Search in sources :

Example 1 with IConnectionCallback

use of org.jumpmind.db.sql.IConnectionCallback in project symmetric-ds by JumpMind.

the class AbstractJdbcDdlReader method readTable.

public Table readTable(final String catalog, final String schema, final String table) {
    try {
        log.debug("reading table: " + table);
        JdbcSqlTemplate sqlTemplate = (JdbcSqlTemplate) platform.getSqlTemplate();
        return postprocessTableFromDatabase(sqlTemplate.execute(new IConnectionCallback<Table>() {

            public Table execute(Connection connection) throws SQLException {
                DatabaseMetaDataWrapper metaData = new DatabaseMetaDataWrapper();
                metaData.setMetaData(connection.getMetaData());
                metaData.setCatalog(catalog);
                metaData.setSchemaPattern(schema);
                metaData.setTableTypes(null);
                ResultSet tableData = null;
                try {
                    log.debug("getting table metadata for " + table);
                    tableData = metaData.getTables(getTableNamePattern(table));
                    log.debug("done getting table metadata for " + table);
                    if (tableData != null && tableData.next()) {
                        Map<String, Object> values = readMetaData(tableData, initColumnsForTable());
                        return readTable(connection, metaData, values);
                    } else {
                        return null;
                    }
                } finally {
                    close(tableData);
                }
            }
        }));
    } catch (SqlException e) {
        if (e.getMessage() != null && StringUtils.containsIgnoreCase(e.getMessage(), "does not exist")) {
            return null;
        } else {
            throw e;
        }
    }
}
Also used : JdbcSqlTemplate(org.jumpmind.db.sql.JdbcSqlTemplate) IConnectionCallback(org.jumpmind.db.sql.IConnectionCallback) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) SqlException(org.jumpmind.db.sql.SqlException)

Example 2 with IConnectionCallback

use of org.jumpmind.db.sql.IConnectionCallback in project symmetric-ds by JumpMind.

the class AbstractJdbcDdlReader method readTables.

/*
     * Reads the database model from the given connection.
     * 
     * @param catalog The catalog to access in the database; use
     * <code>null</code> for the default value
     * 
     * @param schema The schema to access in the database; use <code>null</code>
     * for the default value
     * 
     * @param tableTypes The table types to process; use <code>null</code> or an
     * empty list for the default ones
     * 
     * @return The database model
     */
public Database readTables(final String catalog, final String schema, final String[] tableTypes) {
    JdbcSqlTemplate sqlTemplate = (JdbcSqlTemplate) platform.getSqlTemplate();
    return postprocessModelFromDatabase(sqlTemplate.execute(new IConnectionCallback<Database>() {

        public Database execute(Connection connection) throws SQLException {
            Database db = new Database();
            db.setName(Table.getFullyQualifiedTablePrefix(catalog, schema));
            db.setCatalog(catalog);
            db.setSchema(schema);
            db.addTables(readTables(connection, catalog, schema, tableTypes));
            db.initialize();
            return db;
        }
    }));
}
Also used : JdbcSqlTemplate(org.jumpmind.db.sql.JdbcSqlTemplate) IConnectionCallback(org.jumpmind.db.sql.IConnectionCallback) Connection(java.sql.Connection) Database(org.jumpmind.db.model.Database)

Aggregations

Connection (java.sql.Connection)2 IConnectionCallback (org.jumpmind.db.sql.IConnectionCallback)2 JdbcSqlTemplate (org.jumpmind.db.sql.JdbcSqlTemplate)2 ResultSet (java.sql.ResultSet)1 Database (org.jumpmind.db.model.Database)1 SqlException (org.jumpmind.db.sql.SqlException)1