Search in sources :

Example 21 with ViewableWrapper

use of ch.ehi.ili2db.mapping.ViewableWrapper in project ili2db by claeis.

the class FromXtfRecordConverter method setReferenceColumn.

private void setReferenceColumn(PreparedStatement ps, AbstractClassDef destination, String refoid, Holder<Integer> valuei) throws SQLException {
    String targetRootClassName = Ili2cUtility.getRootViewable(destination).getScopedName(null);
    ViewableWrapper targetObjTable = null;
    ArrayList<ViewableWrapper> targetTables = getTargetTables(destination);
    if (refoid != null) {
        String targetObjClass = oidPool.getObjecttag(targetRootClassName, refoid);
        if (targetObjClass == null) {
            // unknown object
            // handle reference as if it is null
            refoid = null;
        } else {
            targetObjTable = getViewableWrapper(getSqlType((Viewable) tag2class.get(targetObjClass)).getName());
            while (!targetTables.contains(targetObjTable)) {
                targetObjTable = targetObjTable.getExtending();
            }
            if (targetObjTable == null) {
                throw new IllegalStateException("targetObjTable==null");
            }
        }
    }
    for (ViewableWrapper targetTable : targetTables) {
        if (refoid != null && targetTable == targetObjTable) {
            long refsqlId = oidPool.getObjSqlId(targetRootClassName, refoid);
            ps.setLong(valuei.value, refsqlId);
        } else {
            ps.setNull(valuei.value, Types.BIGINT);
        }
        valuei.value++;
    }
}
Also used : Viewable(ch.interlis.ili2c.metamodel.Viewable) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper)

Example 22 with ViewableWrapper

use of ch.ehi.ili2db.mapping.ViewableWrapper in project ili2db by claeis.

the class FromXtfRecordConverter method addAttrToInsertStmt.

