Plex 2E

  • 1.  OwnedCascade / Owners

    Posted Dec 09, 2015 02:34 PM

    Hello, I have a doubt,

     

    In the picture( Entity Relations.jpg), as you can see there is an entity called "Detalle Empleado" into a red square, that is the detail of many entities.

     

    I'm implementing the Ownedcascade Entity in the entity "Detalles Empleado", It has some parents, for example:

     

     

    Detalle Empleado Owned By Country

                                  ... Dependecy ERROR

    Detalle Empleado Owned By Cargo

    Detalle Empleado Owned By Banco

    Detalle Empleado Owned By Sucursales

    Detalle Empleado Owned By Departamentos

    ....

     

     

    Detalle Empleado is a ENT OwnedCascade

    Detalle Empleado Replace Owner

                                  ... by Country

     

     

     

    At this point I only can make a single Replace Owner By ...

     

    so, I've created a new entity call R_Association (R_OwnedCascade.jpg) and I did the replaces in the entity "Detalle Empleado" (R_OwnedCascade Replaces). This doesn't work,

    Error.jpg display the error when i tried to delete a record that exist in the child entity...

     

     

     

    Is it posible to apply to all the OWNED BY the REPLACE OWNER?



  • 2.  Re: OwnedCascade / Owners

    Posted Dec 09, 2015 03:08 PM

    Why don't you code data centrically and not program centrically?

     

    Make the database do the deletes instead of by calling programs? What is your DB?

     

    I know what is wrong with your pattern but want you to first consider programming at a database level using the DBMS. This is new development after all and not maintenace work which I would not advocate changing program centric to database centric.

     

    TBL dependencies SYS

    Controls the implementation of the cascade deletion specified by the ...dependency SYS continuation verb. The allowed system values are described below.

    Note: To ensure predictable results, use either Database or Procedural but not both within a related set of entities.

    Procedural (default)

    The cascade deletion processing is carried out as specified by the action diagram. Typically, this processing must be inherited from your class library.

    Note: This option can cause performance problems over large SQL tables.

    Database

    In an SQL implementations, the cascade deletion is carried out by the database and no class library code is generated. The SQL DDL for the table is generated with the required ON DELETE CASCADE specifiers. This option has no effect on an System i database.

    Note: Not all ODBC drivers and databases support the ON DELETE CASCADE specifier. It is not part of the ODBC 2.0 standard.

    Unenforced

    No cascade deletion processing is generated. This option enables you to specify your own processing.



  • 3.  Re: OwnedCascade / Owners

    Posted Dec 09, 2015 03:27 PM

    Maybe read https://communities.ca.com/docs/DOC-231162956

     

    Once you consider this you need to look at your data model

    Detalle Empleado Owned By Country                              

    ... Dependecy ERROR

    Detalle Empleado Owned By Cargo

    Detalle Empleado Owned By Banco

    Detalle Empleado Owned By Sucursales

    Detalle Empleado Owned By Departamentos

     

    That going to create quite a mess! How many keys! This is case where natural keys would be best suited to being refers relationships and using a surrogate key see Re: Does anyone have experience using "Denoted By"?



  • 4.  Re: OwnedCascade / Owners

    Posted Dec 09, 2015 03:50 PM

    I only say this as it appears as this is NEW DEVELOPMENT and you have a chance to use CA Plex more effectively then when the help text and patterns were written back in the last century!

     

    you need to create OwnedCascade2 and probably OwnedCascade3 and OwnedCascade4 for all the owners you want cascade delete to occur or the ERROR dependency to stop a delete.

     

    This will solve it for you but it is papering over the cracks in your knowledge of how the patterns work and importantly what is generated.

     

    I would go back many steps and just have ONE owned by relationship and generate the delete and see what changes you see in the GENERATED source.

     

    The error message you are getting is a good one it is telling you the object named S4zspgf  can not be found..Does this object name actually exisit in your model if not which is my guess it is a surrogate name...look for this name in your source...this message usually happens when you have tried to replace something and object has not been replaced and a non implemented library object is still be generated as the call hence the surrogate imp name.

     

    Basically your question has a simple answer but really there are data model issues, pattern issues, meta call understanding first.

     



  • 5.  Re: OwnedCascade / Owners

    Posted Dec 09, 2015 05:34 PM

    Hi JMRoman,

    You should rethink your data model: It is a many to many relation, and Plex uses the Owner/Owned pattern thinking in a unique owner. It uses a second owner for associations:

    "Association is an entity that contains functionality to work with an entity that is owned by two parent entities. You can use this entity to model an associated with relationship. Because this “many-to-many” relationship cannot be resolved directly in a relational database, you can use a new entity to store the cross references" (from the Plex help)

    You can extend that pattern, but maybe first you should rethink you relations. It is possible, and we do it, use cascade delete for referred to entities, but it requires some changes in order to apply it to cascade delete. In same way, you could do it for several "owners". But, as George say, it requires a comprehension on how that pattern works.



  • 6.  Re: OwnedCascade / Owners

    Posted Dec 10, 2015 02:30 AM

    have a look at Re: Referential Integrity using Patterns which will help you model the refers relationships.

     

    The point is 'Detalle Empleado' is a very important entity but you are asking all functions that interface to it to know millions of keys. Imagine changing Detalle Empleado to have a new owned by enitity in a years time!!!! All the interfaces would have a new key to be coded for...so make it a surrogate or even better make it an 'indentity Column' and model the owned bys as refers relationships. Use constraints and views/index to support the data model.



  • 7.  Re: OwnedCascade / Owners

    Posted Dec 15, 2015 09:35 AM

    Any progress?



  • 8.  Re: OwnedCascade / Owners

    Posted Dec 21, 2015 11:06 AM

    Sorry, I was absent for these days... well in my model, I was using an OWNED BY and many REFERS TO:

     

    Detalle Empleado OWNED BY Empleado

                                 REFERS TO Cargo

                                 REFERS TO Banco

                                 REFERS TO Sucursal

                                   ............

     

    but how I wanted to use the OWNEDCASCADE(Error Dependency), I must to change the "REFERS TO" by "OWNED BY".

     

    At the moment I´ve left that the DB do the constraints.



  • 9.  Re: OwnedCascade / Owners

    Posted Dec 22, 2015 09:01 AM

    Hi, jmroman

    Let me give you a way to solve your case...Other could be possible.

    You will need to inherit from OwnedCascade as described in Plex help, based on you Owner Empleado. It will give you the cascade mechanism.

    Then,

    1, create a new view in the owned entity for each referred to relation, ordered by the referred key

    2, create on such view a dependent function. Inherit from your processcascade function (owned entity.Fetch.ProcessCascade). Replace Fetch view by each corresponding view in such function.

    3, for each referred to triple, add the dependency...continuation triple, assigning your required dependendecy policy.

    4, For each referred to triple, add the continuation triple ...destructor function...pointing for each corresponding cascade delete function.

     

    If you haven't an owned by relation, it is possible to cascade delete to referred parent, but  a bit more complex (You would need to duplicate the Owned Cascade pattern.

     

    Jorge Ubeda