Skip to content

Configuring Entity Descriptor

Siminov Framework edited this page Dec 25, 2015 · 14 revisions

Entity Descriptor is one which does ORM, it maps Native/JavaScript model class to database table.

                   <!-- Design Of EntityDescriptor.xml -->

    <entity-descriptor>

        <!-- General Properties Of Table And Class -->
    
            <!-- Mandatory Field -->
                <!-- NAME OF TABLE -->
        <property name="table_name">name_of_table</property>
    
            <!-- Mandatory Field -->
                <!-- MAPPED CLASS NAME -->
        <property name="class_name">mapped_class_name</property>
    
    
            <!-- Optional Field -->
        <attributes>
        
                <!-- Column Properties Required Under This Table -->
	    
                    <!-- Optional Field -->
                <attribute>
		    
                        <!-- Mandatory Field -->
                            <!-- COLUMN_NAME: Mandatory Field -->
                    <property name="column_name">column_name_of_table</property>
		    			
                        <!-- Mandatory Field -->
                            <!-- VARIABLE_NAME: Mandatory Field -->
                    <property name="variable_name">class_variable_name</property>
		    		    
                        <!-- Mandatory Field -->
                    <property name="type">java_variable_data_type</property>
			
                        <!-- Optional Field (Default is false) -->
                    <property name="primary_key">true/false</property>
			
                        <!-- Optional Field (Default is false) -->
                    <property name="not_null">true/false</property>
			
                        <!-- Optional Field (Default is false) -->
                    <property name="unique">true/false</property>
			
                        <!-- Optional Field -->
                    <property name="check">condition_to_be_checked (Eg: variable_name 'condition' value; variable_name > 0)</property>
			
                        <!-- Optional Field -->
                    <property name="default">default_value_of_column (Eg: 0.1)</property>
		
                </attribute>		

            </attributes>
		
		
            <!-- Optional Field -->
            <indexes>
        
                <!-- Index Properties -->
                <index>
		    
                        <!-- Mandatory Field -->
                            <!-- NAME OF INDEX -->
                    <property name="name">name_of_index</property>
		    
                        <!-- Mandatory Field -->
                            <!-- UNIQUE: Optional Field (Default is false) -->
                    <property name="unique">true/false</property>
		    
                        <!-- Optional Field -->
                            <!-- Name of the column -->
                    <property name="column">column_name_needs_to_add</property>
		    
                </index>
        
            </indexes>
    
		
            <!-- Map Relationship Properties -->
				
                <!-- Optional Field's -->	
            <relationships>
		    
                <relationship>
	        
                        <!-- Mandatory Field -->
                            <!-- Type of Relationship -->
                    <property name="type">one-to-one|one-to-many|many-to-one|many-to-many</property>
	        
                        <!-- Mandatory Field -->
                            <!-- REFER -->
                    <property name="refer">class_variable_name</property>
	        
                        <!-- Mandatory Field -->
                            <!-- REFER TO -->
                    <property name="refer_to">map_to_class_name</property>
	            
                         <!-- Optional Field -->
                    <property name="on_update">cascade/restrict/no_action/set_null/set_default</property>    
	            
                         <!-- Optional Field -->    
                    <property name="on_delete">cascade/restrict/no_action/set_null/set_default</property>    
	            
                         <!-- Optional Field (Default is false) -->
                    <property name="load">true/false</property>	            
	        
                </relationship>
	    
            </relationships>

        </entity-descriptor>
                   <!-- Android Sample: EntityDescriptor.xml -->

    <entity-descriptor>

        <property name="table_name">BOOK</property>
        <property name="class_name">siminov.core.sample.model.Book</property>
    
        <attributes>
		
            <attribute>
                <property name="variable_name">title</property>
                <property name="column_name">TITLE</property>
                <property name="type">string</property>
                <property name="primary_key">true</property>
                <property name="not_null">true</property>
                <property name="unique">true</property>
            </attribute>		

            <attribute>
                <property name="variable_name">description</property>
                <property name="column_name">DESCRIPTION</property>
                <property name="type">string</property>
            </attribute>

            <attribute>
                <property name="variable_name">author</property>
                <property name="column_name">AUTHOR</property>
                <property name="type">string</property>
            </attribute>

            <attribute>
                <property name="variable_name">link</property>
                <property name="column_name">LINK</property>
                <property name="type">string</property>
                <property name="default">www.wikipedia.org</property>
            </attribute>

        </attributes>
		
	
        <indexes>
            <index>
                <property name="name">BOOK_INDEX_BASED_ON_AUTHOR</property>
                <property name="unique">true</property>
                <property name="column">AUTHOR</property>
            </index>
        </indexes>

        <relationships>

            <relationship>
                <property name="type">one-to-many</property>
                <property name="refer">lessions</property>
                <property name="refer_to">siminov.core.sample.model.Lession</property>
                <property name="on_update">cascade</property>
                <property name="on_delete">cascade</property>
                <property name="load">true</property>
            </relationship>		
	    
        </relationships>
											
    </entity-descriptor>			
			
                <!-- iOS Sample: EntityDescriptor.xml -->


    <entity-descriptor>

        <property name="table_name">BOOK</property>
        <property name="class_name">Book</property>
    
        <attributes>
		
            <attribute>
                <property name="variable_name">title</property>
                <property name="column_name">TITLE</property>
                <property name="type">string</property>
                <property name="primary_key">true</property>
                <property name="not_null">true</property>
                <property name="unique">true</property>
            </attribute>		

            <attribute>
                <property name="variable_name">description</property>
                <property name="column_name">DESCRIPTION</property>
                <property name="type">string</property>
            </attribute>

            <attribute>
                <property name="variable_name">author</property>
                <property name="column_name">AUTHOR</property>
                <property name="type">string</property>
            </attribute>

            <attribute>
                <property name="variable_name">link</property>
                <property name="column_name">LINK</property>
                <property name="type">string</property>
                <property name="default">www.wikipedia.org</property>
            </attribute>

        </attributes>
		
	
        <indexes>
            <index>
                <property name="name">BOOK_INDEX_BASED_ON_AUTHOR</property>
                <property name="unique">true</property>
                <property name="column">AUTHOR</property>
            </index>
        </indexes>

        <relationships>

            <relationship>
                <property name="type">one-to-many</property>
                <property name="refer">lessions</property>
                <property name="refer_to">Lession</property>
                <property name="on_update">cascade</property>
                <property name="on_delete">cascade</property>
                <property name="load">true</property>
            </relationship>		
	    
        </relationships>
											
    </entity-descriptor>				
			
                   <!-- Windows Sample: EntityDescriptor.xml -->


    <entity-descriptor>

        <property name="table_name">BOOK</property>
        <property name="class_name">Siminov.Core.Sample.Model.Book</property>
    
        <attributes>
		
            <attribute>
                <property name="variable_name">title</property>
                <property name="column_name">TITLE</property>
                <property name="type">string</property>
                <property name="primary_key">true</property>
                <property name="not_null">true</property>
                <property name="unique">true</property>
            </attribute>		

            <attribute>
                <property name="variable_name">description</property>
                <property name="column_name">DESCRIPTION</property>
                <property name="type">string</property>
            </attribute>

            <attribute>
                <property name="variable_name">author</property>
                <property name="column_name">AUTHOR</property>
                <property name="type">string</property>
            </attribute>

            <attribute>
                <property name="variable_name">link</property>
                <property name="column_name">LINK</property>
                <property name="type">string</property>
                <property name="default">www.wikipedia.org</property>
            </attribute>

        </attributes>
		
	
        <indexes>
            <index>
                <property name="name">BOOK_INDEX_BASED_ON_AUTHOR</property>
                <property name="unique">true</property>
                <property name="column">AUTHOR</property>
            </index>
        </indexes>

        <relationships>

            <relationship>
                <property name="type">one-to-many</property>
                <property name="refer">lessions</property>
                <property name="refer_to">Siminov.Core.Sample.Model.Lession</property>
                <property name="on_update">cascade</property>
                <property name="on_delete">cascade</property>
                <property name="load">true</property>
            </relationship>		
	    
        </relationships>
											
    </entity-descriptor>			
		
			
                      <!-- JavaScript Sample: Entity Descriptor -->

    <entity-descriptor>

        <property name="table_name">BOOK</property>
        <property name="class_name">Book</property>
    
        <attributes>
		
            <attribute>
                <property name="variable_name">title</property>
                <property name="column_name">TITLE</property>
                <property name="type">string</property>
                <property name="primary_key">true</property>
                <property name="not_null">true</property>
                <property name="unique">true</property>
            </attribute>		

            <attribute>
                <property name="variable_name">description</property>
                <property name="column_name">DESCRIPTION</property>
                <property name="type">string</property>
            </attribute>

            <attribute>
                <property name="variable_name">author</property>
                <property name="column_name">AUTHOR</property>
                <property name="type">string</property>
            </attribute>

            <attribute>
                <property name="variable_name">link</property>
                <property name="column_name">LINK</property>
                <property name="type">string</property>
                <property name="default">www.wikipedia.org</property>
            </attribute>

        </attributes>
	
        <indexes>
	    
            <index>
                <property name="name">BOOK_INDEX_BASED_ON_AUTHOR</property>
                <property name="unique">true</property>
                <property name="column">AUTHOR</property>
            </index>
	    	    
        </indexes>
	
        <relationships>

            <relationship>
                <property name="type">one-to-many</property>
                <property name="refer">lessions</property>
                <property name="refer_to">Lession</property>
                <property name="on_update">cascade</property>
                <property name="on_delete">cascade</property>
                <property name="load">true</property>
            </relationship>		

        </relationships>
											
    </entity-descriptor>		
			

Entity Descriptor Elements

1. Entity Tag

It map database table to its corresponding model class.

  • table_name*: Name of table. It is mandatory field.
  • class_name*: Name of model class name which is to be mapped to relational table name. It is mandatory field.
2. Attribute Tag

It map database table column to its corresponding variable of model class.

  • column_name*: Name of column. It is mandatory field.
  • variable_name*: Name of variable. It is mandatory field.

Properties Of Attribute Tag

  • type*:

Siminov Data Types: (primitive-integer, integer, primitive-long, long, primitive-float, float, double, primitive-double, primitive-boolean, boolean, primitive-byte, byte, string)

  • primary_key*: TRUE/FALSE. It defines whether the column is primary key of table or not. It is optional property. Default value is false.

  • not_null*: TRUE/FALSE. It defines whether the column value can be empty or not. It is optional property. Default value is false.

  • unique*: TRUE/FALSE. It defines whether the column value should be unique or not. It is optional property. Default value is false.

  • default: It defines the default value of column. It is optional property.

  • check: It is used to put condition on column value. It is optional property.

Note: Application Developer can provide their own properties also, and by using following API's they can use properties.

  • Get Properties - [Android:getProperties | iOS:getProperties | Windows:GetProperties | JavaScript:getProperties]: It will return all properties associated with Entity Descriptor Column.

  • Get Property - [Android:getProperty:(Name-of-Property) | iOS:getProperty:Name-of-Property | Windows:GetProperty(Name-of-Property) | JavaScript:getProperty(Name-of-Property)]: It will return property value associated with property name provided.

  • Contains Property - [Android:containsProperty(Name-of-Property) | iOS:containsProperty:Name-of-Property | Windows:ContainsProperty(Name-of-Property) | JavaScript:containPropert(Name-of-Property)]: It will return TRUE/FALSE whether property exists or not.

  • Add Property - [Android:addProperty(Name-of-Property, Value-of-Property) | iOS:addProperty:Name-Of-Property Windows:AddProperty(Name-Of-Property, Value-Of-Property) | JavaScript:addProperty(Name-of-Property, Value-of-Property)]: It will add new property to the collection of Entity Descriptor Column properties.

  • Remove Property - [Android:removeProperty(Name-of-Property) | iOS:removeProperty:Name-Of-Property | Windows:RemoveProperty(Name-Of-Property) | JavaScript:removeProperty(Name-of-Property)]**: It will remove property from Entity Descriptor Column properties based on name provided.

