Search in sources :

Example 6 with OException

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");
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OException(com.orientechnologies.common.exception.OException) ORecordSerializerSchemaAware2CSV(com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerSchemaAware2CSV) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 7 with OException

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);
            }
        }
    }
}
Also used : OException(com.orientechnologies.common.exception.OException) OSecurityUser(com.orientechnologies.orient.core.metadata.security.OSecurityUser) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) ODatabaseListener(com.orientechnologies.orient.core.db.ODatabaseListener) OException(com.orientechnologies.common.exception.OException) OModificationOperationProhibitedException(com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)

Example 8 with OException

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;
}
Also used : OQuery(com.orientechnologies.orient.core.query.OQuery) SQLException(java.sql.SQLException) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) OQueryParsingException(com.orientechnologies.orient.core.exception.OQueryParsingException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 9 with OException

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();
    }
}
Also used : ORecordOperation(com.orientechnologies.orient.core.db.record.ORecordOperation) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OLiveQuery(com.orientechnologies.orient.core.sql.query.OLiveQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OException(com.orientechnologies.common.exception.OException) CountDownLatch(java.util.concurrent.CountDownLatch) OLiveResultListener(com.orientechnologies.orient.core.sql.query.OLiveResultListener) Test(org.junit.Test)

Example 10 with OException

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);
}
Also used : OChannelBinary(com.orientechnologies.orient.enterprise.channel.binary.OChannelBinary) DataOutputStream(java.io.DataOutputStream) OClientConnection(com.orientechnologies.orient.server.OClientConnection) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException)

Aggregations

OException (com.orientechnologies.common.exception.OException)21 IOException (java.io.IOException)12 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)11 OModificationOperationProhibitedException (com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)5 OIOException (com.orientechnologies.common.io.OIOException)5 OChannelBinaryAsynchClient (com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient)4 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)3 OInterruptedException (com.orientechnologies.common.concur.lock.OInterruptedException)3 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)3 ORecordId (com.orientechnologies.orient.core.id.ORecordId)3 OTokenException (com.orientechnologies.orient.core.metadata.security.OTokenException)3 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)3 OOfflineClusterException (com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException)3 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)3 OTokenSecurityException (com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException)3 NamingException (javax.naming.NamingException)3 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)2 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)2 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)2 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2