Return-Path: Delivered-To: apmail-incubator-empire-db-user-archive@minotaur.apache.org Received: (qmail 39923 invoked from network); 7 Oct 2009 20:51:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 7 Oct 2009 20:51:41 -0000 Received: (qmail 35582 invoked by uid 500); 7 Oct 2009 20:51:41 -0000 Delivered-To: apmail-incubator-empire-db-user-archive@incubator.apache.org Received: (qmail 35549 invoked by uid 500); 7 Oct 2009 20:51:41 -0000 Mailing-List: contact empire-db-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: empire-db-user@incubator.apache.org Delivered-To: mailing list empire-db-user@incubator.apache.org Received: (qmail 35540 invoked by uid 99); 7 Oct 2009 20:51:41 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Oct 2009 20:51:41 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [88.79.172.157] (HELO mail.esteam.de) (88.79.172.157) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Oct 2009 20:51:32 +0000 Content-class: urn:content-classes:message Subject: re: Detecting failure to retrieve data MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Date: Wed, 7 Oct 2009 22:51:09 +0200 Message-ID: X-MimeOLE: Produced By Microsoft Exchange V6.5 In-Reply-To: <4ca747c30910051750r30f0d7d9r2c39408de267d401@mail.gmail.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: re: Detecting failure to retrieve data Thread-Index: AcpGHxwJLPtrso5jQueYEuEUzSnjLwBZf9Nw References: <4ca747c30910051750r30f0d7d9r2c39408de267d401@mail.gmail.com> From: =?iso-8859-1?Q?Rainer_D=F6bele?= To: X-Virus-Checked: Checked by ClamAV on apache.org Hi Andrew, when you call DBReader.open() the cursor is positioned before the first = record not on the first record. The open method assumes that you want to retrieve a list of records = hence you should always iterate through the reader like this: reader.open(cmd, conn); while (reader.moveNext()) { // Init updateable record reader.initRecord(EMP, record); } This will work for 0 to n records. However, if you know for sure that the result is a single record or = none, you can instead use the method getRecordData(DBCommandExpr cmd, = Connection conn) on DBReader. This method opens the reader and moves to = the first record. If no record was found this function returns false. About your question whether to subclass DBRecord or use beans: Basically DBRecord objects are something like dynamic beans in a way = that the properties don't have to be declared at compile-time and that = instead of an individual getter / setter for each property you have = several generic ones that require a field reference.=20 Personally I prefer subclassing a DBRecord and use it to create other = type safe methods that work on these derived types. This gives you also = the opportunity to override methods like getValue(), setValue(), = onFieldChanged(), isFieldReadOnly() etc. Using beans IMO only makes sense if you either need to work with other = frameworks that require beans or if you need to serialize your beans. Regards Rainer acooke.org@gmail.com wrote: > re: Detecting failure to retrieve data >=20 > Hi, >=20 > Another question - hopefully simpler. How do I detect when a query > has failed to retrieve data? In particular I have code like: >=20 > cmd =3D schema.createCommand() > cmd.select(schema.CANONICALS.getColumns()) > cmd.where(schema.CANONICALS.VALUE.is(value)) > row =3D new DBRecord(schema.CANONICALS) > reader =3D new DBReader() > reader.open(cmd, cnxn) > ok =3D Schema.CANONICALS.initRecord(row, reader) >=20 > where ok is true even when there are no data (value does not exist in > the VALUE column of the CANONICALS table and "row" contains nulls) > (and similarly if I use the initRecord method on the reader). >=20 > Should ok be false above? It appears to be true, but I must confess > that I am also using Scala (I have modified it to look like Java > above, I hope) and it is possible I am doing something stupid with > Scala... >=20 > Finally, I was originally thinking that I should subclass DBRecord and > so map rows to objects, but now I am thinking that it would be better > to use beans. Is there any reason to prefer one approach rather than > another, or are they for different cases somehow? >=20 > Thanks, > Andrew