Search in sources :

Example 1 with OIndexTxAwareOneValue

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

the class IndexTxAwareOneValueGetEntriesTest method testRemoveAllWithinTransaction.

@Test
public void testRemoveAllWithinTransaction() {
    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));
    index.remove(1, null);
    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(), 1);
    database.commit();
    cursor = index.iterateEntries(Arrays.asList(1, 2), true);
    cursorToSet(cursor, result);
    Assert.assertEquals(result.size(), 1);
}
Also used : OIndexCursor(com.orientechnologies.orient.core.index.OIndexCursor) OIndexTxAwareOneValue(com.orientechnologies.orient.core.index.OIndexTxAwareOneValue) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with OIndexTxAwareOneValue

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

the class IndexTxAwareOneValueGetEntriesTest method testRemoveOneWithinTransaction.

@Test
public void testRemoveOneWithinTransaction() {
    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));
    index.remove(1);
    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(), 1);
    database.commit();
    cursor = index.iterateEntries(Arrays.asList(1, 2), true);
    cursorToSet(cursor, result);
    Assert.assertEquals(result.size(), 1);
}
Also used : OIndexCursor(com.orientechnologies.orient.core.index.OIndexCursor) OIndexTxAwareOneValue(com.orientechnologies.orient.core.index.OIndexTxAwareOneValue) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 3 with OIndexTxAwareOneValue

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

the class IndexTxAwareOneValueGetEntriesTest method testMultiPut.

@Test
public void testMultiPut() {
    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(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();
    cursor = index.iterateEntries(Arrays.asList(1, 2), true);
    cursorToSet(cursor, result);
    Assert.assertEquals(result.size(), 2);
}
Also used : OIndexCursor(com.orientechnologies.orient.core.index.OIndexCursor) OIndexTxAwareOneValue(com.orientechnologies.orient.core.index.OIndexTxAwareOneValue) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 4 with OIndexTxAwareOneValue

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

the class IndexTxAwareOneValueGetEntriesTest method testRemoveAndPut.

@Test
public void testRemoveAndPut() {
    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));
    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.remove(1);
    index.put(1, new ORecordId(clusterId, 1));
    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(), 2);
    database.rollback();
}
Also used : OIndexCursor(com.orientechnologies.orient.core.index.OIndexCursor) OIndexTxAwareOneValue(com.orientechnologies.orient.core.index.OIndexTxAwareOneValue) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 5 with OIndexTxAwareOneValue

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

the class IndexTxAwareOneValueGetValuesTest method testPut.

@Test
public void testPut() {
    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));
    database.commit();
    Assert.assertNull(database.getTransaction().getIndexChanges("idxTxAwareOneValueGetValuesTest"));
    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.put(3, new ORecordId(clusterId, 3));
    Assert.assertNotNull(database.getTransaction().getIndexChanges("idxTxAwareOneValueGetValuesTest"));
    Set<OIdentifiable> resultTwo = new HashSet<OIdentifiable>();
    cursor = index.iterateEntries(Arrays.asList(1, 2, 3), true);
    cursorToSet(cursor, resultTwo);
    Assert.assertEquals(resultTwo.size(), 3);
    database.rollback();
    Assert.assertNull(database.getTransaction().getIndexChanges("idxTxAwareOneValueGetValuesTest"));
    Set<OIdentifiable> resultThree = new HashSet<OIdentifiable>();
    cursor = index.iterateEntries(Arrays.asList(1, 2), true);
    cursorToSet(cursor, resultThree);
    Assert.assertEquals(resultThree.size(), 2);
}
Also used : OIndexCursor(com.orientechnologies.orient.core.index.OIndexCursor) OIndexTxAwareOneValue(com.orientechnologies.orient.core.index.OIndexTxAwareOneValue) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

OIndexTxAwareOneValue (com.orientechnologies.orient.core.index.OIndexTxAwareOneValue)32 ORecordId (com.orientechnologies.orient.core.id.ORecordId)30 Test (org.testng.annotations.Test)30 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)22 OIndexCursor (com.orientechnologies.orient.core.index.OIndexCursor)20 HashSet (java.util.HashSet)20 OIndexFactory (com.orientechnologies.orient.core.index.OIndexFactory)2 OSimpleKeyIndexDefinition (com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition)2 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 OCompositeKey (com.orientechnologies.orient.core.index.OCompositeKey)1 OIndex (com.orientechnologies.orient.core.index.OIndex)1 OIndexTxAwareMultiValue (com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue)1 Edge (com.tinkerpop.blueprints.Edge)1