Hi all,

I have run into a situation where it would be nice to have the jdbc sql
encoders to be moved over to the geoapi FilterVisitor interface, instead
of implementing the old interface and having the FilterVisitorWrapper be
used for backwards compatability.

First the problem:

Consider the following BinaryOperator:

<PropertyIsEqualTo>
  <PropertyName>boolProperty</PropertyName>
  <Literal>1</Literal>
</PropertyIsEqualTo>

The problem with the current system is that we end up with an sql
statement like this:

WHERE boolProperty = '1'.

Which fails for postgres, other databases may be able to convert. What I
would like to do is have the context of the type around while encoding
the literal "1". In this case know that I am encoding a boolean so be
able to convert "1" to Boolean.TRUE.

Half the battle has already been won. With the Converter interface the
literal "1" can be easily converted to a boolean with the context
Boolean.class.

However, the problem is that individual elements of the filter are
encoded in isolation so I have no way of knowing that the literal is
being compared to a boolean at the end of the day.

So... onto my proposal. This may be something that falls into our new
process of needing a wiki page as it effects many modules ( every jdbc
datastore ).

The geoapi FilterVisitor uses the "extraData" parameter in all visit
methods to provide extra context to visitors. For instance:

visit( Literal, Object extraData );

This would solve the problem nicely, as I could pass in the type of the
literal as extra data. So the "visit( PropertyIsEqualTo equalTo )"
method of SQLEncoder would look something like:

Object visit( PropertyIsEqualTo equalTo, Object extraData ) {

  Expression left = equalTo.getExpression1();
  Expression right = equalTo.getExpression2();

  //encode left hand side
  left.visit( this, extraData );

  //check for PropertyName to get the type
  Object hint = null;
  if ( left intsanceof PropertyName ) {
    //evaluate against the feature type to get the class
    hint = (Class) left.evaluate( featureType );
  }

  //encode the right, passing in the hint
  right.visit( this, hint );
}

And then "visit( Literal, Object extraData )" would look like:

Object visit( Literal literal, Object extraData ) {
  Object value = null;
  if ( data instanceof Class ) {
    //evaluate in context of type
    value = literal.evaluate( null, (Class) extraData );
  }
  else {
    //just evaluate
    value = literal.evaluate( null );
  }

  //encoding the literal
  ...
}

I have cc'd all active jdbc module maintainers for feedback.

-Justin

-- 
Justin Deoliveira
[EMAIL PROTECTED]
The Open Planning Project
http://topp.openplans.org

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to