/** * PUBLIC: * Specifies that the creation of clones within a unit of work is done by * sending the cloneMethodName method to the original object. This method * must return a logical shallow copy of the original object. * This can be used if the default mechanism of creating a new instance * does not handle the object's non-persistent attributes correctly. * * @see #useCloneCopyPolicy() */ public void useCloneCopyPolicy(String cloneMethodName) { CloneCopyPolicy policy = new CloneCopyPolicy(); policy.setMethodName(cloneMethodName); setCopyPolicy(policy); }
/** * Return false as a shallow clone is returned, not a new instance. */ public boolean buildsNewInstance() { return getMethodName() == null; }
/** * INTERNAL: */ public CopyPolicy getCopyPolicy() { if (methodName == null && workingCopyMethodName == null){ throw ValidationException.copyPolicyMustSpecifyEitherMethodOrWorkingCopyMethod(getLocation()); } CloneCopyPolicy copyPolicy = new CloneCopyPolicy(); copyPolicy.setMethodName(methodName); copyPolicy.setWorkingCopyMethodName(workingCopyMethodName); return copyPolicy; }
/** * Validate and build the methods. */ public void initialize(Session session) throws DescriptorException { final Class javaClass = this.getDescriptor().getJavaClass(); try { // Must allow for null clone method for 9.0.4 deployment XML. if (this.getMethodName() != null) { this.setMethod(Helper.getDeclaredMethod(javaClass, this.getMethodName(), new Class[0])); } } catch (NoSuchMethodException exception) { session.getIntegrityChecker().handleError(DescriptorException.noSuchMethodWhileInitializingCopyPolicy(this.getMethodName(), this.getDescriptor(), exception)); } catch (SecurityException exception) { session.getIntegrityChecker().handleError(DescriptorException.securityWhileInitializingCopyPolicy(this.getMethodName(), this.getDescriptor(), exception)); } if (this.getWorkingCopyMethodName() != null) { try { this.setWorkingCopyMethod(Helper.getDeclaredMethod(javaClass, this.getWorkingCopyMethodName(), new Class[0])); } catch (NoSuchMethodException exception) { session.getIntegrityChecker().handleError(DescriptorException.noSuchMethodWhileInitializingCopyPolicy(this.getMethodName(), this.getDescriptor(), exception)); } catch (SecurityException exception) { session.getIntegrityChecker().handleError(DescriptorException.securityWhileInitializingCopyPolicy(this.getMethodName(), this.getDescriptor(), exception)); } } }
/** * Clone through the workingCopyClone method, or if not specified the clone method. */ public Object buildWorkingCopyClone(Object domainObject, Session session) throws DescriptorException { if (this.getWorkingCopyMethodName() == null) { //not implemented to perform special operations. return this.buildClone(domainObject, session); } try { if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { return AccessController.doPrivileged(new PrivilegedMethodInvoker(this.getWorkingCopyMethod(), domainObject, new Object[0])); } catch (PrivilegedActionException exception) { Exception throwableException = exception.getException(); if (throwableException instanceof IllegalAccessException) { throw DescriptorException.illegalAccessWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), throwableException); } else { throw DescriptorException.targetInvocationWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), throwableException); } } } else { return PrivilegedAccessHelper.invokeMethod(this.getWorkingCopyMethod(), domainObject, new Object[0]); } } catch (IllegalAccessException exception) { throw DescriptorException.illegalAccessWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), exception); } catch (InvocationTargetException exception) { throw DescriptorException.targetInvocationWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), exception); } }
/** * Create a new instance, unless a workingCopyClone method is specified, then build a new instance and clone it. */ @Override public Object buildWorkingCopyCloneFromRow(Record row, ObjectBuildingQuery query, Object primaryKey, UnitOfWork uow) throws DescriptorException { // For now must preserve CMP code which builds heavy clones with a context. // Also preserve for clients who use the copy policy. ObjectBuilder builder = getDescriptor().getObjectBuilder(); if (getWorkingCopyMethodName() != null) { Object original = builder.buildNewInstance(); builder.buildAttributesIntoShallowObject(original, (AbstractRecord)row, query); return buildWorkingCopyClone(original, query.getSession()); } else { return builder.buildNewInstance(); } }
/** * Clone through calling the clone method. */ public Object buildClone(Object domainObject, Session session) throws DescriptorException { // Must allow for null clone method for 9.0.4 deployment XML. if (this.getMethodName() == null) { return getDescriptor().getObjectBuilder().buildNewInstance(); } try { if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { return AccessController.doPrivileged(new PrivilegedMethodInvoker(this.getMethod(), domainObject, new Object[0])); } catch (PrivilegedActionException exception) { Exception throwableException = exception.getException(); if (throwableException instanceof IllegalAccessException) { throw DescriptorException.illegalAccessWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), throwableException); } else { throw DescriptorException.targetInvocationWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), throwableException); } } } else { return PrivilegedAccessHelper.invokeMethod(this.getMethod(), domainObject, new Object[0]); } } catch (IllegalAccessException exception) { throw DescriptorException.illegalAccessWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), exception); } catch (InvocationTargetException exception) { throw DescriptorException.targetInvocationWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), exception); } }
/** * Validate and build the methods. */ public void initialize(Session session) throws DescriptorException { final Class javaClass = this.getDescriptor().getJavaClass(); try { // Must allow for null clone method for 9.0.4 deployment XML. if (this.getMethodName() != null) { this.setMethod(Helper.getDeclaredMethod(javaClass, this.getMethodName(), new Class[0])); } } catch (NoSuchMethodException exception) { session.getIntegrityChecker().handleError(DescriptorException.noSuchMethodWhileInitializingCopyPolicy(this.getMethodName(), this.getDescriptor(), exception)); } catch (SecurityException exception) { session.getIntegrityChecker().handleError(DescriptorException.securityWhileInitializingCopyPolicy(this.getMethodName(), this.getDescriptor(), exception)); } if (this.getWorkingCopyMethodName() != null) { try { this.setWorkingCopyMethod(Helper.getDeclaredMethod(javaClass, this.getWorkingCopyMethodName(), new Class[0])); } catch (NoSuchMethodException exception) { session.getIntegrityChecker().handleError(DescriptorException.noSuchMethodWhileInitializingCopyPolicy(this.getMethodName(), this.getDescriptor(), exception)); } catch (SecurityException exception) { session.getIntegrityChecker().handleError(DescriptorException.securityWhileInitializingCopyPolicy(this.getMethodName(), this.getDescriptor(), exception)); } } }
/** * Clone through the workingCopyClone method, or if not specified the clone method. */ public Object buildWorkingCopyClone(Object domainObject, Session session) throws DescriptorException { if (this.getWorkingCopyMethodName() == null) { //not implemented to perform special operations. return this.buildClone(domainObject, session); } try { if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { return AccessController.doPrivileged(new PrivilegedMethodInvoker(this.getWorkingCopyMethod(), domainObject, new Object[0])); } catch (PrivilegedActionException exception) { Exception throwableException = exception.getException(); if (throwableException instanceof IllegalAccessException) { throw DescriptorException.illegalAccessWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), throwableException); } else { throw DescriptorException.targetInvocationWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), throwableException); } } } else { return PrivilegedAccessHelper.invokeMethod(this.getWorkingCopyMethod(), domainObject, new Object[0]); } } catch (IllegalAccessException exception) { throw DescriptorException.illegalAccessWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), exception); } catch (InvocationTargetException exception) { throw DescriptorException.targetInvocationWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), exception); } }
/** * Create a new instance, unless a workingCopyClone method is specified, then build a new instance and clone it. */ public Object buildWorkingCopyCloneFromRow(Record row, ObjectBuildingQuery query, Vector primaryKey, UnitOfWork uow) throws DescriptorException { // For now must preserve CMP code which builds heavy clones with a context. // Also preserve for clients who use the copy policy. ObjectBuilder builder = getDescriptor().getObjectBuilder(); if (getWorkingCopyMethodName() != null) { Object original = builder.buildNewInstance(); builder.buildAttributesIntoShallowObject(original, (AbstractRecord)row, query); return buildWorkingCopyClone(original, query.getSession()); } else { return builder.buildNewInstance(); } }
/** * Clone through calling the clone method. */ public Object buildClone(Object domainObject, Session session) throws DescriptorException { // Must allow for null clone method for 9.0.4 deployment XML. if (this.getMethodName() == null) { return getDescriptor().getObjectBuilder().buildNewInstance(); } try { if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { return AccessController.doPrivileged(new PrivilegedMethodInvoker(this.getMethod(), domainObject, new Object[0])); } catch (PrivilegedActionException exception) { Exception throwableException = exception.getException(); if (throwableException instanceof IllegalAccessException) { throw DescriptorException.illegalAccessWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), throwableException); } else { throw DescriptorException.targetInvocationWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), throwableException); } } } else { return PrivilegedAccessHelper.invokeMethod(this.getMethod(), domainObject, new Object[0]); } } catch (IllegalAccessException exception) { throw DescriptorException.illegalAccessWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), exception); } catch (InvocationTargetException exception) { throw DescriptorException.targetInvocationWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), exception); } }
/** * Validate and build the methods. */ public void initialize(Session session) throws DescriptorException { try { // Must allow for null clone method for 9.0.4 deployment XML. if (this.getMethodName() != null) { this.setMethod(Helper.getDeclaredMethod(this.getDescriptor().getJavaClass(), this.getMethodName(), new Class[0])); } } catch (NoSuchMethodException exception) { session.getIntegrityChecker().handleError(DescriptorException.noSuchMethodWhileInitializingCopyPolicy(this.getMethodName(), this.getDescriptor(), exception)); } catch (SecurityException exception) { session.getIntegrityChecker().handleError(DescriptorException.securityWhileInitializingCopyPolicy(this.getMethodName(), this.getDescriptor(), exception)); } if (this.getWorkingCopyMethodName() != null) { try { this.setWorkingCopyMethod(Helper.getDeclaredMethod(this.getDescriptor().getJavaClass(), this.getWorkingCopyMethodName(), new Class[0])); } catch (NoSuchMethodException exception) { session.getIntegrityChecker().handleError(DescriptorException.noSuchMethodWhileInitializingCopyPolicy(this.getMethodName(), this.getDescriptor(), exception)); } catch (SecurityException exception) { session.getIntegrityChecker().handleError(DescriptorException.securityWhileInitializingCopyPolicy(this.getMethodName(), this.getDescriptor(), exception)); } } }
/** * Clone through the workingCopyClone method, or if not specified the clone method. */ public Object buildWorkingCopyClone(Object domainObject, Session session) throws DescriptorException { if (this.getWorkingCopyMethodName() == null) { //not implemented to perform special operations. return this.buildClone(domainObject, session); } try { if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { return AccessController.doPrivileged(new PrivilegedMethodInvoker(this.getWorkingCopyMethod(), domainObject, new Object[0])); } catch (PrivilegedActionException exception) { Exception throwableException = exception.getException(); if (throwableException instanceof IllegalAccessException) { throw DescriptorException.illegalAccessWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), throwableException); } else { throw DescriptorException.targetInvocationWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), throwableException); } } } else { return PrivilegedAccessHelper.invokeMethod(this.getWorkingCopyMethod(), domainObject, new Object[0]); } } catch (IllegalAccessException exception) { throw DescriptorException.illegalAccessWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), exception); } catch (InvocationTargetException exception) { throw DescriptorException.targetInvocationWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), exception); } }
/** * Create a new instance, unless a workingCopyClone method is specified, then build a new instance and clone it. */ @Override public Object buildWorkingCopyCloneFromRow(Record row, ObjectBuildingQuery query, Object primaryKey, UnitOfWork uow) throws DescriptorException { // For now must preserve CMP code which builds heavy clones with a context. // Also preserve for clients who use the copy policy. ObjectBuilder builder = getDescriptor().getObjectBuilder(); if (getWorkingCopyMethodName() != null) { Object original = builder.buildNewInstance(); builder.buildAttributesIntoShallowObject(original, (AbstractRecord)row, query); return buildWorkingCopyClone(original, query.getSession()); } else { return builder.buildNewInstance(); } }
/** * Clone through calling the clone method. */ public Object buildClone(Object domainObject, Session session) throws DescriptorException { // Must allow for null clone method for 9.0.4 deployment XML. if (this.getMethodName() == null) { return getDescriptor().getObjectBuilder().buildNewInstance(); } try { if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { return AccessController.doPrivileged(new PrivilegedMethodInvoker(this.getMethod(), domainObject, new Object[0])); } catch (PrivilegedActionException exception) { Exception throwableException = exception.getException(); if (throwableException instanceof IllegalAccessException) { throw DescriptorException.illegalAccessWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), throwableException); } else { throw DescriptorException.targetInvocationWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), throwableException); } } } else { return PrivilegedAccessHelper.invokeMethod(this.getMethod(), domainObject, new Object[0]); } } catch (IllegalAccessException exception) { throw DescriptorException.illegalAccessWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), exception); } catch (InvocationTargetException exception) { throw DescriptorException.targetInvocationWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), exception); } }
/** * PUBLIC: * Specifies that the creation of clones within a unit of work is done by * sending the cloneMethodName method to the original object. This method * must return a logical shallow copy of the original object. * This can be used if the default mechanism of creating a new instance * does not handle the object's non-persistent attributes correctly. * * @see #useCloneCopyPolicy() */ public void useCloneCopyPolicy(String cloneMethodName) { CloneCopyPolicy policy = new CloneCopyPolicy(); policy.setMethodName(cloneMethodName); setCopyPolicy(policy); }
/** * Return false as a shallow clone is returned, not a new instance. */ public boolean buildsNewInstance() { return getMethodName() == null; }
/** * PUBLIC: * Specifies that the creation of clones within a unit of work is done by * sending the cloneMethodName method to the original object. This method * must return a logical shallow copy of the original object. * This can be used if the default mechanism of creating a new instance * does not handle the object's non-persistent attributes correctly. * * @see #useCloneCopyPolicy() */ public void useCloneCopyPolicy(String cloneMethodName) { CloneCopyPolicy policy = new CloneCopyPolicy(); policy.setMethodName(cloneMethodName); setCopyPolicy(policy); }
/** * Return false as a shallow clone is returned, not a new instance. */ public boolean buildsNewInstance() { return getMethodName() == null; }
public String toString() { return Helper.getShortClassName(this) + "(" + this.getMethodName() + ")"; } }