assertTrue("Size of result is not 1, but " + result.size(),
result.size() == 1);
// Test ignore case in criterion
criteria = new Criteria();
Criterion criterion1 = new Criterion(
AuthorPeer.NAME,
author.getName().toLowerCase(),
Criteria.EQUAL);
criterion1.setIgnoreCase(true);
Criterion criterion2 = new Criterion(
AuthorPeer.AUTHOR_ID, null, Criteria.NOT_EQUAL);
criterion1.and(criterion2);
result = AuthorPeer.doSelect(criteria);
// ignore case should not be set either in Criteria
// nor in other criterions
assertFalse(criteria.isIgnoreCase());
assertFalse(criterion2.isIgnoreCase());
assertTrue("Size of result is not 1, but " + result.size(),
result.size() == 1);
// Test ignore case in attached criterion
criteria = new Criteria();
criterion1 = new Criterion(
AuthorPeer.AUTHOR_ID, null, Criteria.NOT_EQUAL);
criterion2 = new Criterion(
AuthorPeer.NAME,
author.getName().toLowerCase(),
Criteria.EQUAL);
criterion2.setIgnoreCase(true);
criterion1.and(criterion2);
result = AuthorPeer.doSelect(criteria);
// ignore case should not be set either in Criteria
// nor in other criterions
assertFalse(criteria.isIgnoreCase());
assertFalse(criterion1.isIgnoreCase());
assertTrue("Size of result is not 1, but " + result.size(),
result.size() == 1);
// ignore case in "in" query
{
criteria = new Criteria();
Set<String> names = new HashSet<String>();
names.add(author.getName().toLowerCase());
criteria.where(AuthorPeer.NAME, names, Criteria.IN);
criteria.setIgnoreCase(true);
result = AuthorPeer.doSelect(criteria);
assertEquals("Expected result of size 1 but got " + result.size(),
result.size(),
1);
}
// Check that case is not ignored if ignoreCase is not set
// This is known not to work for mysql
author = new Author();
author.setName("author");
author.save();
Adapter adapter = Torque.getAdapter(Torque.getDefaultDB());
if (adapter instanceof MysqlAdapter
|| adapter instanceof MssqlAdapter)
{
log.error("testIgnoreCase(): "
+ "Case sensitive comparisons are known not to work"
+ " with Mysql and MSSQL");
// failing is "expected", so bypass without error
}
else
{
criteria = new Criteria();
criteria.where(AuthorPeer.NAME, author.getName());
result = AuthorPeer.doSelect(criteria);
assertTrue("Size of result is not 1, but " + result.size(),
result.size() == 1);
// again check LIKE treatment
criteria = new Criteria();
criteria.where(
AuthorPeer.NAME,
author.getName().replace('r', '%'),
Criteria.LIKE);
result = AuthorPeer.doSelect(criteria);
assertTrue("Size of result is not 1, but " + result.size(),
result.size() == 1);
// Test different ignore cases in criterions
criteria = new Criteria();
criterion1 = new Criterion(
AuthorPeer.NAME,
author.getName().toLowerCase(),
Criteria.NOT_EQUAL);
criterion2 = new Criterion(
AuthorPeer.NAME,
author.getName().toLowerCase(),
Criteria.EQUAL);
criterion2.setIgnoreCase(true);
criterion1.and(criterion2);
criteria.where(criterion1);
result = AuthorPeer.doSelect(criteria);
assertTrue("Size of result is not 1, but " + result.size(),