Search in sources :

Example 41 with Column

use of com.helger.genericode.v10.Column in project jaxdb by jaxdb.

the class OracleCompiler method dropTypes.

@Override
LinkedHashSet<DropStatement> dropTypes(final $Table table, final Map<String, Map<String, String>> tableNameToEnumToOwner) {
    final LinkedHashSet<DropStatement> statements = super.dropTypes(table, tableNameToEnumToOwner);
    if (table.getColumn() != null) {
        for (final $Column column : table.getColumn()) {
            if (column instanceof $Integer) {
                final $Integer type = ($Integer) column;
                if (Generator.isAuto(type)) {
                    statements.add(new DropStatement("BEGIN EXECUTE IMMEDIATE 'DROP SEQUENCE " + q(getSequenceName(table, type)) + "'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -2289 THEN RAISE; END IF; END;"));
                    statements.add(new DropStatement("BEGIN EXECUTE IMMEDIATE 'DROP TRIGGER " + q(getTriggerName(table, type)) + "'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -4080 THEN RAISE; END IF; END;"));
                }
            }
        }
    }
    return statements;
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)

Example 42 with Column

use of com.helger.genericode.v10.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 43 with Column

use of com.helger.genericode.v10.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)

Example 44 with Column

use of com.helger.genericode.v10.Column in project peppol-commons by phax.

the class MainCreateEnumsFromUBLGenericode method _createGenericode10.

private static void _createGenericode10(final File aFile, final CodeListDocument aCodeList10) throws JCodeModelException {
    final SimpleCodeList aSimpleCodeList = aCodeList10.getSimpleCodeList();
    if (aSimpleCodeList == null) {
        LOGGER.info("  does not contain a SimpleCodeList!");
        return;
    }
    final Column aColCode = Genericode10Helper.getColumnOfID(aCodeList10.getColumnSet(), COLID_CODE);
    if (aColCode == null) {
        LOGGER.info("  No '" + COLID_CODE + "' column found");
        return;
    }
    if (!Genericode10Helper.isKeyColumn(aCodeList10.getColumnSet(), COLID_CODE)) {
        LOGGER.info("  Column '" + COLID_CODE + "' is not a key");
        return;
    }
    final Column aColName = Genericode10Helper.getColumnOfID(aCodeList10.getColumnSet(), COLID_NAME);
    if (aColName == null) {
        LOGGER.info("  No '" + COLID_NAME + "' column found");
        return;
    }
    final JDefinedClass jEnum = CM._package("com.helger.peppol.codelist")._enum("E" + RegExHelper.getAsIdentifier(aCodeList10.getIdentification().getShortName().getValue()))._implements(CM.ref(IHasID.class).narrow(String.class))._implements(IHasDisplayName.class);
    jEnum.javadoc().add("This file is generated from Genericode file " + aFile.getName() + ". Do NOT edit!");
    for (final Row aRow : aCodeList10.getSimpleCodeList().getRow()) {
        final String sCode = Genericode10Helper.getRowValue(aRow, COLID_CODE);
        final String sName = Genericode10Helper.getRowValue(aRow, COLID_NAME);
        String sIdentifier = RegExHelper.getAsIdentifier(sName.toUpperCase(Locale.US));
        sIdentifier = StringHelper.replaceAllRepeatedly(sIdentifier, "__", "_");
        final JEnumConstant jEnumConst = jEnum.enumConstant(sIdentifier);
        jEnumConst.arg(JExpr.lit(sCode));
        jEnumConst.arg(JExpr.lit(sName));
    }
    // fields
    final JFieldVar fID = jEnum.field(JMod.PRIVATE | JMod.FINAL, String.class, "m_sID");
    final JFieldVar fDisplayName = jEnum.field(JMod.PRIVATE | JMod.FINAL, String.class, "m_sDisplayName");
    // Constructor
    final JMethod jCtor = jEnum.constructor(JMod.PRIVATE);
    JVar jID = jCtor.param(JMod.FINAL, String.class, "sID");
    jID.annotate(Nonnull.class);
    jID.annotate(Nonempty.class);
    final JVar jDisplayName = jCtor.param(JMod.FINAL, String.class, "sDisplayName");
    jDisplayName.annotate(Nonnull.class);
    jCtor.body().assign(fID, jID).assign(fDisplayName, jDisplayName);
    // public String getID ()
    JMethod m = jEnum.method(JMod.PUBLIC, String.class, "getID");
    m.annotate(Nonnull.class);
    m.annotate(Nonempty.class);
    m.body()._return(fID);
    // public String getDisplayName ()
    m = jEnum.method(JMod.PUBLIC, String.class, "getDisplayName");
    m.annotate(Nonnull.class);
    m.body()._return(fDisplayName);
    // public static E... getFromIDOrNull (@Nullable String sID)
    m = jEnum.method(JMod.PUBLIC | JMod.STATIC, jEnum, "getFromIDOrNull");
    m.annotate(Nullable.class);
    jID = m.param(JMod.FINAL, String.class, "sID");
    jID.annotate(Nullable.class);
    m.body()._return(CM.ref(EnumHelper.class).staticInvoke("getFromIDOrNull").arg(JExpr.dotClass(jEnum)).arg(jID));
    // public static String getDisplayNameFromIDOrNull (@Nullable String sID)
    m = jEnum.method(JMod.PUBLIC | JMod.STATIC, String.class, "getDisplayNameFromIDOrNull");
    m.annotate(Nullable.class);
    jID = m.param(JMod.FINAL, String.class, "sID");
    jID.annotate(Nullable.class);
    final JVar jValue = m.body().decl(JMod.FINAL, jEnum, "eValue", jEnum.staticInvoke("getFromIDOrNull").arg(jID));
    m.body()._return(JOp.cond(JOp.eq(jValue, JExpr._null()), JExpr._null(), jValue.invoke("getDisplayName")));
}
Also used : SimpleCodeList(com.helger.genericode.v10.SimpleCodeList) JEnumConstant(com.helger.jcodemodel.JEnumConstant) Column(com.helger.genericode.v10.Column) JDefinedClass(com.helger.jcodemodel.JDefinedClass) JFieldVar(com.helger.jcodemodel.JFieldVar) IHasID(com.helger.commons.id.IHasID) Row(com.helger.genericode.v10.Row) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 45 with Column

