use of com.orientechnologies.orient.core.index.OIndexTxAwareOneValue in project orientdb by orientechnologies.
the class IndexTxAwareOneValueGetValuesTest method testRemoveAllWithinTransaction.
@Test
public void testRemoveAllWithinTransaction() {
database.getMetadata().getIndexManager().reload();
database.begin();
final OIndex<?> index = database.getMetadata().getIndexManager().getIndex("idxTxAwareOneValueGetValuesTest");
Assert.assertTrue(index instanceof OIndexTxAwareOneValue);
final int clusterId = database.getDefaultClusterId();
index.put(1, new ORecordId(clusterId, 1));
index.put(2, new ORecordId(clusterId, 2));
index.remove(1, null);
Assert.assertNotNull(database.getTransaction().getIndexChanges("idxTxAwareOneValueGetValuesTest"));
Set<OIdentifiable> result = new HashSet<OIdentifiable>();
OIndexCursor cursor = index.iterateEntries(Arrays.asList(1, 2), true);
cursorToSet(cursor, result);
Assert.assertEquals(result.size(), 1);
database.commit();
cursor = index.iterateEntries(Arrays.asList(1, 2), true);
cursorToSet(cursor, result);
Assert.assertEquals(result.size(), 1);
}
use of com.orientechnologies.orient.core.index.OIndexTxAwareOneValue in project orientdb by orientechnologies.
the class IndexTxAwareOneValueGetValuesTest method testMultiPut.
@Test
public void testMultiPut() {
database.getMetadata().getIndexManager().reload();
database.begin();
final OIndex<?> index = database.getMetadata().getIndexManager().getIndex("idxTxAwareOneValueGetValuesTest");
Assert.assertTrue(index instanceof OIndexTxAwareOneValue);
final int clusterId = database.getDefaultClusterId();
index.put(1, new ORecordId(clusterId, 1));
index.put(1, new ORecordId(clusterId, 1));
index.put(2, new ORecordId(clusterId, 2));
Assert.assertNotNull(database.getTransaction().getIndexChanges("idxTxAwareOneValueGetValuesTest"));
Set<OIdentifiable> result = new HashSet<OIdentifiable>();
OIndexCursor cursor = index.iterateEntries(Arrays.asList(1, 2), true);
cursorToSet(cursor, result);
Assert.assertEquals(result.size(), 2);
database.commit();
cursor = index.iterateEntries(Arrays.asList(1, 2), true);
cursorToSet(cursor, result);
Assert.assertEquals(result.size(), 2);
}
use of com.orientechnologies.orient.core.index.OIndexTxAwareOneValue 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;
}
use of com.orientechnologies.orient.core.index.OIndexTxAwareOneValue in project orientdb by orientechnologies.
the class IndexTxAwareOneValueGetEntriesTest method testPutAfterTransaction.
@Test
public void testPutAfterTransaction() {
database.begin();
final OIndex<?> index = database.getMetadata().getIndexManager().getIndex("idxTxAwareOneValueGetEntriesTest");
Assert.assertTrue(index instanceof OIndexTxAwareOneValue);
final int clusterId = database.getDefaultClusterId();
index.put(1, new ORecordId(clusterId, 1));
index.put(2, new ORecordId(clusterId, 2));
Assert.assertNotNull(database.getTransaction().getIndexChanges("idxTxAwareOneValueGetEntriesTest"));
Set<OIdentifiable> result = new HashSet<OIdentifiable>();
OIndexCursor cursor = index.iterateEntries(Arrays.asList(1, 2), true);
cursorToSet(cursor, result);
Assert.assertEquals(result.size(), 2);
database.commit();
index.put(3, new ORecordId(clusterId, 3));
cursor = index.iterateEntries(Arrays.asList(1, 2, 3), true);
cursorToSet(cursor, result);
Assert.assertEquals(result.size(), 3);
}
use of com.orientechnologies.orient.core.index.OIndexTxAwareOneValue in project orientdb by orientechnologies.
the class IndexTxAwareOneValueGetEntriesTest method testClearAndPut.
@Test
public void testClearAndPut() {
database.begin();
final OIndex<?> index = database.getMetadata().getIndexManager().getIndex("idxTxAwareOneValueGetEntriesTest");
System.out.println("index intstanceof " + (index == null ? "null" : index.getClass()));
Assert.assertTrue(index instanceof OIndexTxAwareOneValue);
final int clusterId = database.getDefaultClusterId();
index.put(1, new ORecordId(clusterId, 1));
index.put(2, new ORecordId(clusterId, 2));
database.commit();
Assert.assertNull(database.getTransaction().getIndexChanges("idxTxAwareOneValueGetEntriesTest"));
Set<OIdentifiable> resultOne = new HashSet<OIdentifiable>();
OIndexCursor cursor = index.iterateEntries(Arrays.asList(1, 2), true);
cursorToSet(cursor, resultOne);
Assert.assertEquals(resultOne.size(), 2);
database.begin();
index.clear();
index.put(2, new ORecordId(clusterId, 2));
Assert.assertNotNull(database.getTransaction().getIndexChanges("idxTxAwareOneValueGetEntriesTest"));
Set<OIdentifiable> resultTwo = new HashSet<OIdentifiable>();
cursor = index.iterateEntries(Arrays.asList(1, 2), true);
cursorToSet(cursor, resultTwo);
Assert.assertEquals(resultTwo.size(), 1);
database.rollback();
Assert.assertNull(database.getTransaction().getIndexChanges("idxTxAwareOneValueGetEntriesTest"));
Set<OIdentifiable> resultThree = new HashSet<OIdentifiable>();
cursor = index.iterateEntries(Arrays.asList(1, 2), true);
cursorToSet(cursor, resultThree);
Assert.assertEquals(resultThree.size(), 2);
}
Aggregations