Search in sources :

Example 11 with UpdateAllQuery

use of org.eclipse.persistence.queries.UpdateAllQuery in project eclipselink by eclipse-ee4j.

the class DatasourceCallQueryMechanism method updateAll.

/**
 * Update the rows on the database.  Assume the call is correct.
 * @exception  DatabaseException - an error has occurred on the database.
 */
@Override
public Integer updateAll() throws DatabaseException {
    if (((UpdateAllQuery) this.query).isPreparedUsingTempStorage() && getExecutionSession().getPlatform().supportsTempTables()) {
        return updateAllUsingTempTables();
    } else {
        Integer rowCount = executeNoSelectCall();
        if (((UpdateAllQuery) this.query).isPreparedUsingTempStorage()) {
            // the query was prepared using Oracle anonymous block
            AbstractRecord outputRow = (AbstractRecord) this.query.getProperty("output");
            rowCount = (Integer) outputRow.get("ROW_COUNT");
        }
        return rowCount;
    }
}
Also used : AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord) UpdateAllQuery(org.eclipse.persistence.queries.UpdateAllQuery)

Example 12 with UpdateAllQuery

use of org.eclipse.persistence.queries.UpdateAllQuery in project eclipselink by eclipse-ee4j.

the class ExpressionQueryMechanism method prepareUpdateAllUsingTempTables.

/**
 * Pre-build the SQL statement from the expressions.
 */
protected void prepareUpdateAllUsingTempTables(HashMap tables_databaseFieldsToValues, HashMap<DatabaseTable, List<DatabaseField>> tablesToPrimaryKeyFields) {
    int nTables = tables_databaseFieldsToValues.size();
    Vector createTableStatements = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(nTables);
    Vector selectStatements = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(nTables);
    Vector updateStatements = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(nTables);
    Vector cleanupStatements = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(nTables);
    Iterator itEntrySets = tables_databaseFieldsToValues.entrySet().iterator();
    while (itEntrySets.hasNext()) {
        Map.Entry entry = (Map.Entry) itEntrySets.next();
        DatabaseTable table = (DatabaseTable) entry.getKey();
        HashMap databaseFieldsToValues = (HashMap) entry.getValue();
        List<DatabaseField> primaryKeyFields = tablesToPrimaryKeyFields.get(table);
        Vector statementsForTable = buildStatementsForUpdateAllForTempTables(table, databaseFieldsToValues, primaryKeyFields);
        createTableStatements.add(statementsForTable.elementAt(0));
        selectStatements.add(statementsForTable.elementAt(1));
        updateStatements.add(statementsForTable.elementAt(2));
        cleanupStatements.add(statementsForTable.elementAt(3));
    }
    getSQLStatements().addAll(createTableStatements);
    getSQLStatements().addAll(selectStatements);
    getSQLStatements().addAll(updateStatements);
    getSQLStatements().addAll(cleanupStatements);
    if (getExecutionSession().getPlatform().dontBindUpdateAllQueryUsingTempTables()) {
        if (getQuery().shouldBindAllParameters() || (getQuery().shouldIgnoreBindAllParameters() && getExecutionSession().getPlatform().shouldBindAllParameters())) {
            getQuery().setShouldBindAllParameters(false);
            getSession().warning("update_all_query_cannot_use_binding_on_this_platform", SessionLog.QUERY);
        }
    }
    ((UpdateAllQuery) getQuery()).setIsPreparedUsingTempStorage(true);
    super.prepareUpdateAll();
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) Iterator(java.util.Iterator) ExpressionIterator(org.eclipse.persistence.internal.expressions.ExpressionIterator) DatabaseTable(org.eclipse.persistence.internal.helper.DatabaseTable) Vector(java.util.Vector) NonSynchronizedVector(org.eclipse.persistence.internal.helper.NonSynchronizedVector) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) UpdateAllQuery(org.eclipse.persistence.queries.UpdateAllQuery)

Example 13 with UpdateAllQuery

use of org.eclipse.persistence.queries.UpdateAllQuery in project eclipselink by eclipse-ee4j.

the class ExpressionQueryMechanism method createSQLSelectStatementForUpdateAllForOracleAnonymousBlock.

