Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #37325
| Path | csiph.com!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | Arne Vajhøj <arne@vajhoej.dk> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Testing the functionality of sub classes |
| Date | Sun, 20 Aug 2017 13:06:46 -0400 |
| Organization | Aioe.org NNTP Server |
| Lines | 135 |
| Message-ID | <oncfj5$b69$1@gioia.aioe.org> (permalink) |
| References | <87fucnh2wu.fsf@munus.decebal.nl> <subclasses-20170819193036@ram.dialup.fu-berlin.de> <87y3qffim5.fsf@munus.decebal.nl> <ona7tq$igi$1@dont-email.me> <87pobrf855.fsf@munus.decebal.nl> <slrnopiu4a.o2q.avl@logic.at> <87ziaue74o.fsf@munus.decebal.nl> <87valie4xz.fsf@munus.decebal.nl> <onc3s5$1ns5$1@gioia.aioe.org> <87o9rae27u.fsf@munus.decebal.nl> <onc96e$1vqj$1@gioia.aioe.org> <87h8x2dxp1.fsf@munus.decebal.nl> <oncdbs$70j$1@gioia.aioe.org> |
| NNTP-Posting-Host | PBuS014lhzVyHjLbXmo/ZQ.user.gioia.aioe.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 |
| Content-Language | en-US |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | csiph.com comp.lang.java.programmer:37325 |
Show key headers only | View raw
On 8/20/2017 12:28 PM, Arne Vajhøj wrote:
> On 8/20/2017 12:13 PM, Cecil Westerhof wrote:
>> Arne Vajhøj <arne@vajhoej.dk> writes:
>>>> Nope, it shows that the H2 driver does follow the standards (and the
>>>> SQLite3 driver does not). The first ResultSet is closed as it should
>>>> be. You can do an isClosed on it. So it is not null, but displays a
>>>> null to show you should not use it anymore.
>>>
>>> The contract for toString is extremely vague.
>>>
>>> I do not see any indication than SQLite does not follow
>>> JDBC standard.
>>>
>>> Reusing result set object should be perfectly valid
>>> per JDBC standard.
>>
>> In the description of Statement (copied with spelling mistakes):
>> All execution methods in the Statement interface implicitly close
>> a statment's current ResultSet object if an open one exists.
>
> It is exactly because of this that I think reuse is valid.
Maybe I am just babbling.
But let me try and show what I am thinking about.
The code is far from complete, but it should hopefully
illustrate what I am thinking about.
public class OpenCloseFun {
public static interface Connection extends AutoCloseable {
public Statement createStatement();
}
public static interface Statement extends AutoCloseable {
public ResultSet executeQuery(String sql);
}
public static interface ResultSet extends AutoCloseable {
public boolean next();
}
public static class MyConnection implements Connection {
private MyRealConnection real;
private MyConnection(MyRealConnection real) {
this.real = real;
}
public static MyConnection create() {
return new MyConnection(new MyRealConnection());
}
public Statement createStatement() {
return new MyStatement(real.createStatement());
}
public void close() throws Exception {
real.close();
}
public String toString() {
return real.toString();
}
}
public static class MyStatement implements Statement {
private MyRealStatement real;
public MyStatement(MyRealStatement real) {
this.real = real;
}
public ResultSet executeQuery(String sql) {
return new MyResultSet(real.executeQuery(sql));
}
public void close() throws Exception {
real.close();
}
public String toString() {
return real.toString();
}
}
public static class MyResultSet implements ResultSet {
private MyRealResultSet real;
public MyResultSet(MyRealResultSet real) {
this.real = real;
}
public boolean next() {
return real.next();
}
public void close() throws Exception {
real.close();
}
public String toString() {
return real.toString();
}
}
public static class MyRealConnection implements Connection {
private MyRealStatement stmt = new MyRealStatement(); // only one
concurrent active Statement per Connection
public MyRealStatement createStatement() {
stmt.init();
return stmt;
}
public void close() throws Exception {
stmt.close();
}
}
public static class MyRealStatement implements Statement {
private MyRealResultSet rs = new MyRealResultSet(); // only one
concurrent active ResultSet per Statement
public void init() {
}
public MyRealResultSet executeQuery(String sql) {
rs.init(sql);
return rs;
}
public void close() throws Exception {
rs.close();
}
}
public static class MyRealResultSet implements ResultSet {
public void init(String sql) {
}
public boolean next() {
return true;
}
public void close() throws Exception {
}
}
public static void main(String[] args) throws Exception {
try(Connection con = MyConnection.create()) {
try(Statement stmt = con.createStatement();
ResultSet rs1 = stmt.executeQuery("something");
ResultSet rs2 = stmt.executeQuery("something else")) {
System.out.println(stmt);
System.out.println(rs1);
System.out.println(rs2);
}
}
}
}
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Testing the functionality of sub classes Cecil Westerhof <Cecil@decebal.nl> - 2017-08-19 19:40 +0200
Re: Testing the functionality of sub classes Cecil Westerhof <Cecil@decebal.nl> - 2017-08-19 21:44 +0200
Re: Testing the functionality of sub classes Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-08-19 16:47 -0400
Re: Testing the functionality of sub classes Cecil Westerhof <Cecil@decebal.nl> - 2017-08-20 01:30 +0200
Re: Testing the functionality of sub classes Andreas Leitgeb <avl@logic.at> - 2017-08-20 11:50 +0000
Re: Testing the functionality of sub classes Cecil Westerhof <Cecil@decebal.nl> - 2017-08-20 14:49 +0200
Re: Testing the functionality of sub classes Cecil Westerhof <Cecil@decebal.nl> - 2017-08-20 15:36 +0200
Re: Testing the functionality of sub classes Arne Vajhøj <arne@vajhoej.dk> - 2017-08-20 09:46 -0400
Re: Testing the functionality of sub classes Andreas Leitgeb <avl@logic.at> - 2017-08-20 14:33 +0000
Re: Testing the functionality of sub classes Arne Vajhøj <arne@vajhoej.dk> - 2017-08-20 11:14 -0400
Re: Testing the functionality of sub classes Cecil Westerhof <Cecil@decebal.nl> - 2017-08-20 16:35 +0200
Re: Testing the functionality of sub classes Arne Vajhøj <arne@vajhoej.dk> - 2017-08-20 11:17 -0400
Re: Testing the functionality of sub classes Cecil Westerhof <Cecil@decebal.nl> - 2017-08-20 18:13 +0200
Re: Testing the functionality of sub classes Arne Vajhøj <arne@vajhoej.dk> - 2017-08-20 12:28 -0400
Re: Testing the functionality of sub classes Arne Vajhøj <arne@vajhoej.dk> - 2017-08-20 13:06 -0400
Re: Testing the functionality of sub classes Cecil Westerhof <Cecil@decebal.nl> - 2017-08-20 19:07 +0200
Re: Testing the functionality of sub classes Arne Vajhøj <arne@vajhoej.dk> - 2017-08-20 11:21 -0400
Re: Testing the functionality of sub classes Cecil Westerhof <Cecil@decebal.nl> - 2017-08-20 18:17 +0200
Re: Testing the functionality of sub classes v_borchert@despammed.com (Volker Borchert) - 2017-08-21 19:53 +0000
Re: Testing the functionality of sub classes v_borchert@despammed.com (Volker Borchert) - 2017-08-19 21:15 +0000
Re: Testing the functionality of sub classes Cecil Westerhof <Cecil@decebal.nl> - 2017-08-20 01:36 +0200
Re: Testing the functionality of sub classes Cecil Westerhof <Cecil@decebal.nl> - 2017-08-20 01:22 +0200
csiph-web