db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject cvs commit: db-ojb/xdocs odmg-tutorial.xml
Date Wed, 01 Oct 2003 19:32:19 GMT
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();
       }
                   ]]></source>
  @@ -192,6 +194,40 @@
                       The ODMG specification includes several levels of locks and isolation.
These are
                       explained in much more detail in the <a href="lockmanager.html">Lock
Manager</a>
                       documentation.
  +                </p>
  +                <p>
  +                    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.
  +                </p>
  +            </subsection>
  +            <subsection name="Persisting Non-Transactional Objects">
  +                <p>
  +                    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:
  +                </p>
  +                <source><![CDATA[
  +    public static void persistChanges(Product product)
  +    {
  +        Implementation impl = OJB.getInstance();
  +        TransactionExt tx = (TransactionExt) impl.newTransaction();
  +
  +        tx.begin();
  +        tx.markDirty(product);
  +        tx.commit();
  +    }
  +                ]]></source>
  +                <p>
  +                    In this function the product is modified outside the context of the
  +                    transaction, and is then the changes are persisted within a transaction.
  +                    The <code>TransactionExt.markDirty()</code> method indicates
to the Transaction
  +                    that the passed object has been modified, even if the Transaction itself
sees
  +                    no changes to the object.
                   </p>
               </subsection>
           </section>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message