Package org.hsqldb

Examples of org.hsqldb.Session


                inStream = new DataInputStream(request.getInputStream());

                int  databaseID = inStream.readInt();
                long sessionID  = inStream.readLong();
                int  mode       = inStream.readByte();
                Session session = DatabaseManager.getSession(databaseID,
                    sessionID);
                Result resultIn = Result.newResult(session, mode, inStream,
                                                   rowIn);

                resultIn.setDatabaseId(databaseID);
                resultIn.setSessionId(sessionID);

                Result resultOut;
                int    type = resultIn.getType();

                if (type == ResultConstants.CONNECT) {
                    try {
                        session = DatabaseManager.newSession(
                            dbType, dbPath, resultIn.getMainString(),
                            resultIn.getSubString(), new HsqlProperties(),
                            resultIn.getZoneString(),
                            resultIn.getUpdateCount());

                        resultIn.readAdditionalResults(null, inStream, rowIn);

                        resultOut = Result.newConnectionAcknowledgeResponse(
                            session.getDatabase(), session.getId(),
                            session.getDatabase().getDatabaseID());
                    } catch (HsqlException e) {
                        resultOut = Result.newErrorResult(e);
                    }
                } else if (type == ResultConstants.DISCONNECT
                           || type == ResultConstants.RESETSESSION) {

                    // Upon DISCONNECT 6 bytes are read by the ClientConnectionHTTP": mode (1 byte), a length (int), and an 'additional results (1 byte)
                    response.setHeader("Cache-Control", "no-cache");    // DB-traffic should not be cached by proxy's
                    response.setContentType("application/octet-stream");
                    response.setContentLength(6);

                    // Only acquire output-stream after headers are set
                    dataOut = new DataOutputStream(response.getOutputStream());

                    dataOut.writeByte(ResultConstants.DISCONNECT);      // Mode
                    dataOut.writeInt(4);                                //Length Int of first result is always read! Minvalue is 4: It is the number of bytes of the current result (it includes the length of this Int itself)
                    dataOut.writeByte(ResultConstants.NONE);            // No Additional results
                    dataOut.close();

                    return;
                } else {
                    int  dbId      = resultIn.getDatabaseId();
                    long sessionId = resultIn.getSessionId();

                    session = DatabaseManager.getSession(dbId, sessionId);

                    resultIn.readLobResults(session, inStream, rowIn);

                    resultOut = session.execute(resultIn);
                }

                HsqlByteArrayOutputStream memStream =
                    new HsqlByteArrayOutputStream();
                DataOutputStream tempOutput = new DataOutputStream(memStream);
