Add equals and hashcode to tasks for flyway

This commit is contained in:
Ken Stevens 2019-10-29 13:34:11 -04:00
parent dd2cb39fd1
commit 94c8f96856
13 changed files with 263 additions and 2 deletions

View File

@ -37,8 +37,7 @@ public class FlywayMigration implements JavaMigration {
@Override
public Integer getChecksum() {
// FIXME KHS
return 0;
return myTask.hashCode();
}
@Override

View File

@ -22,6 +22,8 @@ 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;
@ -101,4 +103,29 @@ 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();
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.appendSuper(super.hashCode())
.append(myConstraintName)
.append(myForeignTableName)
.append(myForeignColumnName)
.toHashCode();
}
}

View File

@ -22,6 +22,8 @@ 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;
import org.thymeleaf.util.StringUtils;
@ -92,4 +94,30 @@ public class AddIndexTask extends BaseTableTask<AddIndexTask> {
public void setColumns(String... theColumns) {
setColumns(Arrays.asList(theColumns));
}
@Override
public boolean equals(Object theO) {
if (this == theO) return true;
if (theO == null || getClass() != theO.getClass()) return false;
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();
}
}

View File

@ -22,6 +22,8 @@ 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;
@ -95,4 +97,28 @@ public class AddTableByColumnTask extends BaseTableTask<AddTableByColumnTask> {
executeSql(getTableName(), sb.toString());
}
@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(myPkColumn, that.myPkColumn)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.appendSuper(super.hashCode())
.append(myAddColumnTasks)
.append(myPkColumn)
.toHashCode();
}
}

View File

@ -23,6 +23,8 @@ package ca.uhn.fhir.jpa.migrate.taskdef;
import ca.uhn.fhir.jpa.migrate.DriverTypeEnum;
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.intellij.lang.annotations.Language;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -77,4 +79,28 @@ public class AddTableRawSqlTask extends BaseTableTask<AddTableRawSqlTask> {
Validate.notBlank("theSql must not be null", theSql);
myDriverNeutralSqls.add(theSql);
}
@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(myDriverToSqls, that.myDriverToSqls)
.append(myDriverNeutralSqls, that.myDriverNeutralSqls)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.appendSuper(super.hashCode())
.append(myDriverToSqls)
.append(myDriverNeutralSqls)
.toHashCode();
}
}

View File

@ -21,6 +21,8 @@ package ca.uhn.fhir.jpa.migrate.taskdef;
*/
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.thymeleaf.util.StringUtils;
import java.util.Locale;
@ -50,5 +52,25 @@ public abstract class BaseTableColumnTask<T extends BaseTableTask> extends BaseT
Validate.notBlank(myColumnName, "Column name not specified");
}
@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();
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.appendSuper(super.hashCode())
.append(myColumnName)
.toHashCode();
}
}

View File

@ -22,6 +22,8 @@ package ca.uhn.fhir.jpa.migrate.taskdef;
import ca.uhn.fhir.jpa.migrate.DriverTypeEnum;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.springframework.util.Assert;
import java.util.HashMap;
@ -186,4 +188,31 @@ public abstract class BaseTableColumnTypeTask<T extends BaseTableTask> extends B
}
@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(myColumnType, that.myColumnType)
.append(myColumnTypeToDriverTypeToSqlType, that.myColumnTypeToDriverTypeToSqlType)
.append(myNullable, that.myNullable)
.append(myColumnLength, that.myColumnLength)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.appendSuper(super.hashCode())
.append(myColumnType)
.append(myColumnTypeToDriverTypeToSqlType)
.append(myNullable)
.append(myColumnLength)
.toHashCode();
}
}

View File

@ -21,6 +21,8 @@ package ca.uhn.fhir.jpa.migrate.taskdef;
*/
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 {
private String myTableName;
@ -43,4 +45,24 @@ public abstract class BaseTableTask<T extends BaseTableTask> extends BaseTask {
public void validate() {
Validate.notBlank(myTableName);
}
@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();
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(myTableName)
.toHashCode();
}
}

View File

@ -169,4 +169,6 @@ public abstract class BaseTask<T extends BaseTask> {
return myArguments;
}
}
}

View File

@ -56,4 +56,5 @@ public class DropColumnTask extends BaseTableColumnTask<DropColumnTask> {
return "alter table " + theTableName + " drop column " + theColumnName;
}
}

View File

@ -23,6 +23,8 @@ package ca.uhn.fhir.jpa.migrate.taskdef;
import ca.uhn.fhir.jpa.migrate.DriverTypeEnum;
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;
@ -100,4 +102,27 @@ 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();
}
}

View File

@ -23,6 +23,8 @@ package ca.uhn.fhir.jpa.migrate.taskdef;
import ca.uhn.fhir.jpa.migrate.DriverTypeEnum;
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;
@ -124,4 +126,26 @@ public class DropIndexTask extends BaseTableTask<DropIndexTask> {
}
return Optional.of(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();
}
}

View File

@ -22,6 +22,8 @@ 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;
import org.springframework.jdbc.core.ColumnMapRowMapper;
@ -127,4 +129,32 @@ public class RenameColumnTask extends BaseTableTask<RenameColumnTask> {
public void setAllowNeitherColumnToExist(boolean theAllowNeitherColumnToExist) {
myAllowNeitherColumnToExist = theAllowNeitherColumnToExist;
}
@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(myAllowNeitherColumnToExist, that.myAllowNeitherColumnToExist)
.append(myDeleteTargetColumnFirstIfBothExist, that.myDeleteTargetColumnFirstIfBothExist)
.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)
.append(myAllowNeitherColumnToExist)
.append(myDeleteTargetColumnFirstIfBothExist)
.toHashCode();
}
}