Re: pre-remove, post-remove

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Mon Nov 08 2010 - 00:09:05 UTC

  • Next message: Andrus Adamchik: "Re: To Dep PK bug?"

    > List<HoMovimentosAplicacoes> movs = new ArrayList<HoMovimentosAplicacoes>();
    > for (HoMovimentosAplicacoes mov : apl.getHoMovimentosAplicacoesArray())
    > movs.add(mov);
    > for (int i = 0; i < movs.size(); i++)
    > apl.removeFromHoMovimentosAplicacoesArray(movs.get(i));
    > manager.getContext().deleteObjects(movs);

    So do you actually call manager.getContext().commitChanges()? As that's where post-remove is invoked?

    > Do I need to remove the objects from the relationships before deleting them or
    > just delete them?

    This is not needed for deletion to happen, but if you plan on reusing related objects (those that haven't been deleted), you'd better make sure the relationships are clean after commit. So you can either set the delete rules to let Cayenne handle the relationships:

    http://cayenne.apache.org/doc12/delete-rules.html

    Or you can manually unset them.

    Andrus

    On Nov 6, 2010, at 5:32 PM, Bruno René Santos wrote:

    > I do something like this:
    >
    > List<HoMovimentosAplicacoes> movs = new ArrayList<HoMovimentosAplicacoes>();
    > for (HoMovimentosAplicacoes mov : apl.getHoMovimentosAplicacoesArray())
    > movs.add(mov);
    > for (int i = 0; i < movs.size(); i++)
    > apl.removeFromHoMovimentosAplicacoesArray(movs.get(i));
    > manager.getContext().deleteObjects(movs);
    >
    > Do I need to remove the objects from the relationships before deleting them or
    > just delete them?
    >
    > Thanx
    > Bruno
    >
    > -----Mensagem original-----
    > De: Andrus Adamchik [mailto:andru..bjectstyle.org]
    > Enviada: sábado, 6 de Novembro de 2010 16:57
    > Para: use..ayenne.apache.org
    > Assunto: Re: pre-remove, post-remove
    >
    > Hi,
    >
    > Just found a bit unrelated issue with POST_LOAD callback:
    >
    > https://issues.apache.org/jira/browse/CAY-1503
    >
    > For your case, it should help if you could post a code example with comments on
    > where you are seeing and not seeing the callbacks.
    >
    > Andrus
    >
    >
    > On Nov 1, 2010, at 8:10 PM, Bruno René Santos wrote:
    >
    >> Hello all,
    >>
    >> I am having a possibly strange behaviour on my lifecycle callbacks. Imagine de
    >> following scenario:
    >>
    >> 1 textfield and 1 table on a web application. I fill table with query results
    >> depending on the textfield value. Each time i get a valueChange event on the
    >> textField I remove all lines from table and create new ones. As each line is a
    >> cayennedataobject, each time I do this procedure I call deleteObject for each
    >> old line that was removed when new lines are created. In the end I
    > commitChanges
    >> and only the last lines are saved in relation with the superclass.
    >>
    >> The problem here is the following. For each erased line cayenne call the
    >> preremove callback where I create a log for the table removal, in pending
    > state.
    >> The state of the object is modified (this is the first weird thing, shouldn’t
    > be
    >> new?) after the preRemove callback the desired process is done but Cayenne
    > never
    >> calls the postRemove callback on this situation, for other regular deletes
    >> everything works.
    >>
    >> Anybody recalls a situation where the preXX callback is called but not the
    >> postXX?
    >>
    >> Thanx
    >> Bruno Santos
    >>
    >>
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Mon Nov 08 2010 - 00:09:33 UTC