• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How do i implement this tricky requirement

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
i have a tricky situation which i am finding difficult to implement. Here is my requirement:


I have to implement this using struts framework. I have a JSP page called Ref.jsp which has a Text Box named Reference Id(uneditable) and many other text boxes to capture the reference details. When user opens this JSP page, Ref.jsp must auto populate the Reference Id text Box. And this value must be 1 higher than the Maximun Reference Id from the Reference Table. Remember that this Ref.jsp page can be opened from many machines. I have one approach of implementing this but that comes again with a drawback. Here is the approach:


1. When user opens the Ref.jsp page, call a synchronised function called maxRefId(). This function will connect to the database gets the maximum ReferenceId from the Reference table, and a dummy record is created with ReferenceId one higher than the maximum ReferenceId. This dummy record's referenceId will be returned to the JSP page, which will be populated in the ReferenceId text Box.
With this approach if different machines request for the Ref.jsp page at the same time, all machines will get different RefId's because of the Sunchronized maxRefId function. Thus the user will enter other reference details and will submit. This details can be updated onto the Reference Table.


Drawback: The draw back with this approach is that every time a user opens the Ref.jsp page a new record is getting created. And if user doesnt enter the other reference details, the record will be left incomplete. If this situation happens many times, the table will be left with many incomplete records.


I request u to suggest any other better approach to implement this. I will be waiting for your replies.


Thanks to all in advance.
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi satish,
I can think of 2 soln but not very sure which will help you out.
First soln is keep this reference id in a seperate table with only one row and one column. Every time you read the reference id when the user hits the jsp page and increment the read value by 1 and give it to the user as well as save the reference id in the table. Then you update the reference table only when the user enters all the other details.

Second soln is do everything as you have already done but when the user did not enter any further reference details, delete that records from the reference table.

If you are using this reference id as autogenerated unique number, doing max+1 is a very bad idea, because this will affect the performance of the application if the reference table grows.

Better soln is for example if you are using oracle as the database then get the sequence number and then increment it.

Hope this helps
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic