| Method from org.apache.openjpa.util.ImplHelper Detail: |
public static void close(Object o) {
try {
if (o instanceof Closeable)
((Closeable) o).close();
} catch (RuntimeException re) {
throw re;
} catch (Exception e) {
throw new GeneralException(e);
}
}
Close the given resource. The resource can be an extent iterator,
query result, large result set relation, or any closeable OpenJPA
component. |
public static Object generateFieldValue(StoreContext ctx,
FieldMetaData fmd) {
return generateValue(ctx, fmd.getDefiningMetaData(), fmd,
fmd.getDeclaredTypeCode());
}
|
public static Object generateIdentityValue(StoreContext ctx,
ClassMetaData meta,
int typeCode) {
return generateValue(ctx, meta, null, typeCode);
}
|
public static Object getManagedInstance(Object o) {
if (o instanceof ManagedInstanceProvider)
return ((ManagedInstanceProvider) o).getManagedInstance();
else
return o;
}
|
public static BitSet getUpdateFields(OpenJPAStateManager sm) {
if ((sm.getPCState() == PCState.PDIRTY
&& (!sm.isFlushed() || sm.isFlushedDirty()))
|| (sm.getPCState() == PCState.PNEW && sm.isFlushedDirty())) {
BitSet dirty = sm.getDirty();
if (sm.isFlushed()) {
dirty = (BitSet) dirty.clone();
dirty.andNot(sm.getFlushed());
}
if (dirty.length() > 0)
return dirty;
}
return null;
}
Returns the fields of the state that require an update. |
public static boolean isAssignable(Class from,
Class to) {
if (from == null || to == null)
return false;
Boolean isAssignable = null;
Map assignableTo = (Map) _assignableTypes.get(from);
if (assignableTo == null) { // "to" cache doesn't exist, so create it...
assignableTo = new ConcurrentReferenceHashMap(ReferenceMap.WEAK,
ReferenceMap.HARD);
_assignableTypes.put(from, assignableTo);
} else { // "to" cache exists...
isAssignable = (Boolean) assignableTo.get(to);
}
if (isAssignable == null) {// we don't have a record of this pair...
isAssignable = Boolean.valueOf(from.isAssignableFrom(to));
assignableTo.put(to, isAssignable);
}
return isAssignable.booleanValue();
}
Returns true if the referenced "to" class is assignable to the "from"
class. This helper method utilizes a cache to help avoid the overhead
of the Class.isAssignableFrom() method. |
public static boolean isManageable(Object instance) {
return instance instanceof PersistenceCapable
|| instance != null && PCRegistry.isRegistered(instance.getClass());
}
Returns true if the specified instance is manageable. |
public static boolean isManagedType(OpenJPAConfiguration conf,
Class type) {
return (PersistenceCapable.class.isAssignableFrom(type)
|| (type != null
&& (conf == null || conf.getRuntimeUnenhancedClassesConstant()
== RuntimeUnenhancedClasssesModes.SUPPORTED)
&& PCRegistry.isRegistered(type)));
}
Returns true if the specified class is a type that can be managed by
OpenJPA. |
public static Collection loadAll(Collection sms,
StoreManager store,
PCState state,
int load,
FetchConfiguration fetch,
Object context) {
Collection failed = null;
OpenJPAStateManager sm;
LockManager lm;
for (Iterator itr = sms.iterator(); itr.hasNext();) {
sm = (OpenJPAStateManager) itr.next();
if (sm.getManagedInstance() == null) {
if (!store.initialize(sm, state, fetch, context))
failed = addFailedId(sm, failed);
} else if (load != StoreManager.FORCE_LOAD_NONE
|| sm.getPCState() == PCState.HOLLOW) {
lm = sm.getContext().getLockManager();
if (!store.load(sm, sm.getUnloaded(fetch), fetch,
lm.getLockLevel(sm), context))
failed = addFailedId(sm, failed);
} else if (!store.exists(sm, context))
failed = addFailedId(sm, failed);
}
return (failed == null) ? Collections.EMPTY_LIST : failed;
}
Helper for store manager implementations. This method simply delegates
to the proper singular method for each state manager. |
public static void registerPersistenceCapable(ReflectingPersistenceCapable pc) {
_unenhancedInstanceMap.put(pc.getManagedInstance(), pc);
}
|
public static PersistenceCapable toPersistenceCapable(Object o,
Object ctx) {
if (o instanceof PersistenceCapable)
return (PersistenceCapable) o;
OpenJPAConfiguration conf = null;
if (ctx instanceof OpenJPAConfiguration)
conf = (OpenJPAConfiguration) ctx;
else if (ctx instanceof StateManager
&& ((StateManager) ctx).getGenericContext() instanceof StoreContext)
conf = ((StoreContext) ((StateManager) ctx).getGenericContext())
.getConfiguration();
if (!isManageable(o))
return null;
// if we had a putIfAbsent() method, we wouldn't need to sync here
synchronized (o) {
PersistenceCapable pc = (PersistenceCapable)
_unenhancedInstanceMap.get(o);
if (pc != null)
return pc;
// if we don't have a conf passed in, then we can't create a new
// ReflectingPC; this will only be the case when invoked from a
// context outside of OpenJPA.
if (conf == null)
return null;
pc = new ReflectingPersistenceCapable(o, conf);
_unenhancedInstanceMap.put(o, pc);
return pc;
}
}
|