/** * INTERNAL: * Configures the mapping to used weaved indirection. * This requires that the toplink-agent be used to weave indirection into the class. * This policy is only require for method access. * @param getMethodName is the name of the original (or weaved in field access case) set method for the mapping. * @param setMethodName is the name of the original (or weaved in field access case) set method for the mapping. * @param hasUsedMethodAccess indicates whether method or field access was originally used. */ public void useWeavedIndirection(String getMethodName, String setMethodName, boolean hasUsedMethodAccess){ setIndirectionPolicy(new WeavedObjectBasicIndirectionPolicy(getMethodName, setMethodName, null, hasUsedMethodAccess)); }
/** * Set the value of the appropriate attribute of target to attributeValue. * In this case, place the value inside the target's ValueHolder. * Change tracking will be turned off when this method is called */ public void setRealAttributeValueInObject(Object target, Object attributeValue) { setRealAttributeValueInObject(target, attributeValue, false); }
/** * Return the "real" attribute value, as opposed to any wrapper. * This will trigger the wrapper to instantiate the value. In a weaved policy, this will * also call the initial setter method to coordinate the values of the valueholder with * the underlying data. */ public Object getRealAttributeValueFromObject(Object object, Object attribute) { Object value = super.getRealAttributeValueFromObject(object, attribute); // Provide the indirection policy with a callback that allows it to do any updates it needs as the result of getting the value. updateValueInObject(object, value, attribute); return value; }
if(mapping.isObjectReferenceMapping() && ((ObjectReferenceMapping)mapping).getIndirectionPolicy().isWeavedObjectBasicIndirectionPolicy()) { WeavedObjectBasicIndirectionPolicy weavedIndirectionPolicy = (WeavedObjectBasicIndirectionPolicy)((ObjectReferenceMapping)mapping).getIndirectionPolicy(); if (weavedIndirectionPolicy.hasUsedMethodAccess()) { getMethodName = weavedIndirectionPolicy.getGetMethodName(); setMethodName = weavedIndirectionPolicy.getSetMethodName();
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) { try { AccessController.doPrivileged(new PrivilegedMethodInvoker(getSetMethod(), target, parameters)); } catch (PrivilegedActionException exception) { Exception throwableException = exception.getException(); PrivilegedAccessHelper.invokeMethod(getSetMethod(), target, parameters);
Method getMethod = Helper.getDeclaredMethod(sourceMapping.getDescriptor().getJavaClass(), getGetMethodName(), new Class[0]); parameterTypes[0] = getMethod.getReturnType(); setMethod = Helper.getDeclaredMethod(sourceMapping.getDescriptor().getJavaClass(), setMethodName, parameterTypes);
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) { try { AccessController.doPrivileged(new PrivilegedMethodInvoker(getSetMethod(), target, parameters)); } catch (PrivilegedActionException exception) { Exception throwableException = exception.getException(); PrivilegedAccessHelper.invokeMethod(getSetMethod(), target, parameters);
Method getMethod = Helper.getDeclaredMethod(sourceMapping.getDescriptor().getJavaClass(), getGetMethodName(), new Class[0]); parameterTypes[0] = getMethod.getReturnType(); setMethod = Helper.getDeclaredMethod(sourceMapping.getDescriptor().getJavaClass(), setMethodName, parameterTypes);
/** * Set the value of the appropriate attribute of target to attributeValue. * In this case, place the value inside the target's ValueHolder. * Change tracking will be turned off when this method is called */ @Override public void setRealAttributeValueInObject(Object target, Object attributeValue) { setRealAttributeValueInObject(target, attributeValue, false); }
/** * INTERNAL: * Configures the mapping to used weaved indirection. * This requires that the toplink-agent be used to weave indirection into the class. * This policy is only require for method access. * @param setMethodName is the name of the original set method for the mapping. */ public void useWeavedIndirection(String setMethodName){ setIndirectionPolicy(new WeavedObjectBasicIndirectionPolicy(setMethodName)); }
/** * Return the "real" attribute value, as opposed to any wrapper. * This will trigger the wrapper to instantiate the value. In a weaved policy, this will * also call the initial setter method to coordinate the values of the valueholder with * the underlying data. */ @Override public Object getRealAttributeValueFromObject(Object object, Object attribute) { boolean wasInstantiated = attribute != null && attribute instanceof ValueHolderInterface && ((ValueHolderInterface)attribute).isInstantiated(); Object value = super.getRealAttributeValueFromObject(object, attribute); // Provide the indirection policy with a callback that allows it to do any updates it needs as the result of getting the value. if (!wasInstantiated && (value != attribute)) { //if the attribute was already unwrapped then do not call this method updateValueInObject(object, value, attribute); } return value; }
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) { try { AccessController.doPrivileged(new PrivilegedMethodInvoker(getSetMethod(), target, parameters)); } catch (PrivilegedActionException exception) { Exception throwableException = exception.getException(); PrivilegedAccessHelper.invokeMethod(getSetMethod(), target, parameters);
/** * Coordinate the valueholder for this mapping with the underlying property by calling the * initial setter method. */ public void updateValueInObject(Object object, Object value, Object attributeValue){ setRealAttributeValueInObject(object, value); ((WeavedAttributeValueHolderInterface)attributeValue).setIsCoordinatedWithProperty(true); }
/** * INTERNAL: * Configures the mapping to used weaved indirection. * This requires that the toplink-agent be used to weave indirection into the class. * This policy is only require for method access. * @param getMethodName is the name of the original (or weaved in field access case) set method for the mapping. * @param setMethodName is the name of the original (or weaved in field access case) set method for the mapping. * @param hasUsedMethodAccess indicates whether method or field access was originally used. */ public void useWeavedIndirection(String getMethodName, String setMethodName, boolean hasUsedMethodAccess){ setIndirectionPolicy(new WeavedObjectBasicIndirectionPolicy(getMethodName, setMethodName, null, hasUsedMethodAccess)); }
/** * Return the "real" attribute value, as opposed to any wrapper. * This will trigger the wrapper to instantiate the value. In a weaved policy, this will * also call the initial setter method to coordinate the values of the valueholder with * the underlying data. */ public Object getRealAttributeValueFromObject(Object object, Object attribute) { boolean wasInstantiated = attribute != null && attribute instanceof ValueHolderInterface && ((ValueHolderInterface)attribute).isInstantiated(); Object value = super.getRealAttributeValueFromObject(object, attribute); // Provide the indirection policy with a callback that allows it to do any updates it needs as the result of getting the value. if (!wasInstantiated && (value != attribute)) { //if the attribute was already unwrapped then do not call this method updateValueInObject(object, value, attribute); } return value; }
/** * Coordinate the valueholder for this mapping with the underlying property by calling the * initial setter method. */ public void updateValueInObject(Object object, Object value, Object attributeValue){ setRealAttributeValueInObject(object, value); ((WeavedAttributeValueHolderInterface)attributeValue).setIsCoordinatedWithProperty(true); }
/** * INTERNAL: * Process the indirection (aka fetch type) */ protected void processIndirection(ForeignReferenceMapping mapping) { boolean usesIndirection = usesIndirection(); // Lazy is not disabled until descriptor initialization (OneToOneMapping preInitialize), // as it cannot be known if weaving occurred until then. String actualAttributeType = getAttributeType(); if (getAccessibleObject() != null){ actualAttributeType = getAccessibleObject().getType(); } if (usesIndirection && usesPropertyAccess()) { mapping.setIndirectionPolicy(new WeavedObjectBasicIndirectionPolicy(getGetMethodName(), getSetMethodName(), actualAttributeType, true)); } else if (usesIndirection && usesFieldAccess()) { mapping.setIndirectionPolicy(new WeavedObjectBasicIndirectionPolicy(Helper.getWeavedGetMethodName(mapping.getAttributeName()), Helper.getWeavedSetMethodName(mapping.getAttributeName()), actualAttributeType, false)); } else { mapping.setUsesIndirection(usesIndirection); } }
/** * Coordinate the valueholder for this mapping with the underlying property by calling the * initial setter method. */ public void updateValueInObject(Object object, Object value, Object attributeValue){ setRealAttributeValueInObject(object, value); ((WeavedAttributeValueHolderInterface)attributeValue).setIsCoordinatedWithProperty(true); }