如何在使用 informix 和 jdbcTemplate 的 spring 引导应用程序中更改设置锁定模式以等待?

How to change set lock mode to wait in in spring boot application which use informix and jdbcTemplate?

我在我的应用程序中使用 Spring boot 2 和 jdbcTemplate。我用的是 Informix。 我正在测试并发性,我希望我的应用程序等待一段时间 查询尝试更新锁定的行。这个时间可以在informix中设置 'SET LOCK MODE TO WAIT 20'。但我正在 spring jdbcTemplate 或 spring.

中寻找方法

我尝试在 jdbcTemplate.setQueryTimeout(60); 中设置超时,但没有成功。

欢迎任何想法。

jdbcTemplate.setQueryTimeout(60);
cachedExecutor.execute(() -> jdbcTemplate.update(updatenIndoPeriodeInLfa()) );

cachedExecutor.execute(() -> jdbcTemplate.update(updatenAfroPeriodeInLfa()) );

private String updatenIndoPeriodeInLfa(){
        String query = "UPDATE  lfa " +
                "set indomonth = 09, indoyear = 2019 , indotype = indo " +
                "WHERE lfa.id in (select id " +
                "                   from   procindo " +
                "                   where  month   =   09    and" +
                "                          year    =   2019     and" +
                "                          type=   indo );";

        return query;
    }

    private String updatenAfroPeriodeInLfa(){
        String query = "UPDATE  lfa " +
                "set afromonth = 09, afroyear  = 2019 , afrotype = indo " +
                "WHERE lfa.id in (select id " +
                "                   from   procafro " +
                "                   where  month   =   09    and" +
                "                          year    =   2019     and" +
                "                          type=   afro );";

        return query;
    }

在深入研究 Informix 文档后,我发现了这个:

应用程序可以使用此 属性 覆盖默认服务器进程以访问锁定的行或 table。获取特定于 Informix 的 IFX_LOCK_MODE_WAIT 变量的值。默认值为 0(不等待锁定)。如果已明确设置该值,则它 return 是设置值。 Returns:整数。 设置特定于 Informix 的 IFX_LOCK_MODE_WAIT 变量的值。 可能的值:

-1 等到锁被释放。

0 不要等待,结束操作,然后 return 出现错误。

nn 等待 nn 秒以释放锁。

然后在我的应用程序数据源配置中,按如下方式传递此 属性:

@Bean(name = "informixDataSource")
public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("com.informix.jdbc.IfxDriver");

        Properties properties = new Properties();
        properties.put("IFX_LOCK_MODE_WAIT", "60");

        dataSource.setConnectionProperties(properties);
        dataSource.setUrl(jdbc.getUrl());
        dataSource.setUsername(jdbc.getUser());
        dataSource.setPassword(jdbc.getPassword());

        return dataSource;
    }