Search in sources :

Example 1 with DbColDateTime

use of ch.ehi.sqlgen.repository.DbColDateTime in project ili2db by claeis.

the class FromIliRecordConverter method createSimpleDbCol.

private boolean createSimpleDbCol(DbTable dbTable, Viewable aclass, AttributeDef attr, Type type, Holder<DbColumn> dbCol, Holder<Unit> unitDef, Holder<Boolean> mText, ArrayList<DbColumn> dbColExts) {
    if (attr.isDomainBoolean()) {
        dbCol.value = new DbColBoolean();
    } else if (attr.isDomainIli1Date()) {
        dbCol.value = new DbColDate();
    } else if (attr.isDomainIliUuid()) {
        dbCol.value = new DbColUuid();
    } else if (attr.isDomainIli2Date()) {
        dbCol.value = new DbColDate();
    } else if (attr.isDomainIli2DateTime()) {
        dbCol.value = new DbColDateTime();
    } else if (attr.isDomainIli2Time()) {
        dbCol.value = new DbColTime();
    } else if (type instanceof BasketType) {
        // skip it; type no longer exists in ili 2.3
        dbCol.value = null;
    } else if (type instanceof EnumerationType) {
        visitedEnumsAttrs.add(attr);
        if (createEnumColAsItfCode) {
            DbColId ret = new DbColId();
            dbCol.value = ret;
        } else {
            DbColVarchar ret = new DbColVarchar();
            ret.setSize(255);
            dbCol.value = ret;
        }
    } else if (type instanceof NumericType) {
        if (type.isAbstract()) {
        } else {
            PrecisionDecimal min = ((NumericType) type).getMinimum();
            PrecisionDecimal max = ((NumericType) type).getMaximum();
            int minLen = min.toString().length();
            int maxLen = max.toString().length();
            if (min.toString().startsWith("-")) {
                minLen -= 1;
            }
            if (max.toString().startsWith("-")) {
                maxLen -= 1;
            }
            if (min.getAccuracy() > 0) {
                DbColDecimal ret = new DbColDecimal();
                int size = Math.max(minLen, maxLen) - 1;
                int precision = min.getAccuracy();
                // EhiLogger.debug("attr "+ attr.getName()+", maxStr <"+maxStr+">, size "+Integer.toString(size)+", precision "+Integer.toString(precision));
                ret.setSize(size);
                ret.setPrecision(precision);
                if (createNumCheck) {
                    ret.setMinValue(min.doubleValue());
                    ret.setMaxValue(max.doubleValue());
                }
                dbCol.value = ret;
            } else {
                DbColNumber ret = new DbColNumber();
                int size = Math.max(minLen, maxLen);
                ret.setSize(size);
                if (createNumCheck) {
                    ret.setMinValue((int) min.doubleValue());
                    ret.setMaxValue((int) max.doubleValue());
                }
                dbCol.value = ret;
            }
            unitDef.value = ((NumericType) type).getUnit();
        }
    } else if (type instanceof TextType) {
        DbColVarchar ret = new DbColVarchar();
        if (((TextType) type).getMaxLength() > 0) {
            ret.setSize(((TextType) type).getMaxLength());
        } else {
            ret.setSize(DbColVarchar.UNLIMITED);
        }
        if (!((TextType) type).isNormalized()) {
            mText.value = true;
        }
        dbCol.value = ret;
    } else if (type instanceof BlackboxType) {
        if (((BlackboxType) type).getKind() == BlackboxType.eXML) {
            DbColXml ret = new DbColXml();
            dbCol.value = ret;
        } else {
            DbColBlob ret = new DbColBlob();
            dbCol.value = ret;
        }
    } else {
        return false;
    }
    return true;
}
Also used : NumericType(ch.interlis.ili2c.metamodel.NumericType) DbColXml(ch.ehi.sqlgen.repository.DbColXml) DbColBlob(ch.ehi.sqlgen.repository.DbColBlob) BasketType(ch.interlis.ili2c.metamodel.BasketType) BlackboxType(ch.interlis.ili2c.metamodel.BlackboxType) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) DbColVarchar(ch.ehi.sqlgen.repository.DbColVarchar) DbColTime(ch.ehi.sqlgen.repository.DbColTime) DbColDecimal(ch.ehi.sqlgen.repository.DbColDecimal) DbColDateTime(ch.ehi.sqlgen.repository.DbColDateTime) DbColNumber(ch.ehi.sqlgen.repository.DbColNumber) DbColDate(ch.ehi.sqlgen.repository.DbColDate) UniquenessConstraint(ch.interlis.ili2c.metamodel.UniquenessConstraint) TextType(ch.interlis.ili2c.metamodel.TextType) PrecisionDecimal(ch.interlis.ili2c.metamodel.PrecisionDecimal) DbColBoolean(ch.ehi.sqlgen.repository.DbColBoolean) DbColUuid(ch.ehi.sqlgen.repository.DbColUuid) DbColId(ch.ehi.sqlgen.repository.DbColId)

