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;
}
}
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();
}
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;
}
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);
}
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);
}
Aggregations