Search in sources :

Example 1 with ForUpdateClause

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());
}
Also used : ObjectLevelReadQuery(org.eclipse.persistence.queries.ObjectLevelReadQuery) ObjectExpression(org.eclipse.persistence.internal.expressions.ObjectExpression) Expression(org.eclipse.persistence.expressions.Expression) TableExpression(org.eclipse.persistence.internal.expressions.TableExpression) SQLSelectStatement(org.eclipse.persistence.internal.expressions.SQLSelectStatement) ValueHolder(org.eclipse.persistence.indirection.ValueHolder) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) ObjectLevelReadQuery(org.eclipse.persistence.queries.ObjectLevelReadQuery) DirectReadQuery(org.eclipse.persistence.queries.DirectReadQuery) DataReadQuery(org.eclipse.persistence.queries.DataReadQuery) ReadQuery(org.eclipse.persistence.queries.ReadQuery) ForUpdateClause(org.eclipse.persistence.internal.expressions.ForUpdateClause)

Example 2 with ForUpdateClause

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;
}
Also used : SQLSelectStatement(org.eclipse.persistence.internal.expressions.SQLSelectStatement) ForUpdateClause(org.eclipse.persistence.internal.expressions.ForUpdateClause) DirectReadQuery(org.eclipse.persistence.queries.DirectReadQuery)

Aggregations

ForUpdateClause (org.eclipse.persistence.internal.expressions.ForUpdateClause)2 SQLSelectStatement (org.eclipse.persistence.internal.expressions.SQLSelectStatement)2 DirectReadQuery (org.eclipse.persistence.queries.DirectReadQuery)2 Expression (org.eclipse.persistence.expressions.Expression)1 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)1 ValueHolder (org.eclipse.persistence.indirection.ValueHolder)1 ObjectExpression (org.eclipse.persistence.internal.expressions.ObjectExpression)1 TableExpression (org.eclipse.persistence.internal.expressions.TableExpression)1 DataReadQuery (org.eclipse.persistence.queries.DataReadQuery)1 ObjectLevelReadQuery (org.eclipse.persistence.queries.ObjectLevelReadQuery)1 ReadQuery (org.eclipse.persistence.queries.ReadQuery)1