Added more information

in tis case i need to make a few changed to the master set, FLEX_FIELD and
completely replace the list of details. here is what i have so far.
i would like to do this in the scope of a single transaction locking the
records while it is being commited.

The last debug statement has all the correct values in the felxFieldBO
object but of course it never gets commited to the database.

** disclaimer **
Everything i know about OJB was gleened from totorials and examples. if
theres an easier way of doing this i would love to be pointed in the correct
direction.

Transaction tx = null;
            tx = odmg.newTransaction();
            tx.begin();
            String queryStr = "select STUFF from " +
FlexField.class.getName();
            String whereClause = " where FLEX_FIELD_NAME=$1";
            logger.debug(queryStr + whereClause);
            OQLQuery query = this.createQuery( queryStr + whereClause );
// select a row by primary key value
            query.bind( view.getFlexFieldName());
            List list= (List) query.execute();
            if ( list != null && list.size() > 0 ){
                FlexField flexFieldBO = (FlexField)list.get(0);

                tx.lock(flexFieldBO, Transaction.WRITE);
                flexFieldBO.setFlexFieldEnabled(view.isEnabled());
                flexFieldBO.setFlexFieldLabel(view.getFlexFieldLabel());
                flexFieldBO.setFlexFieldRequired(view.isRequired());
                if (view.getFlexFieldType().equals(Constants.FLEXTYPE_LIST))
                {
                    Vector listBO = flexFieldBO.getFlexFieldList();
                    Iterator iterList = listBO.iterator();
// delete the old list, this works and deletes records from the database
                         while(iterList.hasNext())
                    {
                        FlexFieldList flexFieldListBO = (FlexFieldList)
iterList.next();
                        db.deletePersistent(flexFieldListBO);
                    }

                    ArrayList viewList = view.getFlexFieldValues();
                    Iterator iter = viewList.iterator();
//build and set a new list
                    Vector fieldList = new Vector();
                    while (iter.hasNext())
                    {
                        String value = (String)iter.next();
                        FlexFieldList flexFieldList = new FlexFieldList();
                        flexFieldList.setFlexFieldListValue(value);

flexFieldList.setFlexFieldName(view.getFlexFieldName());
                        flexFieldList.setFlexField(flexFieldBO);
                        flexFieldBO.addListValue(flexFieldList);
                    }

logger.debug("**************************************************************
********");
                    logger.debug(flexFieldBO);

logger.debug("**************************************************************
********");
                }
                tx.commit();
            }
            else{
                throw new DataNotFound("Flex field record missing");
            }

-----Original Message-----
From: Stephan Jones [mailto:[EMAIL PROTECTED]
Sent: November 5, 2003 5:48 PM
To: [EMAIL PROTECTED]
Subject: ODMG and Updating collections
Importance: High


does anyone have a simple example using ODMG and 1:n mappings

I can get a cascading inserts and Delets to work.

I can not get any updates into the Many portion (FlexFieldList) of the my
mapping.

if someone could give me a few lines of code to properly update the 2
tables.

I'm not sure if I have to select the row first, ect.

Any help would be great.

Here is the Mapping

<class-descriptor
    class="com.redpillconsulting.eca.businessobjects.FlexField"
    table="FLEX_FIELD_T" isolation-level="read-uncommitted">
    <field-descriptor
        column="FLEX_FIELD_NAME"
        id="1"
        jdbc-type="CHAR"
        name="flexFieldName"
        primarykey="true"/>
    <field-descriptor
        column="FLEX_FIELD_LABEL"
        id="2"
        jdbc-type="VARCHAR"
        name="flexFieldLabel"
        nullable="false"/>
    <field-descriptor
        column="FLEX_FIELD_REQUIRED"
        id="3"
        jdbc-type="INTEGER"

conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2IntFieldCo
nversion"
        name="flexFieldRequired"
        nullable="false"/>
    <field-descriptor
        column="FLEX_FIELD_ENABLED"
        id="4"
        jdbc-type="INTEGER"

conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2IntFieldCo
nversion"
        name="flexFieldEnabled"
        nullable="false"/>
    <field-descriptor
        column="FLEX_FIELD_TYPE"
        id="5"
        jdbc-type="CHAR"
        name="flexFieldType"
        nullable="false"/>
    <field-descriptor
        column="FLEX_FIELD_CATEGORY"
        id="6"
        jdbc-type="CHAR"
        name="flexFieldCategory"
        nullable="false"/>
    <collection-descriptor
         name="flexFieldList"

element-class-ref="com.redpillconsulting.eca.businessobjects.FlexFieldList">
         <inverse-foreignkey field-id-ref="2"/>
      </collection-descriptor>
</class-descriptor>
<class-descriptor
    class="com.redpillconsulting.eca.businessobjects.FlexFieldList"
    table="FLEX_FIELD_LISTS_T"
    isolation-level="serializable">
    <field-descriptor
        column="ID"
        id="1"
        jdbc-type="INTEGER"
        name="oid"
        primarykey="true"
        autoincrement="true"/>
    <field-descriptor
        column="FLEX_FIELD_NAME"
        id="2"
        jdbc-type="VARCHAR"
        name="flexFieldName"
        nullable="false"/>
    <field-descriptor
        column="LIST_VALUE"
        id="3"
        jdbc-type="VARCHAR"
        name="flexFieldListValue"
        nullable="false"/>
    <reference-descriptor
         name="flexField"
         class-ref="com.redpillconsulting.eca.businessobjects.FlexField">
         <foreignkey field-id-ref="2"/>
      </reference-descriptor>
</class-descriptor>




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to