Java – Spring StoredProcedure Inject declared parameters or not

dependency-injectionjavaspringstored-procedures

At work one of my colleague asked to me to change the way a Spring StoredProcedure subclass class was initialised from injecting the parameters with Dependency Injection mechanism (Constructor Injection) to a "more straight forward and simple way".

The actual code with DI initialization looks like :

<constructor-arg><ref bean="datasource"/></constructor-arg>
<constructor-arg value="STOREDPR"></constructor-arg>  
<constructor-arg>
<list>
                <bean parent="SQL.TIMESTAMP.IN">
                    <constructor-arg type="java.lang.String" value="parameter1" />
                </bean>
                <bean parent="SQL.TIMESTAMP.INOUT">
                    <constructor-arg type="java.lang.String" value="parameter2" />
                </bean>
                <bean parent="SQL.NUMERIC.IN">
                    <constructor-arg type="java.lang.String" value="parameter3" />
                </bean>
</list>
</constructor-arg>

SubClass of StoredProcedure injected constructor :

public AStoreProcedure(DataSource datasource, String procedureName, List<SqlParameter> params) {
    super(datasource, procedureName);

    for(SqlParameter p : params) 
        declareParameter(p);

    compile();
}

In my opinion construction of a StoredProcedure with DI is not a bad idea since you can change the StoreProcedure signature(declared parameters) without having to change the code of your application, but just changing the XML …

Do you think removing DI mechanism in this case make sense ?
What could be a good alternative ?

Best Answer

There is no way to eliminate possible run-time disagreements between your database and your Java code. The best you can do is ro make your Java code depend only on parths of the schema that are necessary for your business logic, and run integration tests before deploying to production.

Related Topic