【问题标题】:How to dynamically change the name of a stored procedure when using Spring SimpleJdbcCall使用 Spring SimpleJdbcCall 时如何动态更改存储过程的名称
【发布时间】:2016-09-12 15:43:17
【问题描述】:

我想从我的应用程序中动态更改调用的存储过程的名称,而不必使用 SimpleJDBC 部署我的应用程序。

我正在使用连贯缓存来缓存在控制表中维护的存储过程的活动版本。在没有更改存储过程的输入/输出的情况下发生功能更改的情况下,我部署新版本的存储过程并更新控制表中的新名称。在缓存的 TTL(生存时间)到期并刷新缓存后,应用程序可以使用新名称。

但是我的观察是,即使刷新了缓存,execute 语句也会调用部署期间可用的旧版本的存储过程,我该如何更改它

Map response = simpleJdbcCall.execute(new MapSqlParameterSource(map));

非常感谢任何帮助。

谢谢

【问题讨论】:

    标签: spring spring-jdbc spring-cache


    【解决方案1】:

    您的设计似乎有问题。

    SimpleJdbcCall 是一次性编译对象:

    /**
     * Compile this JdbcCall using provided parameters and meta data plus other settings.
     * <p>This finalizes the configuration for this object and subsequent attempts to compile are
     * ignored. This will be implicitly called the first time an un-compiled call is executed.
     * @throws org.springframework.dao.InvalidDataAccessApiUsageException if the object hasn't
     * been correctly initialized, for example if no DataSource has been provided
     */
    public synchronized final void compile() throws InvalidDataAccessApiUsageException {
    

    因此,您无法在运行时更改其内部状态。

    但我可以向您建议解决方案,例如为每个新过程名称创建一个新的缓存实例。为此,您可以编写一些@Cached 服务,它将返回一个SimpleJdbcCall 实例。因此,如果您使缓存过期,将为您创建一个新实例,您有责任将实际过程名称填充到该新对象。

    附:是的,Spring Integration 没有任何内容,请谨慎选择问题的标签。

    【讨论】:

      猜你喜欢
      • 2019-06-02
      • 1970-01-01
      • 2017-09-06
      • 2020-10-08
      • 2017-06-10
      • 2019-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多