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));
}
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();
}
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;
}
Aggregations