<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ 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.
  -->

<xsd:schema xmlns="http://shardingsphere.apache.org/schema/shardingsphere/sharding"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:beans="http://www.springframework.org/schema/beans"
            xmlns:encrypt="http://shardingsphere.apache.org/schema/shardingsphere/encrypt"
            targetNamespace="http://shardingsphere.apache.org/schema/shardingsphere/sharding"
            elementFormDefault="qualified" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://shardingsphere.apache.org/schema/shardingsphere/encrypt http://shardingsphere.apache.org/schema/shardingsphere/encrypt/encrypt.xsd">
    <xsd:import namespace="http://www.springframework.org/schema/beans" schemaLocation="http://www.springframework.org/schema/beans/spring-beans.xsd" />
    <xsd:import namespace="http://shardingsphere.apache.org/schema/shardingsphere/encrypt" schemaLocation="http://shardingsphere.apache.org/schema/shardingsphere/encrypt/encrypt.xsd"/>
    <xsd:element name="data-source">
        <xsd:complexType>
            <xsd:all>
                <xsd:element ref="sharding-rule" />
                <xsd:element ref="props" minOccurs="0" />
            </xsd:all>
            <xsd:attribute name="id" type="xsd:string" use="required" />
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="sharding-rule">
        <xsd:complexType>
            <xsd:all>
                <xsd:element ref="master-slave-rules" minOccurs="0" />
                <xsd:element ref="table-rules" minOccurs="0" />
                <xsd:element ref="binding-table-rules" minOccurs="0" />
                <xsd:element ref="broadcast-table-rules" minOccurs="0" />
                <xsd:element name="encrypt-rule" type="encrypt:encrypt-rule" minOccurs="0" />
            </xsd:all>
            <xsd:attribute name="data-source-names" type="xsd:string" use="required" />
            <xsd:attribute name="default-data-source-name" type="xsd:string" />
            <xsd:attribute name="default-database-strategy-ref" type="xsd:string" />
            <xsd:attribute name="default-table-strategy-ref" type="xsd:string" />
            <xsd:attribute name="default-key-generator-ref" type="xsd:string" />
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="table-rules">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="table-rule" maxOccurs="unbounded" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="table-rule">
        <xsd:complexType>
            <xsd:attribute name="logic-table" type="xsd:string" use="required" />
            <xsd:attribute name="actual-data-nodes" type="xsd:string" />
            <xsd:attribute name="database-strategy-ref" type="xsd:string" />
            <xsd:attribute name="table-strategy-ref" type="xsd:string" />
            <xsd:attribute name="key-generator-ref" type="xsd:string" />
            <xsd:attribute name="logic-index" type="xsd:string" />
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="binding-table-rules">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="binding-table-rule" maxOccurs="unbounded" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="binding-table-rule">
        <xsd:complexType>
            <xsd:attribute name="logic-tables" type="xsd:string" use="required" />
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="broadcast-table-rules">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="broadcast-table-rule" maxOccurs="unbounded" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="broadcast-table-rule">
        <xsd:complexType>
            <xsd:attribute name="table" type="xsd:string" use="required" />
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="standard-strategy">
        <xsd:complexType>
            <xsd:attribute name="id" type="xsd:string" use="required" />
            <xsd:attribute name="sharding-column" type="xsd:string" use="required" />
            <xsd:attribute name="precise-algorithm-ref" type="xsd:string" use="required" />
            <xsd:attribute name="range-algorithm-ref" type="xsd:string" />
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="complex-strategy">
        <xsd:complexType>
            <xsd:attribute name="id" type="xsd:string" use="required" />
            <xsd:attribute name="sharding-columns" type="xsd:string" use="required" />
            <xsd:attribute name="algorithm-ref" type="xsd:string" use="required" />
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="inline-strategy">
        <xsd:complexType>
            <xsd:attribute name="id" type="xsd:string" use="required" />
            <xsd:attribute name="sharding-column" type="xsd:string" use="required" />
            <xsd:attribute name="algorithm-expression" type="xsd:string" use="required" />
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="hint-strategy">
        <xsd:complexType>
            <xsd:attribute name="id" type="xsd:string" use="required" />
            <xsd:attribute name="algorithm-ref" type="xsd:string" use="required" />
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="none-strategy">
        <xsd:complexType>
            <xsd:attribute name="id" type="xsd:string" use="required" />
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="master-slave-rules">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="master-slave-rule" maxOccurs="unbounded" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="master-slave-rule">
        <xsd:complexType>
            <xsd:attribute name="id" type="xsd:string" use="required" />
            <xsd:attribute name="master-data-source-name" type="xsd:string" use="required" />
            <xsd:attribute name="slave-data-source-names" type="xsd:string" use="required" />
            <xsd:attribute name="strategy-ref" type="xsd:string" />
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="key-generator">
        <xsd:complexType>
            <xsd:attribute name="id" type="xsd:string" use="required" />
            <xsd:attribute name="column" type="xsd:string" />
            <xsd:attribute name="type" type="xsd:string" />
            <xsd:attribute name="props-ref" type="xsd:string" />
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="props">
        <xsd:complexType>
            <xsd:complexContent>
                <xsd:extension base="beans:propsType" />
            </xsd:complexContent>
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="tx-type-annotation-driven" />
</xsd:schema>
