Search in sources :

Example 11 with Expression

use of org.datanucleus.store.query.expression.Expression in project datanucleus-rdbms by datanucleus.

the class QueryToSQLMapper method compileHaving.

/**
 * Method to compile the having clause of the query into the SQLStatement.
 * @param stmt SELECT statement
 */
protected void compileHaving(SelectStatement stmt) {
    if (compilation.getExprHaving() != null) {
        // Apply any having to the statement
        compileComponent = CompilationComponent.HAVING;
        Expression havingExpr = compilation.getExprHaving();
        Object havingEval = havingExpr.evaluate(this);
        if (!(havingEval instanceof BooleanExpression)) {
            // Non-boolean having clause should be user exception
            throw new NucleusUserException(Localiser.msg("021051", havingExpr));
        }
        stmt.setHaving((BooleanExpression) havingEval);
        compileComponent = null;
    }
}
Also used : BooleanExpression(org.datanucleus.store.rdbms.sql.expression.BooleanExpression) PrimaryExpression(org.datanucleus.store.query.expression.PrimaryExpression) BooleanSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.BooleanSubqueryExpression) TypeConverterExpression(org.datanucleus.store.rdbms.sql.expression.TypeConverterExpression) StringExpression(org.datanucleus.store.rdbms.sql.expression.StringExpression) NumericSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.NumericSubqueryExpression) StringSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.StringSubqueryExpression) MapExpression(org.datanucleus.store.rdbms.sql.expression.MapExpression) ArrayExpression(org.datanucleus.store.query.expression.ArrayExpression) CaseExpression(org.datanucleus.store.query.expression.CaseExpression) CreatorExpression(org.datanucleus.store.query.expression.CreatorExpression) NewObjectExpression(org.datanucleus.store.rdbms.sql.expression.NewObjectExpression) OrderExpression(org.datanucleus.store.query.expression.OrderExpression) TemporalSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.TemporalSubqueryExpression) ClassExpression(org.datanucleus.store.query.expression.ClassExpression) BooleanExpression(org.datanucleus.store.rdbms.sql.expression.BooleanExpression) Expression(org.datanucleus.store.query.expression.Expression) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) ParameterExpression(org.datanucleus.store.query.expression.ParameterExpression) UnboundExpression(org.datanucleus.store.rdbms.sql.expression.UnboundExpression) TemporalExpression(org.datanucleus.store.rdbms.sql.expression.TemporalExpression) SubqueryExpression(org.datanucleus.store.query.expression.SubqueryExpression) ResultAliasExpression(org.datanucleus.store.rdbms.sql.expression.ResultAliasExpression) VariableExpression(org.datanucleus.store.query.expression.VariableExpression) TypeExpression(org.datanucleus.store.query.expression.TypeExpression) NumericExpression(org.datanucleus.store.rdbms.sql.expression.NumericExpression) CollectionExpression(org.datanucleus.store.rdbms.sql.expression.CollectionExpression) DyadicExpression(org.datanucleus.store.query.expression.DyadicExpression) ColumnExpression(org.datanucleus.store.rdbms.sql.expression.ColumnExpression) JoinExpression(org.datanucleus.store.query.expression.JoinExpression) InvokeExpression(org.datanucleus.store.query.expression.InvokeExpression) NucleusUserException(org.datanucleus.exceptions.NucleusUserException)

Example 12 with Expression

use of org.datanucleus.store.query.expression.Expression in project datanucleus-rdbms by datanucleus.

the class QueryToSQLMapper method processInvokeExpression.

/**
 * Internal method to handle the processing of an InvokeExpression.
 * @param expr The InvokeExpression
 * @param invokedSqlExpr The SQLExpression that we are invoking the method on.
 * @return The resultant SQLExpression
 */
