#    Copyright 2013 Red Hat, Inc. and/or its affiliates.
#
#    This file is part of jcliff.
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program 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 General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

name=datasource
getContents=/subsystem=datasources:read-children-resources(child-type=data-source)
server.preprocess.prepend=/datasource

prefix.undefine=undefine:/
undefine.rule.1=/subsystem=datasources${cmdpath(${path(..)})}:undefine-attribute(name=${name(.)})
undefine.refresh=true

match.add=add:/datasource/*
add.rule.1=data-source add --name=${name(.)} --jndi-name=${value(jndi-name)} --driver-name=${value(driver-name)} --connection-url=${value(connection-url)}
add.rule.2=if result.value==false of /subsystem=datasources/datasource=${name(.)}:read-resource 
add.rule.3=data-source enable --name=${name(.)}
add.rule.4=:reload
add.refresh=true


match.modify=modify:/datasource/*/*
modify.rule.1=/subsystem=datasources/data-source=${name(..)}:write-attribute(name=${name(.)},value=${value(.)})


match.delete=remove:/datasource/*
delete.rule.1=data-source disable --name=${name(.)}
delete.rule.2=data-source remove --name=${name(.)}
delete.refresh=true


match.undefine=undefine:/datasource/*/*
undefine.rule.1=/subsystem=datasources/data-source=${name(..)}:undefine-attribute(name=${name(.)})

match.addConnProperty=add:/datasource/*/connection-properties/*
addConnProperty.rule.1=/subsystem=datasources/data-source=${name(../..)}/connection-properties=${name(.)}:add(value=${value(value)})
addConnProperty.refresh=true
addConnProperty.precedence=20

match.removeConnProperty=remove:/datasource/*/connection-properties/*
removeConnProperty.rule.1=/subsystem=datasources/data-source=${name(../..)}/connection-properties=${name(.)}:remove
removeConnProperty.refresh=true
removeConnProperty.precedence=20

#match.addConnPropertyValue=add:/datasource/*/connection-properties/*/value
#addConnPropertyValue.rule.1=/subsystem=datasources/data-source=${name(../../..)}/connection-properties=${name(..)}:remove
#addConnPropertyValue.rule.2=:reload
#addConnPropertyValue.rule.3=/subsystem=datasources/data-source=${name(../../..)}/connection-properties=${name(..)}:add(value=${value(.)})
#addConnPropertyValue.rule.4=:reload
#addConnPropertyValue.refresh=true
#addConnPropertyValue.precedence=30

#match.modifyConnPropertyValue=modify:/datasource/*/connection-properties/*/value
#modifyConnPropertyValue.rule.1=/subsystem=datasources/data-source=${name(../../..)}/connection-properties=${name(..)}:remove
#modifyConnPropertyValue.rule.2=:reload
#modifyConnPropertyValue.rule.3=/subsystem=datasources/data-source=${name(../../..)}/connection-properties=${name(..)}:add(value=${value(.)})
#modifyConnPropertyValue.rule.4=:reload
#modifyConnPropertyValue.refresh=true

#modifyConnPropertyValue.precedence=40


