Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Build a Derby calendar, Part 3: Using transactions and locking

Nicholas Chase has been involved in Web-site development for companies such as Lucent Technologies, Sun Microsystems, Oracle, and the Tampa Bay Buccaneers. He has been a high school physics teacher, a low-level radioactive waste facility manager, an online science fiction magazine editor, a multimedia engineer, an Oracle instructor, and the chief technology officer of an interactive communications company. He is the author of several books, including XML Primer Plus.

Summary:  In this final tutorial of the series, you'll finish the calendar and reminder application using the Java™ language and the Apache Derby database. In Part 1 and Part 2 of this three-part series, you created a basic calendar and reminder application using a Derby database back end and a GUI and a Web-based front end. Now that the proof of concept is complete, you can add a more friendly interface and use transactions and locking to create a truly multiuser system.

View more content in this series

Date:  27 Sep 2005
Level:  Intermediate PDF:  A4 and Letter (485 KB | 46 pages)Get Adobe® Reader®

Activity:  3349 views
Comments:  

Transactions in action

It's time to stop talking about transactions and isolation levels and finally see them in action. Open two different instances of the CalendarFrame application.

TRANSACTION_READ_COMMITTED

Make sure both application instances are set to See only saved data, which corresponds to the TRANSACTION_READ_COMMITTED isolation level.

In the first window, pick a day and add an event. Then go to the second window and display the events for that day. After a pause, you should get a dialog box (see Figure 10) telling you that the application can't retrieve the data because it's locked.


Figure 10. When you can't get a lock on the data
When you can't get a lock on the data

Now, in the first window, click the Save button to commit the transaction. Go back to the second window and try to refresh the page, but only once (see Figure 11).


Figure 11. Committing the transaction
Committing the transaction

Notice that you can now request the same data that was previously locked.


TRANSACTION_READ_UNCOMMITTED

In the previous example, you saw how the database kept one user from seeing uncommitted data for another user. But what if you don't want that to happen? In both windows, set the isolation level to See all data.

Now add a new record in the first window, but don't save your changes. Go to the second window and display the events for that date. You should see all the events for that date, including the one you just entered a moment ago (see Figure 12).


Figure 12. Seeing dirty data
Seeing 'dirty' data

Now users can complete all their event-management tasks, including seeing what other users are up to.

9 of 13 | Previous | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source, Information Management
ArticleID=94193
TutorialTitle=Build a Derby calendar, Part 3: Using transactions and locking
publish-date=09272005
author1-email=ibmquestions@nicholaschase.com
author1-email-cc=

Next steps from IBM

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.