Search in sources :

Example 36 with ODatabaseDocumentInternal

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

the class OClassImpl method addCluster.

@Override
public OClass addCluster(final String clusterNameOrId) {
    getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
    if (isAbstract()) {
        throw new OSchemaException("Impossible to associate a cluster to an abstract class class");
    }
    acquireSchemaWriteLock();
    try {
        final ODatabaseDocumentInternal database = getDatabase();
        final OStorage storage = database.getStorage();
        if (storage instanceof OStorageProxy) {
            final String cmd = String.format("alter class `%s` addcluster `%s`", name, clusterNameOrId);
            database.command(new OCommandSQL(cmd)).execute();
        } else if (isDistributedCommand()) {
            final int clusterId = owner.createClusterIfNeeded(clusterNameOrId);
            addClusterIdInternal(clusterId);
            final String cmd = String.format("alter class `%s` addcluster `%s`", name, clusterNameOrId);
            final OCommandSQL commandSQL = new OCommandSQL(cmd);
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
        } else {
            final int clusterId = owner.createClusterIfNeeded(clusterNameOrId);
            addClusterIdInternal(clusterId);
        }
    } finally {
        releaseSchemaWriteLock();
    }
    return this;
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 37 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(Locale.ENGLISH);
    newName = newName.toLowerCase(Locale.ENGLISH);
    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 38 with ODatabaseDocumentInternal

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

the class OClassImpl method addSuperClass.

@Override
public OClass addSuperClass(final OClass superClass) {
    getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
    checkParametersConflict(superClass);
    acquireSchemaWriteLock();
    try {
        final ODatabaseDocumentInternal database = getDatabase();
        final OStorage storage = database.getStorage();
        if (storage instanceof OStorageProxy) {
            final String cmd = String.format("alter class `%s` superclass +`%s`", name, superClass != null ? superClass.getName() : null);
            database.command(new OCommandSQL(cmd)).execute();
        } else if (isDistributedCommand()) {
            final String cmd = String.format("alter class `%s` superclass +`%s`", name, superClass != null ? superClass.getName() : null);
            final OCommandSQL commandSQL = new OCommandSQL(cmd);
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
            addSuperClassInternal(superClass);
        } else
            addSuperClassInternal(superClass);
    } finally {
        releaseSchemaWriteLock();
    }
    return this;
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 39 with ODatabaseDocumentInternal

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

the class OClassImpl method setShortName.

public OClass setShortName(String shortName) {
    if (shortName != null) {
        shortName = shortName.trim();
        if (shortName.isEmpty())
            shortName = null;
    }
    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` shortname %s", name, shortName);
            database.command(new OCommandSQL(cmd)).execute();
        } else if (isDistributedCommand()) {
            final String cmd = String.format("alter class `%s` shortname %s", name, shortName);
            final OCommandSQL commandSQL = new OCommandSQL(cmd);
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
            setShortNameInternal(shortName);
        } else
            setShortNameInternal(shortName);
    } finally {
        releaseSchemaWriteLock();
    }
    return this;
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 40 with ODatabaseDocumentInternal

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

the class OClassImpl method setName.

public OClass setName(final String name) {
    if (getName().equals(name))
        return this;
    getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
    final Character wrongCharacter = OSchemaShared.checkClassNameIfValid(name);
    OClass oClass = getDatabase().getMetadata().getSchema().getClass(name);
    if (oClass != null) {
        String error = String.format("Cannot rename class %s to %s. A Class with name %s exists", this.name, name, name);
        throw new OSchemaException(error);
    }
    if (wrongCharacter != null)
        throw new OSchemaException("Invalid class name found. Character '" + wrongCharacter + "' cannot be used in class name '" + name + "'");
    acquireSchemaWriteLock();
    try {
        final ODatabaseDocumentInternal database = getDatabase();
        final OStorage storage = database.getStorage();
        if (storage instanceof OStorageProxy) {
            final String cmd = String.format("alter class `%s` name `%s`", this.name, name);
            database.command(new OCommandSQL(cmd)).execute();
        } else if (isDistributedCommand()) {
            final String cmd = String.format("alter class `%s` name `%s`", this.name, name);
            final OCommandSQL commandSQL = new OCommandSQL(cmd);
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
            setNameInternal(name);
        } else
            setNameInternal(name);
    } finally {
        releaseSchemaWriteLock();
    }
    return this;
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Aggregations

ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)149 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 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)18 OAutoshardedStorage (com.orientechnologies.orient.core.storage.OAutoshardedStorage)18 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)16 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)16 ORID (com.orientechnologies.orient.core.id.ORID)14 OException (com.orientechnologies.common.exception.OException)13 IOException (java.io.IOException)13 ORecordId (com.orientechnologies.orient.core.id.ORecordId)12 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)10 OSchemaException (com.orientechnologies.orient.core.exception.OSchemaException)10 ORecord (com.orientechnologies.orient.core.record.ORecord)8 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)7 OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)6 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)5 OSecurityException (com.orientechnologies.orient.core.exception.OSecurityException)5