Enhancement #38

Entity Extension

Added by Marcelo Coraça de Freitas about 2 years ago. Updated about 2 years ago.

Status:Closed Start date:12/01/2009
Priority:Alto Due date:12/02/2009
Assignee:Marcelo Coraça de Freitas % Done:

0%

Category:- Spent time: 4.50 hours
Target version:- Estimated time:5.00 hours

Description

Implement entity extensions.

There are two possible approaches: * using the Ada tagged type structure and multiple inheritance (probably the best approach) * adding yet another property into the entity registry

The OOP approach is easier to implement and more elegant, while the property approach is more compatible with Ada 95 (multiple inheritance is new in Ada 2005).

History

Updated by Marcelo Coraça de Freitas about 2 years ago

That's an example of how it could work:

type Product_Entity is new KOW_Ent.Entity_Type with record
    Name : Unbounded_String;
end record;

type Book_Extension is new Product_Entity and KOW_Ent.Entity_Extension_Type with record
    Author : Unbounded_String;
end record;

The KOW_Ent.Entity_Extension_Type has itself two properties * Parent_Tag : Unbounded_String * Parent_ID : KOW_ENT.ID_Type

And there are also class wide procedures and functions to handle those properties automatically. The only requirement is for the user to create a table with parent_tag and parent_id columns, which became keywords in KOW_Ent.

Updated by Marcelo Coraça de Freitas about 2 years ago

Marcelo Coraça de Freitas wrote:

That's an example of how it could work:

[...]

The KOW_Ent.Entity_Extension_Type has itself two properties
  • Parent_Tag : Unbounded_String
  • Parent_ID : KOW_ENT.ID_Type

And there are also class wide procedures and functions to handle those properties automatically. The only requirement is for the user to create a table with parent_tag and parent_id columns, which became keywords in KOW_Ent.

there is only a "small" issue in that: interfaces are equivalent to abstract tagged null record....

Updated by Marcelo Coraça de Freitas about 2 years ago

Marcelo Coraça de Freitas wrote:

Marcelo Coraça de Freitas wrote:

That's an example of how it could work:

[...]

The KOW_Ent.Entity_Extension_Type has itself two properties
  • Parent_Tag : Unbounded_String
  • Parent_ID : KOW_ENT.ID_Type

And there are also class wide procedures and functions to handle those properties automatically. The only requirement is for the user to create a table with parent_tag and parent_id columns, which became keywords in KOW_Ent.

there is only a "small" issue in that: interfaces are equivalent to abstract tagged null record....

I can put those properties in the KOW_Ent.Entity_Type type then.. I still gotta think how to do it properly.

Updated by Marcelo Coraça de Freitas about 2 years ago

  • Status changed from New to Accepted

I'm working with this in mind:

        type Entity_Extension_Interface is interface;

        function Cast_From_Extension( Extended_Entity : in Entity_Extension_Interface ) return Entity_Type'Class is abstract;

        function Cast_To_Extension( Entity : in Entity_Type'Class ) return Entity_Extension_Interface is abstract;

The cast functions are used internally by the KOW_Ent framework to call the inherited methods. The entity is to be split into two parts: one containing the main part and other containing the extension.

Updated by Marcelo Coraça de Freitas about 2 years ago

design ready... the interface is now declared as

----------------------
        -- Entity Extension --
        ----------------------

        type Entity_Extension_Interface is interface;
        -- entity extension is our counterpart for OOP-like programming in the database.
        --
        --
        -- one entity can have it's properties extended into multiple tables; each extension can be extended itself.
        --
        -- the main data is stored in the main table; not all data there need to belong to an extended entity
        -- each extension's data is stored into other tables... you can extend the entity in multiple levels.
        --
        -- the entity must have the same ID in all extensions as in the main table.
        --
        --
        -- Example:
        --
        -- Product_Type         : | ID | Name |
        -- Book_Type            : |    |      | Author_ID |
        -- Translated_Book_type : |    |      |           | Translator_ID
        --
        --
        -- A translated_Book_Type must have the data:
        --
        -- translated_books table:
        --      | 2 | 10 |
        --
        -- books
        --      | 2 | 33209 |
        --
        -- products
        --      | 2 | some name |
        --
        --
        -- KOW_Ent load all the data as needed.

        function Cast_From_Extension( Extended_Entity : in Entity_Extension_Interface ) return Entity_Type'Class is abstract;
        -- used to get the object inthe parent form when needed
        -- it's used internally by the framework (by the load, stored and related functions).

        procedure Load_From_Parent( Extended_Entity : in out Entity_Extension_Interface; Parent : in Entity_Type'Class ) is abstract;
        -- used to get the object from the parent into the extended entity
        -- it's used internally by the framework (by the load, stored and related functions).

I still gotta implement support into KOW_View.Entities.

Updated by Marcelo Coraça de Freitas about 2 years ago

  • Status changed from Accepted to Fixed

Updated by Marcelo Coraça de Freitas about 2 years ago

  • Status changed from Fixed to Closed

Also available in: Atom PDF