public BooleanExpression containsMethod(ScalarExpression expr)
{
// ct... = "collection table"
// et... = "element table"
IdentifierFactory idFactory = qs.getStoreManager().getIdentifierFactory();
if (expr instanceof NullLiteral)
{
// JPOX doesn't currently support storing nulls in Collections so just return "1 = 0"
// TODO Add support for storing nulls in collections and querying for this situation
return new BooleanLiteral(qs, mapping, false).eq(new BooleanLiteral(qs, mapping, true));
}
else if( exprs != null )
{
BooleanExpression bExpr = null;
for( int i=0; i<exprs.length; i++)
{
if( bExpr == null )
{
bExpr = exprs[i].eq(expr);
}
else
{
bExpr = bExpr.ior(exprs[i].eq(expr));
}
}
bExpr.encloseWithInParentheses();
return bExpr;
}
else if (expr instanceof UnboundVariable)
{
UnboundVariable var = (UnboundVariable)expr;
if (var.getVariableType() == null)
{
//Set the variable type to be the element type for this collection
//implicit variable type. We now set the type to the collection type
var.setVariableType(qs.getClassLoaderResolver().classForName(arrayStore.getElementType()));
}
//ctJavaName += + '.' + var.getVariableName();
//String etJavaName = qs.getDefaultTableExpression().getRangeVariable().getJavaName() + '.' + var.getVariableName();
String etIdentifier = "UNBOUND" + '.' + var.getVariableName();
String ctIdentifier = idFactory.newIdentifier(idFactory.newIdentifier(te.getAlias(), fieldName), var.getVariableName()).getIdentifierName();
DatastoreIdentifier ctRangeVar = idFactory.newIdentifier(IdentifierType.TABLE, ctIdentifier);
DatastoreIdentifier etRangeVar = idFactory.newIdentifier(IdentifierType.TABLE, etIdentifier);
QueryExpression qexpr = getBackingStoreQueryable().getExistsSubquery(qs, mapping, te, ctRangeVar);
var.bindTo(getBackingStoreQueryable().joinElementsTo(qexpr,
qs,
mapping,
te,
ctRangeVar,
var.getVariableType(),
expr,
expr.te == null ? etRangeVar : expr.te.getAlias()));
return new ExistsExpression(qs, qexpr, true);
}
else if (expr instanceof Literal)
{
String ctIdentifier = idFactory.newIdentifier(te.getAlias(), fieldName).getIdentifierName();
DatastoreIdentifier ctRangeVar = qs.getStoreManager().getIdentifierFactory().newIdentifier(IdentifierType.TABLE, ctIdentifier);
DatastoreIdentifier etRangeVar;
if (expr.te == null) // literals
{
int n = 0;
do
{
String etIdentifier = ctIdentifier + '.' + (++n);
etRangeVar = qs.getStoreManager().getIdentifierFactory().newIdentifier(IdentifierType.TABLE, etIdentifier);
} while (qs.getTableExpression(etRangeVar) != null);
}
else
{
etRangeVar = expr.te.getAlias();
}
ClassLoaderResolver clr=qs.getClassLoaderResolver();
QueryExpression qexpr = getBackingStoreQueryable().getExistsSubquery(qs, mapping, te, ctRangeVar);
ScalarExpression expr1 = getBackingStoreQueryable().joinElementsTo(qexpr,
qs,
mapping,
te,
ctRangeVar,
clr.classForName(expr.getMapping().getType()),
expr,
expr.te == null ? etRangeVar : expr.te.getAlias());
qexpr.andCondition(expr.eq(expr1));
return new ExistsExpression(qs, qexpr, true);
}
else
{
String ctIdentifier = idFactory.newIdentifier(te.getAlias(), fieldName).getIdentifierName();
DatastoreIdentifier ctRangeVar = qs.getStoreManager().getIdentifierFactory().newIdentifier(IdentifierType.TABLE, ctIdentifier);
DatastoreIdentifier etRangeVar;
if (expr.te == null) // literals
{
int n = 0;