Package org.apache.ddlutils.model

Examples of org.apache.ddlutils.model.Column


  }

    private void modifyVarBinaryColumn(Database targetModel, String tableName, String columnName)
    {
        Table table = targetModel.findTable(tableName);
        Column c = table.findColumn(columnName);
        c.setType("VARCHAR");       
        c.setSize("2000");
        System.out.println("updating column " + c.getName() + " for table " + table.getName());
    }
View Full Code Here


            table.addColumns(readColumns(metaData, tableName));

            Collection<String> primaryKeys = readPrimaryKeyNames(metaData, tableName);

            for (Object key : primaryKeys) {
                Column col = table.findColumn((String) key, true);

                if (col != null) {
                    col.setPrimaryKey(true);
                } else {
                    throw new NullPointerException(
                                                   String.format("%s pk %s is null - %s %s",
                                                                 tableName,
                                                                 key,
View Full Code Here

            JdbcUtils.closeResultSet(columnData);
        }
    }

    private static Column readColumn(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException {
        Column column = new Column();

        column.setName((String) values.get("COLUMN_NAME"));
        column.setDefaultValue((String) values.get("COLUMN_DEF"));
        column.setTypeCode(((Integer) values.get("DATA_TYPE")).intValue());

        String typeName = (String) values.get("TYPE_NAME");

        if ((typeName != null) && typeName.startsWith("TIMESTAMP")) {
            column.setTypeCode(Types.TIMESTAMP);
        }

        Integer precision = (Integer) values.get("NUM_PREC_RADIX");

        if (precision != null) {
            column.setPrecisionRadix(precision.intValue());
        }

        String size = (String) values.get("COLUMN_SIZE");

        if (size == null) {
            size = (String) _defaultSizes.get(new Integer(column.getTypeCode()));
        }

        // we're setting the size after the precision and radix in case
        // the database prefers to return them in the size value
        column.setSize(size);

        int scale = 0;
        Object dec_digits = values.get("DECIMAL_DIGITS");

        if (dec_digits instanceof String) {
            scale = (dec_digits == null) ? 0 : NumberUtils.toInt(dec_digits.toString());
        } else if (dec_digits instanceof Integer) {
            scale = (dec_digits == null) ? 0 : (Integer) dec_digits;
        }

        if (scale != 0) {
            column.setScale(scale);
        }

        column.setRequired("NO".equalsIgnoreCase(((String) values.get("IS_NULLABLE")).trim()));
        column.setDescription((String) values.get("REMARKS"));

        return column;
    }
View Full Code Here

        if (fieldDescs != null)
        {
            for (int idx = 0; idx < fieldDescs.length; idx++)
            {
                Column column = mappedTable.findColumn(fieldDescs[idx].getColumnName());

                if (column != null)
                {
                    // we'll check whether another field (of not necessarily the same name)
                    // already maps to this column; if this is the case, we're ignoring
                    // this field
                    boolean alreadyMapped = false;

                    for (Iterator mappedColumnsIt = columnsMap.values().iterator(); mappedColumnsIt.hasNext();)
                    {
                        if (column.equals(mappedColumnsIt.next()))
                        {
                            alreadyMapped = true;
                            break;
                        }
                    }
View Full Code Here

                _elementToRequiredAttributesMap.put(elementName, requiredAttributes);
            }
            for (Iterator columnIt = columns.iterator(); columnIt.hasNext();)
            {
                String columnName = (String)columnIt.next();
                Column column     = mappedTable.findColumn(columnName);

                if (column != null)
                {
                    columnsMap.put(columnName, column);
                    requiredAttributes.put(columnName, Boolean.TRUE);
View Full Code Here

            for (int idx = 0; idx < attributes.getLength(); idx++)
            {
                String attrName  = attributes.getLocalName(idx);
                String attrValue = attributes.getValue(idx);
                Column column    = _preparedModel.getColumnFor(name, attrName);

                if (column == null)
                {
                    throw new DataTaskException("Unknown attribute "+attrName+" of element "+name);
                }
                bean.set(column.getName(), attrValue);
            }
            DdlUtilsDataHandling.this._digester.push(bean);
        }
View Full Code Here

            // linked list
            if ( accessibleTableColumns.getHead() == accessibleTableColumns.getTail() ) {
                proceed = false;
            }

            Column c = new Column();

            // --------------------------
            // Column Name
            // --------------------------

            c.setName(columnDefinition.mColumnName);
            t.addColumn(c);

            // --------------------------
            // Column Type
            // --------------------------

            setupColumnType(pRepository, columnDefinition, c);

            // --------------------------
            // Primary Key
            // --------------------------

            if ( accessibleTableColumns.getPrimaryKeys().contains(c.getName()) || c.getName()
                                                                   .equals(accessibleTableColumns.getMultiColumnName()) ) {
                c.setPrimaryKey(true);
            }

            // --------------------------
            // Null/NotNull
            // --------------------------

            if ( columnDefinition.mIsRequired || accessibleTableColumns.getPrimaryKeys()
                                                       .contains(columnDefinition.mColumnName) ) {
                c.setRequired(true);
            } else {
                c.setRequired(false);
            }

            // --------------------------
            // Unique Index
            // DDLUtils doesn't yet to UNIQUE constraints.. Hmph
            // --------------------------

            if ( columnDefinition.mIsUnique ) {
                UniqueIndex uniqueIndex = new UniqueIndex();
                uniqueIndex.setName("uidx_" + t.getName() + "_" + c.getName());
                uniqueIndex.addColumn(new IndexColumn(c));
                t.addIndex(uniqueIndex);
            }

            // --------------------------
            // References Constraint
            // --------------------------

            if ( columnDefinition.mReferenced != null && !columns.mVersioned ) {

                ForeignKey foreignKey = new ForeignKey();
                Reference reference = new Reference();
                String referencedTableName = columnDefinition.mReferenced.substring(
                        0, columnDefinition.mReferenced.indexOf("(")
                );
                String referencedColumnName = columnDefinition.mReferenced.substring(
                        columnDefinition.mReferenced.indexOf("(") + 1,
                        columnDefinition.mReferenced.indexOf(")")
                );
                org.apache.ddlutils.model.Table referencedTable = pDb.findTable(referencedTableName);
                String fkName = (t.getName()
                                 + c.getName()
                                 + "FK"
                                 + referencedTableName
                                 + referencedColumnName);


                foreignKey.setName(fkName);

                if ( referencedTable != null ) {
                    Column referencedColumn = referencedTable.findColumn(referencedColumnName);
                    if ( referencedTable.getName().equals(t.getName())
                         && pRepository.isLoggingDebug()
                         && referencedColumn.getName().equals(c.getName()) ) {
                        if ( pRepository.isLoggingDebug() ) {
                            pRepository.logDebug(
                                    "Skipping foreign key constraint, table and column are the same. Table.Column="
                                    + referencedTableName
                                    + "."
View Full Code Here

                canColumnsNotExist &= scolumn.isNull();
            } else if (type == EventType.DELETE) {
                canColumnsNotExist &= !scolumn.isKey(); // 主键不允许不存在
            }

            Column matchDbColumn = getMatchColumn(tableHolder.getTable().getColumns(), tcolumn.getColumnName());
            // 匹配字段为空,可能源库发生过DDL操作,目标库重新载入一下meta信息
            if (matchDbColumn == null) { // 尝试reload一下table meta
                // 获取目标库的表信息
                DbMediaSource dbMediaSource = (DbMediaSource) dataMediaPair.getTarget().getSource();
                DbDialect dbDialect = dbDialectFactory.getDbDialect(dataMediaPair.getPipelineId(), dbMediaSource);
                String schemaName = tableHolder.getTable().getSchema();
                if (StringUtils.isEmpty(schemaName)) {
                    schemaName = tableHolder.getTable().getCatalog();
                }
                Table table = dbDialect.findTable(schemaName, tableHolder.getTable().getName(), false); // 强制反查一次,并放入cache

                tableHolder.setTable(table);
                matchDbColumn = getMatchColumn(tableHolder.getTable().getColumns(), tcolumn.getColumnName());
                if (matchDbColumn == null) {
                    if (canColumnsNotExist) {
                        return null;
                    } else {
                        throw new TransformException(scolumn.getColumnName() + " is not found in " + table.toString()
                                                     + " and source : " + dataMediaPair.getTarget().getNamespace()
                                                     + "." + dataMediaPair.getTarget().getName());
                    }
                }
            }

            if (tableHolder.isUseTableTransform()) {
                int sqlType = matchDbColumn.getTypeCode();
                tcolumn.setColumnType(sqlType);
            }
        }

        if (dataMediaPair.getTarget().getSource().getType().isOracle()) {
View Full Code Here

                            throw new ExtractException("data pk column size not match , data:" + eventData.toString());
                        }
                        // 构建字段
                        Column[] allColumns = table.getColumns();
                        for (int i = 0; i < allColumns.length; i++) {
                            Column column = allColumns[i];
                            if (column.isPrimaryKey()) {
                                EventColumn newColumn = new EventColumn();
                                newColumn.setIndex(i); // 设置下标
                                newColumn.setColumnName(column.getName());
                                newColumn.setColumnType(column.getTypeCode());
                                newColumn.setColumnValue(pks[i]);
                                newColumn.setKey(true);
                                newColumn.setNull(pks[i] == null);
                                newColumn.setUpdate(true);
                                // 添加到记录
View Full Code Here

                canColumnsNotExist &= scolumn.isNull();
            } else if (type == EventType.DELETE) {
                canColumnsNotExist &= !scolumn.isKey(); // 主键不允许不存在
            }

            Column matchDbColumn = getMatchColumn(tableHolder.getTable().getColumns(), tcolumn.getColumnName());
            // 匹配字段为空,可能源库发生过DDL操作,目标库重新载入一下meta信息
            if (matchDbColumn == null) { // 尝试reload一下table meta
                // 获取目标库的表信息
                DbMediaSource dbMediaSource = (DbMediaSource) dataMediaPair.getTarget().getSource();
                DbDialect dbDialect = dbDialectFactory.getDbDialect(dataMediaPair.getPipelineId(), dbMediaSource);
                String schemaName = tableHolder.getTable().getSchema();
                if (StringUtils.isEmpty(schemaName)) {
                    schemaName = tableHolder.getTable().getCatalog();
                }
                Table table = dbDialect.findTable(schemaName, tableHolder.getTable().getName(), false); // 强制反查一次,并放入cache

                tableHolder.setTable(table);
                matchDbColumn = getMatchColumn(tableHolder.getTable().getColumns(), tcolumn.getColumnName());
                if (matchDbColumn == null) {
                    if (canColumnsNotExist) {
                        return null;
                    } else {
                        throw new TransformException(scolumn.getColumnName() + " is not found in " + table.toString()
                                                     + " and source : " + dataMediaPair.getTarget().getNamespace()
                                                     + "." + dataMediaPair.getTarget().getName());
                    }
                }
            }

            if (tableHolder.isUseTableTransform()) {
                int sqlType = matchDbColumn.getTypeCode();
                tcolumn.setColumnType(sqlType);
            }
        }

        if (dataMediaPair.getTarget().getSource().getType().isOracle()) {
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.