Class CollectionContainsMethod
- java.lang.Object
-
- org.datanucleus.store.rdbms.sql.method.CollectionContainsMethod
-
-
Constructor Summary
Constructors Constructor Description CollectionContainsMethod()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addRestrictionOnElement(SQLStatement stmt, SQLExpression elemIdExpr, SQLExpression elemExpr)
protected SQLExpression
containsAsJoin(SQLStatement stmt, CollectionExpression collExpr, SQLExpression elemExpr, SQLJoin.JoinType joinType)
Method to return an expression for Collection.contains using INNER JOIN to the element.protected SQLExpression
containsAsSubquery(SQLStatement stmt, CollectionExpression collExpr, SQLExpression elemExpr)
Method to return an expression for Collection.contains using a subquery "EXISTS".protected boolean
elementTypeCompatible(Class elementType, Class collectionElementType)
SQLExpression
getExpression(SQLStatement stmt, SQLExpression expr, List<SQLExpression> args)
Return the expression for this SQL function.protected boolean
getNeedsSubquery(SQLStatement stmt, SQLExpression collExpr, SQLExpression elemExpr)
Convenience method to decide if we handle the contains() by using a subquery, or otherwise via an inner join.
-
-
-
Method Detail
-
getExpression
public SQLExpression getExpression(SQLStatement stmt, SQLExpression expr, List<SQLExpression> args)
Description copied from interface:SQLMethod
Return the expression for this SQL function.- Specified by:
getExpression
in interfaceSQLMethod
- Parameters:
stmt
- SQLStatement that this expression is forexpr
- The expression that it is invoked onargs
- Arguments passed in- Returns:
- The SQL expression using the SQL function
-
getNeedsSubquery
protected boolean getNeedsSubquery(SQLStatement stmt, SQLExpression collExpr, SQLExpression elemExpr)
Convenience method to decide if we handle the contains() by using a subquery, or otherwise via an inner join. If there is an OR or a NOT in the query then uses a subquery.- Parameters:
stmt
- SQLStatementcollExpr
- SQL Expression for the collectionelemExpr
- SQL Expression for the element- Returns:
- Whether to use a subquery
-
containsAsJoin
protected SQLExpression containsAsJoin(SQLStatement stmt, CollectionExpression collExpr, SQLExpression elemExpr, SQLJoin.JoinType joinType)
Method to return an expression for Collection.contains using INNER JOIN to the element. This is only for use when there are no "!contains" and no "OR" operations. Creates SQL by adding INNER JOIN to the join table (where it exists), and also to the element table adding an AND condition on the element (with value of the elemExpr). Returns a BooleanExpression "TRUE" (since the INNER JOIN will guarantee if the element is contained of not).- Parameters:
stmt
- SQLStatementcollExpr
- Collection expressionelemExpr
- Expression for the elementjoinType
- Join type- Returns:
- Contains expression
-
containsAsSubquery
protected SQLExpression containsAsSubquery(SQLStatement stmt, CollectionExpression collExpr, SQLExpression elemExpr)
Method to return an expression for Collection.contains using a subquery "EXISTS". This is for use when there are "!contains" or "OR" operations in the filter. Creates the following SQL,- Collection of NonPC using join table
SELECT 1 FROM JOIN_TBL A0_SUB WHERE A0_SUB.JOIN_OWN_ID = A0.ID AND A0_SUB.JOIN_ELEM_ID = {elemExpr}
- Collection of PC using join table
SELECT 1 FROM ELEM_TABLE A0_SUB INNER JOIN JOIN_TBL B0 ON ... WHERE B0.JOIN_OWN_ID = A0.ID AND A0_SUB.ID = {elemExpr}
- Collection of PC using FK
SELECT 1 FROM ELEM_TABLE A0_SUB WHERE A0_SUB.OWN_ID = A0.ID AND A0_SUB.ID = {elemExpr}
- Parameters:
stmt
- SQLStatementcollExpr
- Collection expressionelemExpr
- Expression for the element- Returns:
- Contains expression
- Collection of NonPC using join table
-
addRestrictionOnElement
protected void addRestrictionOnElement(SQLStatement stmt, SQLExpression elemIdExpr, SQLExpression elemExpr)
-
-