[ rubbish-db ]

Publisher

/**
 * 出版社(インターフェース)
 */
public interface Publisher {

    public String getId();

    public void setId(String id);

    /////////////////////////////////////////////////////////////////

    public String getName();

    public void setName(String name);

    /////////////////////////////////////////////////////////////////

    public Integer getVolumes();

    public void setVolumes(Integer volumes);

    /////////////////////////////////////////////////////////////////

    public Date getUpdate_date();

    public void setUpdate_date(Date update_date);

    /////////////////////////////////////////////////////////////////

    public Date getCreate_date();

    public void setCreate_date(Date create_date);

}

Book

/**
 * 書籍(インターフェース)
 */
public interface Book {

    public String getPublisher();

    public void setPublisher(String publisher);

    /////////////////////////////////////////////////////////////////

    public String getId();

    public void setId(String id);

    /////////////////////////////////////////////////////////////////

    public String getTitle();

    public void setTitle(String title);

    /////////////////////////////////////////////////////////////////

    public String getAuthor();

    public void setAuthor(String author);

    /////////////////////////////////////////////////////////////////

    public Date getIssue_date();

    public void setIssue_date(Date issue_date);

    /////////////////////////////////////////////////////////////////

    public Date getUpdate_date();

    public void setUpdate_date(Date update_date);

    /////////////////////////////////////////////////////////////////

    public Date getCreate_date();

    public void setCreate_date(Date create_date);

}

ソース

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

dbh.connect("jdbc:hsqldb:hsql://localhost", "sa", "");

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

int prows = dbh.insert(publisher);
println("prows=" + prows);

Publisher[] publishers = (Publisher[]) dbh.select(Publisher.class,
        "ORDER BY ID");

for (int i = 0; i < publishers.length; i++)
    println(publishers[i]);

Book book01 = (Book) BF._new(Book.class);
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 = (Book) BF._new(Book.class);
book02.setPublisher("07");
book02.setId("001");
book02.setTitle("蛇場");
book02.setAuthor("御素輪具");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
book02.setIssue_date(df.parse("2001-06-01"));
book02.setUpdate_date(new Date());
book02.setCreate_date(new Date());

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

int brows = dbh.insert(booklist);
println("brows=" + brows);

Book[] books = (Book[]) dbh.select(Book.class,
        "WHERE PUBLISHER=? ORDER BY ID", "07");

for (int i = 0; i < books.length; i++)
    println(books[i]);

dbh.rollback();
dbh.disconnect();

結果

connect database 'url=jdbc:hsqldb:hsql://localhost, user=sa, password='.
'INSERT INTO PUBLISHER (CREATE_DATE, ID, NAME, UPDATE_DATE, VOLUMES) VALUES (?, ?, ?, ?, ?) [2005-09-11 11:04:44.339, 07, 御来利意書房, 2005-09-11 11:04:44.339, 2]'
prows=1
'SELECT * FROM PUBLISHER ORDER BY ID'
Publisher@{create_date=1999-07-10 17:10:00.000, id=00, name=ミュンヒハウゼン出版, update_date=2005-07-10 17:10:00.000, volumes=1}
Publisher@{create_date=1999-07-10 17:10:00.000, id=01, name=栄学館, update_date=2005-07-10 17:10:00.000, volumes=4}
Publisher@{create_date=1999-07-10 17:10:00.000, id=02, name=時源出版, update_date=2005-07-10 17:10:00.000, volumes=4}
Publisher@{create_date=1999-07-10 17:10:00.000, id=03, name=曙蓬莱新聞社, update_date=2005-07-10 17:10:00.000, volumes=4}
Publisher@{create_date=1999-07-10 17:10:00.000, id=04, name=太公望書林, update_date=2005-07-10 17:10:00.000, volumes=12}
Publisher@{create_date=1999-07-10 17:10:00.000, id=05, name=日本曙蓬莱武術協会, update_date=2005-07-10 17:10:00.000, volumes=5}
Publisher@{create_date=1999-07-10 17:10:00.000, id=06, name=民明書房, update_date=2005-07-10 17:10:00.000, volumes=76}
Publisher@{create_date=2005-09-11 11:04:44.339, id=07, name=御来利意書房, update_date=2005-09-11 11:04:44.339, volumes=2}
'INSERT INTO BOOK (AUTHOR, CREATE_DATE, ID, ISSUE_DATE, PUBLISHER, TITLE, UPDATE_DATE) VALUES (?, ?, ?, ?, ?, ?, ?) [愛微意笑, 2005-09-11 11:04:44.399, 000, null, 07, 獲九里伏, 2005-09-11 11:04:44.399]'
'INSERT INTO BOOK (AUTHOR, CREATE_DATE, ID, ISSUE_DATE, PUBLISHER, TITLE, UPDATE_DATE) VALUES (?, ?, ?, ?, ?, ?, ?) [御素輪具, 2005-09-11 11:04:44.399, 001, 2001-06-01 00:00:00.000, 07, 蛇場, 2005-09-11 11:04:44.399]'
brows=2
'SELECT * FROM BOOK WHERE PUBLISHER=? ORDER BY ID [07]'
Book@{author=愛微意笑, create_date=2005-09-11 11:04:44.399, id=000, issue_date=null, publisher=07, title=獲九里伏, update_date=2005-09-11 11:04:44.399}
Book@{author=御素輪具, create_date=2005-09-11 11:04:44.399, id=001, issue_date=2001-06-01 00:00:00.000, publisher=07, title=蛇場, update_date=2005-09-11 11:04:44.399}
rollback transaction.
disconnect database.