mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-25 16:42:34 +00:00
Remove obsolete code for the Liquibase LogHistoryService
Closes #41229 Signed-off-by: Martin Bartoš <mabartos@redhat.com>
This commit is contained in:
@@ -16,30 +16,12 @@
|
||||
*/
|
||||
package org.keycloak.connections.jpa.updater.liquibase.conn;
|
||||
|
||||
import org.keycloak.common.util.reflections.Reflections;
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import liquibase.ContextExpression;
|
||||
import liquibase.Labels;
|
||||
import liquibase.change.CheckSum;
|
||||
import liquibase.change.ColumnConfig;
|
||||
import liquibase.changelog.ChangeSet;
|
||||
import liquibase.changelog.RanChangeSet;
|
||||
import liquibase.changelog.StandardChangeLogHistoryService;
|
||||
import liquibase.database.Database;
|
||||
import liquibase.database.core.MySQLDatabase;
|
||||
import liquibase.exception.DatabaseException;
|
||||
import liquibase.executor.jvm.ChangelogJdbcMdcListener;
|
||||
import liquibase.logging.LogFactory;
|
||||
import liquibase.snapshot.InvalidExampleException;
|
||||
import liquibase.snapshot.SnapshotGeneratorFactory;
|
||||
import liquibase.statement.core.AddPrimaryKeyStatement;
|
||||
@@ -53,7 +35,6 @@ import liquibase.structure.core.Table;
|
||||
*/
|
||||
public class CustomChangeLogHistoryService extends StandardChangeLogHistoryService {
|
||||
|
||||
private List<RanChangeSet> ranChangeSetList;
|
||||
private boolean serviceInitialized;
|
||||
|
||||
@Override
|
||||
@@ -74,68 +55,6 @@ public class CustomChangeLogHistoryService extends StandardChangeLogHistoryServi
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RanChangeSet> getRanChangeSets() throws DatabaseException {
|
||||
if (this.ranChangeSetList == null) {
|
||||
String databaseChangeLogTableName = getDatabase().escapeTableName(getLiquibaseCatalogName(), getLiquibaseSchemaName(), getDatabaseChangeLogTableName());
|
||||
List<RanChangeSet> ranChangeSetList = new ArrayList<>();
|
||||
if (hasDatabaseChangeLogTable()) {
|
||||
LogFactory.getLogger().info("Reading from " + databaseChangeLogTableName);
|
||||
List<Map<String, ?>> results = queryDatabaseChangeLogTable(getDatabase());
|
||||
for (Map rs : results) {
|
||||
String fileName = rs.get("FILENAME").toString();
|
||||
String author = rs.get("AUTHOR").toString();
|
||||
String id = rs.get("ID").toString();
|
||||
String md5sum = rs.get("MD5SUM") == null || getDatabaseChecksumsCompatible() ? null : rs.get("MD5SUM").toString();
|
||||
String description = rs.get("DESCRIPTION") == null ? null : rs.get("DESCRIPTION").toString();
|
||||
String comments = rs.get("COMMENTS") == null ? null : rs.get("COMMENTS").toString();
|
||||
Object tmpDateExecuted = rs.get("DATEEXECUTED");
|
||||
Date dateExecuted = null;
|
||||
if (tmpDateExecuted instanceof Date) {
|
||||
dateExecuted = (Date) tmpDateExecuted;
|
||||
} else if (tmpDateExecuted instanceof LocalDateTime) {
|
||||
dateExecuted = Date.from(((LocalDateTime) tmpDateExecuted).atZone(ZoneId.systemDefault()).toInstant());
|
||||
} else {
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
try {
|
||||
dateExecuted = df.parse((String) tmpDateExecuted);
|
||||
} catch (ParseException e) {
|
||||
}
|
||||
}
|
||||
String tmpOrderExecuted = rs.get("ORDEREXECUTED").toString();
|
||||
Integer orderExecuted = (tmpOrderExecuted == null ? null : Integer.valueOf(tmpOrderExecuted));
|
||||
String tag = rs.get("TAG") == null ? null : rs.get("TAG").toString();
|
||||
String execType = rs.get("EXECTYPE") == null ? null : rs.get("EXECTYPE").toString();
|
||||
ContextExpression contexts = new ContextExpression((String) rs.get("CONTEXTS"));
|
||||
Labels labels = new Labels((String) rs.get("LABELS"));
|
||||
String deploymentId = (String) rs.get("DEPLOYMENT_ID");
|
||||
|
||||
try {
|
||||
RanChangeSet ranChangeSet = new RanChangeSet(fileName, id, author, CheckSum.parse(md5sum), dateExecuted, tag, ChangeSet.ExecType.valueOf(execType), description, comments, contexts, labels, deploymentId);
|
||||
ranChangeSet.setOrderExecuted(orderExecuted);
|
||||
ranChangeSetList.add(ranChangeSet);
|
||||
} catch (IllegalArgumentException e) {
|
||||
LogFactory.getLogger().severe("Unknown EXECTYPE from database: " + execType);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.ranChangeSetList = ranChangeSetList;
|
||||
}
|
||||
return Collections.unmodifiableList(ranChangeSetList);
|
||||
}
|
||||
|
||||
private boolean getDatabaseChecksumsCompatible() {
|
||||
Field f = Reflections.findDeclaredField(StandardChangeLogHistoryService.class, "databaseChecksumsCompatible");
|
||||
if (f != null) {
|
||||
f.setAccessible(true);
|
||||
Boolean databaseChecksumsCompatible = Reflections.getFieldValue(f, this, Boolean.class);
|
||||
return databaseChecksumsCompatible == null ? true : databaseChecksumsCompatible;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return super.getPriority() + 1; // Ensure bigger priority than StandardChangeLogHistoryService
|
||||
|
||||
Reference in New Issue
Block a user