From a9806b47f38e69dc4d5e69440cd6b52ef6d96179 Mon Sep 17 00:00:00 2001 From: diego Dupin Date: Wed, 18 May 2022 16:49:56 +0200 Subject: [PATCH] [misc] code style correction --- .../java/org/mariadb/jdbc/Connection.java | 12 ++-- .../org/mariadb/jdbc/ParameterMetaData.java | 2 +- .../jdbc/client/result/ResultSetMetaData.java | 2 +- .../integration/codec/DateTimeCodecTest.java | 63 ++++++++++--------- 4 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/mariadb/jdbc/Connection.java b/src/main/java/org/mariadb/jdbc/Connection.java index 6fc667127..66d52b7a8 100644 --- a/src/main/java/org/mariadb/jdbc/Connection.java +++ b/src/main/java/org/mariadb/jdbc/Connection.java @@ -59,7 +59,8 @@ public class Connection implements java.sql.Connection { */ public Connection(Configuration conf, ReentrantLock lock, Client client) { this.conf = conf; - this.forceTransactionEnd = Boolean.parseBoolean(conf.nonMappedOptions().getProperty("forceTransactionEnd", "false")); + this.forceTransactionEnd = + Boolean.parseBoolean(conf.nonMappedOptions().getProperty("forceTransactionEnd", "false")); this.lock = lock; this.exceptionFactory = client.getExceptionFactory().setConnection(this); this.client = client; @@ -200,7 +201,8 @@ public void setAutoCommit(boolean autoCommit) throws SQLException { public void commit() throws SQLException { lock.lock(); try { - if (forceTransactionEnd || (client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) { + if (forceTransactionEnd + || (client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) { client.execute(new QueryPacket("COMMIT"), false); } } finally { @@ -212,7 +214,8 @@ public void commit() throws SQLException { public void rollback() throws SQLException { lock.lock(); try { - if (forceTransactionEnd || (client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) { + if (forceTransactionEnd + || (client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) { client.execute(new QueryPacket("ROLLBACK"), true); } } finally { @@ -844,7 +847,8 @@ && getContext().getVersion().getMinorVersion() == 2 } // in transaction => rollback - if (forceTransactionEnd || (client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) { + if (forceTransactionEnd + || (client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) { client.execute(new QueryPacket("ROLLBACK"), true); } diff --git a/src/main/java/org/mariadb/jdbc/ParameterMetaData.java b/src/main/java/org/mariadb/jdbc/ParameterMetaData.java index 14c355058..0aee96fb9 100644 --- a/src/main/java/org/mariadb/jdbc/ParameterMetaData.java +++ b/src/main/java/org/mariadb/jdbc/ParameterMetaData.java @@ -89,7 +89,7 @@ public boolean isSigned(int idx) throws SQLException { @Override public int getPrecision(int idx) throws SQLException { checkIndex(idx); - return (int) params[idx - 1].getPrecision(); + return params[idx - 1].getPrecision(); } /** diff --git a/src/main/java/org/mariadb/jdbc/client/result/ResultSetMetaData.java b/src/main/java/org/mariadb/jdbc/client/result/ResultSetMetaData.java index 3187aa123..7ca3d871b 100644 --- a/src/main/java/org/mariadb/jdbc/client/result/ResultSetMetaData.java +++ b/src/main/java/org/mariadb/jdbc/client/result/ResultSetMetaData.java @@ -180,7 +180,7 @@ public String getCatalogName(int column) throws SQLException { * @throws SQLException if a database access error occurs */ public int getPrecision(final int column) throws SQLException { - return (int) getColumn(column).getPrecision(); + return getColumn(column).getPrecision(); } /** diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/DateTimeCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/DateTimeCodecTest.java index 7afb1b120..8aeaf4adc 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/DateTimeCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/DateTimeCodecTest.java @@ -45,7 +45,7 @@ public static void beforeAll2() throws SQLException { stmt.execute( "CREATE TABLE DateTimeCodec2 (id int not null primary key auto_increment, t1 DATETIME(6))"); stmt.execute( - "CREATE TABLE DateTimeCodec3 (id int not null primary key auto_increment, t1 DATETIME(6))"); + "CREATE TABLE DateTimeCodec3 (id int not null primary key auto_increment, t1 DATETIME(6))"); stmt.execute("FLUSH TABLES"); } @@ -408,36 +408,36 @@ public void getDateTimezoneTest() throws SQLException { try (Connection conGmtm8 = createCon("timezone=auto")) { getDateTimezoneTestGmtm8(conGmtm8, getPrepare(conGmtm8), TimeZone.getTimeZone("GMT-8")); } - } finally{ + } finally { TimeZone.setDefault(initialTz); } } - public void getDateTimezoneTestGmt8(Connection conGmt8, ResultSet rs, TimeZone tz) throws SQLException { + public void getDateTimezoneTestGmt8(Connection conGmt8, ResultSet rs, TimeZone tz) + throws SQLException { - assertEquals( - "2010-01-12T01:55:12+08:00", - rs.getObject(1, OffsetDateTime.class).toString()); + assertEquals("2010-01-12T01:55:12+08:00", rs.getObject(1, OffsetDateTime.class).toString()); conGmt8.createStatement().execute("TRUNCATE TABLE DateTimeCodec3"); - try (PreparedStatement prep = conGmt8.prepareStatement("INSERT INTO DateTimeCodec3 values (?,?)")) { - prep.setInt(1,-2); + try (PreparedStatement prep = + conGmt8.prepareStatement("INSERT INTO DateTimeCodec3 values (?,?)")) { + prep.setInt(1, -2); prep.setString(2, "2010-01-12 01:55:12"); prep.execute(); - prep.setInt(1,1); + prep.setInt(1, 1); prep.setObject(2, OffsetDateTime.parse("2010-01-12T01:55:12+08:00")); prep.execute(); - prep.setInt(1,2); + prep.setInt(1, 2); prep.setObject(2, OffsetDateTime.parse("2010-01-12T01:55:12+01:00")); prep.execute(); - prep.setInt(1,3); + prep.setInt(1, 3); prep.setObject(2, OffsetDateTime.parse("2010-01-12T01:55:12Z")); prep.execute(); - prep.setInt(1,4); + prep.setInt(1, 4); prep.setObject(2, OffsetDateTime.parse("2010-01-12T17:55:12-04:00")); prep.execute(); } @@ -455,10 +455,14 @@ public void getDateTimezoneTestGmt8(Connection conGmt8, ResultSet rs, TimeZone t assertEquals("2010-01-12T01:55:12+08:00", rs.getObject(2, OffsetDateTime.class).toString()); assertEquals("2010-01-12 01:55:12.0", rs.getTimestamp(2).toString()); assertEquals(1263232512000L, rs.getTimestamp(2).getTime()); - assertEquals("2010-01-12 09:55:12.0", rs.getTimestamp(2, Calendar.getInstance(TimeZone.getTimeZone("UTC"))).toString()); + assertEquals( + "2010-01-12 09:55:12.0", + rs.getTimestamp(2, Calendar.getInstance(TimeZone.getTimeZone("UTC"))).toString()); assertEquals("2010-01-12 01:55:12.000000", rs.getString(2)); assertEquals("2010-01-12", rs.getDate(2).toString()); - assertEquals("2010-01-12", rs.getDate(2, Calendar.getInstance(TimeZone.getTimeZone("UTC"))).toString()); + assertEquals( + "2010-01-12", + rs.getDate(2, Calendar.getInstance(TimeZone.getTimeZone("UTC"))).toString()); assertEquals("2010-01-12T01:55:12", rs.getObject(2, LocalDateTime.class).toString()); rs.next(); @@ -483,34 +487,33 @@ public void getDateTimezoneTestGmt8(Connection conGmt8, ResultSet rs, TimeZone t assertEquals("2010-01-13", rs.getDate(2).toString()); } conGmt8.rollback(); - } - public void getDateTimezoneTestGmtm8(Connection conGmt8, ResultSet rs, TimeZone tz) throws SQLException { + public void getDateTimezoneTestGmtm8(Connection conGmt8, ResultSet rs, TimeZone tz) + throws SQLException { - assertEquals( - "2010-01-12T01:55:12-08:00", - rs.getObject(1, OffsetDateTime.class).toString()); + assertEquals("2010-01-12T01:55:12-08:00", rs.getObject(1, OffsetDateTime.class).toString()); conGmt8.createStatement().execute("TRUNCATE TABLE DateTimeCodec3"); - try (PreparedStatement prep = conGmt8.prepareStatement("INSERT INTO DateTimeCodec3 values (?,?)")) { - prep.setInt(1,-2); + try (PreparedStatement prep = + conGmt8.prepareStatement("INSERT INTO DateTimeCodec3 values (?,?)")) { + prep.setInt(1, -2); prep.setString(2, "2010-01-12 01:55:12"); prep.execute(); - prep.setInt(1,1); + prep.setInt(1, 1); prep.setObject(2, OffsetDateTime.parse("2010-01-12T01:55:12-08:00")); prep.execute(); - prep.setInt(1,2); + prep.setInt(1, 2); prep.setObject(2, OffsetDateTime.parse("2010-01-12T01:55:12-01:00")); prep.execute(); - prep.setInt(1,3); + prep.setInt(1, 3); prep.setObject(2, OffsetDateTime.parse("2010-01-12T01:55:12Z")); prep.execute(); - prep.setInt(1,4); + prep.setInt(1, 4); prep.setObject(2, OffsetDateTime.parse("2010-01-12T17:55:12+04:00")); prep.execute(); } @@ -528,10 +531,14 @@ public void getDateTimezoneTestGmtm8(Connection conGmt8, ResultSet rs, TimeZone assertEquals("2010-01-12T01:55:12-08:00", rs.getObject(2, OffsetDateTime.class).toString()); assertEquals("2010-01-12 01:55:12.0", rs.getTimestamp(2).toString()); assertEquals(1263290112000L, rs.getTimestamp(2).getTime()); - assertEquals("2010-01-11 17:55:12.0", rs.getTimestamp(2, Calendar.getInstance(TimeZone.getTimeZone("UTC"))).toString()); + assertEquals( + "2010-01-11 17:55:12.0", + rs.getTimestamp(2, Calendar.getInstance(TimeZone.getTimeZone("UTC"))).toString()); assertEquals("2010-01-12 01:55:12.000000", rs.getString(2)); assertEquals("2010-01-12", rs.getDate(2).toString()); - assertEquals("2010-01-11", rs.getDate(2, Calendar.getInstance(TimeZone.getTimeZone("UTC"))).toString()); + assertEquals( + "2010-01-11", + rs.getDate(2, Calendar.getInstance(TimeZone.getTimeZone("UTC"))).toString()); assertEquals("2010-01-12T01:55:12", rs.getObject(2, LocalDateTime.class).toString()); rs.next(); @@ -556,8 +563,8 @@ public void getDateTimezoneTestGmtm8(Connection conGmt8, ResultSet rs, TimeZone assertEquals("2010-01-12", rs.getDate(2).toString()); } conGmt8.rollback(); - } + @Test public void getTime() throws SQLException { getTime(get());