Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / November 2007

Tip: Looking for answers? Try searching our database.

portable sequence

Thread view: 
Drazen Gemic - 24 Nov 2007 15:33 GMT
Hi !

I need to have a portable global sequence generator that works
regardless of database engine used. For example, Postgres have
sequence, mssql doesn't, but I need sequence for both. I tried to
create one, uzing SERIALIZABLE transactions, but under the increased
load it started to generate deadlocks.

The sequence table, 'uniseq' in this example, contains just one row
with one column ('next_id'), and that column is a sequence value, a
globaly unique number (BIGINT).

If the table is empty, new row is inserted, with sequence number = 1.
Otherwise sequence number is increased and stored.

What should I do to avoid deadlocks ?

Here is the code:

public static Long getUniqId(AdbWrapper dbx)
  {
  boolean flag=true;
  dbx.startTran("SERIALIZABLE"); // transaction start
  Long num=(Long) dbx.getField("select next_id from uniseq");
  if(num == null)
     {
     num=new Long(1);
     flag=(dbx.update("insert into uniseq values (1)") > 0);
     }
  else
     {
     num=new Long(1+num.longValue());
     flag=(dbx.update("update uniseq set next_id="+num) > 0);
     }
  dbx.endTran(flag);   // transaction end
  //
  return num;
  }
Lew - 24 Nov 2007 16:22 GMT
> I need to have a portable global sequence generator that works

You got answers in clj.programmer.  Please do not multi-post.

Signature

Lew

Drazen Gemic - 24 Nov 2007 18:38 GMT
> > I need to have a portable global sequence generator that works
>
> You got answers in clj.programmer.  Please do not multi-post.

In fact I decided to post to cljp later, after I found out that the
traffic in cljd is low.

DG


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.