home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / demo1.xsp < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  2.4 KB  |  78 lines

  1. <?xml version="1.0"?>
  2. <!--
  3.   Copyright 1999-2004 The Apache Software Foundation
  4.  
  5.   Licensed under the Apache License, Version 2.0 (the "License");
  6.   you may not use this file except in compliance with the License.
  7.   You may obtain a copy of the License at
  8.  
  9.       http://www.apache.org/licenses/LICENSE-2.0
  10.  
  11.   Unless required by applicable law or agreed to in writing, software
  12.   distributed under the License is distributed on an "AS IS" BASIS,
  13.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.   See the License for the specific language governing permissions and
  15.   limitations under the License.
  16. -->
  17.  
  18. <!--
  19.  * Simple demo that insert a row into hsqldb using OJB with JDO
  20.  *
  21.  * @author <a href="mailto:antonio@apache.org>Antonio Gallardo</a>
  22.  * @version CVS $Revision: 1.4 $ $Date: 2004/03/17 11:28:20 $
  23. -->
  24.  
  25. <xsp:page language="java" xmlns:xsp="http://apache.org/xsp">
  26.  
  27.     <xsp:structure>
  28.         <xsp:include>javax.jdo.PersistenceManager</xsp:include>
  29.         <xsp:include>javax.jdo.Transaction</xsp:include>
  30.         <xsp:include>org.apache.cocoon.ojb.jdo.components.JdoPMF</xsp:include>
  31.         <xsp:include>javax.jdo.Transaction</xsp:include>
  32.         <xsp:include>org.apache.cocoon.ojb.samples.bean.Department</xsp:include>
  33.     </xsp:structure>
  34.  
  35.     <xsp:init-page>
  36.         JdoPMF pmf = null;
  37.         PersistenceManager persistenceManager = null;
  38.         Department bean = new Department();
  39.         String s;
  40.     </xsp:init-page>
  41.  
  42.     <page>
  43.         <content>
  44.             <title>Hello</title>
  45.             <para>This is my first Cocoon page with OJB!</para>
  46.             <xsp:logic>
  47.             try {
  48.                 /* Get the PersistenceManager */
  49.                 try {
  50.                     pmf = (JdoPMF) manager.lookup(JdoPMF.ROLE);
  51.                     persistenceManager = pmf.getPersistenceManager();
  52.                 } catch (ComponentException cme) {
  53.                     getLogger().error("Could not look up the PersistenceManager", cme);
  54.                 }
  55.                 <!-- Setting up the Bean -->
  56.                 bean.setId(5);
  57.                 bean.setName("JDO Development");
  58.                 <!-- 2. Get current transaction -->
  59.                 Transaction tx = persistenceManager.currentTransaction();
  60.                 <!-- 3. Start a Transaction -->
  61.                 tx.begin();
  62.                 <!-- 4. now perform persistence operations. Store the new user -->
  63.                 persistenceManager.makePersistent(bean);
  64.                 <!-- 5. Commit the transaction  -->
  65.                 tx.commit();
  66.                 s = bean.getId() + " : " + bean.getName();
  67.             </xsp:logic>
  68.             <p> Inserted data: <xsp:expr>s</xsp:expr> </p>
  69.             <xsp:logic>
  70.             }
  71.             finally {
  72.                 manager.release((Component)pmf);
  73.             }
  74.         </xsp:logic>
  75.         </content>
  76.     </page>
  77. </xsp:page>
  78.