Skip to content

Commit 2561d61

Browse files
author
Nageswaran Sokkayaraj
committed
Fixing check-style issues-1
1 parent b3a624d commit 2561d61

File tree

14 files changed

+196
-166
lines changed

14 files changed

+196
-166
lines changed

mysql-replicator-augmenter-model/src/main/java/com/booking/replication/augmenter/model/deserializer/CellValueDeserializer.java

+27-23
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.booking.replication.augmenter.model.schema.ColumnSchema;
44

5-
import javax.xml.bind.DatatypeConverter;
65
import java.io.Serializable;
76
import java.math.BigDecimal;
87
import java.nio.charset.StandardCharsets;
@@ -14,15 +13,20 @@
1413
import java.util.regex.Pattern;
1514
import java.util.stream.IntStream;
1615

16+
import javax.xml.bind.DatatypeConverter;
17+
1718
public class CellValueDeserializer {
1819

1920
private static String binaryToHexString(byte[] value, Integer displayWidth) {
2021
if (displayWidth != null && value.length != displayWidth) {
2122
// zerofill rest of the bytes
2223
byte[] zerofilledValue = new byte[displayWidth];
2324
for (int i = 0; i < displayWidth; i++) {
24-
if (i >= value.length) zerofilledValue[i] = 0;
25-
else zerofilledValue[i] = value[i];
25+
if (i >= value.length) {
26+
zerofilledValue[i] = 0;
27+
} else {
28+
zerofilledValue[i] = value[i];
29+
}
2630
}
2731
return DatatypeConverter.printHexBinary(zerofilledValue);
2832
}
@@ -48,17 +52,17 @@ public static Object deserialize(Map<String, String[]> cache, ColumnSchema colum
4852
return deserializedCellValue;
4953
}
5054

51-
if (columnType.contains("decimal") ||
52-
columnType.contains("numeric")) {
55+
if (columnType.contains("decimal")
56+
|| columnType.contains("numeric")) {
5357
//todo: get precision and decide data type
5458
BigDecimal cellValue1 = (BigDecimal) cellValue;
5559
deserializedCellValue = cellValue1.toPlainString();
5660
;
5761
}
5862

59-
if (columnType.contains("timestamp") ||
60-
columnType.contains("date") ||
61-
columnType.contains("time")) {
63+
if (columnType.contains("timestamp")
64+
|| columnType.contains("date")
65+
|| columnType.contains("time")) {
6266
//todo: Change it to timestamp (long).
6367
deserializedCellValue = cellValue.toString();
6468
}
@@ -72,38 +76,38 @@ public static Object deserialize(Map<String, String[]> cache, ColumnSchema colum
7276

7377
if (columnType.contains("tinyint")) {
7478
if (columnType.contains("unsigned")) {
75-
int a = (Integer) cellValue;
76-
byte x1 = (byte) a;
79+
int intValue = (Integer) cellValue;
80+
byte x1 = (byte) intValue;
7781
deserializedCellValue = Byte.toUnsignedInt(x1);
7882
} else {
7983
deserializedCellValue = cellValue;
8084
}
8185
} else if (columnType.contains("smallint")) {
8286
if (columnType.contains("unsigned")) {
83-
int a = (Integer) cellValue;
84-
short x1 = (short) a;
87+
int intValue = (Integer) cellValue;
88+
short x1 = (short) intValue;
8589
deserializedCellValue = Short.toUnsignedInt(x1);
8690
} else {
8791
deserializedCellValue = cellValue;
8892
}
8993
} else if (columnType.contains("mediumint")) {
9094
if (columnType.contains("unsigned")) {
91-
int a = (Integer) cellValue;
92-
deserializedCellValue = a & 0xffffff;
95+
int intValue = (Integer) cellValue;
96+
deserializedCellValue = intValue & 0xffffff;
9397
} else {
9498
deserializedCellValue = cellValue;
9599
}
96100
} else if (columnType.contains("bigint")) {
97101
if (columnType.contains("unsigned")) {
98-
long a = (Long) cellValue;
99-
deserializedCellValue = Long.toUnsignedString(a);
102+
long longValue = (Long) cellValue;
103+
deserializedCellValue = Long.toUnsignedString(longValue);
100104
} else {
101105
deserializedCellValue = cellValue;
102106
}
103107
} else if (columnType.contains("int")) {
104108
if (columnType.contains("unsigned")) {
105-
int a = (Integer) cellValue;
106-
deserializedCellValue = Integer.toUnsignedLong(a);
109+
int intValue = (Integer) cellValue;
110+
deserializedCellValue = Integer.toUnsignedLong(intValue);
107111
} else {
108112
deserializedCellValue = cellValue;
109113
}
@@ -150,12 +154,12 @@ public static Object deserialize(Map<String, String[]> cache, ColumnSchema colum
150154
}
151155

152156
private static Integer getDisplayWidth(String columnType) {
153-
String pattern = "binary\\((\\d+)\\)";
154-
Pattern r = Pattern.compile(pattern);
155-
Matcher m = r.matcher(columnType);
157+
String patternString = "binary\\((\\d+)\\)";
158+
Pattern pattern = Pattern.compile(patternString);
159+
Matcher matcher = pattern.matcher(columnType);
156160

157-
if (m.find()) {
158-
return Integer.parseInt(m.group(1));
161+
if (matcher.find()) {
162+
return Integer.parseInt(matcher.group(1));
159163
} else {
160164
return null;
161165
}

mysql-replicator-augmenter-model/src/main/java/com/booking/replication/augmenter/model/event/QueryAugmentedEventData.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.booking.replication.augmenter.model.event;
22

3+
import com.booking.replication.augmenter.model.schema.FullTableName;
34
import com.booking.replication.augmenter.model.schema.SchemaSnapshot;
45
import com.booking.replication.augmenter.model.schema.TableSchema;
5-
import com.booking.replication.augmenter.model.schema.FullTableName;
66

77
@SuppressWarnings("unused")
88
public class QueryAugmentedEventData implements TableAugmentedEventData {
@@ -22,7 +22,9 @@ public class QueryAugmentedEventData implements TableAugmentedEventData {
2222
public QueryAugmentedEventData() {
2323
}
2424

25-
public QueryAugmentedEventData(QueryAugmentedEventDataType queryType, QueryAugmentedEventDataOperationType operationType, FullTableName eventTable, long threadId, long executionTime, int errorCode, String sql, TableSchema before, TableSchema after) {
25+
public QueryAugmentedEventData(QueryAugmentedEventDataType queryType, QueryAugmentedEventDataOperationType operationType,
26+
FullTableName eventTable, long threadId, long executionTime, int errorCode, String sql,
27+
TableSchema before, TableSchema after) {
2628
this.queryType = queryType;
2729
this.operationType = operationType;
2830
this.eventTable = eventTable;
@@ -75,15 +77,15 @@ public boolean isDDL() {
7577
return isDDL;
7678
}
7779

78-
public void setDDL(boolean DDL) {
79-
isDDL = DDL;
80+
public void setDDL(boolean isDDL) {
81+
this.isDDL = isDDL;
8082
}
8183

82-
public void setSchemaCompatibilityFlag(boolean isCompatibleSchemaChange){
84+
public void setSchemaCompatibilityFlag(boolean isCompatibleSchemaChange) {
8385
this.isCompatibleSchemaChange = isCompatibleSchemaChange;
8486
}
8587

86-
public boolean getIsCompatibleSchemaChange(){
88+
public boolean getIsCompatibleSchemaChange() {
8789
return this.isCompatibleSchemaChange;
8890
}
8991

mysql-replicator-augmenter-model/src/main/java/com/booking/replication/augmenter/model/event/format/avro/EventDataPresenterAvro.java

+48-35
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
package com.booking.replication.augmenter.model.event.format.avro;
22

33
import com.booking.replication.augmenter.model.definitions.DDL;
4-
import com.booking.replication.augmenter.model.event.*;
4+
import com.booking.replication.augmenter.model.event.AugmentedEvent;
5+
import com.booking.replication.augmenter.model.event.AugmentedEventData;
6+
import com.booking.replication.augmenter.model.event.AugmentedEventHeader;
7+
import com.booking.replication.augmenter.model.event.DeleteRowsAugmentedEventData;
8+
import com.booking.replication.augmenter.model.event.QueryAugmentedEventData;
9+
import com.booking.replication.augmenter.model.event.QueryAugmentedEventDataType;
10+
import com.booking.replication.augmenter.model.event.UpdateRowsAugmentedEventData;
11+
import com.booking.replication.augmenter.model.event.WriteRowsAugmentedEventData;
512
import com.booking.replication.augmenter.model.row.AugmentedRow;
613
import com.booking.replication.augmenter.model.schema.ColumnSchema;
714
import com.booking.replication.augmenter.model.schema.FullTableName;
815
import com.booking.replication.augmenter.model.schema.TableSchema;
16+
917
import com.fasterxml.jackson.databind.ObjectMapper;
1018

1119
import org.apache.avro.Schema;
@@ -97,7 +105,10 @@ public AvroMessageKey convertAugumentedEventHeaderToAvro() {
97105
}
98106

99107
public List<GenericRecord> convertAugumentedEventDataToAvro() throws IOException {
100-
if (this.skipRow) return new ArrayList<>();
108+
if (this.skipRow) {
109+
return new ArrayList<>();
110+
}
111+
101112
try {
102113
Schema avroSchema = createAvroSchema(ADD_META_FILEDS, CONVERT_BIN_TO_HEX, this.eventTable, this.columns);
103114
if (Objects.equals(this.eventType, "ddl")) {
@@ -159,10 +170,9 @@ public static Schema createAvroSchema(boolean addMetaFields, boolean convertBinT
159170

160171
// mysql stores it as tinyint
161172
addIntField(columnName, col.getValueDefault(), builder);
162-
} else if (colType.startsWith("tinyint") ||
163-
colType.startsWith("smallint") ||
164-
colType.startsWith("mediumint")
165-
) {
173+
} else if (colType.startsWith("tinyint")
174+
|| colType.startsWith("smallint")
175+
|| colType.startsWith("mediumint")) {
166176
addIntField(columnName, col.getValueDefault(), builder);
167177
} else if (colType.startsWith("int") || colType.startsWith("integer")) {
168178
if (colType.contains("unsigned")) {
@@ -180,77 +190,81 @@ public static Schema createAvroSchema(boolean addMetaFields, boolean convertBinT
180190
} else {
181191
addLongField(columnName, col.getValueDefault(), builder);
182192
}
183-
} else if (colType.startsWith("float") ||
184-
colType.startsWith("real")
185-
) {
186-
193+
} else if (colType.startsWith("float")
194+
|| colType.startsWith("real")) {
187195
addFloatField(columnName, col.getValueDefault(), builder);
188196
} else if (colType.startsWith("double")) {
189197
addDoubleField(columnName, col.getValueDefault(), builder);
190-
} else if (colType.startsWith("date") ||
191-
colType.startsWith("time") ||
192-
colType.startsWith("timestamp")
193-
) {
198+
} else if (colType.startsWith("date")
199+
|| colType.startsWith("time")
200+
|| colType.startsWith("timestamp")) {
194201
addStringField(columnName, col.getValueDefault(), builder);
195-
} else if (colType.startsWith("binary") ||
196-
colType.startsWith("varbinary") ||
197-
colType.startsWith("longvarbinary") ||
198-
colType.startsWith("array") ||
199-
colType.startsWith("blob")
200-
) {
202+
} else if (colType.startsWith("binary")
203+
|| colType.startsWith("varbinary")
204+
|| colType.startsWith("longvarbinary")
205+
|| colType.startsWith("array")
206+
|| colType.startsWith("blob")) {
201207
if (convertBinToHex) {
202208
addStringField(columnName, col.getValueDefault(), builder);
203209
} else {
204210
builder.name(columnName).type().unionOf().nullBuilder().endNull().and().bytesType().endUnion().noDefault();
205211
}
206212
} else if (colType.contains("bit")) {
207213
addStringField(columnName, col.getValueDefault(), builder);
208-
} else if (colType.startsWith("decimal") ||
209-
colType.startsWith("numeric") ){
214+
} else if (colType.startsWith("decimal")
215+
|| colType.startsWith("numeric")) {
210216
//todo: get precision and decide data type
211217
addStringField(columnName, col.getValueDefault(), builder);
212218
} else {
213219
addStringField(columnName, col.getValueDefault(), builder);
214220
}
215221
}
216-
if (addMetaFields)
222+
223+
if (addMetaFields) {
217224
addMetaFields(builder);
225+
}
226+
218227
return builder.endRecord();
219228
}
220229

221230
private static void addIntField(String name, String defaultVal, SchemaBuilder.FieldAssembler<Schema> builder) {
222-
if (isNullValue(defaultVal))
231+
if (isNullValue(defaultVal)) {
223232
builder.optionalInt(name);
224-
else
233+
} else {
225234
builder.nullableInt(name, Integer.valueOf(defaultVal));
235+
}
226236
}
227237

228238
private static void addFloatField(String name, String defaultVal, SchemaBuilder.FieldAssembler<Schema> builder) {
229-
if (isNullValue(defaultVal))
239+
if (isNullValue(defaultVal)) {
230240
builder.optionalFloat(name);
231-
else
241+
} else {
232242
builder.nullableFloat(name, Float.valueOf(defaultVal));
243+
}
233244
}
234245

235246
private static void addLongField(String name, String defaultVal, SchemaBuilder.FieldAssembler<Schema> builder) {
236-
if (isNullValue(defaultVal))
247+
if (isNullValue(defaultVal)) {
237248
builder.optionalLong(name);
238-
else
249+
} else {
239250
builder.nullableLong(name, Long.valueOf(defaultVal));
251+
}
240252
}
241253

242254
private static void addDoubleField(String name, String defaultVal, SchemaBuilder.FieldAssembler<Schema> builder) {
243-
if (isNullValue(defaultVal))
255+
if (isNullValue(defaultVal)) {
244256
builder.optionalDouble(name);
245-
else
257+
} else {
246258
builder.nullableDouble(name, Double.valueOf(defaultVal));
259+
}
247260
}
248261

249262
private static void addStringField(String name, String defaultVal, SchemaBuilder.FieldAssembler<Schema> builder) {
250-
if (isNullValue(defaultVal))
263+
if (isNullValue(defaultVal)) {
251264
builder.optionalString(name);
252-
else
265+
} else {
253266
builder.nullableString(name, defaultVal);
267+
}
254268
}
255269

256270
private static void addMetaFields(SchemaBuilder.FieldAssembler<Schema> builder) {
@@ -259,8 +273,7 @@ private static void addMetaFields(SchemaBuilder.FieldAssembler<Schema> builder)
259273
addLongField("__binlog_position", "NULL", builder);
260274
}
261275

262-
private static boolean isNullValue(String val){
276+
private static boolean isNullValue(String val) {
263277
return val == null || Objects.equals(val.toUpperCase(), "NULL");
264278
}
265-
266279
}

mysql-replicator-augmenter-model/src/main/java/com/booking/replication/augmenter/model/row/AugmentedRow.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public AugmentedRow(
6262
// times during one second, but in different events. The additional logic is added in
6363
// TimestampOrganizer which protects the ordering of changes in cases when the same row
6464
// is altered multiple times in the same event.
65-
// this.microsecondTransactionOffset = null; // transactionCounter * 100; // one inc <=> 0.1ms
65+
// this.microsecondTransactionOffset = null; // transactionCounter * 100; // one inc <=> 0.1ms
6666

6767
this.eventType = eventType;
6868

mysql-replicator-augmenter-model/src/main/java/com/booking/replication/augmenter/model/schema/ColumnSchema.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public ColumnSchema(
2828
boolean nullable,
2929
String key,
3030
String valueDefault,
31-
String extra
32-
) {
31+
String extra) {
3332
this.name = name;
3433
this.dataType = dataType;
3534
this.columnType = columnType;

mysql-replicator-augmenter-model/src/main/java/com/booking/replication/augmenter/model/schema/FullTableName.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@ public FullTableName(String database, String name) {
1717
}
1818

1919
private String cleaned(String name) {
20-
if(name == null) return name;
20+
if (name == null) {
21+
return name;
22+
}
23+
2124
name = name.replaceAll("`", "");
25+
2226
if ( name.contains(".") ) {
2327
return name.split("\\.")[1];
2428
}
29+
2530
return name;
2631
}
2732

mysql-replicator-augmenter-model/src/main/java/com/booking/replication/augmenter/model/schema/SchemaAtPositionCache.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ public SchemaAtPositionCache deepCopy() {
6969
new String(tableSchema.getFullTableName().getName())
7070
);
7171

72-
for(ColumnSchema columnSchema : tableSchema.getColumnSchemas()) {
73-
ColumnSchema columnSchemaCopy = columnSchema.deepCopy();
74-
clonedColumnSchemaList.add(columnSchemaCopy);
72+
for (ColumnSchema columnSchema : tableSchema.getColumnSchemas()) {
73+
ColumnSchema columnSchemaCopy = columnSchema.deepCopy();
74+
clonedColumnSchemaList.add(columnSchemaCopy);
7575
}
7676

7777
TableSchema tableSchemaClone = new TableSchema(fullTableNameCloned, clonedColumnSchemaList, create);

mysql-replicator-commons/src/main/java/com/booking/replication/commons/checkpoint/GTID.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.io.Serializable;
44

55
@SuppressWarnings("unused")
6-
public class GTID implements Serializable, Comparable<GTID>{
6+
public class GTID implements Serializable, Comparable<GTID> {
77
private GTIDType type;
88
private String value;
99
private byte flags;

mysql-replicator-commons/src/main/java/com/booking/replication/commons/metrics/JMXMetrics.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public JMXMetrics(Map<String, Object> configuration) {
1212

1313
private static JMXMetrics instance;
1414

15-
public static JMXMetrics getInstance(Map<String, Object> configuration){
16-
if(instance == null){
15+
public static JMXMetrics getInstance(Map<String, Object> configuration) {
16+
if (instance == null) {
1717
instance = new JMXMetrics(configuration);
1818
}
1919
return instance;

0 commit comments

Comments
 (0)