Hi,

I'm sure the question was asked several times but I didn't find any valuable
hints in the mailing list. I just want to delete a object and
all the sub-objects as defined in repository.xml. That all with locking of
the root object and in one transaction.
I have the class definition in repository.xml as follows:
<class-descriptor>
...
         <collection-descriptor
         name="subActions"
         element-class-ref="de.virtualsolution.ojb.Action"
         collection-class="org.apache.ojb.odmg.collections.DListImpl"
      >
         <inverse-foreignkey field-id-ref="3"/>
      </collection-descriptor>

    </class-descriptor>

there are some fields and one collection holding sub-actions. The
sub-actions can also have sub-actions. That's a tree structure. I have the
collection class defined because I though only that one is aware of removing
all the childs, doesn't it ? Ok to delete the action I perform a query like
this

        Action action = new Action();
        action.setId(id);

        // 2. build a QueryByExample from this sample instance:
        Query query = new QueryByExample(action);

       // 4. lookup the product specified by the QBE
       action = (Action) broker.getObjectByQuery(query);

and wanna delete the action with deleteObject(action) ....

------------------------------
    static public void deleteObject(Object obj) throws DBException {
        String databaseName = null;

        if (obj == null) {
            return;
        }

        try {
            databaseName =
            ((PersistenceBrokerConfiguration) PersistenceBrokerFactory
            .getConfigurator()
            .getConfigurationFor(null))
            .getRepositoryFilename();
        }
        catch (ConfigurationException e) {
            databaseName = "repository.xml";
        }

        // get facade instance
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        //open database
        try {
            db.open(databaseName, Database.OPEN_READ_WRITE);
        }
        catch (ODMGException ex) {
            m_log.error("Error while opening ODMG database", ex);
            throw new DBException("Error while opening ODMG database", ex);
        }

        Transaction tx = odmg.newTransaction();

        //perform transaction
        try {
            tx.begin();

            tx.lock(obj, Transaction.WRITE);

            db.deletePersistent(obj);

            tx.commit();
        }
        catch (Exception ex) {
            tx.abort();
        } finally {
            try {
                db.close();
            } catch (ODMGException ex) {
                m_log.error("Error while closing ODMG database", ex);
                throw new DBException("Error while closing ODMG database",
ex);
            }
        } //end finally
    }
-------------------------------

Only the root object was deleted. My question is what are the settings for
cascade deleting ? What is the drawback if i go to use the PB API and
auto-delete setting in the descriptor ?

What really means the object locking ? It doesn't prevent another client
from setting new values while the object is locked, so what's going on ?

Thanx for any help.
Thomas


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

Reply via email to