Search in sources :

Example 56 with ORidBag

use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.

the class OPropertyRidBagAbstractIndexDefinitionTest method testCreateValueTwoParametersArrayParams.

public void testCreateValueTwoParametersArrayParams() {
    ORidBag ridBag = new ORidBag();
    ridBag.setAutoConvertToRecord(false);
    ridBag.add(new ORecordId("#1:12"));
    ridBag.add(new ORecordId("#1:23"));
    final Object result = propertyIndex.createValue(ridBag, "25");
    Assert.assertTrue(result instanceof Collection);
    final Collection<?> collectionResult = (Collection<?>) result;
    Assert.assertEquals(collectionResult.size(), 2);
    Assert.assertTrue(collectionResult.contains(new ORecordId("#1:12")));
    Assert.assertTrue(collectionResult.contains(new ORecordId("#1:23")));
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 57 with ORidBag

use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.

the class OPropertyRidBagAbstractIndexDefinitionTest method testCreateValueTwoParameters.

public void testCreateValueTwoParameters() {
    ORidBag ridBag = new ORidBag();
    ridBag.setAutoConvertToRecord(false);
    ridBag.add(new ORecordId("#1:12"));
    ridBag.add(new ORecordId("#1:23"));
    final Object result = propertyIndex.createValue(Arrays.asList(ridBag, "25"));
    Assert.assertTrue(result instanceof Collection);
    final Collection<?> collectionResult = (Collection<?>) result;
    Assert.assertEquals(collectionResult.size(), 2);
    Assert.assertTrue(collectionResult.contains(new ORecordId("#1:12")));
    Assert.assertTrue(collectionResult.contains(new ORecordId("#1:23")));
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 58 with ORidBag

use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.

the class OSBTreeRidBagConcurrencySingleRidBag method testConcurrency.

public void testConcurrency() throws Exception {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(URL);
    if (db.exists()) {
        db.open("admin", "admin");
        db.drop();
    }
    db.create();
    db.declareIntent(new OIntentMassiveInsert());
    ODocument document = new ODocument();
    ORidBag ridBag = new ORidBag();
    ridBag.setAutoConvertToRecord(false);
    document.field("ridBag", ridBag);
    for (int i = 0; i < 100; i++) {
        final ORID ridToAdd = new ORecordId(0, positionCounter.incrementAndGet());
        ridBag.add(ridToAdd);
        ridTree.add(ridToAdd);
    }
    document.save();
    docContainerRid = document.getIdentity();
    List<Future<Void>> futures = new ArrayList<Future<Void>>();
    for (int i = 0; i < 5; i++) futures.add(threadExecutor.submit(new RidAdder(i)));
    for (int i = 0; i < 5; i++) futures.add(threadExecutor.submit(new RidDeleter(i)));
    latch.countDown();
    Thread.sleep(30 * 60000);
    cont = false;
    for (Future<Void> future : futures) future.get();
    document = db.load(document.getIdentity());
    document.setLazyLoad(false);
    ridBag = document.field("ridBag");
    for (OIdentifiable identifiable : ridBag) Assert.assertTrue(ridTree.remove(identifiable.getIdentity()));
    Assert.assertTrue(ridTree.isEmpty());
    System.out.println("Result size is " + ridBag.size());
    db.close();
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Future(java.util.concurrent.Future) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 59 with ORidBag

use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.

the class OCompositeIndexDefinitionTest method testDocumentToIndexRidBagValueSuccessfulOne.

@Test
public void testDocumentToIndexRidBagValueSuccessfulOne() {
    final ODocument document = new ODocument();
    final ORidBag ridBag = new ORidBag();
    ridBag.setAutoConvertToRecord(false);
    ridBag.add(new ORecordId("#1:10"));
    ridBag.add(new ORecordId("#1:11"));
    ridBag.add(new ORecordId("#1:11"));
    document.field("fOne", 12);
    document.field("fTwo", ridBag);
    final OCompositeIndexDefinition compositeIndexDefinition = new OCompositeIndexDefinition("testCollectionClass");
    compositeIndexDefinition.addIndex(new OPropertyIndexDefinition("testCollectionClass", "fOne", OType.INTEGER));
    compositeIndexDefinition.addIndex(new OPropertyRidBagIndexDefinition("testCollectionClass", "fTwo"));
    final Object result = compositeIndexDefinition.getDocumentValueToIndex(document);
    final ArrayList<OCompositeKey> expectedResult = new ArrayList<OCompositeKey>();
    expectedResult.add(new OCompositeKey(12, new ORecordId("#1:10")));
    expectedResult.add(new OCompositeKey(12, new ORecordId("#1:11")));
    expectedResult.add(new OCompositeKey(12, new ORecordId("#1:11")));
    Assert.assertEquals(result, expectedResult);
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 60 with ORidBag

use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.

the class OCompositeIndexDefinitionTest method testCreateRidBagValueSuccessfulTwo.

@Test
public void testCreateRidBagValueSuccessfulTwo() {
    final OCompositeIndexDefinition compositeIndexDefinition = new OCompositeIndexDefinition("testCollectionClass");
    compositeIndexDefinition.addIndex(new OPropertyRidBagIndexDefinition("testCollectionClass", "fTwo"));
    compositeIndexDefinition.addIndex(new OPropertyIndexDefinition("testCollectionClass", "fOne", OType.INTEGER));
    ORidBag ridBag = new ORidBag();
    ridBag.setAutoConvertToRecord(false);
    ridBag.add(new ORecordId("#1:10"));
    ridBag.add(new ORecordId("#1:11"));
    ridBag.add(new ORecordId("#1:11"));
    final Object result = compositeIndexDefinition.createValue(Arrays.asList(ridBag, 12));
    final ArrayList<OCompositeKey> expectedResult = new ArrayList<OCompositeKey>();
    expectedResult.add(new OCompositeKey(new ORecordId("#1:10"), 12));
    expectedResult.add(new OCompositeKey(new ORecordId("#1:11"), 12));
    expectedResult.add(new OCompositeKey(new ORecordId("#1:11"), 12));
    Assert.assertEquals(result, expectedResult);
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Test(org.testng.annotations.Test)

Aggregations

ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)135 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)103 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)70 ORecordId (com.orientechnologies.orient.core.id.ORecordId)37 ArrayList (java.util.ArrayList)27 Test (org.testng.annotations.Test)24 ORID (com.orientechnologies.orient.core.id.ORID)21 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)15 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)13 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)11 OStorage (com.orientechnologies.orient.core.storage.OStorage)7 HashSet (java.util.HashSet)7 ORecordLazyList (com.orientechnologies.orient.core.db.record.ORecordLazyList)6 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)6 ORecordLazyMultiValue (com.orientechnologies.orient.core.db.record.ORecordLazyMultiValue)4 ORecordLazySet (com.orientechnologies.orient.core.db.record.ORecordLazySet)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)3