protected SQLExpression processInvokeExpression(InvokeExpression expr, SQLExpression invokedSqlExpr) {
    if (invokedSqlExpr instanceof NullLiteral) {
        // We cannot invoke anything on a null TODO Handle this "NPE"
        NucleusLogger.QUERY.warn("Compilation of InvokeExpression needs to invoke method \"" + expr.getOperation() + "\" on " + invokedSqlExpr + " but not possible");
    }
    String operation = expr.getOperation();
    if (invokedSqlExpr instanceof MapExpression && operation.equals("contains") && compilation.getQueryLanguage().equalsIgnoreCase(Query.LANGUAGE_JPQL)) {
        // JPQL "MEMBER OF" will be passed through from generic compilation as "contains" since we don't know types at that point
        operation = "containsValue";
    }
    // Process the arguments for invoking
    List args = expr.getArguments();
    List sqlExprArgs = null;
    if (args != null) {
        sqlExprArgs = new ArrayList<SQLExpression>();
        Iterator<Expression> iter = args.iterator();
        while (iter.hasNext()) {
            Expression argExpr = iter.next();
            if (argExpr instanceof PrimaryExpression) {
                processPrimaryExpression((PrimaryExpression) argExpr);
                SQLExpression argSqlExpr = stack.pop();
                if (compileComponent == CompilationComponent.RESULT && operation.equalsIgnoreCase("count") && stmt.getNumberOfTableGroups() > 1) {
                    if (argSqlExpr.getSQLTable() == stmt.getPrimaryTable() && argSqlExpr.getJavaTypeMapping() == stmt.getPrimaryTable().getTable().getIdMapping()) {
                        // Result with "count(this)" and joins to other groups, so enforce distinct
                        argSqlExpr.distinct();
                    }
                }
                sqlExprArgs.add(argSqlExpr);
            } else if (argExpr instanceof ParameterExpression) {
                processParameterExpression((ParameterExpression) argExpr);
                sqlExprArgs.add(stack.pop());
            } else if (argExpr instanceof InvokeExpression) {
                processInvokeExpression((InvokeExpression) argExpr);
                sqlExprArgs.add(stack.pop());
            } else if (argExpr instanceof Literal) {
                processLiteral((Literal) argExpr);
                sqlExprArgs.add(stack.pop());
            } else if (argExpr instanceof DyadicExpression) {
                // Evaluate using this evaluator
                argExpr.evaluate(this);
                sqlExprArgs.add(stack.pop());
            } else if (argExpr instanceof VariableExpression) {
                processVariableExpression((VariableExpression) argExpr);
                sqlExprArgs.add(stack.pop());
            } else if (argExpr instanceof CaseExpression) {
                processCaseExpression((CaseExpression) argExpr);
                sqlExprArgs.add(stack.pop());
            } else {
                throw new NucleusException("Dont currently support invoke expression argument " + argExpr);
            }
        }
        if (operation.equals("INDEX")) {
            // Special case of index expression
            List<Expression> indexArgs = expr.getArguments();
            if (indexArgs == null || indexArgs.size() > 1) {
                throw new NucleusException("Can only use INDEX with single argument");
            }
            PrimaryExpression indexExpr = (PrimaryExpression) indexArgs.get(0);
            String joinAlias = indexExpr.getId();
            String collExprName = joinAlias;
            if (explicitJoinPrimaryByAlias != null) {
                collExprName = explicitJoinPrimaryByAlias.get(joinAlias);
                if (collExprName == null) {
                    throw new NucleusException("Unable to locate primary expression for alias " + joinAlias);
                }
            }
            // Find an expression for the collection field
            List<String> tuples = new ArrayList<>();
            StringTokenizer primTokenizer = new StringTokenizer(collExprName, ".");
            while (primTokenizer.hasMoreTokens()) {
                String token = primTokenizer.nextToken();
                tuples.add(token);
            }
            PrimaryExpression collPrimExpr = new PrimaryExpression(tuples);
            processPrimaryExpression(collPrimExpr);
            SQLExpression collSqlExpr = stack.pop();
            sqlExprArgs.add(collSqlExpr);
        }
    }
    // Invoke the method
    SQLExpression sqlExpr = null;
    if (invokedSqlExpr instanceof org.datanucleus.store.rdbms.sql.expression.SubqueryExpression) {
        if (operation.equalsIgnoreCase("isEmpty")) {
            // Special case of {subquery}.isEmpty(), equates to "NOT EXISTS (subquery)"
            org.datanucleus.store.rdbms.sql.expression.SubqueryExpression subquerySqlExpr = (org.datanucleus.store.rdbms.sql.expression.SubqueryExpression) invokedSqlExpr;
            SQLStatement subStmt = subquerySqlExpr.getSubqueryStatement();
            SQLExpression subqueryNotExistsExpr = new BooleanSubqueryExpression(stmt, "EXISTS", subStmt).not();
            stack.push(subqueryNotExistsExpr);
            return subqueryNotExistsExpr;
        } else if (operation.equalsIgnoreCase("size")) {
            // {subquery}.size() should simply be changed to have a subquery of "SELECT COUNT(*) FROM ..."
            throw new NucleusUserException("Attempt to invoke method `" + operation + "` on Subquery. This is not supported. Change the subquery to return COUNT() instead.");
        }
        throw new NucleusUserException("Attempt to invoke method `" + operation + "` on Subquery. This is not supported");
    }
    if (invokedSqlExpr != null) {
        sqlExpr = invokedSqlExpr.invoke(operation, sqlExprArgs);
    } else {
        sqlExpr = exprFactory.invokeMethod(stmt, null, operation, null, sqlExprArgs);
    }
    stack.push(sqlExpr);
    return sqlExpr;
}
Also used : SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) PrimaryExpression(org.datanucleus.store.query.expression.PrimaryExpression) ArrayList(java.util.ArrayList) SQLStatement(org.datanucleus.store.rdbms.sql.SQLStatement) CaseExpression(org.datanucleus.store.query.expression.CaseExpression) BooleanSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.BooleanSubqueryExpression) NumericSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.NumericSubqueryExpression) StringSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.StringSubqueryExpression) TemporalSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.TemporalSubqueryExpression) SubqueryExpression(org.datanucleus.store.query.expression.SubqueryExpression) TemporalLiteral(org.datanucleus.store.rdbms.sql.expression.TemporalLiteral) Literal(org.datanucleus.store.query.expression.Literal) SQLLiteral(org.datanucleus.store.rdbms.sql.expression.SQLLiteral) ParameterLiteral(org.datanucleus.store.rdbms.sql.expression.ParameterLiteral) CollectionLiteral(org.datanucleus.store.rdbms.sql.expression.CollectionLiteral) BooleanLiteral(org.datanucleus.store.rdbms.sql.expression.BooleanLiteral) IntegerLiteral(org.datanucleus.store.rdbms.sql.expression.IntegerLiteral) NullLiteral(org.datanucleus.store.rdbms.sql.expression.NullLiteral) ArrayList(java.util.ArrayList) List(java.util.List) MapExpression(org.datanucleus.store.rdbms.sql.expression.MapExpression) InvokeExpression(org.datanucleus.store.query.expression.InvokeExpression) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) VariableExpression(org.datanucleus.store.query.expression.VariableExpression) DyadicExpression(org.datanucleus.store.query.expression.DyadicExpression) StringTokenizer(java.util.StringTokenizer) PrimaryExpression(org.datanucleus.store.query.expression.PrimaryExpression) BooleanSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.BooleanSubqueryExpression) TypeConverterExpression(org.datanucleus.store.rdbms.sql.expression.TypeConverterExpression) StringExpression(org.datanucleus.store.rdbms.sql.expression.StringExpression) NumericSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.NumericSubqueryExpression) StringSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.StringSubqueryExpression) MapExpression(org.datanucleus.store.rdbms.sql.expression.MapExpression) ArrayExpression(org.datanucleus.store.query.expression.ArrayExpression) CaseExpression(org.datanucleus.store.query.expression.CaseExpression) CreatorExpression(org.datanucleus.store.query.expression.CreatorExpression) NewObjectExpression(org.datanucleus.store.rdbms.sql.expression.NewObjectExpression) OrderExpression(org.datanucleus.store.query.expression.OrderExpression) TemporalSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.TemporalSubqueryExpression) ClassExpression(org.datanucleus.store.query.expression.ClassExpression) BooleanExpression(org.datanucleus.store.rdbms.sql.expression.BooleanExpression) Expression(org.datanucleus.store.query.expression.Expression) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) ParameterExpression(org.datanucleus.store.query.expression.ParameterExpression) UnboundExpression(org.datanucleus.store.rdbms.sql.expression.UnboundExpression) TemporalExpression(org.datanucleus.store.rdbms.sql.expression.TemporalExpression) SubqueryExpression(org.datanucleus.store.query.expression.SubqueryExpression) ResultAliasExpression(org.datanucleus.store.rdbms.sql.expression.ResultAliasExpression) VariableExpression(org.datanucleus.store.query.expression.VariableExpression) TypeExpression(org.datanucleus.store.query.expression.TypeExpression) NumericExpression(org.datanucleus.store.rdbms.sql.expression.NumericExpression) CollectionExpression(org.datanucleus.store.rdbms.sql.expression.CollectionExpression) DyadicExpression(org.datanucleus.store.query.expression.DyadicExpression) ColumnExpression(org.datanucleus.store.rdbms.sql.expression.ColumnExpression) JoinExpression(org.datanucleus.store.query.expression.JoinExpression) InvokeExpression(org.datanucleus.store.query.expression.InvokeExpression) BooleanSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.BooleanSubqueryExpression) ParameterExpression(org.datanucleus.store.query.expression.ParameterExpression) NucleusException(org.datanucleus.exceptions.NucleusException) NullLiteral(org.datanucleus.store.rdbms.sql.expression.NullLiteral)

