Spring integration select sql参数源中的重复调用
我正在处理一个动态查询,使用selectsql参数源来搜索我需要的信息 这是我的配置:Spring integration select sql参数源中的重复调用,spring-integration,Spring Integration,我正在处理一个动态查询,使用selectsql参数源来搜索我需要的信息 这是我的配置: <int-jdbc:inbound-channel-adapter query="SELECT * FROM CUSTOMER WHERE CUSTOMER.LASTUPDATE_ACTIVE < TO_DATE(:last_process_date,'YYYY-MM-DD HH24:Mi:SS') " channel="headerEnricher.customerBR
<int-jdbc:inbound-channel-adapter query="SELECT * FROM CUSTOMER WHERE CUSTOMER.LASTUPDATE_ACTIVE < TO_DATE(:last_process_date,'YYYY-MM-DD HH24:Mi:SS') "
channel="headerEnricher.customerBR01"
update=""
row-mapper="customerRowMapper"
data-source="jdbcTemplate"
max-rows-per-poll="0"
select-sql-parameter-source="parameterSource.customerBR01">
<!-- Cron Time -->
<int:poller fixed-rate="50" time-unit="SECONDS">
</int:poller>
</int-jdbc:inbound-channel-adapter>
<!-- This is to get last process date -->
<bean id="parameterSource.customerBR01" factory-bean="parameterSourceFactory.customerBR01" factory-method="createParameterSourceNoCache">
<constructor-arg value="" />
</bean>
<bean id="parameterSourceFactory.customerBR01" class="org.springframework.integration.jdbc.ExpressionEvaluatingSqlParameterSourceFactory">
<property name="parameterExpressions">
<map>
<!-- Here we get the last process date -->
<entry key="last_process_date" value="@hsqlHistoricProcessServiceDateDAO.getLastProcessDate(3,1,'CUSTOMER')" />
</map>
</property>
</bean>
其结果是:
Contador 1
Contador 2
因此,这个方法被调用了两次,我只需要一次调用,因为在实际代码中,我为此记录了两次日志 对于您的用例,您不需要禁用缓存;用这个代替
<bean id="parameterSource.customerBR01"
factory-bean="parameterSourceFactory.customerBR01"
factory-method="createParameterSource">
<constructor-arg value="" />
</bean>
如果在多个参数中使用同一个键,并且希望重新计算每个参数,则需要使用…NoCache版本
禁用缓存会产生额外的副作用,因为每次使用密钥都会调用getValue方法两次。一个调用来自NamedParameterUtils.substituteNamedParameters;第二个来自NamedParameterUtils.buildValueArray。Hi Gary。我认为在我的逻辑中,这个解决方案是不可能的,我需要使用NoCache。因为在这个函数@hsqlHistoricProcessServiceDateDAO.getLastProcessDate3,1,'CUSTOMER'的实际代码中,我在嵌入式数据库中搜索一个特定的值,这个值在每次入站执行后都会发生变化。如果我把createParameterSource放进去,每次执行时的值都是一样的,我需要实际更改的值。。。当然可以。不幸的是,如果不改变Spring框架本身,我们在集成框架中无能为力。我们将在那里打开一个JIRA。在解决此问题之前,恐怕您需要在getLastProcessDate中添加自己的逻辑来缓存第一个调用,并在第二个调用后清除缓存。谢谢您的回答。
<bean id="parameterSource.customerBR01"
factory-bean="parameterSourceFactory.customerBR01"
factory-method="createParameterSource">
<constructor-arg value="" />
</bean>