use of com.orientechnologies.orient.core.exception.ODatabaseException in project orientdb by orientechnologies.
the class OServerCommandPostDatabase method execute.
@Override
public boolean execute(final OHttpRequest iRequest, OHttpResponse iResponse) throws Exception {
String[] urlParts = checkSyntax(iRequest.url, 3, "Syntax error: database/<db>/<type>");
iRequest.data.commandInfo = "Create database";
try {
final String databaseName = urlParts[1];
final String storageMode = urlParts[2];
String url = getStoragePath(databaseName, storageMode);
final String type = urlParts.length > 3 ? urlParts[3] : "document";
if (url != null) {
final ODatabaseDocumentInternal database = new ODatabaseDocumentTx(url);
if (database.exists()) {
iResponse.send(OHttpUtils.STATUS_CONFLICT_CODE, OHttpUtils.STATUS_CONFLICT_DESCRIPTION, OHttpUtils.CONTENT_TEXT_PLAIN, "Database '" + database.getURL() + "' already exists.", null);
} else {
for (OStorage stg : Orient.instance().getStorages()) {
if (stg.getName().equalsIgnoreCase(database.getName()) && stg.exists())
throw new ODatabaseException("Database named '" + database.getName() + "' already exists: " + stg);
}
OLogManager.instance().info(this, "Creating database: " + url);
database.create();
sendDatabaseInfo(iRequest, iResponse, database);
}
} else {
throw new OCommandExecutionException("The '" + storageMode + "' storage mode does not exists.");
}
} finally {
}
return false;
}
use of com.orientechnologies.orient.core.exception.ODatabaseException in project orientdb by orientechnologies.
the class OCommandExecutorSQLTruncateCluster method execute.
/**
* Execute the command.
*/
public Object execute(final Map<Object, Object> iArgs) {
if (clusterName == null)
throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
final ODatabaseDocumentInternal database = getDatabase();
final int clusterId = database.getClusterIdByName(clusterName);
if (clusterId < 0) {
throw new ODatabaseException("Cluster with name " + clusterName + " does not exist");
}
final OSchema schema = database.getMetadata().getSchema();
final OClass clazz = schema.getClassByClusterId(clusterId);
if (clazz == null) {
final OStorage storage = database.getStorage();
final OCluster cluster = storage.getClusterById(clusterId);
if (cluster == null) {
throw new ODatabaseException("Cluster with name " + clusterName + " does not exist");
}
try {
storage.checkForClusterPermissions(cluster.getName());
cluster.truncate();
} catch (IOException ioe) {
throw OException.wrapException(new ODatabaseException("Error during truncation of cluster with name " + clusterName), ioe);
}
} else {
clazz.truncateCluster(clusterName);
}
return true;
}
use of com.orientechnologies.orient.core.exception.ODatabaseException in project orientdb by orientechnologies.
the class OClassTrigger method executeMethod.
private RESULT executeMethod(final ODocument iDocument, final Object[] clzMethod) {
if (clzMethod[0] instanceof Class && clzMethod[1] instanceof Method) {
Method method = (Method) clzMethod[1];
Class clz = (Class) clzMethod[0];
String result = null;
try {
result = (String) method.invoke(clz.newInstance(), iDocument);
} catch (Exception ex) {
throw OException.wrapException(new ODatabaseException("Failed to invoke method " + method.getName()), ex);
}
if (result == null) {
return RESULT.RECORD_NOT_CHANGED;
}
return RESULT.valueOf(result);
}
return RESULT.RECORD_NOT_CHANGED;
}
use of com.orientechnologies.orient.core.exception.ODatabaseException in project orientdb by orientechnologies.
the class OIdentifiableIterator method readCurrentRecord.
/**
* Read the current record and increment the counter if the record was found.
*
* @param iRecord
* to read value from database inside it. If record is null link will be created and stored in it.
* @return record which was read from db.
*/
protected ORecord readCurrentRecord(ORecord iRecord, final int iMovement) {
if (limit > -1 && browsedRecords >= limit)
// LIMIT REACHED
return null;
do {
final boolean moveResult;
switch(iMovement) {
case 1:
moveResult = nextPosition();
break;
case -1:
moveResult = prevPosition();
break;
case 0:
moveResult = checkCurrentPosition();
break;
default:
throw new IllegalStateException("Invalid movement value : " + iMovement);
}
if (!moveResult)
return null;
try {
if (iRecord != null) {
ORecordInternal.setIdentity(iRecord, new ORecordId(current.getClusterId(), current.getClusterPosition()));
iRecord = lowLevelDatabase.load(iRecord, fetchPlan, false, true, iterateThroughTombstones, lockingStrategy);
} else
iRecord = lowLevelDatabase.load(current, fetchPlan, false, true, iterateThroughTombstones, lockingStrategy);
} catch (ODatabaseException e) {
if (Thread.interrupted() || lowLevelDatabase.isClosed())
// THREAD INTERRUPTED: RETURN
throw e;
if (e.getCause() instanceof OSecurityException)
throw e;
OLogManager.instance().error(this, "Error on fetching record during browsing. The record has been skipped", e);
}
if (iRecord != null) {
browsedRecords++;
return iRecord;
}
} while (iMovement != 0);
return null;
}
use of com.orientechnologies.orient.core.exception.ODatabaseException in project orientdb by orientechnologies.
the class OClassImpl method removeClusterId.
public OClass removeClusterId(final int clusterId) {
getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
if (clusterIds.length == 1 && clusterId == clusterIds[0])
throw new ODatabaseException(" Impossible to remove the last cluster of class '" + getName() + "' drop the class instead");
acquireSchemaWriteLock();
try {
final ODatabaseDocumentInternal database = getDatabase();
final OStorage storage = database.getStorage();
if (storage instanceof OStorageProxy) {
final String cmd = String.format("alter class `%s` removecluster %d", name, clusterId);
database.command(new OCommandSQL(cmd)).execute();
} else if (isDistributedCommand()) {
final String cmd = String.format("alter class `%s` removecluster %d", name, clusterId);
final OCommandSQL commandSQL = new OCommandSQL(cmd);
commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
database.command(commandSQL).execute();
removeClusterIdInternal(clusterId);
} else
removeClusterIdInternal(clusterId);
} finally {
releaseSchemaWriteLock();
}
return this;
}
Aggregations