I want to write a SpringBatch Tasklet, that automatically activates or de-activates all indexes for a given database table. The code needs to work independantly of the DBMS
You have to make a difference between primary keys (using DatabaseMetaData.getPrimaryKeys()
to retrieve) and other indexes (via dbMetaData.getIndexInfo(null, null, tableName, true, false)
).
In your loop use:
rs.getString("INDEX_NAME")
to extract index namers.getBoolean("NON_UNIQUE")
to extract unique informationrs.getShort("TYPE")
to extract index typers.getInt("ORDINAL_POSITION")
to extract ordinal positionUse ORDINAL_POSITION
as key break (when current value is <= of previous one) to detect index change.
Read official DatabaseMetaData.getIndexInfo() doc