* @param mustExist
* if true, throws a {@link MetaDataException} if no metadata is found
*/
public ClassMetaData getMetaData(Object oid, ClassLoader envLoader, boolean mustExist) {
if (oid == null && mustExist)
throw new MetaDataException(_loc.get("no-oid-meta", oid, "?", _oids.toString()));
if (oid == null)
return null;
if (oid instanceof OpenJPAId) {
Class<?> cls = ((OpenJPAId) oid).getType();
return getMetaData(cls, envLoader, mustExist);
}
// check cache
processRegisteredClasses(envLoader);
Class<?> cls = _oids.get(oid.getClass());
if (cls != null)
return getMetaData(cls, envLoader, mustExist);
// maybe this is some type we've seen but just isn't valid
if (_oids.containsKey(oid.getClass())) {
if (mustExist)
throw new MetaDataException(_loc.get("no-oid-meta", oid, oid.getClass(), _oids));
return null;
}
// if still not match, register any classes that look similar to the
// oid class and check again
resolveIdentityClass(oid);
if (processRegisteredClasses(envLoader).length > 0) {
cls = _oids.get(oid.getClass());
if (cls != null)
return getMetaData(cls, envLoader, mustExist);
}
// record that this is an invalid type
_oids.put(oid.getClass(), null);
if (!mustExist)
return null;
throw new MetaDataException(_loc.get("no-oid-meta", oid, oid.getClass(), _oids)).setFailedObject(oid);
}