/** * Creates the sql for a select from the multi geometry table. * * <p>This method is only called when {@link JDBCDataStore#isAssociations()} is true. * * @param gid The geometry id to select for, may be <code>null</code>. */ protected String selectMultiGeometrySQL(String gid) throws SQLException { BasicSQLDialect dialect = (BasicSQLDialect) getSQLDialect(); StringBuffer sql = new StringBuffer(); sql.append("SELECT "); dialect.encodeColumnName("id", sql); sql.append(","); dialect.encodeColumnName("mgid", sql); sql.append(","); dialect.encodeColumnName("ref", sql); sql.append(" FROM "); encodeTableName(MULTI_GEOMETRY_TABLE, sql, null); if (gid != null) { sql.append(" WHERE "); dialect.encodeColumnName("id", sql); sql.append(" = "); dialect.encodeValue(gid, String.class, sql); } return sql.toString(); }
@Override public void registerClassToSqlMappings(Map<Class<?>, Integer> mappings) { super.registerClassToSqlMappings(mappings); // override since sql server maps all date times to timestamp mappings.put(Date.class, Types.TIMESTAMP); mappings.put(Time.class, Types.TIMESTAMP); }
/** * Creates a new instance of a filter to sql encoder. * * <p>The <tt>featureType</tt> may be null but it is not recommended. Such a case where this may * neccessary is when a literal needs to be encoded in isolation. */ public FilterToSQL createFilterToSQL(SimpleFeatureType featureType) { return initializeFilterToSQL(((BasicSQLDialect) dialect).createFilterToSQL(), featureType); }
dialect.encodeColumnName(attName, sql); sql.append(" = "); int srid = getGeometrySRID(g, att); int dimension = getGeometryDimension(g, att); dialect.encodeGeometryValue(g, dimension, srid, sql); } catch (IOException e) { throw new RuntimeException(e); dialect.encodeValue(values[i], att.getType().getBinding(), sql);
void encodeByteArrayAsHex(byte[] input, StringBuffer sql) { StringBuffer sb = new StringBuffer("\\x"); for (int i = 0; i < input.length; i++) { sb.append(String.format("%02x", input[i])); } super.encodeValue(sb.toString(), String.class, sql); }
@Override public void registerSqlTypeNameToClassMappings(Map<String, Class<?>> mappings) { super.registerSqlTypeNameToClassMappings(mappings); mappings.put("geometry", Geometry.class); mappings.put("uniqueidentifier", UUID.class); mappings.put("time", Time.class); mappings.put("date", Date.class); }
continue; dialect.encodeColumnName(null, colName, sql); sql.append(","); int srid = getGeometrySRID(g, att); int dimension = getGeometryDimension(g, att); dialect.encodeGeometryValue(g, dimension, srid, sql); } catch (IOException e) { throw new RuntimeException(e); dialect.encodeValue(value, binding, sql);
@Override public void encodeValue(Object value, Class type, StringBuffer sql) { if (byte[].class.equals(type)) { byte[] b = (byte[]) value; // encode as hex string sql.append("0x"); for (int i = 0; i < b.length; i++) { sql.append(Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1)); } } else { super.encodeValue(value, type, sql); } }
@Override public void registerSqlTypeNameToClassMappings(Map<String, Class<?>> mappings) { super.registerSqlTypeNameToClassMappings(mappings); mappings.put("geometry", Geometry.class); mappings.put("geography", Geometry.class); mappings.put("text", String.class); mappings.put("int8", Long.class); mappings.put("int4", Integer.class); mappings.put("bool", Boolean.class); mappings.put("character", String.class); mappings.put("varchar", String.class); mappings.put("float8", Double.class); mappings.put("int", Integer.class); mappings.put("float4", Float.class); mappings.put("int2", Short.class); mappings.put("time", Time.class); mappings.put("timetz", Time.class); mappings.put("timestamp", Timestamp.class); mappings.put("timestamptz", Timestamp.class); mappings.put("uuid", UUID.class); mappings.put("hstore", HStore.class); mappings.put("json", String.class); mappings.put("jsonb", String.class); }
/** * Creates the sql for the association table. * * <p>This method is only called when {@link JDBCDataStore#isAssociations()} is true. * * @param fid The feature id of the association */ protected String selectAssociationSQL(String fid) throws SQLException { BasicSQLDialect dialect = (BasicSQLDialect) getSQLDialect(); StringBuffer sql = new StringBuffer(); sql.append("SELECT "); dialect.encodeColumnName("fid", sql); sql.append(","); dialect.encodeColumnName("rtable", sql); sql.append(","); dialect.encodeColumnName("rcol", sql); sql.append(", "); dialect.encodeColumnName("rfid", sql); sql.append(" FROM "); encodeTableName(FEATURE_ASSOCIATION_TABLE, sql, null); if (fid != null) { sql.append(" WHERE "); dialect.encodeColumnName("fid", sql); sql.append(" = "); dialect.encodeValue(fid, String.class, sql); } return sql.toString(); }
dialect.encodeColumnName(attributes[i].getLocalName(), sql); sql.append(" = "); Geometry g = (Geometry) values[i]; int srid = getGeometrySRID(g, attributes[i]); dialect.encodeGeometryValue(g, srid, sql); } catch (IOException e) { throw new RuntimeException(e); dialect.encodeValue(values[i], attributes[i].getType().getBinding(), sql);
@Override public void encodeValue(Object value, Class type, StringBuffer sql) { if (byte[].class == type) { byte[] b = (byte[]) value; if (value != null) { // encode as hex string sql.append("'"); for (int i = 0; i < b.length; i++) { sql.append(Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1)); } sql.append("'"); } else { sql.append("NULL"); } } else { super.encodeValue(value, type, sql); } }
@Override public void registerClassToSqlMappings(Map<Class<?>, Integer> mappings) { super.registerClassToSqlMappings(mappings); // jdbc metadata for geom columns reports DATA_TYPE=1111=Types.OTHER mappings.put(Geometry.class, Types.OTHER); mappings.put(UUID.class, Types.OTHER); mappings.put(HStore.class, Types.OTHER); mappings.put(BigDate.class, Types.BIGINT); }
/** * The filter capabilities which reports which spatial operations the underlying database can * handle natively. * * @return The filter capabilities, never <code>null</code>. */ public FilterCapabilities getFilterCapabilities() { if (dialect instanceof PreparedStatementSQLDialect) return ((PreparedStatementSQLDialect) dialect) .createPreparedFilterToSQL() .getCapabilities(); else return ((BasicSQLDialect) dialect).createFilterToSQL().getCapabilities(); }
@Override public void registerSqlTypeNameToClassMappings( Map<String, Class<?>> mappings) { super.registerSqlTypeNameToClassMappings(mappings); mappings.put( "geometry", Geometry.class ); mappings.put( "uniqueidentifier", UUID.class ); }
/** * Creates the sql for a select from the geometry table. * * <p>This method is only called when {@link JDBCDataStore#isAssociations()} is true. * * @param gid The geometry id to select for, may be <code>null</code> */ protected String selectGeometrySQL(String gid) throws SQLException { BasicSQLDialect dialect = (BasicSQLDialect) getSQLDialect(); StringBuffer sql = new StringBuffer(); sql.append("SELECT "); dialect.encodeColumnName("id", sql); sql.append(","); dialect.encodeColumnName("name", sql); sql.append(","); dialect.encodeColumnName("description", sql); sql.append(","); dialect.encodeColumnName("type", sql); sql.append(","); dialect.encodeColumnName("geometry", sql); sql.append(" FROM "); encodeTableName(GEOMETRY_TABLE, sql, null); if (gid != null) { sql.append(" WHERE "); dialect.encodeColumnName("id", sql); sql.append(" = "); dialect.encodeValue(gid, String.class, sql); } return sql.toString(); }
dialect.encodeColumnName(attName, sql); sql.append(" = "); Geometry g = (Geometry) values[i]; int srid = getGeometrySRID(g, attributes[i]); dialect.encodeGeometryValue(g, srid, sql); } catch (IOException e) { throw new RuntimeException(e); dialect.encodeValue(values[i], attributes[i].getType().getBinding(), sql);
void encodeByteArrayAsEscape(byte[] input, StringBuffer sql) { // escape the into bytea representation StringBuffer sb = new StringBuffer(); for (int i = 0; i < input.length; i++) { byte b = input[i]; if (b == 0) { sb.append("\\\\000"); } else if (b == 39) { sb.append("\\'"); } else if (b == 92) { sb.append("\\\\134'"); } else if (b < 31 || b >= 127) { sb.append("\\\\"); String octal = Integer.toOctalString(b); if (octal.length() == 1) { sb.append("00"); } else if (octal.length() == 2) { sb.append("0"); } sb.append(octal); } else { sb.append((char) b); } } super.encodeValue(sb.toString(), String.class, sql); }
@Override public void registerClassToSqlMappings(Map<Class<?>, Integer> mappings) { super.registerClassToSqlMappings(mappings); // jdbc metadata for geom columns reports DATA_TYPE=1111=Types.OTHER mappings.put(Geometry.class, Types.OTHER); }
/** * Creates a new instance of a filter to sql encoder. * <p> * The <tt>featureType</tt> may be null but it is not recommended. Such a * case where this may neccessary is when a literal needs to be encoded in * isolation. * </p> */ protected FilterToSQL createFilterToSQL(SimpleFeatureType featureType) { return initializeFilterToSQL( ((BasicSQLDialect)dialect).createFilterToSQL(), featureType ); }