<?xml version="1.0" encoding="UTF-8"?>

<!-- 
/* ========================================================================= *
 *                 The Apache Software License,  Version 1.1                 *
 * ========================================================================= *
 *                                                                           *
 *         Copyright (c) 1999-2003  The Apache Software Foundation.          *
 *                           All rights reserved.                            *
 *                                                                           *
 * Redistribution and use in source and binary forms,  with or without modi- *
 * fication, are permitted provided that the following conditions are met:   *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions, and the following disclaimer.                 *
 *                                                                           *
 * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
 *    notice,  this list of conditions  and the following  disclaimer in the *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. The end-user documentation  included with the redistribution,  if any, *
 *    must include the following acknowlegement:                             *
 *                                                                           *
 *       "This product includes  software developed  by the Apache  Software *
 *        Foundation (http://www.apache.org/)."                              *
 *                                                                           *
 *    Alternately, this acknowlegement may appear in the software itself, if *
 *    and wherever such third-party acknowlegements normally appear.         *
 *                                                                           *
 * 4. The names  "DewDrop", "The  Jakarta  Project", and  "Apache  Software  *
 *    Foundation"  must not be used  to endorse or promote  products derived *
 *    from this  software without  prior  written  permission.  For  written *
 *    permission, please contact <apache@apache.org>.                        *
 *                                                                           *
 * 5. Products derived from this software may not be called "Apache" nor may *
 *    "Apache" appear in their names without prior written permission of the *
 *    Apache Software Foundation.                                            *
 *                                                                           *
 * ========================================================================= *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
 * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
 * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
 * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
 * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
 * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
 * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
 * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
 * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
 * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
 * POSSIBILITY OF SUCH DAMAGE.                                               *
 *                                                                           *
 * ========================================================================= *
 *                                                                           *
 * This software  consists of voluntary  contributions made  by many indivi- *
 * duals on behalf of the  Apache Software Foundation.  For more information *
 * on the Apache Software Foundation, please see (http://www.apache.org/).   *
 *                                                                           *
 * ========================================================================= */
-->
<!-- 
  CVS Information: 
  $Revision: 1.10 $
  $Date: 2003/06/27 23:28:21 $
  $Source: /cvsroot/dewdrop/datamodel/src/xml/database.xsd,v $
  $Author: pharaohh $
-->

