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

Code cleanup: avoid re-calling methods #3721

Merged
merged 3 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -258,7 +258,6 @@ private void configureCustomChange() throws CustomChangeException {
public SerializationType getSerializableFieldType(String field) {
switch (field) {
case "class":
return SerializationType.NAMED_FIELD;
case "param":
return SerializationType.NAMED_FIELD;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ public class BlobType extends LiquibaseDataType {
public DatabaseDataType toDatabaseDataType(Database database) {
String originalDefinition = StringUtil.trimToEmpty(getRawDefinition());

final boolean varbinary = originalDefinition.toLowerCase(Locale.US).startsWith("varbinary") || originalDefinition.startsWith("java.sql.Types.VARBINARY");
if ((database instanceof H2Database) || (database instanceof HsqlDatabase)) {
if (originalDefinition.toLowerCase(Locale.US).contains("large object")) {
return new DatabaseDataType("BINARY LARGE OBJECT");
}
if (originalDefinition.toLowerCase(Locale.US).startsWith("varbinary") || originalDefinition.startsWith("java.sql.Types.VARBINARY")) {
if (varbinary) {
return new DatabaseDataType("VARBINARY", getParameters());
} else if (originalDefinition.toLowerCase(Locale.US).startsWith("longvarbinary") || originalDefinition.startsWith("java.sql.Types.LONGVARBINARY")) {
return new DatabaseDataType("LONGVARBINARY", getParameters());
Expand Down Expand Up @@ -68,8 +69,9 @@ public DatabaseDataType toDatabaseDataType(Database database) {
}
}

final boolean blob = originalDefinition.toLowerCase(Locale.US).startsWith("blob") || "java.sql.Types.BLOB".equals(originalDefinition);
if (database instanceof MySQLDatabase) {
if (originalDefinition.toLowerCase(Locale.US).startsWith("blob") || "java.sql.Types.BLOB".equals(originalDefinition)) {
if (blob) {
return new DatabaseDataType("BLOB");
} else if (originalDefinition.toLowerCase(Locale.US).startsWith("varbinary") || "java.sql.Types.VARBINARY".equals
(originalDefinition)) {
Expand All @@ -86,7 +88,7 @@ public DatabaseDataType toDatabaseDataType(Database database) {
}

if (database instanceof PostgresDatabase) {
if (originalDefinition.toLowerCase(Locale.US).startsWith("blob") || "java.sql.Types.BLOB".equals(originalDefinition)) {
if (blob) {
// There are two ways of handling byte arrays ("BLOBs") in pgsql. For consistency with Hibernate ORM
// (see upstream bug https://liquibase.jira.com/browse/CORE-1863) we choose the oid variant.
// For a more thorough discussion of the two alternatives, see:
Expand Down Expand Up @@ -122,7 +124,7 @@ public DatabaseDataType toDatabaseDataType(Database database) {
}

if ((database instanceof DB2Database) || (database instanceof Db2zDatabase)) {
if (originalDefinition.toLowerCase(Locale.US).startsWith("varbinary") || originalDefinition.startsWith("java.sql.Types.VARBINARY")) {
if (varbinary) {
return new DatabaseDataType("VARBINARY", getParameters());
} else if (originalDefinition.toLowerCase(Locale.US).startsWith("binary")) {
return new DatabaseDataType("BINARY", getParameters());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.nio.file.Path;
import java.nio.file.Paths;

public class AntResourceAccessor extends CompositeResourceAccessor {
Expand Down Expand Up @@ -46,10 +47,11 @@ public AntResourceAccessor(AntClassLoader classLoader, String changeLogDirectory
for (String path : classpath.split(System.getProperty("path.separator"))) {
try {
String lowercasePath = path.toLowerCase();
final Path path1 = Paths.get(path);
if (lowercasePath.endsWith(".jar") || lowercasePath.endsWith(".zip")) {
this.addResourceAccessor(new ZipResourceAccessor(Paths.get(path).toAbsolutePath()));
this.addResourceAccessor(new ZipResourceAccessor(path1.toAbsolutePath()));
} else {
this.addResourceAccessor(new DirectoryResourceAccessor(Paths.get(path).toAbsolutePath()));
this.addResourceAccessor(new DirectoryResourceAccessor(path1.toAbsolutePath()));
}
} catch (FileNotFoundException e) {
Scope.getCurrentScope().getLog(getClass()).fine(e.getMessage(), e);
Expand Down