Java Code Examples for org.apache.ddlutils.model.Table#getColumns()

The following examples show how to use org.apache.ddlutils.model.Table#getColumns() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InterbaseModelReader.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Adjusts the columns in the table by fixing types and default values.
 * 
 * @param table The table
 */
protected void adjustColumns(Table table)
{
    Column[] columns = table.getColumns();

    for (int idx = 0; idx < columns.length; idx++)
    {
        if (columns[idx].getTypeCode() == Types.FLOAT)
        {
            columns[idx].setTypeCode(Types.REAL);
        }
        else if ((columns[idx].getTypeCode() == Types.NUMERIC) || (columns[idx].getTypeCode() == Types.DECIMAL))
        {
            if ((columns[idx].getTypeCode() == Types.NUMERIC) && (columns[idx].getSizeAsInt() == 18) && (columns[idx].getScale() == 0))
            {
                columns[idx].setTypeCode(Types.BIGINT);
            }
        }
        else if (TypeMap.isTextType(columns[idx].getTypeCode()))
        {
            columns[idx].setDefaultValue(unescape(columns[idx].getDefaultValue(), "'", "''"));
        }
    }
}
 
Example 2
Source File: InterbaseModelReader.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Adjusts the columns in the table by fixing types and default values.
 * 
 * @param table The table
 */
protected void adjustColumns(Table table)
{
    Column[] columns = table.getColumns();

    for (int idx = 0; idx < columns.length; idx++)
    {
        if (columns[idx].getTypeCode() == Types.FLOAT)
        {
            columns[idx].setTypeCode(Types.REAL);
        }
        else if ((columns[idx].getTypeCode() == Types.NUMERIC) || (columns[idx].getTypeCode() == Types.DECIMAL))
        {
            if ((columns[idx].getTypeCode() == Types.NUMERIC) && (columns[idx].getSizeAsInt() == 18) && (columns[idx].getScale() == 0))
            {
                columns[idx].setTypeCode(Types.BIGINT);
            }
        }
        else if (TypeMap.isTextType(columns[idx].getTypeCode()))
        {
            columns[idx].setDefaultValue(unescape(columns[idx].getDefaultValue(), "'", "''"));
        }
    }
}
 
Example 3
Source File: RdbEventRecordLoader.java    From DataLink with Apache License 2.0 5 votes vote down vote up
private int getSqlType(EventColumn column, Table table, RdbEventRecord record) {
    MediaMappingInfo mappingInfo = RecordMeta.mediaMapping(record);

    MediaSourceType srcMediaSourceType = mappingInfo.getSourceMedia().getMediaSource().getType();
    if (srcMediaSourceType == MediaSourceType.SDDL) {
        srcMediaSourceType = MediaSourceType.MYSQL;
    }
    MediaSourceType targetMediaSourceType = mappingInfo.getTargetMediaSource().getType();

    //源库和目标库字段类型可能不一致,需要采用目标端的数据类型
    //只对异构数据库进行判断,同构数据库约定两边结构肯定是一致的
    if (srcMediaSourceType != targetMediaSourceType) {
        String columnName = column.getColumnName();
        int srcType = column.getColumnType();

        for (Column c : table.getColumns()) {
            if (c.getName().equalsIgnoreCase(columnName)) {
                column.setColumnType(c.getTypeCode());
                break;
            }
        }
        logger.debug(
                String.format("Type for column [%s] in Table [%s].[%s] is [%s] , and corresponding source type is [%s] , and ColumnValue is [%s].",
                        columnName,
                        mappingInfo.getTargetMediaSource().getName(),
                        table.getName(),
                        column.getColumnType(),
                        srcType,
                        column.getColumnValue()));
    }
    return column.getColumnType();

}
 
Example 4
Source File: Oracle8ModelReader.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method that determines the auto increment status using Firebird's system tables.
 *
 * @param table The table
 */
protected void determineAutoIncrementColumns(Table table) throws SQLException
{
    Column[] columns = table.getColumns();

    for (int idx = 0; idx < columns.length; idx++)
    {
        columns[idx].setAutoIncrement(isAutoIncrement(table, columns[idx]));
    }
}
 
Example 5
Source File: ModelComparator.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Creates change objects for columns that are present in the given source table but are no longer in the target
 * table, and applies them to the given intermediate model.
 * 
 * @param sourceModel       The source model
 * @param sourceTable       The source table
 * @param intermediateModel The intermediate model to apply the changes to
 * @param intermediateTable The table from the intermediate model corresponding to the source table
 * @param targetModel       The target model
 * @param targetTable       The target table
 * @return The changes
 */
protected List checkForRemovedColumns(Database sourceModel,
                                      Table    sourceTable,
                                      Database intermediateModel,
                                      Table    intermediateTable,
                                      Database targetModel,
                                      Table    targetTable)
{
    // if the platform does not support dropping pk columns, then the pk handling above will
    // generate appropriate pk changes

    List     changes = new ArrayList();
    Column[] columns = intermediateTable.getColumns();

    for (int columnIdx = 0; columnIdx < columns.length; columnIdx++)
    {
        Column sourceColumn = columns[columnIdx];
        Column targetColumn = targetTable.findColumn(sourceColumn.getName(), _caseSensitive);

        if (targetColumn == null)
        {
            if (_log.isInfoEnabled())
            {
                _log.info("Column " + sourceColumn.getName() + " needs to be removed from table " + intermediateTable.getQualifiedName());
            }

            RemoveColumnChange change = new RemoveColumnChange(intermediateTable.getQualifiedName(), sourceColumn.getName());

            changes.add(change);
            change.apply(intermediateModel, _caseSensitive);
        }
    }
    return changes;
}
 
Example 6
Source File: Oracle8ModelReader.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method that determines the auto increment status using Firebird's system tables.
 *
 * @param table The table
 */
protected void determineAutoIncrementColumns(Table table) throws SQLException
{
    Column[] columns = table.getColumns();

    for (int idx = 0; idx < columns.length; idx++)
    {
        columns[idx].setAutoIncrement(isAutoIncrement(table, columns[idx]));
    }
}
 
Example 7
Source File: ModelComparator.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Creates change objects for columns that are present in the given source table but are no longer in the target
 * table, and applies them to the given intermediate model.
 * 
 * @param sourceModel       The source model
 * @param sourceTable       The source table
 * @param intermediateModel The intermediate model to apply the changes to
 * @param intermediateTable The table from the intermediate model corresponding to the source table
 * @param targetModel       The target model
 * @param targetTable       The target table
 * @return The changes
 */
protected List checkForRemovedColumns(Database sourceModel,
                                      Table    sourceTable,
                                      Database intermediateModel,
                                      Table    intermediateTable,
                                      Database targetModel,
                                      Table    targetTable)
{
    // if the platform does not support dropping pk columns, then the pk handling above will
    // generate appropriate pk changes

    List     changes = new ArrayList();
    Column[] columns = intermediateTable.getColumns();

    for (int columnIdx = 0; columnIdx < columns.length; columnIdx++)
    {
        Column sourceColumn = columns[columnIdx];
        Column targetColumn = targetTable.findColumn(sourceColumn.getName(), _caseSensitive);

        if (targetColumn == null)
        {
            if (_log.isInfoEnabled())
            {
                _log.info("Column " + sourceColumn.getName() + " needs to be removed from table " + intermediateTable.getQualifiedName());
            }

            RemoveColumnChange change = new RemoveColumnChange(intermediateTable.getQualifiedName(), sourceColumn.getName());

            changes.add(change);
            change.apply(intermediateModel, _caseSensitive);
        }
    }
    return changes;
}
 
Example 8
Source File: FirebirdModelReader.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method that determines the auto increment status using Firebird's system tables.
 *
 * @param table The table
 */
protected void determineAutoIncrementColumns(Table table) throws SQLException
{
	// Since for long table and column names, the generator name will be shortened
	// we have to determine for each column whether there is a generator for it
    final String query = "SELECT RDB$GENERATOR_NAME FROM RDB$GENERATORS WHERE RDB$GENERATOR_NAME NOT LIKE '%$%'";

    FirebirdBuilder builder = (FirebirdBuilder)getPlatform().getSqlBuilder();
	Column[]        columns = table.getColumns();
	HashMap         names   = new HashMap();
    String          name;

	for (int idx = 0; idx < columns.length; idx++)
	{
	    name = builder.getGeneratorName(table, columns[idx]);
        if (!getPlatform().isDelimitedIdentifierModeOn())
        {
            name = name.toUpperCase();
        }
		names.put(name, columns[idx]);
	}

	Statement stmt = null;

	try
	{
	    stmt = getConnection().createStatement();

	    ResultSet rs = stmt.executeQuery(query);

        while (rs.next())
        {
            String generatorName = rs.getString(1).trim();
            Column column        = (Column)names.get(generatorName);

            if (column != null)
            {
                column.setAutoIncrement(true);
            }
        }
	}
    finally
    {
        closeStatement(stmt);
    }
}
 
Example 9
Source File: InterbaseModelReader.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method that determines the auto increment status using Interbase's system tables.
 *
 * @param table The table
 */
protected void determineAutoIncrementColumns(Table table) throws SQLException
{
    // Since for long table and column names, the generator name will be shortened
    // we have to determine for each column whether there is a generator for it
    final String query = "SELECT RDB$GENERATOR_NAME FROM RDB$GENERATORS";

    InterbaseBuilder builder = (InterbaseBuilder)getPlatform().getSqlBuilder();
    Column[]         columns = table.getColumns();
    HashMap          names   = new HashMap();
    String           name;

    for (int idx = 0; idx < columns.length; idx++)
    {
        name = builder.getGeneratorName(table, columns[idx]);
        if (!getPlatform().isDelimitedIdentifierModeOn())
        {
            name = name.toUpperCase();
        }
        names.put(name, columns[idx]);
    }

    Statement stmt = null;

    try
    {
        stmt = getConnection().createStatement();

        ResultSet rs = stmt.executeQuery(query);

        while (rs.next())
        {
            String generatorName = rs.getString(1).trim();
            Column column        = (Column)names.get(generatorName);

            if (column != null)
            {
                column.setAutoIncrement(true);
            }
        }
    }
    finally
    {
        closeStatement(stmt);
    }
}
 
Example 10
Source File: FirebirdModelReader.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method that determines the auto increment status using Firebird's system tables.
 *
 * @param table The table
 */
protected void determineAutoIncrementColumns(Table table) throws SQLException
{
	// Since for long table and column names, the generator name will be shortened
	// we have to determine for each column whether there is a generator for it
    final String query = "SELECT RDB$GENERATOR_NAME FROM RDB$GENERATORS WHERE RDB$GENERATOR_NAME NOT LIKE '%$%'";

    FirebirdBuilder builder = (FirebirdBuilder)getPlatform().getSqlBuilder();
	Column[]        columns = table.getColumns();
	HashMap         names   = new HashMap();
    String          name;

	for (int idx = 0; idx < columns.length; idx++)
	{
	    name = builder.getGeneratorName(table, columns[idx]);
        if (!getPlatform().isDelimitedIdentifierModeOn())
        {
            name = name.toUpperCase();
        }
		names.put(name, columns[idx]);
	}

	Statement stmt = null;

	try
	{
	    stmt = getConnection().createStatement();

	    ResultSet rs = stmt.executeQuery(query);

        while (rs.next())
        {
            String generatorName = rs.getString(1).trim();
            Column column        = (Column)names.get(generatorName);

            if (column != null)
            {
                column.setAutoIncrement(true);
            }
        }
	}
    finally
    {
        closeStatement(stmt);
    }
}
 
Example 11
Source File: InterbaseModelReader.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method that determines the auto increment status using Interbase's system tables.
 *
 * @param table The table
 */
protected void determineAutoIncrementColumns(Table table) throws SQLException
{
    // Since for long table and column names, the generator name will be shortened
    // we have to determine for each column whether there is a generator for it
    final String query = "SELECT RDB$GENERATOR_NAME FROM RDB$GENERATORS";

    InterbaseBuilder builder = (InterbaseBuilder)getPlatform().getSqlBuilder();
    Column[]         columns = table.getColumns();
    HashMap          names   = new HashMap();
    String           name;

    for (int idx = 0; idx < columns.length; idx++)
    {
        name = builder.getGeneratorName(table, columns[idx]);
        if (!getPlatform().isDelimitedIdentifierModeOn())
        {
            name = name.toUpperCase();
        }
        names.put(name, columns[idx]);
    }

    Statement stmt = null;

    try
    {
        stmt = getConnection().createStatement();

        ResultSet rs = stmt.executeQuery(query);

        while (rs.next())
        {
            String generatorName = rs.getString(1).trim();
            Column column        = (Column)names.get(generatorName);

            if (column != null)
            {
                column.setAutoIncrement(true);
            }
        }
    }
    finally
    {
        closeStatement(stmt);
    }
}