Search in sources :

Example 56 with OCommandExecutionException

use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.

the class OCommandExecutorSQLCreateSequence method execute.

@Override
public Object execute(Map<Object, Object> iArgs) {
    if (this.sequenceName == null) {
        throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
    }
    final ODatabaseDocument database = getDatabase();
    database.getMetadata().getSequenceLibrary().createSequence(this.sequenceName, this.sequenceType, this.params);
    return database.getMetadata().getSequenceLibrary().getSequenceCount();
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException)

Example 57 with OCommandExecutionException

use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.

the class OCommandExecutorSQLAlterClass method execute.

/**
   * Execute the ALTER CLASS.
   */
public Object execute(final Map<Object, Object> iArgs) {
    final ODatabaseDocument database = getDatabase();
    if (attribute == null)
        throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
    final OClassImpl cls = (OClassImpl) database.getMetadata().getSchema().getClass(className);
    if (cls == null)
        throw new OCommandExecutionException("Cannot alter class '" + className + "' because not found");
    if (!unsafe && attribute == ATTRIBUTES.NAME && cls.isSubClassOf("E"))
        throw new OCommandExecutionException("Cannot alter class '" + className + "' because is an Edge class and could break vertices. Use UNSAFE if you want to force it");
    // REMOVE CACHE OF COMMAND RESULTS
    for (int clId : cls.getPolymorphicClusterIds()) getDatabase().getMetadata().getCommandCache().invalidateResultsOfCluster(getDatabase().getClusterNameById(clId));
    if (value != null && attribute == ATTRIBUTES.SUPERCLASS) {
        checkClassExists(database, className, decodeClassName(value));
    }
    if (value != null && attribute == ATTRIBUTES.SUPERCLASSES) {
        List<String> classes = Arrays.asList(value.split(",\\s*"));
        for (String cName : classes) {
            checkClassExists(database, className, decodeClassName(cName));
        }
    }
    if (!unsafe && value != null && attribute == ATTRIBUTES.NAME) {
        if (!cls.getIndexes().isEmpty()) {
            throw new OCommandExecutionException("Cannot rename class '" + className + "' because it has indexes defined on it. Drop indexes before or use UNSAFE (at your won risk)");
        }
    }
    cls.set(attribute, value);
    return Boolean.TRUE;
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OClassImpl(com.orientechnologies.orient.core.metadata.schema.OClassImpl)

Example 58 with OCommandExecutionException

use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.

the class OCommandExecutorSQLAlterCluster method execute.

/**
   * Execute the ALTER CLUSTER.
   */
public Object execute(final Map<Object, Object> iArgs) {
    if (attribute == null)
        throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
    final List<OCluster> clusters = getClusters();
    if (clusters.isEmpty())
        throw new OCommandExecutionException("Cluster '" + clusterName + "' not found");
    Object result = null;
    for (OCluster cluster : getClusters()) {
        if (clusterId > -1 && clusterName.equals(String.valueOf(clusterId))) {
            clusterName = cluster.getName();
            result = getDatabase().alterCluster(clusterName, attribute, value);
        } else {
            clusterId = cluster.getId();
            result = getDatabase().alterCluster(clusterId, attribute, value);
        }
    }
    return result;
}
Also used : OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OCluster(com.orientechnologies.orient.core.storage.OCluster)

Example 59 with OCommandExecutionException

use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.

the class OCommandExecutorSQLAlterDatabase method execute.

/**
   * Execute the ALTER DATABASE.
   */
public Object execute(final Map<Object, Object> iArgs) {
    if (attribute == null)
        throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
    final ODatabaseDocumentInternal database = getDatabase();
    database.checkSecurity(ORule.ResourceGeneric.DATABASE, ORole.PERMISSION_UPDATE);
    database.setInternal(attribute, value);
    return null;
}
Also used : OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 60 with OCommandExecutionException

use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.

the class OCommandExecutorSQLAlterProperty method execute.

/**
   * Execute the ALTER PROPERTY.
   */
public Object execute(final Map<Object, Object> iArgs) {
    if (attribute == null)
        throw new OCommandExecutionException("Cannot execute the command because it has not yet been parsed");
    final OClassImpl sourceClass = (OClassImpl) getDatabase().getMetadata().getSchema().getClass(className);
    if (sourceClass == null)
        throw new OCommandExecutionException("Source class '" + className + "' not found");
    final OPropertyImpl prop = (OPropertyImpl) sourceClass.getProperty(fieldName);
    if (prop == null)
        throw new OCommandExecutionException("Property '" + className + "." + fieldName + "' not exists");
    if ("null".equalsIgnoreCase(value))
        prop.set(attribute, null);
    else
        prop.set(attribute, value);
    return null;
}
Also used : OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OClassImpl(com.orientechnologies.orient.core.metadata.schema.OClassImpl) OPropertyImpl(com.orientechnologies.orient.core.metadata.schema.OPropertyImpl)

Aggregations

OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)82 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)20 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)19 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)16 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)15 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)14 OException (com.orientechnologies.common.exception.OException)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)9 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)6 IOException (java.io.IOException)6 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)5 OType (com.orientechnologies.orient.core.metadata.schema.OType)5 OQueryParsingException (com.orientechnologies.orient.core.exception.OQueryParsingException)4 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)4 ORecord (com.orientechnologies.orient.core.record.ORecord)4 OHazelcastPlugin (com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin)4 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)4 ArrayList (java.util.ArrayList)4 ORID (com.orientechnologies.orient.core.id.ORID)3 ORecordId (com.orientechnologies.orient.core.id.ORecordId)3