7 Replies Latest reply: Sep 27, 2013 6:43 PM by BradW RSS

    Extending Entities based on different tables?

    BradW

      JDeveloper 11.1.2.4

       

      I have many code tables in the system that have an identical table structure.  I've tried creating a base entity based on this common structure and then have each table extend off of this base entity and specify a unique table name.  The model project will show a warning that the entity does not share the same table as the table it is extending.  I then try and create a view object on the extended entity and JDeveloper gives me a nice error (as apposed to the runtime errors I normally see ) and will not let me proceed. 

       

      In general, when working with subtypes from a db modeling perspective, you can implement them in the same table OR in a completely separate table.  To me it is looking like ADF only supports the former.

       

      So, my question is, is there a trick to this or am I just stuck creating entity objects and repeating the same changes over and over and over and over....

       

      Any thoughts on the topic?

       

       

      Thanks,

       

       

      BradW

        • 1. Re: Extending Entities based on different tables?
          Florin Marcus

          Hi Brad,

           

          If the tables have identical functionality, I would go for dynamic EO's and VO's. There are quite a few blog posts on this online.

           

          Thanks,

          Florin

          • 2. Re: Extending Entities based on different tables?
            Frank Nimphius-Oracle

            Hi,

             

            not sure I can follow, but waht do you eman by "and repeating the same changes over and over and over and over....". Since you nevertheless create entities per table I don't yet see what you want to do. I am not sure dynamic EO and VO will help as suggested in the previous post

             

            Frank

            • 3. Re: Extending Entities based on different tables?
              BradW

              Hi Frank.  We have a quite a few code tables that have similar business rules etc on each table.  The idea was that perhaps we could create a base entity and extend all the different permutations of that base entity, but have different tables specified and perhaps have custom business logic in addition to the standard ones.

               

              I am trying to minimize code duplication, error management duplication, labels etc.  We have already put the custom rules in a base class and then use groovy to execute them.  I'm just trying to see if we can go one step further and use entity inheritance with different tables being specified.

               

              BradW

              • 4. Re: Extending Entities based on different tables?
                Florin Marcus

                Frank,

                My mistake in being too brief earlier, this time I would try a more comprehensive answer.

                 

                 

                Why inheritance is not an option:

                 

                I think that Brad is looking at it from  an OBJECT-RELATIONAL-MAPPING perspective, where Object Inheritance can be mapped database level in three ways:


                1.Single Table per Class Hierarchy

                2.Table per Concrete Class

                3.Joined Subclass


                (More details : Entity Inheritance Mapping Strategies )

                 

                With ADF Business Components, we only have the first option - 'Single Table per Class Hierarchy': http://docs.oracle.com/cd/E16162_01/web.1112/e16182/bcentities.htm#sm0327 , while what Brad would need is the second option: 'Table per Concrete Class'.

                 

                 

                Brad,

                I would say there are several ways I would try to implement this functionality, none of which requires code duplication:

                 

                 

                Solution A:

                Since you are saying the tables have IDENTICAL column names, you can easily get away with it:

                -  You can have one EO and one VO for ALL tables - Just implement first use case in the old fashion way, by using one of your tables.

                - Add a 'dynamic flavour' to your implementation:


                  a) Expose your Entity Definition class, where  you customise the method:

                  @Override

                    public String getSource() {

                       

                        return "YOUR_DYNAMIC_TABLE_NAME";

                    }


                 

                a) Expose your View Object implementation class and override:

                   

                    @Override

                    protected String buildQuery(int i, boolean b) {

                      String query = super.buildQuery(i, b);

                      query = query.replace("TABLE_NAME", "YOUR_DYNAMIC_TABLE_NAME");

                      return query;

                    }

                 

                   

                 

                Solution B:

                In case your tables have ALMOST the same columns, you will need to go through a more complex way of implementing dynamic view and entity objects.

                One example you can find here: Andrejus Baranovskis's Blog: ADF Generator for Dynamic ADF BC and ADF UI - Recreate.

                 

                 

                Hope this helps,

                 

                Florin Marcus

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                • 5. Re: Extending Entities based on different tables?
                  BradW

                  Thanks Florin.  I was wondering if option A was the way to go.  I'll give it a try later today and provide an update.

                   

                  Thanks again for taking the time for formulating a great response.  Sometimes it is difficult to find the time to do so, so many thanks to you.

                   

                  Have a great day!

                   


                  BradW

                  • 6. Re: Extending Entities based on different tables?
                    Frank Nimphius-Oracle

                    Hi,

                     

                    I am trying to minimize code duplication, error management duplication, labels etc.  We have already put the custom rules in a base class and then use groovy to execute them.  I'm just trying to see if we can go one step further and use entity inheritance with different tables being specified.

                     

                    Well for boilerplate code one code read out to helper classes which are shared. This way you would avoid code duplication other than the method signatures you add to the entityImpl pointing to the helper class.

                     

                    Since this question has been cross-posted its difficult to continue a single stream for this discussion: https://groups.google.com/forum/#!msg/adf-methodology/fc8GScH15h8/ZQYlmlVgumoJ

                     

                    I posted additional thought on the EMG forum (which is also where Steve Muench participated in)

                     

                    Frank

                     

                    Btw:: Brad, while you personally want to avoid duplicated code lines, you make us discussing the topic on parallel streams. Can we agree in the future to try one forum first and if this is not giving the result we hope, close the thread and continue on another?  ;-)

                    • 7. Re: Extending Entities based on different tables?
                      BradW

                      Thanks Frank.  Yes, I kind of agree about the cross posting.  I kind of see two different groups of people using the forum vs EMG.  When a time crunch comes, I tend to see how best to get information out there to get an answer quicker.  I'll try and keep this to a single stream in the future.

                       

                      Regardless, here is what I have come up with based on peoples feedback.  I do have one question in the approach below which I'd appreciate some insight to complete this topic.

                       

                      Thanks,

                       


                      BradW

                       

                      So, this is what I have tried out and seems to be working:

                       

                      Table Structure

                      code, description, display_order, effective_start_date, effective_end_date

                       

                      1) Create a DB View which union alls all the code tables in question and established a discriminator column and a pseudo primary key (code + discriminator).  The pseudo primary key is unique across all code tables.  The discriminator is unique across each code table subset.

                       

                      2) Create a base entity with all the business logic and labels ontop of the db view.

                       

                      3) Create entity subtypes for each code table and specify the corresponding id for each code table.  Override the discriminator column and provide a value that matches the code table in question.

                       

                      4) Create a view object for each entity subtype and set the corresponding id for the discriminator.  I needed to either create a ViewCriteria to filter out just the records in question.  Without this, the views did not seem to work properly for some reason.

                       

                      5) Created a base EntityImpl class which takes custom properties from each entity and then programatically does the lock, ins, upd, del

                       

                      Moving forward, they just need to update the db view, create a new entity subtype, set a couple properties and create an adfbc view.  All the business logic will be stored in the base entity object

                       

                      This will work very simply moving forward.  Thanks for everyone's input.

                       


                      BradW