diff --git a/java/client/src/main/java/io/vitess/client/cursor/FieldMap.java b/java/client/src/main/java/io/vitess/client/cursor/FieldMap.java index 454f99a21a3..c4520bb6dea 100644 --- a/java/client/src/main/java/io/vitess/client/cursor/FieldMap.java +++ b/java/client/src/main/java/io/vitess/client/cursor/FieldMap.java @@ -19,13 +19,17 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.collect.ImmutableList; -import io.vitess.proto.Query.Field; import java.util.List; import java.util.Map; + import javax.annotation.Nullable; + import org.apache.commons.collections4.map.CaseInsensitiveMap; +import com.google.common.collect.ImmutableList; + +import io.vitess.proto.Query.Field; + /** * A wrapper for {@code List} that also facilitates lookup by field name. * diff --git a/java/jdbc/src/main/java/io/vitess/jdbc/ConnectionProperties.java b/java/jdbc/src/main/java/io/vitess/jdbc/ConnectionProperties.java index 34e5bf3c243..269a02703aa 100644 --- a/java/jdbc/src/main/java/io/vitess/jdbc/ConnectionProperties.java +++ b/java/jdbc/src/main/java/io/vitess/jdbc/ConnectionProperties.java @@ -207,21 +207,9 @@ public class ConnectionProperties { "Should the driver treat java.util.Date as a TIMESTAMP for the purposes of PreparedStatement.setObject()", true); - private LongConnectionProperty queryTimeout = new LongConnectionProperty( - "queryTimeout", - "The default query timeout, in millis, to use for queries which do not explicitly setQueryTimeout", - Constants.DEFAULT_TIMEOUT - ); - - private LongConnectionProperty connectionTimeout = new LongConnectionProperty( - "connectionTimeout", - "The timeout, in millis, to use when creating new gRPC connections", - Constants.CONNECTION_TIMEOUT - ); - - private LongConnectionProperty transactionTimeout = new LongConnectionProperty( - "transactionTimeout", - "The timeout, in millis, to use when committing or rolling back transactions", + private LongConnectionProperty timeout = new LongConnectionProperty( + "timeout", + "The default timeout, in millis, to use for queries, connections, and transaction commit/rollback. Query timeout can be overridden by explicitly calling setQueryTimeout", Constants.DEFAULT_TIMEOUT ); @@ -480,28 +468,12 @@ public void setTreatUtilDateAsTimestamp(boolean treatUtilDateAsTimestamp) { this.treatUtilDateAsTimestamp.setValue(treatUtilDateAsTimestamp); } - public long getQueryTimeout() { - return queryTimeout.getValueAsLong(); - } - - public void setQueryTimeout(long queryTimeout) { - this.queryTimeout.setValue(queryTimeout); - } - - public long getConnectionTimeout() { - return connectionTimeout.getValueAsLong(); - } - - public void setConnectionTimeout(long connectionTimeout) { - this.connectionTimeout.setValue(connectionTimeout); - } - - public long getTransactionTimeout() { - return transactionTimeout.getValueAsLong(); + public long getTimeout() { + return timeout.getValueAsLong(); } - public void setTransactionTimeout(long transactionTimeout) { - this.transactionTimeout.setValue(transactionTimeout); + public void setTimeout(long timeout) { + this.timeout.setValue(timeout); } public String getTarget() { diff --git a/java/jdbc/src/main/java/io/vitess/jdbc/VitessConnection.java b/java/jdbc/src/main/java/io/vitess/jdbc/VitessConnection.java index c04d1ed7dd9..55f8a51d9ec 100644 --- a/java/jdbc/src/main/java/io/vitess/jdbc/VitessConnection.java +++ b/java/jdbc/src/main/java/io/vitess/jdbc/VitessConnection.java @@ -172,7 +172,7 @@ public void commit() throws SQLException { checkAutoCommit(Constants.SQLExceptionMessages.COMMIT_WHEN_AUTO_COMMIT_TRUE); try { if (isInTransaction()) { - Context context = createContext(getTransactionTimeout()); + Context context = createContext(getTimeout()); this.vtGateTx.commit(context, getTwopcEnabled()).checkedGet(); } } finally { @@ -191,7 +191,7 @@ public void rollback() throws SQLException { checkAutoCommit(Constants.SQLExceptionMessages.ROLLBACK_WHEN_AUTO_COMMIT_TRUE); try { if (isInTransaction()) { - Context context = createContext(getTransactionTimeout()); + Context context = createContext(getTimeout()); this.vtGateTx.rollback(context).checkedGet(); } } finally { diff --git a/java/jdbc/src/main/java/io/vitess/jdbc/VitessStatement.java b/java/jdbc/src/main/java/io/vitess/jdbc/VitessStatement.java index 4e3c47db732..8b15eeac96f 100644 --- a/java/jdbc/src/main/java/io/vitess/jdbc/VitessStatement.java +++ b/java/jdbc/src/main/java/io/vitess/jdbc/VitessStatement.java @@ -78,7 +78,7 @@ public VitessStatement(VitessConnection vitessConnection) { public VitessStatement(VitessConnection vitessConnection, int resultSetType, int resultSetConcurrency) { this.vitessConnection = vitessConnection; - this.queryTimeoutInMillis = vitessConnection.getQueryTimeout(); + this.queryTimeoutInMillis = vitessConnection.getTimeout(); this.vitessResultSet = null; this.resultSetType = resultSetType; this.resultSetConcurrency = resultSetConcurrency; @@ -268,7 +268,7 @@ public void setQueryTimeout(int seconds) throws SQLException { Constants.SQLExceptionMessages.ILLEGAL_VALUE_FOR + "query timeout"); } this.queryTimeoutInMillis = - (0 == seconds) ? vitessConnection.getQueryTimeout() : (long) seconds * 1000; + (0 == seconds) ? vitessConnection.getTimeout() : (long) seconds * 1000; } /** diff --git a/java/jdbc/src/main/java/io/vitess/jdbc/VitessVTGateManager.java b/java/jdbc/src/main/java/io/vitess/jdbc/VitessVTGateManager.java index a5954b9db97..e1a0ebac459 100644 --- a/java/jdbc/src/main/java/io/vitess/jdbc/VitessVTGateManager.java +++ b/java/jdbc/src/main/java/io/vitess/jdbc/VitessVTGateManager.java @@ -108,7 +108,7 @@ private static void updateVtGateConnHashMap(String identifier, VitessJDBCUrl.Hos private static VTGateConn getVtGateConn(VitessJDBCUrl.HostInfo hostInfo, VitessConnection connection) { final String username = connection.getUsername(); final String keyspace = connection.getKeyspace(); - final Context context = CommonUtils.createContext(username,connection.getConnectionTimeout()); + final Context context = CommonUtils.createContext(username,connection.getTimeout()); RetryingInterceptorConfig retryingConfig = getRetryingInterceptorConfig(connection); RpcClient client; if (connection.getUseSSL()) { diff --git a/java/jdbc/src/test/java/io/vitess/jdbc/ConnectionPropertiesTest.java b/java/jdbc/src/test/java/io/vitess/jdbc/ConnectionPropertiesTest.java index ef1916c1fc8..e09ed798051 100644 --- a/java/jdbc/src/test/java/io/vitess/jdbc/ConnectionPropertiesTest.java +++ b/java/jdbc/src/test/java/io/vitess/jdbc/ConnectionPropertiesTest.java @@ -31,7 +31,7 @@ public class ConnectionPropertiesTest { - private static final int NUM_PROPS = 34; + private static final int NUM_PROPS = 32; @Test public void testReflection() throws Exception { diff --git a/java/jdbc/src/test/java/io/vitess/jdbc/VitessStatementTest.java b/java/jdbc/src/test/java/io/vitess/jdbc/VitessStatementTest.java index 6548a1bdbc8..2b427d96488 100644 --- a/java/jdbc/src/test/java/io/vitess/jdbc/VitessStatementTest.java +++ b/java/jdbc/src/test/java/io/vitess/jdbc/VitessStatementTest.java @@ -530,7 +530,7 @@ private void testExecute(int fetchSize, boolean simpleExecute, boolean shouldRun @Test public void testGetQueryTimeout() throws SQLException { VitessConnection mockConn = PowerMockito.mock(VitessConnection.class); - Mockito.when(mockConn.getQueryTimeout()).thenReturn((long)Constants.DEFAULT_TIMEOUT); + Mockito.when(mockConn.getTimeout()).thenReturn((long)Constants.DEFAULT_TIMEOUT); VitessStatement statement = new VitessStatement(mockConn); Assert.assertEquals(30, statement.getQueryTimeout()); @@ -538,7 +538,7 @@ private void testExecute(int fetchSize, boolean simpleExecute, boolean shouldRun @Test public void testGetQueryTimeoutZeroDefault() throws SQLException { VitessConnection mockConn = PowerMockito.mock(VitessConnection.class); - Mockito.when(mockConn.getQueryTimeout()).thenReturn(0L); + Mockito.when(mockConn.getTimeout()).thenReturn(0L); VitessStatement statement = new VitessStatement(mockConn); Assert.assertEquals(0, statement.getQueryTimeout()); @@ -546,7 +546,7 @@ private void testExecute(int fetchSize, boolean simpleExecute, boolean shouldRun @Test public void testSetQueryTimeout() throws SQLException { VitessConnection mockConn = PowerMockito.mock(VitessConnection.class); - Mockito.when(mockConn.getQueryTimeout()).thenReturn((long)Constants.DEFAULT_TIMEOUT); + Mockito.when(mockConn.getTimeout()).thenReturn((long)Constants.DEFAULT_TIMEOUT); VitessStatement statement = new VitessStatement(mockConn);