use of org.eclipse.persistence.internal.expressions.SQLSelectStatement in project eclipselink by eclipse-ee4j.
the class ExpressionQueryMechanism method prepareCursorSelectAllRows.
/**
* Pre-build the SQL statement from the expression.
*/
@Override
public void prepareCursorSelectAllRows() {
if (getQuery().isReportQuery()) {
SQLSelectStatement statement = buildReportQuerySelectStatement(false);
setSQLStatement(statement);
// For bug 2718118 inheritance with cursors is supported provided there is a read all subclasses view.
} else if (getDescriptor().hasInheritance() && getDescriptor().getInheritancePolicy().requiresMultipleTableSubclassRead() && getDescriptor().getInheritancePolicy().hasView()) {
InheritancePolicy inheritancePolicy = getDescriptor().getInheritancePolicy();
SQLSelectStatement statement = inheritancePolicy.buildViewSelectStatement((ObjectLevelReadQuery) getQuery());
setSQLStatement(statement);
} else {
setSQLStatement(buildNormalSelectStatement());
}
super.prepareCursorSelectAllRows();
}
use of org.eclipse.persistence.internal.expressions.SQLSelectStatement in project eclipselink by eclipse-ee4j.
the class ExpressionQueryMechanism method buildStatementsForUpdateAllForTempTables.
protected Vector buildStatementsForUpdateAllForTempTables(DatabaseTable table, HashMap databaseFieldsToValues, List<DatabaseField> primaryKeyFields) {
Vector statements = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(4);
Vector allFields = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance();
Iterator<DatabaseField> it = getDescriptor().getFields().iterator();
while (it.hasNext()) {
DatabaseField field = it.next();
if (table.equals(field.getTable())) {
allFields.add(field);
}
}
Collection assignedFields = databaseFieldsToValues.keySet();
HashMap databaseFieldsToValuesForInsert = databaseFieldsToValues;
Collection assignedFieldsForInsert = assignedFields;
// can do that because all fields initialized to null when temp. table created.
if (!getExecutionSession().getPlatform().isNullAllowedInSelectClause()) {
databaseFieldsToValuesForInsert = new HashMap(databaseFieldsToValues.size());
Iterator itEntries = databaseFieldsToValues.entrySet().iterator();
while (itEntries.hasNext()) {
Map.Entry entry = (Map.Entry) itEntries.next();
if (entry.getValue() instanceof ConstantExpression) {
ConstantExpression constExp = (ConstantExpression) entry.getValue();
if (constExp.getValue() == null) {
continue;
}
}
databaseFieldsToValuesForInsert.put(entry.getKey(), entry.getValue());
}
assignedFieldsForInsert = databaseFieldsToValuesForInsert.keySet();
}
SQLUpdateAllStatementForTempTable createTempTableStatement = new SQLUpdateAllStatementForTempTable();
createTempTableStatement.setMode(SQLModifyAllStatementForTempTable.CREATE_TEMP_TABLE);
createTempTableStatement.setTable(table);
createTempTableStatement.setAllFields(allFields);
createTempTableStatement.setAssignedFields(assignedFields);
createTempTableStatement.setPrimaryKeyFields(primaryKeyFields);
statements.addElement(createTempTableStatement);
SQLSelectStatement selectStatement = createSQLSelectStatementForModifyAllForTempTable(databaseFieldsToValuesForInsert);
SQLCall selectCall = (SQLCall) selectStatement.buildCall(getSession(), getQuery());
SQLUpdateAllStatementForTempTable insertStatement = new SQLUpdateAllStatementForTempTable();
insertStatement.setMode(SQLModifyAllStatementForTempTable.INSERT_INTO_TEMP_TABLE);
insertStatement.setTable(table);
insertStatement.setTranslationRow(getTranslationRow());
insertStatement.setSelectCall(selectCall);
insertStatement.setAssignedFields(assignedFieldsForInsert);
insertStatement.setPrimaryKeyFields(primaryKeyFields);
statements.addElement(insertStatement);
SQLUpdateAllStatementForTempTable updateStatement = new SQLUpdateAllStatementForTempTable();
updateStatement.setMode(SQLModifyAllStatementForTempTable.UPDATE_ORIGINAL_TABLE);
updateStatement.setTable(table);
updateStatement.setTranslationRow(getTranslationRow());
updateStatement.setAssignedFields(assignedFields);
updateStatement.setPrimaryKeyFields(primaryKeyFields);
statements.addElement(updateStatement);
SQLUpdateAllStatementForTempTable cleanupStatement = new SQLUpdateAllStatementForTempTable();
cleanupStatement.setMode(SQLModifyAllStatementForTempTable.CLEANUP_TEMP_TABLE);
cleanupStatement.setTable(table);
statements.addElement(cleanupStatement);
return statements;
}
use of org.eclipse.persistence.internal.expressions.SQLSelectStatement in project eclipselink by eclipse-ee4j.
the class ExpressionQueryMechanism method createSQLSelectStatementForModifyAllForTempTable.
protected SQLSelectStatement createSQLSelectStatementForModifyAllForTempTable(HashMap databaseFieldsToValues) {
ExpressionBuilder builder = ((ModifyAllQuery) getQuery()).getExpressionBuilder();
Expression whereClause = getSelectionCriteria();
ReportQuery reportQuery = new ReportQuery(getDescriptor().getJavaClass(), builder);
reportQuery.setDescriptor(getDescriptor());
reportQuery.setSelectionCriteria(whereClause);
reportQuery.setSession(getSession());
reportQuery.setShouldRetrievePrimaryKeys(true);
if (databaseFieldsToValues != null) {
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.internal.expressions.SQLSelectStatement in project eclipselink by eclipse-ee4j.
the class ContainerPolicy method buildSelectionQueryForDirectCollectionMapping.
/**
* INTERNAL:
* This
* Certain key mappings favor different types of selection query. Return the appropriate
* type of selectionQuery
*/
public ReadQuery buildSelectionQueryForDirectCollectionMapping() {
DirectReadQuery query = new DirectReadQuery();
query.setSQLStatement(new SQLSelectStatement());
query.setContainerPolicy(this);
return query;
}
use of org.eclipse.persistence.internal.expressions.SQLSelectStatement in project eclipselink by eclipse-ee4j.
the class ExpressionQueryMechanism method buildStatementsForDeleteAllForTempTables.
/**
* Build SQLStatements for delete all using temporary table.
* @return {@code Vector<SQLStatement>}
*/
protected Vector buildStatementsForDeleteAllForTempTables() {
Vector statements = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance();
// retrieve rootTable and its primary key fields for composing temporary table
DatabaseTable rootTable = getDescriptor().getMultipleTableInsertOrder().get(0);
List<DatabaseField> rootTablePrimaryKeyFields = getPrimaryKeyFieldsForTable(rootTable);
ClassDescriptor rootDescriptor = getDescriptor();
if (getDescriptor().hasInheritance()) {
rootDescriptor = rootDescriptor.getInheritancePolicy().getRootParentDescriptor();
}
Vector allFields = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance();
Iterator<DatabaseField> it = rootDescriptor.getFields().iterator();
while (it.hasNext()) {
DatabaseField field = it.next();
if (rootTable.equals(field.getTable())) {
allFields.add(field);
}
}
// statements will be executed in reverse order
// statement for temporary table cleanup (Drop table or Delete from temp_table)
SQLDeleteAllStatementForTempTable cleanupStatement = new SQLDeleteAllStatementForTempTable();
cleanupStatement.setMode(SQLModifyAllStatementForTempTable.CLEANUP_TEMP_TABLE);
cleanupStatement.setTable(rootTable);
statements.addElement(cleanupStatement);
// delete statements using temporary table
Vector deleteStatements = buildDeleteAllStatementsForTempTable(getDescriptor(), rootTable, rootTablePrimaryKeyFields, null);
statements.addAll(deleteStatements);
// Insert statement populating temporary table with criteria
SQLSelectStatement selectStatement = createSQLSelectStatementForModifyAllForTempTable(null);
SQLCall selectCall = (SQLCall) selectStatement.buildCall(getSession());
SQLDeleteAllStatementForTempTable insertStatement = new SQLDeleteAllStatementForTempTable();
insertStatement.setMode(SQLModifyAllStatementForTempTable.INSERT_INTO_TEMP_TABLE);
insertStatement.setTable(rootTable);
insertStatement.setTranslationRow(getTranslationRow());
insertStatement.setSelectCall(selectCall);
insertStatement.setPrimaryKeyFields(rootTablePrimaryKeyFields);
statements.addElement(insertStatement);
// Create temporary table statement
SQLDeleteAllStatementForTempTable createTempTableStatement = new SQLDeleteAllStatementForTempTable();
createTempTableStatement.setMode(SQLModifyAllStatementForTempTable.CREATE_TEMP_TABLE);
createTempTableStatement.setTable(rootTable);
createTempTableStatement.setAllFields(allFields);
createTempTableStatement.setPrimaryKeyFields(rootTablePrimaryKeyFields);
statements.addElement(createTempTableStatement);
return statements;
}
Aggregations