use of com.orientechnologies.common.exception.OException in project orientdb by orientechnologies.
the class TestDistributeConfigSerialization method executeTest.
@Override
protected void executeTest() throws Exception {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("plocal:target/server0/databases/" + getDatabaseName());
try {
db.setSerializer(new ORecordSerializerSchemaAware2CSV());
db.create();
db.getMetadata().getSchema().createClass("TestMessaging");
db.activateOnCurrentThread();
db.save(new ODocument("TestMessaging").field("test", "test"));
db.query(new OSQLSynchQuery("select from TestMessaging "));
db.close();
} catch (OException e) {
e.printStackTrace();
Assert.fail("error on creating a csv database in distributed environment");
}
try {
db = new ODatabaseDocumentTx("remote:localhost/" + getDatabaseName());
db.open("admin", "admin");
db.query(new OSQLSynchQuery("select from TestMessaging "));
db.close();
} catch (OException e) {
e.printStackTrace();
Assert.fail("error on creating a csv database in distributed environment");
}
}
use of com.orientechnologies.common.exception.OException in project orientdb by orientechnologies.
the class OAbstractPaginatedStorage method executeCommand.
public Object executeCommand(final OCommandRequestText iCommand, final OCommandExecutor executor) {
if (iCommand.isIdempotent() && !executor.isIdempotent())
throw new OCommandExecutionException("Cannot execute non idempotent command");
long beginTime = Orient.instance().getProfiler().startChrono();
try {
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.get();
// CALL BEFORE COMMAND
Iterable<ODatabaseListener> listeners = db.getListeners();
for (ODatabaseListener oDatabaseListener : listeners) {
oDatabaseListener.onBeforeCommand(iCommand, executor);
}
boolean foundInCache = false;
Object result = null;
if (iCommand.isCacheableResult() && executor.isCacheable() && iCommand.getParameters() == null) {
// TRY WITH COMMAND CACHE
result = db.getMetadata().getCommandCache().get(db.getUser(), iCommand.getText(), iCommand.getLimit());
if (result != null) {
foundInCache = true;
if (iCommand.getResultListener() != null) {
// INVOKE THE LISTENER IF ANY
if (result instanceof Collection) {
for (Object o : (Collection) result) iCommand.getResultListener().result(o);
} else
iCommand.getResultListener().result(result);
// RESET THE RESULT TO AVOID TO SEND IT TWICE
result = null;
}
}
}
if (!foundInCache) {
// EXECUTE THE COMMAND
result = executor.execute(iCommand.getParameters());
if (result != null && iCommand.isCacheableResult() && executor.isCacheable() && (iCommand.getParameters() == null || iCommand.getParameters().isEmpty()))
// CACHE THE COMMAND RESULT
db.getMetadata().getCommandCache().put(db.getUser(), iCommand.getText(), result, iCommand.getLimit(), executor.getInvolvedClusters(), System.currentTimeMillis() - beginTime);
}
// CALL AFTER COMMAND
for (ODatabaseListener oDatabaseListener : listeners) {
oDatabaseListener.onAfterCommand(iCommand, executor, result);
}
return result;
} catch (OException e) {
// PASS THROUGH
throw e;
} catch (Exception e) {
throw OException.wrapException(new OCommandExecutionException("Error on execution of command: " + iCommand), e);
} finally {
if (Orient.instance().getProfiler().isRecording()) {
final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
if (db != null) {
final OSecurityUser user = db.getUser();
final String userString = user != null ? user.toString() : null;
Orient.instance().getProfiler().stopChrono("db." + ODatabaseRecordThreadLocal.INSTANCE.get().getName() + ".command." + iCommand.toString(), "Command executed against the database", beginTime, "db.*.command.*", null, userString);
}
}
}
}
use of com.orientechnologies.common.exception.OException in project orientdb by orientechnologies.
the class OrientJdbcPreparedStatement method executeQuery.
@SuppressWarnings("unchecked")
public ResultSet executeQuery() throws SQLException {
// return super.executeQuery(sql);
sql = mayCleanForSpark(sql);
if (sql.equalsIgnoreCase("select 1")) {
// OPTIMIZATION
documents = new ArrayList<ODocument>();
documents.add(new ODocument().field("1", 1));
} else {
try {
query = new OSQLSynchQuery<ODocument>(mayCleanForSpark(sql));
documents = database.query((OQuery<? extends Object>) query, params.values().toArray());
} catch (OQueryParsingException e) {
throw new SQLSyntaxErrorException("Error while parsing query", e);
} catch (OException e) {
throw new SQLException("Error while executing query", e);
}
}
// return super.executeQuery(sql);
resultSet = new OrientJdbcResultSet(this, documents, resultSetType, resultSetConcurrency, resultSetHoldability);
return resultSet;
}
use of com.orientechnologies.common.exception.OException in project orientdb by orientechnologies.
the class OLiveQueryShotdownTest method testShutDown.
@Test
public void testShutDown() throws Exception {
bootServer();
ODatabaseDocument db = new ODatabaseDocumentTx("remote:localhost/" + OLiveQueryShotdownTest.class.getSimpleName());
db.open("admin", "admin");
db.getMetadata().getSchema().createClass("Test");
final CountDownLatch error = new CountDownLatch(1);
try {
db.command(new OLiveQuery("live select from Test", new OLiveResultListener() {
@Override
public void onUnsubscribe(int iLiveToken) {
}
@Override
public void onLiveResult(int iLiveToken, ORecordOperation iOp) throws OException {
}
@Override
public void onError(int iLiveToken) {
error.countDown();
}
})).execute();
shutdownServer();
assertTrue("onError method never called on shutdow", error.await(2, TimeUnit.SECONDS));
} finally {
// db.close();
}
}
use of com.orientechnologies.common.exception.OException in project orientdb by orientechnologies.
the class OLiveCommandResultListener method onLiveResult.
public void onLiveResult(int iToken, ORecordOperation iOp) throws OException {
boolean sendFail = true;
do {
List<OClientConnection> connections = session.getConnections();
if (connections.size() == 0) {
try {
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.get();
OLogManager.instance().warn(this, "Unsubscribing live query for connection " + connection);
OLiveQueryHook.unsubscribe(iToken, db);
} catch (Exception e) {
OLogManager.instance().warn(this, "Unsubscribing live query for connection " + connection, e);
}
break;
}
OClientConnection curConnection = connections.get(0);
ONetworkProtocolBinary protocol = (ONetworkProtocolBinary) curConnection.getProtocol();
OChannelBinary channel = protocol.getChannel();
try {
channel.acquireWriteLock();
try {
ByteArrayOutputStream content = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(content);
out.writeByte('r');
out.writeByte(iOp.type);
out.writeInt(iToken);
out.writeByte(ORecordInternal.getRecordType(iOp.getRecord()));
writeVersion(out, iOp.getRecord().getVersion());
writeRID(out, (ORecordId) iOp.getRecord().getIdentity());
writeBytes(out, protocol.getRecordBytes(connection, iOp.getRecord()));
channel.writeByte(OChannelBinaryProtocol.PUSH_DATA);
channel.writeInt(Integer.MIN_VALUE);
channel.writeByte(OChannelBinaryProtocol.REQUEST_PUSH_LIVE_QUERY);
channel.writeBytes(content.toByteArray());
channel.flush();
} finally {
channel.releaseWriteLock();
}
sendFail = false;
} catch (IOException e) {
session.removeConnection(curConnection);
connections = session.getConnections();
if (connections.isEmpty()) {
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.get();
OLiveQueryHook.unsubscribe(iToken, db);
break;
}
} catch (Exception e) {
OLogManager.instance().warn(this, "Cannot push cluster configuration to the client %s", e, protocol.getRemoteAddress());
protocol.getServer().getClientConnectionManager().disconnect(connection);
OLiveQueryHook.unsubscribe(iToken, connection.getDatabase());
break;
}
} while (sendFail);
}
Aggregations