Example 2 with DbColDateTime

use of ch.ehi.sqlgen.repository.DbColDateTime in project ili2db by claeis.

the class GeneratorMsSql method visitColumn.

@Override
public void visitColumn(DbTable dbTab, DbColumn column) throws IOException {
    String type = "";
    if (column instanceof DbColBoolean) {
        type = "BIT";
    } else if (column instanceof DbColDateTime) {
        type = "DATETIME";
    } else if (column instanceof DbColDate) {
        type = "DATE";
    } else if (column instanceof DbColTime) {
        type = "TIME";
    } else if (column instanceof DbColDecimal) {
        DbColDecimal col = (DbColDecimal) column;
        type = "DECIMAL(" + Integer.toString(col.getSize()) + "," + Integer.toString(col.getPrecision()) + ")";
    } else if (column instanceof DbColGeometry) {
        type = "GEOMETRY";
    } else if (column instanceof DbColId) {
        type = "BIGINT";
    } else if (column instanceof DbColUuid) {
        type = "VARCHAR(36)";
    } else if (column instanceof DbColNumber) {
        DbColNumber col = (DbColNumber) column;
        type = "NUMERIC(" + Integer.toString(col.getSize()) + ")";
    } else if (column instanceof DbColVarchar) {
        int colsize = ((DbColVarchar) column).getSize();
        if (colsize != DbColVarchar.UNLIMITED)
            type = "VARCHAR(" + Integer.toString(colsize) + ")";
        else
            type = "VARCHAR(MAX)";
    } else {
        type = "VARCHAR(MAX)";
    }
    String isNull = column.isNotNull() ? "NOT NULL" : "NULL";
    if (column.isPrimaryKey()) {
        isNull = "PRIMARY KEY";
    }
    String sep = " ";
    String defaultValue = "";
    if (column.getDefaultValue() != null) {
        defaultValue = sep + "DEFAULT (" + column.getDefaultValue() + ")";
        sep = " ";
    }
    String name = column.getName();
    out.write(getIndent() + colSep + "[" + name + "] " + type + " " + isNull + defaultValue + newline());
    colSep = ",";
}
Also used : DbColBoolean(ch.ehi.sqlgen.repository.DbColBoolean) DbColGeometry(ch.ehi.sqlgen.repository.DbColGeometry) DbColVarchar(ch.ehi.sqlgen.repository.DbColVarchar) DbColTime(ch.ehi.sqlgen.repository.DbColTime) DbColDecimal(ch.ehi.sqlgen.repository.DbColDecimal) DbColDateTime(ch.ehi.sqlgen.repository.DbColDateTime) DbColId(ch.ehi.sqlgen.repository.DbColId) DbColUuid(ch.ehi.sqlgen.repository.DbColUuid) DbColNumber(ch.ehi.sqlgen.repository.DbColNumber) DbColDate(ch.ehi.sqlgen.repository.DbColDate)

Example 3 with DbColDateTime

use of ch.ehi.sqlgen.repository.DbColDateTime in project ili2db by claeis.

the class TransferFromIli method addModelsTable.

