Search in sources :

Example 11 with OIndexCursor

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

the class IndexTxAwareMultiValueGetEntriesTest method testPut.

@Test
public void testPut() {
    database.begin();
    final OIndex<?> index = database.getMetadata().getIndexManager().getIndex("idxTxAwareMultiValueGetEntriesTest");
    Assert.assertTrue(index instanceof OIndexTxAwareMultiValue);
    final int clusterId = database.getDefaultClusterId();
    final List<Long> positions = getValidPositions(clusterId);
    index.put(1, new ORecordId(clusterId, positions.get(0)));
    index.put(1, new ORecordId(clusterId, positions.get(1)));
    index.put(2, new ORecordId(clusterId, positions.get(2)));
    database.commit();
    Assert.assertNull(database.getTransaction().getIndexChanges("idxTxAwareMultiValueGetEntriesTest"));
    Set<OIdentifiable> resultOne = new HashSet<OIdentifiable>();
    OIndexCursor cursor = index.iterateEntries(Arrays.asList(1, 2), true);
    cursorToSet(cursor, resultOne);
    Assert.assertEquals(resultOne.size(), 3);
    database.begin();
    index.put(2, new ORecordId(clusterId, positions.get(3)));
    Assert.assertNotNull(database.getTransaction().getIndexChanges("idxTxAwareMultiValueGetEntriesTest"));
    Set<OIdentifiable> resultTwo = new HashSet<OIdentifiable>();
    cursor = index.iterateEntries(Arrays.asList(1, 2), true);
    cursorToSet(cursor, resultTwo);
    Assert.assertEquals(resultTwo.size(), 4);
    database.rollback();
    Assert.assertNull(database.getTransaction().getIndexChanges("idxTxAwareMultiValueGetEntriesTest"));
    Set<OIdentifiable> resultThree = new HashSet<OIdentifiable>();
    cursor = index.iterateEntries(Arrays.asList(1, 2), true);
    cursorToSet(cursor, resultThree);
    Assert.assertEquals(resultThree.size(), 3);
}
Also used : OIndexTxAwareMultiValue(com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue) OIndexCursor(com.orientechnologies.orient.core.index.OIndexCursor) 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 12 with OIndexCursor

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

the class IndexTxAwareMultiValueGetEntriesTest method testRemoveOne.

@Test
public void testRemoveOne() {
    database.begin();
    final OIndex<?> index = database.getMetadata().getIndexManager().getIndex("idxTxAwareMultiValueGetEntriesTest");
    Assert.assertTrue(index instanceof OIndexTxAwareMultiValue);
    final int clusterId = database.getDefaultClusterId();
    final List<Long> positions = getValidPositions(clusterId);
    final ORecordId firstRecordId = new ORecordId(clusterId, positions.get(0));
    index.put(1, firstRecordId);
    index.put(1, new ORecordId(clusterId, positions.get(1)));
    index.put(2, new ORecordId(clusterId, positions.get(2)));
    database.commit();
    Assert.assertNull(database.getTransaction().getIndexChanges("idxTxAwareMultiValueGetEntriesTest"));
    Set<OIdentifiable> resultOne = new HashSet<OIdentifiable>();
    OIndexCursor cursor = index.iterateEntries(Arrays.asList(1, 2), true);
    cursorToSet(cursor, resultOne);
    Assert.assertEquals(resultOne.size(), 3);
    database.begin();
    index.remove(1, firstRecordId);
    Assert.assertNotNull(database.getTransaction().getIndexChanges("idxTxAwareMultiValueGetEntriesTest"));
    Set<OIdentifiable> resultTwo = new HashSet<OIdentifiable>();
    cursor = index.iterateEntries(Arrays.asList(1, 2), true);
    cursorToSet(cursor, resultTwo);
    Assert.assertEquals(resultTwo.size(), 2);
    database.rollback();
    Assert.assertNull(database.getTransaction().getIndexChanges("idxTxAwareMultiValueGetEntriesTest"));
    Set<OIdentifiable> resultThree = new HashSet<OIdentifiable>();
    cursor = index.iterateEntries(Arrays.asList(1, 2), true);
    cursorToSet(cursor, resultThree);
    Assert.assertEquals(resultThree.size(), 3);
}
Also used : OIndexTxAwareMultiValue(com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue) OIndexCursor(com.orientechnologies.orient.core.index.OIndexCursor) 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 13 with OIndexCursor

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

