Comments (8)
I think we need to add two abstractions RowHandler
and ColumnHandler
. They would work like this:
ResultSetHandler#process(ResultSet)
loops over each row:
call RowHandler#process(ResultSet)
RowHandler#process(ResultSet)
loops over each column:
call ColumnHandler#process(ResultSet, int)
call Converter#convert(Object)
call Setter#setProperty(Object, Object)
This would need to be fleshed out a bit, but would mean we have 5 overall components:
ResultSetHandler -> RowHandler -> ColumnHandler -> Converter -> Setter
If we supply standard implementations for those, and allow users to plug in to any stage, that should cover everything. The stuff you are asking about would be a custom ColumnHandler
. But we might even be able to handle it in the default handler, because it could try to call the appropriate ResultSet#get
method based on the property type, and fall back to ResultSet#getObject
.
Thoughts?
from sql2o.
So you propose to rename ResultSetHandler to RowHandler?
As for converter I'm not shure it's a requred part of ColumnHandler. ColumnHandler can call directrly Resultset.getInt for example to avoid unnecessary boxing and unboxing
from sql2o.
talking about http://commons.apache.org/proper/commons-dbutils/apidocs/org/apache/commons/dbutils/RowProcessor.html - it's not a good abstraction api example.
plain different ResultSetHandler's can cover all of it:
ResultSetHandler<Map<String,Object>>
ResultSetHandler<Object[]>
ResultSetHandler<MyBean>
ResultSetHandler must process one ResultSetRow per-call
You can reuse ResultSetHandler for
- iterating over resultset to convert it anything you want (get rid of other IteratingresultSetImplementations)
- create collection from resultSet
- obtain first line from resultSet
from sql2o.
btw. you can feed sql2o ResultSetHandler to ApacheDbUtils (via simplest adapter)
you can reuse ApacheDbUtils handlers into sql2o (same way via simplest adapter)
maybe just reuse ApacheDbUtils ResultSetHandler as-is (to avoid dependency we can create same interface in sql2o project but in same package)
from sql2o.
Ah I didn't realize what ResultSetHandler was doing, sorry. I thought it was handling the entire ResultSet but it's just handling one row, and the ResultSetIterator is handling the entire ResultSet. That seems good to me.
Yes you are right about the Converter, so I think the overall picture should be:
ResultSetIterator -> ResultSetHandler -> ColumnHandler -> Setter
However in this case, ColumnHandler
would be very similar to the current Converter
, but would allow more flexibility. Instead of:
public interface Converter<T> {
T convert(Object val) throws ConverterException;
}
It would be:
public interface ColumnHandler<T> {
T process(ResultSet rs, int colIdx) throws ConverterException;
}
The IntegerColumnHandler could just call rs.getInt, and the DateTimeColumnHandler (joda) could call rs.getObject and then construct a DateTime, etc.
Users could register a ColumnHandler for different property types, just like they currently register Converters. Also this would be a completely breaking change, so it would have to be a 2.0 release.
from sql2o.
Actually for backwards compatibility, we could keep the existing Converter
interface, and have a DefaultColumnHandler
that calls rs.getObject
and then uses a converter if one exists
from sql2o.
the question is: does we really need backwards compatibility?
2014-04-07 19:10 GMT+04:00 Alden Quimby [email protected]:
Actually for backwards compatibility, we could keep the existing Converterinterface, and have a
DefaultColumnHandler that calls rs.getObject and then uses a converter if
one existsReply to this email directly or view it on GitHubhttps://github.com//issues/77#issuecomment-39742426
.
from sql2o.
@aaberg would have to make that call, but I would say we should shoot for
backwards compatibility for one version and mark things deprecated. Then
remove deprecated things in a following release.
Maybe not though if it's a 2.0 release and we add good documentation on how
to upgrade
On Monday, April 7, 2014, dimzon [email protected] wrote:
the question is: does we really need backwards compatibility?
2014-04-07 19:10 GMT+04:00 Alden Quimby <[email protected]javascript:_e(%7B%7D,'cvml','[email protected]');
:
Actually for backwards compatibility, we could keep the existing
Converterinterface, and have a
DefaultColumnHandler that calls rs.getObject and then uses a converter if
one existsReply to this email directly or view it on GitHub<
https://github.com/aaberg/sql2o/issues/77#issuecomment-39742426>
.Reply to this email directly or view it on GitHubhttps://github.com//issues/77#issuecomment-39757924
.
from sql2o.
Related Issues (20)
- Issue with ArrayParameters.updateQueryWithArrayParameters when query contains '?' character
- When in jar file I receive No suitable driver for error HOT 1
- Publish version 1.6.0 of oracle extensions
- sql2o can't rolback ? HOT 3
- can i change the Type of return value of executeAndFetch()
- State of the Project
- NPE when return query object is of type Map HOT 1
- How to correctly insert with array type (ex bigint[]) columns?
- Library uses now-private reflection mechanism HOT 2
- Can't add ON DELETE CASCADE to forein key when creating table, using PostgreSQL. HOT 1
- Updated MySQL 8.0.26 connector breaks historically working code HOT 2
- Next release HOT 2
- MethodSetter setProperty failing with generic IllegalArgumentException
- Failed test testAllTypes(org.sql2o.reflect.ReflectionFieldSetterFactoryTest) only in Maven HOT 2
- Collection of enums is not properly mapped to query params HOT 1
- SQL2o 1.6.0 Compatabile with JDK 17/ OpenJDK 17 ? HOT 1
- SQL with ? for parameters HOT 4
- Retrieving List<Long> from query HOT 2
- Query.withParams upgrade HOT 2
- Javadoc has an issue with the CDN HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sql2o.