Search in sources :

Example 1 with Sort

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();
        }
    }
}
Also used : ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) Sort(org.apache.derby.iapi.store.access.conglomerate.Sort) ScanManager(org.apache.derby.iapi.store.access.conglomerate.ScanManager) SortController(org.apache.derby.iapi.store.access.SortController)

Example 2 with Sort

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);
}
Also used : GroupFetchScanController(org.apache.derby.iapi.store.access.GroupFetchScanController) ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) ScanManager(org.apache.derby.iapi.store.access.conglomerate.ScanManager) Conglomerate(org.apache.derby.iapi.store.access.conglomerate.Conglomerate) Sort(org.apache.derby.iapi.store.access.conglomerate.Sort) SortController(org.apache.derby.iapi.store.access.SortController)

Example 3 with Sort

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;
}
Also used : Sort(org.apache.derby.iapi.store.access.conglomerate.Sort) ScanManager(org.apache.derby.iapi.store.access.conglomerate.ScanManager)

Example 4 with Sort

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;
}
Also used : ArrayList(java.util.ArrayList) Sort(org.apache.derby.iapi.store.access.conglomerate.Sort) SortController(org.apache.derby.iapi.store.access.SortController)

Example 5 with Sort

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;
}
Also used : MethodFactory(org.apache.derby.iapi.store.access.conglomerate.MethodFactory) Sort(org.apache.derby.iapi.store.access.conglomerate.Sort) SortFactory(org.apache.derby.iapi.store.access.conglomerate.SortFactory)

Aggregations

Sort (org.apache.derby.iapi.store.access.conglomerate.Sort)7 SortController (org.apache.derby.iapi.store.access.SortController)3 ScanManager (org.apache.derby.iapi.store.access.conglomerate.ScanManager)3 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)2 ArrayList (java.util.ArrayList)1 GroupFetchScanController (org.apache.derby.iapi.store.access.GroupFetchScanController)1 ScanController (org.apache.derby.iapi.store.access.ScanController)1 Conglomerate (org.apache.derby.iapi.store.access.conglomerate.Conglomerate)1 MethodFactory (org.apache.derby.iapi.store.access.conglomerate.MethodFactory)1 ScanControllerRowSource (org.apache.derby.iapi.store.access.conglomerate.ScanControllerRowSource)1 SortFactory (org.apache.derby.iapi.store.access.conglomerate.SortFactory)1