| <?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 inserts a row into hsqldb using OJB with PB |
| * |
| * @author <a href="mailto:antonio@apache.org>Antonio Gallardo</a> |
| * @version CVS $Revision: 1.3 $ $Date: 2004/03/17 11:28:20 $ |
| --> |
| |
| <xsp:page language="java" xmlns:xsp="http://apache.org/xsp"> |
| |
| <xsp:structure> |
| <xsp:include>org.apache.cocoon.ojb.samples.bean.Department</xsp:include> |
| <xsp:include>org.apache.ojb.broker.PersistenceBroker</xsp:include> |
| <xsp:include>org.apache.ojb.broker.PersistenceBrokerFactory</xsp:include> |
| </xsp:structure> |
| |
| <page> |
| <content> |
| <title>Hello OJB</title> |
| <para>This is my first Cocoon page with OJB using Persistence Broker!</para> |
| <xsp:logic> |
| /* Get the PersistenceManager */ |
| PersistenceBroker pb = PersistenceBrokerFactory.defaultPersistenceBroker(); |
| Department bean = new Department(); |
| |
| try { |
| <!-- Setting up the Bean --> |
| bean.setId(8); |
| bean.setName("Apache OJB-PB Development"); |
| <!-- 2. Start a Transaction --> |
| pb.beginTransaction(); |
| <!-- 3. now perform persistence operations. Store the new Department --> |
| pb.store(bean); |
| <!-- 4. Commit the transaction --> |
| pb.commitTransaction(); |
| |
| <p> |
| Inserted data: <xsp:expr>bean.getId() + " : " + bean.getName()</xsp:expr> |
| </p> |
| } finally { |
| if (!pb.isClosed()) { |
| if (pb.isInTransaction()) { |
| pb.abortTransaction(); |
| } |
| pb.close(); |
| } |
| } |
| </xsp:logic> |
| </content> |
| </page> |
| </xsp:page> |