private void setRelationalUpdateValues(
      List<ParsedPropertyReplacement> replacementProps,
      FeatureTypeMapping ftMapping,
      PreparedStatement stmt,
      IdFilter filter,
      FIDMapping fidMapping)
      throws SQLException {
    int i = 1;

    for (ParsedPropertyReplacement replacement : replacementProps) {
      Property replacementProp = replacement.getNewValue();
      QName propName = replacementProp.getType().getName();
      Mapping mapping = ftMapping.getMapping(propName);
      if (mapping != null) {
        if (mapping.getJoinedTable() != null && !mapping.getJoinedTable().isEmpty()) {
          continue;
        }

        Object value = replacementProp.getValue();
        if (value != null) {
          ParticleConverter<TypedObjectNode> converter =
              (ParticleConverter<TypedObjectNode>) fs.getConverter(mapping);
          if (mapping instanceof PrimitiveMapping) {
            MappingExpression me = ((PrimitiveMapping) mapping).getMapping();
            if (!(me instanceof DBField)) {
              continue;
            }
            converter.setParticle(stmt, (PrimitiveValue) value, i++);
          } else if (mapping instanceof GeometryMapping) {
            MappingExpression me = ((GeometryMapping) mapping).getMapping();
            if (!(me instanceof DBField)) {
              continue;
            }
            converter.setParticle(stmt, (Geometry) value, i++);
          }
        } else {
          stmt.setObject(i++, null);
        }
      }
    }

    for (String id : filter.getMatchingIds()) {
      IdAnalysis analysis = schema.analyzeId(id);
      int j = i;
      for (String fidKernel : analysis.getIdKernels()) {
        PrimitiveValue value =
            new PrimitiveValue(fidKernel, new PrimitiveType(fidMapping.getColumnType()));
        Object sqlValue = SQLValueMangler.internalToSQL(value);
        stmt.setObject(j++, sqlValue);
      }
      stmt.addBatch();
    }
  }
 /**
  * Inserts the given feature into BLOB table and returns the generated primary key.
  *
  * @param stmt
  * @param feature
  * @return primary key of the feature
  * @throws SQLException
  * @throws FeatureStoreException
  */
 private int insertFeatureBlob(PreparedStatement stmt, Feature feature)
     throws SQLException, FeatureStoreException {
   LOG.debug("Inserting feature with id '" + feature.getId() + "' (BLOB)");
   if (fs.getSchema().getFeatureType(feature.getName()) == null) {
     throw new FeatureStoreException(
         "Cannot insert feature '"
             + feature.getName()
             + "': feature type is not served by this feature store.");
   }
   ICRS crs = blobMapping.getCRS();
   stmt.setString(1, feature.getId());
   stmt.setShort(2, fs.getFtId(feature.getName()));
   byte[] bytes = encodeFeatureBlob(feature, crs);
   stmt.setBytes(3, bytes);
   LOG.debug("Feature blob size: " + bytes.length);
   Geometry bboxGeom = getFeatureEnvelopeAsGeometry(feature);
   blobGeomConverter.setParticle(stmt, bboxGeom, 4);
   stmt.execute();
   int internalId = -1;
   // ResultSet rs = null;
   // try {
   // // TODO only supported for PostgreSQL >= 8.2
   // rs = stmt.getGeneratedKeys();
   // rs.next();
   // internalId = rs.getInt( 1 );
   // } finally {
   // if ( rs != null ) {
   // rs.close();
   // }
   // }
   return internalId;
 }
 private void updateFeatureBlob(final PreparedStatement stmt, final Feature feature)
     throws SQLException {
   LOG.debug("Updating feature with id '" + feature.getId() + "' (BLOB)");
   final ICRS crs = blobMapping.getCRS();
   final byte[] bytes = encodeFeatureBlob(feature, crs);
   stmt.setBytes(1, bytes);
   LOG.debug("Feature blob size: " + bytes.length);
   final Geometry bboxGeom = getFeatureEnvelopeAsGeometry(feature);
   blobGeomConverter.setParticle(stmt, bboxGeom, 2);
   stmt.setString(3, feature.getId());
   stmt.execute();
 }