CloneCopyPolicypublic class CloneCopyPolicy extends AbstractCopyPolicy Purpose: Creates a clone through a clone method. |
Fields Summary |
---|
protected String | methodNameAllow for clone method to be specified. | protected String | workingCopyMethodName | protected transient Method | method | protected transient Method | workingCopyMethod |
Constructors Summary |
---|
public CloneCopyPolicy()
super();
|
Methods Summary |
---|
public java.lang.Object | buildClone(java.lang.Object domainObject, oracle.toplink.essentials.sessions.Session session)Clone through calling the clone method.
// 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 java.lang.Object | buildWorkingCopyClone(java.lang.Object domainObject, oracle.toplink.essentials.sessions.Session session)Clone through the workingCopyClone method, or if not specified the clone method.
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);
}
| public java.lang.Object | buildWorkingCopyCloneFromRow(oracle.toplink.essentials.sessions.Record row, oracle.toplink.essentials.queryframework.ObjectBuildingQuery query)Create a new instance, unless a workingCopyClone method is specified, then build a new instance and clone it.
// 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();
}
| public boolean | buildsNewInstance()Return false as a shallow clone is returned, not a new instance.
return getMethodName() == null;
| protected java.lang.reflect.Method | getMethod()Return the clone method.
return method;
| public java.lang.String | getMethodName()Return the clone method name.
return methodName;
| protected java.lang.reflect.Method | getWorkingCopyMethod()Return the workingCopyClone method.
This is used to clone within a unit of work.
return workingCopyMethod;
| public java.lang.String | getWorkingCopyMethodName()Return the workingCopyClone method name.
This is used to clone within a unit of work.
return workingCopyMethodName;
| public void | initialize(oracle.toplink.essentials.sessions.Session session)Validate and build the methods.
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));
}
}
| protected void | setMethod(java.lang.reflect.Method method)Set the clone method.
this.method = method;
| public void | setMethodName(java.lang.String methodName)Set the clone method name.
this.methodName = methodName;
| protected void | setWorkingCopyMethod(java.lang.reflect.Method method)Set the workingCopyClone method.
This is used to clone within a unit of work.
this.workingCopyMethod = method;
| public void | setWorkingCopyMethodName(java.lang.String methodName)Set the workingCopyClone method name.
This is used to clone within a unit of work.
this.workingCopyMethodName = methodName;
| public java.lang.String | toString()
return Helper.getShortClassName(this) + "(" + this.getMethodName() + ")";
|
|