Search in sources :

Example 1 with OStorage

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

the class OPropertyImpl method setDefaultValue.

public OPropertyImpl setDefaultValue(final String defaultValue) {
    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 property %s default %s", getFullNameQuoted(), quoteString(defaultValue));
            database.command(new OCommandSQL(cmd)).execute();
        } else if (isDistributedCommand()) {
            final String cmd = String.format("alter property %s default %s", getFullNameQuoted(), quoteString(defaultValue));
            final OCommandSQL commandSQL = new OCommandSQL(cmd);
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
            setDefaultValueInternal(defaultValue);
        } else {
            setDefaultValueInternal(defaultValue);
        }
    } finally {
        releaseSchemaWriteLock();
    }
    return this;
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OAutoshardedStorage(com.orientechnologies.orient.core.storage.OAutoshardedStorage) OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) OStorage(com.orientechnologies.orient.core.storage.OStorage) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 2 with OStorage

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

the class OPropertyImpl method setCollate.

public OProperty setCollate(String collate) {
    if (collate == null)
        collate = ODefaultCollate.NAME;
    getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
    acquireSchemaWriteLock();
    try {
        final ODatabaseDocumentInternal database = getDatabase();
        final OStorage storage = database.getStorage();
        final String cmd = String.format("alter property %s collate %s", getFullNameQuoted(), quoteString(collate));
        final OCommandSQL commandSQL = new OCommandSQL(cmd);
        if (storage instanceof OStorageProxy) {
            database.command(commandSQL).execute();
        } else if (isDistributedCommand()) {
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
            setCollateInternal(collate);
        } else
            setCollateInternal(collate);
    } finally {
        releaseSchemaWriteLock();
    }
    return this;
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OAutoshardedStorage(com.orientechnologies.orient.core.storage.OAutoshardedStorage) OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) OStorage(com.orientechnologies.orient.core.storage.OStorage) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 3 with OStorage

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

the class OPropertyImpl method setReadonly.

public OPropertyImpl setReadonly(final boolean isReadonly) {
    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 property %s readonly %s", getFullNameQuoted(), isReadonly);
            database.command(new OCommandSQL(cmd)).execute();
        } else if (isDistributedCommand()) {
            final String cmd = String.format("alter property %s readonly %s", getFullNameQuoted(), isReadonly);
            final OCommandSQL commandSQL = new OCommandSQL(cmd);
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
            setReadonlyInternal(isReadonly);
        } else
            setReadonlyInternal(isReadonly);
    } finally {
        releaseSchemaWriteLock();
    }
    return this;
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OAutoshardedStorage(com.orientechnologies.orient.core.storage.OAutoshardedStorage) OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) OStorage(com.orientechnologies.orient.core.storage.OStorage) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 4 with OStorage

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

the class OPropertyImpl method setRegexp.

public OPropertyImpl setRegexp(final String regexp) {
    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 property %s regexp %s", getFullNameQuoted(), quoteString(regexp));
            database.command(new OCommandSQL(cmd)).execute();
        } else if (isDistributedCommand()) {
            final String cmd = String.format("alter property %s regexp %s", getFullNameQuoted(), quoteString(regexp));
            final OCommandSQL commandSQL = new OCommandSQL(cmd);
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
            setRegexpInternal(regexp);
        } else
            setRegexpInternal(regexp);
    } finally {
        releaseSchemaWriteLock();
    }
    return this;
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OAutoshardedStorage(com.orientechnologies.orient.core.storage.OAutoshardedStorage) OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) OStorage(com.orientechnologies.orient.core.storage.OStorage) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 5 with OStorage

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

the class OSchemaShared method createClassInternal.

private OClass createClassInternal(final String className, final int[] clusterIdsToAdd, final List<OClass> superClasses) throws ClusterIdsAreEmptyException {
    acquireSchemaWriteLock();
    try {
        if (className == null || className.length() == 0)
            throw new OSchemaException("Found class name null or empty");
        if (Character.isDigit(className.charAt(0)))
            throw new OSchemaException("Found invalid class name. Cannot start with numbers");
        final Character wrongCharacter = checkClassNameIfValid(className);
        if (wrongCharacter != null)
            throw new OSchemaException("Found invalid class name. Character '" + wrongCharacter + "' cannot be used in class name.");
        final ODatabaseDocumentInternal database = getDatabase();
        final OStorage storage = database.getStorage();
        checkEmbedded(storage);
        checkClustersAreAbsent(clusterIdsToAdd);
        final int[] clusterIds;
        if (clusterIdsToAdd == null || clusterIdsToAdd.length == 0) {
            throw new ClusterIdsAreEmptyException();
        } else
            clusterIds = clusterIdsToAdd;
        database.checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_CREATE);
        final String key = className.toLowerCase();
        if (classes.containsKey(key))
            throw new OSchemaException("Class '" + className + "' already exists in current database");
        OClassImpl cls = new OClassImpl(this, className, clusterIds);
        classes.put(key, cls);
        if (superClasses != null && superClasses.size() > 0) {
            cls.setSuperClassesInternal(superClasses);
            for (OClass superClass : superClasses) {
                // UPDATE INDEXES
                final int[] clustersToIndex = superClass.getPolymorphicClusterIds();
                final String[] clusterNames = new String[clustersToIndex.length];
                for (int i = 0; i < clustersToIndex.length; i++) clusterNames[i] = database.getClusterNameById(clustersToIndex[i]);
                for (OIndex<?> index : superClass.getIndexes()) for (String clusterName : clusterNames) if (clusterName != null)
                    database.getMetadata().getIndexManager().addClusterToIndex(clusterName, index.getName());
            }
        }
        addClusterClassMap(cls);
        return cls;
    } finally {
        releaseSchemaWriteLock();
    }
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Aggregations

OStorage (com.orientechnologies.orient.core.storage.OStorage)90 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)31 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)23 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)22 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)21 ORecordId (com.orientechnologies.orient.core.id.ORecordId)20 OAutoshardedStorage (com.orientechnologies.orient.core.storage.OAutoshardedStorage)18 OStorageProxy (com.orientechnologies.orient.core.storage.OStorageProxy)18 OPhysicalPosition (com.orientechnologies.orient.core.storage.OPhysicalPosition)12 OAbstractPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)11 File (java.io.File)11 ORID (com.orientechnologies.orient.core.id.ORID)10 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)7 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)7 Test (org.testng.annotations.Test)7 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)6 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)6 OCommandOutputListener (com.orientechnologies.orient.core.command.OCommandOutputListener)5 OSchemaException (com.orientechnologies.orient.core.exception.OSchemaException)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5