-
August 19th, 2004, 11:53 AM
#1
Senior Member
Help in application structure
I have a application that updates several table at 1 time. But now i want to make sure that any failure in updating any 1 of the tables, the database would rollback to the original state. How should i design the structure of my application?
JSP page --- >> Servlet --- >> Controller --- >> Database
In my jsp page, this is where the user enters the data and submit. The servlet would capture all the data that the user enter into the textfield. The Controller class is a file, which i code to manage the updating of the records and also responsible for calling other classes to update to the database. For the database class it is just a class i coded to connect to database, and accept SQL statements through a method to perform insert,update,delete,query.
In my controller, i would call Class A and B to perform update operations.
so in Class A and B i would have something that look like this
Code:
public class A
....
public void updateRecord()
{
String sql = // here goes my sql update statement...
Database db = new Database();
db.executeUpdate(sql);
}
in my database class
Code:
public class Database
....
public void executeUpdate(String sql)
{
// all the update to database goes here
}
in my controller class
Code:
public class UpdateController()
{
A a = new A();
a.updateRecord();
B b = new B();
b.updateRecord();
}
where should i insert the codes to ensure the updating of the records smoothly?
-
August 19th, 2004, 09:23 PM
#2
Rusty here long time since I've played with tables at the programatical level but don't you have to do a comitt for the changes to stay? So if I you do x updates wait on doing the comitt until all x updates are successful, if any of the x fail do a roll back.
Cheers,
-D
If you spend more on coffee than on IT security, you will be hacked. What\'s more, you deserve to be hacked.
-- former White House cybersecurity adviser Richard Clarke
-
August 19th, 2004, 09:34 PM
#3
Death_Knight,
I am not sure of your question here..........are you wanting to update an entire record, or allow partial updates?
I am guessing that you are holding your database in more than one table?
I need a little bit more information, but I would guess that you should create forms for each section of the database, then link those?
cheers
-
August 19th, 2004, 10:16 PM
#4
This should have info on what you are looking for: http://www.fawcette.com/javapro/archives/bs0999/
What you are discussing is called transaction processing, it uses Commit and Rollback functionality to ensure the inserts/updates/deletes/whatever are proper before applying any one set of changes.
Chris Shepherd
The Nelson-Shepherd cutoff: The point at which you realise someone is an idiot while trying to help them.
\"Well as far as the spelling, I speak fluently both your native languages. Do you even can try spell mine ?\" -- Failed Insult
Is your whole family retarded, or did they just catch it from you?
-
August 20th, 2004, 03:08 AM
#5
Senior Member
http://www.fawcette.com/javapro/archives/bs0999/ posted by chsh.
Well, my application works somehow similar like this.
If you're using an ATM to transfer funds between your savings and checking accounts, at some point, the amount being transferred is subtracted from one account (step 1) and added to the other (step 2).
I will briefly describe the classes in my application what it does:
Database.java, a generic database class used by all classes performing database operations.
NewController.java, a specific class responsible for creating a customer record.
Customer.java, this class contain all the sql statements for /insert/update/delete/select operations.
Account.java, this class contain all the sql statements for /insert/update/delete/select operations.
the flow of my application
my Servlet would request all the information from the jsp page. For example
Code:
String name = request.getParameter("customerName");
String accountId = request.getParameter("accountId");
Customer customer = new Customer(name);
Account account = new Account(accountId);
NewController controller = new NewController(customer, account);
In my NewController class, i will call the methods in the Customer and Account class
Code:
public NewController(Customer c, Account a)
{
c.createCustomer();
a.createAccount();
}
So in my Customer and Account class
Code:
public void createCustomer()
{
Database db = new Database();
db.executeUpdate("insert into blah blah blah"):
}
In this case, whenever i create a new customer record, i need to create a account for the customer as well. But in any of the scenario, it may be the creation of the customer record fail, or the creation of the account record fail, how should i alter the structure of my application ?
Sorry for the bad english and my bad explanation
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|