org.zodiac.autoconfigure.datasource.jdbc.condition.ShardingRuleCondition Maven / Gradle / Ivy
package org.zodiac.autoconfigure.datasource.jdbc.condition;
import org.apache.shardingsphere.spring.boot.util.PropertyUtil;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.zodiac.commons.constants.SystemPropertiesConstants;
public final class ShardingRuleCondition extends SpringBootCondition {
@Override
public ConditionOutcome getMatchOutcome(final ConditionContext conditionContext,
final AnnotatedTypeMetadata annotatedTypeMetadata) {
boolean isShardingRule = PropertyUtil.containPropertyPrefix(conditionContext.getEnvironment(),
SystemPropertiesConstants.Zodiac.SPRING_DATASOURCE_JDBC_RULES_MASTER_SHARDING_PREFIX);
boolean isMasterSlaveRule =
new MasterSlaveRuleCondition().getMatchOutcome(conditionContext, annotatedTypeMetadata).isMatch();
boolean isEncryptRule =
new EncryptRuleCondition().getMatchOutcome(conditionContext, annotatedTypeMetadata).isMatch();
return (isMasterSlaveRule || isEncryptRule || !isShardingRule)
? ConditionOutcome.noMatch("Have found master-slave or encrypt rule in environment")
: ConditionOutcome.match();
}
}