3. Index Tag

It defines the structure of index needed on the table.

  • name*: Name of the index. It is mandatory field.

  • unique: TRUE/FALSE. It defines whether index needs to be unique or not. It is not mandatory property. Default value is false.

(A unique index guarantees that the index key contains no duplicate values and therefore every row in the table is in some way unique).

Index Column Tag

  • column*: Name of columns included in index. At least one column should be included.
4. Relationship Tag

It defines relationship between object. Relationship can be of four types:

Relationship Properties

  • type*: Type of the relationship. It is mandatory field.

  • refer*: Name of variable which needs to be mapped. It is mandatory field.

  • refer_to*: Class name of mapped variable. It is mandatory field.

  • on_update*: cascade/restrict/no action/set null/set_default. It defines action needs to be done, when update occur.

  • on_delete*: cascade/restrict/no action/set null/set_default. It defines action needs to be done, when delete occur.

  • load*: It defines whether it need to be load or not.

Relationship Types

  • One To One Relationship (one-to-one): In a one-to-one relationship, each row in one database table is linked to one and only one other row in another table.

  • One To Many Relationship (one-to-many): In a one-to-many relationship, each row in the related to table can be related to many rows in the relating table. This effectively save storage as the related record does not need to be stored multiple times in the relating table.

  • Many To One Relationship (many-to-one): In a many-to-one relationship one entity (typically a column or set of columns) contains values that refer to another entity (a column or set of columns) that has unique values.

  • Many To Many Relationship (many-to-many): In a many-to-many relationship, one or more rows in a table can be related to 0, 1 or many rows in another table. A mapping table is required in order to implement such a relationship.

Note

  • Application developer can assign any name to EntityDescriptor.xml file.

  • Descriptor file should be in same place as per defined in DatabaseDescriptor.xml file.

Android Sample: Entity Descriptor


![Android Sample: Entity Descriptor] (https://raw.github.com/Siminov/core/docs/github/v2.0/entity_descriptor_path.android.png "Android Sample: Entity Descriptor")


iOS Sample: Entity Descriptor


![iOS Sample: Entity Descriptor] (https://raw.github.com/Siminov/core/docs/github/v2.0/entity_descriptor_path.ios.png "iOS Sample: Entity Descriptor")


Windows Sample: Entity Descriptor


![Windows Sample: Entity Descriptor] (https://raw.github.com/Siminov/core/docs/github/v2.0/entity_descriptor_path.windows.png "Windows Sample: Entity Descriptor")