Package org.apache.ddlutils.model

Examples of org.apache.ddlutils.model.Table


        assertEquals("test",
                     model.getName());
        assertEquals(1,
                     model.getTableCount());
       
        Table table = model.getTable(0);

        assertEquals("TableWidthIndex",
                     table.getName());
        assertNull(table.getDescription());
        assertEquals(0, table.getAutoIncrementColumns().length);
        assertEquals(3,
                     table.getColumnCount());
        assertEquals(0,
                     table.getForeignKeyCount());
        assertEquals(2,
                     table.getIndexCount());

        Column column = table.getColumn(0);

        assertEquals("id",
                     column.getName());
        assertEquals("DOUBLE",
                     column.getType());
        assertEquals(Types.DOUBLE,
                     column.getTypeCode());
        assertTrue(column.isPrimaryKey());
        assertTrue(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertNull(column.getDefaultValue());
        assertNull(column.getDescription());

        column = table.getColumn(1);

        assertEquals("when",
                     column.getName());
        assertEquals("TIMESTAMP",
                     column.getType());
        assertEquals(Types.TIMESTAMP,
                     column.getTypeCode());
        assertFalse(column.isPrimaryKey());
        assertTrue(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertNull(column.getDescription());

        column = table.getColumn(2);

        assertEquals("value",
                     column.getName());
        assertEquals("SMALLINT",
                     column.getType());
        assertEquals(Types.SMALLINT,
                     column.getTypeCode());
        assertFalse(column.isPrimaryKey());
        assertFalse(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertEquals("1",
                     column.getDefaultValue());
        assertNull(column.getDescription());

        Index index = table.getIndex(0);

        assertEquals("test index",
                     index.getName());
        assertFalse(index.isUnique());
        assertEquals(1,
                     index.getColumnCount());

        IndexColumn indexColumn = index.getColumn(0);

        assertEquals("value",
                     indexColumn.getName());
        assertNull(indexColumn.getSize());

        index = table.getIndex(1);

        assertNull(index.getName());
        assertFalse(index.isUnique());
        assertEquals(2,
                     index.getColumnCount());
View Full Code Here


        assertEquals("test",
                     model.getName());
        assertEquals(1,
                     model.getTableCount());
       
        Table table = model.getTable(0);

        assertEquals("TableWidthIndices",
                     table.getName());
        assertNull(table.getDescription());
        assertEquals(2,
                     table.getColumnCount());
        assertEquals(0,
                     table.getForeignKeyCount());
        assertEquals(2,
                     table.getIndexCount());

        Column column = table.getColumn(0);

        assertEquals("id",
                     column.getName());
        assertEquals("SMALLINT",
                     column.getType());
        assertEquals(Types.SMALLINT,
                     column.getTypeCode());
        assertFalse(column.isPrimaryKey());
        assertTrue(column.isRequired());
        assertTrue(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertNull(column.getDefaultValue());
        assertNull(column.getDescription());
       
        assertEquals(1, table.getAutoIncrementColumns().length);
        assertEquals(column, table.getAutoIncrementColumns()[0]);

        column = table.getColumn(1);

        assertEquals("when",
                     column.getName());
        assertEquals("DATE",
                     column.getType());
        assertEquals(Types.DATE,
                     column.getTypeCode());
        assertFalse(column.isPrimaryKey());
        assertFalse(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertNull(column.getDescription());

        Index index = table.getIndex(0);

        assertEquals("important column",
                     index.getName());
        assertTrue(index.isUnique());
        assertEquals(1,
                     index.getColumnCount());

        IndexColumn indexColumn = index.getColumn(0);

        assertEquals("id",
                     indexColumn.getName());
        assertNull(indexColumn.getSize());

        index = table.getIndex(1);

        assertNull(index.getName());
        assertFalse(index.isUnique());
        assertEquals(1,
                     index.getColumnCount());
View Full Code Here

        assertEquals(3,
                     model.getTableCount());

        // table A

        Table table = model.getTable(0);

        assertEquals("A",
                     table.getName());
        assertEquals("Table A",
                     table.getDescription());
        assertEquals(3,
                     table.getColumnCount());
        assertEquals(1,
                     table.getForeignKeyCount());
        assertEquals(1,
                     table.getIndexCount());

        Column column = table.getColumn(0);

        assertEquals("id",
                     column.getName());
        assertEquals("INTEGER",
                     column.getType());
        assertEquals(Types.INTEGER,
                     column.getTypeCode());
        assertNull(column.getSize());
        assertEquals(0,
                     column.getSizeAsInt());
        assertTrue(column.isPrimaryKey());
        assertTrue(column.isRequired());
        assertTrue(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertEquals("The primary key of table A",
                     column.getDescription());
        assertEquals(1, table.getAutoIncrementColumns().length);
        assertEquals(column,
                     table.getAutoIncrementColumns()[0]);

        column = table.getColumn(1);

        assertEquals("parentId",
                     column.getName());
        assertEquals("INTEGER",
                     column.getType());
        assertEquals(Types.INTEGER,
                     column.getTypeCode());
        assertNull(column.getSize());
        assertEquals(0,
                     column.getSizeAsInt());
        assertFalse(column.isPrimaryKey());
        assertFalse(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertEquals("The field for the foreign key parent",
                     column.getDescription());

        column = table.getColumn(2);

        assertEquals("name",
                     column.getName());
        assertEquals("VARCHAR",
                     column.getType());
        assertEquals(Types.VARCHAR,
                     column.getTypeCode());
        assertEquals("32",
                     column.getSize());
        assertEquals(32,
                     column.getSizeAsInt());
        assertFalse(column.isPrimaryKey());
        assertTrue(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertEquals("The name",
                     column.getDescription());

        ForeignKey fk = table.getForeignKey(0);

        assertEquals("parent",
                     fk.getName());
        assertEquals(table,
                     fk.getForeignTable());
        assertEquals("A",
                     fk.getForeignTableName());
        assertEquals(1,
                     fk.getReferenceCount());

        Reference ref = fk.getFirstReference();

        assertEquals(table.getColumn(1),
                     ref.getLocalColumn());
        assertEquals("parentId",
                     ref.getLocalColumnName());
        assertEquals(table.getColumn(0),
                     ref.getForeignColumn());
        assertEquals("id",
                     ref.getForeignColumnName());

        Index index = table.getIndex(0);

        assertNull(index.getName());
        assertTrue(index.isUnique());
        assertEquals(1,
                     index.getColumnCount());

        IndexColumn indexColumn = index.getColumn(0);

        assertEquals("name",
                     indexColumn.getName());
        assertNull(indexColumn.getSize());

        // table B
       
        table = model.getTable(1);

        assertEquals("B",
                     table.getName());
        assertEquals("Table B",
                     table.getDescription());
        assertEquals(0, table.getAutoIncrementColumns().length);
        assertEquals(3,
                     table.getColumnCount());
        assertEquals(2,
                     table.getForeignKeyCount());
        assertEquals(1,
                     table.getIndexCount());

        column = table.getColumn(0);

        assertEquals("id",
                     column.getName());
        assertEquals("TIMESTAMP",
                     column.getType());
        assertEquals(Types.TIMESTAMP,
                     column.getTypeCode());
        assertNull(column.getSize());
        assertEquals(0,
                     column.getSizeAsInt());
        assertTrue(column.isPrimaryKey());
        assertTrue(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertEquals("The primary key of table B",
                     column.getDescription());

        column = table.getColumn(1);

        assertEquals("aid",
                     column.getName());
        assertEquals("INTEGER",
                     column.getType());
        assertEquals(Types.INTEGER,
                     column.getTypeCode());
        assertNull(column.getSize());
        assertEquals(0,
                     column.getSizeAsInt());
        assertFalse(column.isPrimaryKey());
        assertFalse(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertEquals("The field for the foreign key towards A",
                     column.getDescription());

        column = table.getColumn(2);

        assertEquals("cid",
                     column.getName());
        assertEquals("CHAR",
                     column.getType());
        assertEquals(Types.CHAR,
                     column.getTypeCode());
        assertEquals("32",
                     column.getSize());
        assertEquals(32,
                     column.getSizeAsInt());
        assertFalse(column.isPrimaryKey());
        assertFalse(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertEquals("The field for the foreign key towards C",
                     column.getDescription());

        fk = table.getForeignKey(0);

        assertNull(fk.getName());
        assertEquals(model.getTable(0),
                     fk.getForeignTable());
        assertEquals("A",
                     fk.getForeignTableName());
        assertEquals(1,
                     fk.getReferenceCount());

        ref = fk.getFirstReference();

        assertEquals(table.getColumn(1),
                     ref.getLocalColumn());
        assertEquals("aid",
                     ref.getLocalColumnName());
        assertEquals(model.getTable(0).getColumn(0),
                     ref.getForeignColumn());
        assertEquals("id",
                     ref.getForeignColumnName());

        fk = table.getForeignKey(1);

        assertNull(fk.getName());
        assertEquals(model.getTable(2),
                     fk.getForeignTable());
        assertEquals("C",
                     fk.getForeignTableName());
        assertEquals(1,
                     fk.getReferenceCount());

        ref = fk.getFirstReference();

        assertEquals(table.getColumn(2),
                     ref.getLocalColumn());
        assertEquals("cid",
                     ref.getLocalColumnName());
        assertEquals(model.getTable(2).getColumn(0),
                     ref.getForeignColumn());
        assertEquals("id",
                     ref.getForeignColumnName());

        index = table.getIndex(0);

        assertNull(index.getName());
        assertFalse(index.isUnique());
        assertEquals(2,
                     index.getColumnCount());

        indexColumn = index.getColumn(0);

        assertEquals("aid",
                     indexColumn.getName());
        assertNull(indexColumn.getSize());

        indexColumn = index.getColumn(1);

        assertEquals("cid",
                     indexColumn.getName());
        assertNull(indexColumn.getSize());

        // table C

        table = model.getTable(2);

        assertEquals("C",
                     table.getName());
        assertEquals("Table C",
                     table.getDescription());
        assertEquals(0, table.getAutoIncrementColumns().length);
        assertEquals(2,
                     table.getColumnCount());
        assertEquals(0,
                     table.getForeignKeyCount());
        assertEquals(1,
                     table.getIndexCount());

        column = table.getColumn(0);

        assertEquals("id",
                     column.getName());
        assertEquals("CHAR",
                     column.getType());
        assertEquals(Types.CHAR,
                     column.getTypeCode());
        assertEquals("32",
                     column.getSize());
        assertEquals(32,
                     column.getSizeAsInt());
        assertTrue(column.isPrimaryKey());
        assertTrue(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertEquals("The primary key of table C",
                     column.getDescription());

        column = table.getColumn(1);

        assertEquals("text",
                     column.getName());
        assertEquals("LONGVARCHAR",
                     column.getType());
        assertEquals(Types.LONGVARCHAR,
                     column.getTypeCode());
        assertNull(column.getSize());
        assertEquals(0,
                     column.getSizeAsInt());
        assertFalse(column.isPrimaryKey());
        assertFalse(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertEquals("The text",
                     column.getDescription());

        index = table.getIndex(0);

        assertEquals("byText",
                     index.getName());
        assertFalse(index.isUnique());
        assertEquals(1,
View Full Code Here

        EventType eventType = eventData.getEventType();
        TableInfoHolder tableHolder = null;

        if (!StringUtils.equalsIgnoreCase(pipeline.getParameters().getSystemSchema(), eventData.getSchemaName())) {
            boolean useTableTransform = pipeline.getParameters().getUseTableTransform();
            Table table = null;
            DataMedia dataMedia = ConfigHelper.findSourceDataMedia(pipeline,
                eventData.getSchemaName(),
                eventData.getTableName());
            eventData.setTableId(dataMedia.getId());
            if (useTableTransform || dataMedia.getSource().getType().isOracle()) {// oracle需要反查一次meta
View Full Code Here

                                                              // meta信息,如果同构数据库,完全没必要反查
            // 获取目标库的表信息
            DbDialect dbDialect = dbDialectFactory.getDbDialect(dataMediaPair.getPipelineId(),
                (DbMediaSource) dataMedia.getSource());

            Table table = dbDialect.findTable(result.getSchemaName(), result.getTableName());
            tableHolder = new TableInfoHolder(table, useTableTransform, enableCompatibleMissColumn);
        }

        // 处理column转化
        List<EventColumn> otherColumns = translateColumns(result,
View Full Code Here

                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());
                    }
                }
            }
View Full Code Here

            public Table apply(List<String> names) {
                Assert.isTrue(names.size() == 2);
                try {
                    beforeFindTable(jdbcTemplate, names.get(0), names.get(0), names.get(1));
                    DdlUtilsFilter filter = getDdlUtilsFilter(jdbcTemplate, names.get(0), names.get(0), names.get(1));
                    Table table = DdlUtils.findTable(jdbcTemplate, names.get(0), names.get(0), names.get(1), filter);
                    afterFindTable(table, jdbcTemplate, names.get(0), names.get(0), names.get(1));
                    return table;
                } catch (Exception e) {
                    throw new NestableRuntimeException("find table error : " + names.toString(), e);
                }
View Full Code Here

                int paramIndex = i + 1;
                EventColumn column = columns.get(i);
                int sqlType = column.getColumnType();

                // 获取一下当前字段名的数据是否必填
                Table table = dbDialect.findTable(data.getSchemaName(), data.getTableName());
                Map<String, Boolean> isRequiredMap = new HashMap<String, Boolean>();
                for (Column tableColumn : table.getColumns()) {
                    isRequiredMap.put(StringUtils.lowerCase(tableColumn.getName()), tableColumn.isRequired());
                }

                Boolean isRequired = isRequiredMap.get(StringUtils.lowerCase(column.getColumnName()));
                if (isRequired == null) {
                    throw new LoadException(String.format("column name %s is not found in Table[%s]",
                                                          column.getColumnName(), table.toString()));
                }

                Object param = SqlUtils.stringToSqlValue(column.getColumnValue(), sqlType, isRequired,
                                                         dbDialect.isEmptyStringNulled());
                try {
View Full Code Here

        eventData.setEventType(EventType.valueOf(rowChange.getEventType().name()));
        eventData.setExecuteTime(entry.getHeader().getExecuteTime());

        boolean useTableTransform = pipeline.getParameters().getUseTableTransform();
        EventType eventType = eventData.getEventType();
        Table table = null;
        TableInfoHolder tableHolder = null;

        if (eventType.isQuery()) {
            // 直接忽略query事件
            return null;
View Full Code Here

                        // 重新构建新的业务主键字段
                        EventColumn pkDataColumn = getMatchColumn(eventData.getColumns(), PK_DATA);
                        String pkData = pkDataColumn.getColumnValue();
                        String[] pks = StringUtils.split(pkData, PK_SPLIT);

                        Table table = dbDialect.findTable(eventData.getSchemaName(), eventData.getTableName());
                        List<EventColumn> newColumns = new ArrayList<EventColumn>();
                        Column[] primaryKeyColumns = table.getPrimaryKeyColumns();
                        if (primaryKeyColumns.length > pks.length) {
                            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); // 设置下标
View Full Code Here

TOP

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

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.