use of ch.ehi.sqlgen.repository.DbColGeometry in project ili2db by claeis.
the class FromIliRecordConverter method generateAttr.
public void generateAttr(DbTable dbTable, Viewable aclass, AttributeDef attr) throws Ili2dbException {
Holder<DbColumn> dbCol = new Holder<DbColumn>();
dbCol.value = null;
Holder<Unit> unitDef = new Holder<Unit>();
unitDef.value = null;
Holder<Boolean> mText = new Holder<Boolean>();
mText.value = false;
ArrayList<DbColumn> dbColExts = new ArrayList<DbColumn>();
Type type = attr.getDomainResolvingAll();
if (createSimpleDbCol(dbTable, aclass, attr, type, dbCol, unitDef, mText, dbColExts)) {
} else if (type instanceof SurfaceOrAreaType) {
if (createItfLineTables) {
dbCol.value = null;
} else {
DbColGeometry ret = new DbColGeometry();
boolean curvePolygon = false;
if (!strokeArcs) {
curvePolygon = true;
}
ret.setType(curvePolygon ? DbColGeometry.CURVEPOLYGON : DbColGeometry.POLYGON);
// get crs from ili
setCrs(ret, attr);
CoordType coord = (CoordType) ((SurfaceOrAreaType) type).getControlPointDomain().getType();
ret.setDimension(coord.getDimensions().length);
setBB(ret, coord, attr.getContainer().getScopedName(null) + "." + attr.getName());
dbCol.value = ret;
}
if (createItfAreaRef) {
if (type instanceof AreaType) {
DbColGeometry ret = new DbColGeometry();
String sqlName = getSqlAttrName(attr, dbTable.getName().getName(), null) + DbNames.ITF_MAINTABLE_GEOTABLEREF_COL_SUFFIX;
ret.setName(sqlName);
ret.setType(DbColGeometry.POINT);
setNullable(aclass, attr, ret);
// get crs from ili
setCrs(ret, attr);
// always 2 (even if defined as 3d in ili)
ret.setDimension(2);
CoordType coord = (CoordType) ((SurfaceOrAreaType) type).getControlPointDomain().getType();
setBB(ret, coord, attr.getContainer().getScopedName(null) + "." + attr.getName());
dbColExts.add(ret);
}
}
} else if (type instanceof PolylineType) {
String attrName = attr.getContainer().getScopedName(null) + "." + attr.getName();
DbColGeometry ret = generatePolylineType((PolylineType) type, attrName);
setCrs(ret, attr);
dbCol.value = ret;
} else if (type instanceof CoordType) {
DbColGeometry ret = new DbColGeometry();
ret.setType(DbColGeometry.POINT);
// get crs from ili
setCrs(ret, attr);
CoordType coord = (CoordType) type;
ret.setDimension(coord.getDimensions().length);
setBB(ret, coord, attr.getContainer().getScopedName(null) + "." + attr.getName());
dbCol.value = ret;
} else if (type instanceof CompositionType) {
// skip it
if (!createGenericStructRef) {
if (isChbaseCatalogueRef(td, attr) && (coalesceCatalogueRef || TrafoConfigNames.CATALOGUE_REF_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.CATALOGUE_REF_TRAFO)))) {
DbColId ret = new DbColId();
ret.setNotNull(false);
ret.setPrimaryKey(false);
if (createFk) {
ret.setReferencedTable(getSqlType(((ReferenceType) ((AttributeDef) ((CompositionType) type).getComponentType().getAttributes().next()).getDomain()).getReferred()));
}
if (createFkIdx) {
ret.setIndex(true);
}
trafoConfig.setAttrConfig(attr, TrafoConfigNames.CATALOGUE_REF_TRAFO, TrafoConfigNames.CATALOGUE_REF_TRAFO_COALESCE);
dbCol.value = ret;
} else if (Ili2cUtility.isMultiSurfaceAttr(td, attr) && (coalesceMultiSurface || TrafoConfigNames.MULTISURFACE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTISURFACE_TRAFO)))) {
multiSurfaceAttrs.addMultiSurfaceAttr(attr);
MultiSurfaceMapping attrMapping = multiSurfaceAttrs.getMapping(attr);
DbColGeometry ret = new DbColGeometry();
boolean curvePolygon = false;
if (!strokeArcs) {
curvePolygon = true;
}
ret.setType(curvePolygon ? DbColGeometry.MULTISURFACE : DbColGeometry.MULTIPOLYGON);
// get crs from ili
AttributeDef surfaceAttr = (AttributeDef) ((CompositionType) ((AttributeDef) ((CompositionType) type).getComponentType().getElement(AttributeDef.class, attrMapping.getBagOfSurfacesAttrName())).getDomain()).getComponentType().getElement(AttributeDef.class, attrMapping.getSurfaceAttrName());
setCrs(ret, surfaceAttr);
SurfaceType surface = ((SurfaceType) surfaceAttr.getDomainResolvingAliases());
CoordType coord = (CoordType) surface.getControlPointDomain().getType();
ret.setDimension(coord.getDimensions().length);
setBB(ret, coord, attr.getContainer().getScopedName(null) + "." + attr.getName());
dbCol.value = ret;
trafoConfig.setAttrConfig(attr, TrafoConfigNames.MULTISURFACE_TRAFO, TrafoConfigNames.MULTISURFACE_TRAFO_COALESCE);
} else if (Ili2cUtility.isMultiLineAttr(td, attr) && (coalesceMultiLine || TrafoConfigNames.MULTILINE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINE_TRAFO)))) {
multiLineAttrs.addMultiLineAttr(attr);
MultiLineMapping attrMapping = multiLineAttrs.getMapping(attr);
DbColGeometry ret = new DbColGeometry();
boolean curvePolyline = false;
if (!strokeArcs) {
curvePolyline = true;
}
ret.setType(curvePolyline ? DbColGeometry.MULTICURVE : DbColGeometry.MULTILINESTRING);
// get crs from ili
AttributeDef polylineAttr = (AttributeDef) ((CompositionType) ((AttributeDef) ((CompositionType) type).getComponentType().getElement(AttributeDef.class, attrMapping.getBagOfLinesAttrName())).getDomain()).getComponentType().getElement(AttributeDef.class, attrMapping.getLineAttrName());
setCrs(ret, polylineAttr);
PolylineType polylineType = ((PolylineType) polylineAttr.getDomainResolvingAliases());
CoordType coord = (CoordType) polylineType.getControlPointDomain().getType();
ret.setDimension(coord.getDimensions().length);
setBB(ret, coord, attr.getContainer().getScopedName(null) + "." + attr.getName());
dbCol.value = ret;
trafoConfig.setAttrConfig(attr, TrafoConfigNames.MULTILINE_TRAFO, TrafoConfigNames.MULTILINE_TRAFO_COALESCE);
} else if (Ili2cUtility.isMultiPointAttr(td, attr) && (coalesceMultiPoint || TrafoConfigNames.MULTIPOINT_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTIPOINT_TRAFO)))) {
multiPointAttrs.addMultiPointAttr(attr);
MultiPointMapping attrMapping = multiPointAttrs.getMapping(attr);
DbColGeometry ret = new DbColGeometry();
ret.setType(DbColGeometry.MULTIPOINT);
// get crs from ili
AttributeDef coordAttr = (AttributeDef) ((CompositionType) ((AttributeDef) ((CompositionType) type).getComponentType().getElement(AttributeDef.class, attrMapping.getBagOfPointsAttrName())).getDomain()).getComponentType().getElement(AttributeDef.class, attrMapping.getPointAttrName());
setCrs(ret, coordAttr);
CoordType coord = (CoordType) (coordAttr.getDomainResolvingAliases());
ret.setDimension(coord.getDimensions().length);
setBB(ret, coord, attr.getContainer().getScopedName(null) + "." + attr.getName());
dbCol.value = ret;
trafoConfig.setAttrConfig(attr, TrafoConfigNames.MULTIPOINT_TRAFO, TrafoConfigNames.MULTIPOINT_TRAFO_COALESCE);
} else if (Ili2cUtility.isArrayAttr(td, attr) && (coalesceArray || TrafoConfigNames.ARRAY_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.ARRAY_TRAFO)))) {
arrayAttrs.addArrayAttr(attr);
ArrayMapping attrMapping = arrayAttrs.getMapping(attr);
AttributeDef localAttr = attrMapping.getValueAttr();
Type localType = localAttr.getDomainResolvingAll();
if (!createSimpleDbCol(dbTable, aclass, localAttr, localType, dbCol, unitDef, mText, dbColExts)) {
throw new IllegalStateException("unexpected attr type " + localAttr.getScopedName());
}
dbCol.value.setArraySize(DbColumn.UNLIMITED_ARRAY);
trafoConfig.setAttrConfig(attr, TrafoConfigNames.ARRAY_TRAFO, TrafoConfigNames.ARRAY_TRAFO_COALESCE);
} else if (isChbaseMultilingual(td, attr) && (expandMultilingual || TrafoConfigNames.MULTILINGUAL_TRAFO_EXPAND.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINGUAL_TRAFO)))) {
for (String sfx : DbNames.MULTILINGUAL_TXT_COL_SUFFIXS) {
DbColVarchar ret = new DbColVarchar();
ret.setName(getSqlAttrName(attr, dbTable.getName().getName(), null) + sfx);
ret.setSize(DbColVarchar.UNLIMITED);
ret.setNotNull(false);
ret.setPrimaryKey(false);
dbColExts.add(ret);
}
trafoConfig.setAttrConfig(attr, TrafoConfigNames.MULTILINGUAL_TRAFO, TrafoConfigNames.MULTILINGUAL_TRAFO_EXPAND);
} else {
// add reference col from struct ele to parent obj to struct table
addParentRef(aclass, attr);
dbCol.value = null;
}
} else {
dbCol.value = null;
}
} else if (type instanceof ReferenceType) {
ArrayList<ViewableWrapper> targetTables = getTargetTables(((ReferenceType) type).getReferred());
for (ViewableWrapper targetTable : targetTables) {
DbColId ret = new DbColId();
ret.setName(ili2sqlName.mapIliAttributeDef(attr, dbTable.getName().getName(), targetTable.getSqlTablename(), targetTables.size() > 1));
ret.setNotNull(false);
ret.setPrimaryKey(false);
if (createFk) {
ret.setReferencedTable(targetTable.getSqlTable());
}
if (createFkIdx) {
ret.setIndex(true);
}
dbColExts.add(ret);
}
} else {
DbColVarchar ret = new DbColVarchar();
ret.setSize(255);
dbCol.value = ret;
}
if (type instanceof EnumerationType) {
if (createEnumTxtCol) {
DbColVarchar ret = new DbColVarchar();
ret.setSize(255);
ret.setName(getSqlAttrName(attr, dbTable.getName().getName(), null) + DbNames.ENUM_TXT_COL_SUFFIX);
setNullable(aclass, attr, ret);
dbColExts.add(ret);
}
}
if (dbCol.value != null) {
String sqlColName = getSqlAttrName(attr, dbTable.getName().getName(), null);
setAttrDbColProps(aclass, attr, dbCol.value, sqlColName);
String subType = null;
Viewable attrClass = (Viewable) attr.getContainer();
if (attrClass != aclass && attrClass.isExtending(aclass)) {
subType = getSqlType(attrClass).getName();
}
if (unitDef.value != null) {
String unitName = unitDef.value.getName();
metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_UNIT, unitName);
}
if (mText.value) {
metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_TEXTKIND, DbExtMetaInfo.TAG_COL_TEXTKIND_MTEXT);
}
if (dbCol.value instanceof DbColGeometry) {
metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_C1_MIN, Double.toString(((DbColGeometry) dbCol.value).getMin1()));
metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_C1_MAX, Double.toString(((DbColGeometry) dbCol.value).getMax1()));
metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_C2_MIN, Double.toString(((DbColGeometry) dbCol.value).getMin2()));
metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_C2_MAX, Double.toString(((DbColGeometry) dbCol.value).getMax2()));
if (((DbColGeometry) dbCol.value).getDimension() == 3) {
metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_C3_MIN, Double.toString(((DbColGeometry) dbCol.value).getMin3()));
metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_C3_MAX, Double.toString(((DbColGeometry) dbCol.value).getMax3()));
}
}
String dispName = attr.getMetaValues().getValue(IliMetaAttrNames.METAATTR_DISPNAME);
if (dispName != null) {
metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_DISPNAME, dispName);
}
customMapping.fixupAttribute(dbTable, dbCol.value, attr);
dbTable.addColumn(dbCol.value);
}
for (DbColumn dbColExt : dbColExts) {
customMapping.fixupAttribute(dbTable, dbColExt, attr);
dbTable.addColumn(dbColExt);
}
if (dbCol.value == null && dbColExts.size() == 0) {
customMapping.fixupAttribute(dbTable, null, attr);
}
}
use of ch.ehi.sqlgen.repository.DbColGeometry in project ili2db by claeis.
the class TransferFromIli method generateItfLineTable.
private void generateItfLineTable(AttributeDef attr, int pass) throws Ili2dbException {
if (pass == 1) {
DbTableName sqlName = getSqlTableNameItfLineTable(attr);
DbTable dbTable = new DbTable();
dbTable.setName(sqlName);
dbTable.setIliName(attr.getContainer().getScopedName(null) + "." + attr.getName());
schema.addTable(dbTable);
return;
}
// second pass; add columns
DbTableName sqlName = getSqlTableNameItfLineTable(attr);
DbTable dbTable = schema.findTable(sqlName);
StringBuffer cmt = new StringBuffer();
String cmtSep = "";
if (attr.getDocumentation() != null) {
cmt.append(cmtSep + attr.getDocumentation());
cmtSep = nl;
}
cmt.append(cmtSep + "@iliname " + attr.getContainer().getScopedName(null) + "." + attr.getName());
cmtSep = nl;
if (cmt.length() > 0) {
dbTable.setComment(cmt.toString());
}
if (deleteExistingData) {
dbTable.setDeleteDataIfTableExists(true);
}
dbTable.setRequiresSequence(true);
DbColId dbColId = recConv.addKeyCol(dbTable);
if (createIliTidCol) {
recConv.addIliTidCol(dbTable, null);
}
if (createBasketCol) {
// add basketCol
DbColId t_basket = new DbColId();
t_basket.setName(DbNames.T_BASKET_COL);
t_basket.setNotNull(true);
t_basket.setScriptComment("REFERENCES " + DbNames.BASKETS_TAB);
if (createFk) {
t_basket.setReferencedTable(new DbTableName(schema.getName(), DbNames.BASKETS_TAB));
}
if (createFkIdx) {
t_basket.setIndex(true);
}
dbTable.addColumn(t_basket);
}
if (createDatasetCol) {
DbColVarchar t_dsName = new DbColVarchar();
t_dsName.setName(DbNames.T_DATASET_COL);
t_dsName.setSize(DbNames.DATASETNAME_COL_SIZE);
t_dsName.setNotNull(true);
t_dsName.setIndex(true);
dbTable.addColumn(t_dsName);
}
SurfaceOrAreaType type = (SurfaceOrAreaType) attr.getDomainResolvingAll();
DbColGeometry dbCol = recConv.generatePolylineType(type, attr.getContainer().getScopedName(null) + "." + attr.getName());
recConv.setCrs(dbCol, attr);
dbCol.setName(ili2sqlName.getSqlColNameItfLineTableGeomAttr(attr, sqlName.getName()));
dbCol.setNotNull(true);
dbTable.addColumn(dbCol);
if (type instanceof SurfaceType) {
dbColId = new DbColId();
dbColId.setName(ili2sqlName.getSqlColNameItfLineTableRefAttr(attr, sqlName.getName()));
dbColId.setNotNull(true);
dbColId.setPrimaryKey(false);
dbColId.setScriptComment("REFERENCES " + recConv.getSqlType((Viewable) attr.getContainer()));
if (createFk) {
dbColId.setReferencedTable(recConv.getSqlType((Viewable) attr.getContainer()));
}
if (createFkIdx) {
dbColId.setIndex(true);
}
dbTable.addColumn(dbColId);
}
Table lineAttrTable = type.getLineAttributeStructure();
if (lineAttrTable != null) {
Iterator attri = lineAttrTable.getAttributes();
while (attri.hasNext()) {
AttributeDef lineattr = (AttributeDef) attri.next();
recConv.generateAttr(dbTable, lineAttrTable, lineattr);
}
}
if (createStdCols) {
AbstractRecordConverter.addStdCol(dbTable);
}
}
use of ch.ehi.sqlgen.repository.DbColGeometry 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 = ",";
}
use of ch.ehi.sqlgen.repository.DbColGeometry in project ili2db by claeis.
the class AbstractRecordConverter method generatePolylineType.
public DbColGeometry generatePolylineType(LineType type, String attrName) {
DbColGeometry ret = new DbColGeometry();
boolean compoundCurve = false;
if (!strokeArcs) {
compoundCurve = true;
}
ret.setType(compoundCurve ? DbColGeometry.COMPOUNDCURVE : DbColGeometry.LINESTRING);
Domain coordDomain = type.getControlPointDomain();
if (coordDomain != null) {
CoordType coord = (CoordType) coordDomain.getType();
ret.setDimension(coord.getDimensions().length);
setBB(ret, coord, attrName);
}
return ret;
}
Aggregations