| <?xml version="1.0"?> |
| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You 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.JDO</xsp:include> |
| <xsp:include>javax.jdo.Transaction</xsp:include> |
| <xsp:include>org.apache.cocoon.ojb.samples.bean.Department</xsp:include> |
| </xsp:structure> |
| |
| <page> |
| <content> |
| <title>Hello</title> |
| <para>This is my first Cocoon page with OJB!</para> |
| <xsp:logic> |
| JDO jdo = null; |
| try { |
| /* Get the PersistenceManager */ |
| PersistenceManager persistenceManager = null; |
| try { |
| jdo = (JDO) manager.lookup(JDO.ROLE); |
| persistenceManager = jdo.getPersistenceManager(); |
| } catch (ComponentException cme) { |
| getLogger().error("Could not look up the PersistenceManager", cme); |
| } |
| |
| <!-- Setting up the Bean --> |
| Department bean = new Department(); |
| 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(); |
| |
| <p> |
| Inserted data: <xsp:expr>bean.getId() + " : " + bean.getName()</xsp:expr> |
| </p> |
| |
| } finally { |
| manager.release(jdo); |
| } |
| </xsp:logic> |
| </content> |
| </page> |
| </xsp:page> |