Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactored data clumps #5802

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import liquibase.exception.Warnings;
import liquibase.executor.ExecutorService;
import liquibase.precondition.AbstractPrecondition;
import liquibase.statement.core.DatabaseTableIdentifier;
import liquibase.statement.core.TableIsEmptyStatement;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -28,7 +29,8 @@ public class TableIsEmptyPrecondition extends AbstractPrecondition {
@Override
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet, ChangeExecListener changeExecListener) throws PreconditionFailedException, PreconditionErrorException {
try {
TableIsEmptyStatement statement = new TableIsEmptyStatement(getCatalogName(), getSchemaName(), getTableName());
TableIsEmptyStatement statement =
new TableIsEmptyStatement( new DatabaseTableIdentifier(getCatalogName(), getSchemaName(), getTableName()));

int result = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database).queryForInt(statement);
if (result > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
@Getter
public class AddAutoIncrementStatement extends AbstractSqlStatement {

private final String catalogName;
private final String schemaName;
private final String tableName;
private final String columnName;
private final String columnDataType;
private final BigInteger startWith;
private final BigInteger incrementBy;
private final Boolean defaultOnNull;
private final String generationType;
private DatabaseTableIdentifier databaseTableIdentifier = new DatabaseTableIdentifier(null, null, null);

public AddAutoIncrementStatement(
String catalogName,
Expand All @@ -28,15 +26,24 @@ public AddAutoIncrementStatement(
BigInteger incrementBy,
Boolean defaultOnNull,
String generationType) {
this.catalogName = catalogName;
this.schemaName = schemaName;
this.tableName = tableName;
this.databaseTableIdentifier.setCatalogName(catalogName);
this.databaseTableIdentifier.setSchemaName(schemaName);
this.databaseTableIdentifier.setTableName(tableName);
this.columnName = columnName;
this.columnDataType = columnDataType;
this.startWith = startWith;
this.incrementBy = incrementBy;
this.defaultOnNull = defaultOnNull;
this.generationType = generationType;
}
public String getCatalogName() {
return databaseTableIdentifier.getCatalogName();
}
public String getSchemaName() {
return databaseTableIdentifier.getSchemaName();
}
public String getTableName() {
return databaseTableIdentifier.getTableName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
@Getter
public class AddColumnStatement extends AbstractSqlStatement {

private String catalogName;
private String schemaName;
private String tableName;
private String columnName;
private String columnType;
private Object defaultValue;
Expand All @@ -29,11 +26,12 @@ public class AddColumnStatement extends AbstractSqlStatement {
private final Set<ColumnConstraint> constraints = new HashSet<>();

private final List<AddColumnStatement> columns = new ArrayList<>();
private DatabaseTableIdentifier databaseTableIdentifier = new DatabaseTableIdentifier(null, null, null);

public AddColumnStatement(String catalogName, String schemaName, String tableName, String columnName, String columnType, Object defaultValue, ColumnConstraint... constraints) {
this.catalogName = catalogName;
this.schemaName = schemaName;
this.tableName = tableName;
this.databaseTableIdentifier.setCatalogName(catalogName);
this.databaseTableIdentifier.setSchemaName(schemaName);
this.databaseTableIdentifier.setTableName(tableName);
this.columnName = columnName;
this.columnType = columnType;
this.defaultValue = defaultValue;
Expand Down Expand Up @@ -157,4 +155,17 @@ public String getUniqueStatementName() {
return null;
}

public String getCatalogName(){
return databaseTableIdentifier.getCatalogName();
}

public String getSchemaName(){
return databaseTableIdentifier.getSchemaName();
}

public String getTableName(){
return databaseTableIdentifier.getTableName();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,35 @@

@Getter
public class AddDefaultValueStatement extends AbstractSqlStatement {
private final String catalogName;
private final String schemaName;
private final String tableName;
private final String columnName;
private final String columnDataType;
private final Object defaultValue;

@Setter
private String defaultValueConstraintName;
private DatabaseTableIdentifier databaseTableIdentifier = new DatabaseTableIdentifier(null, null, null);

public AddDefaultValueStatement(String catalogName, String schemaName, String tableName, String columnName, String columnDataType) {
this(catalogName, schemaName, tableName, columnName, columnDataType, null);
}

public AddDefaultValueStatement(String catalogName, String schemaName, String tableName, String columnName, String columnDataType, Object defaultValue) {
this.catalogName = catalogName;
this.schemaName = schemaName;
this.tableName = tableName;
this.databaseTableIdentifier.setCatalogName(catalogName);
this.databaseTableIdentifier.setSchemaName(schemaName);
this.databaseTableIdentifier.setTableName(tableName);
this.columnName = columnName;
this.columnDataType = columnDataType;
this.defaultValue = defaultValue;
}

public String getCatalogName() {
return databaseTableIdentifier.getCatalogName();
}
public String getSchemaName() {
return databaseTableIdentifier.getSchemaName();
}
public String getTableName() {
return databaseTableIdentifier.getTableName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@

public class AddPrimaryKeyStatement extends AbstractSqlStatement {

@Getter
private final String catalogName;
@Getter
private final String schemaName;
@Getter
private final String tableName;
@Getter
private String tablespace;
@Getter
Expand All @@ -32,6 +26,7 @@ public class AddPrimaryKeyStatement extends AbstractSqlStatement {
@Setter
private String forIndexCatalogName;
private boolean shouldValidate = true;
private DatabaseTableIdentifier databaseTableIdentifier = new DatabaseTableIdentifier(null, null, null);

/**
* @deprecated
Expand All @@ -41,9 +36,9 @@ public AddPrimaryKeyStatement(String catalogName, String schemaName, String tabl
}

public AddPrimaryKeyStatement(String catalogName, String schemaName, String tableName, ColumnConfig[] columns, String constraintName) {
this.catalogName = catalogName;
this.schemaName = schemaName;
this.tableName = tableName;
this.databaseTableIdentifier.setCatalogName(catalogName);
this.databaseTableIdentifier.setSchemaName(schemaName);
this.databaseTableIdentifier.setTableName(tableName);
this.columns = columns;
this.constraintName = constraintName;
}
Expand Down Expand Up @@ -86,4 +81,16 @@ public AddPrimaryKeyStatement setShouldValidate(boolean shouldValidate) {
this.shouldValidate = shouldValidate;
return this;
}

public String getCatalogName() {
return databaseTableIdentifier.getCatalogName();
}

public String getSchemaName() {
return databaseTableIdentifier.getSchemaName();
}

public String getTableName() {
return databaseTableIdentifier.getTableName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@

public class AddUniqueConstraintStatement extends AbstractSqlStatement {

@Getter
private final String catalogName;
@Getter
private final String schemaName;
@Getter
private final String tableName;
@Getter
private final ColumnConfig[] columns;
@Getter
Expand Down Expand Up @@ -41,11 +35,12 @@ public class AddUniqueConstraintStatement extends AbstractSqlStatement {
@Getter
@Setter
private String forIndexCatalogName;
private DatabaseTableIdentifier databaseTableIdentifier = new DatabaseTableIdentifier(null, null, null);

public AddUniqueConstraintStatement(String catalogName, String schemaName, String tableName, ColumnConfig[] columns, String constraintName) {
this.catalogName = catalogName;
this.schemaName = schemaName;
this.tableName = tableName;
this.databaseTableIdentifier.setCatalogName(catalogName);
this.databaseTableIdentifier.setSchemaName(schemaName);
this.databaseTableIdentifier.setTableName(tableName);
this.columns = columns;
this.constraintName = constraintName;
}
Expand Down Expand Up @@ -100,4 +95,16 @@ public AddUniqueConstraintStatement setShouldValidate(boolean shouldValidate) {
this.shouldValidate = shouldValidate;
return this;
}

public String getTableName(){
return databaseTableIdentifier.getTableName();
}

public String getSchemaName(){
return databaseTableIdentifier.getSchemaName();
}

public String getCatalogName(){
return databaseTableIdentifier.getCatalogName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ public class CreateTableStatement extends AbstractSqlStatement implements Compou
/** Table type used by some RDBMS (Snowflake, SAP HANA) supporting different ... types ... of tables (e.g. column- vs. row-based) */
private String tableType;

private final String catalogName;
private String schemaName;
private final String tableName;
private String tablespace;
private String remarks;
private final List<String> columns = new ArrayList<>();
Expand All @@ -36,6 +33,7 @@ in line with the column (this implies that a NN constraint can always affect exa
private final Set<String> computedColumns = new HashSet<>();

private boolean ifNotExists;
private DatabaseTableIdentifier databaseTableIdentifier = new DatabaseTableIdentifier(null, null, null);

public CreateTableStatement(String catalogName, String schemaName, String tableName) {
this(catalogName, schemaName, tableName, null, null);
Expand All @@ -46,9 +44,9 @@ public CreateTableStatement(String catalogName, String schemaName, String tableN
}

public CreateTableStatement(String catalogName, String schemaName, String tableName, String remarks, String tableType) {
this.catalogName = catalogName;
this.schemaName = schemaName;
this.tableName = tableName;
this.databaseTableIdentifier.setCatalogName(catalogName);
this.databaseTableIdentifier.setSchemaName(schemaName);
this.databaseTableIdentifier.setTableName(tableName);
this.remarks = remarks;
this.tableType = tableType;
}
Expand All @@ -64,15 +62,15 @@ public CreateTableStatement(String catalogName, String schemaName, String tableN
}

public String getCatalogName() {
return catalogName;
return databaseTableIdentifier.getCatalogName();
}

public String getSchemaName() {
return schemaName;
return databaseTableIdentifier.getSchemaName();
}

public String getTableName() {
return tableName;
return databaseTableIdentifier.getTableName();
}

public List<String> getColumns() {
Expand Down Expand Up @@ -278,7 +276,7 @@ public Map<String, String> getDefaultValueConstraintNames() {
}

public void setSchemaName(String schemaName) {
this.schemaName = schemaName;
this.databaseTableIdentifier.setSchemaName(schemaName);
}

public void setComputed(String columnName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package liquibase.statement.core;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
public class DatabaseTableIdentifier{
private String catalogName;
private String schemaName;
private String tableName;

}

Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,27 @@
import java.util.List;

public class DeleteStatement extends AbstractSqlStatement {
private final String catalogName;
private final String schemaName;
private final String tableName;
private String where;
private final List<Object> whereParameters = new ArrayList<>();
private final List<String> whereColumnNames = new ArrayList<>();
private DatabaseTableIdentifier databaseTableIdentifier = new DatabaseTableIdentifier(null, null, null);

public DeleteStatement(String catalogName, String schemaName, String tableName) {
this.catalogName = catalogName;
this.schemaName = schemaName;
this.tableName = tableName;
this.databaseTableIdentifier.setCatalogName(catalogName);
this.databaseTableIdentifier.setSchemaName(schemaName);
this.databaseTableIdentifier.setTableName(tableName);
}

public String getCatalogName() {
return catalogName;
return databaseTableIdentifier.getCatalogName();
}

public String getSchemaName() {
return schemaName;
return databaseTableIdentifier.getSchemaName();
}

public String getTableName() {
return tableName;
return databaseTableIdentifier.getTableName();
}

public String getWhere() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@

public class DropColumnStatement extends AbstractSqlStatement {

private String catalogName;
private String schemaName;
private String tableName;
private String columnName;

private final List<DropColumnStatement> columns = new ArrayList<>();
private DatabaseTableIdentifier databaseTableIdentifier = new DatabaseTableIdentifier(null, null, null);

public DropColumnStatement(String catalogName, String schemaName, String tableName, String columnName) {
this.catalogName = catalogName;
this.schemaName = schemaName;
this.tableName = tableName;
this.databaseTableIdentifier.setCatalogName(catalogName);
this.databaseTableIdentifier.setSchemaName(schemaName);
this.databaseTableIdentifier.setTableName(tableName);
this.columnName = columnName;
}

Expand All @@ -34,15 +32,15 @@ public List<DropColumnStatement> getColumns() {
}

public String getCatalogName() {
return catalogName;
return databaseTableIdentifier.getCatalogName();
}

public String getSchemaName() {
return schemaName;
return databaseTableIdentifier.getSchemaName();
}

public String getTableName() {
return tableName;
return databaseTableIdentifier.getTableName();
}

public String getColumnName() {
Expand Down