Example 13 with Expression

use of org.datanucleus.store.query.expression.Expression in project datanucleus-rdbms by datanucleus.

the class QueryToSQLMapper method processCreatorExpression.

/* (non-Javadoc)
     * @see org.datanucleus.query.evaluator.AbstractExpressionEvaluator#processCreatorExpression(org.datanucleus.query.expression.CreatorExpression)
     */
@Override
protected Object processCreatorExpression(CreatorExpression expr) {
    String className = expr.getId();
    Class cls = null;
    try {
        cls = clr.classForName(className);
    } catch (ClassNotResolvedException cnre) {
        if (importsDefinition != null) {
            cls = importsDefinition.resolveClassDeclaration(className, clr, null);
        }
    }
    List<SQLExpression> ctrArgExprs = null;
    List<String> ctrArgAliases = null;
    boolean hasAliases = false;
    List args = expr.getArguments();
    if (args != null) {
        Class[] ctrArgTypes = new Class[args.size()];
        boolean[] ctrArgTypeCheck = new boolean[args.size()];
        ctrArgExprs = new ArrayList<>(args.size());
        ctrArgAliases = new ArrayList<>(args.size());
        Iterator iter = args.iterator();
        int i = 0;
        while (iter.hasNext()) {
            Expression argExpr = (Expression) iter.next();
            String argAlias = argExpr.getAlias();
            if (argAlias != null) {
                hasAliases = true;
            }
            SQLExpression sqlExpr = (SQLExpression) evaluate(argExpr);
            // TODO Cater for "SQL_function" mapping on to ANY type of constructor argument at that position since we don't know the precise type
            if (argExpr instanceof InvokeExpression && ((InvokeExpression) argExpr).getOperation().equalsIgnoreCase("SQL_function")) {
                ctrArgTypeCheck[i] = false;
            } else {
                ctrArgTypeCheck[i] = true;
            }
            ctrArgExprs.add(sqlExpr);
            ctrArgAliases.add(argAlias != null ? argAlias : "####");
            if (sqlExpr instanceof NewObjectExpression) {
                ctrArgTypes[i] = ((NewObjectExpression) sqlExpr).getNewClass();
            } else if (sqlExpr.getJavaTypeMapping() instanceof DatastoreIdMapping || sqlExpr.getJavaTypeMapping() instanceof PersistableMapping) {
                ctrArgTypes[i] = clr.classForName(sqlExpr.getJavaTypeMapping().getType());
            } else {
                ctrArgTypes[i] = sqlExpr.getJavaTypeMapping().getJavaType();
            }
            i++;
        }
        // Check that this class has the required constructor
        Constructor ctr = ClassUtils.getConstructorWithArguments(cls, ctrArgTypes, ctrArgTypeCheck);
        if (ctr == null) {
            throw new NucleusUserException(Localiser.msg("021033", className, StringUtils.objectArrayToString(ctrArgTypes)));
        }
    }
    // TODO Retain the selected constructor (above)
    NewObjectExpression newExpr = new NewObjectExpression(stmt, cls, ctrArgExprs);
    if (hasAliases) {
        newExpr.setArgAliases(ctrArgAliases);
    }
    stack.push(newExpr);
    return newExpr;
}
Also used : InvokeExpression(org.datanucleus.store.query.expression.InvokeExpression) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) Constructor(java.lang.reflect.Constructor) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) ClassNotResolvedException(org.datanucleus.exceptions.ClassNotResolvedException) NewObjectExpression(org.datanucleus.store.rdbms.sql.expression.NewObjectExpression) PersistableMapping(org.datanucleus.store.rdbms.mapping.java.PersistableMapping) DatastoreIdMapping(org.datanucleus.store.rdbms.mapping.java.DatastoreIdMapping) PrimaryExpression(org.datanucleus.store.query.expression.PrimaryExpression) BooleanSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.BooleanSubqueryExpression) TypeConverterExpression(org.datanucleus.store.rdbms.sql.expression.TypeConverterExpression) StringExpression(org.datanucleus.store.rdbms.sql.expression.StringExpression) NumericSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.NumericSubqueryExpression) StringSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.StringSubqueryExpression) MapExpression(org.datanucleus.store.rdbms.sql.expression.MapExpression) ArrayExpression(org.datanucleus.store.query.expression.ArrayExpression) CaseExpression(org.datanucleus.store.query.expression.CaseExpression) CreatorExpression(org.datanucleus.store.query.expression.CreatorExpression) NewObjectExpression(org.datanucleus.store.rdbms.sql.expression.NewObjectExpression) OrderExpression(org.datanucleus.store.query.expression.OrderExpression) TemporalSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.TemporalSubqueryExpression) ClassExpression(org.datanucleus.store.query.expression.ClassExpression) BooleanExpression(org.datanucleus.store.rdbms.sql.expression.BooleanExpression) Expression(org.datanucleus.store.query.expression.Expression) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) ParameterExpression(org.datanucleus.store.query.expression.ParameterExpression) UnboundExpression(org.datanucleus.store.rdbms.sql.expression.UnboundExpression) TemporalExpression(org.datanucleus.store.rdbms.sql.expression.TemporalExpression) SubqueryExpression(org.datanucleus.store.query.expression.SubqueryExpression) ResultAliasExpression(org.datanucleus.store.rdbms.sql.expression.ResultAliasExpression) VariableExpression(org.datanucleus.store.query.expression.VariableExpression) TypeExpression(org.datanucleus.store.query.expression.TypeExpression) NumericExpression(org.datanucleus.store.rdbms.sql.expression.NumericExpression) CollectionExpression(org.datanucleus.store.rdbms.sql.expression.CollectionExpression) DyadicExpression(org.datanucleus.store.query.expression.DyadicExpression) ColumnExpression(org.datanucleus.store.rdbms.sql.expression.ColumnExpression) JoinExpression(org.datanucleus.store.query.expression.JoinExpression) InvokeExpression(org.datanucleus.store.query.expression.InvokeExpression) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) DatastoreClass(org.datanucleus.store.rdbms.table.DatastoreClass) FetchPlanForClass(org.datanucleus.FetchPlanForClass) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with Expression

