protected void addHistoryPolicyLines(NonreflectiveMethodDefinition method, ManyToManyMapping mapping, String mappingName) { if (mapping.getHistoryPolicy() == null) { return; } String policyName = mapping.getAttributeName() + "HistoryPolicy"; addHistoryPolicyLines(method, mapping.getHistoryPolicy(), policyName); method.addLine(mappingName + ".setHistoryPolicy(" + policyName + ");"); }
protected void addHistoryPolicyLines(NonreflectiveMethodDefinition method, ManyToManyMapping mapping, String mappingName) { if (mapping.getHistoryPolicy() == null) { return; } String policyName = mapping.getAttributeName() + "HistoryPolicy"; addHistoryPolicyLines(method, mapping.getHistoryPolicy(), policyName); method.addLine(mappingName + ".setHistoryPolicy(" + policyName + ");"); }
protected void addHistoryPolicyLines(NonreflectiveMethodDefinition method, ManyToManyMapping mapping, String mappingName) { if (mapping.getHistoryPolicy() == null) { return; } String policyName = mapping.getAttributeName() + "HistoryPolicy"; addHistoryPolicyLines(method, mapping.getHistoryPolicy(), policyName); method.addLine(mappingName + ".setHistoryPolicy(" + policyName + ");"); }
/** * INTERNAL: * Perform the commit event. * This is used in the uow to delay data modifications. */ @Override public void performDataModificationEvent(Object[] event, AbstractSession session) throws DatabaseException, DescriptorException { // Hey I might actually want to use an inner class here... ok array for now. if (event[0] == PostInsert) { insertIntoRelationTable((WriteObjectQuery)event[1]); } else if (event[0] == ObjectRemoved) { session.executeQuery((DataModifyQuery)event[1], (AbstractRecord)event[2]); if ((getHistoryPolicy() != null) && getHistoryPolicy().shouldHandleWrites()) { getHistoryPolicy().mappingLogicalDelete((DataModifyQuery)event[1], (AbstractRecord)event[2], session); } } else if (event[0] == ObjectAdded) { insertAddedObjectEntry((WriteObjectQuery)event[1], event[2], (Map)event[3]); } else { throw DescriptorException.invalidDataModificationEventCode(event[0], this); } }
/** * INTERNAL: * Perform the commit event. * This is used in the uow to delay data modifications. */ @Override public void performDataModificationEvent(Object[] event, AbstractSession session) throws DatabaseException, DescriptorException { // Hey I might actually want to use an inner class here... ok array for now. if (event[0] == PostInsert) { insertIntoRelationTable((WriteObjectQuery)event[1]); } else if (event[0] == ObjectRemoved) { session.executeQuery((DataModifyQuery)event[1], (AbstractRecord)event[2]); if ((getHistoryPolicy() != null) && getHistoryPolicy().shouldHandleWrites()) { getHistoryPolicy().mappingLogicalDelete((DataModifyQuery)event[1], (AbstractRecord)event[2], session); } } else if (event[0] == ObjectAdded) { insertAddedObjectEntry((WriteObjectQuery)event[1], event[2], (Map)event[3]); } else { throw DescriptorException.invalidDataModificationEventCode(event[0], this); } }
/** * INTERNAL: * Returns the join criteria stored in the mapping selection query. This criteria * is used to read reference objects across the tables from the database. */ public Expression getJoinCriteria(QueryKeyExpression exp) { if (getHistoryPolicy() != null) { Expression result = super.getJoinCriteria(exp); Expression historyCriteria = getHistoryPolicy().additionalHistoryExpression(exp); if (result != null) { return result.and(historyCriteria); } else if (historyCriteria != null) { return historyCriteria; } else { return null; } } else { return super.getJoinCriteria(exp); } }
/** * INTERNAL: * Perform the commit event. * This is used in the uow to delay data modifications. */ public void performDataModificationEvent(Object[] event, AbstractSession session) throws DatabaseException, DescriptorException { // Hey I might actually want to use an inner class here... ok array for now. if (event[0] == PostInsert) { insertIntoRelationTable((WriteObjectQuery)event[1]); } else if (event[0] == ObjectRemoved) { session.executeQuery((DataModifyQuery)event[1], (AbstractRecord)event[2]); if ((getHistoryPolicy() != null) && getHistoryPolicy().shouldHandleWrites()) { getHistoryPolicy().mappingLogicalDelete((DataModifyQuery)event[1], (AbstractRecord)event[2], session); } } else if (event[0] == ObjectAdded) { insertAddedObjectEntry((WriteObjectQuery)event[1], event[2], (Map)event[3]); } else { throw DescriptorException.invalidDataModificationEventCode(event[0], this); } }
/** * INTERNAL: * Returns the join criteria stored in the mapping selection query. This criteria * is used to read reference objects across the tables from the database. */ @Override public Expression getJoinCriteria(ObjectExpression context, Expression base) { if (getHistoryPolicy() != null) { Expression result = super.getJoinCriteria(context, base); Expression historyCriteria = getHistoryPolicy().additionalHistoryExpression(context, base); if (result != null) { return result.and(historyCriteria); } else if (historyCriteria != null) { return historyCriteria; } else { return null; } } else { return super.getJoinCriteria(context, base); } }
/** * INTERNAL: * Returns the join criteria stored in the mapping selection query. This criteria * is used to read reference objects across the tables from the database. */ @Override public Expression getJoinCriteria(ObjectExpression context, Expression base) { if (getHistoryPolicy() != null) { Expression result = super.getJoinCriteria(context, base); Expression historyCriteria = getHistoryPolicy().additionalHistoryExpression(context, base); if (result != null) { return result.and(historyCriteria); } else if (historyCriteria != null) { return historyCriteria; } else { return null; } } else { return super.getJoinCriteria(context, base); } }
/** * INTERNAL: * This method is called to update collection tables prior to commit. */ @Override public void earlyPreDelete(DeleteObjectQuery query){ AbstractSession querySession = query.getSession(); prepareTranslationRow(query.getTranslationRow(), query.getObject(), querySession); querySession.executeQuery(getDeleteAllQuery(), query.getTranslationRow()); if ((getHistoryPolicy() != null) && getHistoryPolicy().shouldHandleWrites()) { getHistoryPolicy().mappingLogicalDelete(getDeleteAllQuery(), query.getTranslationRow(), querySession); } } /**
/** * INTERNAL: * Add additional fields and check for history. */ protected void postPrepareNestedBatchQuery(ReadQuery batchQuery, ReadAllQuery query) { ReadAllQuery mappingBatchQuery = (ReadAllQuery)batchQuery; mappingBatchQuery.setShouldIncludeData(true); for (Enumeration relationFieldsEnum = getSourceRelationKeyFields().elements(); relationFieldsEnum.hasMoreElements();) { mappingBatchQuery.getAdditionalFields().add(mappingBatchQuery.getExpressionBuilder().getTable(getRelationTable()).getField((DatabaseField)relationFieldsEnum.nextElement())); } if (getHistoryPolicy() != null) { ExpressionBuilder builder = mappingBatchQuery.getExpressionBuilder(); Expression twisted = batchQuery.getSelectionCriteria(); if (query.getSession().getAsOfClause() != null) { builder.asOf(query.getSession().getAsOfClause()); } else if (builder.getAsOfClause() == null) { builder.asOf(AsOfClause.NO_CLAUSE); } twisted = twisted.and(getHistoryPolicy().additionalHistoryExpression(builder)); mappingBatchQuery.setSelectionCriteria(twisted); } }
/** * INTERNAL: * An object was added to the collection during an update, insert it. */ protected void insertAddedObjectEntry(ObjectLevelModifyQuery query, Object objectAdded, Map extraData) throws DatabaseException, OptimisticLockException { //cr 3819 added the line below to fix the translationtable to ensure that it // contains the required values prepareTranslationRow(query.getTranslationRow(), query.getObject(), query.getSession()); AbstractRecord databaseRow = this.mechanism.buildRelationTableSourceAndTargetRow(query.getTranslationRow(), containerPolicy.unwrapIteratorResult(objectAdded), query.getSession(), this); ContainerPolicy.copyMapDataToRow(getContainerPolicy().getKeyMappingDataForWriteQuery(objectAdded, query.getSession()), databaseRow); if(listOrderField != null && extraData != null) { databaseRow.put(listOrderField, extraData.get(listOrderField)); } query.getSession().executeQuery(this.mechanism.getInsertQuery(), databaseRow); if ((getHistoryPolicy() != null) && getHistoryPolicy().shouldHandleWrites()) { getHistoryPolicy().mappingLogicalInsert(this.mechanism.getInsertQuery(), databaseRow, query.getSession()); } }
/** * INTERNAL: * An object was added to the collection during an update, insert it. */ protected void insertAddedObjectEntry(ObjectLevelModifyQuery query, Object objectAdded, Map extraData) throws DatabaseException, OptimisticLockException { //cr 3819 added the line below to fix the translationtable to ensure that it // contains the required values prepareTranslationRow(query.getTranslationRow(), query.getObject(), query.getDescriptor(), query.getSession()); AbstractRecord databaseRow = this.mechanism.buildRelationTableSourceAndTargetRow(query.getTranslationRow(), containerPolicy.unwrapIteratorResult(objectAdded), query.getSession(), this); ContainerPolicy.copyMapDataToRow(getContainerPolicy().getKeyMappingDataForWriteQuery(objectAdded, query.getSession()), databaseRow); if(listOrderField != null && extraData != null) { databaseRow.put(listOrderField, extraData.get(listOrderField)); } query.getExecutionSession().executeQuery(this.mechanism.getInsertQuery(), databaseRow); if ((getHistoryPolicy() != null) && getHistoryPolicy().shouldHandleWrites()) { getHistoryPolicy().mappingLogicalInsert(this.mechanism.getInsertQuery(), databaseRow, query.getSession()); } }
/** * INTERNAL: * An object was added to the collection during an update, insert it. */ protected void insertAddedObjectEntry(ObjectLevelModifyQuery query, Object objectAdded, Map extraData) throws DatabaseException, OptimisticLockException { //cr 3819 added the line below to fix the translationtable to ensure that it // contains the required values prepareTranslationRow(query.getTranslationRow(), query.getObject(), query.getDescriptor(), query.getSession()); AbstractRecord databaseRow = this.mechanism.buildRelationTableSourceAndTargetRow(query.getTranslationRow(), containerPolicy.unwrapIteratorResult(objectAdded), query.getSession(), this); ContainerPolicy.copyMapDataToRow(getContainerPolicy().getKeyMappingDataForWriteQuery(objectAdded, query.getSession()), databaseRow); if(listOrderField != null && extraData != null) { databaseRow.put(listOrderField, extraData.get(listOrderField)); } query.getExecutionSession().executeQuery(this.mechanism.getInsertQuery(), databaseRow); if ((getHistoryPolicy() != null) && getHistoryPolicy().shouldHandleWrites()) { getHistoryPolicy().mappingLogicalInsert(this.mechanism.getInsertQuery(), databaseRow, query.getSession()); } }
/** * INTERNAL: * An object was removed to the collection during an update, delete it if private. */ protected void objectRemovedDuringUpdate(ObjectLevelModifyQuery query, Object objectDeleted, Map extraData) throws DatabaseException, OptimisticLockException { Object unwrappedObjectDeleted = getContainerPolicy().unwrapIteratorResult(objectDeleted); AbstractRecord databaseRow = this.mechanism.buildRelationTableSourceAndTargetRow(query.getTranslationRow(), unwrappedObjectDeleted, query.getSession(), this); // In the uow data queries are cached until the end of the commit. if (query.shouldCascadeOnlyDependentParts()) { // Hey I might actually want to use an inner class here... ok array for now. Object[] event = new Object[3]; event[0] = ObjectRemoved; event[1] = this.mechanism.getDeleteQuery(); event[2] = databaseRow; query.getSession().getCommitManager().addDataModificationEvent(this, event); } else { query.getSession().executeQuery(this.mechanism.getDeleteQuery(), databaseRow); if ((getHistoryPolicy() != null) && getHistoryPolicy().shouldHandleWrites()) { getHistoryPolicy().mappingLogicalDelete(this.mechanism.getDeleteQuery(), databaseRow, query.getSession()); } } // Delete object after join entry is delete if private. super.objectRemovedDuringUpdate(query, objectDeleted, extraData); }
/** * INTERNAL: * An object was removed to the collection during an update, delete it if private. */ @Override protected void objectRemovedDuringUpdate(ObjectLevelModifyQuery query, Object objectDeleted, Map extraData) throws DatabaseException, OptimisticLockException { Object unwrappedObjectDeleted = getContainerPolicy().unwrapIteratorResult(objectDeleted); AbstractRecord databaseRow = this.mechanism.buildRelationTableSourceAndTargetRow(query.getTranslationRow(), unwrappedObjectDeleted, query.getSession(), this); // In the uow data queries are cached until the end of the commit. if (query.shouldCascadeOnlyDependentParts()) { // Hey I might actually want to use an inner class here... ok array for now. Object[] event = new Object[3]; event[0] = ObjectRemoved; event[1] = this.mechanism.getDeleteQuery(); event[2] = databaseRow; query.getSession().getCommitManager().addDataModificationEvent(this, event); } else { query.getSession().executeQuery(this.mechanism.getDeleteQuery(), databaseRow); if ((getHistoryPolicy() != null) && getHistoryPolicy().shouldHandleWrites()) { getHistoryPolicy().mappingLogicalDelete(this.mechanism.getDeleteQuery(), databaseRow, query.getSession()); } } // Delete object after join entry is delete if private. super.objectRemovedDuringUpdate(query, objectDeleted, extraData); }
/** * INTERNAL: * An object was removed to the collection during an update, delete it if private. */ @Override protected void objectRemovedDuringUpdate(ObjectLevelModifyQuery query, Object objectDeleted, Map extraData) throws DatabaseException, OptimisticLockException { Object unwrappedObjectDeleted = getContainerPolicy().unwrapIteratorResult(objectDeleted); AbstractRecord databaseRow = this.mechanism.buildRelationTableSourceAndTargetRow(query.getTranslationRow(), unwrappedObjectDeleted, query.getSession(), this); // In the uow data queries are cached until the end of the commit. if (query.shouldCascadeOnlyDependentParts()) { // Hey I might actually want to use an inner class here... ok array for now. Object[] event = new Object[3]; event[0] = ObjectRemoved; event[1] = this.mechanism.getDeleteQuery(); event[2] = databaseRow; query.getSession().getCommitManager().addDataModificationEvent(this, event); } else { query.getSession().executeQuery(this.mechanism.getDeleteQuery(), databaseRow); if ((getHistoryPolicy() != null) && getHistoryPolicy().shouldHandleWrites()) { getHistoryPolicy().mappingLogicalDelete(this.mechanism.getDeleteQuery(), databaseRow, query.getSession()); } } // Delete object after join entry is delete if private. super.objectRemovedDuringUpdate(query, objectDeleted, extraData); }
/** * INTERNAL: * Append the temporal selection to the query selection criteria. */ protected ReadQuery prepareHistoricalQuery(ReadQuery targetQuery, ObjectBuildingQuery sourceQuery, AbstractSession executionSession) { if (getHistoryPolicy() != null) { if (targetQuery == getSelectionQuery()) { targetQuery = (ObjectLevelReadQuery)targetQuery.clone(); targetQuery.setIsExecutionClone(true); } if (targetQuery.getSelectionCriteria() == getSelectionQuery().getSelectionCriteria()) { targetQuery.setSelectionCriteria((Expression)targetQuery.getSelectionCriteria().clone()); } if (sourceQuery.getSession().getAsOfClause() != null) { ((ObjectLevelReadQuery)targetQuery).setAsOfClause(sourceQuery.getSession().getAsOfClause()); } else if (((ObjectLevelReadQuery)targetQuery).getAsOfClause() == null) { ((ObjectLevelReadQuery)targetQuery).setAsOfClause(AsOfClause.NO_CLAUSE); } Expression temporalExpression = (this).getHistoryPolicy().additionalHistoryExpression(targetQuery.getSelectionCriteria().getBuilder()); targetQuery.setSelectionCriteria(targetQuery.getSelectionCriteria().and(temporalExpression)); } return targetQuery; } }
/** * INTERNAL: * Append the temporal selection to the query selection criteria. */ @Override protected ReadQuery prepareHistoricalQuery(ReadQuery targetQuery, ObjectBuildingQuery sourceQuery, AbstractSession executionSession) { if (getHistoryPolicy() != null) { if (targetQuery == getSelectionQuery()) { targetQuery = (ObjectLevelReadQuery)targetQuery.clone(); targetQuery.setIsExecutionClone(true); } if (targetQuery.getSelectionCriteria() == getSelectionQuery().getSelectionCriteria()) { targetQuery.setSelectionCriteria((Expression)targetQuery.getSelectionCriteria().clone()); } if (sourceQuery.getSession().getAsOfClause() != null) { ((ObjectLevelReadQuery)targetQuery).setAsOfClause(sourceQuery.getSession().getAsOfClause()); } else if (((ObjectLevelReadQuery)targetQuery).getAsOfClause() == null) { ((ObjectLevelReadQuery)targetQuery).setAsOfClause(AsOfClause.NO_CLAUSE); } Expression temporalExpression = (this).getHistoryPolicy().additionalHistoryExpression(targetQuery.getSelectionCriteria().getBuilder(), targetQuery.getSelectionCriteria().getBuilder()); targetQuery.setSelectionCriteria(targetQuery.getSelectionCriteria().and(temporalExpression)); } return targetQuery; } }
/** * INTERNAL: * Append the temporal selection to the query selection criteria. */ @Override protected ReadQuery prepareHistoricalQuery(ReadQuery targetQuery, ObjectBuildingQuery sourceQuery, AbstractSession executionSession) { if (getHistoryPolicy() != null) { if (targetQuery == getSelectionQuery()) { targetQuery = (ObjectLevelReadQuery)targetQuery.clone(); targetQuery.setIsExecutionClone(true); } if (targetQuery.getSelectionCriteria() == getSelectionQuery().getSelectionCriteria()) { targetQuery.setSelectionCriteria((Expression)targetQuery.getSelectionCriteria().clone()); } if (sourceQuery.getSession().getAsOfClause() != null) { ((ObjectLevelReadQuery)targetQuery).setAsOfClause(sourceQuery.getSession().getAsOfClause()); } else if (((ObjectLevelReadQuery)targetQuery).getAsOfClause() == null) { ((ObjectLevelReadQuery)targetQuery).setAsOfClause(AsOfClause.NO_CLAUSE); } Expression temporalExpression = (this).getHistoryPolicy().additionalHistoryExpression(targetQuery.getSelectionCriteria().getBuilder(), targetQuery.getSelectionCriteria().getBuilder()); targetQuery.setSelectionCriteria(targetQuery.getSelectionCriteria().and(temporalExpression)); } return targetQuery; } }