private String getPrimaryKeyColumnsAsCommaSeparatedList(List<PrimaryKeyColumn> pkColumns) { StringBuffer sb = new StringBuffer(); boolean first = true; for (PrimaryKeyColumn c : pkColumns) { if (first) { first = false; } else { sb.append(","); } dialect.encodeColumnName(c.getName(), sb); } return sb.toString(); }
int srid = currentSRID != null ? currentSRID : -1; int dimension = currentDimension != null ? currentDimension : -1; dialect.prepareGeometryValue( (Geometry) literalValue, dimension, srid, Geometry.class, sb); } else if (encodingFunction) { dialect.prepareFunctionArgument(clazz, sb); } else { sb.append("?");
public void registerSqlTypeNameToClassMappings(Map<String, Class<?>> mappings) { super.registerSqlTypeNameToClassMappings(mappings); mappings.put("SDO_GEOMETRY", Geometry.class); mappings.put("MDSYS.SDO_GEOMETRY", Geometry.class); }
/** * Sets a value in a prepared statement, for the specific case of {@link Array} * * <p>This method uses the standard SQL Array handling, subclasses can override to add special * behavior * * @param value the value. * @param att The full attribute description * @param ps The prepared statement. * @param column The column the value maps to. * @param cx The database connection. * @throws SQLException */ public void setArrayValue( Object value, AttributeDescriptor att, PreparedStatement ps, int i, Connection cx) throws SQLException { if (value == null) { ps.setNull(i, Types.ARRAY); } else { String typeName = getArrayComponentTypeName(att); Class<?> componentType = typeName != null ? dataStore.getSqlTypeNameToClassMappings().get(typeName) : String.class; Array array = convertToArray(value, typeName, componentType, cx); ps.setArray(i, array); } }
/** Helper method for setting the values of the WHERE class of a prepared statement. */ public void setPreparedFilterValues( PreparedStatement ps, PreparedFilterToSQL toSQL, int offset, Connection cx) throws SQLException { PreparedStatementSQLDialect dialect = (PreparedStatementSQLDialect) getSQLDialect(); for (int i = 0; i < toSQL.getLiteralValues().size(); i++) { Object value = toSQL.getLiteralValues().get(i); Class binding = toSQL.getLiteralTypes().get(i); Integer srid = toSQL.getSRIDs().get(i); Integer dimension = toSQL.getDimensions().get(i); AttributeDescriptor ad = toSQL.getDescriptors().get(i); if (srid == null) { srid = -1; } if (dimension == null) { dimension = 2; } if (binding != null && Geometry.class.isAssignableFrom(binding)) { dialect.setGeometryValue( (Geometry) value, dimension, srid, binding, ps, offset + i + 1); } else if (ad != null && isArray(ad)) { dialect.setArrayValue(value, ad, ps, offset + i + 1, cx); } else { dialect.setValue(value, binding, ps, offset + i + 1, cx); } if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine((i + 1) + " = " + value); } } }
dialect.encodeColumnName(attName, sql); sql.append(" = "); Geometry geometry = (Geometry) values[i]; final Class<?> binding = att.getType().getBinding(); dialect.prepareGeometryValue( geometry, getDescriptorDimension(att), if (Geometry.class.isAssignableFrom(binding)) { Geometry g = (Geometry) values[i]; dialect.setGeometryValue( g, getDescriptorDimension(att), getDescriptorSRID(att), binding, ps, j + 1); } else { dialect.setValue(values[i], binding, ps, j + 1, cx);
int srid = getGeometrySRID(g, att); int dimension = getGeometryDimension(g, att); dialect.setGeometryValue(g, dimension, srid, binding, ps, i); } else if (isArray(att)) { dialect.setArrayValue(value, att, ps, i, cx); } else { dialect.setValue(value, binding, ps, i, cx); dialect.onInsert(ps, cx, featureType); ps.addBatch();
/** * Helper method for setting the values of the WHERE class of a prepared statement. * */ protected void setPreparedFilterValues( PreparedStatement ps, PreparedFilterToSQL toSQL, int offset, Connection cx ) throws SQLException { PreparedStatementSQLDialect dialect = (PreparedStatementSQLDialect) getSQLDialect(); for ( int i = 0; i < toSQL.getLiteralValues().size(); i++) { Object value = toSQL.getLiteralValues().get(i); Class binding = toSQL.getLiteralTypes().get(i); Integer srid = toSQL.getSRIDs().get(i); if(srid == null) srid = -1; if(binding != null && Geometry.class.isAssignableFrom(binding)) dialect.setGeometryValue((Geometry) value, srid, binding, ps, offset + i+1); else dialect.setValue( value, binding, ps, offset + i+1, cx ); if ( LOGGER.isLoggable( Level.FINE ) ) { LOGGER.fine( (i+1) + " = " + value ); } } }
dialect.encodeColumnName(null, colName, sql); sql.append(","); Class<? extends Geometry> geometryClass = kind.geometryTypes.get(att.getName().getLocalPart()); dialect.prepareGeometryValue( geometryClass, getDescriptorDimension(att),
dialect.encodeSchemaName(getDatabaseSchema(), sb); sb.append("."); dialect.encodeTableName(getPrimaryKey().getTableName(), sb); dialect.encodeColumnName(featureType.getGeometryDescriptor().getLocalName(), sb); sb.append(",");
@Override public void setValue( Object value, Class binding, PreparedStatement ps, int column, Connection cx) throws SQLException { // get the sql type Integer sqlType = dataStore.getMapping(binding); // handl null case if (value == null) { ps.setNull(column, sqlType); return; } switch (sqlType) { case Types.DATE: ps.setString(column, ((Date) value).toString()); break; case Types.TIME: ps.setString(column, ((Time) value).toString()); break; case Types.TIMESTAMP: ps.setString(column, ((Timestamp) value).toString()); break; default: super.setValue(value, binding, ps, column, cx); } }
/** Creates a new instance of a filter to sql encoder to be used in a prepared statement. */ public PreparedFilterToSQL createPreparedFilterToSQL(SimpleFeatureType featureType) { return initializeFilterToSQL( ((PreparedStatementSQLDialect) dialect).createPreparedFilterToSQL(), featureType); }
@Override public void prepareFunctionArgument(Class clazz, StringBuffer sql) { String castExpression = DB2Util.getCastExpression(clazz); if (castExpression != null) sql.append(castExpression); else super.prepareFunctionArgument(clazz, sql); }
@Override public void prepareGeometryValue( Class<? extends Geometry> gClass, int dimension, int srid, Class binding, StringBuffer sql) { if (gClass != null) { sql.append("GeomFromWKB(?)"); } else { super.prepareGeometryValue(gClass, dimension, srid, binding, sql); } }
@Override protected <T> T convert(Object value, Class<T> binding) { if (Integer.class.equals(binding) && value instanceof Boolean) { return (T) Integer.valueOf(Boolean.TRUE.equals(value) ? 1 : 0); } return super.convert(value, binding); }
@Override public void postCreateAttribute( AttributeDescriptor att, String tableName, String schemaName, Connection cx) throws SQLException { super.postCreateAttribute(att, tableName, schemaName, cx); if (att instanceof GeometryDescriptor) { String sql = "SELECT * FROM gpkg_extensions WHERE (lower(table_name)=lower('" + tableName + "') " + "AND lower(column_name)=lower('" + att.getLocalName() + "') " + "AND extension_name='gpkg_rtree_index')"; try (Statement st = cx.createStatement(); ResultSet rs = st.executeQuery(sql)) { // did we get a result? boolean hasSpatialIndex = rs.next(); att.getUserData().put(HAS_SPATIAL_INDEX, hasSpatialIndex); } } }
public CoordinateReferenceSystem createCRS(int srid, Connection cx) throws SQLException { try { return CRS.decode("EPSG:" + srid, true); } catch (Exception e) { LOGGER.log(Level.FINE, "Unable to create CRS from epsg code " + srid, e); // try looking up in spatial ref sys String sql = String.format( "SELECT definition FROM %s WHERE auth_srid = %d", SPATIAL_REF_SYS, srid); LOGGER.fine(sql); Statement st = cx.createStatement(); ResultSet rs = st.executeQuery(sql); try { if (rs.next()) { String wkt = rs.getString(1); try { return CRS.parseWKT(wkt); } catch (Exception e2) { LOGGER.log(Level.FINE, "Unable to create CRS from wkt: " + wkt, e2); } } } finally { dataStore.closeSafe(rs); dataStore.closeSafe(st); } } return super.createCRS(srid, cx); }
@Override protected String getArrayComponentTypeName(AttributeDescriptor att) throws SQLException { if (att == null) { return null; } String name = (String) att.getUserData().get(JDBCDataStore.JDBC_NATIVE_TYPENAME); // in postgresql jdbc the database metadata TYPE_NAME column contains the // array "base type" name, prefixed with an underscore if (name != null && name.startsWith("_")) { return name.substring(1); } return super.getArrayComponentTypeName(att); }
dialect.encodeColumnName(att.getLocalName(), sql); sql.append(" = "); Geometry geometry = (Geometry) values[i]; final Class<?> binding = att.getType().getBinding(); dialect.prepareGeometryValue(geometry, getDescriptorSRID(att), binding, sql ); } else { sql.append("?"); if (Geometry.class.isAssignableFrom( binding ) ) { Geometry g = (Geometry) values[i]; dialect.setGeometryValue(g, getDescriptorSRID(att), binding, ps, i+1); dialect.setValue( values[i], binding, ps, i+1, cx);
/** * Helper method for setting the values of the WHERE class of a prepared statement. * */ protected void setPreparedFilterValues( PreparedStatement ps, PreparedFilterToSQL toSQL, int offset, Connection cx ) throws SQLException { PreparedStatementSQLDialect dialect = (PreparedStatementSQLDialect) getSQLDialect(); for ( int i = 0; i < toSQL.getLiteralValues().size(); i++) { Object value = toSQL.getLiteralValues().get(i); Class binding = toSQL.getLiteralTypes().get(i); Integer srid = toSQL.getSRIDs().get(i); if(srid == null) srid = -1; if(binding != null && Geometry.class.isAssignableFrom(binding)) dialect.setGeometryValue((Geometry) value, srid, binding, ps, offset + i+1); else dialect.setValue( value, binding, ps, offset + i+1, cx ); if ( LOGGER.isLoggable( Level.FINE ) ) { LOGGER.fine( (i+1) + " = " + value ); } } }