use of org.eclipse.persistence.internal.expressions.SQLSelectStatement in project eclipselink by eclipse-ee4j.
the class ExpressionQueryMechanism method buildBaseSelectStatement.
/**
* Return the appropriate select statement containing the fields in the table.
* Ability to switch off AdditionalJoinExpression is required for DeleteAllQuery.
*/
public SQLSelectStatement buildBaseSelectStatement(boolean isSubSelect, Map clonedExpressions, boolean shouldUseAdditionalJoinExpression) {
SQLSelectStatement selectStatement = new SQLSelectStatement();
ObjectLevelReadQuery query = (ObjectLevelReadQuery) getQuery();
selectStatement.setQuery(query);
selectStatement.setLockingClause(query.getLockingClause());
selectStatement.setDistinctState(query.getDistinctState());
selectStatement.setTables((Vector) getDescriptor().getTables().clone());
selectStatement.setWhereClause(buildBaseSelectionCriteria(isSubSelect, clonedExpressions, shouldUseAdditionalJoinExpression));
// instead of the 'left' we will build the SQL using the wrong builder.
if (query.hasDefaultBuilder() && !query.getExpressionBuilder().wasQueryClassSetInternally()) {
selectStatement.setBuilder((ExpressionBuilder) query.getExpressionBuilder().copiedVersionFrom(clonedExpressions));
}
// of table alias always be correct
if (query.hasOrderByExpressions()) {
selectStatement.setOrderByExpressions(cloneExpressions(query.getOrderByExpressions(), clonedExpressions));
}
if (query.hasNonFetchJoinedAttributeExpressions()) {
selectStatement.setNonSelectFields(cloneExpressions(query.getNonFetchJoinAttributeExpressions(), clonedExpressions));
}
if (query.hasUnionExpressions()) {
selectStatement.setUnionExpressions(cloneExpressions(query.getUnionExpressions(), clonedExpressions));
}
if (getQuery().isReadAllQuery() && ((ReadAllQuery) getQuery()).hasHierarchicalExpressions()) {
ReadAllQuery readAllquery = (ReadAllQuery) query;
Expression startsWith = readAllquery.getStartWithExpression();
if (startsWith != null) {
startsWith.copiedVersionFrom(clonedExpressions);
}
selectStatement.setHierarchicalQueryExpressions(startsWith, readAllquery.getConnectByExpression().copiedVersionFrom(clonedExpressions), cloneExpressions(readAllquery.getOrderSiblingsByExpressions(), clonedExpressions), readAllquery.getDirection());
}
selectStatement.setHintString(query.getHintString());
selectStatement.setTranslationRow(getTranslationRow());
return selectStatement;
}
use of org.eclipse.persistence.internal.expressions.SQLSelectStatement in project eclipselink by eclipse-ee4j.
the class ExpressionQueryMechanism method buildUpdateAllStatement.
protected SQLUpdateAllStatement buildUpdateAllStatement(DatabaseTable table, HashMap databaseFieldsToValues, SQLCall selectCallForExist, SQLSelectStatement selectStatementForExist, Collection primaryKeyFields) {
SQLUpdateAllStatement updateAllStatement = new SQLUpdateAllStatement();
updateAllStatement.setTable(table);
updateAllStatement.setTranslationRow(getTranslationRow());
HashMap databaseFieldsToValuesCopy = new HashMap(databaseFieldsToValues.size());
HashMap databaseFieldsToTableAliases = null;
Iterator it = databaseFieldsToValues.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
// for each table to be updated
DatabaseField field = (DatabaseField) entry.getKey();
// here's a Map of left hand fields to right hand expressions
Object value = entry.getValue();
if (value instanceof SQLSelectStatement) {
SQLSelectStatement selStatement = (SQLSelectStatement) value;
SQLCall selCall = (SQLCall) selStatement.buildCall(getSession());
databaseFieldsToValuesCopy.put(field, selCall);
if (databaseFieldsToTableAliases == null) {
databaseFieldsToTableAliases = new HashMap();
updateAllStatement.setPrimaryKeyFieldsForAutoJoin(primaryKeyFields);
}
databaseFieldsToTableAliases.put(field, getAliasTableName(selStatement, table, getExecutionSession().getPlatform()));
} else {
// should be Expression
databaseFieldsToValuesCopy.put(field, value);
}
}
updateAllStatement.setUpdateClauses(databaseFieldsToValuesCopy);
updateAllStatement.setDatabaseFieldsToTableAliases(databaseFieldsToTableAliases);
updateAllStatement.setSelectCallForExist(selectCallForExist);
updateAllStatement.setShouldExtractWhereClauseFromSelectCallForExist(!selectStatementForExist.requiresAliases() && table.equals(selectStatementForExist.getTables().get(0)));
updateAllStatement.setTableAliasInSelectCallForExist(getAliasTableName(selectStatementForExist, table, getExecutionSession().getPlatform()));
updateAllStatement.setPrimaryKeyFieldsForAutoJoin(primaryKeyFields);
return updateAllStatement;
}
use of org.eclipse.persistence.internal.expressions.SQLSelectStatement in project eclipselink by eclipse-ee4j.
the class ExpressionQueryMechanism method createSQLSelectStatementForModifyAll.
/**
* Customary inheritance expression is required for DeleteAllQuery and UpdateAllQuery preparation.
* Ability to switch off AdditionalJoinExpression is required for DeleteAllQuery.
*/
protected SQLSelectStatement createSQLSelectStatementForModifyAll(Expression whereClause, Expression inheritanceExpression, ClassDescriptor desc, boolean useCustomaryInheritanceExpression, boolean shouldUseAdditionalJoinExpression) {
ExpressionBuilder builder;
if (whereClause != null) {
whereClause = (Expression) whereClause.clone();
builder = whereClause.getBuilder();
} else {
builder = new ExpressionBuilder();
}
ReportQuery reportQuery = new ReportQuery(desc.getJavaClass(), builder);
reportQuery.setDescriptor(desc);
reportQuery.setShouldRetrieveFirstPrimaryKey(true);
reportQuery.setSelectionCriteria(whereClause);
reportQuery.setSession(getSession());
SQLSelectStatement selectStatement = ((ExpressionQueryMechanism) reportQuery.getQueryMechanism()).buildReportQuerySelectStatement(false, useCustomaryInheritanceExpression, inheritanceExpression, shouldUseAdditionalJoinExpression);
reportQuery.setSession(null);
return selectStatement;
}
use of org.eclipse.persistence.internal.expressions.SQLSelectStatement in project eclipselink by eclipse-ee4j.
the class ExpressionQueryMechanism method buildUpdateAllStatementForOracleAnonymousBlock.
protected SQLModifyStatement buildUpdateAllStatementForOracleAnonymousBlock(HashMap tables_databaseFieldsToValues, HashMap tablesToPrimaryKeyFields) {
SQLSelectStatement selectStatement = createSQLSelectStatementForUpdateAllForOracleAnonymousBlock(tables_databaseFieldsToValues);
SQLCall selectCall = (SQLCall) selectStatement.buildCall(getSession());
SQLUpdateAllStatementForOracleAnonymousBlock updateAllStatement = new SQLUpdateAllStatementForOracleAnonymousBlock();
updateAllStatement.setTranslationRow(getTranslationRow());
updateAllStatement.setSelectCall(selectCall);
updateAllStatement.setTables_databaseFieldsToValues(tables_databaseFieldsToValues);
updateAllStatement.setTablesToPrimaryKeyFields(tablesToPrimaryKeyFields);
updateAllStatement.setTable(getDescriptor().getTables().firstElement());
return updateAllStatement;
}
use of org.eclipse.persistence.internal.expressions.SQLSelectStatement in project eclipselink by eclipse-ee4j.
the class ExpressionQueryMechanism method buildSelectStatementForDoesExist.
/**
* Return the appropriate select statement to perform a does exist check
* @param field fields for does exist check.
*/
protected SQLSelectStatement buildSelectStatementForDoesExist(DatabaseField field) {
// Build appropriate select statement
SQLSelectStatement selectStatement;
selectStatement = new SQLSelectStatement();
selectStatement.addField(field);
selectStatement.setWhereClause(((Expression) getDescriptor().getObjectBuilder().getPrimaryKeyExpression().clone()).and(getDescriptor().getQueryManager().getAdditionalJoinExpression()));
selectStatement.setTranslationRow(getTranslationRow());
selectStatement.normalize(getSession(), getQuery().getDescriptor());
selectStatement.setHintString(getQuery().getHintString());
return selectStatement;
}
Aggregations