Package org.hsqldb

Examples of org.hsqldb.Session


     */
    DatabaseInformationMain(Database db) {

        super(db);

        Session session = db.sessionManager.getSysSession();

        init(session);
    }
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.readAdditionalResults(session, dataIn, rowIn);

                    resultOut = session.execute(resultIn);
                }
            }

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

        database.txManager.convertTransactionIDs(transactionRowLookup);
    }

    int[] writeTableToDataFile(Table table) throws IOException {

        Session session = database.getSessionManager().getSysSession();
        PersistentStore    store  = session.sessionData.getRowStore(table);
        RowOutputInterface rowOut = cache.rowOut.duplicate();
        DoubleIntIndex pointerLookup = new DoubleIntIndex(
            ((IndexAVL) table.getPrimaryIndex()).sizeEstimate(store), false);
        int[] rootsArray = table.getIndexRootsArray();
View Full Code Here

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

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

                scr.readAll(session);
                scr.close();
            }
View Full Code Here

     *  transaction rollback.
     */
    public static void runScript(Database database, String logFilename) {

        IntKeyHashMap sessionMap = new IntKeyHashMap();
        Session       current    = null;
        int           currentId  = 0;

        database.setReferentialIntegrity(false);

        ScriptReaderBase scr = null;
        String           statement;
        int              statementType;
        Statement dummy = new StatementDML(StatementTypes.UPDATE_CURSOR,
                                           StatementTypes.X_SQL_DATA_CHANGE,
                                           null);

        try {
            StopWatch sw     = new StopWatch();
            Crypto    crypto = database.logger.getCrypto();

            if (crypto == null) {
                scr = new ScriptReaderText(database, logFilename);
            } else {
                scr = new ScriptReaderDecode(database, logFilename, crypto,
                                             true);
            }

            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().newSession(database,
                                database.getUserManager().getSysUser(), false,
                                true, null, 0);

                        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();
                        result = current.executeDirectStatement(statement,
                                ResultProperties.defaultPropsValue);

                        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);

                        Object[] data = scr.getData();

                        scr.getCurrentTable().deleteNoCheckFromLog(current,
                                data);
                        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 (Throwable e) {

View Full Code Here

        //
        PersistentStore store = session.sessionData.getRowStore(t);

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

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

        // Do it.
        for (int i = 0; i < sessions.length; i++) {
            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= ValuePool.getBoolean(s.isAutoCommit());
            row[ireadonly] = ValuePool.getBoolean(s.isReadOnlyDefault());
            row[ilast_id] =
                ValuePool.getLong(((Number) s.getLastIdentity()).longValue());
            row[it_size]   = ValuePool.getLong(s.getTransactionSize());
            row[it_schema] = s.getCurrentSchemaHsqlName().name;

            t.insertSys(store, row);
        }

        return t;
View Full Code Here

            return t;
        }

        PersistentStore store = session.sessionData.getRowStore(t);
        Session sys = database.sessionManager.newSysSession(
            SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
        Result rs = sys.executeDirectStatement(
            "SELECT DOMAIN_CATALOG, DOMAIN_SCHEMA, DOMAIN_NAME, TABLE_CATALOG, "
            + "TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS "
            + "WHERE DOMAIN_NAME IS NOT NULL;", ResultProperties.defaultPropsValue);

        t.insertSys(store, rs);
        sys.close();

        return t;
    }
View Full Code Here

            return t;
        }

        PersistentStore store = session.sessionData.getRowStore(t);
        Session sys = database.sessionManager.newSysSession(
            SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
        Result rs = sys.executeDirectStatement(
            "SELECT UDT_CATALOG, UDT_SCHEMA, UDT_NAME, TABLE_CATALOG, "
            + "TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS "
            + "WHERE UDT_NAME IS NOT NULL;", ResultProperties.defaultPropsValue);

        t.insertSys(store, rs);
        sys.close();

        return t;
    }
View Full Code Here

        }

        PersistentStore store = session.sessionData.getRowStore(t);

        //
        Session sys = database.sessionManager.newSysSession(
            SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
        Result rs = sys.executeDirectStatement(
            "select DISTINCT CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, "
            + "CONSTRAINT_NAME, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME "
            + "from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE", ResultProperties
                .defaultPropsValue);

        t.insertSys(store, rs);
        sys.close();

        return t;
    }
View Full Code Here

        }

        PersistentStore store = session.sessionData.getRowStore(t);

        //
        Session sys = database.sessionManager.newSysSession(
            SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
        String sql = (String) statementMap.get("/*data_type_privileges*/");
        Result rs =
            sys.executeDirectStatement(sql,
                                       ResultProperties.defaultPropsValue);

        t.insertSys(store, rs);
        sys.close();

        return t;
    }
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.