Search in sources :

Example 1 with OIndexFactory

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

the class OrientIndex method create.

private void create(final String indexName, final Class<? extends Element> indexClass, OType iKeyType) {
    this.indexClass = indexClass;
    if (iKeyType == null)
        iKeyType = OType.STRING;
    final OIndexFactory factory = OIndexes.getFactory(OClass.INDEX_TYPE.DICTIONARY.toString(), null);
    this.recordKeyValueIndex = new OIndexTxAwareOneValue(graph.getRawGraph(), (OIndex<OIdentifiable>) graph.getRawGraph().getMetadata().getIndexManager().createIndex("__@recordmap@___" + indexName, OClass.INDEX_TYPE.DICTIONARY.toString(), new OSimpleKeyIndexDefinition(factory.getLastVersion(), OType.LINK, OType.STRING), null, null, null));
    final String className;
    if (Vertex.class.isAssignableFrom(indexClass))
        className = VERTEX;
    else if (Edge.class.isAssignableFrom(indexClass))
        className = EDGE;
    else
        className = indexClass.getName();
    final ODocument metadata = new ODocument();
    metadata.field(CONFIG_CLASSNAME, className);
    metadata.field(CONFIG_RECORD_MAP_NAME, recordKeyValueIndex.getName());
    final OIndexFactory nuFactory = OIndexes.getFactory(OClass.INDEX_TYPE.NOTUNIQUE.toString(), null);
    // CREATE THE MAP
    this.underlying = new OIndexTxAwareMultiValue(graph.getRawGraph(), (OIndex<Set<OIdentifiable>>) graph.getRawGraph().getMetadata().getIndexManager().createIndex(indexName, OClass.INDEX_TYPE.NOTUNIQUE.toString(), new OSimpleKeyIndexDefinition(nuFactory.getLastVersion(), iKeyType), null, null, metadata));
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) OSimpleKeyIndexDefinition(com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition) OIndexTxAwareMultiValue(com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue) OIndexTxAwareOneValue(com.orientechnologies.orient.core.index.OIndexTxAwareOneValue) OIndexFactory(com.orientechnologies.orient.core.index.OIndexFactory) Edge(com.tinkerpop.blueprints.Edge) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 2 with OIndexFactory

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

the class ODeleteStatementTest method testDeleteFromIndexBinary.

public void testDeleteFromIndexBinary() {
    ODatabaseDocument database = new ODatabaseDocumentTx("memory:ODeleteStatementTestDeleteFromIndexBinary");
    database.create();
    OIndexFactory factory = OIndexes.getFactory("NOTUNIQUE", null);
    database.getMetadata().getIndexManager().createIndex("byte-array-manualIndex-notunique", "NOTUNIQUE", new OSimpleKeyIndexDefinition(factory.getLastVersion(), OType.BINARY), null, null, null);
    OIndex<?> index = database.getMetadata().getIndexManager().getIndex("byte-array-manualIndex-notunique");
    byte[] key1 = new byte[] { 0, 1, 2, 3 };
    byte[] key2 = new byte[] { 4, 5, 6, 7 };
    final ODocument doc1 = new ODocument().field("k", "key1");
    final ODocument doc2 = new ODocument().field("k", "key1");
    final ODocument doc3 = new ODocument().field("k", "key2");
    final ODocument doc4 = new ODocument().field("k", "key2");
    doc1.save();
    doc2.save();
    doc3.save();
    doc4.save();
    index.put(key1, doc1);
    index.put(key1, doc2);
    index.put(key2, doc3);
    index.put(key2, doc4);
    Assert.assertTrue(index.remove(key1, doc2));
    database.command(new OCommandSQL("delete from index:byte-array-manualIndex-notunique where key = ? and rid = ?")).execute(key1, doc1);
    // Assert.assertEquals(((Collection<?>) index.get(key1)).size(), 1);
    // Assert.assertEquals(((Collection<?>) index.get(key2)).size(), 2);
    database.close();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OSimpleKeyIndexDefinition(com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OIndexFactory(com.orientechnologies.orient.core.index.OIndexFactory) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 3 with OIndexFactory

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

the class OrientIndex method buildKeyValueIndex.

private OIndex<?> buildKeyValueIndex(final ODocument metadata) {
    final OIndexFactory factory = OIndexes.getFactory(OClass.INDEX_TYPE.DICTIONARY.toString(), null);
    final OIndex<?> recordKeyValueIndex = new OIndexTxAwareOneValue(graph.getRawGraph(), (OIndex<OIdentifiable>) graph.getRawGraph().getMetadata().getIndexManager().createIndex("__@recordmap@___" + underlying.getName(), OClass.INDEX_TYPE.DICTIONARY.toString(), new OSimpleKeyIndexDefinition(factory.getLastVersion(), OType.LINK, OType.STRING), null, null, null));
    final List<ODocument> entries = graph.getRawGraph().query(new OSQLSynchQuery<Object>("select  from index:" + underlying.getName()));
    for (ODocument entry : entries) {
        final OIdentifiable rid = entry.field("rid");
        if (rid != null)
            recordKeyValueIndex.put(new OCompositeKey(rid, entry.field("key")), rid);
    }
    metadata.field(CONFIG_RECORD_MAP_NAME, recordKeyValueIndex.getName());
    return recordKeyValueIndex;
}
Also used : OSimpleKeyIndexDefinition(com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition) OIndexTxAwareOneValue(com.orientechnologies.orient.core.index.OIndexTxAwareOneValue) OIndexFactory(com.orientechnologies.orient.core.index.OIndexFactory) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OIndexFactory (com.orientechnologies.orient.core.index.OIndexFactory)3 OSimpleKeyIndexDefinition (com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition)3 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 OIndexTxAwareOneValue (com.orientechnologies.orient.core.index.OIndexTxAwareOneValue)2 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 OCompositeKey (com.orientechnologies.orient.core.index.OCompositeKey)1 OIndex (com.orientechnologies.orient.core.index.OIndex)1 OIndexTxAwareMultiValue (com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue)1 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1 Edge (com.tinkerpop.blueprints.Edge)1