/** * INTERNAL: * Called only if both * shouldExtendPessimisticLockScope and shouldExtendPessimisticLockScopeInSourceQuery are true. * Adds fields to be locked to the where clause of the source query. * Note that the sourceQuery must be ObjectLevelReadQuery so that it has ExpressionBuilder. * * This method must be implemented in subclasses that allow * setting shouldExtendPessimisticLockScopeInSourceQuery to true. */ public void extendPessimisticLockScopeInSourceQuery(ObjectLevelReadQuery sourceQuery) { Expression exp = sourceQuery.getSelectionCriteria(); if(this.mechanism == null) { ExpressionBuilder builder = sourceQuery.getExpressionBuilder(); Iterator<Map.Entry<DatabaseField, DatabaseField>> it = this.getSourceToTargetKeyFields().entrySet().iterator(); Map.Entry<DatabaseField, DatabaseField> entry = it.next(); exp = builder.getField(entry.getKey()).equal(builder.get(this.getAttributeName()).getField(entry.getValue())).and(exp); } else { exp = this.mechanism.joinRelationTableField(exp, sourceQuery.getExpressionBuilder()); } sourceQuery.setSelectionCriteria(exp); }
/** * INTERNAL: * Called only if both * shouldExtendPessimisticLockScope and shouldExtendPessimisticLockScopeInSourceQuery are true. * Adds fields to be locked to the where clause of the source query. * Note that the sourceQuery must be ObjectLevelReadQuery so that it has ExpressionBuilder. * * This method must be implemented in subclasses that allow * setting shouldExtendPessimisticLockScopeInSourceQuery to true. */ @Override public void extendPessimisticLockScopeInSourceQuery(ObjectLevelReadQuery sourceQuery) { Expression exp = sourceQuery.getSelectionCriteria(); if(this.mechanism == null) { ExpressionBuilder builder = sourceQuery.getExpressionBuilder(); Iterator<Map.Entry<DatabaseField, DatabaseField>> it = this.getSourceToTargetKeyFields().entrySet().iterator(); Map.Entry<DatabaseField, DatabaseField> entry = it.next(); exp = builder.getField(entry.getKey()).equal(builder.get(this.getAttributeName()).getField(entry.getValue())).and(exp); } else { exp = this.mechanism.joinRelationTableField(exp, sourceQuery.getExpressionBuilder()); } sourceQuery.setSelectionCriteria(exp); }
/** * INTERNAL: * Called only if both * shouldExtendPessimisticLockScope and shouldExtendPessimisticLockScopeInSourceQuery are true. * Adds fields to be locked to the where clause of the source query. * Note that the sourceQuery must be ObjectLevelReadQuery so that it has ExpressionBuilder. * * This method must be implemented in subclasses that allow * setting shouldExtendPessimisticLockScopeInSourceQuery to true. */ @Override public void extendPessimisticLockScopeInSourceQuery(ObjectLevelReadQuery sourceQuery) { Expression exp = sourceQuery.getSelectionCriteria(); if(this.mechanism == null) { ExpressionBuilder builder = sourceQuery.getExpressionBuilder(); Iterator<Map.Entry<DatabaseField, DatabaseField>> it = this.getSourceToTargetKeyFields().entrySet().iterator(); Map.Entry<DatabaseField, DatabaseField> entry = it.next(); exp = builder.getField(entry.getKey()).equal(builder.get(this.getAttributeName()).getField(entry.getValue())).and(exp); } else { exp = this.mechanism.joinRelationTableField(exp, sourceQuery.getExpressionBuilder()); } sourceQuery.setSelectionCriteria(exp); }
@Override public void customizeColumnName(final String tableName, final OneToOneMapping databaseMapping, final Session session) { logDatabaseMapping(databaseMapping, session); EntityFieldInspector<?> entityFieldInspector = new JoinColumnFieldInspector(FieldInspector.getFieldInspector( databaseMapping).getField()); for (final DatabaseField foreignKeyField : databaseMapping.getForeignKeyFields()) { String prefix = NameUtils.iconizeTableName(tableName) + "_"; if (!foreignKeyField.getName().startsWith(prefix) && !(entityFieldInspector.isNameValueSet())) { String newFieldName = NameUtils.buildFieldName(tableName, databaseMapping.getAttributeName()) + "_id"; foreignKeyField.setName(newFieldName); logFine(session, "ForeignKeyField-Name was set to {0}", foreignKeyField.getName()); } else if (!foreignKeyField.getName().startsWith(prefix) && entityFieldInspector.isNameValueSet()) { String newFieldName = NameUtils.buildFieldName(tableName, foreignKeyField.getName()); foreignKeyField.setName(newFieldName); logFine(session, "ForeignKeyField-Name was set to {0}", foreignKeyField.getName()); } } Vector associations = databaseMapping.getSourceToTargetKeyFieldAssociations(); for (final Object ass : associations) { logFine(session, "--" + tableName + " -- " + ((Association) ass).getKey().toString() + "----"); } }
dm.setMappedBy(inverse.getAttributeName()); for (DatabaseField sourceField : inverse.getSourceToTargetKeyFields().keySet()) { DatabaseField targetField = inverse.getSourceToTargetKeyFields().get(sourceField);
/** * INTERNAL: * Selection criteria is created with source foreign keys and target keys. */ protected void initializePrivateOwnedCriteria() { if (!isForeignKeyRelationship()) { setPrivateOwnedCriteria(getSelectionCriteria()); } else { Expression pkCriteria = getDescriptor().getObjectBuilder().getPrimaryKeyExpression(); ExpressionBuilder builder = new ExpressionBuilder(); Expression backRef = builder.getManualQueryKey(getAttributeName() + "-back-ref", getDescriptor()); Expression newPKCriteria = pkCriteria.rebuildOn(backRef); Expression twistedSelection = backRef.twist(getSelectionCriteria(), builder); if (getDescriptor().getQueryManager().getAdditionalJoinExpression() != null) { // We don't have to twist the additional join because it's all against the same node, which is our base // but we do have to rebuild it onto the manual query key Expression rebuiltAdditional = getDescriptor().getQueryManager().getAdditionalJoinExpression().rebuildOn(backRef); if (twistedSelection == null) { twistedSelection = rebuiltAdditional; } else { twistedSelection = twistedSelection.and(rebuiltAdditional); } } setPrivateOwnedCriteria(newPKCriteria.and(twistedSelection)); } }
/** * INTERNAL: * Selection criteria is created with source foreign keys and target keys. */ protected void initializePrivateOwnedCriteria() { if (!isForeignKeyRelationship()) { setPrivateOwnedCriteria(getSelectionCriteria()); } else { Expression pkCriteria = getDescriptor().getObjectBuilder().getPrimaryKeyExpression(); ExpressionBuilder builder = new ExpressionBuilder(); Expression backRef = builder.getManualQueryKey(getAttributeName() + "-back-ref", getDescriptor()); Expression newPKCriteria = pkCriteria.rebuildOn(backRef); Expression twistedSelection = backRef.twist(getSelectionCriteria(), builder); if (getDescriptor().getQueryManager().getAdditionalJoinExpression() != null) { // We don't have to twist the additional join because it's all against the same node, which is our base // but we do have to rebuild it onto the manual query key Expression rebuiltAdditional = getDescriptor().getQueryManager().getAdditionalJoinExpression().rebuildOn(backRef); if (twistedSelection == null) { twistedSelection = rebuiltAdditional; } else { twistedSelection = twistedSelection.and(rebuiltAdditional); } } setPrivateOwnedCriteria(newPKCriteria.and(twistedSelection)); } }
/** * INTERNAL: * Selection criteria is created with source foreign keys and target keys. */ protected void initializePrivateOwnedCriteria() { if (!isForeignKeyRelationship()) { setPrivateOwnedCriteria(getSelectionCriteria()); } else { Expression pkCriteria = getDescriptor().getObjectBuilder().getPrimaryKeyExpression(); ExpressionBuilder builder = new ExpressionBuilder(); Expression backRef = builder.getManualQueryKey(getAttributeName() + "-back-ref", getDescriptor()); Expression newPKCriteria = pkCriteria.rebuildOn(backRef); Expression twistedSelection = backRef.twist(getSelectionCriteria(), builder); if (getDescriptor().getQueryManager().getAdditionalJoinExpression() != null) { // We don't have to twist the additional join because it's all against the same node, which is our base // but we do have to rebuild it onto the manual query key Expression rebuiltAdditional = getDescriptor().getQueryManager().getAdditionalJoinExpression().rebuildOn(backRef); if (twistedSelection == null) { twistedSelection = rebuiltAdditional; } else { twistedSelection = twistedSelection.and(rebuiltAdditional); } } setPrivateOwnedCriteria(newPKCriteria.and(twistedSelection)); } }