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.driver.yaml;
19  
20  import lombok.Getter;
21  import lombok.Setter;
22  import org.apache.shardingsphere.authority.yaml.config.YamlAuthorityRuleConfiguration;
23  import org.apache.shardingsphere.globalclock.yaml.config.YamlGlobalClockRuleConfiguration;
24  import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration;
25  import org.apache.shardingsphere.infra.yaml.config.pojo.mode.YamlModeConfiguration;
26  import org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlGlobalRuleConfiguration;
27  import org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
28  import org.apache.shardingsphere.parser.yaml.config.YamlSQLParserRuleConfiguration;
29  import org.apache.shardingsphere.sqlfederation.yaml.config.YamlSQLFederationRuleConfiguration;
30  import org.apache.shardingsphere.sqltranslator.yaml.config.YamlSQLTranslatorRuleConfiguration;
31  import org.apache.shardingsphere.transaction.yaml.config.YamlTransactionRuleConfiguration;
32  
33  import java.util.Collection;
34  import java.util.HashMap;
35  import java.util.LinkedList;
36  import java.util.Map;
37  import java.util.Properties;
38  
39  /**
40   * YAML JDBC configuration.
41   */
42  @Getter
43  @Setter
44  public final class YamlJDBCConfiguration implements YamlConfiguration {
45      
46      private String databaseName;
47      
48      private Map<String, Map<String, Object>> dataSources = new HashMap<>();
49      
50      private Collection<YamlRuleConfiguration> rules = new LinkedList<>();
51      
52      private YamlModeConfiguration mode;
53      
54      private YamlAuthorityRuleConfiguration authority;
55      
56      private YamlSQLParserRuleConfiguration sqlParser;
57      
58      private YamlTransactionRuleConfiguration transaction;
59      
60      private YamlGlobalClockRuleConfiguration globalClock;
61      
62      private YamlSQLFederationRuleConfiguration sqlFederation;
63      
64      private YamlSQLTranslatorRuleConfiguration sqlTranslator;
65      
66      private Properties props = new Properties();
67      
68      /**
69       * Rebuild YAML JDBC configuration.
70       */
71      public void rebuild() {
72          rules.removeIf(YamlGlobalRuleConfiguration.class::isInstance);
73          if (null != authority) {
74              rules.add(authority);
75          }
76          if (null != sqlParser) {
77              rules.add(sqlParser);
78          }
79          if (null != transaction) {
80              rules.add(transaction);
81          }
82          if (null != globalClock) {
83              rules.add(globalClock);
84          }
85          if (null != sqlFederation) {
86              rules.add(sqlFederation);
87          }
88          if (null != sqlTranslator) {
89              rules.add(sqlTranslator);
90          }
91      }
92  }