Search in sources :

Example 26 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class OIndexTxAwareMultiValue method get.

@Override
public Set<OIdentifiable> get(Object key) {
    final OTransactionIndexChanges indexChanges = database.getTransaction().getIndexChanges(delegate.getName());
    if (indexChanges == null)
        return super.get(key);
    key = getCollatingValue(key);
    final Set<OIdentifiable> result = new HashSet<OIdentifiable>();
    if (!indexChanges.cleared) {
        // BEGIN FROM THE UNDERLYING RESULT SET
        final Collection<OIdentifiable> subResult = super.get(key);
        if (subResult != null)
            for (OIdentifiable oid : subResult) result.add(oid);
    }
    final Set<OIdentifiable> processed = new HashSet<OIdentifiable>();
    for (OIdentifiable identifiable : result) {
        Map.Entry<Object, OIdentifiable> entry = calculateTxIndexEntry(key, identifiable, indexChanges);
        if (entry != null)
            processed.add(entry.getValue());
    }
    Set<OIdentifiable> txChanges = calculateTxValue(key, indexChanges);
    if (txChanges != null)
        processed.addAll(txChanges);
    if (!processed.isEmpty())
        return processed;
    return null;
}
Also used : OTransactionIndexChanges(com.orientechnologies.orient.core.tx.OTransactionIndexChanges) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 27 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class OIndexTxAwareMultiValue method calculateTxValue.

private Set<OIdentifiable> calculateTxValue(final Object key, OTransactionIndexChanges indexChanges) {
    final OTransactionIndexChangesPerKey changesPerKey = indexChanges.getChangesPerKey(key);
    if (changesPerKey.entries.isEmpty())
        return null;
    final List<OIdentifiable> result = new ArrayList<OIdentifiable>();
    for (OTransactionIndexEntry entry : changesPerKey.entries) {
        if (entry.operation == OPERATION.REMOVE) {
            if (entry.value == null)
                result.clear();
            else
                result.remove(entry.value);
        } else
            result.add(entry.value);
    }
    if (result.isEmpty())
        return null;
    return new HashSet<OIdentifiable>(result);
}
Also used : OTransactionIndexChangesPerKey(com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey) OTransactionIndexEntry(com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey.OTransactionIndexEntry) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 28 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class OPropertyRidBagIndexDefinition method createValue.

@Override
public Object createValue(final Object... params) {
    if (!(params[0] instanceof ORidBag))
        return null;
    final ORidBag ridBag = (ORidBag) params[0];
    final List<Object> values = new ArrayList<Object>();
    for (final OIdentifiable item : ridBag) {
        values.add(createSingleValue(item));
    }
    return values;
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 29 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class OPropertyRidBagIndexDefinition method createValue.

@Override
public Object createValue(final List<?> params) {
    if (!(params.get(0) instanceof ORidBag))
        return null;
    final ORidBag ridBag = (ORidBag) params.get(0);
    final List<Object> values = new ArrayList<Object>();
    for (final OIdentifiable item : ridBag) {
        values.add(createSingleValue(item));
    }
    return values;
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 30 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class OHashTableIndexEngine method cursor.

@Override
public OIndexCursor cursor(final ValuesTransformer valuesTransformer) {
    return new OIndexAbstractCursor() {

        private int nextEntriesIndex;

        private OHashIndexBucket.Entry<Object, Object>[] entries;

        private Iterator<OIdentifiable> currentIterator = new OEmptyIterator<OIdentifiable>();

        private Object currentKey;

        {
            OHashIndexBucket.Entry<Object, Object> firstEntry = hashTable.firstEntry();
            if (firstEntry == null)
                entries = OCommonConst.EMPTY_BUCKET_ENTRY_ARRAY;
            else
                entries = hashTable.ceilingEntries(firstEntry.key);
            if (entries.length == 0)
                currentIterator = null;
        }

        @Override
        public Map.Entry<Object, OIdentifiable> nextEntry() {
            if (currentIterator == null)
                return null;
            if (currentIterator.hasNext())
                return nextCursorValue();
            while (currentIterator != null && !currentIterator.hasNext()) {
                if (entries.length == 0) {
                    currentIterator = null;
                    return null;
                }
                final OHashIndexBucket.Entry<Object, Object> bucketEntry = entries[nextEntriesIndex];
                currentKey = bucketEntry.key;
                Object value = bucketEntry.value;
                if (valuesTransformer != null)
                    currentIterator = valuesTransformer.transformFromValue(value).iterator();
                else
                    currentIterator = Collections.singletonList((OIdentifiable) value).iterator();
                nextEntriesIndex++;
                if (nextEntriesIndex >= entries.length) {
                    entries = hashTable.higherEntries(entries[entries.length - 1].key);
                    nextEntriesIndex = 0;
                }
            }
            if (currentIterator != null && !currentIterator.hasNext())
                return nextCursorValue();
            currentIterator = null;
            return null;
        }

        private Map.Entry<Object, OIdentifiable> nextCursorValue() {
            final OIdentifiable identifiable = currentIterator.next();
            return new Map.Entry<Object, OIdentifiable>() {

                @Override
                public Object getKey() {
                    return currentKey;
                }

                @Override
                public OIdentifiable getValue() {
                    return identifiable;
                }

                @Override
                public OIdentifiable setValue(OIdentifiable value) {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}
Also used : Iterator(java.util.Iterator) OEmptyIterator(com.orientechnologies.orient.core.iterator.OEmptyIterator) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) Map(java.util.Map)

Aggregations

OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)536 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)278 ORecordId (com.orientechnologies.orient.core.id.ORecordId)120 Test (org.testng.annotations.Test)104 HashSet (java.util.HashSet)89 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)79 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)70 ORID (com.orientechnologies.orient.core.id.ORID)56 OIndexCursor (com.orientechnologies.orient.core.index.OIndexCursor)47 Test (org.junit.Test)43 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)42 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)41 ArrayList (java.util.ArrayList)39 ORecord (com.orientechnologies.orient.core.record.ORecord)35 Map (java.util.Map)31 ByteBuffer (java.nio.ByteBuffer)28 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)26 OIndexTxAwareOneValue (com.orientechnologies.orient.core.index.OIndexTxAwareOneValue)22 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)22 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)21