diff --git a/komodo-core/src/main/resources/config/TeiidSql.cnd b/komodo-core/src/main/resources/config/TeiidSql.cnd index a145937a..588f3ed9 100644 --- a/komodo-core/src/main/resources/config/TeiidSql.cnd +++ b/komodo-core/src/main/resources/config/TeiidSql.cnd @@ -180,6 +180,12 @@ + tsql:from (tsql:from) + tsql:criteria (tsql:criteria) + tsql:select (tsql:select) + +[tsql:create] > tsql:command mixin + - tsql:onCommit (string) + + tsql:table (tsql:groupSymbol) + + tsql:tableColumn (tsql:multipleElementSymbol) + + tsql:primaryKeyColumn (tsql:multipleElementSymbol) [tsql:setQuery] > tsql:queryCommand mixin - tsql:all (boolean) diff --git a/komodo-modeshape-sequencer-teiid-sql-tests/src/test/java/org/komodo/modeshape/teiid/sequencer/AbstractTestTeiidSqlSequencer.java b/komodo-modeshape-sequencer-teiid-sql-tests/src/test/java/org/komodo/modeshape/teiid/sequencer/AbstractTestTeiidSqlSequencer.java index e16b3c6d..58b5609a 100644 --- a/komodo-modeshape-sequencer-teiid-sql-tests/src/test/java/org/komodo/modeshape/teiid/sequencer/AbstractTestTeiidSqlSequencer.java +++ b/komodo-modeshape-sequencer-teiid-sql-tests/src/test/java/org/komodo/modeshape/teiid/sequencer/AbstractTestTeiidSqlSequencer.java @@ -26,7 +26,6 @@ import org.junit.Test; import org.komodo.modeshape.AbstractTSqlSequencerTest; import org.komodo.modeshape.teiid.language.SortSpecification.NullOrdering; -import org.komodo.osgi.PluginService; import org.komodo.repository.KSequencerController.SequencerType; import org.komodo.spi.lexicon.TeiidSqlLexicon.AbstractCompareCriteria; import org.komodo.spi.lexicon.TeiidSqlLexicon.AbstractSetCriteria; @@ -37,6 +36,7 @@ import org.komodo.spi.lexicon.TeiidSqlLexicon.CommandStatement; import org.komodo.spi.lexicon.TeiidSqlLexicon.CompareCriteria; import org.komodo.spi.lexicon.TeiidSqlLexicon.Constant; +import org.komodo.spi.lexicon.TeiidSqlLexicon.Create; import org.komodo.spi.lexicon.TeiidSqlLexicon.CreateProcedureCommand; import org.komodo.spi.lexicon.TeiidSqlLexicon.DeclareStatement; import org.komodo.spi.lexicon.TeiidSqlLexicon.DerivedColumn; @@ -80,7 +80,6 @@ import org.komodo.spi.query.CriteriaOperator; import org.komodo.spi.query.JoinTypeTypes; import org.komodo.spi.query.Operation; -import org.komodo.spi.query.TeiidService; import org.komodo.spi.runtime.version.TeiidVersion; import org.komodo.spi.type.DataTypeManager.DataTypeName; @@ -1775,4 +1774,40 @@ public void testWindowFunction() throws Exception { verifySql("SELECT ROW_NUMBER() OVER (PARTITION BY x ORDER BY y) FROM g", fileNode); } + @Test + public void testLocalTable() throws Exception { + String sql = "Create local TEMPORARY table x(c1 boolean, c2 byte, c3 string);"; + Node fileNode = sequenceSql(sql, TSQL_QUERY); + + Node createNode = verify(fileNode, Create.ID, Create.ID); + + Node tableNode = verify(createNode, Create.TABLE_REF_NAME, GroupSymbol.ID); + verifyProperty(tableNode, Symbol.SHORT_NAME_PROP_NAME, "x"); + + Node columnNode=verify(createNode,Create.COLUMNS_REF_NAME,ElementSymbol.ID); + verifyProperty(columnNode, Symbol.SHORT_NAME_PROP_NAME, "c1"); + verifyProperty(columnNode,Expression.TYPE_CLASS_PROP_NAME,"BOOLEAN"); + + verifySql("CREATE LOCAL TEMPORARY TABLE x(c1 BOOLEAN, c2 BYTE, c3 STRING)", fileNode); + } + + @Test + public void testLocalTablePreserveRows() throws Exception { + String sql = "Create local TEMPORARY table x(c1 boolean, c2 byte, c3 string, primary key (c2, c3)) ON COMMIT PRESERVE ROWS;"; + Node fileNode = sequenceSql(sql, TSQL_QUERY); + + Node createNode = verify(fileNode, Create.ID, Create.ID); + + Node tableNode = verify(createNode, Create.TABLE_REF_NAME, GroupSymbol.ID); + verifyProperty(tableNode, Symbol.SHORT_NAME_PROP_NAME, "x"); + + Node columnNode=verify(createNode,Create.COLUMNS_REF_NAME,ElementSymbol.ID); + verifyProperty(columnNode, Symbol.SHORT_NAME_PROP_NAME, "c1"); + verifyProperty(columnNode,Expression.TYPE_CLASS_PROP_NAME,"BOOLEAN"); + + verify(createNode,Create.PRIMARY_KEY_COLUMNS_REF_NAME,ElementSymbol.ID); + + verifySql("CREATE LOCAL TEMPORARY TABLE x(c1 BOOLEAN, c2 BYTE, c3 STRING, PRIMARY KEY(c2, c3)) ON COMMIT PRESERVE ROWS", fileNode); + } + } diff --git a/komodo-modeshape-sequencer-teiid-sql/src/main/java/org/komodo/modeshape/teiid/TeiidSqlNodeVisitor.java b/komodo-modeshape-sequencer-teiid-sql/src/main/java/org/komodo/modeshape/teiid/TeiidSqlNodeVisitor.java index dfcfd6b3..e0c2cf0e 100644 --- a/komodo-modeshape-sequencer-teiid-sql/src/main/java/org/komodo/modeshape/teiid/TeiidSqlNodeVisitor.java +++ b/komodo-modeshape-sequencer-teiid-sql/src/main/java/org/komodo/modeshape/teiid/TeiidSqlNodeVisitor.java @@ -40,10 +40,10 @@ import org.komodo.modeshape.teiid.language.SortSpecification.NullOrdering; import org.komodo.spi.constants.StringConstants; import org.komodo.spi.lexicon.TeiidSqlConstants; -import org.komodo.spi.lexicon.TeiidSqlContext; import org.komodo.spi.lexicon.TeiidSqlConstants.NonReserved; import org.komodo.spi.lexicon.TeiidSqlConstants.Reserved; import org.komodo.spi.lexicon.TeiidSqlConstants.Tokens; +import org.komodo.spi.lexicon.TeiidSqlContext; import org.komodo.spi.lexicon.TeiidSqlLexicon; import org.komodo.spi.lexicon.TeiidSqlLexicon.*; import org.komodo.spi.query.AggregateFunctions; @@ -53,10 +53,10 @@ import org.komodo.spi.query.JoinTypeTypes; import org.komodo.spi.query.LogicalOperator; import org.komodo.spi.query.MatchMode; -import org.komodo.spi.query.PredicateQuantifier; -import org.komodo.spi.query.TriggerEvent; import org.komodo.spi.query.Operation; import org.komodo.spi.query.ParameterInfo; +import org.komodo.spi.query.PredicateQuantifier; +import org.komodo.spi.query.TriggerEvent; import org.komodo.spi.runtime.version.DefaultTeiidVersion.Version; import org.komodo.spi.runtime.version.TeiidVersion; import org.komodo.spi.type.DataTypeManager.DataTypeName; @@ -742,6 +742,9 @@ protected void visit(Node node, TeiidSqlContext context) throws RepositoryExcept break; case INSERT: insert(context); + break; + case CREATE: + createLocalTempTable(context); break; case STORED_PROCEDURE: storedProcedure(context); @@ -1680,6 +1683,77 @@ public Object dynamicCommand(TeiidSqlContext context) throws Exception { return null; } + public Object createLocalTempTable(TeiidSqlContext context) throws Exception { + Node node = (Node)context.get(NODE_KEY); + + append(CREATE); + append(SPACE); + append(LOCAL); + append(SPACE); + append(TEMPORARY); + append(SPACE); + append(TABLE); + append(SPACE); + + Node table = reference(node, Create.TABLE_REF_NAME); + visit(table); + + append(OPEN_BRACKET); + + tableColumns(context); + primaryKey(context); + + append(CLOSE_BRACKET); + String onCommit = propertyString(node, Create.ON_COMMIT_PROP_NAME); + if (onCommit != null && onCommit.equals(Create.ON_COMMIT_PROP_VALUE)) { + append(SPACE); + append(ON); + append(SPACE); + append(COMMIT); + append(SPACE); + append(PRESERVE); + append(SPACE); + append(ROWS); + } + + return null; + } + + public Object primaryKey(TeiidSqlContext context) throws Exception { + Node node = (Node) context.get(NODE_KEY); + Iterator pkColumns = references(node, Create.PRIMARY_KEY_COLUMNS_REF_NAME); + if(pkColumns.hasNext()){ + append(COMMA); + append(SPACE); + append(PRIMARY); + append(SPACE); + append(KEY); + append(OPEN_BRACKET); + for (int i = 0; pkColumns.hasNext(); ++i) { + if (i > 0) + append(COMMA + SPACE); + Node pkColumn = pkColumns.next(); + append(propertyString(pkColumn,Symbol.SHORT_NAME_PROP_NAME)); + } + append(CLOSE_BRACKET); + } + return null; + } + + public Object tableColumns(TeiidSqlContext context) throws Exception { + Node node = (Node) context.get(NODE_KEY); + Iterator columns = references(node, Create.COLUMNS_REF_NAME); + for (int i = 0; columns.hasNext(); ++i) { + if (i > 0) + append(COMMA + SPACE); + Node column = columns.next(); + append(propertyString(column,Symbol.SHORT_NAME_PROP_NAME)); + append(SPACE); + append(propertyString(column,Expression.TYPE_CLASS_PROP_NAME)); + } + return null; + } + public Object query(TeiidSqlContext context) throws Exception { Node node = (Node) context.get(NODE_KEY); addWithClause(node); diff --git a/komodo-modeshape-sequencer-teiid-sql/src/main/resources/org/komodo/modeshape/teiid/cnd/TeiidSql.cnd b/komodo-modeshape-sequencer-teiid-sql/src/main/resources/org/komodo/modeshape/teiid/cnd/TeiidSql.cnd index 19787015..8116574a 100644 --- a/komodo-modeshape-sequencer-teiid-sql/src/main/resources/org/komodo/modeshape/teiid/cnd/TeiidSql.cnd +++ b/komodo-modeshape-sequencer-teiid-sql/src/main/resources/org/komodo/modeshape/teiid/cnd/TeiidSql.cnd @@ -180,7 +180,13 @@ + tsql:into (tsql:into) + tsql:criteria (tsql:criteria) + tsql:groupBy (tsql:groupBy) - + +[tsql:create] > tsql:command mixin + - tsql:onCommit (string) + + tsql:table (tsql:groupSymbol) + + tsql:tableColumn (tsql:multipleElementSymbol) + + tsql:primaryKeyColumn (tsql:multipleElementSymbol) + [tsql:setQuery] > tsql:queryCommand mixin - tsql:operation (string) < "UNION", "INTERSECT", "EXCEPT" - tsql:all (boolean) diff --git a/komodo-modeshape-vdb/src/main/java/org/komodo/modeshape/visitor/DdlNodeVisitor.java b/komodo-modeshape-vdb/src/main/java/org/komodo/modeshape/visitor/DdlNodeVisitor.java index 123e5ddd..ff7e3bf7 100644 --- a/komodo-modeshape-vdb/src/main/java/org/komodo/modeshape/visitor/DdlNodeVisitor.java +++ b/komodo-modeshape-vdb/src/main/java/org/komodo/modeshape/visitor/DdlNodeVisitor.java @@ -29,21 +29,20 @@ import java.util.List; import java.util.Map; import java.util.Set; - import javax.jcr.Node; import javax.jcr.Property; +import javax.jcr.PropertyIterator; import javax.jcr.RepositoryException; import javax.jcr.Value; import javax.jcr.ValueFormatException; import javax.jcr.nodetype.NodeType; - import org.komodo.modeshape.AbstractNodeVisitor; import org.komodo.modeshape.teiid.TeiidSqlNodeVisitor; import org.komodo.spi.constants.StringConstants; +import org.komodo.spi.ddl.TeiidDDLConstants; import org.komodo.spi.lexicon.TeiidSqlConstants; import org.komodo.spi.lexicon.TeiidSqlConstants.NonReserved; import org.komodo.spi.lexicon.TeiidSqlConstants.Reserved; -import org.komodo.spi.ddl.TeiidDDLConstants; import org.komodo.spi.metadata.MetadataNamespaces; import org.komodo.spi.runtime.version.TeiidVersion; import org.komodo.spi.type.DataTypeManager.DataTypeName; @@ -111,6 +110,10 @@ private enum MixinTypeName { CREATE_FUNCTION(TeiidDdlLexicon.CreateProcedure.FUNCTION_STATEMENT), + CREATE_GLOBAL_TEMP_TABLE(TeiidDdlLexicon.CreateTable.GLOBAL_TEMP_TABLE_STATEMENT), + + CREATE_FOREIGN_TEMP_TABLE(TeiidDdlLexicon.CreateTable.FOREIGN_TEMP_TABLE_STATEMENT), + UNKNOWN(UNDEFINED); private String nodeTypeId; @@ -140,15 +143,9 @@ public static MixinTypeName findName(NodeType nodeType) { } - private enum TableType { - TABLE, - VIEW, - GLOBAL_TEMP_TABLE; - } - private class CreateObjectContext { - private TableType tableType = TableType.TABLE; + private MixinTypeName tableType=MixinTypeName.UNKNOWN; private boolean virtual = false; @@ -168,11 +165,11 @@ public void setVirtual(boolean virtual) { this.virtual = virtual; } - public TableType getTableType() { + public MixinTypeName getTableType() { return tableType; } - public void setTableType(TableType tableType) { + public void setTableType(MixinTypeName tableType) { this.tableType = tableType; } } @@ -567,7 +564,7 @@ private void tableElement(Node tableElement, CreateObjectContext context) throws ColumnContext columnContext = createColumnContext(tableElement); - if (TableType.GLOBAL_TEMP_TABLE == context.getTableType() && columnContext.isAutoIncremented() && + if (MixinTypeName.CREATE_GLOBAL_TEMP_TABLE == context.getTableType() && columnContext.isAutoIncremented() && columnContext.isNotNull() && DataTypeName.INTEGER.equals(columnContext.getDataTypeName())) { append(escapeSinglePart(tableElement.getName())); @@ -735,10 +732,10 @@ private String schemaElementType(Node node) throws Exception { private void tabulation(Node tabulation, CreateObjectContext context) throws Exception { append(SPACE); - addTableBody(tabulation, context); - if (TableType.GLOBAL_TEMP_TABLE != context.getTableType()) { + if ( + MixinTypeName.CREATE_FOREIGN_TEMP_TABLE !=context.getTableType()) { if (context.isVirtual()) { TeiidSqlNodeVisitor visitor = new TeiidSqlNodeVisitor(getVersion()); String teiidSql = visitor.getTeiidSql(tabulation); @@ -763,17 +760,63 @@ private void table(Node table) throws Exception { append(CREATE).append(SPACE); if (context.isPhysical()) { - context.setTableType(TableType.TABLE); + context.setTableType(MixinTypeName.CREATE_TABLE); append(FOREIGN).append(SPACE).append(TABLE); } - else { - context.setTableType(TableType.GLOBAL_TEMP_TABLE); - append(GLOBAL).append(SPACE).append(TEMPORARY).append(SPACE).append(TABLE); - } tabulation(table, context); } + /** + * @param node + * @throws RepositoryException + */ + private void globalTempTable(Node temptable) throws Exception { + if (! includeTables) + return; + + if (!hasMixinType(temptable, TeiidDdlLexicon.CreateTable.GLOBAL_TEMP_TABLE_STATEMENT)) + return; + + append(NEW_LINE); + append(CREATE).append(SPACE).append(GLOBAL).append(SPACE).append(TEMPORARY).append(SPACE).append(TABLE); + CreateObjectContext context = new CreateObjectContext(); + context.setPhysical(false); + context.setTableType(MixinTypeName.CREATE_GLOBAL_TEMP_TABLE); + context.setPhysical(true); + tabulation(temptable,context); + } + + /** + * @param node + * @throws RepositoryException + */ + private void foreignTempTable(Node temptable) throws Exception { + if (! includeTables) + return; + + if (!hasMixinType(temptable, TeiidDdlLexicon.CreateTable.FOREIGN_TEMP_TABLE_STATEMENT)) + return; + + append(NEW_LINE); + append(CREATE).append(SPACE).append(FOREIGN).append(SPACE).append(TEMPORARY).append(SPACE).append(TABLE); + CreateObjectContext context = new CreateObjectContext(); + context.setPhysical(false); + context.setTableType(MixinTypeName.CREATE_FOREIGN_TEMP_TABLE); + context.setPhysical(true); + tabulation(temptable,context); + PropertyIterator props=temptable.getProperties(); + Property property; + String schemaRef=null; + while(props.hasNext()){ + property= props.nextProperty(); + if(property.getName().equals(TeiidDdlLexicon.CreateTable.SCHEMA_REFERENCE)){ + schemaRef=property.getValue().getString(); + } + } + append(SPACE).append(ON).append(SPACE).append(schemaRef).append(SEMI_COLON); + } + private void view(Node view) throws Exception { if (! includeTables) return; @@ -785,7 +828,7 @@ private void view(Node view) throws Exception { CreateObjectContext context = new CreateObjectContext(); context.setVirtual(true); - context.setTableType(TableType.VIEW); + context.setTableType(MixinTypeName.CREATE_VIEW); append(CREATE).append(SPACE).append(VIEW); @@ -982,6 +1025,12 @@ public void visit(Node node) throws RepositoryException { function(node); append(NEW_LINE); break; + case CREATE_GLOBAL_TEMP_TABLE: + globalTempTable(node); + break; + case CREATE_FOREIGN_TEMP_TABLE: + foreignTempTable(node); + break; case UNKNOWN: default: // Not a node we are interested in but may contain such nodes @@ -992,6 +1041,8 @@ public void visit(Node node) throws RepositoryException { } } + + @Override public void visit(Property property) { // Not used diff --git a/komodo-modeshape-vdb/src/test/java/org/komodo/modeshape/vdb/test/ddl/TestDdlNodeVisitor.java b/komodo-modeshape-vdb/src/test/java/org/komodo/modeshape/vdb/test/ddl/TestDdlNodeVisitor.java index fafb4b83..ba9b19b0 100644 --- a/komodo-modeshape-vdb/src/test/java/org/komodo/modeshape/vdb/test/ddl/TestDdlNodeVisitor.java +++ b/komodo-modeshape-vdb/src/test/java/org/komodo/modeshape/vdb/test/ddl/TestDdlNodeVisitor.java @@ -340,17 +340,83 @@ public void testNamespaces() throws Exception { helpTest(ddl, ddl, SEQUENCE_DDL_PATH + "G1\\/tsql:query"); } - @Ignore + @Test( timeout = 5000000 ) public void testGlobalTemporaryTable() throws Exception { - String ddl = "CREATE GLOBAL TEMPORARY TABLE myTemp (" + NEW_LINE + - TAB + "x string," + NEW_LINE + - TAB + "y SERIAL," + NEW_LINE + - TAB + "PRIMARY KEY(x)" + NEW_LINE + - ")"; - helpTest(ddl, ddl, SEQUENCE_DDL_PATH + "myTemp"); + String ddl = "CREATE GLOBAL TEMPORARY TABLE myGlobalTemp (" + NEW_LINE + + TAB + "a SERIAL," + NEW_LINE + + TAB + "b varchar(20)," + NEW_LINE + + TAB + "c string," + NEW_LINE + + TAB + "d boolean," + NEW_LINE + + TAB + "e byte," + NEW_LINE + + TAB + "f tinyint," + NEW_LINE + + TAB + "g short," + NEW_LINE + + TAB + "h smallint," + NEW_LINE + + TAB + "i char(3)," + NEW_LINE + + TAB + "j integer," + NEW_LINE + + TAB + "k long," + NEW_LINE + + TAB + "l bigint," + NEW_LINE + + TAB + "m float," + NEW_LINE + + TAB + "n real," + NEW_LINE + + TAB + "o double," + NEW_LINE + + TAB + "p bigdecimal(5,10)," + NEW_LINE + + TAB + "q date," + NEW_LINE + + TAB + "r time," + NEW_LINE + + TAB + "s timestamp," + NEW_LINE + + TAB + "t blob," + NEW_LINE + + TAB + "u clob," + NEW_LINE + + TAB + "v xml," + NEW_LINE + + TAB + "PRIMARY KEY(a, b)" + NEW_LINE + + ") OPTIONS (\"FOO\" 'BAR', \"UPDATABLE\" 'true');"; + helpTest(ddl, ddl, SEQUENCE_DDL_PATH + "myGlobalTemp"); + } + + @Test( timeout = 5000000 ) + public void testForeignTemporaryTable() throws Exception { + String ddl = "CREATE FOREIGN TEMPORARY TABLE myForeignTemp (" + NEW_LINE + + TAB + "a integer," + NEW_LINE + + TAB + "b varchar(20)," + NEW_LINE + + TAB + "c string," + NEW_LINE + + TAB + "d boolean," + NEW_LINE + + TAB + "e byte," + NEW_LINE + + TAB + "f tinyint," + NEW_LINE + + TAB + "g short," + NEW_LINE + + TAB + "h smallint," + NEW_LINE + + TAB + "i char(3)," + NEW_LINE + + TAB + "j integer," + NEW_LINE + + TAB + "k long," + NEW_LINE + + TAB + "l bigint," + NEW_LINE + + TAB + "m float," + NEW_LINE + + TAB + "n real," + NEW_LINE + + TAB + "o double," + NEW_LINE + + TAB + "p bigdecimal(5,10)," + NEW_LINE + + TAB + "q date," + NEW_LINE + + TAB + "r time," + NEW_LINE + + TAB + "s timestamp," + NEW_LINE + + TAB + "t blob," + NEW_LINE + + TAB + "u clob," + NEW_LINE + + TAB + "v xml," + NEW_LINE + + TAB + "PRIMARY KEY(a, b)" + NEW_LINE + + ") ON pm1;"; + helpTest(ddl, ddl, SEQUENCE_DDL_PATH + "myForeignTemp"); + } + + @Test( timeout = 5000000 ) + public void testMultipleTemporaryTable() throws Exception { + String ddl = "CREATE FOREIGN TEMPORARY TABLE myForeignTemp (" + NEW_LINE + + TAB + "a integer," + NEW_LINE + + TAB + "b varchar(20)," + NEW_LINE + + TAB + "c string," + NEW_LINE + + TAB + "PRIMARY KEY(a, b)" + NEW_LINE +") ON pm1;"+ NEW_LINE + + "CREATE GLOBAL TEMPORARY TABLE myGlobalTemp (" + NEW_LINE + + TAB + "a integer," + NEW_LINE + + TAB + "b varchar(20)," + NEW_LINE + + TAB + "c string," + NEW_LINE + + TAB + "PRIMARY KEY(a, b)" + NEW_LINE +");"; + helpTest(ddl, ddl, SEQUENCE_DDL_PATH + "myForeignTemp"); } + @Test( timeout = 5000000 ) public void testArrayTypes() throws Exception { String ddl = "CREATE FOREIGN PROCEDURE myProc(OUT p1 boolean, IN p2 string, INOUT p3 bigdecimal) RETURNS TABLE (r1 string(100)[], r2 bigdecimal[][])"; @@ -365,4 +431,15 @@ public void testOptions() throws Exception { helpTest(ddl, ddl, SEQUENCE_DDL_PATH + "G1"); } + @Test(timeout = 5000000) + public void testLocalTempTable() throws Exception { + String ddl ="CREATE VIRTUAL PROCEDURE getData(IN p1 integer) RETURNS TABLE (col string)"+NEW_LINE + + "OPTIONS (\"UPDATECOUNT\" '0')"+NEW_LINE+ + "AS"+ NEW_LINE + + "BEGIN"+ NEW_LINE + + "CREATE LOCAL TEMPORARY TABLE x(c1 BOOLEAN, c2 BYTE, c3 STRING, PRIMARY KEY(c2, c3));" + NEW_LINE + + "SELECT * FROM data;"+ NEW_LINE + + "END;"; + helpTest(ddl, ddl, SEQUENCE_DDL_PATH + "G1"); + } } diff --git a/komodo-spi/src/main/java/org/komodo/spi/lexicon/TeiidSqlLexicon.java b/komodo-spi/src/main/java/org/komodo/spi/lexicon/TeiidSqlLexicon.java index cad854ed..e50b8735 100644 --- a/komodo-spi/src/main/java/org/komodo/spi/lexicon/TeiidSqlLexicon.java +++ b/komodo-spi/src/main/java/org/komodo/spi/lexicon/TeiidSqlLexicon.java @@ -3,17 +3,17 @@ * See the COPYRIGHT.txt file distributed with this work for information * regarding copyright ownership. Some portions may be licensed * to Red Hat, Inc. under one or more contributor license agreements. - * + * * This library 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 library 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 library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA @@ -113,32 +113,32 @@ public interface PredicateCriteria extends Expression { * tsql:isDistinctCriteria */ public interface IsDistinctCriteria extends PredicateCriteria { - + String ID = Namespace.PREFIX + COLON + "isDistinctCriteria"; - + /** * NEGATED Property */ String NEGATED_PROP_NAME = Namespace.PREFIX + COLON + "negated"; - + Class NEGATED_PROP_TYPE = Boolean.class; - + boolean NEGATED_PROP_MULTIPLE = false; - + /** * LEFT_ROW_VALUE Reference */ String LEFT_ROW_VALUE_REF_NAME = Namespace.PREFIX + COLON + "leftRowValue"; - + Class LEFT_ROW_VALUE_REF_TYPE = GroupSymbol.class; - + boolean LEFT_ROW_VALUE_REF_MULTIPLE = false; - + /** * RIGHT_ROW_VALUE Reference */ String RIGHT_ROW_VALUE_REF_NAME = Namespace.PREFIX + COLON + "leftRowValue"; - + Class RIGHT_ROW_VALUE_REF_TYPE = GroupSymbol.class; boolean RIGHT_ROW_VALUE_REF_MULTIPLE = false; @@ -198,6 +198,29 @@ public interface Labeled { } + /** + * tsql:create + */ + public interface Create extends LanguageObject { + + String ID = Namespace.PREFIX + COLON + "create"; + + boolean IS_ABSTRACT = false; + + String ON_COMMIT_PROP_NAME="onCommit"; + String ON_COMMIT_PROP_VALUE="PRESERVE_ROWS"; + String COLUMNS_REF_NAME = Namespace.PREFIX + COLON + "column"; + Class COLUMNS_REF_TYPE = ElementSymbol.class; + boolean COLUMNS_REF_MULTIPLE = true; + + String PRIMARY_KEY_COLUMNS_REF_NAME = Namespace.PREFIX + COLON + "primaryKeyColumn"; + Class PRIMARY_KEY_COLUMNS_REF_TYPE = ElementSymbol.class; + boolean PRIMARY_KEY_COLUMNS_REF_MULTIPLE = true; + + String TABLE_REF_NAME = Namespace.PREFIX + COLON + "table"; + + } + /** * tsql:criteria */ @@ -3009,7 +3032,7 @@ public interface Symbol extends LanguageObject { /** * Character used to delimit name components in a symbol */ - String SEPARATOR = DOT; + String SEPARATOR = DOT; /** * NAME Property @@ -3937,6 +3960,8 @@ public enum LexTokens { CRITERIA (Criteria.ID, Criteria.class), + CREATE (Create.ID,Create.class), + ABSTRACT_COMPARE_CRITERIA (AbstractCompareCriteria.ID, AbstractCompareCriteria.class), COMPARE_CRITERIA (CompareCriteria.ID, CompareCriteria.class), diff --git a/plugins/teiid-8.11/src/main/java/org/komodo/teiid/NodeGenerator.java b/plugins/teiid-8.11/src/main/java/org/komodo/teiid/NodeGenerator.java index 021b30f4..2f03ceae 100644 --- a/plugins/teiid-8.11/src/main/java/org/komodo/teiid/NodeGenerator.java +++ b/plugins/teiid-8.11/src/main/java/org/komodo/teiid/NodeGenerator.java @@ -46,6 +46,7 @@ import org.teiid.query.sql.lang.Command; import org.teiid.query.sql.lang.CompareCriteria; import org.teiid.query.sql.lang.CompoundCriteria; +import org.teiid.query.sql.lang.Create; import org.teiid.query.sql.lang.Delete; import org.teiid.query.sql.lang.DynamicCommand; import org.teiid.query.sql.lang.ExistsCriteria; @@ -1158,6 +1159,24 @@ public void visit(CreateProcedureCommand obj) { } } + @Override + public void visit(Create obj){ + if (errorOccurred()) + return; + + try { + Node node = transform(obj); + if(obj.getCommitAction()!=null) + setProperty(node, TeiidSqlLexicon.Create.ON_COMMIT_PROP_NAME, obj.getCommitAction().toString()); + visitObject(node,TeiidSqlLexicon.Create.TABLE_REF_NAME,obj.getGroup()); + visitObjects(node, TeiidSqlLexicon.Create.COLUMNS_REF_NAME, obj.getColumnSymbols()); + visitObjects(node,TeiidSqlLexicon.Create.PRIMARY_KEY_COLUMNS_REF_NAME,obj.getPrimaryKey()); + + } catch (Exception ex) { + setError(ex); + } + } + @SuppressWarnings( "deprecation" ) @Override public void visit(DeclareStatement obj) { diff --git a/plugins/teiid-8.12/src/main/java/org/komodo/teiid/NodeGenerator.java b/plugins/teiid-8.12/src/main/java/org/komodo/teiid/NodeGenerator.java index b2877d1c..8b6af309 100644 --- a/plugins/teiid-8.12/src/main/java/org/komodo/teiid/NodeGenerator.java +++ b/plugins/teiid-8.12/src/main/java/org/komodo/teiid/NodeGenerator.java @@ -46,6 +46,7 @@ import org.teiid.query.sql.lang.Command; import org.teiid.query.sql.lang.CompareCriteria; import org.teiid.query.sql.lang.CompoundCriteria; +import org.teiid.query.sql.lang.Create; import org.teiid.query.sql.lang.Delete; import org.teiid.query.sql.lang.DynamicCommand; import org.teiid.query.sql.lang.ExistsCriteria; @@ -949,6 +950,26 @@ public void visit(Constant obj) { } } + @Override + public void visit(Create obj){ + if (errorOccurred()) + return; + + try { + Node node = transform(obj); + if(obj.getCommitAction()!=null) + setProperty(node, TeiidSqlLexicon.Create.ON_COMMIT_PROP_NAME, obj.getCommitAction().toString()); + visitObject(node,TeiidSqlLexicon.Create.TABLE_REF_NAME,obj.getGroup()); + visitObjects(node, TeiidSqlLexicon.Create.COLUMNS_REF_NAME, obj.getColumnSymbols()); + visitObjects(node,TeiidSqlLexicon.Create.PRIMARY_KEY_COLUMNS_REF_NAME,obj.getPrimaryKey()); + + } catch (Exception ex) { + setError(ex); + } + } + + + @Override public void visit(ElementSymbol obj) { if (errorOccurred())