<schema targetNamespace="http://dewdrop.sourceforge.net/xmlns/database_1_0"
        xmlns:dddb="http://dewdrop.sourceforge.net/xmlns/database_1_0"
        xmlns:rdbms="http://dewdrop.sourceforge.net/xmlns/rdbms/1_0_0/rdbms.xsd"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
        xmlns="http://www.w3.org/2001/XMLSchema" 
        xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
        jaxb:version="1.0"
        elementFormDefault="qualified" 
        attributeFormDefault="unqualified">


    <annotation>
        <appinfo>
            <jaxb:globalBindings 
                 fixedAttributeAsConstantProperty="true" 
                 collectionType="java.util.Vector"
                 typesafeEnumBase="xsd:NMTOKEN" 
                 choiceContentProperty="false" 
                 typesafeEnumMemberName="generateError"
                 bindingStyle="elementBinding"   
                 enableFailFastCheck="false" 
                 generateIsSetMethod="false" 
                 underscoreBinding="asCharInWord"/>
             <jaxb:schemaBindings> 
                 <jaxb:package name="net.sf.dewdrop.database.bind"/> 
             </jaxb:schemaBindings>
        </appinfo>
    </annotation>
    

    <!-- SIMPLE TYPE DEFINITIONS -->
    
    <simpleType name="sqlDataType">
        <annotation>
            <appinfo>
                <jaxb:typesafeEnumClass/>
             </appinfo>
        </annotation>
        <restriction base="xsd:NMTOKEN">
            
            <!-- Numeric Types -->
            <enumeration value="tinyInt"/>  <!-- usually 1 byte   --> <!-- exact -->
            <enumeration value="smallInt"/> <!-- usually 2 bytes  --> <!-- exact -->
            <enumeration value="integer"/>  <!-- usually 4 bytes  --> <!-- exact -->
            <enumeration value="bigInt"/>   <!-- usually 8 bytes  --> <!-- exact -->
            <enumeration value="float"/>    <!-- usually 4 bytes  --> <!-- inexact -->
            <enumeration value="real"/>     <!-- usually 4 bytes  --> <!-- inexact --> <!--same as float-->
            <enumeration value="double"/>   <!-- usually 8 bytes  --> <!-- inexact -->
            <enumeration value="decimal"/>  <!-- unlimited        --> <!-- exact   -->    
            <enumeration value="numeric"/>  <!-- unlimited        --> <!-- exact   -->
            
            <!-- Character Types -->
            <enumeration value="char"/>
            <enumeration value="varChar"/>
            <enumeration value="longVarChar"/> <!-- larger than varchar but smaller than text -->
            <enumeration value="text"/>        <!-- large values of text (a.k.a 'clob' in Oracle -->
            
            <!-- Binary Types -->
            <enumeration value="bit"/>    <!-- predefined length bit string -->
            <enumeration value="varBit"/> <!-- varying length bit string: e.g.'01001' or '011001010101' -->
            <enumeration value="longVarBit"/> <!-- longer binary strings than varbit -->
            <enumeration value="binary"/>  <!-- anything non-text larger than longVarBit: files, byte-code, 
                                                a.k.a. "bytea" in PostgreSQL or "blob" in Oracle -->
            
            <!-- Date/Time Types -->
            <enumeration value="date"/>      <!-- date only:         e.g. YYYY-MM-DD                    -->
            <enumeration value="time"/>      <!-- time only:         e.g. HH:MM:SS.ms                   -->
            <enumeration value="timeTZ"/>    <!-- time with timezone:e.g. HH:MM:SS.ms-05:00             -->
            <enumeration value="timestamp"/> <!-- datetime only:     e.g. YYYY-MM-DD HH:MM:SS.ms        -->
            <enumeration value="timestampTZ"/><!-- datetime timezone:e.g. YYYY-MM-DD HH:MM:SS.ms -08:00 -->
            <enumeration value="interval"/> <!-- length of time:e.g. 1 day 12 hours 59 minutes 3 seconds-->
        
        
            <!-- Boolean Types -->
            <enumeration value="boolean"/> <!-- 'TRUE' or 'FALSE'...not 't', 'f', 0, 1, or anything else-->
            
            <!-- Additional SQL99 Types -->
            <!-- These are not yet implemented: -->
            <enumeration value="struct"/>
            <enumeration value="array"/>
            <enumeration value="ref"/>            
        </restriction>
    </simpleType>

    <simpleType name="modificationAction">
        <annotation>
            <appinfo>
                <jaxb:typesafeEnumClass/>
             </appinfo>
        </annotation>
        <restriction base="xsd:NMTOKEN">
            <enumeration value="cascade"/>
            <enumeration value="setNull"/>
            <enumeration value="setDefault"/>
            <enumeration value="noAction"/>
        </restriction>
    </simpleType>
    
    <!-- END SIMPLE TYPE DEFINITIONS -->
    
    
    
    
    <!-- BEGIN COMPLEX TYPE DEFINITIONS -->

    <!-- Element that allows a user to define native sql code for whatever
         target they want.  This is to allow them to define elements only
         their database may support, or things that DewDrop does not yet
         support.
    -->
    <complexType name="nativeType">
        <simpleContent>
    	    <extension base="string">
                <attribute name="target" type="string"/>
            </extension>
        </simpleContent>
    </complexType>
    <element name="native" type="dddb:nativeType"/>


    <complexType name="sequenceType">
        <attribute name="name" type="token" use="required"/>
        <attribute name="startVal" type="integer"/>
        <attribute name="maxVal" type="integer"/>
        <attribute name="incrementBy" type="integer">
            <annotation>
                <appinfo>
                    <!-- <jaxb:javaType name="int"/> -->
                </appinfo>
            </annotation>
        </attribute>
    </complexType>
    <element name="sequence" type="dddb:sequenceType"/>


    <complexType name="columnRefType">
        <attribute name="local" type="token" use="required"/>
        <attribute name="foreign" type="token"/>
    </complexType>
    <element name="columnRef" type="dddb:columnRefType"/>
    

    <complexType name="primaryKeyType">
        <sequence>
            <element ref="dddb:columnRef" minOccurs="1" maxOccurs="unbounded">
            <!--
                <annotation>
                    <appinfo>
                        <jaxb:property name="columnRefs"/>
                    </appinfo>
                </annotation>
	    -->
            </element>
        </sequence>
        <attribute name="name" type="token"/>
    </complexType>
    <element name="primaryKey" type="dddb:primaryKeyType"/>
    

    <complexType name="foreignKeyType">
        <sequence>
            <element ref="dddb:columnRef" minOccurs="1" maxOccurs="unbounded">
                 <annotation>
                    <appinfo>
                      <!-- <jaxb:property name="ColumnRefs"/> -->
                    </appinfo>
                </annotation>
            </element>            
        </sequence>
        <attribute name="name" type="token"/>
        <attribute name="foreignTable" type="token" use="required"/>
        <attribute name="onUpdate" type="dddb:modificationAction"/>
        <attribute name="onDelete" type="dddb:modificationAction"/>
    </complexType>
    <element name="foreignKey" type="dddb:foreignKeyType"/>
    
    
    <complexType name="uniqueType">
        <sequence>
            <element ref="dddb:columnRef" minOccurs="1" maxOccurs="unbounded">
                <annotation>
                    <appinfo>
                      <!-- <jaxb:property name="ColumnRefs"/> -->
                    </appinfo>
                </annotation>
            </element>
        </sequence>
        <attribute name="name" type="token"/>
    </complexType>
    <element name="unique" type="dddb:uniqueType"/>
    
                
    <complexType name="notNullType">
        <sequence>
            <element ref="dddb:columnRef" minOccurs="1" maxOccurs="1">
                <annotation>
                    <appinfo>
                      <!-- <jaxb:property name="ColumnRefs"/> -->
                    </appinfo>
                </annotation>
            </element>
        </sequence>
        <attribute name="name" type="token"/>
    </complexType>
    <element name="notNull" type="dddb:notNullType"/>
    
    
    <complexType name="constraintType">
        <sequence>
            <choice>
                <element ref="dddb:unique" minOccurs="1" maxOccurs="1"/>
                <element ref="dddb:notNull" minOccurs="1" maxOccurs="1"/>
                <element ref="dddb:primaryKey" minOccurs="1" maxOccurs="1"/>
                <element ref="dddb:foreignKey" minOccurs="1" maxOccurs="1"/>
            </choice>
        </sequence>
        <attribute name="name" type="token"/>
    </complexType>
    <element name="constraint" type="dddb:constraintType"/>


    <complexType name="columnType">
        <sequence>
            <element ref="dddb:foreignKey" minOccurs="0" maxOccurs="1"/>
        </sequence>
        <attribute name="name" type="token" use="required"/>
        <attribute name="sysName" type="token"/>
        <attribute name="type" type="dddb:sqlDataType" use="required"/>
        <attribute name="length" type="integer"/>
        <attribute name="precision" type="integer"/>
        <attribute name="default" type="anySimpleType"/>
        <attribute name="required" type="boolean"/>
        <attribute name="unique" type="boolean"/>
        <attribute name="primaryKey" type="boolean"/>
        <attribute name="tableRef" type="token"/>
        <attribute name="columnRef" type="token"/>
        <attribute name="onDelete" type="dddb:modificationAction"/>
        <attribute name="onUpdate" type="dddb:modificationAction"/>
    </complexType>
    <element name="column" type="dddb:columnType"/>
   
   
    <group name="repeatableTableConstraints">
        <choice>
            <element ref="dddb:foreignKey" minOccurs="0" maxOccurs="unbounded"/>
            <element ref="dddb:unique" minOccurs="0" maxOccurs="unbounded"/>
            <element ref="dddb:notNull" minOccurs="0" maxOccurs="unbounded"/>
        </choice>
    </group>
    
        
    <complexType name="tableType">
        <sequence>
            <element ref="dddb:column" minOccurs="1" maxOccurs="unbounded">
                <annotation>
                    <appinfo>
                      <!-- <jaxb:property name="Columns"/> -->
                    </appinfo>
                </annotation>
            </element>
            <element ref="dddb:primaryKey" minOccurs="0" maxOccurs="1"/>
            <group ref="dddb:repeatableTableConstraints" minOccurs="0" maxOccurs="unbounded"/>
            <element ref="dddb:native" minOccurs="0" maxOccurs="unbounded"/>
        </sequence>
        <attribute name="name" type="token" use="required"/>
        <attribute name="global" type="boolean" default="false"/>
        <attribute name="temporary" type="boolean" default="false"/>
    </complexType>
    <element name="table" type="dddb:tableType"/>
    

    <complexType name="indexType">
        <sequence>
            <element ref="dddb:columnRef" minOccurs="1" maxOccurs="unbounded">
                <annotation>
                    <appinfo>
                      <!-- <jaxb:property name="ColumnRefs"/> -->
                    </appinfo>
                </annotation>
            </element>
        </sequence>
        <attribute name="name" type="token"/>
        <attribute name="targetTable" type="token" use="required"/>
	<attribute name="unique" type="boolean" default="false"/>
	<attribute name="fullText" type="boolean" default="false"/>
    </complexType>
    <element name="index" type="dddb:indexType"/>
    
    
    <!-- Used for adding constraints via the "alteration" element below. -->
    <complexType name="addType">
        <choice>
            <element ref="dddb:column" minOccurs="1" maxOccurs="unbounded">
                <annotation>
                    <appinfo>
                      <!-- <jaxb:property name="Columns"/> -->
                    </appinfo>
                </annotation>
            </element>
            <element ref="dddb:constraint" minOccurs="1" maxOccurs="1"/>
        </choice>
    </complexType>
    <element name="add" type="dddb:addType"/>


    <complexType name="alterationType">
        <choice>
            <element ref="dddb:add"/>
        </choice>
        <attribute name="targetTable" type="token" use="required"/>
    </complexType>
    <element name="alteration" type="dddb:alterationType"/>
    
    <group name="databaseComponents">
        <sequence>
           <element ref="dddb:native" minOccurs="0" maxOccurs="unbounded"/>
           <element ref="dddb:sequence" minOccurs="0" maxOccurs="unbounded"/>
           <element ref="dddb:table" minOccurs="1" maxOccurs="unbounded"/>
           <element ref="dddb:index" minOccurs="0" maxOccurs="unbounded"/>
           <element ref="dddb:alteration" minOccurs="0" maxOccurs="unbounded"/>
        </sequence>
    </group>

    <complexType name="databaseType">
        <group ref="dddb:databaseComponents" minOccurs="1" maxOccurs="unbounded"/>
        <attribute name="name" type="token" use="required"/>
    </complexType>
    <element name="database" type="dddb:databaseType"/>
   
    <!-- END COMPLEX TYPE DEFINITIONS -->
</schema>