public String addAttrToInsertStmt(boolean isUpdate, StringBuffer ret, StringBuffer values, String sep, AttributeDef attr, String sqlTableName) {
    if (attr.getExtending() == null) {
        Type type = attr.getDomainResolvingAliases();
        String attrSqlName = ili2sqlName.mapIliAttributeDef(attr, sqlTableName, null);
        if (attr.isDomainBoolean()) {
            ret.append(sep);
            ret.append(attrSqlName);
            if (isUpdate) {
                ret.append("=?");
            } else {
                values.append(",?");
            }
            sep = ",";
        } else if (type instanceof CompositionType) {
            if (TrafoConfigNames.CATALOGUE_REF_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.CATALOGUE_REF_TRAFO))) {
                ret.append(sep);
                ret.append(attrSqlName);
                if (isUpdate) {
                    ret.append("=?");
                } else {
                    values.append(",?");
                }
                sep = ",";
            } else if (TrafoConfigNames.MULTISURFACE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTISURFACE_TRAFO))) {
                ret.append(sep);
                ret.append(attrSqlName);
                multiSurfaceAttrs.addMultiSurfaceAttr(attr);
                int srsid = getSrsid(getMultiSurfaceAttrDef(type, multiSurfaceAttrs.getMapping(attr)));
                if (isUpdate) {
                    ret.append("=" + geomConv.getInsertValueWrapperMultiSurface("?", srsid));
                } else {
                    values.append("," + geomConv.getInsertValueWrapperMultiSurface("?", srsid));
                }
                sep = ",";
            } else if (TrafoConfigNames.MULTILINE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINE_TRAFO))) {
                ret.append(sep);
                ret.append(attrSqlName);
                multiLineAttrs.addMultiLineAttr(attr);
                int srsid = getSrsid(getMultiLineAttrDef(type, multiLineAttrs.getMapping(attr)));
                if (isUpdate) {
                    ret.append("=" + geomConv.getInsertValueWrapperMultiPolyline("?", srsid));
                } else {
                    values.append("," + geomConv.getInsertValueWrapperMultiPolyline("?", srsid));
                }
                sep = ",";
            } else if (TrafoConfigNames.MULTIPOINT_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTIPOINT_TRAFO))) {
                ret.append(sep);
                ret.append(attrSqlName);
                multiPointAttrs.addMultiPointAttr(attr);
                int srsid = getSrsid(getMultiPointAttrDef(type, multiPointAttrs.getMapping(attr)));
                if (isUpdate) {
                    ret.append("=" + geomConv.getInsertValueWrapperMultiCoord("?", srsid));
                } else {
                    values.append("," + geomConv.getInsertValueWrapperMultiCoord("?", srsid));
                }
                sep = ",";
            } else if (TrafoConfigNames.ARRAY_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.ARRAY_TRAFO))) {
                ret.append(sep);
                ret.append(attrSqlName);
                arrayAttrs.addArrayAttr(attr);
                if (isUpdate) {
                    ret.append("=" + geomConv.getInsertValueWrapperArray("?"));
                } else {
                    values.append("," + geomConv.getInsertValueWrapperArray("?"));
                }
                sep = ",";
            } else if (TrafoConfigNames.MULTILINGUAL_TRAFO_EXPAND.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINGUAL_TRAFO))) {
                for (String sfx : DbNames.MULTILINGUAL_TXT_COL_SUFFIXS) {
                    ret.append(sep);
                    ret.append(attrSqlName + sfx);
                    if (isUpdate) {
                        ret.append("=?");
                    } else {
                        values.append(",?");
                    }
                    sep = ",";
                }
            }
        } else if (type instanceof PolylineType) {
            ret.append(sep);
            ret.append(attrSqlName);
            if (isUpdate) {
                ret.append("=" + geomConv.getInsertValueWrapperPolyline("?", getSrsid(attr)));
            } else {
                values.append("," + geomConv.getInsertValueWrapperPolyline("?", getSrsid(attr)));
            }
            sep = ",";
        } else if (type instanceof SurfaceOrAreaType) {
            if (createItfLineTables) {
            } else {
                ret.append(sep);
                ret.append(attrSqlName);
                if (isUpdate) {
                    ret.append("=" + geomConv.getInsertValueWrapperSurface("?", getSrsid(attr)));
                } else {
                    values.append("," + geomConv.getInsertValueWrapperSurface("?", getSrsid(attr)));
                }
                sep = ",";
            }
            if (createItfAreaRef) {
                if (type instanceof AreaType) {
                    ret.append(sep);
                    ret.append(attrSqlName + DbNames.ITF_MAINTABLE_GEOTABLEREF_COL_SUFFIX);
                    if (isUpdate) {
                        ret.append("=" + geomConv.getInsertValueWrapperCoord("?", getSrsid(attr)));
                    } else {
                        values.append("," + geomConv.getInsertValueWrapperCoord("?", getSrsid(attr)));
                    }
                    sep = ",";
                }
            }
        } else if (type instanceof CoordType) {
            ret.append(sep);
            ret.append(attrSqlName);
            if (isUpdate) {
                ret.append("=" + geomConv.getInsertValueWrapperCoord("?", getSrsid(attr)));
            } else {
                values.append("," + geomConv.getInsertValueWrapperCoord("?", getSrsid(attr)));
            }
            sep = ",";
        } else if (type instanceof EnumerationType) {
            ret.append(sep);
            ret.append(attrSqlName);
            if (isUpdate) {
                ret.append("=?");
            } else {
                values.append(",?");
            }
            sep = ",";
            if (createEnumTxtCol) {
                ret.append(sep);
                ret.append(attrSqlName + DbNames.ENUM_TXT_COL_SUFFIX);
                if (isUpdate) {
                    ret.append("=?");
                } else {
                    values.append(",?");
                }
                sep = ",";
            }
        } else if (type instanceof ReferenceType) {
            ArrayList<ViewableWrapper> targetTables = getTargetTables(((ReferenceType) type).getReferred());
            for (ViewableWrapper targetTable : targetTables) {
                attrSqlName = ili2sqlName.mapIliAttributeDef(attr, sqlTableName, targetTable.getSqlTablename(), targetTables.size() > 1);
                ret.append(sep);
                ret.append(attrSqlName);
                if (isUpdate) {
                    ret.append("=?");
                } else {
                    values.append(",?");
                }
                sep = ",";
            }
        } else {
            ret.append(sep);
            ret.append(attrSqlName);
            if (isUpdate) {
                ret.append("=?");
            } else {
                values.append(",?");
            }
            sep = ",";
        }
    }
    return sep;
}
Also used : PolylineType(ch.interlis.ili2c.metamodel.PolylineType) NumericalType(ch.interlis.ili2c.metamodel.NumericalType) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) Type(ch.interlis.ili2c.metamodel.Type) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) NumericType(ch.interlis.ili2c.metamodel.NumericType) BlackboxType(ch.interlis.ili2c.metamodel.BlackboxType) AreaType(ch.interlis.ili2c.metamodel.AreaType) LineType(ch.interlis.ili2c.metamodel.LineType) ObjectType(ch.interlis.ili2c.metamodel.ObjectType) CoordType(ch.interlis.ili2c.metamodel.CoordType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) AreaType(ch.interlis.ili2c.metamodel.AreaType) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) CoordType(ch.interlis.ili2c.metamodel.CoordType)

