Package henplus.sqlmodel

Examples of henplus.sqlmodel.Table


            final DatabaseMetaData meta = session.getConnection().getMetaData();

            while (tableNamesIter.hasNext() && !_interrupted) {
                final String tableName = tableNamesIter.next();
                rset = meta.getColumns(catalog, null, tableName, null);
                final Table table = buildTable(catalog, meta, tableName, rset);
                result.addTable(table);
            }
        } catch (final Exception e) {
            if (VERBOSE) {
                e.printStackTrace();
View Full Code Here


        return result;
    }

    public Table getTable(final SQLSession session, final String tableName) {
        Table table = null;
        ResultSet rset = null;
        try {
            final String catalog = session.getConnection().getCatalog();
            final DatabaseMetaData meta = session.getConnection().getMetaData();
            rset = meta.getColumns(catalog, null, tableName, null);
View Full Code Here

    }

    private Table buildTable(final String catalog, final DatabaseMetaData meta, final String tableName, final ResultSet rset)
            throws SQLException {

        Table table = null;
        if (rset != null) {
            table = new Table(tableName);
            final PrimaryKey pk = getPrimaryKey(meta, tableName);
            final Map<String, ColumnFkInfo> fks = getForeignKeys(meta, tableName);
            // what about the following duplicate?
            // rset = meta.getColumns(catalog, null, tableName, null);
            while (!_interrupted && rset.next()) {
                final String colname = rset.getString(COLUMN_NAME);
                final Column column = new Column(colname);
                column.setType(rset.getString(TYPE_NAME));
                column.setSize(rset.getInt(COLUMN_SIZE));
                final boolean nullable = rset.getInt(NULLABLE) == DatabaseMetaData.columnNullable ? true : false;
                column.setNullable(nullable);
                final String defaultVal = rset.getString(COLUMN_DEF);
                column.setDefault(defaultVal != null ? defaultVal.trim() : null);
                column.setPosition(rset.getInt(ORDINAL_POSITION));
                column.setPkInfo(pk.getColumnPkInfo(colname));
                column.setFkInfo(fks.get(colname));

                table.addColumn(column);
            }
            rset.close();
        }
        return table;
    }
View Full Code Here

        final LinkedHashMap<String, Table> resolved = new LinkedHashMap<String, Table>();
        Map<String, Table> unresolved = null;

        // first run: separate tables with and without dependencies
        while (_tableIter.hasNext()) {
            final Table t = _tableIter.next();
            if (t == null) {
                continue;
            }
            final Set<ColumnFkInfo> fks = t.getForeignKeys();

            // no dependency / foreign key?
            Logger.debug("[sortTables] put %s to resolved.", t);
            if (fks == null) {
                resolved.put(t.getName(), t);
            } else {
                // dependency fulfilled?
                boolean nodep = true;
                final Iterator<ColumnFkInfo> iter2 = fks.iterator();
                while (iter2.hasNext() && nodep) {
                    final ColumnFkInfo fk = iter2.next();
                    if (!resolved.containsKey(fk.getPkTable())) {
                        nodep = false;
                    }
                }

                if (nodep) {
                    resolved.put(t.getName(), t);
                } else {
                    if (unresolved == null) {
                        unresolved = new HashMap<String, Table>();
                    }
                    unresolved.put(t.getName(), t);
                }
            }
        }

        // second run: we check remaining deps
View Full Code Here

            final ColumnFkInfo fk = iter.next();

            Logger.debug("[resolveDep] FK -> %s: %s", fk.getPkTable(), resolved.containsKey(fk.getPkTable()));
            if (!resolved.containsKey(fk.getPkTable())) {

                final Table inner = unresolved.get(fk.getPkTable());

                // if there's yet a cycle with the two tables inner following t
                // then proceed to the next FK and ignore this potential cycle
                if (duplicateCycle(t, inner)) {
                    continue;
View Full Code Here

        }
        return count;
    }

    private void diffTable(final SQLSession first, final SQLSession second, final String tableName, final boolean colNameIgnoreCase) {
        final Table ref = first.getTable(tableName);
        final Table diff = second.getTable(tableName);
        final TableDiffResult diffResult = TableDiffer.diffTables(ref, diff, colNameIgnoreCase);
        if (diffResult == null) {
            Logger.info("No diff for table " + tableName);
        } else {
            Logger.info("Diff result for table " + tableName + ":");
View Full Code Here

        }
    }

    private void diffTable(final SQLSession session, final String tableName1, final String tableName2,
            final boolean colNameIgnoreCase) {
        final Table ref = session.getTable(tableName1);
        final Table diff = session.getTable(tableName2);
        final TableDiffResult diffResult = TableDiffer.diffTables(ref, diff, colNameIgnoreCase);
        if (diffResult == null) {
            Logger.info("No diff for tables " + tableName1 + " and " + tableName2 + ".");
        } else {
            Logger.info("Diff result for tables " + tableName1 + " and " + tableName2 + ":");
View Full Code Here

TOP

Related Classes of henplus.sqlmodel.Table

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.