Search in sources :

Example 16 with OCompositeKey

use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.

the class OSQLFunctionIn method fetchFromIndex.

private Object fetchFromIndex(OrientBaseGraph graph, OIdentifiable iFrom, Iterable<OIdentifiable> iTo, String[] iEdgeTypes) {
    String edgeClassName = null;
    if (iEdgeTypes == null) {
        edgeClassName = "E";
    } else if (iEdgeTypes.length == 1) {
        edgeClassName = iEdgeTypes[0];
    } else {
        return null;
    }
    OClass edgeClass = graph.getRawGraph().getMetadata().getSchema().getClass(edgeClassName);
    if (edgeClass == null) {
        return null;
    }
    Set<OIndex<?>> indexes = edgeClass.getInvolvedIndexes("in", "out");
    if (indexes == null || indexes.size() == 0) {
        return null;
    }
    OIndex index = indexes.iterator().next();
    OMultiCollectionIterator<OrientVertex> result = new OMultiCollectionIterator<OrientVertex>();
    for (OIdentifiable to : iTo) {
        OCompositeKey key = new OCompositeKey(iFrom, to);
        Object indexResult = index.get(key);
        if (indexResult instanceof OIdentifiable) {
            indexResult = Collections.singleton(indexResult);
        }
        Set<OIdentifiable> identities = new HashSet<OIdentifiable>();
        for (OIdentifiable edge : ((Iterable<OrientEdge>) indexResult)) {
            identities.add((OIdentifiable) ((ODocument) edge.getRecord()).rawField("in"));
        }
        result.add(identities);
    }
    return result;
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) OMultiCollectionIterator(com.orientechnologies.common.collection.OMultiCollectionIterator) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) HashSet(java.util.HashSet) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 17 with OCompositeKey

use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.

the class OSBTree method enhanceCompositeKey.

private K enhanceCompositeKey(K key, PartialSearchMode partialSearchMode) {
    if (!(key instanceof OCompositeKey))
        return key;
    final OCompositeKey compositeKey = (OCompositeKey) key;
    if (!(keySize == 1 || compositeKey.getKeys().size() == keySize || partialSearchMode.equals(PartialSearchMode.NONE))) {
        final OCompositeKey fullKey = new OCompositeKey(compositeKey);
        int itemsToAdd = keySize - fullKey.getKeys().size();
        final Comparable<?> keyItem;
        if (partialSearchMode.equals(PartialSearchMode.HIGHEST_BOUNDARY))
            keyItem = ALWAYS_GREATER_KEY;
        else
            keyItem = ALWAYS_LESS_KEY;
        for (int i = 0; i < itemsToAdd; i++) fullKey.addKey(keyItem);
        return (K) fullKey;
    }
    return key;
}
Also used : OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey)

Example 18 with OCompositeKey

use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.

the class OLuceneFullTextIndexEngine method putInManualindex.

private Document putInManualindex(Object key, OIdentifiable oIdentifiable) {
    Document doc = new Document();
    doc.add(OLuceneIndexType.createField(RID, oIdentifiable.getIdentity().toString(), Field.Store.YES));
    if (key instanceof OCompositeKey) {
        List<Object> keys = ((OCompositeKey) key).getKeys();
        int k = 0;
        for (Object o : keys) {
            doc.add(OLuceneIndexType.createField("k" + k, o, Field.Store.NO));
            k++;
        }
    } else if (key instanceof Collection) {
        Collection<Object> keys = (Collection<Object>) key;
        int k = 0;
        for (Object o : keys) {
            doc.add(OLuceneIndexType.createField("k" + k, o, Field.Store.NO));
            k++;
        }
    } else {
        doc.add(OLuceneIndexType.createField("k0", key, Field.Store.NO));
    }
    return doc;
}
Also used : Collection(java.util.Collection) Document(org.apache.lucene.document.Document) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey)

Example 19 with OCompositeKey

use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.

the class EmbeddedObjectSerializationTest method testEmbeddedObjectSerialization.

public void testEmbeddedObjectSerialization() {
    final ODocument originalDoc = new ODocument();
    final OCompositeKey compositeKey = new OCompositeKey(123, "56", new Date(), new ORecordId("#0:12"));
    originalDoc.field("compositeKey", compositeKey);
    originalDoc.field("int", 12);
    originalDoc.field("val", "test");
    originalDoc.save();
    final ODocument loadedDoc = database.load(originalDoc.getIdentity(), "*:-1", true);
    Assert.assertNotSame(loadedDoc, originalDoc);
    final OCompositeKey loadedCompositeKey = loadedDoc.field("compositeKey");
    Assert.assertEquals(loadedCompositeKey, compositeKey);
    originalDoc.delete();
}
Also used : OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) Date(java.util.Date) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 20 with OCompositeKey

use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.

the class OSQLFunctionOut method fetchFromIndex.

private Object fetchFromIndex(OrientBaseGraph graph, OIdentifiable iFrom, Iterable<OIdentifiable> iTo, String[] iEdgeTypes) {
    String edgeClassName = null;
    if (iEdgeTypes == null) {
        edgeClassName = "E";
    } else if (iEdgeTypes.length == 1) {
        edgeClassName = iEdgeTypes[0];
    } else {
        return null;
    }
    OClass edgeClass = graph.getRawGraph().getMetadata().getSchema().getClass(edgeClassName);
    if (edgeClass == null) {
        return null;
    }
    Set<OIndex<?>> indexes = edgeClass.getInvolvedIndexes("out", "in");
    if (indexes == null || indexes.size() == 0) {
        return null;
    }
    OIndex index = indexes.iterator().next();
    OMultiCollectionIterator<OrientVertex> result = new OMultiCollectionIterator<OrientVertex>();
    for (OIdentifiable to : iTo) {
        OCompositeKey key = new OCompositeKey(iFrom, to);
        Object indexResult = index.get(key);
        if (indexResult instanceof OIdentifiable) {
            indexResult = Collections.singleton(indexResult);
        }
        Set<OIdentifiable> identities = new HashSet<OIdentifiable>();
        for (OIdentifiable edge : ((Iterable<OrientEdge>) indexResult)) {
            identities.add((OIdentifiable) ((ODocument) edge.getRecord()).rawField("in"));
        }
        result.add(identities);
    }
    return result;
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) OMultiCollectionIterator(com.orientechnologies.common.collection.OMultiCollectionIterator) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) HashSet(java.util.HashSet) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OCompositeKey (com.orientechnologies.orient.core.index.OCompositeKey)40 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)22 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)11 ORecordId (com.orientechnologies.orient.core.id.ORecordId)10 ORID (com.orientechnologies.orient.core.id.ORID)8 OBinarySerializerFactory (com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory)5 OBinarySerializer (com.orientechnologies.common.serialization.types.OBinarySerializer)4 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)4 OIndex (com.orientechnologies.orient.core.index.OIndex)3 Collection (java.util.Collection)3 Date (java.util.Date)3 List (java.util.List)3 OMultiCollectionIterator (com.orientechnologies.common.collection.OMultiCollectionIterator)2 OTransactionException (com.orientechnologies.orient.core.exception.OTransactionException)2 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)2 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)2 OType (com.orientechnologies.orient.core.metadata.schema.OType)2 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)2 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)2 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)2