Package org.apache.commons.collections.map

Examples of org.apache.commons.collections.map.ListOrderedMap$1


            }
            query.append("'");
       
            Statement stmt        = getConnection().createStatement();
            ResultSet resultSet   = stmt.executeQuery(query.toString());
            Map       indices     = new ListOrderedMap();
            Map       indexValues = new HashMap();
       
            indexValues.put("NON_UNIQUE", Boolean.FALSE);
            while (resultSet.next())
            {
                indexValues.put("COLUMN_NAME",      resultSet.getString(1));
                indexValues.put("ORDINAL_POSITION", new Short(resultSet.getShort(2)));
                indexValues.put("INDEX_NAME",       resultSet.getString(3));
       
                readIndex(metaData, indexValues, indices);
            }
            resultSet.close();
       
            table.addIndices(indices.values());
        }
       
        return table;
    }
View Full Code Here


    /**
     * {@inheritDoc}
     */
    protected Collection readForeignKeys(DatabaseMetaDataWrapper metaData, String tableName) throws SQLException
    {
        Map       fks    = new ListOrderedMap();
        ResultSet fkData = null;

        try
        {
            if (getPlatform().isDelimitedIdentifierModeOn())
            {
                // Jaybird has a problem when delimited identifiers are used as
                // it is not able to find the foreign key info for the table
                // So we have to filter manually below
                fkData = metaData.getForeignKeys(getDefaultTablePattern());
                while (fkData.next())
                {
                    Map values = readColumns(fkData, getColumnsForFK());
   
                    if (tableName.equals(values.get("FKTABLE_NAME")))
                    {
                        readForeignKey(metaData, values, fks);
                    }
                }
            }
            else
            {
                fkData = metaData.getForeignKeys(tableName);
                while (fkData.next())
                {
                    Map values = readColumns(fkData, getColumnsForFK());
   
                    readForeignKey(metaData, values, fks);
                }
            }
        }
        finally
        {
            if (fkData != null)
            {
                fkData.close();
            }
        }
        return fks.values();
    }
View Full Code Here

        else
        {
            query.append(")");
        }

        Map               indices = new ListOrderedMap();
    PreparedStatement stmt    = null;

        try
        {
        stmt = getConnection().prepareStatement(query.toString());
        stmt.setString(1, getPlatform().isDelimitedIdentifierModeOn() ? tableName : tableName.toUpperCase());
        stmt.setString(2, "N");
        stmt.setString(3, "TABLE");
            stmt.setString(4, "P");
        if (metaData.getSchemaPattern() != null)
        {
          stmt.setString(5, metaData.getSchemaPattern().toUpperCase());
                stmt.setString(6, metaData.getSchemaPattern().toUpperCase());
        }

        ResultSet rs     = stmt.executeQuery();
          Map       values = new HashMap();

          while (rs.next())
          {
            values.put("INDEX_NAME",       rs.getString(1));
            values.put("INDEX_TYPE",       new Short(DatabaseMetaData.tableIndexOther));
            values.put("NON_UNIQUE",       "UNIQUE".equalsIgnoreCase(rs.getString(3)) ? Boolean.FALSE : Boolean.TRUE);
            values.put("COLUMN_NAME",      rs.getString(4));
            values.put("ORDINAL_POSITION", new Short(rs.getShort(5)));

            readIndex(metaData, values, indices);
          }
        }
        finally
        {
            if (stmt != null)
            {
                stmt.close();
            }
        }
    return indices.values();
  }
