Skip to content

Commit

Permalink
[misc] code style correction
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed May 18, 2022
1 parent 43baaa0 commit a9806b4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 34 deletions.
12 changes: 8 additions & 4 deletions src/main/java/org/mariadb/jdbc/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/mariadb/jdbc/ParameterMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
Expand All @@ -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();
}
Expand All @@ -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();
Expand All @@ -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());
Expand Down

0 comments on commit a9806b4

Please sign in to comment.