Skip to content

Commit

Permalink
Use better names.
Browse files Browse the repository at this point in the history
Split regex and petter constant.
  • Loading branch information
arturobernalg committed Jan 26, 2023
1 parent 1816ef7 commit 72673ff
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

public class ChangelogRewriter {

public static final String XSD_PATTERN_STRING = "([dbchangelog|liquibase-pro])-3.[0-9]?[0-9]?.xsd";
public static final Pattern XSD_PATTERN = Pattern.compile(XSD_PATTERN_STRING);
private static final String PATTERN_STRING = "(?ms).*<databaseChangeLog[^>]*>";
private static final Pattern PATTERN = Pattern.compile(PATTERN_STRING);
public static final String XSD_FILE_REGEX = "([dbchangelog|liquibase-pro])-3.[0-9]?[0-9]?.xsd";
public static final Pattern XSD_FILE_PATTERN = Pattern.compile(XSD_FILE_REGEX);
private static final String CHANGELOG_TAG_REGEX = "(?ms).*<databaseChangeLog[^>]*>";
private static final Pattern CHANGELOG_TAG_PATTERN = Pattern.compile(CHANGELOG_TAG_REGEX);

/**
*
Expand Down Expand Up @@ -123,13 +123,13 @@ public static ChangeLogRewriterResult addChangeLogId(String changeLogFile, Strin
String encoding = GlobalConfiguration.OUTPUT_FILE_ENCODING.getCurrentValue();
String changeLogString = StreamUtil.readStreamAsString(is, encoding);
if (changeLogFile.toLowerCase().endsWith(".xml")) {
Matcher matcher = PATTERN.matcher(changeLogString);
Matcher matcher = CHANGELOG_TAG_PATTERN.matcher(changeLogString);
if (matcher.find()) {
//
// Update the XSD versions
//
String header = changeLogString.substring(matcher.start(), matcher.end() - 1);
Matcher xsdMatcher = XSD_PATTERN.matcher(header);
Matcher xsdMatcher = XSD_FILE_PATTERN.matcher(header);
String editedString = xsdMatcher.replaceAll("$1-" + XMLChangeLogSAXParser.getSchemaVersion() + ".xsd");

//
Expand All @@ -140,7 +140,7 @@ public static ChangeLogRewriterResult addChangeLogId(String changeLogFile, Strin
changeLogString = changeLogString.replaceFirst("/>", outputChangeLogString + "/>");
} else {
String outputHeader = editedString + outputChangeLogString + ">";
changeLogString = changeLogString.replaceFirst(PATTERN_STRING, outputHeader);
changeLogString = changeLogString.replaceFirst(CHANGELOG_TAG_REGEX, outputHeader);
}
}
} else if (changeLogFile.toLowerCase().endsWith(".sql")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ public class OfflineConnection implements DatabaseConnection {
private boolean sendsStringParametersAsUnicode = true;
private String connectionUserName;

private static final Pattern PATTERN = Pattern.compile("offline:(\\w+)\\??(.*)");
private static final String OFFLINE_COMMAND_REGEX = "offline:(\\w+)\\??(.*)";
private static final Pattern OFFLINE_COMMAND_PATTERN = Pattern.compile(OFFLINE_COMMAND_REGEX);

public OfflineConnection() {}

public OfflineConnection(String url, ResourceAccessor resourceAccessor) {
this.url = url;
Matcher matcher = PATTERN.matcher(url);
Matcher matcher = OFFLINE_COMMAND_PATTERN.matcher(url);
if (!matcher.matches()) {
throw new UnexpectedLiquibaseException("Could not parse offline url " + url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class CockroachDatabase extends PostgresDatabase {
private Integer databaseMajorVersion;
private Integer databaseMinorVersion;

private static final Pattern VERSION_PATTERN = Pattern.compile("v(\\d+)\\.(\\d+)\\.(\\d+)");
private static final String VERSION_NUMBER_REGEX = "v(\\d+)\\.(\\d+)\\.(\\d+)";
private static final Pattern VERSION_NUMBER_PATTERN = Pattern.compile(VERSION_NUMBER_REGEX);

public CockroachDatabase() {
super.setCurrentDateTimeFunction("NOW()");
Expand Down Expand Up @@ -109,7 +110,7 @@ public void setConnection(DatabaseConnection conn) {
String version = Scope.getCurrentScope().getSingleton(ExecutorService.class).
getExecutor("jdbc", this).queryForObject(new RawSqlStatement("SELECT version()"), String.class);

final Matcher versionMatcher = VERSION_PATTERN.matcher(version);
final Matcher versionMatcher = VERSION_NUMBER_PATTERN.matcher(version);
if (versionMatcher.find()) {
this.databaseMajorVersion = Integer.parseInt(versionMatcher.group(1));
this.databaseMinorVersion = Integer.parseInt(versionMatcher.group(2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@

public class H2Database extends AbstractJdbcDatabase {

private static final Pattern PATCH_VERSION_PATTERN = Pattern.compile("^(?:\\d+\\.)(?:\\d+\\.)(\\d+).*$");
private static final String PATCH_VERSION_REGEX = "^(?:\\d+\\.)(?:\\d+\\.)(\\d+).*$";
private static final Pattern PATCH_VERSION_PATTERN = Pattern.compile(PATCH_VERSION_REGEX);
private static String START_CONCAT = "CONCAT(";
private static String END_CONCAT = ")";
private static String SEP_CONCAT = ", ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@
* Encapsulates Oracle database support.
*/
public class OracleDatabase extends AbstractJdbcDatabase {
public static final Pattern PROXY_USER = Pattern.compile(".*(?:thin|oci)\\:(.+)/@.*");

private static final Pattern VERSION_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)\\..*");
private static final String PROXY_USER_REGEX = ".*(?:thin|oci)\\:(.+)/@.*";
public static final Pattern PROXY_USER_PATTERN = Pattern.compile(PROXY_USER_REGEX);

private static final String VERSION_REGEX = "(\\d+)\\.(\\d+)\\..*";
private static final Pattern VERSION_PATTERN = Pattern.compile(VERSION_REGEX);

public static final String PRODUCT_NAME = "oracle";
private static ResourceBundle coreBundle = getBundle("liquibase/i18n/liquibase-core");
Expand Down Expand Up @@ -80,7 +83,7 @@ public int getPriority() {
}

private void tryProxySession(final String url, final Connection con) {
Matcher m = PROXY_USER.matcher(url);
Matcher m = PROXY_USER_PATTERN.matcher(url);
if (m.matches()) {
Properties props = new Properties();
props.put("PROXY_USER_NAME", m.group(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
public class TimeType extends LiquibaseDataType {

protected static final int MSSQL_TYPE_TIME_DEFAULT_PRECISION = 7;
public static final Pattern PATTERN = Pattern.compile("(\\(\\d+\\))");
private static final String PARENTHESIS_REGEX = "(\\(\\d+\\))";
public static final Pattern PARENTHESIS_PATTERN = Pattern.compile(PARENTHESIS_REGEX);

@Override
public DatabaseDataType toDatabaseDataType(Database database) {
Expand Down Expand Up @@ -64,7 +65,7 @@ public DatabaseDataType toDatabaseDataType(Database database) {

final Object[] parameters = getParameters();
if (parameters == null || parameters.length == 0) {
final Matcher precisionMatcher = PATTERN.matcher(rawDefinition);
final Matcher precisionMatcher = PARENTHESIS_PATTERN.matcher(rawDefinition);
if (precisionMatcher.find()) {
datatype = new DatabaseDataType(datatype.getType() + precisionMatcher.group(1));
}
Expand Down

0 comments on commit 72673ff

Please sign in to comment.