Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Cecil Westerhof Newsgroups: comp.lang.java.programmer Subject: Re: Testing the functionality of sub classes Date: Sun, 20 Aug 2017 14:49:43 +0200 Organization: Decebal Computing Lines: 52 Message-ID: <87ziaue74o.fsf@munus.decebal.nl> References: <87fucnh2wu.fsf@munus.decebal.nl> <87y3qffim5.fsf@munus.decebal.nl> <87pobrf855.fsf@munus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="a3233d099e71e24d901953f13bac9801"; logging-data="5016"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/t8Xu9GuqJtHDqjjZBZhSg0yVtb3dYsNo=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-Homepage: http://www.decebal.nl/ Cancel-Lock: sha1:FtOrLzfVJmpt646FklITGOj0arw= sha1:yvHPdH2WAPqWVoe3kEjsx9CcpI4= Xref: csiph.com comp.lang.java.programmer:37313 Andreas Leitgeb writes: > Cecil Westerhof wrote: >> For example: when creating a new ResultSet through a Statement the >> previous generated should be closed. With the JDBC driver I use for >> SQLite3 the old ResultSet is not closed, but becomes a copy from the >> last generated. > > Are you sure about the "copy"? I'd rather expect(*) that the driver > re-uses the particular ResultSet instance and returns the same ref > again. (*: that is: based on your posted observations. Usually, > instance re-use is frowned upon, like premature optimisation, but then > again, DB driver vendors might have optimised it "well-maturely".) I am not sure: that is also possible. But what is important is that the old ResultSet did not get closed. So if I run the test for the super class with for example MySSQL and this closes the ResultSet (I do not know, but lets pretend) and I do not also test with SQLite3 I will not find this bug. > To verify (or disprove) it, you could run it in e.g. eclipse, and see > if the same (or a new) "id" appears when you execute another query on > the same Statement. > > Even without a debugger, you could print out the System.identityHashCode > for the "two" returned ResultSet references. Just to satisfy my curiosity I executed (I do not like the formatting, but that is what Eclipse does): try ( Statement stmt = conn.createStatement(); ResultSet rsOne = stmt.executeQuery("SELECT 12 AS twelve"); ResultSet rsTwo = stmt.executeQuery("SELECT 'Hello World!' AS message") ) { System.out.println(stmt); System.out.println(rsOne); System.out.println(rsTwo); } And this gives: org.sqlite.jdbc4.JDBC4Statement@685f4c2e org.sqlite.jdbc4.JDBC4ResultSet@7daf6ecc org.sqlite.jdbc4.JDBC4ResultSet@7daf6ecc So yes, it is like you said: the ResultSet is reused. Is also more logical. I jumped to a conclusion. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof