/** * INTERNAL: * Returns list of primary key fields from the reference descriptor. */ public List<DatabaseField> getTargetPrimaryKeyFields() { return getReferenceDescriptor().getPrimaryKeyFields(); }
/** * INTERNAL: * This method is used to calculate the differences between two collections. */ public void compareCollectionsForChange(Object oldCollection, Object newCollection, ChangeRecord changeRecord, AbstractSession session) { this.containerPolicy.compareCollectionsForChange(oldCollection, newCollection, (CollectionChangeRecord) changeRecord, session, getReferenceDescriptor()); }
/** * INTERNAL: * This method is used to calculate the differences between two collections. */ public void compareCollectionsForChange(Object oldCollection, Object newCollection, ChangeRecord changeRecord, AbstractSession session) { this.containerPolicy.compareCollectionsForChange(oldCollection, newCollection, (CollectionChangeRecord) changeRecord, session, getReferenceDescriptor()); }
/** * INTERNAL: * This method is used to calculate the differences between two collections. */ public void compareCollectionsForChange(Object oldCollection, Object newCollection, ChangeRecord changeRecord, AbstractSession session) { this.containerPolicy.compareCollectionsForChange(oldCollection, newCollection, (CollectionChangeRecord) changeRecord, session, getReferenceDescriptor()); }
/** * INTERNAL: * Returns list of primary key fields from the reference descriptor. */ public List<DatabaseField> getTargetPrimaryKeyFields() { return getReferenceDescriptor().getPrimaryKeyFields(); }
/** * INTERNAL: * Returns list of primary key fields from the reference descriptor. */ public List<DatabaseField> getTargetPrimaryKeyFields() { return getReferenceDescriptor().getPrimaryKeyFields(); }
/** * INTERNAL: * Verifies listOrderField's table, if none found sets the default one. * Precondition: listOrderField != null. */ protected void buildListOrderField() { if(this.listOrderField.hasTableName()) { if(!this.getReferenceDescriptor().getDefaultTable().equals(this.listOrderField.getTable())) { throw DescriptorException.listOrderFieldTableIsWrong(this.getDescriptor(), this, this.listOrderField.getTable(), this.getReferenceDescriptor().getDefaultTable()); } } else { this.listOrderField.setTable(this.getReferenceDescriptor().getDefaultTable()); } this.listOrderField = this.getReferenceDescriptor().buildField(this.listOrderField); }
/** * INTERNAL: * Verifies listOrderField's table, if none found sets the default one. * Precondition: listOrderField != null. */ protected void buildListOrderField() { if(this.listOrderField.hasTableName()) { if(!this.getReferenceDescriptor().getDefaultTable().equals(this.listOrderField.getTable())) { throw DescriptorException.listOrderFieldTableIsWrong(this.getDescriptor(), this, this.listOrderField.getTable(), this.getReferenceDescriptor().getDefaultTable()); } } else { this.listOrderField.setTable(this.getReferenceDescriptor().getDefaultTable()); } this.listOrderField = this.getReferenceDescriptor().buildField(this.listOrderField); }
/** * INTERNAL: * Verifies listOrderField's table, if none found sets the default one. * Precondition: listOrderField != null. */ protected void buildListOrderField() { if(this.listOrderField.hasTableName()) { if(!this.getReferenceDescriptor().getDefaultTable().equals(this.listOrderField.getTable())) { throw DescriptorException.listOrderFieldTableIsWrong(this.getDescriptor(), this, this.listOrderField.getTable(), this.getReferenceDescriptor().getDefaultTable()); } } else { this.listOrderField.setTable(this.getReferenceDescriptor().getDefaultTable()); } this.listOrderField = this.getReferenceDescriptor().buildField(this.listOrderField); }
/** * INTERNAL: * Return the DatabaseField that represents the key in a DirectMapMapping. MapContainerPolicy gets it fields from the reference descriptor * of the provided mappings. It uses its keyName to lookup the appropriate mapping and returns the field from * that mapping. */ @Override public DatabaseField getDirectKeyField(CollectionMapping baseMapping){ if (baseMapping == null){ return null; } ClassDescriptor descriptor = baseMapping.getReferenceDescriptor(); DatabaseMapping mapping = descriptor.getMappingForAttributeName(Helper.getAttributeNameFromMethodName(keyName)); if (mapping.isAbstractDirectMapping()){ return ((AbstractDirectMapping)mapping).getField(); } return null; }
/** * INTERNAL: * Return the DatabaseField that represents the key in a DirectMapMapping. MapContainerPolicy gets it fields from the reference descriptor * of the provided mappings. It uses its keyName to lookup the appropriate mapping and returns the field from * that mapping. */ @Override public DatabaseField getDirectKeyField(CollectionMapping baseMapping){ if (baseMapping == null){ return null; } ClassDescriptor descriptor = baseMapping.getReferenceDescriptor(); DatabaseMapping mapping = descriptor.getMappingForAttributeName(Helper.getAttributeNameFromMethodName(keyName)); if (mapping.isAbstractDirectMapping()){ return ((AbstractDirectMapping)mapping).getField(); } return null; }
/** * INTERNAL: * Return the DatabaseField that represents the key in a DirectMapMapping. MapContainerPolicy gets it fields from the reference descriptor * of the provided mappings. It uses its keyName to lookup the appropriate mapping and returns the field from * that mapping * @return */ public DatabaseField getDirectKeyField(CollectionMapping baseMapping){ if (baseMapping == null){ return null; } ClassDescriptor descriptor = baseMapping.getReferenceDescriptor(); DatabaseMapping mapping = descriptor.getMappingForAttributeName(Helper.getAttributeNameFromMethodName(keyName)); if (mapping.isAbstractDirectMapping()){ return ((AbstractDirectMapping)mapping).getField(); } return null; }
/** * INTERNAL: * Return all the fields in the key. MapContainerPolicy gets it fields from the reference descriptor * of the provided mappings. It uses its keyName to lookup the appropriate mapping and returns the fields from * that mapping * @return */ public List<DatabaseField> getAllFieldsForMapKey(CollectionMapping baseMapping){ if (baseMapping == null){ return null; } ClassDescriptor descriptor = baseMapping.getReferenceDescriptor(); if (keyName != null){ DatabaseMapping mapping = descriptor.getMappingForAttributeName(Helper.getAttributeNameFromMethodName(keyName)); return mapping.getFields(); } else { return descriptor.getPrimaryKeyFields(); } }
/** * Return whether the reference objects must be deleted * one by one, as opposed to with a single DELETE statement. */ protected boolean mustDeleteReferenceObjectsOneByOne() { ClassDescriptor referenceDescriptor = this.getReferenceDescriptor(); return referenceDescriptor.hasDependencyOnParts() || referenceDescriptor.usesOptimisticLocking() || (referenceDescriptor.hasInheritance() && referenceDescriptor.getInheritancePolicy().shouldReadSubclasses()) || referenceDescriptor.hasMultipleTables() || containerPolicy.propagatesEventsToCollection(); }
protected void objectOrderChangedDuringUpdate(WriteObjectQuery query, Object orderChangedObject, int orderIndex) { prepareTranslationRow(query.getTranslationRow(), query.getObject(), query.getSession()); AbstractRecord databaseRow = new DatabaseRecord(); // Extract target field and its value. Construct insert statement and execute it List<DatabaseField> targetPrimaryKeyFields = getTargetPrimaryKeyFields(); int size = targetPrimaryKeyFields.size(); for (int index = 0; index < size; index++) { DatabaseField targetPrimaryKey = targetPrimaryKeyFields.get(index); Object targetKeyValue = getReferenceDescriptor().getObjectBuilder().extractValueFromObjectForField(orderChangedObject, targetPrimaryKey, query.getSession()); databaseRow.put(targetPrimaryKey, targetKeyValue); } databaseRow.put(listOrderField, orderIndex); query.getSession().executeQuery(changeOrderTargetQuery, databaseRow); }
protected void objectOrderChangedDuringUpdate(WriteObjectQuery query, Object orderChangedObject, int orderIndex) { prepareTranslationRow(query.getTranslationRow(), query.getObject(), query.getDescriptor(), query.getSession()); AbstractRecord databaseRow = new DatabaseRecord(); // Extract target field and its value. Construct insert statement and execute it List<DatabaseField> targetPrimaryKeyFields = getTargetPrimaryKeyFields(); int size = targetPrimaryKeyFields.size(); for (int index = 0; index < size; index++) { DatabaseField targetPrimaryKey = targetPrimaryKeyFields.get(index); Object targetKeyValue = getReferenceDescriptor().getObjectBuilder().extractValueFromObjectForField(orderChangedObject, targetPrimaryKey, query.getSession()); databaseRow.put(targetPrimaryKey, targetKeyValue); } databaseRow.put(listOrderField, orderIndex); query.getSession().executeQuery(changeOrderTargetQuery, databaseRow); }
protected void objectOrderChangedDuringUpdate(WriteObjectQuery query, Object orderChangedObject, int orderIndex) { prepareTranslationRow(query.getTranslationRow(), query.getObject(), query.getDescriptor(), query.getSession()); AbstractRecord databaseRow = new DatabaseRecord(); // Extract target field and its value. Construct insert statement and execute it List<DatabaseField> targetPrimaryKeyFields = getTargetPrimaryKeyFields(); int size = targetPrimaryKeyFields.size(); for (int index = 0; index < size; index++) { DatabaseField targetPrimaryKey = targetPrimaryKeyFields.get(index); Object targetKeyValue = getReferenceDescriptor().getObjectBuilder().extractValueFromObjectForField(orderChangedObject, targetPrimaryKey, query.getSession()); databaseRow.put(targetPrimaryKey, targetKeyValue); } databaseRow.put(listOrderField, orderIndex); query.getSession().executeQuery(changeOrderTargetQuery, databaseRow); }
/** * Force instantiation of the load group. */ @Override public void load(final Object object, AttributeItem item, final AbstractSession session, final boolean fromFetchGroup) { instantiateAttribute(object, session); if (item.getGroup() != null && (!fromFetchGroup || session.isUnitOfWork()) ){ //if UOW make sure the nested attributes are loaded as the clones will not be instantiated Object value = getRealAttributeValueFromObject(object, session); ContainerPolicy cp = this.containerPolicy; for (Object iterator = cp.iteratorFor(value); cp.hasNext(iterator);) { Object wrappedObject = cp.nextEntry(iterator, session); Object nestedObject = cp.unwrapIteratorResult(wrappedObject); session.load(nestedObject, item.getGroup(nestedObject.getClass()), getReferenceDescriptor(), fromFetchGroup); } } }
/** * Force instantiation of the load group. */ @Override public void load(final Object object, AttributeItem item, final AbstractSession session, final boolean fromFetchGroup) { instantiateAttribute(object, session); if (item.getGroup() != null && (!fromFetchGroup || session.isUnitOfWork()) ){ //if UOW make sure the nested attributes are loaded as the clones will not be instantiated Object value = getRealAttributeValueFromObject(object, session); ContainerPolicy cp = this.containerPolicy; for (Object iterator = cp.iteratorFor(value); cp.hasNext(iterator);) { Object wrappedObject = cp.nextEntry(iterator, session); Object nestedObject = cp.unwrapIteratorResult(wrappedObject); session.load(nestedObject, item.getGroup(nestedObject.getClass()), getReferenceDescriptor(), fromFetchGroup); } } }
/** * Force instantiation of all indirections. */ @Override public void loadAll(Object object, AbstractSession session, IdentityHashSet loaded) { instantiateAttribute(object, session); ClassDescriptor referenceDescriptor = getReferenceDescriptor(); if (referenceDescriptor != null) { boolean hasInheritance = referenceDescriptor.hasInheritance() || referenceDescriptor.hasTablePerClassPolicy(); Object value = getRealAttributeValueFromObject(object, session); ContainerPolicy cp = this.containerPolicy; for (Object iterator = cp.iteratorFor(value); cp.hasNext(iterator);) { Object wrappedObject = cp.nextEntry(iterator, session); Object nestedObject = cp.unwrapIteratorResult(wrappedObject); if (hasInheritance && !nestedObject.getClass().equals(referenceDescriptor.getJavaClass())){ ClassDescriptor concreteReferenceDescriptor = referenceDescriptor.getInheritancePolicy().getDescriptor(nestedObject.getClass()); concreteReferenceDescriptor.getObjectBuilder().loadAll(nestedObject, session, loaded); } else { referenceDescriptor.getObjectBuilder().loadAll(nestedObject, session, loaded); } } } }