View Full Code Here


        try {
            DataInputStream dataIn     = new DataInputStream(inStream);
            int             databaseID = dataIn.readInt();
            long            sessionID  = dataIn.readLong();
            int             mode       = dataIn.readByte();
            Session session = DatabaseManager.getSession(databaseID,
                sessionID);
            Result resultIn = Result.newResult(session, mode, dataIn, rowIn);

            resultIn.setDatabaseId(databaseID);
            resultIn.setSessionId(sessionID);

            //
            Result resultOut;

            if (resultIn.getType() == ResultConstants.CONNECT) {
                try {
                    String databaseName = resultIn.getDatabaseName();
                    int    dbIndex      = server.getDBIndex(databaseName);
                    int    dbID         = server.dbID[dbIndex];

                    session =
                        DatabaseManager.newSession(dbID,
                                                   resultIn.getMainString(),
                                                   resultIn.getSubString(),
                                                   resultIn.getZoneString(),
                                                   resultIn.getUpdateCount());

                    resultIn.readAdditionalResults(session, dataIn, rowIn);

                    resultOut = Result.newConnectionAcknowledgeResponse(
                        session.getDatabase(), session.getId(), dbID);
                } catch (HsqlException e) {
                    resultOut = Result.newErrorResult(e);
                } catch (RuntimeException e) {
                    resultOut = Result.newErrorResult(e);
                }
            } else {
                int dbID = resultIn.getDatabaseId();

                if (session == null) {
                    resultOut = Result.newErrorResult(
                        Error.error(ErrorCode.SERVER_DATABASE_DISCONNECTED));
                } else {
                    resultIn.setSession(session);
                    resultIn.readLobResults(session, dataIn, rowIn);

                    resultOut = session.execute(resultIn);
                }
            }

            int type = resultIn.getType();
View Full Code Here

            } else {
                scr = new ScriptReaderDecode(database, scriptFileName, crypto,
                                             false);
            }

            Session session =
                database.sessionManager.getSysSessionForScript(database);

            scr.readAll(session);
            scr.close();
        } catch (Throwable e) {
View Full Code Here

     */
    DatabaseInformationMain(Database db) {

        super(db);

        Session session = db.sessionManager.getSysSession();

        init(session);
    }
View Full Code Here

                inStream = new DataInputStream(request.getInputStream());

                int  databaseID = inStream.readInt();
                long sessionID  = inStream.readLong();
                int  mode       = inStream.readByte();
                Session session = DatabaseManager.getSession(databaseID,
                    sessionID);
                Result resultIn = Result.newResult(session, mode, inStream,
                                                   rowIn);

                resultIn.setDatabaseId(databaseID);
                resultIn.setSessionId(sessionID);

                Result resultOut;

                if (resultIn.getType() == ResultConstants.CONNECT) {
                    try {
                        session = DatabaseManager.newSession(
                            dbType, dbPath, resultIn.getMainString(),
                            resultIn.getSubString(), new HsqlProperties(),
                            resultIn.getZoneString(),
                            resultIn.getUpdateCount());

                        resultIn.readAdditionalResults(null, inStream, rowIn);

                        resultOut = Result.newConnectionAcknowledgeResponse(
                            session.getDatabase(), session.getId(),
                            session.getDatabase().getDatabaseID());
                    } catch (HsqlException e) {
                        resultOut = Result.newErrorResult(e);
                    }
                } else {
                    int  dbId      = resultIn.getDatabaseId();
                    long sessionId = resultIn.getSessionId();

                    session = DatabaseManager.getSession(dbId, sessionId);

                    resultIn.readLobResults(session, inStream, rowIn);

                    resultOut = session.execute(resultIn);
                }

                //
                response.setContentType("application/octet-stream");
                response.setContentLength(rowOut.size());
View Full Code Here

        try {
            DataInputStream dataIn     = new DataInputStream(inStream);
            int             databaseID = dataIn.readInt();
            long            sessionID  = dataIn.readLong();
            int             mode       = dataIn.readByte();
            Session session = DatabaseManager.getSession(databaseID,
                sessionID);
            Result resultIn = Result.newResult(session, mode, dataIn, rowIn);

            resultIn.setDatabaseId(databaseID);
            resultIn.setSessionId(sessionID);

            //
            Result resultOut;

            if (resultIn.getType() == ResultConstants.CONNECT) {
                try {
                    String databaseName = resultIn.getDatabaseName();
                    int    dbIndex      = server.getDBIndex(databaseName);
                    int    dbID         = server.dbID[dbIndex];

                    session =
                        DatabaseManager.newSession(dbID,
                                                   resultIn.getMainString(),
                                                   resultIn.getSubString(),
                                                   resultIn.getZoneString(),
                                                   resultIn.getUpdateCount());

                    resultIn.readAdditionalResults(session, dataIn, rowIn);

                    resultOut = Result.newConnectionAcknowledgeResponse(
                        session.getDatabase(), session.getId(), dbID);
                } catch (HsqlException e) {
                    resultOut = Result.newErrorResult(e);
                } catch (RuntimeException e) {
                    resultOut = Result.newErrorResult(e);
                }
            } else {
                int dbID = resultIn.getDatabaseId();

                if (session == null) {
                    resultOut = Result.newErrorResult(
                        Error.error(ErrorCode.SERVER_DATABASE_DISCONNECTED));
                } else {
                    resultIn.setSession(session);
                    resultIn.readLobResults(session, dataIn, rowIn);

                    resultOut = session.execute(resultIn);
                }
            }

            int type = resultIn.getType();
View Full Code Here

        Session[] sessions = database.sessionManager.getAllSessions();

        try {
            for (int i = 0; i < sessions.length; i++) {
                Session session = sessions[i];

                if (session.isAutoCommit() == false) {
                    dbLogWriter.writeLogStatement(
                        session, session.getAutoCommitStatement());
                }
            }
        } catch (IOException e) {
            throw Trace.error(Trace.FILE_IO_ERROR, logFileName);
        }
View Full Code Here

     */
    public static void runScript(Database database, String logFilename,
                                 int logType) throws HsqlException {

        IntKeyHashMap sessionMap = new IntKeyHashMap();
        Session sysSession = database.getSessionManager().getSysSession();
        Session       current    = sysSession;
        int           currentId  = 0;

        database.setReferentialIntegrity(false);

        ScriptReaderBase scr = null;

        try {
            StopWatch sw = new StopWatch();

            scr = ScriptReaderBase.newScriptReader(database, logFilename,
                                                   logType);

            while (scr.readLoggedStatement(current)) {
                int sessionId = scr.getSessionNumber();

                if (currentId != sessionId) {
                    currentId = sessionId;
                    current   = (Session) sessionMap.get(currentId);

                    if (current == null) {
                        current =
                            database.getSessionManager().newSession(database,
                                sysSession.getUser(), false, true);

                        sessionMap.put(currentId, current);
                    }
                }

                if (current.isClosed()) {
                    sessionMap.remove(currentId);

                    continue;
                }

                Result result = null;

                switch (scr.getStatementType()) {

                    case ScriptReaderBase.ANY_STATEMENT :
                        result = current.sqlExecuteDirectNoPreChecks(
                            scr.getLoggedStatement());

                        if (result != null && result.isError()) {
                            if (result.getException() != null) {
                                throw result.getException();
                            }

                            throw Trace.error(result);
                        }
                        break;

                    case ScriptReaderBase.SEQUENCE_STATEMENT :
                        scr.getCurrentSequence().reset(
                            scr.getSequenceValue());
                        break;

                    case ScriptReaderBase.COMMIT_STATEMENT :
                        current.commit();
                        break;

                    case ScriptReaderBase.INSERT_STATEMENT : {
                        Object[] data = scr.getData();

                        scr.getCurrentTable().insertNoCheckFromLog(current,
                                data);

                        break;
                    }
                    case ScriptReaderBase.DELETE_STATEMENT : {
                        Object[] data = scr.getData();

                        scr.getCurrentTable().deleteNoCheckFromLog(current,
                                data);

                        break;
                    }
                    case ScriptReaderBase.SCHEMA_STATEMENT : {
                        current.setSchema(scr.getCurrentSchema());
                    }
                }

                if (current.isClosed()) {
                    sessionMap.remove(currentId);
                }
            }
        } catch (Throwable e) {
            String message;
View Full Code Here

    }

    private static void runScript(Database database, ScriptReaderBase scr) {

        IntKeyHashMap sessionMap = new IntKeyHashMap();
        Session       current    = null;
        int           currentId  = 0;
        String        statement;
        int           statementType;
        Statement dummy = new StatementDML(StatementTypes.UPDATE_CURSOR,
                                           StatementTypes.X_SQL_DATA_CHANGE,
                                           null);
        String databaseFile = database.getPath();
        boolean fullReplay = database.getURLProperties().isPropertyTrue(
            HsqlDatabaseProperties.hsqldb_full_log_replay);

        dummy.setCompileTimestamp(Long.MAX_VALUE);
        database.setReferentialIntegrity(false);

        try {
            StopWatch sw = new StopWatch();

            while (scr.readLoggedStatement(current)) {
                int sessionId = scr.getSessionNumber();

                if (current == null || currentId != sessionId) {
                    currentId = sessionId;
                    current   = (Session) sessionMap.get(currentId);

                    if (current == null) {
                        current =
                            database.getSessionManager().newSessionForLog(
                                database);

                        sessionMap.put(currentId, current);
                    }
                }

                if (current.isClosed()) {
                    sessionMap.remove(currentId);

                    continue;
                }

                Result result = null;

                statementType = scr.getStatementType();

                switch (statementType) {

                    case ScriptReaderBase.ANY_STATEMENT :
                        statement = scr.getLoggedStatement();

                        Statement cs;

                        try {
                            cs = current.compileStatement(statement);

                            if (database.getProperties().isVersion18()) {

                                // convert BIT columns in .log to BOOLEAN
                                if (cs.getType()
                                        == StatementTypes.CREATE_TABLE) {
                                    Table table =
                                        (Table) ((StatementSchema) cs)
                                            .getArguments()[0];

                                    for (int i = 0; i < table.getColumnCount();
                                            i++) {
                                        ColumnSchema column =
                                            table.getColumn(i);

                                        if (column.getDataType().isBitType()) {
                                            column.setType(Type.SQL_BOOLEAN);
                                        }
                                    }
                                }
                            }

                            result = current.executeCompiledStatement(cs,
                                    ValuePool.emptyObjectArray);
                        } catch (Throwable e) {
                            result = Result.newErrorResult(e);
                        }

                        if (result != null && result.isError()) {
                            if (result.getException() != null) {
                                throw result.getException();
                            }

                            throw Error.error(result);
                        }
                        break;

                    case ScriptReaderBase.COMMIT_STATEMENT :
                        current.commit(false);
                        break;

                    case ScriptReaderBase.INSERT_STATEMENT : {
                        current.sessionContext.currentStatement = dummy;

                        current.beginAction(dummy);

                        Object[] data = scr.getData();

                        scr.getCurrentTable().insertNoCheckFromLog(current,
                                data);
                        current.endAction(Result.updateOneResult);

                        break;
                    }
                    case ScriptReaderBase.DELETE_STATEMENT : {
                        current.sessionContext.currentStatement = dummy;

                        current.beginAction(dummy);

                        Table    table = scr.getCurrentTable();
                        Object[] data  = scr.getData();
                        Row row = table.getDeleteRowFromLog(current, data);

                        if (row != null) {
                            current.addDeleteAction(table, row, null);
                        }

                        current.endAction(Result.updateOneResult);

                        break;
                    }
                    case ScriptReaderBase.SET_SCHEMA_STATEMENT : {
                        HsqlName name =
                            database.schemaManager.findSchemaHsqlName(
                                scr.getCurrentSchema());

                        current.setCurrentSchemaHsqlName(name);

                        break;
                    }
                    case ScriptReaderBase.SESSION_ID : {
                        break;
                    }
                }

                if (current.isClosed()) {
                    sessionMap.remove(currentId);
                }
            }
        } catch (HsqlException e) {
View Full Code Here

        final int it_latch_count = 13;

        //
        // intermediate holders
        Session[] sessions;
        Session   s;
        Object[]  row;

        // Initialisation
        sessions = database.sessionManager.getVisibleSessions(session);

        // Do it.
        for (int i = 0; i < sessions.length; i++) {
            if (sessions[i].isClosed()) {
                continue;
            }

            s              = sessions[i];
            row            = t.getEmptyRowData();
            row[isid]      = ValuePool.getLong(s.getId());
            row[ict]       = new TimestampData(s.getConnectTime() / 1000);
            row[iuname]    = s.getUsername();
            row[iis_admin] = ValuePool.getBoolean(s.isAdmin());
            row[iautocmt= s.sessionContext.isAutoCommit;
            row[ireadonly] = s.isReadOnlyDefault;

            Number lastId = s.getLastIdentity();

            if (lastId != null) {
                row[ilast_id] = ValuePool.getLong(lastId.longValue());
            }

            row[it_tx]   = Boolean.valueOf(s.isInMidTransaction());
            row[it_size] = ValuePool.getLong(s.getTransactionSize());

            HsqlName name = s.getCurrentSchemaHsqlName();

            if (name != null) {
                row[it_schema] = name.name;
            }
View Full Code Here

TOP

Related Classes of org.hsqldb.Session

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.