RaigorJiang commented on code in PR #29000: URL: https://github.com/apache/shardingsphere/pull/29000#discussion_r1392411609
########## infra/nativetest/src/test/resources/yaml/mask.yaml: ########## @@ -0,0 +1,47 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +mode: + type: Standalone + repository: + type: JDBC + +dataSources: + ds_0: + dataSourceClassName: com.zaxxer.hikari.HikariDataSource + driverClassName: org.h2.Driver + jdbcUrl: jdbc:h2:mem:local_mask_ds_0;MODE=MYSQL;IGNORECASE=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE + username: root + password: 123456 + +rules: +- !MASK + tables: + t_order_item: + columns: + phone: + maskAlgorithm: keep_first_n_last_m_mask + maskAlgorithms: + keep_first_n_last_m_mask: + type: KEEP_FIRST_N_LAST_M + props: + first-n: 3 + last-m: 4 + replace-char: '*' + +props: + sql-show: false Review Comment: @linghengqian Missed a blank line here. ########## infra/nativetest/src/test/java/org/apache/shardingsphere/infra/nativetest/jdbc/features/repository/AddressRepository.java: ########## @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.nativetest.jdbc.features.repository; + +import org.apache.shardingsphere.infra.nativetest.jdbc.features.entity.Address; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.LinkedList; +import java.util.List; + +@SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"}) +public final class AddressRepository { + + private final DataSource dataSource; + + public AddressRepository(final DataSource dataSource) { + this.dataSource = dataSource; + } + + /** + * create table t_address if not exists. + * @throws SQLException SQL exception + */ + public void createTableIfNotExists() throws SQLException { + String sql = "CREATE TABLE IF NOT EXISTS t_address (address_id BIGINT NOT NULL, address_name VARCHAR(100) NOT NULL, PRIMARY KEY (address_id))"; + try ( + Connection connection = dataSource.getConnection(); + Statement statement = connection.createStatement()) { + statement.executeUpdate(sql); + } + } + + /** + * drop table t_address. + * @throws SQLException SQL exception + */ + public void dropTable() throws SQLException { + String sql = "DROP TABLE IF EXISTS t_address"; + try ( + Connection connection = dataSource.getConnection(); + Statement statement = connection.createStatement()) { + statement.executeUpdate(sql); + } + } + + /** + * truncate table t_address. + * @throws SQLException SQL exception + */ + public void truncateTable() throws SQLException { + String sql = "TRUNCATE TABLE t_address"; + try ( + Connection connection = dataSource.getConnection(); + Statement statement = connection.createStatement()) { + statement.executeUpdate(sql); + } + } + + /** + * insert something to table t_address. + * @param address address + * @return addressId of the insert statement + * @throws SQLException SQL exception + */ + public Long insert(final Address address) throws SQLException { + String sql = "INSERT INTO t_address (address_id, address_name) VALUES (?, ?)"; + try ( + Connection connection = dataSource.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement(sql)) { + preparedStatement.setLong(1, address.getAddressId()); + preparedStatement.setString(2, address.getAddressName()); + preparedStatement.executeUpdate(); + } + return address.getAddressId(); + } + + /** + * delete by id. + * @param id id Review Comment: Are these comments necessary? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
