Search in sources :

Example 1 with BasketType

use of ch.interlis.ili2c.metamodel.BasketType 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)

Aggregations

DbColBlob (ch.ehi.sqlgen.repository.DbColBlob)1 DbColBoolean (ch.ehi.sqlgen.repository.DbColBoolean)1 DbColDate (ch.ehi.sqlgen.repository.DbColDate)1 DbColDateTime (ch.ehi.sqlgen.repository.DbColDateTime)1 DbColDecimal (ch.ehi.sqlgen.repository.DbColDecimal)1 DbColId (ch.ehi.sqlgen.repository.DbColId)1 DbColNumber (ch.ehi.sqlgen.repository.DbColNumber)1 DbColTime (ch.ehi.sqlgen.repository.DbColTime)1 DbColUuid (ch.ehi.sqlgen.repository.DbColUuid)1 DbColVarchar (ch.ehi.sqlgen.repository.DbColVarchar)1 DbColXml (ch.ehi.sqlgen.repository.DbColXml)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 PrecisionDecimal (ch.interlis.ili2c.metamodel.PrecisionDecimal)1 TextType (ch.interlis.ili2c.metamodel.TextType)1 UniquenessConstraint (ch.interlis.ili2c.metamodel.UniquenessConstraint)1