Search in sources :

Example 1 with OSortedMultiIterator

use of com.orientechnologies.common.collection.OSortedMultiIterator in project orientdb by orientechnologies.

the class OCommandExecutorSQLSelect method searchForSubclassIndexes.

private boolean searchForSubclassIndexes(final OClass iSchemaClass) {
    Collection<OClass> subclasses = iSchemaClass.getSubclasses();
    if (subclasses.size() == 0) {
        return false;
    }
    final OOrderBy order = new OOrderBy();
    order.setItems(new ArrayList<OOrderByItem>());
    if (this.orderedFields != null) {
        for (OPair<String, String> pair : this.orderedFields) {
            OOrderByItem item = new OOrderByItem();
            item.setRecordAttr(pair.getKey());
            if (pair.getValue() == null) {
                item.setType(OOrderByItem.ASC);
            } else {
                item.setType(pair.getValue().toUpperCase().equals("DESC") ? OOrderByItem.DESC : OOrderByItem.ASC);
            }
            order.getItems().add(item);
        }
    }
    OSortedMultiIterator<OIdentifiable> cursor = new OSortedMultiIterator<OIdentifiable>(order);
    boolean fullySorted = true;
    if (!iSchemaClass.isAbstract()) {
        Iterator<OIdentifiable> parentClassIterator = (Iterator<OIdentifiable>) searchInClasses(iSchemaClass, false, true);
        if (parentClassIterator.hasNext()) {
            cursor.add(parentClassIterator);
            fullySorted = false;
        }
    }
    if (uniqueResult != null) {
        uniqueResult.clear();
    }
    int attempted = 0;
    for (OClass subclass : subclasses) {
        List<OIndexCursor> subcursors = getIndexCursors(subclass);
        fullySorted = fullySorted && fullySortedByIndex;
        if (subcursors == null || subcursors.size() == 0) {
            if (attempted > 0) {
                revertSubclassesProfiler(context, attempted);
            }
            return false;
        }
        for (OIndexCursor c : subcursors) {
            if (!fullySortedByIndex) {
            // TODO sort every iterator
            }
            attempted++;
            cursor.add(c);
        }
    }
    fullySortedByIndex = fullySorted;
    uniqueResult = new ConcurrentHashMap<ORID, ORID>();
    fetchFromTarget(cursor);
    if (uniqueResult != null) {
        uniqueResult.clear();
    }
    uniqueResult = null;
    return true;
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OIdentifiableIterator(com.orientechnologies.orient.core.iterator.OIdentifiableIterator) OMultiCollectionIterator(com.orientechnologies.common.collection.OMultiCollectionIterator) OSortedMultiIterator(com.orientechnologies.common.collection.OSortedMultiIterator) ORID(com.orientechnologies.orient.core.id.ORID) OSortedMultiIterator(com.orientechnologies.common.collection.OSortedMultiIterator)

Aggregations

OMultiCollectionIterator (com.orientechnologies.common.collection.OMultiCollectionIterator)1 OSortedMultiIterator (com.orientechnologies.common.collection.OSortedMultiIterator)1 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1 ORID (com.orientechnologies.orient.core.id.ORID)1 OIdentifiableIterator (com.orientechnologies.orient.core.iterator.OIdentifiableIterator)1 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1