Rework hashcode generation (#1684)
* Rework hashcode generation * Compile fix * Hashcoode refactoring * FIx compile errors
This commit is contained in:
parent
ba0048aade
commit
3edeb03edc
|
@ -74,7 +74,7 @@ public class AddForeignKeyTask extends BaseTableColumnTask<AddForeignKeyTask> {
|
|||
return;
|
||||
}
|
||||
|
||||
String sql = null;
|
||||
String sql;
|
||||
switch (getDriverType()) {
|
||||
case MARIADB_10_1:
|
||||
case MYSQL_5_7:
|
||||
|
@ -105,28 +105,20 @@ public class AddForeignKeyTask extends BaseTableColumnTask<AddForeignKeyTask> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object theO) {
|
||||
if (this == theO) return true;
|
||||
|
||||
if (theO == null || getClass() != theO.getClass()) return false;
|
||||
|
||||
AddForeignKeyTask that = (AddForeignKeyTask) theO;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.appendSuper(super.equals(theO))
|
||||
.append(myConstraintName, that.myConstraintName)
|
||||
.append(myForeignTableName, that.myForeignTableName)
|
||||
.append(myForeignColumnName, that.myForeignColumnName)
|
||||
.isEquals();
|
||||
protected void generateHashCode(HashCodeBuilder theBuilder) {
|
||||
super.generateHashCode(theBuilder);
|
||||
theBuilder.append(myConstraintName);
|
||||
theBuilder.append(myForeignTableName);
|
||||
theBuilder.append(myForeignColumnName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.appendSuper(super.hashCode())
|
||||
.append(myConstraintName)
|
||||
.append(myForeignTableName)
|
||||
.append(myForeignColumnName)
|
||||
.toHashCode();
|
||||
protected void generateEquals(EqualsBuilder theBuilder, BaseTask theOtherObject) {
|
||||
AddForeignKeyTask otherObject = (AddForeignKeyTask) theOtherObject;
|
||||
super.generateEquals(theBuilder, otherObject);
|
||||
theBuilder.append(myConstraintName, otherObject.myConstraintName);
|
||||
theBuilder.append(myForeignTableName, otherObject.myForeignTableName);
|
||||
theBuilder.append(myForeignColumnName, otherObject.myForeignColumnName);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -103,22 +103,13 @@ public class AddIdGeneratorTask extends BaseTask<AddIdGeneratorTask> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object theO) {
|
||||
if (this == theO) return true;
|
||||
|
||||
if (!(theO instanceof AddIdGeneratorTask)) return false;
|
||||
|
||||
AddIdGeneratorTask that = (AddIdGeneratorTask) theO;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.append(myGeneratorName, that.myGeneratorName)
|
||||
.isEquals();
|
||||
protected void generateEquals(EqualsBuilder theBuilder, BaseTask<AddIdGeneratorTask> theOtherObject) {
|
||||
AddIdGeneratorTask otherObject = (AddIdGeneratorTask) theOtherObject;
|
||||
theBuilder.append(myGeneratorName, otherObject.myGeneratorName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(myGeneratorName)
|
||||
.toHashCode();
|
||||
protected void generateHashCode(HashCodeBuilder theBuilder) {
|
||||
theBuilder.append(myGeneratorName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,28 +97,21 @@ public class AddIndexTask extends BaseTableTask<AddIndexTask> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object theO) {
|
||||
if (this == theO) return true;
|
||||
protected void generateEquals(EqualsBuilder theBuilder, BaseTask<AddIndexTask> theOtherObject) {
|
||||
super.generateEquals(theBuilder, theOtherObject);
|
||||
|
||||
if (theO == null || getClass() != theO.getClass()) return false;
|
||||
AddIndexTask otherObject = (AddIndexTask) theOtherObject;
|
||||
theBuilder.append(myIndexName, otherObject.myIndexName);
|
||||
theBuilder.append(myColumns, otherObject.myColumns);
|
||||
theBuilder.append(myUnique, otherObject.myUnique);
|
||||
|
||||
AddIndexTask that = (AddIndexTask) theO;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.appendSuper(super.equals(theO))
|
||||
.append(myIndexName, that.myIndexName)
|
||||
.append(myColumns, that.myColumns)
|
||||
.append(myUnique, that.myUnique)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.appendSuper(super.hashCode())
|
||||
.append(myIndexName)
|
||||
.append(myColumns)
|
||||
.append(myUnique)
|
||||
.toHashCode();
|
||||
protected void generateHashCode(HashCodeBuilder theBuilder) {
|
||||
super.generateHashCode(theBuilder);
|
||||
theBuilder.append(myIndexName);
|
||||
theBuilder.append(myColumns);
|
||||
theBuilder.append(myUnique);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,26 +110,17 @@ public class AddTableByColumnTask extends BaseTableTask<AddTableByColumnTask> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object theO) {
|
||||
if (this == theO) return true;
|
||||
|
||||
if (theO == null || getClass() != theO.getClass()) return false;
|
||||
|
||||
AddTableByColumnTask that = (AddTableByColumnTask) theO;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.appendSuper(super.equals(theO))
|
||||
.append(myAddColumnTasks, that.myAddColumnTasks)
|
||||
.append(myPkColumns, that.myPkColumns)
|
||||
.isEquals();
|
||||
protected void generateEquals(EqualsBuilder theBuilder, BaseTask<AddTableByColumnTask> theOtherObject) {
|
||||
super.generateEquals(theBuilder, theOtherObject);
|
||||
AddTableByColumnTask otherObject = (AddTableByColumnTask) theOtherObject;
|
||||
theBuilder.append(myAddColumnTasks, otherObject.myAddColumnTasks);
|
||||
theBuilder.append(myPkColumns, otherObject.myPkColumns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.appendSuper(super.hashCode())
|
||||
.append(myAddColumnTasks)
|
||||
.append(myPkColumns)
|
||||
.toHashCode();
|
||||
protected void generateHashCode(HashCodeBuilder theBuilder) {
|
||||
super.generateHashCode(theBuilder);
|
||||
theBuilder.append(myAddColumnTasks);
|
||||
theBuilder.append(myPkColumns);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,11 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class AddTableRawSqlTask extends BaseTableTask<AddTableRawSqlTask> {
|
||||
|
||||
|
@ -87,24 +91,15 @@ public class AddTableRawSqlTask extends BaseTableTask<AddTableRawSqlTask> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object theO) {
|
||||
if (this == theO) return true;
|
||||
|
||||
if (theO == null || getClass() != theO.getClass()) return false;
|
||||
|
||||
AddTableRawSqlTask that = (AddTableRawSqlTask) theO;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.appendSuper(super.equals(theO))
|
||||
.append(myDriverNeutralSqls, that.myDriverNeutralSqls)
|
||||
.isEquals();
|
||||
protected void generateEquals(EqualsBuilder theBuilder, BaseTask<AddTableRawSqlTask> theOtherObject) {
|
||||
super.generateEquals(theBuilder, theOtherObject);
|
||||
AddTableRawSqlTask otherObject = (AddTableRawSqlTask) theOtherObject;
|
||||
theBuilder.append(myDriverNeutralSqls, otherObject.myDriverNeutralSqls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.appendSuper(super.hashCode())
|
||||
.append(myDriverNeutralSqls)
|
||||
.toHashCode();
|
||||
protected void generateHashCode(HashCodeBuilder theBuilder) {
|
||||
super.generateHashCode(theBuilder);
|
||||
theBuilder.append(myDriverNeutralSqls);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,6 +103,17 @@ public class ArbitrarySqlTask extends BaseTask<ArbitrarySqlTask> {
|
|||
myConditionalOnExistenceOf.add(new TableAndColumn(theTableName, theColumnName));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateEquals(EqualsBuilder theBuilder, BaseTask<ArbitrarySqlTask> theOtherObject) {
|
||||
ArbitrarySqlTask otherObject = (ArbitrarySqlTask) theOtherObject;
|
||||
theBuilder.append(myTableName, otherObject.myTableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateHashCode(HashCodeBuilder theBuilder) {
|
||||
theBuilder.append(myTableName);
|
||||
}
|
||||
|
||||
public enum QueryModeEnum {
|
||||
BATCH_UNTIL_NO_MORE
|
||||
}
|
||||
|
@ -134,7 +145,7 @@ public class ArbitrarySqlTask extends BaseTask<ArbitrarySqlTask> {
|
|||
do {
|
||||
logInfo(ourLog, "Querying for up to {} rows", myBatchSize);
|
||||
rows = getTxTemplate().execute(t -> {
|
||||
JdbcTemplate jdbcTemplate = newJdbcTemnplate();
|
||||
JdbcTemplate jdbcTemplate = newJdbcTemplate();
|
||||
jdbcTemplate.setMaxRows(myBatchSize);
|
||||
return jdbcTemplate.query(mySql, new ColumnMapRowMapper());
|
||||
});
|
||||
|
@ -168,25 +179,4 @@ public class ArbitrarySqlTask extends BaseTask<ArbitrarySqlTask> {
|
|||
return myColumn;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object theO) {
|
||||
if (this == theO) return true;
|
||||
|
||||
if (!(theO instanceof ArbitrarySqlTask)) return false;
|
||||
|
||||
ArbitrarySqlTask that = (ArbitrarySqlTask) theO;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.append(myTableName, that.myTableName)
|
||||
.append(myExecuteOnlyIfTableExists, that.myExecuteOnlyIfTableExists)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(myTableName)
|
||||
.toHashCode();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.thymeleaf.util.StringUtils;
|
|||
|
||||
import java.util.Locale;
|
||||
|
||||
public abstract class BaseTableColumnTask<T extends BaseTableTask> extends BaseTableTask<T> {
|
||||
public abstract class BaseTableColumnTask<T extends BaseTableTask<T>> extends BaseTableTask<T> {
|
||||
|
||||
private String myColumnName;
|
||||
|
||||
|
@ -53,24 +53,15 @@ public abstract class BaseTableColumnTask<T extends BaseTableTask> extends BaseT
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object theO) {
|
||||
if (this == theO) return true;
|
||||
|
||||
if (!(theO instanceof BaseTableColumnTask)) return false;
|
||||
|
||||
BaseTableColumnTask<?> that = (BaseTableColumnTask<?>) theO;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.appendSuper(super.equals(theO))
|
||||
.append(myColumnName, that.myColumnName)
|
||||
.isEquals();
|
||||
protected void generateEquals(EqualsBuilder theBuilder, BaseTask<T> theOtherObject) {
|
||||
BaseTableColumnTask<T> otherObject = (BaseTableColumnTask<T>) theOtherObject;
|
||||
super.generateEquals(theBuilder, otherObject);
|
||||
theBuilder.append(myColumnName, otherObject.myColumnName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.appendSuper(super.hashCode())
|
||||
.append(myColumnName)
|
||||
.toHashCode();
|
||||
protected void generateHashCode(HashCodeBuilder theBuilder) {
|
||||
super.generateHashCode(theBuilder);
|
||||
theBuilder.append(myColumnName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,17 +25,12 @@ import org.apache.commons.lang3.Validate;
|
|||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class BaseTableColumnTypeTask<T extends BaseTableTask> extends BaseTableColumnTask<T> {
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(BaseTableColumnTypeTask.class);
|
||||
|
||||
|
||||
public abstract class BaseTableColumnTypeTask<T extends BaseTableColumnTypeTask<T>> extends BaseTableColumnTask<T> {
|
||||
private ColumnTypeEnum myColumnType;
|
||||
private Map<ColumnTypeEnum, Map<DriverTypeEnum, String>> myColumnTypeToDriverTypeToSqlType = new HashMap<>();
|
||||
private Boolean myNullable;
|
||||
|
@ -116,6 +111,12 @@ public abstract class BaseTableColumnTypeTask<T extends BaseTableTask> extends B
|
|||
return myColumnType;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T setColumnType(ColumnTypeEnum theColumnType) {
|
||||
myColumnType = theColumnType;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
private void setColumnType(ColumnTypeEnum theColumnType, DriverTypeEnum theDriverType, String theColumnTypeSql) {
|
||||
Map<DriverTypeEnum, String> columnSqlType = myColumnTypeToDriverTypeToSqlType.computeIfAbsent(theColumnType, k -> new HashMap<>());
|
||||
if (columnSqlType.containsKey(theDriverType)) {
|
||||
|
@ -124,7 +125,6 @@ public abstract class BaseTableColumnTypeTask<T extends BaseTableTask> extends B
|
|||
columnSqlType.put(theDriverType, theColumnTypeSql);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
super.validate();
|
||||
|
@ -138,12 +138,6 @@ public abstract class BaseTableColumnTypeTask<T extends BaseTableTask> extends B
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T setColumnType(ColumnTypeEnum theColumnType) {
|
||||
myColumnType = theColumnType;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
protected String getSqlType() {
|
||||
return getSqlType(getColumnLength());
|
||||
}
|
||||
|
@ -181,6 +175,30 @@ public abstract class BaseTableColumnTypeTask<T extends BaseTableTask> extends B
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateHashCode(HashCodeBuilder theBuilder) {
|
||||
super.generateHashCode(theBuilder);
|
||||
theBuilder.append(getColumnTypeName(myColumnType));
|
||||
theBuilder.append(myNullable);
|
||||
theBuilder.append(myColumnLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateEquals(EqualsBuilder theBuilder, BaseTask<T> theOtherObject) {
|
||||
BaseTableColumnTypeTask otherObject = (BaseTableColumnTypeTask) theOtherObject;
|
||||
super.generateEquals(theBuilder, otherObject);
|
||||
theBuilder.append(getColumnTypeName(myColumnType), getColumnTypeName(otherObject.myColumnType));
|
||||
theBuilder.append(myNullable, otherObject.myNullable);
|
||||
theBuilder.append(myColumnLength, otherObject.myColumnLength);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Object getColumnTypeName(ColumnTypeEnum theColumnType) {
|
||||
if (theColumnType == null) {
|
||||
return null;
|
||||
}
|
||||
return myColumnType.name();
|
||||
}
|
||||
|
||||
public enum ColumnTypeEnum {
|
||||
|
||||
|
@ -191,42 +209,7 @@ public abstract class BaseTableColumnTypeTask<T extends BaseTableTask> extends B
|
|||
FLOAT,
|
||||
INT,
|
||||
BLOB,
|
||||
CLOB
|
||||
;
|
||||
CLOB;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object theO) {
|
||||
if (this == theO) return true;
|
||||
|
||||
if (!(theO instanceof BaseTableColumnTypeTask)) return false;
|
||||
|
||||
BaseTableColumnTypeTask<?> that = (BaseTableColumnTypeTask<?>) theO;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.appendSuper(super.equals(theO))
|
||||
.append(getColumnTypeName(myColumnType), getColumnTypeName(that.myColumnType))
|
||||
.append(myNullable, that.myNullable)
|
||||
.append(myColumnLength, that.myColumnLength)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.appendSuper(super.hashCode())
|
||||
.append(getColumnTypeName(myColumnType))
|
||||
.append(myNullable)
|
||||
.append(myColumnLength)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Object getColumnTypeName(ColumnTypeEnum theColumnType) {
|
||||
if (theColumnType == null) {
|
||||
return null;
|
||||
}
|
||||
return myColumnType.name();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.apache.commons.lang3.Validate;
|
|||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
|
||||
public abstract class BaseTableTask<T extends BaseTableTask> extends BaseTask {
|
||||
public abstract class BaseTableTask<T extends BaseTableTask<T>> extends BaseTask<T> {
|
||||
private String myTableName;
|
||||
|
||||
public BaseTableTask(String theProductVersion, String theSchemaVersion) {
|
||||
|
@ -38,6 +38,7 @@ public abstract class BaseTableTask<T extends BaseTableTask> extends BaseTask {
|
|||
public T setTableName(String theTableName) {
|
||||
Validate.notBlank(theTableName);
|
||||
myTableName = theTableName;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
|
@ -47,22 +48,13 @@ public abstract class BaseTableTask<T extends BaseTableTask> extends BaseTask {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object theO) {
|
||||
if (this == theO) return true;
|
||||
|
||||
if (!(theO instanceof BaseTableTask)) return false;
|
||||
|
||||
BaseTableTask<?> that = (BaseTableTask<?>) theO;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.append(myTableName, that.myTableName)
|
||||
.isEquals();
|
||||
protected void generateEquals(EqualsBuilder theBuilder, BaseTask<T> theOtherObject) {
|
||||
BaseTableTask<T> otherObject = (BaseTableTask<T>) theOtherObject;
|
||||
theBuilder.append(myTableName, otherObject.myTableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(myTableName)
|
||||
.toHashCode();
|
||||
protected void generateHashCode(HashCodeBuilder theBuilder) {
|
||||
theBuilder.append(myTableName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ package ca.uhn.fhir.jpa.migrate.taskdef;
|
|||
*/
|
||||
|
||||
import ca.uhn.fhir.jpa.migrate.DriverTypeEnum;
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -38,9 +40,11 @@ import java.util.regex.Pattern;
|
|||
|
||||
public abstract class BaseTask<T extends BaseTask> {
|
||||
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(BaseTask.class);
|
||||
public static final String MIGRATION_VERSION_PATTERN = "\\d{8}\\.\\d+";
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(BaseTask.class);
|
||||
private static final Pattern versionPattern = Pattern.compile(MIGRATION_VERSION_PATTERN);
|
||||
private final String myProductVersion;
|
||||
private final String mySchemaVersion;
|
||||
private DriverTypeEnum.ConnectionProperties myConnectionProperties;
|
||||
private DriverTypeEnum myDriverType;
|
||||
private String myDescription;
|
||||
|
@ -50,8 +54,6 @@ public abstract class BaseTask<T extends BaseTask> {
|
|||
private List<ExecutedStatement> myExecutedStatements = new ArrayList<>();
|
||||
private boolean myNoColumnShrink;
|
||||
private boolean myFailureAllowed;
|
||||
private final String myProductVersion;
|
||||
private final String mySchemaVersion;
|
||||
|
||||
protected BaseTask(String theProductVersion, String theSchemaVersion) {
|
||||
myProductVersion = theProductVersion;
|
||||
|
@ -151,7 +153,7 @@ public abstract class BaseTask<T extends BaseTask> {
|
|||
return getConnectionProperties().getTxTemplate();
|
||||
}
|
||||
|
||||
public JdbcTemplate newJdbcTemnplate() {
|
||||
public JdbcTemplate newJdbcTemplate() {
|
||||
return getConnectionProperties().newJdbcTemplate();
|
||||
}
|
||||
|
||||
|
@ -197,6 +199,30 @@ public abstract class BaseTask<T extends BaseTask> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
HashCodeBuilder builder = new HashCodeBuilder();
|
||||
generateHashCode(builder);
|
||||
return builder.hashCode();
|
||||
}
|
||||
|
||||
protected abstract void generateHashCode(HashCodeBuilder theBuilder);
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object theObject) {
|
||||
if (theObject == null || getClass().equals(theObject.getClass()) == false) {
|
||||
return false;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
T otherObject = (T) theObject;
|
||||
|
||||
EqualsBuilder b = new EqualsBuilder();
|
||||
generateEquals(b, otherObject);
|
||||
return b.isEquals();
|
||||
}
|
||||
|
||||
protected abstract void generateEquals(EqualsBuilder theBuilder, BaseTask<T> theOtherObject);
|
||||
|
||||
public static class ExecutedStatement {
|
||||
private final String mySql;
|
||||
private final List<Object> myArguments;
|
||||
|
|
|
@ -77,7 +77,7 @@ public class CalculateHashesTask extends BaseTableColumnTask<CalculateHashesTask
|
|||
while(true) {
|
||||
MyRowCallbackHandler rch = new MyRowCallbackHandler();
|
||||
getTxTemplate().execute(t -> {
|
||||
JdbcTemplate jdbcTemplate = newJdbcTemnplate();
|
||||
JdbcTemplate jdbcTemplate = newJdbcTemplate();
|
||||
jdbcTemplate.setMaxRows(100000);
|
||||
String sql = "SELECT * FROM " + getTableName() + " WHERE " + getColumnName() + " IS NULL";
|
||||
logInfo(ourLog, "Finding up to {} rows in {} that requires hashes", myBatchSize, getTableName());
|
||||
|
@ -184,7 +184,7 @@ public class CalculateHashesTask extends BaseTableColumnTask<CalculateHashesTask
|
|||
arguments.add((Number) nextRow.get("SP_ID"));
|
||||
|
||||
// Apply update SQL
|
||||
newJdbcTemnplate().update(sqlBuilder.toString(), arguments.toArray());
|
||||
newJdbcTemplate().update(sqlBuilder.toString(), arguments.toArray());
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -81,6 +81,21 @@ public class DropForeignKeyTask extends BaseTableTask<DropForeignKeyTask> {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateEquals(EqualsBuilder theBuilder, BaseTask theOtherObject) {
|
||||
DropForeignKeyTask otherObject = (DropForeignKeyTask) theOtherObject;
|
||||
super.generateEquals(theBuilder, otherObject);
|
||||
theBuilder.append(myConstraintName, otherObject.myConstraintName);
|
||||
theBuilder.append(myParentTableName, otherObject.myParentTableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateHashCode(HashCodeBuilder theBuilder) {
|
||||
super.generateHashCode(theBuilder);
|
||||
theBuilder.append(myConstraintName);
|
||||
theBuilder.append(myParentTableName);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
static List<String> generateSql(String theTableName, String theConstraintName, DriverTypeEnum theDriverType) {
|
||||
List<String> sqls = new ArrayList<>();
|
||||
|
@ -103,28 +118,4 @@ public class DropForeignKeyTask extends BaseTableTask<DropForeignKeyTask> {
|
|||
}
|
||||
return sqls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object theO) {
|
||||
if (this == theO) return true;
|
||||
|
||||
if (theO == null || getClass() != theO.getClass()) return false;
|
||||
|
||||
DropForeignKeyTask that = (DropForeignKeyTask) theO;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.appendSuper(super.equals(theO))
|
||||
.append(myConstraintName, that.myConstraintName)
|
||||
.append(myParentTableName, that.myParentTableName)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.appendSuper(super.hashCode())
|
||||
.append(myConstraintName)
|
||||
.append(myParentTableName)
|
||||
.toHashCode();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,22 +103,13 @@ public class DropIdGeneratorTask extends BaseTask<DropIdGeneratorTask> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object theO) {
|
||||
if (this == theO) return true;
|
||||
|
||||
if (!(theO instanceof DropIdGeneratorTask)) return false;
|
||||
|
||||
DropIdGeneratorTask that = (DropIdGeneratorTask) theO;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.append(myGeneratorName, that.myGeneratorName)
|
||||
.isEquals();
|
||||
protected void generateEquals(EqualsBuilder theBuilder, BaseTask<DropIdGeneratorTask> theOtherObject) {
|
||||
DropIdGeneratorTask otherObject = (DropIdGeneratorTask) theOtherObject;
|
||||
theBuilder.append(myGeneratorName, otherObject.myGeneratorName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(myGeneratorName)
|
||||
.toHashCode();
|
||||
protected void generateHashCode(HashCodeBuilder theBuilder) {
|
||||
theBuilder.append(myGeneratorName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,6 +78,19 @@ public class DropIndexTask extends BaseTableTask<DropIndexTask> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateEquals(EqualsBuilder theBuilder, BaseTask theOtherObject) {
|
||||
DropIndexTask otherObject = (DropIndexTask) theOtherObject;
|
||||
super.generateEquals(theBuilder, otherObject);
|
||||
theBuilder.append(myIndexName, otherObject.myIndexName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateHashCode(HashCodeBuilder theBuilder) {
|
||||
super.generateHashCode(theBuilder);
|
||||
theBuilder.append(myIndexName);
|
||||
}
|
||||
|
||||
static List<String> createDropIndexSql(DriverTypeEnum.ConnectionProperties theConnectionProperties, String theTableName, String theIndexName, DriverTypeEnum theDriverType) throws SQLException {
|
||||
Validate.notBlank(theIndexName, "theIndexName must not be blank");
|
||||
Validate.notBlank(theTableName, "theTableName must not be blank");
|
||||
|
@ -130,26 +143,4 @@ public class DropIndexTask extends BaseTableTask<DropIndexTask> {
|
|||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object theO) {
|
||||
if (this == theO) return true;
|
||||
|
||||
if (theO == null || getClass() != theO.getClass()) return false;
|
||||
|
||||
DropIndexTask that = (DropIndexTask) theO;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.appendSuper(super.equals(theO))
|
||||
.append(myIndexName, that.myIndexName)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.appendSuper(super.hashCode())
|
||||
.append(myIndexName)
|
||||
.toHashCode();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,22 +80,15 @@ public class ExecuteRawSqlTask extends BaseTask<ExecuteRawSqlTask> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object theO) {
|
||||
if (this == theO) return true;
|
||||
|
||||
if (!(theO instanceof ExecuteRawSqlTask)) return false;
|
||||
|
||||
ExecuteRawSqlTask that = (ExecuteRawSqlTask) theO;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.append(myDriverNeutralSqls, that.myDriverNeutralSqls)
|
||||
.isEquals();
|
||||
protected void generateEquals(EqualsBuilder theBuilder, BaseTask<ExecuteRawSqlTask> theOtherObject) {
|
||||
ExecuteRawSqlTask otherObject = (ExecuteRawSqlTask) theOtherObject;
|
||||
theBuilder.append(myDriverNeutralSqls, otherObject.myDriverNeutralSqls);
|
||||
theBuilder.append(myDriverToSqls, otherObject.myDriverToSqls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(myDriverNeutralSqls)
|
||||
.toHashCode();
|
||||
protected void generateHashCode(HashCodeBuilder theBuilder) {
|
||||
theBuilder.append(myDriverNeutralSqls);
|
||||
theBuilder.append(myDriverToSqls);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,22 +68,13 @@ public class InitializeSchemaTask extends BaseTask<InitializeSchemaTask> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object theO) {
|
||||
if (this == theO) return true;
|
||||
|
||||
if (theO == null || getClass() != theO.getClass()) return false;
|
||||
|
||||
InitializeSchemaTask that = (InitializeSchemaTask) theO;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.append(mySchemaInitializationProvider, that.mySchemaInitializationProvider)
|
||||
.isEquals();
|
||||
protected void generateEquals(EqualsBuilder theBuilder, BaseTask<InitializeSchemaTask> theOtherObject) {
|
||||
InitializeSchemaTask otherObject = (InitializeSchemaTask) theOtherObject;
|
||||
theBuilder.append(mySchemaInitializationProvider, otherObject.mySchemaInitializationProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(mySchemaInitializationProvider)
|
||||
.toHashCode();
|
||||
protected void generateHashCode(HashCodeBuilder theBuilder) {
|
||||
theBuilder.append(mySchemaInitializationProvider);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ package ca.uhn.fhir.jpa.migrate.taskdef;
|
|||
|
||||
import ca.uhn.fhir.jpa.migrate.JdbcUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -137,26 +136,9 @@ public class RenameColumnTask extends BaseTableTask<RenameColumnTask> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object theO) {
|
||||
if (this == theO) return true;
|
||||
|
||||
if (theO == null || getClass() != theO.getClass()) return false;
|
||||
|
||||
RenameColumnTask that = (RenameColumnTask) theO;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.appendSuper(super.equals(theO))
|
||||
.append(myOldName, that.myOldName)
|
||||
.append(myNewName, that.myNewName)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.appendSuper(super.hashCode())
|
||||
.append(myOldName)
|
||||
.append(myNewName)
|
||||
.toHashCode();
|
||||
protected void generateHashCode(HashCodeBuilder theBuilder) {
|
||||
super.generateHashCode(theBuilder);
|
||||
theBuilder.append(myOldName);
|
||||
theBuilder.append(myNewName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,6 +81,21 @@ public class RenameIndexTask extends BaseTableTask<RenameIndexTask> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateEquals(EqualsBuilder theBuilder, BaseTask theOtherObject) {
|
||||
RenameIndexTask otherObject = (RenameIndexTask) theOtherObject;
|
||||
super.generateEquals(theBuilder, otherObject);
|
||||
theBuilder.append(myOldIndexName, otherObject.myOldIndexName);
|
||||
theBuilder.append(myNewIndexName, otherObject.myNewIndexName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateHashCode(HashCodeBuilder theBuilder) {
|
||||
super.generateHashCode(theBuilder);
|
||||
theBuilder.append(myOldIndexName);
|
||||
theBuilder.append(myNewIndexName);
|
||||
}
|
||||
|
||||
static List<String> createRenameIndexSql(DriverTypeEnum.ConnectionProperties theConnectionProperties, String theTableName, String theOldIndexName, String theNewIndexName, DriverTypeEnum theDriverType) throws SQLException {
|
||||
Validate.notBlank(theOldIndexName, "theOldIndexName must not be blank");
|
||||
Validate.notBlank(theNewIndexName, "theNewIndexName must not be blank");
|
||||
|
@ -110,28 +125,4 @@ public class RenameIndexTask extends BaseTableTask<RenameIndexTask> {
|
|||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object theO) {
|
||||
if (this == theO) return true;
|
||||
|
||||
if (theO == null || getClass() != theO.getClass()) return false;
|
||||
|
||||
RenameIndexTask that = (RenameIndexTask) theO;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.appendSuper(super.equals(theO))
|
||||
.append(myOldIndexName, that.myOldIndexName)
|
||||
.append(myNewIndexName, that.myNewIndexName)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.appendSuper(super.hashCode())
|
||||
.append(myOldIndexName)
|
||||
.append(myNewIndexName)
|
||||
.toHashCode();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue