Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Development/MetadataCollection"

Line 1: Line 1:
 
== Metadata Collection Requirements and Design   ==
 
== Metadata Collection Requirements and Design   ==
  
Enhancement Request : Bug 330846  
+
Enhancement Request: {{bug|330846}}
  
 
This feature will help eclipselink users to gather the metadata configurations annotated on/in several different entities on to a single centralized location (class)  for better maintenence over time. The prposed feature will leverage existing standards and convensions for grouping metadata and builds upon the same to further simplify its usage and maintenence.   
 
This feature will help eclipselink users to gather the metadata configurations annotated on/in several different entities on to a single centralized location (class)  for better maintenence over time. The prposed feature will leverage existing standards and convensions for grouping metadata and builds upon the same to further simplify its usage and maintenence.   
Line 15: Line 15:
 
*all related converters  
 
*all related converters  
 
*all related query redirectors   
 
*all related query redirectors   
 
<br>
 
  
 
at a central place like any ordinary utility class  
 
at a central place like any ordinary utility class  
Line 25: Line 23:
  
 
The Metadata Collection is somewhat similar to the existing support for assembling all metatadata in eclipselink-orm.xml; however, it does not aim to be an all encompassing storehouse for the entire metadata of the project, as is the eclipselink-orm.xml. It is expected to be used to group related metadata for easier maintenance.  
 
The Metadata Collection is somewhat similar to the existing support for assembling all metatadata in eclipselink-orm.xml; however, it does not aim to be an all encompassing storehouse for the entire metadata of the project, as is the eclipselink-orm.xml. It is expected to be used to group related metadata for easier maintenance.  
 
<br>
 
  
 
This &nbsp;feature will be available in both the Java annotations and XML mappings.  
 
This &nbsp;feature will be available in both the Java annotations and XML mappings.  
Line 33: Line 29:
  
 
===== &nbsp;&nbsp;@MetadataCollection  =====
 
===== &nbsp;&nbsp;@MetadataCollection  =====
 +
<pre>/*
 +
A Metadata Collection can be defined on any ordinary java class to group related metadata like
 +
named queries, resultset mappings, convertors, query redirectors, etc at a central place rather than
 +
on an entity to increase reusability and clarity of code. A central location will also simplify the
 +
maintenance of these metadata. A eclipselink persistence project can have several classes that have been
 +
marked with Metadata Collection so that the users can group related metadata in to several sets for easier
 +
maintenance.
  
[code]
+
*/
 
+
/**
+
 
+
A Metadata Collection can be defined on any ordinary java class to group related metadata like named queries, resultset mappings, convertors, query redirectors, etc at a central place rather than on an entity to increase reusability and clarity of code. A central location will also simplify the maintenance of these metadata. A eclipselink persistence project can have several classes that have been marked with Metadata Collection so that the users can group related metadata in to several sets for easier maintenance.
+
 
+
 
+
 
+
*/  
+
 
+
 
@Target(TYPE)  
 
@Target(TYPE)  
 
 
@Retention(RUNTIME)  
 
@Retention(RUNTIME)  
 
 
public @interface MetadataCollection{  
 
public @interface MetadataCollection{  
 
+
    NamedQueries namedQueries();  
&nbsp;&nbsp; &nbsp;NamedQueries namedQueries();  
+
    NamedNativeQueries namedNativeQueries();
 
+
    NamedStoredProcedureQueries namedStoredProcedureQueries();
&nbsp;&nbsp; &nbsp;NamedNativeQueries namedNativeQueries();  
+
    SQLResultSetMappings[] resultSetMappings() default {};  
 
+
    Convertors convertors();  
&nbsp;&nbsp; &nbsp;NamedStoredProcedureQueries namedStoredProcedureQueries();  
+
    QueryRedirectors queryRedirectors;
 
+
}
&nbsp;&nbsp; &nbsp;SQLResultSetMappings[] resultSetMappings() default {};  
+
</pre>
 
+
====  ====
&nbsp;&nbsp; &nbsp;Convertors convertors();  
+
 
+
&nbsp;&nbsp; &nbsp;QueryRedirectors queryRedirectors;  
+
 
+
}  
+
 
+
[/code]
+
  
 
==== XML Element  ====
 
==== XML Element  ====
Line 70: Line 56:
 
A metadata complex xml element will be created to group all related metadata together:  
 
A metadata complex xml element will be created to group all related metadata together:  
  
[code]
+
<br>
 +
<pre>&lt;xs:complexType name="metadata-collection"&gt;
  
&lt;xs:complexType name="metadata-collection"&gt;  
+
    &lt;xs:annotation&gt;  
  
&nbsp;&nbsp; &nbsp; &lt;xs:annotation&gt;  
+
        &lt;xs:documentation&gt;  
  
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;xs:documentation&gt;  
+
        &lt;/xs:documentation&gt;&nbsp;  
  
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/xs:documentation&gt;&nbsp;  
+
    &lt;/xs:annotation&gt;  
  
