View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shardingsphere.sharding.yaml.config;
19  
20  import lombok.Getter;
21  import lombok.Setter;
22  import org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfiguration;
23  import org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
24  import org.apache.shardingsphere.mode.tuple.annotation.RepositoryTupleField;
25  import org.apache.shardingsphere.mode.tuple.annotation.RepositoryTupleEntity;
26  import org.apache.shardingsphere.mode.tuple.annotation.RepositoryTupleField.Type;
27  import org.apache.shardingsphere.mode.tuple.annotation.RepositoryTupleKeyListNameGenerator;
28  import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
29  import org.apache.shardingsphere.sharding.yaml.config.cache.YamlShardingCacheConfiguration;
30  import org.apache.shardingsphere.sharding.yaml.config.rule.YamlShardingAutoTableRuleConfiguration;
31  import org.apache.shardingsphere.sharding.yaml.config.rule.YamlTableRuleConfiguration;
32  import org.apache.shardingsphere.sharding.yaml.config.strategy.audit.YamlShardingAuditStrategyConfiguration;
33  import org.apache.shardingsphere.sharding.yaml.config.strategy.keygen.YamlKeyGenerateStrategyConfiguration;
34  import org.apache.shardingsphere.sharding.yaml.config.strategy.sharding.YamlShardingStrategyConfiguration;
35  import org.apache.shardingsphere.sharding.yaml.swapper.ShardingBindingTableRepositoryTupleKeyListNameGenerator;
36  
37  import java.util.Collection;
38  import java.util.LinkedHashMap;
39  import java.util.LinkedList;
40  import java.util.Map;
41  
42  /**
43   * Sharding rule configuration for YAML.
44   */
45  @RepositoryTupleEntity("sharding")
46  @Getter
47  @Setter
48  public final class YamlShardingRuleConfiguration implements YamlRuleConfiguration {
49      
50      @RepositoryTupleField(type = Type.TABLE)
51      private Map<String, YamlTableRuleConfiguration> tables = new LinkedHashMap<>();
52      
53      @RepositoryTupleField(type = Type.TABLE)
54      private Map<String, YamlShardingAutoTableRuleConfiguration> autoTables = new LinkedHashMap<>();
55      
56      @RepositoryTupleField(type = Type.TABLE)
57      @RepositoryTupleKeyListNameGenerator(ShardingBindingTableRepositoryTupleKeyListNameGenerator.class)
58      private Collection<String> bindingTables = new LinkedList<>();
59      
60      @RepositoryTupleField(type = Type.DEFAULT_STRATEGY)
61      private YamlShardingStrategyConfiguration defaultDatabaseStrategy;
62      
63      @RepositoryTupleField(type = Type.DEFAULT_STRATEGY)
64      private YamlShardingStrategyConfiguration defaultTableStrategy;
65      
66      @RepositoryTupleField(type = Type.DEFAULT_STRATEGY)
67      private YamlKeyGenerateStrategyConfiguration defaultKeyGenerateStrategy;
68      
69      @RepositoryTupleField(type = Type.DEFAULT_STRATEGY)
70      private YamlShardingAuditStrategyConfiguration defaultAuditStrategy;
71      
72      @RepositoryTupleField(type = Type.ALGORITHM)
73      private Map<String, YamlAlgorithmConfiguration> shardingAlgorithms = new LinkedHashMap<>();
74      
75      @RepositoryTupleField(type = Type.ALGORITHM)
76      private Map<String, YamlAlgorithmConfiguration> keyGenerators = new LinkedHashMap<>();
77      
78      @RepositoryTupleField(type = Type.ALGORITHM)
79      private Map<String, YamlAlgorithmConfiguration> auditors = new LinkedHashMap<>();
80      
81      @RepositoryTupleField(type = Type.OTHER)
82      private String defaultShardingColumn;
83      
84      @RepositoryTupleField(type = Type.OTHER)
85      private YamlShardingCacheConfiguration shardingCache;
86      
87      @Override
88      public Class<ShardingRuleConfiguration> getRuleConfigurationType() {
89          return ShardingRuleConfiguration.class;
90      }
91  }