/** * INTERNAL: * Set the properties needed to be cascaded into the custom query. */ protected void prepareCustomQuery(DatabaseQuery customQuery) { UpdateObjectQuery customUpdateQuery = (UpdateObjectQuery)customQuery; customUpdateQuery.setObject(getObject()); customUpdateQuery.setObjectChangeSet(getObjectChangeSet()); customUpdateQuery.setCascadePolicy(getCascadePolicy()); customUpdateQuery.setShouldMaintainCache(shouldMaintainCache()); customUpdateQuery.setModifyRow(null); }
protected void objectUnchangedDuringUpdate(ObjectLevelModifyQuery query, Object object, Object backupClone) throws DatabaseException, OptimisticLockException { // Always write for updates, either private or in uow if calling this method. UpdateObjectQuery updateQuery = new UpdateObjectQuery(); updateQuery.setIsExecutionClone(true); updateQuery.setBackupClone(backupClone); prepareModifyQueryForUpdate(query, updateQuery, object); query.getSession().executeQuery(updateQuery, updateQuery.getTranslationRow()); }
/** * INTERNAL: * Check to see if a custom query should be used for this query. * This is done before the query is copied and prepared/executed. * null means there is none. */ protected DatabaseQuery checkForCustomQuery(AbstractSession session, AbstractRecord translationRow) { checkDescriptor(session); // check if user defined a custom query DescriptorQueryManager queryManager = this.descriptor.getQueryManager(); if ((!isCallQuery())// this is not a hand-coded (custom SQL, SDK etc.) call && (!isUserDefined())// and this is not a user-defined query (in the query manager) && queryManager.hasUpdateQuery()) {// and there is a user-defined query (in the query manager) return queryManager.getUpdateQuery(); } return null; }
/** * INTERNAL: * Perform an update. */ public void executeCommit() throws DatabaseException, OptimisticLockException { // Check for redirection. QueryRedirector localRedirector = getRedirectorForQuery(); // refactored redirection for bug 3241138 if ( localRedirector!= null) { redirectQuery(localRedirector, this, session, translationRow); return; } getQueryMechanism().updateObjectForWrite(); }
/** * INTERNAL: * Perform an update. */ public void executeCommit() throws DatabaseException, OptimisticLockException { // Check for redirection. QueryRedirector localRedirector = getRedirector(); // refactored redirection for bug 3241138 if ( localRedirector!= null) { redirectQuery(localRedirector, this, session, translationRow); return; } getQueryMechanism().updateObjectForWrite(); }
/** * INTERNAL: Generates the update stored procedure for this descriptor */ protected StoredProcedureDefinition generateUpdateStoredProcedure(ClassDescriptor descriptor) { UpdateObjectQuery updateQuery = new UpdateObjectQuery(); updateQuery.setDescriptor(descriptor); updateQuery.setModifyRow(descriptor.getObjectBuilder().buildTemplateUpdateRow(getSession())); return this.generateObjectStoredProcedure(updateQuery, descriptor.getFields(), "UPD_"); }
/** * PUBLIC: * Update the object and all of its privately owned parts in the database. * Update should only be used if the application knows that the object is new, * otherwise writeObject should be used. * The update operation can be customized through using an update query. * * @exception DatabaseException if an error occurs on the database, * these include constraint violations, security violations and general database errors. * @exception OptimisticLockException if the object's descriptor is using optimistic locking and * the object has been updated or deleted by another user since it was last read. * * @see UpdateObjectQuery * @see #writeObject(Object) */ public Object updateObject(Object domainObject) throws DatabaseException, OptimisticLockException { UpdateObjectQuery query = new UpdateObjectQuery(); query.setObject(domainObject); query.setIsExecutionClone(true); return executeQuery(query); }
method.addLine("descriptor.getQueryManager().setInsertCall(insertCall);"); if (descriptor.getQueryManager().hasUpdateQuery() && descriptor.getQueryManager().getUpdateQuery().isSQLCallQuery()) { method.addLine("descriptor.getQueryManager().setUpdateSQLString(\"" + constructValidSQLorEJBQLLinesForJavaSource(descriptor.getQueryManager().getUpdateQuery().getSQLString()) + "\");"); } else if (descriptor.getQueryManager().hasUpdateQuery() && descriptor.getQueryManager().getUpdateQuery().getDatasourceCall() instanceof XMLInteraction) { addXMLInteractionLines(method, (XMLInteraction)descriptor.getQueryManager().getUpdateQuery().getDatasourceCall(), "updateCall"); method.addLine("descriptor.getQueryManager().setUpdateCall(updateCall);"); method.addLine("descriptor.getQueryManager().setDeleteSQLString(\"" + constructValidSQLorEJBQLLinesForJavaSource(descriptor.getQueryManager().getDeleteQuery().getSQLString()) + "\");"); } else if (descriptor.getQueryManager().hasDeleteQuery() && descriptor.getQueryManager().getUpdateQuery().getDatasourceCall() instanceof XMLInteraction) { addXMLInteractionLines(method, (XMLInteraction)descriptor.getQueryManager().getDeleteQuery().getDatasourceCall(), "deleteCall"); method.addLine("descriptor.getQueryManager().setDeleteCall(deleteCall);");
private static boolean isSoftDeleted(final DescriptorEvent event) { final ObjectChangeSet changeSet = ((UpdateObjectQuery) event.getQuery()).getObjectChangeSet(); final List<DirectToFieldChangeRecord> changes = changeSet.getChanges().stream() .filter(record -> record instanceof DirectToFieldChangeRecord) .map(record -> (DirectToFieldChangeRecord) record).collect(Collectors.toList()); return changes.stream().filter(record -> DELETED_PROPERTY.equals(record.getAttribute()) && Boolean.parseBoolean(record.getNewValue().toString())).count() > 0; }
public void preUpdateWithChanges(DescriptorEvent event) { if (event.getQuery() instanceof UpdateObjectQuery) { UpdateObjectQuery query = (UpdateObjectQuery) event.getQuery(); for (ChangeRecord cr : query.getObjectChangeSet().getChanges()) { String clazz = query.getObject().getClass().getSimpleName(); Object id = query.getObjectChangeSet().getId(); Object newValue = PropertyUtils.getProperty(query.getObject(), cr.getAttribute()); Object oldVal = cr.getOldValue(); } }
/** * ADVANCED: * Set the receiver's update call. * This allows the user to override the update operation. */ public void setUpdateCall(Call call) { if (call == null) { return; } UpdateObjectQuery query = new UpdateObjectQuery(); query.setCall(call); setUpdateQuery(query); }
/** * ADVANCED: * Set the receiver's update SQL string. * This allows the user to override the SQL generated by EclipseLink, with there own SQL or procedure call. * The arguments are translated from the fields of the source row, * through replacing the field names marked by '#' with the values for those fields. * This must check the optimistic lock field and raise an error on optimistic lock failure. * Warning: Allowing an unverified SQL string to be passed into this * method makes your application vulnerable to SQL injection attacks. * <p> * Example, "update EMPLOYEE set F_NAME to #F_NAME, L_NAME to #L_NAME where EMPLOYEE_ID = #EMPLOYEE_ID". */ public void setUpdateSQLString(String sqlString) { if (sqlString == null) { return; } UpdateObjectQuery query = new UpdateObjectQuery(); query.setSQLString(sqlString); setUpdateQuery(query); }
/** * INTERNAL: * Prepare the receiver for execution in a session. */ protected void prepare() { super.prepare(); getQueryMechanism().prepareUpdateObject(); }
commitQuery = new InsertObjectQuery(); } else { commitQuery = new UpdateObjectQuery();
manager.setUpdateQuery((UpdateObjectQuery)getUpdateQuery().clone());
/** * ADVANCED: * Return the receiver's update call. * This allows the user to override the update operation. */ public Call getUpdateCall() { if (getUpdateQuery() == null) { return null; } return getUpdateQuery().getDatasourceCall(); }
/** * ADVANCED: * Return the receiver's update SQL string. * This allows the user to override the SQL generated by EclipseLink, with there own SQL or procedure call. * The arguments are translated from the fields of the source row, * through replacing the field names marked by '#' with the values for those fields. * This must check the optimistic lock field and raise an error on optimistic lock failure. * <p> * Example, "update EMPLOYEE set F_NAME to #F_NAME, L_NAME to #L_NAME where EMPLOYEE_ID = #EMPLOYEE_ID". */ public String getUpdateSQLString() { if (getUpdateQuery() == null) { return null; } return getUpdateQuery().getSQLString(); }
/** * INTERNAL: * Perform an update. */ public void executeCommitWithChangeSet() throws DatabaseException, OptimisticLockException { // Check for redirection. QueryRedirector localRedirector = getRedirectorForQuery(); // refactored redirection for bug 3241138 if ( localRedirector!= null) { redirectQuery(localRedirector, this, session, translationRow); return; } getQueryMechanism().updateObjectForWriteWithChangeSet(); }
/** * INTERNAL: Generates the update stored procedure for this descriptor */ protected StoredProcedureDefinition generateUpdateStoredProcedure(ClassDescriptor descriptor) { UpdateObjectQuery updateQuery = new UpdateObjectQuery(); updateQuery.setDescriptor(descriptor); updateQuery.setModifyRow(descriptor.getObjectBuilder().buildTemplateUpdateRow(getSession())); return this.generateObjectStoredProcedure(updateQuery, descriptor.getFields(), "UPD_"); }
/** * PUBLIC: * Update the object and all of its privately owned parts in the database. * Update should only be used if the application knows that the object is new, * otherwise writeObject should be used. * The update operation can be customized through using an update query. * * @exception DatabaseException if an error occurs on the database, * these include constraint violations, security violations and general database errors. * @exception OptimisticLockException if the object's descriptor is using optimistic locking and * the object has been updated or deleted by another user since it was last read. * * @see UpdateObjectQuery * @see #writeObject(Object) */ public Object updateObject(Object domainObject) throws DatabaseException, OptimisticLockException { UpdateObjectQuery query = new UpdateObjectQuery(); query.setObject(domainObject); query.setIsExecutionClone(true); return executeQuery(query); }