{
// inner joins
List<Author> bookAuthors = null;
try
{
Criteria criteria = new Criteria();
criteria.addJoin(
AuthorPeer.AUTHOR_ID,
BookPeer.AUTHOR_ID,
Criteria.INNER_JOIN);
bookAuthors = AuthorPeer.doSelect(criteria);
// from Details section
Author author = bookAuthors.get(0);
List<Book> books = author.getBooks();
}
catch (Exception e)
{
e.printStackTrace();
fail("inner join : Exception caught : "
+ e.getClass().getName()
+ " : " + e.getMessage());
}
assertTrue(
"inner join : size of bookAuthors is not 3, but"
+ bookAuthors.size(),
bookAuthors.size() == 3);
// test explicit sql statements from details section
List<List<Object>> result = null;
try
{
result = BasePeer.doSelect(
"SELECT book.* FROM book "
+ "INNER JOIN author "
+ "ON book.AUTHOR_ID=author.AUTHOR_ID",
new ObjectListMapper(),
(String) null);
}
catch (Exception e)
{
e.printStackTrace();
fail("Explicit SQL query 1 : Exception caught : "
+ e.getClass().getName()
+ " : " + e.getMessage());
}
assertTrue(
"Explicit SQL query 1 : size of result is not 3, but"
+ result.size(),
result.size() == 3);
result = null;
try
{
result = BasePeer.doSelect(
"SELECT book.* FROM book,author "
+ "WHERE book.AUTHOR_ID=author.AUTHOR_ID",
new ObjectListMapper(),
(String) null);
}
catch (Exception e)
{
e.printStackTrace();
fail("Explicit SQL query 2 : Exception caught : "
+ e.getClass().getName()
+ " : " + e.getMessage());
}
assertTrue(
"Explicit SQL query 2 : size of result is not 3, but"
+ result.size(),
result.size() == 3);
// test left outer join
bookAuthors = null;
try
{
Criteria criteria = new Criteria();
criteria.addJoin(
AuthorPeer.AUTHOR_ID,
BookPeer.AUTHOR_ID,
Criteria.LEFT_JOIN);
bookAuthors = AuthorPeer.doSelect(criteria);
}