home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0"?>
- <!--
- Copyright 1999-2004 The Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-
- <!--
- * Simple demo that insert a row into hsqldb using OJB with JDO
- *
- * @author <a href="mailto:antonio@apache.org>Antonio Gallardo</a>
- * @version CVS $Revision: 1.4 $ $Date: 2004/03/17 11:28:20 $
- -->
-
- <xsp:page language="java" xmlns:xsp="http://apache.org/xsp">
-
- <xsp:structure>
- <xsp:include>javax.jdo.PersistenceManager</xsp:include>
- <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.bean.Department</xsp:include>
- </xsp:structure>
-
- <xsp:init-page>
- JdoPMF pmf = null;
- PersistenceManager persistenceManager = null;
- Department bean = new Department();
- String s;
- </xsp:init-page>
-
- <page>
- <content>
- <title>Hello</title>
- <para>This is my first Cocoon page with OJB!</para>
- <xsp:logic>
- try {
- /* Get the PersistenceManager */
- try {
- pmf = (JdoPMF) manager.lookup(JdoPMF.ROLE);
- persistenceManager = pmf.getPersistenceManager();
- } catch (ComponentException cme) {
- getLogger().error("Could not look up the PersistenceManager", cme);
- }
- <!-- Setting up the Bean -->
- bean.setId(5);
- bean.setName("JDO Development");
- <!-- 2. Get current transaction -->
- Transaction tx = persistenceManager.currentTransaction();
- <!-- 3. Start a Transaction -->
- tx.begin();
- <!-- 4. now perform persistence operations. Store the new user -->
- persistenceManager.makePersistent(bean);
- <!-- 5. Commit the transaction -->
- tx.commit();
- s = bean.getId() + " : " + bean.getName();
- </xsp:logic>
- <p> Inserted data: <xsp:expr>s</xsp:expr> </p>
- <xsp:logic>
- }
- finally {
- manager.release((Component)pmf);
- }
- </xsp:logic>
- </content>
- </page>
- </xsp:page>
-