Search in sources :

Example 61 with OCommandExecutionException

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

the class OCommandExecutorSQLCreateClass method execute.

/**
   * Execute the CREATE CLASS.
   */
public Object execute(final Map<Object, Object> iArgs) {
    if (className == null)
        throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
    final ODatabaseDocument database = getDatabase();
    boolean alreadyExists = database.getMetadata().getSchema().existsClass(className);
    if (!alreadyExists || !ifNotExists) {
        if (clusters != null)
            database.getMetadata().getSchema().createClass(className, clusters, superClasses.toArray(new OClass[0]));
        else
            database.getMetadata().getSchema().createClass(className, clusterIds, superClasses.toArray(new OClass[0]));
    }
    return database.getMetadata().getSchema().getClasses().size();
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException)

Example 62 with OCommandExecutionException

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

the class OCommandExecutorSQLDelegate method parse.

@SuppressWarnings("unchecked")
public OCommandExecutorSQLDelegate parse(final OCommandRequest iCommand) {
    if (iCommand instanceof OCommandRequestText) {
        final OCommandRequestText textRequest = (OCommandRequestText) iCommand;
        final String text = textRequest.getText();
        if (text == null)
            throw new IllegalArgumentException("Command text is null");
        final String textUpperCase = upperCase(text);
        delegate = OSQLEngine.getInstance().getCommand(textUpperCase);
        if (delegate == null)
            throw new OCommandExecutorNotFoundException("Cannot find a command executor for the command request: " + iCommand);
        delegate.setContext(context);
        delegate.setLimit(iCommand.getLimit());
        delegate.parse(iCommand);
        delegate.setProgressListener(progressListener);
        if (delegate.getFetchPlan() != null)
            textRequest.setFetchPlan(delegate.getFetchPlan());
    } else
        throw new OCommandExecutionException("Cannot find a command executor for the command request: " + iCommand);
    return this;
}
Also used : OCommandRequestText(com.orientechnologies.orient.core.command.OCommandRequestText) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OCommandExecutorNotFoundException(com.orientechnologies.orient.core.command.OCommandExecutorNotFoundException)

Example 63 with OCommandExecutionException

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

the class OCommandExecutorSQLDelete method result.

/**
   * Deletes the current record.
   */
public boolean result(final Object iRecord) {
    final ORecordAbstract record = ((OIdentifiable) iRecord).getRecord();
    if (record instanceof ODocument && compiledFilter != null && !Boolean.TRUE.equals(this.compiledFilter.evaluate(record, (ODocument) record, getContext()))) {
        return true;
    }
    try {
        if (record.getIdentity().isValid()) {
            if (returning.equalsIgnoreCase("BEFORE"))
                allDeletedRecords.add(record);
            // RESET VERSION TO DISABLE MVCC AVOIDING THE CONCURRENT EXCEPTION IF LOCAL CACHE IS NOT UPDATED
            ORecordInternal.setVersion(record, -1);
            if (!unsafe && record instanceof ODocument) {
                // CHECK IF ARE VERTICES OR EDGES
                final OClass cls = ((ODocument) record).getSchemaClass();
                if (cls != null) {
                    if (cls.isSubClassOf("V"))
                        // FOUND VERTEX
                        throw new OCommandExecutionException("'DELETE' command cannot delete vertices. Use 'DELETE VERTEX' command instead, or apply the 'UNSAFE' keyword to force it");
                    else if (cls.isSubClassOf("E"))
                        // FOUND EDGE
                        throw new OCommandExecutionException("'DELETE' command cannot delete edges. Use 'DELETE EDGE' command instead, or apply the 'UNSAFE' keyword to force it");
                }
            }
            record.delete();
            recordCount++;
            return true;
        }
        return false;
    } finally {
        if (lockStrategy.equalsIgnoreCase("RECORD"))
            ((OAbstractPaginatedStorage) getDatabase().getStorage()).releaseWriteLock(record.getIdentity());
    }
}
Also used : ORecordAbstract(com.orientechnologies.orient.core.record.ORecordAbstract) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 64 with OCommandExecutionException

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

the class OCommandExecutorSQLDropIndex method execute.

/**
   * Execute the REMOVE INDEX.
   */
public Object execute(final Map<Object, Object> iArgs) {
    if (name == null)
        throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
    if (name.equals("*")) {
        long totalIndexed = 0;
        for (OIndex<?> idx : getDatabase().getMetadata().getIndexManager().getIndexes()) {
            getDatabase().getMetadata().getIndexManager().dropIndex(idx.getName());
            totalIndexed++;
        }
        return totalIndexed;
    } else
        getDatabase().getMetadata().getIndexManager().dropIndex(name);
    return 1;
}
Also used : OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException)

Example 65 with OCommandExecutionException

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

the class OCommandExecutorSQLDropSequence 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().dropSequence(this.sequenceName);
    return true;
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException)

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