/** * INTERNAL: * Extract the primary key value from the source row. * Used for batch reading, most following same order and fields as in the mapping. */ protected Vector extractPrimaryKeyFromRow(AbstractRecord row, AbstractSession session) { Vector key = new Vector(getSourceKeyFields().size()); for (Enumeration fieldEnum = getSourceKeyFields().elements(); fieldEnum.hasMoreElements();) { DatabaseField field = (DatabaseField)fieldEnum.nextElement(); 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; }
/** * INTERNAL: * Extract the source primary key value from the target row. * Used for batch reading, most following same order and fields as in the mapping. */ protected Vector extractKeyFromTargetRow(AbstractRecord row, AbstractSession session) { Vector key = new Vector(getTargetForeignKeyFields().size()); for (int index = 0; index < getTargetForeignKeyFields().size(); index++) { DatabaseField targetField = getTargetForeignKeyFields().elementAt(index); DatabaseField sourceField = getSourceKeyFields().elementAt(index); Object value = row.get(targetField); // Must ensure the classification gets a cache hit. try { value = session.getDatasourcePlatform().getConversionManager().convertObject(value, getDescriptor().getObjectBuilder().getFieldClassification(sourceField)); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, getDescriptor(), e); } key.addElement(value); } return key; }
/** * INTERNAL: * get reference object keys */ public Vector getReferenceObjectKeys(ObjectLevelModifyQuery query) throws DatabaseException, OptimisticLockException { Vector referenceObjectKeys = new Vector(getSourceKeyFields().size()); //For CR#2587-S.M. For nested aggregate collections the source keys can easily be read from the original query. AbstractRecord translationRow = query.getTranslationRow(); for (Enumeration sourcekeys = getSourceKeyFields().elements(); sourcekeys.hasMoreElements();) { DatabaseField sourceKey = (DatabaseField)sourcekeys.nextElement(); // CR#2587. Try first to get the source key from the original query. If that fails try to get it from the object. Object referenceKey = null; if ((translationRow != null) && (translationRow.containsKey(sourceKey))) { referenceKey = translationRow.get(sourceKey); } else { referenceKey = getDescriptor().getObjectBuilder().extractValueFromObjectForField(query.getObject(), sourceKey, query.getSession()); } referenceObjectKeys.addElement(referenceKey); } return referenceObjectKeys; }
/** * INTERNAL: * get reference object keys */ public Vector getReferenceObjectKeys(ObjectLevelModifyQuery query) throws DatabaseException, OptimisticLockException { Vector referenceObjectKeys = new Vector(getSourceKeyFields().size()); //For CR#2587-S.M. For nested aggregate collections the source keys can easily be read from the original query. AbstractRecord translationRow = query.getTranslationRow(); for (Enumeration sourcekeys = getSourceKeyFields().elements(); sourcekeys.hasMoreElements();) { DatabaseField sourceKey = (DatabaseField)sourcekeys.nextElement(); // CR#2587. Try first to get the source key from the original query. If that fails try to get it from the object. Object referenceKey = null; if ((translationRow != null) && (translationRow.containsKey(sourceKey))) { referenceKey = translationRow.get(sourceKey); } else { referenceKey = getDescriptor().getObjectBuilder().extractValueFromObjectForField(query.getObject(), sourceKey, query.getSession()); } referenceObjectKeys.addElement(referenceKey); } return referenceObjectKeys; }
/** * INTERNAL: * get reference object keys */ public Vector getReferenceObjectKeys(ObjectLevelModifyQuery query) throws DatabaseException, OptimisticLockException { Vector referenceObjectKeys = new Vector(getSourceKeyFields().size()); //For CR#2587-S.M. For nested aggregate collections the source keys can easily be read from the original query. AbstractRecord translationRow = query.getTranslationRow(); for (Enumeration sourcekeys = getSourceKeyFields().elements(); sourcekeys.hasMoreElements();) { DatabaseField sourceKey = (DatabaseField)sourcekeys.nextElement(); // CR#2587. Try first to get the source key from the original query. If that fails try to get it from the object. Object referenceKey = null; if ((translationRow != null) && (translationRow.containsKey(sourceKey))) { referenceKey = translationRow.get(sourceKey); } else { referenceKey = getDescriptor().getObjectBuilder().extractValueFromObjectForField(query.getObject(), sourceKey, query.getSession()); } referenceObjectKeys.addElement(referenceKey); } return referenceObjectKeys; }
/** * INTERNAL: * The foreign keys and the primary key names are converted to DatabaseFields and stored. */ protected void initializeTargetForeignKeyToSourceKeys(AbstractSession session) throws DescriptorException { if (getTargetForeignKeyFields().isEmpty()) { throw DescriptorException.noTargetForeignKeysSpecified(this); } for (int index = 0; index < getTargetForeignKeyFields().size(); index++) { DatabaseField foreignKeyfield = getTargetForeignKeyFields().get(index); foreignKeyfield = getReferenceDescriptor().buildField(foreignKeyfield); getTargetForeignKeyFields().set(index, foreignKeyfield); } for (int index = 0; index < getSourceKeyFields().size(); index++) { DatabaseField sourceKeyfield = getSourceKeyFields().get(index); sourceKeyfield = getDescriptor().buildField(sourceKeyfield); getSourceKeyFields().set(index, sourceKeyfield); } if (getTargetForeignKeyFields().size() != getSourceKeyFields().size()) { throw DescriptorException.targetForeignKeysSizeMismatch(this); } Iterator<DatabaseField> targetForeignKeysEnum = getTargetForeignKeyFields().iterator(); Iterator<DatabaseField> sourceKeysEnum = getSourceKeyFields().iterator(); while (targetForeignKeysEnum.hasNext()) { getTargetForeignKeyToSourceKeys().put(targetForeignKeysEnum.next(), sourceKeysEnum.next()); } }
/** * INTERNAL: * The foreign keys and the primary key names are converted to DatabaseFields and stored. The source keys * are not specified by the user so primary keys are extracted from the reference descriptor. */ protected void initializeTargetForeignKeyToSourceKeysWithDefaults(AbstractSession session) throws DescriptorException { if (getTargetForeignKeyFields().isEmpty()) { throw DescriptorException.noTargetForeignKeysSpecified(this); } List<DatabaseField> sourceKeys = getDescriptor().getPrimaryKeyFields(); setSourceKeyFields(org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(sourceKeys)); for (int index = 0; index < getTargetForeignKeyFields().size(); index++) { DatabaseField foreignKeyfield = getTargetForeignKeyFields().get(index); foreignKeyfield = getReferenceDescriptor().buildField(foreignKeyfield); getTargetForeignKeyFields().set(index, foreignKeyfield); } if (getTargetForeignKeyFields().size() != sourceKeys.size()) { throw DescriptorException.targetForeignKeysSizeMismatch(this); } for (int index = 0; index < getTargetForeignKeyFields().size(); index++) { getTargetForeignKeyToSourceKeys().put(getTargetForeignKeyFields().get(index), sourceKeys.get(index)); } }
/** * INTERNAL: * The foreign keys and the primary key names are converted to DatabaseFields and stored. */ protected void initializeTargetForeignKeyToSourceKeys(AbstractSession session) throws DescriptorException { if (getTargetForeignKeyFields().isEmpty()) { throw DescriptorException.noTargetForeignKeysSpecified(this); } for (int index = 0; index < getTargetForeignKeyFields().size(); index++) { DatabaseField foreignKeyfield = getTargetForeignKeyFields().get(index); foreignKeyfield = getReferenceDescriptor().buildField(foreignKeyfield); getTargetForeignKeyFields().set(index, foreignKeyfield); } for (int index = 0; index < getSourceKeyFields().size(); index++) { DatabaseField sourceKeyfield = getSourceKeyFields().get(index); sourceKeyfield = getDescriptor().buildField(sourceKeyfield); if (usesIndirection()) { sourceKeyfield.setKeepInRow(true); } getSourceKeyFields().set(index, sourceKeyfield); } if (getTargetForeignKeyFields().size() != getSourceKeyFields().size()) { throw DescriptorException.targetForeignKeysSizeMismatch(this); } Iterator<DatabaseField> targetForeignKeysEnum = getTargetForeignKeyFields().iterator(); Iterator<DatabaseField> sourceKeysEnum = getSourceKeyFields().iterator(); while (targetForeignKeysEnum.hasNext()) { getTargetForeignKeyToSourceKeys().put(targetForeignKeysEnum.next(), sourceKeysEnum.next()); } }
/** * INTERNAL: * The foreign keys and the primary key names are converted to DatabaseFields and stored. */ protected void initializeTargetForeignKeyToSourceKeys(AbstractSession session) throws DescriptorException { if (getTargetForeignKeyFields().isEmpty()) { throw DescriptorException.noTargetForeignKeysSpecified(this); } for (int index = 0; index < getTargetForeignKeyFields().size(); index++) { DatabaseField foreignKeyfield = getTargetForeignKeyFields().get(index); foreignKeyfield = getReferenceDescriptor().buildField(foreignKeyfield); getTargetForeignKeyFields().set(index, foreignKeyfield); } for (int index = 0; index < getSourceKeyFields().size(); index++) { DatabaseField sourceKeyfield = getSourceKeyFields().get(index); sourceKeyfield = getDescriptor().buildField(sourceKeyfield); if (usesIndirection()) { sourceKeyfield.setKeepInRow(true); } getSourceKeyFields().set(index, sourceKeyfield); } if (getTargetForeignKeyFields().size() != getSourceKeyFields().size()) { throw DescriptorException.targetForeignKeysSizeMismatch(this); } Iterator<DatabaseField> targetForeignKeysEnum = getTargetForeignKeyFields().iterator(); Iterator<DatabaseField> sourceKeysEnum = getSourceKeyFields().iterator(); while (targetForeignKeysEnum.hasNext()) { getTargetForeignKeyToSourceKeys().put(targetForeignKeysEnum.next(), sourceKeysEnum.next()); } }
/** * INTERNAL: * Extract the source primary key value from the target row. * Used for batch reading, most following same order and fields as in the mapping. */ @Override protected Object extractKeyFromTargetRow(AbstractRecord row, AbstractSession session) { int size = this.targetForeignKeyFields.size(); Object[] key = new Object[size]; ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager(); for (int index = 0; index < size; index++) { DatabaseField targetField = this.targetForeignKeyFields.get(index); DatabaseField sourceField = this.sourceKeyFields.get(index); Object value = row.get(targetField); // Must ensure the classification gets a cache hit. try { value = conversionManager.convertObject(value, sourceField.getType()); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, getDescriptor(), e); } key[index] = value; } return new CacheId(key); }
/** * INTERNAL: * Extract the source primary key value from the target row. * Used for batch reading, most following same order and fields as in the mapping. */ @Override protected Object extractKeyFromTargetRow(AbstractRecord row, AbstractSession session) { int size = this.targetForeignKeyFields.size(); Object[] key = new Object[size]; ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager(); for (int index = 0; index < size; index++) { DatabaseField targetField = this.targetForeignKeyFields.get(index); DatabaseField sourceField = this.sourceKeyFields.get(index); Object value = row.get(targetField); // Must ensure the classification gets a cache hit. try { value = conversionManager.convertObject(value, sourceField.getType()); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, getDescriptor(), e); } key[index] = value; } return new CacheId(key); }
if (getDescriptor().getObjectChangePolicy().getClass().equals(DeferredChangeDetectionPolicy.class)) { getReferenceDescriptor().setObjectChangePolicy(new DeferredChangeDetectionPolicy()); } else if (getDescriptor().getObjectChangePolicy().getClass().equals(ObjectChangeTrackingPolicy.class) && getReferenceDescriptor().getObjectChangePolicy().getClass().equals(AttributeChangeTrackingPolicy.class)) { getReferenceDescriptor().setObjectChangePolicy(new ObjectChangeTrackingPolicy()); DatabaseField targetKey = getTargetForeignKeyFields().get(index); if (targetKey.getType() == null) { targetKey.setType(getDescriptor().getObjectBuilder().getFieldClassification(foreignKey));
if (getDescriptor().getObjectChangePolicy().getClass().equals(DeferredChangeDetectionPolicy.class)) { getReferenceDescriptor().setObjectChangePolicy(new DeferredChangeDetectionPolicy()); } else if (getDescriptor().getObjectChangePolicy().getClass().equals(ObjectChangeTrackingPolicy.class) && getReferenceDescriptor().getObjectChangePolicy().getClass().equals(AttributeChangeTrackingPolicy.class)) { getReferenceDescriptor().setObjectChangePolicy(new ObjectChangeTrackingPolicy()); DatabaseField targetKey = getTargetForeignKeyFields().get(index); if (targetKey.getType() == null) { targetKey.setType(getDescriptor().getObjectBuilder().getFieldClassification(foreignKey));
/** * INTERNAL: * The foreign keys and the primary key names are converted to DatabaseFields and stored. The source keys * are not specified by the user so primary keys are extracted from the reference descriptor. */ protected void initializeTargetForeignKeyToSourceKeysWithDefaults(AbstractSession session) throws DescriptorException { if (getTargetForeignKeyFields().isEmpty()) { throw DescriptorException.noTargetForeignKeysSpecified(this); } List<DatabaseField> sourceKeys = getDescriptor().getPrimaryKeyFields(); if (usesIndirection()) { for (DatabaseField field : sourceKeys) { field.setKeepInRow(true); } } setSourceKeyFields(org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(sourceKeys)); for (int index = 0; index < getTargetForeignKeyFields().size(); index++) { DatabaseField foreignKeyfield = getTargetForeignKeyFields().get(index); foreignKeyfield = getReferenceDescriptor().buildField(foreignKeyfield); getTargetForeignKeyFields().set(index, foreignKeyfield); } if (getTargetForeignKeyFields().size() != sourceKeys.size()) { throw DescriptorException.targetForeignKeysSizeMismatch(this); } for (int index = 0; index < getTargetForeignKeyFields().size(); index++) { getTargetForeignKeyToSourceKeys().put(getTargetForeignKeyFields().get(index), sourceKeys.get(index)); } }
/** * INTERNAL: * The foreign keys and the primary key names are converted to DatabaseFields and stored. The source keys * are not specified by the user so primary keys are extracted from the reference descriptor. */ protected void initializeTargetForeignKeyToSourceKeysWithDefaults(AbstractSession session) throws DescriptorException { if (getTargetForeignKeyFields().isEmpty()) { throw DescriptorException.noTargetForeignKeysSpecified(this); } List<DatabaseField> sourceKeys = getDescriptor().getPrimaryKeyFields(); if (usesIndirection()) { for (DatabaseField field : sourceKeys) { field.setKeepInRow(true); } } setSourceKeyFields(org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(sourceKeys)); for (int index = 0; index < getTargetForeignKeyFields().size(); index++) { DatabaseField foreignKeyfield = getTargetForeignKeyFields().get(index); foreignKeyfield = getReferenceDescriptor().buildField(foreignKeyfield); getTargetForeignKeyFields().set(index, foreignKeyfield); } if (getTargetForeignKeyFields().size() != sourceKeys.size()) { throw DescriptorException.targetForeignKeysSizeMismatch(this); } for (int index = 0; index < getTargetForeignKeyFields().size(); index++) { getTargetForeignKeyToSourceKeys().put(getTargetForeignKeyFields().get(index), sourceKeys.get(index)); } }
/** * INTERNAL: * Checks if object is deleted from the database or not. */ public boolean verifyDelete(Object object, AbstractSession session) throws DatabaseException { // Row is built for translation if (isReadOnly()) { return true; } AbstractRecord row = getDescriptor().getObjectBuilder().buildRowForTranslation(object, session); Object value = session.executeQuery(getSelectionQuery(), row); return getContainerPolicy().isEmpty(value); }
/** * INTERNAL: * Checks if object is deleted from the database or not. */ @Override public boolean verifyDelete(Object object, AbstractSession session) throws DatabaseException { // Row is built for translation if (isReadOnly()) { return true; } AbstractRecord row = getDescriptor().getObjectBuilder().buildRowForTranslation(object, session); Object value = session.executeQuery(getSelectionQuery(), row); return getContainerPolicy().isEmpty(value); }
/** * INTERNAL: * Checks if object is deleted from the database or not. */ @Override public boolean verifyDelete(Object object, AbstractSession session) throws DatabaseException { // Row is built for translation if (isReadOnly()) { return true; } AbstractRecord row = getDescriptor().getObjectBuilder().buildRowForTranslation(object, session); Object value = session.executeQuery(getSelectionQuery(), row); return getContainerPolicy().isEmpty(value); }
if (mapping.getDescriptor().hasTablePerClassPolicy()) { return;
if (getDescriptor() != null){ // descriptor will only be null in special case where the mapping has not been added to a descriptor prior to initialization. getDescriptor().addMappingsPostCalculateChanges(this); // always equivalent to Private Owned if (getDescriptor().hasInheritance()){ for (ClassDescriptor descriptor: (List<ClassDescriptor>)getDescriptor().getInheritancePolicy().getAllChildDescriptors()){ descriptor.addMappingsPostCalculateChanges(this);