Best practice for CustomTaskChange

The purpose of a CustomTaskChange (CTC for short) is to execute some arbirtary sql with complex loops and other “strange” things.

To that end, you obviously need a JdbcHelper to handle the hassle of JDBC.

My idea was to use the spring JdbcTemplate class. I can not use it because the Database parameter exposed to the execute method of CTC does not expose the DataSource needed to initialize a spring JdbcTemplate.

I see that liquidbase already has a JdbcTemplate class to that purpose but it missed all the facility to manipulate binded parameters compared to the spring one.

So my questions are :

  1. is it ok to use the liquibase JdbcTemplate ?
  2. if it is ok, I think that it would be great to “backport” the spring JdbcTemplate functions that deals with binded parameters to liquibase jdbcTemplate (otherwise, I can create my own subclass of liquibase JdbcTemplate but then all the other users of liquibase will also have to do so)
  3. or maybe I’m totally misguided and should proceed with another mindset ?

regards

Yes, some sort of JDBC Helper would be good to use.  We do have a JdbcTemplate class that was more or less copied and modified from spring’s code, but I would not recommend using it.  It is used internally in liqubase and I don’t consider it a public API and so may change from release to release.

Since your custom task change is running in your codebase, you can use any 3rd party libraries you have, including the spring JdbcTemplate libraries if you can get a datasource.  I think there are some libraries that you can give a connection and it will create a DataSource wrapper around it.  Possibly just creating a custom implementation of DataSource? 

Nathan

Hi,

sorry for my answer delay.

Since your custom task change is running in your codebase, you can use any 3rd party libraries you have, including the spring JdbcTemplate libraries if you can get a datasource.  I think there are some libraries that you can give a connection and it will create a DataSource wrapper around it.  Possibly just creating a custom implementation of DataSource?

The idea is to have this into liquibase so that all users of liquibase may benefit from it, not just me.

At the end, I am currently using your jdbcTemplate to execute the selects and I use InsertStatement and UpdateStatement to execute insert and update