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