Search in sources :

Example 6 with OCompositeKey

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

the class OrientIndex method removeElement.

protected void removeElement(final T element) {
    graph.setCurrentGraphInThreadLocal();
    graph.autoStartTransaction();
    final OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>("select from index:" + recordKeyValueIndex.getName() + " where key between [" + element.getIdentity() + "] and [" + element.getIdentity() + "]");
    final Collection<ODocument> entries = (Collection<ODocument>) graph.getRawGraph().query(query);
    for (ODocument entry : entries) {
        final OCompositeKey key = entry.field("key");
        final List<Object> keys = key.getKeys();
        underlying.remove(keys.get(1).toString(), element.getIdentity());
        recordKeyValueIndex.remove(key, element.getIdentity());
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Collection(java.util.Collection) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 7 with OCompositeKey

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

the class OrientIndex method put.

public void put(final String key, final Object value, final T element) {
    final String keyTemp = key + SEPARATOR + value;
    final ODocument doc = element.getRecord();
    if (!doc.getIdentity().isValid())
        doc.save();
    graph.setCurrentGraphInThreadLocal();
    graph.autoStartTransaction();
    underlying.put(keyTemp, doc);
    recordKeyValueIndex.put(new OCompositeKey(doc.getIdentity(), keyTemp), doc.getIdentity());
}
Also used : OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 8 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 9 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 10 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)

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