/** * Add the primary key and its value to the databaseRow for all the non default tables. * This method is used while writing into the multiple tables. */ public void addPrimaryKeyForNonDefaultTable(AbstractRecord databaseRow) { // this method has been revised so it calls addPrimaryKeyForNonDefaultTable(DatabaseRow, Object, Session) is similar. // the session and object are null in this case. addPrimaryKeyForNonDefaultTable(databaseRow, null, null); }
/** * Build the row representation of an object. The row built is used only for translations * for the expressions in the expresion framework. */ public AbstractRecord buildRowForTranslation(Object object, AbstractSession session) { AbstractRecord databaseRow = createRecord(); for (Iterator mappings = getPrimaryKeyMappings().iterator(); mappings.hasNext();) { DatabaseMapping mapping = (DatabaseMapping)mappings.next(); if (mapping != null) { mapping.writeFromObjectIntoRow(object, databaseRow, session); } } // If this descriptor has multiple tables then we need to append the primary keys for // the non default tables, this is require for m-m, dc defined in the Builder that prefixes the wrong table name. // Ideally the mappings should take part in building the translation row so they can add required values. addPrimaryKeyForNonDefaultTable(databaseRow, object, session); return databaseRow; }
/** * Build the row representation of an object. */ public AbstractRecord buildRowForWhereClause(ObjectLevelModifyQuery query) { AbstractRecord databaseRow = createRecord(); for (Iterator mappings = getDescriptor().getMappings().iterator(); mappings.hasNext();) { DatabaseMapping mapping = (DatabaseMapping)mappings.next(); mapping.writeFromObjectIntoRowForWhereClause(query, databaseRow); } // If this descriptor has multiple tables then we need to append the primary keys for // the non default tables. if (!getDescriptor().isAggregateDescriptor()) { addPrimaryKeyForNonDefaultTable(databaseRow); } return databaseRow; }
/** * Build the row representation of the object for update. The row built does not * contain entries for uninstantiated attributes. */ public AbstractRecord buildRowForShallowInsertWithChangeSet(AbstractRecord databaseRow, ObjectChangeSet objectChangeSet, AbstractSession session) { for (Iterator changeRecords = objectChangeSet.getChanges().iterator(); changeRecords.hasNext();) { ChangeRecord changeRecord = (ChangeRecord)changeRecords.next(); DatabaseMapping mapping = changeRecord.getMapping(); mapping.writeFromObjectIntoRowForShallowInsertWithChangeRecord(changeRecord, databaseRow, session); } // If this descriptor is involved in inheritence add the class type. if (getDescriptor().hasInheritance()) { getDescriptor().getInheritancePolicy().addClassIndicatorFieldToRow(databaseRow); } // If this descriptor has multiple tables then we need to append the primary keys for // the non default tables. if (!getDescriptor().isAggregateDescriptor()) { addPrimaryKeyForNonDefaultTable(databaseRow); } return databaseRow; }
/** * Build the row representation of the object for update. The row built does not * contain entries for uninstantiated attributes. */ public AbstractRecord buildRowForShallowInsert(AbstractRecord databaseRow, Object object, AbstractSession session) { // PERF: Avoid synchronized enumerator as is concurrency bottleneck. Vector mappings = getDescriptor().getMappings(); int mappingsSize = mappings.size(); for (int index = 0; index < mappingsSize; index++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(index); mapping.writeFromObjectIntoRowForShallowInsert(object, databaseRow, session); } // If this descriptor is involved in inheritence add the class type. if (getDescriptor().hasInheritance()) { getDescriptor().getInheritancePolicy().addClassIndicatorFieldToRow(databaseRow); } // If this descriptor has multiple tables then we need to append the primary keys for // the non default tables. if (!getDescriptor().isAggregateDescriptor()) { addPrimaryKeyForNonDefaultTable(databaseRow); } return databaseRow; }
/** * Build the row representation of an object. */ public AbstractRecord buildRow(AbstractRecord databaseRow, Object object, AbstractSession session) { // PERF: Avoid synchronized enumerator as is concurrency bottleneck. Vector mappings = getDescriptor().getMappings(); int mappingsSize = mappings.size(); for (int index = 0; index < mappingsSize; index++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(index); mapping.writeFromObjectIntoRow(object, databaseRow, session); } // If this descriptor is involved in inheritence add the class type. if (getDescriptor().hasInheritance()) { getDescriptor().getInheritancePolicy().addClassIndicatorFieldToRow(databaseRow); } // If this descriptor has multiple tables then we need to append the primary keys for // the non default tables. if (!getDescriptor().isAggregateDescriptor()) { addPrimaryKeyForNonDefaultTable(databaseRow); } return databaseRow; }
public void buildTemplateInsertRow(AbstractSession session, AbstractRecord databaseRow) { for (Iterator mappings = getDescriptor().getMappings().iterator(); mappings.hasNext();) { DatabaseMapping mapping = (DatabaseMapping)mappings.next(); mapping.writeInsertFieldsIntoRow(databaseRow, session); } // If this descriptor is involved in inheritence add the class type. if (getDescriptor().hasInheritance()) { getDescriptor().getInheritancePolicy().addClassIndicatorFieldToInsertRow(databaseRow); } // If this descriptor has multiple tables then we need to append the primary keys for // the non default tables. if (!getDescriptor().isAggregateDescriptor()) { addPrimaryKeyForNonDefaultTable(databaseRow); } if (getDescriptor().usesOptimisticLocking()) { getDescriptor().getOptimisticLockingPolicy().addLockFieldsToUpdateRow(databaseRow, session); } //** sequencing refactoring if (getDescriptor().usesSequenceNumbers() && session.getSequencing().shouldAcquireValueAfterInsert(getDescriptor().getJavaClass())) { databaseRow.remove(getDescriptor().getSequenceNumberField()); } }
getDescriptor().getObjectBuilder().addPrimaryKeyForNonDefaultTable(getModifyRow());
/** * Update the object's primary key by fetching a new sequence number from the accessor. */ protected void updateObjectAndRowWithSequenceNumber() throws DatabaseException { WriteObjectQuery writeQuery = getWriteObjectQuery(); Object object = writeQuery.getObject(); Object sequenceValue = getDescriptor().getObjectBuilder().assignSequenceNumber(object, getSession()); if (sequenceValue == null) { return; } Vector primaryKeys = getDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(object, getSession()); writeQuery.setPrimaryKey(primaryKeys); DatabaseField sequenceNumberField = getDescriptor().getSequenceNumberField(); // Now I need to update the row getModifyRow().put(sequenceNumberField, sequenceValue); getDescriptor().getObjectBuilder().addPrimaryKeyForNonDefaultTable(getModifyRow()); // update the changeSet if there is one if (getSession().isUnitOfWork()) { ObjectChangeSet objectChangeSet = writeQuery.getObjectChangeSet(); if ((objectChangeSet == null) && (((UnitOfWorkImpl)getSession()).getUnitOfWorkChangeSet() != null)) { objectChangeSet = (ObjectChangeSet)((UnitOfWorkImpl)getSession()).getUnitOfWorkChangeSet().getObjectChangeSetForClone(object); } if (objectChangeSet != null) { updateChangeSet(getDescriptor(), objectChangeSet, sequenceNumberField, object); objectChangeSet.setCacheKey(new CacheKey(primaryKeys)); } } }