Search in sources :

Example 31 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 32 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 33 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)

Example 34 with OStorageProxy

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

the class OMetadataDefault method init.

private void init(final boolean iLoad) {
    final ODatabaseDocumentInternal database = getDatabase();
    schemaClusterId = database.getClusterIdByName(CLUSTER_INTERNAL_NAME);
    final AtomicBoolean schemaLoaded = new AtomicBoolean(false);
    schema = new OSchemaProxy(database.getStorage().getResource(OSchema.class.getSimpleName(), new Callable<OSchemaShared>() {

        public OSchemaShared call() {
            ODatabaseDocumentInternal database = getDatabase();
            final OSchemaShared instance = new OSchemaShared(database.getStorageVersions().classesAreDetectedByClusterId());
            if (iLoad)
                instance.load();
            schemaLoaded.set(true);
            return instance;
        }
    }), database);
    indexManager = new OIndexManagerProxy(database.getStorage().getResource(OIndexManager.class.getSimpleName(), new Callable<OIndexManager>() {

        public OIndexManager call() {
            OIndexManager instance;
            if (database.getStorage() instanceof OStorageProxy)
                instance = new OIndexManagerRemote(database);
            else
                instance = new OIndexManagerShared(database);
            if (iLoad)
                try {
                    instance.load();
                } catch (Exception e) {
                    OLogManager.instance().error(this, "[OMetadata] Error on loading index manager, reset index configuration", e);
                    instance.create();
                }
            return instance;
        }
    }), database);
    security = new OSecurityProxy(database.getStorage().getResource(OSecurity.class.getSimpleName(), new Callable<OSecurity>() {

        public OSecurity call() {
            final OSecurity instance = OSecurityManager.instance().newSecurity();
            if (iLoad) {
                security = instance;
                instance.load();
            }
            return instance;
        }
    }), database);
    commandCache = database.getStorage().getResource(OCommandCache.class.getSimpleName(), new Callable<OCommandCache>() {

        public OCommandCache call() {
            return new OCommandCacheSoftRefs(database.getName());
        }
    });
    final Class<? extends OSecurity> securityClass = (Class<? extends OSecurity>) database.getProperty(ODatabase.OPTIONS.SECURITY.toString());
    if (securityClass != null)
        // INSTALL CUSTOM WRAPPED SECURITY
        try {
            final OSecurity wrapped = security;
            security = securityClass.getDeclaredConstructor(OSecurity.class, ODatabaseDocumentInternal.class).newInstance(wrapped, database);
        } catch (Exception e) {
            throw OException.wrapException(new OSecurityException("Cannot install custom security implementation (" + securityClass + ")"), e);
        }
    functionLibrary = new OFunctionLibraryProxy(database.getStorage().getResource(OFunctionLibrary.class.getSimpleName(), new Callable<OFunctionLibrary>() {

        public OFunctionLibrary call() {
            final OFunctionLibraryImpl instance = new OFunctionLibraryImpl();
            if (iLoad && !(database.getStorage() instanceof OStorageProxy))
                instance.load();
            return instance;
        }
    }), database);
    sequenceLibrary = new OSequenceLibraryProxy(database.getStorage().getResource(OSequenceLibrary.class.getSimpleName(), new Callable<OSequenceLibrary>() {

        @Override
        public OSequenceLibrary call() throws Exception {
            final OSequenceLibraryImpl instance = new OSequenceLibraryImpl();
            if (iLoad) {
                instance.load();
            }
            return instance;
        }
    }), database);
    scheduler = new OSchedulerProxy(database.getStorage().getResource(OScheduler.class.getSimpleName(), new Callable<OScheduler>() {

        public OScheduler call() {
            final OSchedulerImpl instance = new OSchedulerImpl();
            if (iLoad && !(database.getStorage() instanceof OStorageProxy))
                instance.load();
            return instance;
        }
    }), database);
    if (schemaLoaded.get())
        schema.onPostIndexManagement();
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OIndexManagerShared(com.orientechnologies.orient.core.index.OIndexManagerShared) OIndexManagerRemote(com.orientechnologies.orient.core.index.OIndexManagerRemote) OFunctionLibraryImpl(com.orientechnologies.orient.core.metadata.function.OFunctionLibraryImpl) OSequenceLibraryProxy(com.orientechnologies.orient.core.metadata.sequence.OSequenceLibraryProxy) OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) OFunctionLibraryProxy(com.orientechnologies.orient.core.metadata.function.OFunctionLibraryProxy) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) OCommandCacheSoftRefs(com.orientechnologies.orient.core.cache.OCommandCacheSoftRefs) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) OIndexManagerProxy(com.orientechnologies.orient.core.index.OIndexManagerProxy) Callable(java.util.concurrent.Callable) OSequenceLibrary(com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary) OSchemaProxy(com.orientechnologies.orient.core.metadata.schema.OSchemaProxy) OFunctionLibrary(com.orientechnologies.orient.core.metadata.function.OFunctionLibrary) OSchemaShared(com.orientechnologies.orient.core.metadata.schema.OSchemaShared) OSecurity(com.orientechnologies.orient.core.metadata.security.OSecurity) OSequenceLibraryImpl(com.orientechnologies.orient.core.metadata.sequence.OSequenceLibraryImpl) OSchedulerImpl(com.orientechnologies.orient.core.schedule.OSchedulerImpl) OScheduler(com.orientechnologies.orient.core.schedule.OScheduler) OException(com.orientechnologies.common.exception.OException) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) IOException(java.io.IOException) OIndexManager(com.orientechnologies.orient.core.index.OIndexManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OSecurityProxy(com.orientechnologies.orient.core.metadata.security.OSecurityProxy) OSchedulerProxy(com.orientechnologies.orient.core.schedule.OSchedulerProxy)

Example 35 with OStorageProxy

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

the class OSchemaShared method doCreateClass.

private OClass doCreateClass(final String className, int[] clusterIds, int retry, OClass... superClasses) throws ClusterIdsAreEmptyException {
    OClass result;
    final ODatabaseDocumentInternal db = getDatabase();
    final OStorage storage = db.getStorage();
    StringBuilder cmd = null;
    getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_CREATE);
    if (superClasses != null)
        OClassImpl.checkParametersConflict(Arrays.asList(superClasses));
    acquireSchemaWriteLock();
    try {
        final String key = className.toLowerCase();
        if (classes.containsKey(key) && retry == 0)
            throw new OSchemaException("Class '" + className + "' already exists in current database");
        if (!executeThroughDistributedStorage())
            checkClustersAreAbsent(clusterIds);
        if (clusterIds == null || clusterIds.length == 0) {
            clusterIds = createClusters(className, getDatabase().getStorage().getConfiguration().getMinimumClusters());
        }
        cmd = new StringBuilder("create class ");
        if (getDatabase().getStorage().getConfiguration().isStrictSql())
            cmd.append('`');
        cmd.append(className);
        if (getDatabase().getStorage().getConfiguration().isStrictSql())
            cmd.append('`');
        List<OClass> superClassesList = new ArrayList<OClass>();
        if (superClasses != null && superClasses.length > 0) {
            boolean first = true;
            for (OClass superClass : superClasses) {
                // Filtering for null
                if (superClass != null) {
                    if (first)
                        cmd.append(" extends ");
                    else
                        cmd.append(", ");
                    cmd.append('`').append(superClass.getName()).append('`');
                    first = false;
                    superClassesList.add(superClass);
                }
            }
        }
        if (clusterIds != null) {
            if (clusterIds.length == 1 && clusterIds[0] == -1)
                cmd.append(" abstract");
            else {
                cmd.append(" cluster ");
                for (int i = 0; i < clusterIds.length; ++i) {
                    if (i > 0)
                        cmd.append(',');
                    else
                        cmd.append(' ');
                    cmd.append(clusterIds[i]);
                }
            }
        }
        if (executeThroughDistributedStorage()) {
            createClassInternal(className, clusterIds, superClassesList);
            final OAutoshardedStorage autoshardedStorage = (OAutoshardedStorage) storage;
            OCommandSQL commandSQL = new OCommandSQL(cmd.toString());
            commandSQL.addExcludedNode(autoshardedStorage.getNodeId());
            final Object res = db.command(commandSQL).execute();
        } else if (storage instanceof OStorageProxy) {
            db.command(new OCommandSQL(cmd.toString())).execute();
            reload();
        } else
            createClassInternal(className, clusterIds, superClassesList);
        result = classes.get(className.toLowerCase());
        // WAKE UP DB LIFECYCLE LISTENER
        for (Iterator<ODatabaseLifecycleListener> it = Orient.instance().getDbLifecycleListeners(); it.hasNext(); ) it.next().onCreateClass(getDatabase(), result);
    } finally {
        releaseSchemaWriteLock();
    }
    return result;
}
Also used : OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) OStorage(com.orientechnologies.orient.core.storage.OStorage) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OAutoshardedStorage(com.orientechnologies.orient.core.storage.OAutoshardedStorage) ODatabaseLifecycleListener(com.orientechnologies.orient.core.db.ODatabaseLifecycleListener)

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