/** * Build and return the expression to use as the where clause to an update object. * The row is passed to allow the version number to be extracted from it. */ public Expression buildUpdateExpression(DatabaseTable table, AbstractRecord transactionRow, AbstractRecord modifyRow) { // Only the first table must use the lock check. Expression primaryKeyExpression = buildPrimaryKeyExpression(table); if (getDescriptor().usesOptimisticLocking()) { return getDescriptor().getOptimisticLockingPolicy().buildUpdateExpression(table, primaryKeyExpression, transactionRow, modifyRow); } else { return primaryKeyExpression; } }
/** * Build and return the expression to use as the where clause to delete an object. * The row is passed to allow the version number to be extracted from it. */ public Expression buildDeleteExpression(DatabaseTable table, AbstractRecord row) { if (getDescriptor().usesOptimisticLocking() && (getDescriptor().getTables().firstElement().equals(table))) { return getDescriptor().getOptimisticLockingPolicy().buildDeleteExpression(table, primaryKeyExpression, row); } else { return buildPrimaryKeyExpression(table); } }
/** * Update the foreign key fields when resolving a bi-directonal reference in a UOW. * This must always be dynamic as it is called within an insert or delete query and * is really part of the write operation and does not fire update events or worry about locking. */ protected void updateForeignKeyFieldShallow(WriteObjectQuery writeQuery) { for (Enumeration tablesEnum = getDescriptor().getTables().elements(); tablesEnum.hasMoreElements();) { DatabaseTable table = (DatabaseTable)tablesEnum.nextElement(); SQLUpdateStatement updateStatement = new SQLUpdateStatement(); updateStatement.setModifyRow(getModifyRow()); updateStatement.setTranslationRow(getTranslationRow()); updateStatement.setTable(table); updateStatement.setWhereClause(getDescriptor().getObjectBuilder().buildPrimaryKeyExpression(table));// Must not check version, ok as just inserted it. // Bug 2996585 StatementQueryMechanism updateMechanism = new StatementQueryMechanism(writeQuery, updateStatement); writeQuery.setModifyRow(updateStatement.getModifyRow()); updateMechanism.updateObject(); } } }
sqlStatement.setWhereClause((Expression)getPrimaryKeyExpression().clone()); } else { sqlStatement.setWhereClause(buildPrimaryKeyExpression(table));