teiid SVN: r3207 - branches/7.4.x/client/src/main/java/org/teiid/jdbc.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-05-31 14:52:23 -0400 (Tue, 31 May 2011)
New Revision: 3207
Modified:
branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java
Log:
correcting missing message
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java 2011-05-31 18:42:40 UTC (rev 3206)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java 2011-05-31 18:52:23 UTC (rev 3207)
@@ -641,7 +641,7 @@
updateCounts[i] = (Integer)results[i].get(0);
}
if (logger.isLoggable(Level.FINER)) {
- logger.fine(JDBCPlugin.Util.getString("Recieved update counts: " + Arrays.toString(updateCounts))); //$NON-NLS-1$
+ logger.finer("Recieved update counts: " + Arrays.toString(updateCounts)); //$NON-NLS-1$
}
// In update scenarios close the statement implicitly
try {
13 years, 6 months
teiid SVN: r3206 - in branches/7.4.x/engine/src: test/java/org/teiid/query/processor and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-05-31 14:42:40 -0400 (Tue, 31 May 2011)
New Revision: 3206
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
Log:
TEIID-1528 fix for regression
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2011-05-31 15:50:52 UTC (rev 3205)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2011-05-31 18:42:40 UTC (rev 3206)
@@ -152,7 +152,7 @@
toCriteria.add(j);
}
}
- List<Criteria> joinCriteria = (List<Criteria>) joinNode.getProperty(Info.JOIN_CRITERIA);
+ List<Criteria> joinCriteria = (List<Criteria>) joinNode.getProperty(Info.NON_EQUI_JOIN_CRITERIA);
for (int index : toCriteria) {
SingleElementSymbol lses = leftExpressions.get(index);
SingleElementSymbol rses = rightExpressions.get(index);
@@ -163,7 +163,7 @@
joinNode.setProperty(Info.JOIN_TYPE, JoinType.JOIN_INNER);
}
}
- joinNode.setProperty(Info.JOIN_CRITERIA, joinCriteria);
+ joinNode.setProperty(Info.NON_EQUI_JOIN_CRITERIA, joinCriteria);
leftExpressions = RelationalNode.projectTuple(reorder, leftExpressions);
rightExpressions = RelationalNode.projectTuple(reorder, rightExpressions);
joinNode.setProperty(NodeConstants.Info.LEFT_EXPRESSIONS, leftExpressions);
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestTempTables.java 2011-05-31 15:50:52 UTC (rev 3205)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestTempTables.java 2011-05-31 18:42:40 UTC (rev 3206)
@@ -312,7 +312,10 @@
@Test public void testUnneededMergePredicate() throws Exception {
execute("create local temporary table x (e1 string, e2 integer, primary key (e1))", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
execute("create local temporary table x1 (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
- TestOptimizer.helpPlan("select x.e1 from x, x1 where x.e2 = x1.e2 and x.e1 = x1.e1", this.metadata, new String[] {"SELECT x.e2, x.e1 FROM x ORDER BY x.e1", "SELECT x1.e2, x1.e1 FROM x1 ORDER BY x1.e1"}, ComparisonMode.EXACT_COMMAND_STRING);
+ TestOptimizer.helpPlan("select x.e1 from x makenotdep, x1 makenotdep where x.e2 = x1.e2 and x.e1 = x1.e1", this.metadata, new String[] {"SELECT x.e2, x.e1 FROM x ORDER BY x.e1", "SELECT x1.e2, x1.e1 FROM x1 ORDER BY x1.e1"}, ComparisonMode.EXACT_COMMAND_STRING);
+ execute("insert into x (e2, e1) values (2, 'b')", new List[] {Arrays.asList(1)}); //$NON-NLS-1$
+ execute("insert into x1 (e2, e1) values (3, 'b')", new List[] {Arrays.asList(1)}); //$NON-NLS-1$
+ execute("select x.e1 from x makenotdep, x1 makenotdep where x.e2 = x1.e2 and x.e1 = x1.e1", new List[0]); //$NON-NLS-1$
}
private void sampleTable() throws Exception {
13 years, 6 months
teiid SVN: r3205 - in branches/7.1.1.CP2/engine/src: test/java/org/teiid/query/optimizer and 1 other directory.
by teiid-commits@lists.jboss.org
Author: mdrillin
Date: 2011-05-31 11:50:52 -0400 (Tue, 31 May 2011)
New Revision: 3205
Modified:
branches/7.1.1.CP2/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java
branches/7.1.1.CP2/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java
Log:
TEIID-1571 - Fix for invalid merge
Modified: branches/7.1.1.CP2/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java
===================================================================
--- branches/7.1.1.CP2/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java 2011-05-30 09:48:28 UTC (rev 3204)
+++ branches/7.1.1.CP2/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java 2011-05-31 15:50:52 UTC (rev 3205)
@@ -260,7 +260,7 @@
ExpressionMappingVisitor.mapExpressions(groupBy, symbolMap);
node.setProperty(NodeConstants.Info.GROUP_COLS, groupBy.getSymbols());
if (!singleMapping) {
- GroupsUsedByElementsVisitor.getGroups(groupCols, groups);
+ GroupsUsedByElementsVisitor.getGroups(groupBy, groups);
}
}
} else if (type == NodeConstants.Types.SOURCE || type == NodeConstants.Types.ACCESS) {
Modified: branches/7.1.1.CP2/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java
===================================================================
--- branches/7.1.1.CP2/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java 2011-05-30 09:48:28 UTC (rev 3204)
+++ branches/7.1.1.CP2/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java 2011-05-31 15:50:52 UTC (rev 3205)
@@ -317,5 +317,16 @@
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
+
+ @Test public void testMergeGroupBy() throws Exception {
+ BasicSourceCapabilities caps = TestAggregatePushdown.getAggregateCapabilities();
+ caps.setFunctionSupport("+", true); //$NON-NLS-1$
+ ProcessorPlan plan = TestOptimizer.helpPlan("SELECT x FROM (select c.e1 as x from (select e1 from pm1.g1) as c, pm1.g2 as d) as a group by x", //$NON-NLS-1$
+ FakeMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(caps),
+ new String[] {
+ "SELECT g_0.e1 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 GROUP BY g_0.e1"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+
+ TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+ }
}
13 years, 6 months
teiid SVN: r3204 - in branches/7.4.x: engine/src/main/java/org/teiid/query/mapping/xml and 8 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-05-30 05:48:28 -0400 (Mon, 30 May 2011)
New Revision: 3204
Modified:
branches/7.4.x/api/src/main/java/org/teiid/metadata/Table.java
branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingDocument.java
branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingNode.java
branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java
branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java
branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/ContextReplacerVisitor.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/CriteriaPlanner.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLNodeMappingVisitor.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java
branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java
branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/XMLQueryResolver.java
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/xml/TestMarkExcludeVisitor.java
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/xml/TestNameInSourceResolverVisitor.java
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java
branches/7.4.x/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java
branches/7.4.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
branches/7.4.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java
Log:
TEIID-1615 adding xml pseudo groups for document model subqueries and adding several resolving and metadata improvements for xml
Modified: branches/7.4.x/api/src/main/java/org/teiid/metadata/Table.java
===================================================================
--- branches/7.4.x/api/src/main/java/org/teiid/metadata/Table.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/api/src/main/java/org/teiid/metadata/Table.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -23,8 +23,10 @@
package org.teiid.metadata;
import java.util.Collection;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import org.teiid.core.types.DataTypeManager;
import org.teiid.metadata.AbstractMetadataRecord.DataModifiable;
@@ -80,6 +82,8 @@
private transient long lastModified;
private transient long lastDataModification;
+ private transient Map<Class<?>, Object> attachments;
+
public List<String> getBindings() {
return bindings;
}
@@ -333,4 +337,46 @@
this.updatePlanEnabled = updatePlanEnabled;
}
+ /**
+ * Add attachment
+ *
+ * @param <T> the expected type
+ * @param attachment the attachment
+ * @param type the type
+ * @return any previous attachment
+ * @throws IllegalArgumentException for a null name, attachment or type
+ * @throws UnsupportedOperationException when not supported by the implementation
+ */
+ synchronized public <T> T addAttchment(Class<T> type, T attachment) {
+ if (type == null)
+ throw new IllegalArgumentException("Null type"); //$NON-NLS-1$
+ if (this.attachments == null) {
+ this.attachments = new HashMap<Class<?>, Object>();
+ }
+ Object result = this.attachments.put(type, attachment);
+ if (result == null)
+ return null;
+ return type.cast(result);
+ }
+
+ /**
+ * Get attachment
+ *
+ * @param <T> the expected type
+ * @param type the type
+ * @return the attachment or null if not present
+ * @throws IllegalArgumentException for a null name or type
+ */
+ synchronized public <T> T getAttachment(Class<T> type) {
+ if (type == null)
+ throw new IllegalArgumentException("Null type"); //$NON-NLS-1$
+ if (this.attachments == null) {
+ return null;
+ }
+ Object result = this.attachments.get(type.getName());
+ if (result == null)
+ return null;
+ return type.cast(result);
+ }
+
}
\ No newline at end of file
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingDocument.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingDocument.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingDocument.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -22,11 +22,6 @@
package org.teiid.query.mapping.xml;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
import org.teiid.core.TeiidRuntimeException;
import org.teiid.query.QueryPlugin;
@@ -160,26 +155,10 @@
/**
* @see org.teiid.query.mapping.xml.MappingNode#clone()
*/
- public Object clone() {
- // I found this as cheap way of cloneing for now fast, may be we will
- // do all the object cloneing later..
- try {
- MappingOutputter out = new MappingOutputter();
- StringWriter stream = new StringWriter();
- out.write(this, new PrintWriter(stream));
- MappingLoader loader = new MappingLoader();
- MappingDocument doc = loader.loadDocument(new ByteArrayInputStream(stream.toString().getBytes()));
-
- // Copy the values of the instance variables.
- doc.formatted = this.formatted;
- doc.encoding = this.encoding;
- doc.name = this.name;
-
- return doc;
- } catch (IOException e) {
- throw new RuntimeException(e);
- } catch(MappingException e) {
- throw new RuntimeException(e);
- }
- }
+ public MappingDocument clone() {
+ MappingDocument clone = (MappingDocument) super.clone();
+ clone.root = (MappingBaseNode) clone.getChildren().iterator().next();
+ return clone;
+ }
+
}
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingNode.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingNode.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingNode.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -31,6 +31,7 @@
import java.util.List;
import java.util.Map;
+import org.teiid.core.TeiidRuntimeException;
import org.teiid.query.QueryPlugin;
import org.teiid.query.sql.symbol.ElementSymbol;
@@ -42,14 +43,16 @@
*/
public abstract class MappingNode implements Cloneable, Serializable {
- /** The parent of this node, null if root. */
+ private static final long serialVersionUID = 6761829541871178451L;
+
+ /** The parent of this node, null if root. */
private MappingNode parent;
/** Child nodes, usually just 1 or 2, but occasionally more */
- private LinkedList children = new LinkedList();
+ private List<MappingNode> children = new LinkedList<MappingNode>();
/** node properties, as defined in NodeConstants.Properties. */
- private Map nodeProperties;
+ private Map<Integer, Object> nodeProperties;
/** default constructor */
public MappingNode(){
@@ -89,8 +92,8 @@
}
}
- for (Iterator i = root.getChildren().iterator(); i.hasNext();) {
- MappingNode child = (MappingNode)i.next();
+ for (Iterator<MappingNode> i = root.getChildren().iterator(); i.hasNext();) {
+ MappingNode child = i.next();
MappingNode found = findNode(child, partialName);
if (found != null) {
return found;
@@ -104,7 +107,7 @@
* Set the parent of this node. This method is restricted, as
* it should be called only when {@link #addChild adding a child node}
*/
- private void setParent( MappingNode parent ) {
+ void setParent( MappingNode parent ) {
this.parent = parent;
}
@@ -112,7 +115,7 @@
* Get the children contained by this node, or an empty List
* @return children; if no children, return empty List (never null)
*/
- public List getChildren(){
+ public List<MappingNode> getChildren(){
return this.children;
}
@@ -120,11 +123,11 @@
* Get all children of this node of a specified target node type. The value
* of node type should be one of {@link #ATTRIBUTE} or {@link #ELEMENT}.
*/
- public List getChildren( String type ) {
- List subset = new ArrayList();
- Iterator iter = children.iterator();
+ public List<MappingNode> getChildren( String type ) {
+ List<MappingNode> subset = new ArrayList<MappingNode>();
+ Iterator<MappingNode> iter = children.iterator();
while ( iter.hasNext() ) {
- MappingNode node = (MappingNode)iter.next();
+ MappingNode node = iter.next();
if ( node.getProperty(MappingNodeConstants.Properties.NODE_TYPE).equals(type) ) {
subset.add( node );
}
@@ -132,11 +135,11 @@
return subset;
}
- public List getNodeChildren() {
- List subset = new ArrayList();
- Iterator iter = children.iterator();
+ public List<MappingNode> getNodeChildren() {
+ List<MappingNode> subset = new ArrayList<MappingNode>();
+ Iterator<MappingNode> iter = children.iterator();
while ( iter.hasNext() ) {
- MappingNode node = (MappingNode)iter.next();
+ MappingNode node = iter.next();
if ( !node.getProperty(MappingNodeConstants.Properties.NODE_TYPE).equals(MappingNodeConstants.ATTRIBUTE) ) {
subset.add( node );
}
@@ -184,7 +187,7 @@
if (value != null){
// Get the default for the property ...
final Object defaultValue = MappingNodeConstants.Defaults.DEFAULT_VALUES.get(propertyID);
- final Map props = getNodeProperties(); // props is never null
+ final Map<Integer, Object> props = getNodeProperties(); // props is never null
if ( !value.equals(defaultValue) ) { // we know value is not null
// Set the value only if different than the default; note that the 'getProperty'
// method is returning the default if there isn't a value
@@ -209,9 +212,9 @@
* object.
* @see #getProperties
*/
- public Map getNodeProperties(){
+ public Map<Integer, Object> getNodeProperties(){
if(nodeProperties == null) {
- nodeProperties = new HashMap();
+ nodeProperties = new HashMap<Integer, Object>();
}
return nodeProperties;
}
@@ -318,9 +321,9 @@
str.append(node.getNodeProperties());
str.append("\n"); //$NON-NLS-1$
- Iterator i = node.getChildren().iterator();
+ Iterator<MappingNode> i = node.getChildren().iterator();
while (i.hasNext()){
- buildTreeString((MappingNode)i.next(), str, tabLevel);
+ buildTreeString(i.next(), str, tabLevel);
}
}
@@ -391,9 +394,9 @@
private static MappingNode traverseDownForFirstNodeWithPropertyString(Integer propertyKey, Object value, boolean isStringValue, MappingNode node, boolean breadthFirst) {
if (breadthFirst) {
- Iterator children = node.getChildren().iterator();
+ Iterator<MappingNode> children = node.getChildren().iterator();
while (children.hasNext()){
- MappingNode child = (MappingNode)children.next();
+ MappingNode child = children.next();
if (checkThisNodeForPropertyValue(propertyKey, value, isStringValue, child)){
return child;
}
@@ -404,9 +407,9 @@
}
}
- Iterator children = node.getChildren().iterator();
+ Iterator<MappingNode> children = node.getChildren().iterator();
while (children.hasNext()){
- MappingNode child = (MappingNode)children.next();
+ MappingNode child = children.next();
//recursive call to this method
MappingNode result = traverseDownForFirstNodeWithPropertyString(propertyKey, value, isStringValue, child, breadthFirst);
@@ -477,4 +480,18 @@
public String getNameInSource() {
return null;
}
+
+ public MappingNode clone() {
+ try {
+ MappingNode clone = (MappingNode) super.clone();
+ clone.children = new ArrayList<MappingNode>(children);
+ for (int i = 0; i < clone.children.size(); i++) {
+ clone.children.set(i, clone.children.get(i).clone());
+ clone.children.get(i).setParent(clone);
+ }
+ return clone;
+ } catch (CloneNotSupportedException e) {
+ throw new TeiidRuntimeException(e);
+ }
+ }
}
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -33,6 +33,7 @@
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.StringUtil;
import org.teiid.query.QueryPlugin;
import org.teiid.query.mapping.relational.QueryNode;
import org.teiid.query.mapping.xml.MappingNode;
@@ -154,6 +155,19 @@
throw new QueryMetadataException(msg);
}
+ @Override
+ public Collection getGroupsForPartialName(String partialGroupName)
+ throws TeiidComponentException, QueryMetadataException {
+ Collection groups = super.getGroupsForPartialName(partialGroupName);
+ ArrayList<String> allGroups = new ArrayList<String>(groups);
+ for (String name : tempStore.getData().keySet()) {
+ if (StringUtil.endsWithIgnoreCase(name, partialGroupName)
+ && (name.length() == partialGroupName.length() || (name.length() > partialGroupName.length() && name.charAt(name.length() - partialGroupName.length() - 1) == '.'))) {
+ allGroups.add(name);
+ }
+ }
+ return allGroups;
+ }
public Object getModelID(Object groupOrElementID)
throws TeiidComponentException, QueryMetadataException {
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -93,7 +93,8 @@
public enum Type {
VIRTUAL,
TEMP,
- SCALAR
+ SCALAR,
+ XML
}
private String ID; // never null, upper cased fully-qualified string
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -188,7 +188,7 @@
}
Table table = this.store.findGroup(elementName.substring(0, columnIndex).toUpperCase());
String shortElementName = elementName.substring(columnIndex + 1);
- for (Column column : (List<Column>)getElementIDsInGroupID(table)) {
+ for (Column column : getElementIDsInGroupID(table)) {
if (column.getName().equalsIgnoreCase(shortElementName)) {
return column;
}
@@ -256,7 +256,7 @@
return metadataRecord.getName();
}
- public List getElementIDsInGroupID(final Object groupID) throws TeiidComponentException, QueryMetadataException {
+ public List<Column> getElementIDsInGroupID(final Object groupID) throws TeiidComponentException, QueryMetadataException {
ArgCheck.isInstanceOf(Table.class, groupID);
return ((Table)groupID).getColumns();
}
@@ -710,13 +710,19 @@
ArgCheck.isInstanceOf(Table.class, groupID);
Table tableRecord = (Table) groupID;
+
+ MappingDocument mappingDoc = tableRecord.getAttachment(MappingDocument.class);
+
+ if (mappingDoc != null) {
+ return mappingDoc;
+ }
+
final String groupName = tableRecord.getFullName();
if(tableRecord.isVirtual()) {
- // get mappin transform
+ // get mapping transform
String document = tableRecord.getSelectTransformation();
InputStream inputStream = new ByteArrayInputStream(document.getBytes());
MappingLoader reader = new MappingLoader();
- MappingDocument mappingDoc = null;
try{
mappingDoc = reader.loadDocument(inputStream);
mappingDoc.setName(groupName);
@@ -727,6 +733,7 @@
inputStream.close();
} catch(Exception e) {}
}
+ tableRecord.addAttchment(MappingDocument.class, mappingDoc);
return mappingDoc;
}
@@ -757,14 +764,14 @@
/**
* @see org.teiid.query.metadata.QueryMetadataInterface#getXMLTempGroups(java.lang.Object)
*/
- public Collection getXMLTempGroups(final Object groupID) throws TeiidComponentException, QueryMetadataException {
+ public Collection<Table> getXMLTempGroups(final Object groupID) throws TeiidComponentException, QueryMetadataException {
ArgCheck.isInstanceOf(Table.class, groupID);
Table tableRecord = (Table) groupID;
if(tableRecord.getTableType() == Table.Type.Document) {
return this.store.getXMLTempGroups(tableRecord);
}
- return Collections.EMPTY_SET;
+ return Collections.emptySet();
}
public int getCardinality(final Object groupID) throws TeiidComponentException, QueryMetadataException {
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/ContextReplacerVisitor.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/ContextReplacerVisitor.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/ContextReplacerVisitor.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -41,7 +41,7 @@
*/
class ContextReplacerVisitor extends ExpressionMappingVisitor {
- private Collection contextFunctions = new LinkedList(); //contains Function objects
+ private Collection<Function> contextFunctions = new LinkedList<Function>(); //contains Function objects
/**
* Construct a new visitor
@@ -55,7 +55,7 @@
* which were stripped out of the language object by this visitor
* @return Collection of Function
*/
- Collection getContextFunctions(){
+ Collection<Function> getContextFunctions(){
return this.contextFunctions;
}
@@ -78,9 +78,9 @@
* Helper to quickly replace 'context'
* @param obj Language object
*/
- static final Collection replaceContextFunctions(LanguageObject obj) {
+ static final Collection<Function> replaceContextFunctions(LanguageObject obj) {
if (obj == null){
- return Collections.EMPTY_SET;
+ return Collections.emptySet();
}
ContextReplacerVisitor visitor = new ContextReplacerVisitor();
PreOrderNavigator.doVisit(obj, visitor);
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/CriteriaPlanner.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/CriteriaPlanner.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/CriteriaPlanner.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -64,9 +64,9 @@
static void placeUserCriteria(Criteria criteria, XMLPlannerEnvironment planEnv)
throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
- for (Iterator conjunctIter = Criteria.separateCriteriaByAnd(criteria).iterator(); conjunctIter.hasNext();) {
+ for (Iterator<Criteria> conjunctIter = Criteria.separateCriteriaByAnd(criteria).iterator(); conjunctIter.hasNext();) {
- Criteria conjunct = (Criteria) conjunctIter.next();
+ Criteria conjunct = conjunctIter.next();
if (planStagingTableCriteria(conjunct, planEnv)) {
continue;
@@ -79,11 +79,10 @@
MappingNode context = null;
- Collection contextFunctions = ContextReplacerVisitor.replaceContextFunctions(conjunct);
+ Collection<Function> contextFunctions = ContextReplacerVisitor.replaceContextFunctions(conjunct);
if (!contextFunctions.isEmpty()) {
//ensure that every part of the conjunct is to the same context
- for (Iterator i = contextFunctions.iterator(); i.hasNext();) {
- Function contextFunction = (Function)i.next();
+ for (Function contextFunction : contextFunctions) {
MappingNode otherContext = getContext(planEnv, contextFunction);
if (context == null) {
context = otherContext;
@@ -102,7 +101,7 @@
context = planEnv.mappingDoc;
}
- Set sourceNodes = collectSourceNodesInConjunct(conjunct, context, planEnv.mappingDoc);
+ Set<MappingNode> sourceNodes = collectSourceNodesInConjunct(conjunct, context, planEnv.mappingDoc);
//TODO: this can be replaced with method on the source node?
MappingSourceNode criteriaRs = findRootResultSetNode(context, sourceNodes, criteria);
@@ -118,18 +117,16 @@
/**
* This method collects all the MappingSourceNode(s) at or below the context given.
*/
- private static Set collectSourceNodesInConjunct(Criteria conjunct, MappingNode context, MappingDocument mappingDoc)
+ private static Set<MappingNode> collectSourceNodesInConjunct(Criteria conjunct, MappingNode context, MappingDocument mappingDoc)
throws QueryPlannerException {
- Collection elements = ElementCollectorVisitor.getElements(conjunct, true);
- Set resultSets = new HashSet();
+ Collection<ElementSymbol> elements = ElementCollectorVisitor.getElements(conjunct, true);
+ Set<MappingNode> resultSets = new HashSet<MappingNode>();
String contextFullName = context.getFullyQualifiedName().toUpperCase();
//validate that each element's group is under the current context or is in the direct parentage
- for (Iterator i = elements.iterator(); i.hasNext();) {
- ElementSymbol elementSymbol = (ElementSymbol)i.next();
-
+ for (ElementSymbol elementSymbol : elements) {
String elementFullName = elementSymbol.getCanonicalName();
MappingNode node = MappingNode.findNode(mappingDoc, elementFullName);
@@ -158,20 +155,16 @@
return resultSets;
}
- private static MappingSourceNode findRootResultSetNode(MappingNode context, Set resultSets, Criteria criteria)
+ private static MappingSourceNode findRootResultSetNode(MappingNode context, Set<MappingNode> resultSets, Criteria criteria)
throws QueryPlannerException {
if (context instanceof MappingSourceNode) {
return (MappingSourceNode)context;
}
- Set criteriaResultSets = new HashSet();
+ Set<MappingNode> criteriaResultSets = new HashSet<MappingNode>();
// if the context node is not the root node then we need to find the root source node from list.
- for (Iterator i = resultSets.iterator(); i.hasNext();) {
-
- // these are actually source nodes.
- MappingNode node = (MappingNode)i.next();
-
+ for (MappingNode node : resultSets) {
MappingNode root = node;
while (node != null) {
@@ -288,14 +281,13 @@
static String getStagingTableForConjunct(Criteria conjunct, QueryMetadataInterface metadata)
throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
- Collection elements = ElementCollectorVisitor.getElements(conjunct, true);
+ Collection<ElementSymbol> elements = ElementCollectorVisitor.getElements(conjunct, true);
boolean first = true;
String resultSet = null;
// Check each remaining element to make sure it matches
- for(Iterator elemIter = elements.iterator(); elemIter.hasNext();) {
- ElementSymbol element = (ElementSymbol) elemIter.next();
+ for (ElementSymbol element : elements) {
GroupSymbol group = element.getGroupSymbol();
//assumes that all non-xml group elements are temp elements
boolean hasTempElement = !metadata.isXMLGroup(group.getMetadataID());
@@ -314,7 +306,7 @@
}
if (resultSet != null) {
- Collection functions = ContextReplacerVisitor.replaceContextFunctions(conjunct);
+ Collection<Function> functions = ContextReplacerVisitor.replaceContextFunctions(conjunct);
if (!functions.isEmpty()) {
throw new QueryPlannerException(QueryPlugin.Util.getString("CriteriaPlanner.staging_context")); //$NON-NLS-1$
}
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -229,7 +229,7 @@
throws QueryMetadataException, TeiidComponentException, QueryPlannerException {
// get elements in the old group
- List elements = ResolverUtil.resolveElementsInGroup(oldSymbol, planEnv.getGlobalMetadata());
+ List<ElementSymbol> elements = ResolverUtil.resolveElementsInGroup(oldSymbol, planEnv.getGlobalMetadata());
TempMetadataStore store = planEnv.getGlobalMetadata().getMetadataStore();
@@ -280,7 +280,7 @@
}
}
- private boolean canRaiseInputset(Command command, Collection<ElementSymbol> bindings) throws TeiidComponentException {
+ private boolean canRaiseInputset(Command command, Collection<ElementSymbol> bindings) {
// check to see if this is query.
if (!(command instanceof Query)) {
return false;
@@ -311,14 +311,13 @@
* @param criteria - criteria on which the elements need to modified
* @return true if converted; false otherwise
*/
- private boolean convertCriteria(GroupSymbol newGroupSymbol, Query transformationQuery, Criteria criteria, TempMetadataAdapter metadata, Map symbolMap)
- throws QueryMetadataException, TeiidComponentException {
+ private boolean convertCriteria(GroupSymbol newGroupSymbol, Query transformationQuery, Criteria criteria, TempMetadataAdapter metadata, Map symbolMap) {
String groupName = newGroupSymbol.getName();
Collection<ElementSymbol> elementsInCriteria = ElementCollectorVisitor.getElements(criteria, true);
- Map mappedElements = new HashMap();
+ Map<ElementSymbol, ElementSymbol> mappedElements = new HashMap<ElementSymbol, ElementSymbol>();
- List projectedSymbols = transformationQuery.getProjectedSymbols();
+ List<SingleElementSymbol> projectedSymbols = transformationQuery.getProjectedSymbols();
boolean addedProjectedSymbol = false;
@@ -383,10 +382,8 @@
* If the element has alias wrapping, then return the matching alias element.
* @return matched alias symbol; null otherwise.
*/
- private AliasSymbol getMachingAlias(List elementsInGroup, ElementSymbol symbol) {
-
- for(Iterator i = elementsInGroup.iterator(); i.hasNext();) {
- final SingleElementSymbol element = (SingleElementSymbol)i.next();
+ private AliasSymbol getMachingAlias(List<SingleElementSymbol> elementsInGroup, ElementSymbol symbol) {
+ for (SingleElementSymbol element : elementsInGroup) {
if (element instanceof AliasSymbol) {
AliasSymbol alias = (AliasSymbol)element;
if (alias.getSymbol().equals(symbol)) {
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLNodeMappingVisitor.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLNodeMappingVisitor.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLNodeMappingVisitor.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -26,15 +26,20 @@
import org.teiid.api.exception.query.QueryPlannerException;
import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidException;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.query.QueryPlugin;
import org.teiid.query.mapping.xml.MappingDocument;
import org.teiid.query.mapping.xml.MappingNode;
+import org.teiid.query.mapping.xml.MappingSourceNode;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TempMetadataID;
+import org.teiid.query.resolver.util.ResolverVisitor;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.navigator.PreOrderNavigator;
+import org.teiid.query.sql.navigator.PreOrPostOrderNavigator;
import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.Symbol;
import org.teiid.query.sql.visitor.AbstractSymbolMappingVisitor;
@@ -62,29 +67,56 @@
* @see AbstractSymbolMappingVisitor#getMappedSymbol(Symbol)
*/
protected Symbol getMappedSymbol(Symbol symbol) {
- if(!(symbol instanceof ElementSymbol)) {
- return null;
- }
-
- // Lookup full path to mapping node from symbol
- ElementSymbol element = (ElementSymbol) symbol;
-
try {
- String path = metadata.getFullName(element.getMetadataID()).toUpperCase();
-
+ Object metadataId = null;
+ Object groupId = null;
+ if (symbol instanceof GroupSymbol) {
+ GroupSymbol groupSymbol = (GroupSymbol)symbol;
+ metadataId = groupSymbol.getMetadataID();
+ groupId = metadataId;
+ } else {
+ ElementSymbol element = (ElementSymbol) symbol;
+ metadataId = element.getMetadataID();
+ groupId = element.getGroupSymbol().getMetadataID();
+ }
+ boolean xml = metadata.isXMLGroup(groupId);
+ if (!xml && !((groupId instanceof TempMetadataID) && ((TempMetadataID)groupId).getMetadataType() == TempMetadataID.Type.XML)) {
+ return symbol;
+ }
+ String path = metadata.getFullName(metadataId).toUpperCase();
+
// Find mapping node for specified path
- MappingNode elementNode = MappingNode.findNode(rootNode, path);
- if(elementNode == null) {
+ MappingNode node = MappingNode.findNode(rootNode, path);
+ if(node == null) {
return null;
}
-
+ MappingSourceNode msn = node.getSourceNode();
+ if (msn == null) {
+ return null;
+ }
+ if (symbol instanceof GroupSymbol) {
+ GroupSymbol gs = msn.getMappedSymbol(new GroupSymbol(msn.getResultName()));
+ if (!xml && gs.getMetadataID() == null) {
+ ResolverVisitor.resolveLanguageObject(gs, metadata);
+ }
+ return gs;
+ }
// Construct a new element node based on mapping node reference
- String symbolName = elementNode.getNameInSource();
+ String symbolName = node.getNameInSource();
if (symbolName == null){
return null;
}
- return elementNode.getSourceNode().getMappedSymbol(new ElementSymbol(symbolName));
- } catch (TeiidComponentException err) {
+ ElementSymbol es = msn.getMappedSymbol(new ElementSymbol(symbolName));
+ if (!xml) {
+ if (((ElementSymbol)symbol).isExternalReference()) {
+ es.setIsExternalReference(true);
+ }
+ if (es.getMetadataID() == null) {
+ ResolverVisitor.resolveLanguageObject(es, metadata);
+ }
+ }
+ return es;
+ } catch (TeiidException err) {
throw new TeiidRuntimeException(err);
}
}
@@ -100,17 +132,15 @@
*/
public static Criteria convertCriteria(Criteria simpleCrit, MappingDocument rootNode, QueryMetadataInterface metadata)
throws QueryPlannerException, TeiidComponentException{
- return (Criteria)convertObject(simpleCrit, rootNode, metadata);
+ return convertObject((Criteria)simpleCrit.clone(), rootNode, metadata, true);
}
- public static LanguageObject convertObject(LanguageObject object, MappingDocument rootNode, QueryMetadataInterface metadata)
+ public static <T extends LanguageObject> T convertObject(T object, MappingDocument rootNode, QueryMetadataInterface metadata, boolean deep)
throws QueryPlannerException, TeiidComponentException{
- LanguageObject copy = (LanguageObject)object.clone();
-
//Don't want to do deep visiting
XMLNodeMappingVisitor mappingVisitor = new XMLNodeMappingVisitor(rootNode, metadata);
try {
- PreOrderNavigator.doVisit(copy, mappingVisitor);
+ PreOrPostOrderNavigator.doVisit(object, mappingVisitor, PreOrPostOrderNavigator.PRE_ORDER, deep);
} catch (TeiidRuntimeException e) {
Throwable child = e.getChild();
@@ -126,7 +156,7 @@
throw new QueryPlannerException("ERR.015.004.0046", QueryPlugin.Util.getString("ERR.015.004.0046", new Object[] {unmappedSymbols, object})); //$NON-NLS-1$ //$NON-NLS-2$
}
- return copy;
+ return object;
}
}
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -57,6 +57,7 @@
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.SelectSymbol;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.sql.visitor.ElementCollectorVisitor;
import org.teiid.query.util.CommandContext;
@@ -110,7 +111,7 @@
GroupSymbol group = xmlQuery.getFrom().getGroups().iterator().next();
MappingDocument doc = (MappingDocument)metadata.getMappingNode(group.getMetadataID());
- doc = (MappingDocument)doc.clone();
+ doc = doc.clone();
// make a copy of the document
planEnv.mappingDoc = doc;
@@ -247,10 +248,9 @@
}
// Get all the valid nodes to be marked as included.
- Collection validElements = ElementCollectorVisitor.getElements(select, true);
- HashSet elements = new HashSet(validElements.size());
- for (final Iterator i = validElements.iterator(); i.hasNext();) {
- final ElementSymbol element = (ElementSymbol)i.next();
+ Collection<ElementSymbol> validElements = ElementCollectorVisitor.getElements(select, true);
+ HashSet<String> elements = new HashSet<String>(validElements.size());
+ for (ElementSymbol element : validElements) {
elements.add(element.getCanonicalName());
}
@@ -277,8 +277,8 @@
return;
}
- List elements = orderBy.getSortKeys();
- List types = orderBy.getTypes();
+ List<SingleElementSymbol> elements = orderBy.getSortKeys();
+ List<Boolean> types = orderBy.getTypes();
for (int i = 0; i< elements.size(); i++) {
ElementSymbol elemSymbol = (ElementSymbol) elements.get(i);
@@ -301,7 +301,7 @@
by = new OrderBy();
}
ElementSymbol mappedSymbol = (ElementSymbol)sourceNode.getSymbolMap().get(new ElementSymbol(elementNode.getNameInSource()));
- by.addVariable((ElementSymbol)mappedSymbol.clone(), ((Boolean)types.get(i)).booleanValue());
+ by.addVariable(mappedSymbol.clone(), ((Boolean)types.get(i)).booleanValue());
rs.setOrderBy(by);
}
}
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -86,10 +86,8 @@
public void visit(MappingBaseNode baseNode) {
try {
// first if there are any explicit staging tables plan them first
- List stagingTables = baseNode.getStagingTables();
- for (final Iterator i = stagingTables.iterator(); i.hasNext();) {
-
- final String tableName = (String)i.next();
+ List<String> stagingTables = baseNode.getStagingTables();
+ for (String tableName : stagingTables) {
planStagingTable(tableName, planEnv);
}
@@ -206,15 +204,15 @@
static void prepareQuery(MappingSourceNode sourceNode, XMLPlannerEnvironment planEnv, QueryCommand rsQuery)
throws TeiidComponentException, QueryResolverException {
- Collection externalGroups = getExternalGroups(sourceNode);
+ Collection<GroupSymbol> externalGroups = getExternalGroups(sourceNode);
rsQuery.setExternalGroupContexts(new GroupContext(null, externalGroups));
QueryResolver.resolveCommand(rsQuery, planEnv.getGlobalMetadata());
}
- private static Collection getExternalGroups(MappingSourceNode sourceNode) {
- Collection externalGroups = new HashSet();
+ private static Collection<GroupSymbol> getExternalGroups(MappingSourceNode sourceNode) {
+ Collection<GroupSymbol> externalGroups = new HashSet<GroupSymbol>();
MappingSourceNode parentSource = sourceNode.getParentSourceNode();
while (parentSource != null) {
@@ -249,12 +247,12 @@
return singleParentage;
}
- private static LinkedList getResultSetStack(MappingSourceNode contextNode, MappingBaseNode node) {
- LinkedList rsStack = new LinkedList();
+ private static LinkedList<MappingSourceNode> getResultSetStack(MappingSourceNode contextNode, MappingBaseNode node) {
+ LinkedList<MappingSourceNode> rsStack = new LinkedList<MappingSourceNode>();
while (node != null && node != contextNode) {
if (node instanceof MappingSourceNode) {
- rsStack.add(0, node);
+ rsStack.add(0, (MappingSourceNode)node);
}
node = node.getParentNode();
}
@@ -312,7 +310,7 @@
joinCriteria = (Criteria)joinCriteria.clone();
//update the from clause
- FromClause clause = (FromClause)currentQuery.getFrom().getClauses().remove(0);
+ FromClause clause = currentQuery.getFrom().getClauses().remove(0);
JoinPredicate join = null;
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -134,7 +134,7 @@
//check for already staged queries
if (groups.size() == 1) {
GroupSymbol group = groups.iterator().next();
- group = QueryUtil.createResolvedGroup((GroupSymbol)group.clone(), planEnv.getGlobalMetadata());
+ group = QueryUtil.createResolvedGroup(group.clone(), planEnv.getGlobalMetadata());
if (planEnv.isStagingTable(group.getMetadataID()) && stagableQuery.getCriteria() == null) {
return false;
}
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -127,7 +127,7 @@
ResolverUtil.resolveOrderBy(query.getOrderBy(), query, metadata);
}
- List symbols = query.getSelect().getProjectedSymbols();
+ List<SingleElementSymbol> symbols = query.getSelect().getProjectedSymbols();
if (query.getInto() != null) {
GroupSymbol symbol = query.getInto().getGroup();
@@ -281,7 +281,7 @@
// Look for elements that are not selectable and remove them
for (ElementSymbol element : elements) {
if(metadata.elementSupports(element.getMetadataID(), SupportConstants.Element.SELECT)) {
- element = (ElementSymbol)element.clone();
+ element = element.clone();
element.setGroupSymbol(group);
result.add(element);
}
@@ -368,6 +368,9 @@
}
}
+ /**
+ * @param tfr
+ */
public LinkedHashSet<GroupSymbol> preTableFunctionReference(TableFunctionReference tfr) {
LinkedHashSet<GroupSymbol> saved = new LinkedHashSet<GroupSymbol>(this.currentGroups);
if (allowImplicit) {
@@ -571,7 +574,7 @@
public void visit(From obj) {
assert currentGroups.isEmpty();
- for (FromClause clause : (List<FromClause>)obj.getClauses()) {
+ for (FromClause clause : obj.getClauses()) {
checkImplicit(clause);
}
super.visit(obj);
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/XMLQueryResolver.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/XMLQueryResolver.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/XMLQueryResolver.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -25,26 +25,35 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.Iterator;
+import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.core.TeiidComponentException;
-import org.teiid.core.util.StringUtil;
import org.teiid.query.QueryPlugin;
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingNode;
+import org.teiid.query.mapping.xml.MappingSourceNode;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.TempMetadataAdapter;
+import org.teiid.query.metadata.TempMetadataID.Type;
+import org.teiid.query.optimizer.xml.SourceNodeGenaratorVisitor;
import org.teiid.query.resolver.CommandResolver;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.resolver.util.ResolverVisitor;
+import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Criteria;
import org.teiid.query.sql.lang.GroupContext;
import org.teiid.query.sql.lang.OrderBy;
import org.teiid.query.sql.lang.Query;
import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.lang.SubqueryContainer;
import org.teiid.query.sql.symbol.AliasSymbol;
import org.teiid.query.sql.symbol.AllInGroupSymbol;
import org.teiid.query.sql.symbol.AllSymbol;
@@ -52,16 +61,57 @@
import org.teiid.query.sql.symbol.ExpressionSymbol;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.SelectSymbol;
-import org.teiid.query.sql.visitor.CommandCollectorVisitor;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.sql.visitor.ElementCollectorVisitor;
import org.teiid.query.sql.visitor.GroupCollectorVisitor;
+import org.teiid.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
/**
*/
public class XMLQueryResolver implements CommandResolver {
+
+ private static final class ResolvingNode {
+ ElementSymbol elementSymbol;
+ TreeMap<String, ResolvingNode> children = new TreeMap<String, ResolvingNode>(String.CASE_INSENSITIVE_ORDER);
+
+ public void add(String name, ElementSymbol symbol) {
+ if (name == null) {
+ this.elementSymbol = symbol;
+ return;
+ }
+ int index = name.lastIndexOf('.');
+ String childName = name;
+ if (index >= 0) {
+ childName = name.substring(0, index);
+ name = name.substring(index + 1, name.length());
+ } else {
+ childName = null;
+ }
+ ResolvingNode child = children.get(name);
+ if (child == null) {
+ child = new ResolvingNode();
+ children.put(name, child);
+ }
+ child.add(childName, symbol);
+ }
+
+ public <T extends Collection<ElementSymbol>> T values(T values) {
+ if (elementSymbol != null) {
+ values.add(elementSymbol);
+ }
+ for (ResolvingNode node : children.values()) {
+ node.values(values);
+ }
+ return values;
+ }
+
+ public List<ElementSymbol> values() {
+ return values(new LinkedList<ElementSymbol>());
+ }
+ }
- /**
+ /**
* @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, TempMetadataAdapter, boolean)
*/
public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals)
@@ -80,31 +130,41 @@
GroupContext externalGroups = query.getExternalGroupContexts();
// valid elements for select
- List<ElementSymbol> validSelectElems = getElementsInDocument(group, metadata);
- resolveXMLSelect(query, group, validSelectElems, metadata);
+ List<ElementSymbol> validSelectElems = ResolverUtil.resolveElementsInGroup(group, metadata);
+ ResolvingNode root = new ResolvingNode();
+ for (ElementSymbol elementSymbol : validSelectElems) {
+ root.add(elementSymbol.getName(), elementSymbol);
+ }
+ resolveXMLSelect(query, group, root, metadata);
// valid elements for criteria and order by
- Collection<ElementSymbol> validCriteriaElements = collectValidCriteriaElements(group, metadata);
+ Collection<ElementSymbol> validCriteriaElements = collectTempElements(group, metadata);
+ for (ElementSymbol elementSymbol : validCriteriaElements) {
+ root.add(elementSymbol.getName(), elementSymbol);
+ }
Criteria crit = query.getCriteria();
OrderBy orderBy = query.getOrderBy();
-
- List<Command> commands = CommandCollectorVisitor.getCommands(query);
- for (Command subCommand : commands) {
- QueryResolver.setChildMetadata(subCommand, command);
-
- QueryResolver.resolveCommand(subCommand, metadata.getMetadata());
- }
-
+
if(crit != null) {
- resolveXMLCriteria(crit, externalGroups, validCriteriaElements, metadata);
+ List<SubqueryContainer> commands = ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(crit);
+ if (!commands.isEmpty()) {
+ addPseudoSubqueryGroups(metadata, group, validSelectElems);
+ for (SubqueryContainer subCommand : commands) {
+ QueryResolver.setChildMetadata(subCommand.getCommand(), command);
+
+ QueryResolver.resolveCommand(subCommand.getCommand(), metadata.getMetadata());
+ }
+ }
+
+ resolveXMLCriteria(crit, externalGroups, root, metadata);
// Resolve functions in current query
ResolverVisitor.resolveLanguageObject(crit, metadata);
}
// resolve any orderby specified on the query
if(orderBy != null) {
- resolveXMLOrderBy(orderBy, externalGroups, validCriteriaElements, metadata);
+ resolveXMLOrderBy(orderBy, externalGroups, root, metadata);
}
//we throw exceptions in these cases, since the clauses will not be resolved
@@ -117,6 +177,62 @@
}
}
+ private void addPseudoSubqueryGroups(TempMetadataAdapter metadata,
+ GroupSymbol group, List<ElementSymbol> validSelectElems)
+ throws TeiidComponentException, QueryMetadataException,
+ QueryResolverException {
+ /*
+ * The next section of resolving logic adds in pseduo groups that can be used
+ * in subqueries
+ */
+ MappingDocument doc = (MappingDocument) metadata.getMappingNode(group.getMetadataID());
+ doc = doc.clone();
+ doc = SourceNodeGenaratorVisitor.extractSourceNodes(doc);
+
+ HashMap<String, List<ElementSymbol>> psuedoGroups = new HashMap<String, List<ElementSymbol>>();
+ for (ElementSymbol elementSymbol : validSelectElems) {
+ MappingNode node = MappingNode.findNode(doc, elementSymbol.getCanonicalName());
+ if (node == null) {
+ continue;
+ }
+ MappingSourceNode mappingSourceNode = node.getSourceNode();
+ if (mappingSourceNode == null) {
+ continue;
+ }
+ String mappingClass = mappingSourceNode.getSource();
+ String tableName = SingleElementSymbol.getShortName(mappingClass);
+
+ String name = elementSymbol.getName();
+ int index = name.lastIndexOf('.');
+ String xmlTableName = name.substring(0, index);
+ if (!xmlTableName.endsWith(tableName)) {
+ continue;
+ }
+ List<ElementSymbol> elements = psuedoGroups.get(xmlTableName);
+ if (elements == null) {
+ elements = new ArrayList<ElementSymbol>();
+ psuedoGroups.put(xmlTableName, elements);
+ }
+ ElementSymbol es = new ElementSymbol(name.substring(index+1, name.length()));
+ es.setType(elementSymbol.getType());
+ es.setMetadataID(elementSymbol.getMetadataID());
+ elements.add(es);
+ }
+
+ for (Map.Entry<String, List<ElementSymbol>> entry : psuedoGroups.entrySet()) {
+ for (ElementSymbol elem : new ArrayList<ElementSymbol>(entry.getValue())) {
+ if (elem.getName().charAt(0) == '@') {
+ ElementSymbol alias = elem.clone();
+ alias.setShortName(elem.getName().substring(1));
+ if (!entry.getValue().contains(alias)) {
+ entry.getValue().add(alias);
+ }
+ }
+ }
+ ResolverUtil.addTempGroup(metadata, new GroupSymbol(entry.getKey()), entry.getValue(), false).setMetadataType(Type.XML);
+ }
+ }
+
/**
* Method resolveXMLSelect.
* @param select Select clause in user command
@@ -128,7 +244,7 @@
* @throws QueryMetadataException if resolving fails
* @throws TeiidComponentException if resolving fails
*/
- void resolveXMLSelect(Query query, GroupSymbol group, List<ElementSymbol> validElements, QueryMetadataInterface metadata)
+ void resolveXMLSelect(Query query, GroupSymbol group, ResolvingNode validElements, QueryMetadataInterface metadata)
throws QueryMetadataException, TeiidComponentException, QueryResolverException {
GroupContext externalGroups = null;
@@ -159,7 +275,7 @@
}
select.clearSymbols();
AllSymbol all = new AllSymbol();
- all.setElementSymbols(validElements);
+ all.setElementSymbols(validElements.values());
select.addSymbol(all);
query.setSelect(select);
return;
@@ -177,7 +293,7 @@
if(elementPart.equalsIgnoreCase(group.getName())) {
select.clearSymbols();
AllSymbol all = new AllSymbol();
- all.setElementSymbols(validElements);
+ all.setElementSymbols(validElements.values());
select.addSymbol(all);
query.setSelect(select);
} else {
@@ -186,12 +302,12 @@
resolveElement(elementSymbol, validElements, externalGroups, metadata);
// now find all the elements under this node and set as elements.
- List<ElementSymbol> elementsInNode = getElementsUnderNode(elementSymbol, validElements, metadata);
+ List<ElementSymbol> elementsInNode = getElementsUnderNode(elementSymbol, validElements.values(), metadata);
((AllInGroupSymbol)ss).setElementSymbols(elementsInNode);
}
} else if (ss instanceof AllSymbol) {
AllSymbol all = (AllSymbol)ss;
- all.setElementSymbols(validElements);
+ all.setElementSymbols(validElements.values());
return;
} else if (ss instanceof ExpressionSymbol) {
throw new QueryResolverException(QueryPlugin.Util.getString("XMLQueryResolver.no_expressions_in_select")); //$NON-NLS-1$
@@ -202,30 +318,12 @@
}
}
- /**
- * Collect all fully-qualified valid elements. These can then be used to
- * validate elements used in the query. It's easier to look up the valid
- * elements because the user is allow to used any partially-qualified name,
- * which makes the logic for doing lookups essentially impossible with the
- * existing metadata interface.
- * @param group Document group
- * @param metadata Metadata interface
- * @return Collection of ElementSymbol for each possible valid element
- * @throws QueryMetadataException
- * @throws TeiidComponentException
- * @throws QueryResolverException
- */
- public static Collection<ElementSymbol> collectValidCriteriaElements(GroupSymbol group, QueryMetadataInterface metadata)
- throws QueryMetadataException, TeiidComponentException, QueryResolverException {
-
- // Get all groups and elements
- List<ElementSymbol> validElements = getElementsInDocument(group, metadata);
-
+ public static Collection<ElementSymbol> collectTempElements(GroupSymbol group, QueryMetadataInterface metadata)
+ throws QueryMetadataException, TeiidComponentException {
+ ArrayList<ElementSymbol> validElements = new ArrayList<ElementSymbol>();
// Create GroupSymbol for temp groups and add to groups
- Collection tempGroups = metadata.getXMLTempGroups(group.getMetadataID());
- Iterator tempGroupIter = tempGroups.iterator();
- while(tempGroupIter.hasNext()) {
- Object tempGroupID = tempGroupIter.next();
+ Collection<?> tempGroups = metadata.getXMLTempGroups(group.getMetadataID());
+ for (Object tempGroupID : tempGroups) {
String name = metadata.getFullName(tempGroupID);
GroupSymbol tempGroup = new GroupSymbol(name);
tempGroup.setMetadataID(tempGroupID);
@@ -235,7 +333,6 @@
return validElements;
}
-
/**
* <p> Resolve the criteria specified on the XML query. The elements specified on the criteria should
* be present on one of the mapping node objects passed to this method, or else be an element on a
@@ -255,7 +352,7 @@
* @param metadata QueryMetadataInterface the metadata(for resolving criteria on temp groups)
* @throws QueryResolverException if any of the above fail conditions are met
*/
- public static void resolveXMLCriteria(Criteria criteria,GroupContext externalGroups, Collection<ElementSymbol> validElements, QueryMetadataInterface metadata)
+ public static void resolveXMLCriteria(LanguageObject criteria,GroupContext externalGroups, ResolvingNode validElements, QueryMetadataInterface metadata)
throws QueryMetadataException, TeiidComponentException, QueryResolverException {
// Walk through each element in criteria and check against valid elements
@@ -278,7 +375,7 @@
* @throws QueryMetadataException if resolving fails
* @throws TeiidComponentException if resolving fails
*/
- static void resolveXMLOrderBy(OrderBy orderBy, GroupContext externalGroups, Collection<ElementSymbol> validElements, QueryMetadataInterface metadata)
+ static void resolveXMLOrderBy(OrderBy orderBy, GroupContext externalGroups, ResolvingNode validElements, QueryMetadataInterface metadata)
throws QueryMetadataException, TeiidComponentException, QueryResolverException {
// Walk through each element in OrderBy clause and check against valid elements
@@ -298,100 +395,62 @@
* @throws QueryMetadataException
* @throws TeiidComponentException
*/
- static void resolveElement(ElementSymbol elem, Collection<ElementSymbol> validElements, GroupContext externalGroups, QueryMetadataInterface metadata)
+ static void resolveElement(ElementSymbol elem, ResolvingNode validElements, GroupContext externalGroups, QueryMetadataInterface metadata)
throws QueryResolverException, QueryMetadataException, TeiidComponentException {
// Get exact matching name
- String critElemName = elem.getName();
- String critElemNameSuffix = "." + elem.getCanonicalName(); //$NON-NLS-1$
+ String partialName = elem.getName();
+ String fullName = partialName;
- // Prepare results
- ElementSymbol exactMatch = null;
- List<ElementSymbol> partialMatches = new ArrayList<ElementSymbol>(2); // anything over 1 is an error and should be rare
+ ResolvingNode current = validElements;
+ String part = partialName;
+ for (int i = 0; partialName != null; i++) {
+ int index = partialName.lastIndexOf('.');
+ if (index < 0) {
+ part = partialName;
+ partialName = null;
+ } else {
+ part = partialName.substring(index + 1, partialName.length());
+ partialName = partialName.substring(0, index);
+ }
+ current = current.children.get(part);
+ if (current == null) {
+ if (i == 0 && part.charAt(0) != '@') {
+ //handle attribute case
+ part = '@' + part;
+ current = validElements.children.get(part);
+ if (current != null) {
+ continue;
+ }
+ }
+ try {
+ ResolverVisitor.resolveLanguageObject(elem, Collections.EMPTY_LIST, externalGroups, metadata);
+ return;
+ } catch (QueryResolverException e) {
+ throw new QueryResolverException(e, "ERR.015.008.0019", QueryPlugin.Util.getString("ERR.015.008.0019", fullName)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ }
- //List of XML attributes that might match the criteria element,
- //if the criteria is specified without the optional "@" sign
- List<ElementSymbol> attributeMatches = new ArrayList<ElementSymbol>(2);
+ List<ElementSymbol> partialMatches = current.values();
- // look up name based on ID match - will work for uuid version
- try {
+ if (partialMatches.size() != 1) {
+ // Found multiple matches
+ throw new QueryResolverException("ERR.015.008.0020", QueryPlugin.Util.getString("ERR.015.008.0020", fullName)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
- Object elementID = metadata.getElementID(critElemName);
-
- if(elementID != null) {
- critElemName = metadata.getFullName(elementID);
- }
- } catch(QueryMetadataException e) {
- //e.printStackTrace();
- // ignore and go on
- }
-
- // Walk through each valid element looking for a match
- for (ElementSymbol currentElem : validElements) {
- // Look for exact match
- if(currentElem.getName().equalsIgnoreCase(critElemName)) {
- exactMatch = currentElem;
- break;
- }
-
- if(currentElem.getName().toUpperCase().endsWith(critElemNameSuffix)) {
- partialMatches.add(currentElem);
- } else {
- // The criteria element might be referring to an
- // XML attribute, but might not have the optional
- // "@" sign
- String currentElemName = currentElem.getName();
- int atSignIndex = currentElemName.indexOf("@"); //$NON-NLS-1$
- if (atSignIndex != -1){
- currentElemName = StringUtil.replace(currentElemName, "@", ""); //$NON-NLS-1$ //$NON-NLS-2$
- if(currentElemName.equalsIgnoreCase(critElemName)) {
- attributeMatches.add(currentElem);
- } else {
- currentElemName = currentElemName.toUpperCase();
- if(currentElemName.endsWith(critElemNameSuffix)) {
- attributeMatches.add(currentElem);
- }
- }
- }
- }
- }
-
- // Check for single partial match
- if(exactMatch == null){
- if (partialMatches.size() == 1) {
- exactMatch = partialMatches.get(0);
- } else if (partialMatches.size() == 0 && attributeMatches.size() == 1){
- exactMatch = attributeMatches.get(0);
- }
- }
-
- if(exactMatch != null) {
- String name = elem.getOutputName();
- // Resolve based on exact match
- elem.setShortName(exactMatch.getShortName());
- elem.setShortCanonicalName(exactMatch.getShortCanonicalName());
- elem.setMetadataID(exactMatch.getMetadataID());
- elem.setType(exactMatch.getType());
- elem.setGroupSymbol(exactMatch.getGroupSymbol());
- elem.setOutputName(name);
- } else if(partialMatches.size() == 0 && attributeMatches.size() == 0){
- try {
- ResolverVisitor.resolveLanguageObject(elem, Collections.EMPTY_LIST, externalGroups, metadata);
- } catch (QueryResolverException e) {
- throw new QueryResolverException(e, "ERR.015.008.0019", QueryPlugin.Util.getString("ERR.015.008.0019", critElemName)); //$NON-NLS-1$ //$NON-NLS-2$
- }
- } else {
- // Found multiple matches
- throw new QueryResolverException("ERR.015.008.0020", QueryPlugin.Util.getString("ERR.015.008.0020", critElemName)); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ ElementSymbol exactMatch = partialMatches.get(0);
+ String name = elem.getOutputName();
+ // Resolve based on exact match
+ elem.setShortName(exactMatch.getShortName());
+ elem.setShortCanonicalName(exactMatch.getShortCanonicalName());
+ elem.setMetadataID(exactMatch.getMetadataID());
+ elem.setType(exactMatch.getType());
+ elem.setGroupSymbol(exactMatch.getGroupSymbol());
+ elem.setOutputName(name);
}
- static List<ElementSymbol> getElementsInDocument(GroupSymbol group, QueryMetadataInterface metadata)
- throws QueryMetadataException, TeiidComponentException {
- return ResolverUtil.resolveElementsInGroup(group, metadata);
- }
-
- static List<ElementSymbol> getElementsUnderNode(ElementSymbol node, List<ElementSymbol> validElements, QueryMetadataInterface metadata)
+ static List<ElementSymbol> getElementsUnderNode(ElementSymbol node, Collection<ElementSymbol> validElements, QueryMetadataInterface metadata)
throws TeiidComponentException, QueryMetadataException {
List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/xml/TestMarkExcludeVisitor.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/xml/TestMarkExcludeVisitor.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/xml/TestMarkExcludeVisitor.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -47,11 +47,11 @@
QueryMetadataInterface metadata = TestXMLProcessor.exampleMetadataCached();
Query query = (Query)TestXMLProcessor.helpGetCommand(sql, metadata);
- Collection groups = GroupCollectorVisitor.getGroups(query, true);
- GroupSymbol group = (GroupSymbol) groups.iterator().next();
+ Collection<GroupSymbol> groups = GroupCollectorVisitor.getGroups(query, true);
+ GroupSymbol group = groups.iterator().next();
MappingDocument docOrig = (MappingDocument)metadata.getMappingNode(metadata.getGroupID(group.getName()));
- MappingDocument doc = (MappingDocument)docOrig.clone();
+ MappingDocument doc = docOrig.clone();
doc = XMLPlanner.preMarkExcluded(query, doc);
XMLPlanner.removeExcluded(doc);
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/xml/TestNameInSourceResolverVisitor.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/xml/TestNameInSourceResolverVisitor.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/xml/TestNameInSourceResolverVisitor.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -63,7 +63,7 @@
GroupSymbol group = groups.iterator().next();
MappingDocument docOrig = (MappingDocument)metadata.getMappingNode(metadata.getGroupID(group.getName()));
- MappingDocument doc = (MappingDocument)docOrig.clone();
+ MappingDocument doc = docOrig.clone();
XMLPlannerEnvironment env = new XMLPlannerEnvironment(metadata);
env.mappingDoc = doc;
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -90,7 +90,59 @@
*/
@SuppressWarnings("nls")
public class TestXMLProcessor {
- private static final boolean DEBUG = false;
+ private static final String CARDS_MANAGER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + //$NON-NLS-1$
+ "<BaseballPlayers>\r\n" + //$NON-NLS-1$
+ " <Player PlayerID=\"1001\">\r\n" + //$NON-NLS-1$
+ " <FirstName>Albert</FirstName>\r\n" + //$NON-NLS-1$
+ " <LastName>Pujols</LastName>\r\n" + //$NON-NLS-1$
+ " <Manager ManagerID=\"1004\">\r\n" + //$NON-NLS-1$
+ " <FirstName>Tony</FirstName>\r\n" + //$NON-NLS-1$
+ " <LastName>LaRussa</LastName>\r\n" + //$NON-NLS-1$
+ " <Owner OwnerID=\"1009\">\r\n" + //$NON-NLS-1$
+ " <FirstName>Bill</FirstName>\r\n" + //$NON-NLS-1$
+ " <LastName>DeWitt</LastName>\r\n" + //$NON-NLS-1$
+ " </Owner>\r\n" + //$NON-NLS-1$
+ " </Manager>\r\n" + //$NON-NLS-1$
+ " </Player>\r\n" + //$NON-NLS-1$
+ " <Player PlayerID=\"1002\">\r\n" + //$NON-NLS-1$
+ " <FirstName>Jim</FirstName>\r\n" + //$NON-NLS-1$
+ " <LastName>Edmunds</LastName>\r\n" + //$NON-NLS-1$
+ " <Manager ManagerID=\"1004\">\r\n" + //$NON-NLS-1$
+ " <FirstName>Tony</FirstName>\r\n" + //$NON-NLS-1$
+ " <LastName>LaRussa</LastName>\r\n" + //$NON-NLS-1$
+ " <Owner OwnerID=\"1009\">\r\n" + //$NON-NLS-1$
+ " <FirstName>Bill</FirstName>\r\n" + //$NON-NLS-1$
+ " <LastName>DeWitt</LastName>\r\n" + //$NON-NLS-1$
+ " </Owner>\r\n" + //$NON-NLS-1$
+ " </Manager>\r\n" + //$NON-NLS-1$
+ " </Player>\r\n" + //$NON-NLS-1$
+ " <Player PlayerID=\"1003\">\r\n" + //$NON-NLS-1$
+ " <FirstName>David</FirstName>\r\n" + //$NON-NLS-1$
+ " <LastName>Eckstein</LastName>\r\n" + //$NON-NLS-1$
+ " <Manager ManagerID=\"1004\">\r\n" + //$NON-NLS-1$
+ " <FirstName>Tony</FirstName>\r\n" + //$NON-NLS-1$
+ " <LastName>LaRussa</LastName>\r\n" + //$NON-NLS-1$
+ " <Owner OwnerID=\"1009\">\r\n" + //$NON-NLS-1$
+ " <FirstName>Bill</FirstName>\r\n" + //$NON-NLS-1$
+ " <LastName>DeWitt</LastName>\r\n" + //$NON-NLS-1$
+ " </Owner>\r\n" + //$NON-NLS-1$
+ " </Manager>\r\n" + //$NON-NLS-1$
+ " </Player>\r\n" + //$NON-NLS-1$
+ " <Player PlayerID=\"1005\">\r\n" + //$NON-NLS-1$
+ " <FirstName>Derrek</FirstName>\r\n" + //$NON-NLS-1$
+ " <LastName>Lee</LastName>\r\n" + //$NON-NLS-1$
+ " </Player>\r\n" + //$NON-NLS-1$
+ " <Player PlayerID=\"1006\">\r\n" + //$NON-NLS-1$
+ " <FirstName>Corey</FirstName>\r\n" + //$NON-NLS-1$
+ " <LastName>Patterson</LastName>\r\n" + //$NON-NLS-1$
+ " </Player>\r\n" + //$NON-NLS-1$
+ " <Player PlayerID=\"1008\">\r\n" + //$NON-NLS-1$
+ " <FirstName>Carlos</FirstName>\r\n" + //$NON-NLS-1$
+ " <LastName>Zambrano</LastName>\r\n" + //$NON-NLS-1$
+ " </Player>\r\n" + //$NON-NLS-1$
+ "</BaseballPlayers>\r\n\r\n";
+
+ private static final boolean DEBUG = false;
/**
* Construct some fake metadata. Basic conceptual tree is:
@@ -11153,63 +11205,18 @@
QueryMetadataInterface metadata = RealMetadataFactory.exampleCase3225();
FakeDataManager dataMgr = exampleDataManagerCase3225(metadata);
- String expectedDoc =
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + //$NON-NLS-1$
- "<BaseballPlayers>\r\n" + //$NON-NLS-1$
- " <Player PlayerID=\"1001\">\r\n" + //$NON-NLS-1$
- " <FirstName>Albert</FirstName>\r\n" + //$NON-NLS-1$
- " <LastName>Pujols</LastName>\r\n" + //$NON-NLS-1$
- " <Manager ManagerID=\"1004\">\r\n" + //$NON-NLS-1$
- " <FirstName>Tony</FirstName>\r\n" + //$NON-NLS-1$
- " <LastName>LaRussa</LastName>\r\n" + //$NON-NLS-1$
- " <Owner OwnerID=\"1009\">\r\n" + //$NON-NLS-1$
- " <FirstName>Bill</FirstName>\r\n" + //$NON-NLS-1$
- " <LastName>DeWitt</LastName>\r\n" + //$NON-NLS-1$
- " </Owner>\r\n" + //$NON-NLS-1$
- " </Manager>\r\n" + //$NON-NLS-1$
- " </Player>\r\n" + //$NON-NLS-1$
- " <Player PlayerID=\"1002\">\r\n" + //$NON-NLS-1$
- " <FirstName>Jim</FirstName>\r\n" + //$NON-NLS-1$
- " <LastName>Edmunds</LastName>\r\n" + //$NON-NLS-1$
- " <Manager ManagerID=\"1004\">\r\n" + //$NON-NLS-1$
- " <FirstName>Tony</FirstName>\r\n" + //$NON-NLS-1$
- " <LastName>LaRussa</LastName>\r\n" + //$NON-NLS-1$
- " <Owner OwnerID=\"1009\">\r\n" + //$NON-NLS-1$
- " <FirstName>Bill</FirstName>\r\n" + //$NON-NLS-1$
- " <LastName>DeWitt</LastName>\r\n" + //$NON-NLS-1$
- " </Owner>\r\n" + //$NON-NLS-1$
- " </Manager>\r\n" + //$NON-NLS-1$
- " </Player>\r\n" + //$NON-NLS-1$
- " <Player PlayerID=\"1003\">\r\n" + //$NON-NLS-1$
- " <FirstName>David</FirstName>\r\n" + //$NON-NLS-1$
- " <LastName>Eckstein</LastName>\r\n" + //$NON-NLS-1$
- " <Manager ManagerID=\"1004\">\r\n" + //$NON-NLS-1$
- " <FirstName>Tony</FirstName>\r\n" + //$NON-NLS-1$
- " <LastName>LaRussa</LastName>\r\n" + //$NON-NLS-1$
- " <Owner OwnerID=\"1009\">\r\n" + //$NON-NLS-1$
- " <FirstName>Bill</FirstName>\r\n" + //$NON-NLS-1$
- " <LastName>DeWitt</LastName>\r\n" + //$NON-NLS-1$
- " </Owner>\r\n" + //$NON-NLS-1$
- " </Manager>\r\n" + //$NON-NLS-1$
- " </Player>\r\n" + //$NON-NLS-1$
- " <Player PlayerID=\"1005\">\r\n" + //$NON-NLS-1$
- " <FirstName>Derrek</FirstName>\r\n" + //$NON-NLS-1$
- " <LastName>Lee</LastName>\r\n" + //$NON-NLS-1$
- " </Player>\r\n" + //$NON-NLS-1$
- " <Player PlayerID=\"1006\">\r\n" + //$NON-NLS-1$
- " <FirstName>Corey</FirstName>\r\n" + //$NON-NLS-1$
- " <LastName>Patterson</LastName>\r\n" + //$NON-NLS-1$
- " </Player>\r\n" + //$NON-NLS-1$
- " <Player PlayerID=\"1008\">\r\n" + //$NON-NLS-1$
- " <FirstName>Carlos</FirstName>\r\n" + //$NON-NLS-1$
- " <LastName>Zambrano</LastName>\r\n" + //$NON-NLS-1$
- " </Player>\r\n" + //$NON-NLS-1$
- "</BaseballPlayers>\r\n\r\n"; //$NON-NLS-1$
- helpTestProcess("select * from xmltest.playersDoc where context(manager, owner.@ownerid) = '1009'", expectedDoc, metadata, dataMgr); //$NON-NLS-1$
+ helpTestProcess("select * from xmltest.playersDoc where context(manager, owner.@ownerid) = '1009'", CARDS_MANAGER, metadata, dataMgr); //$NON-NLS-1$
}
+ @Test public void testBaseballPlayersPseudoGroup() throws Exception {
+ QueryMetadataInterface metadata = RealMetadataFactory.exampleCase3225();
+ FakeDataManager dataMgr = exampleDataManagerCase3225(metadata);
+
+ helpTestProcess("select * from xmltest.playersDoc where context(manager, manager.firstname) > ALL (select firstname from player)", CARDS_MANAGER, metadata, dataMgr); //$NON-NLS-1$
+ }
+
/**
* Ensures that temp tables are still visible when processing criteria
*/
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -22,8 +22,9 @@
package org.teiid.query.resolver;
-import junit.framework.TestCase;
+import static org.junit.Assert.*;
+import org.junit.Test;
import org.teiid.query.parser.QueryParser;
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.sql.lang.Command;
@@ -38,7 +39,7 @@
import org.teiid.query.unittest.RealMetadataFactory;
-public class TestXMLResolver extends TestCase {
+public class TestXMLResolver {
public Command helpResolve(String sql) {
Command cmd = TestResolver.helpResolve(sql, RealMetadataFactory.example1Cached());
@@ -54,7 +55,7 @@
TestResolver.helpResolveException(sql, RealMetadataFactory.example1Cached(), expectedMessage);
}
- public void testXMLCriteriaShortElement() {
+ @Test public void testXMLCriteriaShortElement() {
CompareCriteria expected = new CompareCriteria();
GroupSymbol gs = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
ElementSymbol es = new ElementSymbol("root.node1", null, gs); //$NON-NLS-1$
@@ -67,7 +68,7 @@
assertEquals("Did not match expected criteria", expected, actual); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElement1() {
+ @Test public void testXMLCriteriaLongElement1() {
CompareCriteria expected = new CompareCriteria();
GroupSymbol gs = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
ElementSymbol es = new ElementSymbol("root.node1", null, gs); //$NON-NLS-1$
@@ -81,7 +82,7 @@
assertEquals("Did not match expected criteria", expected, actual); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElement2() {
+ @Test public void testXMLCriteriaLongElement2() {
CompareCriteria expected1 = new CompareCriteria();
GroupSymbol gs = new GroupSymbol("xmltest.doc4"); //$NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("root.node1", null, gs); //$NON-NLS-1$
@@ -94,7 +95,7 @@
assertEquals("Did not match expected criteria", expected1, actual); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElement3() {
+ @Test public void testXMLCriteriaLongElement3() {
GroupSymbol gs = new GroupSymbol("xmltest.doc4"); //$NON-NLS-1$
CompareCriteria expected2 = new CompareCriteria();
ElementSymbol es2 = new ElementSymbol("root.node1.@node2", null, gs); //$NON-NLS-1$
@@ -108,7 +109,7 @@
assertEquals("Did not match expected criteria", expected2, actual); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElement4() {
+ @Test public void testXMLCriteriaLongElement4() {
GroupSymbol gs = new GroupSymbol("xmltest.doc4"); //$NON-NLS-1$
CompareCriteria expected3 = new CompareCriteria();
ElementSymbol es3 = new ElementSymbol("root.node3", null, gs); //$NON-NLS-1$
@@ -121,76 +122,76 @@
assertEquals("Did not match expected criteria", expected3, actual); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElement5() {
+ @Test public void testXMLCriteriaLongElement5() {
helpResolve("select * from xmltest.doc4 where root.node1 = 'yyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElement6() {
+ @Test public void testXMLCriteriaLongElement6() {
helpResolve("select * from xmltest.doc4 where root.node1.@node2 = 'yyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElement7() {
+ @Test public void testXMLCriteriaLongElement7() {
helpResolve("select * from xmltest.doc4 where root.node3 = 'yyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElement8() {
+ @Test public void testXMLCriteriaLongElement8() {
helpResolve("select * from xmltest.doc4 where node3 = 'yyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElementFail1() {
+ @Test public void testXMLCriteriaLongElementFail1() {
helpResolveException("select * from xmltest.doc4 where node3.node1.node2 = 'xyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElementFail2() {
+ @Test public void testXMLCriteriaLongElementFail2() {
helpResolveException("select * from xmltest.doc4 where root.node1.node2.node3 = 'xyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElementFail3() {
+ @Test public void testXMLCriteriaLongElementFail3() {
helpResolveException("select * from xmltest.doc4 where root.node1.node3 = 'xyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElementFail4() {
+ @Test public void testXMLCriteriaLongElementFail4() {
helpResolveException("select * from xmltest.doc4 where node2.node1.node2 = 'xyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaTempElement1() {
+ @Test public void testXMLCriteriaTempElement1() {
helpResolve("select * from xmltest.doc4 where tm1.g1.e1 = 'x'"); //$NON-NLS-1$
}
- public void testXMLCriteriaTempElement2() {
+ @Test public void testXMLCriteriaTempElement2() {
helpResolve("select * from xmltest.doc4 where root.node1.@node2 = 'yyz' and tm1.g1.e2 = 'y'"); //$NON-NLS-1$
}
- public void testXMLCriteriaTempElement3() {
+ @Test public void testXMLCriteriaTempElement3() {
helpResolve("select * from xmltest.doc4 where tm1.g1.e1 = 'x' and tm1.g1.e2 = 'y'"); //$NON-NLS-1$
}
- public void testXMLCriteriaTempElementFail1() {
+ @Test public void testXMLCriteriaTempElementFail1() {
helpResolveException("select * from xmltest.doc4 where tm1.g2.e1 = 'xyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaTempElementFail2() {
+ @Test public void testXMLCriteriaTempElementFail2() {
helpResolveException("select * from xmltest.doc4 where root.node1.node2.node3 = 'xyz' and e1 = 'x'"); //$NON-NLS-1$
}
- public void testXMLCriteriaTempElementFail3() {
+ @Test public void testXMLCriteriaTempElementFail3() {
helpResolveException("select * from xmltest.doc4 where e3 = 'xyz' and tm1.g2.e4='m'"); //$NON-NLS-1$
}
//tests ambiguously-named elements in both root temp group and document
- public void testXMLAmbiguousName1() {
+ @Test public void testXMLAmbiguousName1() {
helpResolve("select * from xmltest.doc4 where root.node1 is null"); //$NON-NLS-1$
}
- public void testXMLAmbiguousName2() {
+ @Test public void testXMLAmbiguousName2() {
helpResolve("select * from xmltest.doc4 where tm1.g1.node1 = 'yyz'"); //$NON-NLS-1$
}
- public void testXMLAmbiguousName3() {
+ @Test public void testXMLAmbiguousName3() {
helpResolveException("select * from xmltest.doc4 where node1 = 'yyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElementInAnonymous() {
+ @Test public void testXMLCriteriaLongElementInAnonymous() {
CompareCriteria expected = new CompareCriteria();
GroupSymbol gs = new GroupSymbol("xmltest.doc2"); //$NON-NLS-1$
ElementSymbol es = new ElementSymbol("root.node1.node3", null, gs); //$NON-NLS-1$
@@ -203,7 +204,7 @@
assertEquals("Did not match expected criteria", expected, actual); //$NON-NLS-1$
}
- public void testXMLAmbiguousShortName() {
+ @Test public void testXMLAmbiguousShortName() {
CompareCriteria expected = new CompareCriteria();
ElementSymbol es = new ElementSymbol("node2"); //$NON-NLS-1$
GroupSymbol gs = new GroupSymbol("doc3"); //$NON-NLS-1$
@@ -218,95 +219,95 @@
/**
* defect 9745
*/
- public void testXMLAttributeInCriteria() {
+ @Test public void testXMLAttributeInCriteria() {
helpResolve("select * from xmltest.doc4 where root.node1.@node2 = 'x'"); //$NON-NLS-1$
}
/**
* defect 9745
*/
- public void testXMLAttributeInCriteria2() {
+ @Test public void testXMLAttributeInCriteria2() {
helpResolve("select * from xmltest.doc4 where root.node1.node2 = 'x'"); //$NON-NLS-1$
}
/**
* defect 9745
*/
- public void testXMLAttributeInCriteria3() {
+ @Test public void testXMLAttributeInCriteria3() {
helpResolve("select * from xmltest.doc4 where node2 = 'x'"); //$NON-NLS-1$
}
- public void testXMLAttributeElementAmbiguity1() {
+ @Test public void testXMLAttributeElementAmbiguity1() {
helpResolve("select * from xmltest.doc4 where root.node3.node4 = 'x'"); //$NON-NLS-1$
}
- public void testXMLAttributeElementAmbiguity2() {
+ @Test public void testXMLAttributeElementAmbiguity2() {
helpResolve("select * from xmltest.doc4 where root.node3.@node4 = 'x'"); //$NON-NLS-1$
}
- public void testXMLAttributeElementAmbiguity3() {
+ @Test public void testXMLAttributeElementAmbiguity3() {
helpResolve("select * from xmltest.doc4 where root.node3.node4 = 'x' and root.node3.@node4='y'"); //$NON-NLS-1$
}
/*
* This should resolve to the XML element root.node3.root.node6
*/
- public void testXMLAttributeElementAmbiguity4() {
+ @Test public void testXMLAttributeElementAmbiguity4() {
helpResolve("select * from xmltest.doc4 where root.node6 = 'x'"); //$NON-NLS-1$
}
/*
* This should resolve to the XML attribute root.@node6
*/
- public void testXMLAttributeElementAmbiguity5() {
+ @Test public void testXMLAttributeElementAmbiguity5() {
helpResolve("select * from xmltest.doc4 where root.@node6 = 'x'"); //$NON-NLS-1$
}
- public void testXMLAttributeFullPath() {
+ @Test public void testXMLAttributeFullPath() {
helpResolve("select * from xmltest.doc4 where xmltest.doc4.root.@node6 = 'x'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElementWithGroup1() {
+ @Test public void testXMLCriteriaLongElementWithGroup1() {
helpResolve("select * from xmltest.doc4 where xmltest.doc4.root.node1 = 'yyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElementWithGroup2() {
+ @Test public void testXMLCriteriaLongElementWithGroup2() {
helpResolve("select * from xmltest.doc4 where xmltest.doc4.root.node1.@node2 = 'yyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElementWithGroup3() {
+ @Test public void testXMLCriteriaLongElementWithGroup3() {
helpResolve("select * from xmltest.doc4 where xmltest.doc4.root.node3 = 'yyz'"); //$NON-NLS-1$
}
- /*public void testXMLElementPotentialAmbiguous() {
+ /*@Test public void testXMLElementPotentialAmbiguous() {
helpResolve("select * from xmltest.doc6 where node = 'yyz'");
}*/
- public void testXMLSelect() {
+ @Test public void testXMLSelect() {
helpResolve("select root.node3.@node4 from xmltest.doc4"); //$NON-NLS-1$
}
- public void testXMLSelect2() {
+ @Test public void testXMLSelect2() {
helpResolve("select root.node3.node4 from xmltest.doc4"); //$NON-NLS-1$
}
- public void testXMLSelect3() {
+ @Test public void testXMLSelect3() {
helpResolve("select root.@node6 from xmltest.doc4"); //$NON-NLS-1$
}
- public void testXMLSelect4() {
+ @Test public void testXMLSelect4() {
helpResolve("select root.node6 from xmltest.doc4"); //$NON-NLS-1$
}
- public void testXMLSelect5() {
+ @Test public void testXMLSelect5() {
helpResolve("select node2 from xmltest.doc4"); //$NON-NLS-1$
}
- public void testDEFECT_19771() {
+ @Test public void testDEFECT_19771() {
helpResolveException("select node2 AS NODE2 from xmltest.doc4"); //$NON-NLS-1$
}
- public void testContext() {
+ @Test public void testContext() {
GroupSymbol gs1 = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("root.node1.node2.node3", null, gs1); //$NON-NLS-1$
ElementSymbol es2 = new ElementSymbol("root.node1", null, gs1); //$NON-NLS-1$
@@ -324,7 +325,7 @@
assertEquals("Did not match expected criteria", expected, actual); //$NON-NLS-1$
}
- public void testRowLimit() {
+ @Test public void testRowLimit() {
GroupSymbol gs1 = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("root.node1.node2.node3", null, gs1); //$NON-NLS-1$
es1.setGroupSymbol(gs1);
@@ -342,7 +343,7 @@
assertEquals("Did not match expected criteria", expected, actual); //$NON-NLS-1$
}
- public void testRowLimitException() {
+ @Test public void testRowLimitException() {
GroupSymbol gs1 = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("root.node1.node2.node3", null, gs1); //$NON-NLS-1$
Expression[] exprs = new Expression[]{es1};
@@ -359,23 +360,23 @@
assertEquals("Did not match expected criteria", expected, actual); //$NON-NLS-1$
}
- public void testXMLQueryFail1() {
+ @Test public void testXMLQueryFail1() {
helpResolveException("SELECT DISTINCT * FROM vm1.doc1"); //$NON-NLS-1$
}
- public void testXMLQueryFail2() {
+ @Test public void testXMLQueryFail2() {
helpResolveException("SELECT a2 FROM vm1.doc1"); //$NON-NLS-1$
}
- public void testXMLQueryFail3() {
+ @Test public void testXMLQueryFail3() {
helpResolveException("SELECT * FROM vm1.doc1, vm1.doc2"); //$NON-NLS-1$
}
- public void testXMLWithOrderBy1() {
+ @Test public void testXMLWithOrderBy1() {
helpResolveException("select * from xmltest.doc4 order by node1"); //$NON-NLS-1$
}
- public void testConversionInXML() {
+ @Test public void testConversionInXML() {
// Expected left expression
GroupSymbol gs1 = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("root.node1", null, gs1); //$NON-NLS-1$
@@ -397,7 +398,7 @@
assertNotNull("Failed to resolve function", actualRightExpr.getFunctionDescriptor()); //$NON-NLS-1$
}
- public void testXMLWithSelect1() throws Exception {
+ @Test public void testXMLWithSelect1() throws Exception {
CompareCriteria expected = new CompareCriteria();
GroupSymbol gs = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
ElementSymbol es = new ElementSymbol("root.node1", null, gs); //$NON-NLS-1$
@@ -410,11 +411,11 @@
assertEquals("Did not match expected criteria", expected, actual); //$NON-NLS-1$
}
- public void testXMLWithSelect1a() {
+ @Test public void testXMLWithSelect1a() {
helpResolveException("select 'a' from xmltest.doc1 where node1 = 'yyz'", "Expressions cannot be selected by XML Queries"); //$NON-NLS-1$ //$NON-NLS-2$
}
- public void testXMLWithSelect2() {
+ @Test public void testXMLWithSelect2() {
CompareCriteria expected = new CompareCriteria();
GroupSymbol gs = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
ElementSymbol es = new ElementSymbol("root.node1", null, gs); //$NON-NLS-1$
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -2517,10 +2517,10 @@
// Create mapping classes - baseball players employees doc
QueryNode playersNode = new QueryNode("SELECT stock.employees.employeeNum, firstName, lastName, supervisorNum FROM stock.employees WHERE specializesInItemNum is not null"); //$NON-NLS-1$ //$NON-NLS-2$
- Table rsPlayers = createVirtualGroup("players", xmltest, playersNode); //$NON-NLS-1$
+ Table rsPlayers = createVirtualGroup("player", xmltest, playersNode); //$NON-NLS-1$
QueryNode managersNode = new QueryNode("SELECT stock.employees.employeeNum, firstName, lastName, supervisorNum FROM stock.employees WHERE stock.employees.employeeNum = ?"); //$NON-NLS-1$ //$NON-NLS-2$
- managersNode.addBinding("xmltest.players.supervisorNum"); //$NON-NLS-1$
+ managersNode.addBinding("xmltest.player.supervisorNum"); //$NON-NLS-1$
Table rsManagers = createVirtualGroup("managers", xmltest, managersNode); //$NON-NLS-1$
// TODO what if elements in criteria weren't fully qualified? see defect 19541
@@ -2548,11 +2548,11 @@
MappingElement root2 = doc2.addChildElement(new MappingElement("BaseballPlayers")); //$NON-NLS-1$
MappingElement player = root2.addChildElement(new MappingElement("Player")); //$NON-NLS-1$
- player.setSource("xmltest.players"); //$NON-NLS-1$
+ player.setSource("xmltest.player"); //$NON-NLS-1$
player.setMaxOccurrs(-1);
- player.addAttribute(new MappingAttribute("PlayerID", "xmltest.players.employeeNum")); //$NON-NLS-1$ //$NON-NLS-2$
- player.addChildElement(new MappingElement("FirstName", "xmltest.players.firstName")); //$NON-NLS-1$ //$NON-NLS-2$
- player.addChildElement(new MappingElement("LastName", "xmltest.players.lastName")); //$NON-NLS-1$ //$NON-NLS-2$
+ player.addAttribute(new MappingAttribute("PlayerID", "xmltest.player.employeeNum")); //$NON-NLS-1$ //$NON-NLS-2$
+ player.addChildElement(new MappingElement("FirstName", "xmltest.player.firstName")); //$NON-NLS-1$ //$NON-NLS-2$
+ player.addChildElement(new MappingElement("LastName", "xmltest.player.lastName")); //$NON-NLS-1$ //$NON-NLS-2$
MappingElement manager = player.addChildElement(new MappingElement("Manager")); //$NON-NLS-1$
manager.setSource("xmltest.managers");//$NON-NLS-1$
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2011-05-29 18:10:40 UTC (rev 3203)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2011-05-30 09:48:28 UTC (rev 3204)
@@ -120,9 +120,9 @@
MappingElement sourceNode = complexRoot.addChildElement(new MappingElement("a1")); //$NON-NLS-1$
sourceNode.setSource("test.group"); //$NON-NLS-1$
- sourceNode.addChildElement(new MappingElement("a2", "e1")); //$NON-NLS-1$ //$NON-NLS-2$
- sourceNode.addChildElement(new MappingElement("b2", "e2")); //$NON-NLS-1$ //$NON-NLS-2$
- sourceNode.addChildElement(new MappingElement("c2", "e3")); //$NON-NLS-1$ //$NON-NLS-2$
+ sourceNode.addChildElement(new MappingElement("a2", "test.group.e1")); //$NON-NLS-1$ //$NON-NLS-2$
+ sourceNode.addChildElement(new MappingElement("b2", "test.group.e2")); //$NON-NLS-1$ //$NON-NLS-2$
+ sourceNode.addChildElement(new MappingElement("c2", "test.group.e3")); //$NON-NLS-1$ //$NON-NLS-2$
Schema docModel = RealMetadataFactory.createVirtualModel("vm1", metadataStore); //$NON-NLS-1$
Table doc1 = RealMetadataFactory.createXmlDocument("doc1", docModel, doc); //$NON-NLS-1$
13 years, 6 months
teiid SVN: r3203 - in branches/7.4.x: client/src/test/java/org/teiid/jdbc and 4 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-05-29 14:10:40 -0400 (Sun, 29 May 2011)
New Revision: 3203
Modified:
branches/7.4.x/client/src/main/java/org/teiid/jdbc/EmbeddedProfile.java
branches/7.4.x/client/src/main/java/org/teiid/jdbc/JDBCURL.java
branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java
branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java
branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/AbstractWorkItem.java
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java
branches/7.4.x/engine/src/test/java/org/teiid/dqp/internal/process/TestWorkItemState.java
Log:
TEIID-1614 adding a fix for embedded thread hanging
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/EmbeddedProfile.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/EmbeddedProfile.java 2011-05-27 20:07:57 UTC (rev 3202)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/EmbeddedProfile.java 2011-05-29 18:10:40 UTC (rev 3203)
@@ -28,6 +28,7 @@
import org.teiid.core.TeiidException;
import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.util.PropertiesUtils;
import org.teiid.core.util.ReflectionHelper;
import org.teiid.net.CommunicationException;
import org.teiid.net.ConnectionException;
@@ -36,7 +37,9 @@
public class EmbeddedProfile implements ConnectionProfile {
- /**
+ public static final String USE_CALLING_THREAD = "useCallingThread"; //$NON-NLS-1$
+
+ /**
* This method tries to make a connection to the given URL. This class
* will return a null if this is not the right driver to connect to the given URL.
* @param The URL used to establish a connection.
@@ -61,7 +64,7 @@
protected ServerConnection createServerConnection(Properties info)
throws TeiidException {
- return (ServerConnection)ReflectionHelper.create("org.teiid.transport.LocalServerConnection", Arrays.asList(info, true), Thread.currentThread().getContextClassLoader()); //$NON-NLS-1$
+ return (ServerConnection)ReflectionHelper.create("org.teiid.transport.LocalServerConnection", Arrays.asList(info, PropertiesUtils.getBooleanProperty(info, USE_CALLING_THREAD, true)), Thread.currentThread().getContextClassLoader()); //$NON-NLS-1$
}
}
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/JDBCURL.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/JDBCURL.java 2011-05-27 20:07:57 UTC (rev 3202)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/JDBCURL.java 2011-05-29 18:10:40 UTC (rev 3203)
@@ -57,6 +57,7 @@
ExecutionProperties.PROP_FETCH_SIZE,
ExecutionProperties.PROP_XML_FORMAT,
ExecutionProperties.PROP_XML_VALIDATION,
+ EmbeddedProfile.USE_CALLING_THREAD,
ExecutionProperties.DISABLE_LOCAL_TRANSACTIONS)));
public static final Set<String> KNOWN_PROPERTIES = getKnownProperties();
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java 2011-05-27 20:07:57 UTC (rev 3202)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java 2011-05-29 18:10:40 UTC (rev 3203)
@@ -533,7 +533,6 @@
}
final RequestMessage reqMessage = createRequestMessage(commands, isBatchedCommand, resultsMode);
- reqMessage.setSync(synch);
ResultsFuture<ResultsMessage> pendingResult = execute(reqMessage, synch);
final ResultsFuture<Boolean> result = new ResultsFuture<Boolean>();
pendingResult.addCompletionListener(new ResultsFuture.CompletionListener<ResultsMessage>() {
@@ -581,7 +580,8 @@
reqMsg.setFetchSize(this.fetchSize);
reqMsg.setRowLimit(this.maxRows);
reqMsg.setTransactionIsolation(this.driverConnection.getTransactionIsolation());
-
+ String useCallingThread = getExecutionProperty(EmbeddedProfile.USE_CALLING_THREAD);
+ reqMsg.setSync(synch && (useCallingThread == null || Boolean.valueOf(useCallingThread)));
// Get connection properties and set them onto request message
copyPropertiesToRequest(reqMsg);
Modified: branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java
===================================================================
--- branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java 2011-05-27 20:07:57 UTC (rev 3202)
+++ branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java 2011-05-29 18:10:40 UTC (rev 3203)
@@ -135,7 +135,7 @@
@Test public void testGetPropertyInfo1() throws Exception {
DriverPropertyInfo info[] = drv.getPropertyInfo("jdbc:teiid:vdb@mm://localhost:12345;applicationName=x", null); //$NON-NLS-1$
- assertEquals(19, info.length);
+ assertEquals(20, info.length);
assertEquals(false, info[0].required);
assertEquals("ApplicationName", info[0].name); //$NON-NLS-1$
assertEquals("x", info[0].value); //$NON-NLS-1$
Modified: branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml
===================================================================
--- branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml 2011-05-27 20:07:57 UTC (rev 3202)
+++ branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml 2011-05-29 18:10:40 UTC (rev 3203)
@@ -223,7 +223,16 @@
to create session. Teiid also verifies that the same user is using this connection during the life of the connection.
if it finds a different security context on the calling thread, it switches the identity on the connection,
if the new user is also eligible to log in to Teiid otherwise connection fails to execute.</entry>
- </row>
+ </row>
+ <row id="useCallingThread">
+ <entry>
+ <code>useCallingThread</code>
+ </entry>
+ <entry>
+ <code>boolean</code>
+ </entry>
+ <entry>Only applies to "local" connections. When this option is set to "true" (the default), then the calling thread will be used to process the query. If false, then an engine thread will be used.</entry>
+ </row>
<row>
<entry>
<code>QueryTimeout</code>
@@ -458,7 +467,8 @@
there is a way to make connections that by-pass making a socket based JDBC connection.
You can use slightly modified data source configuration to make a "local" connection, where the JDBC API will lookup a local Teiid runtime in the same VM.</para>
<warning><para>Since DataSources start before before Teiid VDBs are deployed, leave the min pool size of local connections as the default of 0. Otherwise errors will occur on the startup of the Teiid DataSource.</para></warning>
- <note><para>Local connections use their calling thread to perform processing operations rather than using an engine thread while the calling thread is blocked.</para></note>
+ <note><para>Be default local connections use their calling thread to perform processing operations rather than using an engine thread while the calling thread is blocked.
+ To disable this behavior set the connection property useCallingThreads=false.</para></note>
<example>
<title>Local data source</title>
<programlisting><![CDATA[<datasources>
Modified: branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/AbstractWorkItem.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/AbstractWorkItem.java 2011-05-27 20:07:57 UTC (rev 3202)
+++ branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/AbstractWorkItem.java 2011-05-29 18:10:40 UTC (rev 3203)
@@ -43,10 +43,10 @@
private ThreadState threadState = ThreadState.MORE_WORK;
private volatile boolean isProcessing;
- private boolean useCallingThread;
+ private Thread callingThread;
- public AbstractWorkItem(boolean useCallingThread) {
- this.useCallingThread = useCallingThread;
+ public AbstractWorkItem(Thread callingThread) {
+ this.callingThread = callingThread;
}
public void run() {
@@ -99,14 +99,14 @@
if (isDoneProcessing()) {
logTrace("done processing - ignoring more"); //$NON-NLS-1$
this.threadState = ThreadState.DONE;
- } else if (!this.useCallingThread) {
+ } else if (this.callingThread == null) {
resumeProcessing();
}
break;
default:
throw new IllegalStateException("Should not END on " + this.threadState); //$NON-NLS-1$
}
- return useCallingThread;
+ return this.callingThread != null;
}
protected boolean isIdle() {
@@ -127,11 +127,11 @@
break;
case IDLE:
this.threadState = ThreadState.MORE_WORK;
- if (this.useCallingThread) {
- if (isProcessing) {
+ if (this.callingThread != null) {
+ if (this.callingThread == Thread.currentThread()) {
+ run(); //restart with the calling thread
+ } else {
this.notifyAll(); //notify the waiting caller
- } else {
- run(); //restart with the calling thread
}
} else {
resumeProcessing();
@@ -152,17 +152,17 @@
protected abstract void process();
protected boolean pauseProcessing() {
- if (useCallingThread && !shouldPause()) {
+ if (this.callingThread != null && !shouldPause()) {
return false;
}
- while (useCallingThread && this.getThreadState() == ThreadState.IDLE) {
+ while (this.callingThread != null && this.getThreadState() == ThreadState.IDLE) {
try {
this.wait(); //the lock should already be held
} catch (InterruptedException e) {
interrupted(e);
}
}
- return useCallingThread;
+ return this.callingThread != null;
}
/**
Modified: branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2011-05-27 20:07:57 UTC (rev 3202)
+++ branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2011-05-29 18:10:40 UTC (rev 3203)
@@ -162,7 +162,7 @@
private long processingTimestamp = System.currentTimeMillis();
public RequestWorkItem(DQPCore dqpCore, RequestMessage requestMsg, Request request, ResultsReceiver<ResultsMessage> receiver, RequestID requestID, DQPWorkContext workContext) {
- super(workContext.useCallingThread() || requestMsg.isSync());
+ super(workContext.useCallingThread() || requestMsg.isSync() ? Thread.currentThread() : null);
this.requestMsg = requestMsg;
this.requestID = requestID;
this.processorTimeslice = dqpCore.getProcessorTimeSlice();
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java 2011-05-27 20:07:57 UTC (rev 3202)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java 2011-05-29 18:10:40 UTC (rev 3203)
@@ -403,7 +403,7 @@
if (groupingExpressions != null) {
newGroupingExpressions = new HashSet<SingleElementSymbol>();
for (SingleElementSymbol singleElementSymbol : groupingExpressions) {
- newGroupingExpressions.add((SingleElementSymbol)symbolMap.getKeys().get(virtualElements.indexOf(singleElementSymbol)).clone());
+ newGroupingExpressions.add(symbolMap.getKeys().get(virtualElements.indexOf(singleElementSymbol)).clone());
}
}
Modified: branches/7.4.x/engine/src/test/java/org/teiid/dqp/internal/process/TestWorkItemState.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/dqp/internal/process/TestWorkItemState.java 2011-05-27 20:07:57 UTC (rev 3202)
+++ branches/7.4.x/engine/src/test/java/org/teiid/dqp/internal/process/TestWorkItemState.java 2011-05-29 18:10:40 UTC (rev 3203)
@@ -25,10 +25,20 @@
import static org.junit.Assert.*;
import org.junit.Test;
+import org.teiid.dqp.internal.process.AbstractWorkItem.ThreadState;
public class TestWorkItemState {
+ private final class WorkItemRunner implements Runnable {
+ TestWorkItem workItem;
+
+ @Override
+ public void run() {
+ workItem.run();
+ }
+ }
+
private class TestWorkItem extends AbstractWorkItem {
private boolean isDone;
@@ -40,7 +50,11 @@
}
private TestWorkItem(boolean done, boolean callMoreWork) {
- super(false);
+ this(done, callMoreWork, null);
+ }
+
+ private TestWorkItem(boolean done, boolean callMoreWork, Thread callingThread) {
+ super(callingThread);
this.isDone = done;
this.callMoreWork = callMoreWork;
}
@@ -152,5 +166,27 @@
}
}
+
+ @Test public void testUsingCallingThreadIdle() throws Exception {
+ WorkItemRunner r = new WorkItemRunner();
+ Thread t = new Thread(r);
+ final TestWorkItem item = new TestWorkItem(false, false, t) {
+ @Override
+ protected boolean shouldPause() {
+ return true;
+ }
+ };
+ r.workItem = item;
+ t.start();
+ for (int i = 0; i < 10 && item.getThreadState() != ThreadState.IDLE; i++) {
+ Thread.sleep(100);
+ }
+ if (item.getThreadState() != ThreadState.IDLE) {
+ fail();
+ }
+ item.moreWork();
+ //if we don't return from this call, that means that this thread has been hijacked -
+ //we should instead use t.
+ }
}
13 years, 6 months
teiid SVN: r3202 - in branches/7.4.x/engine/src: test/java/org/teiid/query/resolver and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-05-27 16:07:57 -0400 (Fri, 27 May 2011)
New Revision: 3202
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/InsertResolver.java
branches/7.4.x/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
Log:
TEIID-1613 fix for insert resolving
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/InsertResolver.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/InsertResolver.java 2011-05-26 15:47:40 UTC (rev 3201)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/InsertResolver.java 2011-05-27 20:07:57 UTC (rev 3202)
@@ -135,7 +135,7 @@
List<Reference> references = new ArrayList<Reference>(insert.getVariables().size());
for (int i = 0; i < insert.getVariables().size(); i++) {
Reference ref = new Reference(i);
- ref.setType(((ElementSymbol)insert.getVariables().get(i)).getType());
+ ref.setType(insert.getVariables().get(i).getType());
references.add(ref);
}
insert.setValues(references);
@@ -198,7 +198,7 @@
//TODO: a special case here is a projected literal
throw new QueryResolverException(QueryPlugin.Util.getString("InsertResolver.cant_convert_query_type", new Object[] {expression, expression.getType().getName(), element, element.getType().getName()})); //$NON-NLS-1$
}
- } else if (element.getType() == null && expression.getType() != null && !usingQuery) {
+ } else if (element.getType() == null && expression.getType() != null) {
element.setType(expression.getType());
newValues.add(expression);
} else {
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/resolver/TestResolver.java 2011-05-26 15:47:40 UTC (rev 3201)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/resolver/TestResolver.java 2011-05-27 20:07:57 UTC (rev 3202)
@@ -2618,6 +2618,11 @@
helpResolveException(sql, "Cannot convert insert query expression projected symbol '3' of type java.lang.Integer to insert column 'pm1.g1.e3' of type java.lang.Boolean"); //$NON-NLS-1$
}
+ @Test public void testInsertWithQueryImplicitWithColumns() {
+ String sql = "Insert into #X (x) select 1 as x"; //$NON-NLS-1$
+ helpResolve(sql); //$NON-NLS-1$
+ }
+
@Test public void testInsertWithQueryImplicitWithoutColumns() {
String sql = "Insert into #X select 1 as x, 2 as y, 3 as z"; //$NON-NLS-1$
helpResolve(sql); //$NON-NLS-1$
13 years, 7 months
teiid SVN: r3201 - in branches/7.4.x: build/kits/jboss-container/deploy/teiid and 6 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-05-26 11:47:40 -0400 (Thu, 26 May 2011)
New Revision: 3201
Modified:
branches/7.4.x/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml
branches/7.4.x/build/kits/jboss-container/teiid-releasenotes.html
branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/odbc.xml
branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/ssl.xml
branches/7.4.x/engine/src/main/java/org/teiid/security/Credentials.java
branches/7.4.x/runtime/src/main/java/org/teiid/odbc/ODBCClientRemote.java
branches/7.4.x/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
branches/7.4.x/runtime/src/main/java/org/teiid/transport/ODBCSocketListener.java
branches/7.4.x/runtime/src/main/java/org/teiid/transport/PgBackendProtocol.java
branches/7.4.x/runtime/src/main/resources/org/teiid/runtime/i18n.properties
branches/7.4.x/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java
Log:
TEIID-1460 adding ssl support to odbc
Modified: branches/7.4.x/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml
===================================================================
--- branches/7.4.x/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml 2011-05-26 14:59:56 UTC (rev 3200)
+++ branches/7.4.x/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml 2011-05-26 15:47:40 UTC (rev 3201)
@@ -229,7 +229,7 @@
<bean name="OdbcSslConfiguration" class="org.teiid.transport.SSLConfiguration">
<!-- can be one of disabled or enabled
disabled = no transport or message level security will be used
- enabled = traffic will be secured using this configuration
+ enabled = traffic will be secured using this configuration if the client supports SSL
-->
<property name="mode">disabled</property>
<property name="keystoreFilename">cert.keystore</property>
Modified: branches/7.4.x/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- branches/7.4.x/build/kits/jboss-container/teiid-releasenotes.html 2011-05-26 14:59:56 UTC (rev 3200)
+++ branches/7.4.x/build/kits/jboss-container/teiid-releasenotes.html 2011-05-26 15:47:40 UTC (rev 3201)
@@ -56,6 +56,7 @@
<LI><B>Cache Invalidation</B> - Prepared plan and result set caches have will invalidate entries based upon metadata and data changes respectively. See the cache configuration maxStaleness setting and the Admin and Developer Guides for more.
<LI><B>Runtime Updates of Metadata</B> - ALTER statements have been added to change view/procedure/INSTEAD OF trigger (update procedure) definitions. A CREATE TRIGGER statement is also available to add an INSTEAD OF trigger (update procedures) to views.
System procedures were added to set extension metadata and stat values. By default all effects of metadata updates happen only on running vdbs across the cluster. To make the changes persistent see the Developers Guide Runtime Updates section.
+ <LI><B>ODBC SSL</B> - added support for SSL encrypted ODBC connections.
</UL>
<h2><a name="Compatibility">Compatibility Issues</a></h2>
Modified: branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/odbc.xml
===================================================================
--- branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/odbc.xml 2011-05-26 14:59:56 UTC (rev 3200)
+++ branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/odbc.xml 2011-05-26 15:47:40 UTC (rev 3201)
@@ -23,6 +23,11 @@
<para>Before an application can use ODBC, you must first install the ODBC driver on same machine that
the application is running on and then create Data Source Name (DSN) that represents a connection profile for your Teiid VDB.
</para>
+
+ <warning><para>Teiid currently only supports plain text passward authentication for ODBC.
+ If the client/server are not configured to use SSL, the password will be sent in plain text over the network.
+ If you need secure passwords in transit and are not using SSL, then consider installing a security domain
+ that will accept safe password values from the client (for example encrypted or hashed).</para></warning>
<section id="install">
<title>Installing the ODBC Driver Client</title>
@@ -145,7 +150,6 @@
listenes for ODBC requests on port 35432</para>
<para>In the <emphasis>User Name</emphasis> and <emphasis>Password</emphasis> edit boxes, supply the user name and password
for the Teiid runtime access.</para>
- <para>Leave <emphasis>SSL Mode</emphasis> to disabled. SSL connections are currently not supported.</para>
<para>Provide any description about the data source in the <emphasis>Description</emphasis> field.</para>
</listitem>
Modified: branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/ssl.xml
===================================================================
--- branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/ssl.xml 2011-05-26 14:59:56 UTC (rev 3200)
+++ branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/ssl.xml 2011-05-26 15:47:40 UTC (rev 3201)
@@ -13,13 +13,13 @@
<section id="default_security">
<title>Default Security</title>
- <para>If you are using a socket connection, then you may need to secure the channel more completely.</para>
-
- <para>By default all sensitive (non-data) messages between client and server
+ <para>By default all JDBC/Admin sensitive (non-data) messages between client and server
are encrypted using a <ulink url="http://en.wikipedia.org/wiki/Diffie-Hellman_key_exchange">Diffy-Hellman</ulink>
key that is negotiated per connection. This
encryption is controlled by <code>clientEncryptionEnabled</code> property in <code>JdbcSslConfiguration</code> and
<code>AdminSslConfiguration</code> sections in the &jboss-beans; file.</para>
+
+ <para>If you are using a socket connection, then you may need to secure the channel more completely - especially if using ODBC, which currently only supports plain text authentication.</para>
</section>
<section id="ssl_modes">
Modified: branches/7.4.x/engine/src/main/java/org/teiid/security/Credentials.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/security/Credentials.java 2011-05-26 14:59:56 UTC (rev 3200)
+++ branches/7.4.x/engine/src/main/java/org/teiid/security/Credentials.java 2011-05-26 15:47:40 UTC (rev 3201)
@@ -26,7 +26,9 @@
public class Credentials implements Serializable {
- private char[] credentials = null;
+ private static final long serialVersionUID = 7453114713211221240L;
+
+ private char[] credentials = null;
/**
* Construct a new PasswordCredentials
Modified: branches/7.4.x/runtime/src/main/java/org/teiid/odbc/ODBCClientRemote.java
===================================================================
--- branches/7.4.x/runtime/src/main/java/org/teiid/odbc/ODBCClientRemote.java 2011-05-26 14:59:56 UTC (rev 3200)
+++ branches/7.4.x/runtime/src/main/java/org/teiid/odbc/ODBCClientRemote.java 2011-05-26 15:47:40 UTC (rev 3201)
@@ -85,7 +85,7 @@
void functionCallResponse(byte[] data);
void functionCallResponse(int data);
- void sslDenied();
+ void sendSslResponse();
// unimplemented backend messages
Modified: branches/7.4.x/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
===================================================================
--- branches/7.4.x/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2011-05-26 14:59:56 UTC (rev 3200)
+++ branches/7.4.x/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2011-05-26 15:47:40 UTC (rev 3201)
@@ -637,7 +637,7 @@
@Override
public void sslRequest() {
- this.client.sslDenied();
+ this.client.sendSslResponse();
}
private void setEncoding() {
Modified: branches/7.4.x/runtime/src/main/java/org/teiid/transport/ODBCSocketListener.java
===================================================================
--- branches/7.4.x/runtime/src/main/java/org/teiid/transport/ODBCSocketListener.java 2011-05-26 14:59:56 UTC (rev 3200)
+++ branches/7.4.x/runtime/src/main/java/org/teiid/transport/ODBCSocketListener.java 2011-05-26 15:47:40 UTC (rev 3201)
@@ -23,11 +23,8 @@
import java.util.Properties;
-import javax.net.ssl.SSLEngine;
-
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.DefaultChannelPipeline;
-import org.jboss.netty.handler.ssl.SslHandler;
import org.teiid.common.buffer.StorageManager;
import org.teiid.core.TeiidException;
import org.teiid.jdbc.EmbeddedProfile;
@@ -66,12 +63,8 @@
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = new DefaultChannelPipeline();
- SSLEngine engine = config.getServerSSLEngine();
- if (engine != null) {
- pipeline.addLast("ssl", new SslHandler(engine)); //$NON-NLS-1$
- }
pipeline.addLast("odbcFrontendProtocol", new PgFrontendProtocol(1 << 20)); //$NON-NLS-1$
- pipeline.addLast("odbcBackendProtocol", new PgBackendProtocol(maxLobSize)); //$NON-NLS-1$
+ pipeline.addLast("odbcBackendProtocol", new PgBackendProtocol(maxLobSize, config)); //$NON-NLS-1$
pipeline.addLast("handler", this); //$NON-NLS-1$
return pipeline;
}
Modified: branches/7.4.x/runtime/src/main/java/org/teiid/transport/PgBackendProtocol.java
===================================================================
--- branches/7.4.x/runtime/src/main/java/org/teiid/transport/PgBackendProtocol.java 2011-05-26 14:59:56 UTC (rev 3200)
+++ branches/7.4.x/runtime/src/main/java/org/teiid/transport/PgBackendProtocol.java 2011-05-26 15:47:40 UTC (rev 3201)
@@ -28,6 +28,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
+import java.security.GeneralSecurityException;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.ParameterMetaData;
@@ -41,13 +42,18 @@
import java.util.List;
import java.util.Properties;
+import javax.net.ssl.SSLEngine;
+
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.ChannelDownstreamHandler;
import org.jboss.netty.channel.ChannelEvent;
+import org.jboss.netty.channel.ChannelFuture;
+import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.handler.ssl.SslHandler;
import org.teiid.client.util.ResultsFuture;
import org.teiid.core.util.ObjectConverterUtil;
import org.teiid.core.util.ReaderInputStream;
@@ -59,6 +65,7 @@
import org.teiid.logging.LogManager;
import org.teiid.net.socket.ServiceInvocationStruct;
import org.teiid.odbc.ODBCClientRemote;
+import org.teiid.runtime.RuntimePlugin;
import org.teiid.transport.pg.PGbytea;
/**
@@ -68,7 +75,25 @@
@SuppressWarnings("nls")
public class PgBackendProtocol implements ChannelDownstreamHandler, ODBCClientRemote {
- private final class ResultsWorkItem implements Runnable {
+ private final class SSLEnabler implements ChannelFutureListener {
+
+ private SSLEngine engine;
+
+ public SSLEnabler(SSLEngine engine) {
+ this.engine = engine;
+ }
+
+ @Override
+ public void operationComplete(ChannelFuture future) throws Exception {
+ if (future.isSuccess()) {
+ SslHandler handler = new SslHandler(engine);
+ future.getChannel().getPipeline().addFirst("sslHandler", handler);
+ handler.handshake();
+ }
+ }
+ }
+
+ private final class ResultsWorkItem implements Runnable {
private final List<PgColInfo> cols;
private final String sql;
private final ResultSetImpl rs;
@@ -164,8 +189,11 @@
private volatile ResultsFuture<Boolean> nextFuture;
- public PgBackendProtocol(int maxLobSize) {
+ private SSLConfiguration config;
+
+ public PgBackendProtocol(int maxLobSize, SSLConfiguration config) {
this.maxLobSize = maxLobSize;
+ this.config = config;
}
@Override
@@ -550,10 +578,23 @@
}
@Override
- public void sslDenied() {
+ public void sendSslResponse() {
+ SSLEngine engine = null;
+ try {
+ engine = config.getServerSSLEngine();
+ } catch (IOException e) {
+ LogManager.logError(LogConstants.CTX_ODBC, e, RuntimePlugin.Util.getString("PgBackendProtocol.ssl_error"));
+ } catch (GeneralSecurityException e) {
+ LogManager.logError(LogConstants.CTX_ODBC, e, RuntimePlugin.Util.getString("PgBackendProtocol.ssl_error"));
+ }
ChannelBuffer buffer = ChannelBuffers.directBuffer(1);
- buffer.writeByte('N');
- Channels.write(this.ctx, this.message.getFuture(), buffer, this.message.getRemoteAddress());
+ if (engine == null) {
+ buffer.writeByte('N');
+ } else {
+ this.message.getFuture().addListener(new SSLEnabler(engine));
+ buffer.writeByte('S');
+ }
+ Channels.write(this.ctx, this.message.getFuture(), buffer, this.message.getRemoteAddress());
}
private void sendErrorResponse(Throwable t) throws IOException {
Modified: branches/7.4.x/runtime/src/main/resources/org/teiid/runtime/i18n.properties
===================================================================
--- branches/7.4.x/runtime/src/main/resources/org/teiid/runtime/i18n.properties 2011-05-26 14:59:56 UTC (rev 3200)
+++ branches/7.4.x/runtime/src/main/resources/org/teiid/runtime/i18n.properties 2011-05-26 15:47:40 UTC (rev 3201)
@@ -91,4 +91,6 @@
metadata_loaded=VDB {0}.{1} model {2} metadata is currently being loaded.
ambigious_name=Ambiguous VDB name specified. Only single occurrence of the "." is allowed in the VDB name. Also, when version based vdb name is specified, then a separate "version" connection option is not allowed:{0}.{1}
lo_not_supported=LO functions are not supported
-SSLConfiguration.no_anonymous=The anonymous cipher suite TLS_DH_anon_WITH_AES_128_CBC_SHA is not available. Please change the transport to be non-SSL or use non-anonymous SSL.
\ No newline at end of file
+SSLConfiguration.no_anonymous=The anonymous cipher suite TLS_DH_anon_WITH_AES_128_CBC_SHA is not available. Please change the transport to be non-SSL or use non-anonymous SSL.
+
+PgBackendProtocol.ssl_error=Could not initialize ODBC SSL. non-SSL connections will still be allowed.
\ No newline at end of file
Modified: branches/7.4.x/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java
===================================================================
--- branches/7.4.x/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java 2011-05-26 14:59:56 UTC (rev 3200)
+++ branches/7.4.x/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java 2011-05-26 15:47:40 UTC (rev 3201)
@@ -24,8 +24,13 @@
import static org.junit.Assert.*;
+import java.io.IOException;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
import java.nio.charset.Charset;
+import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -33,6 +38,10 @@
import java.sql.Statement;
import java.util.Properties;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSocketFactory;
+
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -44,37 +53,107 @@
import org.teiid.jdbc.FakeServer;
import org.teiid.jdbc.TeiidDriver;
import org.teiid.jdbc.TestMMDatabaseMetaData;
+import org.teiid.net.socket.SocketUtil;
@SuppressWarnings("nls")
public class TestODBCSocketTransport {
-
- static InetSocketAddress addr;
- static ODBCSocketListener odbcTransport;
- @BeforeClass public static void oneTimeSetup() throws Exception {
- SocketConfiguration config = new SocketConfiguration();
- config.setSSLConfiguration(new SSLConfiguration());
- addr = new InetSocketAddress(0);
- config.setBindAddress(addr.getHostName());
- config.setPortNumber(0);
- odbcTransport = new ODBCSocketListener(config, BufferManagerFactory.getStandaloneBufferManager(), 0, 100000);
+public static class AnonSSLSocketFactory extends SSLSocketFactory {
- FakeServer server = new FakeServer();
- server.setUseCallingThread(false);
- server.deployVDB("parts", UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb");
+ private SSLSocketFactory sslSocketFactory;
- TeiidDriver driver = new TeiidDriver();
- driver.setEmbeddedProfile(server);
- odbcTransport.setDriver(driver);
+ public AnonSSLSocketFactory() {
+ try {
+ sslSocketFactory = SSLContext.getDefault().getSocketFactory();
+ } catch (NoSuchAlgorithmException e) {
+ throw new RuntimeException();
+ }
+ }
+
+ public Socket createSocket() throws IOException {
+ return sslSocketFactory.createSocket();
+ }
+
+ public Socket createSocket(InetAddress address, int port,
+ InetAddress localAddress, int localPort) throws IOException {
+ return sslSocketFactory.createSocket(address, port, localAddress,
+ localPort);
+ }
+
+ public Socket createSocket(InetAddress host, int port)
+ throws IOException {
+ return sslSocketFactory.createSocket(host, port);
+ }
+
+ public Socket createSocket(Socket s, String host, int port,
+ boolean autoClose) throws IOException {
+ SSLSocket socket = (SSLSocket)sslSocketFactory.createSocket(s, host, port, autoClose);
+ SocketUtil.addCipherSuite(socket, SocketUtil.ANON_CIPHER_SUITE);
+ return socket;
+ }
+
+ public Socket createSocket(String host, int port,
+ InetAddress localHost, int localPort) throws IOException,
+ UnknownHostException {
+ return sslSocketFactory.createSocket(host, port, localHost,
+ localPort);
+ }
+
+ public Socket createSocket(String host, int port) throws IOException,
+ UnknownHostException {
+ return sslSocketFactory.createSocket(host, port);
+ }
+
+ public String[] getDefaultCipherSuites() {
+ return sslSocketFactory.getDefaultCipherSuites();
+ }
+
+ public String[] getSupportedCipherSuites() {
+ return sslSocketFactory.getSupportedCipherSuites();
+ }
}
- @AfterClass public static void oneTimeTearDown() throws Exception {
- if (odbcTransport != null) {
+ static class FakeOdbcServer {
+ InetSocketAddress addr;
+ ODBCSocketListener odbcTransport;
+
+ public void start() throws Exception {
+ SocketConfiguration config = new SocketConfiguration();
+ SSLConfiguration sslConfig = new SSLConfiguration();
+ sslConfig.setMode(SSLConfiguration.ENABLED);
+ sslConfig.setAuthenticationMode(SSLConfiguration.ANONYMOUS);
+ config.setSSLConfiguration(sslConfig);
+ addr = new InetSocketAddress(0);
+ config.setBindAddress(addr.getHostName());
+ config.setPortNumber(0);
+ odbcTransport = new ODBCSocketListener(config, BufferManagerFactory.getStandaloneBufferManager(), 0, 100000);
+
+ FakeServer server = new FakeServer();
+ server.setUseCallingThread(false);
+ server.deployVDB("parts", UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb");
+
+ TeiidDriver driver = new TeiidDriver();
+ driver.setEmbeddedProfile(server);
+ odbcTransport.setDriver(driver);
+ }
+
+ public void stop() {
odbcTransport.stop();
}
+
}
+ private static FakeOdbcServer odbcServer = new FakeOdbcServer();
+
+ @BeforeClass public static void oneTimeSetup() throws Exception {
+ odbcServer.start();
+ }
+
+ @AfterClass public static void oneTimeTearDown() throws Exception {
+ odbcServer.stop();
+ }
+
Connection conn;
@Before public void setUp() throws Exception {
@@ -82,7 +161,7 @@
Properties p = new Properties();
p.setProperty("user", "testuser");
p.setProperty("password", "testpassword");
- conn = d.connect("jdbc:postgresql://"+addr.getHostName()+":" +odbcTransport.getPort()+"/parts", p);
+ conn = d.connect("jdbc:postgresql://"+odbcServer.addr.getHostName()+":" +odbcServer.odbcTransport.getPort()+"/parts", p);
}
@After public void tearDown() throws Exception {
@@ -181,4 +260,18 @@
ResultSet rs = stmt.executeQuery("select has_function_privilege(100, 'foo')");
rs.next();
}
+
+ @Test public void testSelectSsl() throws Exception {
+ conn.close();
+ Driver d = new Driver();
+ Properties p = new Properties();
+ p.setProperty("user", "testuser");
+ p.setProperty("password", "testpassword");
+ p.setProperty("ssl", "true");
+ p.setProperty("sslfactory", AnonSSLSocketFactory.class.getName());
+ conn = d.connect("jdbc:postgresql://"+odbcServer.addr.getHostName()+":" +odbcServer.odbcTransport.getPort()+"/parts", p);
+ Statement s = conn.createStatement();
+ assertTrue(s.execute("select * from tables order by name"));
+ TestMMDatabaseMetaData.compareResultSet("TestODBCSocketTransport/testSelect", s.getResultSet());
+ }
}
13 years, 7 months
teiid SVN: r3200 - in branches/7.4.x/connectors/translator-jdbc/src: test/java/org/teiid/translator/jdbc/teradata and 1 other directory.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2011-05-26 10:59:56 -0400 (Thu, 26 May 2011)
New Revision: 3200
Modified:
branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java
branches/7.4.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java
Log:
TEIID-1495: more teradata changes based on errors from BQT
Modified: branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java
===================================================================
--- branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java 2011-05-25 22:13:57 UTC (rev 3199)
+++ branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java 2011-05-26 14:59:56 UTC (rev 3200)
@@ -68,19 +68,21 @@
convert.addTypeMapping("double precision", FunctionModifier.DOUBLE); //$NON-NLS-1$
convert.addTypeMapping("numeric(18,0)", FunctionModifier.BIGINTEGER); //$NON-NLS-1$
convert.addTypeMapping("char(1)", FunctionModifier.CHAR); //$NON-NLS-1$
- convert.addConvert(FunctionModifier.INTEGER, FunctionModifier.STRING, new ImplicitConvertModifier());
- convert.addConvert(FunctionModifier.BIGDECIMAL, FunctionModifier.STRING, new ImplicitConvertModifier());
- convert.addConvert(FunctionModifier.BIGINTEGER, FunctionModifier.STRING, new ImplicitConvertModifier());
- convert.addConvert(FunctionModifier.FLOAT, FunctionModifier.STRING, new ImplicitConvertModifier());
- convert.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.STRING, new ImplicitConvertModifier());
- convert.addConvert(FunctionModifier.LONG, FunctionModifier.STRING, new ImplicitConvertModifier());
- convert.addConvert(FunctionModifier.SHORT, FunctionModifier.STRING, new ImplicitConvertModifier());
- convert.addConvert(FunctionModifier.DOUBLE, FunctionModifier.STRING, new ImplicitConvertModifier());
- convert.addConvert(FunctionModifier.BYTE, FunctionModifier.STRING, new ImplicitConvertModifier());
- convert.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.TIME, new TimeModifier("TIME")); //$NON-NLS-1$
- convert.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.DATE, new TimeModifier("DATE")); //$NON-NLS-1$
- convert.addConvert(FunctionModifier.TIME, FunctionModifier.TIMESTAMP, new TimeModifier("TIMESTAMP")); //$NON-NLS-1$
- convert.addConvert(FunctionModifier.DATE, FunctionModifier.TIMESTAMP, new TimeModifier("TIMESTAMP")); //$NON-NLS-1$
+
+ convert.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.TIME, new CastModifier("TIME")); //$NON-NLS-1$
+ convert.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.DATE, new CastModifier("DATE")); //$NON-NLS-1$
+ convert.addConvert(FunctionModifier.TIME, FunctionModifier.TIMESTAMP, new CastModifier("TIMESTAMP")); //$NON-NLS-1$
+ convert.addConvert(FunctionModifier.DATE, FunctionModifier.TIMESTAMP, new CastModifier("TIMESTAMP")); //$NON-NLS-1$
+
+ convert.addConvert(FunctionModifier.STRING, FunctionModifier.INTEGER, new CastModifier("integer")); //$NON-NLS-1$
+ convert.addConvert(FunctionModifier.STRING, FunctionModifier.BIGDECIMAL, new CastModifier("decimal(37,5)"));//$NON-NLS-1$
+ convert.addConvert(FunctionModifier.STRING, FunctionModifier.BIGINTEGER, new CastModifier("numeric(18,0)"));//$NON-NLS-1$
+ convert.addConvert(FunctionModifier.STRING, FunctionModifier.FLOAT, new CastModifier("float"));//$NON-NLS-1$
+ convert.addConvert(FunctionModifier.STRING, FunctionModifier.BOOLEAN, new CastModifier("byteint"));//$NON-NLS-1$
+ convert.addConvert(FunctionModifier.STRING, FunctionModifier.LONG, new CastModifier("numeric(18,0)"));//$NON-NLS-1$
+ convert.addConvert(FunctionModifier.STRING, FunctionModifier.SHORT, new CastModifier("smallint"));//$NON-NLS-1$
+ convert.addConvert(FunctionModifier.STRING, FunctionModifier.DOUBLE, new CastModifier("double precision"));//$NON-NLS-1$
+ convert.addConvert(FunctionModifier.STRING, FunctionModifier.BYTE, new CastModifier("byteint")); //$NON-NLS-1$
convert.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new FunctionModifier() {
@Override
@@ -308,9 +310,6 @@
Expression expr2 = function.getParameters().get(1);
if (function.getParameters().size() > 2) {
Expression expr3 = function.getParameters().get(2);
- target.add("(");//$NON-NLS-1$
- target.add(expr3);
- target.add("+");//$NON-NLS-1$
target.add("position("); //$NON-NLS-1$
target.addAll(expressionToString(expr1, this.convertModifier));
target.add( " in "); //$NON-NLS-1$
@@ -318,8 +317,7 @@
target.addAll(expressionToString(expr2, this.convertModifier));
target.add(","); //$NON-NLS-1$
target.add(expr3);
- target.add(")"); //$NON-NLS-1$
- target.add("))"); //$NON-NLS-1$
+ target.add("))"); //$NON-NLS-1$
}
else {
target.add("position("); //$NON-NLS-1$
@@ -379,17 +377,9 @@
}
}
- public static class ImplicitConvertModifier extends FunctionModifier {
- @Override
- public List<?> translate(Function function) {
- return Arrays.asList(function.getParameters().get(0));
- }
- }
-
-
- public static class TimeModifier extends FunctionModifier {
+ public static class CastModifier extends FunctionModifier {
private String target;
- public TimeModifier(String target) {
+ public CastModifier(String target) {
this.target = target;
}
@Override
Modified: branches/7.4.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java
===================================================================
--- branches/7.4.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java 2011-05-25 22:13:57 UTC (rev 3199)
+++ branches/7.4.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java 2011-05-26 14:59:56 UTC (rev 3200)
@@ -112,17 +112,21 @@
@Test public void testByteToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "string", "1");
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "string", "cast(1 AS varchar(4000))");
}
@Test public void testByte2ToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)-1), Byte.class), "string", "-1");
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)-1), Byte.class), "string", "cast(-1 AS varchar(4000))");
}
@Test public void testDoubleToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.0), Double.class), "string", "1.0");
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.0), Double.class), "string", "cast(1.0 AS varchar(4000))");
}
+ @Test public void testStringToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("1.0", String.class), "double", "cast('1.0' AS double precision)");
+ }
+
@Test public void testInDecompose() throws Exception {
Expression left = LANG_FACTORY.createLiteral("1", String.class);
List<Expression> right = new ArrayList<Expression>();
@@ -196,7 +200,7 @@
@Test public void testLocateFunction() throws Exception {
String input = "SELECT INTKEY, STRINGKEY, SHORTVALUE FROM BQT1.SmallA WHERE (LOCATE(0, STRINGKEY) = 2) OR (LOCATE(2, SHORTVALUE, 4) = 6) ORDER BY intkey";
- String out = "SELECT SmallA.IntKey, SmallA.StringKey, SmallA.ShortValue FROM SmallA WHERE position('0' in SmallA.StringKey) = 2 OR (4+position('2' in substr(cast(SmallA.ShortValue AS varchar(100)),4))) = 6 ORDER BY SmallA.IntKey";
+ String out = "SELECT SmallA.IntKey, SmallA.StringKey, SmallA.ShortValue FROM SmallA WHERE position('0' in SmallA.StringKey) = 2 OR position('2' in substr(cast(SmallA.ShortValue AS varchar(100)),4)) = 6 ORDER BY SmallA.IntKey";
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, null, input, out, TRANSLATOR);
}
}
13 years, 7 months
teiid SVN: r3199 - branches/7.1.x/connectors/sandbox/connector-template/src/main/resources.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2011-05-25 18:13:57 -0400 (Wed, 25 May 2011)
New Revision: 3199
Added:
branches/7.1.x/connectors/sandbox/connector-template/src/main/resources/coherence-ds.xml
Log:
TEIID-1594 added datasource xml file for testing
Added: branches/7.1.x/connectors/sandbox/connector-template/src/main/resources/coherence-ds.xml
===================================================================
--- branches/7.1.x/connectors/sandbox/connector-template/src/main/resources/coherence-ds.xml (rev 0)
+++ branches/7.1.x/connectors/sandbox/connector-template/src/main/resources/coherence-ds.xml 2011-05-25 22:13:57 UTC (rev 3199)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<connection-factories>
+
+ <no-tx-connection-factory>
+ <!-- The jndi name of the DataSource -->
+ <jndi-name>CoherenceDS</jndi-name>
+
+ <!-- The resource archive file that defines JCA connection for Coherence (do not change this) -->
+ <rar-name>coherence_connector-0.1.rar</rar-name>
+ <!-- connection interface; (do not change this) -->
+ <connection-definition>javax.resource.cci.ConnectionFactory</connection-definition>
+
+ <max-pool-size>20</max-pool-size>
+
+ </no-tx-connection-factory>
+
+</connection-factories>
\ No newline at end of file
Property changes on: branches/7.1.x/connectors/sandbox/connector-template/src/main/resources/coherence-ds.xml
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
13 years, 7 months