Package org.apache.ddlutils.model

Examples of org.apache.ddlutils.model.Column


        Table curTable = currentModel.findTable(change.getChangedTable().getName(), getPlatform().isDelimitedIdentifierModeOn());

        if (!change.isAtEnd())
        {
            Column prevColumn = change.getPreviousColumn();

            if (prevColumn != null)
            {
                // we need the corresponding column object from the current table
                prevColumn = curTable.findColumn(prevColumn.getName(), getPlatform().isDelimitedIdentifierModeOn());
            }
            // Even though Interbase can only add columns, we can move them later on
            print("ALTER TABLE ");
            printlnIdentifier(getTableName(change.getChangedTable()));
            printIndent();
View Full Code Here


     * @param table      The table
     * @return The value
     */
    protected Object getObjectFromResultSet(ResultSet resultSet, String columnName, Table table) throws SQLException
    {
        Column column = (table == null ? null : table.findColumn(columnName, isDelimitedIdentifierModeOn()));
        Object value  = null;

        if (column != null)
        {
            int originalJdbcType = column.getTypeCode();
            int targetJdbcType   = getPlatformInfo().getTargetJdbcType(originalJdbcType);
            int jdbcType         = originalJdbcType;

            // in general we're trying to retrieve the value using the original type
            // but sometimes we also need the target type:
View Full Code Here

            String propName = columnName;

            if (table != null)
            {
                Column column = table.findColumn(columnName, _caseSensitive);

                if (column != null)
                {
                    propName = column.getName();
                }
            }
            _columnsToProperties.put(columnName, propName);
        }
        if (singleKnownTable && (tableName != null))
View Full Code Here

     */
    public void createTable(Database database, Table table, Map parameters) throws IOException
    {
        for (int idx = 0; idx < table.getColumnCount(); idx++)
        {
            Column column = table.getColumn(idx);

            if (column.isAutoIncrement())
            {
                createAutoIncrementSequence(table, column);
            }
        }
        super.createTable(database, table, parameters);
View Full Code Here

        {
            Table table = model.getTable(tableIdx);

            for (int columnIdx = 0; columnIdx < table.getColumnCount(); columnIdx++)
            {
                Column column = table.getColumn(columnIdx);

                if (TypeMap.isTextType(column.getTypeCode()) ||
                    TypeMap.isDateTimeType(column.getTypeCode()))
                {
                    String defaultValue = column.getDefaultValue();

                    if ((defaultValue != null) && (defaultValue.length() >= 2) &&
                        defaultValue.startsWith("'") && defaultValue.endsWith("'"))
                    {
                        defaultValue = defaultValue.substring(1, defaultValue.length() - 1);
                        column.setDefaultValue(defaultValue);
                    }
                }
            }
        }
    }
View Full Code Here

        assertEquals(0,
                     table.getForeignKeyCount());
        assertEquals(0,
                     table.getIndexCount());

        Column column = table.getColumn(0);

        assertEquals("ID",
                     column.getName());
        assertEquals("INTEGER",
                     column.getType());
        assertEquals(Types.INTEGER,
                     column.getTypeCode());
        assertTrue(column.isPrimaryKey());
        assertTrue(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertEquals("The primary key",
                     column.getDescription());
        assertEquals("javaId", column.getJavaName());
        assertEquals(
            "<?xml version=\"1.0\"?>\n<!DOCTYPE database SYSTEM \"" + LocalEntityResolver.DTD_PREFIX + "\">\n" +
            "  <database name=\"test\">\n" +
            "    <table name=\"SomeTable\" description=\"Some table\">\n" +
            "      <column name=\"ID\" primaryKey=\"true\" required=\"true\" type=\"INTEGER\" autoIncrement=\"false\" description=\"The primary key\" javaName=\"javaId\"/>\n" +
View Full Code Here

        assertEquals(0,
                     someTable.getForeignKeyCount());
        assertEquals(0,
                     someTable.getIndexCount());

        Column pkColumn = someTable.getColumn(0);

        assertEquals("ID",
                     pkColumn.getName());
        assertEquals("VARCHAR",
                     pkColumn.getType());
        assertEquals(Types.VARCHAR,
                     pkColumn.getTypeCode());
        assertEquals(16,
                     pkColumn.getSizeAsInt());
        assertTrue(pkColumn.isPrimaryKey());
        assertTrue(pkColumn.isRequired());
        assertFalse(pkColumn.isAutoIncrement());
        assertNull(pkColumn.getDefaultValue());
        assertEquals("The primary key",
                     pkColumn.getDescription());

        Table anotherTable = model.getTable(1);

        assertEquals("AnotherTable",
                     anotherTable.getName());
        assertEquals("And another table",
                     anotherTable.getDescription());
        assertEquals(0, anotherTable.getAutoIncrementColumns().length);
        assertEquals(1,
                     anotherTable.getColumnCount());
        assertEquals(1,
                     anotherTable.getForeignKeyCount());
        assertEquals(0,
                     anotherTable.getIndexCount());

        Column fkColumn = anotherTable.getColumn(0);

        assertEquals("Some_ID",
                     fkColumn.getName());
        assertEquals("VARCHAR",
                     fkColumn.getType());
        assertEquals(Types.VARCHAR,
                     fkColumn.getTypeCode());
        assertEquals(16,
                     fkColumn.getSizeAsInt());
        assertFalse(fkColumn.isPrimaryKey());
        assertFalse(fkColumn.isRequired());
        assertFalse(fkColumn.isAutoIncrement());
        assertEquals("The foreign key",
                     fkColumn.getDescription());

        ForeignKey fk = anotherTable.getForeignKey(0);

        assertNull(fk.getName());
        assertEquals(someTable,
View Full Code Here

        Table    table = getModel().findTable(tableName);
        DynaBean bean  = getModel().createDynaBeanFor(table);

        for (int idx = 0; (idx < table.getColumnCount()) && (idx < columnValues.length); idx++)
        {
            Column column = table.getColumn(idx);

            bean.set(column.getName(), columnValues[idx]);
        }
        getPlatform().insert(getModel(), bean);
    }
View Full Code Here

            {
                Table table = model.getTable(tableIdx);

                for (int columnIdx = 0; columnIdx < table.getColumnCount(); columnIdx++)
                {
                    Column column     = table.getColumn(columnIdx);
                    int    origType   = column.getTypeCode();
                    int    targetType = getPlatformInfo().getTargetJdbcType(origType);

                    // we adjust the column types if the native type would back-map to a
                    // different jdbc type
                    if (targetType != origType)
                    {
                        column.setTypeCode(targetType);
                        // we should also adapt the default value
                        if (column.getDefaultValue() != null)
                        {
                            DefaultValueHelper helper = getPlatform().getSqlBuilder().getDefaultValueHelper();

                            column.setDefaultValue(helper.convert(column.getDefaultValue(), origType, targetType));
                        }
                    }
                    // we also promote the default size if the column has no size
                    // spec of its own
                    if ((column.getSize() == null) && getPlatformInfo().hasSize(targetType))
                    {
                        Integer defaultSize = getPlatformInfo().getDefaultSize(targetType);

                        if (defaultSize != null)
                        {
                            column.setSize(defaultSize.toString());
                        }
                    }
                    // finally the platform might return a synthetic default value if the column
                    // is a primary key column
                    if (getPlatformInfo().isSyntheticDefaultValueForRequiredReturned() &&
                        (column.getDefaultValue() == null) && column.isRequired() && !column.isAutoIncrement())
                    {
                        switch (column.getTypeCode())
                        {
                            case Types.TINYINT:
                            case Types.SMALLINT:
                            case Types.INTEGER:
                            case Types.BIGINT:
                                column.setDefaultValue("0");
                                break;
                            case Types.REAL:
                            case Types.FLOAT:
                            case Types.DOUBLE:
                                column.setDefaultValue("0.0");
                                break;
                            case Types.BIT:
                                column.setDefaultValue("false");
                                break;
                            default:
                                column.setDefaultValue("");
                                break;
                        }
                    }
                }
                // we also add the default names to foreign keys that are initially unnamed
View Full Code Here

        Object   value    = dynaBean.get(attrName);

        if ((value instanceof byte[]) && !(expected instanceof byte[]) && (dynaBean instanceof SqlDynaBean))
        {
            SqlDynaClass dynaClass = (SqlDynaClass)((SqlDynaBean)dynaBean).getDynaClass();
            Column       column    = ((SqlDynaProperty)dynaClass.getDynaProperty(attrName)).getColumn();

            if (TypeMap.isBinaryType(column.getTypeCode()))
            {
                value = new BinaryObjectsHelper().deserialize((byte[])value);
            }
        }
        if (expected == null)
View Full Code Here

TOP

Related Classes of org.apache.ddlutils.model.Column

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.