use of com.helger.genericode.v10.Column in project SpinalTap by airbnb.

the class Table method toThriftTable.

public static com.airbnb.jitney.event.spinaltap.v1.Table toThriftTable(Table table) {
    Set<String> primaryKey = ImmutableSet.of();
    if (table.getPrimaryKey().isPresent()) {
        primaryKey = ImmutableSet.copyOf(table.getPrimaryKey().get().getColumns().values().stream().map(ColumnMetadata::getName).sorted().collect(Collectors.toList()));
    }
    Map<String, Column> columns = table.getColumns().values().stream().map(c -> {
        com.airbnb.jitney.event.spinaltap.v1.Column column = new com.airbnb.jitney.event.spinaltap.v1.Column(c.getColType().getCode(), c.isPrimaryKey(), c.getName());
        column.setPosition(c.getPosition());
        return column;
    }).collect(Collectors.toMap(c -> c.getName(), c -> c));
    com.airbnb.jitney.event.spinaltap.v1.Table thriftTable = new com.airbnb.jitney.event.spinaltap.v1.Table(table.getId(), table.getName(), table.getDatabase(), primaryKey, columns);
    if (!Strings.isNullOrEmpty(table.getOverridingDatabase())) {
        thriftTable.setOverridingDatabase(table.getOverridingDatabase());
    }
    return thriftTable;
}
Also used : Column(com.airbnb.jitney.event.spinaltap.v1.Column) ImmutableSet(com.google.common.collect.ImmutableSet) Getter(lombok.Getter) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Value(lombok.Value) Strings(com.google.common.base.Strings) List(java.util.List) Optional(com.google.common.base.Optional) Map(java.util.Map) Splitter(com.google.common.base.Splitter) Column(com.airbnb.jitney.event.spinaltap.v1.Column) Column(com.airbnb.jitney.event.spinaltap.v1.Column)

Aggregations

org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)21 ArrayList (java.util.ArrayList)17 HashMap (java.util.HashMap)11 Column (org.molgenis.emx2.Column)11 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)10 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint)10 Column (com.google.bigtable.v2.Column)9 List (java.util.List)9 Family (com.google.bigtable.v2.Family)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint)8 Test (org.junit.Test)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table)7 MolgenisException (org.molgenis.emx2.MolgenisException)6 Map (java.util.Map)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer)4 SqlColumnExecutor.validateColumn (org.molgenis.emx2.sql.SqlColumnExecutor.validateColumn)4 Cell (com.google.bigtable.v2.Cell)3 ResultSet (java.sql.ResultSet)3 ExecutionException (java.util.concurrent.ExecutionException)3