typhon-project / typhonml

Eclipse Public License 2.0
6 stars 1 forks source link

AddEntity change operator - no information concerning the target database #21

Closed benatspo closed 5 years ago

benatspo commented 5 years ago

Hi,

I'm facing a problem while developing the AddEntity change operator. I'm able to define the change operator in the XMI file, but one information is missing: the target database (in which the entity has to be added). It is possible to add a new database, or a new table (in case of a relational database) in the XMI file, but it is not possible to map the new entity with the database (and to the physical object containing it). Could you please:

You can find an exemple of the actual XMI file for a AddEntity change operator below.

Many thanks in advance.

<?xml version="1.0" encoding="ASCII"?>
<typhonml:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:typhonml="http://org.typhon.dsls.typhonml.sirius">
  <databases xsi:type="typhonml:RelationalDB" name="RelationalDatabase">
    <tables name="UserDB" entity="//@dataTypes.2">
      <indexSpec name="userIndex" attributes="//@dataTypes.2/@attributes.1"/>
      <idSpec attributes="//@dataTypes.2/@attributes.1"/>
    </tables>
    <tables name="CreditCardDB" entity="//@dataTypes.3">
      <indexSpec name="creditCardIndex" attributes="//@dataTypes.3/@attributes.1"/>
      <idSpec attributes="//@dataTypes.3/@attributes.1"/>
    </tables>
    <tables name="CommentDB" entity="//@changeOperators.0">
      <indexSpec name="creditCardIndex" attributes="//@dataTypes.3/@attributes.1"/>
      <idSpec attributes="//@dataTypes.3/@attributes.1"/>
    </tables>
  </databases>
  <dataTypes xsi:type="typhonml:PrimitiveDataType" name="Date"/>
  <dataTypes xsi:type="typhonml:PrimitiveDataType" name="String"/>
  <dataTypes xsi:type="typhonml:Entity" name="User">
    <attributes name="id" type="//@dataTypes.1"/>
    <attributes name="name" type="//@dataTypes.1"/>
    <relations name="paymentsDetails" type="//@dataTypes.3" cardinality="zero_many" isContainment="true"/>
  </dataTypes>
  <dataTypes xsi:type="typhonml:Entity" name="CreditCard">
    <attributes name="id" type="//@dataTypes.1"/>
    <attributes name="number" type="//@dataTypes.1"/>
    <attributes name="expiryDate" type="//@dataTypes.0"/>
  </dataTypes>
  <changeOperators xsi:type="typhonml:AddEntity" name="Comment">
    <attributes name="id" type="//@dataTypes.1"/>
    <attributes name="name" type="//@dataTypes.1"/>
    <relations name="user" type="//@dataTypes.2" cardinality="one" isContainment="false"/>
  </changeOperators>
</typhonml:Model>
jdirocco commented 5 years ago

hi @benatspo , You can add a new entity to the Model root object as you did. An entity is not related to a specific DB but it is linked to a Table (RelationDB), a Collection (DocumentDB), a KeyValueElement (KeyValueDB), a GraphNode (GraphDB), and a Column (ColumnDB). Those metaclasses are devoted to storing the data of the referred conceptual data entity and all of them have a reference to the entity. Those links allow you to refer the Entity and AddEntity because the latter extends Entity. Moreover, Entity (and AddEntity) provides several operations (e.g., get Collections, getTables, etc) that permit to know who is referring to the selected entity. From Table, Collections, etc you can know the DB container by Container operation.

In your example, you properly mapped the CommentDB table to the new Comment AddedEntity. Did I miss something?

benatspo commented 5 years ago

Hi @md2manoppello,

I understand your response, but the problem is that the methods "getTables(), getCollections(), get..." all return "null". Indeed, the source XMI file containing the change operator, does not contain information about the corresponding database:

  <changeOperators xsi:type="typhonml:AddEntity" name="Comment">
    <attributes name="id" type="//@dataTypes.1"/>
    <attributes name="name" type="//@dataTypes.1"/>
    <relations name="user" type="//@dataTypes.2" cardinality="one" isContainment="false"/>
  </changeOperators>

When i executed the "getTables(), getCollections(), get..." on the AddEntity operator, i always get "null". The problem is that the AddEntity object is created in the code for our test, and not from the representation mode in TyphonML, so we are not sure that the change operator (described in the above code) is complete.

In the example code i gave in the issue, i forced my test to add a new "Table", that's why i have some data in the XMI, but it was just a workaround. Actually, the final XMI file contains the new entity, but without database mapping.

Here are the source, and the target XMI files, without workaround. What am I missing ? Will the AddEntity operator contain data in the "getTables(), getCollections(), get..." methods when created through the evolution mode in the representation file in Eclipse ?

jdirocco commented 5 years ago

Hi, (Convention: from now tables, collections, etc will be named as storage units.) The current editors (textual and graphical) are not complete and we are working on. However, a storage unit should be manually selected when a new entity is added because it's a subjective choice (the DB and the storage unit should be selected). The entity operations provide proper results if the entity links are set. For instance, the enclosed pictures depict how to play with getTable

operation: the former shows how getTable works on the eclipse bundle bundle and the latter shows how the operation can be used as a stand-alone java program. standalone2

am I wrong?

benatspo commented 5 years ago

Hi,

You are right about the manually selected storage unit. You are also right about the operations in a java program.

The only blocking point are the current editors (textual and graphical) that are not complete, as you said.

For the moment, until the editors are improved, i'm not able to have a complete change operator for this operation. So i'll wait for the next release to be able to have that storage unit information in the change operator.

That's the object of this issue. Thank you for your clarification, and i'm looking forward having news from those new editors.