Author: shawkins
Date: 2012-01-09 14:33:46 -0500 (Mon, 09 Jan 2012)
New Revision: 3782
Added:
trunk/api/src/main/java/org/teiid/language/BatchedCommand.java
trunk/api/src/main/java/org/teiid/language/Parameter.java
Removed:
trunk/api/src/main/java/org/teiid/language/IteratorValueSource.java
Modified:
trunk/api/src/main/java/org/teiid/language/Delete.java
trunk/api/src/main/java/org/teiid/language/Insert.java
trunk/api/src/main/java/org/teiid/language/Literal.java
trunk/api/src/main/java/org/teiid/language/Update.java
trunk/api/src/main/java/org/teiid/language/visitor/AbstractLanguageVisitor.java
trunk/api/src/main/java/org/teiid/language/visitor/LanguageObjectVisitor.java
trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java
trunk/api/src/main/java/org/teiid/translator/BaseDelegatingExecutionFactory.java
trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java
trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCBaseExecution.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCQueryExecution.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCUpdateExecution.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/TranslatedCommand.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/SubstringFunctionModifier.java
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCUpdateExecution.java
trunk/documentation/developer-guide/src/main/docbook/en-US/content/translator-api.xml
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/ProjectIntoNode.java
trunk/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java
trunk/engine/src/test/java/org/teiid/query/processor/relational/TestProjectIntoNode.java
Log:
TEIID-1894 removed the bulk insert mode from the project into node and consolidated the
translator api via an new expression type, Parameter
Added: trunk/api/src/main/java/org/teiid/language/BatchedCommand.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/BatchedCommand.java
(rev 0)
+++ trunk/api/src/main/java/org/teiid/language/BatchedCommand.java 2012-01-09 19:33:46 UTC
(rev 3782)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.language;
+
+import java.util.Iterator;
+import java.util.List;
+
+public interface BatchedCommand extends Command {
+
+ Iterator<? extends List<?>> getParameterValues();
+
+ void setParameterValues(Iterator<? extends List<?>> values);
+
+}
Property changes on: trunk/api/src/main/java/org/teiid/language/BatchedCommand.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/api/src/main/java/org/teiid/language/Delete.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/Delete.java 2012-01-07 16:10:27 UTC (rev
3781)
+++ trunk/api/src/main/java/org/teiid/language/Delete.java 2012-01-09 19:33:46 UTC (rev
3782)
@@ -22,15 +22,19 @@
package org.teiid.language;
+import java.util.Iterator;
+import java.util.List;
+
import org.teiid.language.visitor.LanguageObjectVisitor;
/**
* Represents a DELETE command.
*/
-public class Delete extends BaseLanguageObject implements Command {
+public class Delete extends BaseLanguageObject implements BatchedCommand {
private NamedTable table;
private Condition where;
+ private Iterator<? extends List<?>> parameterValues;
public Delete(NamedTable group, Condition criteria) {
this.table = group;
@@ -72,5 +76,14 @@
public void setWhere(Condition criteria) {
this.where = criteria;
}
+
+ @Override
+ public Iterator<? extends List<?>> getParameterValues() {
+ return parameterValues;
+ }
+
+ public void setParameterValues(Iterator<? extends List<?>>
parameterValues) {
+ this.parameterValues = parameterValues;
+ }
}
Modified: trunk/api/src/main/java/org/teiid/language/Insert.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/Insert.java 2012-01-07 16:10:27 UTC (rev
3781)
+++ trunk/api/src/main/java/org/teiid/language/Insert.java 2012-01-09 19:33:46 UTC (rev
3782)
@@ -22,16 +22,18 @@
package org.teiid.language;
+import java.util.Iterator;
import java.util.List;
import org.teiid.language.visitor.LanguageObjectVisitor;
-public class Insert extends BaseLanguageObject implements Command {
+public class Insert extends BaseLanguageObject implements BatchedCommand {
private NamedTable table;
private List<ColumnReference> columns;
private InsertValueSource valueSource;
+ private Iterator<? extends List<?>> parameterValues;
public Insert(NamedTable group, List<ColumnReference> elements,
InsertValueSource valueSource) {
this.table = group;
@@ -66,5 +68,14 @@
public void setValueSource(InsertValueSource values) {
this.valueSource = values;
}
+
+ @Override
+ public Iterator<? extends List<?>> getParameterValues() {
+ return parameterValues;
+ }
+
+ public void setParameterValues(Iterator<? extends List<?>>
parameterValues) {
+ this.parameterValues = parameterValues;
+ }
}
Deleted: trunk/api/src/main/java/org/teiid/language/IteratorValueSource.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/IteratorValueSource.java 2012-01-07
16:10:27 UTC (rev 3781)
+++ trunk/api/src/main/java/org/teiid/language/IteratorValueSource.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.language;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.teiid.language.visitor.LanguageObjectVisitor;
-
-public class IteratorValueSource<T extends List<?>> extends
BaseLanguageObject implements InsertValueSource {
-
- private Iterator<T> iter;
- private int columnCount;
-
- public IteratorValueSource(Iterator<T> iter, int columnCount) {
- this.iter = iter;
- this.columnCount = columnCount;
- }
-
- /**
- * A memory safe iterator of the insert values. Only 1 iterator is associated
- * with the value source. Once it is consumed there are no more values.
- * @return
- */
- public Iterator<T> getIterator() {
- return iter;
- }
-
- public int getColumnCount() {
- return columnCount;
- }
-
- @Override
- public void acceptVisitor(LanguageObjectVisitor visitor) {
- visitor.visit(this);
- }
-
-}
Modified: trunk/api/src/main/java/org/teiid/language/Literal.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/Literal.java 2012-01-07 16:10:27 UTC (rev
3781)
+++ trunk/api/src/main/java/org/teiid/language/Literal.java 2012-01-09 19:33:46 UTC (rev
3782)
@@ -33,8 +33,6 @@
private Object value;
private Class<?> type;
- private boolean bindValue;
- private boolean multiValued;
private boolean isBindEligible;
public Literal(Object value, Class<?> type) {
@@ -58,22 +56,6 @@
this.value = value;
}
- public boolean isBindValue() {
- return bindValue;
- }
-
- public void setBindValue(boolean bindValue) {
- this.bindValue = bindValue;
- }
-
- public boolean isMultiValued() {
- return multiValued;
- }
-
- public void setMultiValued(boolean multiValued) {
- this.multiValued = multiValued;
- }
-
public void setType(Class<?> type) {
this.type = type;
}
@@ -81,7 +63,6 @@
/**
* Set by the optimizer if the literal was created by the evaluation of another
expression.
* Setting to true will not always result in the value being handled as a bind value.
- * That can be forced {@link #isBindValue()}
* @return
*/
public boolean isBindEligible() {
Added: trunk/api/src/main/java/org/teiid/language/Parameter.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/Parameter.java (rev
0)
+++ trunk/api/src/main/java/org/teiid/language/Parameter.java 2012-01-09 19:33:46 UTC (rev
3782)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.language;
+
+import org.teiid.language.visitor.LanguageObjectVisitor;
+
+public class Parameter extends BaseLanguageObject implements Expression {
+
+ private Class<?> type;
+ private int valueIndex;
+
+ @Override
+ public Class<?> getType() {
+ return type;
+ }
+
+ public void setType(Class<?> type) {
+ this.type = type;
+ }
+
+ @Override
+ public void acceptVisitor(LanguageObjectVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ public void setValueIndex(int valueIndex) {
+ this.valueIndex = valueIndex;
+ }
+
+ /**
+ * 0-based index of the parameter values in the {@link
BatchedCommand#getParameterValues()} row value
+ * @return
+ */
+ public int getValueIndex() {
+ return valueIndex;
+ }
+
+}
Property changes on: trunk/api/src/main/java/org/teiid/language/Parameter.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/api/src/main/java/org/teiid/language/Update.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/Update.java 2012-01-07 16:10:27 UTC (rev
3781)
+++ trunk/api/src/main/java/org/teiid/language/Update.java 2012-01-09 19:33:46 UTC (rev
3782)
@@ -22,6 +22,7 @@
package org.teiid.language;
+import java.util.Iterator;
import java.util.List;
import org.teiid.language.visitor.LanguageObjectVisitor;
@@ -29,11 +30,12 @@
/**
* Represents an UPDATE command in the language objects.
*/
-public class Update extends BaseLanguageObject implements Command {
+public class Update extends BaseLanguageObject implements BatchedCommand {
private NamedTable table;
private List<SetClause> changes;
private Condition where;
+ private Iterator<? extends List<?>> parameterValues;
public Update(NamedTable group, List<SetClause> changes, Condition criteria) {
this.table = group;
@@ -68,5 +70,14 @@
public void setWhere(Condition criteria) {
this.where = criteria;
}
+
+ @Override
+ public Iterator<? extends List<?>> getParameterValues() {
+ return parameterValues;
+ }
+
+ public void setParameterValues(Iterator<? extends List<?>>
parameterValues) {
+ this.parameterValues = parameterValues;
+ }
}
Modified: trunk/api/src/main/java/org/teiid/language/visitor/AbstractLanguageVisitor.java
===================================================================
---
trunk/api/src/main/java/org/teiid/language/visitor/AbstractLanguageVisitor.java 2012-01-07
16:10:27 UTC (rev 3781)
+++
trunk/api/src/main/java/org/teiid/language/visitor/AbstractLanguageVisitor.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -24,42 +24,7 @@
import java.util.Collection;
-import org.teiid.language.AggregateFunction;
-import org.teiid.language.AndOr;
-import org.teiid.language.Argument;
-import org.teiid.language.BatchedUpdates;
-import org.teiid.language.Call;
-import org.teiid.language.ColumnReference;
-import org.teiid.language.Comparison;
-import org.teiid.language.Delete;
-import org.teiid.language.DerivedColumn;
-import org.teiid.language.DerivedTable;
-import org.teiid.language.Exists;
-import org.teiid.language.ExpressionValueSource;
-import org.teiid.language.Function;
-import org.teiid.language.GroupBy;
-import org.teiid.language.In;
-import org.teiid.language.Insert;
-import org.teiid.language.IsNull;
-import org.teiid.language.IteratorValueSource;
-import org.teiid.language.Join;
-import org.teiid.language.LanguageObject;
-import org.teiid.language.Like;
-import org.teiid.language.Limit;
-import org.teiid.language.Literal;
-import org.teiid.language.NamedTable;
-import org.teiid.language.Not;
-import org.teiid.language.OrderBy;
-import org.teiid.language.ScalarSubquery;
-import org.teiid.language.SearchedCase;
-import org.teiid.language.SearchedWhenClause;
-import org.teiid.language.Select;
-import org.teiid.language.SetClause;
-import org.teiid.language.SetQuery;
-import org.teiid.language.SortSpecification;
-import org.teiid.language.SubqueryComparison;
-import org.teiid.language.SubqueryIn;
-import org.teiid.language.Update;
+import org.teiid.language.*;
/**
@@ -147,5 +112,5 @@
public void visit(SetQuery obj) {}
public void visit(SetClause obj) {}
public void visit(SearchedWhenClause obj) {}
- public void visit(IteratorValueSource obj) {}
+ public void visit(Parameter obj) {}
}
Modified: trunk/api/src/main/java/org/teiid/language/visitor/LanguageObjectVisitor.java
===================================================================
---
trunk/api/src/main/java/org/teiid/language/visitor/LanguageObjectVisitor.java 2012-01-07
16:10:27 UTC (rev 3781)
+++
trunk/api/src/main/java/org/teiid/language/visitor/LanguageObjectVisitor.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -22,45 +22,7 @@
package org.teiid.language.visitor;
-import org.teiid.language.AggregateFunction;
-import org.teiid.language.AndOr;
-import org.teiid.language.Argument;
-import org.teiid.language.BatchedUpdates;
-import org.teiid.language.Call;
-import org.teiid.language.ColumnReference;
-import org.teiid.language.Comparison;
-import org.teiid.language.Delete;
-import org.teiid.language.DerivedColumn;
-import org.teiid.language.DerivedTable;
-import org.teiid.language.Exists;
-import org.teiid.language.ExpressionValueSource;
-import org.teiid.language.Function;
-import org.teiid.language.GroupBy;
-import org.teiid.language.In;
-import org.teiid.language.Insert;
-import org.teiid.language.IsNull;
-import org.teiid.language.IteratorValueSource;
-import org.teiid.language.Join;
-import org.teiid.language.Like;
-import org.teiid.language.Limit;
-import org.teiid.language.Literal;
-import org.teiid.language.NamedTable;
-import org.teiid.language.Not;
-import org.teiid.language.OrderBy;
-import org.teiid.language.ScalarSubquery;
-import org.teiid.language.SearchedCase;
-import org.teiid.language.SearchedWhenClause;
-import org.teiid.language.Select;
-import org.teiid.language.SetClause;
-import org.teiid.language.SetQuery;
-import org.teiid.language.SortSpecification;
-import org.teiid.language.SubqueryComparison;
-import org.teiid.language.SubqueryIn;
-import org.teiid.language.Update;
-import org.teiid.language.WindowFunction;
-import org.teiid.language.WindowSpecification;
-import org.teiid.language.With;
-import org.teiid.language.WithItem;
+import org.teiid.language.*;
/**
*/
@@ -99,9 +61,9 @@
public void visit(SetQuery obj);
public void visit(SetClause obj);
public void visit(SearchedWhenClause obj);
- public void visit(IteratorValueSource obj);
public void visit(With obj);
public void visit(WithItem obj);
public void visit(WindowFunction windowFunction);
public void visit(WindowSpecification windowSpecification);
+ public void visit(Parameter obj);
}
Modified: trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java 2012-01-07
16:10:27 UTC (rev 3781)
+++ trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -31,51 +31,7 @@
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.StringUtil;
-import org.teiid.language.AggregateFunction;
-import org.teiid.language.AndOr;
-import org.teiid.language.Argument;
-import org.teiid.language.Call;
-import org.teiid.language.ColumnReference;
-import org.teiid.language.Command;
-import org.teiid.language.Comparison;
-import org.teiid.language.Condition;
-import org.teiid.language.Delete;
-import org.teiid.language.DerivedColumn;
-import org.teiid.language.DerivedTable;
-import org.teiid.language.Exists;
-import org.teiid.language.Expression;
-import org.teiid.language.ExpressionValueSource;
-import org.teiid.language.Function;
-import org.teiid.language.GroupBy;
-import org.teiid.language.In;
-import org.teiid.language.Insert;
-import org.teiid.language.IsNull;
-import org.teiid.language.IteratorValueSource;
-import org.teiid.language.Join;
-import org.teiid.language.LanguageObject;
-import org.teiid.language.Like;
-import org.teiid.language.Limit;
-import org.teiid.language.Literal;
-import org.teiid.language.NamedTable;
-import org.teiid.language.Not;
-import org.teiid.language.OrderBy;
-import org.teiid.language.QueryExpression;
-import org.teiid.language.SQLConstants;
-import org.teiid.language.ScalarSubquery;
-import org.teiid.language.SearchedCase;
-import org.teiid.language.SearchedWhenClause;
-import org.teiid.language.Select;
-import org.teiid.language.SetClause;
-import org.teiid.language.SetQuery;
-import org.teiid.language.SortSpecification;
-import org.teiid.language.SubqueryComparison;
-import org.teiid.language.SubqueryIn;
-import org.teiid.language.TableReference;
-import org.teiid.language.Update;
-import org.teiid.language.WindowFunction;
-import org.teiid.language.WindowSpecification;
-import org.teiid.language.With;
-import org.teiid.language.WithItem;
+import org.teiid.language.*;
import org.teiid.language.Argument.Direction;
import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.language.SQLConstants.Tokens;
@@ -538,17 +494,10 @@
}
@Override
- public void visit(IteratorValueSource obj) {
- buffer.append(VALUES).append(Tokens.SPACE).append(Tokens.LPAREN);
- for (int i = 0; i < obj.getColumnCount(); i++) {
- if (i > 0) {
- buffer.append(", "); //$NON-NLS-1$
- }
- buffer.append("?"); //$NON-NLS-1$
- }
- buffer.append(Tokens.RPAREN);
+ public void visit(Parameter obj) {
+ buffer.append('?');
}
-
+
public void visit(IsNull obj) {
append(obj.getExpression());
buffer.append(Tokens.SPACE)
@@ -664,9 +613,7 @@
}
public void visit(Literal obj) {
- if (obj.isBindValue()) {
- buffer.append("?"); //$NON-NLS-1$
- } else if (obj.getValue() == null) {
+ if (obj.getValue() == null) {
buffer.append(NULL);
} else {
Class<?> type = obj.getType();
Modified:
trunk/api/src/main/java/org/teiid/translator/BaseDelegatingExecutionFactory.java
===================================================================
---
trunk/api/src/main/java/org/teiid/translator/BaseDelegatingExecutionFactory.java 2012-01-07
16:10:27 UTC (rev 3781)
+++
trunk/api/src/main/java/org/teiid/translator/BaseDelegatingExecutionFactory.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -254,10 +254,6 @@
return delegate.supportsInlineViews();
}
@Override
- public boolean supportsInsertWithIterator() {
- return delegate.supportsInsertWithIterator();
- }
- @Override
public boolean supportsInsertWithQueryExpression() {
return delegate.supportsInsertWithQueryExpression();
}
Modified: trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java
===================================================================
--- trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2012-01-07 16:10:27
UTC (rev 3781)
+++ trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2012-01-09 19:33:46
UTC (rev 3782)
@@ -23,7 +23,6 @@
package org.teiid.translator;
import java.util.Collection;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -804,16 +803,6 @@
return false;
}
- /**
- * Support indicates that the connector can accept INSERTs
- * with values specified by an {@link Iterator}
- * @since 7.1
- * @return
- */
- public boolean supportsInsertWithIterator() {
- return false;
- }
-
public static <T> T getInstance(Class<T> expectedType, String className,
Collection<?> ctorObjs, Class<? extends T> defaultClass) throws
TranslatorException {
try {
if (className == null) {
Modified: trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-01-07 16:10:27 UTC
(rev 3781)
+++ trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-01-09 19:33:46 UTC
(rev 3782)
@@ -57,7 +57,9 @@
<li>BigDecimal division that returns a quotient that is equal to zero will have a
scale of zero as well. Prior releases would typically return a zero value with a scale of
16.
<li>The env function no longer returns the value for the session id, the
session_id() function should be used instead.
<li>The CommandContext no longer provides getEnvironmentProperties()
- <li>Unaliased derived columns in the SELECT clause have different default names
than prior releases. The name will be exprX where X is the SELECT clause position.
+ <li>Unaliased derived columns in the SELECT clause have different default names
than prior releases. The name will be exprX where X is the SELECT clause position.
+ <li>The translator API facilities for iterator/bulk updates were combined and
updated. Multi-valued literals were replaced by the Parameter class with an associated
value iterator
+ available on the BatchedCommand. The IteratorValueSource class was also removed.
</ul>
<h4>from 7.5</h4>
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCBaseExecution.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCBaseExecution.java 2012-01-07
16:10:27 UTC (rev 3781)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCBaseExecution.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -32,12 +32,13 @@
import org.teiid.language.Command;
import org.teiid.language.Literal;
+import org.teiid.language.Parameter;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.logging.MessageLevel;
-import org.teiid.translator.TranslatorException;
import org.teiid.translator.Execution;
import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.TranslatorException;
/**
@@ -77,25 +78,31 @@
/**
* Bind the values in the TranslatedCommand to the PreparedStatement
*/
- protected void bindPreparedStatementValues(PreparedStatement stmt, TranslatedCommand
tc, int rowCount) throws SQLException {
- List<?> params = tc.getPreparedValues();
+ protected void bind(PreparedStatement stmt, List<?> params, List<?>
batchValues)
+ throws SQLException {
+ for (int i = 0; i< params.size(); i++) {
+ Object paramValue = params.get(i);
+ Object value = null;
+ Class<?> paramType = null;
+ if (paramValue instanceof Literal) {
+ Literal litParam = (Literal)paramValue;
+ value = litParam.getValue();
+ paramType = litParam.getType();
+ } else {
+ Parameter param = (Parameter)paramValue;
+ if (batchValues == null) {
+ throw new AssertionError("Expected batchValues when using a
Parameter"); //$NON-NLS-1$
+ }
+ value = batchValues.get(param.getValueIndex());
+ paramType = param.getType();
+ }
+ this.executionFactory.bindValue(stmt, value, paramType, i+1);
+ }
+ if (batchValues != null) {
+ stmt.addBatch();
+ }
+ }
- for (int row = 0; row < rowCount; row++) {
- for (int i = 0; i< params.size(); i++) {
- Literal paramValue = (Literal)params.get(i);
- Object value = paramValue.getValue();
- if (paramValue.isMultiValued()) {
- value = ((List<?>)value).get(row);
- }
- Class<?> paramType = paramValue.getType();
- this.executionFactory.bindValue(stmt, value, paramType, i+1);
- }
- if (rowCount > 1) {
- stmt.addBatch();
- }
- }
- }
-
//
===========================================================================================================================
// Methods
//
===========================================================================================================================
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2012-01-07
16:10:27 UTC (rev 3781)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -47,34 +47,14 @@
import javax.sql.DataSource;
import org.teiid.core.util.PropertiesUtils;
-import org.teiid.language.Argument;
-import org.teiid.language.Call;
-import org.teiid.language.ColumnReference;
-import org.teiid.language.Command;
-import org.teiid.language.Expression;
-import org.teiid.language.Function;
-import org.teiid.language.LanguageObject;
-import org.teiid.language.Limit;
-import org.teiid.language.Literal;
-import org.teiid.language.QueryExpression;
-import org.teiid.language.SQLConstants;
-import org.teiid.language.SetQuery;
+import org.teiid.language.*;
import org.teiid.language.Argument.Direction;
import org.teiid.language.SetQuery.Operation;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.RuntimeMetadata;
-import org.teiid.translator.ExecutionContext;
-import org.teiid.translator.ExecutionFactory;
-import org.teiid.translator.ProcedureExecution;
-import org.teiid.translator.ResultSetExecution;
-import org.teiid.translator.SourceSystemFunctions;
-import org.teiid.translator.Translator;
-import org.teiid.translator.TranslatorException;
-import org.teiid.translator.TranslatorProperty;
-import org.teiid.translator.TypeFacility;
-import org.teiid.translator.UpdateExecution;
+import org.teiid.translator.*;
/**
@@ -446,11 +426,6 @@
}
@Override
- public boolean supportsInsertWithIterator() {
- return super.supportsBulkUpdate();
- }
-
- @Override
public boolean supportsBatchedUpdates() {
return true;
}
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCQueryExecution.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCQueryExecution.java 2012-01-07
16:10:27 UTC (rev 3781)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCQueryExecution.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -36,10 +36,10 @@
import org.teiid.language.QueryExpression;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
-import org.teiid.translator.TranslatorException;
import org.teiid.translator.DataNotAvailableException;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.ResultSetExecution;
+import org.teiid.translator.TranslatorException;
/**
@@ -82,7 +82,7 @@
results = getStatement().executeQuery(sql);
} else {
PreparedStatement pstatement = getPreparedStatement(sql);
- bindPreparedStatementValues(pstatement, translatedComm, 1);
+ bind(pstatement, translatedComm.getPreparedValues(), null);
results = pstatement.executeQuery();
}
addStatementWarnings();
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCUpdateExecution.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCUpdateExecution.java 2012-01-07
16:10:27 UTC (rev 3781)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCUpdateExecution.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -29,11 +29,10 @@
import java.util.Iterator;
import java.util.List;
+import org.teiid.language.BatchedCommand;
import org.teiid.language.BatchedUpdates;
import org.teiid.language.Command;
import org.teiid.language.Insert;
-import org.teiid.language.IteratorValueSource;
-import org.teiid.language.Literal;
import org.teiid.translator.DataNotAvailableException;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.TranslatorException;
@@ -107,7 +106,7 @@
}
pstmt = getPreparedStatement(tCommand.getSql());
}
- bindPreparedStatementValues(pstmt, tCommand, 1);
+ bind(pstmt, tCommand.getPreparedValues(), null);
pstmt.addBatch();
} else {
if (previousCommand != null && previousCommand.isPrepared())
{
@@ -170,57 +169,43 @@
} else {
PreparedStatement pstatement = getPreparedStatement(sql);
- if (command instanceof Insert) {
- Insert insert = (Insert)command;
- if (insert.getValueSource() instanceof IteratorValueSource) {
- commitType = getAutoCommit(translatedComm);
- if (commitType) {
- connection.setAutoCommit(false);
- }
-
- IteratorValueSource<List<Object>> ivs =
(IteratorValueSource)insert.getValueSource();
- List<Object>[] values = new List[ivs.getColumnCount()];
- for (int i = 0; i < ivs.getColumnCount(); i++) {
- values[i] = new ArrayList<Object>();
- Literal literal = new Literal(values[i],
insert.getColumns().get(i).getType());
- literal.setMultiValued(true);
- translatedComm.getPreparedValues().add(literal);
- }
- Iterator<List<Object>> i = ivs.getIterator();
- int maxBatchSize =
this.executionFactory.getMaxPreparedInsertBatchSize();
- while (i.hasNext()) {
- int batchSize = 0;
- while (i.hasNext() && batchSize++ < maxBatchSize) {
- List<Object> next = i.next();
- for (int j = 0; j < ivs.getColumnCount(); j++) {
- values[j].add(next.get(j));
- }
- }
- updateCount += executePreparedBatch(translatedComm, pstatement,
batchSize);
- for (int j = 0; j < ivs.getColumnCount(); j++) {
- values[j].clear();
- }
- }
- succeeded = true;
- return new int[updateCount];
- }
- }
+ Iterator<? extends List<?>> vi = null;
+ if (command instanceof BatchedCommand) {
+ BatchedCommand batchCommand = (BatchedCommand)command;
+ vi = batchCommand.getParameterValues();
+ }
- int rowCount = 1;
- for (int i = 0; i< translatedComm.getPreparedValues().size(); i++) {
- Literal paramValue =
(Literal)translatedComm.getPreparedValues().get(i);
- if (paramValue.isMultiValued()) {
- rowCount = ((List<?>)paramValue.getValue()).size();
- break;
- }
- }
- if (rowCount > 1) {
+ if (vi != null) {
commitType = getAutoCommit(translatedComm);
if (commitType) {
connection.setAutoCommit(false);
}
+ int maxBatchSize = (command instanceof
Insert)?this.executionFactory.getMaxPreparedInsertBatchSize():Integer.MAX_VALUE;
+ boolean done = false;
+ outer: while (!done) {
+ for (int i = 0; i < maxBatchSize; i++) {
+ if (vi.hasNext()) {
+ List<?> values = vi.next();
+ bind(pstatement, translatedComm.getPreparedValues(), values);
+ } else {
+ if (i == 0) {
+ break outer;
+ }
+ done = true;
+ break;
+ }
+ }
+ int[] results = pstatement.executeBatch();
+
+ for (int i=0; i<results.length; i++) {
+ updateCount += results[i];
+ }
+ }
+ } else {
+ bind(pstatement, translatedComm.getPreparedValues(), null);
+ updateCount = pstatement.executeUpdate();
+ addStatementWarnings();
}
- updateCount = executePreparedBatch(translatedComm, pstatement,
rowCount);
succeeded = true;
}
return new int[] {updateCount};
@@ -233,23 +218,6 @@
}
}
- private int executePreparedBatch(TranslatedCommand translatedComm, PreparedStatement
pstatement, int rowCount)
- throws SQLException {
- bindPreparedStatementValues(pstatement, translatedComm, rowCount);
- int updateCount = 0;
- if (rowCount > 1) {
- int[] results = pstatement.executeBatch();
-
- for (int i=0; i<results.length; i++) {
- updateCount += results[i];
- }
- } else {
- updateCount = pstatement.executeUpdate();
- }
- addStatementWarnings();
- return updateCount;
- }
-
/**
* @param command
* @return
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java 2012-01-07
16:10:27 UTC (rev 3781)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -39,20 +39,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.teiid.language.Argument;
-import org.teiid.language.Call;
-import org.teiid.language.Command;
-import org.teiid.language.Comparison;
-import org.teiid.language.DerivedColumn;
-import org.teiid.language.ExpressionValueSource;
-import org.teiid.language.Function;
-import org.teiid.language.In;
-import org.teiid.language.LanguageObject;
-import org.teiid.language.Like;
-import org.teiid.language.Literal;
-import org.teiid.language.NamedTable;
-import org.teiid.language.SearchedCase;
-import org.teiid.language.SetClause;
+import org.teiid.language.*;
import org.teiid.language.Argument.Direction;
import org.teiid.language.SQLConstants.Reserved;
import org.teiid.language.SQLConstants.Tokens;
@@ -255,12 +242,18 @@
}
return parts;
}
+
+ @Override
+ public void visit(Parameter obj) {
+ buffer.append(UNDEFINED_PARAM);
+ preparedValues.add(obj);
+ }
/**
* @see
org.teiid.language.visitor.SQLStringVisitor#visit(org.teiid.language.Literal)
*/
public void visit(Literal obj) {
- if (this.prepared && ((replaceWithBinding &&
obj.isBindEligible()) || TranslatedCommand.isBindEligible(obj) || obj.isBindValue())) {
+ if (this.prepared && ((replaceWithBinding &&
obj.isBindEligible()) || TranslatedCommand.isBindEligible(obj))) {
buffer.append(UNDEFINED_PARAM);
preparedValues.add(obj);
} else {
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/TranslatedCommand.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/TranslatedCommand.java 2012-01-07
16:10:27 UTC (rev 3781)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/TranslatedCommand.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -27,12 +27,11 @@
import java.util.List;
import org.teiid.language.Command;
-import org.teiid.language.Insert;
-import org.teiid.language.IteratorValueSource;
import org.teiid.language.Literal;
+import org.teiid.language.Parameter;
import org.teiid.language.visitor.CollectorVisitor;
-import org.teiid.translator.TranslatorException;
import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.TranslatorException;
import org.teiid.translator.TypeFacility;
@@ -86,15 +85,14 @@
* @return
*/
private boolean hasBindValue(Command command) {
+ if (!CollectorVisitor.collectObjects(Parameter.class, command).isEmpty()) {
+ return true;
+ }
for (Literal l : CollectorVisitor.collectObjects(Literal.class, command)) {
- if (l.isBindValue() || isBindEligible(l)) {
+ if (isBindEligible(l)) {
return true;
}
}
- if (command instanceof Insert) {
- Insert insert = (Insert)command;
- return insert.getValueSource() instanceof IteratorValueSource<?>;
- }
return false;
}
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/SubstringFunctionModifier.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/SubstringFunctionModifier.java 2012-01-07
16:10:27 UTC (rev 3781)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/SubstringFunctionModifier.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -55,10 +55,8 @@
Boolean isNegative = null;
if (length instanceof Literal) {
Literal l = (Literal)length;
- if (!l.isMultiValued()) {
- int value = (Integer)l.getValue();
- isNegative = value < 0;
- }
+ int value = (Integer)l.getValue();
+ isNegative = value < 0;
}
Expression maxLength = new Function(
SourceSystemFunctions.SUBTRACT_OP,
Modified:
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCUpdateExecution.java
===================================================================
---
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCUpdateExecution.java 2012-01-07
16:10:27 UTC (rev 3781)
+++
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCUpdateExecution.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -24,50 +24,32 @@
import java.sql.Connection;
import java.sql.PreparedStatement;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.mockito.Mockito;
-import org.teiid.language.Command;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.language.Expression;
import org.teiid.language.ExpressionValueSource;
import org.teiid.language.Insert;
-import org.teiid.language.IteratorValueSource;
-import org.teiid.language.Literal;
+import org.teiid.language.Parameter;
import org.teiid.translator.ExecutionContext;
public class TestJDBCUpdateExecution {
- @Test public void testBulkUpdate() throws Exception {
- Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB,
"insert into BQT1.SmallA (IntKey, IntNum) values (1, 2)"); //$NON-NLS-1$
- Literal value =
((Literal)((ExpressionValueSource)((Insert)command).getValueSource()).getValues().get(0));
- Literal value1 =
((Literal)((ExpressionValueSource)((Insert)command).getValueSource()).getValues().get(1));
- value.setMultiValued(true);
- value.setBindValue(true);
- value.setValue(Arrays.asList(1, 2));
- value1.setMultiValued(true);
- value1.setBindValue(true);
- value1.setValue(Arrays.asList(2, 3));
- Connection connection = Mockito.mock(Connection.class);
- PreparedStatement p = Mockito.mock(PreparedStatement.class);
- Mockito.stub(p.executeBatch()).toReturn(new int [] {1, 1});
- Mockito.stub(connection.prepareStatement("INSERT INTO SmallA (IntKey, IntNum)
VALUES (?, ?)")).toReturn(p); //$NON-NLS-1$
-
- JDBCExecutionFactory config = new JDBCExecutionFactory();
-
- JDBCUpdateExecution updateExecution = new JDBCUpdateExecution(command, connection,
Mockito.mock(ExecutionContext.class), config);
- updateExecution.execute();
- Mockito.verify(p, Mockito.times(2)).addBatch();
- }
-
@Test public void testInsertIteratorUpdate() throws Exception {
Insert command = (Insert)TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB,
"insert into BQT1.SmallA (IntKey, IntNum) values (1, 2)"); //$NON-NLS-1$
- List<List<Integer>> values = new ArrayList<List<Integer>>();
- values.add(Arrays.asList(1, 2));
- values.add(Arrays.asList(2, 3));
- command.setValueSource(new IteratorValueSource(values.iterator(), 2));
-
+ Parameter param = new Parameter();
+ param.setType(DataTypeManager.DefaultDataClasses.INTEGER);
+ param.setValueIndex(0);
+ List<Expression> values =
((ExpressionValueSource)command.getValueSource()).getValues();
+ values.set(0, param);
+ param = new Parameter();
+ param.setType(DataTypeManager.DefaultDataClasses.INTEGER);
+ param.setValueIndex(1);
+ values.set(1, param);
+ command.setParameterValues(Arrays.asList(Arrays.asList(1, 2), Arrays.asList(1,
2)).iterator());
Connection connection = Mockito.mock(Connection.class);
PreparedStatement p = Mockito.mock(PreparedStatement.class);
Mockito.stub(p.executeBatch()).toReturn(new int [] {1, 1});
Modified:
trunk/documentation/developer-guide/src/main/docbook/en-US/content/translator-api.xml
===================================================================
---
trunk/documentation/developer-guide/src/main/docbook/en-US/content/translator-api.xml 2012-01-07
16:10:27 UTC (rev 3781)
+++
trunk/documentation/developer-guide/src/main/docbook/en-US/content/translator-api.xml 2012-01-09
19:33:46 UTC (rev 3782)
@@ -465,10 +465,15 @@
<listitem>
<para>
<code>Literal</code>
- – represents a literal scalar value, but may also be multi-valued in
- the case of bulk updates.
+ – represents a literal scalar value.
</para>
</listitem>
+ <listitem>
+ <para>
+ <code>Parameter</code>
+ – represents a parameter with multiple values. The command should be an instance of
BatchedCommand, which provides all values via getParameterValues.
+ </para>
+ </listitem>
<listitem>
<para>
<code>Function</code>
@@ -585,7 +590,7 @@
inserted into. It will also has a list of <code>ColumnReference</code>
specifying the columns
of the <code>NamedTable</code> that are being inserted into. It
also has
<code>InsertValueSource</code>, which will be a list of
- Expressions (<code>ExpressionValueSource</code>), or a
<code>QueryExpression</code>, or an Iterator
(<code>IteratorValueSource</code>)</para>
+ Expressions (<code>ExpressionValueSource</code>) or a
<code>QueryExpression</code></para>
</section>
<section>
@@ -1416,17 +1421,6 @@
</row>
<row>
<entry>
- <para>InsertWithIterator</para>
- </entry>
- <entry>
- <para/>
- </entry>
- <entry>
- <para>Translator supports inserts with an iterator of values.
The values would typically be from an evaluated QueryExpression.</para>
- </entry>
- </row>
- <row>
- <entry>
<para>CommonTableExpressions</para>
</entry>
<entry>
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java 2012-01-07
16:10:27 UTC (rev 3781)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -101,7 +101,7 @@
tgtCaps.setCapabilitySupport(Capability.QUERY_ORDERBY_UNRELATED,
srcCaps.supportsOrderByUnrelated());
tgtCaps.setCapabilitySupport(Capability.QUERY_AGGREGATES_ENHANCED_NUMERIC,
srcCaps.supportsAggregatesEnhancedNumeric());
tgtCaps.setCapabilitySupport(Capability.QUERY_ORDERBY_NULL_ORDERING,
srcCaps.supportsOrderByNullOrdering());
- tgtCaps.setCapabilitySupport(Capability.INSERT_WITH_ITERATOR,
srcCaps.supportsInsertWithIterator());
+ tgtCaps.setCapabilitySupport(Capability.INSERT_WITH_ITERATOR,
srcCaps.supportsBulkUpdate());
tgtCaps.setCapabilitySupport(Capability.COMMON_TABLE_EXPRESSIONS,
srcCaps.supportsCommonTableExpressions());
tgtCaps.setCapabilitySupport(Capability.ELEMENTARY_OLAP,
srcCaps.supportsElementaryOlapOperations());
setSupports(connectorID, tgtCaps, Capability.ADVANCED_OLAP,
srcCaps.supportsAdvancedOlapOperations(), Capability.ELEMENTARY_OLAP);
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java 2012-01-07
16:10:27 UTC (rev 3781)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
@@ -33,7 +34,7 @@
import org.teiid.common.buffer.TupleSource;
import org.teiid.core.CoreConstants;
import org.teiid.core.TeiidComponentException;
-import org.teiid.core.TeiidException;
+import org.teiid.core.TeiidProcessingException;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.language.*;
import org.teiid.language.DerivedColumn;
@@ -67,6 +68,8 @@
public class LanguageBridgeFactory {
private RuntimeMetadataImpl metadataFactory = null;
+ private int valueIndex = 0;
+ private List<List<?>> allValues = new LinkedList<List<?>>();
public LanguageBridgeFactory(QueryMetadataInterface metadata) {
if (metadata != null) {
@@ -454,11 +457,17 @@
result.setWindowSpecification(ws);
return result;
}
-
- Literal translate(Constant constant) {
+
+ org.teiid.language.Expression translate(Constant constant) {
+ if (constant.isMultiValued()) {
+ Parameter result = new Parameter();
+ result.setType(constant.getType());
+ final List<?> values = (List<?>)constant.getValue();
+ allValues.add(values);
+ result.setValueIndex(valueIndex++);
+ return result;
+ }
Literal result = new Literal(constant.getValue(), constant.getType());
- result.setBindValue(constant.isMultiValued());
- result.setMultiValued(constant.isMultiValued());
result.setBindEligible(constant.isBindEligible());
return result;
}
@@ -543,44 +552,54 @@
for (ElementSymbol elementSymbol : elements) {
translatedElements.add(translate(elementSymbol));
}
-
+ Iterator<List<?>> parameterValues = null;
InsertValueSource valueSource = null;
if (insert.getQueryExpression() != null) {
valueSource = translate(insert.getQueryExpression());
} else if (insert.getTupleSource() != null) {
final TupleSource ts = insert.getTupleSource();
- valueSource = new IteratorValueSource<List<?>>(new
Iterator<List<?>>() {
-
- List<?> next;
+ parameterValues = new Iterator<List<?>>() {
+ List<?> nextRow;
@Override
- public void remove() {
- throw new UnsupportedOperationException();
+ public boolean hasNext() {
+ if (nextRow == null) {
+ try {
+ nextRow = ts.nextTuple();
+ } catch (TeiidComponentException e) {
+ throw new TeiidRuntimeException(e);
+ } catch (TeiidProcessingException e) {
+ throw new TeiidRuntimeException(e);
+ }
+ }
+ return nextRow != null;
}
@Override
public List<?> next() {
- if (hasNext()) {
- List<?> result = next;
- next = null;
- return result;
+ if (nextRow == null && !hasNext()) {
+ throw new NoSuchElementException();
}
- throw new NoSuchElementException();
+ List<?> result = nextRow;
+ nextRow = null;
+ return result;
}
@Override
- public boolean hasNext() {
- if (next != null) {
- return true;
- }
- try {
- next = ts.nextTuple();
- } catch (TeiidException e) {
- throw new TeiidRuntimeException(e);
- }
- return next != null;
+ public void remove() {
+ throw new UnsupportedOperationException();
}
- }, elements.size());
+
+ };
+ List<org.teiid.language.Expression> translatedValues = new
ArrayList<org.teiid.language.Expression>();
+ for (int i = 0; i < insert.getVariables().size(); i++) {
+ ElementSymbol es = insert.getVariables().get(i);
+ Parameter param = new Parameter();
+ param.setType(es.getType());
+ param.setValueIndex(i);
+ translatedValues.add(param);
+ }
+ valueSource = new ExpressionValueSource(translatedValues);
} else {
// This is for the simple one row insert.
List values = insert.getValues();
@@ -591,16 +610,40 @@
valueSource = new ExpressionValueSource(translatedValues);
}
- return new org.teiid.language.Insert(translate(insert.getGroup()),
+ org.teiid.language.Insert result = new
org.teiid.language.Insert(translate(insert.getGroup()),
translatedElements,
valueSource);
+ result.setParameterValues(parameterValues);
+ setBatchValues(result);
+ return result;
}
+
+ private void setBatchValues(BatchedCommand bc) {
+ if (valueIndex == 0) {
+ return;
+ }
+ if (bc.getParameterValues() != null) {
+ throw new IllegalStateException("Already set batch values");
//$NON-NLS-1$
+ }
+ int rowCount = allValues.get(0).size();
+ List<List<?>> result = new ArrayList<List<?>>(rowCount);
+ for (int i = 0; i < rowCount; i++) {
+ List<Object> row = new ArrayList<Object>(allValues.size());
+ for (List<?> vals : allValues) {
+ row.add(vals.get(i));
+ }
+ result.add(row);
+ }
+ bc.setParameterValues(result.iterator());
+ }
/* Update */
org.teiid.language.Update translate(Update update) {
- return new org.teiid.language.Update(translate(update.getGroup()),
+ org.teiid.language.Update result = new
org.teiid.language.Update(translate(update.getGroup()),
translate(update.getChangeList()),
translate(update.getCriteria()));
+ setBatchValues(result);
+ return result;
}
List<org.teiid.language.SetClause> translate(SetClauseList setClauseList) {
@@ -619,6 +662,7 @@
org.teiid.language.Delete translate(Delete delete) {
org.teiid.language.Delete deleteImpl = new
org.teiid.language.Delete(translate(delete.getGroup()),
translate(delete.getCriteria()));
+ setBatchValues(deleteImpl);
return deleteImpl;
}
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java 2012-01-07
16:10:27 UTC (rev 3781)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -171,8 +171,6 @@
SourceCapabilities caps =
capFinder.findCapabilities(modelName);
if (caps.supportsCapability(Capability.INSERT_WITH_ITERATOR))
{
pinode.setMode(org.teiid.query.processor.relational.ProjectIntoNode.Mode.ITERATOR);
- } else if (caps.supportsCapability(Capability.BULK_UPDATE))
{
-
pinode.setMode(org.teiid.query.processor.relational.ProjectIntoNode.Mode.BULK);
} else if
(caps.supportsCapability(Capability.BATCHED_UPDATES)) {
pinode.setMode(org.teiid.query.processor.relational.ProjectIntoNode.Mode.BATCH);
} else {
Modified:
trunk/engine/src/main/java/org/teiid/query/processor/relational/ProjectIntoNode.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/relational/ProjectIntoNode.java 2012-01-07
16:10:27 UTC (rev 3781)
+++
trunk/engine/src/main/java/org/teiid/query/processor/relational/ProjectIntoNode.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -27,6 +27,7 @@
import static org.teiid.query.analysis.AnalysisRecord.*;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.teiid.client.plan.PlanNode;
@@ -48,7 +49,7 @@
public class ProjectIntoNode extends RelationalNode {
public enum Mode {
- BATCH, BULK, ITERATOR, SINGLE
+ BATCH, ITERATOR, SINGLE
}
private static int REQUEST_CREATION = 1;
@@ -157,31 +158,13 @@
requests = 0;
}
break;
- case BULK:
- //convert to multivalued parameter
- List<Constant> parameters = new
ArrayList<Constant>(intoElements.size());
- for (int i = 0; i < intoElements.size(); i++) {
- Constant value = new Constant(null,
((ElementSymbol)intoElements.get(i)).getType());
- value.setMultiValued(new ArrayList<Object>(currentBatch.getTuples().size()));
- parameters.add(value);
- }
- for (List row : currentBatch.getTuples()) {
- for (int i = 0; i < row.size(); i++) {
- ((List<Object>)parameters.get(i).getValue()).add(row.get(i));
- }
- }
- // Create a bulk insert command batching all rows in the current batch.
- Insert insert = new Insert(intoGroup, intoElements, parameters);
- // Register insert command against source
- registerRequest(insert);
- break;
case BATCH:
// Register batched update command against source
int endRow = currentBatch.getEndRow();
- List rows = new ArrayList(endRow-batchRow);
+ List<Command> rows = new
ArrayList<Command>(endRow-batchRow);
for(int rowNum = batchRow; rowNum <= endRow; rowNum++) {
- insert = new Insert( intoGroup,
+ Insert insert = new Insert( intoGroup,
intoElements,
convertValuesToConstants(currentBatch.getTuple(rowNum), intoElements));
rows.add( insert );
@@ -205,9 +188,7 @@
checkExitConditions();
// End this node's work
- List outputRow = new ArrayList(1);
- outputRow.add(new Integer(this.insertCount));
- addBatchRow(outputRow);
+ addBatchRow(Arrays.asList(insertCount));
terminateBatches();
return pullBatch();
}
@@ -271,11 +252,11 @@
return props;
}
- private List convertValuesToConstants(List values, List elements) {
- ArrayList constants = new ArrayList(values.size());
+ private List<Constant> convertValuesToConstants(List<?> values,
List<ElementSymbol> elements) {
+ ArrayList<Constant> constants = new
ArrayList<Constant>(values.size());
for(int i=0; i<elements.size(); i++) {
- ElementSymbol es = (ElementSymbol)elements.get(i);
- Class type = es.getType();
+ ElementSymbol es = elements.get(i);
+ Class<?> type = es.getType();
constants.add(new Constant(values.get(i),type));
}
return constants;
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java 2012-01-07
16:10:27 UTC (rev 3781)
+++
trunk/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -95,6 +95,7 @@
caps.setCapabilitySupport(Capability.BATCHED_UPDATES, doBatching);
caps.setCapabilitySupport(Capability.BULK_UPDATE, doBulkInsert);
+ caps.setCapabilitySupport(Capability.INSERT_WITH_ITERATOR, doBulkInsert);
caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
@@ -108,7 +109,7 @@
Arrays.asList(new Object[] { "2", new
Integer(2), Boolean.TRUE, new Double(2) })}); //$NON-NLS-1$
if (doBulkInsert) {
- dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2,
pm1.g2.e3, pm1.g2.e4) VALUES (?, ?, ?, ?)", //$NON-NLS-1$
+ dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2,
pm1.g2.e3, pm1.g2.e4) VALUES (...)", //$NON-NLS-1$
new List[] { Arrays.asList(new Object[] { new
Integer(2)})});
}
else
@@ -153,7 +154,7 @@
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
- caps.setCapabilitySupport(Capability.BULK_UPDATE, true);
+ caps.setCapabilitySupport(Capability.INSERT_WITH_ITERATOR, true);
caps.setFunctionSupport(SourceSystemFunctions.CONVERT, true);
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
@@ -164,7 +165,7 @@
QueryMetadataInterface metadata =
RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
HardcodedDataManager dataManager = new HardcodedDataManager();
- dataManager.addData("INSERT INTO pm1.g1 (pm1.g1.e1, pm1.g1.e2) VALUES (?,
?)", //$NON-NLS-1$
+ dataManager.addData("INSERT INTO pm1.g1 (pm1.g1.e1, pm1.g1.e2) VALUES
(...)", //$NON-NLS-1$
new List[] { Arrays.asList(new Object[] { new Integer(1)
})});
String sql = "SELECT 1, convert(1, float) INTO pm1.g1"; //$NON-NLS-1$
@@ -230,7 +231,7 @@
}
@Test public void testInsertIntoWithSubquery_Bulk() {
- helpInsertIntoWithSubquery( Capability.BULK_UPDATE );
+ helpInsertIntoWithSubquery( Capability.INSERT_WITH_ITERATOR );
}
@Test public void testInsertIntoWithSubquery_Pushdown() {
@@ -257,8 +258,8 @@
if (cap != null) {
switch (cap) {
- case BULK_UPDATE:
- dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2,
pm1.g2.e3, pm1.g2.e4) VALUES (?, ?, ?, ?)", //$NON-NLS-1$
+ case INSERT_WITH_ITERATOR:
+ dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2,
pm1.g2.e3, pm1.g2.e4) VALUES (...)", //$NON-NLS-1$
new List[] { Arrays.asList(new Object[] { new Integer(2)})});
break;
case BATCHED_UPDATES:
@@ -324,6 +325,7 @@
caps.setCapabilitySupport(Capability.BATCHED_UPDATES, doBatching);
caps.setCapabilitySupport(Capability.BULK_UPDATE, doBulkInsert);
+ caps.setCapabilitySupport(Capability.INSERT_WITH_ITERATOR, doBulkInsert);
caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
@@ -337,8 +339,8 @@
Arrays.asList(new Object[] { "2", new
Integer(2), Boolean.TRUE, new Double(2) })}); //$NON-NLS-1$
if (doBulkInsert) {
- dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2,
pm1.g2.e3, pm1.g2.e4) VALUES (?, ?, ?, ?)", //$NON-NLS-1$
- new List[] { Arrays.asList(new Object[] { new
Integer(2)})});
+ dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2,
pm1.g2.e3, pm1.g2.e4) VALUES (...)", //$NON-NLS-1$
+ new List[] { Arrays.asList(new Object[] { new
Integer(4)})});
}
else
if (doBatching) {
Modified:
trunk/engine/src/test/java/org/teiid/query/processor/relational/TestProjectIntoNode.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/processor/relational/TestProjectIntoNode.java 2012-01-07
16:10:27 UTC (rev 3781)
+++
trunk/engine/src/test/java/org/teiid/query/processor/relational/TestProjectIntoNode.java 2012-01-09
19:33:46 UTC (rev 3782)
@@ -111,10 +111,6 @@
helpTestNextBatch(100, Mode.BATCH);
}
- @Test public void testNextBatch_BulkInsert() throws Exception {
- helpTestNextBatch(100, Mode.BULK);
- }
-
@Test public void testNextBatch_NoBatching() throws Exception {
helpTestNextBatch(100, Mode.SINGLE);
}