Methods Summary |
---|
protected boolean | doesObjectExist()INTERNAL:
Return if the object exists on the database or not.
This first checks existence in the chache, then on the database.
boolean doesExist;
if (getSession().isUnitOfWork()) {
doesExist = !((UnitOfWorkImpl)getSession()).isCloneNewObject(getObject());
if (doesExist) {
doesExist = ((UnitOfWorkImpl)getSession()).isObjectRegistered(getObject());
}
} else {
//Initialize does exist query
DoesExistQuery existQuery = (DoesExistQuery)getDescriptor().getQueryManager().getDoesExistQuery().clone();
existQuery.setObject(getObject());
existQuery.setPrimaryKey(getPrimaryKey());
existQuery.setDescriptor(getDescriptor());
existQuery.setTranslationRow(getTranslationRow());
doesExist = ((Boolean)getSession().executeQuery(existQuery)).booleanValue();
}
return doesExist;
|
public void | executeCommit()INTERNAL:
Decide whether to perform an insert, update or delete and
delegate the work to the mechanism.
boolean doesExist = doesObjectExist();
boolean shouldBeDeleted = shouldObjectBeDeleted();
// Do insert, update or delete
if (doesExist) {
if (shouldBeDeleted) {
// Must do a delete
getQueryMechanism().deleteObjectForWrite();
} else {
// Must do an update
getQueryMechanism().updateObjectForWrite();
}
} else if (!shouldBeDeleted) {
// Must do an insert
getQueryMechanism().insertObjectForWrite();
}
|
public void | executeCommitWithChangeSet()INTERNAL:
Perform a does exist check to decide whether to perform an insert or update and
delegate the work to the mechanism.
// Do insert of update
if (!getObjectChangeSet().isNew()) {
// Must do an update
if (!getSession().getCommitManager().isCommitInPreModify(objectChangeSet)) {
//If the changeSet is in the PreModify then it is in the process of being written
getQueryMechanism().updateObjectForWriteWithChangeSet();
}
} else {
// check whether the object is already being committed -
// if it is and it is new, then a shallow insert must be done
if (getSession().getCommitManager().isCommitInPreModify(objectChangeSet)) {
// a shallow insert must be performed
this.dontCascadeParts();
getQueryMechanism().insertObjectForWriteWithChangeSet();
getSession().getCommitManager().markShallowCommit(object);
} else {
// Must do an insert
getQueryMechanism().insertObjectForWriteWithChangeSet();
}
}
|
public java.lang.Object | executeDatabaseQuery()INTERNAL:
Perform a does exist check to decide whether to perform an insert or update and
delegate the work to the mechanism. Does exists check will also perform an
optimistic lock check if required.
if (getObjectChangeSet() != null) {
return getQueryMechanism().executeWriteWithChangeSet();
} else {
return getQueryMechanism().executeWrite();
}
|
public void | executeShallowWrite()INTERNAL:
Perform a shallow write. The decision, which shallow action should be
executed is based on the existence of the associated object. If
the object exists, perform a shallow delete. Do a shallow
insert otherwise.
Note that there currently is *no* shallow update operation.
If shallow updates become necessary, the decision logic must
also perform a delete check as in {@link this.executeCommit}.
boolean doesExist = doesObjectExist();
// Shallow writes only occur for inserts or deletes
if (doesExist) {
getQueryMechanism().shallowDeleteObjectForWrite(getObject(), this, getSession().getCommitManager());
} else {
getQueryMechanism().shallowInsertObjectForWrite(getObject(), this, getSession().getCommitManager());
}
|
public boolean | isWriteObjectQuery()PUBLIC:
Return if this is a write object query.
return true;
|
public void | prepareForExecution()INTERNAL:
Prepare the receiver for execution in a session.
super.prepareForExecution();
// Set the tranlation row, it may already be set in the custom query situation.
if ((getTranslationRow() == null) || (getTranslationRow().isEmpty())) {
setTranslationRow(getDescriptor().getObjectBuilder().buildRowForTranslation(getObject(), getSession()));
}
|
public boolean | shouldDependentObjectBeDeleted(java.lang.Object object)INTERNAL:
Return whether a dependent object should be deleted from the database or not.
Dependent objects should not be removed if not already scheduled for removal in a UoW.
Returns "true" outside a UoW. Used by relationship mappings when cascading a delete operation.
boolean shouldBeDeleted;
if (getSession().isUnitOfWork()) {
shouldBeDeleted = ((UnitOfWorkImpl)getSession()).isObjectDeleted(object);
} else {
// Deletes are cascaded outside a UoW
shouldBeDeleted = true;
}
return shouldBeDeleted;
|
protected boolean | shouldObjectBeDeleted()INTERNAL:
Return if the attached object should be deleted from the database or not.
This information is available only, if the session is a UoW. Returns "false" outside a UoW.
In this case an existence check should be performed and either an insert or update executed.
Only used internally.
boolean shouldBeDeleted;
if (getSession().isUnitOfWork()) {
shouldBeDeleted = ((UnitOfWorkImpl)getSession()).isObjectDeleted(getObject());
} else {
// Deletes must be explicitly user defined outside a UoW
shouldBeDeleted = false;
}
return shouldBeDeleted;
|