Search in sources :

Example 11 with ODatabaseException

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;
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OStorage(com.orientechnologies.orient.core.storage.OStorage) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 12 with ODatabaseException

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;
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OStorage(com.orientechnologies.orient.core.storage.OStorage) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) OCluster(com.orientechnologies.orient.core.storage.OCluster) IOException(java.io.IOException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 13 with ODatabaseException

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;
}
Also used : OImmutableClass(com.orientechnologies.orient.core.metadata.schema.OImmutableClass) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) Method(java.lang.reflect.Method) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OException(com.orientechnologies.common.exception.OException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) OCommandScriptException(com.orientechnologies.orient.core.command.script.OCommandScriptException)

Example 14 with ODatabaseException

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;
}
Also used : OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 15 with ODatabaseException

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;
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Aggregations

ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)28 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)7 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)7 OException (com.orientechnologies.common.exception.OException)5 ORecordId (com.orientechnologies.orient.core.id.ORecordId)5 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)5 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)4 IOException (java.io.IOException)4 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)3 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)3 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)3 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)3 OStorage (com.orientechnologies.orient.core.storage.OStorage)3 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)2 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 ORecord (com.orientechnologies.orient.core.record.ORecord)2 OLocalClusterWrapperStrategy (com.orientechnologies.orient.server.distributed.impl.OLocalClusterWrapperStrategy)2 ArrayList (java.util.ArrayList)2 Test (org.testng.annotations.Test)2 OMultiCollectionIterator (com.orientechnologies.common.collection.OMultiCollectionIterator)1