Package com.asakusafw.dmdl.thundergate.util

Examples of com.asakusafw.dmdl.thundergate.util.TableModelBuilder


     * table cache without SID.
     * @throws Exception if test was failed
     */
    @Test
    public void table_cached_invalid_delete() throws Exception {
        TableModelDescription table = new TableModelBuilder("SIMPLE")
            .add("", "SID", new BasicType(PropertyTypeKind.LONG))
            .add("", "TIMESTAMP", new BasicType(PropertyTypeKind.DATETIME))
            .add("", "DELETE", new BasicType(PropertyTypeKind.LONG))
            .toDescription();

View Full Code Here


    /**
     * simple join.
     */
    @Test
    public void simple() {
        TableModelDescription left = new TableModelBuilder("LEFT")
            .add(null, "SID", PropertyTypeKind.LONG, Attribute.PRIMARY_KEY)
            .add(null, "RIGHT_ID", PropertyTypeKind.LONG)
            .add(null, "VALUE", new StringType(255))
            .toDescription();
        TableModelDescription right = new TableModelBuilder("RIGHT")
            .add(null, "SID", PropertyTypeKind.LONG, Attribute.PRIMARY_KEY)
            .add(null, "VALUE", new StringType(255))
            .toDescription();
        JoinedModelDescription join = new JoinedModelBuilder("SIMPLE", left, "l", right, "r")
            .on("l.RIGHT_ID", "r.SID")
View Full Code Here

    /**
     * simple summarize.
     */
    @Test
    public void simple() {
        TableModelDescription target = new TableModelBuilder("TARGET")
            .add(null, "SID", PropertyTypeKind.LONG, Attribute.PRIMARY_KEY)
            .add(null, "VALUE_A", PropertyTypeKind.INT)
            .add(null, "VALUE_B", PropertyTypeKind.LONG)
            .add(null, "VALUE_C", PropertyTypeKind.DATE)
            .toDescription();
View Full Code Here

    /**
     * Summarize with conflict grouping key and aggregation target.
     */
    @Test
    public void conflict_key() {
        TableModelDescription target = new TableModelBuilder("TARGET")
            .add(null, "SID", PropertyTypeKind.LONG, Attribute.PRIMARY_KEY)
            .add(null, "GROUPING", PropertyTypeKind.INT)
            .toDescription();
        SummarizedModelDescription summarize = new SummarizedModelBuilder("SIMPLE", target, "t")
            .groupBy("GROUPING")
View Full Code Here

    /**
     * simple table.
     */
    @Test
    public void simple() {
        TableModelDescription table = new TableModelBuilder("SIMPLE")
            .add("comment", "VALUE", new StringType(255))
            .toDescription();
        emitDmdl(RecordModelGenerator.generate(table));

        ModelLoader loader = generateJava();
View Full Code Here

    /**
     * all types.
     */
    @Test
    public void primitives() {
        TableModelDescription table = new TableModelBuilder("SIMPLE")
            .add(null, "TYPE_BOOLEAN", PropertyTypeKind.BOOLEAN)
            .add(null, "TYPE_BYTE", PropertyTypeKind.BYTE)
            .add(null, "TYPE_SHORT", PropertyTypeKind.SHORT)
            .add(null, "TYPE_INT", PropertyTypeKind.INT)
            .add(null, "TYPE_LONG", PropertyTypeKind.LONG)
View Full Code Here

    /**
     * table with primary keys.
     */
    @Test
    public void primary_keys() {
        TableModelDescription table = new TableModelBuilder("SIMPLE")
            .add("SID", "SID", PropertyTypeKind.LONG, Attribute.PRIMARY_KEY)
            .add("comment", "VALUE", new StringType(255))
            .toDescription();
        emitDmdl(RecordModelGenerator.generate(table));

View Full Code Here

            ps = conn.prepareStatement(sql);
            ps.setString(1, databaseName);
            rs = ps.executeQuery();

            String prevTableName = null;
            TableModelBuilder builder = null;
            while (rs.next()) {
                // カラム情報の取り出し
                String tableName = rs.getString(1);
                String columnName = rs.getString(2);
                String columnComment = rs.getString(3);
                String dataType = rs.getString(4);
                long characterMaximumLength = rs.getLong(5);
                int numericPrecision = rs.getInt(6);
                int numericScale = rs.getInt(7);
                String isNullable = rs.getString(8);
                String columnKey = rs.getString(9);

                if (filter.acceptModel(tableName) == false) {
                    if (tableName.equals(prevTableName) == false) {
                        LOG.info("テーブル{}はユーザの指定によりスキップされます", tableName);
                        prevTableName = tableName;
                    }
                    continue;
                }

                // 対象テーブルが変わったかを確認
                if (builder == null
                        || prevTableName == null
                        || prevTableName.equals(tableName) == false) {
                    if (builder != null) {
                        results.add(builder.toDescription());
                    }
                    builder = new TableModelBuilder(tableName);
                    prevTableName = tableName;
                }

                // データ型からプロパティの型を得る
                PropertyTypeKind propertyType = MySqlDataType.getPropertyTypeByString(dataType);
                if (propertyType == null) {
                    LOG.error("データ型{}は未サポートのため、無視されます({}:{})", new Object[] {
                            dataType,
                            tableName,
                            columnName,
                    });
                    continue;
                }

                // Attributeに設定すべき項目があるか調べる
                // 現状は、NOT NULL制約と、PRIMARY KEY制約にのみ対応
                List<Attribute> attributeList = Lists.create();
                if (isNullable != null && isNullable.equals(STR_NOT_NULL)) {
                    attributeList.add(Attribute.NOT_NULL);
                }
                if (columnKey != null && columnKey.equals(MySQLConstants.STR_IS_PK)) {
                    attributeList.add(Attribute.PRIMARY_KEY);
                }

                Attribute[] attributes = attributeList.toArray(new Attribute[attributeList.size()]);
                switch (propertyType) {
                case BIG_DECIMAL:
                    DecimalType decimalType = new DecimalType(numericPrecision, numericScale);
                    builder.add(columnComment, columnName, decimalType, attributes);
                    break;
                case STRING:
                    StringType stringType = new StringType((int) characterMaximumLength);
                    builder.add(columnComment, columnName, stringType, attributes);
                    break;
                default:
                    builder.add(columnComment, columnName, propertyType, attributes);
                    break;
                }
            }
            if (builder != null) {
                results.add(builder.toDescription());
            }
        } finally {
            if (rs != null) {
                try {
                    rs.close();
View Full Code Here

TOP

Related Classes of com.asakusafw.dmdl.thundergate.util.TableModelBuilder

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.