public static void addModelsTable(DbSchema schema, Settings config) {
    DbTable tab = new DbTable();
    tab.setName(new DbTableName(schema.getName(), DbNames.MODELS_TAB));
    DbColVarchar fileCol = new DbColVarchar();
    fileCol.setName(DbNames.MODELS_TAB_FILE_COL);
    fileCol.setNotNull(true);
    fileCol.setSize(250);
    tab.addColumn(fileCol);
    DbColVarchar iliversionCol = new DbColVarchar();
    iliversionCol.setName(DbNames.MODELS_TAB_ILIVERSION_COL);
    iliversionCol.setNotNull(true);
    iliversionCol.setSize(3);
    tab.addColumn(iliversionCol);
    DbColVarchar importsCol = new DbColVarchar();
    importsCol.setName(DbNames.MODELS_TAB_MODELNAME_COL);
    importsCol.setNotNull(true);
    int modelNameColSize = DbColVarchar.UNLIMITED;
    String modelNameColSizeStr = config.getValue(Config.MODELS_TAB_MODELNAME_COLSIZE);
    if (modelNameColSizeStr != null) {
        try {
            modelNameColSize = Integer.parseInt(modelNameColSizeStr);
        } catch (NumberFormatException e) {
        }
    }
    importsCol.setSize(modelNameColSize);
    tab.addColumn(importsCol);
    DbColVarchar contentCol = new DbColVarchar();
    contentCol.setName(DbNames.MODELS_TAB_CONTENT_COL);
    contentCol.setNotNull(true);
    contentCol.setSize(DbColVarchar.UNLIMITED);
    tab.addColumn(contentCol);
    DbColDateTime importDateCol = new DbColDateTime();
    importDateCol.setName(DbNames.MODELS_TAB_IMPORTDATE_COL);
    importDateCol.setNotNull(true);
    tab.addColumn(importDateCol);
    DbIndex pk = new DbIndex();
    pk.setPrimary(true);
    pk.addAttr(importsCol);
    pk.addAttr(iliversionCol);
    tab.addIndex(pk);
    schema.addTable(tab);
}
Also used : DbColVarchar(ch.ehi.sqlgen.repository.DbColVarchar) DbColDateTime(ch.ehi.sqlgen.repository.DbColDateTime) DbTableName(ch.ehi.sqlgen.repository.DbTableName) DbIndex(ch.ehi.sqlgen.repository.DbIndex) DbTable(ch.ehi.sqlgen.repository.DbTable)

Example 4 with DbColDateTime

use of ch.ehi.sqlgen.repository.DbColDateTime in project ili2db by claeis.

the class AbstractRecordConverter method addStdCol.

public static void addStdCol(DbTable table) {
    DbColumn dbCol = new DbColDateTime();
    dbCol.setName(DbNames.T_LAST_CHANGE_COL);
    dbCol.setNotNull(true);
    table.addColumn(dbCol);
    dbCol = new DbColDateTime();
    dbCol.setName(DbNames.T_CREATE_DATE_COL);
    dbCol.setNotNull(true);
    table.addColumn(dbCol);
    DbColVarchar dbColUsr = new DbColVarchar();
    dbColUsr.setName(DbNames.T_USER_COL);
    dbColUsr.setNotNull(true);
    dbColUsr.setSize(40);
    table.addColumn(dbColUsr);
}
Also used : DbColumn(ch.ehi.sqlgen.repository.DbColumn) DbColVarchar(ch.ehi.sqlgen.repository.DbColVarchar) DbColDateTime(ch.ehi.sqlgen.repository.DbColDateTime)

Aggregations

DbColDateTime (ch.ehi.sqlgen.repository.DbColDateTime)4 DbColVarchar (ch.ehi.sqlgen.repository.DbColVarchar)4 DbColBoolean (ch.ehi.sqlgen.repository.DbColBoolean)2 DbColDate (ch.ehi.sqlgen.repository.DbColDate)2 DbColDecimal (ch.ehi.sqlgen.repository.DbColDecimal)2 DbColId (ch.ehi.sqlgen.repository.DbColId)2 DbColNumber (ch.ehi.sqlgen.repository.DbColNumber)2 DbColTime (ch.ehi.sqlgen.repository.DbColTime)2 DbColUuid (ch.ehi.sqlgen.repository.DbColUuid)2 DbColBlob (ch.ehi.sqlgen.repository.DbColBlob)1 DbColGeometry (ch.ehi.sqlgen.repository.DbColGeometry)1 DbColXml (ch.ehi.sqlgen.repository.DbColXml)1 DbColumn (ch.ehi.sqlgen.repository.DbColumn)1 DbIndex (ch.ehi.sqlgen.repository.DbIndex)1 DbTable (ch.ehi.sqlgen.repository.DbTable)1 DbTableName (ch.ehi.sqlgen.repository.DbTableName)1 BasketType (ch.interlis.ili2c.metamodel.BasketType)1 BlackboxType (ch.interlis.ili2c.metamodel.BlackboxType)1 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)1 NumericType (ch.interlis.ili2c.metamodel.NumericType)1