use of org.datanucleus.store.query.expression.Expression in project datanucleus-rdbms by datanucleus.

the class JPQLQuery method compileQueryUpdate.

/**
 * Method to compile the query for RDBMS for a bulk update.
 * @param parameterValues The parameter values (if any)
 * @param candidateCmd Meta-data for the candidate class
 */
protected void compileQueryUpdate(Map parameterValues, AbstractClassMetaData candidateCmd) {
    Expression[] updateExprs = compilation.getExprUpdate();
    if (updateExprs == null || updateExprs.length == 0) {
        // Nothing to update
        return;
    }
    // Generate statement for candidate and related classes in this inheritance tree
    RDBMSStoreManager storeMgr = (RDBMSStoreManager) getStoreManager();
    DatastoreClass candidateTbl = storeMgr.getDatastoreClass(candidateCmd.getFullClassName(), clr);
    if (candidateTbl == null) {
        // TODO Using subclass-table, so find the table(s) it can be persisted into
        throw new NucleusDataStoreException("Bulk update of " + candidateCmd.getFullClassName() + " not supported since candidate has no table of its own");
    }
    // Find tables potentially affected by this UPDATE statement
    List<BulkTable> tables = new ArrayList<>();
    tables.add(new BulkTable(candidateTbl, true));
    if (candidateTbl.getSuperDatastoreClass() != null) {
        DatastoreClass tbl = candidateTbl;
        while (tbl.getSuperDatastoreClass() != null) {
            tbl = tbl.getSuperDatastoreClass();
            tables.add(new BulkTable(tbl, false));
        }
    }
    List<SQLStatement> stmts = new ArrayList<>();
    List<Boolean> stmtCountFlags = new ArrayList<>();
    for (BulkTable bulkTable : tables) {
        // Generate statement for candidate
        DatastoreClass table = bulkTable.table;
        Map<String, Object> extensions = null;
        if (!storeMgr.getDatastoreAdapter().supportsOption(DatastoreAdapter.UPDATE_DELETE_STATEMENT_ALLOW_TABLE_ALIAS_IN_WHERE_CLAUSE)) {
            extensions = new HashMap<>();
            extensions.put(SQLStatement.EXTENSION_SQL_TABLE_NAMING_STRATEGY, "table-name");
        }
        UpdateStatement stmt = new UpdateStatement(storeMgr, table, null, null, extensions);
        stmt.setClassLoaderResolver(clr);
        stmt.setCandidateClassName(candidateCmd.getFullClassName());
        JavaTypeMapping multitenancyMapping = table.getSurrogateMapping(SurrogateColumnType.MULTITENANCY, false);
        if (multitenancyMapping != null) {
            // Multi-tenancy restriction
            SQLExpression tenantExpr = stmt.getSQLExpressionFactory().newExpression(stmt, stmt.getPrimaryTable(), multitenancyMapping);
            SQLExpression tenantVal = stmt.getSQLExpressionFactory().newLiteral(stmt, multitenancyMapping, ec.getTenantId());
            stmt.whereAnd(tenantExpr.eq(tenantVal), true);
        }
        // TODO Discriminator restriction?
        JavaTypeMapping softDeleteMapping = table.getSurrogateMapping(SurrogateColumnType.SOFTDELETE, false);
        if (softDeleteMapping != null) {
            // Soft-delete restriction
            SQLExpression softDeleteExpr = stmt.getSQLExpressionFactory().newExpression(stmt, stmt.getPrimaryTable(), softDeleteMapping);
            SQLExpression softDeleteVal = stmt.getSQLExpressionFactory().newLiteral(stmt, softDeleteMapping, Boolean.FALSE);
            stmt.whereAnd(softDeleteExpr.eq(softDeleteVal), true);
        }
        Set<String> options = new HashSet<>();
        options.add(QueryToSQLMapper.OPTION_CASE_INSENSITIVE);
        options.add(QueryToSQLMapper.OPTION_EXPLICIT_JOINS);
        if (// Default to false for "IS NULL" with null param
        getBooleanExtensionProperty(EXTENSION_USE_IS_NULL_WHEN_EQUALS_NULL_PARAM, false)) {
            options.add(QueryToSQLMapper.OPTION_NULL_PARAM_USE_IS_NULL);
        }
        QueryToSQLMapper sqlMapper = new QueryToSQLMapper(stmt, compilation, parameterValues, null, null, candidateCmd, subclasses, getFetchPlan(), ec, null, options, extensions);
        setMapperJoinTypes(sqlMapper);
        sqlMapper.compile();
        if (stmt.hasUpdates()) {
            stmts.add(stmt);
            stmtCountFlags.add(bulkTable.useInCount);
            datastoreCompilation.setStatementParameters(stmt.getSQLText().getParametersForStatement());
            datastoreCompilation.setPrecompilable(sqlMapper.isPrecompilable());
        }
    }
    datastoreCompilation.clearStatements();
    Iterator<SQLStatement> stmtIter = stmts.iterator();
    Iterator<Boolean> stmtCountFlagsIter = stmtCountFlags.iterator();
    while (stmtIter.hasNext()) {
        SQLStatement stmt = stmtIter.next();
        Boolean useInCount = stmtCountFlagsIter.next();
        if (stmts.size() == 1) {
            useInCount = true;
        }
        datastoreCompilation.addStatement(stmt, stmt.getSQLText().toSQL(), useInCount);
    }
}
Also used : UpdateStatement(org.datanucleus.store.rdbms.sql.UpdateStatement) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) ArrayList(java.util.ArrayList) SQLStatement(org.datanucleus.store.rdbms.sql.SQLStatement) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager) NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) ColumnExpression(org.datanucleus.store.rdbms.sql.expression.ColumnExpression) Expression(org.datanucleus.store.query.expression.Expression) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) DatastoreClass(org.datanucleus.store.rdbms.table.DatastoreClass) HashSet(java.util.HashSet)

