final int counter[] = new int[1];
counter[0] = 0;
final JdbcTemplate jdbc = new JdbcTemplate(getDataSource());
try {
String sql = " from t_history_property_delta where old_value like 'org.projectforge.%' or new_value like 'org.projectforge.%'";
jdbc.query("select id, old_value, new_value, property_type" + sql, new ResultSetExtractor() {
@Override
public Object extractData(final ResultSet rs) throws SQLException, DataAccessException
{
while (rs.next() == true) {
final int id = rs.getInt("ID");
final String oldValue = rs.getString("OLD_VALUE");
final String newValue = rs.getString("NEW_VALUE");
final Serializable oldId = getObjectId(oldValue);
final Serializable newId = getObjectId(newValue);
final String propertyType = rs.getString("PROPERTY_TYPE");
final int pos = propertyType.indexOf("_$$_javassist_");
final String newPropertyType;
if (pos > 0) {
newPropertyType = propertyType.substring(0, pos);
} else {
newPropertyType = null;
}
if (oldId == null && newId == null) {
continue;
}
final StringBuffer buf = new StringBuffer();
boolean first = true;
buf.append("update t_history_property_delta set ");
if (oldId != null) {
buf.append("OLD_VALUE='").append(oldId).append("'");
first = false;
}
if (newId != null) {
if (first == false) {
buf.append(", ");
} else {
first = false;
}
buf.append("NEW_VALUE='").append(newId).append("'");
}
if (newPropertyType != null) {
if (first == false) {
buf.append(", ");
} else {
first = false;
}
buf.append("PROPERTY_TYPE='").append(newPropertyType).append("'");
}
buf.append(" where ID=").append(id);
final String sql = buf.toString();
log.info(sql);
jdbc.execute(sql);
counter[0]++;
}
return null;
}
});
int no = jdbc.queryForInt("select count(*)" + sql);
if (no > 0) {
log.warn("" + no + " of data base history entries aren't fixed.");
}
sql = " from t_history_property_delta where property_type like '%_$$_javassist_%'";
jdbc.query("select id, property_type" + sql, new ResultSetExtractor() {
@Override
public Object extractData(final ResultSet rs) throws SQLException, DataAccessException
{
while (rs.next() == true) {
final int id = rs.getInt("ID");