pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Advise on mapping JTable to large PostgreSQL table requested?
3+ messages / 3 participants
[nested] [flat]

* Advise on mapping JTable to large PostgreSQL table requested?
@ 2005-12-06 09:09  Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>
  0 siblings, 1 reply; 3+ messages in thread

From: Joost Kraaijeveld @ 2005-12-06 09:09 UTC (permalink / raw)
  To: pgsql-jdbc

Hi,

As here are people that know databases and Java....

I *must* (as in: I have no choice and it can't be solved another way by
customer demand) display a large table (> 1.100.000 records) in a JTable
( or something that looks like a JTable for the customer).

The customer wants to able to search the data and wants the focus (if
the search succeeds) to be on the record in the table.

AS a JTable works with rows, so I have written code that calculates the
row of the record in the query and maps any row request to an index in
the query.

To make it more clear (?;-):

1. Customer wants the record with 'some text' in column 'a'
2. I calculate the index:
select count(*) from table where a < 'some text'
3. I check if the index is in a local cache ( an AbstractTableModel
derived object that maintains a vector of cached record).
4. If not, I get 100 records before and after the requested record,
including the record itself and put them in the local cache so that
JTable can call AbstratTableModel.getValueAt(row,column) without the
need of accessing the database.
5. I set the JTable selection to the index found in step 2 and as long
as a requested row is in my cache I have a snappy respons.

The trouble is that step 2 takes a lot of time (it is proportional to
the size of the table?).

I assume that I am not the first person that tries something like this.
I want to know if my way of solving this problem is the most adequate,
or that there are other ways of achieving my goal (which is indeed
emulating an ISAM database). 

TIA


-- 
Groeten,

Joost Kraaijeveld
Askesis B.V.
Molukkenstraat 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416
e-mail: J.Kraaijeveld@Askesis.nl
web: www.askesis.nl 





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Advise on mapping JTable to large PostgreSQL table
@ 2005-12-06 15:57  Kris Jurka <books@ejurka.com>
  parent: Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>
  0 siblings, 1 reply; 3+ messages in thread

From: Kris Jurka @ 2005-12-06 15:57 UTC (permalink / raw)
  To: Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>; +Cc: pgsql-jdbc



On Tue, 6 Dec 2005, Joost Kraaijeveld wrote:

> I *must* (as in: I have no choice and it can't be solved another way by
> customer demand) display a large table (> 1.100.000 records) in a JTable
> ( or something that looks like a JTable for the customer).
>
> AS a JTable works with rows, so I have written code that calculates the
> row of the record in the query and maps any row request to an index in
> the query.
>
> 1. Customer wants the record with 'some text' in column 'a'
> 2. I calculate the index:
> select count(*) from table where a < 'some text'

There's got to be a better way of storing this index.  If this is readonly 
data then you could easily number all of these in the database itself.  I 
think the problem may be that you are trying to index all this data as an 
array where you need an absolute offset.  Perhaps a different data 
structure would make a better backing type?

> 4. If not, I get 100 records before and after the requested record,
> including the record itself and put them in the local cache so that
> JTable can call AbstratTableModel.getValueAt(row,column) without the
> need of accessing the database.

How do you determine the records before and after at the moment?

Kris Jurka



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Advise on mapping JTable to large PostgreSQL table
@ 2005-12-06 22:33  Andres Olarte <olarte.andres@gmail.com>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Andres Olarte @ 2005-12-06 22:33 UTC (permalink / raw)
  To: pgsql-jdbc

Couldn't you use a single ugly "SELECT *" with a cursor and then fill your
local cache as the client is scrolling through the table?  It will scroll
kind of slow the first time, but then i'll work nice. I'm not very into
Swing, but for that you'd only need the number of rows  with something like
"SELECT count(*)".

On 12/6/05, Kris Jurka <books@ejurka.com> wrote:
>
>
>
> On Tue, 6 Dec 2005, Joost Kraaijeveld wrote:
>
> > I *must* (as in: I have no choice and it can't be solved another way by
> > customer demand) display a large table (> 1.100.000 records) in a JTable
> > ( or something that looks like a JTable for the customer).
> >
> > AS a JTable works with rows, so I have written code that calculates the
> > row of the record in the query and maps any row request to an index in
> > the query.
> >
> > 1. Customer wants the record with 'some text' in column 'a'
> > 2. I calculate the index:
> > select count(*) from table where a < 'some text'
>
> There's got to be a better way of storing this index.  If this is readonly
> data then you could easily number all of these in the database itself.  I
> think the problem may be that you are trying to index all this data as an
> array where you need an absolute offset.  Perhaps a different data
> structure would make a better backing type?
>
> > 4. If not, I get 100 records before and after the requested record,
> > including the record itself and put them in the local cache so that
> > JTable can call AbstratTableModel.getValueAt(row,column) without the
> > need of accessing the database.
>
> How do you determine the records before and after at the moment?
>
> Kris Jurka
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
>       choose an index scan if your joining column's datatypes do not
>       match
>

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2005-12-06 22:33 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-12-06 09:09 Advise on mapping JTable to large PostgreSQL table requested? Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>
2005-12-06 15:57 ` Re: Advise on mapping JTable to large PostgreSQL table Kris Jurka <books@ejurka.com>
2005-12-06 22:33   ` Re: Advise on mapping JTable to large PostgreSQL table Andres Olarte <olarte.andres@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox