db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject cvs commit: db-ojb release-notes.txt
Date Sat, 13 Dec 2003 18:18:33 GMT
thma        2003/12/13 10:18:33

  Modified:    src/jdori/org/apache/ojb/tutorial5 UCDeleteProduct.java
                        UCEditProduct.java
               xdocs    tutorial4.xml
               .        release-notes.txt
  Log:
  remove obsolete broker calls from the JDO tutorials
  
  Revision  Changes    Path
  1.5       +31 -31    db-ojb/src/jdori/org/apache/ojb/tutorial5/UCDeleteProduct.java
  
  Index: UCDeleteProduct.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/jdori/org/apache/ojb/tutorial5/UCDeleteProduct.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- UCDeleteProduct.java	8 Apr 2003 20:19:27 -0000	1.4
  +++ UCDeleteProduct.java	13 Dec 2003 18:18:33 -0000	1.5
  @@ -1,12 +1,12 @@
   package org.apache.ojb.tutorial5;
   
  +import java.util.Collection;
  +
   import javax.jdo.PersistenceManager;
   import javax.jdo.PersistenceManagerFactory;
  +import javax.jdo.Query;
   import javax.jdo.Transaction;
   
  -import org.apache.ojb.broker.Identity;
  -import org.apache.ojb.broker.PersistenceBroker;
  -import org.apache.ojb.broker.PersistenceBrokerFactory;
   
   /**
    * Usecase for deleting a Product entry
  @@ -29,45 +29,45 @@
       public void apply()
       {
       	PersistenceManager manager = null;
  +		Transaction tx = null;
           String in = readLineWithMessage("Delete Product with id:");
           int id = Integer.parseInt(in);
   
  -        // We don't have a reference to the selected Product.
  -        // So first we have to lookup the object,
  -        // we do this by a query by example (QBE):
  -        // 1. build an example object with matching primary key values:
  -        Product example = new Product();
  -        example.setId(id);
  -        PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -        Identity oid = new Identity(example, broker);
           try
           {
  -        	manager = factory.getPersistenceManager();
  -            
  -            // start transaction
  -            Transaction tx = null;
  -            // open transaction
  -            tx = manager.currentTransaction();
  -            tx.begin();
  -
  -			Product toBeDeleted =
  -                (Product) manager.getObjectById(oid, false);
  -            if (toBeDeleted == null)
  -            {
  -            	System.out.println("did not find a matching instance...");
  -            	tx.rollback();
  -            	return;	
  -            }
  -            manager.deletePersistent(toBeDeleted);
  +			// 1. start transaction
  +			manager = factory.getPersistenceManager();   
  +			tx = manager.currentTransaction();       
  +			tx.begin();
   
  -            tx.commit();
  -            manager.close();
  +			// 2. Build a query to look up product by the id            
  +			Query query = manager.newQuery(Product.class, "id == " + id);     
  +            
  +			// 3. execute query  
  +			Collection result = (Collection) query.execute();
  +			
  +			// 4. if no matching product was found, print a message
  +			if (result.size() == 0)
  +			{
  +				System.out.println("did not find a Product with id=" + id);
  +				tx.rollback();
  +				manager.close();
  +				return;		
  +			}
  +			// 5. if a matching product was found, delete it
  +			else
  +			{
  +				Product toBeDeleted = (Product) result.iterator().next();        	
  +				manager.deletePersistent(toBeDeleted);
  +	            tx.commit();
  +            	manager.close();
  +			}
           }
           catch (Throwable t)
           {
               // rollback in case of errors
               //broker.abortTransaction();
  -            manager.currentTransaction().rollback();
  +            tx.rollback();
               t.printStackTrace();
           }
       }
  
  
  
  1.7       +2 -0      db-ojb/src/jdori/org/apache/ojb/tutorial5/UCEditProduct.java
  
  Index: UCEditProduct.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/jdori/org/apache/ojb/tutorial5/UCEditProduct.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- UCEditProduct.java	5 Dec 2003 22:47:04 -0000	1.6
  +++ UCEditProduct.java	13 Dec 2003 18:18:33 -0000	1.7
  @@ -73,6 +73,8 @@
                           + toBeEdited.getStock()
                           + "):");
               toBeEdited.setStock(Integer.parseInt(in));
  +            
  +            // 5. commit changes
               manager.currentTransaction().commit();
           }
           catch (Throwable t)
  
  
  
  1.13      +117 -112  db-ojb/xdocs/tutorial4.xml
  
  Index: tutorial4.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/xdocs/tutorial4.xml,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- tutorial4.xml	7 Aug 2003 22:50:58 -0000	1.12
  +++ tutorial4.xml	13 Dec 2003 18:18:33 -0000	1.13
  @@ -302,15 +302,15 @@
   </p>
   <p>
   	The user enters the products unique id.
  -	The object to be edited is looked up by this id. (Steps 1. and 2.)
  +	The object to be edited is looked up by this id. (Steps 1., 2. and 3.)
   	This lookup is necessary as our
   	application does not hold a list of all product objects.
   </p>
   <p>
  -	The product is then edited (Step 3.).
  +	The product is then edited (Step 4.).
   </p>
   <p>
  -	In step four the transaction is commited. All changes to objects
  +	In step five the transaction is commited. All changes to objects
   	touched by the transaction are now made persistent.
       Because we modified an existing object an update operation is
       performed against the backend database.
  @@ -318,64 +318,67 @@
   <source><![CDATA[
   public void apply()
   {
  -    PersistenceManager manager = null;
  -    String in = readLineWithMessage("Edit Product with id:");
  -    int id = Integer.parseInt(in);
  -
  -    // We don't have a reference to the selected Product.
  -    // So first we have to lookup the object,
  -
  -    Product toBeEdited;
  -    try
  -    {
  -        manager = factory.getPersistenceManager();
  -
  -        // 1. create Identity representing the instance to edit.
  -        Product example = new Product();
  -        example.setId(id);
  -        Identity oid = new Identity(example);
  -
  -        // 2. start tx and retrieve instance by identity lookup
  -        manager.currentTransaction().begin();
  -        toBeEdited = (Product) manager.getObjectById(oid, false);
  -        if (toBeEdited == null)
  -        {
  -            System.out.println("did not find a matching instance...");
  -            manager.currentTransaction().rollback();
  -            return;
  -        }
  -
  -        // 3. edit the existing entry
  -        System.out.println("please edit the product entry");
  -        in =
  -            readLineWithMessage(
  -                "enter name (was " + toBeEdited.getName() + "):");
  -        toBeEdited.setName(in);
  -        in =
  -            readLineWithMessage(
  -                "enter price (was " + toBeEdited.getPrice() + "):");
  -        toBeEdited.setPrice(Double.parseDouble(in));
  -        in =
  -            readLineWithMessage(
  -                "enter available stock (was "
  -                    + toBeEdited.getStock()
  -                    + "):");
  -        toBeEdited.setStock(Integer.parseInt(in));
  -
  -        // 4. commit transaction. changes to toBeEdited are made
  -        // persistent
  -        manager.currentTransaction().commit();
  -    }
  -    catch (Throwable t)
  -    {
  -        // rollback in case of errors
  -        manager.currentTransaction().rollback();
  -        t.printStackTrace();
  -    }
  -    finally
  -    {
  -        manager.close();
  -    }
  +	PersistenceManager manager = null;
  +    	
  +	// ask user which object should edited
  +	String in = readLineWithMessage("Edit Product with id:");
  +	int id = Integer.parseInt(in);
  +
  +	Product toBeEdited;
  +	try
  +	{
  +		// 1. start transaction
  +		manager = factory.getPersistenceManager();          
  +		manager.currentTransaction().begin();
  +
  +		// We don't have a reference to the selected Product.
  +		// So we have to look it up first,
  +
  +
  +		// 2. Build a query to look up product by the id            
  +		Query query = manager.newQuery(Product.class, "id == " + id);     
  +            
  +		// 3. execute query  
  +		Collection result = (Collection) query.execute();
  +		toBeEdited = (Product) result.iterator().next();
  +            
  +		if (toBeEdited == null)
  +		{
  +			System.out.println("did not find a matching instance...");
  +			manager.currentTransaction().rollback();
  +			return;	
  +		}
  +            
  +		// 4. edit the existing entry
  +		System.out.println("please edit the product entry");
  +		in =
  +			readLineWithMessage(
  +				"enter name (was " + toBeEdited.getName() + "):");
  +		toBeEdited.setName(in);
  +		in =
  +			readLineWithMessage(
  +				"enter price (was " + toBeEdited.getPrice() + "):");
  +		toBeEdited.setPrice(Double.parseDouble(in));
  +		in =
  +			readLineWithMessage(
  +				"enter available stock (was "
  +					+ toBeEdited.getStock()
  +					+ "):");
  +		toBeEdited.setStock(Integer.parseInt(in));
  +		
  +		// 5. commit changes
  +		manager.currentTransaction().commit();
  +	}
  +	catch (Throwable t)
  +	{
  +		// rollback in case of errors
  +		manager.currentTransaction().rollback();
  +		t.printStackTrace();
  +	}
  +	finally 
  +	{
  +		manager.close();	
  +	}
   }
   ]]></source>
   
  @@ -389,68 +392,70 @@
   </p>
   <p>
   	The user enters the products unique id.
  -	The object to be deleted is looked up by this id. (Steps 1. and 2.)
  +	The object to be deleted is looked up by this id. (Steps 1., 2. and 3.)
   	This lookup is necessary as our
   	application does not hold a list of all product objects.
   </p>
   <p>
  -	In the third step we ask the PersistenceManager to
  -	delete the persistent object.
  +	In the fourth step we check if a Product matching to the id could be found.
  +	If no entry is found we print a message and quit the work.
   </p>
  -<p>
  -	In the last step we commit the transaction. All changes to objects
  -	touched by the transaction are now made persistent.
  -    Because we marked an existing object for deletion, a delete operation is
  +<p>	
  +	If a Product entry was found we delete it in step 5 by calling
  +	the PersistenceManager to delete the persistent object.
  +
  +	On transaction commit all changes to objects
  +	touched by the transaction are made persistent.
  +    Because we marked the Product entry for deletion, a delete operation is
       performed against the backend database.
   </p>
   
   <source><![CDATA[
   public void apply()
   {
  -    PersistenceManager manager = null;
  -    String in = readLineWithMessage("Delete Product with id:");
  -    int id = Integer.parseInt(in);
  -
  -    // We don't have a reference to the selected Product.
  -    // 1. build an Identity representing the instance in question
  -    Product example = new Product();
  -    example.setId(id);
  -    Identity oid = new Identity(example);
  -    try
  -    {
  -        // 2. obtain PM, start tx and perform identity lookup
  -        manager = factory.getPersistenceManager();
  -
  -        // start transaction
  -        Transaction tx = null;
  -        // open transaction
  -        tx = manager.currentTransaction();
  -        tx.begin();
  -
  -        Product toBeDeleted =
  -            (Product) manager.getObjectById(oid, false);
  -        if (toBeDeleted == null)
  -        {
  -            System.out.println("did not find a matching instance...");
  -            tx.rollback();
  -            return;
  -        }
  -        // 3. mark object as deleted
  -        manager.deletePersistent(toBeDeleted);
  -
  -        // commit transaction. A DELETE statement is generated
  -        // and executed to remove toBeDeleted from the database
  -        tx.commit();
  -        manager.close();
  -    }
  -    catch (Throwable t)
  -    {
  -        // rollback in case of errors
  -        manager.currentTransaction().rollback();
  -        t.printStackTrace();
  -    }
  -}
  -]]></source>
  +	PersistenceManager manager = null;
  +	Transaction tx = null;
  +	String in = readLineWithMessage("Delete Product with id:");
  +	int id = Integer.parseInt(in);
  +
  +	try
  +	{
  +		// 1. start transaction
  +		manager = factory.getPersistenceManager();   
  +		tx = manager.currentTransaction();       
  +		tx.begin();
  +
  +		// 2. Build a query to look up product by the id            
  +		Query query = manager.newQuery(Product.class, "id == " + id);     
  +            
  +		// 3. execute query  
  +		Collection result = (Collection) query.execute();
  +			
  +		// 4. if no matching product was found, print a message
  +		if (result.size() == 0)
  +		{
  +			System.out.println("did not find a Product with id=" + id);
  +			tx.rollback();
  +			manager.close();
  +			return;		
  +		}
  +		// 5. if a matching product was found, delete it
  +		else
  +		{
  +			Product toBeDeleted = (Product) result.iterator().next();        	
  +			manager.deletePersistent(toBeDeleted);
  +			tx.commit();
  +			manager.close();
  +		}
  +	}
  +	catch (Throwable t)
  +	{
  +		// rollback in case of errors
  +		//broker.abortTransaction();
  +		tx.rollback();
  +		t.printStackTrace();
  +	}
  +}]]></source>
   
   </subsection>
   </section>
  
  
  
  1.28      +5 -5      db-ojb/release-notes.txt
  
  Index: release-notes.txt
  ===================================================================
  RCS file: /home/cvs/db-ojb/release-notes.txt,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- release-notes.txt	13 Dec 2003 17:51:05 -0000	1.27
  +++ release-notes.txt	13 Dec 2003 18:18:33 -0000	1.28
  @@ -7,7 +7,6 @@
   provides transparent transactional persistence for Java Objects against
   relational databases. OJB provides ODMG and JDO interfaces.
   
  -
   ---------------------------------------------------------------------
   Release 1.0 rc5
   ---------------------------------------------------------------------
  @@ -19,11 +18,10 @@
   - With this release we are feature complete for the 1.0 release!
   For 1.0 you should not expect more features to be added.
   
  -
   NOTES:
  -- changes in repository.dtd, OJB.properties are made
  +- slight changes in repository.dtd, OJB.properties were made
   
  -- intern kernel interface method signature changed:
  +- internal kernel interface method signature changed:
   in JdbcAccess two method signatures change
   in StatementManagerIF one method signature change
   These changes are necessary to fix a "design bug" in handling
  @@ -63,6 +61,8 @@
   please cast Transaction to TransactionExt and use new method flush().
   
   - make odmg collections pluggable via OJB.properties file
  +
  +- Restructuring and further enhancements of the documentation.
   
   
   BUG FIXES:
  
  
  

---------------------------------------------------------------------
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