Introduce SQL builder to prevent duplicate methods for Statement / Prepared
statements
--------------------------------------------------------------------------------------
Key: GEOT-2487
URL: http://jira.codehaus.org/browse/GEOT-2487
Project: GeoTools
Issue Type: Improvement
Components: data jdbc-ng
Reporter: Jody Garnett
Fix For: 2.6-M2
In trying to reuse some code for issuing select statements (in order to
generate aggregate functions) I have run into duplicated logic between the
following two methods:
- protected String selectSQL(SimpleFeatureType featureType, Query query) throws
IOException
- protected PreparedStatement selectSQLPS( SimpleFeatureType featureType, Query
query, Connection cx )
While this is "okay" in an isolated incident it really starts to harm code
reuse:
- each new kind of query results in 2 methods:
-- selectSQLPS( Expression expression, Query query, Connection cx )
-- selectSQLPS( Expression expression, Query query, Connection cx )
- each new kind of query that wants to create a select based on a Query needs
to copy the original two methods
-- selectAssociationSQL and selectAssociationSQLPS
-- selectBounds and selectBoundsSQL
-- selectCountSQL and selectCountSQLPS
-- selectGeometryAssociation and selectGeometryAssociationPS
-- selectGeometrySQL and selectGeometrySQLPS
-- selectMultipleGeometrySQL and selectMultipleGeometrySQLPS
-- selectRelationshipSQL and selectRelationshipSQL PS
- This approach to prepaired statements actually results in *everything* being
duplicated
-- insertSQL and insertSQLPS
-- updateSQL and updateSQLPS
The fact that this trap is not needed for the creation of a normal statement
(by passing around a StringBuffer to build up the SQL statement) gives us a way
forward.
Create the following class:
- SQL (named after the fact the StringBuffer is always called "sql" in the code
- Make it method compatible with StringBuffer (so lots of appends)
- Make it "slurp up" any object references; and store them into an internal
List<Object> for issuing prepared statements
- Have a look if we can can parameratize this with an Dialect; in order to
smooth allow append( Filter ); if not we can just allow append(
PreparedFilterToSQL ) which can grab the sql and object values
This split also results in some strange modal code that could be very fragile
and hard to document:
{code}
SQLDialect dialect = getDataStore().getSQLDialect();
if ( dialect instanceof PreparedStatementSQLDialect ) {
PreparedStatement ps = getDataStore().selectSQLPS(querySchema,
preQuery, cx);
reader = new JDBCFeatureReader( ps, cx, this, querySchema,
query.getHints() );
} else {
//build up a statement for the content
String sql = getDataStore().selectSQL(querySchema, preQuery);
getDataStore().getLogger().fine(sql);
reader = new JDBCFeatureReader( sql, cx, this, querySchema,
query.getHints() );
}
{code}
Do we need two super classes here? One for prepared statements and on for
normal statements? There is a chance we use the SQL class to sort this outL
{code}
SQLDialect dialect = getDataStore().getSQLDialect();
SQL sql = new SQL( dialect );
sql = selectSQL( querySchema, preQuery, cx, sql ); // would build
onto an existing SQL if being used to build aggregation function
if( sql.isPreparedStatement() ){
PreparedStatement ps = sql.toPreparedStatement( cx );
reader = new JDBCFeatureReader( ps, cx, this, querySchema,
query.getHints() );
} else {
// build up a statement for the content
getDataStore().getLogger().fine(sql);
reader = new JDBCFeatureReader( sql.toSQL(), cx, this,
querySchema, query.getHints() );
}
{code}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables
unlimited royalty-free distribution of the report engine
for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel