cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/ojb/java/org/apache/cocoon/ojb/samples EmployeeDAO.java
Date Wed, 04 Feb 2004 17:33:59 GMT
joerg       2004/02/04 09:33:59

  Modified:    src/blocks/ojb/samples/jdo/xsp demo1.xsp
               src/blocks/ojb/conf repository.xml package.jdo
               src/blocks/ojb build.xml
               src/blocks/ojb/samples/woody employee.js
               src/blocks/ojb/samples/odmg/xsp demo1.xsp
  Added:       src/blocks/ojb/java/org/apache/cocoon/ojb/samples/bean
                        Employee.java Department.java
               src/blocks/ojb/java/org/apache/cocoon/ojb/samples
                        EmployeeDAO.java
  Removed:     src/blocks/ojb/conf EmployeeImpl.java
               src/blocks/ojb/conf/java Department.java Employee.java
  Log:
  - fixed some bugs like missing repository.xml and EmployeeImpl.class;
  - renamed EmployeeImpl to EmployeeDAO (data access object) as it is not an implementation
of an interface as one would expect;
  - classes to be enhanced into additional package "bean"
  - moved java files from conf and conf/java to src/java/**/samples/ (what hacks have that
been!!), so the default samples build can be used;
  - made "personnel" datasource the default in repository.xml as "default" is not available
