<?xml version="1.0" encoding="ISO-8859-1"?>
<persistence-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="../../../../defs/config-metier/Persistence.xsd">
    <layer name="mysql" persistence-model="xemelios-sql">
        <!-- persistence-model defines the way informations are defined -->
        <!-- only xemelios-sql is defined at this moment -->
        <document id="DocumentRapport" repository-import-xslt-file="">
            <table type="repository" base-name="RAPPORT_REPOSITORY" version="2">
                CREATE TABLE IF NOT EXISTS ${base-name} (
                ID VARCHAR(25),
                LIBELLE VARCHAR(100),
                COLLECTIVITE VARCHAR(15) NOT NULL,
                REPOSITORY LONGBLOB,
                ENCODING VARCHAR(20)
                ) TYPE MYISAM
                <patch from-version="1">
                    <sql failonerror="false">ALTER TABLE ${base-name} ADD ID VARCHAR(25)</sql>
                    <sql failonerror="false">ALTER TABLE ${base-name} ADD LIBELLE VARCHAR(100)</sql>
                </patch>
            </table>
            <table type="special-key" base-name="RAPPORT_SPECIAL_KEYS" version="1">
                CREATE TABLE IF NOT EXISTS ${base-name} (
                COLLECTIVITE VARCHAR(15) NOT NULL,
                BUDGET VARCHAR(24) NOT NULL,
                INITIAL_DOC_NAME VARCHAR(100) NOT NULL,
                KEY1 VARCHAR(100) NOT NULL,
                LIB1 VARCHAR(200),
                KEY2 VARCHAR(100),
                LIB2 VARCHAR(200),
                KEY3 VARCHAR(100),
                LIB3 VARCHAR(200),
                INDEX IX_${base-name}_BC (COLLECTIVITE,BUDGET)
                ) TYPE MYISAM
            </table>
            <table type="list-bc" base-name="RAPPORT_LIST_BUDG_COLL" version="1">
                CREATE TABLE IF NOT EXISTS ${base-name} (
                COLLECTIVITE VARCHAR(15) NOT NULL,
                BUDGET VARCHAR(24) NOT NULL,
                BUDGET_LIB VARCHAR(200),
                COLLECTIVITE_LIB VARCHAR(200),
                INITIAL_DOC_NAME VARCHAR(100) NOT NULL,
                INDEX IX_${base-name}_BC (COLLECTIVITE,BUDGET)
                ) TYPE MYISAM
            </table>
            <etat id="DonneesRapport" import-xslt-file="rapport/etatRapport-import-mysql.xsl" >
                <table type="document" base-name="RAPPORT_DOCUMENTS" version="1">
                    CREATE TABLE IF NOT EXISTS ${base-name} ( 
                    COLLECTIVITE VARCHAR(15) NOT NULL, 
                    BUDGET VARCHAR(24) NOT NULL, 
                    INITIAL_DOC_NAME VARCHAR(100) NOT NULL, 
                    DOC_ID VARCHAR(100) NOT NULL, 
                    DOC LONGBLOB, 
                    ENCODING VARCHAR(20), 
                    INDEX IX_${base-name}_BC (COLLECTIVITE,BUDGET,DOC_ID) 
                    ) TYPE MYISAM
                </table>
                <table type="index" id="RAPPORT_IX" base-name="RAPPORT_IX" version="1" main="true">
                    CREATE TABLE IF NOT EXISTS ${base-name} ( 
                    COLLECTIVITE VARCHAR(15) NOT NULL, 
                    BUDGET VARCHAR(24) NOT NULL, 
                    DOC_ID VARCHAR(100) NOT NULL, 
                    LIBELLE VARCHAR(255) ,
                    ID VARCHAR(255) ,
                    CODE VARCHAR(255) ,
                    DATECONTROLE VARCHAR(255) ,
                    SIRET VARCHAR(255) ,
                    DOCID VARCHAR(255) ,
                    INDEX IX_${base-name}_BC (COLLECTIVITE,BUDGET,DOC_ID), 
                    INDEX IX_${base-name}_DC (DOC_ID)
                    ) TYPE MYISAM
                </table>

                
                <!-- CRITERIA /DocumentRapport -->
                <criteria id="CRI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_LIBELLE" type="1" sql-index-id="SQI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_LIBELLE">
                    <where-clause>fn:string-compare(${table}.${column},Libelle)</where-clause>
                </criteria>
                <criteria id="CRI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_ID" type="1" sql-index-id="SQI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_ID">
                    <where-clause>fn:string-compare(${table}.${column},ID)</where-clause>
                </criteria>
                <criteria id="CRI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_CODE" type="1" sql-index-id="SQI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_CODE">
                    <where-clause>fn:string-compare(${table}.${column},Code)</where-clause>
                </criteria>
                <criteria id="CRI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_DATECONTROLE" type="1" sql-index-id="SQI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_DATECONTROLE">
                    <where-clause>fn:date-compare(${table}.${column},dateControle)</where-clause>
                </criteria>
                <criteria id="CRI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_SIRET" type="1" sql-index-id="SQI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_SIRET">
                    <where-clause>fn:string-compare(${table}.${column},Siret)</where-clause>
                </criteria>
                <criteria id="CRI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_DOCID" type="1" sql-index-id="SQI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_DOCID">
                    <where-clause>${table}.${column}='##VALEUR:docId##'</where-clause>
                </criteria>
                
                
                <!-- SQL-INDEX /DocumentRapport -->
                <sql-index id="SQI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_LIBELLE"         path="/n:DocumentRapport/n:Budget/n:Libelle/@n:V"                   column="LIBELLE" datatype="string" table="RAPPORT_IX" />
                <sql-index id="SQI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_ID"              path="/n:DocumentRapport/n:DonneesRapport/n:Rapport/n:Id/@n:V"    column="ID" datatype="string" table="RAPPORT_IX" />
                <sql-index id="SQI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_CODE"            path="/n:DocumentRapport/n:Budget/n:Code/@n:V"                      column="CODE" datatype="string" table="RAPPORT_IX" />
                <sql-index id="SQI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_DATECONTROLE"    path="/n:DocumentRapport/n:DateControle/@n:V"                         column="DATECONTROLE" datatype="string" table="RAPPORT_IX" />
                <sql-index id="SQI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_SIRET"           path="/n:DocumentRapport/n:Collectivite/n:Siret/@n:V"               column="SIRET" datatype="string" table="RAPPORT_IX" />
                <sql-index id="SQI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_DOCID"           path="/n:DocumentRapport/n:DocId/@n:V"                                column="DOCID" datatype="string" table="RAPPORT_IX" />
                <!--sql-index id="SQI_DOCUMENTRAPPORT_DOCUMENTRAPPORT_ID_M"            path="/n:DocumentRapport/n:DonneesRapport/n:Rapport/n:Id/@n:V"    column="ID" datatype="string" table="RAPPORT_IX" /-->
                
            </etat>
        </document>
    </layer>
</persistence-config>