Anyframe Core

anyframe.core.hibernate
Interface IDynamicHibernateService


public interface IDynamicHibernateService

By integrating Hibernate and Velocity, this services helps in dynamically generating the appropriate HQL (Hibernate Query Language) according to the input conditions. We define dynamic HQLs in a separate XML file and use the queryName to call the specified HQL. This allows the Hibernate based data access to be simple and the HQL is understood easily resulting in less errors and easier HQL modifications.

Configuration Example :

 <bean id="dynamicHibernateService"
           class="anyframe.core.hibernate.impl.DynamicHibernateService">
     <property name="sessionFactory" ref="sessionFactory" />
     <property name="fileNames">
         <list>
             <value>classpath:dynamic/dynamic-hibernate.xml</value>
         </list>
     </property>
 </bean>
 

Configuration Attributes :

Dynamic HQL Definition XML Example: In the XML file defining the dynamic HQL, the root element is defined as and we can define numerous in the The example is as follows:

 <query name="getSaleList">
 <![CDATA[
     SELECT new Product( product.prodNo as prodNo
         , product.prodName as prodName
         , product.sellAmount as sellAmount
         , category.categoryName as categoryName
         , product.regDate as regDate )
     FROM Product product join product.category category
     WHERE
         #if(<b>$prodNo</b>)
             product.prodNo like <b>:prodNo</b>
         #else
             product.prodName like :prodName
         #end
         #if ($sellerId)
             AND product.sellerId = :sellerId
         #end
         #if ($categoryNo)
             AND category.categoryNo = :categoryNo
         #end
     ORDER BY product.<b>{{sortColumn}}</b> {{sortDirection}}
 ]]>
 </query>
 

Author:
SoYon Lim

Field Summary
static Log LOGGER
           
 
Method Summary
 Object find(String queryName, Object[] values)
          We find the appropropriate HQL by the dynamic HQL's identifier defined in a separate XML.
 Object findByNamedParam(String queryName, String[] paramNames, Object[] values)
          We find the appropropriate HQL by the dynamic HQL's identifier defined in a separate XML.
 Object findByNamedParam(String queryName, String paramName, Object value)
          We find the appropropriate HQL by the dynamic HQL's identifier defined in a separate XML.
 List findList(String queryName, Object[] values)
          We find the appropropriate HQL by the dynamic HQL's identifier defined in a separate XML.
 List findList(String queryName, Object[] values, int pageIndex, int pageSize)
          We find the appropropriate HQL by the dynamic HQL's identifier defined in a separate XML.
 List findListByNamedParam(String queryName, String[] paramNames, Object[] values)
          We find the appropropriate HQL by the dynamic HQL's identifier defined in a separate XML.
 List findListByNamedParam(String queryName, String[] paramNames, Object[] values, int pageIndex, int pageSize)
          We find the appropropriate HQL by the dynamic HQL's identifier defined in a separate XML.
 List findListByNamedParam(String queryName, String paramName, Object value)
          We find the appropropriate HQL by the dynamic HQL's identifier defined in a separate XML.
 List findListByNamedParam(String queryName, String paramName, Object value, int pageIndex, int pageSize)
          We find the appropropriate HQL by the dynamic HQL's identifier defined in a separate XML.
 

Field Detail

LOGGER

static final Log LOGGER
Method Detail

findListByNamedParam

List findListByNamedParam(String queryName,
                          String[] paramNames,
                          Object[] values)
                          throws Exception
We find the appropropriate HQL by the dynamic HQL's identifier defined in a separate XML. Then, we replace the phrase handled by variables with the inputted values and return the executed result values of appropriate HQL phrases completed by the Hibernate session. We return the the executed results in a list type.

Parameters:
queryName - Executable dynamic HQL's identifier
paramNames - The variable names for replacing with the inputted variables
values - Variable values for replacing in phrases handled with variables
Returns:
Being specified HQL execution results, returns numerous data in a list type
Throws:
Exception - In the case there is a problem in executing the specified HQL

findListByNamedParam

List findListByNamedParam(String queryName,
                          String paramName,
                          Object value)
                          throws Exception
We find the appropropriate HQL by the dynamic HQL's identifier defined in a separate XML. Then, we replace the phrase handled by variables with the inputted values and return the executed result values of appropriate HQL phrases completed by the Hibernate session. When the variable is one , we may use this easily and return the executed results in a list type.

Parameters:
queryName - Executable dynamic HQL's identifier
paramName - The variable name for replacing with the inputted variable
value - Variable value for replacing in phrases handled with variable
Returns:
Being specified HQL execution results, returns numerous data in a list type
Throws:
Exception - In the case there is a problem in executing the specified HQL

findList

List findList(String queryName,
              Object[] values)
              throws Exception
We find the appropropriate HQL by the dynamic HQL's identifier defined in a separate XML. Then, we replace the phrase handled by variables with the inputted values and return the executed result values of appropriate HQL phrases completed by the Hibernate session. We return the the executed results in a list type.

