示例#1
0
  @Override
  public Class<?> getMapping(ResultSet columnMetaData, Connection cx) throws SQLException {
    // the sqlite jdbc driver maps geometry type to varchar, so do a lookup
    // in the geometry_columns table
    String tbl = columnMetaData.getString("TABLE_NAME");
    String col = columnMetaData.getString("COLUMN_NAME");

    String sql =
        "SELECT type FROM geometry_columns "
            + "WHERE f_table_name = '"
            + tbl
            + "' "
            + "AND f_geometry_column = '"
            + col
            + "'";
    LOGGER.fine(sql);

    Statement st = cx.createStatement();
    try {
      ResultSet rs = st.executeQuery(sql);
      try {
        if (rs.next()) {
          String type = rs.getString("type");
          return Geometries.getForName(type).getBinding();
        }
      } finally {
        dataStore.closeSafe(rs);
      }

      // check geometry columns views
      sql =
          "SELECT b.type FROM views_geometry_columns a, geometry_columns b "
              + "WHERE a.f_table_name = b.f_table_name "
              + "AND a.f_geometry_column = b.f_geometry_column "
              + "AND a.view_name = '"
              + tbl
              + "' "
              + "AND a.view_geometry = '"
              + col
              + "'";
      LOGGER.fine(sql);
      try {
        rs = st.executeQuery(sql);
        try {
          if (rs.next()) {
            String type = rs.getString("type");
            return Geometries.getForName(type).getBinding();
          }
        } finally {
          dataStore.closeSafe(rs);
        }
      } catch (SQLException e) {
        LOGGER.log(Level.FINEST, "error querying views_geometry_columns", e);
      }
    } finally {
      dataStore.closeSafe(st);
    }

    return null;
  }
  @Override
  public Class<?> getMapping(ResultSet columnMetaData, Connection cx) throws SQLException {

    String typeName = columnMetaData.getString("TYPE_NAME");
    if ("UUID".equalsIgnoreCase(typeName)) {
      return UUID.class;
    } else if ("BLOB".equalsIgnoreCase(typeName)) {
      String schemaName = columnMetaData.getString("TABLE_SCHEM");
      String tableName = columnMetaData.getString("TABLE_NAME");
      String columnName = columnMetaData.getString("COLUMN_NAME");

      // look up in geometry columns table
      StringBuffer sql = new StringBuffer("SELECT type FROM geometry_columns WHERE ");
      if (schemaName != null) {
        sql.append("f_table_schema = '").append(schemaName).append("'").append(" AND ");
      }
      sql.append("f_table_name = '").append(tableName).append("' AND ");
      sql.append("f_geometry_column = '").append(columnName).append("'");

      Statement st = cx.createStatement();
      try {
        LOGGER.fine(sql.toString());
        ResultSet rs = st.executeQuery(sql.toString());
        try {
          if (rs.next()) {
            String type = rs.getString(1);
            Geometries g = Geometries.getForName(type);
            if (g != null) {
              return g.getBinding();
            }
            LOGGER.warning("Geometry type " + type + " not supported.");
          }
        } finally {
          dataStore.closeSafe(rs);
        }
      } finally {
        dataStore.closeSafe(st);
      }

      // not a geometry blob, return byte[].class
      return byte[].class;
    }

    // do a check for a column remark which marks this as a geometry
    // do this mostly for backwards compatability
    String remark = columnMetaData.getString("REMARKS");
    if (remark != null) {
      Geometries g = Geometries.getForName(remark);
      if (g != null) {
        return g.getBinding();
      }
    }

    return null;
  }