• 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

Creating ID's

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want create a job id for a particular job.It should not duplicate the previous job ids.i want to store these job id to my database.Please tell me how create a algorithm to create job ids.
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The database will usually happily create unique job numbers with the AUTO_INCREMENT option.
 
Sarath Koiloth Ramath
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to create an id which must be Aplha-numeric.Also these Id is inserting in some other tables too..
[ November 10, 2008: Message edited by: Sarath Koiloth Ramath ]
 
Campbell Ritchie
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sequential numbers.
a0000 a0001 a0002 a0003 . . . a9999 b0000 b0001 b0002 . . . c0000 . . .
When you get to z9999 change to aa0000
 
Sarath Koiloth Ramath
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to create those numbers..?Its a web application.
[ November 11, 2008: Message edited by: Sarath Koiloth Ramath ]
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sarath Koiloth Ramath:
How to create those numbers..?Its a web application.



By writing code.
The ranch is not a Code Mill.
Try it out yourself and if you get stuck, we will surely help you out.
Best of luck.
 
Sarath Koiloth Ramath
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know how to create those sequence..but how to implement these thing in every request.Every time i had to check the database wheather these Id is already taken or not.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sarath Koiloth Ramath:
I know how to create those sequence..but how to implement these thing in every request.Every time i had to check the database wheather these Id is already taken or not.



You can either:
1) Always maintain the highest unique ID in your application. This way you don't have to query the DB everytime. Just pull out the current highest ID on application start up.
2) Come up with an algorithm which will always give you an unique ID. Using the system time in milliseconds might be one of the ways to achieve this. You can further convert this long to say Hex and store it as a String to achieve the alpha numeric requirement.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One option could be to create a cache of the "largest" ids that are in the database, this way you don't have to continually access the database, instead you access your hash map object.

The only catch to this is every time you restart the server, you're cache will be cleared. So you will probably need an algorithm of some sort that will be called every time your server starts up to fill the cache.

Once you add a new id to the the database, you can then write to the database, remove the lowest id from the cache, and add the new id from the cache.

-AA
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anthony Andras:
One option could be to create a cache of the "largest" ids that are in the database, this way you don't have to continually access the database, instead you access your hash map object.

The only catch to this is every time you restart the server, you're cache will be cleared. So you will probably need an algorithm of some sort that will be called every time your server starts up to fill the cache.

Once you add a new id to the the database, you can then write to the database, remove the lowest id from the cache, and add the new id from the cache.

-AA



The other catch is when some other process inserts into a table and invalidates the values in your cache.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic