use of ch.interlis.ili2c.metamodel.EnumerationType in project ili2db by claeis.
the class ReduceToBaseModel method translateAttrValue.
private void translateAttrValue(IomObject iomObj, AttributeDef srcAttr) {
String srcAttrName = srcAttr.getName();
int attrc = iomObj.getattrvaluecount(srcAttrName);
if (attrc == 0) {
return;
}
boolean isCompType = srcAttr.getDomain() instanceof CompositionType ? true : false;
boolean isEnumType = srcAttr.getDomainResolvingAliases() instanceof EnumerationType ? true : false;
EnumerationType srcEnumType = null;
if (isEnumType) {
srcEnumType = (EnumerationType) srcAttr.getDomainResolvingAliases();
}
AttributeDef destAttr = (AttributeDef) ((ViewableTransferElement) srctag2destElement.get(srcAttr.getScopedName())).obj;
for (int attri = 0; attri < attrc; attri++) {
String attrValue = iomObj.getattrprim(srcAttrName, attri);
if (attrValue != null) {
if (isEnumType) {
attrValue = translateEnumValue((String) attrValue, srcEnumType, (EnumerationType) destAttr.getDomainResolvingAliases());
iomObj.setattrvalue(srcAttrName, (String) attrValue);
}
} else {
IomObject structValue = iomObj.getattrobj(srcAttrName, attri);
if (isCompType) {
translateObject(structValue);
}
}
}
}
use of ch.interlis.ili2c.metamodel.EnumerationType in project ili2db by claeis.
the class GeodbGenerator method visit1Begin.
public void visit1Begin() throws IOException {
Iterator domainNamei = geodbDomains.keySet().iterator();
while (domainNamei.hasNext()) {
String domainName = (String) domainNamei.next();
Object ilidomaino = geodbDomains.get(domainName);
ch.interlis.ili2c.metamodel.Type type = null;
if (ilidomaino instanceof ch.interlis.ili2c.metamodel.Domain) {
type = ((ch.interlis.ili2c.metamodel.Domain) ilidomaino).getType();
} else if (ilidomaino instanceof ch.interlis.ili2c.metamodel.AttributeDef) {
type = ((ch.interlis.ili2c.metamodel.AttributeDef) ilidomaino).getDomain();
} else {
throw new IllegalArgumentException("domain!=AttributeDef && domain!=DomainDef");
}
if (type instanceof ch.interlis.ili2c.metamodel.EnumerationType) {
com.esri.arcgis.geodatabase.CodedValueDomain domain = new com.esri.arcgis.geodatabase.CodedValueDomain();
domain.setFieldType(esriFieldType.esriFieldTypeInteger);
java.util.ArrayList ev = new java.util.ArrayList();
buildEnumList(ev, "", ((EnumerationType) type).getConsolidatedEnumeration());
int itfCode = 0;
Iterator iter = ev.iterator();
while (iter.hasNext()) {
String value = (String) iter.next();
domain.addCode(/*code*/
itfCode, /*name*/
value);
itfCode++;
}
domain.setName(domainName);
domain.setSplitPolicy(com.esri.arcgis.geodatabase.esriSplitPolicyType.esriSPTDuplicate);
domain.setMergePolicy(com.esri.arcgis.geodatabase.esriMergePolicyType.esriMPTAreaWeighted);
wksp.addDomain(domain);
} else if (type instanceof ch.interlis.ili2c.metamodel.NumericType) {
PrecisionDecimal min = ((NumericType) type).getMinimum();
PrecisionDecimal max = ((NumericType) type).getMaximum();
com.esri.arcgis.geodatabase.RangeDomain domain = new com.esri.arcgis.geodatabase.RangeDomain();
if (min.getAccuracy() > 0) {
// double
domain.setMinValue(new Double(min.doubleValue()));
domain.setMaxValue(new Double(max.doubleValue()));
domain.setFieldType(esriFieldType.esriFieldTypeDouble);
} else {
// int
domain.setMinValue(new Integer((int) min.doubleValue()));
domain.setMaxValue(new Integer((int) max.doubleValue()));
domain.setFieldType(esriFieldType.esriFieldTypeInteger);
}
domain.setName(domainName);
domain.setSplitPolicy(com.esri.arcgis.geodatabase.esriSplitPolicyType.esriSPTDuplicate);
domain.setMergePolicy(com.esri.arcgis.geodatabase.esriMergePolicyType.esriMPTAreaWeighted);
wksp.addDomain(domain);
}
}
}
use of ch.interlis.ili2c.metamodel.EnumerationType in project ili2db by claeis.
the class PostgisColumnConverter method toIomArray.
@Override
public String[] toIomArray(ch.interlis.ili2c.metamodel.AttributeDef attr, Object sqlArray, EnumCodeMapper enumTypes) throws SQLException, ConverterException {
java.sql.Array array = (java.sql.Array) sqlArray;
String[] ret = null;
ch.interlis.ili2c.metamodel.Type type = attr.getDomainResolvingAliases();
if (attr.isDomainBoolean()) {
Boolean[] values = (Boolean[]) array.getArray();
ret = new String[values.length];
for (int i = 0; i < values.length; i++) {
if (values[i]) {
ret[i] = "true";
} else {
ret[i] = "false";
}
}
} else if (attr.isDomainIli1Date()) {
java.sql.Date[] values = (java.sql.Date[]) array.getArray();
ret = new String[values.length];
for (int i = 0; i < values.length; i++) {
java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyyMMdd");
GregorianCalendar date = new GregorianCalendar();
date.setGregorianChange(ToXtfRecordConverter.PURE_GREGORIAN_CALENDAR);
fmt.setCalendar(date);
ret[i] = fmt.format(values[i]);
}
} else if (attr.isDomainIliUuid()) {
java.util.UUID[] values = (java.util.UUID[]) array.getArray();
ret = new String[values.length];
for (int i = 0; i < values.length; i++) {
ret[i] = values[i].toString();
}
} else if (attr.isDomainIli2Date()) {
java.sql.Date[] values = (java.sql.Date[]) array.getArray();
ret = new String[values.length];
for (int i = 0; i < values.length; i++) {
java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyy-MM-dd");
GregorianCalendar date = new GregorianCalendar();
date.setGregorianChange(ToXtfRecordConverter.PURE_GREGORIAN_CALENDAR);
fmt.setCalendar(date);
ret[i] = fmt.format(values[i]);
}
} else if (attr.isDomainIli2DateTime()) {
java.sql.Timestamp[] values = (java.sql.Timestamp[]) array.getArray();
ret = new String[values.length];
for (int i = 0; i < values.length; i++) {
// with timezone: yyyy-MM-dd'T'HH:mm:ss.SSSZ
java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
GregorianCalendar date = new GregorianCalendar();
date.setGregorianChange(ToXtfRecordConverter.PURE_GREGORIAN_CALENDAR);
fmt.setCalendar(date);
ret[i] = fmt.format(values[i]);
}
} else if (attr.isDomainIli2Time()) {
java.sql.Time[] values = (java.sql.Time[]) array.getArray();
ret = new String[values.length];
for (int i = 0; i < values.length; i++) {
java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("HH:mm:ss.SSS");
ret[i] = fmt.format(values[i]);
}
} else if (type instanceof EnumerationType) {
if (createEnumColAsItfCode) {
Integer[] values = (Integer[]) array.getArray();
ret = new String[values.length];
for (int i = 0; i < values.length; i++) {
ret[i] = enumTypes.mapItfCode2XtfCode((EnumerationType) type, values[i].toString());
}
} else {
ret = ((String[]) array.getArray());
}
} else if (type instanceof NumericType) {
if (type.isAbstract()) {
} else {
PrecisionDecimal min = ((NumericType) type).getMinimum();
PrecisionDecimal max = ((NumericType) type).getMaximum();
if (min.getAccuracy() > 0) {
BigDecimal[] values = (BigDecimal[]) array.getArray();
ret = new String[values.length];
for (int i = 0; i < values.length; i++) {
ret[i] = values[i].toString();
}
} else {
Integer[] values = (Integer[]) array.getArray();
ret = new String[values.length];
for (int i = 0; i < values.length; i++) {
ret[i] = values[i].toString();
}
}
}
} else if (type instanceof TextType) {
ret = ((String[]) array.getArray());
} else if (type instanceof BlackboxType) {
if (((BlackboxType) type).getKind() == BlackboxType.eXML) {
Object[] values = (Object[]) array.getArray();
ret = new String[values.length];
for (int i = 0; i < values.length; i++) {
ret[i] = toIomXml(values[i]);
}
} else {
Object[] values = (Object[]) array.getArray();
ret = new String[values.length];
for (int i = 0; i < values.length; i++) {
ret[i] = toIomBlob(values[i]);
}
}
} else {
throw new IllegalArgumentException(attr.getScopedName());
}
return ret;
}
use of ch.interlis.ili2c.metamodel.EnumerationType in project ili2db by claeis.
the class TransferFromIli method updateSingleEnumTable.
public void updateSingleEnumTable(java.sql.Connection conn) throws Ili2dbException {
DbTableName tabName = new DbTableName(schema.getName(), DbNames.ENUM_TAB);
String sqlName = tabName.getName();
if (tabName.getSchema() != null) {
sqlName = tabName.getSchema() + "." + sqlName;
}
try {
// insert entries
String insStmt = "INSERT INTO " + sqlName + " (" + DbNames.ENUM_TAB_SEQ_COL + "," + DbNames.ENUM_TAB_ILICODE_COL + "," + DbNames.ENUM_TAB_ITFCODE_COL + "," + DbNames.ENUM_TAB_DISPNAME_COL + "," + DbNames.ENUM_TAB_INACTIVE_COL + "," + DbNames.ENUM_TAB_DESCRIPTION_COL + "," + DbNames.ENUM_TAB_THIS_COL + "," + DbNames.ENUM_TAB_BASE_COL + ") VALUES (?,?,?,?,?,?,?,?)";
EhiLogger.traceBackendCmd(insStmt);
java.sql.PreparedStatement insPrepStmt = conn.prepareStatement(insStmt);
String thisClass = null;
try {
addMissingEnumDomains(visitedEnums);
java.util.Iterator entri = visitedEnums.iterator();
while (entri.hasNext()) {
Object entro = entri.next();
if (entro instanceof AttributeDef) {
AttributeDef attr = (AttributeDef) entro;
if (attr.getDomain() instanceof ch.interlis.ili2c.metamodel.TypeAlias) {
continue;
}
EnumerationType type = (EnumerationType) attr.getDomainResolvingAll();
thisClass = attr.getContainer().getScopedName(null) + "." + attr.getName();
AttributeDef base = (AttributeDef) attr.getExtending();
String baseClass = null;
if (base != null) {
baseClass = base.getContainer().getScopedName(null) + "." + base.getName();
}
HashSet exstEntries = readEnumTable(conn, true, thisClass, tabName);
updateEnumEntries(exstEntries, insPrepStmt, type, thisClass, baseClass);
} else if (entro instanceof Domain) {
Domain domain = (Domain) entro;
if (domain == td.INTERLIS.BOOLEAN) {
continue;
}
EnumerationType type = (EnumerationType) domain.getType();
thisClass = domain.getScopedName(null);
Domain base = (Domain) domain.getExtending();
String baseClass = null;
if (base != null) {
baseClass = base.getScopedName(null);
}
HashSet exstEntries = readEnumTable(conn, true, thisClass, tabName);
updateEnumEntries(exstEntries, insPrepStmt, type, thisClass, baseClass);
}
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to insert enum values for type " + thisClass, ex);
} finally {
insPrepStmt.close();
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to update enum-table " + sqlName, ex);
}
}
use of ch.interlis.ili2c.metamodel.EnumerationType in project ili2db by claeis.
the class FromXtfRecordConverter method addAttrValue.
public int addAttrValue(IomObject iomObj, String sqlType, long sqlId, String sqlTableName, PreparedStatement ps, int valuei, AttributeDef attr, ArrayList structQueue) throws SQLException, ConverterException {
if (attr.getExtending() == null) {
String attrName = attr.getName();
if (attr.isDomainBoolean()) {
String value = iomObj.getattrvalue(attrName);
if (value != null) {
if (value.equals("true")) {
geomConv.setBoolean(ps, valuei, true);
} else {
geomConv.setBoolean(ps, valuei, false);
}
} else {
ps.setNull(valuei, Types.BIT);
}
valuei++;
} else if (attr.isDomainIliUuid()) {
String value = iomObj.getattrvalue(attrName);
if (value == null) {
geomConv.setUuidNull(ps, valuei);
} else {
Object toInsertUUID = geomConv.fromIomUuid(value);
ps.setObject(valuei, toInsertUUID);
}
valuei++;
} else if (attr.isDomainIli1Date()) {
String value = iomObj.getattrvalue(attrName);
if (value != null) {
GregorianCalendar gdate = new GregorianCalendar(Integer.parseInt(value.substring(0, 4)), Integer.parseInt(value.substring(4, 6)) - 1, Integer.parseInt(value.substring(6, 8)));
java.sql.Date date = new java.sql.Date(gdate.getTimeInMillis());
geomConv.setDate(ps, valuei, date);
} else {
ps.setNull(valuei, Types.DATE);
}
valuei++;
} else if (attr.isDomainIli2Date()) {
String value = iomObj.getattrvalue(attrName);
if (value != null) {
XMLGregorianCalendar xmldate;
try {
xmldate = javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(value);
} catch (DatatypeConfigurationException e) {
throw new ConverterException(e);
}
java.sql.Date date = new java.sql.Date(xmldate.toGregorianCalendar().getTimeInMillis());
geomConv.setDate(ps, valuei, date);
} else {
ps.setNull(valuei, Types.DATE);
}
valuei++;
} else if (attr.isDomainIli2Time()) {
String value = iomObj.getattrvalue(attrName);
if (value != null) {
XMLGregorianCalendar xmldate;
try {
xmldate = javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(value);
} catch (DatatypeConfigurationException e) {
throw new ConverterException(e);
}
java.sql.Time time = new java.sql.Time(xmldate.toGregorianCalendar().getTimeInMillis());
geomConv.setTime(ps, valuei, time);
} else {
ps.setNull(valuei, Types.TIME);
}
valuei++;
} else if (attr.isDomainIli2DateTime()) {
String value = iomObj.getattrvalue(attrName);
if (value != null) {
XMLGregorianCalendar xmldate;
try {
xmldate = javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(value);
} catch (DatatypeConfigurationException e) {
throw new ConverterException(e);
}
java.sql.Timestamp datetime = new java.sql.Timestamp(xmldate.toGregorianCalendar().getTimeInMillis());
geomConv.setTimestamp(ps, valuei, datetime);
} else {
ps.setNull(valuei, Types.TIMESTAMP);
}
valuei++;
} else {
Type type = attr.getDomainResolvingAliases();
if (type instanceof CompositionType) {
int structc = iomObj.getattrvaluecount(attrName);
if (TrafoConfigNames.CATALOGUE_REF_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.CATALOGUE_REF_TRAFO))) {
IomObject catref = iomObj.getattrobj(attrName, 0);
String refoid = null;
if (catref != null) {
IomObject structvalue = catref.getattrobj(IliNames.CHBASE1_CATALOGUEREFERENCE_REFERENCE, 0);
if (structvalue != null) {
refoid = structvalue.getobjectrefoid();
}
}
if (refoid != null) {
String targetClassName = IliNames.CHBASE1_CATALOGUES_ITEM;
long refsqlId = oidPool.getObjSqlId(targetClassName, refoid);
ps.setLong(valuei, refsqlId);
} else {
ps.setNull(valuei, Types.BIGINT);
}
valuei++;
} else if (TrafoConfigNames.MULTISURFACE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTISURFACE_TRAFO))) {
IomObject iomValue = iomObj.getattrobj(attrName, 0);
IomObject iomMultisurface = null;
MultiSurfaceMapping attrMapping = null;
if (iomValue != null) {
attrMapping = multiSurfaceAttrs.getMapping(attr);
int surfacec = iomValue.getattrvaluecount(attrMapping.getBagOfSurfacesAttrName());
for (int surfacei = 0; surfacei < surfacec; surfacei++) {
IomObject iomSurfaceStructure = iomValue.getattrobj(attrMapping.getBagOfSurfacesAttrName(), surfacei);
IomObject iomPoly = iomSurfaceStructure.getattrobj(attrMapping.getSurfaceAttrName(), 0);
IomObject iomSurface = iomPoly.getattrobj("surface", 0);
if (iomMultisurface == null) {
iomMultisurface = new ch.interlis.iom_j.Iom_jObject("MULTISURFACE", null);
}
iomMultisurface.addattrobj("surface", iomSurface);
}
}
if (iomMultisurface != null) {
AttributeDef surfaceAttr = getMultiSurfaceAttrDef(type, attrMapping);
SurfaceType surface = ((SurfaceType) surfaceAttr.getDomainResolvingAliases());
CoordType coord = (CoordType) surface.getControlPointDomain().getType();
boolean is3D = coord.getDimensions().length == 3;
Object geomObj = geomConv.fromIomMultiSurface(iomMultisurface, getSrsid(surfaceAttr), surface.getLineAttributeStructure() != null, is3D, getP(surface));
ps.setObject(valuei, geomObj);
} else {
geomConv.setSurfaceNull(ps, valuei);
}
valuei++;
} else if (TrafoConfigNames.MULTILINE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINE_TRAFO))) {
IomObject iomValue = iomObj.getattrobj(attrName, 0);
IomObject iomMultiline = null;
MultiLineMapping attrMapping = null;
if (iomValue != null) {
attrMapping = multiLineAttrs.getMapping(attr);
int polylinec = iomValue.getattrvaluecount(attrMapping.getBagOfLinesAttrName());
for (int polylinei = 0; polylinei < polylinec; polylinei++) {
IomObject iomPolylineStructure = iomValue.getattrobj(attrMapping.getBagOfLinesAttrName(), polylinei);
IomObject iomPoly = iomPolylineStructure.getattrobj(attrMapping.getLineAttrName(), 0);
if (iomMultiline == null) {
iomMultiline = new ch.interlis.iom_j.Iom_jObject(Wkb2iox.OBJ_MULTIPOLYLINE, null);
}
iomMultiline.addattrobj(Wkb2iox.ATTR_POLYLINE, iomPoly);
}
}
if (iomMultiline != null) {
AttributeDef polylineAttr = getMultiLineAttrDef(type, attrMapping);
PolylineType line = ((PolylineType) polylineAttr.getDomainResolvingAliases());
CoordType coord = (CoordType) line.getControlPointDomain().getType();
boolean is3D = coord.getDimensions().length == 3;
Object geomObj = geomConv.fromIomMultiPolyline(iomMultiline, getSrsid(polylineAttr), is3D, getP(line));
ps.setObject(valuei, geomObj);
} else {
geomConv.setPolylineNull(ps, valuei);
}
valuei++;
} else if (TrafoConfigNames.MULTIPOINT_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTIPOINT_TRAFO))) {
IomObject iomValue = iomObj.getattrobj(attrName, 0);
IomObject iomMultipoint = null;
MultiPointMapping attrMapping = null;
if (iomValue != null) {
attrMapping = multiPointAttrs.getMapping(attr);
int pointc = iomValue.getattrvaluecount(attrMapping.getBagOfPointsAttrName());
for (int pointi = 0; pointi < pointc; pointi++) {
IomObject iomPointStructure = iomValue.getattrobj(attrMapping.getBagOfPointsAttrName(), pointi);
IomObject iomPoint = iomPointStructure.getattrobj(attrMapping.getPointAttrName(), 0);
if (iomMultipoint == null) {
iomMultipoint = new ch.interlis.iom_j.Iom_jObject(Wkb2iox.OBJ_MULTIPOINT, null);
}
iomMultipoint.addattrobj(Wkb2iox.ATTR_COORD, iomPoint);
}
}
if (iomMultipoint != null) {
AttributeDef coordAttr = getMultiPointAttrDef(type, attrMapping);
CoordType coord = ((CoordType) coordAttr.getDomainResolvingAliases());
boolean is3D = coord.getDimensions().length == 3;
Object geomObj = geomConv.fromIomMultiCoord(iomMultipoint, getSrsid(coordAttr), is3D);
ps.setObject(valuei, geomObj);
} else {
geomConv.setCoordNull(ps, valuei);
}
valuei++;
} else if (TrafoConfigNames.ARRAY_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.ARRAY_TRAFO))) {
int valuec = iomObj.getattrvaluecount(attrName);
String[] iomArray = new String[valuec];
ArrayMapping attrMapping = arrayAttrs.getMapping(attr);
for (int elei = 0; elei < valuec; elei++) {
IomObject iomValue = iomObj.getattrobj(attrName, elei);
String value = iomValue.getattrvalue(attrMapping.getValueAttr().getName());
iomArray[elei] = value;
}
if (iomArray.length > 0) {
Object geomObj = geomConv.fromIomArray(attrMapping.getValueAttr(), iomArray, enumTypes);
ps.setObject(valuei, geomObj);
} else {
geomConv.setArrayNull(ps, valuei);
}
valuei++;
} else if (TrafoConfigNames.MULTILINGUAL_TRAFO_EXPAND.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINGUAL_TRAFO))) {
IomObject iomMulti = iomObj.getattrobj(attrName, 0);
for (String sfx : DbNames.MULTILINGUAL_TXT_COL_SUFFIXS) {
if (iomMulti != null) {
String value = getMultilingualText(iomMulti, sfx);
if (value != null) {
ps.setString(valuei, value);
} else {
ps.setNull(valuei, Types.VARCHAR);
}
} else {
ps.setNull(valuei, Types.VARCHAR);
}
valuei++;
}
} else {
// enqueue struct values
for (int structi = 0; structi < structc; structi++) {
IomObject struct = iomObj.getattrobj(attrName, structi);
String sqlAttrName = ili2sqlName.mapIliAttributeDef(attr, sqlTableName, null);
enqueStructValue(structQueue, sqlId, sqlType, sqlAttrName, struct, structi, attr);
}
}
} else if (type instanceof PolylineType) {
IomObject value = iomObj.getattrobj(attrName, 0);
if (value != null) {
boolean is3D = ((CoordType) ((PolylineType) type).getControlPointDomain().getType()).getDimensions().length == 3;
ps.setObject(valuei, geomConv.fromIomPolyline(value, getSrsid(attr), is3D, getP((PolylineType) type)));
} else {
geomConv.setPolylineNull(ps, valuei);
}
valuei++;
} else if (type instanceof SurfaceOrAreaType) {
if (createItfLineTables) {
} else {
IomObject value = iomObj.getattrobj(attrName, 0);
if (value != null) {
boolean is3D = ((CoordType) ((SurfaceOrAreaType) type).getControlPointDomain().getType()).getDimensions().length == 3;
Object geomObj = geomConv.fromIomSurface(value, getSrsid(attr), ((SurfaceOrAreaType) type).getLineAttributeStructure() != null, is3D, getP((SurfaceOrAreaType) type));
ps.setObject(valuei, geomObj);
} else {
geomConv.setSurfaceNull(ps, valuei);
}
valuei++;
}
if (createItfAreaRef) {
if (type instanceof AreaType) {
IomObject value = null;
if (isItfReader) {
value = iomObj.getattrobj(attrName, 0);
} else {
value = iomObj.getattrobj(ItfReader2.SAVED_GEOREF_PREFIX + attrName, 0);
}
if (value != null) {
boolean is3D = ((CoordType) ((SurfaceOrAreaType) type).getControlPointDomain().getType()).getDimensions().length == 3;
ps.setObject(valuei, geomConv.fromIomCoord(value, getSrsid(attr), is3D));
} else {
geomConv.setCoordNull(ps, valuei);
}
valuei++;
}
}
} else if (type instanceof CoordType) {
IomObject value = iomObj.getattrobj(attrName, 0);
if (value != null) {
boolean is3D = ((CoordType) type).getDimensions().length == 3;
ps.setObject(valuei, geomConv.fromIomCoord(value, getSrsid(attr), is3D));
} else {
geomConv.setCoordNull(ps, valuei);
}
valuei++;
} else if (type instanceof NumericType) {
String value = iomObj.getattrvalue(attrName);
if (type.isAbstract()) {
} else {
PrecisionDecimal min = ((NumericType) type).getMinimum();
PrecisionDecimal max = ((NumericType) type).getMaximum();
if (min.getAccuracy() > 0) {
if (value != null) {
try {
ps.setDouble(valuei, Double.parseDouble(value));
} catch (java.lang.NumberFormatException ex) {
EhiLogger.logError(ex);
}
} else {
geomConv.setDecimalNull(ps, valuei);
}
} else {
if (value != null) {
try {
int val = (int) Math.round(Double.parseDouble(value));
ps.setInt(valuei, val);
} catch (java.lang.NumberFormatException ex) {
EhiLogger.logError(ex);
}
} else {
ps.setNull(valuei, Types.INTEGER);
}
}
valuei++;
}
} else if (type instanceof EnumerationType) {
String value = iomObj.getattrvalue(attrName);
if (createEnumColAsItfCode) {
if (value != null) {
int itfCode = mapXtfCode2ItfCode((EnumerationType) type, value);
ps.setInt(valuei, itfCode);
} else {
ps.setNull(valuei, Types.INTEGER);
}
} else {
if (value != null) {
ps.setString(valuei, value);
} else {
ps.setNull(valuei, Types.VARCHAR);
}
}
valuei++;
if (createEnumTxtCol) {
if (value != null) {
ps.setString(valuei, beautifyEnumDispName(value));
} else {
ps.setNull(valuei, Types.VARCHAR);
}
valuei++;
}
} else if (type instanceof ReferenceType) {
IomObject structvalue = iomObj.getattrobj(attrName, 0);
String refoid = null;
if (structvalue != null) {
refoid = structvalue.getobjectrefoid();
}
Holder<Integer> valueiRef = new Holder<Integer>(valuei);
setReferenceColumn(ps, ((ReferenceType) type).getReferred(), refoid, valueiRef);
valuei = valueiRef.value;
} else if (type instanceof BlackboxType) {
String value = iomObj.getattrvalue(attrName);
if (((BlackboxType) type).getKind() == BlackboxType.eXML) {
if (value == null) {
geomConv.setXmlNull(ps, valuei);
} else {
Object toInsertXml = geomConv.fromIomXml(value);
ps.setObject(valuei, toInsertXml);
}
valuei++;
} else {
if (value == null) {
geomConv.setBlobNull(ps, valuei);
} else {
Object toInsertBlob = geomConv.fromIomBlob(value);
ps.setObject(valuei, toInsertBlob);
}
valuei++;
}
} else {
String value = iomObj.getattrvalue(attrName);
if (value != null) {
ps.setString(valuei, value);
} else {
ps.setNull(valuei, Types.VARCHAR);
}
valuei++;
}
}
}
return valuei;
}
Aggregations