📄 ramaccessmanager.java
字号:
* objects, key'd by conglomerate id. By caching, this avoids the cost * of reading the conglomerate info from disk on each subsequent query * which accesses the conglomerate. * <p> * The interfaces and internal routines which deal with this cache are: * conglomCacheInit() - initializes the cache at boot time. * * * **/ /** * Initialize the conglomerate cache. * <p> * Simply calls the cache manager to create the cache with some hard * coded defaults for size. * <p> * @exception StandardException Standard exception policy. **/ private void conglomCacheInit() throws StandardException { // Get a cache factory to create the conglomerate cache. CacheFactory cf = (CacheFactory) Monitor.startSystemModule( org.apache.derby.iapi.reference.Module.CacheFactory); // Now create the conglomerate cache. conglom_cache = cf.newCacheManager( this, AccessFactoryGlobals.CFG_CONGLOMDIR_CACHE, 200, 300); } /** * Find a conglomerate by conglomid in the cache. * <p> * Look for a conglomerate given a conglomid. If in cache return it, * otherwise fault in an entry by asking the owning factory to produce * an entry. * <p> * * @return The conglomerate object identified by "conglomid". * * @param conglomid The conglomerate id of the conglomerate to look up. * * @exception StandardException Standard exception policy. **/ /* package */ Conglomerate conglomCacheFind( TransactionManager xact_mgr, long conglomid) throws StandardException { Conglomerate conglom = null; Long conglomid_obj = new Long(conglomid); synchronized (conglom_cache) { CacheableConglomerate cache_entry = (CacheableConglomerate) conglom_cache.findCached(conglomid_obj); if (cache_entry != null) { conglom = cache_entry.getConglom(); conglom_cache.release(cache_entry); // SanityManager.DEBUG_PRINT("find", "find hit : " + conglomid); } else { // SanityManager.DEBUG_PRINT("find", "find miss: " + conglomid); // If not in cache - ask the factory for it and insert it. conglom = getFactoryFromConglomId(conglomid).readConglomerate( xact_mgr, new ContainerKey(0, conglomid)); if (conglom != null) { // on cache miss, put the missing conglom in the cache. cache_entry = (CacheableConglomerate) this.conglom_cache.create(conglomid_obj, conglom); this.conglom_cache.release(cache_entry); } } } return(conglom); } /** * Invalide the current Conglomerate Cache. * <p> * Abort of certain operations will invalidate the contents of the * cache. Longer term we could just invalidate those entries, but * for now just invalidate the whole cache. * <p> * * @exception StandardException Standard exception policy. **/ /* package */ protected void conglomCacheInvalidate() throws StandardException { synchronized (conglom_cache) { conglom_cache.ageOut(); } return; } /** * Update a conglomerate directory entry. * <p> * Update the Conglom column of the Conglomerate Directory. The * Conglomerate with id "conglomid" is replaced by "new_conglom". * <p> * * @param conglomid The conglomid of conglomerate to replace. * @param new_conglom The new Conglom to update the conglom column to. * * @exception StandardException Standard exception policy. **/ /* package */ void conglomCacheUpdateEntry( long conglomid, Conglomerate new_conglom) throws StandardException { Long conglomid_obj = new Long(conglomid); synchronized (conglom_cache) { // remove the current entry CacheableConglomerate conglom_entry = (CacheableConglomerate) conglom_cache.findCached(conglomid_obj); if (conglom_entry != null) conglom_cache.remove(conglom_entry); // insert the updated entry. conglom_entry = (CacheableConglomerate) conglom_cache.create(conglomid_obj, new_conglom); conglom_cache.release(conglom_entry); } return; } /** * Add a newly created conglomerate to the cache. * <p> * * @param conglomid The conglomid of conglomerate to replace. * @param conglom The Conglom to add. * * @exception StandardException Standard exception policy. **/ /* package */ void conglomCacheAddEntry( long conglomid, Conglomerate conglom) throws StandardException { synchronized (conglom_cache) { // insert the updated entry. CacheableConglomerate conglom_entry = (CacheableConglomerate) conglom_cache.create(new Long(conglomid), conglom); conglom_cache.release(conglom_entry); } return; } /** * Remove an entry from the cache. * <p> * * @param conglomid The conglomid of conglomerate to replace. * * @exception StandardException Standard exception policy. **/ /* package */ void conglomCacheRemoveEntry(long conglomid) throws StandardException { synchronized (conglom_cache) { CacheableConglomerate conglom_entry = (CacheableConglomerate) conglom_cache.findCached(new Long(conglomid)); if (conglom_entry != null) conglom_cache.remove(conglom_entry); } return; } /************************************************************************** * Public Methods implementing AccessFactory Interface: ************************************************************************** */ /** Database creation finished. Tell RawStore. @exception StandardException cloudscape standard error policy */ public void createFinished() throws StandardException { rawstore.createFinished(); } /** Find an access method that implements a format type. @see AccessFactory#findMethodFactoryByFormat **/ public MethodFactory findMethodFactoryByFormat(UUID format) { MethodFactory factory; // See if there's an access method that supports the desired // format type as its primary format type. factory = (MethodFactory) formathash.get(format); if (factory != null) return factory; // No primary format. See if one of the access methods // supports it as a secondary format. Enumeration e = formathash.elements(); while (e.hasMoreElements()) { factory = (MethodFactory) e.nextElement(); if (factory.supportsFormat(format)) return factory; } // No such implementation. return null; } /** Find an access method that implements an implementation type. @see AccessFactory#findMethodFactoryByImpl **/ public MethodFactory findMethodFactoryByImpl(String impltype) throws StandardException { // See if there's an access method that supports the desired // implementation type as its primary implementation type. MethodFactory factory = (MethodFactory) implhash.get(impltype); if (factory != null) return factory; // No primary implementation. See if one of the access methods // supports the implementation type as a secondary. Enumeration e = implhash.elements(); while (e.hasMoreElements()) { factory = (MethodFactory) e.nextElement(); if (factory.supportsImplementation(impltype)) return factory; } factory = null; // try and load an implementation. a new properties object needs // to be created to hold the conglomerate type property, since // that value is specific to the conglomerate we want to boot, not // to the service as a whole Properties conglomProperties = new Properties(serviceProperties); conglomProperties.put(AccessFactoryGlobals.CONGLOM_PROP, impltype); try { factory = (MethodFactory) Monitor.bootServiceModule( false, this, MethodFactory.MODULE, impltype, conglomProperties); } catch (StandardException se) { if (!se.getMessageId().equals(SQLState.SERVICE_MISSING_IMPLEMENTATION)) throw se; } conglomProperties = null; if (factory != null) { registerAccessMethod(factory); return factory; } // No such implementation. return null; } public LockFactory getLockFactory() { return rawstore.getLockFactory(); } public TransactionController getTransaction( ContextManager cm) throws StandardException { return getAndNameTransaction(cm, AccessFactoryGlobals.USER_TRANS_NAME); } public TransactionController getAndNameTransaction( ContextManager cm, String transName) throws StandardException { if (cm == null) return null; // XXX (nat) should throw exception // See if there's already a transaction context. RAMTransactionContext rtc = (RAMTransactionContext) cm.getContext(AccessFactoryGlobals.RAMXACT_CONTEXT_ID); if (rtc == null) { // No transaction context. Create or find a raw store transaction, // make a context for it, and push the context. Note this puts the // raw store transaction context above the access context, which is // required for error handling assumptions to be correct. Transaction rawtran = rawstore.findUserTransaction(cm, transName); RAMTransaction rt = new RAMTransaction(this, rawtran, null); rtc = new RAMTransactionContext( cm, AccessFactoryGlobals.RAMXACT_CONTEXT_ID, rt, false /* abortAll */); TransactionController tc = rtc.getTransaction(); if (xactProperties != null) { rawtran.setup(tc); tc.commit(); } rawtran.setDefaultLockingPolicy(system_default_locking_policy); tc.commit(); return tc; } return rtc.getTransaction(); } /** * Start a global transaction. * <p> * Get a transaction controller with which to manipulate data within * the access manager. Implicitly creates an access context. * <p> * Must only be called if no other transaction context exists in the * current context manager. If another transaction exists in the context * an exception will be thrown. * <p> * The (format_id, global_id, branch_id) triplet is meant to come exactly * from a javax.transaction.xa.Xid. We don't use Xid so that the system * can be delivered on a non-1.2 vm system and not require the javax classes * in the path. * * @param cm The context manager for the current context. * @param format_id the format id part of the Xid - ie. Xid.getFormatId(). * @param global_id the global transaction identifier part of XID - ie. * Xid.getGlobalTransactionId(). * @param branch_id The branch qualifier of the Xid - ie. * Xid.getBranchQaulifier() * * @exception StandardException Standard exception policy. * @see TransactionController **/ public /* XATransactionController */ Object startXATransaction( ContextManager cm, int format_id, byte[] global_id, byte[] branch_id) throws StandardException { RAMTransaction xa_tc = null; if (SanityManager.DEBUG) { SanityManager.ASSERT(global_id != null); SanityManager.ASSERT(branch_id != null); } if (cm == null) return null; // XXX (nat) should throw exception // See if there's already a transaction context. RAMTransactionContext rtc = (RAMTransactionContext) cm.getContext(AccessFactoryGlobals.RAMXACT_CONTEXT_ID); if (rtc == null) { // No transaction context. Create or find a raw store transaction, // make a context for it, and push the context. Note this puts the // raw store transaction context above the access context, which is // required for error handling assumptions to be correct. Transaction rawtran = rawstore.startGlobalTransaction( cm, format_id, global_id, branch_id); xa_tc = new RAMTransaction(this, rawtran, null); rtc = new RAMTransactionContext(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -