|
From: Dmitriy K. <dko...@ru...> - 2004-02-16 15:54:58
|
+1 for removing it=2E I beilive I=27ve discussed the removal with Rod a l= ong time ago=2E=2E=2E ----- Original Message ----- From=3A j=C3=BCrgen h=C3=B6ller =5Bwerk3AT=5D =3Cjuergen=2Ehoeller=40werk= 3at=2Ecom=3E Date=3A Monday=2C February 16=2C 2004 10=3A45 am Subject=3A =5BSpringframework-developer=5D JdbcHelper =3E Does anyone object to getting rid of JdbcHelper=3F I actually wanted = =3E to suggest this before RC1=2C but I=27m inclined to still move it to = =3E the sandbox at this point of time=2C as it=27s undocumented and not = =3E used within the framework=2E =3E = =3E I simply don=27t see the point in JdbcHelper=3A All you can do there = =3E can easily be built with JdbcTemplate or JDBC operation objects - = =3E and should be built that way=2E We shouldn=27t offer an unnecessarily= = =3E large number of ways to do things=2C particularly not via static = =3E utility methods=2E =3E = =3E Juergen =3E = =3E = =3E DI J=C3=BCrgen H=C3=B6ller =3E Senior System Architect =3E =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F =3E = =3E werk3ATS - division systementwicklung =3E werk3AT informations- und mediensysteme =3E = =3E europaplatz 4 =3E A - 4020 linz =3E = =3E t=2E +43 (0) 732 71 65 29 502 =3E f=2E +43 (0) 732 71 65 29 3 =3E juergen=2Ehoeller=40werk3at=2Ecom =3E http=3A//www=2Ewerk3at=2Ecom =3E =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F =3E werk3ATS - WIR ENTWICKELN ERFOLG =3E = =3E = =3E ------------------------------------------------------- =3E SF=2ENet is sponsored by=3A Speed Start Your Linux Apps Now=2E =3E Build and deploy apps =26 Web services for Linux with =3E a free DVD software kit from IBM=2E Click Now! =3E http=3A//ads=2Eosdn=2Ecom/=3Fad=5Fid=1356=26alloc=5Fid438=26op=3Dclic= k =3E =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F =3E Springframework-developer mailing list =3E Springframework-developer=40lists=2Esourceforge=2Enet =3E https=3A//lists=2Esourceforge=2Enet/lists/listinfo/springframework-de= veloper =3E |
|
From: <rod...@in...> - 2004-02-16 16:45:41
|
I've actually just (yesterday) introduced into into a whole bunch of test cases at a client. Maybe we could put an improved runSQLFunction() method on JdbcTemplate? This is a very convenient one-liner, and basically the only reason I use JdbcTemplate. Regards, Rod |
|
From: <tri...@tr...> - 2004-02-16 17:30:40
|
I can see the need to go beyond a single row/value type query.
How about a new method for the JdbcTemplate:
Object runSqlStatement(String)
Based on the type of SQL passed in it would return:
1) An Integer containing the number of rows affected if it is an update statement
runSqlStatement("update emp set salary = salary * 1.5") would return an Integer
with the update count
2) A single Object (Integer/Long/String) based on the value returned from a
single value/single row query
runSqlStatement("select last_name frmo emp where id = 2") would return a String
containing the last name
3) An ArrayList of ArrayLists containing a list of rows with a list of column
values returned by the query
runSqlStatement("selecy id, last_name from emp") would return an ArrayList
containing an ArrayList for each row. The second list would contain an Integer
with the id and a String with the last_name.
Number 3 might be a stretch, but we would still have to check for this, since we
have no control over the SQL coming in.
Thomas
Quoting rod...@in...:
> I've actually just (yesterday) introduced into into a whole
> bunch of test cases at a client. Maybe we could put an
> improved runSQLFunction() method on JdbcTemplate? This is a
> very convenient one-liner, and basically the only reason I
> use JdbcTemplate.
>
> Regards,
> Rod
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
|
|
From: Rod J. <rod...@in...> - 2004-02-16 20:34:02
|
Thomas,
Sounds great. With this there I'd be glad to get rid of JdbcHelper.
Not sure about (3). I think this needs further thought. For 1.1 we could add
a true disconnected result set: not RowSet as it throws SQLException, which
we want to get away from.
Also a convenience method returning int would be handy, for counts and the
like. Please can I have this, despite Juergen's dislike of convenience
methods :-)
Regards,
Rod
----- Original Message -----
From: <tri...@tr...>
To: <spr...@li...>
Sent: Monday, February 16, 2004 5:26 PM
Subject: RE: [Springframework-developer] JdbcHelper
> I can see the need to go beyond a single row/value type query.
>
> How about a new method for the JdbcTemplate:
>
> Object runSqlStatement(String)
>
> Based on the type of SQL passed in it would return:
>
> 1) An Integer containing the number of rows affected if it is an update
statement
>
> runSqlStatement("update emp set salary = salary * 1.5") would return an
Integer
> with the update count
>
> 2) A single Object (Integer/Long/String) based on the value returned from
a
> single value/single row query
>
> runSqlStatement("select last_name frmo emp where id = 2") would return a
String
> containing the last name
>
> 3) An ArrayList of ArrayLists containing a list of rows with a list of
column
> values returned by the query
>
> runSqlStatement("selecy id, last_name from emp") would return an ArrayList
> containing an ArrayList for each row. The second list would contain an
Integer
> with the id and a String with the last_name.
>
>
> Number 3 might be a stretch, but we would still have to check for this,
since we
> have no control over the SQL coming in.
>
> Thomas
>
>
> Quoting rod...@in...:
>
> > I've actually just (yesterday) introduced into into a whole
> > bunch of test cases at a client. Maybe we could put an
> > improved runSQLFunction() method on JdbcTemplate? This is a
> > very convenient one-liner, and basically the only reason I
> > use JdbcTemplate.
> >
> > Regards,
> > Rod
> >
> >
> > -------------------------------------------------------
> > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > Build and deploy apps & Web services for Linux with
> > a free DVD software kit from IBM. Click Now!
> > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >
>
>
>
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
|
|
From: <tri...@tr...> - 2004-02-16 21:20:03
|
I have committed the new method to CVS. I will add my local tests to the proper
test class later today or tomorrow (this is a standalone feature so little risk
of breaking any other functionality). This might actually turn out to be more
of a test of MockObjects than real code, but it will at least outline expected
functionality.
I ended up implementing (3) as an ArrayList of HashMaps using the column name as
key. We could replace this with a disconnected rowset in the future.
I'll think about the convenience method - is "int" sufficient?
Here is an example:
DriverManagerDataSource ds = new DriverManagerDataSource();
ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
ds.setUrl("jdbc:oracle:thin:@localhost:1521:ORCL");
ds.setUsername("scott");
ds.setPassword("tiger");
JdbcTemplate jt = new JdbcTemplate(ds);
Object o = jt.runSqlStatement("select * from emp");
System.out.println(o.getClass().getName());
System.out.println(o);
java.util.ArrayList
[{SAL=800, HIREDATE=1980-12-17 00:00:00.0, COMM=null, EMPNO=7369, JOB=CLERK,
DEPTNO=20, MGR=7902, ENAME=SMITH}, {SAL=1600, HIREDATE=1981-02-20 00:00:00.0,
COMM=300, EMPNO=7499, JOB=SALESMAN, DEPTNO=30, MGR=7698, ENAME=ALLEN},
{SAL=1250, HIREDATE=1981-02-22 00:00:00.0, COMM=500, EMPNO=7521, JOB=SALESMAN,
DEPTNO=30, MGR=7698, ENAME=WARD}, {SAL=2975, HIREDATE=1981-04-02 00:00:00.0,
COMM=null, EMPNO=7566, JOB=MANAGER, DEPTNO=20, MGR=7839, ENAME=JONES},
{SAL=1250, HIREDATE=1981-09-28 00:00:00.0, COMM=1400, EMPNO=7654, JOB=SALESMAN,
DEPTNO=30, MGR=7698, ENAME=MARTIN}, {SAL=2850, HIREDATE=1981-05-01 00:00:00.0,
COMM=null, EMPNO=7698, JOB=MANAGER, DEPTNO=30, MGR=7839, ENAME=BLAKE},
{SAL=2450, HIREDATE=1981-06-09 00:00:00.0, COMM=null, EMPNO=7782, JOB=MANAGER,
DEPTNO=10, MGR=7839, ENAME=CLARK}, {SAL=3000, HIREDATE=1987-04-19 00:00:00.0,
COMM=null, EMPNO=7788, JOB=ANALYST, DEPTNO=20, MGR=7566, ENAME=SCOTT},
{SAL=5000, HIREDATE=1981-11-17 00:00:00.0, COMM=null, EMPNO=7839, JOB=PRESIDENT,
DEPTNO=10, MGR=null, ENAME=KING}, {SAL=1500, HIREDATE=1981-09-08 00:00:00.0,
COMM=0, EMPNO=7844, JOB=SALESMAN, DEPTNO=30, MGR=7698, ENAME=TURNER}, {SAL=1100,
HIREDATE=1987-05-23 00:00:00.0, COMM=null, EMPNO=7876, JOB=CLERK, DEPTNO=20,
MGR=7788, ENAME=ADAMS}, {SAL=950, HIREDATE=1981-12-03 00:00:00.0, COMM=null,
EMPNO=7900, JOB=CLERK, DEPTNO=30, MGR=7698, ENAME=JAMES}, {SAL=3000,
HIREDATE=1981-12-03 00:00:00.0, COMM=null, EMPNO=7902, JOB=ANALYST, DEPTNO=20,
MGR=7566, ENAME=FORD}, {SAL=1300, HIREDATE=1982-01-23 00:00:00.0, COMM=null,
EMPNO=7934, JOB=CLERK, DEPTNO=10, MGR=7782, ENAME=MILLER}]
Thomas
Quoting Rod Johnson <rod...@in...>:
> Thomas,
>
> Sounds great. With this there I'd be glad to get rid of JdbcHelper.
>
> Not sure about (3). I think this needs further thought. For 1.1 we could add
> a true disconnected result set: not RowSet as it throws SQLException, which
> we want to get away from.
>
> Also a convenience method returning int would be handy, for counts and the
> like. Please can I have this, despite Juergen's dislike of convenience
> methods :-)
>
> Regards,
> Rod
>
> ----- Original Message -----
> From: <tri...@tr...>
> To: <spr...@li...>
> Sent: Monday, February 16, 2004 5:26 PM
> Subject: RE: [Springframework-developer] JdbcHelper
>
>
> > I can see the need to go beyond a single row/value type query.
> >
> > How about a new method for the JdbcTemplate:
> >
> > Object runSqlStatement(String)
> >
> > Based on the type of SQL passed in it would return:
> >
> > 1) An Integer containing the number of rows affected if it is an update
> statement
> >
> > runSqlStatement("update emp set salary = salary * 1.5") would return an
> Integer
> > with the update count
> >
> > 2) A single Object (Integer/Long/String) based on the value returned from
> a
> > single value/single row query
> >
> > runSqlStatement("select last_name frmo emp where id = 2") would return a
> String
> > containing the last name
> >
> > 3) An ArrayList of ArrayLists containing a list of rows with a list of
> column
> > values returned by the query
> >
> > runSqlStatement("selecy id, last_name from emp") would return an ArrayList
> > containing an ArrayList for each row. The second list would contain an
> Integer
> > with the id and a String with the last_name.
> >
> >
> > Number 3 might be a stretch, but we would still have to check for this,
> since we
> > have no control over the SQL coming in.
> >
> > Thomas
> >
> >
> > Quoting rod...@in...:
> >
> > > I've actually just (yesterday) introduced into into a whole
> > > bunch of test cases at a client. Maybe we could put an
> > > improved runSQLFunction() method on JdbcTemplate? This is a
> > > very convenient one-liner, and basically the only reason I
> > > use JdbcTemplate.
> > >
> > > Regards,
> > > Rod
> > >
> > >
> > > -------------------------------------------------------
> > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > Build and deploy apps & Web services for Linux with
> > > a free DVD software kit from IBM. Click Now!
> > > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > > _______________________________________________
> > > Springframework-developer mailing list
> > > Spr...@li...
> > > https://lists.sourceforge.net/lists/listinfo/springframework-developer
> > >
> >
> >
> >
> >
> >
> > -------------------------------------------------------
> > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > Build and deploy apps & Web services for Linux with
> > a free DVD software kit from IBM. Click Now!
> > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
|
|
From: Jonathan H. <jh...@ad...> - 2004-02-17 14:20:01
|
Why not establish an interface that extends RowSet?
----- Original Message -----
From: "Rod Johnson" <rod...@in...>
To: <spr...@li...>
Sent: Monday, February 16, 2004 1:30 PM
Subject: Re: [Springframework-developer] JdbcHelper
> Thomas,
>
> Sounds great. With this there I'd be glad to get rid of JdbcHelper.
>
> Not sure about (3). I think this needs further thought. For 1.1 we could
add
> a true disconnected result set: not RowSet as it throws SQLException,
which
> we want to get away from.
>
> Also a convenience method returning int would be handy, for counts and the
> like. Please can I have this, despite Juergen's dislike of convenience
> methods :-)
>
> Regards,
> Rod
>
> ----- Original Message -----
> From: <tri...@tr...>
> To: <spr...@li...>
> Sent: Monday, February 16, 2004 5:26 PM
> Subject: RE: [Springframework-developer] JdbcHelper
>
>
> > I can see the need to go beyond a single row/value type query.
> >
> > How about a new method for the JdbcTemplate:
> >
> > Object runSqlStatement(String)
> >
> > Based on the type of SQL passed in it would return:
> >
> > 1) An Integer containing the number of rows affected if it is an update
> statement
> >
> > runSqlStatement("update emp set salary = salary * 1.5") would return an
> Integer
> > with the update count
> >
> > 2) A single Object (Integer/Long/String) based on the value returned
from
> a
> > single value/single row query
> >
> > runSqlStatement("select last_name frmo emp where id = 2") would return a
> String
> > containing the last name
> >
> > 3) An ArrayList of ArrayLists containing a list of rows with a list of
> column
> > values returned by the query
> >
> > runSqlStatement("selecy id, last_name from emp") would return an
ArrayList
> > containing an ArrayList for each row. The second list would contain an
> Integer
> > with the id and a String with the last_name.
> >
> >
> > Number 3 might be a stretch, but we would still have to check for this,
> since we
> > have no control over the SQL coming in.
> >
> > Thomas
> >
> >
> > Quoting rod...@in...:
> >
> > > I've actually just (yesterday) introduced into into a whole
> > > bunch of test cases at a client. Maybe we could put an
> > > improved runSQLFunction() method on JdbcTemplate? This is a
> > > very convenient one-liner, and basically the only reason I
> > > use JdbcTemplate.
> > >
> > > Regards,
> > > Rod
> > >
> > >
> > > -------------------------------------------------------
> > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > Build and deploy apps & Web services for Linux with
> > > a free DVD software kit from IBM. Click Now!
> > > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > > _______________________________________________
> > > Springframework-developer mailing list
> > > Spr...@li...
> > > https://lists.sourceforge.net/lists/listinfo/springframework-developer
> > >
> >
> >
> >
> >
> >
> > -------------------------------------------------------
> > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > Build and deploy apps & Web services for Linux with
> > a free DVD software kit from IBM. Click Now!
> > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
|
|
From: <jue...@we...> - 2004-02-16 19:10:06
|
Thomas,
=20
That sounds excellent: simple and intuitive. +1 for implementing it that =
way!
=20
Do you have a chance to implement this within the 1.0 timeframe, i.e. =
ASAP? I'd really like to drop JdbcHelper for 1.0 final.
=20
Juergen
=20
________________________________
Von: spr...@li... im Auftrag =
von tri...@tr...
Gesendet: Mo 16.02.2004 18:26
An: spr...@li...
Betreff: RE: [Springframework-developer] JdbcHelper
I can see the need to go beyond a single row/value type query.
How about a new method for the JdbcTemplate:
Object runSqlStatement(String)
Based on the type of SQL passed in it would return:
1) An Integer containing the number of rows affected if it is an update =
statement
runSqlStatement("update emp set salary =3D salary * 1.5") would return =
an Integer
with the update count
2) A single Object (Integer/Long/String) based on the value returned =
from a
single value/single row query
runSqlStatement("select last_name frmo emp where id =3D 2") would return =
a String
containing the last name
3) An ArrayList of ArrayLists containing a list of rows with a list of =
column
values returned by the query
runSqlStatement("selecy id, last_name from emp") would return an =
ArrayList
containing an ArrayList for each row. The second list would contain an =
Integer
with the id and a String with the last_name.
Number 3 might be a stretch, but we would still have to check for this, =
since we
have no control over the SQL coming in.
Thomas
Quoting rod...@in...:
> I've actually just (yesterday) introduced into into a whole
> bunch of test cases at a client. Maybe we could put an
> improved runSQLFunction() method on JdbcTemplate? This is a
> very convenient one-liner, and basically the only reason I
> use JdbcTemplate.
>
> Regards,
> Rod
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=3D1356&alloc_id=3D3438&op=3Dclick
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=3D1356&alloc_id=3D3438&op=3Dclick
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|
|
From: <jue...@we...> - 2004-02-17 17:15:56
|
I've reviewed the code, and I think it's good that we're addressing this =
in JdbcTemplate itself. However, on second thought, it seems confusing =
to have a runSqlStatement method that executes either a query or update, =
with a multitude of possible result semantics. Thus, I've refactored =
this into overloaded query/queryForList/queryForObject/queryForInt =
methods.
I've also added corresponding queryXxx and update methods that work with =
PreparedStatements, taking an Object[] (and optionally a int[] array for =
the SQL types) as arguments that get bound to the PreparedStatement. =
This effectively offers some of the conveniences of SqlQuery's find =
methods in JdbcTemplate itself; I think that's a valuable addition.
Furthermore, I've put the new methods in JdbcOperations. In the course =
of this, I've dropped doWithResultFromXxx methods from the =
JdbcOperations interface: This is not something to be used on a regular =
basis, thus I guess it's enough to make them available in JdbcTemplate =
itself. This completely avoids the need to refer to the =
ResultSetExtractor interface in the JdbcOperations interface.
As a further minor change, I've allowed ResultSetExtractor to return an =
arbitrary result object. The doWithResultFromXxx methods simply pass =
this through. The new queryForList/queryForObject/queryForInt methods =
are more elegant to implement with this. Finally, I've also moved =
ColumnExtractor and DefaultColumnExtractor to the sandbox: They were =
just used by JdbcHelper.
(to be committed in about half an hour)
Juergen
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...]On Behalf
Of tri...@tr...
Sent: Monday, February 16, 2004 10:16 PM
To: spr...@li...
Subject: Re: [Springframework-developer] JdbcHelper
I have committed the new method to CVS. I will add my local tests to =
the proper
test class later today or tomorrow (this is a standalone feature so =
little risk
of breaking any other functionality). This might actually turn out to =
be more
of a test of MockObjects than real code, but it will at least outline =
expected
functionality.
I ended up implementing (3) as an ArrayList of HashMaps using the column =
name as
key. We could replace this with a disconnected rowset in the future.
I'll think about the convenience method - is "int" sufficient?
Here is an example:
DriverManagerDataSource ds =3D new DriverManagerDataSource();
ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
ds.setUrl("jdbc:oracle:thin:@localhost:1521:ORCL");
ds.setUsername("scott");
ds.setPassword("tiger");
JdbcTemplate jt =3D new JdbcTemplate(ds);
Object o =3D jt.runSqlStatement("select * from emp");
System.out.println(o.getClass().getName());
System.out.println(o);
java.util.ArrayList
[{SAL=3D800, HIREDATE=3D1980-12-17 00:00:00.0, COMM=3Dnull, =
EMPNO=3D7369, JOB=3DCLERK,
DEPTNO=3D20, MGR=3D7902, ENAME=3DSMITH}, {SAL=3D1600, =
HIREDATE=3D1981-02-20 00:00:00.0,
COMM=3D300, EMPNO=3D7499, JOB=3DSALESMAN, DEPTNO=3D30, MGR=3D7698, =
ENAME=3DALLEN},
{SAL=3D1250, HIREDATE=3D1981-02-22 00:00:00.0, COMM=3D500, EMPNO=3D7521, =
JOB=3DSALESMAN,
DEPTNO=3D30, MGR=3D7698, ENAME=3DWARD}, {SAL=3D2975, =
HIREDATE=3D1981-04-02 00:00:00.0,
COMM=3Dnull, EMPNO=3D7566, JOB=3DMANAGER, DEPTNO=3D20, MGR=3D7839, =
ENAME=3DJONES},
{SAL=3D1250, HIREDATE=3D1981-09-28 00:00:00.0, COMM=3D1400, =
EMPNO=3D7654, JOB=3DSALESMAN,
DEPTNO=3D30, MGR=3D7698, ENAME=3DMARTIN}, {SAL=3D2850, =
HIREDATE=3D1981-05-01 00:00:00.0,
COMM=3Dnull, EMPNO=3D7698, JOB=3DMANAGER, DEPTNO=3D30, MGR=3D7839, =
ENAME=3DBLAKE},
{SAL=3D2450, HIREDATE=3D1981-06-09 00:00:00.0, COMM=3Dnull, =
EMPNO=3D7782, JOB=3DMANAGER,
DEPTNO=3D10, MGR=3D7839, ENAME=3DCLARK}, {SAL=3D3000, =
HIREDATE=3D1987-04-19 00:00:00.0,
COMM=3Dnull, EMPNO=3D7788, JOB=3DANALYST, DEPTNO=3D20, MGR=3D7566, =
ENAME=3DSCOTT},
{SAL=3D5000, HIREDATE=3D1981-11-17 00:00:00.0, COMM=3Dnull, =
EMPNO=3D7839, JOB=3DPRESIDENT,
DEPTNO=3D10, MGR=3Dnull, ENAME=3DKING}, {SAL=3D1500, =
HIREDATE=3D1981-09-08 00:00:00.0,
COMM=3D0, EMPNO=3D7844, JOB=3DSALESMAN, DEPTNO=3D30, MGR=3D7698, =
ENAME=3DTURNER}, {SAL=3D1100,
HIREDATE=3D1987-05-23 00:00:00.0, COMM=3Dnull, EMPNO=3D7876, =
JOB=3DCLERK, DEPTNO=3D20,
MGR=3D7788, ENAME=3DADAMS}, {SAL=3D950, HIREDATE=3D1981-12-03 =
00:00:00.0, COMM=3Dnull,
EMPNO=3D7900, JOB=3DCLERK, DEPTNO=3D30, MGR=3D7698, ENAME=3DJAMES}, =
{SAL=3D3000,
HIREDATE=3D1981-12-03 00:00:00.0, COMM=3Dnull, EMPNO=3D7902, =
JOB=3DANALYST, DEPTNO=3D20,
MGR=3D7566, ENAME=3DFORD}, {SAL=3D1300, HIREDATE=3D1982-01-23 =
00:00:00.0, COMM=3Dnull,
EMPNO=3D7934, JOB=3DCLERK, DEPTNO=3D10, MGR=3D7782, ENAME=3DMILLER}]
Thomas
Quoting Rod Johnson <rod...@in...>:
> Thomas,
>=20
> Sounds great. With this there I'd be glad to get rid of JdbcHelper.
>=20
> Not sure about (3). I think this needs further thought. For 1.1 we =
could add
> a true disconnected result set: not RowSet as it throws SQLException, =
which
> we want to get away from.
>=20
> Also a convenience method returning int would be handy, for counts and =
the
> like. Please can I have this, despite Juergen's dislike of convenience
> methods :-)
>=20
> Regards,
> Rod
>=20
> ----- Original Message -----
> From: <tri...@tr...>
> To: <spr...@li...>
> Sent: Monday, February 16, 2004 5:26 PM
> Subject: RE: [Springframework-developer] JdbcHelper
>=20
>=20
> > I can see the need to go beyond a single row/value type query.
> >
> > How about a new method for the JdbcTemplate:
> >
> > Object runSqlStatement(String)
> >
> > Based on the type of SQL passed in it would return:
> >
> > 1) An Integer containing the number of rows affected if it is an =
update
> statement
> >
> > runSqlStatement("update emp set salary =3D salary * 1.5") would =
return an
> Integer
> > with the update count
> >
> > 2) A single Object (Integer/Long/String) based on the value returned =
from
> a
> > single value/single row query
> >
> > runSqlStatement("select last_name frmo emp where id =3D 2") would =
return a
> String
> > containing the last name
> >
> > 3) An ArrayList of ArrayLists containing a list of rows with a list =
of
> column
> > values returned by the query
> >
> > runSqlStatement("selecy id, last_name from emp") would return an =
ArrayList
> > containing an ArrayList for each row. The second list would contain =
an
> Integer
> > with the id and a String with the last_name.
> >
> >
> > Number 3 might be a stretch, but we would still have to check for =
this,
> since we
> > have no control over the SQL coming in.
> >
> > Thomas
> >
> >
> > Quoting rod...@in...:
> >
> > > I've actually just (yesterday) introduced into into a whole
> > > bunch of test cases at a client. Maybe we could put an
> > > improved runSQLFunction() method on JdbcTemplate? This is a
> > > very convenient one-liner, and basically the only reason I
> > > use JdbcTemplate.
> > >
> > > Regards,
> > > Rod
> > >
> > >
> > > -------------------------------------------------------
> > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > Build and deploy apps & Web services for Linux with
> > > a free DVD software kit from IBM. Click Now!
> > > http://ads.osdn.com/?ad_id=3D1356&alloc_id=3D3438&op=3Dclick
> > > _______________________________________________
> > > Springframework-developer mailing list
> > > Spr...@li...
> > > =
https://lists.sourceforge.net/lists/listinfo/springframework-developer
> > >
> >
> >
> >
> >
> >
> > -------------------------------------------------------
> > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > Build and deploy apps & Web services for Linux with
> > a free DVD software kit from IBM. Click Now!
> > http://ads.osdn.com/?ad_id=3D1356&alloc_id=3D3438&op=3Dclick
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > =
https://lists.sourceforge.net/lists/listinfo/springframework-developer
>=20
>=20
>=20
>=20
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=3D1356&alloc_id=3D3438&op=3Dclick
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>=20
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=3D1356&alloc_id=3D3438&op=3Dclick
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|
|
From: <tri...@tr...> - 2004-02-17 19:06:28
|
I like the changes - the new method names fit better with the rest of the
JdbcTemplate and Rod got his convenience 'int' method. Unfortunaltely it did
not work to well for Oracle since getObject() maps a NUMERIC to
java.math.BigDecimal. I added an explicit new Integer(getInt()) when the target
is an Integer and the result looks like it could be an integer (NUMERIC,
INTEGER, SMALLINT, TINYINT).
These all work for Oracle:
int i1 = jt.queryForInt("select count(*) from emp");
Object o2 = jt.queryForObject("select sysdate from dual", java.util.Date.class);
Object o3 = jt.queryForObject("select to_number('12.456', '9999.999') from
dual", Number.class);
Object o4 = jt.queryForList("select * from emp");
Quoting "jürgen höller [werk3AT]" <jue...@we...>:
> I've reviewed the code, and I think it's good that we're addressing this =
> in JdbcTemplate itself. However, on second thought, it seems confusing =
> to have a runSqlStatement method that executes either a query or update, =
> with a multitude of possible result semantics. Thus, I've refactored =
> this into overloaded query/queryForList/queryForObject/queryForInt =
> methods.
>
> I've also added corresponding queryXxx and update methods that work with =
> PreparedStatements, taking an Object[] (and optionally a int[] array for =
> the SQL types) as arguments that get bound to the PreparedStatement. =
> This effectively offers some of the conveniences of SqlQuery's find =
> methods in JdbcTemplate itself; I think that's a valuable addition.
>
> Furthermore, I've put the new methods in JdbcOperations. In the course =
> of this, I've dropped doWithResultFromXxx methods from the =
> JdbcOperations interface: This is not something to be used on a regular =
> basis, thus I guess it's enough to make them available in JdbcTemplate =
> itself. This completely avoids the need to refer to the =
> ResultSetExtractor interface in the JdbcOperations interface.
>
> As a further minor change, I've allowed ResultSetExtractor to return an =
> arbitrary result object. The doWithResultFromXxx methods simply pass =
> this through. The new queryForList/queryForObject/queryForInt methods =
> are more elegant to implement with this. Finally, I've also moved =
> ColumnExtractor and DefaultColumnExtractor to the sandbox: They were =
> just used by JdbcHelper.
>
> (to be committed in about half an hour)
>
> Juergen
>
>
> -----Original Message-----
> From: spr...@li...
> [mailto:spr...@li...]On Behalf
> Of tri...@tr...
> Sent: Monday, February 16, 2004 10:16 PM
> To: spr...@li...
> Subject: Re: [Springframework-developer] JdbcHelper
>
>
>
> I have committed the new method to CVS. I will add my local tests to =
> the proper
> test class later today or tomorrow (this is a standalone feature so =
> little risk
> of breaking any other functionality). This might actually turn out to =
> be more
> of a test of MockObjects than real code, but it will at least outline =
> expected
> functionality.
>
> I ended up implementing (3) as an ArrayList of HashMaps using the column =
> name as
> key. We could replace this with a disconnected rowset in the future.
>
> I'll think about the convenience method - is "int" sufficient?
>
> Here is an example:
>
> DriverManagerDataSource ds =3D new DriverManagerDataSource();
> ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
> ds.setUrl("jdbc:oracle:thin:@localhost:1521:ORCL");
> ds.setUsername("scott");
> ds.setPassword("tiger");
> JdbcTemplate jt =3D new JdbcTemplate(ds);
> Object o =3D jt.runSqlStatement("select * from emp");
> System.out.println(o.getClass().getName());
> System.out.println(o);
>
> java.util.ArrayList
> [{SAL=3D800, HIREDATE=3D1980-12-17 00:00:00.0, COMM=3Dnull, =
> EMPNO=3D7369, JOB=3DCLERK,
> DEPTNO=3D20, MGR=3D7902, ENAME=3DSMITH}, {SAL=3D1600, =
> HIREDATE=3D1981-02-20 00:00:00.0,
> COMM=3D300, EMPNO=3D7499, JOB=3DSALESMAN, DEPTNO=3D30, MGR=3D7698, =
> ENAME=3DALLEN},
> {SAL=3D1250, HIREDATE=3D1981-02-22 00:00:00.0, COMM=3D500, EMPNO=3D7521, =
> JOB=3DSALESMAN,
> DEPTNO=3D30, MGR=3D7698, ENAME=3DWARD}, {SAL=3D2975, =
> HIREDATE=3D1981-04-02 00:00:00.0,
> COMM=3Dnull, EMPNO=3D7566, JOB=3DMANAGER, DEPTNO=3D20, MGR=3D7839, =
> ENAME=3DJONES},
> {SAL=3D1250, HIREDATE=3D1981-09-28 00:00:00.0, COMM=3D1400, =
> EMPNO=3D7654, JOB=3DSALESMAN,
> DEPTNO=3D30, MGR=3D7698, ENAME=3DMARTIN}, {SAL=3D2850, =
> HIREDATE=3D1981-05-01 00:00:00.0,
> COMM=3Dnull, EMPNO=3D7698, JOB=3DMANAGER, DEPTNO=3D30, MGR=3D7839, =
> ENAME=3DBLAKE},
> {SAL=3D2450, HIREDATE=3D1981-06-09 00:00:00.0, COMM=3Dnull, =
> EMPNO=3D7782, JOB=3DMANAGER,
> DEPTNO=3D10, MGR=3D7839, ENAME=3DCLARK}, {SAL=3D3000, =
> HIREDATE=3D1987-04-19 00:00:00.0,
> COMM=3Dnull, EMPNO=3D7788, JOB=3DANALYST, DEPTNO=3D20, MGR=3D7566, =
> ENAME=3DSCOTT},
> {SAL=3D5000, HIREDATE=3D1981-11-17 00:00:00.0, COMM=3Dnull, =
> EMPNO=3D7839, JOB=3DPRESIDENT,
> DEPTNO=3D10, MGR=3Dnull, ENAME=3DKING}, {SAL=3D1500, =
> HIREDATE=3D1981-09-08 00:00:00.0,
> COMM=3D0, EMPNO=3D7844, JOB=3DSALESMAN, DEPTNO=3D30, MGR=3D7698, =
> ENAME=3DTURNER}, {SAL=3D1100,
> HIREDATE=3D1987-05-23 00:00:00.0, COMM=3Dnull, EMPNO=3D7876, =
> JOB=3DCLERK, DEPTNO=3D20,
> MGR=3D7788, ENAME=3DADAMS}, {SAL=3D950, HIREDATE=3D1981-12-03 =
> 00:00:00.0, COMM=3Dnull,
> EMPNO=3D7900, JOB=3DCLERK, DEPTNO=3D30, MGR=3D7698, ENAME=3DJAMES}, =
> {SAL=3D3000,
> HIREDATE=3D1981-12-03 00:00:00.0, COMM=3Dnull, EMPNO=3D7902, =
> JOB=3DANALYST, DEPTNO=3D20,
> MGR=3D7566, ENAME=3DFORD}, {SAL=3D1300, HIREDATE=3D1982-01-23 =
> 00:00:00.0, COMM=3Dnull,
> EMPNO=3D7934, JOB=3DCLERK, DEPTNO=3D10, MGR=3D7782, ENAME=3DMILLER}]
>
> Thomas
>
>
> Quoting Rod Johnson <rod...@in...>:
>
> > Thomas,
> >=20
> > Sounds great. With this there I'd be glad to get rid of JdbcHelper.
> >=20
> > Not sure about (3). I think this needs further thought. For 1.1 we =
> could add
> > a true disconnected result set: not RowSet as it throws SQLException, =
> which
> > we want to get away from.
> >=20
> > Also a convenience method returning int would be handy, for counts and =
> the
> > like. Please can I have this, despite Juergen's dislike of convenience
> > methods :-)
> >=20
> > Regards,
> > Rod
> >=20
> > ----- Original Message -----
> > From: <tri...@tr...>
> > To: <spr...@li...>
> > Sent: Monday, February 16, 2004 5:26 PM
> > Subject: RE: [Springframework-developer] JdbcHelper
> >=20
> >=20
> > > I can see the need to go beyond a single row/value type query.
> > >
> > > How about a new method for the JdbcTemplate:
> > >
> > > Object runSqlStatement(String)
> > >
> > > Based on the type of SQL passed in it would return:
> > >
> > > 1) An Integer containing the number of rows affected if it is an =
> update
> > statement
> > >
> > > runSqlStatement("update emp set salary =3D salary * 1.5") would =
> return an
> > Integer
> > > with the update count
> > >
> > > 2) A single Object (Integer/Long/String) based on the value returned =
> from
> > a
> > > single value/single row query
> > >
> > > runSqlStatement("select last_name frmo emp where id =3D 2") would =
> return a
> > String
> > > containing the last name
> > >
> > > 3) An ArrayList of ArrayLists containing a list of rows with a list =
> of
> > column
> > > values returned by the query
> > >
> > > runSqlStatement("selecy id, last_name from emp") would return an =
> ArrayList
> > > containing an ArrayList for each row. The second list would contain =
> an
> > Integer
> > > with the id and a String with the last_name.
> > >
> > >
> > > Number 3 might be a stretch, but we would still have to check for =
> this,
> > since we
> > > have no control over the SQL coming in.
> > >
> > > Thomas
> > >
> > >
> > > Quoting rod...@in...:
> > >
> > > > I've actually just (yesterday) introduced into into a whole
> > > > bunch of test cases at a client. Maybe we could put an
> > > > improved runSQLFunction() method on JdbcTemplate? This is a
> > > > very convenient one-liner, and basically the only reason I
> > > > use JdbcTemplate.
> > > >
> > > > Regards,
> > > > Rod
> > > >
> > > >
> > > > -------------------------------------------------------
> > > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > > Build and deploy apps & Web services for Linux with
> > > > a free DVD software kit from IBM. Click Now!
> > > > http://ads.osdn.com/?ad_id=3D1356&alloc_id=3D3438&op=3Dclick
> > > > _______________________________________________
> > > > Springframework-developer mailing list
> > > > Spr...@li...
> > > > =
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
> > > >
> > >
> > >
> > >
> > >
> > >
> > > -------------------------------------------------------
> > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > Build and deploy apps & Web services for Linux with
> > > a free DVD software kit from IBM. Click Now!
> > > http://ads.osdn.com/?ad_id=3D1356&alloc_id=3D3438&op=3Dclick
> > > _______________________________________________
> > > Springframework-developer mailing list
> > > Spr...@li...
> > > =
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >=20
> >=20
> >=20
> >=20
> > -------------------------------------------------------
> > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > Build and deploy apps & Web services for Linux with
> > a free DVD software kit from IBM. Click Now!
> > http://ads.osdn.com/?ad_id=3D1356&alloc_id=3D3438&op=3Dclick
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >=20
>
>
>
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=3D1356&alloc_id=3D3438&op=3Dclick
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
|
|
From: <rod...@in...> - 2004-02-17 17:39:04
|
>Finally, I've also moved ColumnExtractor and DefaultColumnExtractor to the sandbox: They were just used by JdbcHelper. Good. These were really intended for a simple reflective mapping approach that never eventuated. iBATIS does that kind of thing well, so we shouldn't reinvent it. |
|
From: <jue...@we...> - 2004-02-17 19:26:42
|
Great! This is really a convenient way to execute simple SQL statements, =
both for update and for query.=20
=20
Allowing for using PreparedStatements without having to implement a =
PreparedStatementSetter is a significant benefit, as is giving easy =
access to simple results, avoiding the need for implementing a =
RowCallbackHandler. int results are worth special support here, as =
aggregate functions (count etc) all have integer results.
=20
I guess this is as good as it gets in a programmatic fashion. For =
declarative statements declarations and declarative parameter and/or =
result mappings, iBATIS SQL Maps is the way to go. Both approaches have =
clear value; it's good to see them both tap their respective full =
potential.
=20
Juergen
=20
________________________________
Von: spr...@li... im Auftrag =
von tri...@tr...
Gesendet: Di 17.02.2004 20:02
An: spr...@li...
Betreff: RE: [Springframework-developer] JdbcHelper
I like the changes - the new method names fit better with the rest of =
the
JdbcTemplate and Rod got his convenience 'int' method. Unfortunaltely =
it did
not work to well for Oracle since getObject() maps a NUMERIC to
java.math.BigDecimal. I added an explicit new Integer(getInt()) when =
the target
is an Integer and the result looks like it could be an integer (NUMERIC,
INTEGER, SMALLINT, TINYINT).
These all work for Oracle:
int i1 =3D jt.queryForInt("select count(*) from emp");
Object o2 =3D jt.queryForObject("select sysdate from dual", =
java.util.Date.class);
Object o3 =3D jt.queryForObject("select to_number('12.456', '9999.999') =
from
dual", Number.class);
Object o4 =3D jt.queryForList("select * from emp");
Quoting "j=FCrgen h=F6ller [werk3AT]" <jue...@we...>:
> I've reviewed the code, and I think it's good that we're addressing =
this =3D
> in JdbcTemplate itself. However, on second thought, it seems confusing =
=3D
> to have a runSqlStatement method that executes either a query or =
update, =3D
> with a multitude of possible result semantics. Thus, I've refactored =
=3D
> this into overloaded query/queryForList/queryForObject/queryForInt =3D
> methods.
>
> I've also added corresponding queryXxx and update methods that work =
with =3D
> PreparedStatements, taking an Object[] (and optionally a int[] array =
for =3D
> the SQL types) as arguments that get bound to the PreparedStatement. =
=3D
> This effectively offers some of the conveniences of SqlQuery's find =
=3D
> methods in JdbcTemplate itself; I think that's a valuable addition.
>
> Furthermore, I've put the new methods in JdbcOperations. In the course =
=3D
> of this, I've dropped doWithResultFromXxx methods from the =3D
> JdbcOperations interface: This is not something to be used on a =
regular =3D
> basis, thus I guess it's enough to make them available in JdbcTemplate =
=3D
> itself. This completely avoids the need to refer to the =3D
> ResultSetExtractor interface in the JdbcOperations interface.
>
> As a further minor change, I've allowed ResultSetExtractor to return =
an =3D
> arbitrary result object. The doWithResultFromXxx methods simply pass =
=3D
> this through. The new queryForList/queryForObject/queryForInt methods =
=3D
> are more elegant to implement with this. Finally, I've also moved =3D
> ColumnExtractor and DefaultColumnExtractor to the sandbox: They were =
=3D
> just used by JdbcHelper.
>
> (to be committed in about half an hour)
>
> Juergen
>
>
> -----Original Message-----
> From: spr...@li...
> [mailto:spr...@li...]On =
Behalf
> Of tri...@tr...
> Sent: Monday, February 16, 2004 10:16 PM
> To: spr...@li...
> Subject: Re: [Springframework-developer] JdbcHelper
>
>
>
> I have committed the new method to CVS. I will add my local tests to =
=3D
> the proper
> test class later today or tomorrow (this is a standalone feature so =
=3D
> little risk
> of breaking any other functionality). This might actually turn out to =
=3D
> be more
> of a test of MockObjects than real code, but it will at least outline =
=3D
> expected
> functionality.
>
> I ended up implementing (3) as an ArrayList of HashMaps using the =
column =3D
> name as
> key. We could replace this with a disconnected rowset in the future.
>
> I'll think about the convenience method - is "int" sufficient?
>
> Here is an example:
>
> DriverManagerDataSource ds =3D3D new DriverManagerDataSource();
> ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
> ds.setUrl("jdbc:oracle:thin:@localhost:1521:ORCL");
> ds.setUsername("scott");
> ds.setPassword("tiger");
> JdbcTemplate jt =3D3D new JdbcTemplate(ds);
> Object o =3D3D jt.runSqlStatement("select * from emp");
> System.out.println(o.getClass().getName());
> System.out.println(o);
>
> java.util.ArrayList
> [{SAL=3D3D800, HIREDATE=3D3D1980-12-17 00:00:00.0, COMM=3D3Dnull, =3D
> EMPNO=3D3D7369, JOB=3D3DCLERK,
> DEPTNO=3D3D20, MGR=3D3D7902, ENAME=3D3DSMITH}, {SAL=3D3D1600, =3D
> HIREDATE=3D3D1981-02-20 00:00:00.0,
> COMM=3D3D300, EMPNO=3D3D7499, JOB=3D3DSALESMAN, DEPTNO=3D3D30, =
MGR=3D3D7698, =3D
> ENAME=3D3DALLEN},
> {SAL=3D3D1250, HIREDATE=3D3D1981-02-22 00:00:00.0, COMM=3D3D500, =
EMPNO=3D3D7521, =3D
> JOB=3D3DSALESMAN,
> DEPTNO=3D3D30, MGR=3D3D7698, ENAME=3D3DWARD}, {SAL=3D3D2975, =3D
> HIREDATE=3D3D1981-04-02 00:00:00.0,
> COMM=3D3Dnull, EMPNO=3D3D7566, JOB=3D3DMANAGER, DEPTNO=3D3D20, =
MGR=3D3D7839, =3D
> ENAME=3D3DJONES},
> {SAL=3D3D1250, HIREDATE=3D3D1981-09-28 00:00:00.0, COMM=3D3D1400, =3D
> EMPNO=3D3D7654, JOB=3D3DSALESMAN,
> DEPTNO=3D3D30, MGR=3D3D7698, ENAME=3D3DMARTIN}, {SAL=3D3D2850, =3D
> HIREDATE=3D3D1981-05-01 00:00:00.0,
> COMM=3D3Dnull, EMPNO=3D3D7698, JOB=3D3DMANAGER, DEPTNO=3D3D30, =
MGR=3D3D7839, =3D
> ENAME=3D3DBLAKE},
> {SAL=3D3D2450, HIREDATE=3D3D1981-06-09 00:00:00.0, COMM=3D3Dnull, =3D
> EMPNO=3D3D7782, JOB=3D3DMANAGER,
> DEPTNO=3D3D10, MGR=3D3D7839, ENAME=3D3DCLARK}, {SAL=3D3D3000, =3D
> HIREDATE=3D3D1987-04-19 00:00:00.0,
> COMM=3D3Dnull, EMPNO=3D3D7788, JOB=3D3DANALYST, DEPTNO=3D3D20, =
MGR=3D3D7566, =3D
> ENAME=3D3DSCOTT},
> {SAL=3D3D5000, HIREDATE=3D3D1981-11-17 00:00:00.0, COMM=3D3Dnull, =3D
> EMPNO=3D3D7839, JOB=3D3DPRESIDENT,
> DEPTNO=3D3D10, MGR=3D3Dnull, ENAME=3D3DKING}, {SAL=3D3D1500, =3D
> HIREDATE=3D3D1981-09-08 00:00:00.0,
> COMM=3D3D0, EMPNO=3D3D7844, JOB=3D3DSALESMAN, DEPTNO=3D3D30, =
MGR=3D3D7698, =3D
> ENAME=3D3DTURNER}, {SAL=3D3D1100,
> HIREDATE=3D3D1987-05-23 00:00:00.0, COMM=3D3Dnull, EMPNO=3D3D7876, =3D
> JOB=3D3DCLERK, DEPTNO=3D3D20,
> MGR=3D3D7788, ENAME=3D3DADAMS}, {SAL=3D3D950, HIREDATE=3D3D1981-12-03 =
=3D
> 00:00:00.0, COMM=3D3Dnull,
> EMPNO=3D3D7900, JOB=3D3DCLERK, DEPTNO=3D3D30, MGR=3D3D7698, =
ENAME=3D3DJAMES}, =3D
> {SAL=3D3D3000,
> HIREDATE=3D3D1981-12-03 00:00:00.0, COMM=3D3Dnull, EMPNO=3D3D7902, =3D
> JOB=3D3DANALYST, DEPTNO=3D3D20,
> MGR=3D3D7566, ENAME=3D3DFORD}, {SAL=3D3D1300, HIREDATE=3D3D1982-01-23 =
=3D
> 00:00:00.0, COMM=3D3Dnull,
> EMPNO=3D3D7934, JOB=3D3DCLERK, DEPTNO=3D3D10, MGR=3D3D7782, =
ENAME=3D3DMILLER}]
>
> Thomas
>
>
> Quoting Rod Johnson <rod...@in...>:
>
> > Thomas,
> >=3D20
> > Sounds great. With this there I'd be glad to get rid of JdbcHelper.
> >=3D20
> > Not sure about (3). I think this needs further thought. For 1.1 we =
=3D
> could add
> > a true disconnected result set: not RowSet as it throws =
SQLException, =3D
> which
> > we want to get away from.
> >=3D20
> > Also a convenience method returning int would be handy, for counts =
and =3D
> the
> > like. Please can I have this, despite Juergen's dislike of =
convenience
> > methods :-)
> >=3D20
> > Regards,
> > Rod
> >=3D20
> > ----- Original Message -----
> > From: <tri...@tr...>
> > To: <spr...@li...>
> > Sent: Monday, February 16, 2004 5:26 PM
> > Subject: RE: [Springframework-developer] JdbcHelper
> >=3D20
> >=3D20
> > > I can see the need to go beyond a single row/value type query.
> > >
> > > How about a new method for the JdbcTemplate:
> > >
> > > Object runSqlStatement(String)
> > >
> > > Based on the type of SQL passed in it would return:
> > >
> > > 1) An Integer containing the number of rows affected if it is an =
=3D
> update
> > statement
> > >
> > > runSqlStatement("update emp set salary =3D3D salary * 1.5") would =
=3D
> return an
> > Integer
> > > with the update count
> > >
> > > 2) A single Object (Integer/Long/String) based on the value =
returned =3D
> from
> > a
> > > single value/single row query
> > >
> > > runSqlStatement("select last_name frmo emp where id =3D3D 2") =
would =3D
> return a
> > String
> > > containing the last name
> > >
> > > 3) An ArrayList of ArrayLists containing a list of rows with a =
list =3D
> of
> > column
> > > values returned by the query
> > >
> > > runSqlStatement("selecy id, last_name from emp") would return an =
=3D
> ArrayList
> > > containing an ArrayList for each row. The second list would =
contain =3D
> an
> > Integer
> > > with the id and a String with the last_name.
> > >
> > >
> > > Number 3 might be a stretch, but we would still have to check for =
=3D
> this,
> > since we
> > > have no control over the SQL coming in.
> > >
> > > Thomas
> > >
> > >
> > > Quoting rod...@in...:
> > >
> > > > I've actually just (yesterday) introduced into into a whole
> > > > bunch of test cases at a client. Maybe we could put an
> > > > improved runSQLFunction() method on JdbcTemplate? This is a
> > > > very convenient one-liner, and basically the only reason I
> > > > use JdbcTemplate.
> > > >
> > > > Regards,
> > > > Rod
> > > >
> > > >
> > > > -------------------------------------------------------
> > > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > > Build and deploy apps & Web services for Linux with
> > > > a free DVD software kit from IBM. Click Now!
> > > > =
http://ads.osdn.com/?ad_id=3D3D1356&alloc_id=3D3D3438&op=3D3Dclick
> > > > _______________________________________________
> > > > Springframework-developer mailing list
> > > > Spr...@li...
> > > > =3D
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
> > > >
> > >
> > >
> > >
> > >
> > >
> > > -------------------------------------------------------
> > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > Build and deploy apps & Web services for Linux with
> > > a free DVD software kit from IBM. Click Now!
> > > http://ads.osdn.com/?ad_id=3D3D1356&alloc_id=3D3D3438&op=3D3Dclick
> > > _______________________________________________
> > > Springframework-developer mailing list
> > > Spr...@li...
> > > =3D
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >=3D20
> >=3D20
> >=3D20
> >=3D20
> > -------------------------------------------------------
> > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > Build and deploy apps & Web services for Linux with
> > a free DVD software kit from IBM. Click Now!
> > http://ads.osdn.com/?ad_id=3D3D1356&alloc_id=3D3D3438&op=3D3Dclick
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > =
https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >=3D20
>
>
>
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=3D3D1356&alloc_id=3D3D3438&op=3D3Dclick
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=3D1356&alloc_id=3D3438&op=3Dclick
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=3D1356&alloc_id=3D3438&op=3Dclick
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|
|
From: Colin S. <col...@ex...> - 2004-02-17 23:33:22
|
Agreed. I can kill some convenience methods that do essentially the same
thing...
jürgen höller [werk3AT] wrote:
>Great! This is really a convenient way to execute simple SQL statements, both for update and for query.
>
>Allowing for using PreparedStatements without having to implement a PreparedStatementSetter is a significant benefit, as is giving easy access to simple results, avoiding the need for implementing a RowCallbackHandler. int results are worth special support here, as aggregate functions (count etc) all have integer results.
>
>I guess this is as good as it gets in a programmatic fashion. For declarative statements declarations and declarative parameter and/or result mappings, iBATIS SQL Maps is the way to go. Both approaches have clear value; it's good to see them both tap their respective full potential.
>
>Juergen
>
>
>________________________________
>
>Von: spr...@li... im Auftrag von tri...@tr...
>Gesendet: Di 17.02.2004 20:02
>An: spr...@li...
>Betreff: RE: [Springframework-developer] JdbcHelper
>
>
>
>I like the changes - the new method names fit better with the rest of the
>JdbcTemplate and Rod got his convenience 'int' method. Unfortunaltely it did
>not work to well for Oracle since getObject() maps a NUMERIC to
>java.math.BigDecimal. I added an explicit new Integer(getInt()) when the target
>is an Integer and the result looks like it could be an integer (NUMERIC,
>INTEGER, SMALLINT, TINYINT).
>
>These all work for Oracle:
>int i1 = jt.queryForInt("select count(*) from emp");
>Object o2 = jt.queryForObject("select sysdate from dual", java.util.Date.class);
>Object o3 = jt.queryForObject("select to_number('12.456', '9999.999') from
>dual", Number.class);
>Object o4 = jt.queryForList("select * from emp");
>
>
>Quoting "jürgen höller [werk3AT]" <jue...@we...>:
>
>
>
>>I've reviewed the code, and I think it's good that we're addressing this =
>>in JdbcTemplate itself. However, on second thought, it seems confusing =
>>to have a runSqlStatement method that executes either a query or update, =
>>with a multitude of possible result semantics. Thus, I've refactored =
>>this into overloaded query/queryForList/queryForObject/queryForInt =
>>methods.
>>
>>I've also added corresponding queryXxx and update methods that work with =
>>PreparedStatements, taking an Object[] (and optionally a int[] array for =
>>the SQL types) as arguments that get bound to the PreparedStatement. =
>>This effectively offers some of the conveniences of SqlQuery's find =
>>methods in JdbcTemplate itself; I think that's a valuable addition.
>>
>>Furthermore, I've put the new methods in JdbcOperations. In the course =
>>of this, I've dropped doWithResultFromXxx methods from the =
>>JdbcOperations interface: This is not something to be used on a regular =
>>basis, thus I guess it's enough to make them available in JdbcTemplate =
>>itself. This completely avoids the need to refer to the =
>>ResultSetExtractor interface in the JdbcOperations interface.
>>
>>As a further minor change, I've allowed ResultSetExtractor to return an =
>>arbitrary result object. The doWithResultFromXxx methods simply pass =
>>this through. The new queryForList/queryForObject/queryForInt methods =
>>are more elegant to implement with this. Finally, I've also moved =
>>ColumnExtractor and DefaultColumnExtractor to the sandbox: They were =
>>just used by JdbcHelper.
>>
>>(to be committed in about half an hour)
>>
>>Juergen
>>
>>
>>-----Original Message-----
>>From: spr...@li...
>>[mailto:spr...@li...]On Behalf
>>Of tri...@tr...
>>Sent: Monday, February 16, 2004 10:16 PM
>>To: spr...@li...
>>Subject: Re: [Springframework-developer] JdbcHelper
>>
>>
>>
>>I have committed the new method to CVS. I will add my local tests to =
>>the proper
>>test class later today or tomorrow (this is a standalone feature so =
>>little risk
>>of breaking any other functionality). This might actually turn out to =
>>be more
>>of a test of MockObjects than real code, but it will at least outline =
>>expected
>>functionality.
>>
>>I ended up implementing (3) as an ArrayList of HashMaps using the column =
>>name as
>>key. We could replace this with a disconnected rowset in the future.
>>
>>I'll think about the convenience method - is "int" sufficient?
>>
>>Here is an example:
>>
>>DriverManagerDataSource ds =3D new DriverManagerDataSource();
>>ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
>>ds.setUrl("jdbc:oracle:thin:@localhost:1521:ORCL");
>>ds.setUsername("scott");
>>ds.setPassword("tiger");
>>JdbcTemplate jt =3D new JdbcTemplate(ds);
>>Object o =3D jt.runSqlStatement("select * from emp");
>>System.out.println(o.getClass().getName());
>>System.out.println(o);
>>
>>java.util.ArrayList
>>[{SAL=3D800, HIREDATE=3D1980-12-17 00:00:00.0, COMM=3Dnull, =
>>EMPNO=3D7369, JOB=3DCLERK,
>>DEPTNO=3D20, MGR=3D7902, ENAME=3DSMITH}, {SAL=3D1600, =
>>HIREDATE=3D1981-02-20 00:00:00.0,
>>COMM=3D300, EMPNO=3D7499, JOB=3DSALESMAN, DEPTNO=3D30, MGR=3D7698, =
>>ENAME=3DALLEN},
>>{SAL=3D1250, HIREDATE=3D1981-02-22 00:00:00.0, COMM=3D500, EMPNO=3D7521, =
>>JOB=3DSALESMAN,
>>DEPTNO=3D30, MGR=3D7698, ENAME=3DWARD}, {SAL=3D2975, =
>>HIREDATE=3D1981-04-02 00:00:00.0,
>>COMM=3Dnull, EMPNO=3D7566, JOB=3DMANAGER, DEPTNO=3D20, MGR=3D7839, =
>>ENAME=3DJONES},
>>{SAL=3D1250, HIREDATE=3D1981-09-28 00:00:00.0, COMM=3D1400, =
>>EMPNO=3D7654, JOB=3DSALESMAN,
>>DEPTNO=3D30, MGR=3D7698, ENAME=3DMARTIN}, {SAL=3D2850, =
>>HIREDATE=3D1981-05-01 00:00:00.0,
>>COMM=3Dnull, EMPNO=3D7698, JOB=3DMANAGER, DEPTNO=3D30, MGR=3D7839, =
>>ENAME=3DBLAKE},
>>{SAL=3D2450, HIREDATE=3D1981-06-09 00:00:00.0, COMM=3Dnull, =
>>EMPNO=3D7782, JOB=3DMANAGER,
>>DEPTNO=3D10, MGR=3D7839, ENAME=3DCLARK}, {SAL=3D3000, =
>>HIREDATE=3D1987-04-19 00:00:00.0,
>>COMM=3Dnull, EMPNO=3D7788, JOB=3DANALYST, DEPTNO=3D20, MGR=3D7566, =
>>ENAME=3DSCOTT},
>>{SAL=3D5000, HIREDATE=3D1981-11-17 00:00:00.0, COMM=3Dnull, =
>>EMPNO=3D7839, JOB=3DPRESIDENT,
>>DEPTNO=3D10, MGR=3Dnull, ENAME=3DKING}, {SAL=3D1500, =
>>HIREDATE=3D1981-09-08 00:00:00.0,
>>COMM=3D0, EMPNO=3D7844, JOB=3DSALESMAN, DEPTNO=3D30, MGR=3D7698, =
>>ENAME=3DTURNER}, {SAL=3D1100,
>>HIREDATE=3D1987-05-23 00:00:00.0, COMM=3Dnull, EMPNO=3D7876, =
>>JOB=3DCLERK, DEPTNO=3D20,
>>MGR=3D7788, ENAME=3DADAMS}, {SAL=3D950, HIREDATE=3D1981-12-03 =
>>00:00:00.0, COMM=3Dnull,
>>EMPNO=3D7900, JOB=3DCLERK, DEPTNO=3D30, MGR=3D7698, ENAME=3DJAMES}, =
>>{SAL=3D3000,
>>HIREDATE=3D1981-12-03 00:00:00.0, COMM=3Dnull, EMPNO=3D7902, =
>>JOB=3DANALYST, DEPTNO=3D20,
>>MGR=3D7566, ENAME=3DFORD}, {SAL=3D1300, HIREDATE=3D1982-01-23 =
>>00:00:00.0, COMM=3Dnull,
>>EMPNO=3D7934, JOB=3DCLERK, DEPTNO=3D10, MGR=3D7782, ENAME=3DMILLER}]
>>
>>Thomas
>>
>>
>>Quoting Rod Johnson <rod...@in...>:
>>
>>
>>
>>>Thomas,
>>>=20
>>>Sounds great. With this there I'd be glad to get rid of JdbcHelper.
>>>=20
>>>Not sure about (3). I think this needs further thought. For 1.1 we =
>>>
>>>
>>could add
>>
>>
>>>a true disconnected result set: not RowSet as it throws SQLException, =
>>>
>>>
>>which
>>
>>
>>>we want to get away from.
>>>=20
>>>Also a convenience method returning int would be handy, for counts and =
>>>
>>>
>>the
>>
>>
>>>like. Please can I have this, despite Juergen's dislike of convenience
>>>methods :-)
>>>=20
>>>Regards,
>>>Rod
>>>=20
>>>----- Original Message -----
>>>From: <tri...@tr...>
>>>To: <spr...@li...>
>>>Sent: Monday, February 16, 2004 5:26 PM
>>>Subject: RE: [Springframework-developer] JdbcHelper
>>>=20
>>>=20
>>>
>>>
>>>>I can see the need to go beyond a single row/value type query.
>>>>
>>>>How about a new method for the JdbcTemplate:
>>>>
>>>>Object runSqlStatement(String)
>>>>
>>>>Based on the type of SQL passed in it would return:
>>>>
>>>>1) An Integer containing the number of rows affected if it is an =
>>>>
>>>>
>>update
>>
>>
>>>statement
>>>
>>>
>>>>runSqlStatement("update emp set salary =3D salary * 1.5") would =
>>>>
>>>>
>>return an
>>
>>
>>>Integer
>>>
>>>
>>>>with the update count
>>>>
>>>>2) A single Object (Integer/Long/String) based on the value returned =
>>>>
>>>>
>>from
>>
>>
>>>a
>>>
>>>
>>>>single value/single row query
>>>>
>>>>runSqlStatement("select last_name frmo emp where id =3D 2") would =
>>>>
>>>>
>>return a
>>
>>
>>>String
>>>
>>>
>>>>containing the last name
>>>>
>>>>3) An ArrayList of ArrayLists containing a list of rows with a list =
>>>>
>>>>
>>of
>>
>>
>>>column
>>>
>>>
>>>>values returned by the query
>>>>
>>>>runSqlStatement("selecy id, last_name from emp") would return an =
>>>>
>>>>
>>ArrayList
>>
>>
>>>>containing an ArrayList for each row. The second list would contain =
>>>>
>>>>
>>an
>>
>>
>>>Integer
>>>
>>>
>>>>with the id and a String with the last_name.
>>>>
>>>>
>>>>Number 3 might be a stretch, but we would still have to check for =
>>>>
>>>>
>>this,
>>
>>
>>>since we
>>>
>>>
>>>>have no control over the SQL coming in.
>>>>
>>>>Thomas
>>>>
>>>>
>>>>Quoting rod...@in...:
>>>>
>>>>
>>>>
>>>>>I've actually just (yesterday) introduced into into a whole
>>>>>bunch of test cases at a client. Maybe we could put an
>>>>>improved runSQLFunction() method on JdbcTemplate? This is a
>>>>>very convenient one-liner, and basically the only reason I
>>>>>use JdbcTemplate.
>>>>>
>>>>>Regards,
>>>>>Rod
>>>>>
>>>>>
>>>>>-------------------------------------------------------
>>>>>SF.Net is sponsored by: Speed Start Your Linux Apps Now.
>>>>>Build and deploy apps & Web services for Linux with
>>>>>a free DVD software kit from IBM. Click Now!
>>>>>http://ads.osdn.com/?ad_id=3D1356&alloc_id=3D3438&op=3Dclick
>>>>>_______________________________________________
>>>>>Springframework-developer mailing list
>>>>>Spr...@li...
>>>>>=
>>>>>
>>>>>
>>https://lists.sourceforge.net/lists/listinfo/springframework-developer
>>
>>
>>>>
>>>>
|
|
From: Eduardo I. I. <zi...@su...> - 2004-02-27 19:59:03
|
I noticed that JdbcHelper.queryForList() method returns an ArrayList, but a LinkedList should not be more appropriate (more performant without need of array realocation as the list grows) as it is a generic funcition and the rowcount is not known in advance? |
|
From: <tri...@tr...> - 2004-02-27 20:47:54
|
Eduardo, I assume that you mean the new JdbcTemplate.queryForList() It's an interesting question and I think the jury is still out on whether the Linked List or ArrayList would perform better here - I have seen arguments going both ways (if I have some extra time I will run some benchmarks for our specific use). A lot depends on the size of the resultset and I would not use this method for running a query returning a really large number of rows anyway. That said, I'd be happy to change it if there definitely is a performace difference. Thomas Quoting Eduardo Issao Ito <zi...@su...>: > > I noticed that JdbcHelper.queryForList() method returns an ArrayList, but a > LinkedList should not be more appropriate (more performant without need of > array > realocation as the list grows) as it is a generic funcition and the rowcount > is > not known in advance? > > > > ------------------------------------------------------- > SF.Net is sponsored by: Speed Start Your Linux Apps Now. > Build and deploy apps & Web services for Linux with > a free DVD software kit from IBM. Click Now! > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer > |
|
From: <tri...@tr...> - 2004-02-27 21:50:00
|
Here is a quick unscientific benchmark:
JdbcTemplate jt = new JdbcTemplate(ds);
String sql = "select * from my_large_table where rownum <= 200000";
long start = System.currentTimeMillis();
List l = jt.queryForList(sql);
int x = 0;
for (int i = 0; i < l.size(); i++) {
x++;
}
long done = System.currentTimeMillis();
System.out.println(": " + x + " in " + (done - start) + "ms");
And the results:
java.util.LinkedList: 2000 in 1156ms
java.util.ArrayList: 2000 in 1156ms
java.util.LinkedList: 20000 in 5968ms
java.util.ArrayList: 20000 in 6031ms
java.util.LinkedList: 200000 in 52154ms
java.util.ArrayList: 200000 in 52639ms
As you can see the difference is very small. Most of the time is spent reading
the data from the database so the List processing only make up a tiny fraction
of the total time. I looked at the memory usage during the 200000 row runs and
these were the numbers:
java.util.LinkedList: [196MB]
java.util.ArrayList: [192MB]
Thomas
Quoting tri...@tr...:
> Eduardo,
>
> I assume that you mean the new JdbcTemplate.queryForList()
>
> It's an interesting question and I think the jury is still out on whether
> the
> Linked List or ArrayList would perform better here - I have seen arguments
> going
> both ways (if I have some extra time I will run some benchmarks for our
> specific
> use). A lot depends on the size of the resultset and I would not use this
> method for running a query returning a really large number of rows anyway.
> That
> said, I'd be happy to change it if there definitely is a performace
> difference.
>
> Thomas
>
>
> Quoting Eduardo Issao Ito <zi...@su...>:
>
> >
> > I noticed that JdbcHelper.queryForList() method returns an ArrayList, but a
>
> > LinkedList should not be more appropriate (more performant without need of
> > array
> > realocation as the list grows) as it is a generic funcition and the
> rowcount
> > is
> > not known in advance?
> >
> >
> >
> > -------------------------------------------------------
> > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > Build and deploy apps & Web services for Linux with
> > a free DVD software kit from IBM. Click Now!
> > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >
>
>
>
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
|
|
From: Eduardo I. I. <zi...@su...> - 2004-02-27 22:18:58
|
So ArrayList seems ok for this usage, and we have quick random access also!
As usual in the performance area, our intuition is not so useful as a simple
benchmark...
Thanks!
PS: Why that (almost) empty loop? The question was about how to populate the List.
tri...@tr... wrote:
> Here is a quick unscientific benchmark:
>
> JdbcTemplate jt = new JdbcTemplate(ds);
> String sql = "select * from my_large_table where rownum <= 200000";
> long start = System.currentTimeMillis();
> List l = jt.queryForList(sql);
> int x = 0;
> for (int i = 0; i < l.size(); i++) {
> x++;
> }
> long done = System.currentTimeMillis();
> System.out.println(": " + x + " in " + (done - start) + "ms");
>
> And the results:
>
> java.util.LinkedList: 2000 in 1156ms
> java.util.ArrayList: 2000 in 1156ms
>
> java.util.LinkedList: 20000 in 5968ms
> java.util.ArrayList: 20000 in 6031ms
>
> java.util.LinkedList: 200000 in 52154ms
> java.util.ArrayList: 200000 in 52639ms
>
> As you can see the difference is very small. Most of the time is spent reading
> the data from the database so the List processing only make up a tiny fraction
> of the total time. I looked at the memory usage during the 200000 row runs and
> these were the numbers:
>
> java.util.LinkedList: [196MB]
> java.util.ArrayList: [192MB]
>
> Thomas
>
>
>
> Quoting tri...@tr...:
>
>
>>Eduardo,
>>
>>I assume that you mean the new JdbcTemplate.queryForList()
>>
>>It's an interesting question and I think the jury is still out on whether
>>the
>>Linked List or ArrayList would perform better here - I have seen arguments
>>going
>>both ways (if I have some extra time I will run some benchmarks for our
>>specific
>>use). A lot depends on the size of the resultset and I would not use this
>>method for running a query returning a really large number of rows anyway.
>>That
>>said, I'd be happy to change it if there definitely is a performace
>>difference.
>>
>>Thomas
>>
>>
>>Quoting Eduardo Issao Ito <zi...@su...>:
>>
>>
>>>I noticed that JdbcHelper.queryForList() method returns an ArrayList, but a
>>
>>>LinkedList should not be more appropriate (more performant without need of
>>>array
>>>realocation as the list grows) as it is a generic funcition and the
>>
>>rowcount
>>
>>>is
>>>not known in advance?
>>>
>>>
>>>
>>>-------------------------------------------------------
>>>SF.Net is sponsored by: Speed Start Your Linux Apps Now.
>>>Build and deploy apps & Web services for Linux with
>>>a free DVD software kit from IBM. Click Now!
>>>http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
>>>_______________________________________________
>>>Springframework-developer mailing list
>>>Spr...@li...
>>>https://lists.sourceforge.net/lists/listinfo/springframework-developer
>>>
>>
>>
>>
>>
>>
>>-------------------------------------------------------
>>SF.Net is sponsored by: Speed Start Your Linux Apps Now.
>>Build and deploy apps & Web services for Linux with
>>a free DVD software kit from IBM. Click Now!
>>http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
>>_______________________________________________
>>Springframework-developer mailing list
>>Spr...@li...
>>https://lists.sourceforge.net/lists/listinfo/springframework-developer
>>
>
>
>
>
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
|
|
From: <tri...@tr...> - 2004-02-27 22:31:55
|
Quoting Eduardo Issao Ito <zi...@su...>:
>
> So ArrayList seems ok for this usage, and we have quick random access also!
>
> As usual in the performance area, our intuition is not so useful as a simple
>
> benchmark...
>
> Thanks!
>
>
> PS: Why that (almost) empty loop? The question was about how to populate the
> List.
I thought it would be more realistic test if we actually did something with the
list rather tan just populate it and throw it away.
Thomas
>
>
> tri...@tr... wrote:
>
> > Here is a quick unscientific benchmark:
> >
> > JdbcTemplate jt = new JdbcTemplate(ds);
> > String sql = "select * from my_large_table where rownum <= 200000";
> > long start = System.currentTimeMillis();
> > List l = jt.queryForList(sql);
> > int x = 0;
> > for (int i = 0; i < l.size(); i++) {
> > x++;
> > }
> > long done = System.currentTimeMillis();
> > System.out.println(": " + x + " in " + (done - start) + "ms");
> >
> > And the results:
> >
> > java.util.LinkedList: 2000 in 1156ms
> > java.util.ArrayList: 2000 in 1156ms
> >
> > java.util.LinkedList: 20000 in 5968ms
> > java.util.ArrayList: 20000 in 6031ms
> >
> > java.util.LinkedList: 200000 in 52154ms
> > java.util.ArrayList: 200000 in 52639ms
> >
> > As you can see the difference is very small. Most of the time is spent
> reading
> > the data from the database so the List processing only make up a tiny
> fraction
> > of the total time. I looked at the memory usage during the 200000 row runs
> and
> > these were the numbers:
> >
> > java.util.LinkedList: [196MB]
> > java.util.ArrayList: [192MB]
> >
> > Thomas
> >
> >
> >
> > Quoting tri...@tr...:
> >
> >
> >>Eduardo,
> >>
> >>I assume that you mean the new JdbcTemplate.queryForList()
> >>
> >>It's an interesting question and I think the jury is still out on whether
> >>the
> >>Linked List or ArrayList would perform better here - I have seen arguments
> >>going
> >>both ways (if I have some extra time I will run some benchmarks for our
> >>specific
> >>use). A lot depends on the size of the resultset and I would not use this
> >>method for running a query returning a really large number of rows anyway.
>
> >>That
> >>said, I'd be happy to change it if there definitely is a performace
> >>difference.
> >>
> >>Thomas
> >>
> >>
> >>Quoting Eduardo Issao Ito <zi...@su...>:
> >>
> >>
> >>>I noticed that JdbcHelper.queryForList() method returns an ArrayList, but
> a
> >>
> >>>LinkedList should not be more appropriate (more performant without need
> of
> >>>array
> >>>realocation as the list grows) as it is a generic funcition and the
> >>
> >>rowcount
> >>
> >>>is
> >>>not known in advance?
> >>>
> >>>
> >>>
> >>>-------------------------------------------------------
> >>>SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> >>>Build and deploy apps & Web services for Linux with
> >>>a free DVD software kit from IBM. Click Now!
> >>>http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> >>>_______________________________________________
> >>>Springframework-developer mailing list
> >>>Spr...@li...
> >>>https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >>>
> >>
> >>
> >>
> >>
> >>
> >>-------------------------------------------------------
> >>SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> >>Build and deploy apps & Web services for Linux with
> >>a free DVD software kit from IBM. Click Now!
> >>http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> >>_______________________________________________
> >>Springframework-developer mailing list
> >>Spr...@li...
> >>https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >>
> >
> >
> >
> >
> >
> >
> > -------------------------------------------------------
> > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > Build and deploy apps & Web services for Linux with
> > a free DVD software kit from IBM. Click Now!
> > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >
>
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
|