View Full Code Here

    protected void processTableStructureChanges(Database           currentModel,
                                                Database           desiredModel,
                                                CreationParameters params,
                                                Collection         changes) throws IOException
    {
        ListOrderedMap changesPerTable = new ListOrderedMap();
        ListOrderedMap unchangedFKs    = new ListOrderedMap();
        boolean        caseSensitive   = getPlatform().isDelimitedIdentifierModeOn();

        // we first sort the changes for the tables
        // however since the changes might contain source or target tables
        // we use the names rather than the table objects
        for (Iterator changeIt = changes.iterator(); changeIt.hasNext();)
        {
            TableChange change = (TableChange)changeIt.next();
            String      name   = change.getChangedTable().getName();

            if (!caseSensitive)
            {
                name = name.toUpperCase();
            }

            List changesForTable = (ArrayList)changesPerTable.get(name);

            if (changesForTable == null)
            {
                changesForTable = new ArrayList();
                changesPerTable.put(name, changesForTable);
                unchangedFKs.put(name, getUnchangedForeignKeys(currentModel, desiredModel, name));
            }
            changesForTable.add(change);
        }
        // we also need to drop the foreign keys of the unchanged tables referencing the changed tables
        addRelevantFKsFromUnchangedTables(currentModel, desiredModel, changesPerTable.keySet(), unchangedFKs);

        // we're dropping the unchanged foreign keys
        for (Iterator tableFKIt = unchangedFKs.entrySet().iterator(); tableFKIt.hasNext();)
        {
            Map.Entry entry       = (Map.Entry)tableFKIt.next();
            Table     targetTable = desiredModel.findTable((String)entry.getKey(), caseSensitive);

            for (Iterator fkIt = ((List)entry.getValue()).iterator(); fkIt.hasNext();)
            {
                writeExternalForeignKeyDropStmt(targetTable, (ForeignKey)fkIt.next());
            }
        }

        // We're using a copy of the current model so that the table structure changes can
        // modify it
        Database copyOfCurrentModel = null;

        try
        {
            copyOfCurrentModel = (Database)currentModel.clone();
        }
        catch (CloneNotSupportedException ex)
        {
            throw new DdlUtilsException(ex);
        }
       
        for (Iterator tableChangeIt = changesPerTable.entrySet().iterator(); tableChangeIt.hasNext();)
        {
            Map.Entry entry       = (Map.Entry)tableChangeIt.next();
            Table     targetTable = desiredModel.findTable((String)entry.getKey(), caseSensitive);

            processTableStructureChanges(copyOfCurrentModel,
                                         desiredModel,
                                         (String)entry.getKey(),
                                         params == null ? null : params.getParametersFor(targetTable),
                                         (List)entry.getValue());
        }
        // and finally we're re-creating the unchanged foreign keys
        for (Iterator tableFKIt = unchangedFKs.entrySet().iterator(); tableFKIt.hasNext();)
        {
            Map.Entry entry       = (Map.Entry)tableFKIt.next();
            Table     targetTable = desiredModel.findTable((String)entry.getKey(), caseSensitive);

            for (Iterator fkIt = ((List)entry.getValue()).iterator(); fkIt.hasNext();)
View Full Code Here

     * @param sourceTable The source table
     * @param targetTable The target table
     */
    protected void writeCopyDataStatement(Table sourceTable, Table targetTable) throws IOException
    {
        ListOrderedMap columns = new ListOrderedMap();

        for (int idx = 0; idx < sourceTable.getColumnCount(); idx++)
        {
            Column sourceColumn = sourceTable.getColumn(idx);
            Column targetColumn = targetTable.findColumn(sourceColumn.getName(),
                                                         getPlatform().isDelimitedIdentifierModeOn());


            if (targetColumn != null)
            {
                columns.put(sourceColumn, targetColumn);
            }
        }

        print("INSERT INTO ");
        printIdentifier(getTableName(targetTable));
        print(" (");
        for (Iterator columnIt = columns.keySet().iterator(); columnIt.hasNext();)
        {
            printIdentifier(getColumnName((Column)columnIt.next()));
            if (columnIt.hasNext())
            {
                print(",");
            }
        }
        print(") SELECT ");
        for (Iterator columnsIt = columns.entrySet().iterator(); columnsIt.hasNext();)
        {
            Map.Entry entry = (Map.Entry)columnsIt.next();

            writeCastExpression((Column)entry.getKey(),
                                (Column)entry.getValue());
View Full Code Here

     */
    private List sortTables(Table[] tables)
    {
        ArrayList      result    = new ArrayList();
        HashSet        processed = new HashSet();
        ListOrderedMap pending   = new ListOrderedMap();

        for (int idx = 0; idx < tables.length; idx++)
        {
            Table table = tables[idx];

            if (table.getForeignKeyCount() == 0)
            {
                result.add(table);
                processed.add(table);
            }
            else
            {
                HashSet waitedFor = new HashSet();

                for (int fkIdx = 0; fkIdx < table.getForeignKeyCount(); fkIdx++)
                {
                    Table waitedForTable = table.getForeignKey(fkIdx).getForeignTable();

                    if (!table.equals(waitedForTable))
                    {
                        waitedFor.add(waitedForTable);
                    }
                }
                pending.put(table, waitedFor);
            }
        }

        HashSet newProcessed = new HashSet();

        while (!processed.isEmpty() && !pending.isEmpty())
        {
            newProcessed.clear();
            for (Iterator it = pending.entrySet().iterator(); it.hasNext();)
            {
                Map.Entry entry     = (Map.Entry)it.next();
                Table     table     = (Table)entry.getKey();
                HashSet   waitedFor = (HashSet)entry.getValue();

                waitedFor.removeAll(processed);
                if (waitedFor.isEmpty())
                {
                    it.remove();
                    result.add(table);
                    newProcessed.add(table);
                }
            }
            processed.clear();

            HashSet tmp = processed;

            processed    = newProcessed;
            newProcessed = tmp;
        }
        // the remaining are within circular dependencies
        for (Iterator it = pending.keySet().iterator(); it.hasNext();)
        {
            result.add(it.next());
        }
        return result;
    }
View Full Code Here

    /**
    * Remove the stamp from stack (when resuming)
    */
    private static void popTransactionStartStamp() {
        ListOrderedMap map = (ListOrderedMap) suspendedTxStartStamps.get();
        if (map.size() > 0) {
            transactionStartStamp.set((Timestamp) map.remove(map.lastKey()));
        } else {
            Debug.logError("Error in transaction handling - no saved start stamp found - using NOW.", module);
            transactionStartStamp.set(UtilDateTime.nowTimestamp());
        }
    }
View Full Code Here

        // remember the z-folder for later removal
        toRemove.add((NodeImpl) u.getNode().getParent().getParent());
        assertEquals(usersPath + "/z/zz/z", u.getNode().getPath());

        Map<String, String> m = new ListOrderedMap();
        m.put("zz",     "/z/zz/zz");
        m.put("zzz",    "/z/zz/zzz");
        m.put("zzzz",   "/z/zz/zzzz");
        m.put("zh",     "/z/zh/zh");
        m.put("zHzh",   "/z/zH/zHzh");
        m.put("z_Hz",   "/z/z_/z_Hz");
        m.put("z\u00cfrich", "/z/z\u00cf/z\u00cfrich");

        for (String uid : m.keySet()) {
            u = (UserImpl) uMgr.createUser(uid, uid);
            save(s);
            assertEquals(usersPath + m.get(uid), u.getNode().getPath());
        }
    }
View Full Code Here

        // remember the z-folder for later removal
        toRemove.add((NodeImpl) u.getNode().getParent().getParent().getParent());
        assertEquals(usersPath + "/z/zz/zzz/z", u.getNode().getPath());

        Map<String, String> m = new ListOrderedMap();
        m.put("zz",     "/z/zz/zzz/zz");
        m.put("zzz",    "/z/zz/zzz/zzz");
        m.put("zzzz",   "/z/zz/zzz/zzzz");
        m.put("zH",     "/z/zH/zHH/zH");
        m.put("zHzh",   "/z/zH/zHz/zHzh");
        m.put("z_Hz",   "/z/z_/z_H/z_Hz");
        m.put("z\u00cfrich", "/z/z\u00cf/z\u00cfr/z\u00cfrich");

        for (String uid : m.keySet()) {
            u = (UserImpl) uMgr.createUser(uid, uid);
            save(s);

            assertEquals(usersPath + m.get(uid), u.getNode().getPath());

            Authorizable az = uMgr.getAuthorizable(uid);
            assertNotNull(az);
        }
    }
View Full Code Here

        toRemove.add((NodeImpl) u.getNode().getParent().getParent());

        String zu = Text.escapeIllegalJcrChars("z*");
        String zur = Text.escapeIllegalJcrChars("z*r");

        Map<String, String> m = new ListOrderedMap();
        // test illegal JCR chars in uid
        // on level 2
        m.put("z*rich", "/z/" + zu + "/" + Text.escapeIllegalJcrChars("z*rich"));
        m.put("z*riq""/z/" + zu + "/" + Text.escapeIllegalJcrChars("z*riq"));
        m.put("z*",     "/z/" + zu + "/" + zu)// still on level 2 (too short for 3)
        // on level 3
        m.put("z*rik""/z/" + zu + "/" + zur + "/" + Text.escapeIllegalJcrChars("z*rik"));
        m.put("z*.ri""/z/" + zu + "/" + Text.escapeIllegalJcrChars("z*.") + "/" + Text.escapeIllegalJcrChars("z*.ri"));

        for (String uid : m.keySet()) {
            u = (UserImpl) uMgr.createUser(uid, uid);
            save(s);
            assertEquals(usersPath + m.get(uid), u.getNode().getPath());

            Authorizable ath = uMgr.getAuthorizable(uid);
            assertNotNull("User with id " + uid + " must exist.", ath);
            assertFalse("User with id " + uid + " must not be a group.", ath.isGroup());
        }
View Full Code Here

TOP

Related Classes of org.apache.commons.collections.map.ListOrderedMap$1

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.