Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.databases > #643

Re: Local database library

From Martin Gregorie <martin@address-in-sig.invalid>
Newsgroups comp.lang.java.databases
Subject Re: Local database library
Date 2013-10-26 21:04 +0000
Organization A noiseless patient Spider
Message-ID <l4hapf$tcl$1@dont-email.me> (permalink)
References (2 earlier) <20131004110242.1be4f5ea@efreet.linux> <d50f8d5a-bf95-4d95-bc93-6a53b0a16522@googlegroups.com> <20131005120659.39a89f3b@efreet.linux> <ec4d1b88-d33a-4b76-a0e6-709319845718@googlegroups.com> <20131026120811.1a9bc341@efreet.linux>

Show all headers | View raw


On Sat, 26 Oct 2013 12:08:11 -0700, Kevin Nathan wrote:

> It's not SQL that is the brute force method, it's putting the SQL into
> every Java file that needs it, often the same query, or very similar,
> query. It works, but not what I would like to see. The data access is
> not split out from the rest of the code, and that was what I was wanting
> to do.
>
No, don't do that.

As I said earlier, put all your SQL into one class. You'll find a lot of 
commonality: starting/stopping the session and transaction start, commit/
rollback need only be written once with this approach. On top of that you 
need one method for each singleton select, update, insert or delete  and 
three methods for each query that uses a cursor (declare+run the query, 
fetch a row, close the cursor). But, before doing anything *collect all 
the queries* and look at them - you'll probably find several that are 
common to all programs and that, with minor tweaks such as adjusting the 
attribute list, can be combined.

Then use your judgement as to whether you want to write one large class 
containing all the SQL and is common to all programs or whether you want 
to break it up: one class for data retrieval and another for updates may 
work. If you break it up, put the common code for controlling sessions 
and transactions and dealing with SQL exceptions in a superclass and 
split the rest into two or more subclasses. Actually, once you've 
collected the SQL statements and looked at them, the way you'll want to 
group them into classes should become obvious.
 

-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Back to comp.lang.java.databases | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Local database library Kevin Nathan <knathan@project54.com> - 2013-10-01 13:52 -0700
  Re: Local database library Arne Vajhøj <arne@vajhoej.dk> - 2013-10-01 17:38 -0400
    Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-01 15:41 -0700
      Re: Local database library Arne Vajhøj <arne@vajhoej.dk> - 2013-10-01 20:53 -0400
        Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-02 10:09 -0700
          Re: Local database library Martin Gregorie <martin@address-in-sig.invalid> - 2013-10-02 19:49 +0000
            Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-04 10:48 -0700
              Re: Local database library Martin Gregorie <martin@address-in-sig.invalid> - 2013-10-05 15:43 +0000
                Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-05 11:19 -0700
          Re: Local database library Arne Vajhøj <arne@vajhoej.dk> - 2013-10-02 22:05 -0400
            Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-04 10:57 -0700
              Re: Local database library Arne Vajhøj <arne@vajhoej.dk> - 2013-10-04 22:00 -0400
                Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-05 11:28 -0700
                Re: Local database library Arne Vajhøj <arne@vajhoej.dk> - 2013-10-05 15:15 -0400
                Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-05 12:49 -0700
  Re: Local database library "John B. Matthews" <nospam@nospam.invalid> - 2013-10-02 15:37 -0400
    Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-04 11:02 -0700
      Re: Local database library Lew <lewbloch@gmail.com> - 2013-10-04 15:56 -0700
        Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-05 12:06 -0700
          Re: Local database library Lew <lewbloch@gmail.com> - 2013-10-15 16:41 -0700
            Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-26 12:08 -0700
              Re: Local database library Martin Gregorie <martin@address-in-sig.invalid> - 2013-10-26 21:04 +0000
                Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-26 18:58 -0700
              Re: Local database library Arne Vajhøj <arne@vajhoej.dk> - 2013-10-26 18:39 -0400
                Re: Local database library Kevin Nathan <knathan@project54.com> - 2013-10-26 19:04 -0700
            Re: Local database library Arne Vajhøj <arne@vajhoej.dk> - 2013-10-26 18:33 -0400

csiph-web