use of org.apache.derby.iapi.store.access.conglomerate.Sort in project derby by apache.
the class RAMTransaction method closeControllers.
/**
************************************************************************
* Private/Protected methods of This class:
**************************************************************************
*/
// XXX (nat) currently closes all controllers.
protected void closeControllers(boolean closeHeldControllers) throws StandardException {
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 = scanControllers.get(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.clear();
}
}
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 = conglomerateControllers.get(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.clear();
}
}
if ((sortControllers != null) && !sortControllers.isEmpty()) {
if (closeHeldControllers) {
// element from the list.
for (int i = sortControllers.size() - 1; i >= 0; i--) {
SortController sc = sortControllers.get(i);
sc.completedInserts();
}
sortControllers.clear();
}
}
if ((sorts != null) && (!sorts.isEmpty())) {
if (closeHeldControllers) {
// element from the list.
for (int i = sorts.size() - 1; i >= 0; i--) {
Sort sort = sorts.get(i);
if (sort != null)
sort.drop(this);
}
sorts.clear();
freeSortIds.clear();
}
}
}
use of org.apache.derby.iapi.store.access.conglomerate.Sort in project derby by apache.
the class RAMTransaction method debugOpened.
/**
* Return a string with debug information about opened congloms/scans/sorts.
* <p>
* Return a string with debugging information about current opened
* congloms/scans/sorts which have not been close()'d.
* Calls to this routine are only valid under code which is conditional
* on SanityManager.DEBUG.
* <p>
*
* @return String with debugging information.
*
* @exception StandardException Standard exception policy.
*/
public String debugOpened() throws StandardException {
String str = null;
if (SanityManager.DEBUG) {
str = "";
for (Iterator<ScanManager> it = scanControllers.iterator(); it.hasNext(); ) {
ScanController sc = it.next();
str += "open scan controller: " + sc + "\n";
}
for (Iterator<ConglomerateController> it = conglomerateControllers.iterator(); it.hasNext(); ) {
ConglomerateController cc = (ConglomerateController) it.next();
str += "open conglomerate controller: " + cc + "\n";
}
if (sortControllers != null) {
for (Iterator<SortController> it = sortControllers.iterator(); it.hasNext(); ) {
SortController sc = it.next();
str += "open sort controller: " + sc + "\n";
}
}
if (sorts != null) {
for (int i = 0; i < sorts.size(); i++) {
Sort sort = sorts.get(i);
if (sort != null) {
str += "sorts created by createSort() in current xact:" + sort + "\n";
}
}
}
if (tempCongloms != null) {
for (Iterator<Long> it = tempCongloms.keySet().iterator(); it.hasNext(); ) {
Long conglomId = it.next();
Conglomerate c = tempCongloms.get(conglomId);
str += "temp conglomerate id = " + conglomId + ": " + c;
}
}
}
return (str);
}
use of org.apache.derby.iapi.store.access.conglomerate.Sort in project derby by apache.
the class RAMTransaction method openSortScan.
/**
* @see TransactionController#openSortScan
* @exception StandardException Standard error policy.
*/
public ScanController openSortScan(long id, boolean hold) throws StandardException {
Sort sort;
// if it doesn't exist.
if (sorts == null || id >= sorts.size() || (sort = ((Sort) sorts.get((int) id))) == null) {
throw StandardException.newException(SQLState.AM_NO_SUCH_SORT, id);
}
// Open a scan on it.
ScanManager sc = sort.openSortScan(this, hold);
// Keep track of it so we can release on close.
scanControllers.add(sc);
return sc;
}
use of org.apache.derby.iapi.store.access.conglomerate.Sort in project derby by apache.
the class RAMTransaction method openSort.
/**
* @see TransactionController#openSort
* @exception StandardException Standard error policy.
*/
public SortController openSort(long id) throws StandardException {
Sort sort;
// if it doesn't exist.
if (sorts == null || id >= sorts.size() || (sort = (sorts.get((int) id))) == null) {
throw StandardException.newException(SQLState.AM_NO_SUCH_SORT, id);
}
// Open it.
SortController sc = sort.open(this);
// Keep track of it so we can release on close.
if (sortControllers == null)
sortControllers = new ArrayList<SortController>();
sortControllers.add(sc);
return sc;
}
use of org.apache.derby.iapi.store.access.conglomerate.Sort in project derby by apache.
the class RAMTransaction method createSort.
/**
* @see TransactionController#createSort
* @exception StandardException Standard error policy.
*/
public long createSort(Properties implParameters, DataValueDescriptor[] template, ColumnOrdering[] columnOrdering, SortObserver sortObserver, boolean alreadyInOrder, long estimatedRows, int estimatedRowSize) throws StandardException {
// Get the implementation type from the parameters.
// XXX (nat) need to figure out how to select sort implementation.
String implementation = null;
if (implParameters != null)
implementation = implParameters.getProperty(AccessFactoryGlobals.IMPL_TYPE);
if (implementation == null)
implementation = AccessFactoryGlobals.SORT_EXTERNAL;
// Find the appropriate factory for the desired implementation.
MethodFactory mfactory;
mfactory = accessmanager.findMethodFactoryByImpl(implementation);
if (mfactory == null || !(mfactory instanceof SortFactory)) {
throw (StandardException.newException(SQLState.AM_NO_FACTORY_FOR_IMPLEMENTATION, implementation));
}
SortFactory sfactory = (SortFactory) mfactory;
// Decide what segment the sort should use.
// XXX (nat) sorts always in segment 0
int segment = 0;
// Create the sort.
Sort sort = sfactory.createSort(this, segment, implParameters, template, columnOrdering, sortObserver, alreadyInOrder, estimatedRows, estimatedRowSize);
// Add the sort to the sorts vector
if (sorts == null) {
sorts = new ArrayList<Sort>();
freeSortIds = new ArrayList<Integer>();
}
int sortid;
if (freeSortIds.isEmpty()) {
// no free identifiers, add sort at the end
sortid = sorts.size();
sorts.add(sort);
} else {
// reuse a sort identifier
sortid = (freeSortIds.remove(freeSortIds.size() - 1)).intValue();
sorts.set(sortid, sort);
}
return sortid;
}
Aggregations