&nbsp;&nbsp; &nbsp; &lt;/xs:annotation&gt;  
+
    &lt;xs:sequence&gt;  
  
&nbsp;&nbsp; &nbsp; &lt;xs:sequence&gt;  
+
        &lt;xs:element name="named-queries" &nbsp;minOccurs="0"&gt;
 +
              &lt;xs:element ref="named-query"/&gt;  
 +
        &lt;/xs:element&gt;  
  
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;xs:element name="namedQueries" &nbsp;minOccurs="0"&gt;  
+
        &lt;xs:element name="named-native-queries" minOccurs="0"&gt;
 +
              &lt;xs:element ref="named-native-query"/&gt;
 +
        &lt;/xs:element&gt;  
  
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/xs:element&gt;  
+
        &lt;xs:element name="named-stored-procedure-queries"&gt;  
 +
              &lt;xs:element ref="named-stored-procedure-query"/&gt;  
 +
        &lt;/xs:element&gt;  
  
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;xs:element name="namedNativeQueries" minOccurs="0"&gt;  
+
        &lt;xs:element name="resultset-mappings" minOccurs="0"&gt;
 +
              &lt;xs:element ref="sql-resultset-mapping"/&gt;
 +
        &lt;/xs:element&gt;  
  
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/xs:element&gt;  
+
        &lt;xs:element name="convertors" minOccurs="0"
 +
              &lt;xs:element ref="convertor"/&gt;  
 +
        &lt;/xs:element&gt;  
  
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;xs:element name="namedStoredProcedureQueries"&gt;  
+
        &lt;xs:element name="query-redirectors" minOccurs="0"&gt;  
 +
              &lt;xs:element ref="query-redirector"/&gt;
 +
        &lt;/xs:element&gt;  
  
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/xs:element&gt;
+
    &lt;/xs:sequence&gt;  
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;xs:element name="resultSetMappings" minOccurs="0"&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/xs:element&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;xs:element name=convertors minOccurs="0"
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/xs:element&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;xs:element name="query-redirectors" minOccurs="0"&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/xs:element&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp;&lt;/xs:sequence&gt;
+
  
 
&lt;/xs:complexType&gt;  
 
&lt;/xs:complexType&gt;  
  
[/code]
+
</pre>
 +
===== <br> Example:  =====
 +
