Search in sources :

Example 76 with OCommandExecutionException

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

the class OQueryOperatorInstanceof method evaluateExpression.

@Override
protected boolean evaluateExpression(final OIdentifiable iRecord, final OSQLFilterCondition iCondition, final Object iLeft, final Object iRight, OCommandContext iContext) {
    final OSchema schema = ((OMetadataInternal) ODatabaseRecordThreadLocal.INSTANCE.get().getMetadata()).getImmutableSchemaSnapshot();
    final String baseClassName = iRight.toString();
    final OClass baseClass = schema.getClass(baseClassName);
    if (baseClass == null)
        throw new OCommandExecutionException("Class '" + baseClassName + "' is not defined in database schema");
    OClass cls = null;
    if (iLeft instanceof OIdentifiable) {
        // GET THE RECORD'S CLASS
        final ORecord record = ((OIdentifiable) iLeft).getRecord();
        if (record instanceof ODocument) {
            cls = ODocumentInternal.getImmutableSchemaClass(((ODocument) record));
        }
    } else if (iLeft instanceof String)
        // GET THE CLASS BY NAME
        cls = schema.getClass((String) iLeft);
    return cls != null ? cls.isSubClassOf(baseClass) : false;
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal) ORecord(com.orientechnologies.orient.core.record.ORecord) 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 77 with OCommandExecutionException

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

the class OMatchStatement method getLowerSubclass.

private String getLowerSubclass(String className1, String className2) {
    OSchema schema = getDatabase().getMetadata().getSchema();
    OClass class1 = schema.getClass(className1);
    OClass class2 = schema.getClass(className2);
    if (class1 == null) {
        throw new OCommandExecutionException("Class " + className1 + " not found in the schema");
    }
    if (class2 == null) {
        throw new OCommandExecutionException("Class " + className2 + " not found in the schema");
    }
    if (class1.isSubClassOf(class2)) {
        return class1.getName();
    }
    if (class2.isSubClassOf(class1)) {
        return class2.getName();
    }
    return null;
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException)

Example 78 with OCommandExecutionException

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

the class OCommandExecutorSQLCreateSequenceTest method testDrop.

@Test
public void testDrop() {
    db.command(new OCommandSQL("CREATE SEQUENCE SequenceDrop TYPE ORDERED")).execute();
    List<ODocument> results = db.query(new OSQLSynchQuery("select sequence('SequenceDrop').next() as val"));
    assertEquals(results.size(), 1);
    for (ODocument result : results) {
        assertEquals(result.field("val"), 1L);
    }
    db.command(new OCommandSQL("drop sequence SequenceDrop")).execute();
    try {
        results = db.query(new OSQLSynchQuery("select sequence('SequenceDrop').next() as val"));
        fail();
    } catch (OCommandSQLParsingException e) {
    } catch (OCommandExecutionException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 79 with OCommandExecutionException

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

the class OCommandExecutorSQLHARemoveServer method execute.

/**
   * Execute the command.
   */
public Object execute(final Map<Object, Object> iArgs) {
    final ODatabaseDocumentInternal database = getDatabase();
    database.checkSecurity(ORule.ResourceGeneric.SERVER, "remove", ORole.PERMISSION_EXECUTE);
    final String dbUrl = database.getURL();
    final String path = dbUrl.substring(dbUrl.indexOf(":") + 1);
    final OServer serverInstance = OServer.getInstanceByPath(path);
    final OHazelcastPlugin dManager = (OHazelcastPlugin) serverInstance.getDistributedManager();
    if (dManager == null || !dManager.isEnabled())
        throw new OCommandExecutionException("OrientDB is not started in distributed mode");
    final String databaseName = database.getName();
    return dManager.removeNodeFromConfiguration(parsedStatement.serverName.getStringValue(), databaseName, false, true);
}
Also used : OServer(com.orientechnologies.orient.server.OServer) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OHazelcastPlugin(com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 80 with OCommandExecutionException

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

the class OCommandExecutorSQLHASyncCluster method execute.

/**
   * Execute the SYNC CLUSTER.
   */
public Object execute(final Map<Object, Object> iArgs) {
    final ODatabaseDocumentInternal database = getDatabase();
    database.checkSecurity(ORule.ResourceGeneric.CLUSTER, "sync", ORole.PERMISSION_UPDATE);
    final String dbUrl = database.getURL();
    final String path = dbUrl.substring(dbUrl.indexOf(":") + 1);
    final OServer serverInstance = OServer.getInstanceByPath(path);
    final OHazelcastPlugin dManager = (OHazelcastPlugin) serverInstance.getDistributedManager();
    if (dManager == null || !dManager.isEnabled())
        throw new OCommandExecutionException("OrientDB is not started in distributed mode");
    final String databaseName = database.getName();
    try {
        if (this.parsedStatement.modeFull) {
            return replaceCluster(dManager, database, serverInstance, databaseName, this.parsedStatement.clusterName.getStringValue());
        }
    // else {
    // int merged = 0;
    // return String.format("Merged %d records", merged);
    // }
    } catch (Exception e) {
        throw OException.wrapException(new OCommandExecutionException("Cannot execute synchronization of cluster"), e);
    }
    return "Mode not supported";
}
Also used : OServer(com.orientechnologies.orient.server.OServer) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OHazelcastPlugin(com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) OException(com.orientechnologies.common.exception.OException) OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) IOException(java.io.IOException)

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