DBZ-252 reformat code to not have anything after closing "}"

This commit is contained in:
rkuchar 2018-04-08 14:23:14 +02:00 committed by Gunnar Morling
parent 9aa2d75c94
commit 9311c82bc5
10 changed files with 108 additions and 173 deletions

View File

@ -1,106 +0,0 @@
/*
* Copyright Debezium Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.debezium.connector.mysql;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* Encapsulates a set of the MySQL system variables.
*
* @author Randall Hauch
*/
public class MySqlSystemVariables {
public static enum Scope {
GLOBAL, SESSION, LOCAL;
}
/**
* The system variable name for the name of the character set that the server uses by default.
* See http://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_character-set-server
*/
public static final String CHARSET_NAME_SERVER = "character_set_server";
/**
* The system variable name to see if the MySQL tables are stored and looked-up in case sensitive way.
* See https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_lower_case_table_names
*/
public static final String LOWER_CASE_TABLE_NAMES = "lower_case_table_names";
private final ConcurrentMap<String, String> global = new ConcurrentHashMap<>();
private final ConcurrentMap<String, String> session = new ConcurrentHashMap<>();
/**
* Create an instance.
*/
public MySqlSystemVariables() {
}
/**
* Set the variable with the specified scope.
*
* @param scope the variable scope; may be null if the session scope is to be used
* @param name the name of the variable; may not be null
* @param value the variable value; may be null if the value for the named variable is to be removed
* @return this object for method chaining purposes; never null
*/
public MySqlSystemVariables setVariable(Scope scope, String name, String value) {
name = variableName(name);
if (value != null) {
forScope(scope).put(name, value);
} else {
forScope(scope).remove(name);
}
return this;
}
/**
* Get the variable with the specified name and scope.
*
* @param name the name of the variable; may not be null
* @param scope the variable scope; may not be null
* @return the variable value; may be null if the variable is not currently set
*/
public String getVariable(String name, Scope scope) {
name = variableName(name);
return forScope(scope).get(name);
}
/**
* Get the variable with the specified name, first checking the {@link Scope#SESSION session} (or {@link Scope#LOCAL local})
* variables and then the {@link Scope#GLOBAL global} variables.
*
* @param name the name of the variable; may not be null
* @return the variable value; may be null if the variable is not currently set
*/
public String getVariable(String name) {
name = variableName(name);
String value = session.get(name);
if (value == null) {
value = global.get(name);
}
return value;
}
private String variableName(String name) {
return name.toLowerCase();
}
private ConcurrentMap<String, String> forScope(Scope scope) {
if (scope != null) {
switch (scope) {
case GLOBAL:
return global;
case SESSION:
case LOCAL:
return session;
}
}
return session;
}
}

View File

@ -46,7 +46,8 @@ public SystemVariables setVariable(Scope scope, String name, String value) {
name = variableName(name);
if (value != null) {
forScope(scope).put(name, value);
} else {
}
else {
forScope(scope).remove(name);
}
return this;
@ -77,7 +78,7 @@ public String getVariable(String name) {
for (ConcurrentMap<String, String> variablesByScope : orderedSystemVariablesByPriority) {
String variableName = variablesByScope.get(name);
if(variableName != null) {
if (variableName != null) {
return variableName;
}
}

View File

@ -273,13 +273,16 @@ protected Column createColumnFromConstant(String columnName, String constantValu
column.type("CHAR");
column.jdbcType(Types.CHAR);
column.length(constantValue.length() - 2);
} else if (constantValue.equalsIgnoreCase("TRUE") || constantValue.equalsIgnoreCase("FALSE")) {
}
else if (constantValue.equalsIgnoreCase("TRUE") || constantValue.equalsIgnoreCase("FALSE")) {
column.type("BOOLEAN");
column.jdbcType(Types.BOOLEAN);
} else {
}
else {
setTypeInfoForConstant(constantValue, column);
}
} catch (Throwable t) {
}
catch (Throwable t) {
logger.debug("Unable to create an artificial column for the constant: " + constantValue);
}
return column.create();
@ -290,19 +293,22 @@ protected void setTypeInfoForConstant(String constantValue, ColumnEditor column)
Integer.parseInt(constantValue);
column.type("INTEGER");
column.jdbcType(Types.INTEGER);
} catch (NumberFormatException e) {
}
catch (NumberFormatException e) {
}
try {
Long.parseLong(constantValue);
column.type("BIGINT");
column.jdbcType(Types.BIGINT);
} catch (NumberFormatException e) {
}
catch (NumberFormatException e) {
}
try {
Float.parseFloat(constantValue);
column.type("FLOAT");
column.jdbcType(Types.FLOAT);
} catch (NumberFormatException e) {
}
catch (NumberFormatException e) {
}
try {
Double.parseDouble(constantValue);
@ -315,20 +321,24 @@ protected void setTypeInfoForConstant(String constantValue, ColumnEditor column)
char c = constantValue.charAt(i);
if (c == '+' || c == '-') {
continue;
} else if (c == '.') {
}
else if (c == '.') {
foundDecimalPoint = true;
} else if (Character.isDigit(c)) {
}
else if (Character.isDigit(c)) {
if (foundDecimalPoint)
++scale;
else
++precision;
} else {
}
else {
break;
}
}
column.length(precision);
column.scale(scale);
} catch (NumberFormatException e) {
}
catch (NumberFormatException e) {
}
try {
BigDecimal decimal = new BigDecimal(constantValue);
@ -336,7 +346,8 @@ protected void setTypeInfoForConstant(String constantValue, ColumnEditor column)
column.jdbcType(Types.DECIMAL);
column.length(decimal.precision());
column.scale(decimal.precision());
} catch (NumberFormatException e) {
}
catch (NumberFormatException e) {
}
}

View File

@ -4,6 +4,8 @@ The MIT License (MIT).
Copyright (c) 2015-2017, Ivan Kochurkin (kvanttt@gmail.com), Positive Technologies.
Copyright (c) 2017, Ivan Khudyashev (IHudyashov@ptsecurity.com)
https://github.com/antlr/grammars-v4/blob/master/mysql/MySqlLexer.g4
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
@ -21,6 +23,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
lexer grammar MySqlLexer;

View File

@ -4,6 +4,8 @@ The MIT License (MIT).
Copyright (c) 2015-2017, Ivan Kochurkin (kvanttt@gmail.com), Positive Technologies.
Copyright (c) 2017, Ivan Khudyashev (IHudyashov@ptsecurity.com)
https://github.com/antlr/grammars-v4/blob/master/mysql/MySqlParser.g4
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights

View File

@ -61,7 +61,8 @@ public void parse(String ddlContent, Tables databaseTables) {
if (!proxyParseTreeListener.getErrors().isEmpty()) {
throw new MultipleParsingExceptions(proxyParseTreeListener.getErrors());
}
} else {
}
else {
throw new MultipleParsingExceptions(parsingErrorListener.getErrors());
}
}

View File

@ -11,7 +11,7 @@
/**
* https://github.com/parrt/antlr4/blob/case-insensitivity-doc/doc/resources/CaseChangingCharStream.java
*
* <p>
* This class supports case-insensitive lexing by wrapping an existing
* {@link CharStream} and forcing the lexer to see either upper or
* lowercase characters. Grammar literals should then be either upper or
@ -28,6 +28,7 @@ public class CaseChangingCharStream implements CharStream {
/**
* Constructs a new CaseChangingCharStream wrapping the given {@link CharStream} forcing
* all characters to upper case or lower case.
*
* @param stream The stream to wrap.
* @param upper If true force each symbol to upper case, otherwise force to lower.
*/

View File

@ -8,11 +8,11 @@
import org.antlr.v4.runtime.ParserRuleContext;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class DataTypeResolver {

View File

@ -36,6 +36,7 @@ public class ProxyParseTreeListener implements ParseTreeListener {
private Collection<ParsingException> errors = new ArrayList<>();
private final BiFunction<ParsingException, Collection<ParsingException>, Collection<ParsingException>> accumulateError;
/**
* Creates a new proxy without an empty list of listeners. Add
* listeners before walking the tree.
@ -61,7 +62,8 @@ public void enterEveryRule(ParserRuleContext ctx) {
try {
listener.enterEveryRule(ctx);
ctx.enterRule(listener);
} catch (ParsingException parsingException) {
}
catch (ParsingException parsingException) {
accumulateError.apply(parsingException, errors);
}
}
@ -73,7 +75,8 @@ public void exitEveryRule(ParserRuleContext ctx) {
try {
ctx.exitRule(listener);
listener.exitEveryRule(ctx);
} catch (ParsingException parsingException) {
}
catch (ParsingException parsingException) {
accumulateError.apply(parsingException, errors);
}
}
@ -84,7 +87,8 @@ public void visitErrorNode(ErrorNode node) {
for (ParseTreeListener listener : getListeners()) {
try {
listener.visitErrorNode(node);
} catch (ParsingException parsingException) {
}
catch (ParsingException parsingException) {
accumulateError.apply(parsingException, errors);
}
}
@ -95,7 +99,8 @@ public void visitTerminal(TerminalNode node) {
for (ParseTreeListener listener : getListeners()) {
try {
listener.visitTerminal(node);
} catch (ParsingException parsingException) {
}
catch (ParsingException parsingException) {
accumulateError.apply(parsingException, errors);
}
}

View File

@ -152,7 +152,8 @@ private TableId parseQualifiedTableId(MySqlParser.TableNameContext tableNameCont
if ((dotIndex = fullTableName.indexOf(".")) > 0) {
return resolveTableId(fullTableName.substring(0, dotIndex),
fullTableName.substring(dotIndex + 1, fullTableName.length()));
} else {
}
else {
return resolveTableId(currentSchema(), fullTableName);
}
}
@ -164,7 +165,8 @@ private String parseColumnName(MySqlParser.UidContext uidContext) {
private String getFullTableName(TableId tableId) {
if (tableId.catalog() != null) {
return tableId.catalog() + "." + tableId.table();
} else {
}
else {
return tableId.table();
}
}
@ -180,7 +182,8 @@ private void resolveColumnDataType(MySqlParser.DataTypeContext dataTypeContext)
Integer length = Integer.valueOf(stringDataTypeContext.lengthOneDimension().decimalLiteral().getText());
columnEditor.length(length);
}
} else if (dataTypeContext instanceof MySqlParser.DimensionDataTypeContext) {
}
else if (dataTypeContext instanceof MySqlParser.DimensionDataTypeContext) {
// TINYINT | SMALLINT | MEDIUMINT | INT | INTEGER | BIGINT
// REAL | DOUBLE | FLOAT
// DECIMAL | NUMERIC | DEC | FIXED
@ -214,17 +217,21 @@ private void resolveColumnDataType(MySqlParser.DataTypeContext dataTypeContext)
if (scale != null) {
columnEditor.scale(scale);
}
} else if (dataTypeContext instanceof MySqlParser.SimpleDataTypeContext) {
}
else if (dataTypeContext instanceof MySqlParser.SimpleDataTypeContext) {
// DATE | TINYBLOB | BLOB | MEDIUMBLOB | LONGBLOB | BOOL | BOOLEAN
dataTypeName = ((MySqlParser.SimpleDataTypeContext) dataTypeContext).typeName.getText();
} else if (dataTypeContext instanceof MySqlParser.CollectionDataTypeContext) {
}
else if (dataTypeContext instanceof MySqlParser.CollectionDataTypeContext) {
// ENUM | SET
// do not care about charsetName or collationName
dataTypeName = ((MySqlParser.CollectionDataTypeContext) dataTypeContext).typeName.getText();
} else if (dataTypeContext instanceof MySqlParser.SpatialDataTypeContext) {
}
else if (dataTypeContext instanceof MySqlParser.SpatialDataTypeContext) {
// GEOMETRYCOLLECTION | LINESTRING | MULTILINESTRING | MULTIPOINT | MULTIPOLYGON | POINT | POLYGON
dataTypeName = ((MySqlParser.SpatialDataTypeContext) dataTypeContext).typeName.getText();
} else {
}
else {
throw new IllegalStateException("Not recognized instance of data type context for " + dataTypeContext.getText());
}
@ -374,7 +381,8 @@ public void exitAlterByAddColumn(MySqlParser.AlterByAddColumnContext ctx) {
if (ctx.FIRST() != null) {
tableEditor.reorderColumn(columnName, null);
} else if (ctx.AFTER() != null) {
}
else if (ctx.AFTER() != null) {
String afterColumn = parseColumnName(ctx.uid(1));
tableEditor.reorderColumn(columnName, afterColumn);
}
@ -404,7 +412,8 @@ public void exitColumnDefinition(MySqlParser.ColumnDefinitionContext ctx) {
if (columnEditors.size() > parsingColumnIndex) {
// assign next column editor to parse another column definition
columnEditor = columnEditors.get(parsingColumnIndex++);
} else {
}
else {
// all columns parsed
// reset global variables for next parsed statement
columnEditors = null;
@ -428,7 +437,8 @@ public void enterAlterByChangeColumn(MySqlParser.AlterByChangeColumnContext ctx)
Column existingColumn = tableEditor.columnWithName(oldColumnName);
if (existingColumn != null) {
columnEditor = existingColumn.edit();
} else {
}
else {
throw new ParsingException(null, "Trying to change column " + oldColumnName + " in "
+ getFullTableName(tableEditor.tableId()) + " table, which does not exists.");
}
@ -445,7 +455,8 @@ public void exitAlterByChangeColumn(MySqlParser.AlterByChangeColumnContext ctx)
if (ctx.FIRST() != null) {
tableEditor.reorderColumn(newColumnName, null);
} else if (ctx.afterColumn != null) {
}
else if (ctx.afterColumn != null) {
tableEditor.reorderColumn(newColumnName, parseColumnName(ctx.afterColumn));
}
});
@ -459,7 +470,8 @@ public void enterAlterByModifyColumn(MySqlParser.AlterByModifyColumnContext ctx)
Column column = tableEditor.columnWithName(columnName);
if (column != null) {
columnEditor = column.edit();
} else {
}
else {
throw new ParsingException(null, "Trying to change column " + columnName + " in "
+ getFullTableName(tableEditor.tableId()) + " table, which does not exists.");
}
@ -474,7 +486,8 @@ public void exitAlterByModifyColumn(MySqlParser.AlterByModifyColumnContext ctx)
if (ctx.FIRST() != null) {
tableEditor.reorderColumn(columnEditor.name(), null);
} else if (ctx.AFTER() != null) {
}
else if (ctx.AFTER() != null) {
String afterColumn = parseColumnName(ctx.uid(1));
tableEditor.reorderColumn(columnEditor.name(), afterColumn);
}
@ -635,7 +648,8 @@ public void enterCreateIndex(MySqlParser.CreateIndexContext ctx) {
parsePrimaryIndexColumnNames(ctx.indexColumnNames());
signalAlterTable(tableId, null, ctx);
}
} else {
}
else {
throw new ParsingException(null, "Trying to create index on non existing table " + getFullTableName(tableId));
}
}
@ -655,7 +669,8 @@ public void exitSqlStatement(MySqlParser.SqlStatementContext ctx) {
tableEditor = null;
columnEditor = null;
debugParsed(ctx);
} else {
}
else {
// if table editor was not set, then nothing was parsed
debugSkipped(ctx);
}
@ -665,6 +680,7 @@ public void exitSqlStatement(MySqlParser.SqlStatementContext ctx) {
/**
* Runs the function if {@link MySqlAntlrDdlParser#tableEditor} is not null.
*
* @param function function to run.
*/
private void runIfTableEditorNotNull(Runnable function) {
@ -675,6 +691,7 @@ private void runIfTableEditorNotNull(Runnable function) {
/**
* Runs the function if {@link MySqlAntlrDdlParser#tableEditor} and {@link MySqlAntlrDdlParser#columnEditor} is not null.
*
* @param function function to run.
*/
private void runIfAllEditorsNotNull(Runnable function) {