Package com.asakusafw.modelgen.util

Examples of com.asakusafw.modelgen.util.TableModelBuilder$Column


            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);
                    builder.namespace(Constants.SOURCE_TABLE);
                    prevTableName = tableName;
                }

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

                // Attributeに設定すべき項目があるか調べる
                // 現状は、NOT NULL制約と、PRIMARY KEY制約にのみ対応
                ArrayList<Attribute> attributeList = new ArrayList<Attribute>();
                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


     * 単純なテーブル
     * @throws Throwable 例外が発生した場合
     */
    @Test
    public void simple() throws Throwable {
        TableModelDescription a = new TableModelBuilder("A")
            .add(null, "id", PropertyTypeKind.LONG)
            .add(null, "hoge", new StringType(255))
            .toDescription();
        TableModelDescription b = new TableModelBuilder("B")
            .add(null, "id", PropertyTypeKind.LONG)
            .add(null, "foo", new StringType(255))
            .toDescription();
        JoinedModelDescription j = new JoinedModelBuilder("J", a, "a", b, "b")
            .on("a.id", "b.id")
View Full Code Here

     */
    @Test
    public void simple() throws Throwable {
        init("simple");

        TableModelDescription model = new TableModelBuilder("Model")
            .add(null, "id", PropertyTypeKind.LONG, Attribute.PRIMARY_KEY)
            .toDescription();

        new Table().emit(model);
        new TsvIn().emit(model);
View Full Code Here

     */
    @Test
    public void complex() throws Throwable {
        init("complex");

        TableModelDescription model = new TableModelBuilder("Model")
            .add(null, "id", PropertyTypeKind.LONG, Attribute.PRIMARY_KEY)
            .add(null, "value", new StringType(255))
            .add(null, "date", PropertyTypeKind.DATE)
            .add(null, "price", PropertyTypeKind.INT)
            .add(null, "flag", PropertyTypeKind.BOOLEAN)
View Full Code Here

     */
    @Test
    public void empty() throws Throwable {
        init("empty");

        TableModelDescription model = new TableModelBuilder("Model")
            .add(null, "id", PropertyTypeKind.LONG, Attribute.PRIMARY_KEY)
            .toDescription();

        new Table().emit(model);
        new TsvIn().emit(model);
View Full Code Here

     * 単純なテーブル
     * @throws Throwable 例外が発生した場合
     */
    @Test
    public void simple() throws Throwable {
        TableModelDescription model = new TableModelBuilder("Hello")
            .add(null, "id", PropertyTypeKind.LONG, Attribute.PRIMARY_KEY)
            .add(null, "value", new StringType(255))
            .toDescription();

        new Table().emit(model);
View Full Code Here

     * booleanのgetter名に関するもの。
     * @throws Throwable 例外が発生した場合
     */
    @Test
    public void booleanGetter() throws Throwable {
        TableModelDescription model = new TableModelBuilder("Hello")
            .add(null, "id", PropertyTypeKind.LONG, Attribute.PRIMARY_KEY)
            .add(null, "frag", PropertyTypeKind.BOOLEAN)
            .toDescription();

        new Table().emit(model);
View Full Code Here

     * Writableのテスト。
     * @throws Throwable 例外が発生した場合
     */
    @Test
    public void writable() throws Throwable {
        TableModelDescription model = new TableModelBuilder("Hello")
            .add(null, "id", PropertyTypeKind.LONG, Attribute.PRIMARY_KEY)
            .add(null, "value", new StringType(255))
            .add(null, "nothing", new StringType(255))
            .toDescription();

View Full Code Here

     * 名前空間付きのモデル。
     * @throws Throwable 例外が発生した場合
     */
    @Test
    public void namespace() throws Throwable {
        TableModelDescription model = new TableModelBuilder("Hello")
            .namespace("testing", "table")
            .add(null, "id", PropertyTypeKind.LONG, Attribute.PRIMARY_KEY)
            .add(null, "value", new StringType(255))
            .toDescription();

View Full Code Here

     * 単純なモデルのテスト。
     * @throws Throwable 例外が発生した場合
     */
    @Test
    public void simple() throws Throwable {
        TableModelDescription model = new TableModelBuilder("Model")
            .add(null, "id", PropertyTypeKind.LONG, Attribute.PRIMARY_KEY)
            .toDescription();

        new Table().emit(model);
        new TsvIn().emit(model);
View Full Code Here

TOP

Related Classes of com.asakusafw.modelgen.util.TableModelBuilder$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.