繁体   English   中英

自定义 StoredProcedure class 作为 Spring 组件并扩展 jdbc StoredProcedure

[英]Custom StoredProcedure class as a Spring component and extends jdbc StoredProcedure

I have a custom Stored Procedure class which is extending jdbc.StoredProcedure but I have annotated this class with Spring @Component to bring this class bean into Spring context.

我为什么要这样做?

  1. 我想在执行方法上添加 spring-retry,该方法仅适用于 spring 组件
  2. 我想重用已编译的 StoredProcedure,而不是创建一个新的 object 并每次重新编译,这样我每次都可以重用已编译的 StoredProcedure。

这种实现有什么问题吗? 这个基于 Spring 组件的 StoredProcedure 有什么问题吗?

前任:

    @Component
public class ExampleStoredProcedure extends StoredProcedure {
  @Autowired
  private DataSource dataSource;

  @Postconstruct
  public void init() {
     super.setDataSource(dataSource);
     setSql("stored_procedure_name");
//TODO      declare parameters
     compile();
  }

  public void execute(){
    //Todo set all parameters to ParameterSource
    super.execute(parameterSource);
  }
}

尝试实现一个分层的应用程序架构,在其中使用 spring 重试您的服务,如下例所示:

https://dzone.com/articles/spring-retry-way-to-handle-failures

这些服务方法可以定义事务边界并调用您的数据持久层方法,这些方法可以基于 spring 数据的标准化方法来调用存储过程和管理数据库连接等。

有关 Spring 和架构的更多信息,请参阅此简介:

https://www.petrikainulainen.net/software-development/design/understanding-spring-web-application-architecture-the-classic-way/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM