Search in sources :

Example 1 with ODatabaseException

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

the class OSerializableWrapper method toStream.

@Override
public byte[] toStream() throws OSerializationException {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    try {
        ObjectOutputStream writer = new ObjectOutputStream(output);
        writer.writeObject(serializable);
        writer.close();
    } catch (IOException e) {
        throw OException.wrapException(new ODatabaseException("Error on serialization of Serializable"), e);
    }
    return output.toByteArray();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 2 with ODatabaseException

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

the class OrientGraphFactory method getDatabase.

/**
   * Gives new connection to database. If current factory configured to use pool (see {@link #setupPool(int, int)} method),
   * retrieves connection from pool. Otherwise creates new connection each time.
   *
   * @param iCreate if true automatically creates database if database with given URL does not exist
   * @param iOpen   if true automatically opens the database
   * @return database
   */
public ODatabaseDocumentTx getDatabase(final boolean iCreate, final boolean iOpen) {
    if (pool != null)
        return pool.acquire();
    final ODatabaseDocumentTx db = new ODatabaseDocumentTx(url);
    final String connMode = settings.getConnectionStrategy();
    db.setProperty(OStorageRemote.PARAM_CONNECTION_STRATEGY, connMode);
    for (Map.Entry<String, Object> entry : properties.entrySet()) {
        db.setProperty(entry.getKey(), entry.getValue());
    }
    if (!db.getURL().startsWith("remote:") && !db.exists()) {
        if (iCreate)
            db.create();
        else if (iOpen)
            throw new ODatabaseException("Database '" + url + "' not found");
    } else if (iOpen)
        db.open(user, password);
    return db;
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with ODatabaseException

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

the class OrientBaseGraph method makeActive.

public void makeActive() {
    if (database == null) {
        throw new ODatabaseException("Database is closed");
    }
    activeGraph.set(this);
    final ODatabaseDocument tlDb = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
    if (tlDb != database)
        ODatabaseRecordThreadLocal.INSTANCE.set(getDatabase());
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException)

Example 4 with ODatabaseException

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

the class OrientBaseGraph method shutdown.

/**
   * Closes the Graph. After closing the Graph cannot be used.
   */
public void shutdown(boolean closeDb, boolean commitTx) {
    makeActive();
    try {
        if (!isClosed() && commitTx) {
            final OStorage storage = getDatabase().getStorage().getUnderlying();
            if (storage instanceof OAbstractPaginatedStorage) {
                if (((OAbstractPaginatedStorage) storage).getWALInstance() != null)
                    getDatabase().commit();
            }
        }
    } catch (RuntimeException e) {
        OLogManager.instance().error(this, "Error during context close for db " + url, e);
        throw e;
    } catch (Exception e) {
        OLogManager.instance().error(this, "Error during context close for db " + url, e);
        throw OException.wrapException(new ODatabaseException("Error during context close for db " + url), e);
    } finally {
        try {
            if (closeDb) {
                getDatabase().close();
                if (getDatabase().isPooled()) {
                    database = null;
                }
            }
        } catch (Exception e) {
            OLogManager.instance().error(this, "Error during context close for db " + url, e);
        }
    }
    url = null;
    username = null;
    password = null;
    pollGraphFromStack(closeDb);
    if (!closeDb)
        getDatabase().activateOnCurrentThread();
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) OException(com.orientechnologies.common.exception.OException) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 5 with ODatabaseException

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

the class TestExceptionNotOpen method testExceptionNotOpenMemory.

@Test
public void testExceptionNotOpenMemory() {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:testExceptionNotOpenMemory");
    try {
        db.save(new ODocument());
        Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
        db.delete(new ODocument());
        Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
        db.hide(new ORecordId());
        Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
        db.begin();
        Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
        db.begin(OTransaction.TXTYPE.NOTX);
        Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
        db.rollback();
        Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
        db.commit();
        Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
        db.getMetadata();
        Assert.fail();
    } catch (ODatabaseException ex) {
    }
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

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