public void read(AbstractBuilding building, long parentId) throws SQLException {
    ResultSet rs = null;

    try {
      psBuildingInstallation.setLong(1, parentId);
      rs = psBuildingInstallation.executeQuery();

      while (rs.next()) {
        long installationId = rs.getLong("ID");
        int isExternal = rs.getInt("IS_EXTERNAL");

        BuildingInstallation buildingInstallation = null;
        IntBuildingInstallation intBuildingInstallation = null;

        if (isExternal == 1) buildingInstallation = new BuildingInstallationImpl();
        else intBuildingInstallation = new IntBuildingInstallationImpl();

        String gmlName = rs.getString("NAME");
        String gmlNameCodespace = rs.getString("NAME_CODESPACE");

        if (buildingInstallation != null)
          Util.dbGmlName2featureName(buildingInstallation, gmlName, gmlNameCodespace);
        else Util.dbGmlName2featureName(intBuildingInstallation, gmlName, gmlNameCodespace);

        String description = rs.getString("DESCRIPTION");
        if (description != null) {
          StringOrRef stringOrRef = new StringOrRefImpl();
          stringOrRef.setValue(description);

          if (buildingInstallation != null) buildingInstallation.setDescription(stringOrRef);
          else intBuildingInstallation.setDescription(stringOrRef);
        }

        String clazz = rs.getString("CLASS");
        if (clazz != null) {
          if (buildingInstallation != null) buildingInstallation.setClazz(clazz);
          else intBuildingInstallation.setClazz(clazz);
        }

        String function = rs.getString("FUNCTION");
        if (function != null) {
          Pattern p = Pattern.compile("\\s+");
          String[] functionList = p.split(function.trim());

          if (buildingInstallation != null)
            buildingInstallation.setFunction(Arrays.asList(functionList));
          else intBuildingInstallation.setFunction(Arrays.asList(functionList));
        }

        String usage = rs.getString("USAGE");
        if (usage != null) {
          Pattern p = Pattern.compile("\\s+");
          String[] usageList = p.split(usage.trim());

          if (buildingInstallation != null) buildingInstallation.setUsage(Arrays.asList(usageList));
          else intBuildingInstallation.setUsage(Arrays.asList(usageList));
        }

        for (int lod = 2; lod < 5; lod++) {
          long lodSurfaceGeometryId = rs.getLong("LOD" + lod + "_GEOMETRY_ID");

          if (!rs.wasNull() && lodSurfaceGeometryId != 0) {
            DBSurfaceGeometryResult geometry = surfaceGeometryExporter.read(lodSurfaceGeometryId);

            if (geometry != null) {
              GeometryProperty<AbstractGeometry> geometryProperty =
                  new GeometryPropertyImpl<AbstractGeometry>();

              if (geometry.getAbstractGeometry() != null)
                geometryProperty.setGeometry(geometry.getAbstractGeometry());
              else geometryProperty.setHref(geometry.getTarget());

              switch (lod) {
                case 2:
                  if (buildingInstallation != null)
                    buildingInstallation.setLod2Geometry(geometryProperty);
                  break;
                case 3:
                  if (buildingInstallation != null)
                    buildingInstallation.setLod3Geometry(geometryProperty);
                  break;
                case 4:
                  if (buildingInstallation != null)
                    buildingInstallation.setLod4Geometry(geometryProperty);
                  else intBuildingInstallation.setLod4Geometry(geometryProperty);
                  break;
              }
            }
          }
        }

        if (buildingInstallation != null) {
          cityObjectReader.read(buildingInstallation, installationId);

          BuildingInstallationProperty buildInstProp = new BuildingInstallationPropertyImpl();
          buildInstProp.setObject(buildingInstallation);
          building.addOuterBuildingInstallation(buildInstProp);
        } else {
          cityObjectReader.read(intBuildingInstallation, installationId);

          IntBuildingInstallationProperty intInstProp = new IntBuildingInstallationPropertyImpl();
          intInstProp.setObject(intBuildingInstallation);
          building.addInteriorBuildingInstallation(intInstProp);
        }
      }
    } finally {
      if (rs != null) rs.close();
    }
  }
  public void read(BridgeRoom room, long parentId) throws SQLException {
    ResultSet rs = null;

    try {
      psBridgeRoomInstallation.setLong(1, parentId);
      rs = psBridgeRoomInstallation.executeQuery();

      while (rs.next()) {
        long installationId = rs.getLong(1);

        int classId = rs.getInt(2);
        if (rs.wasNull()
            || classId == 0
            || Util.classId2cityObject(classId) != CityGMLClass.INT_BRIDGE_INSTALLATION) continue;

        IntBridgeInstallation intBridgeInstallation = new IntBridgeInstallation();

        String clazz = rs.getString(3);
        if (clazz != null) {
          Code code = new Code(clazz);
          code.setCodeSpace(rs.getString(4));
          intBridgeInstallation.setClazz(code);
        }

        String function = rs.getString(5);
        String functionCodeSpace = rs.getString(6);
        if (function != null)
          intBridgeInstallation.setFunction(Util.string2codeList(function, functionCodeSpace));

        String usage = rs.getString(7);
        String usageCodeSpace = rs.getString(8);
        if (usage != null)
          intBridgeInstallation.setUsage(Util.string2codeList(usage, usageCodeSpace));

        // boundarySurface
        // geometry objects of _BoundarySurface elements have to be referenced by lod4Geometry
        // So we first export all _BoundarySurfaces
        thematicSurfaceExporter.read(intBridgeInstallation, installationId);

        // geometry
        long surfaceGeometryId = rs.getLong(11);
        Object geomObj = rs.getObject(14);
        if (surfaceGeometryId != 0 || geomObj != null) {
          GeometryProperty<AbstractGeometry> geometryProperty = null;
          if (surfaceGeometryId != 0) {
            DBSurfaceGeometryResult geometry = surfaceGeometryExporter.read(surfaceGeometryId);
            if (geometry != null) {
              geometryProperty = new GeometryProperty<AbstractGeometry>();
              if (geometry.getAbstractGeometry() != null)
                geometryProperty.setGeometry(geometry.getAbstractGeometry());
              else geometryProperty.setHref(geometry.getTarget());
            }
          } else {
            GeometryObject geometry =
                dbExporterManager.getDatabaseAdapter().getGeometryConverter().getGeometry(geomObj);
            if (geometry != null) {
              geometryProperty = new GeometryProperty<AbstractGeometry>();
              geometryProperty.setGeometry(
                  geometryExporter.getPointOrCurveGeometry(geometry, true));
            }
          }

          if (geometryProperty != null) intBridgeInstallation.setLod4Geometry(geometryProperty);
        }

        // implicit geometry
        long implicitGeometryId = rs.getLong(17);
        if (implicitGeometryId != 0) {
          GeometryObject referencePoint = null;
          Object referencePointObj = rs.getObject(20);
          if (!rs.wasNull() && referencePointObj != null)
            referencePoint =
                dbExporterManager
                    .getDatabaseAdapter()
                    .getGeometryConverter()
                    .getPoint(referencePointObj);

          String transformationMatrix = rs.getString(23);

          ImplicitGeometry implicit =
              implicitGeometryExporter.read(
                  implicitGeometryId, referencePoint, transformationMatrix);
          if (implicit != null) {
            ImplicitRepresentationProperty implicitProperty = new ImplicitRepresentationProperty();
            implicitProperty.setObject(implicit);
            intBridgeInstallation.setLod4ImplicitRepresentation(implicitProperty);
          }
        }

        cityObjectReader.read(intBridgeInstallation, installationId);

        IntBridgeInstallationProperty intInstProp = new IntBridgeInstallationProperty();
        intInstProp.setObject(intBridgeInstallation);
        room.addBridgeRoomInstallation(intInstProp);
      }
    } finally {
      if (rs != null) rs.close();
    }
  }
  public void read(Room room, long parentId) throws SQLException {
    ResultSet rs = null;

    try {
      psRoomInstallation.setLong(1, parentId);
      rs = psRoomInstallation.executeQuery();

      while (rs.next()) {
        long installationId = rs.getLong("ID");
        IntBuildingInstallation intBuildingInstallation = new IntBuildingInstallationImpl();

        String gmlName = rs.getString("NAME");
        String gmlNameCodespace = rs.getString("NAME_CODESPACE");

        Util.dbGmlName2featureName(intBuildingInstallation, gmlName, gmlNameCodespace);

        String description = rs.getString("DESCRIPTION");
        if (description != null) {
          StringOrRef stringOrRef = new StringOrRefImpl();
          stringOrRef.setValue(description);

          intBuildingInstallation.setDescription(stringOrRef);
        }

        String clazz = rs.getString("CLASS");
        if (clazz != null) {
          intBuildingInstallation.setClazz(clazz);
        }

        String function = rs.getString("FUNCTION");
        if (function != null) {
          Pattern p = Pattern.compile("\\s+");
          String[] functionList = p.split(function.trim());

          intBuildingInstallation.setFunction(Arrays.asList(functionList));
        }

        String usage = rs.getString("USAGE");
        if (usage != null) {
          Pattern p = Pattern.compile("\\s+");
          String[] usageList = p.split(usage.trim());

          intBuildingInstallation.setUsage(Arrays.asList(usageList));
        }

        long lodSurfaceGeometryId = rs.getLong("LOD4_GEOMETRY_ID");
        if (!rs.wasNull() && lodSurfaceGeometryId != 0) {
          DBSurfaceGeometryResult geometry = surfaceGeometryExporter.read(lodSurfaceGeometryId);

          if (geometry != null) {
            GeometryProperty<AbstractGeometry> geometryProperty =
                new GeometryPropertyImpl<AbstractGeometry>();

            if (geometry.getAbstractGeometry() != null)
              geometryProperty.setGeometry(geometry.getAbstractGeometry());
            else geometryProperty.setHref(geometry.getTarget());

            intBuildingInstallation.setLod4Geometry(geometryProperty);
          }
        }

        cityObjectReader.read(intBuildingInstallation, installationId);

        IntBuildingInstallationProperty intInstProp = new IntBuildingInstallationPropertyImpl();
        intInstProp.setObject(intBuildingInstallation);
        room.addRoomInstallation(intInstProp);
      }
    } finally {
      if (rs != null) rs.close();
    }
  }
  public void read(AbstractBridge bridge, long parentId, ProjectionPropertyFilter projectionFilter)
      throws SQLException {
    ResultSet rs = null;

    try {
      psBridgeInstallation.setLong(1, parentId);
      rs = psBridgeInstallation.executeQuery();

      while (rs.next()) {
        long installationId = rs.getLong(1);

        int classId = rs.getInt(2);
        if (rs.wasNull() || classId == 0) continue;

        BridgeInstallation bridgeInstallation = null;
        IntBridgeInstallation intBridgeInstallation = null;

        CityGMLClass type = Util.classId2cityObject(classId);
        switch (type) {
          case BRIDGE_INSTALLATION:
            if (projectionFilter.pass(CityGMLModuleType.BRIDGE, "outerBridgeInstallation"))
              bridgeInstallation = new BridgeInstallation();
            break;
          case INT_BRIDGE_INSTALLATION:
            if (projectionFilter.pass(CityGMLModuleType.BRIDGE, "interiorBridgeInstallation"))
              intBridgeInstallation = new IntBridgeInstallation();
            break;
          default:
            continue;
        }

        if (bridgeInstallation == null && intBridgeInstallation == null) return;

        String clazz = rs.getString(3);
        if (clazz != null) {
          Code code = new Code(clazz);
          code.setCodeSpace(rs.getString(4));
          if (bridgeInstallation != null) bridgeInstallation.setClazz(code);
          else intBridgeInstallation.setClazz(code);
        }

        String function = rs.getString(5);
        String functionCodeSpace = rs.getString(6);
        if (function != null) {
          if (bridgeInstallation != null)
            bridgeInstallation.setFunction(Util.string2codeList(function, functionCodeSpace));
          else intBridgeInstallation.setFunction(Util.string2codeList(function, functionCodeSpace));
        }

        String usage = rs.getString(7);
        String usageCodeSpace = rs.getString(8);
        if (usage != null) {
          if (bridgeInstallation != null)
            bridgeInstallation.setUsage(Util.string2codeList(usage, usageCodeSpace));
          else intBridgeInstallation.setUsage(Util.string2codeList(usage, usageCodeSpace));
        }

        // boundarySurface
        // geometry objects of _BoundarySurface elements have to be referenced by lodXGeometry
        // So we first export all _BoundarySurfaces
        if (bridgeInstallation != null)
          thematicSurfaceExporter.read(bridgeInstallation, installationId);
        else thematicSurfaceExporter.read(intBridgeInstallation, installationId);

        // geometry
        for (int lod = 0; lod < 3; lod++) {
          long surfaceGeometryId = rs.getLong(9 + lod);
          Object geomObj = rs.getObject(12 + lod);
          if (surfaceGeometryId == 0 && geomObj == null) continue;

          GeometryProperty<AbstractGeometry> geometryProperty = null;

          if (surfaceGeometryId != 0) {
            DBSurfaceGeometryResult geometry = surfaceGeometryExporter.read(surfaceGeometryId);
            if (geometry != null) {
              geometryProperty = new GeometryProperty<AbstractGeometry>();
              if (geometry.getAbstractGeometry() != null)
                geometryProperty.setGeometry(geometry.getAbstractGeometry());
              else geometryProperty.setHref(geometry.getTarget());
            }
          } else {
            GeometryObject geometry =
                dbExporterManager.getDatabaseAdapter().getGeometryConverter().getGeometry(geomObj);
            if (geometry != null) {
              geometryProperty = new GeometryProperty<AbstractGeometry>();
              geometryProperty.setGeometry(
                  geometryExporter.getPointOrCurveGeometry(geometry, true));
            }
          }

          if (geometryProperty != null) {
            switch (lod) {
              case 0:
                if (bridgeInstallation != null)
                  bridgeInstallation.setLod2Geometry(geometryProperty);
                break;
              case 1:
                if (bridgeInstallation != null)
                  bridgeInstallation.setLod3Geometry(geometryProperty);
                break;
              case 2:
                if (bridgeInstallation != null)
                  bridgeInstallation.setLod4Geometry(geometryProperty);
                else intBridgeInstallation.setLod4Geometry(geometryProperty);
                break;
            }
          }
        }

        // implicit geometry
        for (int lod = 0; lod < 3; lod++) {
          long implicitGeometryId = rs.getLong(15 + lod);
          if (rs.wasNull()) continue;

          GeometryObject referencePoint = null;
          Object referencePointObj = rs.getObject(18 + lod);
          if (!rs.wasNull() && referencePointObj != null)
            referencePoint =
                dbExporterManager
                    .getDatabaseAdapter()
                    .getGeometryConverter()
                    .getPoint(referencePointObj);

          String transformationMatrix = rs.getString(21 + lod);

          ImplicitGeometry implicit =
              implicitGeometryExporter.read(
                  implicitGeometryId, referencePoint, transformationMatrix);
          if (implicit != null) {
            ImplicitRepresentationProperty implicitProperty = new ImplicitRepresentationProperty();
            implicitProperty.setObject(implicit);

            switch (lod) {
              case 0:
                if (bridgeInstallation != null)
                  bridgeInstallation.setLod2ImplicitRepresentation(implicitProperty);
                break;
              case 1:
                if (bridgeInstallation != null)
                  bridgeInstallation.setLod3ImplicitRepresentation(implicitProperty);
                break;
              case 2:
                if (bridgeInstallation != null)
                  bridgeInstallation.setLod4ImplicitRepresentation(implicitProperty);
                else intBridgeInstallation.setLod4ImplicitRepresentation(implicitProperty);
                break;
            }
          }
        }

        if (bridgeInstallation != null) {
          cityObjectReader.read(bridgeInstallation, installationId);

          BridgeInstallationProperty bridgeInstProp = new BridgeInstallationProperty();
          bridgeInstProp.setObject(bridgeInstallation);
          bridge.addOuterBridgeInstallation(bridgeInstProp);
        } else {
          cityObjectReader.read(intBridgeInstallation, installationId);

          IntBridgeInstallationProperty intInstProp = new IntBridgeInstallationProperty();
          intInstProp.setObject(intBridgeInstallation);
          bridge.addInteriorBridgeInstallation(intInstProp);
        }
      }
    } finally {
      if (rs != null) rs.close();
    }
  }