Example 23 with ViewableWrapper

use of ch.ehi.ili2db.mapping.ViewableWrapper in project ili2db by claeis.

the class TransferFromXtf method createQueryStmt4sqlid.

private String createQueryStmt4sqlid(Viewable aclass) {
    ArrayList<ViewableWrapper> wrappers = recConv.getTargetTables(aclass);
    StringBuffer ret = new StringBuffer();
    int i = 1;
    ret.append("SELECT " + colT_ID + "," + DbNames.T_ILI_TID_COL + "," + DbNames.T_TYPE_COL + " FROM (");
    String sep = "";
    for (ViewableWrapper wrapper : wrappers) {
        ret.append(sep);
        ret.append("SELECT r" + i + "." + colT_ID);
        ret.append(", r" + i + "." + DbNames.T_ILI_TID_COL);
        if (recConv.createTypeDiscriminator() || wrapper.includesMultipleTypes()) {
            ret.append(", r" + i + "." + DbNames.T_TYPE_COL);
        } else {
            ret.append(", '" + wrapper.getSqlTable().getName() + "' " + DbNames.T_TYPE_COL);
        }
        ret.append(" FROM ");
        ret.append(wrapper.getSqlTable().getQName());
        ret.append(" r" + i + "");
        i++;
        sep = " UNION ";
    }
    ret.append(") r0");
    ret.append(" WHERE r0." + DbNames.T_ILI_TID_COL + "=?");
    return ret.toString();
}
Also used : ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper)

Example 24 with ViewableWrapper

use of ch.ehi.ili2db.mapping.ViewableWrapper in project ili2db by claeis.

the class AbstractRecordConverter method getTargetTables.

public ArrayList<ViewableWrapper> getTargetTables(Viewable destination) {
    if (targetTablesPool.containsKey(destination)) {
        return targetTablesPool.get(destination);
    }
    ArrayList<ViewableWrapper> ret = new ArrayList<ViewableWrapper>();
    ArrayList<Viewable> candids = new ArrayList<Viewable>();
    candids.add(destination);
    while (!candids.isEmpty()) {
        Viewable candid = candids.remove(0);
        String inheritanceStrategy = trafoConfig.getViewableConfig(candid, TrafoConfigNames.INHERITANCE_TRAFO);
        if (TrafoConfigNames.INHERITANCE_TRAFO_SUPERCLASS.equals(inheritanceStrategy)) {
            // ViewableWrapper of base
            ret.add(class2wrapper.get(candid));
        } else if (TrafoConfigNames.INHERITANCE_TRAFO_SUBCLASS.equals(inheritanceStrategy)) {
            // visit all sub classes
            candids.addAll(candid.getDirectExtensions());
        } else if (TrafoConfigNames.INHERITANCE_TRAFO_NEWCLASS.equals(inheritanceStrategy)) {
            ViewableWrapper wrapper = class2wrapper.get(candid);
            // classes that have no defined Wrapper are loaded by the compiler, but are not used
            if (wrapper != null) {
                ret.add(wrapper);
            }
        } else if (TrafoConfigNames.INHERITANCE_TRAFO_NEWANDSUBCLASS.equals(inheritanceStrategy)) {
            ViewableWrapper wrapper = class2wrapper.get(candid);
            // classes that have no defined Wrapper are loaded by the compiler, but are not used
            if (wrapper != null) {
                ret.add(wrapper);
            }
            // visit all sub classes
            candids.addAll(candid.getDirectExtensions());
        } else {
        // skip it
        // classes that have no assigned inheritanceStrategy are loaded by the compiler, but are not used
        // example:
        // CLASS CatalogueObjectTrees_V1.Catalogues.Item is loaded and an extension
        // of CLASS CatalogueObjects_V1.Catalogues.Item.
        // It is loaded because it is defined in the same ili-file, but is normally not used.
        }
    }
    // buffer result, so that later calls return exactly the same ordering of targetTables
    // first call: build sql statement
    // second++ calls: set/get sql parameters
    targetTablesPool.put(destination, ret);
    return ret;
}
Also used : ArrayList(java.util.ArrayList) Viewable(ch.interlis.ili2c.metamodel.Viewable) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper)

