Integer result = 1;
final BooleanFactory b = vendor.getBooleanFactory();
final LiteralFactory l = vendor.getLiteralFactory();
final ColumnsFactory c = vendor.getColumnsFactory();
final QueryFactory q = vendor.getQueryFactory();
final TableReferenceFactory t = vendor.getTableReferenceFactory();
if( value instanceof Collection<?> )
{
// Collection
Integer collectionIndex = 0;
Boolean collectionIsSet = value instanceof Set<?>;
Boolean topLevel = collectionPath.equals( DBNames.QNAME_TABLE_COLLECTION_PATH_TOP_LEVEL_NAME );
String collTable = TABLE_NAME_PREFIX + currentTableIndex;
String collCol = DBNames.QNAME_TABLE_COLLECTION_PATH_COLUMN_NAME;
ColumnReferenceByName collColExp = c.colName( collTable, collCol );
BooleanBuilder collectionCondition = b.booleanBuilder();
if( topLevel && negationActive )
{
afterWhere
.and( b
.booleanBuilder(
b.neq( collColExp,
l.s( DBNames.QNAME_TABLE_COLLECTION_PATH_TOP_LEVEL_NAME ) ) )
.or( b.isNull( collColExp ) ).createExpression() );
}
Integer totalItemsProcessed = 0;
for( Object item : (Collection<?>) value )
{
String path = collectionPath + DBNames.QNAME_TABLE_COLLECTION_PATH_SEPARATOR
+ ( collectionIsSet ? "*{1,}" : collectionIndex );
Boolean isCollection = ( item instanceof Collection<?> );
BooleanBuilder newWhere = b.booleanBuilder();
if( !isCollection )
{
newWhere.reset( b.regexp( collColExp, l.s( path ) ) );
}
totalItemsProcessed
= totalItemsProcessed
+ modifyFromClauseAndWhereClauseToGetValue( qName, item, predicate,
negationActive,
currentTableIndex, maxTableIndex, columnName, path, vendor,
newWhere, afterWhere, fromClause,
groupBy, having, qNameJoins, variables, values, valueSQLTypes );
++collectionIndex;
collectionCondition.or( newWhere.createExpression() );
}
result = totalItemsProcessed;
if( topLevel )
{
if( totalItemsProcessed == 0 )
{
collectionCondition.and( b.isNotNull( collColExp ) )
.and(
b.eq( collColExp,
l.l( DBNames.QNAME_TABLE_COLLECTION_PATH_TOP_LEVEL_NAME ) ) );
}
else if( !negationActive )
{
groupBy.addGroupingElements( q.groupingElement( c.colName( TABLE_NAME_PREFIX
+ currentTableIndex,
DBNames.ENTITY_TABLE_PK_COLUMN_NAME ) ) );
having
.and( b.eq(
l.func( SQLFunctions.COUNT,