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

EclipseLink/Development/MetadataCollection

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