📄 ramtransaction.java
字号:
/* Derby - Class org.apache.derby.impl.store.access.RAMTransaction Copyright 1997, 2004 The Apache Software Foundation or its licensors, as applicable. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package org.apache.derby.impl.store.access;import java.util.Enumeration;import java.util.Hashtable;import java.util.Properties;import java.util.Vector;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.services.context.ContextManager;import org.apache.derby.iapi.services.io.Storable;import org.apache.derby.iapi.services.daemon.Serviceable;import org.apache.derby.iapi.services.monitor.Monitor;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.store.access.conglomerate.Conglomerate;import org.apache.derby.iapi.store.access.conglomerate.ConglomerateFactory;import org.apache.derby.iapi.store.access.conglomerate.ScanManager;import org.apache.derby.iapi.store.access.conglomerate.MethodFactory;import org.apache.derby.iapi.store.access.conglomerate.ScanControllerRowSource;import org.apache.derby.iapi.store.access.conglomerate.Sort;import org.apache.derby.iapi.store.access.conglomerate.SortFactory;import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;import org.apache.derby.iapi.store.access.AccessFactory;import org.apache.derby.iapi.store.access.AccessFactoryGlobals;import org.apache.derby.iapi.store.access.ColumnOrdering;import org.apache.derby.iapi.store.access.ConglomerateController;import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo;import org.apache.derby.iapi.store.access.FileResource;import org.apache.derby.iapi.store.access.GroupFetchScanController;import org.apache.derby.iapi.store.access.Qualifier;import org.apache.derby.iapi.store.access.RowLocationRetRowSource;import org.apache.derby.iapi.store.access.RowSource;import org.apache.derby.iapi.store.access.ScanController;import org.apache.derby.iapi.store.access.SortController;import org.apache.derby.iapi.store.access.SortCostController;import org.apache.derby.iapi.store.access.SortObserver;import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo;import org.apache.derby.iapi.store.access.StoreCostController;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.iapi.store.access.XATransactionController;import org.apache.derby.iapi.store.raw.ContainerHandle;import org.apache.derby.iapi.store.raw.LockingPolicy;import org.apache.derby.iapi.store.raw.Loggable;import org.apache.derby.iapi.store.raw.Page;import org.apache.derby.iapi.store.raw.Transaction;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil;import org.apache.derby.iapi.store.access.DatabaseInstant;import org.apache.derby.iapi.store.access.BackingStoreHashtable;import org.apache.derby.iapi.services.io.FormatableBitSet;import java.io.Serializable;// debuggingimport org.apache.derby.iapi.services.stream.HeaderPrintWriter;import org.apache.derby.iapi.services.stream.InfoStreams; public class RAMTransaction implements XATransactionController, TransactionManager{ /** The corresponding raw store transaction. **/ protected Transaction rawtran; /** The access manager this transaction is under. **/ protected RAMAccessManager accessmanager; /** The context this transaction is being managed by. **/ protected RAMTransactionContext context; /** The parent transaction if this is a nested user transaction. **/ protected RAMTransaction parent_tran; // XXX (nat) management of the controllers is still embryonic. // XXX (nat) would be nice if sort controllers were like conglom controllers private Vector scanControllers; private Vector conglomerateControllers; private Vector sorts; private Vector sortControllers; /** Where to look for temporary conglomerates. **/ protected Hashtable tempCongloms = null; /** Next id to use for a temporary conglomerate. **/ private long nextTempConglomId = -1; /** * Set by alter table to indicate that the conglomerate cache needs to * be invalidated if a transaction aborting error is encountered, cleared * after cleanup. */ private boolean alterTableCallMade = false; /** * The lock level of the transaction. * <p> * Cannot lock a level lower than the getSystemLockLevel(). So if * getSystemLockLevel() is table level locking, setting the transaction * locking level to record has no effect. **/ private int transaction_lock_level; /************************************************************************** * Constructors for This class: ************************************************************************** */ private final void init( RAMAccessManager myaccessmanager, Transaction theRawTran, RAMTransaction parent_tran) { this.rawtran = theRawTran; this.parent_tran = parent_tran; accessmanager = myaccessmanager; scanControllers = new Vector(); conglomerateControllers = new Vector(); sorts = null; // allocated on demand. sortControllers = null; // allocated on demand if (parent_tran != null) { // allow nested transactions to see temporary conglomerates which // were created in the parent transaction. This is necessary for // language which compiling plans in nested transactions against // user temporaries created in parent transactions. tempCongloms = parent_tran.tempCongloms; } else { tempCongloms = null; // allocated on demand } } protected RAMTransaction( RAMAccessManager myaccessmanager, Transaction theRawTran, RAMTransaction parent_transaction) throws StandardException { init(myaccessmanager, theRawTran, parent_transaction); } RAMTransaction( RAMAccessManager myaccessmanager, RAMTransaction tc, int format_id, byte[] global_id, byte[] branch_id) throws StandardException { init(myaccessmanager, tc.getRawStoreXact(), null); if (SanityManager.DEBUG) SanityManager.ASSERT(tc.getRawStoreXact().isIdle()); this.context = tc.context; // switch the transaction pointer in the context to point to this xact this.context.setTransaction(this); this.rawtran.createXATransactionFromLocalTransaction( format_id, global_id, branch_id); // invalidate old tc, so caller does not use it. Can't just call // destroy as that screws up the contexts which we want to just leave // alone. tc.rawtran = null; } RAMTransaction() { } /************************************************************************** * Private/Protected methods of This class: ************************************************************************** */ // XXX (nat) currently closes all controllers. protected void closeControllers(boolean closeHeldControllers) throws StandardException { Enumeration e; if (!scanControllers.isEmpty()) { // loop from end to beginning, removing scans which are not held. for (int i = scanControllers.size() - 1; i >= 0; i--) { ScanManager sc = (ScanManager) scanControllers.elementAt(i); if (sc.closeForEndTransaction(closeHeldControllers)) { // TODO - now counting on scan's removing themselves by // calling the closeMe() method. /* scanControllers.removeElementAt(i); */ } } if (closeHeldControllers) { if (SanityManager.DEBUG) { SanityManager.ASSERT(scanControllers.isEmpty()); } // just to make sure everything has been closed and removed. scanControllers.removeAllElements(); } } if (!conglomerateControllers.isEmpty()) { // loop from end to beginning, removing scans which are not held. for (int i = conglomerateControllers.size() - 1; i >= 0; i--) { ConglomerateController cc = (ConglomerateController) conglomerateControllers.elementAt(i); if (cc.closeForEndTransaction(closeHeldControllers)) { // TODO - now counting on cc's removing themselves by // calling the closeMe() method. /* conglomerateControllers.removeElementAt(i); */ } } if (closeHeldControllers) { if (SanityManager.DEBUG) { SanityManager.ASSERT(scanControllers.isEmpty()); } // just to make sure everything has been closed and removed. conglomerateControllers.removeAllElements(); } } if ((sortControllers != null) && !sortControllers.isEmpty()) { if (closeHeldControllers) { e = sortControllers.elements(); while (e.hasMoreElements()) { SortController sc = (SortController) e.nextElement(); sc.close(); } sortControllers.removeAllElements(); } } if ((sorts != null) && (!sorts.isEmpty())) { if (closeHeldControllers) { e = sorts.elements(); while (e.hasMoreElements()) { Sort sort = (Sort) e.nextElement(); if (sort != null) sort.drop(this); } sorts.removeAllElements(); } } } /** * Determine correct locking policy for a conglomerate open. * <p> * Determine from the following table whether to table or record lock * the conglomerate we are opening. * <p> * * * System level override * ------------------------------- * user requests table locking record locking * ------------- ------------- -------------- * TransactionController.MODE_TABLE TABLE TABLE * TransactionController.MODE_RECORD TABLE RECORD **/ private LockingPolicy determine_locking_policy( int requested_lock_level, int isolation_level) { LockingPolicy ret_locking_policy; if ((accessmanager.getSystemLockLevel() == TransactionController.MODE_TABLE) || (requested_lock_level == TransactionController.MODE_TABLE)) { ret_locking_policy = accessmanager.table_level_policy[isolation_level]; } else { ret_locking_policy = accessmanager.record_level_policy[isolation_level]; } return(ret_locking_policy); } private int determine_lock_level( int requested_lock_level) { int ret_lock_level; if ((accessmanager.getSystemLockLevel() == TransactionController.MODE_TABLE) || (requested_lock_level == TransactionController.MODE_TABLE)) { ret_lock_level = TransactionController.MODE_TABLE; } else { ret_lock_level = TransactionController.MODE_RECORD; } return(ret_lock_level); } private Conglomerate findExistingConglomerate(long conglomId) throws StandardException { Conglomerate conglom = null; if (conglomId < 0) { if (tempCongloms != null) conglom = (Conglomerate) tempCongloms.get(new Long(conglomId)); } else { conglom = accessmanager.conglomCacheFind(this, conglomId); } if (conglom == null) { throw StandardException.newException( SQLState.STORE_CONGLOMERATE_DOES_NOT_EXIST, new Long(conglomId)); } else { return(conglom); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -