use of org.eclipse.persistence.internal.expressions.SQLSelectStatement in project eclipselink by eclipse-ee4j.
the class AbstractDirectMapping method buildSelectionQueryForDirectCollectionKeyMapping.
/**
* INTERNAL:
* Certain key mappings favor different types of selection query. Return the appropriate
* type of selectionQuery.
*/
@Override
public ReadQuery buildSelectionQueryForDirectCollectionKeyMapping(ContainerPolicy containerPolicy) {
DataReadQuery query = new DataReadQuery();
query.setSQLStatement(new SQLSelectStatement());
query.setContainerPolicy(containerPolicy);
return query;
}
use of org.eclipse.persistence.internal.expressions.SQLSelectStatement in project eclipselink by eclipse-ee4j.
the class ObjectRelationalDataTypeDescriptor method getRef.
/**
* INTERNAL:
* Get the ref for the object.
* This is required for use by Refs, there might be a better way to do it when objID are supported.
* (i.e. getting it from the object or identity map).
*/
public Ref getRef(Object object, AbstractSession session) {
SQLSelectStatement statement = new SQLSelectStatement();
// Assumed only one for obj-rel descriptors.
statement.addTable(getTables().firstElement());
statement.getFields().addElement(new org.eclipse.persistence.expressions.ExpressionBuilder().ref());
statement.setWhereClause(getObjectBuilder().buildPrimaryKeyExpressionFromObject(object, session));
statement.setRequiresAliases(true);
statement.normalize(session, this);
ValueReadQuery valueQuery = new ValueReadQuery();
valueQuery.setSQLStatement(statement);
valueQuery.checkPrepare(session, new DatabaseRecord(), true);
// Must return unwrapped Ref on WLS.
valueQuery.getCall().setIsNativeConnectionRequired(true);
Ref ref = (Ref) session.executeQuery(valueQuery);
return ref;
}
use of org.eclipse.persistence.internal.expressions.SQLSelectStatement in project eclipselink by eclipse-ee4j.
the class InheritancePolicy method buildViewSelectStatement.
/**
* INTERNAL:
* Build a select statement for all subclasses on the view using the same
* selection criteria as the query.
*/
public SQLSelectStatement buildViewSelectStatement(ObjectLevelReadQuery query) {
// 2612538 - the default size of Map (32) is appropriate
Map clonedExpressions = new IdentityHashMap();
ExpressionQueryMechanism mechanism = (ExpressionQueryMechanism) query.getQueryMechanism();
// CR#3166555 - Have the mechanism build the statement to avoid duplicating code and ensure that lock-mode, hints, hierarchical, etc. are set.
SQLSelectStatement selectStatement = mechanism.buildBaseSelectStatement(false, clonedExpressions);
selectStatement.setTables(new ArrayList<>(1));
selectStatement.addTable(getReadAllSubclassesView());
// Case, normal read for branch inheritance class that reads subclasses all in its own table(s).
if (getWithAllSubclassesExpression() != null) {
Expression branchIndicator = (Expression) getWithAllSubclassesExpression().clone();
if (branchIndicator != null) {
selectStatement.setWhereClause(branchIndicator.and(selectStatement.getWhereClause()));
}
}
selectStatement.setFields(mechanism.getSelectionFields(selectStatement, true));
selectStatement.normalizeForView(query.getSession(), getDescriptor(), clonedExpressions);
// Allow for joining indexes to be computed to ensure distinct rows
if (query.hasJoining()) {
query.getJoinedAttributeManager().computeJoiningMappingIndexes(false, query.getSession(), 0);
}
return selectStatement;
}
use of org.eclipse.persistence.internal.expressions.SQLSelectStatement in project eclipselink by eclipse-ee4j.
the class InheritancePolicy method buildClassIndicatorSelectStatement.
/**
* INTERNAL:
* Return a select statement that will be used to query the class indicators required to query.
* This is used in the abstract-multiple read.
*/
public SQLSelectStatement buildClassIndicatorSelectStatement(ObjectLevelReadQuery query) {
SQLSelectStatement selectStatement;
selectStatement = new SQLSelectStatement();
selectStatement.useDistinct();
selectStatement.addTable(classIndicatorField.getTable());
selectStatement.addField(getClassIndicatorField());
// 2612538 - the default size of Map (32) is appropriate
Map clonedExpressions = new IdentityHashMap();
selectStatement.setWhereClause(((ExpressionQueryMechanism) query.getQueryMechanism()).buildBaseSelectionCriteria(false, clonedExpressions));
appendWithAllSubclassesExpression(selectStatement);
selectStatement.setTranslationRow(query.getTranslationRow());
if (query.isReadAllQuery() && ((ReadAllQuery) query).hasHierarchicalExpressions()) {
ReadAllQuery readAllQuery = (ReadAllQuery) query;
selectStatement.setHierarchicalQueryExpressions(readAllQuery.getStartWithExpression(), readAllQuery.getConnectByExpression(), readAllQuery.getOrderSiblingsByExpressions(), readAllQuery.getDirection());
}
selectStatement.setHintString(query.getHintString());
selectStatement.normalize(query.getSession(), getDescriptor(), clonedExpressions);
return selectStatement;
}
use of org.eclipse.persistence.internal.expressions.SQLSelectStatement in project eclipselink by eclipse-ee4j.
the class MongoPlatform method buildCallFromStatement.
/**
* INTERNAL:
* Override this method to throw an exception by default.
* Platforms that support dynamic querying can override this to generate an EISInteraction.
*/
@Override
public DatasourceCall buildCallFromStatement(SQLStatement statement, DatabaseQuery query, AbstractSession session) {
if (query.isObjectLevelReadQuery()) {
ObjectLevelReadQuery readQuery = (ObjectLevelReadQuery) query;
MappedInteraction interaction = new MappedInteraction();
interaction.setProperty(OPERATION, MongoOperation.FIND);
interaction.setProperty(COLLECTION, ((EISDescriptor) query.getDescriptor()).getDataTypeName());
if (readQuery.getFirstResult() > 0) {
interaction.setProperty(SKIP, readQuery.getFirstResult());
}
if (readQuery.getMaxRows() > 0) {
interaction.setProperty(LIMIT, readQuery.getMaxRows());
}
if (readQuery.getFetchSize() > 0) {
interaction.setProperty(BATCH_SIZE, readQuery.getMaxRows());
}
DatabaseRecord row = new DatabaseRecord();
if (statement.getWhereClause() != null) {
appendExpressionToQueryRow(statement.getWhereClause(), row, query);
}
if (readQuery.hasOrderByExpressions()) {
DatabaseRecord sort = new DatabaseRecord();
for (Expression orderBy : readQuery.getOrderByExpressions()) {
appendExpressionToSortRow(orderBy, sort, query);
}
row.put(MongoRecord.SORT, sort);
}
if (readQuery.isReportQuery()) {
DatabaseRecord select = new DatabaseRecord();
for (Object field : ((SQLSelectStatement) statement).getFields()) {
if (field instanceof DatabaseField) {
select.put((DatabaseField) field, 1);
} else if (field instanceof Expression) {
Object value = extractValueFromExpression((Expression) field, readQuery);
if (!(value instanceof DatabaseField)) {
throw new EISException("Query too complex for Mongo translation, only field selects are supported in query: " + query);
}
select.put((DatabaseField) value, 1);
}
}
row.put("$select", select);
}
interaction.setInputRow(row);
return interaction;
}
throw new EISException("Query too complex for Mongo translation, only select queries are supported in query: " + query);
}
Aggregations