soulasuna commented on a change in pull request #11995: URL: https://github.com/apache/shardingsphere/pull/11995#discussion_r695579624
########## File path: shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/SimpleSQLNoteShadowAlgorithm.java ########## @@ -0,0 +1,117 @@ +/* + * 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.shadow.algorithm.shadow.note; + +import com.google.common.base.Preconditions; +import lombok.Getter; +import lombok.Setter; +import org.apache.shardingsphere.shadow.api.shadow.note.NoteShadowAlgorithm; +import org.apache.shardingsphere.shadow.api.shadow.note.PreciseNoteShadowValue; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Properties; + +/** + * Simple note shadow algorithm. + */ +@Getter +@Setter +public final class SimpleSQLNoteShadowAlgorithm implements NoteShadowAlgorithm<String> { + + private static final String NOTE_SPACE = ","; + + private static final String NOTE_ELEMENT_SPACE = "="; + + private static final String NOTE_PREFIX = "/*"; + + private static final String NOTE_SUFFIX = "*/"; + + private Properties props = new Properties(); + + @Override + public String getType() { + return "SIMPLE_NOTE"; + } + + @Override + public void init() { + checkPropsSize(); + } + + private void checkPropsSize() { + Preconditions.checkState(!props.isEmpty(), "Simple note shadow algorithm props cannot be empty."); + } + + @Override + public boolean isShadow(final Collection<String> shadowTableNames, final PreciseNoteShadowValue<String> noteShadowValue) { + if (!shadowTableNames.contains(noteShadowValue.getLogicTableName())) { + return false; + } + Optional<Map<String, String>> noteOptional = parseNote(noteShadowValue.getSqlNoteValue()); + return noteOptional.filter(stringStringMap -> props.entrySet().stream().allMatch(entry -> Objects.equals(entry.getValue(), stringStringMap.get(String.valueOf(entry.getKey()))))).isPresent(); + } + + private Optional<Map<String, String>> parseNote(final String sqlNoteValue) { Review comment: I will fix it. ########## File path: shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/note/PreciseNoteShadowValue.java ########## @@ -15,24 +15,19 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.algorithm; +package org.apache.shardingsphere.shadow.api.shadow.note; import lombok.Getter; -import lombok.Setter; -import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm; -import java.util.Properties; +import lombok.RequiredArgsConstructor; +import lombok.ToString; +import org.apache.shardingsphere.shadow.api.shadow.ShadowValue; -/** - * Simple note shadow algorithm. - */ +@RequiredArgsConstructor @Getter -@Setter -public final class SimpleSQLNoteShadowAlgorithm implements ShadowAlgorithm { +@ToString +public class PreciseNoteShadowValue<T extends Comparable<?>> implements ShadowValue { Review comment: I will fix it. ########## File path: shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/PreciseColumnShadowValue.java ########## @@ -0,0 +1,40 @@ +/* + * 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.shadow.api.shadow.column; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.ToString; +import org.apache.shardingsphere.shadow.api.shadow.ShadowValue; + +/** + * Shadow value for precise column. + */ +@RequiredArgsConstructor +@Getter +@ToString +public class PreciseColumnShadowValue<T extends Comparable<?>> implements ShadowValue { Review comment: I will fix it. -- 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]