the class IndexTxAwareMultiValueGetEntriesTest method testClear.

@Test
public void testClear() {
    database.begin();
    final OIndex<?> index = database.getMetadata().getIndexManager().getIndex("idxTxAwareMultiValueGetEntriesTest");
    Assert.assertTrue(index instanceof OIndexTxAwareMultiValue);
    final int clusterId = database.getDefaultClusterId();
    final List<Long> positions = getValidPositions(clusterId);
    index.put(1, new ORecordId(clusterId, positions.get(0)));
    index.put(1, new ORecordId(clusterId, positions.get(1)));
    index.put(2, new ORecordId(clusterId, positions.get(2)));
    database.commit();
    Assert.assertNull(database.getTransaction().getIndexChanges("idxTxAwareMultiValueGetEntriesTest"));
    Set<OIdentifiable> resultOne = new HashSet<OIdentifiable>();
    OIndexCursor cursor = index.iterateEntries(Arrays.asList(1, 2), true);
    cursorToSet(cursor, resultOne);
    Assert.assertEquals(resultOne.size(), 3);
    database.begin();
    index.clear();
    Assert.assertNotNull(database.getTransaction().getIndexChanges("idxTxAwareMultiValueGetEntriesTest"));
    Set<OIdentifiable> resultTwo = new HashSet<OIdentifiable>();
    cursor = index.iterateEntries(Arrays.asList(1, 2), true);
    cursorToSet(cursor, resultTwo);
    Assert.assertEquals(resultTwo.size(), 0);
    database.rollback();
    Assert.assertNull(database.getTransaction().getIndexChanges("idxTxAwareMultiValueGetEntriesTest"));
    cursor = index.iterateEntries(Arrays.asList(1, 2), true);
    Set<OIdentifiable> resultThree = new HashSet<OIdentifiable>();
    cursorToSet(cursor, resultThree);
    Assert.assertEquals(resultThree.size(), 3);
}
Also used : OIndexTxAwareMultiValue(com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue) OIndexCursor(com.orientechnologies.orient.core.index.OIndexCursor) 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 14 with OIndexCursor

use of com.orientechnologies.orient.core.index.OIndexCursor 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 15 with OIndexCursor

use of com.orientechnologies.orient.core.index.OIndexCursor 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);
}
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

OIndexCursor (com.orientechnologies.orient.core.index.OIndexCursor)53 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)47 ORecordId (com.orientechnologies.orient.core.id.ORecordId)42 Test (org.testng.annotations.Test)41 HashSet (java.util.HashSet)40 OIndexTxAwareMultiValue (com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue)20 OIndexTxAwareOneValue (com.orientechnologies.orient.core.index.OIndexTxAwareOneValue)20 OIndexDefinition (com.orientechnologies.orient.core.index.OIndexDefinition)8 OCompositeIndexDefinition (com.orientechnologies.orient.core.index.OCompositeIndexDefinition)7 OIndexDefinitionMultiValue (com.orientechnologies.orient.core.index.OIndexDefinitionMultiValue)6 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)5 OIndex (com.orientechnologies.orient.core.index.OIndex)3 OIndexCursorCollectionValue (com.orientechnologies.orient.core.index.OIndexCursorCollectionValue)3 OIndexCursorSingleValue (com.orientechnologies.orient.core.index.OIndexCursorSingleValue)3 Map (java.util.Map)3 Set (java.util.Set)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)1 OIndexFullText (com.orientechnologies.orient.core.index.OIndexFullText)1