Page title (cookbook approach, tutorial , ...)

- TARGET-AUDIENCE: *beginner* advanced expert
- COCOON-RELEASES: 2.0.3, 2.0.4
- DOCUMENT-STATUS: *draft* reviewed released


===Introduction===

This is copy&paste from http://joose.iki.fi/ojb/

This page is my setup and adventure to get cforms work with OJB and 1:n relationships. After all this is working, this could be used as a template to create tutorial / something to help others to do the same thing.

Status

OJB stuff seems to work ok, because the test-script executes ok.

UPDATE works when I added hidden field with id see template.

DELETE works.

Everything is working

TODO

Database

CREATE TABLE parent (

PRIMARY KEY (id));

CREATE TABLE childs (

PRIMARY KEY(id), FOREIGN KEY(parent_id) REFERENCES parent (id));

So we have one-to-many (1:n) connection between parent and child.

So if we add new records, we first have to add record to table A and afterthat records to table childs.

Java classes

parent

package net.vettenranta;

import java.util.ArrayList; import java.util.Collection;

import java.io.Serializable;

public class Parent implements Serializable {

}

child

package net.vettenranta;

import java.io.Serializable;

public class Child implements Serializable {

}

DAO

package net.vettenranta;

import java.util.Iterator;

import javax.jdo.PersistenceManager; import javax.jdo.Transaction;

import org.apache.cocoon.ojb.jdo.components.JdoPMF; import org.apache.ojb.broker.Identity; import org.apache.ojb.broker.PersistenceBroker; import org.apache.ojb.broker.PersistenceBrokerFactory; import org.apache.ojb.broker.util.ObjectModificationDefaultImpl;

public class DAO {

}

package.jdo

<?xml version="1.0"?> <!DOCTYPE jdo SYSTEM "file:/javax/jdo/jdo.dtd">

<jdo>

</jdo>

Enhancing the classes

I have untarred jdo to my homedirectory.

Manually

This will place enhanced binaries to output directory. It will create that directory.

$ export CLASSPATH=~/jdo-1_0_1-ri/jdo.jar:~/jdo-1_0_1-ri/jdori-enhancer.jar:~/jdo-1_0_1-ri/jdori.jar:. $ java com.sun.jdori.enhancer.Main -d output package.jdo net/vettenranta/Parent.class net/vettenranta/Child.class

repository.xml

<descriptor-repository version="1.0" isolation-level="read-uncommitted">

</descriptor-repository>

Test-script (in cocoon flowscript)

This script works. So It's pretty safe to say that everything should be ok.

function test () {

}

CForms flowscript

CForms binding

<fb:context xmlns:fb="http://apache.org/cocoon/forms/1.0#binding" path="/" >

</fb:context>

CForms forms

<fd:form

</fd:form>

CForms template

CForms template file has to have (in row-repeater) <fi:widget id="id"><fi:styling type="hidden"><fi:widget>

Software

ojb 1.0.rc6 jdo 1.0.1-ri (sun) IBM Java2 1.4.1 Cocoon 2.1.5.1 Postgresql 7.3.4-3.rhl9 postgresql-jdbc-7.3.4-3.rhl9 redhat 9


page metadata

- AUTHOR: JooseVettenranta
- AUTHOR-CONTACT: mailto:joose@iki.fi[[BR]] - REVIEWED-BY:[[BR]] - REVIEWER-CONTACT:[[BR]]

NewbieGuideToOJB2 (last edited 2009-09-20 23:42:07 by localhost)