<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~ JBoss, Home of Professional Open Source.
  ~ Copyright 2016, Red Hat Middleware LLC, and individual contributors
  ~ as indicated by the @author tags. See the copyright.txt file in the
  ~ distribution for a full listing of individual contributors.
  ~
  ~ This is free software; you can redistribute it and/or modify it
  ~ under the terms of the GNU Lesser General Public License as
  ~ published by the Free Software Foundation; either version 2.1 of
  ~ the License, or (at your option) any later version.
  ~
  ~ This software is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  ~ Lesser General Public License for more details.
  ~
  ~ You should have received a copy of the GNU Lesser General Public
  ~ License along with this software; if not, write to the Free
  ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  ~
  -->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="urn:jboss:domain:transactions:5.0"
           xmlns="urn:jboss:domain:transactions:5.0"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified"
           version="4.1">

    <!-- The transaction subsystem root element -->
    <xs:element name="subsystem" type="subsystem"/>

    <xs:complexType name="subsystem">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                The configuration of the transactions subsystem.
            ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="core-environment" type="core-environment" maxOccurs="1"/>
            <xs:element name="recovery-environment" type="recovery-environment" maxOccurs="1"/>
            <xs:element name="coordinator-environment" type="coordinator-environment" minOccurs="0" maxOccurs="1"/>
            <xs:element name="object-store" type="object-store" minOccurs="0" maxOccurs="1"/>
            <xs:element name="jts" type="jts-Type" minOccurs="0" maxOccurs="1"/>
            <xs:choice minOccurs="0" maxOccurs="1">
                <xs:element name="use-journal-store" type="use-journal-store-Type" minOccurs="0" maxOccurs="1"/>
                <xs:element name="jdbc-store" type="jdbc-store-Type" minOccurs="0" maxOccurs="1"/>
            </xs:choice>
            <xs:element name="commit-markable-resources" type="cmr-resources-Type" minOccurs="0" maxOccurs="1"></xs:element>
        </xs:sequence>


    </xs:complexType>

    <xs:complexType name="recovery-environment">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                The recovery environment configuration.

                The "socket-binding" attribute is used to reference the correct socket binding to use for the
                recovery environment.
                The "status-socket-binding" attribute is used to reference the correct socket binding to use for the
                transaction status manager.
                The "recovery-listener" attribute sets if recovery system should listen on a network socket or not.
            ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="socket-binding" type="xs:string" />
        <xs:attribute name="status-socket-binding" type="xs:string" />
        <xs:attribute name="recovery-listener" type="xs:boolean" default="false"/>
    </xs:complexType>

    <xs:complexType name="core-environment">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                The core environment configuration.

                The process-id element specifies the process id implemention.
                The "node-identifier" attribute is used to set the node identifier on the core environment.
            ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:all>
            <xs:element name="process-id" type="process-id" />
        </xs:all>
        <xs:attribute name="node-identifier" type="xs:string" default="1"/>
    </xs:complexType>
    <xs:complexType name="process-id">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                The process identifer implementation
                The "node-identifier" attribute is used to set the node identifier on the core environment.
                The "socket-process-id-max-ports" attribute is used to set the max ports on the core environment.
            ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:choice>
            <xs:element name="uuid" type="uuid" />
            <xs:element name="socket" type="socket-id" />
        </xs:choice>
    </xs:complexType>
    <xs:complexType name="uuid">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                The UUID based process identifer implementation
            ]]>
            </xs:documentation>
        </xs:annotation>
    </xs:complexType>
    <xs:complexType name="socket-id">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                The socket based process identifer implementation
                The "socket-binding" attribute is used to specify the port to bind to.
                The "socket-process-id-max-ports" attribute is used to set the max ports on the core environment.
            ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="socket-binding" type="xs:string" use="required"/>
        <xs:attribute name="socket-process-id-max-ports" type="xs:int" default="10" />
    </xs:complexType>

    <xs:attribute name="socket-process-id-max-ports" type="xs:int" default="10" />

    <xs:complexType name="coordinator-environment">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                The coordinator environment configuration.
                statistics-enabled - if recording of transaction statistics is enabled, false otherwise.
                enable-tsm-status - if the transaction status manager (TSM) service, needed for out of process recovery, should be provided or not.
                default-timeout - the default transaction lifetime, in seconds.
                maximum-timeout - the maximum transaction lifetime, in seconds.
            ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="statistics-enabled" type="xs:boolean" default="false"/>
        <xs:attribute name="enable-statistics" type="xs:boolean" default="false">
            <xs:annotation>
                <xs:documentation>
                    <![CDATA[ Deprecated. Use statistics-enabled. ]]>
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="enable-tsm-status" type="xs:boolean" default="false"/>
        <xs:attribute name="default-timeout" type="xs:int" default="300" />
        <xs:attribute name="maximum-timeout" type="xs:int" default="31536000" />
    </xs:complexType>

    <xs:complexType name="object-store">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                The object store configuration.

                The "path" attribute denotes a relative or absolute filesystem path denoting where the transaction
                manager object store should store data.

                The "relative-to" attribute references a global path configuration in the domain model, defaulting
                to the JBoss Application Server data directory (jboss.server.data.dir). If the value of the "path" attribute
                does not specify an absolute pathname, it will treated as relative to this path.
            ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="path" type="xs:string" default="tx-object-store"/>
        <xs:attribute name="relative-to" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="jts-Type">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                The flag to enable JTS.
            ]]>
            </xs:documentation>
        </xs:annotation>
    </xs:complexType>

    <xs:complexType name="use-journal-store-Type">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                The flag to enable the journal transaction log store.
            ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="enable-async-io" type="xs:boolean" use="optional" default="false">
            <xs:annotation>
                <xs:documentation>
                    <![CDATA[
                        Enable AsyncIO for the journal transaction log store.
                        ]]>
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="jdbc-store-Type">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                        The presence of this tag enable the jdbc transaction log store.
                    ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:all>
            <xs:element name="action" type="jdbc-store-settings-Type" minOccurs="0" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation>
                        <![CDATA[
                             Configure jdbc store for default action store. If not present defaults are used.
                                ]]>
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="communication" type="jdbc-store-settings-Type" minOccurs="0" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation>
                        <![CDATA[
                            Configure jdbc store for communication store. If not present defaults are used.
                                ]]>
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="state" type="jdbc-store-settings-Type" minOccurs="0" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation>
                        <![CDATA[
                           Configure jdbc store for state store. If not present defaults are used.
                                ]]>
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:all>
        <xs:attribute name="datasource-jndi-name" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation>
                    <![CDATA[
                        Configure datasource jndi used to connect for jdbc store
                        ]]>
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="jdbc-store-settings-Type">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                    Settings for jdbc store
                    ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="table-prefix" type="xs:string" use="optional" />
        <xs:attribute name="drop-table" type="xs:boolean" use="optional" default="false"/>
    </xs:complexType>

    <xs:complexType name="cmr-resources-Type">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                    A list of non XA aware datasources that can reliably participate in an XA transaction.
                    ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:all>
            <xs:element name="commit-markable-resource" type="cmr-resource-Type" minOccurs="1"/>
        </xs:all>
    </xs:complexType>

    <xs:complexType name="cmr-resource-Type">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                    Settings for a single commit markable resource.
					Each datasource must be defined in the datasources subsystem configuration and
					each one must be marked with the connectable="true" attribute.
                    ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:all>
            <xs:element name="xid-location" type="cmr-table-Type" minOccurs="0" maxOccurs="1"/>
        </xs:all>
        <xs:attribute name="jndi-name" type="xs:token" use="required"/>
    </xs:complexType>

    <xs:complexType name="cmr-table-Type">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                    Storage settings for a single commit markable resource. For datasource resources
					this will specifiy the table name where the xid of the commit-markable-resource
					is stored
                    ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="name" type="xs:token" use="optional" default="xids">
            <xs:annotation>
                <xs:documentation>
                    <![CDATA[
					A name for the storage location
					]]>
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="immediate-cleanup" type="xs:boolean" use="optional" default="true">
            <xs:annotation>
                <xs:documentation>
                    <![CDATA[
					Indicates whether the entry should be removed as soon as the transaction has
					completed
					]]>
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="batch-size" type="xs:integer" use="optional" default="100">
            <xs:annotation>
                <xs:documentation>
                    <![CDATA[
					If deletion of entries are deferred to the recovery module (ie immediate-cleanup
					is set to false) then the batch size specifies how many xids to remove per DML
					statement. Tuning the batch size is resource manager specific.
					]]>
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

</xs:schema>