Search in sources :

Example 26 with Column

use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.

the class H2DdlReader method readColumn.

@Override
protected Column readColumn(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException {
    Column column = super.readColumn(metaData, values);
    if (values.get("CHARACTER_MAXIMUM_LENGTH") != null) {
        String maxLength = (String) values.get("CHARACTER_MAXIMUM_LENGTH");
        if (isNotBlank(maxLength)) {
            Integer size = new Integer(maxLength);
            column.setSize(size.toString());
            column.findPlatformColumn(platform.getName()).setSize(size);
        }
    }
    if (values.get("COLUMN_DEFAULT") != null) {
        column.setDefaultValue(values.get("COLUMN_DEFAULT").toString());
    }
    if (values.get("NUMERIC_SCALE") != null) {
        int scale = (Integer) values.get("NUMERIC_SCALE");
        column.setScale(scale);
        column.findPlatformColumn(platform.getName()).setDecimalDigits(scale);
    }
    if (TypeMap.isTextType(column.getMappedTypeCode()) && (column.getDefaultValue() != null)) {
        column.setDefaultValue(unescape(column.getDefaultValue(), "'", "''"));
    }
    String autoIncrement = (String) values.get("IS_AUTOINCREMENT");
    if (autoIncrement != null && "YES".equalsIgnoreCase(autoIncrement.trim())) {
        column.setAutoIncrement(true);
        column.setDefaultValue(null);
    }
    return column;
}
Also used : Column(org.jumpmind.db.model.Column)

Example 27 with Column

use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.

the class HsqlDb2DdlReader method readColumn.

@Override
protected Column readColumn(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException {
    Column column = super.readColumn(metaData, values);
    if (TypeMap.isTextType(column.getMappedTypeCode()) && (column.getDefaultValue() != null)) {
        column.setDefaultValue(unescape(column.getDefaultValue(), "'", "''"));
    }
    String autoIncrement = (String) values.get("IS_AUTOINCREMENT");
    if (autoIncrement != null) {
        column.setAutoIncrement("YES".equalsIgnoreCase(autoIncrement.trim()));
    }
    return column;
}
Also used : Column(org.jumpmind.db.model.Column)

Example 28 with Column

use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.

the class InterbaseDdlReader method readColumns.

@Override
protected Collection<Column> readColumns(DatabaseMetaDataWrapper metaData, String tableName) throws SQLException {
    ResultSet columnData = null;
    try {
        List<Column> columns = new ArrayList<Column>();
        if (getPlatform().getDdlBuilder().isDelimitedIdentifierModeOn()) {
            // Jaybird has a problem when delimited identifiers are used as
            // it is not able to find the columns for the table
            // So we have to filter manually below
            columnData = metaData.getColumns(getDefaultTablePattern(), getDefaultColumnPattern());
            while (columnData.next()) {
                Map<String, Object> values = readMetaData(columnData, getColumnsForColumn());
                if (tableName.equals(values.get("TABLE_NAME"))) {
                    columns.add(readColumn(metaData, values));
                }
            }
        } else {
            columnData = metaData.getColumns(tableName, getDefaultColumnPattern());
            while (columnData.next()) {
                Map<String, Object> values = readMetaData(columnData, getColumnsForColumn());
                columns.add(readColumn(metaData, values));
            }
        }
        return columns;
    } finally {
        if (columnData != null) {
            columnData.close();
        }
    }
}
Also used : Column(org.jumpmind.db.model.Column) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList)

Example 29 with Column

use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.

the class FirebirdDdlReader method determineAutoIncrementColumns.

/*
     * Helper method that determines the auto increment status using Firebird's
     * system tables.
     * 
     * @param table The table
     */
protected void determineAutoIncrementColumns(Connection connection, Table table) throws SQLException {
    /*
         * Since for long table and column names, the trigger name will be
         * shortened we have to determine for each column whether there is a
         * trigger on it
         */
    Column[] columns = table.getColumns();
    HashMap<String, Column> names = new HashMap<String, Column>();
    String name;
    for (int idx = 0; idx < columns.length; idx++) {
        name = ((FirebirdDdlBuilder) getPlatform().getDdlBuilder()).getTriggerName(table, columns[idx]);
        if (!getPlatform().getDdlBuilder().isDelimitedIdentifierModeOn()) {
            name = name.toUpperCase();
        }
        names.put(name, columns[idx]);
    }
    PreparedStatement stmt = connection.prepareStatement("SELECT RDB$TRIGGER_NAME FROM RDB$TRIGGERS WHERE RDB$RELATION_NAME=?");
    stmt.setString(1, table.getName());
    ResultSet rs = null;
    try {
        rs = stmt.executeQuery();
        while (rs.next()) {
            String triggerName = rs.getString(1).trim();
            Column column = (Column) names.get(triggerName);
            if (column != null) {
                column.setAutoIncrement(true);
            }
        }
    } finally {
        if (rs != null) {
            rs.close();
        }
        stmt.close();
    }
}
Also used : Column(org.jumpmind.db.model.Column) HashMap(java.util.HashMap) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 30 with Column

use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.

the class DerbyDdlReader method readColumn.

@Override
protected Column readColumn(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException {
    Column column = super.readColumn(metaData, values);
    String defaultValue = column.getDefaultValue();
    if (defaultValue != null) {
        // IDENTITY'
        if ("GENERATED_BY_DEFAULT".equals(defaultValue) || defaultValue.startsWith("AUTOINCREMENT:")) {
            column.setDefaultValue(null);
            column.setAutoIncrement(true);
        } else if (TypeMap.isTextType(column.getMappedTypeCode())) {
            column.setDefaultValue(unescape(defaultValue, "'", "''"));
        }
    }
    return column;
}
Also used : Column(org.jumpmind.db.model.Column)

Aggregations

Column (org.jumpmind.db.model.Column)179 Table (org.jumpmind.db.model.Table)78 ArrayList (java.util.ArrayList)34 IndexColumn (org.jumpmind.db.model.IndexColumn)23 PlatformColumn (org.jumpmind.db.model.PlatformColumn)21 Test (org.junit.Test)16 Row (org.jumpmind.db.sql.Row)15 LinkedHashMap (java.util.LinkedHashMap)12 ResultSet (java.sql.ResultSet)11 DmlStatement (org.jumpmind.db.sql.DmlStatement)10 SqlException (org.jumpmind.db.sql.SqlException)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 IIndex (org.jumpmind.db.model.IIndex)9 HashMap (java.util.HashMap)8 ForeignKey (org.jumpmind.db.model.ForeignKey)8 CsvData (org.jumpmind.symmetric.io.data.CsvData)8 PreparedStatement (java.sql.PreparedStatement)7 IOException (java.io.IOException)6 SQLException (java.sql.SQLException)6 Reference (org.jumpmind.db.model.Reference)6