/*
 * ModeShape (http://www.modeshape.org)
 *
 * Licensed 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.
 */

<jcr='http://www.jcp.org/jcr/1.0'>
<nt='http://www.jcp.org/jcr/nt/1.0'>
<mix='http://www.jcp.org/jcr/mix/1.0'>
<ddl='http://www.modeshape.org/ddl/1.0'>
<teiidddl='http://www.modeshape.org/ddl/teiid/1.0'>

// =============================================================================
// Table Constraint
// =============================================================================

[teiidddl:constraint] abstract mixin
- teiidddl:constraintType (string) < 'PRIMARY KEY', 'UNIQUE', 'ACCESSPATTERN', 'FOREIGN KEY', 'INDEX'
- teiidddl:tableElementRefs (reference) multiple
 
[teiidddl:tableElementConstraint] > teiidddl:constraint mixin
- teiidddl:constraintType (string) mandatory < 'PRIMARY KEY', 'UNIQUE', 'ACCESSPATTERN'

[teiidddl:foreignKeyConstraint] > teiidddl:constraint mixin
- teiidddl:constraintType (string) = 'FOREIGN KEY' mandatory autocreated < 'FOREIGN KEY'
- teiidddl:tableRef (reference) mandatory
- teiidddl:tableRefElementRefs (reference) multiple
 
[teiidddl:indexConstraint] > teiidddl:constraint mixin
- teiidddl:constraintType (string) = 'INDEX' mandatory autocreated < 'INDEX'
- teiidddl:expression (string)

// =============================================================================
// SCHEMA ELEMENT
// =============================================================================

[teiidddl:schemaElement] mixin
- teiidddl:schemaElementType (string) = 'FOREIGN' mandatory autocreated < 'FOREIGN', 'VIRTUAL'

// =============================================================================
// CREATE TABLE
// =============================================================================

[teiidddl:tableElement] > ddl:columnDefinition, mix:referenceable mixin
- teiidddl:autoIncrement (boolean) = 'false'
- ddl:nullable (string) = 'NULL' mandatory autocreated < 'NULL', 'NOT NULL'
+ * (ddl:statementOption) = ddl:statementOption 

[teiidddl:abstractCreateTable] > ddl:createTableStatement, teiidddl:schemaElement, mix:referenceable abstract mixin
- teiidddl:queryExpression (string)
+ * (teiidddl:constraint) = teiidddl:constraint sns

[teiidddl:createTable] > teiidddl:abstractCreateTable mixin
[teiidddl:createView] > teiidddl:abstractCreateTable mixin

// =============================================================================
// CREATE PROCEDURE
// =============================================================================

[teiidddl:procedureParameter] > mix:referenceable mixin
- teiidddl:parameterType (string) = 'IN' mandatory autocreated < 'IN', 'OUT', 'INOUT', 'VARIADIC'
- teiidddl:result (boolean) = 'false' autocreated
- ddl:nullable (string) = 'NULL' mandatory autocreated < 'NULL', 'NOT NULL'
- ddl:datatypeName (STRING)
- ddl:datatypeLength (LONG)
- ddl:datatypePrecision (LONG)
- ddl:datatypeScale (LONG)
- ddl:defaultOption (STRING) < 'LITERAL', 'DATETIME', 'USER', 'CURRENT_USER', 'SESSION_USER', 'SYSTEM_USER', 'NULL'
- ddl:defaultValue (STRING)
- ddl:defaultPrecision (LONG)
+ * (ddl:statementOption) = ddl:statementOption

[teiidddl:resultColumn] mixin
- ddl:datatypeName (string)
- ddl:datatypeLength (long)
- ddl:datatypePrecision (long)
- ddl:datatypeScale (long)
- ddl:nullable (string) = 'NULL' mandatory autocreated < 'NULL', 'NOT NULL'
+ * (ddl:statementOption) = ddl:statementOption

[teiidddl:resultSet] abstract mixin

[teiidddl:resultDataType] > teiidddl:resultSet, teiidddl:resultColumn mixin

[teiidddl:resultColumns] > teiidddl:resultSet mixin
- teiidddl:table (boolean) = 'false' autocreated
+ * (teiidddl:resultColumn) = teiidddl:resultColumn

[teiidddl:abstractCreateProcedure] > ddl:creatable, ddl:statement, teiidddl:schemaElement abstract mixin
+ * (teiidddl:procedureParameter) = teiidddl:procedureParameter
+ resultSet (teiidddl:resultSet)
+ * (ddl:statementOption) = ddl:statementOption

[teiidddl:createFunction] > teiidddl:abstractCreateProcedure mixin

[teiidddl:createProcedure] > teiidddl:abstractCreateProcedure, mix:referenceable mixin
- teiidddl:statement (string)

// =============================================================================
// ALTER OPTIONS
// =============================================================================

[teiidddl:alterOptionsList] mixin
- teiidddl:dropped (string) multiple
+ * (ddl:statementOption) = ddl:statementOption

[teiidddl:alterOptions] > ddl:creatable, ddl:statement, teiidddl:schemaElement abstract mixin
- teiidddl:reference (reference) mandatory
+ alters (teiidddl:alterOptionsList)

[teiidddl:alterTable] > teiidddl:alterOptions mixin
[teiidddl:alterView] > teiidddl:alterOptions mixin
[teiidddl:alterProcedure] > teiidddl:alterOptions mixin

[teiidddl:alterColumn] > teiidddl:alterOptionsList, mix:referenceable mixin
- teiidddl:reference (reference) mandatory

[teiidddl:alterParameter] > teiidddl:alterOptionsList, mix:referenceable mixin
- teiidddl:reference (reference) mandatory

// =============================================================================
// CREATE TRIGGER - use node type name as name of trigger
// =============================================================================

[teiidddl:triggerRowAction] mixin
- teiidddl:action (string) mandatory

[teiidddl:createTrigger] > ddl:creatable, ddl:statement mixin
- teiidddl:insteadOf (string) mandatory < 'INSERT', 'UPDATE', 'DELETE'
- teiidddl:tableRef (reference) mandatory
- teiidddl:atomic (boolean) = 'true' autocreated
+ rowAction (teiidddl:triggerRowAction) = teiidddl:triggerRowAction sns
+ * (ddl:statementOption) = ddl:statementOption

// =============================================================================
// OPTION NAMESPACE
// =============================================================================

[teiidddl:optionNamespace] > ddl:statement mixin
- teiidddl:uri (string) mandatory