Example 25 with ViewableWrapper

use of ch.ehi.ili2db.mapping.ViewableWrapper in project ili2db by claeis.

the class AbstractRecordConverter method getStructWrappers.

public ArrayList<ViewableWrapper> getStructWrappers(Table structClass) {
    ArrayList<ViewableWrapper> ret = new ArrayList<ViewableWrapper>();
    ViewableWrapper structWrapper = class2wrapper.get(structClass);
    if (structWrapper != null) {
        while (structWrapper.getExtending() != null) {
            structWrapper = structWrapper.getExtending();
        }
        ret.add(structWrapper);
        return ret;
    }
    ArrayList<ExtendableContainer<AbstractLeafElement>> exts = new ArrayList<ExtendableContainer<AbstractLeafElement>>();
    exts.addAll(structClass.getDirectExtensions());
    while (exts.size() > 0) {
        structClass = (Table) exts.remove(0);
        structWrapper = class2wrapper.get(structClass);
        if (structWrapper != null) {
            while (structWrapper.getExtending() != null) {
                structWrapper = structWrapper.getExtending();
            }
            ret.add(structWrapper);
        } else {
            exts.addAll(structClass.getDirectExtensions());
        }
    }
    return ret;
}
Also used : ExtendableContainer(ch.interlis.ili2c.metamodel.ExtendableContainer) AbstractLeafElement(ch.interlis.ili2c.metamodel.AbstractLeafElement) ArrayList(java.util.ArrayList) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper)

Aggregations

ViewableWrapper (ch.ehi.ili2db.mapping.ViewableWrapper)25 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)12 Viewable (ch.interlis.ili2c.metamodel.Viewable)11 CompositionType (ch.interlis.ili2c.metamodel.CompositionType)9 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)9 SurfaceOrAreaType (ch.interlis.ili2c.metamodel.SurfaceOrAreaType)9 ArrayList (java.util.ArrayList)9 AreaType (ch.interlis.ili2c.metamodel.AreaType)8 BlackboxType (ch.interlis.ili2c.metamodel.BlackboxType)8 CoordType (ch.interlis.ili2c.metamodel.CoordType)8 ObjectType (ch.interlis.ili2c.metamodel.ObjectType)8 PolylineType (ch.interlis.ili2c.metamodel.PolylineType)8 ReferenceType (ch.interlis.ili2c.metamodel.ReferenceType)8 SurfaceType (ch.interlis.ili2c.metamodel.SurfaceType)8 Type (ch.interlis.ili2c.metamodel.Type)8 HashSet (java.util.HashSet)8 Iterator (java.util.Iterator)8 DbTableName (ch.ehi.sqlgen.repository.DbTableName)7 IomObject (ch.interlis.iom.IomObject)7 AssociationDef (ch.interlis.ili2c.metamodel.AssociationDef)5