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;
}
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;
}
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();
}
}
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);
}
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";
}
Aggregations