public DetachedValueStateManager(PersistenceCapable pc, ClassMetaData meta, StoreContext ctx) { _pc = ImplHelper.toPersistenceCapable(pc, ctx.getConfiguration()); _meta = meta; _ctx = ctx; }
/** * Return the result object based on its cached oid. */ private static Object fromObjectId(Object oid, StoreContext sctx, FetchConfiguration fc) { if (oid == null) return null; Object obj = sctx.find(oid, fc, null, null, 0); if (obj == null) throw new ObjectNotFoundException(oid); return obj; }
/** * Return the state manager for the given instance, using a detached * state manager if the instnace is not managed. */ public static OpenJPAStateManager getStateManager(Object obj, StoreContext ctx) { if (obj == null) return null; OpenJPAStateManager sm = ctx.getStateManager(obj); if (sm == null) // must be detached return new DetachedValueStateManager(obj, ctx); return sm; }
public DetachedValueStateManager(Object pc, StoreContext ctx) { this(ImplHelper.toPersistenceCapable(pc, ctx.getConfiguration()), ctx.getConfiguration().getMetaDataRepositoryInstance() .getMetaData(ImplHelper.getManagedInstance(pc).getClass(), ctx.getClassLoader(), true), ctx); }
public Object getResultObject() throws Exception { Class type = getPCType(); MetaDataRepository repos = ctx.getConfiguration(). getMetaDataRepositoryInstance(); ClassMetaData meta = repos.getMetaData (type, ctx.getClassLoader(), true); Object oid = getObjectId(meta); Object res = ctx.find(oid, null, null, this, 0); if (res == null) throw new ObjectNotFoundException(oid); return res; }
/** * Transform the given data into an embedded PC field value. Default * implementation assumes the data is an {@link AbstractPCData}. */ protected Object toEmbeddedField(OpenJPAStateManager sm, ValueMetaData vmd, Object data, FetchConfiguration fetch, Object context) { AbstractPCData pcdata = (AbstractPCData) data; OpenJPAStateManager embedded = sm.getContext().embed(null, pcdata.getId(), sm, vmd); pcdata.load(embedded, (BitSet) pcdata.getLoaded().clone(), fetch, context); return embedded.getManagedInstance(); }
public Object fetch(int field) { StateManager sm = _pc.pcGetStateManager(); if (sm != null) { if (sm instanceof DetachedStateManager) return fetchFromDetachedSM((DetachedStateManager) sm, field); if (_ctx.getAllowReferenceToSiblingContext() && sm instanceof StateManagerImpl) { return ((StateManagerImpl) sm).fetch(field); } throw new UnsupportedException(_loc.get("detach-val-badsm", _pc)); } provideField(field); Object val = fetchField(field, false); clear(); return _meta.getField(field).getExternalValue(val, _ctx.getBroker()); }
public JDBCFetchConfiguration getFetchConfiguration() { return (JDBCFetchConfiguration) _ctx.getFetchConfiguration(); }
/** * Return the value to cache for the given object. Caches its oid by * default. */ protected Object toRelationData(Object val, StoreContext ctx) { return ctx.getObjectId(val); }
public void setContext(StoreContext ctx, JDBCConfiguration conf) { _ctx = ctx; _conf = conf; _dict = _conf.getDBDictionaryInstance(); _sql = _conf.getSQLFactoryInstance(); _log = _conf.getLog(JDBCConfiguration.LOG_DIAG); LockManager lm = ctx.getLockManager(); if (lm instanceof JDBCLockManager) _lm = (JDBCLockManager) lm; _ds = getDataSource(ctx); if (_conf.getUpdateManagerInstance().orderDirty()) ctx.setOrderDirtyObjects(true); }
public void setContext(StoreContext ctx, JDBCConfiguration conf) { _ctx = ctx; _conf = conf; _dict = _conf.getDBDictionaryInstance(); _sql = _conf.getSQLFactoryInstance(); LockManager lm = ctx.getLockManager(); if (lm instanceof JDBCLockManager) _lm = (JDBCLockManager) lm; if (!ctx.isManaged() && _conf.isConnectionFactoryModeManaged()) _ds = _conf.getDataSource2(ctx); else _ds = _conf.getDataSource(ctx); if (_conf.getUpdateManagerInstance().orderDirty()) ctx.setOrderDirtyObjects(true); }
public Executor newDataStoreExecutor(ClassMetaData meta, boolean subs) { boolean parallel = !getContext().getStoreContext().getBroker() .getMultithreaded(); ParallelExecutor ex = new ParallelExecutor(this, meta, parallel); for (StoreQuery q : _queries) { ex.addExecutor(q.newDataStoreExecutor(meta, subs)); } return ex; }
protected void addContextClassLoaders(MultiClassLoader loader) { super.addContextClassLoaders(loader); loader.addClassLoader(_ctx.getClassLoader()); }
public void lock() { if (_state.ctx != null) _state.ctx.lock(); }
/** * Helper for store manager implementations. This method simply delegates * to the proper singular method for each state manager. * * @see StoreManager#loadAll * @since 0.4.0 */ 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; }
public Object getResultObject() throws Exception { Class type = getPCType(); MetaDataRepository repos = ctx.getConfiguration(). getMetaDataRepositoryInstance(); ClassMetaData meta = repos.getMetaData (type, ctx.getClassLoader(), true); Object oid = getObjectId(meta); Object res = ctx.find(oid, null, null, this, 0); if (res == null) throw new ObjectNotFoundException(oid); return res; }
public DetachedValueStateManager(Object pc, StoreContext ctx) { this(ImplHelper.toPersistenceCapable(pc, ctx.getConfiguration()), ctx.getConfiguration().getMetaDataRepositoryInstance() .getMetaData(ImplHelper.getManagedInstance(pc).getClass(), ctx.getClassLoader(), true), ctx); }
/** * Transform the given data into an embedded PC field value. Default * implementation assumes the data is an {@link AbstractPCData}. */ protected Object toEmbeddedField(OpenJPAStateManager sm, ValueMetaData vmd, Object data, FetchConfiguration fetch, Object context) { AbstractPCData pcdata = (AbstractPCData) data; OpenJPAStateManager embedded = sm.getContext().embed(null, pcdata.getId(), sm, vmd); pcdata.load(embedded, (BitSet) pcdata.getLoaded().clone(), fetch, context); return embedded.getManagedInstance(); }