Aggregations

Expression (org.datanucleus.store.query.expression.Expression)14 SQLExpression (org.datanucleus.store.rdbms.sql.expression.SQLExpression)14 BooleanExpression (org.datanucleus.store.rdbms.sql.expression.BooleanExpression)13 ColumnExpression (org.datanucleus.store.rdbms.sql.expression.ColumnExpression)13 ArrayExpression (org.datanucleus.store.query.expression.ArrayExpression)12 CaseExpression (org.datanucleus.store.query.expression.CaseExpression)12 ClassExpression (org.datanucleus.store.query.expression.ClassExpression)12 CreatorExpression (org.datanucleus.store.query.expression.CreatorExpression)12 DyadicExpression (org.datanucleus.store.query.expression.DyadicExpression)12 InvokeExpression (org.datanucleus.store.query.expression.InvokeExpression)12 JoinExpression (org.datanucleus.store.query.expression.JoinExpression)12 OrderExpression (org.datanucleus.store.query.expression.OrderExpression)12 ParameterExpression (org.datanucleus.store.query.expression.ParameterExpression)12 PrimaryExpression (org.datanucleus.store.query.expression.PrimaryExpression)12 SubqueryExpression (org.datanucleus.store.query.expression.SubqueryExpression)12 TypeExpression (org.datanucleus.store.query.expression.TypeExpression)12 VariableExpression (org.datanucleus.store.query.expression.VariableExpression)12 BooleanSubqueryExpression (org.datanucleus.store.rdbms.sql.expression.BooleanSubqueryExpression)12 CollectionExpression (org.datanucleus.store.rdbms.sql.expression.CollectionExpression)12 MapExpression (org.datanucleus.store.rdbms.sql.expression.MapExpression)12