How do I configure to automatically convert the integer parameters of ValueList statements to hql statements

  • 2020-05-27 07:22:36
  • OfStack

Parameters passed through valuelist's queryMap are of type string by default, and in hql of the valuelist configuration file, an error is reported if this value is assigned directly to an integer field. 1. Generally, we will use the transformation function in hql for processing, as follows:

<entry key="areasInfoAdapter">
       <bean  parent="abstractHibernate30Adapter">
                   <property name="defaultNumberPerPage"><value>19</value></property>
                     <property name="statementBuilder"><ref bean="statementBuilderHql"/></property> 
                      <property name="defaultSortColumn"><value>id</value></property>
                      <property name="defaultSortDirection"><value>desc</value></property>
                      <property name="hql">
                              from com.berheley.hcms.persistence.model.TBaseAreas as tb
                              where tb.status='1' 
                               /~hId  : and tb.hId  = to_number{hId}  ~/
                               /~oId  : and tb.oId  = to_number{oId}  ~/
                               order by tb.code asc
                      <property name="defaultFocusPropertyObjectAlias"><value>vo</value></property>
                      <property name="maxRowsForFocus"><value>160000</value></property>            
                      <property name="removeEmptyStrings"><value>true</value></property>

This approach is cumbersome, requiring the addition of functions to all integer fields, and function incompatibilities can occur during database migration. You can use the ValueList configuration to set the integer fields in 1. valuelist will transform the configured parameters before assembling sql. As follows:

<bean id="integerSetterHql" class="net.mlw.vlh.adapter.hibernate3.util.setter.IntegerSetter"></bean>
 <bean id="statementBuilderHql" class="net.mlw.vlh.adapter.hibernate3.util.StatementBuilder">
    <property name="setters">
      <entry key="uId"><ref bean="integerSetterHql"/></entry>
                                     <entry key="oId"><ref bean="integerSetterHql"/></entry>

Related articles: