You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/09/15 15:07:54 UTC
[shardingsphere] branch master updated: Refactor ShardingSpherePreconditions.checkState (#21005)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 1cda7cea3a2 Refactor ShardingSpherePreconditions.checkState (#21005)
1cda7cea3a2 is described below
commit 1cda7cea3a2d42a2d52c5227cd33c59f5fa6ae76
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Thu Sep 15 23:07:43 2022 +0800
Refactor ShardingSpherePreconditions.checkState (#21005)
---
.../protocol/PostgreSQLArrayParameterDecoder.java | 14 ++++-----
...MGRMySQLDatabaseDiscoveryProviderAlgorithm.java | 6 ++--
.../complex/ComplexInlineShardingAlgorithm.java | 2 +-
.../sharding/inline/InlineShardingAlgorithm.java | 2 +-
.../shardingsphere/sharding/rule/ShardingRule.java | 2 +-
.../shardingsphere/sharding/rule/TableRule.java | 2 +-
.../update/AddMigrationSourceResourceUpdater.java | 2 +-
.../type/dialect/OpenGaussDatabaseType.java | 2 +-
.../type/dialect/PostgreSQLDatabaseType.java | 2 +-
.../props/DataSourcePropertiesValidator.java | 2 +-
.../impl/driver/jdbc/type/util/ResultSetUtil.java | 2 +-
.../result/impl/memory/MemoryMergedResult.java | 2 +-
.../exception/ShardingSpherePreconditions.java | 35 ++++------------------
.../exception/ShardingSpherePreconditionsTest.java | 28 +++--------------
.../driver/jdbc/core/ShardingSphereSavepoint.java | 2 +-
.../core/connection/ShardingSphereConnection.java | 4 +--
.../core/resultset/ShardingSphereResultSet.java | 2 +-
.../core/api/impl/AbstractPipelineJobAPIImpl.java | 4 +--
.../datasource/AbstractDataSourceChecker.java | 2 +-
.../pipeline/core/importer/DataRecordMerger.java | 2 +-
.../pipeline/core/importer/DefaultImporter.java | 2 +-
.../core/util/PipelineTableMetaDataUtil.java | 4 +--
.../check/datasource/MySQLDataSourceChecker.java | 3 +-
.../pipeline/mysql/ingest/client/MySQLClient.java | 2 +-
.../SingleTableDropSchemaMetadataValidator.java | 2 +-
.../sqltranslator/jooq/JooQDialectRegistry.java | 2 +-
.../jta/datasource/swapper/DataSourceSwapper.java | 2 +-
.../vertx/VertxBackendConnection.java | 2 +-
.../handler/DatabaseRequiredBackendHandler.java | 2 +-
.../handler/ProxyBackendHandlerFactory.java | 2 +-
.../distsql/ral/RALBackendHandlerFactory.java | 2 +-
.../distsql/ral/hint/HintRALBackendHandler.java | 2 +-
.../ral/updatable/LabelInstanceHandler.java | 2 +-
.../ral/updatable/SetInstanceStatusHandler.java | 10 +++----
.../SetReadwriteSplittingStatusHandler.java | 13 ++++----
.../ral/updatable/UnlabelInstanceHandler.java | 2 +-
.../distsql/rul/RULBackendHandlerFactory.java | 2 +-
.../transaction/TransactionBackendHandler.java | 6 ++--
.../handler/transaction/TransactionSetHandler.java | 2 +-
.../handler/transaction/TransactionXAHandler.java | 2 +-
.../describe/PostgreSQLComDescribeExecutor.java | 2 +-
41 files changed, 73 insertions(+), 114 deletions(-)
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/PostgreSQLArrayParameterDecoder.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/PostgreSQLArrayParameterDecoder.java
index 5df83eedf8e..bd6f0b5eddf 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/PostgreSQLArrayParameterDecoder.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/PostgreSQLArrayParameterDecoder.java
@@ -41,7 +41,7 @@ public final class PostgreSQLArrayParameterDecoder {
* @return int array
*/
public short[] decodeInt2Array(final byte[] parameterBytes, final boolean isBinary) {
- ShardingSpherePreconditions.checkState(!isBinary, new UnsupportedSQLOperationException("binary mode"));
+ ShardingSpherePreconditions.checkState(!isBinary, () -> new UnsupportedSQLOperationException("binary mode"));
String parameterValue = new String(parameterBytes, StandardCharsets.UTF_8);
Collection<String> parameterElements = decodeText(parameterValue);
short[] result = new short[parameterElements.size()];
@@ -60,7 +60,7 @@ public final class PostgreSQLArrayParameterDecoder {
* @return int array
*/
public int[] decodeInt4Array(final byte[] parameterBytes, final boolean isBinary) {
- ShardingSpherePreconditions.checkState(!isBinary, new UnsupportedSQLOperationException("binary mode"));
+ ShardingSpherePreconditions.checkState(!isBinary, () -> new UnsupportedSQLOperationException("binary mode"));
String parameterValue = new String(parameterBytes, StandardCharsets.UTF_8);
Collection<String> parameterElements = decodeText(parameterValue);
int[] result = new int[parameterElements.size()];
@@ -79,7 +79,7 @@ public final class PostgreSQLArrayParameterDecoder {
* @return int array
*/
public long[] decodeInt8Array(final byte[] parameterBytes, final boolean isBinary) {
- ShardingSpherePreconditions.checkState(!isBinary, new UnsupportedSQLOperationException("binary mode"));
+ ShardingSpherePreconditions.checkState(!isBinary, () -> new UnsupportedSQLOperationException("binary mode"));
String parameterValue = new String(parameterBytes, StandardCharsets.UTF_8);
Collection<String> parameterElements = decodeText(parameterValue);
long[] result = new long[parameterElements.size()];
@@ -98,7 +98,7 @@ public final class PostgreSQLArrayParameterDecoder {
* @return int array
*/
public float[] decodeFloat4Array(final byte[] parameterBytes, final boolean isBinary) {
- ShardingSpherePreconditions.checkState(!isBinary, new UnsupportedSQLOperationException("binary mode"));
+ ShardingSpherePreconditions.checkState(!isBinary, () -> new UnsupportedSQLOperationException("binary mode"));
String parameterValue = new String(parameterBytes, StandardCharsets.UTF_8);
Collection<String> parameterElements = decodeText(parameterValue);
float[] result = new float[parameterElements.size()];
@@ -117,7 +117,7 @@ public final class PostgreSQLArrayParameterDecoder {
* @return int array
*/
public double[] decodeFloat8Array(final byte[] parameterBytes, final boolean isBinary) {
- ShardingSpherePreconditions.checkState(!isBinary, new UnsupportedSQLOperationException("binary mode"));
+ ShardingSpherePreconditions.checkState(!isBinary, () -> new UnsupportedSQLOperationException("binary mode"));
String parameterValue = new String(parameterBytes, StandardCharsets.UTF_8);
Collection<String> parameterElements = decodeText(parameterValue);
double[] result = new double[parameterElements.size()];
@@ -136,7 +136,7 @@ public final class PostgreSQLArrayParameterDecoder {
* @return int array
*/
public boolean[] decodeBoolArray(final byte[] parameterBytes, final boolean isBinary) {
- ShardingSpherePreconditions.checkState(!isBinary, new UnsupportedSQLOperationException("binary mode"));
+ ShardingSpherePreconditions.checkState(!isBinary, () -> new UnsupportedSQLOperationException("binary mode"));
String parameterValue = new String(parameterBytes, StandardCharsets.UTF_8);
Collection<String> parameterElements = decodeText(parameterValue);
boolean[] result = new boolean[parameterElements.size()];
@@ -155,7 +155,7 @@ public final class PostgreSQLArrayParameterDecoder {
* @return int array
*/
public String[] decodeStringArray(final byte[] parameterBytes, final boolean isBinary) {
- ShardingSpherePreconditions.checkState(!isBinary, new UnsupportedSQLOperationException("binary mode"));
+ ShardingSpherePreconditions.checkState(!isBinary, () -> new UnsupportedSQLOperationException("binary mode"));
String parameterValue = new String(parameterBytes, StandardCharsets.UTF_8);
Collection<String> parameterElements = decodeText(parameterValue);
return parameterElements.toArray(EMPTY_STRING_ARRAY);
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProviderAlgorithm.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProviderAlgorithm.java
index e02fa1cf70e..3a73b84b229 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProviderAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProviderAlgorithm.java
@@ -107,20 +107,20 @@ public final class MGRMySQLDatabaseDiscoveryProviderAlgorithm implements Databas
private void checkPluginActive(final String databaseName, final Statement statement) throws SQLException {
try (ResultSet resultSet = statement.executeQuery(QUERY_PLUGIN_STATUS)) {
- ShardingSpherePreconditions.checkState(resultSet.next() && "ACTIVE".equals(resultSet.getString("PLUGIN_STATUS")), new InvalidMGRPluginException(databaseName));
+ ShardingSpherePreconditions.checkState(resultSet.next() && "ACTIVE".equals(resultSet.getString("PLUGIN_STATUS")), () -> new InvalidMGRPluginException(databaseName));
}
}
private void checkSinglePrimaryMode(final String databaseName, final Statement statement) throws SQLException {
try (ResultSet resultSet = statement.executeQuery(QUERY_SINGLE_PRIMARY_MODE)) {
- ShardingSpherePreconditions.checkState(resultSet.next() && "ON".equals(resultSet.getString("VARIABLE_VALUE")), new InvalidMGRModeException(databaseName));
+ ShardingSpherePreconditions.checkState(resultSet.next() && "ON".equals(resultSet.getString("VARIABLE_VALUE")), () -> new InvalidMGRModeException(databaseName));
}
}
private void checkGroupName(final String databaseName, final Statement statement) throws SQLException {
try (ResultSet resultSet = statement.executeQuery(QUERY_GROUP_NAME)) {
ShardingSpherePreconditions.checkState(resultSet.next() && props.getProperty("group-name", "").equals(resultSet.getString("VARIABLE_VALUE")),
- new InvalidMGRGroupNameConfigurationException(props.getProperty("group-name"), databaseName));
+ () -> new InvalidMGRGroupNameConfigurationException(props.getProperty("group-name"), databaseName));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/complex/ComplexInlineShardingAlgorithm.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/complex/ComplexInlineShardingAlgorithm.java
index a6a7db623cb..773e0a51694 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/complex/ComplexInlineShardingAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/complex/ComplexInlineShardingAlgorithm.java
@@ -84,7 +84,7 @@ public final class ComplexInlineShardingAlgorithm implements ComplexKeysSharding
public Collection<String> doSharding(final Collection<String> availableTargetNames, final ComplexKeysShardingValue<Comparable<?>> shardingValue) {
if (!shardingValue.getColumnNameAndRangeValuesMap().isEmpty()) {
ShardingSpherePreconditions.checkState(allowRangeQuery,
- new UnsupportedSQLOperationException(String.format("Since the property of `%s` is false, inline sharding algorithm can not tackle with range query", ALLOW_RANGE_QUERY_KEY)));
+ () -> new UnsupportedSQLOperationException(String.format("Since the property of `%s` is false, inline sharding algorithm can not tackle with range query", ALLOW_RANGE_QUERY_KEY)));
return availableTargetNames;
}
Map<String, Collection<Comparable<?>>> columnNameAndShardingValuesMap = shardingValue.getColumnNameAndShardingValuesMap();
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithm.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithm.java
index d3783070727..e02e47e0bc5 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithm.java
@@ -80,7 +80,7 @@ public final class InlineShardingAlgorithm implements StandardShardingAlgorithm<
@Override
public Collection<String> doSharding(final Collection<String> availableTargetNames, final RangeShardingValue<Comparable<?>> shardingValue) {
ShardingSpherePreconditions.checkState(allowRangeQuery,
- new UnsupportedSQLOperationException(String.format("Since the property of `%s` is false, inline sharding algorithm can not tackle with range query", ALLOW_RANGE_QUERY_KEY)));
+ () -> new UnsupportedSQLOperationException(String.format("Since the property of `%s` is false, inline sharding algorithm can not tackle with range query", ALLOW_RANGE_QUERY_KEY)));
return availableTargetNames;
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
index cec8239186e..55b1b99594f 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
@@ -611,7 +611,7 @@ public final class ShardingRule implements DatabaseRule, DataNodeContainedRule,
*/
public Comparable<?> generateKey(final String logicTableName) {
Optional<TableRule> tableRule = findTableRule(logicTableName);
- ShardingSpherePreconditions.checkState(tableRule.isPresent(), new GenerateKeyStrategyNotFoundException(logicTableName));
+ ShardingSpherePreconditions.checkState(tableRule.isPresent(), () -> new GenerateKeyStrategyNotFoundException(logicTableName));
KeyGenerateAlgorithm keyGenerator = null != tableRule.get().getKeyGeneratorName() ? keyGenerators.get(tableRule.get().getKeyGeneratorName()) : defaultKeyGenerateAlgorithm;
return keyGenerator.generateKey();
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
index 5ea17ef4d1b..519279c8793 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
@@ -243,7 +243,7 @@ public final class TableRule {
private void checkRule(final List<String> dataNodes) {
ShardingSpherePreconditions.checkState(!isEmptyDataNodes(dataNodes) || null == tableShardingStrategyConfig || tableShardingStrategyConfig instanceof NoneShardingStrategyConfiguration,
- new DataNodesMissedWithShardingTableException(logicTable));
+ () -> new DataNodesMissedWithShardingTableException(logicTable));
}
/**
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/AddMigrationSourceResourceUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/AddMigrationSourceResourceUpdater.java
index 79ae7d68e96..f506b6db64f 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/AddMigrationSourceResourceUpdater.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/AddMigrationSourceResourceUpdater.java
@@ -49,7 +49,7 @@ public final class AddMigrationSourceResourceUpdater implements RALUpdater<AddMi
public void executeUpdate(final String databaseName, final AddMigrationSourceResourceStatement sqlStatement) {
List<DataSourceSegment> dataSources = new ArrayList<>(sqlStatement.getDataSources());
ShardingSpherePreconditions.checkState(dataSources.stream().noneMatch(each -> each instanceof HostnameAndPortBasedDataSourceSegment),
- new UnsupportedSQLOperationException("Not currently support add hostname and port, please use url"));
+ () -> new UnsupportedSQLOperationException("Not currently support add hostname and port, please use url"));
URLBasedDataSourceSegment urlBasedDataSourceSegment = (URLBasedDataSourceSegment) dataSources.get(0);
DatabaseType databaseType = DatabaseTypeEngine.getDatabaseType(urlBasedDataSourceSegment.getUrl());
Map<String, DataSourceProperties> sourcePropertiesMap = ResourceSegmentsConverter.convert(databaseType, dataSources);
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/OpenGaussDatabaseType.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/OpenGaussDatabaseType.java
index 27f59bb64da..1784fef50c4 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/OpenGaussDatabaseType.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/OpenGaussDatabaseType.java
@@ -66,7 +66,7 @@ public final class OpenGaussDatabaseType implements SchemaSupportedDatabaseType
@Override
public void handleRollbackOnly(final boolean rollbackOnly, final SQLStatement statement) throws SQLException {
ShardingSpherePreconditions.checkState(!rollbackOnly || statement instanceof CommitStatement || statement instanceof RollbackStatement,
- new SQLFeatureNotSupportedException("Current transaction is aborted, commands ignored until end of transaction block."));
+ () -> new SQLFeatureNotSupportedException("Current transaction is aborted, commands ignored until end of transaction block."));
}
@Override
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseType.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseType.java
index eee522d04c8..7e83b6ba356 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseType.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseType.java
@@ -65,7 +65,7 @@ public final class PostgreSQLDatabaseType implements SchemaSupportedDatabaseType
@Override
public void handleRollbackOnly(final boolean rollbackOnly, final SQLStatement statement) throws SQLException {
ShardingSpherePreconditions.checkState(!rollbackOnly || statement instanceof CommitStatement || statement instanceof RollbackStatement,
- new SQLFeatureNotSupportedException("Current transaction is aborted, commands ignored until end of transaction block."));
+ () -> new SQLFeatureNotSupportedException("Current transaction is aborted, commands ignored until end of transaction block."));
}
@Override
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidator.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidator.java
index dde479671ed..091b649d7cb 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidator.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidator.java
@@ -80,7 +80,7 @@ public final class DataSourcePropertiesValidator {
private void checkFailFast(final DataSource dataSource, final DatabaseType databaseType) throws SQLException, ShardingSphereInternalException {
try (Connection connection = dataSource.getConnection()) {
ShardingSpherePreconditions.checkState(null == databaseType || DatabaseTypeEngine.getDatabaseType(connection.getMetaData().getURL()).getType().equals(databaseType.getType()),
- new MismatchedProtocolAndDataSourceException());
+ MismatchedProtocolAndDataSourceException::new);
}
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtil.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtil.java
index da89a6768a8..128e5f14b73 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtil.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtil.java
@@ -55,7 +55,7 @@ public final class ResultSetUtil {
* @throws SQLException SQL exception
*/
public static Object convertValue(final Object value, final Class<?> convertType) throws SQLException {
- ShardingSpherePreconditions.checkState(null != convertType, new SQLFeatureNotSupportedException("Type can not be null"));
+ ShardingSpherePreconditions.checkState(null != convertType, () -> new SQLFeatureNotSupportedException("Type can not be null"));
if (null == value) {
return convertNullValue(convertType);
}
diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResult.java b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResult.java
index ec7c405afef..52c6b22eca3 100644
--- a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResult.java
+++ b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResult.java
@@ -70,7 +70,7 @@ public abstract class MemoryMergedResult<T extends ShardingSphereRule> implement
@Override
public final Object getValue(final int columnIndex, final Class<?> type) throws SQLException {
ShardingSpherePreconditions.checkState(Blob.class != type && Clob.class != type && Reader.class != type && InputStream.class != type && SQLXML.class != type,
- new SQLFeatureNotSupportedException(String.format("Get value from `%s`", type.getName())));
+ () -> new SQLFeatureNotSupportedException(String.format("Get value from `%s`", type.getName())));
Object result = currentResultSetRow.getCell(columnIndex);
wasNull = null == result;
return result;
diff --git a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditions.java b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditions.java
index fa08bf8c37f..217e5606d79 100644
--- a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditions.java
+++ b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditions.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.util.exception.external.ShardingSphereExt
import org.apache.shardingsphere.infra.util.exception.internal.ShardingSphereInternalException;
import java.sql.SQLException;
+import java.util.function.Supplier;
/**
* ShardingSphere preconditions.
@@ -33,38 +34,14 @@ public final class ShardingSpherePreconditions {
/**
* Ensures the truth of an expression involving the state of the calling instance.
*
+ * @param <T> type of exception
* @param expectedExpression expected expression
- * @param exceptionIfUnexpected exception thrown if expression is unexpected
+ * @param exceptionSupplierIfUnexpected exception from this supplier will be thrown if expression is unexpected
+ * @throws T exception to be thrown
*/
- public static void checkState(final boolean expectedExpression, final ShardingSphereExternalException exceptionIfUnexpected) {
+ public static <T extends Throwable> void checkState(final boolean expectedExpression, final Supplier<T> exceptionSupplierIfUnexpected) throws T {
if (!expectedExpression) {
- throw exceptionIfUnexpected;
- }
- }
-
- /**
- * Ensures the truth of an expression involving the state of the calling instance.
- *
- * @param expectedExpression expected expression
- * @param exceptionIfUnexpected exception thrown if expression is unexpected
- * @throws ShardingSphereInternalException ShardingSphere internal exception
- */
- public static void checkState(final boolean expectedExpression, final ShardingSphereInternalException exceptionIfUnexpected) throws ShardingSphereInternalException {
- if (!expectedExpression) {
- throw exceptionIfUnexpected;
- }
- }
-
- /**
- * Ensures the truth of an expression involving the state of the calling instance.
- *
- * @param expectedExpression expected expression
- * @param exceptionIfUnexpected exception thrown if expression is unexpected
- * @throws SQLException SQL exception
- */
- public static void checkState(final boolean expectedExpression, final SQLException exceptionIfUnexpected) throws SQLException {
- if (!expectedExpression) {
- throw exceptionIfUnexpected;
+ throw exceptionSupplierIfUnexpected.get();
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditionsTest.java b/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditionsTest.java
index b8f05d19561..d7ded4fd48c 100644
--- a/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditionsTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditionsTest.java
@@ -28,33 +28,13 @@ import java.sql.SQLException;
public final class ShardingSpherePreconditionsTest {
@Test(expected = ShardingSphereExternalException.class)
- public void assertCheckStateToThrowsExternalException() {
- ShardingSpherePreconditions.checkState(false, new SQLWrapperException(new SQLException()));
+ public void assertCheckStateToThrowsException() {
+ ShardingSpherePreconditions.checkState(false, () -> new SQLWrapperException(new SQLException()));
}
@Test
- public void assertCheckStateToNotThrowExternalException() {
- ShardingSpherePreconditions.checkState(true, new SQLWrapperException(new SQLException()));
- }
-
- @Test(expected = ShardingSphereInternalException.class)
- public void assertCheckStateToThrowsInternalException() throws ShardingSphereInternalException {
- ShardingSpherePreconditions.checkState(false, new ShardingSphereInternalExceptionFixture("message"));
- }
-
- @Test
- public void assertCheckStateToNotThrowInternalException() throws ShardingSphereInternalException {
- ShardingSpherePreconditions.checkState(true, new ShardingSphereInternalExceptionFixture("message"));
- }
-
- @Test(expected = SQLException.class)
- public void assertCheckStateToThrowsSQLException() throws SQLException {
- ShardingSpherePreconditions.checkState(false, new SQLException("message"));
- }
-
- @Test
- public void assertCheckStateToNotThrowSQLException() throws SQLException {
- ShardingSpherePreconditions.checkState(true, new SQLException("message"));
+ public void assertCheckStateToNotThrowException() {
+ ShardingSpherePreconditions.checkState(true, () -> new SQLWrapperException(new SQLException()));
}
@Test(expected = ShardingSphereExternalException.class)
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/ShardingSphereSavepoint.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/ShardingSphereSavepoint.java
index 0b61080e7af..cf4613a987c 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/ShardingSphereSavepoint.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/ShardingSphereSavepoint.java
@@ -36,7 +36,7 @@ public final class ShardingSphereSavepoint implements Savepoint {
}
public ShardingSphereSavepoint(final String name) throws SQLException {
- ShardingSpherePreconditions.checkState(null != name && 0 != name.length(), new SQLFeatureNotSupportedException("Savepoint name can not be NULL or empty"));
+ ShardingSpherePreconditions.checkState(null != name && 0 != name.length(), () -> new SQLFeatureNotSupportedException("Savepoint name can not be NULL or empty"));
savepointName = name;
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
index 4bccfb296ae..f5b418b0953 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
@@ -210,7 +210,7 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter {
@Override
public Savepoint setSavepoint() throws SQLException {
checkClose();
- ShardingSpherePreconditions.checkState(isHoldTransaction(), new SQLFeatureNotSupportedException("Savepoint can only be used in transaction blocks."));
+ ShardingSpherePreconditions.checkState(isHoldTransaction(), () -> new SQLFeatureNotSupportedException("Savepoint can only be used in transaction blocks."));
return connectionManager.setSavepoint();
}
@@ -224,7 +224,7 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter {
}
private void checkClose() throws SQLException {
- ShardingSpherePreconditions.checkState(!isClosed(), new ConnectionClosedException().toSQLException());
+ ShardingSpherePreconditions.checkState(!isClosed(), () -> new ConnectionClosedException().toSQLException());
}
@SuppressWarnings("MagicConstant")
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSet.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSet.java
index 638e709652b..3e6149a3d54 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSet.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSet.java
@@ -390,7 +390,7 @@ public final class ShardingSphereResultSet extends AbstractResultSetAdapter {
private Integer getIndexFromColumnLabelAndIndexMap(final String columnLabel) throws SQLException {
Integer result = columnLabelAndIndexMap.get(columnLabel);
- ShardingSpherePreconditions.checkState(null != result, new SQLFeatureNotSupportedException(String.format("Can not get index from column label `%s`.", columnLabel)));
+ ShardingSpherePreconditions.checkState(null != result, () -> new SQLFeatureNotSupportedException(String.format("Can not get index from column label `%s`.", columnLabel)));
return result;
}
}
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/AbstractPipelineJobAPIImpl.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/AbstractPipelineJobAPIImpl.java
index b05649ea31f..9f562e68309 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/AbstractPipelineJobAPIImpl.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/AbstractPipelineJobAPIImpl.java
@@ -75,7 +75,7 @@ public abstract class AbstractPipelineJobAPIImpl implements PipelineJobAPI {
@Override
public void createProcessConfiguration(final PipelineProcessConfiguration processConfig) {
PipelineProcessConfiguration existingProcessConfig = processConfigPersistService.load(getJobType());
- ShardingSpherePreconditions.checkState(null == existingProcessConfig, new CreateExistsProcessConfigurationException());
+ ShardingSpherePreconditions.checkState(null == existingProcessConfig, CreateExistsProcessConfigurationException::new);
processConfigPersistService.persist(getJobType(), processConfig);
}
@@ -176,7 +176,7 @@ public abstract class AbstractPipelineJobAPIImpl implements PipelineJobAPI {
log.info("Start disabled pipeline job {}", jobId);
pipelineDistributedBarrier.removeParentNode(PipelineMetaDataNode.getJobBarrierDisablePath(jobId));
JobConfigurationPOJO jobConfigPOJO = getElasticJobConfigPOJO(jobId);
- ShardingSpherePreconditions.checkState(jobConfigPOJO.isDisabled(), new PipelineJobHasAlreadyStartedException(jobId));
+ ShardingSpherePreconditions.checkState(jobConfigPOJO.isDisabled(), () -> new PipelineJobHasAlreadyStartedException(jobId));
jobConfigPOJO.setDisabled(false);
jobConfigPOJO.getProps().remove("stop_time");
PipelineAPIFactory.getJobConfigurationAPI().updateJobConfiguration(jobConfigPOJO);
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/datasource/AbstractDataSourceChecker.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/datasource/AbstractDataSourceChecker.java
index b5e73edddbb..1cb1c72f28e 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/datasource/AbstractDataSourceChecker.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/datasource/AbstractDataSourceChecker.java
@@ -69,7 +69,7 @@ public abstract class AbstractDataSourceChecker implements DataSourceChecker {
Connection connection = dataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sql);
ResultSet resultSet = preparedStatement.executeQuery()) {
- ShardingSpherePreconditions.checkState(!resultSet.next(), new PrepareJobWithTargetTableNotEmptyException(each));
+ ShardingSpherePreconditions.checkState(!resultSet.next(), () -> new PrepareJobWithTargetTableNotEmptyException(each));
}
}
}
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/importer/DataRecordMerger.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/importer/DataRecordMerger.java
index 57e2544aa79..8f0c5dc4bf9 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/importer/DataRecordMerger.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/importer/DataRecordMerger.java
@@ -100,7 +100,7 @@ public final class DataRecordMerger {
dataRecords.put(dataRecord.getKey(), dataRecord);
return;
}
- ShardingSpherePreconditions.checkState(!IngestDataChangeType.DELETE.equals(beforeDataRecord.getType()), new UnsupportedSQLOperationException("Not Delete"));
+ ShardingSpherePreconditions.checkState(!IngestDataChangeType.DELETE.equals(beforeDataRecord.getType()), () -> new UnsupportedSQLOperationException("Not Delete"));
if (checkUpdatedPrimaryKey(dataRecord)) {
dataRecords.remove(dataRecord.getOldKey());
}
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/importer/DefaultImporter.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/importer/DefaultImporter.java
index 5ca7e20d3cc..558f73aabd8 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/importer/DefaultImporter.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/importer/DefaultImporter.java
@@ -127,7 +127,7 @@ public final class DefaultImporter extends AbstractLifecycleExecutor implements
return;
}
boolean success = tryFlush(dataSource, buffer);
- ShardingSpherePreconditions.checkState(!isRunning() || success, new PipelineImporterJobWriteException());
+ ShardingSpherePreconditions.checkState(!isRunning() || success, PipelineImporterJobWriteException::new);
}
private boolean tryFlush(final DataSource dataSource, final List<DataRecord> buffer) {
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineTableMetaDataUtil.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineTableMetaDataUtil.java
index 26bc40b2c27..62bc64515ff 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineTableMetaDataUtil.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineTableMetaDataUtil.java
@@ -112,9 +112,9 @@ public final class PipelineTableMetaDataUtil {
if (1 == primaryKeys.size()) {
return tableMetaData.getColumnMetaData(tableMetaData.getPrimaryKeyColumns().get(0));
}
- ShardingSpherePreconditions.checkState(primaryKeys.isEmpty(), new SplitPipelineJobException(tableName, "primary key is union primary"));
+ ShardingSpherePreconditions.checkState(primaryKeys.isEmpty(), () -> new SplitPipelineJobException(tableName, "primary key is union primary"));
Collection<PipelineIndexMetaData> uniqueIndexes = tableMetaData.getUniqueIndexes();
- ShardingSpherePreconditions.checkState(!uniqueIndexes.isEmpty(), new SplitPipelineJobException(tableName, "no primary key or unique index"));
+ ShardingSpherePreconditions.checkState(!uniqueIndexes.isEmpty(), () -> new SplitPipelineJobException(tableName, "no primary key or unique index"));
if (1 == uniqueIndexes.size() && 1 == uniqueIndexes.iterator().next().getColumns().size()) {
PipelineColumnMetaData column = uniqueIndexes.iterator().next().getColumns().get(0);
if (!column.isNullable()) {
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceChecker.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceChecker.java
index 33be9eb3dc8..17e93509045 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceChecker.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceChecker.java
@@ -106,7 +106,8 @@ public final class MySQLDataSourceChecker extends AbstractDataSourceChecker {
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next() || !BINLOG_ROW_IMAGE.equalsIgnoreCase(key)) {
String actualValue = resultSet.getString(2);
- ShardingSpherePreconditions.checkState(toBeCheckedValue.equalsIgnoreCase(actualValue), new PrepareJobWithInvalidSourceDataSourceException(key, toBeCheckedValue, actualValue));
+ ShardingSpherePreconditions.checkState(toBeCheckedValue.equalsIgnoreCase(actualValue),
+ () -> new PrepareJobWithInvalidSourceDataSourceException(key, toBeCheckedValue, actualValue));
}
}
}
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/MySQLClient.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/MySQLClient.java
index 8036c022092..39c2144f44b 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/MySQLClient.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/MySQLClient.java
@@ -207,7 +207,7 @@ public final class MySQLClient {
* @return binlog event
*/
public synchronized AbstractBinlogEvent poll() {
- ShardingSpherePreconditions.checkState(running, new BinlogSyncChannelAlreadyClosedException());
+ ShardingSpherePreconditions.checkState(running, BinlogSyncChannelAlreadyClosedException::new);
try {
return blockingEventQueue.poll(100L, TimeUnit.MILLISECONDS);
} catch (final InterruptedException ignored) {
diff --git a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidator.java b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidator.java
index 41a35c565cc..078558889a9 100644
--- a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidator.java
+++ b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidator.java
@@ -41,7 +41,7 @@ public final class SingleTableDropSchemaMetadataValidator implements SingleTable
String schemaName = each.getValue();
ShardingSphereSchema schema = database.getSchema(schemaName);
ShardingSpherePreconditions.checkNotNull(schema, new SchemaNotFoundException(schemaName));
- ShardingSpherePreconditions.checkState(containsCascade || schema.getAllTableNames().isEmpty(), new DropNotEmptySchemaException(schemaName));
+ ShardingSpherePreconditions.checkState(containsCascade || schema.getAllTableNames().isEmpty(), () -> new DropNotEmptySchemaException(schemaName));
}
}
}
diff --git a/shardingsphere-kernel/shardingsphere-sql-translator/shardingsphere-sql-translator-provider/shardingsphere-sql-translator-jooq-provider/src/main/java/org/apache/shardingsphere/sqltranslator/jooq/JooQDialectRegistry.java b/shardingsphere-kernel/shardingsphere-sql-translator/shardingsphere-sql-translator-provider/shardingsphere-sql-translator-jooq-provider/src/main/java/org/apache/shardingsphere/sqltranslator/jooq/JooQDialectRegistry.java
index ec201e1754d..8e6b22b36e8 100644
--- a/shardingsphere-kernel/shardingsphere-sql-translator/shardingsphere-sql-translator-provider/shardingsphere-sql-translator-jooq-provider/src/main/java/org/apache/shardingsphere/sqltranslator/jooq/JooQDialectRegistry.java
+++ b/shardingsphere-kernel/shardingsphere-sql-translator/shardingsphere-sql-translator-provider/shardingsphere-sql-translator-jooq-provider/src/main/java/org/apache/shardingsphere/sqltranslator/jooq/JooQDialectRegistry.java
@@ -55,7 +55,7 @@ public final class JooQDialectRegistry {
*/
public static SQLDialect getSQLDialect(final DatabaseType databaseType) throws SQLTranslationException {
SQLDialect result = DATABASE_DIALECT_MAP.get(databaseType);
- ShardingSpherePreconditions.checkState(null != result, new UnsupportedTranslatedDatabaseException(databaseType));
+ ShardingSpherePreconditions.checkState(null != result, () -> new UnsupportedTranslatedDatabaseException(databaseType));
return result;
}
}
diff --git a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/datasource/swapper/DataSourceSwapper.java b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/datasource/swapper/DataSou [...]
index 72db00c6435..8574965c117 100644
--- a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/datasource/swapper/DataSourceSwapper.java
+++ b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/datasource/swapper/DataSourceSwapper.java
@@ -69,7 +69,7 @@ public final class DataSourceSwapper {
exceptions.add(ex);
}
}
- ShardingSpherePreconditions.checkState(null != result || exceptions.isEmpty(), new XADataSourceInitializeException(xaDataSourceDefinition));
+ ShardingSpherePreconditions.checkState(null != result || exceptions.isEmpty(), () -> new XADataSourceInitializeException(xaDataSourceDefinition));
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/vertx/VertxBackendConnection.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/vertx/VertxBackendConnection.java
index 770fc4651ae..e48d3d16d74 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/vertx/VertxBackendConnection.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/vertx/VertxBackendConnection.java
@@ -59,7 +59,7 @@ public final class VertxBackendConnection implements BackendConnection<Future<Vo
public VertxBackendConnection(final ConnectionSession connectionSession) {
ShardingSpherePreconditions.checkState(TransactionType.LOCAL == connectionSession.getTransactionStatus().getTransactionType(),
- new UnsupportedSQLOperationException("Vert.x backend supports LOCAL transaction only for now"));
+ () -> new UnsupportedSQLOperationException("Vert.x backend supports LOCAL transaction only for now"));
closed = new AtomicBoolean(false);
this.connectionSession = connectionSession;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/DatabaseRequiredBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/DatabaseRequiredBackendHandler.java
index a14c3a27f2c..bc9fb3ea00a 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/DatabaseRequiredBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/DatabaseRequiredBackendHandler.java
@@ -61,6 +61,6 @@ public abstract class DatabaseRequiredBackendHandler<T extends SQLStatement> imp
private void checkDatabaseName(final String databaseName) {
ShardingSpherePreconditions.checkNotNull(databaseName, new NoDatabaseSelectedException());
- ShardingSpherePreconditions.checkState(ProxyContext.getInstance().databaseExists(databaseName), new UnknownDatabaseException(databaseName));
+ ShardingSpherePreconditions.checkState(ProxyContext.getInstance().databaseExists(databaseName), () -> new UnknownDatabaseException(databaseName));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java
index d88107b7d3e..edaf17d2bcc 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java
@@ -160,7 +160,7 @@ public final class ProxyBackendHandlerFactory {
private static void checkUnsupportedDistSQLStatementInTransaction(final SQLStatement sqlStatement, final ConnectionSession connectionSession) {
ShardingSpherePreconditions.checkState(!connectionSession.getTransactionStatus().isInTransaction() || isSupportedDistSQLStatementInTransaction(sqlStatement),
- new UnsupportedSQLOperationException("Non-query dist sql is not supported within a transaction"));
+ () -> new UnsupportedSQLOperationException("Non-query dist sql is not supported within a transaction"));
}
private static boolean isSupportedDistSQLStatementInTransaction(final SQLStatement sqlStatement) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandlerFactory.java
index c30ac19d53b..51d6aa0a11a 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandlerFactory.java
@@ -144,7 +144,7 @@ public final class RALBackendHandlerFactory {
private static RALBackendHandler<?> createRALBackendHandler(final RALStatement sqlStatement, final ConnectionSession connectionSession) {
Class<? extends RALBackendHandler<?>> clazz = HANDLERS.get(sqlStatement.getClass());
- ShardingSpherePreconditions.checkState(null != clazz, new UnsupportedSQLOperationException(String.format("Unsupported SQL statement : %s", sqlStatement.getClass().getCanonicalName())));
+ ShardingSpherePreconditions.checkState(null != clazz, () -> new UnsupportedSQLOperationException(String.format("Unsupported SQL statement : %s", sqlStatement.getClass().getCanonicalName())));
RALBackendHandler<?> result = newInstance(clazz);
result.init(sqlStatement, connectionSession);
return result;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/hint/HintRALBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/hint/HintRALBackendHandler.java
index 6ccf77e2c63..a2a0978e749 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/hint/HintRALBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/hint/HintRALBackendHandler.java
@@ -48,7 +48,7 @@ public final class HintRALBackendHandler extends RALBackendHandler {
public ResponseHeader execute() throws SQLException {
ShardingSpherePreconditions.checkState(
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getProps().<Boolean>getValue(ConfigurationPropertyKey.PROXY_HINT_ENABLED),
- new UnsupportedSQLOperationException(String.format("%s should be true, please check your config", ConfigurationPropertyKey.PROXY_HINT_ENABLED.getKey())));
+ () -> new UnsupportedSQLOperationException(String.format("%s should be true, please check your config", ConfigurationPropertyKey.PROXY_HINT_ENABLED.getKey())));
hintRALStatementExecutor = HintRALStatementExecutorFactory.newInstance(sqlStatement, connectionSession);
return hintRALStatementExecutor.execute();
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LabelInstanceHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LabelInstanceHandler.java
index 700b8e5aad5..23031819eb3 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LabelInstanceHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LabelInstanceHandler.java
@@ -42,7 +42,7 @@ public final class LabelInstanceHandler extends UpdatableRALBackendHandler<Label
public void update(final ContextManager contextManager) {
MetaDataPersistService persistService = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getPersistService();
ShardingSpherePreconditions.checkState(null != persistService && null != persistService.getRepository() && !(persistService.getRepository() instanceof StandalonePersistRepository),
- new UnsupportedSQLOperationException("Labels can only be added in cluster mode"));
+ () -> new UnsupportedSQLOperationException("Labels can only be added in cluster mode"));
String instanceId = getSqlStatement().getInstanceId();
Optional<ComputeNodeInstance> computeNodeInstance = contextManager.getInstanceContext().getComputeNodeInstanceById(instanceId);
if (computeNodeInstance.isPresent()) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetInstanceStatusHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetInstanceStatusHandler.java
index 0e14d8a7dac..6b9d0fcf1e9 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetInstanceStatusHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetInstanceStatusHandler.java
@@ -33,7 +33,7 @@ public final class SetInstanceStatusHandler extends UpdatableRALBackendHandler<S
@Override
protected void update(final ContextManager contextManager) {
- ShardingSpherePreconditions.checkState(contextManager.getInstanceContext().isCluster(), new UnsupportedSQLOperationException("Only allowed in cluster mode"));
+ ShardingSpherePreconditions.checkState(contextManager.getInstanceContext().isCluster(), () -> new UnsupportedSQLOperationException("Only allowed in cluster mode"));
String instanceId = getSqlStatement().getInstanceId();
boolean isDisable = "DISABLE".equals(getSqlStatement().getStatus());
if (isDisable) {
@@ -46,15 +46,15 @@ public final class SetInstanceStatusHandler extends UpdatableRALBackendHandler<S
private void checkEnablingIsValid(final ContextManager contextManager, final String instanceId) {
ShardingSpherePreconditions.checkState(contextManager.getInstanceContext().getComputeNodeInstanceById(instanceId).isPresent(),
- new UnsupportedSQLOperationException(String.format("`%s` does not exist", instanceId)));
+ () -> new UnsupportedSQLOperationException(String.format("`%s` does not exist", instanceId)));
}
private void checkDisablingIsValid(final ContextManager contextManager, final String instanceId) {
ShardingSpherePreconditions.checkState(!contextManager.getInstanceContext().getInstance().getCurrentInstanceId().equals(instanceId),
- new UnsupportedSQLOperationException(String.format("`%s` is the currently in use instance and cannot be disabled", instanceId)));
+ () -> new UnsupportedSQLOperationException(String.format("`%s` is the currently in use instance and cannot be disabled", instanceId)));
ShardingSpherePreconditions.checkState(contextManager.getInstanceContext().getComputeNodeInstanceById(instanceId).isPresent(),
- new UnsupportedSQLOperationException(String.format("`%s` does not exist", instanceId)));
+ () -> new UnsupportedSQLOperationException(String.format("`%s` does not exist", instanceId)));
ShardingSpherePreconditions.checkState(StateType.CIRCUIT_BREAK != contextManager.getInstanceContext().getComputeNodeInstanceById(instanceId).get().getState().getCurrentState(),
- new UnsupportedSQLOperationException(String.format("`%s` compute node has been disabled", instanceId)));
+ () -> new UnsupportedSQLOperationException(String.format("`%s` compute node has been disabled", instanceId)));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetReadwriteSplittingStatusHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetReadwriteSplittingStatusHandler.java
index 1aba186851f..f2c0d16164d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetReadwriteSplittingStatusHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetReadwriteSplittingStatusHandler.java
@@ -80,11 +80,11 @@ public final class SetReadwriteSplittingStatusHandler extends UpdatableRALBacken
private void checkReadwriteSplittingRule(final ContextManager contextManager, final String databaseName) {
Optional<ReadwriteSplittingRule> rule = contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getRuleMetaData().findSingleRule(ReadwriteSplittingRule.class);
- ShardingSpherePreconditions.checkState(rule.isPresent(), new UnsupportedSQLOperationException("The current schema has no read_write splitting rules"));
+ ShardingSpherePreconditions.checkState(rule.isPresent(), () -> new UnsupportedSQLOperationException("The current schema has no read_write splitting rules"));
}
private void checkModeAndPersistRepository(final ContextManager contextManager) {
- ShardingSpherePreconditions.checkState(contextManager.getInstanceContext().isCluster(), new UnsupportedSQLOperationException("Mode must be `Cluster`"));
+ ShardingSpherePreconditions.checkState(contextManager.getInstanceContext().isCluster(), () -> new UnsupportedSQLOperationException("Mode must be `Cluster`"));
}
private void checkDatabaseName(final String databaseName) {
@@ -129,7 +129,7 @@ public final class SetReadwriteSplittingStatusHandler extends UpdatableRALBacken
}
private void checkIsNotDisabled(final Collection<String> disabledResources, final String toBeEnabledResource) {
- ShardingSpherePreconditions.checkState(disabledResources.contains(toBeEnabledResource), new UnsupportedSQLOperationException(String.format("`%s` is not disabled", toBeEnabledResource)));
+ ShardingSpherePreconditions.checkState(disabledResources.contains(toBeEnabledResource), () -> new UnsupportedSQLOperationException(String.format("`%s` is not disabled", toBeEnabledResource)));
}
private void checkDisable(final ContextManager contextManager, final String databaseName, final Collection<String> disabledResources, final String toBeDisabledResource,
@@ -143,20 +143,21 @@ public final class SetReadwriteSplittingStatusHandler extends UpdatableRALBacken
private void checkIsDisabled(final Map<String, String> replicaResources, final Collection<String> disabledResources, final String toBeDisabledResource) {
String toBeDisableResourceRuleNames = replicaResources.get(toBeDisabledResource);
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(toBeDisableResourceRuleNames) || !disabledResources.contains(toBeDisabledResource),
- new UnsupportedSQLOperationException(String.format("`%s` has been disabled", toBeDisabledResource)));
+ () -> new UnsupportedSQLOperationException(String.format("`%s` has been disabled", toBeDisabledResource)));
}
private void checkIsReplicaResource(final Map<String, String> replicaResources, final String toBeDisabledResource) {
ShardingSpherePreconditions.checkState(replicaResources.containsKey(toBeDisabledResource),
- new UnsupportedSQLOperationException(String.format("`%s` is not used as a read resource by any read-write separation rules,cannot be disabled", toBeDisabledResource)));
+ () -> new UnsupportedSQLOperationException(String.format("`%s` is not used as a read resource by any read-write separation rules,cannot be disabled", toBeDisabledResource)));
}
private void checkIsLastResource(final Map<String, String> replicaResources, final String toBeDisabledResource) {
Collection<String> onlyOneResourceRules = getOnlyOneResourceRules(replicaResources);
Collection<String> toBeDisabledResourceRuleNames = Splitter.on(",").trimResults().splitToList(replicaResources.get(toBeDisabledResource));
onlyOneResourceRules = onlyOneResourceRules.stream().filter(toBeDisabledResourceRuleNames::contains).collect(Collectors.toSet());
+ Collection<String> finalOnlyOneResourceRules = onlyOneResourceRules;
ShardingSpherePreconditions.checkState(onlyOneResourceRules.isEmpty(),
- new UnsupportedSQLOperationException(String.format("`%s` is the last read resource in `%s`, cannot be disabled", toBeDisabledResource, onlyOneResourceRules)));
+ () -> new UnsupportedSQLOperationException(String.format("`%s` is the last read resource in `%s`, cannot be disabled", toBeDisabledResource, finalOnlyOneResourceRules)));
}
private Collection<String> getGroupNames(final String toBeDisableResource, final Map<String, String> replicaResources,
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/UnlabelInstanceHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/UnlabelInstanceHandler.java
index 7322e9810ee..8813db82e81 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/UnlabelInstanceHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/UnlabelInstanceHandler.java
@@ -43,7 +43,7 @@ public final class UnlabelInstanceHandler extends UpdatableRALBackendHandler<Unl
protected void update(final ContextManager contextManager) {
MetaDataPersistService persistService = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getPersistService();
ShardingSpherePreconditions.checkState(null != persistService.getRepository() && !(persistService.getRepository() instanceof StandalonePersistRepository),
- new UnsupportedSQLOperationException("Labels can only be removed in cluster mode"));
+ () -> new UnsupportedSQLOperationException("Labels can only be removed in cluster mode"));
String instanceId = getSqlStatement().getInstanceId();
Optional<ComputeNodeInstance> computeNodeInstance = contextManager.getInstanceContext().getComputeNodeInstanceById(instanceId);
if (computeNodeInstance.isPresent()) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/RULBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/RULBackendHandlerFactory.java
index 3bb1d5acde9..2152ff38589 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/RULBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/RULBackendHandlerFactory.java
@@ -69,7 +69,7 @@ public final class RULBackendHandlerFactory {
private static RULBackendHandler<?> createRULBackendHandler(final RULStatement sqlStatement, final ConnectionSession connectionSession) {
Class<? extends RULBackendHandler<?>> clazz = HANDLERS.get(sqlStatement.getClass());
- ShardingSpherePreconditions.checkState(null != clazz, new UnsupportedSQLOperationException(String.format("Unsupported SQL statement : %s", sqlStatement.getClass().getCanonicalName())));
+ ShardingSpherePreconditions.checkState(null != clazz, () -> new UnsupportedSQLOperationException(String.format("Unsupported SQL statement : %s", sqlStatement.getClass().getCanonicalName())));
RULBackendHandler<?> result = newInstance(clazz);
result.init(sqlStatement, connectionSession);
return result;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandler.java
index a400760eda2..b30a7de46fb 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandler.java
@@ -149,19 +149,19 @@ public final class TransactionBackendHandler implements ProxyBackendHandler {
private void handleSavepoint() throws SQLException {
ShardingSpherePreconditions.checkState(connectionSession.getTransactionStatus().isInTransaction() || !isPostgreSQLOrOpenGauss(),
- new SQLFeatureNotSupportedException("SAVEPOINT can only be used in transaction blocks"));
+ () -> new SQLFeatureNotSupportedException("SAVEPOINT can only be used in transaction blocks"));
backendTransactionManager.setSavepoint(((SavepointStatement) tclStatement).getSavepointName());
}
private void handleRollbackToSavepoint() throws SQLException {
ShardingSpherePreconditions.checkState(connectionSession.getTransactionStatus().isInTransaction() || !isPostgreSQLOrOpenGauss(),
- new SQLFeatureNotSupportedException("ROLLBACK TO SAVEPOINT can only be used in transaction blocks"));
+ () -> new SQLFeatureNotSupportedException("ROLLBACK TO SAVEPOINT can only be used in transaction blocks"));
backendTransactionManager.rollbackTo(((RollbackStatement) tclStatement).getSavepointName().get());
}
private void handleReleaseSavepoint() throws SQLException {
ShardingSpherePreconditions.checkState(connectionSession.getTransactionStatus().isInTransaction() || !isPostgreSQLOrOpenGauss(),
- new SQLFeatureNotSupportedException("RELEASE SAVEPOINT can only be used in transaction blocks"));
+ () -> new SQLFeatureNotSupportedException("RELEASE SAVEPOINT can only be used in transaction blocks"));
backendTransactionManager.releaseSavepoint(((ReleaseSavepointStatement) tclStatement).getSavepointName());
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionSetHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionSetHandler.java
index ef577ca21b6..4865ad8e317 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionSetHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionSetHandler.java
@@ -43,7 +43,7 @@ public final class TransactionSetHandler implements ProxyBackendHandler {
@Override
public ResponseHeader execute() {
- ShardingSpherePreconditions.checkState(null != sqlStatement.getScope() || !connectionSession.getTransactionStatus().isInTransaction(), new SwitchTypeInTransactionException());
+ ShardingSpherePreconditions.checkState(null != sqlStatement.getScope() || !connectionSession.getTransactionStatus().isInTransaction(), SwitchTypeInTransactionException::new);
if (TransactionAccessType.READ_ONLY == sqlStatement.getAccessMode()) {
connectionSession.setReadOnly(true);
} else if (TransactionAccessType.READ_WRITE == sqlStatement.getAccessMode()) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionXAHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionXAHandler.java
index 9e51083b833..741dcc1789e 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionXAHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionXAHandler.java
@@ -74,7 +74,7 @@ public final class TransactionXAHandler implements ProxyBackendHandler {
* we have to let session occupy the thread when doing xa transaction. according to https://dev.mysql.com/doc/refman/5.7/en/xa-states.html XA and local transactions are mutually
* exclusive
*/
- ShardingSpherePreconditions.checkState(!connectionSession.getTransactionStatus().isInTransaction(), new XATransactionNestedBeginException());
+ ShardingSpherePreconditions.checkState(!connectionSession.getTransactionStatus().isInTransaction(), XATransactionNestedBeginException::new);
ResponseHeader header = backendHandler.execute();
connectionSession.getConnectionContext().getTransactionConnectionContext().setInTransaction(true);
return header;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java
index 51601275689..507ed98f182 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java
@@ -164,7 +164,7 @@ public final class PostgreSQLComDescribeExecutor implements CommandExecutor {
}
column = caseInsensitiveColumns.get(columnName);
}
- ShardingSpherePreconditions.checkState(null != column, new ColumnNotFoundException(logicTableName, columnName));
+ ShardingSpherePreconditions.checkState(null != column, () -> new ColumnNotFoundException(logicTableName, columnName));
preparedStatement.getParameterTypes().set(parameterMarkerIndex++, PostgreSQLColumnType.valueOfJDBCType(column.getDataType()));
}
}