@Override public Object visit(Function function, Object extraData) throws RuntimeException { helper.out = out; try { encodingFunction = true; boolean encoded = helper.visitFunction(function, extraData); encodingFunction = false; if (encoded) { return extraData; } else { return super.visit(function, extraData); } } catch (IOException e) { throw new RuntimeException(e); } }
public PreparedFilterToSQL createPreparedFilterToSQL() { PreparedFilterToSQL f2s = new PreparedFilterToSQL(); f2s.setCapabilities(BASE_DBMS_CAPABILITIES); return f2s; }
/** Generates a 'DELETE FROM' prepared statement. */ protected PreparedStatement deleteSQLPS( SimpleFeatureType featureType, Filter filter, Connection cx) throws SQLException { StringBuffer sql = new StringBuffer(); sql.append("DELETE FROM "); encodeTableName(featureType.getTypeName(), sql, null); PreparedFilterToSQL toSQL = null; if (filter != null && !Filter.INCLUDE.equals(filter)) { // encode filter try { toSQL = createPreparedFilterToSQL(featureType); sql.append(" ").append(toSQL.encodeToString(filter)); } catch (FilterToSQLException e) { throw new RuntimeException(e); } } LOGGER.fine(sql.toString()); PreparedStatement ps = cx.prepareStatement(sql.toString()); if (toSQL != null) { setPreparedFilterValues(ps, toSQL, 0, cx); } return ps; }
/** 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); } } }
/** * Writes the SQL for the PropertyIsBetween Filter. * * @param filter the Filter to be visited. * @throws RuntimeException for io exception with writer */ public Object visit(PropertyIsBetween filter, Object extraData) throws RuntimeException { LOGGER.finer("exporting PropertyIsBetween"); Expression expr = filter.getExpression(); Class context = super.getExpressionType(expr); if (helper.isArray(context)) { helper.out = out; helper.visitArrayBetween(filter, context.getComponentType(), extraData); return extraData; } else { return super.visit(filter, extraData); } }
/** * 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 ); } } }
public Object visit(Literal expression, Object context) throws RuntimeException { if (!prepareEnabled) return super.visit(expression, context); Class clazz = getTargetClassFromContext(context); Object literalValue = evaluateLiteral(expression, clazz); literalValues.add(literalValue); SRIDs.add(currentSRID);
int whereClauseIndex = sql.indexOf(WHERE_CLAUSE_PLACE_HOLDER); if (whereClauseIndex != -1) { toSQL.setInline(true); sql.replace( whereClauseIndex, whereClauseIndex + WHERE_CLAUSE_PLACE_HOLDER_LENGTH, "AND " + toSQL.encodeToString(filter)); toSQL.setInline(false); } else { sql.append(" ").append(toSQL.encodeToString(filter));
/** * 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(); }
out.write(escapeName(colNames[j])); out.write(" = "); out.write('?');
/** * Helper method for setting the values of the WHERE class of a prepared statement from a list * of PreparedFilterToSQL. */ protected void setPreparedFilterValues(PreparedStatement ps, List toSQLs, Connection cx) throws SQLException { int offset = 0; for (PreparedFilterToSQL toSQL : (List<PreparedFilterToSQL>) toSQLs) { setPreparedFilterValues(ps, toSQL, offset, cx); offset += toSQL.getLiteralValues().size(); } }
Object literalValue = evaluateLiteral( expression, (context instanceof Class ? (Class) context : null) ); literalValues.add(literalValue); SRIDs.add(currentSRID);
/** * 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 ); } } }
/** * 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(); }
out.write( escapeName(colNames[j]) ); out.write(" = "); out.write('?');
/** * Helper method for setting the values of the WHERE class of a prepared statement from a * list of PreparedFilterToSQL. * */ protected void setPreparedFilterValues(PreparedStatement ps, List toSQLs, Connection cx) throws SQLException { int offset = 0; for (PreparedFilterToSQL toSQL : (List<PreparedFilterToSQL>) toSQLs) { setPreparedFilterValues(ps, toSQL, offset, cx); offset += toSQL.getLiteralValues().size(); } }
Object literalValue = evaluateLiteral( expression, (context instanceof Class ? (Class) context : null) ); literalValues.add(literalValue); SRIDs.add(currentSRID);
@Override public Object visit(Function function, Object extraData) throws RuntimeException { try { encodingFunction = false; // encodingFunction = true; boolean encoded = visitFunction(function, extraData); // encodingFunction = false; if (encoded) { return extraData; } else { return super.visit(function, extraData); } } catch (IOException e) { throw new RuntimeException(e); } } }
public PreparedFilterToSQL createPreparedFilterToSQL() { PreparedFilterToSQL f2s = new PreparedFilterToSQL(); f2s.setCapabilities(BASE_DBMS_CAPABILITIES); return f2s; }
sql.append(" ").append(toSQL.encodeToString(filter)); } catch (FilterToSQLException e) { throw new RuntimeException(e);