1 21 package oracle.toplink.essentials.queryframework; 23 24 import oracle.toplink.essentials.exceptions.*; 25 import oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl; 26 27 41 public class WriteObjectQuery extends ObjectLevelModifyQuery { 42 public WriteObjectQuery() { 43 super(); 44 } 45 46 public WriteObjectQuery(Object objectToWrite) { 47 this(); 48 setObject(objectToWrite); 49 } 50 51 public WriteObjectQuery(Call call) { 52 this(); 53 setCall(call); 54 } 55 56 65 public Object executeDatabaseQuery() throws DatabaseException, OptimisticLockException { 66 if (getObjectChangeSet() != null) { 67 return getQueryMechanism().executeWriteWithChangeSet(); 68 } else { 69 return getQueryMechanism().executeWrite(); 70 } 71 } 72 73 78 public void executeCommit() throws DatabaseException, OptimisticLockException { 79 boolean doesExist; 80 81 if (getSession().isUnitOfWork()) { 82 doesExist = !((UnitOfWorkImpl)getSession()).isCloneNewObject(getObject()); 83 if (doesExist) { 84 doesExist = ((UnitOfWorkImpl)getSession()).isObjectRegistered(getObject()); 85 } 86 } else { 87 DoesExistQuery existQuery = (DoesExistQuery)getDescriptor().getQueryManager().getDoesExistQuery().clone(); 89 existQuery.setObject(getObject()); 90 existQuery.setPrimaryKey(getPrimaryKey()); 91 existQuery.setDescriptor(getDescriptor()); 92 existQuery.setTranslationRow(getTranslationRow()); 93 94 doesExist = ((Boolean )getSession().executeQuery(existQuery)).booleanValue(); 95 } 96 97 if (doesExist) { 99 getQueryMechanism().updateObjectForWrite(); 101 } else { 102 getQueryMechanism().insertObjectForWrite(); 104 } 105 } 106 107 112 public void executeCommitWithChangeSet() throws DatabaseException, OptimisticLockException { 113 if (!getObjectChangeSet().isNew()) { 115 if (!getSession().getCommitManager().isCommitInPreModify(objectChangeSet)) { 117 getQueryMechanism().updateObjectForWriteWithChangeSet(); 119 } 120 } else { 121 if (getSession().getCommitManager().isCommitInPreModify(objectChangeSet)) { 124 this.dontCascadeParts(); 126 getQueryMechanism().insertObjectForWriteWithChangeSet(); 127 getSession().getCommitManager().markShallowCommit(object); 128 } else { 129 getQueryMechanism().insertObjectForWriteWithChangeSet(); 131 } 132 } 133 } 134 135 139 public boolean isWriteObjectQuery() { 140 return true; 141 } 142 143 147 public void prepareForExecution() throws QueryException { 148 super.prepareForExecution(); 149 150 if ((getTranslationRow() == null) || (getTranslationRow().isEmpty())) { 152 setTranslationRow(getDescriptor().getObjectBuilder().buildRowForTranslation(getObject(), getSession())); 153 } 154 } 155 } 156 | Popular Tags |