Methods Summary |
---|
public boolean | addInto(java.lang.Object key, java.lang.Object element, java.lang.Object container, oracle.toplink.essentials.internal.sessions.AbstractSession session)INTERNAL:
Add element into container which implements the Map interface.
Object wrapped = element;
if (hasElementDescriptor()) {
wrapped = getElementDescriptor().getObjectBuilder().wrapObject(element, session);
}
try {
if (key != null) {
return ((Map) container).put(key, wrapped) != null;
} else {
return ((Map) container).put(keyFrom(element, session), wrapped) != null;
}
} catch (ClassCastException ex1) {
throw QueryException.mapKeyNotComparable(element, container);
}
|
public void | clear(java.lang.Object container)INTERNAL:
Remove all the elements from container.
try {
((Map)container).clear();
} catch (UnsupportedOperationException ex) {
throw QueryException.methodNotValid(container, "clear()");
}
|
public boolean | compareKeys(java.lang.Object sourceValue, oracle.toplink.essentials.internal.sessions.AbstractSession session)INTERNAL:
Return true if keys are the same in the source as the backup. False otherwise
in the case of readonly compare against the original
Object backUpVersion = null;
if (((UnitOfWorkImpl)session).isClassReadOnly(sourceValue.getClass())) {
backUpVersion = ((UnitOfWorkImpl)session).getOriginalVersionOfObject(sourceValue);
} else {
backUpVersion = ((UnitOfWorkImpl)session).getBackupClone(sourceValue);
}
return (keyFrom(backUpVersion, session).equals(keyFrom(sourceValue, session)));
|
protected boolean | contains(java.lang.Object element, java.lang.Object container)INTERNAL:
Return the true if element exists in container.
return ((Map)container).containsValue(element);
|
public void | convertClassNamesToClasses(java.lang.ClassLoader classLoader)INTERNAL:
Convert all the class-name-based settings in this ContainerPolicy to
actual class-based settings. This method is used when converting a
project that has been built with class names to a project with classes.
super.convertClassNamesToClasses(classLoader);
if (elementClassName == null){
return;
}
try {
Class elementClass = null;
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
try {
elementClass = (Class)AccessController.doPrivileged(new PrivilegedClassForName(elementClassName, true, classLoader));
} catch (PrivilegedActionException exception) {
throw ValidationException.classNotFoundWhileConvertingClassNames(containerClassName, exception.getException());
}
} else {
elementClass = oracle.toplink.essentials.internal.security.PrivilegedAccessHelper.getClassForName(elementClassName, true, classLoader);
}
setElementClass(elementClass);
} catch (ClassNotFoundException exc){
throw ValidationException.classNotFoundWhileConvertingClassNames(containerClassName, exc);
}
|
public java.lang.Class | getElementClass()INTERNAL:
Returns the element class which defines the map key.
return elementClass;
|
public java.lang.String | getElementClassName()INTERNAL:
Returns the element class name which defines the map key.
return elementClassName;
|
public java.lang.Class | getInterfaceType()INTERNAL:
return ClassConstants.Map_Class;
|
public java.lang.String | getKeyName()INTERNAL:
Returns the key name which will return the value of the key to be used
in the container.
return keyName;
|
public boolean | isMapPolicy()INTERNAL
Yes this is a MapPolicy
return true;
|
public boolean | isValidContainer(java.lang.Object container)INTERNAL:
Validate the container type.
// PERF: Use instanceof which is inlined, not isAssignable which
// is very inefficent.
return container instanceof Map;
|
public java.lang.Object | iteratorFor(java.lang.Object container)INTERNAL:
Return an Iterator for the given container.
return ((Map)container).values().iterator();
|
public java.lang.Object | keyFrom(java.lang.Object element, oracle.toplink.essentials.internal.sessions.AbstractSession session)INTERNAL:
Return the key for the specified element.
// Should only run through this once ...
if (keyName != null && keyMethod == null && keyField == null) {
try {
keyMethod = Helper.getDeclaredMethod(elementClass, keyName, (Class[]) null);
} catch (NoSuchMethodException ex) {
try {
keyField = Helper.getField(elementClass, keyName);
} catch (NoSuchFieldException e) {
throw ValidationException.mapKeyNotDeclaredInItemClass(keyName, elementClass);
}
}
}
Object keyElement = element;
if (hasElementDescriptor()) {
keyElement = getElementDescriptor().getObjectBuilder().unwrapObject(element, session);
}
if (keyMethod != null) {
try {
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
try {
return AccessController.doPrivileged(new PrivilegedMethodInvoker(keyMethod, keyElement, (Object[])null));
} catch (PrivilegedActionException exception) {
Exception throwableException = exception.getException();
if (throwableException instanceof IllegalAccessException) {
throw QueryException.cannotAccessMethodOnObject(keyMethod, keyElement);
} else {
throw QueryException.calledMethodThrewException(keyMethod, keyElement, throwableException);
}
}
} else {
return PrivilegedAccessHelper.invokeMethod(keyMethod, keyElement, (Object[])null);
}
} catch (IllegalAccessException e) {
throw QueryException.cannotAccessMethodOnObject(keyMethod, keyElement);
} catch (InvocationTargetException exception) {
throw QueryException.calledMethodThrewException(keyMethod, keyElement, exception);
}
} else if (keyField != null) {
try {
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
try {
return AccessController.doPrivileged(new PrivilegedGetValueFromField(keyField, keyElement));
} catch (PrivilegedActionException exception) {
throw QueryException.cannotAccessFieldOnObject(keyField, keyElement);
}
} else {
return oracle.toplink.essentials.internal.security.PrivilegedAccessHelper.getValueFromField(keyField, keyElement);
}
} catch (IllegalAccessException e) {
throw QueryException.cannotAccessFieldOnObject(keyField, keyElement);
}
} else {
// If we get this far I think it is safe to assume we have
// an element descriptor.
return ((CMP3Policy) getElementDescriptor().getCMPPolicy()).createPrimaryKeyInstance(keyElement, session);
}
|
public void | prepare(oracle.toplink.essentials.queryframework.DatabaseQuery query, oracle.toplink.essentials.internal.sessions.AbstractSession session)Prepare and validate.
Set the element class.
if ((getElementClass() == null) && (query.getDescriptor() != null)) {
setElementClass(query.getDescriptor().getJavaClass());
}
super.prepare(query, session);
|
public boolean | removeFrom(java.lang.Object key, java.lang.Object element, java.lang.Object container, oracle.toplink.essentials.internal.sessions.AbstractSession session)INTERNAL:
Remove element from container which implements the Map interface.
try {
Object returnValue = null;
if (key != null) {
returnValue = ((Map)container).remove(key);
} else {
returnValue = ((Map)container).remove(keyFrom(element, session));
}
if (returnValue == null) {
return false;
} else {
return true;
}
} catch (UnsupportedOperationException ex) {
throw QueryException.methodNotValid(container, "remove(Object element)");
}
|
public boolean | removeFromWithIdentity(java.lang.Object element, java.lang.Object container, oracle.toplink.essentials.internal.sessions.AbstractSession session)INTERNAL:
Remove element from container which implements the Map interface.
boolean found = false;
Vector knownKeys = new Vector(1);
try {
Iterator iterator = ((Map)container).keySet().iterator();
while (iterator.hasNext()) {
Object key = iterator.next();
if (((Map)container).get(key) == element) {
knownKeys.addElement(key);
found = true;
}
}
if (found) {
for (int index = 0; index < knownKeys.size(); ++index) {
((Map)container).remove(knownKeys.elementAt(index));
}
}
return found;
} catch (UnsupportedOperationException ex) {
throw QueryException.methodNotValid(container, "remove(Object element)");
}
|
public void | setElementClass(java.lang.Class elementClass)INTERNAL:
Sets the element class which defines the method.
if (elementClass != null) {
elementClassName = elementClass.getName();
}
this.elementClass = elementClass;
|
public void | setKeyName(java.lang.String keyName, java.lang.String elementClassName)INTERNAL:
Sets the key name to be used to generate the key in a Map type container
class. The key name, may be the name of a field or method.
// The key name and class name must be held as the policy is used
// directly from the mapping.
this.keyName = keyName;
this.elementClassName = elementClassName;
|
public void | setKeyName(java.lang.String keyName)INTERNAL:
Sets the key name to be used to generate the key in a Map type container
class. The key name, maybe the name of a field or method.
this.keyName = keyName;
|
public int | sizeFor(java.lang.Object container)INTERNAL:
Return the size of container.
return ((Map)container).size();
|
public void | validateElementAndRehashIfRequired(java.lang.Object sourceValue, java.lang.Object targetMap, oracle.toplink.essentials.internal.sessions.AbstractSession session, java.lang.Object targetVersionOfSource)INTERNAL:
If the key has changed, remove the element and add it back into the target.
if (session.isUnitOfWork()) {
//this must be a unit of work at this point
Object backupValue = ((UnitOfWorkImpl)session).getBackupClone(sourceValue);
if (!keyFrom(backupValue, session).equals(keyFrom(sourceValue, session))) {
//the key has been changed. Remove the old value and put back the new one
removeFrom(backupValue, targetMap, session);
addInto(targetVersionOfSource, targetMap, session);
}
}
|