You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2011/05/14 19:34:25 UTC
svn commit: r1103171 [4/4] - in /db/torque/torque4/trunk:
torque-runtime/src/main/java/org/apache/torque/util/
torque-runtime/src/test/java/org/apache/torque/sql/
torque-runtime/src/test/java/org/apache/torque/util/
torque-templates/src/main/java/org/a...
Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java?rev=1103171&r1=1103170&r2=1103171&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java (original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java Sat May 14 17:34:23 2011
@@ -28,7 +28,6 @@ import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -57,6 +56,7 @@ import org.apache.torque.test.A;
import org.apache.torque.test.APeer;
import org.apache.torque.test.Author;
import org.apache.torque.test.AuthorPeer;
+import org.apache.torque.test.AuthorRecordMapper;
import org.apache.torque.test.B;
import org.apache.torque.test.BPeer;
import org.apache.torque.test.BitCompositePk;
@@ -67,6 +67,7 @@ import org.apache.torque.test.BlobTest;
import org.apache.torque.test.BlobTestPeer;
import org.apache.torque.test.Book;
import org.apache.torque.test.BookPeer;
+import org.apache.torque.test.BookRecordMapper;
import org.apache.torque.test.BooleanCheck;
import org.apache.torque.test.BooleanCheckPeer;
import org.apache.torque.test.C;
@@ -373,13 +374,13 @@ public class DataTest extends BaseRuntim
criteria.add(NullValueTablePeer.NUMBER_OBJ1,
(Integer)null,
Criteria.NOT_EQUAL);
- List result = NullValueTablePeer.doSelect(criteria);
+ List<NullValueTable> result = NullValueTablePeer.doSelect(criteria);
assertEquals("testNullSelects()"
+ "Result size should be 1 but is "
+ result.size(),
1,
result.size());
- nvt = (NullValueTable) result.get(0);
+ nvt = result.get(0);
assertEquals("testNullSelects()"
+ "Text1 should be \"text\" but is"
+ nvt.getText1(),
@@ -401,7 +402,7 @@ public class DataTest extends BaseRuntim
+ result.size(),
1,
result.size());
- nvt = (NullValueTable) result.get(0);
+ nvt = result.get(0);
assertEquals("testNullSelects()"
+ "Text2 should be \"text\" but is"
+ nvt.getText2(),
@@ -842,14 +843,14 @@ public class DataTest extends BaseRuntim
Criteria criteria = new Criteria();
criteria.addAscendingOrderByColumn(AuthorPeer.NAME);
- List authors = AuthorPeer.doSelect(criteria);
+ List<Author> authors = AuthorPeer.doSelect(criteria);
assertEquals("List should contain 2 authors", 2, authors.size());
assertEquals("First Author's name should be \"Name\"",
"Name",
- ((Author) authors.get(0)).getName());
+ authors.get(0).getName());
assertEquals("Second Author's name should be \"OtherName\"",
"OtherName",
- ((Author) authors.get(1)).getName());
+ authors.get(1).getName());
author.setName("NewName");
author.save();
@@ -861,10 +862,10 @@ public class DataTest extends BaseRuntim
assertEquals("List should contain 2 authors", 2, authors.size());
assertEquals("First Author's name should be \"NewName\"",
"NewName",
- ((Author) authors.get(0)).getName());
+ authors.get(0).getName());
assertEquals("Second Author's name should be \"OtherName\"",
"OtherName",
- ((Author) authors.get(1)).getName());
+ authors.get(1).getName());
// Test doUpdate methods in Peer explicitly
Connection connection = Transaction.begin(AuthorPeer.DATABASE_NAME);
@@ -1059,7 +1060,7 @@ public class DataTest extends BaseRuntim
Criteria criteria = new Criteria();
criteria.addJoin(AuthorPeer.AUTHOR_ID, BookPeer.AUTHOR_ID,
Criteria.LEFT_JOIN);
- List authorList = AuthorPeer.doSelect(criteria);
+ List<Author> authorList = AuthorPeer.doSelect(criteria);
// Here we get 5 authors:
// the author with one book, the author without books,
// and three times the author with three books
@@ -1260,7 +1261,7 @@ public class DataTest extends BaseRuntim
// test simple ascending order by
Criteria criteria = new Criteria();
criteria.addAscendingOrderByColumn(BookPeer.TITLE);
- List bookList = BookPeer.doSelect(criteria);
+ List<Book> bookList = BookPeer.doSelect(criteria);
if (bookList.size() != 4)
{
fail("Ascending Order By: "
@@ -1268,18 +1269,18 @@ public class DataTest extends BaseRuntim
+ bookList.size()
+ ", should be 4");
}
- if (! "Book 1".equals(((Book) bookList.get(0)).getTitle()))
+ if (! "Book 1".equals(bookList.get(0).getTitle()))
{
fail("Ascending Order By: "
+ "Title of first Book is "
+ ((Book) bookList.get(0)).getTitle()
+ ", should be \"Book 1\"");
}
- if (! "Book 4".equals(((Book) bookList.get(3)).getTitle()))
+ if (! "Book 4".equals(bookList.get(3).getTitle()))
{
fail("Ascending Order By: "
+ "Title of fourth Book is "
- + ((Book) bookList.get(3)).getTitle()
+ + bookList.get(3).getTitle()
+ ", should be \"Book 4\"");
}
@@ -1294,18 +1295,18 @@ public class DataTest extends BaseRuntim
+ bookList.size()
+ ", should be 4");
}
- if (! "Book 1".equals(((Book) bookList.get(3)).getTitle()))
+ if (! "Book 1".equals(bookList.get(3).getTitle()))
{
fail("Descending Order By: "
+ "Title of fourth Book is "
- + ((Book) bookList.get(3)).getTitle()
+ + bookList.get(3).getTitle()
+ ", should be \"Book 1\"");
}
- if (! "Book 4".equals(((Book) bookList.get(0)).getTitle()))
+ if (! "Book 4".equals((bookList.get(0)).getTitle()))
{
fail("Descending Order By: "
+ "Title of first Book is "
- + ((Book) bookList.get(0)).getTitle()
+ + bookList.get(0).getTitle()
+ ", should be \"Book 4\"");
}
@@ -1654,9 +1655,9 @@ public class DataTest extends BaseRuntim
// basically a BaseBookPeer.setDbName(criteria);
// and BasePeer.doSelect(criteria);
CompositeMapper mapper = new CompositeMapper();
- mapper.addMapper(new BookPeer.BookRecordMapper(), 0);
+ mapper.addMapper(new BookRecordMapper(), 0);
mapper.addMapper(
- new AuthorPeer.AuthorRecordMapper(),
+ new AuthorRecordMapper(),
BookPeer.numColumns);
List<List<Object>> queryResult
@@ -1747,7 +1748,17 @@ public class DataTest extends BaseRuntim
{
Criteria c = new Criteria();
c.add(DateTestPeer.DATE_VALUE, Criteria.CURRENT_DATE);
- c.add(DateTestPeer.TIME_VALUE, Criteria.CURRENT_TIME);
+ DB adapter = Torque.getDatabase(Torque.getDefaultDB()).getAdapter();
+ if (adapter instanceof DBOracle)
+ {
+ log.warn("testCurrentDate(): "
+ + Criteria.CURRENT_TIME
+ + "is not supported by Oracle");
+ }
+ else
+ {
+ c.add(DateTestPeer.TIME_VALUE, Criteria.CURRENT_TIME);
+ }
List<DateTest> result = DateTestPeer.doSelect(c);
}
@@ -1771,8 +1782,8 @@ public class DataTest extends BaseRuntim
largePk.setName("testLargePk");
largePk.save();
- List largePkList = LargePkPeer.doSelect(new Criteria());
- LargePk readLargePk = (LargePk) largePkList.get(0);
+ List<LargePk> largePkList = LargePkPeer.doSelect(new Criteria());
+ LargePk readLargePk = largePkList.get(0);
assertTrue("the inserted Id, " + largePk.getLargePkId()
+ " , and the read id, " + readLargePk.getLargePkId()
+ " , should be equal",
@@ -2077,7 +2088,7 @@ public class DataTest extends BaseRuntim
int minorVersion = getMysqlMinorVersion();
if (majorVersion < 4 || (majorVersion == 4 && minorVersion == 0))
{
- log.error("testSubqueries(): "
+ log.warn("testSubqueries(): "
+ "Subselects are not supported by Mysql < 4.1");
return;
}
@@ -2092,6 +2103,9 @@ public class DataTest extends BaseRuntim
Author author2b = new Author();
author2b.setName("author2");
author2b.save();
+ Author author3 = new Author();
+ author3.setName("author3");
+ author3.save();
// subquery with "in" clause
{
@@ -2102,7 +2116,7 @@ public class DataTest extends BaseRuntim
criteria.add(AuthorPeer.AUTHOR_ID, subquery, Criteria.IN);
criteria.addDescendingOrderByColumn(AuthorPeer.AUTHOR_ID);
- List result = AuthorPeer.doSelect(criteria);
+ List<?> result = AuthorPeer.doSelect(criteria);
assertEquals("Expected result of size 2 but got " + result.size(),
result.size(),
2);
@@ -2142,6 +2156,45 @@ public class DataTest extends BaseRuntim
author1.getAuthorId(),
author.getAuthorId());
}
+
+ // subquery containin an in()
+ {
+ Criteria subquery = new Criteria();
+ subquery.addSelectColumn(AuthorPeer.AUTHOR_ID);
+ List<String> nameList = new ArrayList<String>();
+ nameList.add(author1.getName());
+ nameList.add(author2.getName());
+ subquery.add(AuthorPeer.NAME, nameList, Criteria.IN);
+ Criteria criteria = new Criteria();
+ criteria.add(AuthorPeer.AUTHOR_ID, subquery, Criteria.IN);
+ criteria.addAscendingOrderByColumn(AuthorPeer.AUTHOR_ID);
+
+ List<Author> result = AuthorPeer.doSelect(criteria);
+ assertEquals("Expected result of size 2 but got " + result.size(),
+ result.size(),
+ 3);
+ Author author = result.get(0);
+ assertEquals("Expected author with Id "
+ + author1.getAuthorId()
+ + " but got "
+ + author.getAuthorId(),
+ author1.getAuthorId(),
+ author.getAuthorId());
+ author = result.get(1);
+ assertEquals("Expected author with Id "
+ + author2.getAuthorId()
+ + " but got "
+ + author.getAuthorId(),
+ author2.getAuthorId(),
+ author.getAuthorId());
+ author = result.get(2);
+ assertEquals("Expected author with Id "
+ + author2b.getAuthorId()
+ + " but got "
+ + author.getAuthorId(),
+ author2b.getAuthorId(),
+ author.getAuthorId());
+ }
}
/**
@@ -2161,7 +2214,7 @@ public class DataTest extends BaseRuntim
author3.setName("author3");
author3.save();
- // "in" query with list
+ // "in" query with String list and ignoreCase = false
{
Criteria criteria = new Criteria();
List<String> nameList = new ArrayList<String>();
@@ -2190,7 +2243,36 @@ public class DataTest extends BaseRuntim
author.getAuthorId());
}
- // "in" query with array
+ // "in" query with Integer list and ignoreCase = true
+ {
+ Criteria criteria = new Criteria();
+ List<Integer> idList = new ArrayList<Integer>();
+ idList.add(author1.getAuthorId());
+ idList.add(author2.getAuthorId());
+ criteria.add(AuthorPeer.AUTHOR_ID, idList, Criteria.IN);
+ criteria.addDescendingOrderByColumn(AuthorPeer.AUTHOR_ID);
+
+ List<Author> result = AuthorPeer.doSelect(criteria);
+ assertEquals("Expected result of size 2 but got " + result.size(),
+ 2,
+ result.size());
+ Author author = result.get(0);
+ assertEquals("Expected author with Id "
+ + author2.getAuthorId()
+ + " at first position but got "
+ + author.getAuthorId(),
+ author2.getAuthorId(),
+ author.getAuthorId());
+ author = result.get(1);
+ assertEquals("Expected author with Id "
+ + author1.getAuthorId()
+ + " at second position but got "
+ + author.getAuthorId(),
+ author1.getAuthorId(),
+ author.getAuthorId());
+ }
+
+ // "in" query with array and ignoreCase = false
{
Criteria criteria = new Criteria();
String[] nameArray = new String[] {"author1", "author3"};
@@ -2216,8 +2298,68 @@ public class DataTest extends BaseRuntim
author1.getAuthorId(),
author.getAuthorId());
}
+
+ // "in" query with String list and ignoreCase = true
+ {
+ Criteria criteria = new Criteria();
+ List<String> nameList = new ArrayList<String>();
+ nameList.add("AuTHor1");
+ nameList.add("AuTHor2");
+ criteria.add(AuthorPeer.NAME, nameList, Criteria.IN);
+ criteria.setIgnoreCase(true);
+ criteria.addDescendingOrderByColumn(AuthorPeer.AUTHOR_ID);
+
+ List<Author> result = AuthorPeer.doSelect(criteria);
+ assertEquals("Expected result of size 2 but got " + result.size(),
+ 2,
+ result.size());
+ Author author = result.get(0);
+ assertEquals("Expected author with Id "
+ + author2.getAuthorId()
+ + " at first position but got "
+ + author.getAuthorId(),
+ author2.getAuthorId(),
+ author.getAuthorId());
+ author = result.get(1);
+ assertEquals("Expected author with Id "
+ + author1.getAuthorId()
+ + " at second position but got "
+ + author.getAuthorId(),
+ author1.getAuthorId(),
+ author.getAuthorId());
+ }
+
+ // "in" query with Integer list and ignoreCase = true
+ {
+ Criteria criteria = new Criteria();
+ List<Integer> idList = new ArrayList<Integer>();
+ idList.add(author1.getAuthorId());
+ idList.add(author2.getAuthorId());
+ criteria.add(AuthorPeer.AUTHOR_ID, idList, Criteria.IN);
+ criteria.setIgnoreCase(true);
+ criteria.addDescendingOrderByColumn(AuthorPeer.AUTHOR_ID);
+
+ List<Author> result = AuthorPeer.doSelect(criteria);
+ assertEquals("Expected result of size 2 but got " + result.size(),
+ 2,
+ result.size());
+ Author author = result.get(0);
+ assertEquals("Expected author with Id "
+ + author2.getAuthorId()
+ + " at first position but got "
+ + author.getAuthorId(),
+ author2.getAuthorId(),
+ author.getAuthorId());
+ author = result.get(1);
+ assertEquals("Expected author with Id "
+ + author1.getAuthorId()
+ + " at second position but got "
+ + author.getAuthorId(),
+ author1.getAuthorId(),
+ author.getAuthorId());
+ }
}
-
+
/**
* Tests whether a table implementing an interface actually
* returns an instance of this interface
@@ -2237,24 +2379,27 @@ public class DataTest extends BaseRuntim
ifc.setName("John Doe");
ifc.save();
- List results = IfcTablePeer.doSelect(new Criteria());
+ List<IfcTable> results = IfcTablePeer.doSelect(new Criteria());
- for (Iterator i = results.iterator(); i.hasNext();)
+ for (IfcTable ifcTable : results)
{
- assertTrue("IfcTablePeer.doSelect should return instances of TestInterface",
- i.next() instanceof TestInterface);
+ assertTrue("IfcTablePeer.doSelect should return"
+ + " instances of TestInterface",
+ ifcTable instanceof TestInterface);
}
IfcTable2 ifc2 = new IfcTable2();
- assertTrue("IfcTable2 should be an instance of LocalTestInterface", ifc2 instanceof LocalTestInterface);
+ assertTrue("IfcTable2 should be an instance of LocalTestInterface",
+ ifc2 instanceof LocalTestInterface);
- List results2 = IfcTable2Peer.doSelect(new Criteria());
+ List<IfcTable2> results2 = IfcTable2Peer.doSelect(new Criteria());
- for (Iterator i = results2.iterator(); i.hasNext();)
+ for (IfcTable2 ifcTable2 : results2)
{
- assertTrue("IfcTable2Peer.doSelect should return instances of LocalTestInterface",
- i.next() instanceof LocalTestInterface);
+ assertTrue("IfcTable2Peer.doSelect should return"
+ + " instances of LocalTestInterface",
+ ifcTable2 instanceof LocalTestInterface);
}
}
@@ -2338,7 +2483,7 @@ public class DataTest extends BaseRuntim
assertEquals(1, authors.size());
}
- public void testEscaping() throws Exception
+ public void testLikeClauseEscaping() throws Exception
{
String[] authorNames
= {"abc", "bbc", "a_c", "a%c", "a\\c", "a\"c", "a'c"};
@@ -2366,6 +2511,7 @@ public class DataTest extends BaseRuntim
likeResults.put("%'c", "a'c");
cleanBookstore();
+ // Save authors
for (int i = 0; i < authorNames.length; ++i)
{
Author author = new Author();
@@ -2373,17 +2519,18 @@ public class DataTest extends BaseRuntim
author.save();
}
+ // Check authors are in the database
for (int i = 0; i < authorNames.length; ++i)
{
Criteria criteria = new Criteria();
criteria.add(AuthorPeer.NAME, authorNames[i]);
- List authorList = AuthorPeer.doSelect(criteria);
+ List<Author> authorList = AuthorPeer.doSelect(criteria);
assertEquals(
"AuthorList should contain one author"
+ " when querying for " + authorNames[i],
1,
authorList.size());
- Author author = (Author) authorList.get(0);
+ Author author = authorList.get(0);
assertEquals("Name of author should be " + authorNames[i],
authorNames[i],
author.getName());
@@ -2417,18 +2564,18 @@ public class DataTest extends BaseRuntim
Criteria criteria = new Criteria();
criteria.add(AuthorPeer.NAME, (Object) "AbC", Criteria.LIKE);
criteria.setIgnoreCase(true);
- List authorList = AuthorPeer.doSelect(criteria);
+ List<Author> authorList = AuthorPeer.doSelect(criteria);
assertEquals(
"AuthorList should contain one author",
1,
authorList.size());
- Author author = (Author) authorList.get(0);
+ Author author = authorList.get(0);
assertEquals("Name of author should be abc",
"abc",
author.getName());
- // check that the escape clause (where needed) also works with all
- // the other query stuff
+ // check that the escape clause (where needed) also works
+ // with limit, offset and order by
criteria = new Criteria();
Criteria.Criterion criterion1 = criteria.getNewCriterion(
AuthorPeer.NAME,
@@ -2482,9 +2629,9 @@ public class DataTest extends BaseRuntim
Author author = new Author();
author.setName("shutdownName");
author.save();
- List authors = AuthorPeer.doSelect(new Criteria());
+ List<Author> authors = AuthorPeer.doSelect(new Criteria());
assertEquals("List should contain one author", 1, authors.size());
- author = (Author) authors.get(0);
+ author = authors.get(0);
assertEquals("Author's name should be shutdownName",
"shutdownName",
author.getName());
Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/util/LargeSelectTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/util/LargeSelectTest.java?rev=1103171&r1=1103170&r2=1103171&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/util/LargeSelectTest.java (original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/util/LargeSelectTest.java Sat May 14 17:34:23 2011
@@ -25,6 +25,7 @@ import org.apache.torque.BaseRuntimeTest
import org.apache.torque.TorqueException;
import org.apache.torque.test.Author;
import org.apache.torque.test.AuthorPeer;
+import org.apache.torque.test.AuthorRecordMapper;
/**
* Test code for LargeSelect.
@@ -101,7 +102,7 @@ public class LargeSelectTest extends Bas
{
new LargeSelect<Author>(criteria, TEST_PAGE_SIZE,
"org.apache.torque.test.AuthorPeer",
- new AuthorPeer.AuthorRecordMapper());
+ new AuthorRecordMapper());
}
catch (IllegalArgumentException success)
{
@@ -119,7 +120,7 @@ public class LargeSelectTest extends Bas
{
new LargeSelect<Author>(criteria, TEST_PAGE_SIZE,
"org.apache.torque.test.AuthorPeer",
- new AuthorPeer.AuthorRecordMapper());
+ new AuthorRecordMapper());
}
catch (IllegalArgumentException success)
{
@@ -136,7 +137,7 @@ public class LargeSelectTest extends Bas
{
new LargeSelect<Author>(criteria, 0,
"org.apache.torque.test.AuthorPeer",
- new AuthorPeer.AuthorRecordMapper());
+ new AuthorRecordMapper());
}
catch (IllegalArgumentException success)
{
@@ -153,7 +154,7 @@ public class LargeSelectTest extends Bas
{
new LargeSelect<Author>(criteria, TEST_PAGE_SIZE, 0,
"org.apache.torque.test.AuthorPeer",
- new AuthorPeer.AuthorRecordMapper());
+ new AuthorRecordMapper());
}
catch (IllegalArgumentException success)
{
@@ -170,7 +171,7 @@ public class LargeSelectTest extends Bas
{
new LargeSelect<Author>(criteria, TEST_PAGE_SIZE,
"org.apache.torque.test.Author",
- new AuthorPeer.AuthorRecordMapper());
+ new AuthorRecordMapper());
}
catch (IllegalArgumentException success)
{
@@ -206,12 +207,13 @@ public class LargeSelectTest extends Bas
criteria,
TEST_PAGE_SIZE,
"org.apache.torque.test.AuthorPeer",
- new AuthorPeer.AuthorRecordMapper());
+ new AuthorRecordMapper());
assertEquals("Page size", TEST_PAGE_SIZE, ls.getPageSize());
assertTrue("Paginated", ls.getPaginated());
- // Page 0
+ // Page 0, assuming that the asserts occur before the first records
+ // have been read
assertEquals("Current page number", 0, ls.getCurrentPageNumber());
assertFalse("Previous results available", ls.getPreviousResultsAvailable());
assertTrue("Next results available", ls.getNextResultsAvailable());
@@ -335,7 +337,7 @@ public class LargeSelectTest extends Bas
criteria,
TEST_PAGE_SIZE,
"org.apache.torque.test.AuthorPeer",
- new AuthorPeer.AuthorRecordMapper());
+ new AuthorRecordMapper());
// Page 1
List<Author> results = ls.getNextResults();
@@ -364,7 +366,7 @@ public class LargeSelectTest extends Bas
criteria,
TEST_PAGE_SIZE,
"org.apache.torque.test.AuthorPeer",
- new AuthorPeer.AuthorRecordMapper());
+ new AuthorRecordMapper());
assertEquals("Page size", TEST_PAGE_SIZE, ls.getPageSize());
assertTrue("Paginated", ls.getPaginated());
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org