in cocoon.xconf and so does not work;
  
  Please never so much hacks in a build again! It was a hard work to get that working!
  
  Revision  Changes    Path
  1.1                  cocoon-2.1/src/blocks/ojb/java/org/apache/cocoon/ojb/samples/bean/Employee.java
  
  Index: Employee.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.ojb.samples.bean;
  
  import java.io.Serializable;
  
  /**
   *  Employee's Bean
   *
   * @author <a href="mailto:antonio@apache.org">Antonio Gallardo</a>
   * @version CVS $Id: Employee.java,v 1.1 2004/02/04 17:33:58 joerg Exp $
  */
  public class Employee implements Serializable {
  
      private int id;
      protected int departmentId;
      protected String name;
  
      public Employee(){
          this.id = 1;
          this.departmentId = 1;
          this.name = "My Name";
      }
  
      public int getId() {
          return this.id;
      }
  
      public int getDepartmentId() {
          return this.departmentId;
      }
  
      public String getName() {
          return this.name;
      }
  
      public void setId(int newId) {
          this.id = newId;
      }
  
      public void setDepartmentId(int newDepartmentId) {
          this.departmentId = newDepartmentId;
      }
  
      public void setName(String newName) {
          this.name = newName;
      }
  } 
  
  
  
  1.1                  cocoon-2.1/src/blocks/ojb/java/org/apache/cocoon/ojb/samples/bean/Department.java
  
  Index: Department.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.ojb.samples.bean;
  
  import java.io.Serializable;
  
  /**
   *  Department's Bean
   *
   * @author <a href="mailto:antonio@apache.org">Antonio Gallardo</a>
   * @version CVS $Id: Department.java,v 1.1 2004/02/04 17:33:58 joerg Exp $
  */
  public class Department implements Serializable {
  
      private int id;
      protected String name;
  
      public Department(){
      }
  
      public int getId() {
          return id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setId(int newId) {
          id = newId;
      }
  
      public void setName(String newName) {
          name = newName;
      }
  }
  
  
  
  1.2       +1 -1      cocoon-2.1/src/blocks/ojb/samples/jdo/xsp/demo1.xsp
  
  Index: demo1.xsp
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/ojb/samples/jdo/xsp/demo1.xsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- demo1.xsp	28 Sep 2003 04:31:10 -0000	1.1
  +++ demo1.xsp	4 Feb 2004 17:33:58 -0000	1.2
  @@ -65,7 +65,7 @@
   		<xsp:include>javax.jdo.Transaction</xsp:include>
   		<xsp:include>org.apache.cocoon.ojb.jdo.components.JdoPMF</xsp:include>
   		<xsp:include>javax.jdo.Transaction</xsp:include>
  -		<xsp:include>org.apache.cocoon.ojb.samples.Department</xsp:include>
  +		<xsp:include>org.apache.cocoon.ojb.samples.bean.Department</xsp:include>
   	</xsp:structure>
   
   	<xsp:init-page>
  
  
  
  1.2       +3 -4      cocoon-2.1/src/blocks/ojb/conf/repository.xml
  
  Index: repository.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/ojb/conf/repository.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- repository.xml	3 Feb 2004 11:12:04 -0000	1.1
  +++ repository.xml	4 Feb 2004 17:33:58 -0000	1.2
  @@ -18,7 +18,6 @@
   -->
       <jdbc-connection-descriptor
           jcd-alias="default"
  -        default-connection="true"
           platform="Hsqldb"
           jdbc-level="3.0"
           driver="org.hsqldb.jdbcDriver"
  @@ -42,18 +41,18 @@
           </sequence-manager>
       </jdbc-connection-descriptor>
   
  -    <jdbc-connection-descriptor jcd-alias="personnel">
  +    <jdbc-connection-descriptor jcd-alias="personnel" default-connection="true">
           <sequence-manager className="org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl">
               <attribute attribute-name="grabSize" attribute-value="5"/>
           </sequence-manager>
       </jdbc-connection-descriptor>
   
  -    <class-descriptor class="org.apache.cocoon.ojb.samples.Department" table="DEPARTMENT">
  +    <class-descriptor class="org.apache.cocoon.ojb.samples.bean.Department" table="DEPARTMENT">
           <field-descriptor name="id"   column="ID"   jdbc-type="INTEGER" primarykey="true"/>
           <field-descriptor name="name" column="NAME" jdbc-type="VARCHAR"/>
       </class-descriptor>
   
  -    <class-descriptor class="org.apache.cocoon.ojb.samples.Employee" table="EMPLOYEE">
  +    <class-descriptor class="org.apache.cocoon.ojb.samples.bean.Employee" table="EMPLOYEE">
           <field-descriptor name="id"             column="ID"             jdbc-type="INTEGER"
primarykey="true"/>
           <field-descriptor name="departmentId" column="DEPARTMENT_ID" jdbc-type="INTEGER"/>
           <field-descriptor name="name"           column="NAME"           jdbc-type="VARCHAR"/>
  
  
  
  1.2       +1 -1      cocoon-2.1/src/blocks/ojb/conf/package.jdo
  
  Index: package.jdo
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/ojb/conf/package.jdo,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- package.jdo	3 Feb 2004 11:12:04 -0000	1.1
  +++ package.jdo	4 Feb 2004 17:33:58 -0000	1.2
  @@ -2,7 +2,7 @@
   <!DOCTYPE jdo SYSTEM "file:/javax/jdo/jdo.dtd">
   
   <jdo>
  -    <package name="org.apache.cocoon.ojb.samples">
  +    <package name="org.apache.cocoon.ojb.samples.bean">
            <class name="Employee" identity-type="datastore">
               <extension vendor-name="ojb" key="table" value="EMPLOYEE"/>
               <field name="id" persistence-modifier="persistent">
  
  
  
  1.2       +47 -49    cocoon-2.1/src/blocks/ojb/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/ojb/build.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- build.xml	3 Feb 2004 11:12:04 -0000	1.1
  +++ build.xml	4 Feb 2004 17:33:59 -0000	1.2
  @@ -1,51 +1,49 @@
  -<project default="main" >
  +<project default="main">
   
  -<property name="jdoEnhancer" value="com.sun.jdori.enhancer.Main"/>
  -<property name="jdobuildpath" value="${build.webapp.webinf}/classes"/>
  -<property name="packagebuildpath" value="${jdobuildpath}/org/apache/cocoon/ojb/samples"/>
  -<property name="jdofile" value="${packagebuildpath}/package.jdo"/>
  -
  -   <path id="ojb.classpath">
  -<!--       <path refid="classpath"/> -->
  -		<pathelement path="${jdobuildpath}"/>
  -		<fileset dir="${block.dir}/lib">
  -			<include name="**/*.jar"/>
  -		</fileset>
  -		<fileset dir="${basedir}/lib/local">
  -			<include name="**/*.jar"/>
  -		</fileset>
  -	</path>
  -
  -    <available classname="${jdoEnhancer}" classpathref="ojb.classpath" property="jdo.present"/>
  -
  -    <target name="main" unless="unless.exclude.webapp.samples" depends="compile, jdo"/>
  -
  -    <target name="compile" unless="unless.exclude.webapp.samples">
  -        <copy file="${block.dir}/conf/package.jdo" tofile="${jdofile}"/>
  -        <copy file="${block.dir}/conf/repository.dtd" tofile="${jdobuildpath}/repository.dtd"/>
  -        <copy file="${block.dir}/conf/OJB.properties" tofile="${jdobuildpath}/OJB.properties"/>
  -        <copy file="${block.dir}/conf/EmployeeImpl.java" tofile="${build.blocks}/ojb/dest/java/EmployeeImpl.java"/>
  -        <!-- Build the Bean samples classes -->
  -        <mkdir dir="${jdobuildpath}"/>
  -        <javac destdir="${jdobuildpath}"
  -             debug="${compiler.debug}"
  -             optimize="${compiler.optimize}"
  -             deprecation="${compiler.deprecation}"
  -             target="${target.vm}"
  -             nowarn="${compiler.nowarn}"
  -             compiler="${compiler}">
  -                <src path="${block.dir}/conf/java"/>
  -        </javac>
  -    </target>
  -
  -    <target name="jdo" if="jdo.present" unless="unless.exclude.webapp.samples">
  -      <!-- Run the JDO Enhancer -->
  -      <echo>Running JDO Enhancer because ${jdo.present} ...</echo>
  -      <java fork="yes" failonerror="yes" classname="${jdoEnhancer}" classpathref="ojb.classpath">
  -        <arg line="-f -d ${jdobuildpath} ${jdofile} ${packagebuildpath}/Employee.class"/>
  -      </java>
  -      <java fork="yes" failonerror="yes" classname="${jdoEnhancer}" classpathref="ojb.classpath">
  -        <arg line="-f -d ${jdobuildpath} ${jdofile} ${packagebuildpath}/Department.class"/>
  -      </java>
  -    </target>
  +  <property name="jdoEnhancer" value="com.sun.jdori.enhancer.Main"/>
  +  <property name="build.blocks.ojb.samples" value="${build.blocks}/ojb/samples"/>
  +
  +  <path id="ojb.classpath">
  +    <pathelement path="${build.blocks.ojb.samples}"/>
  +    <fileset dir="${block.dir}/lib">
  +      <include name="*.jar"/>
  +    </fileset>
  +    <fileset dir="${basedir}/lib/local">
  +      <include name="*.jar"/>
  +    </fileset>
  +  </path>
  +
  +  <available classname="${jdoEnhancer}" classpathref="ojb.classpath" property="jdo.present"/>
  +
  +  <target name="main" unless="unless.exclude.webapp.samples" depends="jdo"/>
  +
  +  <target name="prepare">
  +    <mkdir dir="${build.blocks.ojb.samples}"/>
  +    <copy file="${block.dir}/conf/package.jdo" tofile="${build.blocks.ojb.samples}/package.jdo"/>
  +    <copy file="${block.dir}/conf/repository.dtd" tofile="${build.webapp.classes}/repository.dtd"/>
  +    <copy file="${block.dir}/conf/repository.xml" tofile="${build.webapp.classes}/repository.xml"/>
  +    <copy file="${block.dir}/conf/OJB.properties" tofile="${build.webapp.classes}/OJB.properties"/>
  +  </target>
  +
  +  <!-- unfortunately this build.xml is called before the samples are compiled,
  +       so we have to do it here "by hand" -->
  +  <target name="compile" unless="unless.exclude.webapp.samples">
  +    <javac compiler="${compiler}" nowarn="${compiler.nowarn}"
  +           target="${target.vm}" deprecation="${compiler.deprecation}"
  +           optimize="${compiler.optimize}" debug="${compiler.debug}"
  +           destdir="${build.blocks.ojb.samples}">
  +      <src path="${blocks}/ojb/java"/>
  +      <classpath refid="ojb.classpath"/>
  +      <include name="**/samples/bean/*.java"/>
  +    </javac>
  +  </target>
  +
  +  <target name="jdo" if="jdo.present" unless="unless.exclude.webapp.samples" depends="prepare,
compile">
  +    <property name="build.blocks.ojb.samples.package" value="${build.blocks.ojb.samples}/org/apache/cocoon/ojb/samples/bean"/>
  +    <!-- Run the JDO Enhancer -->
  +    <echo>Running JDO Enhancer because ${jdo.present} ...</echo>
  +    <java fork="yes" failonerror="yes" classname="${jdoEnhancer}" classpathref="ojb.classpath">
  +      <arg line="-f -d ${build.blocks.ojb.samples} ${build.blocks.ojb.samples}/package.jdo
${build.blocks.ojb.samples.package}/Employee.class ${build.blocks.ojb.samples.package}/Department.class"/>
  +    </java>
  +  </target>
   </project>
  
  
  
  1.8       +4 -4      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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- employee.js	4 Feb 2004 14:18:15 -0000	1.7
  +++ employee.js	4 Feb 2004 17:33:59 -0000	1.8
  @@ -6,13 +6,13 @@
      	var factory = cocoon.getComponent(Packages.org.apache.cocoon.ojb.jdo.components.JdoPMF.ROLE);
   
       // Create a empty Bean
  -    var bean = new Packages.org.apache.cocoon.ojb.samples.Employee();
  -    var ojbEmployee = Packages.org.apache.cocoon.ojb.samples.EmployeeImpl();
  +    var bean = new Packages.org.apache.cocoon.ojb.samples.bean.Employee();
  +    var dao = new Packages.org.apache.cocoon.ojb.samples.EmployeeDAO();
   
   	// Fill some initial data to the bean
   	bean.setId(1);
       // Load bean based on the given PrimaryKey
  -    ojbEmployee.retrieve(bean, factory);
  +    dao.retrieve(bean, factory);
   
       // Load the Bean to the form
       form.load(bean);
  @@ -22,7 +22,7 @@
   	form.save(bean);
   
       // Update Bean in Database
  -	ojbEmployee.update(bean, factory);
  +	dao.update(bean, factory);
   	// Clean up the operation
   	cocoon.releaseComponent(factory);
   
  
  
  
  1.2       +3 -3      cocoon-2.1/src/blocks/ojb/samples/odmg/xsp/demo1.xsp
  
  Index: demo1.xsp
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/ojb/samples/odmg/xsp/demo1.xsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- demo1.xsp	1 Feb 2004 21:37:29 -0000	1.1
  +++ demo1.xsp	4 Feb 2004 17:33:59 -0000	1.2
  @@ -62,7 +62,7 @@
   
   	<xsp:structure>
   		<xsp:include>org.apache.cocoon.ojb.odmg.components.OdmgImplementation</xsp:include>
  -		<xsp:include>org.apache.cocoon.ojb.samples.Department</xsp:include>
  +		<xsp:include>org.apache.cocoon.ojb.samples.bean.Department</xsp:include>
   		<xsp:include>org.odmg.Implementation</xsp:include>
   		<xsp:include>org.odmg.Transaction</xsp:include>
   		<xsp:include>org.odmg.ODMGException</xsp:include>
  
  
  
  1.1                  cocoon-2.1/src/blocks/ojb/java/org/apache/cocoon/ojb/samples/EmployeeDAO.java
  
  Index: EmployeeDAO.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.ojb.samples;
  
  import javax.jdo.PersistenceManager;
  import javax.jdo.Transaction;
  
  import org.apache.cocoon.ojb.jdo.components.JdoPMF;
  import org.apache.cocoon.ojb.samples.bean.*;
  import org.apache.ojb.broker.Identity;
  import org.apache.ojb.broker.PersistenceBroker;
  import org.apache.ojb.broker.PersistenceBrokerFactory;
  /**
   *  Employee's Impl
   *
   * @author <a href="mailto:antonio@apache.org">Antonio Gallardo</a>
   * @version CVS $Id: EmployeeDAO.java,v 1.1 2004/02/04 17:33:59 joerg Exp $
  */
  public class EmployeeDAO {
  
      public EmployeeDAO(){}
  
      public void retrieve(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 to bean
          copyData(b, bean);
          // 5. End transaction
          persistenceManager.currentTransaction().commit();
      }
  
      public void insert(Employee e, JdoPMF pmf) {
          /* 1. Get the PersistenceManager */
          PersistenceManager persistenceManager = pmf.getPersistenceManager();
          // 2. Get current transaction
          Transaction tx = persistenceManager.currentTransaction();
          // 3. Start a Transaction
          tx.begin();
          // 4. now perform persistence operations. Store the Employee
          persistenceManager.makePersistent(e);
          // 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) {
          to.setId(from.getId());
          to.setDepartmentId(from.getDepartmentId());
          to.setName(from.getName());
      }
  }
  
  
  

Mime
View raw message