cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anto...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/ojb/java/org/apache/cocoon/ojb/samples EmployeeImpl.java
Date Fri, 10 Oct 2003 16:00:46 GMT
antonio     2003/10/10 09:00:46

  Modified:    src/blocks/ojb/samples/woody employee.js employee.xml
               src/blocks/ojb/java/org/apache/cocoon/ojb/samples
                        EmployeeImpl.java
  Log:
  OJB Employee: Adding remove and update function.
  
  Revision  Changes    Path
  1.5       +1 -1      cocoon-2.1/src/blocks/ojb/samples/woody/employee.js
  
  Index: employee.js
  ===================================================================
  RCS file: /home/cvs//cocoon-2.1/src/blocks/ojb/samples/woody/employee.js,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- employee.js	10 Oct 2003 06:10:00 -0000	1.4
  +++ employee.js	10 Oct 2003 16:00:46 -0000	1.5
  @@ -22,7 +22,7 @@
   	form.save(bean);
   
       // Insert Bean in Database
  -	ojbEmployee.insert(bean, factory);
  +	ojbEmployee.remove(bean, factory);
   	// Clean up the operation
   	cocoon.releaseComponent(factory);
   
  
  
  
  1.4       +4 -4      cocoon-2.1/src/blocks/ojb/samples/woody/employee.xml
  
  Index: employee.xml
  ===================================================================
  RCS file: /home/cvs//cocoon-2.1/src/blocks/ojb/samples/woody/employee.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- employee.xml	10 Oct 2003 06:10:00 -0000	1.3
  +++ employee.xml	10 Oct 2003 16:00:46 -0000	1.4
  @@ -62,9 +62,9 @@
       <wd:field id="id" required="true">
           <wd:label>ID :</wd:label>
           <wd:datatype base="integer">
  -        <wd:validation>
  +        <!-- <wd:validation>
                   <wd:range min="20"/>
  -            </wd:validation>
  +            </wd:validation> -->
           </wd:datatype>
       </wd:field>
   
  
  
  
  1.4       +47 -4     cocoon-2.1/src/blocks/ojb/java/org/apache/cocoon/ojb/samples/EmployeeImpl.java
  
  Index: EmployeeImpl.java
  ===================================================================
  RCS file: /home/cvs//cocoon-2.1/src/blocks/ojb/java/org/apache/cocoon/ojb/samples/EmployeeImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- EmployeeImpl.java	10 Oct 2003 06:10:00 -0000	1.3
  +++ EmployeeImpl.java	10 Oct 2003 16:00:46 -0000	1.4
  @@ -58,7 +58,7 @@
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
   /**
  - *  Department's Impl
  + *  Employee's Impl
    *
    * @author <a href="mailto:antonio@apache.org">Antonio Gallardo</a>
    * @version CVS $Id$
  @@ -66,8 +66,7 @@
   public class EmployeeImpl {
   
   	public EmployeeImpl(){}
  -	
  -	
  +
   	public void retrieve(Employee bean, JdoPMF pmf) {
   		
   		/* 1. Get the PersistenceManager */
  @@ -101,6 +100,50 @@
   		// 5. Commit the transaction
   		tx.commit();
   	}
  +	
  +	public void update(Employee bean, JdoPMF pmf) {
  +		
  +		/* 1. Get the PersistenceManager */
  +		PersistenceManager persistenceManager = pmf.getPersistenceManager();
  +		
  +		Employee e = new Employee();
  +		e.setId(bean.getId());
  +		PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +		Identity oid = new Identity(e, broker);
  +		
  +		Employee b = new Employee();
  +		//	2. start transaction
  +		persistenceManager.currentTransaction().begin();
  +		// 3. Get the Object based on the primary key
  +		b = (Employee) persistenceManager.getObjectById(oid, false);
  +		// 4. Copy data from bean
  +		copyData(bean, b);
  +		// Store to database
  +		// persistenceManager.makePersistent(b);
  +		// 5. End transaction
  +		persistenceManager.currentTransaction().commit();
  +	}
  +	
  +	public void remove(Employee bean, JdoPMF pmf) {
  +		
  +			/* 1. Get the PersistenceManager */
  +			PersistenceManager persistenceManager = pmf.getPersistenceManager();
  +		
  +			Employee e = new Employee();
  +			e.setId(bean.getId());
  +			PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +			Identity oid = new Identity(e, broker);
  +		
  +			Employee b = new Employee();
  +			//	2. start transaction
  +			persistenceManager.currentTransaction().begin();
  +			// 3. Get the Object based on the primary key
  +			b = (Employee) persistenceManager.getObjectById(oid, false);
  +			// Delete in the database
  +			persistenceManager.deletePersistent(b);
  +			// 5. End transaction
  +			persistenceManager.currentTransaction().commit();
  +		}
   	
   	private void copyData(Employee from, Employee to)
   	{
  
  
  

Mime
View raw message