Search in sources :

Example 41 with OStorageProxy

use of com.orientechnologies.orient.core.storage.OStorageProxy in project orientdb by orientechnologies.

the class ORidBagTest method testFromEmbeddedToSBTreeAndBackTx.

public void testFromEmbeddedToSBTreeAndBackTx() throws IOException {
    OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(7);
    OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(-1);
    if (database.getStorage() instanceof OStorageProxy) {
        OServerAdmin server = new OServerAdmin(database.getURL()).connect("root", ODatabaseHelper.getServerRootPassword());
        server.setGlobalConfiguration(OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD, 7);
        server.setGlobalConfiguration(OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD, -1);
        server.close();
    }
    ORidBag ridBag = new ORidBag();
    ODocument document = new ODocument();
    document.field("ridBag", ridBag);
    Assert.assertTrue(ridBag.isEmbedded());
    database.begin();
    document.save();
    database.commit();
    document.reload();
    ridBag = document.field("ridBag");
    Assert.assertTrue(ridBag.isEmbedded());
    List<OIdentifiable> addedItems = new ArrayList<OIdentifiable>();
    database.begin();
    for (int i = 0; i < 6; i++) {
        ODocument docToAdd = new ODocument();
        docToAdd.save();
        ridBag.add(docToAdd);
        addedItems.add(docToAdd);
    }
    document.save();
    database.commit();
    document.reload();
    ridBag = document.field("ridBag");
    Assert.assertTrue(ridBag.isEmbedded());
    ODocument docToAdd = new ODocument();
    ridBag.add(docToAdd);
    addedItems.add(docToAdd);
    database.begin();
    document.save();
    database.commit();
    Assert.assertTrue(!ridBag.isEmbedded());
    List<OIdentifiable> addedItemsCopy = new ArrayList<OIdentifiable>(addedItems);
    for (OIdentifiable id : ridBag) Assert.assertTrue(addedItems.remove(id));
    Assert.assertTrue(addedItems.isEmpty());
    document.reload();
    ridBag = document.field("ridBag");
    Assert.assertTrue(!ridBag.isEmbedded());
    addedItems.addAll(addedItemsCopy);
    for (OIdentifiable id : ridBag) Assert.assertTrue(addedItems.remove(id));
    Assert.assertTrue(addedItems.isEmpty());
    addedItems.addAll(addedItemsCopy);
    for (int i = 0; i < 3; i++) ridBag.remove(addedItems.remove(i));
    addedItemsCopy.clear();
    addedItemsCopy.addAll(addedItems);
    database.begin();
    document.save();
    database.commit();
    Assert.assertTrue(!ridBag.isEmbedded());
    for (OIdentifiable id : ridBag) Assert.assertTrue(addedItems.remove(id));
    Assert.assertTrue(addedItems.isEmpty());
    document.reload();
    ridBag = document.field("ridBag");
    Assert.assertTrue(!ridBag.isEmbedded());
    addedItems.addAll(addedItemsCopy);
    for (OIdentifiable id : ridBag) Assert.assertTrue(addedItems.remove(id));
    Assert.assertTrue(addedItems.isEmpty());
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) OServerAdmin(com.orientechnologies.orient.client.remote.OServerAdmin) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 42 with OStorageProxy

use of com.orientechnologies.orient.core.storage.OStorageProxy in project orientdb by orientechnologies.

the class OSBTreeRidBagTest method beforeMethod.

@BeforeMethod
public void beforeMethod() throws IOException {
    topThreshold = OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.getValueAsInteger();
    bottomThreshold = OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.getValueAsInteger();
    if (database.getStorage() instanceof OStorageProxy) {
        OServerAdmin server = new OServerAdmin(database.getURL()).connect("root", ODatabaseHelper.getServerRootPassword());
        server.setGlobalConfiguration(OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD, -1);
        server.setGlobalConfiguration(OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD, -1);
        server.close();
    }
    OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(-1);
    OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(-1);
}
Also used : OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) OServerAdmin(com.orientechnologies.orient.client.remote.OServerAdmin) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 43 with OStorageProxy

use of com.orientechnologies.orient.core.storage.OStorageProxy in project orientdb by orientechnologies.

the class RecordReloadTest method documentReloadLatestVersionLinkedValueTwo.

public void documentReloadLatestVersionLinkedValueTwo() throws Exception {
    if (!(database.getStorage() instanceof OStorageProxy))
        return;
    ExecutorService executor = Executors.newSingleThreadExecutor();
    final ODocument document = new ODocument();
    document.field("value", "value one");
    ODocument linkedValue = new ODocument();
    linkedValue.field("val", "value 1");
    document.field("link", linkedValue);
    document.save();
    final ORID rid = document.getIdentity();
    final Future<?> future = executor.submit(new Runnable() {

        @Override
        public void run() {
            ODatabaseDocumentTx db = new ODatabaseDocumentTx(url);
            db.open("admin", "admin");
            ODocument doc = db.load(rid);
            ODocument linkedValue = doc.field("link");
            linkedValue.field("val", "value 2");
            linkedValue.save();
            db.close();
        }
    });
    future.get();
    document.reload("*:1", true, false);
    linkedValue = document.field("link");
    Assert.assertEquals(linkedValue.field("val"), "value 1");
}
Also used : OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) ExecutorService(java.util.concurrent.ExecutorService) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OStorageProxy (com.orientechnologies.orient.core.storage.OStorageProxy)43 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)20 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)18 OAutoshardedStorage (com.orientechnologies.orient.core.storage.OAutoshardedStorage)18 OStorage (com.orientechnologies.orient.core.storage.OStorage)18 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)9 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)9 OrientTest (com.orientechnologies.orient.test.database.base.OrientTest)9 Profile (com.orientechnologies.orient.test.domain.whiz.Profile)9 Test (org.testng.annotations.Test)9 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)7 OServerAdmin (com.orientechnologies.orient.client.remote.OServerAdmin)6 ORID (com.orientechnologies.orient.core.id.ORID)6 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)4 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 OSchemaException (com.orientechnologies.orient.core.exception.OSchemaException)3 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)3 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)3 ORecord (com.orientechnologies.orient.core.record.ORecord)3 ODatabaseLifecycleListener (com.orientechnologies.orient.core.db.ODatabaseLifecycleListener)2