/** * INTERNAL: * Initialize the mapping. */ @Override public void initialize(AbstractSession session) throws DescriptorException { super.initialize(session); // Must build foreign keys fields. List foreignKeyFields = getForeignKeyFields(); int size = foreignKeyFields.size(); for (int index = 0; index < size; index++) { DatabaseField foreignKeyField = (DatabaseField)foreignKeyFields.get(index); foreignKeyField = getDescriptor().buildField(foreignKeyField); foreignKeyFields.set(index, foreignKeyField); } initializeForeignKeys(session); if (shouldInitializeSelectionCriteria()) { initializeSelectionCriteria(session); } else { setShouldVerifyDelete(false); } setFields(collectFields()); }
/** * INTERNAL: * Get a value from the object and set that in the respective field of the row. */ public void writeFromObjectIntoRow(Object object, AbstractRecord Record, AbstractSession session) { if (isReadOnly() || (!isForeignKeyRelationship())) { return; } AbstractRecord referenceRow = getIndirectionPolicy().extractReferenceRow(getAttributeValueFromObject(object)); if (referenceRow == null) { // Extract from object. Object referenceObject = getRealAttributeValueFromObject(object, session); for (int i = 0; i < getForeignKeyFields().size(); i++) { DatabaseField sourceKey = getForeignKeyFields().get(i); DatabaseField targetKey = (DatabaseField)getSourceToTargetKeyFields().get(sourceKey); Object referenceValue = null; // If privately owned part is null then method cannot be invoked. if (referenceObject != null) { referenceValue = getReferenceDescriptor().getObjectBuilder().extractValueFromObjectForField(referenceObject, targetKey, session); } Record.add(sourceKey, referenceValue); } } else { for (int i = 0; i < getForeignKeyFields().size(); i++) { DatabaseField sourceKey = getForeignKeyFields().get(i); Record.add(sourceKey, referenceRow.get(sourceKey)); } } }
/** * PUBLIC: * Define the source foreign key relationship in the one-to-one mapping. * This method is used to add foreign key relationships to the mapping. * Both the source foreign key field name and the corresponding * target primary key field name must be specified. */ public void addForeignKeyField(DatabaseField sourceForeignKeyField, DatabaseField targetKeyField) { this.getSourceToTargetKeyFields().put(sourceForeignKeyField, targetKeyField); this.getTargetToSourceKeyFields().put(targetKeyField, sourceForeignKeyField); this.getForeignKeyFields().add(sourceForeignKeyField); this.setIsForeignKeyRelationship(true); }
/** * INTERNAL: * The foreign keys primary keys are stored as database fields in the hashtable. */ protected void initializeForeignKeys(AbstractSession session) { HashMap newSourceToTargetKeyFields = new HashMap(getSourceToTargetKeyFields().size()); HashMap newTargetToSourceKeyFields = new HashMap(getTargetToSourceKeyFields().size()); Iterator iterator = getSourceToTargetKeyFields().entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = (Map.Entry)iterator.next(); DatabaseField sourceField = (DatabaseField)entry.getKey(); DatabaseField targetField = (DatabaseField)entry.getValue(); sourceField = getDescriptor().buildField(sourceField); targetField = getReferenceDescriptor().buildField(targetField); newSourceToTargetKeyFields.put(sourceField, targetField); newTargetToSourceKeyFields.put(targetField, sourceField); } setSourceToTargetKeyFields(newSourceToTargetKeyFields); setTargetToSourceKeyFields(newTargetToSourceKeyFields); }
clone.setForeignKeyFields(org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(getForeignKeyFields().size())); clone.setSourceToTargetKeyFields(new HashMap(getSourceToTargetKeyFields().size())); clone.setTargetToSourceKeyFields(new HashMap(getTargetToSourceKeyFields().size())); Map setOfFields = new HashMap(getTargetToSourceKeyFields().size()); for (Enumeration enumtr = getForeignKeyFields().elements(); enumtr.hasMoreElements();) { DatabaseField field = (DatabaseField)enumtr.nextElement(); clone.getForeignKeyFields().addElement(fieldClone); Iterator sourceKeyIterator = getSourceToTargetKeyFields().keySet().iterator(); while (sourceKeyIterator.hasNext()) { DatabaseField sourceField = (DatabaseField)sourceKeyIterator.next(); DatabaseField targetField = (DatabaseField)getSourceToTargetKeyFields().get(sourceField); setOfFields.put(sourceField, sourceClone); clone.getSourceToTargetKeyFields().put(sourceClone, targetClone); Iterator targetKeyIterator = getTargetToSourceKeyFields().keySet().iterator(); while (targetKeyIterator.hasNext()) { DatabaseField targetField = (DatabaseField)targetKeyIterator.next(); DatabaseField sourceField = (DatabaseField)getTargetToSourceKeyFields().get(targetField); setOfFields.put(sourceField, sourceClone); clone.getTargetToSourceKeyFields().put(targetClone, sourceClone);
/** * 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)); } }
for (Enumeration enumeration = getFields().elements(); enumeration.hasMoreElements();) { DatabaseField field = (DatabaseField)enumeration.nextElement(); if (row.get(field) == null) { return getIndirectionPolicy().nullValueFromRow(); ReadQuery targetQuery = getSelectionQuery(); if (targetQuery.isObjectLevelReadQuery() && (query.shouldCascadeAllParts() || (query.shouldCascadePrivateParts() && isPrivateOwned()) || (query.shouldCascadeByMapping() && this.cascadeRefresh))) { targetQuery = (ObjectLevelReadQuery)targetQuery.clone(); ((ObjectLevelReadQuery)targetQuery).setShouldRefreshIdentityMapResult(query.shouldRefreshIdentityMapResult()); return getIndirectionPolicy().valueFromQuery(targetQuery, row, query.getSession());
/** * INTERNAL: * Reads the private owned object. */ protected Object readPrivateOwnedForObject(ObjectLevelModifyQuery modifyQuery) throws DatabaseException { if (modifyQuery.getSession().isUnitOfWork()) { return getRealAttributeValueFromObject(modifyQuery.getBackupClone(), modifyQuery.getSession()); } else { if (!shouldVerifyDelete()) { return null; } ReadObjectQuery readQuery = (ReadObjectQuery)getSelectionQuery().clone(); readQuery.setSelectionCriteria(getPrivateOwnedCriteria()); return modifyQuery.getSession().executeQuery(readQuery, modifyQuery.getTranslationRow()); } }
/** * INTERNAL: * Extract the foreign key value from the source row. */ protected Vector extractForeignKeyFromRow(AbstractRecord row, AbstractSession session) { Vector key = new Vector(); Iterator sourceKeyIterator = getSourceToTargetKeyFields().keySet().iterator(); while (sourceKeyIterator.hasNext()) { DatabaseField field = (DatabaseField)sourceKeyIterator.next(); Object value = row.get(field); // Must ensure the classification gets a cache hit. try { value = session.getDatasourcePlatform().getConversionManager().convertObject(value, getDescriptor().getObjectBuilder().getFieldClassification(field)); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, getDescriptor(), e); } key.addElement(value); } return key; }
/** * PUBLIC: * Define the source foreign key relationship in the one-to-one mapping. * This method is used to add foreign key relationships to the mapping. * Both the source foreign key field name and the corresponding * target primary key field name must be specified. */ public void addForeignKeyFieldName(String sourceForeignKeyFieldName, String targetKeyFieldName) { this.addForeignKeyField(new DatabaseField(sourceForeignKeyFieldName), new DatabaseField(targetKeyFieldName)); }
/** * INTERNAL: * The foreign keys primary keys are stored as database fields in the hashtable. */ protected void initializeForeignKeys(AbstractSession session) { HashMap newSourceToTargetKeyFields = new HashMap(getSourceToTargetKeyFields().size()); HashMap newTargetToSourceKeyFields = new HashMap(getTargetToSourceKeyFields().size()); Iterator iterator = getSourceToTargetKeyFields().entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = (Map.Entry)iterator.next(); DatabaseField sourceField = (DatabaseField)entry.getKey(); DatabaseField targetField = (DatabaseField)entry.getValue(); sourceField = getDescriptor().buildField(sourceField); targetField = getReferenceDescriptor().buildField(targetField); newSourceToTargetKeyFields.put(sourceField, targetField); newTargetToSourceKeyFields.put(targetField, sourceField); } setSourceToTargetKeyFields(newSourceToTargetKeyFields); setTargetToSourceKeyFields(newTargetToSourceKeyFields); }
public Object clone() { EISOneToOneMapping clone = (EISOneToOneMapping)super.clone(); clone.setForeignKeyFields(org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(getForeignKeyFields().size())); clone.setSourceToTargetKeyFields(new HashMap(getSourceToTargetKeyFields().size())); clone.setTargetToSourceKeyFields(new HashMap(getTargetToSourceKeyFields().size())); Map setOfFields = new HashMap(getTargetToSourceKeyFields().size()); for (Enumeration enumtr = getForeignKeyFields().elements(); enumtr.hasMoreElements();) { DatabaseField field = (DatabaseField)enumtr.nextElement(); clone.getForeignKeyFields().addElement(fieldClone); Iterator sourceKeyIterator = getSourceToTargetKeyFields().keySet().iterator(); while (sourceKeyIterator.hasNext()) { DatabaseField sourceField = (DatabaseField)sourceKeyIterator.next(); DatabaseField targetField = getSourceToTargetKeyFields().get(sourceField); setOfFields.put(sourceField, sourceClone); clone.getSourceToTargetKeyFields().put(sourceClone, targetClone); Iterator targetKeyIterator = getTargetToSourceKeyFields().keySet().iterator(); while (targetKeyIterator.hasNext()) { DatabaseField targetField = (DatabaseField)targetKeyIterator.next(); DatabaseField sourceField = getTargetToSourceKeyFields().get(targetField); clone.getTargetToSourceKeyFields().put(targetClone, sourceClone);
/** * 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)); } }
wasCacheUsed[0] = Boolean.TRUE; return this.getAttributeValueFromObject(cached); for (Enumeration enumeration = getFields().elements(); enumeration.hasMoreElements();) { DatabaseField field = (DatabaseField)enumeration.nextElement(); if (row.get(field) == null) { return getIndirectionPolicy().nullValueFromRow(); ReadQuery targetQuery = getSelectionQuery(); if (targetQuery.isObjectLevelReadQuery() && (query.shouldCascadeAllParts() || (query.shouldCascadePrivateParts() && isPrivateOwned()) || (query.shouldCascadeByMapping() && this.cascadeRefresh))) { targetQuery = (ObjectLevelReadQuery)targetQuery.clone(); ((ObjectLevelReadQuery)targetQuery).setShouldRefreshIdentityMapResult(query.shouldRefreshIdentityMapResult()); return getIndirectionPolicy().valueFromQuery(targetQuery, row, query.getSession());
/** * PUBLIC: * Define the source foreign key relationship in the one-to-one mapping. * This method is used to add foreign key relationships to the mapping. * Both the source foreign key field name and the corresponding * target primary key field name must be specified. */ @Override public void addForeignKeyField(DatabaseField sourceForeignKeyField, DatabaseField targetKeyField) { getSourceToTargetKeyFields().put(sourceForeignKeyField, targetKeyField); getTargetToSourceKeyFields().put(targetKeyField, sourceForeignKeyField); getForeignKeyFields().add(sourceForeignKeyField); setIsForeignKeyRelationship(true); }
/** * INTERNAL: * Reads the private owned object. */ @Override protected Object readPrivateOwnedForObject(ObjectLevelModifyQuery modifyQuery) throws DatabaseException { if (modifyQuery.getSession().isUnitOfWork()) { return getRealAttributeValueFromObject(modifyQuery.getBackupClone(), modifyQuery.getSession()); } else { if (!shouldVerifyDelete()) { return null; } ReadObjectQuery readQuery = (ReadObjectQuery)getSelectionQuery().clone(); readQuery.setSelectionCriteria(getPrivateOwnedCriteria()); return modifyQuery.getSession().executeQuery(readQuery, modifyQuery.getTranslationRow()); } }
/** * PUBLIC: * Define the source foreign key relationship in the one-to-one mapping. * This method is used to add foreign key relationships to the mapping. * Both the source foreign key field name and the corresponding * target primary key field name must be specified. */ public void addForeignKeyFieldName(String sourceForeignKeyFieldName, String targetKeyFieldName) { this.addForeignKeyField(new DatabaseField(sourceForeignKeyFieldName), new DatabaseField(targetKeyFieldName)); }
/** * INTERNAL: * Initialize the mapping. */ public void initialize(AbstractSession session) throws DescriptorException { super.initialize(session); // Must build foreign keys fields. List foreignKeyFields = getForeignKeyFields(); int size = foreignKeyFields.size(); for (int index = 0; index < size; index++) { DatabaseField foreignKeyField = (DatabaseField)foreignKeyFields.get(index); foreignKeyField = getDescriptor().buildField(foreignKeyField); foreignKeyFields.set(index, foreignKeyField); } initializeForeignKeys(session); if (shouldInitializeSelectionCriteria()) { initializeSelectionCriteria(session); } else { setShouldVerifyDelete(false); } setFields(collectFields()); }
/** * INTERNAL: * Get a value from the object and set that in the respective field of the row. */ @Override public void writeFromObjectIntoRow(Object object, AbstractRecord Record, AbstractSession session, WriteType writeType) { if (isReadOnly() || (!isForeignKeyRelationship())) { return; } AbstractRecord referenceRow = getIndirectionPolicy().extractReferenceRow(getAttributeValueFromObject(object)); if (referenceRow == null) { // Extract from object. Object referenceObject = getRealAttributeValueFromObject(object, session); for (int i = 0; i < getForeignKeyFields().size(); i++) { DatabaseField sourceKey = getForeignKeyFields().get(i); DatabaseField targetKey = getSourceToTargetKeyFields().get(sourceKey); Object referenceValue = null; // If privately owned part is null then method cannot be invoked. if (referenceObject != null) { referenceValue = getReferenceDescriptor().getObjectBuilder().extractValueFromObjectForField(referenceObject, targetKey, session); } Record.add(sourceKey, referenceValue); } } else { for (int i = 0; i < getForeignKeyFields().size(); i++) { DatabaseField sourceKey = getForeignKeyFields().get(i); Record.add(sourceKey, referenceRow.get(sourceKey)); } } }
/** * INTERNAL: * The foreign keys primary keys are stored as database fields in the hashtable. */ protected void initializeForeignKeys(AbstractSession session) { HashMap newSourceToTargetKeyFields = new HashMap(getSourceToTargetKeyFields().size()); HashMap newTargetToSourceKeyFields = new HashMap(getTargetToSourceKeyFields().size()); Iterator iterator = getSourceToTargetKeyFields().entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = (Map.Entry)iterator.next(); DatabaseField sourceField = (DatabaseField)entry.getKey(); DatabaseField targetField = (DatabaseField)entry.getValue(); sourceField = getDescriptor().buildField(sourceField); targetField = getReferenceDescriptor().buildField(targetField); newSourceToTargetKeyFields.put(sourceField, targetField); newTargetToSourceKeyFields.put(targetField, sourceField); } setSourceToTargetKeyFields(newSourceToTargetKeyFields); setTargetToSourceKeyFields(newTargetToSourceKeyFields); }