use of org.eclipse.persistence.internal.expressions.ForUpdateClause in project eclipselink by eclipse-ee4j.
the class DirectCollectionMapping method valueFromRow.
/**
* INTERNAL:
* Return the value of the reference attribute or a value holder.
* Check whether the mapping's attribute should be optimized through batch and joining.
* Overridden to support flashback/historical queries.
*/
@Override
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession session, boolean isTargetProtected, Boolean[] wasCacheUsed) throws DatabaseException {
if (this.descriptor.getCachePolicy().isProtectedIsolation()) {
if (this.isCacheable && isTargetProtected && cacheKey != null) {
// cachekey will be null when isolating to uow
// used cached collection
Object result = null;
Object cached = cacheKey.getObject();
if (cached != null) {
if (wasCacheUsed != null) {
wasCacheUsed[0] = Boolean.TRUE;
}
return this.getAttributeValueFromObject(cached);
}
return result;
} else if (!this.isCacheable && !isTargetProtected && cacheKey != null) {
return this.indirectionPolicy.buildIndirectObject(new ValueHolder<>(null));
}
}
if (row.hasSopObject()) {
return getAttributeValueFromObject(row.getSopObject());
}
if (sourceQuery.isObjectLevelReadQuery() && (((ObjectLevelReadQuery) sourceQuery).isAttributeBatchRead(this.descriptor, getAttributeName()) || (sourceQuery.isReadAllQuery() && shouldUseBatchReading()))) {
return batchedValueFromRow(row, (ObjectLevelReadQuery) sourceQuery, cacheKey);
}
if (shouldUseValueFromRowWithJoin(joinManager, sourceQuery)) {
return valueFromRowInternalWithJoin(row, joinManager, sourceQuery, cacheKey, session, isTargetProtected);
}
// if the query uses batch reading, return a special value holder
// or retrieve the object from the query property.
ReadQuery targetQuery = getSelectionQuery();
boolean extendingPessimisticLockScope = isExtendingPessimisticLockScope(sourceQuery) && extendPessimisticLockScope == ExtendPessimisticLockScope.TARGET_QUERY;
if ((getHistoryPolicy() != null) || (sourceQuery.getSession().getAsOfClause() != null) || ((sourceQuery.isObjectLevelReadQuery() && ((ObjectLevelReadQuery) sourceQuery).hasAsOfClause()) && (sourceQuery.shouldCascadeAllParts() || (sourceQuery.shouldCascadePrivateParts() && isPrivateOwned()) || (sourceQuery.shouldCascadeByMapping() && this.cascadeRefresh))) || extendingPessimisticLockScope) {
targetQuery = (ReadQuery) targetQuery.clone();
// Code copied roughly from initializeSelectionStatement.
SQLSelectStatement statement = new SQLSelectStatement();
statement.addTable(getReferenceTable());
statement.addField(getDirectField().clone());
if (isDirectMapMapping()) {
statement.addField(((DirectMapMapping) this).getDirectKeyField().clone());
}
statement.setWhereClause((Expression) getSelectionCriteria().clone());
if (sourceQuery.isObjectLevelReadQuery()) {
statement.getBuilder().asOf(((ObjectLevelReadQuery) sourceQuery).getAsOfClause());
}
if (extendingPessimisticLockScope) {
statement.setLockingClause(new ForUpdateClause(sourceQuery.getLockMode()));
}
if (getHistoryPolicy() != null) {
ExpressionBuilder builder = statement.getBuilder();
if (sourceQuery.getSession().getAsOfClause() != null) {
builder.asOf(sourceQuery.getSession().getAsOfClause());
} else if (builder.getAsOfClause() == null) {
builder.asOf(AsOfClause.NO_CLAUSE);
}
Expression temporalExpression = getHistoryPolicy().additionalHistoryExpression(builder, builder);
statement.setWhereClause(statement.getWhereClause().and(temporalExpression));
if (builder.hasAsOfClause()) {
statement.getTables().set(0, getHistoryPolicy().getHistoricalTables().get(0));
}
}
statement.normalize(sourceQuery.getSession(), null);
targetQuery.setSQLStatement(statement);
}
return getIndirectionPolicy().valueFromQuery(targetQuery, row, sourceQuery.getSession());
}
use of org.eclipse.persistence.internal.expressions.ForUpdateClause in project eclipselink by eclipse-ee4j.
the class RelationTableMechanism method getLockRelationTableQueryClone.
/**
* INTERNAL:
* Returns a query that
*/
ReadQuery getLockRelationTableQueryClone(AbstractSession session, short lockMode) {
DirectReadQuery lockRelationTableQueryClone = (DirectReadQuery) lockRelationTableQuery.clone();
SQLSelectStatement statement = new SQLSelectStatement();
statement.addTable(this.relationTable);
statement.addField(this.sourceRelationKeyFields.get(0).clone());
statement.setWhereClause((Expression) lockRelationTableQuery.getSelectionCriteria().clone());
statement.setLockingClause(new ForUpdateClause(lockMode));
statement.normalize(session, null);
lockRelationTableQueryClone.setSQLStatement(statement);
lockRelationTableQueryClone.setIsExecutionClone(true);
return lockRelationTableQueryClone;
}
Aggregations