rubbish-db / チュートリアル / インターフェースのみのJavaBeanでWHERE句を組み立てる


[ 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();
dbh.setLogging(true);

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

Publisher publisher = (Publisher) BF._new(Publisher.class);
publisher.setId("01");
publisher.setUpdate_date(new ZDate("2005-07-10 17:10:00"));
Publisher[] publishers = (Publisher[]) dbh.select(QBE.join(publisher));

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

Book book = (Book) BF._new(Book.class);
book.setPublisher("01");
book.setAuthor("中津川大観");
Book[] books = (Book[]) dbh.select(QBE.join_or(book));

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

dbh.disconnect();

結果

connect database 'url=jdbc:hsqldb:hsql://localhost, user=sa, password='.
'SELECT * FROM PUBLISHER WHERE UPDATE_DATE = ? AND ID = ? [2005-07-10 17:10:00.000, 01]'
Publisher@{create_date=1999-07-10 17:10:00.000, id=01, name=栄学館, update_date=2005-07-10 17:10:00.000, volumes=4}
'SELECT * FROM BOOK WHERE PUBLISHER = ? OR AUTHOR = ? [01, 中津川大観]'
Book@{author=null, create_date=1999-06-10 17:10:00.000, id=000, issue_date=null, publisher=01, title=インド母なる大地を往く, update_date=2005-06-10 17:10:00.000}
Book@{author=null, create_date=1999-06-10 17:10:00.000, id=001, issue_date=null, publisher=01, title=騎馬民族の逆襲, update_date=2005-06-10 17:10:00.000}
Book@{author=null, create_date=1999-06-10 17:10:00.000, id=002, issue_date=null, publisher=01, title=中国武闘三千年, update_date=2005-06-10 17:10:00.000}
Book@{author=null, create_date=1999-06-10 17:10:00.000, id=003, issue_date=null, publisher=01, title=武家社会に於ける風俗・迷信, update_date=2005-06-10 17:10:00.000}
Book@{author=中津川大観, create_date=1999-06-10 17:10:00.000, id=000, issue_date=null, publisher=02, title=偉大なる中国拳法, update_date=2005-06-10 17:10:00.000}
Book@{author=中津川大観, create_date=1999-06-10 17:10:00.000, id=001, issue_date=null, publisher=02, title=戦場にかける橋, update_date=2005-06-10 17:10:00.000}
Book@{author=中津川大観, create_date=1999-06-10 17:10:00.000, id=002, issue_date=null, publisher=02, title=中国拳法裏面史, update_date=2005-06-10 17:10:00.000}
Book@{author=中津川大観, create_date=1999-06-10 17:10:00.000, id=003, issue_date=null, publisher=02, title=武芸秘史, update_date=2005-06-10 17:10:00.000}
disconnect database.