<pre>@MetadataCollection{
 +
    namedQueries={
 +
          @NamedQuery(name=SavingsAccountQueries.fetchWithdrawalBalance, query="SELECT account.balance
 +
                      FROM Account account WHERE account.user=:userName"),
  
<br>
+
    },
 +
    namedStoredProcedureQueries={
 +
    },
 +
    convertors={
 +
          @Convertor(name=SavingsAccountQueries.genderConvertor,
 +
                convertorClass=com.company.product.module.convertors.GenderConvertor)
 +
     
 +
    }
  
<br>
+
}
  
Example:
+
public class SavingsAccountQueries {
  
[code]
+
    public static final String fetchWithdrawalBalance="fetchWithdrawalBalance";
 +
    public static final String genderConvertor="genderConvertor";
  
&lt;metadata-collection&gt;
+
}
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;named-queries&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;named-query name="" query=""/&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;/named-query&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;named-native-queries&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;named-native-query name="" query=""/&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &lt;/named-native-queries&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &lt;named-stored-procedure-queries&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;named-stored-procedure-query name="" query="" /&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &lt;/named-stored-procedure-queries&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &lt;result-set-mappings&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;sql-resultset-mapping&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;!-- &lt;entity&gt;and &lt;field&gt; mappings --&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/sql-resultset-mapping&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &lt;/resultset-mappings&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &lt;convertors&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;convertor name="" class=""&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/convertor&gt;
+
 
+
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &lt;/convertors&gt;
+
  
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;query-redirectors&gt;  
+
</pre> <pre>&lt;metadata-collection&gt;  
  
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;query-redirector allqueries="DefaultRedirector.class"/&gt;  
+
    &lt;named-queries&gt;  
 +
        &lt;named-query name="" query=""/&gt;
 +
    &lt;/named-query&gt;  
  
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/query-redirectors&gt;  
+
    &lt;named-native-queries&gt;  
 +
        &lt;named-native-query name="" query=""/&gt;  
 +
    &lt;/named-native-queries&gt;  
 +
   
 +
    &lt;named-stored-procedure-queries&gt;
 +
      &lt;named-stored-procedure-query name="" query="" /&gt;
 +
    &lt;/named-stored-procedure-queries&gt;
 +
   
 +
    &lt;result-set-mappings&gt;
 +
        &lt;sql-resultset-mapping&gt;
 +
            &lt;!-- &lt;entity&gt;and &lt;field&gt; mappings --&gt;
 +
        &lt;/sql-resultset-mapping&gt;
 +
    &lt;/resultset-mappings&gt;  
  
&lt;/metadata-collection&gt;  
+
    &lt;convertors&gt;
 +
        &lt;convertor name="" class=""&gt;
 +
        &lt;/convertor&gt;
 +
    &lt;/convertors&gt;  
  
[/code]
+
    &lt;query-redirectors&gt;
 +
        &lt;query-redirector allqueries="DefaultRedirector.class"/&gt;
 +
    &lt;/query-redirectors&gt;
  
&nbsp;
+
&lt;/metadata-collection&gt;
  
which can be annotated on any ordinary top level java class to group metadata that belongs to more than one entity.
+
</pre>

Revision as of 14:33, 30 November 2010

Metadata Collection Requirements and Design 

Enhancement Request: bug 330846

This feature will help eclipselink users to gather the metadata configurations annotated on/in several different entities on to a single centralized location (class)  for better maintenence over time. The prposed feature will leverage existing standards and convensions for grouping metadata and builds upon the same to further simplify its usage and maintenence. 


List of Requirements:

   This feature should provide eclipselink users the ability to group:

  • all types of related named queries
  • all related resultset mappings
  • all related converters
  • all related query redirectors   

at a central place like any ordinary utility class

Metadata

The following sections will give in detail the changes and modifications that are required for implementing this feature.

The Metadata Collection is somewhat similar to the existing support for assembling all metatadata in eclipselink-orm.xml; however, it does not aim to be an all encompassing storehouse for the entire metadata of the project, as is the eclipselink-orm.xml. It is expected to be used to group related metadata for easier maintenance.

This  feature will be available in both the Java annotations and XML mappings.

Annotation:

  @MetadataCollection
/* 
A Metadata Collection can be defined on any ordinary java class to group related metadata like 
named queries, resultset mappings, convertors, query redirectors, etc at a central place rather than 
on an entity to increase reusability and clarity of code. A central location will also simplify the 
maintenance of these metadata. A eclipselink persistence project can have several classes that have been 
marked with Metadata Collection so that the users can group related metadata in to several sets for easier 
maintenance.

*/
 
@Target(TYPE) 
@Retention(RUNTIME) 
public @interface MetadataCollection{ 
    NamedQueries namedQueries(); 
    NamedNativeQueries namedNativeQueries();  
    NamedStoredProcedureQueries namedStoredProcedureQueries();  
    SQLResultSetMappings[] resultSetMappings() default {}; 
    Convertors convertors(); 
    QueryRedirectors queryRedirectors;
}

XML Element

A metadata complex xml element will be created to group all related metadata together:


<xs:complexType name="metadata-collection"> 

     <xs:annotation> 

        <xs:documentation> 

        </xs:documentation>  

     </xs:annotation> 

     <xs:sequence> 

         <xs:element name="named-queries"  minOccurs="0">
              <xs:element ref="named-query"/> 
         </xs:element> 

         <xs:element name="named-native-queries" minOccurs="0"> 
              <xs:element ref="named-native-query"/>
         </xs:element> 

         <xs:element name="named-stored-procedure-queries"> 
              <xs:element ref="named-stored-procedure-query"/> 
         </xs:element> 

         <xs:element name="resultset-mappings" minOccurs="0"> 
              <xs:element ref="sql-resultset-mapping"/>
         </xs:element> 

         <xs:element name="convertors" minOccurs="0" 
              <xs:element ref="convertor"/> 
         </xs:element> 

         <xs:element name="query-redirectors" minOccurs="0"> 
              <xs:element ref="query-redirector"/>
         </xs:element> 

     </xs:sequence> 

</xs:complexType> 


Example:
@MetadataCollection{
     namedQueries={
          @NamedQuery(name=SavingsAccountQueries.fetchWithdrawalBalance, query="SELECT account.balance 
                      FROM Account account WHERE account.user=:userName"),

     },
     namedStoredProcedureQueries={
     },
     convertors={
          @Convertor(name=SavingsAccountQueries.genderConvertor,
                convertorClass=com.company.product.module.convertors.GenderConvertor)
      
     }

}

public class SavingsAccountQueries {

    public static final String fetchWithdrawalBalance="fetchWithdrawalBalance";
    public static final String genderConvertor="genderConvertor";

} 

<metadata-collection> 
   <named-queries> 
       <named-query name="" query=""/> 
   </named-query> 
   <named-native-queries> 
       <named-native-query name="" query=""/> 
   </named-native-queries> 
   
   <named-stored-procedure-queries> 
     <named-stored-procedure-query name="" query="" /> 
   </named-stored-procedure-queries> 
   
   <result-set-mappings> 
       <sql-resultset-mapping> 
           <!-- <entity>and <field> mappings --> 
       </sql-resultset-mapping> 
   </resultset-mappings> 
   <convertors> 
        <convertor name="" class=""> 
       </convertor> 
   </convertors> 
   <query-redirectors> 
       <query-redirector allqueries="DefaultRedirector.class"/> 
   </query-redirectors> 

</metadata-collection>

Back to the top