diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java index cdfae0683efde..3b09e073bbd5c 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java @@ -171,7 +171,7 @@ public final int getUpdateCount() throws SQLException { } private int accumulate() throws SQLException { - long result = 0; + long result = 0L; boolean hasResult = false; for (Statement each : getRoutedStatements()) { int updateCount = each.getUpdateCount(); diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java index 1989b586f8489..ee3ed65614258 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java @@ -122,7 +122,7 @@ private Map getTrafficDataSourceMap(final String databaseNam private Map createDataSourcePoolPropertiesMap(final Collection instances, final Collection users, final DataSourcePoolProperties propsSample, final String schema) { - Map result = new LinkedHashMap<>(); + Map result = new LinkedHashMap<>(instances.size(), 1F); for (InstanceMetaData each : instances) { result.put(each.getId(), createDataSourcePoolProperties((ProxyInstanceMetaData) each, users, propsSample, schema)); } diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetUtils.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetUtils.java index fa5a3989604ec..f7fb31dd9225e 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetUtils.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetUtils.java @@ -50,7 +50,7 @@ public static Map createColumnLabelAndIndexMap(final SQLStateme if (selectContainsEnhancedTable && hasSelectExpandProjections(sqlStatementContext)) { return createColumnLabelAndIndexMapWithExpandProjections((SelectStatementContext) sqlStatementContext); } - Map result = new CaseInsensitiveMap<>(resultSetMetaData.getColumnCount(), 1); + Map result = new CaseInsensitiveMap<>(resultSetMetaData.getColumnCount(), 1F); for (int columnIndex = resultSetMetaData.getColumnCount(); columnIndex > 0; columnIndex--) { result.put(resultSetMetaData.getColumnLabel(columnIndex), columnIndex); } diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/state/circuit/resultset/CircuitBreakerResultSet.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/state/circuit/resultset/CircuitBreakerResultSet.java index baa7819fac50f..679d6500103ca 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/state/circuit/resultset/CircuitBreakerResultSet.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/state/circuit/resultset/CircuitBreakerResultSet.java @@ -117,32 +117,32 @@ public int getInt(final String columnLabel) { @Override public long getLong(final int columnIndex) { - return 0; + return 0L; } @Override public long getLong(final String columnLabel) { - return 0; + return 0L; } @Override public float getFloat(final int columnIndex) { - return 0; + return 0F; } @Override public float getFloat(final String columnLabel) { - return 0; + return 0F; } @Override public double getDouble(final int columnIndex) { - return 0; + return 0D; } @Override public double getDouble(final String columnLabel) { - return 0; + return 0D; } @Override diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/api/ShardingSphereDataSourceFactoryTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/api/ShardingSphereDataSourceFactoryTest.java index c1f3e2aeb95ef..64b1d82f54b72 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/api/ShardingSphereDataSourceFactoryTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/api/ShardingSphereDataSourceFactoryTest.java @@ -27,7 +27,7 @@ import javax.sql.DataSource; import java.sql.SQLException; -import java.util.HashMap; +import java.util.Collections; import java.util.LinkedList; import java.util.Properties; @@ -43,19 +43,19 @@ void assertCreateDataSourceWithModeConfiguration() throws SQLException { @Test void assertCreateDataSourceWithDatabaseNameAndModeConfiguration() throws SQLException { - assertDataSource(ShardingSphereDataSourceFactory.createDataSource("test_db", new ModeConfiguration("Standalone", null), new HashMap<>(), null, null), "test_db"); + assertDataSource(ShardingSphereDataSourceFactory.createDataSource("test_db", new ModeConfiguration("Standalone", null), Collections.emptyMap(), null, null), "test_db"); } @Test void assertCreateDataSourceWithAllParametersForMultipleDataSourcesWithDefaultDatabaseName() throws SQLException { assertDataSource(ShardingSphereDataSourceFactory.createDataSource( - new ModeConfiguration("Standalone", null), new HashMap<>(), new LinkedList<>(), new Properties()), DefaultDatabase.LOGIC_NAME); + new ModeConfiguration("Standalone", null), Collections.emptyMap(), new LinkedList<>(), new Properties()), DefaultDatabase.LOGIC_NAME); } @Test void assertCreateDataSourceWithAllParametersForMultipleDataSources() throws SQLException { assertDataSource(ShardingSphereDataSourceFactory.createDataSource( - "test_db", new ModeConfiguration("Standalone", null), new HashMap<>(), new LinkedList<>(), new Properties()), "test_db"); + "test_db", new ModeConfiguration("Standalone", null), Collections.emptyMap(), new LinkedList<>(), new Properties()), "test_db"); } @Test diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/ResultSetGetterAdapterTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/ResultSetGetterAdapterTest.java index 094887aa125c1..1a71303be3a3e 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/ResultSetGetterAdapterTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/ResultSetGetterAdapterTest.java @@ -191,15 +191,15 @@ void assertGetBigDecimalColumnLabelWithScale() throws SQLException { @Test void assertGetBytesForColumnIndex() throws SQLException { MergedResult mergedResult = mock(MergedResult.class); - when(mergedResult.getValue(1, byte[].class)).thenReturn(new byte[]{1}); - assertThat(mockShardingSphereResultSet(mergedResult).getBytes(1), is(new byte[]{1})); + when(mergedResult.getValue(1, byte[].class)).thenReturn(new byte[]{(byte) 1}); + assertThat(mockShardingSphereResultSet(mergedResult).getBytes(1), is(new byte[]{(byte) 1})); } @Test void assertGetBytesForColumnLabel() throws SQLException { MergedResult mergedResult = mock(MergedResult.class); - when(mergedResult.getValue(1, byte[].class)).thenReturn(new byte[]{1}); - assertThat(mockShardingSphereResultSet(mergedResult).getBytes("col"), is(new byte[]{1})); + when(mergedResult.getValue(1, byte[].class)).thenReturn(new byte[]{(byte) 1}); + assertThat(mockShardingSphereResultSet(mergedResult).getBytes("col"), is(new byte[]{(byte) 1})); } @Test diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java index cecee9d459cfb..1567a6c823306 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java @@ -81,7 +81,7 @@ void assertNewConstructorWithAllArguments() throws Exception { void assertRemoveGlobalRuleConfiguration() throws Exception { Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS); when(connection.getMetaData().getURL()).thenReturn("jdbc:mock://127.0.0.1/foo_ds"); - CacheOption cacheOption = new CacheOption(1024, 1024); + CacheOption cacheOption = new CacheOption(1024, 1024L); SQLParserRuleConfiguration sqlParserRuleConfig = new SQLParserRuleConfiguration(cacheOption, cacheOption); try ( ShardingSphereDataSource actual = new ShardingSphereDataSource(DefaultDatabase.LOGIC_NAME, @@ -150,8 +150,8 @@ private HikariDataSource createHikariDataSource() { result.setPassword("root"); result.setMaximumPoolSize(10); result.setMinimumIdle(2); - result.setConnectionTimeout(15 * 1000L); - result.setIdleTimeout(40 * 1000L); + result.setConnectionTimeout(15L * 1000L); + result.setIdleTimeout(40L * 1000L); return result; } } diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationPreparedStatementTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationPreparedStatementTest.java index 7cfcd73fa2d9d..942585e63590f 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationPreparedStatementTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationPreparedStatementTest.java @@ -86,7 +86,7 @@ void assertSetNClobForReader() { @Test void assertSetNClobForReaderAndLength() { - assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSpherePreparedStatement.setNClob(1, new StringReader(""), 1)); + assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSpherePreparedStatement.setNClob(1, new StringReader(""), 1L)); } @Test @@ -96,7 +96,7 @@ void assertSetNCharacterStream() { @Test void assertSetNCharacterStreamWithLength() { - assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSpherePreparedStatement.setNCharacterStream(1, new StringReader(""), 1)); + assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSpherePreparedStatement.setNCharacterStream(1, new StringReader(""), 1L)); } @Test diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedUpdateOperationResultSetTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedUpdateOperationResultSetTest.java index 8c573fa2f0ef5..b82fa5318be27 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedUpdateOperationResultSetTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedUpdateOperationResultSetTest.java @@ -303,12 +303,12 @@ void assertUpdateNCharacterStreamForColumnLabel() { @Test void assertUpdateNCharacterStreamForColumnIndexWithLength() { - assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSphereResultSet.updateNCharacterStream(1, new StringReader(""), 1)); + assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSphereResultSet.updateNCharacterStream(1, new StringReader(""), 1L)); } @Test void assertUpdateNCharacterStreamForColumnLabelWithLength() { - assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSphereResultSet.updateNCharacterStream("label", new StringReader(""), 1)); + assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSphereResultSet.updateNCharacterStream("label", new StringReader(""), 1L)); } @Test @@ -363,12 +363,12 @@ void assertUpdateBlobForColumnLabelWithInputStream() { @Test void assertUpdateBlobForColumnIndexWithInputStreamAndLength() { - assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSphereResultSet.updateBlob(1, System.in, 100)); + assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSphereResultSet.updateBlob(1, System.in, 100L)); } @Test void assertUpdateBlobForColumnLabelWithInputStreamAndLength() { - assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSphereResultSet.updateBlob("label", System.in, 100)); + assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSphereResultSet.updateBlob("label", System.in, 100L)); } @Test @@ -393,12 +393,12 @@ void assertUpdateClobForColumnLabelWithInputStream() { @Test void assertUpdateClobForColumnIndexWithInputStreamAndLength() { - assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSphereResultSet.updateClob(1, new StringReader(""), 100)); + assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSphereResultSet.updateClob(1, new StringReader(""), 100L)); } @Test void assertUpdateClobForColumnLabelWithInputStreamAndLength() { - assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSphereResultSet.updateClob("label", new StringReader(""), 100)); + assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSphereResultSet.updateClob("label", new StringReader(""), 100L)); } @Test @@ -423,12 +423,12 @@ void assertUpdateNClobForColumnLabelWithInputStream() { @Test void assertUpdateNClobForColumnIndexWithInputStreamAndLength() { - assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSphereResultSet.updateNClob(1, new StringReader(""), 100)); + assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSphereResultSet.updateNClob(1, new StringReader(""), 100L)); } @Test void assertUpdateNClobForColumnLabelWithInputStreamAndLength() { - assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSphereResultSet.updateNClob("label", new StringReader(""), 100)); + assertThrows(SQLFeatureNotSupportedException.class, () -> shardingSphereResultSet.updateNClob("label", new StringReader(""), 100L)); } @Test diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java index 554873c3b6e7e..facf443929f92 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java @@ -42,7 +42,7 @@ import java.sql.Connection; import java.util.Arrays; -import java.util.LinkedHashMap; +import java.util.Collections; import java.util.Map; import java.util.Properties; @@ -71,11 +71,9 @@ void setUp() { } private Map mockDatabases() { - Map result = new LinkedHashMap<>(); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, Answers.RETURNS_DEEP_STUBS); when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); - result.put(DefaultDatabase.LOGIC_NAME, database); - return result; + return Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database); } @Test diff --git a/kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedPrivilegeProvider.java b/kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedPrivilegeProvider.java index c51f4b7a183ea..8128c4b04a5ec 100644 --- a/kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedPrivilegeProvider.java +++ b/kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedPrivilegeProvider.java @@ -45,7 +45,7 @@ public final class DatabasePermittedPrivilegeProvider implements PrivilegeProvid @Override public void init(final Properties props) { - userDatabaseMappings = props.getProperty(DatabasePermittedPrivilegeProvider.USER_DATABASE_MAPPINGS_KEY, ""); + userDatabaseMappings = props.getProperty(USER_DATABASE_MAPPINGS_KEY, ""); checkUserDatabaseMappings(); } diff --git a/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/update/AlterSQLTranslatorRuleExecutorTest.java b/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/update/AlterSQLTranslatorRuleExecutorTest.java index 91a947cdc36a3..58199c766ca71 100644 --- a/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/update/AlterSQLTranslatorRuleExecutorTest.java +++ b/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/update/AlterSQLTranslatorRuleExecutorTest.java @@ -37,20 +37,18 @@ class AlterSQLTranslatorRuleExecutorTest { - private DistSQLUpdateExecuteEngine engine; - @Test void assertExecute() { - AlterSQLTranslatorRuleStatement sqlStatement = new AlterSQLTranslatorRuleStatement(new AlgorithmSegment("Native", PropertiesBuilder.build(new Property("foo", "bar"))), Boolean.TRUE); - engine = new DistSQLUpdateExecuteEngine(sqlStatement, null, mockContextManager()); - assertDoesNotThrow(() -> engine.executeUpdate()); + AlterSQLTranslatorRuleStatement sqlStatement = new AlterSQLTranslatorRuleStatement(new AlgorithmSegment("Native", PropertiesBuilder.build(new Property("foo", "bar"))), true); + DistSQLUpdateExecuteEngine engine = new DistSQLUpdateExecuteEngine(sqlStatement, null, mockContextManager()); + assertDoesNotThrow(engine::executeUpdate); } @Test void assertExecuteWithNullOriginalSQLWhenTranslatingFailed() { AlterSQLTranslatorRuleStatement sqlStatement = new AlterSQLTranslatorRuleStatement(new AlgorithmSegment("Native", PropertiesBuilder.build(new Property("foo", "bar"))), null); - engine = new DistSQLUpdateExecuteEngine(sqlStatement, null, mockContextManager()); - assertDoesNotThrow(() -> engine.executeUpdate()); + DistSQLUpdateExecuteEngine engine = new DistSQLUpdateExecuteEngine(sqlStatement, null, mockContextManager()); + assertDoesNotThrow(engine::executeUpdate); } @SuppressWarnings({"rawtypes", "unchecked"}) @@ -59,12 +57,8 @@ private ContextManager mockContextManager() { SQLTranslatorRule rule = mock(SQLTranslatorRule.class); GlobalRuleDefinitionExecutor executor = mock(GlobalRuleDefinitionExecutor.class); when(executor.getRuleClass()).thenReturn(SQLTranslatorRule.class); - when(rule.getConfiguration()).thenReturn(createSQLTranslatorRuleConfiguration()); + when(rule.getConfiguration()).thenReturn(new SQLTranslatorRuleConfiguration("NATIVE", new Properties(), true)); when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(executor.getRuleClass())).thenReturn(rule); return result; } - - private SQLTranslatorRuleConfiguration createSQLTranslatorRuleConfiguration() { - return new SQLTranslatorRuleConfiguration("NATIVE", new Properties(), true); - } }