Search in sources :

Example 11 with OIndexTxAwareMultiValue

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

the class IndexTxAwareMultiValueGetTest method testClear.

@Test
public void testClear() {
    database.getMetadata().getIndexManager().reload();
    database.begin();
    final OIndex<?> index = database.getMetadata().getIndexManager().getIndex("idxTxAwareMultiValueGetTest");
    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("idxTxAwareMultiValueGetTest"));
    Assert.assertEquals(((OIndexTxAwareMultiValue) index).get(1).size(), 2);
    Assert.assertEquals(((OIndexTxAwareMultiValue) index).get(2).size(), 1);
    database.begin();
    index.clear();
    Assert.assertNotNull(database.getTransaction().getIndexChanges("idxTxAwareMultiValueGetTest"));
    Assert.assertNull(((OIndexTxAwareMultiValue) index).get(1));
    Assert.assertNull(((OIndexTxAwareMultiValue) index).get(2));
    database.rollback();
    Assert.assertNull(database.getTransaction().getIndexChanges("idxTxAwareMultiValueGetTest"));
    Assert.assertEquals(((OIndexTxAwareMultiValue) index).get(1).size(), 2);
    Assert.assertEquals(((OIndexTxAwareMultiValue) index).get(2).size(), 1);
}
Also used : OIndexTxAwareMultiValue(com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Test(org.testng.annotations.Test)

Example 12 with OIndexTxAwareMultiValue

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

the class IndexTxAwareMultiValueGetTest method testRemoveOneWithinTransaction.

@Test
public void testRemoveOneWithinTransaction() {
    database.getMetadata().getIndexManager().reload();
    database.begin();
    final OIndex<?> index = database.getMetadata().getIndexManager().getIndex("idxTxAwareMultiValueGetTest");
    Assert.assertTrue(index instanceof OIndexTxAwareMultiValue);
    final int clusterId = database.getDefaultClusterId();
    index.put(1, new ORecordId(clusterId, 1));
    index.remove(1, new ORecordId(clusterId, 1));
    Assert.assertNotNull(database.getTransaction().getIndexChanges("idxTxAwareMultiValueGetTest"));
    Collection<?> result = ((OIndexTxAwareMultiValue) index).get(1);
    Assert.assertNull(result);
    database.commit();
    result = ((OIndexTxAwareMultiValue) index).get(1);
    Assert.assertEquals(result.size(), 0);
}
Also used : OIndexTxAwareMultiValue(com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Test(org.testng.annotations.Test)

Example 13 with OIndexTxAwareMultiValue

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

the class IndexTxAwareMultiValueGetTest method testRemoveOne.

@Test
public void testRemoveOne() {
    database.getMetadata().getIndexManager().reload();
    database.begin();
    final OIndex<?> index = database.getMetadata().getIndexManager().getIndex("idxTxAwareMultiValueGetTest");
    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("idxTxAwareMultiValueGetTest"));
    Assert.assertEquals(((OIndexTxAwareMultiValue) index).get(1).size(), 2);
    Assert.assertEquals(((OIndexTxAwareMultiValue) index).get(2).size(), 1);
    database.begin();
    index.remove(1, firstRecordId);
    Assert.assertNotNull(database.getTransaction().getIndexChanges("idxTxAwareMultiValueGetTest"));
    Assert.assertEquals(((OIndexTxAwareMultiValue) index).get(1).size(), 1);
    Assert.assertEquals(((OIndexTxAwareMultiValue) index).get(2).size(), 1);
    database.rollback();
    Assert.assertNull(database.getTransaction().getIndexChanges("idxTxAwareMultiValueGetTest"));
    Assert.assertEquals(((OIndexTxAwareMultiValue) index).get(1).size(), 2);
    Assert.assertEquals(((OIndexTxAwareMultiValue) index).get(2).size(), 1);
}
Also used : OIndexTxAwareMultiValue(com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Test(org.testng.annotations.Test)

Example 14 with OIndexTxAwareMultiValue

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

the class IndexTxAwareMultiValueGetTest method testRemoveAllWithinTransaction.

@Test
public void testRemoveAllWithinTransaction() {
    database.getMetadata().getIndexManager().reload();
    database.begin();
    final OIndex<?> index = database.getMetadata().getIndexManager().getIndex("idxTxAwareMultiValueGetTest");
    Assert.assertTrue(index instanceof OIndexTxAwareMultiValue);
    final int clusterId = database.getDefaultClusterId();
    index.put(1, new ORecordId(clusterId, 1));
    index.remove(1, null);
    Assert.assertNotNull(database.getTransaction().getIndexChanges("idxTxAwareMultiValueGetTest"));
    Collection<?> result = ((OIndexTxAwareMultiValue) index).get(1);
    Assert.assertNull(result);
    database.commit();
    result = ((OIndexTxAwareMultiValue) index).get(1);
    Assert.assertEquals(result.size(), 0);
}
Also used : OIndexTxAwareMultiValue(com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Test(org.testng.annotations.Test)

Example 15 with OIndexTxAwareMultiValue

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

the class IndexTxAwareMultiValueGetEntriesTest method testRemoveOneWithinTransaction.

@Test
public void testRemoveOneWithinTransaction() {
    database.begin();
    final OIndex<?> index = database.getMetadata().getIndexManager().getIndex("idxTxAwareMultiValueGetEntriesTest");
    Assert.assertTrue(index instanceof OIndexTxAwareMultiValue);
    final int clusterId = database.getDefaultClusterId();
    List<Long> positions = getValidPositions(clusterId);
    index.put(1, new ORecordId(clusterId, positions.get(1)));
    index.put(2, new ORecordId(clusterId, positions.get(2)));
    index.remove(1, new ORecordId(clusterId, positions.get(1)));
    Assert.assertNotNull(database.getTransaction().getIndexChanges("idxTxAwareMultiValueGetEntriesTest"));
    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();
    result = new HashSet<OIdentifiable>();
    cursor = index.iterateEntries(Arrays.asList(1, 2), true);
    cursorToSet(cursor, result);
    Assert.assertEquals(result.size(), 1);
}
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)

Aggregations

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