Search in sources :

Example 31 with Column$

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$ForeignKeyUnary.Column$ in project jaxdb by jaxdb.

the class SQLiteDecompiler method makeColumn.

@Override
$Column makeColumn(final String columnName, final String typeName, final long size, final int decimalDigits, final String _default, final Boolean nullable, final Boolean autoIncrement) {
    final $Column column;
    if (typeName.startsWith("BIGINT")) {
        final $Bigint type = newColumn($Bigint.class);
        if (size != 2000000000)
            type.setPrecision$(new $Bigint.Precision$((byte) size));
        if (_default != null)
            type.setDefault$(new $Bigint.Default$(Long.valueOf(_default)));
        if (autoIncrement != null && autoIncrement)
            type.setGenerateOnInsert$(new $Bigint.GenerateOnInsert$($Integer.GenerateOnInsert$.AUTO_5FINCREMENT));
        column = type;
    } else if (typeName.startsWith("BINARY")) {
        final $Binary type = newColumn($Binary.class);
        final Long length = getLength(typeName);
        if (length != null)
            type.setLength$(new $Binary.Length$(length));
        column = type;
    } else if (typeName.startsWith("BLOB")) {
        final $Blob type = newColumn($Blob.class);
        final Long length = getLength(typeName);
        if (length != null)
            type.setLength$(new $Blob.Length$(length));
        column = type;
    } else if ("BOOLEAN".equals(typeName)) {
        final $Boolean type = newColumn($Boolean.class);
        if (_default != null)
            type.setDefault$(new $Boolean.Default$(Boolean.parseBoolean(_default)));
        column = type;
    } else if (typeName.startsWith("VARCHAR") || typeName.startsWith("CHARACTER")) {
        final $Char type = newColumn($Char.class);
        if (typeName.startsWith("VARCHAR"))
            type.setVarying$(new $Char.Varying$(true));
        final Long length = getLength(typeName);
        if (length != null)
            type.setLength$(new $Char.Length$(length));
        if (_default != null)
            type.setDefault$(new $Char.Default$(_default.substring(1, _default.length() - 1)));
        column = type;
    } else if (typeName.startsWith("TEXT")) {
        final $Clob type = newColumn($Clob.class);
        final Long length = getLength(typeName);
        if (length != null)
            type.setLength$(new $Clob.Length$(length));
        column = type;
    } else if ("DATE".equals(typeName)) {
        final $Date type = newColumn($Date.class);
        if (_default != null)
            type.setDefault$(new $Date.Default$(_default.substring(1, _default.length() - 1)));
        column = type;
    } else if ("DATETIME".equals(typeName)) {
        final $Datetime type = newColumn($Datetime.class);
        if (size != 2000000000)
            type.setPrecision$(new $Datetime.Precision$((byte) size));
        if (_default != null)
            type.setDefault$(new $Datetime.Default$(_default.substring(1, _default.length() - 1)));
        column = type;
    } else if (typeName.startsWith("DECIMAL")) {
        final $Decimal type = newColumn($Decimal.class);
        if (!"DECIMAL(15,0)".equals(typeName)) {
            final int open = typeName.indexOf('(');
            if (open > 0) {
                final int comma = typeName.indexOf(',', open + 1);
                if (comma > open) {
                    final int close = typeName.indexOf(')', comma + 1);
                    if (close > comma) {
                        type.setPrecision$(new $Decimal.Precision$(Integer.valueOf(typeName.substring(open + 1, comma).trim())));
                        type.setScale$(new $Decimal.Scale$(Integer.valueOf(typeName.substring(comma + 1, close).trim())));
                    }
                }
            }
        }
        if (_default != null)
            type.setDefault$(new $Decimal.Default$(new BigDecimal(_default)));
        column = type;
    } else if ("DOUBLE".equals(typeName)) {
        final $Double type = newColumn($Double.class);
        if (_default != null)
            type.setDefault$(new $Double.Default$(Double.valueOf(_default)));
        column = type;
    } else // }
    if ("FLOAT".equals(typeName)) {
        final $Float type = newColumn($Float.class);
        if (_default != null)
            type.setDefault$(new $Float.Default$(Float.valueOf(_default)));
        column = type;
    } else if (typeName.startsWith("INT") || typeName.startsWith("MEDIUMINT")) {
        final $Int type = newColumn($Int.class);
        if (size != 2000000000)
            type.setPrecision$(new $Int.Precision$((byte) size));
        if (_default != null)
            type.setDefault$(new $Int.Default$(Integer.valueOf(_default)));
        if ("INTEGER".equals(typeName))
            type.setGenerateOnInsert$(new $Int.GenerateOnInsert$($Integer.GenerateOnInsert$.AUTO_5FINCREMENT));
        column = type;
    } else if ("SMALLINT".equals(typeName)) {
        final $Smallint type = newColumn($Smallint.class);
        if (size != 2000000000)
            type.setPrecision$(new $Smallint.Precision$((byte) size));
        if (_default != null)
            type.setDefault$(new $Smallint.Default$(Short.valueOf(_default)));
        if (autoIncrement != null && autoIncrement)
            type.setGenerateOnInsert$(new $Smallint.GenerateOnInsert$($Integer.GenerateOnInsert$.AUTO_5FINCREMENT));
        column = type;
    } else if ("TIME".equals(typeName)) {
        final $Time type = newColumn($Time.class);
        if (size != 2000000000)
            type.setPrecision$(new $Time.Precision$((byte) size));
        if (_default != null)
            type.setDefault$(new $Time.Default$(_default.substring(1, _default.length() - 1)));
        column = type;
    } else if ("TINYINT".equals(typeName)) {
        final $Tinyint type = newColumn($Tinyint.class);
        if (size != 2000000000)
            type.setPrecision$(new $Tinyint.Precision$((byte) size));
        if (_default != null)
            type.setDefault$(new $Tinyint.Default$(Byte.valueOf(_default)));
        if (autoIncrement != null && autoIncrement)
            type.setGenerateOnInsert$(new $Tinyint.GenerateOnInsert$($Integer.GenerateOnInsert$.AUTO_5FINCREMENT));
        column = type;
    } else {
        throw new UnsupportedOperationException("Unsupported column type: " + typeName);
    }
    column.setName$(new $Column.Name$(columnName));
    if (nullable != null && !nullable)
        column.setNull$(new $Column.Null$(false));
    return column;
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Datetime(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Datetime) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Date(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Date) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint) BigDecimal(java.math.BigDecimal) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Time(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Time) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary)

