Search in sources :

Example 56 with ODatabaseDocumentInternal

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

the class OPropertyImpl method setMax.

public OPropertyImpl setMax(final String max) {
    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 max %s", getFullNameQuoted(), quoteString(max));
            database.command(new OCommandSQL(cmd)).execute();
        } else if (isDistributedCommand()) {
            final String cmd = String.format("alter property %s max %s", getFullNameQuoted(), quoteString(max));
            final OCommandSQL commandSQL = new OCommandSQL(cmd);
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
            setMaxInternal(max);
        } else
            setMaxInternal(max);
    } 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 57 with ODatabaseDocumentInternal

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

the class OPropertyImpl method setLinkedType.

public OProperty setLinkedType(final OType linkedType) {
    getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
    checkLinkTypeSupport(getType());
    acquireSchemaWriteLock();
    try {
        final ODatabaseDocumentInternal database = getDatabase();
        final OStorage storage = database.getStorage();
        if (storage instanceof OStorageProxy) {
            final String cmd = String.format("alter property %s linkedtype %s", getFullNameQuoted(), linkedType);
            database.command(new OCommandSQL(cmd)).execute();
        } else if (isDistributedCommand()) {
            final String cmd = String.format("alter property %s linkedtype %s", getFullNameQuoted(), linkedType);
            final OCommandSQL commandSQL = new OCommandSQL(cmd);
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
            setLinkedTypeInternal(linkedType);
        } else
            setLinkedTypeInternal(linkedType);
    } 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 58 with ODatabaseDocumentInternal

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

the class OPropertyImpl method setCustom.

public OPropertyImpl setCustom(final String name, final String value) {
    getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
    acquireSchemaWriteLock();
    try {
        final String cmd = String.format("alter property %s custom %s=%s", getFullNameQuoted(), name, quoteString(value));
        final ODatabaseDocumentInternal database = getDatabase();
        final OStorage storage = database.getStorage();
        if (storage instanceof OStorageProxy) {
            database.command(new OCommandSQL(cmd)).execute();
        } else if (isDistributedCommand()) {
            final OCommandSQL commandSQL = new OCommandSQL(cmd);
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
            setCustomInternal(name, value);
        } else
            setCustomInternal(name, value);
    } 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 59 with ODatabaseDocumentInternal

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

the class OClassImpl method renameCluster.

private void renameCluster(String oldName, String newName) {
    oldName = oldName.toLowerCase();
    newName = newName.toLowerCase();
    final ODatabaseDocumentInternal database = getDatabase();
    final OStorage storage = database.getStorage();
    if (storage.getClusterIdByName(newName) != -1)
        return;
    final int clusterId = storage.getClusterIdByName(oldName);
    if (clusterId == -1)
        return;
    if (!hasClusterId(clusterId))
        return;
    database.command(new OCommandSQL("alter cluster `" + oldName + "` name `" + newName + "`")).execute();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 60 with ODatabaseDocumentInternal

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

the class OClassImpl method dropProperty.

public void dropProperty(final String propertyName) {
    if (getDatabase().getTransaction().isActive())
        throw new IllegalStateException("Cannot drop a property inside a transaction");
    getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_DELETE);
    final String lowerName = propertyName.toLowerCase();
    acquireSchemaWriteLock();
    try {
        if (!properties.containsKey(lowerName))
            throw new OSchemaException("Property '" + propertyName + "' not found in class " + name + "'");
        final ODatabaseDocumentInternal database = getDatabase();
        final OStorage storage = database.getStorage();
        if (storage instanceof OStorageProxy) {
            if (getDatabase().getStorage().getConfiguration().isStrictSql()) {
                database.command(new OCommandSQL("drop property " + name + ".`" + propertyName + "`")).execute();
            } else {
                database.command(new OCommandSQL("drop property " + name + '.' + propertyName)).execute();
            }
        } else if (isDistributedCommand()) {
            OScenarioThreadLocal.executeAsDistributed(new Callable<OProperty>() {

                @Override
                public OProperty call() throws Exception {
                    dropPropertyInternal(propertyName);
                    return null;
                }
            });
            String stm;
            if (getDatabase().getStorage().getConfiguration().isStrictSql()) {
                stm = "drop property " + name + ".`" + propertyName + "`";
            } else {
                stm = "drop property " + name + "." + propertyName;
            }
            final OCommandSQL commandSQL = new OCommandSQL(stm);
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
        } else
            OScenarioThreadLocal.executeAsDistributed(new Callable<OProperty>() {

                @Override
                public OProperty call() throws Exception {
                    dropPropertyInternal(propertyName);
                    return null;
                }
            });
    } finally {
        releaseSchemaWriteLock();
    }
}
Also used : OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) Callable(java.util.concurrent.Callable) 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) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL)

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