Search in sources :

Example 91 with ODatabaseDocumentInternal

use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.

the class OIndexRIDContainer method convertToSbTree.

private void convertToSbTree() {
    final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.get();
    final OIndexRIDContainerSBTree tree = new OIndexRIDContainerSBTree(fileId, (OAbstractPaginatedStorage) db.getStorage().getUnderlying());
    tree.addAll(underlying);
    underlying = tree;
    isEmbedded = false;
}
Also used : ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 92 with ODatabaseDocumentInternal

use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal 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 93 with ODatabaseDocumentInternal

use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.

the class OClassImpl method addProperty.

private OProperty addProperty(final String propertyName, final OType type, final OType linkedType, final OClass linkedClass, final boolean unsafe) {
    if (type == null)
        throw new OSchemaException("Property type not defined.");
    if (propertyName == null || propertyName.length() == 0)
        throw new OSchemaException("Property name is null or empty");
    if (getDatabase().getStorage().getConfiguration().isStrictSql()) {
        validatePropertyName(propertyName);
    }
    if (getDatabase().getTransaction().isActive())
        throw new OSchemaException("Cannot create property '" + propertyName + "' inside a transaction");
    final ODatabaseDocumentInternal database = getDatabase();
    database.checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
    if (linkedType != null)
        OPropertyImpl.checkLinkTypeSupport(type);
    if (linkedClass != null)
        OPropertyImpl.checkSupportLinkedClass(type);
    acquireSchemaWriteLock();
    try {
        final StringBuilder cmd = new StringBuilder("create property ");
        // CLASS.PROPERTY NAME
        if (getDatabase().getStorage().getConfiguration().isStrictSql())
            cmd.append('`');
        cmd.append(name);
        if (getDatabase().getStorage().getConfiguration().isStrictSql())
            cmd.append('`');
        cmd.append('.');
        if (getDatabase().getStorage().getConfiguration().isStrictSql())
            cmd.append('`');
        cmd.append(propertyName);
        if (getDatabase().getStorage().getConfiguration().isStrictSql())
            cmd.append('`');
        // TYPE
        cmd.append(' ');
        cmd.append(type.name);
        if (linkedType != null) {
            // TYPE
            cmd.append(' ');
            cmd.append(linkedType.name);
        } else if (linkedClass != null) {
            // TYPE
            cmd.append(' ');
            if (getDatabase().getStorage().getConfiguration().isStrictSql())
                cmd.append('`');
            cmd.append(linkedClass.getName());
            if (getDatabase().getStorage().getConfiguration().isStrictSql())
                cmd.append('`');
        }
        if (unsafe)
            cmd.append(" unsafe ");
        final OStorage storage = database.getStorage();
        if (storage instanceof OStorageProxy) {
            database.command(new OCommandSQL(cmd.toString())).execute();
            reload();
            return getProperty(propertyName);
        } else if (isDistributedCommand()) {
            final OProperty prop = (OProperty) OScenarioThreadLocal.executeAsDistributed(new Callable<OProperty>() {

                @Override
                public OProperty call() throws Exception {
                    return addPropertyInternal(propertyName, type, linkedType, linkedClass, unsafe);
                }
            });
            final OCommandSQL commandSQL = new OCommandSQL(cmd.toString());
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
            return prop;
        } else
            return (OProperty) OScenarioThreadLocal.executeAsDistributed(new Callable<OProperty>() {

                @Override
                public OProperty call() throws Exception {
                    return addPropertyInternal(propertyName, type, linkedType, linkedClass, unsafe);
                }
            });
    } finally {
        releaseSchemaWriteLock();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) OException(com.orientechnologies.common.exception.OException) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) IOException(java.io.IOException) OSecurityAccessException(com.orientechnologies.orient.core.exception.OSecurityAccessException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Callable(java.util.concurrent.Callable)

Example 94 with ODatabaseDocumentInternal

use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.

the class OClassImpl method clearCustom.

public void clearCustom() {
    getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
    acquireSchemaWriteLock();
    try {
        final ODatabaseDocumentInternal database = getDatabase();
        final OStorage storage = database.getStorage();
        if (storage instanceof OStorageProxy) {
            final String cmd = String.format("alter class `%s` custom clear", getName());
            database.command(new OCommandSQL(cmd)).execute();
        } else if (isDistributedCommand()) {
            final String cmd = String.format("alter class `%s` custom clear", getName());
            final OCommandSQL commandSQL = new OCommandSQL(cmd);
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
            clearCustomInternal();
        } else
            clearCustomInternal();
    } finally {
        releaseSchemaWriteLock();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 95 with ODatabaseDocumentInternal

use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.

the class ODocument method fetchSchemaIfCan.

private void fetchSchemaIfCan() {
    if (_schema == null) {
        ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
        if (db != null && !db.isClosed()) {
            OMetadataInternal metadata = (OMetadataInternal) db.getMetadata();
            _schema = metadata.getImmutableSchemaSnapshot();
        }
    }
}
Also used : OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Aggregations

ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)139 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)42 OStorage (com.orientechnologies.orient.core.storage.OStorage)31 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)26 OStorageProxy (com.orientechnologies.orient.core.storage.OStorageProxy)20 OAutoshardedStorage (com.orientechnologies.orient.core.storage.OAutoshardedStorage)18 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)17 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)16 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)14 ORID (com.orientechnologies.orient.core.id.ORID)13 IOException (java.io.IOException)13 OException (com.orientechnologies.common.exception.OException)12 ORecordId (com.orientechnologies.orient.core.id.ORecordId)11 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)10 OSchemaException (com.orientechnologies.orient.core.exception.OSchemaException)10 ORecord (com.orientechnologies.orient.core.record.ORecord)7 OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)6 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)5 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)5 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)5