protected SQLSelectStatement createSQLSelectStatementForUpdateAllForOracleAnonymousBlock(HashMap tables_databaseFieldsToValues) {
    ExpressionBuilder builder = ((UpdateAllQuery) getQuery()).getExpressionBuilder();
    Expression whereClause = getSelectionCriteria();
    ReportQuery reportQuery = new ReportQuery(getDescriptor().getJavaClass(), builder);
    reportQuery.setDescriptor(getDescriptor());
    reportQuery.setSelectionCriteria(whereClause);
    reportQuery.setSession(getSession());
    reportQuery.setShouldRetrievePrimaryKeys(true);
    Iterator itDatabaseFieldsToValues = tables_databaseFieldsToValues.values().iterator();
    while (itDatabaseFieldsToValues.hasNext()) {
        HashMap databaseFieldsToValues = (HashMap) itDatabaseFieldsToValues.next();
        Iterator itValues = databaseFieldsToValues.values().iterator();
        while (itValues.hasNext()) {
            reportQuery.addAttribute("", (Expression) itValues.next());
        }
    }
    SQLSelectStatement selectStatement = ((ExpressionQueryMechanism) reportQuery.getQueryMechanism()).buildReportQuerySelectStatement(false);
    reportQuery.setSession(null);
    return selectStatement;
}
Also used : FieldExpression(org.eclipse.persistence.internal.expressions.FieldExpression) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) QueryKeyExpression(org.eclipse.persistence.internal.expressions.QueryKeyExpression) ParameterExpression(org.eclipse.persistence.internal.expressions.ParameterExpression) ObjectExpression(org.eclipse.persistence.internal.expressions.ObjectExpression) DataExpression(org.eclipse.persistence.internal.expressions.DataExpression) Expression(org.eclipse.persistence.expressions.Expression) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) ReportQuery(org.eclipse.persistence.queries.ReportQuery) Iterator(java.util.Iterator) ExpressionIterator(org.eclipse.persistence.internal.expressions.ExpressionIterator) SQLSelectStatement(org.eclipse.persistence.internal.expressions.SQLSelectStatement) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) UpdateAllQuery(org.eclipse.persistence.queries.UpdateAllQuery)

Example 14 with UpdateAllQuery

use of org.eclipse.persistence.queries.UpdateAllQuery in project eclipselink by eclipse-ee4j.

the class UpdateAllQueryAdvancedJunitTest method testFirstNamePrefixBLAForSalary.

public static void testFirstNamePrefixBLAForSalary() {
    ExpressionBuilder builder = new ExpressionBuilder();
    Expression selectionExpression = builder.get("salary").lessThan(20000);
    UpdateAllQuery updateQuery = new UpdateAllQuery(Employee.class, selectionExpression);
    updateQuery.addUpdate("firstName", Expression.fromLiteral("'BLA'", null).concat(builder.get("firstName")));
    updateAllQueryInternal(updateQuery);
}
Also used : Expression(org.eclipse.persistence.expressions.Expression) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) UpdateAllQuery(org.eclipse.persistence.queries.UpdateAllQuery)

Example 15 with UpdateAllQuery

use of org.eclipse.persistence.queries.UpdateAllQuery in project eclipselink by eclipse-ee4j.

the class UpdateAllQueryAdvancedJunitTest method testAssignManagerName.

public static void testAssignManagerName() {
    ExpressionBuilder builder = new ExpressionBuilder();
    Expression selectionExpression = builder.get("manager").notNull();
    UpdateAllQuery updateQuery = new UpdateAllQuery(Employee.class, selectionExpression);
    updateQuery.addUpdate("firstName", builder.get("manager").get("firstName"));
    updateAllQueryInternal(updateQuery);
}
Also used : Expression(org.eclipse.persistence.expressions.Expression) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) UpdateAllQuery(org.eclipse.persistence.queries.UpdateAllQuery)

Aggregations

UpdateAllQuery (org.eclipse.persistence.queries.UpdateAllQuery)57 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)36 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)22 Expression (org.eclipse.persistence.expressions.Expression)19 EntityManager (jakarta.persistence.EntityManager)13 DeleteAllQuery (org.eclipse.persistence.queries.DeleteAllQuery)12 ReportQuery (org.eclipse.persistence.queries.ReportQuery)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Vector (java.util.Vector)9 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)8 Iterator (java.util.Iterator)7 HashMap (java.util.HashMap)5 Map (java.util.Map)4 IdentityHashMap (java.util.IdentityHashMap)3 DataExpression (org.eclipse.persistence.internal.expressions.DataExpression)3 ExpressionIterator (org.eclipse.persistence.internal.expressions.ExpressionIterator)3 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)3 ConstantExpression (org.eclipse.persistence.internal.expressions.ConstantExpression)2 FieldExpression (org.eclipse.persistence.internal.expressions.FieldExpression)2