teiid SVN: r4491 - in trunk/engine/src: test/java/org/teiid/query/parser and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-09-30 08:57:02 -0400 (Sun, 30 Sep 2012)
New Revision: 4491
Modified:
trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java
trunk/engine/src/main/java/org/teiid/query/parser/TeiidSQLParserTokenManager.java
trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
Log:
TEIID-2233 better handling for token errors
Modified: trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java 2012-09-29 19:14:01 UTC (rev 4490)
+++ trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java 2012-09-30 12:57:02 UTC (rev 4491)
@@ -22,6 +22,8 @@
package org.teiid.query.parser;
+import static org.teiid.query.parser.TeiidSQLParserTokenManager.*;
+
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
@@ -219,7 +221,14 @@
return pe.getMessage();
}
StringBuilder sb = encountered(pe, 1);
- sb.append(pe.getMessage());
+ if (pe.currentToken.kind == INVALID_TOKEN) {
+ sb.append(QueryPlugin.Util.getString("QueryParser.lexicalError", pe.currentToken.image)); //$NON-NLS-1$
+ } else if (pe.currentToken.next != null && pe.currentToken.next.kind == -1) {
+ sb.append(QueryPlugin.Util.getString("QueryParser.lexicalError", pe.currentToken.next.image)); //$NON-NLS-1$
+ }
+ if (pe.getMessage() != null) {
+ sb.append(pe.getMessage());
+ }
return sb.toString();
}
StringBuffer expected = new StringBuffer();
@@ -236,7 +245,7 @@
});
int maxSize = expectedTokenSequences[0].length;
StringBuilder retval = encountered(pe, maxSize);
- if (currentToken.next.kind == -1) {
+ if (currentToken.next.kind == INVALID_TOKEN) {
retval.append(QueryPlugin.Util.getString("QueryParser.lexicalError", currentToken.next.image)); //$NON-NLS-1$
return retval.toString();
}
@@ -288,22 +297,35 @@
} else {
addTokenSequence(1, retval, currentToken);
}
- if (currentToken.next.kind == -1) {
- maxSize = 1;
- }
- retval.append(" [*]"); //$NON-NLS-1$
- Token last = addTokenSequence(maxSize, retval, currentToken.next);
- if (last.kind != 0) {
- retval.append("[*]"); //$NON-NLS-1$
- if (last.next == null) {
- this.parser.getNextToken();
+ if (currentToken.next != null) {
+ boolean space = true;
+ if (currentToken.next.kind == INVALID_TOKEN) {
+ maxSize = 1;
+ space = currentToken.endColumn + 1 != currentToken.next.beginColumn;
}
- if (last.next != null) {
+ if (space) {
retval.append(" "); //$NON-NLS-1$
- addTokenSequence(1, retval, last.next);
}
+ retval.append("[*]"); //$NON-NLS-1$
+ Token last = addTokenSequence(maxSize, retval, currentToken.next);
+ if (last.kind != 0) {
+ retval.append("[*]"); //$NON-NLS-1$
+ if (last.next == null) {
+ this.parser.getNextToken();
+ }
+ if (last.next != null) {
+ if (!space) {
+ space = last.endColumn + 1 != last.next.beginColumn;
+ }
+ if (space) {
+ retval.append(" "); //$NON-NLS-1$
+ }
+ addTokenSequence(1, retval, last.next);
+ }
+ }
+ currentToken = currentToken.next;
}
- retval.append("\" at line ").append(currentToken.next.beginLine).append(", column ").append(currentToken.next.beginColumn); //$NON-NLS-1$ //$NON-NLS-2$
+ retval.append("\" at line ").append(currentToken.beginLine).append(", column ").append(currentToken.beginColumn); //$NON-NLS-1$ //$NON-NLS-2$
retval.append(".").append(pe.eol); //$NON-NLS-1$
return retval;
}
Modified: trunk/engine/src/main/java/org/teiid/query/parser/TeiidSQLParserTokenManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/TeiidSQLParserTokenManager.java 2012-09-29 19:14:01 UTC (rev 4490)
+++ trunk/engine/src/main/java/org/teiid/query/parser/TeiidSQLParserTokenManager.java 2012-09-30 12:57:02 UTC (rev 4491)
@@ -29,6 +29,7 @@
*/
class TeiidSQLParserTokenManager extends SQLParserTokenManager {
+ static final int INVALID_TOKEN = -1;
int tokenCount = 0;
Token head;
@@ -57,12 +58,12 @@
return t;
} catch (TokenMgrError err) {
Token t = new Token();
- t.kind = -1;
+ t.kind = INVALID_TOKEN;
t.beginColumn = this.input_stream.getBeginColumn();
t.beginLine = this.input_stream.getBeginLine();
- t.endColumn = t.beginColumn+1;
+ t.endColumn = t.beginColumn;
t.endLine = t.beginLine;
- t.image = new String(this.input_stream.buffer, this.input_stream.bufpos+1, 1);
+ t.image = this.input_stream.GetImage().substring(0, 1);
try {
//mark the char a consumed
this.input_stream.readChar();
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2012-09-29 19:14:01 UTC (rev 4490)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2012-09-30 12:57:02 UTC (rev 4491)
@@ -2696,8 +2696,16 @@
/** SELECT xx.yy%.a from xx.yy */
@Test public void testFailsWildcardInSelect(){
- helpException("SELECT xx.yy%.a from xx.yy", "TEIID31100 Parsing error: Encountered \"SELECT xx.yy [*]%[*] .\" at line 1, column 13.\nLexical error. Character is not a valid token: % "); //$NON-NLS-1$
+ helpException("SELECT xx.yy%.a from xx.yy", "TEIID31100 Parsing error: Encountered \"SELECT xx.yy[*]%[*].\" at line 1, column 13.\nLexical error. Character is not a valid token: % "); //$NON-NLS-1$
}
+
+ @Test public void testFailsWildcardInSelect1(){
+ helpException("SELECT % from xx.yy", "TEIID31100 Parsing error: Encountered \"SELECT [*]%[*] from\" at line 1, column 8.\nLexical error. Character is not a valid token: % "); //$NON-NLS-1$
+ }
+
+ @Test public void testInvalidToken(){
+ helpException("%", "");
+ }
/** SELECT a or b from g */
@Test public void testOrInSelect(){
12 years, 2 months
teiid SVN: r4490 - trunk/engine/src/test/java/org/teiid/query/function.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-09-29 15:14:01 -0400 (Sat, 29 Sep 2012)
New Revision: 4490
Modified:
trunk/engine/src/test/java/org/teiid/query/function/TestFunctionTree.java
Log:
TEIID-2233 adding a functiontree test
Modified: trunk/engine/src/test/java/org/teiid/query/function/TestFunctionTree.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/function/TestFunctionTree.java 2012-09-29 19:08:49 UTC (rev 4489)
+++ trunk/engine/src/test/java/org/teiid/query/function/TestFunctionTree.java 2012-09-29 19:14:01 UTC (rev 4490)
@@ -77,7 +77,7 @@
@Test public void testLoadErrors() {
FunctionMethod method = new FunctionMethod(
- "dummy", null, null, PushDown.CAN_PUSHDOWN, "nonexistentClass", "noMethod", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "dummy", null, null, PushDown.CAN_PUSHDOWN, null, "noMethod", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new ArrayList<FunctionParameter>(0),
new FunctionParameter("output", DataTypeManager.DefaultDataTypes.STRING), false, Determinism.DETERMINISTIC); //$NON-NLS-1$
@@ -89,6 +89,16 @@
new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions(), new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
fail();
} catch (TeiidRuntimeException e) {
+ assertEquals("TEIID31123 Could not load non-FOREIGN UDF \"dummy\", since both invocation class and invocation method are required.", e.getMessage());
+ }
+
+ method.setInvocationClass("nonexistantClass");
+
+ //should fail, no class
+ try {
+ new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions(), new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
+ fail();
+ } catch (TeiidRuntimeException e) {
}
12 years, 2 months
teiid SVN: r4489 - trunk/connectors/translator-object.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-09-29 15:08:49 -0400 (Sat, 29 Sep 2012)
New Revision: 4489
Modified:
trunk/connectors/translator-object/
Log:
adding to svn ignore
Property changes on: trunk/connectors/translator-object
___________________________________________________________________
Modified: svn:ignore
- .settings
+ .settings
target
12 years, 2 months
teiid SVN: r4488 - in trunk: engine/src/main/java/org/teiid/query and 5 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-09-29 15:07:41 -0400 (Sat, 29 Sep 2012)
New Revision: 4488
Added:
trunk/api/src/main/java/org/teiid/metadata/MetadataException.java
trunk/engine/src/main/java/org/teiid/query/parser/TeiidSQLParserTokenManager.java
Modified:
trunk/api/src/main/java/org/teiid/metadata/DuplicateRecordException.java
trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java
trunk/api/src/main/java/org/teiid/metadata/MetadataStore.java
trunk/api/src/main/java/org/teiid/metadata/ParseException.java
trunk/api/src/main/java/org/teiid/metadata/Parser.java
trunk/api/src/main/java/org/teiid/metadata/Schema.java
trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java
trunk/engine/src/main/java/org/teiid/query/function/FunctionTree.java
trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java
trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
trunk/engine/src/main/resources/org/teiid/query/i18n.properties
trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java
trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
Log:
TEIID-2233 updating parse exceptions to provide more context and updating the functiontree validation
Modified: trunk/api/src/main/java/org/teiid/metadata/DuplicateRecordException.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/DuplicateRecordException.java 2012-09-28 16:09:37 UTC (rev 4487)
+++ trunk/api/src/main/java/org/teiid/metadata/DuplicateRecordException.java 2012-09-29 19:07:41 UTC (rev 4488)
@@ -22,12 +22,14 @@
package org.teiid.metadata;
-public class DuplicateRecordException extends AssertionError {
+import org.teiid.core.BundleUtil.Event;
+public class DuplicateRecordException extends MetadataException {
+
private static final long serialVersionUID = -1319489333975416115L;
- public DuplicateRecordException(String msg) {
- super(msg);
+ public DuplicateRecordException(Event e, String msg) {
+ super(e, msg);
}
}
Added: trunk/api/src/main/java/org/teiid/metadata/MetadataException.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/MetadataException.java (rev 0)
+++ trunk/api/src/main/java/org/teiid/metadata/MetadataException.java 2012-09-29 19:07:41 UTC (rev 4488)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * 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
+ * 02110-1301 USA.
+ */
+
+package org.teiid.metadata;
+
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.BundleUtil.Event;
+
+public class MetadataException extends TeiidRuntimeException {
+ private static final long serialVersionUID = -7889770730039591817L;
+
+ public MetadataException(Event event, Throwable cause) {
+ super(event, cause);
+ }
+
+ public MetadataException(Throwable cause) {
+ super(cause);
+ }
+
+ public MetadataException(Event event, String message) {
+ super(event, message);
+ }
+
+ public MetadataException(String message) {
+ super(message);
+ }
+
+ public MetadataException(Event event,
+ Throwable e, String message) {
+ super(event, e, message);
+ }
+}
\ No newline at end of file
Property changes on: trunk/api/src/main/java/org/teiid/metadata/MetadataException.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java 2012-09-28 16:09:37 UTC (rev 4487)
+++ trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java 2012-09-29 19:07:41 UTC (rev 4488)
@@ -151,7 +151,7 @@
throw new TranslatorException(DataPlugin.Event.TEIID60008, DataPlugin.Util.gs(DataPlugin.Event.TEIID60008, name));
}
if (table.getColumnByName(name) != null) {
- throw new DuplicateRecordException(DataPlugin.Util.gs(DataPlugin.Event.TEIID60016, table.getFullName() + AbstractMetadataRecord.NAME_DELIM_CHAR + name));
+ throw new DuplicateRecordException(DataPlugin.Event.TEIID60016, DataPlugin.Util.gs(DataPlugin.Event.TEIID60016, table.getFullName() + AbstractMetadataRecord.NAME_DELIM_CHAR + name));
}
Column column = new Column();
column.setName(name);
@@ -276,11 +276,10 @@
return index;
}
- private void assignColumn(Table table, ColumnSet<?> columns, String columnName)
- throws TranslatorException {
+ private void assignColumn(Table table, ColumnSet<?> columns, String columnName) {
Column column = table.getColumnByName(columnName);
if (column == null) {
- throw new TranslatorException(DataPlugin.Event.TEIID60011, DataPlugin.Util.gs(DataPlugin.Event.TEIID60011, columnName));
+ throw new MetadataException(DataPlugin.Event.TEIID60011, DataPlugin.Util.gs(DataPlugin.Event.TEIID60011, columnName));
}
columns.getColumns().add(column);
}
@@ -386,7 +385,7 @@
}
private void assignColumns(List<String> columnNames, Table table,
- ColumnSet<?> columns) throws TranslatorException {
+ ColumnSet<?> columns) {
for (String columnName : columnNames) {
assignColumn(table, columns, columnName);
}
@@ -562,9 +561,9 @@
/**
* Parses, but does not close, the given {@link Reader} into this {@link MetadataFactory}
* @param ddl
- * @throws ParseException
+ * @throws MetadataException
*/
- public void parse(Reader ddl) throws ParseException {
+ public void parse(Reader ddl) throws MetadataException {
this.parser.parseDDL(this, ddl);
}
Modified: trunk/api/src/main/java/org/teiid/metadata/MetadataStore.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/MetadataStore.java 2012-09-28 16:09:37 UTC (rev 4487)
+++ trunk/api/src/main/java/org/teiid/metadata/MetadataStore.java 2012-09-29 19:07:41 UTC (rev 4488)
@@ -51,7 +51,7 @@
public void addSchema(Schema schema) {
if (this.schemas.put(schema.getName(), schema) != null) {
- throw new DuplicateRecordException(DataPlugin.Util.gs(DataPlugin.Event.TEIID60012, schema.getName()));
+ throw new DuplicateRecordException(DataPlugin.Event.TEIID60012, DataPlugin.Util.gs(DataPlugin.Event.TEIID60012, schema.getName()));
}
this.schemaList.add(schema);
}
Modified: trunk/api/src/main/java/org/teiid/metadata/ParseException.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/ParseException.java 2012-09-28 16:09:37 UTC (rev 4487)
+++ trunk/api/src/main/java/org/teiid/metadata/ParseException.java 2012-09-29 19:07:41 UTC (rev 4488)
@@ -22,13 +22,20 @@
package org.teiid.metadata;
-import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.BundleUtil.Event;
-public class ParseException extends TeiidRuntimeException {
+public class ParseException extends MetadataException {
private static final long serialVersionUID = -7889770730039591817L;
public ParseException(Event event, Throwable cause) {
super(event, cause);
}
+
+ public ParseException(Event event, String message) {
+ super(event, message);
+ }
+
+ public ParseException(String message) {
+ super(message);
+ }
}
\ No newline at end of file
Modified: trunk/api/src/main/java/org/teiid/metadata/Parser.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/Parser.java 2012-09-28 16:09:37 UTC (rev 4487)
+++ trunk/api/src/main/java/org/teiid/metadata/Parser.java 2012-09-29 19:07:41 UTC (rev 4488)
@@ -31,7 +31,7 @@
* The {@link Reader} will not be closed by this call.
* @param factory
* @param ddl
- * @throws ParseException
+ * @throws MetadataException
*/
- void parseDDL(MetadataFactory factory, Reader ddl) throws ParseException;
+ void parseDDL(MetadataFactory factory, Reader ddl) throws MetadataException;
}
\ No newline at end of file
Modified: trunk/api/src/main/java/org/teiid/metadata/Schema.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/Schema.java 2012-09-28 16:09:37 UTC (rev 4487)
+++ trunk/api/src/main/java/org/teiid/metadata/Schema.java 2012-09-29 19:07:41 UTC (rev 4488)
@@ -43,14 +43,14 @@
public void addTable(Table table) {
table.setParent(this);
if (this.tables.put(table.getName(), table) != null) {
- throw new DuplicateRecordException(DataPlugin.Util.gs(DataPlugin.Event.TEIID60013, table.getName()));
+ throw new DuplicateRecordException(DataPlugin.Event.TEIID60013, DataPlugin.Util.gs(DataPlugin.Event.TEIID60013, table.getName()));
}
}
public void addProcedure(Procedure procedure) {
procedure.setParent(this);
if (this.procedures.put(procedure.getName(), procedure) != null) {
- throw new DuplicateRecordException(DataPlugin.Util.gs(DataPlugin.Event.TEIID60014, procedure.getName()));
+ throw new DuplicateRecordException(DataPlugin.Event.TEIID60014, DataPlugin.Util.gs(DataPlugin.Event.TEIID60014, procedure.getName()));
}
}
@@ -58,7 +58,7 @@
function.setParent(this);
//TODO: ensure that all uuids are unique
if (this.functions.put(function.getUUID(), function) != null) {
- throw new DuplicateRecordException(DataPlugin.Util.gs(DataPlugin.Event.TEIID60015, function.getUUID()));
+ throw new DuplicateRecordException(DataPlugin.Event.TEIID60015, DataPlugin.Util.gs(DataPlugin.Event.TEIID60015, function.getUUID()));
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java 2012-09-28 16:09:37 UTC (rev 4487)
+++ trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java 2012-09-29 19:07:41 UTC (rev 4488)
@@ -535,6 +535,7 @@
TEIID31119,
TEIID31120,
TEIID31121,
- TEIID31122,
+ TEIID31122,
+ TEIID31123,
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/function/FunctionTree.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/function/FunctionTree.java 2012-09-28 16:09:37 UTC (rev 4487)
+++ trunk/engine/src/main/java/org/teiid/query/function/FunctionTree.java 2012-09-29 19:07:41 UTC (rev 4488)
@@ -36,7 +36,6 @@
import org.teiid.UserDefinedAggregate;
import org.teiid.core.CoreConstants;
-import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.ReflectionHelper;
import org.teiid.logging.LogConstants;
@@ -44,6 +43,7 @@
import org.teiid.metadata.AbstractMetadataRecord;
import org.teiid.metadata.FunctionMethod;
import org.teiid.metadata.FunctionParameter;
+import org.teiid.metadata.MetadataException;
import org.teiid.metadata.FunctionMethod.PushDown;
import org.teiid.query.QueryPlugin;
import org.teiid.query.function.metadata.FunctionCategoryConstants;
@@ -313,6 +313,9 @@
boolean requiresContext = false;
// Defect 20007 - Ignore the invocation method if pushdown is not required.
if (validateClass && (method.getPushdown() == PushDown.CAN_PUSHDOWN || method.getPushdown() == PushDown.CANNOT_PUSHDOWN)) {
+ if (method.getInvocationClass() == null || method.getInvocationMethod() == null) {
+ throw new MetadataException(QueryPlugin.Event.TEIID31123, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31123, method.getName()));
+ }
try {
Class<?> methodClass = source.getInvocationClass(method.getInvocationClass(), method.getClassLoader()==null?Thread.currentThread().getContextClassLoader():method.getClassLoader());
ReflectionHelper helper = new ReflectionHelper(methodClass);
@@ -324,36 +327,36 @@
requiresContext = true;
}
} catch (ClassNotFoundException e) {
- throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30387, e,QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30387, method.getName(), method.getInvocationClass()));
+ throw new MetadataException(QueryPlugin.Event.TEIID30387, e,QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30387, method.getName(), method.getInvocationClass()));
} catch (NoSuchMethodException e) {
- throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30388, e,QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30388, method, method.getInvocationClass(), method.getInvocationMethod()));
+ throw new MetadataException(QueryPlugin.Event.TEIID30388, e,QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30388, method, method.getInvocationClass(), method.getInvocationMethod()));
} catch (Exception e) {
- throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30389, e,QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30389, method, method.getInvocationClass(), method.getInvocationMethod()));
+ throw new MetadataException(QueryPlugin.Event.TEIID30389, e,QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30389, method, method.getInvocationClass(), method.getInvocationMethod()));
}
if (invocationMethod != null) {
// Check return type is non void
Class<?> methodReturn = invocationMethod.getReturnType();
if(method.getAggregateAttributes() == null && methodReturn.equals(Void.TYPE)) {
- throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30390, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30390, method.getName(), invocationMethod));
+ throw new MetadataException(QueryPlugin.Event.TEIID30390, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30390, method.getName(), invocationMethod));
}
// Check that method is public
int modifiers = invocationMethod.getModifiers();
if(! Modifier.isPublic(modifiers)) {
- throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30391, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30391, method.getName(), invocationMethod));
+ throw new MetadataException(QueryPlugin.Event.TEIID30391, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30391, method.getName(), invocationMethod));
}
// Check that method is static
if(! Modifier.isStatic(modifiers)) {
if (method.getAggregateAttributes() == null) {
- throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30392, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30392, method.getName(), invocationMethod));
+ throw new MetadataException(QueryPlugin.Event.TEIID30392, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30392, method.getName(), invocationMethod));
}
} else if (method.getAggregateAttributes() != null) {
- throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30600, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30600, method.getName(), invocationMethod));
+ throw new MetadataException(QueryPlugin.Event.TEIID30600, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30600, method.getName(), invocationMethod));
}
if (method.getAggregateAttributes() != null && !(UserDefinedAggregate.class.isAssignableFrom(invocationMethod.getDeclaringClass()))) {
- throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30601, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30601, method.getName(), method.getInvocationClass(), UserDefinedAggregate.class.getName()));
+ throw new MetadataException(QueryPlugin.Event.TEIID30601, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30601, method.getName(), method.getInvocationClass(), UserDefinedAggregate.class.getName()));
}
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java 2012-09-28 16:09:37 UTC (rev 4487)
+++ trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java 2012-09-29 19:07:41 UTC (rev 4488)
@@ -28,6 +28,7 @@
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import org.teiid.api.exception.query.QueryParserException;
@@ -60,14 +61,11 @@
}
};
- // Used in parsing TokenMgrError message
- private static final String LINE_MARKER = "line "; //$NON-NLS-1$
- private static final String COL_MARKER = "column "; //$NON-NLS-1$
-
private static final String XQUERY_DECLARE = "declare"; //$NON-NLS-1$
private static final String XML_OPEN_BRACKET = "<"; //$NON-NLS-1$
private SQLParser parser;
+ private TeiidSQLParserTokenManager tm;
/**
* Construct a QueryParser - this may be reused.
@@ -87,9 +85,13 @@
private SQLParser getSqlParser(Reader sql) {
if(parser == null) {
- parser = new SQLParser(sql);
+ JavaCharStream jcs = new JavaCharStream(sql);
+ tm = new TeiidSQLParserTokenManager(new JavaCharStream(sql));
+ parser = new SQLParser(tm);
+ parser.jj_input_stream = jcs;
} else {
parser.ReInit(sql);
+ tm.reinit();
}
return parser;
}
@@ -117,8 +119,8 @@
return result;
} catch(ParseException pe) {
throw convertParserException(pe);
- } catch(TokenMgrError tme) {
- throw handleTokenMgrError(tme);
+ } finally {
+ tm.reinit();
}
}
@@ -157,11 +159,8 @@
throw new QueryParserException(QueryPlugin.Event.TEIID30378, pe, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30378, sql));
}
throw convertParserException(pe);
- } catch(TokenMgrError tme) {
- if(sql.startsWith(XML_OPEN_BRACKET) || sql.startsWith(XQUERY_DECLARE)) {
- throw new QueryParserException(QueryPlugin.Event.TEIID30378, tme, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30378, sql));
- }
- throw handleTokenMgrError(tme);
+ } finally {
+ tm.reinit();
}
return result;
}
@@ -194,25 +193,34 @@
} catch(ParseException pe) {
throw convertParserException(pe);
-
- } catch(TokenMgrError tme) {
- throw handleTokenMgrError(tme);
+ } finally {
+ tm.reinit();
}
return result;
}
private QueryParserException convertParserException(ParseException pe) {
+ if (pe.currentToken == null) {
+ List<Token> preceeding = findPreceeding(parser.token, 1);
+ if (!preceeding.isEmpty()) {
+ pe.currentToken = preceeding.get(0);
+ } else {
+ pe.currentToken = parser.token;
+ }
+ }
QueryParserException qpe = new QueryParserException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31100, getMessage(pe, 1, 10)));
qpe.setParseException(pe);
- if (pe.currentToken == null) {
- pe.currentToken = parser.token;
- }
return qpe;
}
- public static String getMessage(ParseException pe, int maxTokenSequence, int maxExpansions) {
+ public String getMessage(ParseException pe, int maxTokenSequence, int maxExpansions) {
if (!pe.specialConstructor) {
- return pe.getMessage();
+ if (pe.currentToken == null) {
+ return pe.getMessage();
+ }
+ StringBuilder sb = encountered(pe, 1);
+ sb.append(pe.getMessage());
+ return sb.toString();
}
StringBuffer expected = new StringBuffer();
int[][] expectedTokenSequences = pe.expectedTokenSequences;
@@ -227,21 +235,11 @@
}
});
int maxSize = expectedTokenSequences[0].length;
- StringBuilder retval = new StringBuilder("Encountered \""); //$NON-NLS-1$
- Token tok = currentToken.next;
- for (int i = 0; i < maxSize; i++) {
- if (i != 0)
- retval.append(" "); //$NON-NLS-1$
- if (tok.kind == 0) {
- retval.append(tokenImage[0]);
- break;
- }
- retval.append(pe.add_escapes(tok.image));
- tok = tok.next;
+ StringBuilder retval = encountered(pe, maxSize);
+ if (currentToken.next.kind == -1) {
+ retval.append(QueryPlugin.Util.getString("QueryParser.lexicalError", currentToken.next.image)); //$NON-NLS-1$
+ return retval.toString();
}
- retval.append("\" at line " + currentToken.next.beginLine + ", column " //$NON-NLS-1$ //$NON-NLS-2$
- + currentToken.next.beginColumn);
- retval.append("." + eol); //$NON-NLS-1$
for (int i = 0; i < expectedTokenSequences.length; i++) {
boolean truncateStart = expectedTokenSequences[i].length == maxSize && maxSize > 1 && maxSize > maxTokenSequence;
int start = 0;
@@ -281,6 +279,118 @@
return retval.toString();
}
+ private StringBuilder encountered(ParseException pe, int maxSize) {
+ StringBuilder retval = new StringBuilder("Encountered \""); //$NON-NLS-1$
+ Token currentToken = pe.currentToken;
+ List<Token> preceeding = findPreceeding(currentToken, 2);
+ if (!preceeding.isEmpty()) {
+ addTokenSequence(preceeding.size() + 1, retval, preceeding.get(0));
+ } else {
+ addTokenSequence(1, retval, currentToken);
+ }
+ if (currentToken.next.kind == -1) {
+ maxSize = 1;
+ }
+ retval.append(" [*]"); //$NON-NLS-1$
+ Token last = addTokenSequence(maxSize, retval, currentToken.next);
+ if (last.kind != 0) {
+ retval.append("[*]"); //$NON-NLS-1$
+ if (last.next == null) {
+ this.parser.getNextToken();
+ }
+ if (last.next != null) {
+ retval.append(" "); //$NON-NLS-1$
+ addTokenSequence(1, retval, last.next);
+ }
+ }
+ retval.append("\" at line ").append(currentToken.next.beginLine).append(", column ").append(currentToken.next.beginColumn); //$NON-NLS-1$ //$NON-NLS-2$
+ retval.append(".").append(pe.eol); //$NON-NLS-1$
+ return retval;
+ }
+
+ private List<Token> findPreceeding(Token currentToken, int count) {
+ LinkedList<Token> preceeding = new LinkedList<Token>();
+ Token tok = this.tm.head;
+ boolean found = false;
+ while (tok != null) {
+ if (tok == currentToken) {
+ found = true;
+ break;
+ }
+ preceeding.add(tok);
+ if (preceeding.size() > count) {
+ preceeding.removeFirst();
+ }
+ tok = tok.next;
+ }
+ if (!found) {
+ preceeding.clear();
+ }
+ return preceeding;
+ }
+
+ private Token addTokenSequence(int maxSize, StringBuilder retval,
+ Token tok) {
+ Token last = tok;
+ for (int i = 0; i < maxSize && tok != null; i++) {
+ if (i != 0)
+ retval.append(" "); //$NON-NLS-1$
+ if (tok.kind == 0) {
+ retval.append(SQLParserConstants.tokenImage[0]);
+ return tok;
+ }
+ last = tok;
+ add_escapes(tok.image, retval);
+ tok = tok.next;
+ }
+ return last;
+ }
+
+ /**
+ * Used to convert raw characters to their escaped version
+ * when these raw version cannot be used as part of an ASCII
+ * string literal. Also escapes double quotes.
+ */
+ protected void add_escapes(String str, StringBuilder retval) {
+ for (int i = 0; i < str.length(); i++) {
+ char ch = str.charAt(i);
+ switch (ch)
+ {
+ case 0 :
+ continue;
+ case '\b':
+ retval.append("\\b"); //$NON-NLS-1$
+ continue;
+ case '\t':
+ retval.append("\\t"); //$NON-NLS-1$
+ continue;
+ case '\n':
+ retval.append("\\n"); //$NON-NLS-1$
+ continue;
+ case '\f':
+ retval.append("\\f"); //$NON-NLS-1$
+ continue;
+ case '\r':
+ retval.append("\\r"); //$NON-NLS-1$
+ continue;
+ case '\"':
+ retval.append("\\\""); //$NON-NLS-1$
+ continue;
+ case '\\':
+ retval.append("\\\\"); //$NON-NLS-1$
+ continue;
+ default:
+ if (ch < 0x20 || ch > 0x7e) {
+ String s = "0000" + Integer.toString(ch, 16); //$NON-NLS-1$
+ retval.append("\\u" + s.substring(s.length() - 4, s.length())); //$NON-NLS-1$
+ } else {
+ retval.append(ch);
+ }
+ continue;
+ }
+ }
+ }
+
/**
* Takes a SQL string representing an SQL expression
* and returns the object representation.
@@ -302,9 +412,8 @@
} catch(ParseException pe) {
throw convertParserException(pe);
-
- } catch(TokenMgrError tme) {
- throw handleTokenMgrError(tme);
+ } finally {
+ tm.reinit();
}
return result;
}
@@ -322,41 +431,12 @@
} catch(ParseException pe) {
throw convertParserException(pe);
-
- } catch(TokenMgrError tme) {
- throw handleTokenMgrError(tme);
+ } finally {
+ tm.reinit();
}
return result;
}
- private QueryParserException handleTokenMgrError(TokenMgrError tme) {
-// LogManager.logError( LogConstants.CTX_QUERY_PARSER, tme, new Object[] {"Exception parsing: ", sql} );
-
- // From TokenMgrError, here is format of lexical error:
- //
- // "Lexical error at line " + errorLine + ", column " + errorColumn +
- // ". Encountered: " + (EOFSeen ? "<EOF> " : ("\"" +
- // addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
- // "after : \"" + addEscapes(errorAfter) + "\""
-
- String msg = tme.getMessage();
- int index = msg.indexOf(LINE_MARKER);
- if(index > 0) {
- index += LINE_MARKER.length();
- int lastIndex = msg.indexOf(",", index); //$NON-NLS-1$
-
- index = msg.indexOf(COL_MARKER, lastIndex);
- if(index > 0) {
- index += COL_MARKER.length();
- lastIndex = msg.indexOf(".", index); //$NON-NLS-1$
-
- return new QueryParserException(QueryPlugin.Util.getString("QueryParser.lexicalError", tme.getMessage())); //$NON-NLS-1$
- }
-
- }
- return new QueryParserException(QueryPlugin.Util.getString("QueryParser.parsingError", tme.getMessage())); //$NON-NLS-1$
- }
-
public void parseDDL(MetadataFactory factory, String ddl) {
parseDDL(factory, new StringReader(ddl));
}
@@ -366,11 +446,13 @@
getSqlParser(ddl).parseMetadata(factory);
} catch (ParseException e) {
throw new org.teiid.metadata.ParseException(QueryPlugin.Event.TEIID30386, convertParserException(e));
- }
+ } finally {
+ tm.reinit();
+ }
HashSet<FunctionMethod> functions = new HashSet<FunctionMethod>();
for (FunctionMethod functionMethod : factory.getSchema().getFunctions().values()) {
if (!functions.add(functionMethod)) {
- throw new DuplicateRecordException(DataPlugin.Util.gs(DataPlugin.Event.TEIID60015, functionMethod.getName()));
+ throw new DuplicateRecordException(DataPlugin.Event.TEIID60015, DataPlugin.Util.gs(DataPlugin.Event.TEIID60015, functionMethod.getName()));
}
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2012-09-28 16:09:37 UTC (rev 4487)
+++ trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2012-09-29 19:07:41 UTC (rev 4488)
@@ -34,7 +34,6 @@
import org.teiid.core.util.PropertiesUtils;
import org.teiid.core.util.StringUtil;
import org.teiid.language.SQLConstants;
-import org.teiid.language.SQLConstants.Reserved;
import org.teiid.metadata.*;
import org.teiid.metadata.Column.SearchType;
import org.teiid.metadata.ProcedureParameter.Type;
@@ -162,16 +161,7 @@
return true;
}
- /**
- * Check that this is a valid alias, remove quotes, and return updated
- * alias string.
- * @param id Metadata alias
- */
- String validateAlias(String id) throws ParseException {
- return validateName(id, false);
- }
-
- private String validateName(String id, boolean element) throws ParseException {
+ String validateName(String id, boolean element) throws ParseException {
if(id.indexOf('.') != -1) {
String key = "SQLParser.Invalid_alias"; //$NON-NLS-1$
if (element) {
@@ -182,14 +172,6 @@
return id;
}
- /**
- * Check that this is a valid element name, remove quotes
- * @param id Metadata alias
- */
- String validateElementName(String id) throws ParseException {
- return validateName(id, true);
- }
-
static String removeEscapeChars(String str, String tickChar) {
return StringUtil.replaceAll(str, tickChar + tickChar, tickChar);
}
@@ -304,38 +286,6 @@
return null;
}
- /**
- * Helper for the FROM clause that takes the join type string and adds
- * the join type to the From clause based on that type.
- * @param groupID Left group ID
- * @param rid Right group ID
- * @param joinType Join type word from query
- * @param from From clause to update
- * @throws ParseException if parsing failed
- */
- JoinType getJoinType(Token joinTypeToken) throws ParseException {
- if(joinTypeToken == null) {
- return JoinType.JOIN_INNER;
- }
- String joinType = joinTypeToken.image;
- if(joinType.equalsIgnoreCase(Reserved.INNER)) {
- return JoinType.JOIN_INNER;
- } else if(joinType.equalsIgnoreCase(Reserved.CROSS)) {
- return JoinType.JOIN_CROSS;
- } else if(joinType.equalsIgnoreCase(Reserved.LEFT)) {
- return JoinType.JOIN_LEFT_OUTER;
- } else if(joinType.equalsIgnoreCase(Reserved.RIGHT)) {
- return JoinType.JOIN_RIGHT_OUTER;
- } else if(joinType.equalsIgnoreCase(Reserved.FULL)) {
- return JoinType.JOIN_FULL_OUTER;
- } else if(joinType.equalsIgnoreCase(Reserved.UNION)) {
- return JoinType.JOIN_UNION;
- } else {
- Object[] params = new Object[] { joinType };
- throw new ParseException(QueryPlugin.Util.getString("SQLParser.Unknown_join_type", params)); //$NON-NLS-1$
- }
- }
-
int getOperator(String opString) {
if (opString.equals("=")) { //$NON-NLS-1$
return CompareCriteria.EQ;
@@ -370,7 +320,7 @@
return new Block(stmt);
}
- void setColumnOptions(BaseColumn c) throws ParseException {
+ void setColumnOptions(BaseColumn c) throws MetadataException {
Map<String, String> props = c.getProperties();
setCommonProperties(c, props);
@@ -384,7 +334,7 @@
}
}
- private void setColumnOptions(Column c, Map<String, String> props) throws ParseException {
+ private void setColumnOptions(Column c, Map<String, String> props) throws MetadataException {
String v = props.remove(DDLConstants.CASE_SENSITIVE);
if (v != null) {
c.setCaseSensitive(isTrue(v));
@@ -461,7 +411,7 @@
c.setScale(Integer.parseInt(matcher.group(4)));
}
else {
- throw new ParseException(QueryPlugin.Util.getString("udt_format_wrong", c.getName())); //$NON-NLS-1$
+ throw new MetadataException(QueryPlugin.Util.getString("udt_format_wrong", c.getName())); //$NON-NLS-1$
}
}
}
@@ -511,7 +461,7 @@
}
static void replaceProcedureWithFunction(MetadataFactory factory,
- Procedure proc) throws ParseException {
+ Procedure proc) throws MetadataException {
FunctionMethod method = new FunctionMethod();
method.setName(proc.getName());
method.setPushdown(proc.isVirtual()?FunctionMethod.PushDown.CAN_PUSHDOWN:FunctionMethod.PushDown.MUST_PUSHDOWN);
@@ -519,7 +469,7 @@
ArrayList<FunctionParameter> ins = new ArrayList<FunctionParameter>();
for (ProcedureParameter pp:proc.getParameters()) {
if (pp.getType() == ProcedureParameter.Type.InOut || pp.getType() == ProcedureParameter.Type.Out) {
- throw new ParseException(QueryPlugin.Util.getString("SQLParser.function_in", proc.getName())); //$NON-NLS-1$
+ throw new MetadataException(QueryPlugin.Util.getString("SQLParser.function_in", proc.getName())); //$NON-NLS-1$
}
FunctionParameter fp = new FunctionParameter(pp.getName(), pp.getRuntimeType(), pp.getAnnotation());
@@ -533,7 +483,7 @@
method.setInputParameters(ins);
if (proc.getResultSet() != null || method.getOutputParameter() == null) {
- throw new ParseException(QueryPlugin.Util.getString("SQLParser.function_return", proc.getName())); //$NON-NLS-1$
+ throw new MetadataException(QueryPlugin.Util.getString("SQLParser.function_return", proc.getName())); //$NON-NLS-1$
}
method.setAnnotation(proc.getAnnotation());
@@ -580,12 +530,12 @@
return Boolean.valueOf(text);
}
- Column getColumn(String columnName, Table table) throws ParseException {
+ Column getColumn(String columnName, Table table) throws MetadataException {
Column c = table.getColumnByName(columnName);
if (c != null) {
return c;
}
- throw new ParseException(QueryPlugin.Util.getString("SQLParser.no_column", columnName, table.getName())); //$NON-NLS-1$
+ throw new MetadataException(QueryPlugin.Util.getString("SQLParser.no_column", columnName, table.getName())); //$NON-NLS-1$
}
void createDDLTrigger(MetadataFactory schema, AlterTrigger trigger) {
@@ -603,9 +553,8 @@
}
}
- BaseColumn addProcColumn(MetadataFactory factory, Procedure proc, String name, ParsedDataType type, boolean rs) throws ParseException{
+ BaseColumn addProcColumn(MetadataFactory factory, Procedure proc, String name, ParsedDataType type, boolean rs) throws MetadataException {
try {
- name = validateElementName(name);
BaseColumn column = null;
if (rs) {
column = factory.addProcedureResultSetColumn(name, type.type, proc);
@@ -615,7 +564,7 @@
if (pp.getType() == Type.ReturnValue) {
added = true;
if (pp.getDatatype() != factory.getDataTypes().get(type.type)) {
- throw new ParseException(QueryPlugin.Util.getString("SQLParser.proc_type_conflict", proc.getName(), pp.getDatatype(), type.type)); //$NON-NLS-1$
+ throw new MetadataException(QueryPlugin.Util.getString("SQLParser.proc_type_conflict", proc.getName(), pp.getDatatype(), type.type)); //$NON-NLS-1$
}
}
}
@@ -626,7 +575,7 @@
setTypeInfo(type, column);
return column;
} catch (TranslatorException e){
- throw new ParseException(e.getMessage());
+ throw new MetadataException(e.getMessage());
}
}
@@ -655,7 +604,7 @@
return key;
}
- KeyRecord addFBI(MetadataFactory factory, List<Expression> expressions, Table table, String name) throws ParseException {
+ KeyRecord addFBI(MetadataFactory factory, List<Expression> expressions, Table table, String name) throws MetadataException {
List<String> columnNames = new ArrayList<String>(expressions.size());
List<Boolean> nonColumnExpressions = new ArrayList<Boolean>(expressions.size());
boolean fbi = false;
@@ -674,7 +623,7 @@
table.addAttchment(MetadataFactory.class, factory);
return factory.addFunctionBasedIndex(name != null?name:(SQLConstants.NonReserved.INDEX+(fbi?table.getFunctionBasedIndexes().size():table.getIndexes().size())), columnNames, nonColumnExpressions, table);
}catch(TranslatorException e){
- throw new ParseException(e.getMessage());
+ throw new MetadataException(e.getMessage());
}
}
Added: trunk/engine/src/main/java/org/teiid/query/parser/TeiidSQLParserTokenManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/TeiidSQLParserTokenManager.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/query/parser/TeiidSQLParserTokenManager.java 2012-09-29 19:07:41 UTC (rev 4488)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * 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
+ * 02110-1301 USA.
+ */
+
+package org.teiid.query.parser;
+
+import java.io.IOException;
+
+/**
+ * A customized TokenManager to keep a token history and to treat lexical errors as invalid single character tokens
+ */
+class TeiidSQLParserTokenManager extends SQLParserTokenManager {
+
+ int tokenCount = 0;
+ Token head;
+
+ public TeiidSQLParserTokenManager(JavaCharStream stream) {
+ super(stream);
+ }
+
+ void reinit() {
+ tokenCount = 0;
+ head = null;
+ }
+
+ @Override
+ public Token getNextToken() {
+ try {
+ Token t = super.getNextToken();
+ //if we're in the default lex state, keep track of a history of tokens
+ //this logic is not perfect as deep lookaheads can ruin the positioning
+ if (tokenCount == 0) {
+ head = t;
+ }
+ tokenCount++;
+ if (tokenCount > 10) {
+ head = head.next;
+ }
+ return t;
+ } catch (TokenMgrError err) {
+ Token t = new Token();
+ t.kind = -1;
+ t.beginColumn = this.input_stream.getBeginColumn();
+ t.beginLine = this.input_stream.getBeginLine();
+ t.endColumn = t.beginColumn+1;
+ t.endLine = t.beginLine;
+ t.image = new String(this.input_stream.buffer, this.input_stream.bufpos+1, 1);
+ try {
+ //mark the char a consumed
+ this.input_stream.readChar();
+ } catch (IOException e) {
+ }
+ return t;
+ }
+ }
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/query/parser/TeiidSQLParserTokenManager.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2012-09-28 16:09:37 UTC (rev 4487)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2012-09-29 19:07:41 UTC (rev 4488)
@@ -576,13 +576,17 @@
description=Partial or full name of a single entity.
example={code:sql}tbl.col{code}\n{code:sql}"tbl"."col"{code}
*/
-String id() :
+String id(Boolean validate) :
{
}
{
(<ID>|nonReserved())
{
- return normalizeId(getToken(0).image);
+ String id = normalizeId(getToken(0).image);
+ if (validate != null) {
+ return validateName(id, validate);
+ }
+ return id;
}
}
@@ -637,7 +641,7 @@
}
{
- <CREATE> <TRIGGER> <ON> target = id() <INSTEAD> <OF>
+ <CREATE> <TRIGGER> <ON> target = id(null) <INSTEAD> <OF>
(event = <INSERT> | event = <UPDATE> | event = <DELETE>)
<AS> triggerAction = forEachRowTriggerAction(info)
{
@@ -668,7 +672,7 @@
{
<ALTER>
(
- (<VIEW> target = id() <AS> { comment = getToken(1).specialToken; } command = queryExpression(info))
+ (<VIEW> target = id(null) <AS> { comment = getToken(1).specialToken; } command = queryExpression(info))
{
if (comment != null) {
command.setCacheHint(getQueryCacheOption(comment.image));
@@ -678,7 +682,7 @@
alterView.setDefinition(command);
return alterView;
}
- | (<PROCEDURE> target = id() <AS> { comment = getToken(1).specialToken; } stmt = statement(info))
+ | (<PROCEDURE> target = id(null) <AS> { comment = getToken(1).specialToken; } stmt = statement(info))
{
CreateProcedureCommand cup = new CreateProcedureCommand(asBlock(stmt));
if (comment != null) {
@@ -689,7 +693,7 @@
alterProc.setDefinition(cup);
return alterProc;
}
- | (<TRIGGER> <ON> target = id() <INSTEAD> <OF>
+ | (<TRIGGER> <ON> target = id(null) <INSTEAD> <OF>
(event = <INSERT> | event = <UPDATE> | event = <DELETE>)
((<AS> triggerAction = forEachRowTriggerAction(info))
|<ENABLED> {enabled=true;}| <DISABLED> {enabled=false;}))
@@ -796,7 +800,7 @@
}
{
<DROP> <TABLE>
- table = id()
+ table = id(null)
{
drop.setTable(new GroupSymbol(table));
return drop;
@@ -814,11 +818,11 @@
String table = null;
String pkId = null;
Column col = null;
- List<String> columnNames = null;
+ List<ElementSymbol> pk = null;
}
{
<CREATE> <LOCAL> <TEMPORARY> <TABLE>
- table = id()
+ table = id(null)
<LPAREN>
{
create.setTable(new GroupSymbol(table));
@@ -834,11 +838,9 @@
}
)*
[<COMMA> <PRIMARY> <KEY>
- columnNames = getColumnNames()
+ pk = columnList(true, true)
{
- for (String id : columnNames) {
- create.getPrimaryKey().add(new ElementSymbol(validateElementName(id)));
- }
+ create.getPrimaryKey().addAll(pk);
}
]
<RPAREN>
@@ -861,7 +863,7 @@
boolean notNull = false;
}
{
- element = id()
+ element = id(Boolean.TRUE)
(
type = parseDataType()
|
@@ -875,7 +877,7 @@
[<NOT> <NULL> { notNull = true; }]
{
Column c = new Column();
- c.setName(validateElementName(element));
+ c.setName(element);
c.setRuntimeType(type.type);
c.setAutoIncremented(autoIncrement);
c.setNullType(notNull?NullType.No_Nulls:NullType.Nullable);
@@ -933,7 +935,7 @@
Expression ex;
}
{
- id = id() {return new ElementSymbol(id);}
+ id = id(null) {return new ElementSymbol(id);}
|
ex = exception(info)
{
@@ -982,7 +984,7 @@
}
{
(
- LOOKAHEAD(2) ([label = id() <COLON>]
+ LOOKAHEAD(2) ([label = id(null) <COLON>]
(
stmt = loopStatement(info) |
stmt = whileStatement(info) |
@@ -1047,7 +1049,7 @@
block.addStatement(stmt, false);
}
)*
- [<EXCEPTION> eId = id() {block.setExceptionGroup(validateAlias(eId));}
+ [<EXCEPTION> eId = id(Boolean.FALSE) {block.setExceptionGroup(eId);}
(
stmt = statement(info)
{
@@ -1078,10 +1080,10 @@
{
(
(
- (mode = <BREAK> | mode = <CONTINUE>) [label = id()]
+ (mode = <BREAK> | mode = <CONTINUE>) [label = id(null)]
)
|
- (mode = <LEAVE> label = id())
+ (mode = <LEAVE> label = id(null))
)
{
breakStmt.setMode(BranchingStatement.BranchingMode.valueOf(mode.image.toUpperCase()));
@@ -1132,7 +1134,7 @@
query = queryExpression(info)
<RPAREN>
<AS>
- cursor = id()
+ cursor = id(null)
stmt = statement(info)
{
loopStmt = new LoopStatement(asBlock(stmt), query, cursor);
@@ -1183,7 +1185,7 @@
{
<DECLARE>
(type = parseDataType() | <EXCEPTION> {type = new ParsedDataType(getToken(0).image);})
- var = id()
+ var = id(null)
{
variableID = new ElementSymbol(var);
}
@@ -1215,7 +1217,7 @@
boolean returnable=true;
}
{
- var = id()
+ var = id(null)
{
elementID = new ElementSymbol(var);
}
@@ -1355,7 +1357,7 @@
elements = createElementsWithTypes(info)
[<INTO>
- groupID = id()
+ groupID = id(null)
{
group = new GroupSymbol(groupID);
}
@@ -1402,21 +1404,19 @@
Expression value = null;
}
{
- element = id()
+ element = id(shortName?Boolean.TRUE:null)
<EQ>
value = expression(info)
{
- String symbolName = shortName?validateElementName(element):element;
- ElementSymbol symbol = new ElementSymbol(symbolName);
+ ElementSymbol symbol = new ElementSymbol(element);
using.addClause(symbol, value);
}
(<COMMA>
- element = id()
+ element = id(null)
<EQ>
value = expression(info)
{
- symbolName = shortName?validateElementName(element):element;
- symbol = new ElementSymbol(symbolName);
+ symbol = new ElementSymbol(element);
using.addClause(symbol, value);
}
)*
@@ -1437,17 +1437,17 @@
List<TableFunctionReference.ProjectedColumn> elements = new ArrayList<TableFunctionReference.ProjectedColumn>();
}
{
- element = id()
+ element = id(Boolean.TRUE)
type = parseDataType()
{
- TableFunctionReference.ProjectedColumn symbol = new TableFunctionReference.ProjectedColumn(validateElementName(element), type.type);
+ TableFunctionReference.ProjectedColumn symbol = new TableFunctionReference.ProjectedColumn(element, type.type);
elements.add(symbol);
}
(LOOKAHEAD(2) <COMMA>
- element = id()
+ element = id(Boolean.TRUE)
type = parseDataType()
{
- symbol = new TableFunctionReference.ProjectedColumn(validateElementName(element), type.type);
+ symbol = new TableFunctionReference.ProjectedColumn(element, type.type);
elements.add(symbol);
}
)*
@@ -1481,7 +1481,7 @@
storedProcedure.setCalledWithReturn(true);
}
]
- <CALL> procName = id()
+ <CALL> procName = id(null)
{
storedProcedure.setProcedureName(procName);
}
@@ -1519,7 +1519,7 @@
{
(
(<EXEC> | <EXECUTE> | <CALL>)
- procName = id()
+ procName = id(null)
{
storedProcedure.setProcedureName(procName);
}
@@ -1561,7 +1561,7 @@
{
storedProcedure.setDisplayNamedParameters(true);
}
- (name=id()
+ (name=id(null)
<EQ> [<GT>]
value = expression(info)
{
@@ -1572,7 +1572,7 @@
parameter = null;
}
( <COMMA>
- name=id()
+ name=id(null)
<EQ> [<GT>]
value = expression(info)
{
@@ -1602,9 +1602,9 @@
}
{
<INSERT> <INTO>
- group = id()
+ group = id(null)
- [LOOKAHEAD(<LPAREN> id()) columns = columnList(false) {
+ [LOOKAHEAD(<LPAREN> id(null)) columns = columnList(false, true) {
insert.setVariables(columns);
}]
@@ -1640,40 +1640,6 @@
}
/*
-name=column list
-description=A list of column references.
-example={code:sql}(col1, col2, ...){code}
-*/
-List<ElementSymbol> columnList(boolean validate) :
-{
- String element = null;
- List<ElementSymbol> symbols = new LinkedList<ElementSymbol>();
-}
-{
- <LPAREN>
- element = id()
- {
- if (validate) {
- element = validateElementName(element);
- }
- symbols.add(new ElementSymbol(element));
- }
- ( <COMMA>
- element = id()
- {
- if (validate) {
- element = validateElementName(element);
- }
- symbols.add(new ElementSymbol(element));
- }
- )*
- <RPAREN>
- {
- return symbols;
- }
-}
-
-/*
name=expression list
description=A list of expressions.
example={code:sql}col1, 'a', ...{code}
@@ -1714,7 +1680,7 @@
}
{
<UPDATE>
- group = id()
+ group = id(null)
<SET>
setClauseList = setClauseList(false, info)
{
@@ -1753,7 +1719,7 @@
}
{
<DELETE> <FROM>
- group = id()
+ group = id(null)
[criteria = where(info)]
[option = option(info)
{
@@ -1811,11 +1777,11 @@
QueryCommand queryExpression = null;
}
{
- name = id()
- [ columns = columnList(true)]
+ name = id(Boolean.FALSE)
+ [ columns = columnList(true, true)]
<AS> <LPAREN> queryExpression = queryExpression(info) <RPAREN>
{
- return new WithQueryCommand(new GroupSymbol(validateAlias(name)), columns, queryExpression);
+ return new WithQueryCommand(new GroupSymbol(name), columns, queryExpression);
}
}
@@ -1891,7 +1857,7 @@
{
(
query=query(info) |
- (<TABLE> name=id() {
+ (<TABLE> name=id(null) {
Query q = new Query();
q.setSelect(new Select(Arrays.asList(new MultipleElementSymbol())));
q.setFrom(new From(Arrays.asList(new UnaryFromClause(new GroupSymbol(name)))));
@@ -1953,7 +1919,7 @@
}
{
<INTO>
- (groupID=id())
+ (groupID=id(null))
{
into = new Into(new GroupSymbol(groupID));
return into;
@@ -2025,11 +1991,10 @@
(
// Expression
expression=expression(info)
- [[<AS>] alias=id() ]
+ [[<AS>] alias=id(Boolean.FALSE) ]
)
{
if(alias != null) {
- alias = validateAlias(alias);
return new AliasSymbol(alias, expression);
}
return expression;
@@ -2050,12 +2015,9 @@
(
// Expression
expression=expression(info)
- [<AS> alias=id() ]
+ [<AS> alias=id(Boolean.FALSE) ]
)
{
- if(alias != null) {
- alias = validateAlias(alias);
- }
return new DerivedColumn(alias, expression);
}
}
@@ -2143,7 +2105,7 @@
]
[
<ENCODING>
- encoding = id()
+ encoding = id(null)
]
[
orderBy = orderby(info)
@@ -2424,7 +2386,7 @@
[
<AS> (<STRING> | <VARCHAR> | <CLOB> | <VARBINARY> | <BLOB>) { t = getToken(0);}
]
- [ <ENCODING> enc = id() ]
+ [ <ENCODING> enc = id(null) ]
[ <VERSION> ver = stringVal() ]
[ ( <INCLUDING> {declr = true;}| <EXCLUDING> {declr = false;}) <XMLDECLARATION> ]
<RPAREN>
@@ -2460,12 +2422,12 @@
<COLUMNS>
columns = createElementsWithTypes(info)
<RPAREN>
- [<AS>] aliasID=id()
+ [<AS>] aliasID=id(Boolean.FALSE)
{
ArrayTable result = new ArrayTable();
result.setArrayValue(array);
result.setColumns(columns);
- result.setName(validateAlias(aliasID));
+ result.setName(aliasID);
return result;
}
}
@@ -2537,7 +2499,7 @@
skip = intVal()
]
<RPAREN>
- [<AS>] aliasID=id()
+ [<AS>] aliasID=id(Boolean.FALSE)
{
TextTable result = new TextTable();
result.setFile(file);
@@ -2546,7 +2508,7 @@
result.setEscape(escape);
result.setHeader(header);
result.setSkip(skip);
- result.setName(validateAlias(aliasID));
+ result.setName(aliasID);
result.setQuote(quote);
result.setUsingRowDelimiter(useRowDelimiter);
result.setSelector(selector);
@@ -2569,7 +2531,7 @@
Integer position = null;
}
{
- name = id()
+ name = id(Boolean.TRUE)
datatype = parseDataType()
[
<WIDTH>
@@ -2587,7 +2549,7 @@
position = intVal()
]
{
- TextTable.TextColumn result = new TextTable.TextColumn(validateElementName(name), datatype.type, width, noTrim);
+ TextTable.TextColumn result = new TextTable.TextColumn(name, datatype.type, width, noTrim);
result.setSelector(selector);
result.setPosition(position);
return result;
@@ -2699,14 +2661,14 @@
}
)*
<RPAREN>
- [<AS>] aliasID=id()
+ [<AS>] aliasID=id(Boolean.FALSE)
{
ObjectTable result = new ObjectTable();
result.setScriptingLanguage(lang);
result.setRowScript(rowScript);
result.setPassing(passingValues);
result.setColumns(columns);
- result.setName(validateAlias(aliasID));
+ result.setName(aliasID);
return result;
}
}
@@ -2724,7 +2686,7 @@
Expression defaultExpr = null;
}
{
- name = id()
+ name = id(null)
datatype = parseDataType()
path = stringVal()
[
@@ -2784,14 +2746,14 @@
)*
]
<RPAREN>
- [<AS>] aliasID=id()
+ [<AS>] aliasID=id(Boolean.FALSE)
{
XMLTable result = new XMLTable();
result.setXquery(xquery);
result.setNamespaces(xmlNamespaces);
result.setPassing(passingValues);
result.setColumns(columns);
- result.setName(validateAlias(aliasID));
+ result.setName(aliasID);
return result;
}
}
@@ -2809,7 +2771,7 @@
Expression defaultExpr = null;
}
{
- name = id()
+ name = id(null)
((
<FOR> <ORDINALITY>
@@ -2871,10 +2833,10 @@
command = storedProcedure(info, 1) )
<RPAREN>
[<AS>]
- aliasID = id()
+ aliasID = id(Boolean.FALSE)
{
- SubqueryFromClause clause = new SubqueryFromClause(validateAlias(aliasID), command);
+ SubqueryFromClause clause = new SubqueryFromClause(aliasID, command);
setFromClauseOptions(lparen, clause);
clause.setTable(table);
return clause;
@@ -2895,10 +2857,10 @@
UnaryFromClause clause = null;
}
{
- (groupID=id() {groupToken = getToken(0);} [[<AS>] aliasID=id()])
+ (groupID=id(null) {groupToken = getToken(0);} [[<AS>] aliasID=id(Boolean.FALSE)])
{
if(aliasID != null) {
- group = new GroupSymbol(validateAlias(aliasID), groupID);
+ group = new GroupSymbol(aliasID, groupID);
} else {
group = new GroupSymbol(groupID);
}
@@ -3551,35 +3513,35 @@
<OPTION>
(
<MAKEDEP>
- id=id()
+ id=id(null)
{
option.addDependentGroup(id);
}
(<COMMA>
- id=id()
+ id=id(null)
{
option.addDependentGroup(id);
}
)* |
<MAKENOTDEP>
- id=id()
+ id=id(null)
{
option.addNotDependentGroup(id);
}
(<COMMA>
- id=id()
+ id=id(null)
{
option.addNotDependentGroup(id);
}
)* |
nocache = <NOCACHE>
- [id=id()
+ [id=id(null)
{
option.addNoCacheGroup(id);
}
(<COMMA>
- id=id()
+ id=id(null)
{
option.addNoCacheGroup(id);
}
@@ -3844,7 +3806,11 @@
OrderBy orderBy = null;
}
{
- <OVER>
+ <OVER> {
+ if (!(agg instanceof AggregateSymbol)) {
+ throw new ParseException(QueryPlugin.Util.getString("SQLParser.invalid_window", agg)); //$NON-NLS-1$
+ }
+ }
<LPAREN>
[<PARTITION> <BY> partitionList = expressionList(info)]
[orderBy = orderby(info)]
@@ -3852,9 +3818,6 @@
{
WindowFunction result = new WindowFunction();
WindowSpecification ws = new WindowSpecification();
- if (!(agg instanceof AggregateSymbol)) {
- throw new ParseException(QueryPlugin.Util.getString("SQLParser.invalid_window", agg)); //$NON-NLS-1$
- }
result.setFunction((AggregateSymbol)agg);
ws.setPartition(partitionList);
ws.setOrderBy(orderBy);
@@ -4122,7 +4085,7 @@
| ( funcToken = <XMLPI>
<LPAREN>
(
- [LOOKAHEAD(1) <NAME>] literal = id()
+ [LOOKAHEAD(1) <NAME>] literal = id(null)
)
{
args.add(new Constant(literal));
@@ -4148,7 +4111,7 @@
return expression;
}
|
- ( funcName = id()
+ ( funcName = id(null)
<LPAREN>
[<ALL> { distinct = false; } | <DISTINCT> {distinct = true;} ]
[ args = expressionList(info) ]
@@ -4241,7 +4204,7 @@
{
<XMLELEMENT> <LPAREN>
(
- [LOOKAHEAD(1) <NAME>] name = id()
+ [LOOKAHEAD(1) <NAME>] name = id(null)
)
[
LOOKAHEAD(2) <COMMA> xmlNamespaces = xmlNamespaces(info)
@@ -4362,7 +4325,7 @@
}
{
(
- uri = stringVal() <AS> prefix = id()
+ uri = stringVal() <AS> prefix = id(null)
{
return new XMLNamespaces.NamespaceItem(uri, prefix);
}
@@ -4602,9 +4565,9 @@
String prefix = null;
}
{
- <SET> <NAMESPACE> uri = stringVal() <AS> prefix = id()
+ <SET> <NAMESPACE> uri = stringVal() <AS> prefix = id(Boolean.FALSE)
{
- factory.addNamespace(validateAlias(prefix), uri);
+ factory.addNamespace(prefix, uri);
}
}
@@ -4627,12 +4590,12 @@
{
<CREATE> [<VIRTUAL> | <FOREIGN> {virtual = false;}] (<PROCEDURE> | <FUNCTION> {function = true;})
//the below is optional beacuse to allow the designer based metadata
- ( procName = id()
+ ( procName = id(null)
{
try {
proc = factory.addProcedure(procName);
} catch(TranslatorException e){
- throw new ParseException(e.getMessage());
+ throw new MetadataException(e);
}
}
@@ -4660,7 +4623,7 @@
proc.setFunction(function);
if (stmt != null){
if (function || !virtual) {
- throw new ParseException(QueryPlugin.Util.getString("SQLParser.function_def", procName));
+ throw new MetadataException(QueryPlugin.Util.getString("SQLParser.function_def", procName));
}
proc.setQueryPlan((comment != null?comment.image+" ":"") + stmt.toString());
}
@@ -4695,7 +4658,7 @@
|(<OUT> {ppType = ProcedureParameter.Type.Out;})
|(<INOUT> {ppType = ProcedureParameter.Type.InOut;})
|(<VARIADIC> {ppType = ProcedureParameter.Type.In ; vararg = true;}))]
- name = id()
+ name = id(Boolean.TRUE)
type = parseDataType()
[<NOT> <NULL> {notNull = true;}]
[<RESULT>
@@ -4708,7 +4671,7 @@
]
{
try {
- param = factory.addProcedureParameter(validateElementName(name), type.type, ppType, proc);
+ param = factory.addProcedureParameter(name, type.type, ppType, proc);
setTypeInfo(type, param);
if (notNull) {
param.setNullType(Column.NullType.No_Nulls);
@@ -4717,7 +4680,7 @@
param.setVarArg(vararg);
}
} catch (TranslatorException e){
- throw new ParseException(e.getMessage());
+ throw new MetadataException(e);
}
}
[<DEFAULT_KEYWORD> defaultValue = stringVal() {param.setDefaultValue(defaultValue);}]
@@ -4741,7 +4704,7 @@
BaseColumn column = null;
}
{
- name = id()
+ name = id(Boolean.TRUE)
type = parseDataType()
{
column = addProcColumn(factory, proc, name, type, true);
@@ -4771,13 +4734,13 @@
}
{
<CREATE> (<FOREIGN> <TABLE> | [<VIRTUAL>] <VIEW> {view = true;})
- tableName = id()
+ tableName = id(null)
{
try{
table = factory.addTable(tableName);
table.setVirtual(view);
} catch(TranslatorException e){
- throw new ParseException(e.getMessage());
+ throw new MetadataException(e);
}
}
[<LPAREN>
@@ -4785,7 +4748,7 @@
(LOOKAHEAD(3) <COMMA>
createColumn(factory, table)
)*
- (<COMMA>{name=null;} [<CONSTRAINT> name = id()] (constraint = primaryKey(factory, table, name) | constraint = constraint(factory, table, name, ParseInfo.DEFAULT_INSTANCE) | constraint = foreignKey(factory, table, name))
+ (<COMMA>{name=null;} [<CONSTRAINT> name = id(null)] (constraint = primaryKey(factory, table, name) | constraint = constraint(factory, table, name, ParseInfo.DEFAULT_INSTANCE) | constraint = foreignKey(factory, table, name))
[optionsClause(constraint, factory)
{
setCommonProperties(constraint, constraint.getProperties());
@@ -4802,7 +4765,7 @@
{
if (query != null){
if (!view) {
- throw new ParseException(QueryPlugin.Util.getString("SQLParser.view_def", tableName));
+ throw new MetadataException(QueryPlugin.Util.getString("SQLParser.view_def", tableName));
}
table.setSelectTransformation((comment != null?comment.image+" ":"") + query.toString());
}
@@ -4833,20 +4796,15 @@
}
{
<FOREIGN> <KEY>
- columnNames = getColumnNames()
- {
- for (String col: columnNames) {
- column = getColumn(col, table);
- }
- }
+ columnNames = columnList(true, false)
<REFERENCES>
- viewName = id()
- [pkColumnNames = getColumnNames()]
+ viewName = id(null)
+ [pkColumnNames = columnList(true, false)]
{
try{
return factory.addForiegnKey(name != null?name:("FK"+table.getForeignKeys().size()), columnNames, pkColumnNames, viewName, table);
} catch (TranslatorException e){
- throw new ParseException(e.getMessage());
+ throw new MetadataException(e);
}
}
}
@@ -4864,18 +4822,15 @@
}
{
<PRIMARY> <KEY>
- columnNames = getColumnNames()
+ columnNames = columnList(true, false)
{
- for (String col: columnNames) {
- column = getColumn(col, table);
- }
if (table.getPrimaryKey() != null){
- throw new ParseException(QueryPlugin.Util.getString("SQLParser.pk_exists", table.getName()));
+ throw new MetadataException(QueryPlugin.Util.getString("SQLParser.pk_exists", table.getName()));
}
try{
return factory.addPrimaryKey(name!=null?name:"PK", columnNames, table);
} catch(TranslatorException e){
- throw new ParseException(e.getMessage());
+ throw new MetadataException(e);
}
}
}
@@ -4896,11 +4851,8 @@
}
{
(( type = <UNIQUE> | type = <ACCESSPATTERN>)
- columnNames = getColumnNames()
+ columnNames = columnList(true, false)
{
- for (String col: columnNames) {
- column = getColumn(col, table);
- }
try{
if (type.image.equalsIgnoreCase("UNIQUE")) {
return factory.addIndex(name != null?name:("UNIQUE"+table.getUniqueKeys().size()), false, columnNames, table);
@@ -4908,7 +4860,7 @@
return factory.addAccessPattern(name != null?name:("AP"+table.getAccessPatterns().size()), columnNames, table);
}
}catch(TranslatorException e){
- throw new ParseException(e.getMessage());
+ throw new MetadataException(e);
}
}) | (
type = <INDEX>
@@ -4922,24 +4874,32 @@
}
/*
-name=column name list
+name=column list
description=A list of column names.
example={code:sql}(a, b){code}
*/
-ArrayList<String> getColumnNames() :
+List columnList(boolean validate, boolean asElementSymbols) :
{
- ArrayList list = new ArrayList<String>();
+ ArrayList list = new ArrayList();
String id = null;
}
{
<LPAREN>
- id = id()
+ id = id(validate?Boolean.TRUE:null)
{
- list.add(id);
+ if (asElementSymbols) {
+ list.add(new ElementSymbol(id));
+ } else {
+ list.add(id);
+ }
}
- (<COMMA> id = id()
+ (<COMMA> id = id(validate?Boolean.TRUE:null)
{
- list.add(id);
+ if (asElementSymbols) {
+ list.add(new ElementSymbol(id));
+ } else {
+ list.add(id);
+ }
}
)*
<RPAREN>
@@ -4968,17 +4928,17 @@
Token word = null;
}
{
- element = id()
+ element = id(Boolean.TRUE)
(
type = parseDataType()
{
try{
- column = factory.addColumn(validateElementName(element), type.type, table);
+ column = factory.addColumn(element, type.type, table);
column.setUpdatable(true);
setTypeInfo(type, column);
columnName.add(element);
}catch(TranslatorException e){
- throw new ParseException(e.getMessage());
+ throw new MetadataException(e);
}
}
)
@@ -5004,12 +4964,12 @@
factory.addIndex("UNIQUE"+table.getIndexes().size(), false, columnName, table);
} else if (pk) {
if (table.getPrimaryKey() != null) {
- throw new ParseException(QueryPlugin.Util.getString("SQLParser.pk_exists", table.getName()));
+ throw new MetadataException(QueryPlugin.Util.getString("SQLParser.pk_exists", table.getName()));
}
factory.addPrimaryKey("PK", columnName, table);
}
}catch(TranslatorException e){
- throw new ParseException(e.getMessage());
+ throw new MetadataException(e);
}
column.setAutoIncremented(autoIncrement);
@@ -5043,7 +5003,7 @@
String strVal = null;
}
{
- key = id()
+ key = id(null)
(value = nonNumericLiteral()
| [strVal = plusMinus()] value = unsignedNumericLiteral(strVal))
{
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2012-09-28 16:09:37 UTC (rev 4487)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2012-09-29 19:07:41 UTC (rev 4488)
@@ -64,7 +64,7 @@
# parser (005)
TEIID31100=Parsing error: {0}
QueryParser.nullSqlCrit=Parser cannot parse a null sql criteria.
-QueryParser.lexicalError=Lexical error: {0}
+QueryParser.lexicalError=Lexical error. Character is not a valid token: {0}
QueryParser.nullSqlExpr=Parser cannot parse a null sql expression.
TEIID30378=Direct usage of XQuery is no longer supported, use XMLQUERY instead.
@@ -245,7 +245,6 @@
ERR.015.009.0002= Error translating criteria on the user''s command, the criteria translated to {0} is not valid
TEIID30373=Error simplifying mathematical expression: {0}
-SQLParser.Unknown_join_type=Unknown join type: {0}
SQLParser.Aggregate_only_top_level=Aggregate functions are only allowed HAVING/SELECT/ORDER BY clauses. Window functions are only allowed in the SELECT/ORDER BY clauses: {0}. Both require a FROM clause to be present.
SQLParser.window_only_top_level=Window functions are not allowed in the HAVING clause: {0}
SQLParser.Unknown_agg_func=Unknown aggregate function: {0}
@@ -1032,6 +1031,7 @@
TEIID31120=An exception may only be chained to another exception. {0} is not valid.
TEIID31121=The expected result set of the procedure {0} does not match the result set from returnable statement {1} use WITHOUT RETURN to indicate the statement should not be returned - {2}
TEIID31122=Null exception reference.
+TEIID31123=Could not load non-FOREIGN UDF "{0}", since both invocation class and invocation method are required.
SQLParser.proc_type_conflict=Result type {1} conflicts with return type {2} for procedure {0}
SQLParser.param_out=Procedure {0} RESULT param {1} must be of type OUT.
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java 2012-09-28 16:09:37 UTC (rev 4487)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java 2012-09-29 19:07:41 UTC (rev 4488)
@@ -31,7 +31,6 @@
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.api.exception.query.QueryParserException;
import org.teiid.metadata.*;
-import org.teiid.metadata.ParseException;
import org.teiid.metadata.BaseColumn.NullType;
import org.teiid.query.metadata.MetadataValidator;
import org.teiid.query.metadata.SystemMetadata;
@@ -118,7 +117,7 @@
assertEquals("hello", e6.getDefaultValue());
}
- @Test(expected=ParseException.class)
+ @Test(expected=MetadataException.class)
public void testDuplicatePrimarykey() throws Exception {
String ddl = "CREATE FOREIGN TABLE G1( e1 integer primary key, e2 varchar primary key)";
MetadataStore mds = new MetadataStore();
@@ -216,7 +215,7 @@
assertEquals(table.getColumns().subList(1, 3), table.getAccessPatterns().get(1).getColumns());
}
- @Test(expected=ParseException.class)
+ @Test(expected=MetadataException.class)
public void testWrongPrimarykey() throws Exception {
String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, PRIMARY KEY (e3))";
@@ -341,7 +340,7 @@
assertEquals(fk.getPrimaryKey().getColumns(), s.getSchema("model").getTable("G1").getColumns());
}
- @Test(expected=ParseException.class)
+ @Test(expected=MetadataException.class)
public void testTableWithPlan() throws Exception {
String ddl = "CREATE foreign table G1 as select 1";
MetadataStore mds = new MetadataStore();
@@ -515,7 +514,7 @@
assertEquals("boolean", fm.getInputParameters().get(0).getType());
}
- @Test(expected=ParseException.class) public void testInvalidFunctionBody() throws Exception {
+ @Test(expected=MetadataException.class) public void testInvalidFunctionBody() throws Exception {
String ddl = "CREATE FUNCTION SourceFunc(flag boolean) RETURNS varchar AS SELECT 'a';";
Schema s = helpParse(ddl, "model").getSchema();
@@ -524,7 +523,7 @@
assertTrue( fm.getInputParameters().get(0).isVarArg());
}
- @Test(expected=ParseException.class) public void testInvalidProcedureBody() throws Exception {
+ @Test(expected=MetadataException.class) public void testInvalidProcedureBody() throws Exception {
String ddl = "CREATE FOREIGN PROCEDURE SourceFunc(flag boolean) RETURNS varchar AS SELECT 'a';";
Schema s = helpParse(ddl, "model").getSchema();
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2012-09-28 16:09:37 UTC (rev 4487)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2012-09-29 19:07:41 UTC (rev 4488)
@@ -2649,7 +2649,7 @@
}
@Test public void testLikeWithEscapeException(){
- helpException("SELECT a from db.g where b like '#String' escape '#1'", "TEIID31100 Parsing error: TEIID30398 LIKE/SIMILAR TO ESCAPE value must be a single character: [#1]."); //$NON-NLS-1$ //$NON-NLS-2$
+ helpException("SELECT a from db.g where b like '#String' escape '#1'", "TEIID31100 Parsing error: Encountered \"like '#String' escape [*]'#1'[*] <EOF>\" at line 1, column 50.\nTEIID30398 LIKE/SIMILAR TO ESCAPE value must be a single character: [#1]."); //$NON-NLS-1$ //$NON-NLS-2$
}
/** SELECT "date"."time" from db.g */
@@ -2696,7 +2696,7 @@
/** SELECT xx.yy%.a from xx.yy */
@Test public void testFailsWildcardInSelect(){
- helpException("SELECT xx.yy%.a from xx.yy"); //$NON-NLS-1$
+ helpException("SELECT xx.yy%.a from xx.yy", "TEIID31100 Parsing error: Encountered \"SELECT xx.yy [*]%[*] .\" at line 1, column 13.\nLexical error. Character is not a valid token: % "); //$NON-NLS-1$
}
/** SELECT a or b from g */
@@ -3236,7 +3236,7 @@
//using clause should use short names
@Test public void testDynamicCommandStatement3(){
- helpException("create virtual procedure begin execute string z as a1 string, a2 integer into #g using variables.x=variables.y; end", "TEIID31100 Parsing error: Invalid simple identifier format: [variables.x]"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpException("create virtual procedure begin execute string z as a1 string, a2 integer into #g using variables.x=variables.y; end", "TEIID31100 Parsing error: Encountered \"into #g using [*]variables.x[*] =\" at line 1, column 88.\nInvalid simple identifier format: [variables.x]"); //$NON-NLS-1$ //$NON-NLS-2$
}
//into clause requires as clause
@@ -4738,7 +4738,7 @@
try {
QueryParser.getQueryParser().parseCommand("SELECT FROM"); //$NON-NLS-1$
} catch(QueryParserException e) {
- assertTrue(e.getMessage().startsWith("TEIID31100 Parsing error: Encountered \"FROM\" at line 1, column 8.")); //$NON-NLS-1$
+ assertTrue(e.getMessage(), e.getMessage().startsWith("TEIID31100 Parsing error: Encountered \"SELECT [*]FROM[*]\" at line 1, column 8.")); //$NON-NLS-1$
}
}
@@ -4787,7 +4787,7 @@
}
@Test public void testCreateTempTable7() {
- helpException("Create local TEMPORARY table tempTable (c1.x boolean, c2 byte)" ,"TEIID31100 Parsing error: Invalid simple identifier format: [c1.x]"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpException("Create local TEMPORARY table tempTable (c1.x boolean, c2 byte)" ,"TEIID31100 Parsing error: Encountered \"table tempTable ( [*]c1.x[*] boolean\" at line 1, column 41.\nInvalid simple identifier format: [c1.x]"); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testCreateTempTableWithPrimaryKey() {
@@ -4833,7 +4833,7 @@
@Test public void testBadAlias() {
String sql = "select a as a.x from foo"; //$NON-NLS-1$
- helpException(sql, "TEIID31100 Parsing error: Invalid alias format: [a.x]"); //$NON-NLS-1$
+ helpException(sql, "TEIID31100 Parsing error: Encountered \"select a as [*]a.x[*] from\" at line 1, column 13.\nInvalid alias format: [a.x]"); //$NON-NLS-1$
}
@Test public void testNameSpacedFunctionName() {
12 years, 2 months
teiid SVN: r4487 - in trunk/connectors: translator-jpa/src/main/java/org/teiid/translator/jpa and 2 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2012-09-28 12:09:37 -0400 (Fri, 28 Sep 2012)
New Revision: 4487
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPA2ExecutionFactory.java
trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPExecutionFactory.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java
Log:
TEIID-2176: Turning off the native procedure by default; user can override the translator property in the vdb.xml to turn it on
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2012-09-28 15:59:09 UTC (rev 4486)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2012-09-28 16:09:37 UTC (rev 4487)
@@ -140,7 +140,6 @@
setSupportsInnerJoins(true);
setMaxInCriteriaSize(DEFAULT_MAX_IN_CRITERIA);
setMaxDependentInPredicates(DEFAULT_MAX_DEPENDENT_PREDICATES);
- setSupportsNativeQueries(true);
}
@Override
Modified: trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPA2ExecutionFactory.java
===================================================================
--- trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPA2ExecutionFactory.java 2012-09-28 15:59:09 UTC (rev 4486)
+++ trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPA2ExecutionFactory.java 2012-09-28 16:09:37 UTC (rev 4487)
@@ -52,10 +52,6 @@
public class JPA2ExecutionFactory extends ExecutionFactory<EntityManagerFactory, EntityManager> {
private Map<String, FunctionModifier> functionModifiers = new TreeMap<String, FunctionModifier>(String.CASE_INSENSITIVE_ORDER);
- public JPA2ExecutionFactory() {
- setSupportsNativeQueries(true);
- }
-
@Override
public void start() throws TranslatorException {
super.start();
Modified: trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPExecutionFactory.java
===================================================================
--- trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPExecutionFactory.java 2012-09-28 15:59:09 UTC (rev 4486)
+++ trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPExecutionFactory.java 2012-09-28 16:09:37 UTC (rev 4487)
@@ -63,7 +63,6 @@
public LDAPExecutionFactory() {
this.setMaxInCriteriaSize(1000);
this.setMaxDependentInPredicates(25); //no spec limit on query size, AD is 10MB for the query
- setSupportsNativeQueries(true);
}
@TranslatorProperty(display="Default Search Base DN", description="Default Base DN for LDAP Searches")
Modified: trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java
===================================================================
--- trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java 2012-09-28 15:59:09 UTC (rev 4486)
+++ trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java 2012-09-28 16:09:37 UTC (rev 4487)
@@ -70,7 +70,6 @@
setSupportsOrderBy(false);
setSupportsOuterJoins(true);
setSupportedJoinCriteria(SupportedJoinCriteria.KEY);
- setSupportsNativeQueries(true);
}
@TranslatorProperty(display="Audit Model Fields", advanced=true)
12 years, 2 months
teiid SVN: r4486 - in trunk/connectors/translator-object/src/main/java/org/teiid/translator/object: mapcache and 1 other directory.
by teiid-commits@lists.jboss.org
Author: van.halbert
Date: 2012-09-28 11:59:09 -0400 (Fri, 28 Sep 2012)
New Revision: 4486
Modified:
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanBaseExecutionFactory.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheExecutionFactory.java
Log:
TEIID-2210 - sorry about that, a new class was accidentally left in but not checked in, so removed any reference for now
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanBaseExecutionFactory.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanBaseExecutionFactory.java 2012-09-28 12:43:11 UTC (rev 4485)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanBaseExecutionFactory.java 2012-09-28 15:59:09 UTC (rev 4486)
@@ -32,7 +32,6 @@
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.TranslatorProperty;
-import org.teiid.translator.object.JavaBeanMetadataProcessor;
import org.teiid.translator.object.ObjectConnection;
import org.teiid.translator.object.ObjectExecutionFactory;
import org.teiid.translator.object.ObjectPlugin;
@@ -170,12 +169,7 @@
@Override
public void getMetadata(MetadataFactory metadataFactory, ObjectConnection conn)
throws TranslatorException {
- if (this.isFullTextSearchingSupported()) {
-
- } else {
- JavaBeanMetadataProcessor processor = new JavaBeanMetadataProcessor();
- processor.getMetadata(metadataFactory, this);
- }
+
}
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheExecutionFactory.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheExecutionFactory.java 2012-09-28 12:43:11 UTC (rev 4485)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheExecutionFactory.java 2012-09-28 15:59:09 UTC (rev 4486)
@@ -31,7 +31,6 @@
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.Translator;
import org.teiid.translator.TranslatorException;
-import org.teiid.translator.object.JavaBeanMetadataProcessor;
import org.teiid.translator.object.ObjectConnection;
import org.teiid.translator.object.ObjectExecutionFactory;
import org.teiid.translator.object.ObjectPlugin;
@@ -101,7 +100,6 @@
@Override
public void getMetadata(MetadataFactory metadataFactory, ObjectConnection conn)
throws TranslatorException {
- JavaBeanMetadataProcessor processor = new JavaBeanMetadataProcessor();
- processor.getMetadata(metadataFactory, this);
+
}
}
12 years, 2 months
teiid SVN: r4485 - in trunk/connectors/translator-object: .settings and 11 other directories.
by teiid-commits@lists.jboss.org
Author: van.halbert
Date: 2012-09-28 08:43:11 -0400 (Fri, 28 Sep 2012)
New Revision: 4485
Removed:
trunk/connectors/translator-object/.settings/org.eclipse.jdt.core.prefs
trunk/connectors/translator-object/.settings/org.maven.ide.eclipse.prefs
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/util/ObjectUtil.java
Modified:
trunk/connectors/translator-object/
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecutionFactory.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectPlugin.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanBaseExecutionFactory.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanConnectionImpl.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanExecutionFactory.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanRemoteExecutionFactory.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/LuceneSearch.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/SearchByKey.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheExecutionFactory.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/BasicKeySearchCriteria.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/SearchCriterion.java
trunk/connectors/translator-object/src/main/resources/org/teiid/translator/object/i18n.properties
trunk/connectors/translator-object/src/test/example_vdbs/infinispancache-vdb.xml
trunk/connectors/translator-object/src/test/example_vdbs/infinispanremotecache-vdb.xml
trunk/connectors/translator-object/src/test/example_vdbs/mapcache-vdb.xml
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiILuceneSearch.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiKeySearch.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/mapcache/TestMapCacheKeySearch.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/search/TestBasicKeySearchCriteria.java
Log:
TEIID-2210 - general generic/cast/nls cleanup, increasing MAX_SET_SIZE to 10000, and corrrections to BasicKeySearchCriteria based on assumption that only a PK can be used to query the cache
Property changes on: trunk/connectors/translator-object
___________________________________________________________________
Modified: svn:ignore
- target
+ .settings
Deleted: trunk/connectors/translator-object/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- trunk/connectors/translator-object/.settings/org.eclipse.jdt.core.prefs 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/.settings/org.eclipse.jdt.core.prefs 2012-09-28 12:43:11 UTC (rev 4485)
@@ -1,6 +0,0 @@
-#Wed Jan 25 12:40:49 CST 2012
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.compliance=1.6
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.6
Deleted: trunk/connectors/translator-object/.settings/org.maven.ide.eclipse.prefs
===================================================================
--- trunk/connectors/translator-object/.settings/org.maven.ide.eclipse.prefs 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/.settings/org.maven.ide.eclipse.prefs 2012-09-28 12:43:11 UTC (rev 4485)
@@ -1,6 +0,0 @@
-#Wed Jan 25 12:40:49 CST 2012
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.compliance=1.6
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.6
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java 2012-09-28 12:43:11 UTC (rev 4485)
@@ -81,7 +81,7 @@
LogConstants.CTX_CONNECTOR,
"ObjectExecution calling search strategy : " + connection.getClass().getName()); //$NON-NLS-1$
- return connection.performSearch((Select) query);
+ return connection.performSearch(query);
}
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecutionFactory.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecutionFactory.java 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecutionFactory.java 2012-09-28 12:43:11 UTC (rev 4485)
@@ -22,8 +22,6 @@
package org.teiid.translator.object;
-import java.util.Collections;
-import java.util.List;
import java.util.Map;
import javax.naming.Context;
@@ -51,7 +49,7 @@
public abstract class ObjectExecutionFactory extends
ExecutionFactory<ConnectionFactory, ObjectConnection> {
- public static final int MAX_SET_SIZE = 1000;
+ public static final int MAX_SET_SIZE = 10000;
// rootClassName identifies the name of the class that is identified by the
// unique key in the cache
@@ -81,9 +79,9 @@
if (this.getRootClassName() == null
|| this.getRootClassName().trim().length() == -1) {
String msg = ObjectPlugin.Util.getString(
- "ObjectExecutionFactory.rootClassNameNotDefined",
+ "ObjectExecutionFactory.rootClassNameNotDefined", //$NON-NLS-1$
new Object[] {});
- throw new TranslatorException(msg); //$NON-NLS-1$
+ throw new TranslatorException(msg);
}
try {
@@ -92,9 +90,9 @@
} catch (ClassNotFoundException e) {
String msg = ObjectPlugin.Util.getString(
- "ObjectExecutionFactory.rootClassNotFound",
+ "ObjectExecutionFactory.rootClassNotFound", //$NON-NLS-1$
new Object[] { this.rootClassName });
- throw new TranslatorException(msg); //$NON-NLS-1$
+ throw new TranslatorException(msg);
}
}
@@ -109,12 +107,6 @@
}
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public List getSupportedFunctions() {
- return Collections.EMPTY_LIST;
- }
-
@Override
public boolean supportsInnerJoins() {
return false;
@@ -143,10 +135,6 @@
return true;
}
- public boolean supportsOrCriteria() {
- return true;
- }
-
@Override
public boolean supportsLikeCriteria() {
// at this point, i've been unable to get the Like to work.
@@ -189,11 +177,8 @@
*
* @param rootClassName
*/
- public synchronized void setRootClassName(String rootClassName) {
- if (this.rootClassName == null) {
- this.rootClassName = rootClassName;
-
- }
+ public void setRootClassName(String rootClassName) {
+ this.rootClassName = rootClassName;
}
/**
@@ -213,9 +198,7 @@
* @param jndiName the JNDI name of the {@link Map cache} instance that should be used
* @see #setCacheJndiName(String)
*/
- public synchronized void setCacheJndiName( String jndiName ) {
- if (this.cacheJndiName == jndiName || this.cacheJndiName != null
- && this.cacheJndiName.equals(jndiName)) return; // unchanged
+ public void setCacheJndiName( String jndiName ) {
this.cacheJndiName = jndiName;
}
@@ -241,28 +224,31 @@
if (jndiName != null && jndiName.trim().length() != 0) {
try {
Context context = null;
- if (context == null) {
- try {
- context = new InitialContext();
- } catch (NamingException err) {
- throw new TranslatorException(err);
- }
- }
+ try {
+ context = new InitialContext();
+ } catch (NamingException err) {
+ throw new TranslatorException(err);
+ }
cache = context.lookup(jndiName);
if (cache == null) {
String msg = ObjectPlugin.Util.getString(
- "ObjectExecutionFactory.cacheNotFoundinJNDI",
+ "ObjectExecutionFactory.cacheNotFoundinJNDI", //$NON-NLS-1$
new Object[] { jndiName });
- throw new TranslatorException(msg); //$NON-NLS-1$
+ throw new TranslatorException(msg);
}
- } catch (Throwable err) {
+ } catch (Exception err) {
if (err instanceof RuntimeException) throw (RuntimeException)err;
throw new TranslatorException(err);
}
}
return cache;
}
+
+ @Override
+ public boolean supportsOnlyLiteralComparison() {
+ return true;
+ }
}
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectPlugin.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectPlugin.java 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectPlugin.java 2012-09-28 12:43:11 UTC (rev 4485)
@@ -39,9 +39,5 @@
public static final BundleUtil Util = new BundleUtil(PLUGIN_ID, PLUGIN_ID + ".i18n", ResourceBundle.getBundle(PLUGIN_ID + ".i18n")); //$NON-NLS-1$ //$NON-NLS-2$
public static enum Event implements BundleUtil.Event {
- TEIID12001, // unsupported capability
- TEIID12005,
- TEIID12006,
- TEIID12007,
}
}
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanBaseExecutionFactory.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanBaseExecutionFactory.java 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanBaseExecutionFactory.java 2012-09-28 12:43:11 UTC (rev 4485)
@@ -21,10 +21,6 @@
*/
package org.teiid.translator.object.infinispan;
-import java.io.File;
-import java.io.IOException;
-import java.util.Properties;
-
import javax.resource.cci.ConnectionFactory;
import org.infinispan.Cache;
@@ -32,9 +28,11 @@
import org.infinispan.api.BasicCacheContainer;
import org.infinispan.manager.CacheContainer;
import org.infinispan.manager.DefaultCacheManager;
+import org.teiid.metadata.MetadataFactory;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.TranslatorProperty;
+import org.teiid.translator.object.JavaBeanMetadataProcessor;
import org.teiid.translator.object.ObjectConnection;
import org.teiid.translator.object.ObjectExecutionFactory;
import org.teiid.translator.object.ObjectPlugin;
@@ -45,8 +43,6 @@
*
*/
public abstract class InfinispanBaseExecutionFactory extends ObjectExecutionFactory {
- public static final String PROPERTIES_FILE = "META-INF" + File.separator
- + "datagrid.properties";
private String cacheName = null;
private String configurationFileName = null;
@@ -60,10 +56,8 @@
super.start();
if (this.getCacheName() == null || this.getCacheName().isEmpty()) {
- String msg = ObjectPlugin.Util.getString(
- "InfinispanBaseExecutionFactory.cacheNameNotDefined",
- new Object[] {});
- throw new TranslatorException(msg); //$NON-NLS-1$
+ String msg = ObjectPlugin.Util.getString("InfinispanBaseExecutionFactory.cacheNameNotDefined"); //$NON-NLS-1$
+ throw new TranslatorException(msg);
}
}
@@ -164,15 +158,26 @@
if (cache == null) {
String msg = ObjectPlugin.Util.getString(
- "InfinispanBaseExecutionFactory.cacheNotFound", new Object[] { (getCacheName() != null ? getCacheName()
- : "DefaultCache") });
- throw new TranslatorException(msg); //$NON-NLS-1$
+ "InfinispanBaseExecutionFactory.cacheNotFound", new Object[] { (getCacheName() != null ? getCacheName() //$NON-NLS-1$
+ : "DefaultCache") }); //$NON-NLS-1$
+ throw new TranslatorException(msg);
}
return cache;
}
+ @Override
+ public void getMetadata(MetadataFactory metadataFactory, ObjectConnection conn)
+ throws TranslatorException {
+ if (this.isFullTextSearchingSupported()) {
+
+ } else {
+ JavaBeanMetadataProcessor processor = new JavaBeanMetadataProcessor();
+ processor.getMetadata(metadataFactory, this);
+ }
+ }
+
@Override
public ObjectConnection getConnection(ConnectionFactory factory,
@@ -181,18 +186,12 @@
return new InfinispanConnectionImpl(this);
}
- protected String jdgProperty(String name) {
- Properties props = new Properties();
- try {
- props.load(this.getClass().getClassLoader()
- .getResourceAsStream(PROPERTIES_FILE));
- } catch (IOException ioe) {
- throw new RuntimeException(ioe);
- }
- return props.getProperty(name);
- }
-
public void cleanUp() {
}
+
+ @Override
+ public boolean supportsOrCriteria() {
+ return isFullTextSearchingSupported();
+ }
}
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanConnectionImpl.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanConnectionImpl.java 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanConnectionImpl.java 2012-09-28 12:43:11 UTC (rev 4485)
@@ -91,10 +91,8 @@
throws TranslatorException {
if (factory.isFullTextSearchingSupported()) {
return LuceneSearch.performSearch(command, this);
- } else {
- return SearchByKey.performSearch(command, this);
}
-
+ return SearchByKey.performSearch(command, this);
}
public BasicCache<String, Object> getCache()
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanExecutionFactory.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanExecutionFactory.java 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanExecutionFactory.java 2012-09-28 12:43:11 UTC (rev 4485)
@@ -21,9 +21,7 @@
*/
package org.teiid.translator.object.infinispan;
-import java.io.File;
import java.io.IOException;
-import java.util.Properties;
import org.infinispan.api.BasicCacheContainer;
import org.infinispan.manager.DefaultCacheManager;
@@ -56,9 +54,6 @@
*/
@Translator(name = "infinispan-cache", description = "The Infinispan Cache Translator")
public class InfinispanExecutionFactory extends InfinispanBaseExecutionFactory {
- public static final String PROPERTIES_FILE = "META-INF" + File.separator
- + "datagrid.properties";
-
private boolean supportsLuceneSearching = false;
protected BasicCacheContainer cacheContainer = null;
@@ -78,8 +73,8 @@
if (configFile == null || configFile.trim().length() == 0) {
String msg = ObjectPlugin.Util
.getString(
- "InfinispanExecutionFactory.undefinedHowToGetCache");
- throw new TranslatorException(msg); //$NON-NLS-1$
+ "InfinispanExecutionFactory.undefinedHowToGetCache"); //$NON-NLS-1$
+ throw new TranslatorException(msg);
}
useJndi = false;
@@ -147,10 +142,10 @@
return (BasicCacheContainer) object;
}
String msg = ObjectPlugin.Util.getString(
- "InfinispanExecutionFactory.unsupportedContainerType",
+ "InfinispanExecutionFactory.unsupportedContainerType", //$NON-NLS-1$
new Object[] { object.getClass().getName(),
- "BasicCacheContainer" });
- throw new TranslatorException(msg); //$NON-NLS-1$
+ "BasicCacheContainer" }); //$NON-NLS-1$
+ throw new TranslatorException(msg);
}
@@ -167,17 +162,6 @@
return container;
}
- protected String jdgProperty(String name) {
- Properties props = new Properties();
- try {
- props.load(this.getClass().getClassLoader()
- .getResourceAsStream(PROPERTIES_FILE));
- } catch (IOException ioe) {
- throw new RuntimeException(ioe);
- }
- return props.getProperty(name);
- }
-
public void cleanUp() {
this.cacheContainer = null;
}
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanRemoteExecutionFactory.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanRemoteExecutionFactory.java 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanRemoteExecutionFactory.java 2012-09-28 12:43:11 UTC (rev 4485)
@@ -115,7 +115,7 @@
} else {
if (this.getRemoteServerList() == null
|| this.getRemoteServerList().isEmpty()
- || this.getRemoteServerList().equals("")) {
+ || this.getRemoteServerList().equals("")) { //$NON-NLS-1$
container = new RemoteCacheManager();
LogManager
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/LuceneSearch.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/LuceneSearch.java 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/LuceneSearch.java 2012-09-28 12:43:11 UTC (rev 4485)
@@ -31,16 +31,7 @@
import org.infinispan.query.CacheQuery;
import org.infinispan.query.Search;
import org.infinispan.query.SearchManager;
-import org.teiid.language.AndOr;
-import org.teiid.language.ColumnReference;
-import org.teiid.language.Comparison;
-import org.teiid.language.Condition;
-import org.teiid.language.Exists;
-import org.teiid.language.Expression;
-import org.teiid.language.In;
-import org.teiid.language.Like;
-import org.teiid.language.Literal;
-import org.teiid.language.Select;
+import org.teiid.language.*;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.metadata.Column;
@@ -64,7 +55,7 @@
throws TranslatorException {
SearchManager searchManager = Search
- .getSearchManager((Cache) connection.getCache() );
+ .getSearchManager((Cache<?, ?>) connection.getCache() );
QueryBuilder queryBuilder = searchManager.buildQueryBuilderForClass(
connection.getFactory().getRootClass()).get();
@@ -145,7 +136,7 @@
default:
final String msg = ObjectPlugin.Util
- .getString("LuceneSearch.invalidOperator", new Object[] { op, "And, Or" }); //$NON-NLS-1$
+ .getString("LuceneSearch.invalidOperator", new Object[] { op, "And, Or" }); //$NON-NLS-1$ //$NON-NLS-2$
throw new TranslatorException(msg);
}
@@ -179,10 +170,10 @@
LogManager.logTrace(LogConstants.CTX_CONNECTOR,
"Parsing Comparison criteria."); //$NON-NLS-1$
- Comparison.Operator op = ((Comparison) obj).getOperator();
+ Comparison.Operator op = obj.getOperator();
- Expression lhs = ((Comparison) obj).getLeftExpression();
- Expression rhs = ((Comparison) obj).getRightExpression();
+ Expression lhs = obj.getLeftExpression();
+ Expression rhs = obj.getRightExpression();
// joins between the objects in the same cache is not usable
if ((lhs instanceof ColumnReference && rhs instanceof ColumnReference)
@@ -231,7 +222,7 @@
default:
final String msg = ObjectPlugin.Util
- .getString("LuceneSearch.invalidOperator", new Object[] { op, "NE, EQ, GT, LT" }); //$NON-NLS-1$
+ .getString("LuceneSearch.invalidOperator", new Object[] { op, "NE, EQ, GT, LT" }); //$NON-NLS-1$ //$NON-NLS-2$
throw new TranslatorException(msg);
}
return true;
@@ -241,11 +232,11 @@
public static boolean visit(In obj, BooleanJunction<BooleanJunction> junction, QueryBuilder queryBuilder) throws TranslatorException {
LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing IN criteria."); //$NON-NLS-1$
- Expression lhs = ((In) obj).getLeftExpression();
+ Expression lhs = obj.getLeftExpression();
Column mdIDElement = ((ColumnReference) lhs).getMetadataObject();
- List<Expression> rhsList = ((In) obj).getRightExpressions();
+ List<Expression> rhsList = obj.getRightExpressions();
boolean createdQuery = false;
for (Expression expr : rhsList) {
@@ -259,8 +250,8 @@
createdQuery = true;
} else {
String msg = ObjectPlugin.Util.getString(
- "LuceneSearch.Unsupported_expression",
- new Object[] { expr, "IN" });
+ "LuceneSearch.Unsupported_expression", //$NON-NLS-1$
+ new Object[] { expr, "IN" }); //$NON-NLS-1$
throw new TranslatorException(msg);
}
}
@@ -271,8 +262,8 @@
LogManager.logTrace(LogConstants.CTX_CONNECTOR,
"Parsing LIKE criteria."); //$NON-NLS-1$
- Expression lhs = ((Like) obj).getLeftExpression();
- Expression rhs = ((Like) obj).getRightExpression();
+ Expression lhs = obj.getLeftExpression();
+ Expression rhs = obj.getRightExpression();
Column c = null;
Expression literalExp = null;
@@ -289,11 +280,11 @@
value = (String) escapeReservedChars(((Literal) literalExp)
.getValue());
- createLikeQuery(c, value.replaceAll("%", ""), junction, queryBuilder); // "*"
+ createLikeQuery(c, value.replaceAll("%", ""), junction, queryBuilder); // "*" //$NON-NLS-1$ //$NON-NLS-2$
} else {
final String msg = ObjectPlugin.Util.getString(
- "LuceneSearch.Unsupported_expression",
- new Object[] { literalExp.toString(), "LIKE" });
+ "LuceneSearch.Unsupported_expression", //$NON-NLS-1$
+ new Object[] { literalExp.toString(), "LIKE" }); //$NON-NLS-1$
throw new TranslatorException(msg);
}
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/SearchByKey.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/SearchByKey.java 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/SearchByKey.java 2012-09-28 12:43:11 UTC (rev 4485)
@@ -56,30 +56,22 @@
}
private static List<Object> get(SearchCriterion criterion,
- BasicCache<String, Object> cache, Class rootClass)
+ BasicCache<String, Object> cache, Class<?> rootClass)
throws TranslatorException {
List<Object> results = null;
if (criterion.getOperator() == SearchCriterion.Operator.ALL) {
-
- if (cache instanceof RemoteCache) {
+ Map<String, Object> map = cache;
+ if (cache instanceof RemoteCache<?, ?>) {
RemoteCache<?, ?> rc = (RemoteCache<?, ?>) cache;
- Map<?, ?> c = rc.getBulk();
- results = new ArrayList<Object>();
- for (Iterator it = c.keySet().iterator(); it.hasNext();) {
- Object v = cache.get(it.next());
- addValue(v, results, rootClass);
- }
-
- } else {
- Set keys = cache.keySet();
- results = new ArrayList<Object>();
- for (Iterator it = keys.iterator(); it.hasNext();) {
- Object v = cache.get(it.next());
- addValue(v, results, rootClass);
- }
+ map = (Map<String, Object>) rc.getBulk();
}
-
+ Set<String> keys = map.keySet();
+ results = new ArrayList<Object>();
+ for (Iterator<?> it = keys.iterator(); it.hasNext();) {
+ Object v = cache.get(it.next());
+ addValue(v, results, rootClass);
+ }
return results;
}
@@ -91,7 +83,6 @@
results = new ArrayList<Object>();
}
-
if (criterion.getOperator().equals(SearchCriterion.Operator.EQUALS)) {
Object value = criterion.getValue();
@@ -120,7 +111,7 @@
}
- private static void addValue(Object value, List<Object> results, Class rootNodeType) {
+ private static void addValue(Object value, List<Object> results, Class<?> rootNodeType) {
if (value != null && value.getClass().equals(rootNodeType)) {
if (value.getClass().isArray()) {
@@ -129,13 +120,13 @@
return;
}
- if (value instanceof Collection) {
- results.addAll((Collection) value);
+ if (value instanceof Collection<?>) {
+ results.addAll((Collection<?>) value);
return;
}
- if (value instanceof Map) {
- Map<?, Object> mapRows = (Map) value;
+ if (value instanceof Map<?, ?>) {
+ Map<?, ?> mapRows = (Map<?, ?>) value;
results.addAll(mapRows.values());
return;
}
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheExecutionFactory.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheExecutionFactory.java 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheExecutionFactory.java 2012-09-28 12:43:11 UTC (rev 4485)
@@ -27,9 +27,11 @@
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
+import org.teiid.metadata.MetadataFactory;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.Translator;
import org.teiid.translator.TranslatorException;
+import org.teiid.translator.object.JavaBeanMetadataProcessor;
import org.teiid.translator.object.ObjectConnection;
import org.teiid.translator.object.ObjectExecutionFactory;
import org.teiid.translator.object.ObjectPlugin;
@@ -58,26 +60,19 @@
if (jndiName == null || jndiName.trim().length() == 0) {
String msg = ObjectPlugin.Util
.getString(
- "MapCacheExecutionFactory.undefinedJndiName", new Object[] { });
- throw new TranslatorException(msg); //$NON-NLS-1$
+ "MapCacheExecutionFactory.undefinedJndiName"); //$NON-NLS-1$
+ throw new TranslatorException(msg);
}
}
- @Override
- public boolean supportsOnlyLiteralComparison() {
- return true;
- }
-
-
protected synchronized Map<?,?> getCache() throws TranslatorException {
if (this.cache != null) return this.cache;
Object object = findCacheUsingJNDIName();
- Map<?,?> cache = null;
- if (object instanceof Map) {
+ if (object instanceof Map<?,?>) {
cache = (Map<?,?>)object;
@@ -85,14 +80,12 @@
} else {
String msg = ObjectPlugin.Util.getString(
- "MapCacheExecutionFactory.unexpectedCacheType",
- new Object[] { (object == null ? "nullObject" : object.getClass().getName()), "Map" });
- throw new TranslatorException(msg); //$NON-NLS-1$
+ "MapCacheExecutionFactory.unexpectedCacheType", //$NON-NLS-1$
+ new Object[] { (object == null ? "nullObject" : object.getClass().getName()), "Map" }); //$NON-NLS-1$ //$NON-NLS-2$
+ throw new TranslatorException(msg);
}
- this.cache = cache;
return this.cache;
-
}
@@ -104,4 +97,11 @@
return new MapCacheConnection(this);
}
+
+ @Override
+ public void getMetadata(MetadataFactory metadataFactory, ObjectConnection conn)
+ throws TranslatorException {
+ JavaBeanMetadataProcessor processor = new JavaBeanMetadataProcessor();
+ processor.getMetadata(metadataFactory, this);
+ }
}
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/BasicKeySearchCriteria.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/BasicKeySearchCriteria.java 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/BasicKeySearchCriteria.java 2012-09-28 12:43:11 UTC (rev 4485)
@@ -24,25 +24,19 @@
import java.util.ArrayList;
import java.util.List;
-import org.teiid.language.AggregateFunction;
import org.teiid.language.ColumnReference;
import org.teiid.language.Command;
import org.teiid.language.Comparison;
-import org.teiid.language.Comparison.Operator;
import org.teiid.language.Expression;
-import org.teiid.language.Function;
import org.teiid.language.In;
import org.teiid.language.Literal;
-import org.teiid.language.ScalarSubquery;
-import org.teiid.language.SearchedCase;
import org.teiid.language.Select;
+import org.teiid.language.Comparison.Operator;
import org.teiid.language.visitor.HierarchyVisitor;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.metadata.Column;
-import org.teiid.translator.TranslatorException;
import org.teiid.translator.object.ObjectExecutionFactory;
-import org.teiid.translator.object.ObjectPlugin;
/**
* The BasicKeySearchCriteria parses the {@link Command select} and creates
@@ -58,17 +52,14 @@
// search criteria based on the WHERE clause
private SearchCriterion criterion;
- private List<String> exceptionMessages = new ArrayList<String>(2);
-
private BasicKeySearchCriteria(ObjectExecutionFactory factory) {
}
public static BasicKeySearchCriteria getInstance(
ObjectExecutionFactory factory,
- Select command) throws TranslatorException {
+ Select command) {
BasicKeySearchCriteria visitor = new BasicKeySearchCriteria(factory);
visitor.visitNode(command);
- visitor.throwExceptionIfFound();
return visitor;
}
@@ -80,11 +71,8 @@
* @return
*/
public SearchCriterion getCriterion() {
- if (this.criterion != null) {
-
- } else {
+ if (this.criterion == null) {
this.criterion = new SearchCriterion();
-
}
return this.criterion;
@@ -92,123 +80,58 @@
@Override
public void visit(Comparison obj) {
-
+ if (!(obj.getRightExpression() instanceof Literal)) {
+ //the translator does not support joins, but the unit tests assume that it does
+ return;
+ }
LogManager.logTrace(LogConstants.CTX_CONNECTOR,
"Parsing Comparison criteria."); //$NON-NLS-1$
- Comparison.Operator op = ((Comparison) obj).getOperator();
+ Comparison.Operator op = obj.getOperator();
- Expression lhs = ((Comparison) obj).getLeftExpression();
- Expression rhs = ((Comparison) obj).getRightExpression();
+ Expression lhs = obj.getLeftExpression();
+ Expression rhs = obj.getRightExpression();
- // comparison between the ojbects is not usable, because the
- // nameInSource and its parent(s)
- // will be how the child objects are obtained
- if ((lhs instanceof ColumnReference && rhs instanceof ColumnReference)
- || (lhs instanceof Literal && rhs instanceof Literal)) {
- return;
- }
+ Literal literal = (Literal)rhs;
+ Column mdIDElement = ((ColumnReference) lhs).getMetadataObject();
- Object value = null;
- Column mdIDElement = null;
- Literal literal = null;
- if (lhs instanceof ColumnReference && isValidExpression(rhs)) {
- mdIDElement = ((ColumnReference) lhs).getMetadataObject();
- literal = (Literal) rhs;
- value = literal.getValue();
-
- } else if (rhs instanceof ColumnReference && isValidExpression(lhs)) {
- mdIDElement = ((ColumnReference) rhs).getMetadataObject();
- literal = (Literal) lhs;
- value = literal.getValue();
-
- }
-
- if (mdIDElement == null || value == null) {
- String msg = ObjectPlugin.Util
- .getString(
- "BasicKeySearchCriteria.missingComparisonExpression", new Object[] { });
- addException(msg);
- return;
- }
-
addCompareCriteria(mdIDElement,
- escapeReservedChars(literal.getValue()), op);
+ literal.getValue(), op);
}
public void visit(In obj) {
LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing IN criteria."); //$NON-NLS-1$
- Expression lhs = ((In) obj).getLeftExpression();
- isValidExpression(lhs);
+ Expression lhs = obj.getLeftExpression();
Column mdIDElement = ((ColumnReference) lhs).getMetadataObject();
- List<Expression> rhsList = ((In) obj).getRightExpressions();
+ List<Expression> rhsList = obj.getRightExpressions();
- Class<?> type = lhs.getType();
List<Object> parms = new ArrayList<Object>(rhsList.size());
for (Expression expr : rhsList) {
+ Literal literal = (Literal) expr;
- if (expr instanceof Literal) {
- Literal literal = (Literal) expr;
-
- parms.add(escapeReservedChars(literal.getValue()));
-
- type = literal.getType();
-
- } else {
- String msg = ObjectPlugin.Util
- .getString(
- "BasicKeySearchCriteria.Unsupported_expression", new Object[] {expr });
- addException(msg);
- return;
- }
-
+ parms.add(literal.getValue());
}
- addInCriteria(mdIDElement, parms, type);
+ addInCriteria(mdIDElement, parms);
}
private void addCompareCriteria(Column column, Object value, Operator op) {
- SearchCriterion sc = new SearchCriterion(column, value, op.toString(),
- SearchCriterion.Operator.EQUALS, column.getRuntimeType());
+ SearchCriterion sc = new SearchCriterion(column, value, SearchCriterion.Operator.EQUALS,
+ column.getRuntimeType());
addSearchCriterion(sc);
}
- private void addInCriteria(Column column, List<Object> parms, Class<?> type) {
- SearchCriterion sc = new SearchCriterion(column, parms, "in",
- SearchCriterion.Operator.IN, column.getRuntimeType());
+ private void addInCriteria(Column column, List<Object> parms) {
+ SearchCriterion sc = new SearchCriterion(column, parms, SearchCriterion.Operator.IN,
+ column.getRuntimeType());
addSearchCriterion(sc);
-
}
- private boolean isValidExpression(Expression e) {
- if (e instanceof ColumnReference) {
- return true;
- } else if (e instanceof Literal) {
- return true;
-
- } else {
- String msg = null;
- if (e instanceof AggregateFunction) {
- msg = ObjectPlugin.Util.gs(ObjectPlugin.Event.TEIID12001);
- } else if (e instanceof Function) {
- msg = ObjectPlugin.Util.gs(ObjectPlugin.Event.TEIID12005);
- } else if (e instanceof ScalarSubquery) {
- msg = ObjectPlugin.Util.gs(ObjectPlugin.Event.TEIID12006);
- } else if (e instanceof SearchedCase) {
- msg = ObjectPlugin.Util.gs(ObjectPlugin.Event.TEIID12007);
- }
- LogManager.logError(LogConstants.CTX_CONNECTOR, msg + e.toString());
- addException(msg + e.toString());
- }
- return false;
-
- }
-
private void addSearchCriterion(SearchCriterion searchCriteria) {
// only searching on primary key is part of the criteria sent for cache
// lookup
@@ -218,51 +141,10 @@
assert (searchCriteria.getField() != null);
if (this.criterion != null) {
- searchCriteria.addOrCriterion(this.criterion);
+ throw new AssertionError("There should not be more than one predicate against the primary key"); //$NON-NLS-1$
}
this.criterion = searchCriteria;
}
- protected static Object escapeReservedChars(final Object value) {
- if (value instanceof String) {
- String expr = (String) value;
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < expr.length(); i++) {
- char curChar = expr.charAt(i);
- switch (curChar) {
- case '\\':
- sb.append("\\5c"); //$NON-NLS-1$
- break;
- case '*':
- sb.append("\\2a"); //$NON-NLS-1$
- break;
- case '(':
- sb.append("\\28"); //$NON-NLS-1$
- break;
- case ')':
- sb.append("\\29"); //$NON-NLS-1$
- break;
- case '\u0000':
- sb.append("\\00"); //$NON-NLS-1$
- break;
- default:
- sb.append(curChar);
- }
- }
- return sb.toString();
- }
- return value;
- }
-
- private void addException(String msg) {
- exceptionMessages.add(msg);
- }
-
- protected void throwExceptionIfFound() throws TranslatorException {
- if (!exceptionMessages.isEmpty())
- throw new TranslatorException("ObjectProjections Exception: "
- + exceptionMessages.toString());
- }
-
}
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/SearchCriterion.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/SearchCriterion.java 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/SearchCriterion.java 2012-09-28 12:43:11 UTC (rev 4485)
@@ -22,6 +22,7 @@
package org.teiid.translator.object.search;
import org.teiid.metadata.Column;
+import org.teiid.metadata.ColumnSet;
import org.teiid.metadata.Table;
public class SearchCriterion {
@@ -37,7 +38,6 @@
private boolean isAnd = false;
private Operator operator;
- private String operatorString;
private Column column;
private Object value;
private String runtimeType;
@@ -46,21 +46,17 @@
this.operator = Operator.ALL;
}
- public SearchCriterion(Column column, Object value, String operaterString,
- String type) {
+ public SearchCriterion(Column column, Object value, String type) {
this.column = column;
this.value = value;
- this.operatorString = operaterString;
this.runtimeType = type;
this.operator = Operator.EQUALS;
-
}
- public SearchCriterion(Column column, Object value, String operaterString,
- Operator operator, String type) {
- this(column, value, operaterString, type);
+ public SearchCriterion(Column column, Object value, Operator operator,
+ String type) {
+ this(column, value, type);
this.operator = operator;
-
}
public Column getColumn() {
@@ -68,16 +64,12 @@
}
public String getTableName() {
- Object p = column.getParent();
+ ColumnSet<?> p = column.getParent();
if (p instanceof Table) {
Table t = (Table) p;
return t.getName();
- } else {
- // don't this would happen, but just in case at the moment
- assert (p.getClass().getName() != null);
}
-
- return null;
+ throw new AssertionError();
}
public String getField() {
@@ -100,15 +92,6 @@
this.operator = operator;
}
- public String getOperatorString() {
- return this.operatorString;
- }
-
- public void setOperatorString(String operatorString) {
- this.operatorString = operatorString;
-
- }
-
public String getRuntimeType() {
return this.runtimeType;
}
Deleted: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/util/ObjectUtil.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/util/ObjectUtil.java 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/util/ObjectUtil.java 2012-09-28 12:43:11 UTC (rev 4485)
@@ -1,53 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * 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
- * 02110-1301 USA.
- */
-package org.teiid.translator.object.util;
-
-import java.util.Collection;
-
-import org.teiid.core.util.ReflectionHelper;
-import org.teiid.translator.TranslatorException;
-
-public class ObjectUtil {
-
- public static Object createObject(String objectClassName,
- Collection<?> ctors, ClassLoader loader) throws TranslatorException {
- try {
-
- return ReflectionHelper.create(objectClassName, ctors, loader);
- } catch (Exception e1) {
- throw new TranslatorException(e1);
- }
- }
-
- public static Object createObject(String objectClassName,
- Object[] ctorObjs, Class<?>[] argTypes, ClassLoader loader) throws TranslatorException {
- try {
-
- return ReflectionHelper.create(objectClassName, ctorObjs, argTypes, loader);
- } catch (Exception e1) {
- e1.printStackTrace();
- throw new TranslatorException(e1);
- }
- }
-
-
-}
Modified: trunk/connectors/translator-object/src/main/resources/org/teiid/translator/object/i18n.properties
===================================================================
--- trunk/connectors/translator-object/src/main/resources/org/teiid/translator/object/i18n.properties 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/main/resources/org/teiid/translator/object/i18n.properties 2012-09-28 12:43:11 UTC (rev 4485)
@@ -19,12 +19,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA.
#
-TEIID12001=Received IAggregate, but it is not supported. Check capabilities.
-TEIID12005=Received IFunction, but it is not supported. Check capabilities.
-TEIID12006=Received IScalarSubquery, but it is not supported. Check capabilities.
-TEIID12007=Received ISearchedCaseExpression, but it is not supported. Check capabilities.
-
-
ObjectExecutionFactory.rootClassNameNotDefined=RootClassName is undefined
ObjectExecutionFactory.rootClassNotFound=RootClass {0} not found to load
ObjectExecutionFactory.cacheNotFoundinJNDI=Cache was not found using JNDI name {0}
Modified: trunk/connectors/translator-object/src/test/example_vdbs/infinispancache-vdb.xml
===================================================================
--- trunk/connectors/translator-object/src/test/example_vdbs/infinispancache-vdb.xml 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/test/example_vdbs/infinispancache-vdb.xml 2012-09-28 12:43:11 UTC (rev 4485)
@@ -23,7 +23,7 @@
PlayerName varchar(255)
)
AS
- SELECT o.TeamName, y.Name FROM (Select TeamObject from Team) as T, OBJECTTABLE('x' PASSING T.TeamObject AS x COLUMNS TeamName varchar(255) 'teiid_row.name', players object 'teiid_row.players') as o, OBJECTTABLE('m' PASSING o.players as m COLUMNS Name string 'teiid_row') as y;
+ SELECT o.TeamName, y.Name FROM Team as T, OBJECTTABLE('x' PASSING T.TeamObject AS x COLUMNS TeamName varchar(255) 'teiid_row.name', players object 'teiid_row.players') as o, OBJECTTABLE('m' PASSING o.players as m COLUMNS Name string 'teiid_row') as y;
]]> </metadata>
</model>
Modified: trunk/connectors/translator-object/src/test/example_vdbs/infinispanremotecache-vdb.xml
===================================================================
--- trunk/connectors/translator-object/src/test/example_vdbs/infinispanremotecache-vdb.xml 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/test/example_vdbs/infinispanremotecache-vdb.xml 2012-09-28 12:43:11 UTC (rev 4485)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<vdb name="team" version="1">
- <description>Shows how to call Web Services</description>
+ <description>Shows how to call a remoteInfinispan Cache</description>
<property name="UseConnectorMetadata" value="cached" />
<!-- connection-jndi-name="dummy" -->
@@ -23,7 +23,7 @@
PlayerName varchar(255)
)
AS
- SELECT o.TeamName, y.Name FROM (Select TeamObject from Team) as T, OBJECTTABLE('x' PASSING T.TeamObject AS x COLUMNS TeamName varchar(255) 'teiid_row.name', players object 'teiid_row.players') as o, OBJECTTABLE('m' PASSING o.players as m COLUMNS Name string 'teiid_row') as y;
+ SELECT o.TeamName, y.Name FROM Team as T, OBJECTTABLE('x' PASSING T.TeamObject AS x COLUMNS TeamName varchar(255) 'teiid_row.name', players object 'teiid_row.players') as o, OBJECTTABLE('m' PASSING o.players as m COLUMNS Name string 'teiid_row') as y;
]]> </metadata>
</model>
Modified: trunk/connectors/translator-object/src/test/example_vdbs/mapcache-vdb.xml
===================================================================
--- trunk/connectors/translator-object/src/test/example_vdbs/mapcache-vdb.xml 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/test/example_vdbs/mapcache-vdb.xml 2012-09-28 12:43:11 UTC (rev 4485)
@@ -23,7 +23,7 @@
PlayerName varchar(255)
)
AS
- SELECT o.TeamName, y.Name FROM (Select TeamObject from Team) as T, OBJECTTABLE('x' PASSING T.TeamObject AS x COLUMNS TeamName varchar(255) 'teiid_row.name', players object 'teiid_row.players') as o, OBJECTTABLE('m' PASSING o.players as m COLUMNS Name string 'teiid_row') as y;
+ SELECT o.TeamName, y.Name FROM Team as T, OBJECTTABLE('x' PASSING T.TeamObject AS x COLUMNS TeamName varchar(255) 'teiid_row.name', players object 'teiid_row.players') as o, OBJECTTABLE('m' PASSING o.players as m COLUMNS Name string 'teiid_row') as y;
]]> </metadata>
</model>
Modified: trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiILuceneSearch.java
===================================================================
--- trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiILuceneSearch.java 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiILuceneSearch.java 2012-09-28 12:43:11 UTC (rev 4485)
@@ -21,8 +21,8 @@
*/
package org.teiid.translator.object.infinispan;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
import java.util.ArrayList;
import java.util.List;
@@ -36,9 +36,7 @@
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.object.BasicSearchTest;
-import org.teiid.translator.object.ObjectConnection;
import org.teiid.translator.object.ObjectExecution;
-import org.teiid.translator.object.infinispan.search.LuceneSearch;
import org.teiid.translator.object.util.TradesCacheSource;
import org.teiid.translator.object.util.VDBUtility;
Modified: trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiKeySearch.java
===================================================================
--- trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiKeySearch.java 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiKeySearch.java 2012-09-28 12:43:11 UTC (rev 4485)
@@ -21,28 +21,21 @@
*/
package org.teiid.translator.object.infinispan;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
import java.util.ArrayList;
import java.util.List;
-import javax.naming.Context;
-
import org.infinispan.manager.CacheContainer;
import org.infinispan.manager.DefaultCacheManager;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.mockito.Mock;
import org.teiid.language.Select;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.object.BasicSearchTest;
-import org.teiid.translator.object.ObjectConnection;
import org.teiid.translator.object.ObjectExecution;
-import org.teiid.translator.object.infinispan.search.SearchByKey;
import org.teiid.translator.object.util.TradesCacheSource;
import org.teiid.translator.object.util.VDBUtility;
Modified: trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/mapcache/TestMapCacheKeySearch.java
===================================================================
--- trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/mapcache/TestMapCacheKeySearch.java 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/mapcache/TestMapCacheKeySearch.java 2012-09-28 12:43:11 UTC (rev 4485)
@@ -27,19 +27,26 @@
import static org.mockito.Mockito.when;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import javax.naming.Context;
import org.junit.Before;
import org.junit.BeforeClass;
+import org.junit.Test;
import org.mockito.Mock;
import org.teiid.language.Select;
+import org.teiid.metadata.MetadataFactory;
+import org.teiid.metadata.Table;
+import org.teiid.query.metadata.SystemMetadata;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.object.BasicSearchTest;
import org.teiid.translator.object.ObjectExecution;
+import org.teiid.translator.object.ObjectExecutionFactory;
import org.teiid.translator.object.util.TradesCacheSource;
import org.teiid.translator.object.util.VDBUtility;
@@ -112,6 +119,30 @@
return rows;
}
+ @Test public void testGetMetadata() throws Exception {
+
+ Map dts = SystemMetadata.getInstance().getSystemStore().getDatatypes();
+
+ MetadataFactory mfactory = new MetadataFactory("TestVDB", 1, "Trade", dts, new Properties(), null);
+
+ MapCacheExecutionFactory factory = new MapCacheExecutionFactory() {
+
+ };
+
+ factory.setCacheJndiName(JNDI_NAME);
+ factory.setRootClassName(TradesCacheSource.TRADE_CLASS_NAME);
+ factory.start();
+
+ factory.getMetadata(mfactory, null);
+
+ Map<String, Table> tables = mfactory.getSchema().getTables();
+ for (Iterator<Table> it=tables.values().iterator(); it.hasNext();) {
+ Table t = it.next();
+ System.out.println(t.getName() + " - " + (t.getSelectTransformation() != null ? t.getSelectTransformation() : t.getSQLString()));
+ }
+
+ }
+
}
Modified: trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/search/TestBasicKeySearchCriteria.java
===================================================================
--- trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/search/TestBasicKeySearchCriteria.java 2012-09-28 12:02:37 UTC (rev 4484)
+++ trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/search/TestBasicKeySearchCriteria.java 2012-09-28 12:43:11 UTC (rev 4485)
@@ -21,11 +21,10 @@
*/
package org.teiid.translator.object.search;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.*;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.teiid.language.Select;
import org.teiid.translator.object.ObjectExecutionFactory;
@@ -70,6 +69,7 @@
}
+ @Ignore(value="Or is unnecessary as the optimizer will use IN and it was not implemented correctly (the results were not cumulative and we have to restict pushdown support of comparisions to only the primary key as no post filtering is performed")
@Test public void test5Equals() throws Exception {
Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select * From Trade_Object.Trade where Trade_Object.Trade.Name = 'MyName' and (Trade_Object.Trade.TradeId = '2' or Trade_Object.Trade.Settled = 'true') or (Trade_Object.Trade.Settled = 'false' and Trade_Object.Trade.TradeId = 3) "); //$NON-NLS-1$
@@ -78,7 +78,6 @@
validateSearchCriteria(criteria.getCriterion(), 5, false, true);
}
-
@Test public void testQueryIncludeLegsNoCriteria() throws Exception {
Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select T.TradeId, T.Name as TradeName, L.Name as LegName From Trade_Object.Trade as T, Trade_Object.Leg as L Where T.TradeId = L.TradeId"); //$NON-NLS-1$
@@ -141,7 +140,6 @@
assertNotNull(criteria.getColumn());
assertNotNull(criteria.getField());
assertNotNull(criteria.getOperator());
- assertNotNull(criteria.getOperatorString());
assertNotNull(criteria.getTableName());
assertNotNull(criteria.getRuntimeType());
assertNotNull(criteria.getValue());
12 years, 2 months
teiid SVN: r4484 - in trunk/engine/src: test/java/org/teiid/query/processor and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-09-28 08:02:37 -0400 (Fri, 28 Sep 2012)
New Revision: 4484
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/TriggerActionPlanner.java
trunk/engine/src/test/java/org/teiid/query/processor/TestTriggerActions.java
Log:
TEIID-2222 additional fix for dynamic sql in a trigger action
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/TriggerActionPlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/TriggerActionPlanner.java 2012-09-27 19:55:13 UTC (rev 4483)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/TriggerActionPlanner.java 2012-09-28 12:02:37 UTC (rev 4484)
@@ -51,7 +51,7 @@
import org.teiid.query.sql.proc.TriggerAction;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.Symbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.util.CommandContext;
@@ -109,18 +109,22 @@
TriggerAction ta, QueryMetadataInterface metadata,
Map<ElementSymbol, Expression> params)
throws QueryMetadataException, TeiidComponentException {
- QueryCommand query;
- ArrayList<Expression> selectSymbols = new ArrayList<Expression>();
List<ElementSymbol> allSymbols = ResolverUtil.resolveElementsInGroup(ta.getView(), metadata);
+ GroupSymbol old = new GroupSymbol(SQLConstants.Reserved.OLD);
+ GroupSymbol newGroup = new GroupSymbol(SQLConstants.Reserved.NEW);
for (ElementSymbol elementSymbol : allSymbols) {
- params.put(new ElementSymbol(SQLConstants.Reserved.OLD + Symbol.SEPARATOR + elementSymbol.getShortName()), elementSymbol);
+ ElementSymbol es = elementSymbol.clone();
+ es.setGroupSymbol(old);
+ params.put(es, elementSymbol);
if (userCommand instanceof Update) {
//default to old
- params.put(new ElementSymbol(SQLConstants.Reserved.NEW + Symbol.SEPARATOR + elementSymbol.getShortName()), elementSymbol);
+ es = elementSymbol.clone();
+ es.setGroupSymbol(newGroup);
+ params.put(es, elementSymbol);
}
}
- selectSymbols.addAll(LanguageObject.Util.deepClone(allSymbols, ElementSymbol.class));
- query = new Query(new Select(selectSymbols), new From(Arrays.asList(new UnaryFromClause(ta.getView()))), ((TranslatableProcedureContainer)userCommand).getCriteria(), null, null);
+ ArrayList<Expression> selectSymbols = new ArrayList<Expression>(LanguageObject.Util.deepClone(allSymbols, ElementSymbol.class));
+ QueryCommand query = new Query(new Select(selectSymbols), new From(Arrays.asList(new UnaryFromClause(ta.getView()))), ((TranslatableProcedureContainer)userCommand).getCriteria(), null, null);
return query;
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestTriggerActions.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestTriggerActions.java 2012-09-27 19:55:13 UTC (rev 4483)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestTriggerActions.java 2012-09-28 12:02:37 UTC (rev 4484)
@@ -103,6 +103,25 @@
helpProcess(plan, context, dm, expected);
}
+ @Test public void testDynamicUpdate() throws Exception {
+ TransformationMetadata metadata = TestUpdateValidator.example1();
+ TestUpdateValidator.createView("select '1' as x, 2 as y", metadata, GX);
+ Table t = metadata.getMetadataStore().getSchemas().get(VM1).getTables().get(GX);
+ t.setDeletePlan("");
+ t.setUpdatePlan("FOR EACH ROW BEGIN execute immediate 'update pm1.g1 set e1 = new.x where e2 = new.y'; END");
+ t.setInsertPlan("");
+
+ String sql = "update gx set x = 1 where y = 2";
+
+ HardcodedDataManager dm = new HardcodedDataManager();
+ dm.addData("UPDATE pm1.g1 SET e1 = '1' WHERE e2 = 2", new List[] {Arrays.asList(1)});
+ CommandContext context = createCommandContext();
+ BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+ ProcessorPlan plan = TestProcessor.helpGetPlan(TestResolver.helpResolve(sql, metadata), metadata, new DefaultCapabilitiesFinder(caps), context);
+ List<?>[] expected = new List[] {Arrays.asList(1)};
+ helpProcess(plan, context, dm, expected);
+ }
+
@Test public void testDynamicRecursion() throws Exception {
TransformationMetadata metadata = TestUpdateValidator.example1();
TestUpdateValidator.createView("select 'a' as x, 2 as y", metadata, GX);
12 years, 2 months
teiid SVN: r4483 - in trunk: engine/src/main/java/org/teiid/query/metadata and 6 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-09-27 15:55:13 -0400 (Thu, 27 Sep 2012)
New Revision: 4483
Added:
trunk/api/src/main/java/org/teiid/metadata/ParseException.java
trunk/api/src/main/java/org/teiid/metadata/Parser.java
Modified:
trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java
trunk/engine/src/main/java/org/teiid/query/metadata/DDLMetadataRepository.java
trunk/engine/src/main/java/org/teiid/query/metadata/SystemMetadata.java
trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java
trunk/engine/src/test/java/org/teiid/query/metadata/TestMetadataValidator.java
trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
trunk/runtime/src/main/java/org/teiid/deployers/PgCatalogMetadataStore.java
trunk/runtime/src/main/java/org/teiid/runtime/AbstractVDBDeployer.java
trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java
Log:
TEIID-2231 exposing a ddl parser
Modified: trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java 2012-09-27 18:42:37 UTC (rev 4482)
+++ trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java 2012-09-27 19:55:13 UTC (rev 4483)
@@ -22,15 +22,21 @@
package org.teiid.metadata;
+import java.io.Reader;
import java.io.Serializable;
+import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
+import org.teiid.CommandContext;
import org.teiid.connector.DataPlugin;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.metadata.FunctionMethod.PushDown;
import org.teiid.metadata.ProcedureParameter.Type;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.TypeFacility;
@@ -56,6 +62,7 @@
private Schema schema = new Schema();
private String idPrefix;
private int count;
+ private transient Parser parser;
public MetadataFactory(String vdbName, int vdbVersion, String schemaName, Map<String, Datatype> runtimeTypes, Properties importProperties, String rawMetadata) {
this.vdbName = vdbName;
@@ -400,6 +407,48 @@
}
/**
+ * Adds a non-pushdown function based upon the given {@link Method}.
+ * @param name
+ * @param method
+ * @return
+ * @throws TranslatorException
+ */
+ public FunctionMethod addFunction(String name, Method method) throws TranslatorException {
+ String returnType = DataTypeManager.getDataTypeName(method.getReturnType());
+ Class<?>[] params = method.getParameterTypes();
+ String[] paramTypes = new String[params.length];
+ boolean nullOnNull = false;
+ for (int i = 0; i < params.length; i++) {
+ Class<?> clazz = params[i];
+ if (clazz.isPrimitive()) {
+ nullOnNull = true;
+ if ( clazz == Boolean.TYPE ) clazz = Boolean.class;
+ else if ( clazz == Character.TYPE ) clazz = Character.class;
+ else if ( clazz == Byte.TYPE ) clazz = Byte.class;
+ else if ( clazz == Short.TYPE ) clazz = Short.class;
+ else if ( clazz == Integer.TYPE ) clazz = Integer.class;
+ else if ( clazz == Long.TYPE ) clazz = Long.class;
+ else if ( clazz == Float.TYPE ) clazz = Float.class;
+ else if ( clazz == Double.TYPE ) clazz = Double.class;
+ }
+ paramTypes[i] = DataTypeManager.getDataTypeName(clazz);
+ }
+ if (params.length > 0 && params[0] == CommandContext.class) {
+ paramTypes = Arrays.copyOfRange(paramTypes, 1, paramTypes.length);
+ }
+ FunctionMethod func = FunctionMethod.createFunctionMethod(name, null, null, returnType, paramTypes);
+ setUUID(func);
+ getSchema().addFunction(func);
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ func.setInvocationMethod(method.getName());
+ func.setPushdown(PushDown.CANNOT_PUSHDOWN);
+ func.setClassloader(classLoader);
+ func.setInvocationClass(method.getDeclaringClass().getName());
+ func.setNullOnNull(nullOnNull);
+ return func;
+ }
+
+ /**
* Set to false to disable correcting column and other names to be valid Teiid names.
* @param autoCorrectColumnNames
*/
@@ -422,6 +471,12 @@
return store;
}
+ /**
+ * Set the {@link Schema} to a different instance. This is typically called
+ * in special situations where the {@link MetadataFactory} logic is not used
+ * to construct the {@link Schema}.
+ * @param schema
+ */
public void setSchema(Schema schema) {
this.schema = schema;
}
@@ -503,4 +558,21 @@
public Map<String, Datatype> getBuiltinDataTypes() {
return builtinDataTypes;
}
+
+ /**
+ * Parses, but does not close, the given {@link Reader} into this {@link MetadataFactory}
+ * @param ddl
+ * @throws ParseException
+ */
+ public void parse(Reader ddl) throws ParseException {
+ this.parser.parseDDL(this, ddl);
+ }
+
+ public void setParser(Parser parser) {
+ this.parser = parser;
+ }
+
+ public Parser getParser() {
+ return parser;
+ }
}
Added: trunk/api/src/main/java/org/teiid/metadata/ParseException.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/ParseException.java (rev 0)
+++ trunk/api/src/main/java/org/teiid/metadata/ParseException.java 2012-09-27 19:55:13 UTC (rev 4483)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * 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
+ * 02110-1301 USA.
+ */
+
+package org.teiid.metadata;
+
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.BundleUtil.Event;
+
+public class ParseException extends TeiidRuntimeException {
+ private static final long serialVersionUID = -7889770730039591817L;
+
+ public ParseException(Event event, Throwable cause) {
+ super(event, cause);
+ }
+}
\ No newline at end of file
Property changes on: trunk/api/src/main/java/org/teiid/metadata/ParseException.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/api/src/main/java/org/teiid/metadata/Parser.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/Parser.java (rev 0)
+++ trunk/api/src/main/java/org/teiid/metadata/Parser.java 2012-09-27 19:55:13 UTC (rev 4483)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * 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
+ * 02110-1301 USA.
+ */
+
+package org.teiid.metadata;
+
+import java.io.Reader;
+
+public interface Parser {
+
+ /**
+ * Parses the given {@link Reader} into the {@link MetadataFactory}.
+ * The {@link Reader} will not be closed by this call.
+ * @param factory
+ * @param ddl
+ * @throws ParseException
+ */
+ void parseDDL(MetadataFactory factory, Reader ddl) throws ParseException;
+}
\ No newline at end of file
Property changes on: trunk/api/src/main/java/org/teiid/metadata/Parser.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/DDLMetadataRepository.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/DDLMetadataRepository.java 2012-09-27 18:42:37 UTC (rev 4482)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/DDLMetadataRepository.java 2012-09-27 19:55:13 UTC (rev 4483)
@@ -21,23 +21,18 @@
*/
package org.teiid.query.metadata;
-import org.teiid.api.exception.query.QueryParserException;
-import org.teiid.core.TeiidRuntimeException;
+import java.io.StringReader;
+
import org.teiid.metadata.MetadataFactory;
-import org.teiid.query.QueryPlugin;
-import org.teiid.query.parser.QueryParser;
import org.teiid.translator.ExecutionFactory;
import org.teiid.translator.TranslatorException;
public class DDLMetadataRepository extends BaseMetadataRepository {
-
@Override
public void loadMetadata(MetadataFactory factory, ExecutionFactory executionFactory, Object connectionFactory) throws TranslatorException {
- try {
- QueryParser.getQueryParser().parseDDL(factory, factory.getRawMetadata());
- } catch (QueryParserException e) {
- throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30386, e);
+ if (factory.getRawMetadata() != null) {
+ factory.parse(new StringReader(factory.getRawMetadata()));
}
super.loadMetadata(factory, executionFactory, connectionFactory);
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/SystemMetadata.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/SystemMetadata.java 2012-09-27 18:42:37 UTC (rev 4482)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/SystemMetadata.java 2012-09-27 19:55:13 UTC (rev 4483)
@@ -34,7 +34,6 @@
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.VDBMetaData;
-import org.teiid.api.exception.query.QueryParserException;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.types.DataTypeManager.DefaultDataTypes;
@@ -134,8 +133,6 @@
};
QueryParser.getQueryParser().parseDDL(factory, new InputStreamReader(is, Charset.forName("UTF-8"))); //$NON-NLS-1$
return factory;
- } catch (QueryParserException e) {
- throw new TeiidRuntimeException(e);
} finally {
try {
is.close();
Modified: trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java 2012-09-27 18:42:37 UTC (rev 4482)
+++ trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java 2012-09-27 19:55:13 UTC (rev 4483)
@@ -35,6 +35,7 @@
import org.teiid.metadata.DuplicateRecordException;
import org.teiid.metadata.FunctionMethod;
import org.teiid.metadata.MetadataFactory;
+import org.teiid.metadata.Parser;
import org.teiid.query.QueryPlugin;
import org.teiid.query.sql.lang.CacheHint;
import org.teiid.query.sql.lang.Command;
@@ -47,7 +48,7 @@
* input stream. Putting multiple queries into the same stream will result
* in unpredictable and most likely incorrect behavior.</p>
*/
-public class QueryParser {
+public class QueryParser implements Parser {
private static ThreadLocal<QueryParser> QUERY_PARSER = new ThreadLocal<QueryParser>() {
/**
@@ -356,15 +357,15 @@
return new QueryParserException(QueryPlugin.Util.getString("QueryParser.parsingError", tme.getMessage())); //$NON-NLS-1$
}
- public void parseDDL(MetadataFactory factory, String ddl) throws QueryParserException {
+ public void parseDDL(MetadataFactory factory, String ddl) {
parseDDL(factory, new StringReader(ddl));
}
- public void parseDDL(MetadataFactory factory, Reader ddl) throws QueryParserException {
+ public void parseDDL(MetadataFactory factory, Reader ddl) {
try {
getSqlParser(ddl).parseMetadata(factory);
} catch (ParseException e) {
- throw convertParserException(e);
+ throw new org.teiid.metadata.ParseException(QueryPlugin.Event.TEIID30386, convertParserException(e));
}
HashSet<FunctionMethod> functions = new HashSet<FunctionMethod>();
for (FunctionMethod functionMethod : factory.getSchema().getFunctions().values()) {
Modified: trunk/engine/src/test/java/org/teiid/query/metadata/TestMetadataValidator.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/metadata/TestMetadataValidator.java 2012-09-27 18:42:37 UTC (rev 4482)
+++ trunk/engine/src/test/java/org/teiid/query/metadata/TestMetadataValidator.java 2012-09-27 19:55:13 UTC (rev 4483)
@@ -34,6 +34,7 @@
import org.teiid.metadata.MetadataStore;
import org.teiid.metadata.Table;
import org.teiid.query.function.SystemFunctionManager;
+import org.teiid.query.parser.QueryParser;
import org.teiid.query.parser.TestDDLParser;
import org.teiid.query.validator.ValidatorFailure;
import org.teiid.query.validator.ValidatorReport;
@@ -64,6 +65,7 @@
DDLMetadataRepository repo = new DDLMetadataRepository();
MetadataFactory mf = new MetadataFactory("myVDB",1, modelName, TestDDLParser.getDataTypes(), new Properties(), ddl);
+ mf.setParser(QueryParser.getQueryParser());
mf.setBuiltinDataTypes(SystemMetadata.getInstance().getSystemStore().getDatatypes());
mf.getSchema().setPhysical(physical);
repo.loadMetadata(mf, null, null);
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java 2012-09-27 18:42:37 UTC (rev 4482)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java 2012-09-27 19:55:13 UTC (rev 4483)
@@ -31,6 +31,7 @@
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.api.exception.query.QueryParserException;
import org.teiid.metadata.*;
+import org.teiid.metadata.ParseException;
import org.teiid.metadata.BaseColumn.NullType;
import org.teiid.query.metadata.MetadataValidator;
import org.teiid.query.metadata.SystemMetadata;
@@ -117,7 +118,7 @@
assertEquals("hello", e6.getDefaultValue());
}
- @Test(expected=QueryParserException.class)
+ @Test(expected=ParseException.class)
public void testDuplicatePrimarykey() throws Exception {
String ddl = "CREATE FOREIGN TABLE G1( e1 integer primary key, e2 varchar primary key)";
MetadataStore mds = new MetadataStore();
@@ -215,7 +216,7 @@
assertEquals(table.getColumns().subList(1, 3), table.getAccessPatterns().get(1).getColumns());
}
- @Test(expected=QueryParserException.class)
+ @Test(expected=ParseException.class)
public void testWrongPrimarykey() throws Exception {
String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, PRIMARY KEY (e3))";
@@ -340,7 +341,7 @@
assertEquals(fk.getPrimaryKey().getColumns(), s.getSchema("model").getTable("G1").getColumns());
}
- @Test(expected=QueryParserException.class)
+ @Test(expected=ParseException.class)
public void testTableWithPlan() throws Exception {
String ddl = "CREATE foreign table G1 as select 1";
MetadataStore mds = new MetadataStore();
@@ -514,7 +515,7 @@
assertEquals("boolean", fm.getInputParameters().get(0).getType());
}
- @Test(expected=QueryParserException.class) public void testInvalidFunctionBody() throws Exception {
+ @Test(expected=ParseException.class) public void testInvalidFunctionBody() throws Exception {
String ddl = "CREATE FUNCTION SourceFunc(flag boolean) RETURNS varchar AS SELECT 'a';";
Schema s = helpParse(ddl, "model").getSchema();
@@ -523,7 +524,7 @@
assertTrue( fm.getInputParameters().get(0).isVarArg());
}
- @Test(expected=QueryParserException.class) public void testInvalidProcedureBody() throws Exception {
+ @Test(expected=ParseException.class) public void testInvalidProcedureBody() throws Exception {
String ddl = "CREATE FOREIGN PROCEDURE SourceFunc(flag boolean) RETURNS varchar AS SELECT 'a';";
Schema s = helpParse(ddl, "model").getSchema();
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2012-09-27 18:42:37 UTC (rev 4482)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2012-09-27 19:55:13 UTC (rev 4483)
@@ -53,10 +53,10 @@
import org.teiid.adminapi.AdminProcessingException;
import org.teiid.adminapi.Translator;
import org.teiid.adminapi.impl.ModelMetaData;
-import org.teiid.adminapi.impl.ModelMetaData.Message.Severity;
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.adminapi.impl.VDBMetadataParser;
import org.teiid.adminapi.impl.VDBTranslatorMetaData;
+import org.teiid.adminapi.impl.ModelMetaData.Message.Severity;
import org.teiid.common.buffer.BufferManager;
import org.teiid.core.TeiidException;
import org.teiid.deployers.CompositeVDB;
@@ -69,8 +69,8 @@
import org.teiid.deployers.VirtualDatabaseException;
import org.teiid.dqp.internal.datamgr.ConnectorManager;
import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
-import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException;
import org.teiid.dqp.internal.datamgr.TranslatorRepository;
+import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException;
import org.teiid.jboss.rest.ResteasyEnabler;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
@@ -361,10 +361,7 @@
cached = true;
LogManager.logTrace(LogConstants.CTX_RUNTIME, "Model ", model.getName(), "in VDB ", vdb.getName(), " was loaded from cached metadata"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} else {
- factory = new MetadataFactory(vdb.getName(), vdb.getVersion(), model.getName(), datatypes, model.getProperties(), model.getSchemaText());
- factory.setBuiltinDataTypes(builtin);
- factory.getSchema().setPhysical(model.isSource());
-
+ factory = createMetadataFactory(vdb, model);
ExecutionFactory ef = null;
Object cf = null;
Modified: trunk/runtime/src/main/java/org/teiid/deployers/PgCatalogMetadataStore.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/PgCatalogMetadataStore.java 2012-09-27 18:42:37 UTC (rev 4482)
+++ trunk/runtime/src/main/java/org/teiid/deployers/PgCatalogMetadataStore.java 2012-09-27 19:55:13 UTC (rev 4483)
@@ -28,7 +28,6 @@
import java.util.Map;
import java.util.Properties;
-import org.teiid.CommandContext;
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.core.types.ArrayImpl;
import org.teiid.core.types.DataTypeManager;
@@ -37,7 +36,6 @@
import org.teiid.metadata.FunctionMethod;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.Table;
-import org.teiid.metadata.FunctionMethod.PushDown;
import org.teiid.metadata.Table.Type;
import org.teiid.odbc.ODBCServerRemoteImpl;
import org.teiid.query.metadata.TransformationMetadata;
@@ -539,29 +537,15 @@
return t;
}
- private FunctionMethod addFunction(String javaFunction, String name) {
+ private FunctionMethod addFunction(String javaFunction, String name) throws TranslatorException {
Method[] methods = FunctionMethods.class.getMethods();
for (Method method : methods) {
if (!method.getName().equals(javaFunction)) {
continue;
}
- String returnType = DataTypeManager.getDataTypeName(method.getReturnType());
- Class<?>[] params = method.getParameterTypes();
- String[] paramTypes = new String[params.length];
- for (int i = 0; i < params.length; i++) {
- paramTypes[i] = DataTypeManager.getDataTypeName(params[i]);
- }
- if (params.length > 0 && params[0] == CommandContext.class) {
- paramTypes = Arrays.copyOfRange(paramTypes, 1, paramTypes.length);
- }
- FunctionMethod func = FunctionMethod.createFunctionMethod(name, name, "pg", returnType, paramTypes); //$NON-NLS-1$
- setUUID(func);
- getSchema().addFunction(func);
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- func.setInvocationMethod(javaFunction);
- func.setPushdown(PushDown.CANNOT_PUSHDOWN);
- func.setClassloader(classLoader);
- func.setInvocationClass(FunctionMethods.class.getName());
+ FunctionMethod func = addFunction(name, method);
+ func.setCategory("pg"); //$NON-NLS-1$
+ func.setDescription(name);
return func;
}
throw new AssertionError("Could not find function"); //$NON-NLS-1$
Modified: trunk/runtime/src/main/java/org/teiid/runtime/AbstractVDBDeployer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/runtime/AbstractVDBDeployer.java 2012-09-27 18:42:37 UTC (rev 4482)
+++ trunk/runtime/src/main/java/org/teiid/runtime/AbstractVDBDeployer.java 2012-09-27 19:55:13 UTC (rev 4483)
@@ -40,12 +40,14 @@
import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
+import org.teiid.metadata.Datatype;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.MetadataRepository;
import org.teiid.metadata.MetadataStore;
import org.teiid.query.metadata.DDLMetadataRepository;
import org.teiid.query.metadata.DirectQueryMetadataRepository;
import org.teiid.query.metadata.NativeMetadataRepository;
+import org.teiid.query.parser.QueryParser;
import org.teiid.translator.TranslatorException;
public abstract class AbstractVDBDeployer {
@@ -181,6 +183,16 @@
getVDBRepository().finishDeployment(vdb.getName(), vdb.getVersion());
}
}
+
+ protected MetadataFactory createMetadataFactory(VDBMetaData vdb,
+ ModelMetaData model) {
+ Map<String, Datatype> datatypes = this.getVDBRepository().getRuntimeTypeMap();
+ MetadataFactory factory = new MetadataFactory(vdb.getName(), vdb.getVersion(), model.getName(), datatypes, model.getProperties(), model.getSchemaText());
+ factory.setBuiltinDataTypes(this.getVDBRepository().getSystemStore().getDatatypes());
+ factory.getSchema().setPhysical(model.isSource());
+ factory.setParser(new QueryParser()); //for thread safety each factory gets it's own instance.
+ return factory;
+ }
/**
* @throws VirtualDatabaseException
Modified: trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java 2012-09-27 18:42:37 UTC (rev 4482)
+++ trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java 2012-09-27 19:55:13 UTC (rev 4483)
@@ -31,7 +31,6 @@
import java.sql.SQLException;
import java.util.Arrays;
import java.util.LinkedHashMap;
-import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
@@ -78,7 +77,6 @@
import org.teiid.jdbc.TeiidSQLException;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
-import org.teiid.metadata.Datatype;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.MetadataRepository;
import org.teiid.metadata.MetadataStore;
@@ -481,10 +479,7 @@
ConnectorManagerRepository cmr,
MetadataRepository metadataRepository, MetadataStore store,
AtomicInteger loadCount) throws TranslatorException {
- Map<String, Datatype> datatypes = this.repo.getRuntimeTypeMap();
- MetadataFactory factory = new MetadataFactory(vdb.getName(), vdb.getVersion(), model.getName(), datatypes, model.getProperties(), model.getSchemaText());
- factory.setBuiltinDataTypes(this.repo.getSystemStore().getDatatypes());
- factory.getSchema().setPhysical(model.isSource());
+ MetadataFactory factory = createMetadataFactory(vdb, model);
ExecutionFactory ef = null;
Object cf = null;
12 years, 2 months
teiid SVN: r4482 - in trunk: client/src/main/java/org/teiid/net/socket and 3 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-09-27 14:42:37 -0400 (Thu, 27 Sep 2012)
New Revision: 4482
Modified:
trunk/admin/src/main/java/org/teiid/adminapi/impl/SessionMetadata.java
trunk/client/src/main/java/org/teiid/net/socket/SocketServerConnection.java
trunk/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java
trunk/runtime/src/main/java/org/teiid/transport/LogonImpl.java
trunk/runtime/src/test/java/org/teiid/transport/TestCommSockets.java
Log:
TEIID-2172 updating the logic to not prematurely terminate
Modified: trunk/admin/src/main/java/org/teiid/adminapi/impl/SessionMetadata.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/SessionMetadata.java 2012-09-27 10:24:37 UTC (rev 4481)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/SessionMetadata.java 2012-09-27 18:42:37 UTC (rev 4482)
@@ -40,7 +40,7 @@
private static final long serialVersionUID = 918638989081830034L;
private String applicationName;
- private long lastPingTime = System.currentTimeMillis();
+ private volatile long lastPingTime = System.currentTimeMillis();
private long createdTime;
private String ipAddress;
private String clientHostName;
Modified: trunk/client/src/main/java/org/teiid/net/socket/SocketServerConnection.java
===================================================================
--- trunk/client/src/main/java/org/teiid/net/socket/SocketServerConnection.java 2012-09-27 10:24:37 UTC (rev 4481)
+++ trunk/client/src/main/java/org/teiid/net/socket/SocketServerConnection.java 2012-09-27 18:42:37 UTC (rev 4482)
@@ -20,9 +20,6 @@
* 02110-1301 USA.
*/
-/**
- *
- */
package org.teiid.net.socket;
import java.io.IOException;
@@ -338,6 +335,15 @@
}
public void cleanUp() {
+ if (this.serverInstance != null && this.logonResult != null && "8.2".compareTo(this.serverInstance.getServerVersion()) <= 0) { //$NON-NLS-1$
+ ILogon newLogon = this.serverInstance.getService(ILogon.class);
+ try {
+ newLogon.assertIdentity(null);
+ } catch (InvalidSessionException e) {
+ } catch (TeiidComponentException e) {
+ } catch (CommunicationException e) {
+ }
+ }
closeServerInstance();
}
Modified: trunk/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java 2012-09-27 10:24:37 UTC (rev 4481)
+++ trunk/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java 2012-09-27 18:42:37 UTC (rev 4482)
@@ -95,7 +95,7 @@
long currentTime = System.currentTimeMillis();
for (SessionMetadata info : sessionCache.values()) {
try {
- if (!info.isEmbedded() && currentTime - info.getLastPingTime() > ServerConnection.PING_INTERVAL * 5) {
+ if (!info.isEmbedded() && currentTime - info.getLastPingTime() > ServerConnection.PING_INTERVAL * 3) {
LogManager.logInfo(LogConstants.CTX_SECURITY, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40007, info.getSessionId()));
closeSession(info.getSessionId());
} else if (sessionExpirationTimeLimit > 0 && currentTime - info.getCreatedTime() > sessionExpirationTimeLimit) {
@@ -389,7 +389,7 @@
public void run() {
monitorSessions();
}
- }, 0, ServerConnection.PING_INTERVAL * 5);
+ }, ServerConnection.PING_INTERVAL * 3, ServerConnection.PING_INTERVAL * 2);
}
public void stop(){
Modified: trunk/runtime/src/main/java/org/teiid/transport/LogonImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/LogonImpl.java 2012-09-27 10:24:37 UTC (rev 4481)
+++ trunk/runtime/src/main/java/org/teiid/transport/LogonImpl.java 2012-09-27 18:42:37 UTC (rev 4482)
@@ -244,6 +244,11 @@
@Override
public void assertIdentity(SessionToken checkSession) throws InvalidSessionException, TeiidComponentException {
+ if (checkSession == null) {
+ //disassociate
+ this.updateDQPContext(new SessionMetadata());
+ return;
+ }
SessionMetadata sessionInfo = null;
try {
sessionInfo = this.service.validateSession(checkSession.getSessionID());
Modified: trunk/runtime/src/test/java/org/teiid/transport/TestCommSockets.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/transport/TestCommSockets.java 2012-09-27 10:24:37 UTC (rev 4481)
+++ trunk/runtime/src/test/java/org/teiid/transport/TestCommSockets.java 2012-09-27 18:42:37 UTC (rev 4482)
@@ -32,14 +32,17 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.teiid.client.security.ILogon;
import org.teiid.common.buffer.BufferManagerFactory;
import org.teiid.common.buffer.impl.MemoryStorageManager;
import org.teiid.core.crypto.NullCryptor;
import org.teiid.core.util.ObjectConverterUtil;
+import org.teiid.dqp.service.SessionServiceException;
import org.teiid.net.CommunicationException;
import org.teiid.net.ConnectionException;
+import org.teiid.net.ServerConnection;
import org.teiid.net.TeiidURL;
import org.teiid.net.socket.SocketServerConnection;
import org.teiid.net.socket.SocketServerConnectionFactory;
@@ -116,6 +119,7 @@
assertEquals(1, stats.maxSockets);
}
+ @Ignore
@Test public void testLobs() throws Exception {
SocketServerConnection conn = helpEstablishConnection(false);
FakeService fs = conn.getService(FakeService.class);
@@ -222,23 +226,38 @@
helpEstablishConnection(true, config, p);
}
- @Test public void testSelectNewInstance() throws Exception {
+ @Test public void testSelectNewInstanceWithoutPooling() throws Exception {
+ Properties p = new Properties();
+ p.setProperty("org.teiid.sockets.maxCachedInstances", "0");
+ helpTestNewInstance(p);
+ }
+
+ @Test public void testSelectNewInstanceWithPooling() throws Exception {
+ Properties p = new Properties();
+ p.setProperty("org.teiid.sockets.maxCachedInstances", "16");
+ helpTestNewInstance(p);
+ }
+
+ private void helpTestNewInstance(Properties p)
+ throws CommunicationException, ConnectionException,
+ SessionServiceException {
SSLConfiguration config = new SSLConfiguration();
- Properties p = new Properties();
SocketServerConnection conn = helpEstablishConnection(false, config, p);
SocketListenerStats stats = listener.getStats();
assertEquals(2, stats.objectsRead); // handshake response, logon,
assertEquals(1, stats.sockets);
conn.cleanUp();
assertEquals(1, this.service.getActiveSessionsCount());
- helpEstablishConnection(false, config, p);
+ ServerConnection conn2 = helpEstablishConnection(false, config, p);
+ assertEquals(2, this.service.getActiveSessionsCount());
conn.selectServerInstance(false);
assertEquals(2, this.service.getActiveSessionsCount());
assertTrue(conn.isOpen(1000));
stats = listener.getStats();
- assertEquals(7, stats.objectsRead); // ping (pool test), assert identity, ping (isOpen)
+ assertEquals(8, stats.objectsRead); // (ping (pool test), assert identityx2, ping (isOpen))x2
assertEquals(2, stats.sockets);
conn.close();
+ conn2.close();
}
@Test public void testEnableCipherSuites() throws Exception {
12 years, 2 months