• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is this a good way of creating counter?

 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is using a database sequence(Oracle), a good way to create counter in a jsp page. So far it looks like it is working. any disadvantages?
Beksy
[This message has been edited by Beksy Kurian (edited October 16, 2001).]
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Offhand, it's an expensive thing to obtain a connection, query the sequence, and disconnect, all for the sake of a page count.

*on the other hand*... how else are these things done, right?

One thing I noticed about Oracle sequences, which I hadn't realized until I had performed testing over several days time... If the sequence has a buffer, and it is not queried for some amount of time (which I haven't been able to figure out, or see where it is set)... the sequence looses the buffered numbers.

I used a sequence for 'next primary key' generation.. I was noticing the following.. one day when i did my tests, I'd have 100,101,102,103,etc...
Several hours later it would be 104,105,106,etc...

But on the next day, it would start at 120,121,122,123...
and the next day would be 140,141,142.

The sequence buffered 20 'next numbers'... but if they're not used in time, they're gone!

Now you *could* set it not to buffer any, but does anyone know how to tell Oracle to simply *not* dump its buffer. My books don't show me the magical 'timeout' setting.
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If we set to 'no cache' will that help?
Beksy
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Now you *could* set it not to buffer any, but does anyone know how to tell Oracle to simply *not* dump its buffer. My books don't show me the magical 'timeout' setting.


Would setting the buffer size to one do it? No idea.
I agree with everything Mike had to say, but for a rough and ready age count you could use an insance variable in the servlet
as described in this thread
Dave.
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks you David and Mike
Beksy
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just as a final note:

the word i was looking for was 'CACHE'
so:
CREATE SEQUENCE seqName INCREMENT BY 1 START WITH 1000 CACHE 20;

will give me a single-increment sequence, starting at 1000.

BUT.. the CACHE is not persistent over time, and so if I don't grab the next one 'in time', my next number will be some number that is startNumber + (increment * n) where n > 1 (It flushes all the cached numbers that are not used, and gets the next block of 'increment' numbers).

I'm not sure of how to control this cache-flushing behaviour. I agree that if this is really bad for your app, simply specify NO-CACHE. But what if you want the cache for the performance increase, but don't want the thing to expire?

Edited to add this:
I've asked an Oracle guru here at work. He tells me that each new session with the database results in the sequence being cycled.
[This message has been edited by Mike Curwen (edited October 17, 2001).]
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oracle Sequence is meant for producing Unique numbers rather serial numbers,coz this depends on the oracle user session, u'll get different numbers for a purticular sequence if u open multiple session for a same user.So better insert that sequence values to a column and get the row count which will equal to the number of hits.But to tell u this is quite costly.
 
reply
    Bookmark Topic Watch Topic
  • New Topic