Skip to content

Commit dcc84ae

Browse files
authored
chore: add code formatter (#422)
1 parent de1c580 commit dcc84ae

File tree

76 files changed

+1697
-1299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1697
-1299
lines changed

.github/workflows/units.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,13 @@ jobs:
1616
java-version: ${{matrix.java}}
1717
- run: java -version
1818
- run: mvn -B test
19+
lint:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: actions/setup-java@v4
24+
with:
25+
distribution: zulu
26+
java-version: 8
27+
- run: java -version
28+
- run: mvn com.coveo:fmt-maven-plugin:check -B -ntp

docs/contributing.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ use GitHub pull requests for this purpose. Consult
2222
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
2323
information on using pull requests.
2424

25+
## Code Formatting
26+
27+
Run the following command to format the code:
28+
29+
```shell
30+
mvn com.coveo:fmt-maven-plugin:format
31+
```
32+
2533
## Community Guidelines
2634

2735
This project follows [Google's Open Source Community

pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@
255255
<artifactId>serviceloader-maven-plugin</artifactId>
256256
<version>1.4.0</version>
257257
</plugin>
258+
<plugin>
259+
<groupId>com.coveo</groupId>
260+
<artifactId>fmt-maven-plugin</artifactId>
261+
<version>2.9</version>
262+
</plugin>
258263
</plugins>
259264
</pluginManagement>
260265
<plugins>
@@ -310,6 +315,17 @@
310315
</execution>
311316
</executions>
312317
</plugin>
318+
<plugin>
319+
<groupId>com.coveo</groupId>
320+
<artifactId>fmt-maven-plugin</artifactId>
321+
<executions>
322+
<execution>
323+
<goals>
324+
<goal>format</goal>
325+
</goals>
326+
</execution>
327+
</executions>
328+
</plugin>
313329
</plugins>
314330
</build>
315331
<profiles>

src/main/java/liquibase/ext/spanner/CloudSpanner.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,24 @@
1313
*/
1414
package liquibase.ext.spanner;
1515

16+
import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE;
17+
import static java.time.format.DateTimeFormatter.ISO_LOCAL_TIME;
18+
1619
import com.google.cloud.spanner.Type;
1720
import com.google.cloud.spanner.jdbc.CloudSpannerJdbcConnection;
1821
import java.sql.DriverManager;
1922
import java.sql.SQLException;
23+
import java.text.ParseException;
24+
import java.time.Instant;
25+
import java.time.OffsetDateTime;
26+
import java.time.ZoneOffset;
27+
import java.util.Date;
2028
import liquibase.Scope;
2129
import liquibase.database.AbstractJdbcDatabase;
2230
import liquibase.database.DatabaseConnection;
2331
import liquibase.database.OfflineConnection;
2432
import liquibase.database.jvm.JdbcConnection;
2533
import liquibase.util.ISODateFormat;
26-
import java.text.ParseException;
27-
import java.time.Instant;
28-
import java.time.OffsetDateTime;
29-
import java.time.ZoneOffset;
30-
import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE;
31-
import static java.time.format.DateTimeFormatter.ISO_LOCAL_TIME;
32-
import java.util.Date;
3334

3435
public class CloudSpanner extends AbstractJdbcDatabase implements ICloudSpanner {
3536

@@ -47,7 +48,7 @@ public CloudSpanner() {
4748
public java.lang.Integer getDefaultPort() {
4849
return 9010;
4950
}
50-
51+
5152
@Override
5253
public boolean dataTypeIsNotModifiable(final String typeName) {
5354
// All data types are returned including the length by the JDBC driver
@@ -137,17 +138,19 @@ public void setConnection(final DatabaseConnection conn) {
137138
// The latter should be safe, even if the caller uses the connection for other purposes, as
138139
// even if the connection was not replaced it would have been closed by Liquibase at the same
139140
// moment.
140-
if (!(conn instanceof CloudSpannerConnection) && conn instanceof JdbcConnection
141-
&& ((JdbcConnection) conn)
142-
.getUnderlyingConnection() instanceof CloudSpannerJdbcConnection) {
141+
if (!(conn instanceof CloudSpannerConnection)
142+
&& conn instanceof JdbcConnection
143+
&& ((JdbcConnection) conn).getUnderlyingConnection()
144+
instanceof CloudSpannerJdbcConnection) {
143145
// The underlying connection is a Spanner JDBC connection. Check whether it already included a
144146
// user-agent string.
145147
if (!conn.getURL().contains("userAgent=")) {
146148
// The underlying connection does not use a specific user-agent string. Create a replacement
147149
// connection that will be used by Liquibase with the correct user-agent.
148150
try {
149-
connectionToUse = new CloudSpannerConnection(
150-
DriverManager.getConnection(conn.getURL() + ";userAgent=sp-liq"), conn);
151+
connectionToUse =
152+
new CloudSpannerConnection(
153+
DriverManager.getConnection(conn.getURL() + ";userAgent=sp-liq"), conn);
151154
} catch (SQLException e) {
152155
// Ignore and use the original connection. This could for example happen if the user is
153156
// using an older version of the Spanner JDBC driver that does not support this user-agent

src/main/java/liquibase/ext/spanner/CloudSpannerConnection.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
/**
22
* Copyright 2021 Google LLC
33
*
4-
* <p>
5-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6-
* in compliance with the License. You may obtain a copy of the License at
4+
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
76
*
8-
* <p>
9-
* https://www.apache.org/licenses/LICENSE-2.0
7+
* <p>https://www.apache.org/licenses/LICENSE-2.0
108
*
11-
* <p>
12-
* Unless required by applicable law or agreed to in writing, software distributed under the License
13-
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14-
* or implied. See the License for the specific language governing permissions and limitations under
15-
* the License.
9+
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
* express or implied. See the License for the specific language governing permissions and
12+
* limitations under the License.
1613
*/
1714
package liquibase.ext.spanner;
1815

@@ -75,5 +72,4 @@ public void open(String url, Driver driverObject, Properties driverProperties)
7572
}
7673
super.open(url, driverObject, driverProperties);
7774
}
78-
7975
}

src/main/java/liquibase/ext/spanner/ICloudSpanner.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
import liquibase.database.Database;
44

5-
public interface ICloudSpanner extends Database {
6-
}
5+
public interface ICloudSpanner extends Database {}

src/main/java/liquibase/ext/spanner/change/AddColumnChangeSpanner.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
import liquibase.statement.SqlStatement;
2222
import liquibase.statement.core.UpdateStatement;
2323

24-
@DatabaseChange(name="addColumn", description = "Adds a new column to an existing table", priority = ChangeMetaData.PRIORITY_DATABASE, appliesTo = "table")
24+
@DatabaseChange(
25+
name = "addColumn",
26+
description = "Adds a new column to an existing table",
27+
priority = ChangeMetaData.PRIORITY_DATABASE,
28+
appliesTo = "table")
2529
public class AddColumnChangeSpanner extends AddColumnChange {
2630

2731
@Override

src/main/java/liquibase/ext/spanner/change/CreateTableChangeSpanner.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,24 @@
2020
import liquibase.ext.spanner.ICloudSpanner;
2121
import liquibase.ext.spanner.sqlgenerator.CreateTableStatementSpanner;
2222

23-
/** Custom implementation for Cloud Spanner that enables the creation of nullable primary key columns. */
24-
@DatabaseChange(name="createTable", description = "Create Table", priority = ChangeMetaData.PRIORITY_DATABASE)
23+
/**
24+
* Custom implementation for Cloud Spanner that enables the creation of nullable primary key
25+
* columns.
26+
*/
27+
@DatabaseChange(
28+
name = "createTable",
29+
description = "Create Table",
30+
priority = ChangeMetaData.PRIORITY_DATABASE)
2531
public class CreateTableChangeSpanner extends CreateTableChange {
2632

2733
@Override
2834
public boolean supports(Database database) {
2935
return (database instanceof ICloudSpanner);
3036
}
31-
37+
3238
@Override
3339
protected CreateTableStatementSpanner generateCreateTableStatement() {
34-
return new CreateTableStatementSpanner(getCatalogName(), getSchemaName(), getTableName(), getRemarks(), getTableType());
40+
return new CreateTableStatementSpanner(
41+
getCatalogName(), getSchemaName(), getTableName(), getRemarks(), getTableType());
3542
}
36-
3743
}

src/main/java/liquibase/ext/spanner/change/DropAllForeignKeyConstraintsChangeSpanner.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,25 @@
1818
import liquibase.ext.spanner.ICloudSpanner;
1919
import liquibase.statement.SqlStatement;
2020

21-
@DatabaseChange(name="dropAllForeignKeyConstraints", description = "Drops all foreign key constraints for a table", priority = ChangeMetaData.PRIORITY_DATABASE, appliesTo = "table")
21+
@DatabaseChange(
22+
name = "dropAllForeignKeyConstraints",
23+
description = "Drops all foreign key constraints for a table",
24+
priority = ChangeMetaData.PRIORITY_DATABASE,
25+
appliesTo = "table")
2226
public class DropAllForeignKeyConstraintsChangeSpanner extends DropAllForeignKeyConstraintsChange {
2327

2428
@Override
2529
public boolean supports(Database database) {
2630
return (database instanceof ICloudSpanner);
2731
}
28-
32+
2933
public SqlStatement[] generateStatements(Database database) {
3034
List<SqlStatement> sqlStatements = new ArrayList<>();
31-
35+
3236
JdbcConnection connection = (JdbcConnection) database.getConnection();
33-
try (PreparedStatement ps = connection.prepareStatement("SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_CATALOG=? AND TABLE_SCHEMA=? AND TABLE_NAME=? AND CONSTRAINT_TYPE='FOREIGN KEY'")) {
37+
try (PreparedStatement ps =
38+
connection.prepareStatement(
39+
"SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_CATALOG=? AND TABLE_SCHEMA=? AND TABLE_NAME=? AND CONSTRAINT_TYPE='FOREIGN KEY'")) {
3440
ps.setString(1, MoreObjects.firstNonNull(getBaseTableCatalogName(), ""));
3541
ps.setString(2, MoreObjects.firstNonNull(getBaseTableSchemaName(), ""));
3642
ps.setString(3, getBaseTableName());
@@ -45,10 +51,10 @@ public SqlStatement[] generateStatements(Database database) {
4551
}
4652
}
4753
} catch (SQLException | DatabaseException e) {
48-
throw new UnexpectedLiquibaseException(String.format("Could not retrieve foreign keys for table %s", getBaseTableName()), e);
54+
throw new UnexpectedLiquibaseException(
55+
String.format("Could not retrieve foreign keys for table %s", getBaseTableName()), e);
4956
}
50-
57+
5158
return sqlStatements.toArray(new SqlStatement[sqlStatements.size()]);
5259
}
53-
5460
}

src/main/java/liquibase/ext/spanner/change/MergeColumnsChangeSpanner.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@
3131
* Cloud Spanner-specific implementation of {@link MergeColumnChange}. Cloud Spanner requires all
3232
* UPDATE and DELETE statements to include a WHERE clause, even when all rows should be
3333
* updated/deleted. This feature is a safety precaution against accidental updates/deletes.
34-
*
35-
* {@link SpannerMergeColumnsChange} will use a Partitioned DML statement to fill the data in the new column.
34+
*
35+
* <p>{@link SpannerMergeColumnsChange} will use a Partitioned DML statement to fill the data in the
36+
* new column.
3637
*/
37-
@DatabaseChange(name = "mergeColumns",
38-
description = "Concatenates the values in two columns, joins them by with string, and stores the resulting value in a new column.",
38+
@DatabaseChange(
39+
name = "mergeColumns",
40+
description =
41+
"Concatenates the values in two columns, joins them by with string, and stores the resulting value in a new column.",
3942
priority = ChangeMetaData.PRIORITY_DATABASE)
4043
public class MergeColumnsChangeSpanner extends MergeColumnChange {
4144

@@ -55,12 +58,17 @@ public SqlStatement[] generateStatements(final Database database) {
5558

5659
statements.add(new RawSqlStatement("SET AUTOCOMMIT=TRUE"));
5760
statements.add(new RawSqlStatement("SET AUTOCOMMIT_DML_MODE='PARTITIONED_NON_ATOMIC'"));
58-
String updateStatement = "UPDATE "
59-
+ database.escapeTableName(getCatalogName(), getSchemaName(), getTableName()) + " SET "
60-
+ database.escapeObjectName(getFinalColumnName(), Column.class) + " = "
61-
+ database.getConcatSql(database.escapeObjectName(getColumn1Name(), Column.class),
62-
"'" + getJoinString() + "'", database.escapeObjectName(getColumn2Name(), Column.class))
63-
+ " WHERE TRUE";
61+
String updateStatement =
62+
"UPDATE "
63+
+ database.escapeTableName(getCatalogName(), getSchemaName(), getTableName())
64+
+ " SET "
65+
+ database.escapeObjectName(getFinalColumnName(), Column.class)
66+
+ " = "
67+
+ database.getConcatSql(
68+
database.escapeObjectName(getColumn1Name(), Column.class),
69+
"'" + getJoinString() + "'",
70+
database.escapeObjectName(getColumn2Name(), Column.class))
71+
+ " WHERE TRUE";
6472
statements.add(new RawSqlStatement(updateStatement));
6573
statements.add(new RawSqlStatement("SET AUTOCOMMIT_DML_MODE='TRANSACTIONAL'"));
6674

@@ -80,5 +88,4 @@ public SqlStatement[] generateStatements(final Database database) {
8088

8189
return statements.toArray(new SqlStatement[statements.size()]);
8290
}
83-
8491
}

0 commit comments

Comments
 (0)