[ rubbish-db ]

DAO

ソース

RubbishDatabase dbh = new RubbishDatabase();
dbh.setLogging(true);

dbh.connect("jdbc:hsqldb:hsql://localhost", "sa", "");
DAOFactory factory = new DAOFactory(dbh, "C:/eclipse/workspace/rubbish-db/sample/src/sample/hsqldb/dao");

BookDAO bookDAO = (BookDAO) factory._new(BookDAO.class);

Publisher publisher = new Publisher();
publisher.setId("07");
publisher.setName("御来利意書房");
publisher.setVolumes(new Integer(2));
publisher.setUpdate_date(new Date());
publisher.setCreate_date(new Date());

Book book01 = new Book();
book01.setPublisher("07");
book01.setId("000");
book01.setTitle("獲九里伏");
book01.setAuthor("愛微意笑");
book01.setIssue_date(null);
book01.setUpdate_date(new Date());
book01.setCreate_date(new Date());

Book book02 = new Book();
book02.setPublisher("07");
book02.setId("001");
book02.setTitle("蛇場");
book02.setAuthor("御素輪具");
book02.setIssue_date(new ZDate("2001-06-01"));
book02.setUpdate_date(new Date());
book02.setCreate_date(new Date());

println("----------");

dbh.insert(publisher);

int rows01 = bookDAO.insert(book01);
println("rows=" + rows01);
dbh.select(Book.class, "WHERE PUBLISHER=? ORDER BY ID", "07", new SBLK() {
    public void each(Object row) {
        println(row);
    }
});

dbh.rollback();

println("----------");

dbh.insert(publisher);

Book[] books01 = { book01, book02 };

Integer rows02 = bookDAO.insert(books01);
println("rows=" + rows02);
dbh.select(Book.class, "WHERE PUBLISHER=? ORDER BY ID", "07", new SBLK() {
    public void each(Object row) {
        println(row);
    }
});

dbh.rollback();

println("----------");

dbh.insert(publisher);

List books02 = new ArrayList();
books02.add(book01);
books02.add(book02);

bookDAO.insert(books02);
dbh.select(Book.class, "WHERE PUBLISHER=? ORDER BY ID", "07", new SBLK() {
    public void each(Object row) {
        println(row);
    }
});

dbh.rollback();

println("----------");

dbh.disconnect();

結果

connect database 'url=jdbc:hsqldb:hsql://localhost, user=sa, password='.
----------
'INSERT INTO PUBLISHER (CREATE_DATE, ID, NAME, UPDATE_DATE, VOLUMES) VALUES (?, ?, ?, ?, ?) [2006-01-09 06:16:36.664, 07, 御来利意書房, 2006-01-09 06:16:36.664, 2]'
'INSERT INTO BOOK (AUTHOR, CREATE_DATE, ID, ISSUE_DATE, PUBLISHER, TITLE, UPDATE_DATE) VALUES (?, ?, ?, ?, ?, ?, ?) [愛微意笑, 2006-01-09 06:16:36.664, 000, null, 07, 獲九里伏, 2006-01-09 06:16:36.664]'
rows=1
'SELECT * FROM BOOK WHERE PUBLISHER=? ORDER BY ID [07]'
Book@{author=愛微意笑, create_date=2006-01-09 06:16:36.664, id=000, issue_date=null, publisher=07, title=獲九里伏, update_date=2006-01-09 06:16:36.664}
rollback transaction.
----------
'INSERT INTO PUBLISHER (CREATE_DATE, ID, NAME, UPDATE_DATE, VOLUMES) VALUES (?, ?, ?, ?, ?) [2006-01-09 06:16:36.664, 07, 御来利意書房, 2006-01-09 06:16:36.664, 2]'
'INSERT INTO BOOK (AUTHOR, CREATE_DATE, ID, ISSUE_DATE, PUBLISHER, TITLE, UPDATE_DATE) VALUES (?, ?, ?, ?, ?, ?, ?) [愛微意笑, 2006-01-09 06:16:36.664, 000, null, 07, 獲九里伏, 2006-01-09 06:16:36.664]'
'INSERT INTO BOOK (AUTHOR, CREATE_DATE, ID, ISSUE_DATE, PUBLISHER, TITLE, UPDATE_DATE) VALUES (?, ?, ?, ?, ?, ?, ?) [御素輪具, 2006-01-09 06:16:36.664, 001, 2001-06-01 00:00:00.000, 07, 蛇場, 2006-01-09 06:16:36.664]'
rows=2
'SELECT * FROM BOOK WHERE PUBLISHER=? ORDER BY ID [07]'
Book@{author=愛微意笑, create_date=2006-01-09 06:16:36.664, id=000, issue_date=null, publisher=07, title=獲九里伏, update_date=2006-01-09 06:16:36.664}
Book@{author=御素輪具, create_date=2006-01-09 06:16:36.664, id=001, issue_date=2001-06-01 00:00:00.000, publisher=07, title=蛇場, update_date=2006-01-09 06:16:36.664}
rollback transaction.
----------
'INSERT INTO PUBLISHER (CREATE_DATE, ID, NAME, UPDATE_DATE, VOLUMES) VALUES (?, ?, ?, ?, ?) [2006-01-09 06:16:36.664, 07, 御来利意書房, 2006-01-09 06:16:36.664, 2]'
'INSERT INTO BOOK (AUTHOR, CREATE_DATE, ID, ISSUE_DATE, PUBLISHER, TITLE, UPDATE_DATE) VALUES (?, ?, ?, ?, ?, ?, ?) [愛微意笑, 2006-01-09 06:16:36.664, 000, null, 07, 獲九里伏, 2006-01-09 06:16:36.664]'
'INSERT INTO BOOK (AUTHOR, CREATE_DATE, ID, ISSUE_DATE, PUBLISHER, TITLE, UPDATE_DATE) VALUES (?, ?, ?, ?, ?, ?, ?) [御素輪具, 2006-01-09 06:16:36.664, 001, 2001-06-01 00:00:00.000, 07, 蛇場, 2006-01-09 06:16:36.664]'
'SELECT * FROM BOOK WHERE PUBLISHER=? ORDER BY ID [07]'
Book@{author=愛微意笑, create_date=2006-01-09 06:16:36.664, id=000, issue_date=null, publisher=07, title=獲九里伏, update_date=2006-01-09 06:16:36.664}
Book@{author=御素輪具, create_date=2006-01-09 06:16:36.664, id=001, issue_date=2001-06-01 00:00:00.000, publisher=07, title=蛇場, update_date=2006-01-09 06:16:36.664}
rollback transaction.
----------
disconnect database.