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