Example 32 with Column$

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$ForeignKeyUnary.Column$ in project jaxdb by jaxdb.

the class Generator method getTypes.

private Type[] getTypes(final Table table, final Map<String, Table> tableNameToTable, final int depth, final Info info) throws GeneratorExecutionException {
    final List<$Column> columns = table.getColumn();
    final int size = columns == null ? 0 : columns.size();
    final Type[] types;
    if (table.getExtends$() == null) {
        types = new Type[depth + size];
        info.rootClassName = schemaClassName + "." + Identifiers.toClassCase(table.getName$().text());
    } else {
        types = getTypes(tableNameToTable.get(table.getExtends$().text()), tableNameToTable, depth + size, info);
    }
    if (columns != null) {
        final boolean isSuperTable = depth != 0;
        info.totalPrimaryCount.inc(getPrimaryColumnCount(table), isSuperTable);
        for (int c = 1; c <= size; ++c) {
            final $Column column = columns.get(size - c);
            final Type type = getType(table, column);
            if (org.jaxdb.ddlx.Generator.isAuto(column))
                info.totalAutoCount.inc(1, isSuperTable);
            if (type.keyForUpdate)
                info.totalKeyForUpdateCount.inc(1, isSuperTable);
            types[types.length - depth - c] = type;
        }
    }
    return types;
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint)

Aggregations

org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)21 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)16 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint)16 ArrayList (java.util.ArrayList)13 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint)13 HashMap (java.util.HashMap)9 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer)9 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named)7 ResultSet (java.sql.ResultSet)6 List (java.util.List)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob)6