Package org.hsqldb.lib

Examples of org.hsqldb.lib.HashMappedList


     */
    private int[] processColumnList(Table t,
                                    boolean acceptAscDesc)
                                    throws HsqlException {

        HashMappedList list = Parser.processColumnList(tokenizer,
            acceptAscDesc);
        int   size = list.size();
        int[] col  = new int[size];

        for (int i = 0; i < size; i++) {
            col[i] = t.getColumnNr((String) list.getKey(i));
        }

        return col;
    }
View Full Code Here


        while (schemas.hasNext()) {
            String schemaKey = (String) schemas.next();
            HsqlName schema =
                database.schemaManager.toSchemaHsqlName(schemaKey);
            HashMappedList tTable =
                database.schemaManager.getTables(schema.name);
            HsqlArrayList forwardFK = new HsqlArrayList();

            // schema creation
            {
                String ddl = getSchemaCreateDDL(database, schema);

                addRow(r, ddl);
            }

            // sequences
            /*
                     CREATE SEQUENCE <name>
                     [AS {INTEGER | BIGINT}]
                     [START WITH <value>]
                     [INCREMENT BY <value>]
             */
            Iterator it = database.schemaManager.sequenceIterator(schema.name);

            while (it.hasNext()) {
                NumberSequence seq = (NumberSequence) it.next();
                StringBuffer   a   = new StringBuffer(128);

                a.append(Token.T_CREATE).append(' ');
                a.append(Token.T_SEQUENCE).append(' ');
                a.append(seq.getName().statementName).append(' ');
                a.append(Token.T_AS).append(' ');
                a.append(Types.getTypeString(seq.getType())).append(' ');
                a.append(Token.T_START).append(' ');
                a.append(Token.T_WITH).append(' ');
                a.append(seq.peek()).append(' ');

                if (seq.getIncrement() != 1) {
                    a.append(Token.T_INCREMENT).append(' ');
                    a.append(Token.T_BY).append(' ');
                    a.append(seq.getIncrement()).append(' ');
                }

                addRow(r, a.toString());
            }

            // tables
            for (int i = 0, tSize = tTable.size(); i < tSize; i++) {
                Table t = (Table) tTable.get(i);

                if (t.isView()) {
                    continue;
                }

                StringBuffer a = new StringBuffer(128);

                getTableDDL(database, t, i, forwardFK, false, a);
                addRow(r, a.toString());

                // indexes for table
                for (int j = 1; j < t.getIndexCount(); j++) {
                    Index index = t.getIndex(j);

                    if (HsqlName.isReservedName(index.getName().name)) {

                        // the following are autocreated with the table
                        // indexes for primary keys
                        // indexes for unique constraints
                        // own table indexes for foreign keys
                        continue;
                    }

                    a = new StringBuffer(64);

                    a.append(Token.T_CREATE).append(' ');

                    if (index.isUnique()) {
                        a.append(Token.T_UNIQUE).append(' ');
                    }

                    a.append(Token.T_INDEX).append(' ');
                    a.append(index.getName().statementName);
                    a.append(' ').append(Token.T_ON).append(' ');
                    a.append(t.getName().statementName);

                    int[] col = index.getColumns();
                    int   len = index.getVisibleColumns();

                    getColumnList(t, col, len, a);
                    addRow(r, a.toString());
                }

                // readonly for TEXT tables only
                if (t.isText() && t.isConnected() && t.isDataReadOnly()) {
                    a = new StringBuffer(64);

                    a.append(Token.T_SET).append(' ').append(
                        Token.T_TABLE).append(' ');
                    a.append(t.getName().statementName);
                    a.append(' ').append(Token.T_READONLY).append(' ').append(
                        Token.T_TRUE);
                    addRow(r, a.toString());
                }

                // data source
                String dataSource = getDataSource(t);

                if (dataSource != null) {
                    addRow(r, dataSource);
                }

                // header
                String header = getDataSourceHeader(t);

                if (!indexRoots && header != null) {
                    addRow(r, header);
                }

                // triggers
                int numTrigs = TriggerDef.NUM_TRIGS;

                for (int tv = 0; tv < numTrigs; tv++) {
                    HsqlArrayList trigVec = t.triggerLists[tv];

                    if (trigVec == null) {
                        continue;
                    }

                    int trCount = trigVec.size();

                    for (int k = 0; k < trCount; k++) {
                        a = ((TriggerDef) trigVec.get(k)).getDDL();

                        addRow(r, a.toString());
                    }
                }
            }

            // forward referencing foreign keys
            for (int i = 0, tSize = forwardFK.size(); i < tSize; i++) {
                Constraint   c = (Constraint) forwardFK.get(i);
                StringBuffer a = new StringBuffer(128);

                a.append(Token.T_ALTER).append(' ').append(
                    Token.T_TABLE).append(' ');
                a.append(c.getRef().getName().statementName);
                a.append(' ').append(Token.T_ADD).append(' ');
                getFKStatement(c, a);
                addRow(r, a.toString());
            }

            // SET <tablename> INDEX statements
            Session sysSession = database.sessionManager.getSysSession();

            for (int i = 0, tSize = tTable.size(); i < tSize; i++) {
                Table t = (Table) tTable.get(i);

                if (indexRoots && t.isIndexCached()
                        && !t.isEmpty(sysSession)) {
                    addRow(r, getIndexRootsDDL((Table) tTable.get(i)));
                }
            }

            // RESTART WITH <value> statements
            for (int i = 0, tSize = tTable.size(); i < tSize; i++) {
                Table t = (Table) tTable.get(i);

                if (!t.isTemp()) {
                    String ddl = getIdentityUpdateDDL(t);

                    addRow(r, ddl);
                }
            }

            // views
            for (int i = 0, tSize = tTable.size(); i < tSize; i++) {
                Table t = (Table) tTable.get(i);

                if (t.isView()) {
                    View         v = (View) tTable.get(i);
                    StringBuffer a = new StringBuffer(128);

                    a.append(Token.T_CREATE).append(' ').append(
                        Token.T_VIEW).append(' ');
                    a.append(v.getName().statementName).append(' ').append(
View Full Code Here

     *
     */
    private static void addRightsStatements(Database dDatabase, Result r) {

        StringBuffer   a;
        HashMappedList userlist = dDatabase.getUserManager().getUsers();
        Iterator       users    = userlist.values().iterator();
        GranteeManager gm       = dDatabase.getGranteeManager();
        Iterator       grantees = gm.getGrantees().iterator();

        for (; users.hasNext(); ) {
            User   u    = (User) users.next();
View Full Code Here

        tableType       = type;
        tableName       = name;
        primaryKeyCols  = null;
        primaryKeyTypes = null;
        identityColumn  = -1;
        columnList      = new HashMappedList();
        indexList       = new Index[0];
        constraintList  = new Constraint[0];
        triggerLists    = new HsqlArrayList[TriggerDef.NUM_TRIGS];

// ----------------------------------------------------------------------------
View Full Code Here

                                   || c.getDeleteAction()
                                      == Constraint.SET_DEFAULT;

                // -- list for records to be inserted if this is
                // -- a 'ON DELETE SET [NULL|DEFAULT]' constraint
                HashMappedList rowSet = null;

                if (isUpdate) {
                    rowSet = (HashMappedList) tableUpdateLists.get(reftable);

                    if (rowSet == null) {
                        rowSet = new HashMappedList();

                        tableUpdateLists.add(reftable, rowSet);
                    }
                }
View Full Code Here

                boolean hasref =
                    reftable.getNextConstraintIndex(0, Constraint.MAIN) != -1;
                Index refindex = c.getRefIndex();

                // -- walk the index for all the nodes that reference update node
                HashMappedList rowSet =
                    (HashMappedList) tableUpdateLists.get(reftable);

                if (rowSet == null) {
                    rowSet = new HashMappedList();

                    tableUpdateLists.add(reftable, rowSet);
                }

                for (Row refrow = refiterator.next(); ;
View Full Code Here

    }

    static void clearUpdateLists(HashMappedList tableUpdateList) {

        for (int i = 0; i < tableUpdateList.size(); i++) {
            HashMappedList updateList =
                (HashMappedList) tableUpdateList.get(i);

            updateList.clear();
        }
    }
View Full Code Here

        HashSet path = constraintPath == null ? new HashSet()
                                              : constraintPath;

        constraintPath = null;

        HashMappedList tUpdateList = tableUpdateList == null
                                     ? new HashMappedList()
                                     : tableUpdateList;

        tableUpdateList = null;

        if (database.isReferentialIntegrity()) {
            for (int i = 0; i < deleteList.size(); i++) {
                Row row = (Row) deleteList.get(i);

                path.clear();
                checkCascadeDelete(session, this, tUpdateList, row, false,
                                   path);
            }
        }

        // check transactions
        database.txManager.checkDelete(session, deleteList);

        for (int i = 0; i < tUpdateList.size(); i++) {
            Table          table      = (Table) tUpdateList.getKey(i);
            HashMappedList updateList = (HashMappedList) tUpdateList.get(i);

            database.txManager.checkDelete(session, updateList);
        }

        // perform delete
        fireAll(session, Trigger.DELETE_BEFORE);

        if (database.isReferentialIntegrity()) {
            for (int i = 0; i < deleteList.size(); i++) {
                Row row = (Row) deleteList.get(i);

                path.clear();
                checkCascadeDelete(session, this, tUpdateList, row, true,
                                   path);
            }
        }

        for (int i = 0; i < deleteList.size(); i++) {
            Row row = (Row) deleteList.get(i);

            if (!row.isCascadeDeleted()) {
                deleteNoRefCheck(session, row);
            }
        }

        for (int i = 0; i < tUpdateList.size(); i++) {
            Table          table      = (Table) tUpdateList.getKey(i);
            HashMappedList updateList = (HashMappedList) tUpdateList.get(i);

            table.updateRowSet(session, updateList, null, false);
            updateList.clear();
        }

        fireAll(session, Trigger.DELETE_AFTER);
        path.clear();
View Full Code Here

        HashSet path = constraintPath == null ? new HashSet()
                                              : constraintPath;

        constraintPath = null;

        HashMappedList tUpdateList = tableUpdateList == null
                                     ? new HashMappedList()
                                     : tableUpdateList;

        tableUpdateList = null;

        // set identity column where null and check columns
        for (int i = 0; i < updateList.size(); i++) {
            Object[] data = (Object[]) updateList.get(i);

            // this means the identity column can be set to null to force
            // creation of a new identity value
            setIdentityColumn(session, data);
            enforceFieldValueLimits(data, cols);
            enforceNullConstraints(data);
        }

        // perform check/cascade operations
        if (database.isReferentialIntegrity()) {
            for (int i = 0; i < updateList.size(); i++) {
                Object[] data = (Object[]) updateList.get(i);
                Row      row  = (Row) updateList.getKey(i);

                checkCascadeUpdate(session, this, tUpdateList, row, data,
                                   cols, null, path);
            }
        }

        fireAll(session, Trigger.UPDATE_BEFORE);

        // merge any triggered change to this table with the update list
        HashMappedList triggeredList = (HashMappedList) tUpdateList.get(this);

        if (triggeredList != null) {
            for (int i = 0; i < triggeredList.size(); i++) {
                Row      row  = (Row) triggeredList.getKey(i);
                Object[] data = (Object[]) triggeredList.get(i);

                mergeKeepUpdate(session, updateList, cols, colTypes, row,
                                data);
            }

            triggeredList.clear();
        }

        // check transactions
        for (int i = 0; i < tUpdateList.size(); i++) {
            Table          table       = (Table) tUpdateList.getKey(i);
            HashMappedList updateListT = (HashMappedList) tUpdateList.get(i);

            database.txManager.checkDelete(session, updateListT);
        }

        database.txManager.checkDelete(session, updateList);

        // update lists - main list last
        for (int i = 0; i < tUpdateList.size(); i++) {
            Table          table       = (Table) tUpdateList.getKey(i);
            HashMappedList updateListT = (HashMappedList) tUpdateList.get(i);

            table.updateRowSet(session, updateListT, null, false);
            updateListT.clear();
        }

        updateRowSet(session, updateList, cols, true);
        fireAll(session, Trigger.UPDATE_AFTER);
        path.clear();
View Full Code Here

        sessionId                 = id;
        database                  = db;
        this.user                 = user;
        rowActionList             = new HsqlArrayList(true);
        savepoints                = new HashMappedList(4);
        isAutoCommit              = autocommit;
        isReadOnly                = readonly;
        dbCommandInterpreter      = new DatabaseCommandInterpreter(this);
        compiledStatementExecutor = new CompiledStatementExecutor(this);
        compiledStatementManager  = db.compiledStatementManager;
View Full Code Here

TOP

Related Classes of org.hsqldb.lib.HashMappedList

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.