Return-Path:
Delivered-To: apmail-db-ojb-dev-archive@www.apache.org
Received: (qmail 41594 invoked from network); 2 Oct 2003 05:23:27 -0000
Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12)
by minotaur-2.apache.org with SMTP; 2 Oct 2003 05:23:27 -0000
Received: (qmail 80481 invoked by uid 500); 2 Oct 2003 05:23:05 -0000
Delivered-To: apmail-db-ojb-dev-archive@db.apache.org
Received: (qmail 80321 invoked by uid 500); 2 Oct 2003 05:23:04 -0000
Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm
Precedence: bulk
List-Unsubscribe:
List-Subscribe:
List-Help:
List-Post:
List-Id: "OJB Developers List"
Reply-To: "OJB Developers List"
Delivered-To: mailing list ojb-dev@db.apache.org
Received: (qmail 9348 invoked by uid 500); 1 Oct 2003 19:32:10 -0000
Date: 1 Oct 2003 19:32:19 -0000
Message-ID: <20031001193219.55361.qmail@minotaur.apache.org>
From: brianm@apache.org
To: db-ojb-cvs@apache.org
Subject: cvs commit: db-ojb/xdocs odmg-tutorial.xml
X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N
X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N
brianm 2003/10/01 12:32:19
Modified: src/test/org/apache/ojb/tutorials ODMGExample.java
xdocs odmg-tutorial.xml
Log:
Fixed major bug in sample code and added discussion of locking in ODMG to the tutorial
Revision Changes Path
1.2 +15 -0 db-ojb/src/test/org/apache/ojb/tutorials/ODMGExample.java
Index: ODMGExample.java
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/tutorials/ODMGExample.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ODMGExample.java 30 Sep 2003 19:29:16 -0000 1.1
+++ ODMGExample.java 1 Oct 2003 19:32:19 -0000 1.2
@@ -7,6 +7,7 @@
import org.odmg.Transaction;
import org.apache.ojb.odmg.OJB;
+import org.apache.ojb.odmg.TransactionExt;
/**
* ODMG API Usage Examples for the ODMG Tutorial
@@ -19,6 +20,7 @@
{
Implementation impl = OJB.getInstance();
Transaction tx = impl.newTransaction();
+ tx.begin();
tx.lock(product, Transaction.WRITE);
tx.commit();
}
@@ -27,6 +29,7 @@
{
Implementation impl = OJB.getInstance();
Transaction tx = impl.newTransaction();
+ tx.begin();
OQLQuery query = impl.newOQLQuery();
query.create("select products from " + Product.class + " where name = '" + name + "'");
@@ -41,6 +44,7 @@
{
Implementation impl = OJB.getInstance();
Transaction tx = impl.newTransaction();
+ tx.begin();
tx.lock(product, Transaction.WRITE);
product.setStock(new Integer(product.getStock().intValue() - number));
@@ -52,8 +56,19 @@
{
Implementation impl = OJB.getInstance();
Transaction tx = impl.newTransaction();
+ tx.begin();
Database db = impl.getDatabase(product);
db.deletePersistent(product);
+ tx.commit();
+ }
+
+ public static void persistChanges(Product product)
+ {
+ Implementation impl = OJB.getInstance();
+ TransactionExt tx = (TransactionExt) impl.newTransaction();
+
+ tx.begin();
+ tx.markDirty(product);
tx.commit();
}
1.2 +38 -2 db-ojb/xdocs/odmg-tutorial.xml
Index: odmg-tutorial.xml
===================================================================
RCS file: /home/cvs/db-ojb/xdocs/odmg-tutorial.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- odmg-tutorial.xml 30 Sep 2003 19:29:16 -0000 1.1
+++ odmg-tutorial.xml 1 Oct 2003 19:32:19 -0000 1.2
@@ -83,6 +83,7 @@
{
Implementation impl = OJB.getInstance();
Transaction tx = impl.newTransaction();
+ tx.begin();
tx.lock(product, Transaction.WRITE);
tx.commit();
}
@@ -113,6 +114,7 @@
{
Implementation impl = OJB.getInstance();
Transaction tx = impl.newTransaction();
+ tx.begin();
OQLQuery query = impl.newOQLQuery();
query.create("select products from " + Product.class + " where name = '" + name + "'");
@@ -134,9 +136,9 @@
{
Implementation impl = OJB.getInstance();
Transaction tx = impl.newTransaction();
+ tx.begin();
tx.lock(product, Transaction.WRITE);
-
product.setStock(new Integer(product.getStock().intValue() - number));
tx.commit();
@@ -162,9 +164,9 @@
Implementation impl = OJB.getInstance();
Transaction tx = impl.newTransaction();
+ tx.begin();
Database db = impl.getDatabase(product);
db.deletePersistent(product);
-
tx.commit();
}
]]>
@@ -192,6 +194,40 @@
The ODMG specification includes several levels of locks and isolation. These are
explained in much more detail in the Lock Manager
documentation.
+
+
+ In the ODMG API, locks obtained on objects are locked within the context
+ of a thread. Any object modified within the context of a transaction will
+ be stored with the transaction, however changes made to the same object
+ by other threads will also be stored. The ODMG locking conventions ensure
+ that an object can only be modified within the transaction on the locking thread.
+
+
+
+
+ Frequently, objects will be modified outside of the context of an
+ ODMG transaction, such as a data access object in a web application.
+ In those cases a persistent object can still be modified, but not
+ directly through the OMG ODMG specification. OJB provides an extension
+ to the ODMG specification for instances such as this. Examine this code:
+
+
+
+ In this function the product is modified outside the context of the
+ transaction, and is then the changes are persisted within a transaction.
+ The TransactionExt.markDirty() method indicates to the Transaction
+ that the passed object has been modified, even if the Transaction itself sees
+ no changes to the object.
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org