Parameters:
queryName - Executable dynamic HQL's identifier
values - Defines as 'name=value' the variable values for replacing the variables defined in dynamic HQL
Returns:
Being specified HQL execution results, returns numerous data in a list type
Throws:
Exception - In the case there is a problem in executing the specified HQL

findList

List findList(String queryName,
              Object[] values,
              int pageIndex,
              int pageSize)
              throws Exception
We find the appropropriate HQL by the dynamic HQL's identifier defined in a separate XML. Then, we replace the phrase handled by variables with the inputted values and return the executed result values of appropriate HQL phrases completed by the Hibernate session. We return the numerous result according to the specific pages in a list type. The paging handling is not executed if either of pageIndex or pageSize is 0.

Parameters:
queryName - Executable dynamic HQL's identifier
values - Defines as 'name=value' the variable values for replacing the variables defined in dynamic HQL
pageIndex - Page number (greater than equal to one)
pageSize - The number of data for showing in the selected page (greater than equal to one)
Returns:
Being specified HQL execution results, returns numerous data in a list type
Throws:
Exception - In the case there is a problem in executing the specified HQL

findListByNamedParam

List findListByNamedParam(String queryName,
                          String[] paramNames,
                          Object[] values,
                          int pageIndex,
                          int pageSize)
                          throws Exception
We find the appropropriate HQL by the dynamic HQL's identifier defined in a separate XML. Then, we replace the phrase handled by variables with the inputted values and return the executed result values of appropriate HQL phrases completed by the Hibernate session. We return the numerous result according to the specific pages in a list type. The paging handling is not executed if either of pageIndex or pageSize is 0.

Parameters:
queryName - Executable dynamic HQL's identifier
paramNames - The variable names for replacing with the inputted variables
values - Variable values for replacing in phrases handled with variables
pageIndex - Page number (greater than equal to one)
pageSize - The number of data for showing in the selected page (greater than equal to one)
Returns:
Being specified HQL execution results, returns numerous data in a list type
Throws:
Exception - In the case there is a problem in executing the specified HQL

findListByNamedParam

List findListByNamedParam(String queryName,
                          String paramName,
                          Object value,
                          int pageIndex,
                          int pageSize)
                          throws Exception
We find the appropropriate HQL by the dynamic HQL's identifier defined in a separate XML. Then, we replace the phrase handled by variables with the inputted values and return the executed result values of appropriate HQL phrases completed by the Hibernate session. When the variable is one, this is efficiently used. At execution, returns in a list type the numerous results of the HQL completed by Hibernate session. The paging handling is not executed if either of pageIndex or pageSize is 0.

Parameters:
queryName - Executable dynamic HQL's identifier
paramName - The variable name for replacing with the inputted variable
value - Variable value for replacing in phrases handled with variable
pageIndex - Page number (greater than equal to one)
pageSize - The number of data for showing in the selected page (greater than equal to one)
Returns:
Being specified HQL execution results, returns numerous data in a list type
Throws:
Exception - In the case there is a problem in executing the specified HQL

findByNamedParam

Object findByNamedParam(String queryName,
                        String[] paramNames,
                        Object[] values)
                        throws Exception
We find the appropropriate HQL by the dynamic HQL's identifier defined in a separate XML. Then, we replace the phrase handled by variables with the inputted values and return the executed result values of appropriate HQL phrases completed by the Hibernate session. After execution, returns the result in object type.

Parameters:
queryName - Executable dynamic HQL's identifier
paramNames - The variable names for replacing with the inputted variables
values - Variable values for replacing in phrases handled with variables
Returns:
Being specified HQL execution results, returns numerous data in a list type
Throws:
Exception - In the case there is a problem in executing the specified HQL

findByNamedParam

Object findByNamedParam(String queryName,
                        String paramName,
                        Object value)
                        throws Exception
We find the appropropriate HQL by the dynamic HQL's identifier defined in a separate XML. Then, we replace the phrase handled by variables with the inputted values and return the executed result values of appropriate HQL phrases completed by the Hibernate session. When the variable is one, this is efficiently used. After execution, returns the result in object type.

Parameters:
queryName - Executable dynamic HQL's identifier
paramName - The variable name for replacing with the inputted variable
value - Variable value for replacing in phrases handled with variable
Returns:
Being specified HQL execution results, returns numerous data in a list type
Throws:
Exception - In the case there is a problem in executing the specified HQL

find

Object find(String queryName,
            Object[] values)
            throws Exception
We find the appropropriate HQL by the dynamic HQL's identifier defined in a separate XML. Then, we replace the phrase handled by variables with the inputted values and return the executed result values of appropriate HQL phrases completed by the Hibernate session. After execution, returns the result in object type.

Parameters:
queryName - Executable dynamic HQL's identifier
values - Defines as 'name=value' the variable values for replacing the variables defined in dynamic HQL
Returns:
Being specified HQL execution results, returns numerous data in a list type
Throws:
Exception - In the case there is a problem in executing the specified HQL

Anyframe Core

Copyright © 2008-2009 Samsung SDS. All Rights Reserved.