Search in sources :

Example 1 with OStorageProxy

use of com.orientechnologies.orient.core.storage.OStorageProxy 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 OStorageProxy

use of com.orientechnologies.orient.core.storage.OStorageProxy 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 OStorageProxy

use of com.orientechnologies.orient.core.storage.OStorageProxy 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 OStorageProxy

use of com.orientechnologies.orient.core.storage.OStorageProxy 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 OStorageProxy

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

the class OSchemaShared method dropClass.

/*
   * (non-Javadoc)
   * 
   * @see com.orientechnologies.orient.core.metadata.schema.OSchema#dropClass(java.lang.String)
   */
public void dropClass(final String className) {
    final ODatabaseDocumentInternal db = getDatabase();
    final OStorage storage = db.getStorage();
    final StringBuilder cmd;
    acquireSchemaWriteLock();
    try {
        if (getDatabase().getTransaction().isActive())
            throw new IllegalStateException("Cannot drop a class inside a transaction");
        if (className == null)
            throw new IllegalArgumentException("Class name is null");
        getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_DELETE);
        final String key = className.toLowerCase();
        OClass cls = classes.get(key);
        if (cls == null)
            throw new OSchemaException("Class '" + className + "' was not found in current database");
        if (!cls.getSubclasses().isEmpty())
            throw new OSchemaException("Class '" + className + "' cannot be dropped because it has sub classes " + cls.getSubclasses() + ". Remove the dependencies before trying to drop it again");
        cmd = new StringBuilder("drop class ");
        cmd.append(className);
        cmd.append(" unsafe");
        if (executeThroughDistributedStorage()) {
            final OAutoshardedStorage autoshardedStorage = (OAutoshardedStorage) storage;
            OCommandSQL commandSQL = new OCommandSQL(cmd.toString());
            commandSQL.addExcludedNode(autoshardedStorage.getNodeId());
            db.command(commandSQL).execute();
            dropClassInternal(className);
        } else if (storage instanceof OStorageProxy) {
            final OCommandSQL commandSQL = new OCommandSQL(cmd.toString());
            db.command(commandSQL).execute();
            final OClass classToDrop = getClass(className);
            reload();
            if (// really dropped, for example there may be no rights to drop a class
            getClass(className) == null)
                dropClassIndexes(classToDrop);
        } else
            dropClassInternal(className);
        // FREE THE RECORD CACHE
        getDatabase().getLocalCache().freeCluster(cls.getDefaultClusterId());
    } finally {
        releaseSchemaWriteLock();
    }
}
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) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

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