teiid SVN: r1843 - in trunk/engine/src/main/java/com/metamatrix/query: optimizer/relational/rules and 3 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-02-18 21:29:42 -0500 (Thu, 18 Feb 2010)
New Revision: 1843
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java
trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
trunk/engine/src/main/java/com/metamatrix/query/sql/LanguageObject.java
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/OrderBy.java
Log:
TEIID-989 adding back the type hint to the clone method... It would probably be better to not even bother using generics here.
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java 2010-02-18 20:18:35 UTC (rev 1842)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java 2010-02-19 02:29:42 UTC (rev 1843)
@@ -157,7 +157,7 @@
connectSubqueryContainers(plan); //TODO: merge with node creation
// Set top column information on top node
- List<SingleElementSymbol> topCols = Util.deepClone(command.getProjectedSymbols());
+ List<SingleElementSymbol> topCols = Util.deepClone(command.getProjectedSymbols(), SingleElementSymbol.class);
// Build rule set based on hints
RuleStack rules = RelationalPlanner.buildRules(hints);
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java 2010-02-18 20:18:35 UTC (rev 1842)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java 2010-02-19 02:29:42 UTC (rev 1843)
@@ -341,7 +341,7 @@
}
}
- List<SingleElementSymbol> projectedViewSymbols = Util.deepClone(projectedSymbols);
+ List<SingleElementSymbol> projectedViewSymbols = Util.deepClone(projectedSymbols, SingleElementSymbol.class);
SymbolMap viewMapping = SymbolMap.createSymbolMap(NodeEditor.findParent(unionSource, NodeConstants.Types.SOURCE).getGroups().iterator().next(), projectedSymbols, metadata);
for (AggregateSymbol agg : aggregates) {
Modified: trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2010-02-18 20:18:35 UTC (rev 1842)
+++ trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2010-02-19 02:29:42 UTC (rev 1843)
@@ -902,7 +902,7 @@
private Insert rewriteSelectInto(Query query) throws QueryValidatorException {
Into into = query.getInto();
try {
- List<ElementSymbol> allIntoElements = Util.deepClone(ResolverUtil.resolveElementsInGroup(into.getGroup(), metadata));
+ List<ElementSymbol> allIntoElements = Util.deepClone(ResolverUtil.resolveElementsInGroup(into.getGroup(), metadata), ElementSymbol.class);
Insert insert = new Insert(into.getGroup(), allIntoElements, Collections.emptyList());
query.setInto(null);
insert.setQueryExpression(query);
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/LanguageObject.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/LanguageObject.java 2010-02-18 20:18:35 UTC (rev 1842)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/LanguageObject.java 2010-02-19 02:29:42 UTC (rev 1843)
@@ -48,11 +48,10 @@
public static class Util {
- @SuppressWarnings("unchecked")
- public static <S extends LanguageObject, T extends S> ArrayList<S> deepClone(List<T> collection) {
+ public static <S extends LanguageObject, T extends S> ArrayList<S> deepClone(List<T> collection, Class<S> type) {
ArrayList<S> result = new ArrayList<S>(collection.size());
for (LanguageObject obj : collection) {
- result.add((S)obj.clone());
+ result.add(type.cast(obj.clone()));
}
return result;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/OrderBy.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/OrderBy.java 2010-02-18 20:18:35 UTC (rev 1842)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/OrderBy.java 2010-02-19 02:29:42 UTC (rev 1843)
@@ -144,7 +144,7 @@
*/
public OrderBy clone() {
OrderBy clone = new OrderBy();
- clone.orderByItems = LanguageObject.Util.deepClone(this.orderByItems);
+ clone.orderByItems = LanguageObject.Util.deepClone(this.orderByItems, OrderByItem.class);
return clone;
}
13 years, 9 months
teiid SVN: r1842 - in branches/JCA: build/kit-jboss-container/deploy/teiid/teiid-engine.rar/META-INF and 33 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2010-02-18 15:18:35 -0500 (Thu, 18 Feb 2010)
New Revision: 1842
Added:
branches/JCA/console/src/main/java/org/teiid/rhq/plugin/util/DeploymentUtils.java
Removed:
branches/JCA/console/.settings/
Modified:
branches/JCA/build/kit-jboss-container/deploy/teiid/teiid-engine.rar/META-INF/ra.xml
branches/JCA/build/kit-jboss-container/deploy/teiid/teiid-jboss-beans.xml
branches/JCA/build/kit-runtime/deploy.properties
branches/JCA/client/src/main/java/com/metamatrix/common/batch/BatchSerializer.java
branches/JCA/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/OioOjbectChannelFactory.java
branches/JCA/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerInstanceImpl.java
branches/JCA/client/src/main/java/com/metamatrix/common/lob/ReaderInputStream.java
branches/JCA/common-core/src/main/java/com/metamatrix/common/types/DataTypeManager.java
branches/JCA/common-core/src/main/java/com/metamatrix/core/util/HashCodeUtil.java
branches/JCA/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java
branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/LocateFunctionModifier.java
branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ConvertModifier.java
branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/LocateFunctionModifier.java
branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java
branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/TranslatedCommand.java
branches/JCA/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2SqlTranslator.java
branches/JCA/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java
branches/JCA/console/src/main/java/org/teiid/rhq/plugin/Facet.java
branches/JCA/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java
branches/JCA/console/src/main/java/org/teiid/rhq/plugin/VDBDiscoveryComponent.java
branches/JCA/console/src/main/java/org/teiid/rhq/plugin/util/ProfileServiceUtil.java
branches/JCA/console/src/resources/embedded/META-INF/rhq-plugin.xml
branches/JCA/engine/src/main/java/com/metamatrix/common/buffer/BufferManager.java
branches/JCA/engine/src/main/java/com/metamatrix/common/buffer/TupleBuffer.java
branches/JCA/engine/src/main/java/com/metamatrix/common/buffer/TupleSource.java
branches/JCA/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java
branches/JCA/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java
branches/JCA/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
branches/JCA/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/BatchCollector.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/BatchIterator.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/QueryProcessor.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/AccessNode.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/BatchedUpdateNode.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentAccessNode.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureExecutionNode.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentValueSource.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DuplicateFilter.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/InsertPlanExecutionNode.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/JoinNode.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/JoinStrategy.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/LimitNode.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/MergeJoinStrategy.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/NullNode.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/PartitionedSortJoin.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/PlanExecutionNode.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectIntoNode.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SortNode.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SortUtility.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SourceState.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareEvaluator.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareRelationalNode.java
branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/UnionAllNode.java
branches/JCA/engine/src/main/java/com/metamatrix/query/sql/lang/JoinType.java
branches/JCA/engine/src/main/java/com/metamatrix/query/sql/lang/SetQuery.java
branches/JCA/engine/src/main/java/com/metamatrix/query/tempdata/TempTableStoreImpl.java
branches/JCA/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItem.java
branches/JCA/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/SynchConnectorWorkItem.java
branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/AbstractWorkItem.java
branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/CodeTableCache.java
branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java
branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java
branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
branches/JCA/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
branches/JCA/engine/src/test/java/com/metamatrix/query/optimizer/TestPartitionedJoinPlanning.java
branches/JCA/engine/src/test/java/com/metamatrix/query/processor/FakeTupleSource.java
branches/JCA/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
branches/JCA/engine/src/test/java/com/metamatrix/query/processor/relational/TestBatchedUpdateNode.java
branches/JCA/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectIntoNode.java
branches/JCA/engine/src/test/java/com/metamatrix/query/processor/xml/TestXMLPlanningEnhancements.java
branches/JCA/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java
branches/JCA/engine/src/test/java/org/teiid/dqp/internal/process/TestCodeTableCache.java
branches/JCA/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java
branches/JCA/test-integration/common/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java
Log:
TEIID-833: forward merging trunk into JCA -r 1798:1840
Modified: branches/JCA/build/kit-jboss-container/deploy/teiid/teiid-engine.rar/META-INF/ra.xml
===================================================================
--- branches/JCA/build/kit-jboss-container/deploy/teiid/teiid-engine.rar/META-INF/ra.xml 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/build/kit-jboss-container/deploy/teiid/teiid-engine.rar/META-INF/ra.xml 2010-02-18 20:18:35 UTC (rev 1842)
@@ -47,10 +47,10 @@
<config-property-value>localhost</config-property-value>
</config-property>
<config-property>
- <description>Process pool maximum thread count. (default 64)</description>
+ <description>Process pool maximum thread count. (default 16) Increase this value if your load includes a large number of XQueries or if the system's available processors is larger than 8.</description>
<config-property-name>MaxThreads</config-property-name>
<config-property-type>java.lang.Integer</config-property-type>
- <config-property-value>64</config-property-value>
+ <config-property-value>16</config-property-value>
</config-property>
<config-property>
<description>Query processor time slice, in milliseconds. (default 2000)</description>
@@ -62,16 +62,15 @@
<description>Plan debug messages allowed. see option debug.</description>
<config-property-name>OptionDebugAllowed</config-property-name>
<config-property-type>java.lang.Boolean</config-property-type>
- <config-property-value>true</config-property-value>
</config-property>
<config-property>
- <description>Maximum allowed fetch size, set via JDBC. User requested value ignored above this value. (default 20000)</description>
+ <description>Maximum allowed fetch size, set via JDBC. User requested value ignored above this value. (default 20480)</description>
<config-property-name>MaxRowsFetchSize</config-property-name>
<config-property-type>java.lang.Integer</config-property-type>
- <config-property-value>2000</config-property-value>
+ <config-property-value>20480</config-property-value>
</config-property>
<config-property>
- <description>The max lob chunk size transferred each time when processing blobs, clobs(10KB default)</description>
+ <description>The max lob chunk size in KB transferred each time when processing blobs, clobs(100KB default)</description>
<config-property-name>LobChunkSizeInKB</config-property-name>
<config-property-type>java.lang.Integer</config-property-type>
<config-property-value>10</config-property-value>
Modified: branches/JCA/build/kit-jboss-container/deploy/teiid/teiid-jboss-beans.xml
===================================================================
--- branches/JCA/build/kit-jboss-container/deploy/teiid/teiid-jboss-beans.xml 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/build/kit-jboss-container/deploy/teiid/teiid-jboss-beans.xml 2010-02-18 20:18:35 UTC (rev 1842)
@@ -48,10 +48,23 @@
<property name="useDisk">true</property>
<property name="diskDirectory">${jboss.server.temp.dir}/teiid</property>
<property name="bufferMemorySizeInMB">64</property>
- <property name="processorBatchSize">2000</property>
- <property name="connectorBatchSize">2000</property>
+ <!-- The max row count of a batch sent internally within the query processor. Should be <= the connectorBatchSize. (default 256) -->
+ <property name="processorBatchSize">512</property>
+ <!-- The max row count of a batch from a connector. Should be even multiple of processorBatchSize. (default 512) -->
+ <property name="connectorBatchSize">1024</property>
<property name="maxProcessingBatches">8</property>
- <property name="maxReserveBatches">64</property>
+ <!--
+ The number of batch columns to allow in memory (default 16384).
+ This value should be set lower or higher depending on the available memory to Teiid in the VM.
+ 16384 is considered a good default for a dedicated 32-bit VM running Teiid with a 1 gig heap.
+ -->
+ <property name="maxReserveBatchColumns">16384</property>
+ <!--
+ The number of batch columns guarenteed to a processing operation. Set this value lower if the workload typically
+ processes larger numbers of concurrent queries with large intermediate results from operations such as sorting,
+ grouping, etc. (default 124)
+ -->
+ <property name="maxProcessingBatchesColumns">128</property>
<!-- Max File size in GB -->
<property name="maxFileSize">2</property>
<property name="maxOpenFiles">256</property>
Modified: branches/JCA/build/kit-runtime/deploy.properties
===================================================================
--- branches/JCA/build/kit-runtime/deploy.properties 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/build/kit-runtime/deploy.properties 2010-02-18 20:18:35 UTC (rev 1842)
@@ -28,37 +28,42 @@
# Processor settings
#
-#Process pool maximum thread count. (default 64)
-process.maxThreads=64
+#Process pool maximum thread count. (default 16) Increase this value if your load includes a large number of XQueries
+#or if the system's available processors is larger than 8.
+process.maxThreads=16
#Query processor time slice, in milliseconds. (default 2000)
process.timeSliceInMilli=2000
-#Plan debug messages allowed. see option debug.
-process.optionDebugAllowed=true
-
#Maximum allowed fetch size, set via JDBC. User requested value ignored above this value. (default 20480)
process.maxRowsFetchSize=20480
-# The max lob chunk size transferred each time when processing blobs, clobs(100KB default)
+# The max lob chunk size in KB transferred each time when processing blobs, clobs(100KB default)
process.lobChunkSizeInKB=100
#
# BufferManager Settings
#
-#The max size of a batch sent between connector and query service. Should be even multiple of processorBatchSize. (default 2048)
-dqp.buffer.connectorBatchSize=2048
+#The max row count of a batch from a connector. Should be even multiple of processorBatchSize. (default 512)
+dqp.buffer.connectorBatchSize=1024
-#The max size of a batch sent internally within the query processor. Should be <= the connectorBatchSize. (default 1024)
-dqp.buffer.processorBatchSize=1024
+#The max row count of a batch sent internally within the query processor. Should be <= the connectorBatchSize. (default 256)
+dqp.buffer.processorBatchSize=512
#Defines whether to use disk buffering or not. (default true)
dqp.buffer.useDisk=true
-#The number of batches to actively hold in the BufferManager
-org.teiid.buffer.maxReserveBatches=64
+#The number of batch columns to allow in memory (default 16384).
+#This value should be set lower or higher depending on the available memory to Teiid in the VM.
+#16384 is considered a good default for a dedicated 32-bit VM running Teiid with a 1 gig heap.
+org.teiid.buffer.maxReserveBatchColumns=16384
+#The number of batch columns guarenteed to a processing operation. Set this value lower if the workload typically
+#processes larger numbers of concurrent queries with large intermediate results from operations such as sorting,
+#grouping, etc. (default 124)
+org.teiid.buffer.maxProcessingBatchesColumns=128
+
#
# Cache Settings
#
Modified: branches/JCA/client/src/main/java/com/metamatrix/common/batch/BatchSerializer.java
===================================================================
--- branches/JCA/client/src/main/java/com/metamatrix/common/batch/BatchSerializer.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/client/src/main/java/com/metamatrix/common/batch/BatchSerializer.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -322,10 +322,6 @@
int b;
boolean readingShort;
int length = in.readInt();
- /* Although using a StringBuffer and doing a toString() to get the String value reuses
- * the StringBuffer's internal char[], the StringBuffer.append() calls are all synchronized,
- * and likely too costly compared to simply copying the array during derialization.
- */
char[] chars = new char[length];
readingShort = true;
for (int i = 0; i < length; i++) {
Modified: branches/JCA/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/OioOjbectChannelFactory.java
===================================================================
--- branches/JCA/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/OioOjbectChannelFactory.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/OioOjbectChannelFactory.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -58,6 +58,7 @@
private final Socket socket;
private ObjectOutputStream outputStream;
private ObjectInputStream inputStream;
+ private Object readLock = new Object();
private OioObjectChannel(Socket socket) throws IOException {
log.fine("creating new OioObjectChannel"); //$NON-NLS-1$
@@ -118,13 +119,15 @@
//## JDBC4.0-end ##
public Object read() throws IOException, ClassNotFoundException {
log.finer("reading message from socket"); //$NON-NLS-1$
- try {
- return inputStream.readObject();
- } catch (SocketTimeoutException e) {
- throw e;
- } catch (IOException e) {
- close();
- throw e;
+ synchronized (readLock) {
+ try {
+ return inputStream.readObject();
+ } catch (SocketTimeoutException e) {
+ throw e;
+ } catch (IOException e) {
+ close();
+ throw e;
+ }
}
}
Modified: branches/JCA/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerInstanceImpl.java
===================================================================
--- branches/JCA/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerInstanceImpl.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerInstanceImpl.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -70,19 +70,18 @@
public class SocketServerInstanceImpl implements SocketServerInstance {
static final int HANDSHAKE_RETRIES = 10;
+ private static Logger log = Logger.getLogger("org.teiid.client.sockets"); //$NON-NLS-1$
private AtomicInteger MESSAGE_ID = new AtomicInteger();
+ private Map<Serializable, ResultsReceiver<Object>> asynchronousListeners = new ConcurrentHashMap<Serializable, ResultsReceiver<Object>>();
private HostInfo hostInfo;
private boolean ssl;
- private ObjectChannel socketChannel;
- private static Logger log = Logger.getLogger("org.teiid.client.sockets"); //$NON-NLS-1$
private long synchTimeout;
+ private ObjectChannel socketChannel;
private Cryptor cryptor;
- private Map<Serializable, ResultsReceiver<Object>> asynchronousListeners = new ConcurrentHashMap<Serializable, ResultsReceiver<Object>>();
-
private boolean hasReader;
public SocketServerInstanceImpl() {
@@ -95,7 +94,7 @@
this.synchTimeout = synchTimeout;
}
- public void connect(ObjectChannelFactory channelFactory) throws CommunicationException, IOException {
+ public synchronized void connect(ObjectChannelFactory channelFactory) throws CommunicationException, IOException {
InetSocketAddress address = new InetSocketAddress(hostInfo.getInetAddress(), hostInfo.getPortNumber());
this.socketChannel = channelFactory.createObjectChannel(address, ssl);
try {
@@ -249,6 +248,45 @@
public Cryptor getCryptor() {
return this.cryptor;
}
+
+ void read(long timeout, TimeUnit unit, ResultsFuture<?> future) throws TimeoutException, InterruptedException {
+ long timeoutMillis = (int)Math.min(unit.toMillis(timeout), Integer.MAX_VALUE);
+ long start = System.currentTimeMillis();
+ while (!future.isDone()) {
+ boolean reading = false;
+ synchronized (this) {
+ if (!hasReader) {
+ hasReader = true;
+ reading = true;
+ } else if (!future.isDone()) {
+ this.wait(Math.max(1, timeoutMillis));
+ }
+ }
+ if (reading) {
+ try {
+ if (!future.isDone()) {
+ receivedMessage(socketChannel.read());
+ }
+ } catch (SocketTimeoutException e) {
+ } catch (Exception e) {
+ exceptionOccurred(e);
+ } finally {
+ synchronized (this) {
+ hasReader = false;
+ this.notifyAll();
+ }
+ }
+ }
+ if (!future.isDone()) {
+ long now = System.currentTimeMillis();
+ timeoutMillis -= now - start;
+ start = now;
+ if (timeoutMillis <= 0) {
+ throw new TimeoutException();
+ }
+ }
+ }
+ }
@SuppressWarnings("unchecked")
//## JDBC4.0-begin ##
@@ -315,42 +353,7 @@
public Object get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException,
TimeoutException {
- long timeoutMillis = (int)Math.min(unit.toMillis(timeout), Integer.MAX_VALUE);
- long start = System.currentTimeMillis();
- while (!isDone()) {
- boolean reading = false;
- synchronized (SocketServerInstanceImpl.this) {
- if (!hasReader) {
- hasReader = true;
- reading = true;
- } else if (!isDone()) {
- SocketServerInstanceImpl.this.wait(Math.max(1, timeoutMillis));
- }
- }
- if (reading) {
- try {
- if (!isDone()) {
- receivedMessage(socketChannel.read());
- }
- } catch (SocketTimeoutException e) {
- } catch (Exception e) {
- exceptionOccurred(e);
- } finally {
- synchronized (SocketServerInstanceImpl.this) {
- hasReader = false;
- SocketServerInstanceImpl.this.notifyAll();
- }
- }
- }
- if (!isDone()) {
- long now = System.currentTimeMillis();
- timeoutMillis -= now - start;
- start = now;
- if (timeoutMillis <= 0) {
- throw new TimeoutException();
- }
- }
- }
+ read(timeout, unit, this);
return super.get(timeout, unit);
}
};
Modified: branches/JCA/client/src/main/java/com/metamatrix/common/lob/ReaderInputStream.java
===================================================================
--- branches/JCA/client/src/main/java/com/metamatrix/common/lob/ReaderInputStream.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/client/src/main/java/com/metamatrix/common/lob/ReaderInputStream.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -32,13 +32,15 @@
import java.nio.CharBuffer;
import java.nio.charset.Charset;
+import com.metamatrix.common.types.Streamable;
+
public class ReaderInputStream extends InputStream {
- private static final int DEFAULT_BUFFER_SIZE = 100 * 1024;
+ private static final int DEFAULT_BUFFER_SIZE = Streamable.STREAMING_BATCH_SIZE_IN_BYTES;
private final Reader reader;
private final Charset charSet;
- private final int bufferSize;
+ private char[] charBuffer;
private boolean hasMore = true;
private ByteBuffer currentBuffer;
@@ -52,7 +54,7 @@
public ReaderInputStream(Reader reader, Charset charSet, int bufferSize) {
this.reader = reader;
this.charSet = charSet;
- this.bufferSize = bufferSize;
+ this.charBuffer = new char[bufferSize];
if (charSet.displayName().equalsIgnoreCase("UTF-16")) { //$NON-NLS-1$
prefixBytes = 2;
}
@@ -64,18 +66,12 @@
if (!hasMore) {
return -1;
}
- char[] charBuffer = new char[bufferSize];
int charsRead = reader.read(charBuffer);
if (charsRead == -1) {
hasMore = false;
return -1;
}
- if (charsRead != charBuffer.length) {
- char[] buf = new char[charsRead];
- System.arraycopy(charBuffer, 0, buf, 0, charsRead);
- charBuffer = buf;
- }
- currentBuffer = charSet.encode(CharBuffer.wrap(charBuffer));
+ currentBuffer = charSet.encode(CharBuffer.wrap(charBuffer, 0, charsRead));
if (!needsPrefix) {
currentBuffer.position(prefixBytes);
}
Modified: branches/JCA/common-core/src/main/java/com/metamatrix/common/types/DataTypeManager.java
===================================================================
--- branches/JCA/common-core/src/main/java/com/metamatrix/common/types/DataTypeManager.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/common-core/src/main/java/com/metamatrix/common/types/DataTypeManager.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -34,6 +34,7 @@
/*## JDBC3.0-JDK1.5-begin ##
import com.metamatrix.core.jdbc.SQLXML;
## JDBC3.0-JDK1.5-end ##*/
+import java.sql.Time;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
@@ -43,7 +44,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.WeakHashMap;
import javax.xml.transform.Source;
@@ -68,6 +68,7 @@
import com.metamatrix.core.ErrorMessageKeys;
import com.metamatrix.core.MetaMatrixRuntimeException;
import com.metamatrix.core.util.ArgCheck;
+import com.metamatrix.core.util.HashCodeUtil;
/**
* <p>
@@ -85,11 +86,57 @@
*/
public class DataTypeManager {
- private static final int MAX_VALUE_MAP_SIZE = 10000;
- private static boolean USE_VALUE_CACHE = PropertiesUtils.getBooleanProperty(System.getProperties(), "org.teiid.useValueCache", true); //$NON-NLS-1$
+ private static final boolean USE_VALUE_CACHE = PropertiesUtils.getBooleanProperty(System.getProperties(), "org.teiid.useValueCache", true); //$NON-NLS-1$
- private static Map<Class<?>, Map<Object, WeakReference<Object>>> valueMaps = new HashMap<Class<?>, Map<Object, WeakReference<Object>>>();
+ private static boolean valueCacheEnabled;
+
+ private interface ValueCache<T> {
+ T getValue(T value);
+ }
+
+ private static class HashedValueCache<T> implements ValueCache<T> {
+
+ final Object[] cache;
+ final boolean weak = false;
+
+ HashedValueCache(int size) {
+ cache = new Object[1 << size];
+ }
+
+ @SuppressWarnings("unchecked")
+ public T getValue(T value) {
+ int index = hash(primaryHash(value)) & (cache.length - 1);
+ Object canonicalValue = get(index);
+ if (value.equals(canonicalValue)) {
+ return (T)canonicalValue;
+ }
+ set(index, value);
+ return value;
+ }
+
+ protected Object get(int index) {
+ return cache[index];
+ }
+
+ protected void set(int index, T value) {
+ cache[index] = value;
+ }
+
+ protected int primaryHash(T value) {
+ return value.hashCode();
+ }
+ /*
+ * The same power of 2 hash bucketing from the Java HashMap
+ */
+ final static int hash(int h) {
+ h ^= (h >>> 20) ^ (h >>> 12);
+ return h ^= (h >>> 7) ^ (h >>> 4);
+ }
+ }
+
+ private static Map<Class<?>, ValueCache<?>> valueMaps = new HashMap<Class<?>, ValueCache<?>>(128);
+
public static final int MAX_STRING_LENGTH = 4000;
public static final class DefaultDataTypes {
@@ -152,7 +199,7 @@
* Doubly-nested map of String srcType --> Map of String targetType -->
* Transform
*/
- private static Map<String, Map<String, Transform>> transforms = new HashMap<String, Map<String, Transform>>();
+ private static Map<String, Map<String, Transform>> transforms = new HashMap<String, Map<String, Transform>>(128);
/** Utility to easily get Transform given srcType and targetType */
private static Transform getTransformFromMaps(String srcType,
@@ -165,10 +212,10 @@
}
/** Base data type names and classes, Type name --> Type class */
- private static Map<String, Class> dataTypeNames = new LinkedHashMap<String, Class>();
+ private static Map<String, Class> dataTypeNames = new LinkedHashMap<String, Class>(128);
/** Base data type names and classes, Type class --> Type name */
- private static Map<Class, String> dataTypeClasses = new LinkedHashMap<Class, String>();
+ private static Map<Class, String> dataTypeClasses = new LinkedHashMap<Class, String>(128);
private static Set<String> DATA_TYPE_NAMES = Collections.unmodifiableSet(dataTypeNames.keySet());
@@ -426,38 +473,94 @@
*/
static void loadDataTypes() {
DataTypeManager.addDataType(DefaultDataTypes.BOOLEAN, DefaultDataClasses.BOOLEAN);
- valueMaps.put(DefaultDataClasses.BOOLEAN, Collections.synchronizedMap(new WeakHashMap<Object, WeakReference<Object>>()));
DataTypeManager.addDataType(DefaultDataTypes.BYTE, DefaultDataClasses.BYTE);
- valueMaps.put(DefaultDataClasses.BYTE, Collections.synchronizedMap(new WeakHashMap<Object, WeakReference<Object>>()));
DataTypeManager.addDataType(DefaultDataTypes.SHORT, DefaultDataClasses.SHORT);
- valueMaps.put(DefaultDataClasses.SHORT, Collections.synchronizedMap(new WeakHashMap<Object, WeakReference<Object>>()));
DataTypeManager.addDataType(DefaultDataTypes.CHAR, DefaultDataClasses.CHAR);
- valueMaps.put(DefaultDataClasses.CHAR, Collections.synchronizedMap(new WeakHashMap<Object, WeakReference<Object>>()));
DataTypeManager.addDataType(DefaultDataTypes.INTEGER, DefaultDataClasses.INTEGER);
- valueMaps.put(DefaultDataClasses.INTEGER, Collections.synchronizedMap(new WeakHashMap<Object, WeakReference<Object>>()));
DataTypeManager.addDataType(DefaultDataTypes.LONG, DefaultDataClasses.LONG);
- valueMaps.put(DefaultDataClasses.LONG, Collections.synchronizedMap(new WeakHashMap<Object, WeakReference<Object>>()));
DataTypeManager.addDataType(DefaultDataTypes.BIG_INTEGER, DefaultDataClasses.BIG_INTEGER);
- valueMaps.put(DefaultDataClasses.BIG_INTEGER, Collections.synchronizedMap(new WeakHashMap<Object, WeakReference<Object>>()));
DataTypeManager.addDataType(DefaultDataTypes.FLOAT, DefaultDataClasses.FLOAT);
- valueMaps.put(DefaultDataClasses.FLOAT, Collections.synchronizedMap(new WeakHashMap<Object, WeakReference<Object>>()));
DataTypeManager.addDataType(DefaultDataTypes.DOUBLE, DefaultDataClasses.DOUBLE);
- valueMaps.put(DefaultDataClasses.DOUBLE, Collections.synchronizedMap(new WeakHashMap<Object, WeakReference<Object>>()));
DataTypeManager.addDataType(DefaultDataTypes.BIG_DECIMAL, DefaultDataClasses.BIG_DECIMAL);
- valueMaps.put(DefaultDataClasses.BIG_DECIMAL, Collections.synchronizedMap(new WeakHashMap<Object, WeakReference<Object>>()));
DataTypeManager.addDataType(DefaultDataTypes.DATE, DefaultDataClasses.DATE);
- valueMaps.put(DefaultDataClasses.DATE, Collections.synchronizedMap(new WeakHashMap<Object, WeakReference<Object>>()));
DataTypeManager.addDataType(DefaultDataTypes.TIME, DefaultDataClasses.TIME);
- valueMaps.put(DefaultDataClasses.TIME, Collections.synchronizedMap(new WeakHashMap<Object, WeakReference<Object>>()));
DataTypeManager.addDataType(DefaultDataTypes.TIMESTAMP, DefaultDataClasses.TIMESTAMP);
- valueMaps.put(DefaultDataClasses.TIMESTAMP, Collections.synchronizedMap(new WeakHashMap<Object, WeakReference<Object>>()));
DataTypeManager.addDataType(DefaultDataTypes.STRING, DefaultDataClasses.STRING);
- valueMaps.put(DefaultDataClasses.STRING, Collections.synchronizedMap(new WeakHashMap<Object, WeakReference<Object>>()));
DataTypeManager.addDataType(DefaultDataTypes.CLOB, DefaultDataClasses.CLOB);
DataTypeManager.addDataType(DefaultDataTypes.XML, DefaultDataClasses.XML);
DataTypeManager.addDataType(DefaultDataTypes.OBJECT, DefaultDataClasses.OBJECT);
DataTypeManager.addDataType(DefaultDataTypes.NULL, DefaultDataClasses.NULL);
DataTypeManager.addDataType(DefaultDataTypes.BLOB, DefaultDataClasses.BLOB);
+
+ if (USE_VALUE_CACHE) {
+ valueMaps.put(DefaultDataClasses.BOOLEAN, new ValueCache<Boolean>() {
+ @Override
+ public Boolean getValue(Boolean value) {
+ return Boolean.valueOf(value);
+ }
+ });
+ valueMaps.put(DefaultDataClasses.BYTE, new ValueCache<Byte>() {
+ @Override
+ public Byte getValue(Byte value) {
+ return Byte.valueOf(value);
+ }
+ });
+ valueMaps.put(DefaultDataClasses.SHORT, new HashedValueCache<Short>(13));
+ valueMaps.put(DefaultDataClasses.CHAR, new HashedValueCache<Character>(13));
+ valueMaps.put(DefaultDataClasses.INTEGER, new HashedValueCache<Integer>(14));
+ valueMaps.put(DefaultDataClasses.LONG, new HashedValueCache<Long>(14));
+ valueMaps.put(DefaultDataClasses.BIG_INTEGER, new HashedValueCache<BigInteger>(14));
+ valueMaps.put(DefaultDataClasses.FLOAT, new HashedValueCache<Float>(14));
+ valueMaps.put(DefaultDataClasses.DOUBLE, new HashedValueCache<Double>(14));
+ valueMaps.put(DefaultDataClasses.DATE, new HashedValueCache<Date>(14));
+ valueMaps.put(DefaultDataClasses.TIME, new HashedValueCache<Time>(14));
+ valueMaps.put(DefaultDataClasses.TIMESTAMP, new HashedValueCache<Timestamp>(14));
+ valueMaps.put(DefaultDataClasses.BIG_DECIMAL, new HashedValueCache<BigDecimal>(15) {
+ @Override
+ protected Object get(int index) {
+ WeakReference<?> ref = (WeakReference<?>) cache[index];
+ if (ref != null) {
+ return ref.get();
+ }
+ return null;
+ }
+
+ @Override
+ protected void set(int index, BigDecimal value) {
+ cache[index] = new WeakReference<BigDecimal>(value);
+ }
+ });
+ valueMaps.put(DefaultDataClasses.STRING, new HashedValueCache<String>(15) {
+ HashedValueCache<String> smallCache = new HashedValueCache<String>(13);
+
+ @Override
+ public String getValue(String value) {
+ if (value.length() < 14) {
+ return smallCache.getValue(value);
+ }
+ return super.getValue(value);
+ }
+
+ @Override
+ protected Object get(int index) {
+ WeakReference<?> ref = (WeakReference<?>) cache[index];
+ if (ref != null) {
+ return ref.get();
+ }
+ return null;
+ }
+
+ @Override
+ protected void set(int index, String value) {
+ cache[index] = new WeakReference<Object>(value);
+ }
+
+ @Override
+ protected int primaryHash(String value) {
+ return HashCodeUtil.expHashCode(value);
+ }
+ });
+ }
}
/**
@@ -723,27 +826,26 @@
sourceConverters.put(sourceClass, transform);
}
+ public static void setValueCacheEnabled(boolean enabled) {
+ valueCacheEnabled = enabled;
+ }
+
+ public static boolean isValueCacheEnabled() {
+ return valueCacheEnabled;
+ }
+
@SuppressWarnings("unchecked")
public static <T> T getCanonicalValue(T value) {
- if (USE_VALUE_CACHE) {
+ if (USE_VALUE_CACHE && valueCacheEnabled) {
if (value == null) {
return null;
}
- Map<Object, WeakReference<Object>> valueMap = valueMaps.get(value.getClass());
- if (valueMap == null) {
+ //TODO: this initial lookup is inefficient, since there are likely collisions
+ ValueCache valueCache = valueMaps.get(value.getClass());
+ if (valueCache == null) {
return value;
}
- WeakReference<Object> valueReference = valueMap.get(value);
- Object canonicalValue = null;
- if (valueReference != null) {
- canonicalValue = valueReference.get();
- }
- if (canonicalValue != null) {
- return (T)canonicalValue;
- }
- if (valueMap.size() <= MAX_VALUE_MAP_SIZE) {
- valueMap.put(value, new WeakReference<Object>(value));
- }
+ return (T)valueCache.getValue(value);
}
return value;
}
Modified: branches/JCA/common-core/src/main/java/com/metamatrix/core/util/HashCodeUtil.java
===================================================================
--- branches/JCA/common-core/src/main/java/com/metamatrix/core/util/HashCodeUtil.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/common-core/src/main/java/com/metamatrix/core/util/HashCodeUtil.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -24,6 +24,7 @@
import java.util.Iterator;
import java.util.List;
+import java.util.RandomAccess;
/**
* <P>This class provides utility functions for generating good
@@ -105,9 +106,7 @@
* Compute a hash code on a large collection by walking the list
* and combining the hash code at every exponential index:
* 1, 2, 4, 8, ... This has been shown to give a good hash
- * for good time complexity. This uses an iterator to walk
- * the collection and pull the necessary hash code values.
- * Slower than a List or array but faster than getting EVERY value.
+ * for good time complexity.
*/
public static final int expHashCode(int previous, List x) {
if(x == null || x.size() == 0) {
@@ -115,19 +114,42 @@
}
int size = x.size(); // size of collection
int hc = (PRIME*previous) + size; // hash code so far
- int skip = 0; // skip between samples
- int total = 0; // collection examined already
- Iterator iter = x.iterator(); // collection iterator
- Object obj = iter.next(); // last iterated object, primed at first
- while(total < size) {
- for(int i=0; i<skip; i++) { // skip to next sample
- obj = iter.next();
+ if (x instanceof RandomAccess) {
+ int index = 1;
+ int xlen = x.size()+1; // switch to 1-based
+ while(index < xlen) {
+ hc = hashCode(hc, x.get(index-1));
+ index = index << 1; // left shift by 1 to double
}
- hc = hashCode(hc, obj); // add sample to hashcode
- skip = (skip == 0) ? 1 : skip << 1; // left shift by 1 to double
- total += skip; // update total
+ } else {
+ int skip = 0; // skip between samples
+ int total = 0; // collection examined already
+ Iterator iter = x.iterator(); // collection iterator
+ Object obj = iter.next(); // last iterated object, primed at first
+ while(total < size) {
+ for(int i=0; i<skip; i++) { // skip to next sample
+ obj = iter.next();
+ }
+ hc = hashCode(hc, obj); // add sample to hashcode
+ skip = (skip == 0) ? 1 : skip << 1; // left shift by 1 to double
+ total += skip; // update total
+ }
}
return hc;
}
+
+ public static final int expHashCode(String x) {
+ if(x == null) {
+ return 0;
+ }
+ int hc = x.length();
+ int index = 1;
+ int xlen = x.length()+1; // switch to 1-based
+ while(index < xlen) {
+ hc = PRIME * hc + x.charAt(index-1);
+ index = index << 1; // left shift by 1 to double
+ }
+ return hc;
+ }
}
Modified: branches/JCA/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java
===================================================================
--- branches/JCA/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -1015,6 +1015,9 @@
append(obj);
buffer.append(SQLReservedWords.RPAREN);
} else {
+ if (!parent.isAll() && obj instanceof ISetQuery) {
+ ((ISetQuery)obj).setAll(false);
+ }
append(obj);
}
}
Modified: branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/LocateFunctionModifier.java
===================================================================
--- branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/LocateFunctionModifier.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/LocateFunctionModifier.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -29,6 +29,7 @@
import org.teiid.connector.language.IExpression;
import org.teiid.connector.language.IFunction;
import org.teiid.connector.language.ILanguageFactory;
+import org.teiid.connector.language.ILiteral;
public class LocateFunctionModifier extends org.teiid.connector.jdbc.translator.LocateFunctionModifier {
@@ -44,8 +45,29 @@
parts.add("position("); //$NON-NLS-1$
parts.add(params.get(0));
parts.add(" in "); //$NON-NLS-1$
+ boolean useSubStr = false;
if (params.size() == 3) {
+ useSubStr = true;
+ if (params.get(2) instanceof ILiteral && ((ILiteral)params.get(2)).getValue() instanceof Integer) {
+ Integer value = (Integer)((ILiteral)params.get(2)).getValue();
+ if (value > 1) {
+ ((ILiteral)params.get(2)).setValue(value - 1);
+ } else {
+ useSubStr = false;
+ }
+ }
+ }
+ if (useSubStr) {
+ parts.add(0, "("); //$NON-NLS-1$
parts.add(this.getLanguageFactory().createFunction("substr", params.subList(1, 3), TypeFacility.RUNTIME_TYPES.STRING)); //$NON-NLS-1$
+ parts.add(")"); //$NON-NLS-1$
+ parts.add(" + "); //$NON-NLS-1$
+ if (params.get(2) instanceof ILiteral && ((ILiteral)params.get(2)).getValue() instanceof Integer) {
+ parts.add(params.get(2));
+ } else {
+ parts.add(params.get(2));
+ parts.add(" - 1"); //$NON-NLS-1$
+ }
} else {
parts.add(params.get(1));
}
Modified: branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ConvertModifier.java
===================================================================
--- branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ConvertModifier.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ConvertModifier.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -181,8 +181,14 @@
this.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.STRING, new FunctionModifier() {
@Override
public List<?> translate(IFunction function) {
- IExpression stringValue = function.getParameters().get(0);
- return Arrays.asList("CASE WHEN ", stringValue, " = 0 THEN 'false' WHEN ", stringValue, " IS NOT NULL THEN 'true' END"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ IExpression booleanValue = function.getParameters().get(0);
+ if (booleanValue instanceof IFunction) {
+ IFunction nested = (IFunction)booleanValue;
+ if (nested.getName().equalsIgnoreCase("convert") && Number.class.isAssignableFrom(nested.getParameters().get(0).getType())) { //$NON-NLS-1$
+ booleanValue = nested.getParameters().get(0);
+ }
+ }
+ return Arrays.asList("CASE WHEN ", booleanValue, " = 0 THEN 'false' WHEN ", booleanValue, " IS NOT NULL THEN 'true' END"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
});
this.addConvert(FunctionModifier.STRING, FunctionModifier.BOOLEAN, new FunctionModifier() {
Modified: branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/LocateFunctionModifier.java
===================================================================
--- branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/LocateFunctionModifier.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/LocateFunctionModifier.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -160,7 +160,7 @@
private IExpression ensurePositiveStartIndex(IExpression startIndex) {
if (startIndex instanceof ILiteral) {
ILiteral literal = (ILiteral)startIndex;
- if (literal.getValue() != null && ((Integer)literal.getValue() < 1)) {
+ if (literal.getValue() instanceof Integer && ((Integer)literal.getValue() < 1)) {
literal.setValue(1);
}
} else {
Modified: branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java
===================================================================
--- branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -32,6 +32,7 @@
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.teiid.connector.api.ExecutionContext;
@@ -76,6 +77,7 @@
private List preparedValues = new ArrayList();
private Set<ILanguageObject> recursionObjects = Collections.newSetFromMap(new IdentityHashMap<ILanguageObject, Boolean>());
+ private Map<ILanguageObject, Object> translations = new IdentityHashMap<ILanguageObject, Object>();
private boolean replaceWithBinding = false;
@@ -98,7 +100,19 @@
}
List<?> parts = null;
if (!recursionObjects.contains(obj)) {
- parts = translator.translate(obj, context);
+ Object trans = this.translations.get(obj);
+ if (trans instanceof List<?>) {
+ parts = (List<?>)trans;
+ } else if (trans instanceof ILanguageObject) {
+ obj = (ILanguageObject)trans;
+ } else {
+ parts = translator.translate(obj, context);
+ if (parts != null) {
+ this.translations.put(obj, parts);
+ } else {
+ this.translations.put(obj, obj);
+ }
+ }
}
if (parts != null) {
recursionObjects.add(obj);
Modified: branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/TranslatedCommand.java
===================================================================
--- branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/TranslatedCommand.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/TranslatedCommand.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -45,8 +45,8 @@
private boolean prepared;
private List preparedValues;
- private SQLConversionVisitor sqlConversionVisitor;
private Translator sqlTranslator;
+ private ExecutionContext context;
/**
* Constructor, takes a SQLConversionVisitor subclass
@@ -54,8 +54,7 @@
*/
public TranslatedCommand(ExecutionContext context, Translator sqlTranslator){
this.sqlTranslator = sqlTranslator;
- this.sqlConversionVisitor = sqlTranslator.getSQLConversionVisitor();
- this.sqlConversionVisitor.setExecutionContext(context);
+ this.context = context;
}
/**
@@ -66,20 +65,18 @@
* @throws ConnectorException
*/
public void translateCommand(ICommand command) throws ConnectorException {
- this.sql = getSQL(command);
- this.preparedValues = this.sqlConversionVisitor.getPreparedValues();
- this.prepared = this.sqlConversionVisitor.isPrepared();
- }
-
- private String getSQL(ICommand command) {
+ SQLConversionVisitor sqlConversionVisitor = sqlTranslator.getSQLConversionVisitor();
+ sqlConversionVisitor.setExecutionContext(context);
if (sqlTranslator.usePreparedStatements() || hasBindValue(command)) {
- this.sqlConversionVisitor.setPrepared(true);
+ sqlConversionVisitor.setPrepared(true);
}
- this.sqlConversionVisitor.append(command);
- return this.sqlConversionVisitor.toString();
- }
-
+ sqlConversionVisitor.append(command);
+ this.sql = sqlConversionVisitor.toString();
+ this.preparedValues = sqlConversionVisitor.getPreparedValues();
+ this.prepared = sqlConversionVisitor.isPrepared();
+ }
+
/**
* Simple check to see if any values in the command should be replaced with bind values
*
Modified: branches/JCA/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2SqlTranslator.java
===================================================================
--- branches/JCA/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2SqlTranslator.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2SqlTranslator.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -233,5 +233,14 @@
input, output,
TRANSLATOR);
}
+
+ @Test public void testBooleanToString() throws Exception {
+ String input = "SELECT convert(convert(INTKEY, boolean), string) FROM BQT1.SmallA"; //$NON-NLS-1$
+ String output = "SELECT CASE WHEN SmallA.IntKey = 0 THEN 'false' WHEN SmallA.IntKey IS NOT NULL THEN 'true' END FROM SmallA"; //$NON-NLS-1$
+
+ TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB,
+ input,
+ output, TRANSLATOR);
+ }
}
Modified: branches/JCA/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java
===================================================================
--- branches/JCA/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -409,7 +409,7 @@
*/
@Test public void testLocate() throws Exception {
String input = "SELECT locate(INTNUM, 'chimp', 1) FROM BQT1.SMALLA"; //$NON-NLS-1$
- String output = "SELECT position(cast(SmallA.IntNum AS varchar(4000)) in substr('chimp', 1)) FROM SmallA"; //$NON-NLS-1$
+ String output = "SELECT position(cast(SmallA.IntNum AS varchar(4000)) in 'chimp') FROM SmallA"; //$NON-NLS-1$
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB,
input, output,
@@ -443,7 +443,7 @@
*/
@Test public void testLocate3() throws Exception {
String input = "SELECT locate(INTNUM, '234567890', 1) FROM BQT1.SMALLA WHERE INTKEY = 26"; //$NON-NLS-1$
- String output = "SELECT position(cast(SmallA.IntNum AS varchar(4000)) in substr('234567890', 1)) FROM SmallA WHERE SmallA.IntKey = 26"; //$NON-NLS-1$
+ String output = "SELECT position(cast(SmallA.IntNum AS varchar(4000)) in '234567890') FROM SmallA WHERE SmallA.IntKey = 26"; //$NON-NLS-1$
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB,
input, output,
@@ -477,7 +477,7 @@
*/
@Test public void testLocate5() throws Exception {
String input = "SELECT locate(STRINGNUM, 'chimp', -5) FROM BQT1.SMALLA"; //$NON-NLS-1$
- String output = "SELECT position(SmallA.StringNum in substr('chimp', 1)) FROM SmallA"; //$NON-NLS-1$
+ String output = "SELECT position(SmallA.StringNum in 'chimp') FROM SmallA"; //$NON-NLS-1$
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB,
input, output,
@@ -494,7 +494,7 @@
*/
@Test public void testLocate6() throws Exception {
String input = "SELECT locate(STRINGNUM, 'chimp', INTNUM) FROM BQT1.SMALLA"; //$NON-NLS-1$
- String output = "SELECT position(SmallA.StringNum in substr('chimp', CASE WHEN SmallA.IntNum < 1 THEN 1 ELSE SmallA.IntNum END)) FROM SmallA"; //$NON-NLS-1$
+ String output = "SELECT (position(SmallA.StringNum in substr('chimp', CASE WHEN SmallA.IntNum < 1 THEN 1 ELSE SmallA.IntNum END)) + CASE WHEN SmallA.IntNum < 1 THEN 1 ELSE SmallA.IntNum END - 1) FROM SmallA"; //$NON-NLS-1$
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB,
input, output,
@@ -511,7 +511,7 @@
*/
@Test public void testLocate7() throws Exception {
String input = "SELECT locate(STRINGNUM, 'chimp', LOCATE(STRINGNUM, 'chimp') + 1) FROM BQT1.SMALLA"; //$NON-NLS-1$
- String output = "SELECT position(SmallA.StringNum in substr('chimp', CASE WHEN (position(SmallA.StringNum in 'chimp') + 1) < 1 THEN 1 ELSE (position(SmallA.StringNum in 'chimp') + 1) END)) FROM SmallA"; //$NON-NLS-1$
+ String output = "SELECT (position(SmallA.StringNum in substr('chimp', CASE WHEN (position(SmallA.StringNum in 'chimp') + 1) < 1 THEN 1 ELSE (position(SmallA.StringNum in 'chimp') + 1) END)) + CASE WHEN (position(SmallA.StringNum in 'chimp') + 1) < 1 THEN 1 ELSE (position(SmallA.StringNum in 'chimp') + 1) END - 1) FROM SmallA"; //$NON-NLS-1$
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB,
input, output,
Modified: branches/JCA/console/src/main/java/org/teiid/rhq/plugin/Facet.java
===================================================================
--- branches/JCA/console/src/main/java/org/teiid/rhq/plugin/Facet.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/console/src/main/java/org/teiid/rhq/plugin/Facet.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -21,17 +21,32 @@
*/
package org.teiid.rhq.plugin;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.deployers.spi.management.deploy.DeploymentManager;
+import org.jboss.deployers.spi.management.deploy.DeploymentProgress;
+import org.jboss.deployers.spi.management.deploy.DeploymentStatus;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.ConfigurationUpdateStatus;
+import org.rhq.core.domain.content.PackageDetailsKey;
import org.rhq.core.domain.content.PackageType;
+import org.rhq.core.domain.content.transfer.ContentResponseResult;
+import org.rhq.core.domain.content.transfer.DeployIndividualPackageResponse;
import org.rhq.core.domain.content.transfer.DeployPackageStep;
import org.rhq.core.domain.content.transfer.DeployPackagesResponse;
import org.rhq.core.domain.content.transfer.RemovePackagesResponse;
@@ -39,10 +54,13 @@
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.measurement.MeasurementReport;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.domain.resource.CreateResourceStatus;
+import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
import org.rhq.core.pluginapi.content.ContentFacet;
import org.rhq.core.pluginapi.content.ContentServices;
+import org.rhq.core.pluginapi.content.version.PackageVersions;
import org.rhq.core.pluginapi.inventory.CreateChildResourceFacet;
import org.rhq.core.pluginapi.inventory.CreateResourceReport;
import org.rhq.core.pluginapi.inventory.DeleteResourceFacet;
@@ -52,36 +70,35 @@
import org.rhq.core.pluginapi.measurement.MeasurementFacet;
import org.rhq.core.pluginapi.operation.OperationFacet;
import org.rhq.core.pluginapi.operation.OperationResult;
+import org.rhq.core.util.ZipUtil;
+import org.rhq.core.util.exception.ThrowableUtil;
import org.teiid.rhq.admin.utils.SingletonConnectionManager;
-import org.teiid.rhq.comm.Component;
import org.teiid.rhq.comm.Connection;
import org.teiid.rhq.comm.ConnectionException;
import org.teiid.rhq.comm.ExecutedResult;
-import org.teiid.rhq.comm.VMComponent;
import org.teiid.rhq.plugin.objects.ExecutedOperationResultImpl;
+import org.teiid.rhq.plugin.util.DeploymentUtils;
+import org.teiid.rhq.plugin.util.ProfileServiceUtil;
-
/**
* This class implements required RHQ interfaces and provides common logic used
* by all MetaMatrix components.
*/
-public abstract class Facet implements ResourceComponent,
- MeasurementFacet, OperationFacet, ConfigurationFacet, ContentFacet,
- DeleteResourceFacet, CreateChildResourceFacet {
+public abstract class Facet implements ResourceComponent, MeasurementFacet,
+ OperationFacet, ConfigurationFacet, ContentFacet, DeleteResourceFacet,
+ CreateChildResourceFacet {
protected static SingletonConnectionManager connMgr = SingletonConnectionManager
.getInstance();
- protected final Log LOG = LogFactory
- .getLog(Facet.class);
-
+ protected final Log LOG = LogFactory.getLog(Facet.class);
+
/**
* Represents the resource configuration of the custom product being
* managed.
*/
protected Configuration resourceConfiguration;
-
/**
* All AMPS plugins are stateful - this context contains information that
* your resource component can use when performing its processing.
@@ -99,6 +116,40 @@
protected boolean isAvailable = false;
+ /**
+ * Name of the backing package type that will be used when discovering
+ * packages. This corresponds to the name of the package type defined in the
+ * plugin descriptor.
+ */
+ private static final String PKG_TYPE_FILE = "vdb";
+
+ /**
+ * Architecture string used in describing discovered packages.
+ */
+ private static final String ARCHITECTURE = "noarch";
+
+ private static final String BACKUP_FILE_EXTENSION = ".rej";
+
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ private PackageVersions versions;
+
+ /**
+ * The name of the ManagedDeployment (e.g.:
+ * vfszip:/C:/opt/jboss-5.0.0.GA/server/default/deploy/foo.vdb).
+ */
+ protected String deploymentName;
+
+ /**
+ * The type of the ManagedDeployment.
+ */
+ // protected KnownDeploymentTypes deploymentType;
+ /**
+ * The absolute path of the deployment file (e.g.:
+ * C:/opt/jboss-5.0.0.GA/server/default/deploy/foo.vdb).
+ */
+ protected File deploymentFile;
+
abstract String getComponentType();
/**
@@ -122,7 +173,7 @@
public void stop() {
this.isAvailable = false;
}
-
+
/**
* @return the resourceConfiguration
*/
@@ -131,7 +182,8 @@
}
/**
- * @param resourceConfiguration the resourceConfiguration to set
+ * @param resourceConfiguration
+ * the resourceConfiguration to set
*/
public void setResourceConfiguration(Configuration resourceConfiguration) {
this.resourceConfiguration = resourceConfiguration;
@@ -161,16 +213,16 @@
this.identifier = identifier;
}
- protected void setOperationArguments(String name, Configuration configuration,
- Map argumentMap) {
-// moved this logic up to the associated implemented class
- throw new InvalidPluginConfigurationException("Not implemented on component type " + this.getComponentType() + " named " + this.getComponentName());
-
-
+ protected void setOperationArguments(String name,
+ Configuration configuration, Map argumentMap) {
+ // moved this logic up to the associated implemented class
+ throw new InvalidPluginConfigurationException(
+ "Not implemented on component type " + this.getComponentType()
+ + " named " + this.getComponentName());
+
}
- protected void execute(final ExecutedResult result,
- final Map valueMap) {
+ protected void execute(final ExecutedResult result, final Map valueMap) {
Connection conn = null;
try {
conn = getConnection();
@@ -210,15 +262,15 @@
}
/*
- * (non-Javadoc)
- * This method is called by JON to check the availability of the inventoried component on a time scheduled basis
+ * (non-Javadoc) This method is called by JON to check the availability of
+ * the inventoried component on a time scheduled basis
*
* @see org.rhq.core.pluginapi.inventory.ResourceComponent#getAvailability()
*/
public AvailabilityType getAvailability() {
LOG.debug("Checking availability of " + identifier); //$NON-NLS-1$
-
+
return AvailabilityType.UP;
}
@@ -259,16 +311,13 @@
Set operationDefinitionSet = this.resourceContext.getResourceType()
.getOperationDefinitions();
+ ExecutedResult result = new ExecutedOperationResultImpl(this
+ .getComponentType(), name, operationDefinitionSet);
- ExecutedResult result = new ExecutedOperationResultImpl(
- this.getComponentType(),
- name,
- operationDefinitionSet);
-
setOperationArguments(name, configuration, valueMap);
-
+
execute(result, valueMap);
-
+
return ((ExecutedOperationResultImpl) result).getOperationResult();
}
@@ -290,9 +339,10 @@
// start with.
// note that it is empty, so we're assuming there are no required
// configs in the plugin descriptor.
- resourceConfiguration = this.resourceContext.getPluginConfiguration();
+ resourceConfiguration = this.resourceContext
+ .getPluginConfiguration();
}
-
+
Configuration config = resourceConfiguration;
return config;
@@ -314,81 +364,400 @@
report.setStatus(ConfigurationUpdateStatus.SUCCESS);
}
- /**
- * When this is called, the plugin is responsible for scanning its managed
- * resource and look for content that need to be managed for that resource.
- * This method should only discover packages of the given package type.
- *
- * @see ContentFacet#discoverDeployedPackages(PackageType)
- */
- public Set<ResourcePackageDetails> discoverDeployedPackages(PackageType type) {
- return null;
+ @Override
+ public void deleteResource() throws Exception {
+ // TODO Auto-generated method stub
+
}
- /**
- * The plugin container calls this method when new packages need to be
- * deployed/installed on resources.
- *
- * @see ContentFacet#deployPackages(Set, ContentServices)
- */
+ @Override
public DeployPackagesResponse deployPackages(
Set<ResourcePackageDetails> packages,
ContentServices contentServices) {
- return null;
+ String resourceTypeName = this.resourceContext.getResourceType()
+ .getName();
+
+ // You can only update the one application file referenced by this
+ // resource, so punch out if multiple are
+ // specified.
+ if (packages.size() != 1) {
+ log.warn("Request to update " + resourceTypeName
+ + " file contained multiple packages: " + packages);
+ DeployPackagesResponse response = new DeployPackagesResponse(
+ ContentResponseResult.FAILURE);
+ response.setOverallRequestErrorMessage("Only one "
+ + resourceTypeName + " can be updated at a time.");
+ return response;
+ }
+
+ ResourcePackageDetails packageDetails = packages.iterator().next();
+
+ log.debug("Updating VDB file '" + this.deploymentFile + "' using ["
+ + packageDetails + "]...");
+ // Find location of existing application.
+ if (!this.deploymentFile.exists()) {
+ return failApplicationDeployment(
+ "Could not find application to update at location: "
+ + this.deploymentFile, packageDetails);
+ }
+
+ log.debug("Writing new EAR/WAR bits to temporary file...");
+ File tempFile;
+ try {
+ tempFile = writeNewAppBitsToTempFile(contentServices,
+ packageDetails);
+ } catch (Exception e) {
+ return failApplicationDeployment(
+ "Error writing new application bits to temporary file - cause: "
+ + e, packageDetails);
+ }
+ log.debug("Wrote new EAR/WAR bits to temporary file '" + tempFile
+ + "'.");
+
+ boolean deployExploded = this.deploymentFile.isDirectory();
+
+ // Backup the original app file/dir.
+ File tempDir = resourceContext.getTemporaryDirectory();
+ File backupDir = new File(tempDir, "deployBackup");
+ File backupOfOriginalFile = new File(backupDir, this.deploymentFile
+ .getName());
+ log.debug("Backing up existing EAR/WAR '" + this.deploymentFile
+ + "' to '" + backupOfOriginalFile + "'...");
+ try {
+ if (backupOfOriginalFile.exists()) {
+ FileUtils.forceDelete(backupOfOriginalFile);
+ }
+ if (this.deploymentFile.isDirectory()) {
+ FileUtils.copyDirectory(this.deploymentFile,
+ backupOfOriginalFile, true);
+ } else {
+ FileUtils.copyFile(this.deploymentFile, backupOfOriginalFile,
+ true);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to backup existing "
+ + resourceTypeName + "'" + this.deploymentFile + "' to '"
+ + backupOfOriginalFile + "'.");
+ }
+
+ // Now stop the original app.
+ try {
+ DeploymentManager deploymentManager = ProfileServiceUtil
+ .getDeploymentManager();
+ DeploymentProgress progress = deploymentManager
+ .stop(this.deploymentName);
+ DeploymentUtils.run(progress);
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to stop deployment ["
+ + this.deploymentName + "].", e);
+ }
+
+ // And then remove it (this will delete the physical file/dir from the
+ // deploy dir).
+ try {
+ DeploymentManager deploymentManager = ProfileServiceUtil
+ .getDeploymentManager();
+ DeploymentProgress progress = deploymentManager
+ .remove(this.deploymentName);
+ DeploymentUtils.run(progress);
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to remove deployment ["
+ + this.deploymentName + "].", e);
+ }
+
+ // Deploy away!
+ log.debug("Deploying '" + tempFile + "'...");
+ DeploymentManager deploymentManager = null;
+ try {
+ deploymentManager = ProfileServiceUtil.getDeploymentManager();
+ DeploymentUtils.deployArchive(deploymentManager, tempFile,
+ deployExploded);
+ } catch (Exception e) {
+ // Deploy failed - rollback to the original app file...
+ log.debug("Redeploy failed - rolling back to original archive...",
+ e);
+ String errorMessage = ThrowableUtil.getAllMessages(e);
+ try {
+ // Try to delete the new app file, which failed to deploy, if it
+ // still exists.
+ if (this.deploymentFile.exists()) {
+ try {
+ FileUtils.forceDelete(this.deploymentFile);
+ } catch (IOException e1) {
+ log.debug("Failed to delete application file '"
+ + this.deploymentFile
+ + "' that failed to deploy.", e1);
+ }
+ }
+ // Now redeploy the original file - this generally should
+ // succeed.
+ DeploymentUtils.deployArchive(deploymentManager,
+ backupOfOriginalFile, deployExploded);
+ errorMessage += " ***** ROLLED BACK TO ORIGINAL APPLICATION FILE. *****";
+ } catch (Exception e1) {
+ log.debug("Rollback failed!", e1);
+ errorMessage += " ***** FAILED TO ROLLBACK TO ORIGINAL APPLICATION FILE. *****: "
+ + ThrowableUtil.getAllMessages(e1);
+ }
+ log
+ .info("Failed to update " + resourceTypeName + " file '"
+ + this.deploymentFile + "' using ["
+ + packageDetails + "].");
+ return failApplicationDeployment(errorMessage, packageDetails);
+ }
+
+ // Deploy was successful!
+ deleteBackupOfOriginalFile(backupOfOriginalFile);
+ persistApplicationVersion(packageDetails, this.deploymentFile);
+
+ DeployPackagesResponse response = new DeployPackagesResponse(
+ ContentResponseResult.SUCCESS);
+ DeployIndividualPackageResponse packageResponse = new DeployIndividualPackageResponse(
+ packageDetails.getKey(), ContentResponseResult.SUCCESS);
+ response.addPackageResponse(packageResponse);
+
+ log.debug("Updated " + resourceTypeName + " file '"
+ + this.deploymentFile + "' successfully - returning response ["
+ + response + "]...");
+
+ return response;
}
- /**
- * When a remote client wants to see the actual data content for an
- * installed package, this method will be called. This method must return a
- * stream of data containing the full content of the package.
- *
- * @see ContentFacet#retrievePackageBits(ResourcePackageDetails)
- */
- public InputStream retrievePackageBits(ResourcePackageDetails packageDetails) {
- return null;
+ @Override
+ public Set<ResourcePackageDetails> discoverDeployedPackages(PackageType arg0) {
+ if (!this.deploymentFile.exists())
+ throw new IllegalStateException("Deployment file '"
+ + this.deploymentFile + "' for " + "VDB Archive"
+ + " does not exist.");
+
+ String fileName = this.deploymentFile.getName();
+ PackageVersions packageVersions = loadPackageVersions();
+ String version = packageVersions.getVersion(fileName);
+ if (version == null) {
+ // This is either the first time we've discovered this VDB, or
+ // someone purged the PC's data dir.
+ version = "1.0";
+ packageVersions.putVersion(fileName, version);
+ packageVersions.saveToDisk();
+ }
+
+ // Package name is the deployment's file name (e.g. foo.ear).
+ PackageDetailsKey key = new PackageDetailsKey(fileName, version,
+ PKG_TYPE_FILE, ARCHITECTURE);
+ ResourcePackageDetails packageDetails = new ResourcePackageDetails(key);
+ packageDetails.setFileName(fileName);
+ packageDetails.setLocation(this.deploymentFile.getPath());
+ if (!this.deploymentFile.isDirectory())
+ packageDetails.setFileSize(this.deploymentFile.length());
+ packageDetails.setFileCreatedDate(null); // TODO: get created date via
+ // SIGAR
+ Set<ResourcePackageDetails> packages = new HashSet<ResourcePackageDetails>();
+ packages.add(packageDetails);
+
+ return packages;
}
- /**
- * This is the method that is used when the component has to create the
- * installation steps and their results.
- *
- * @see ContentFacet#generateInstallationSteps(ResourcePackageDetails)
- */
+ @Override
public List<DeployPackageStep> generateInstallationSteps(
- ResourcePackageDetails packageDetails) {
+ ResourcePackageDetails arg0) {
return null;
}
+ public RemovePackagesResponse removePackages(
+ Set<ResourcePackageDetails> packages) {
+ throw new UnsupportedOperationException(
+ "Cannot remove the package backing an VDB resource.");
+ }
+
+ @Override
+ public InputStream retrievePackageBits(ResourcePackageDetails packageDetails) {
+ File packageFile = new File(packageDetails.getName());
+ File fileToSend;
+ try {
+ if (packageFile.isDirectory()) {
+ fileToSend = File.createTempFile("rhq", ".zip");
+ ZipUtil.zipFileOrDirectory(packageFile, fileToSend);
+ } else
+ fileToSend = packageFile;
+ return new BufferedInputStream(new FileInputStream(fileToSend));
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to retrieve package bits for "
+ + packageDetails, e);
+ }
+ }
+
/**
- * This is called when the actual content of packages should be deleted from
- * the managed resource.
+ * Returns an instantiated and loaded versions store access point.
*
- * @see ContentFacet#removePackages(Set)
+ * @return will not be <code>null</code>
*/
- public RemovePackagesResponse removePackages(
- Set<ResourcePackageDetails> packages) {
- return null;
+ private PackageVersions loadPackageVersions() {
+ if (this.versions == null) {
+ ResourceType resourceType = this.resourceContext.getResourceType();
+ String pluginName = resourceType.getPlugin();
+ File dataDirectoryFile = this.resourceContext.getDataDirectory();
+ dataDirectoryFile.mkdirs();
+ String dataDirectory = dataDirectoryFile.getAbsolutePath();
+ log.trace("Creating application versions store with plugin name ["
+ + pluginName + "] and data directory [" + dataDirectory
+ + "]");
+ this.versions = new PackageVersions(pluginName, dataDirectory);
+ this.versions.loadFromDisk();
+ }
+
+ return this.versions;
}
/**
- * When called, the plugin container is asking the plugin to create a new
- * managed resource. The new resource's details need to be added to the
- * given report.
+ * Creates the necessary transfer objects to report a failed application
+ * deployment (update).
*
- * @see CreateChildResourceFacet#createResource(CreateResourceReport)
+ * @param errorMessage
+ * reason the deploy failed
+ * @param packageDetails
+ * describes the update being made
+ *
+ * @return response populated to reflect a failure
*/
- public CreateResourceReport createResource(CreateResourceReport report) {
- return null;
+ private DeployPackagesResponse failApplicationDeployment(
+ String errorMessage, ResourcePackageDetails packageDetails) {
+ DeployPackagesResponse response = new DeployPackagesResponse(
+ ContentResponseResult.FAILURE);
+
+ DeployIndividualPackageResponse packageResponse = new DeployIndividualPackageResponse(
+ packageDetails.getKey(), ContentResponseResult.FAILURE);
+ packageResponse.setErrorMessage(errorMessage);
+
+ response.addPackageResponse(packageResponse);
+
+ return response;
}
+ private File writeNewAppBitsToTempFile(ContentServices contentServices,
+ ResourcePackageDetails packageDetails) throws Exception {
+ File tempDir = resourceContext.getTemporaryDirectory();
+ File tempFile = new File(tempDir, this.deploymentFile.getName());
+
+ OutputStream tempOutputStream = null;
+ try {
+ tempOutputStream = new BufferedOutputStream(new FileOutputStream(
+ tempFile));
+ long bytesWritten = contentServices.downloadPackageBits(
+ resourceContext.getContentContext(), packageDetails
+ .getKey(), tempOutputStream, true);
+ log
+ .debug("Wrote " + bytesWritten + " bytes to '" + tempFile
+ + "'.");
+ } catch (IOException e) {
+ log.error(
+ "Error writing updated application bits to temporary location: "
+ + tempFile, e);
+ throw e;
+ } finally {
+ if (tempOutputStream != null) {
+ try {
+ tempOutputStream.close();
+ } catch (IOException e) {
+ log.error("Error closing temporary output stream", e);
+ }
+ }
+ }
+ if (!tempFile.exists()) {
+ log.error("Temporary file for application update not written to: "
+ + tempFile);
+ throw new Exception();
+ }
+ return tempFile;
+ }
+
+ private void persistApplicationVersion(
+ ResourcePackageDetails packageDetails, File appFile) {
+ String packageName = appFile.getName();
+ PackageVersions versions = loadApplicationVersions();
+ versions.putVersion(packageName, packageDetails.getVersion());
+ }
+
+ private void deleteBackupOfOriginalFile(File backupOfOriginalFile) {
+ try {
+ FileUtils.forceDelete(backupOfOriginalFile);
+ } catch (Exception e) {
+ // not critical.
+ log.warn("Failed to delete backup of original file: "
+ + backupOfOriginalFile);
+ }
+ }
+
/**
- * When called, the plugin container is asking the plugin to delete a
- * managed resource.
+ * Returns an instantiated and loaded versions store access point.
*
- * @see DeleteResourceFacet#deleteResource()
+ * @return will not be <code>null</code>
*/
- public void deleteResource() {
+ private PackageVersions loadApplicationVersions() {
+ if (versions == null) {
+ ResourceType resourceType = resourceContext.getResourceType();
+ String pluginName = resourceType.getPlugin();
+
+ File dataDirectoryFile = resourceContext.getDataDirectory();
+
+ if (!dataDirectoryFile.exists()) {
+ dataDirectoryFile.mkdir();
+ }
+
+ String dataDirectory = dataDirectoryFile.getAbsolutePath();
+
+ log.debug("Creating application versions store with plugin name ["
+ + pluginName + "] and data directory [" + dataDirectory
+ + "]");
+
+ versions = new PackageVersions(pluginName, dataDirectory);
+ versions.loadFromDisk();
+ }
+
+ return versions;
}
-
-
+
+ @Override
+ public CreateResourceReport createResource(CreateResourceReport createResourceReport) {
+ ResourcePackageDetails details = createResourceReport
+ .getPackageDetails();
+ PackageDetailsKey key = details.getKey();
+ // This is the full path to a temporary file which was written by the UI
+ // layer.
+ String archivePath = key.getName();
+
+ try {
+ File archiveFile = new File(archivePath);
+
+ if (!DeploymentUtils.hasCorrectExtension(archiveFile.getName(), resourceContext.getResourceType())) {
+ createResourceReport.setStatus(CreateResourceStatus.FAILURE);
+ createResourceReport
+ .setErrorMessage("Incorrect extension specified on filename ["
+ + archivePath + "]");
+ return createResourceReport;
+ }
+
+ Configuration deployTimeConfig = details
+ .getDeploymentTimeConfiguration();
+ @SuppressWarnings( { "ConstantConditions" })
+ // boolean deployExploded = deployTimeConfig.getSimple(
+ // "deployExploded").getBooleanValue();
+
+ DeploymentManager deploymentManager = ProfileServiceUtil.getDeploymentManager();
+ DeploymentUtils.deployArchive(deploymentManager, archiveFile, false);
+
+ createResourceReport.setResourceName(archivePath);
+ createResourceReport.setResourceKey(archivePath);
+ createResourceReport.setStatus(CreateResourceStatus.SUCCESS);
+
+ } catch (Throwable t) {
+ log.error("Error deploying application for report: "
+ + createResourceReport, t);
+ createResourceReport.setStatus(CreateResourceStatus.FAILURE);
+ createResourceReport.setException(t);
+ }
+
+ return createResourceReport;
+
+ }
+
}
Modified: branches/JCA/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java
===================================================================
--- branches/JCA/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -27,8 +27,13 @@
import java.util.Properties;
import java.util.Set;
+import javax.naming.NamingException;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.RunState;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.measurement.AvailabilityType;
@@ -36,11 +41,17 @@
import org.rhq.core.domain.measurement.MeasurementReport;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
-import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.teiid.rhq.admin.utils.SingletonConnectionManager;
import org.teiid.rhq.comm.Connection;
import org.teiid.rhq.comm.ConnectionConstants;
-import org.teiid.rhq.comm.ConnectionConstants.ComponentType;
+//import org.teiid.rhq.comm.ConnectionConstants;
+//import org.teiid.rhq.comm.Connection;
+//import org.teiid.rhq.comm.ConnectionConstants;
+//import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.System.Metrics;
+import org.teiid.rhq.plugin.util.PluginConstants;
+import org.teiid.rhq.plugin.util.ProfileServiceUtil;
+import org.teiid.rhq.plugin.util.PluginConstants.Operation;
+import org.teiid.rhq.plugin.util.PluginConstants.ComponentType.Runtime.Metrics;
/**
@@ -60,12 +71,27 @@
@Override
public AvailabilityType getAvailability() {
+ RunState runState = null;
+ ManagedComponent mc;
+ try {
+ mc = ProfileServiceUtil.getManagedComponent(
+ new ComponentType(PluginConstants.ComponentType.Runtime.TYPE,
+ PluginConstants.ComponentType.Runtime.SUBTYPE),
+ PluginConstants.ComponentType.Runtime.TEIID_RUNTIME_ENGINE);
+ runState = mc.getRunState();
+ } catch (NamingException e) {
+ LOG.error("Naming exception getting: " + PluginConstants.ComponentType.Runtime.TEIID_RUNTIME_ENGINE);
+ return AvailabilityType.DOWN;
+ } catch (Exception e) {
+ LOG.error("Exception getting: " + PluginConstants.ComponentType.Runtime.TEIID_RUNTIME_ENGINE);
+ return AvailabilityType.DOWN;
+ }
+
+ return (runState == RunState.RUNNING) ? AvailabilityType.UP : AvailabilityType.DOWN;
+
+ }
- return AvailabilityType.UP;
- }
-
-
protected void setOperationArguments(String name, Configuration configuration,
Map valueMap) {
Modified: branches/JCA/console/src/main/java/org/teiid/rhq/plugin/VDBDiscoveryComponent.java
===================================================================
--- branches/JCA/console/src/main/java/org/teiid/rhq/plugin/VDBDiscoveryComponent.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/console/src/main/java/org/teiid/rhq/plugin/VDBDiscoveryComponent.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -26,8 +26,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.deployers.spi.management.ManagementView;
import org.jboss.managed.api.ComponentType;
import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedDeployment;
import org.jboss.managed.api.ManagedProperty;
import org.jboss.managed.plugins.ManagedObjectImpl;
import org.jboss.metatype.api.values.CollectionValueSupport;
@@ -67,13 +69,27 @@
String vdbName = ((SimpleValueSupport) mcVdb.getProperty("name")
.getValue()).getValue().toString();
- String vdbVersion = ((SimpleValueSupport) mcVdb.getProperty("version")
- .getValue()).getValue().toString();
- //TODO: Correct this after deploying proper VDB/Metadata
+// ManagementView managementView = ProfileServiceUtil
+// .getManagementView(ProfileServiceUtil.getProfileService(),
+// false);
+ //ManagedDeployment managedDeployment = managementView.getDeploymentNamesForType(arg0)(vdbName);
+ //Set deploymentNames = null;
+
+// try
+// {
+// deploymentNames = managementView.getDeploymentNames();
+// }
+// catch (Exception e)
+// {
+// log.error("Unable to get deployment for type " , e);
+// }
+ String vdbVersion = ((SimpleValueSupport) mcVdb.getProperty(
+ "version").getValue()).getValue().toString();
+ // TODO: Correct this after deploying proper VDB/Metadata
String vdbDescription = "description"; // mcVdb.getProperty("description");
String vdbStatus = "active"; // mcVdb.getProperty("status");
String vdbURL = "url"; // mcVdb.getProperty("url");
-
+
/**
*
* A discovered resource must have a unique key, that must stay the
@@ -85,23 +101,25 @@
vdbName, // Resource Name
vdbVersion, // Version
PluginConstants.ComponentType.VDB.DESCRIPTION, // Description
- discoveryContext.getDefaultPluginConfiguration(), // Plugin Config
+ discoveryContext.getDefaultPluginConfiguration(), // Plugin
+ // Config
null // Process info from a process scan
);
-
- //Get plugin config map for models
+
+ // Get plugin config map for models
Configuration configuration = detail.getPluginConfiguration();
configuration.put(new PropertySimple("name", vdbName));
configuration.put(new PropertySimple("version", vdbVersion));
- configuration.put(new PropertySimple("description", vdbDescription));
+ configuration
+ .put(new PropertySimple("description", vdbDescription));
configuration.put(new PropertySimple("status", vdbStatus));
- configuration.put(new PropertySimple("url", vdbURL));
-
+ configuration.put(new PropertySimple("url", vdbURL));
+
getModels(mcVdb, configuration);
detail.setPluginConfiguration(configuration);
-
+
// Add to return values
discoveredResources.add(detail);
log.info("Discovered Teiid VDB: " + vdbName);
@@ -115,28 +133,33 @@
* @param configuration
*/
private void getModels(ManagedComponent mcVdb, Configuration configuration) {
- //Get models from VDB
+ // Get models from VDB
ManagedProperty property = mcVdb.getProperty("models");
- CollectionValueSupport valueSupport = (CollectionValueSupport) property.getValue();
+ CollectionValueSupport valueSupport = (CollectionValueSupport) property
+ .getValue();
MetaValue[] metaValues = valueSupport.getElements();
-
+
PropertyList modelsList = new PropertyList("models");
configuration.put(modelsList);
-
+
for (MetaValue value : metaValues) {
GenericValueSupport genValueSupport = (GenericValueSupport) value;
- ManagedObjectImpl managedObject = (ManagedObjectImpl)genValueSupport.getValue();
+ ManagedObjectImpl managedObject = (ManagedObjectImpl) genValueSupport
+ .getValue();
String modelName = managedObject.getName();
- String type = ((SimpleValueSupport) managedObject.getProperty("modelType").getValue()).getValue().toString();
- String visibility = ((SimpleValueSupport) managedObject.getProperty("visible").getValue()).getValue().toString();
- String path = ((SimpleValueSupport) managedObject.getProperty("path").getValue()).getValue().toString();
-
- PropertyMap model = new PropertyMap("model", new PropertySimple("name", modelName),
- new PropertySimple("type", type), new PropertySimple("path", path),
- new PropertySimple("visibility", visibility));
+ String type = ((SimpleValueSupport) managedObject.getProperty(
+ "modelType").getValue()).getValue().toString();
+ String visibility = ((SimpleValueSupport) managedObject
+ .getProperty("visible").getValue()).getValue().toString();
+ String path = ((SimpleValueSupport) managedObject.getProperty(
+ "path").getValue()).getValue().toString();
+
+ PropertyMap model = new PropertyMap("model", new PropertySimple(
+ "name", modelName), new PropertySimple("type", type),
+ new PropertySimple("path", path), new PropertySimple(
+ "visibility", visibility));
modelsList.add(model);
}
- }
-
+ }
}
Copied: branches/JCA/console/src/main/java/org/teiid/rhq/plugin/util/DeploymentUtils.java (from rev 1840, trunk/console/src/main/java/org/teiid/rhq/plugin/util/DeploymentUtils.java)
===================================================================
--- branches/JCA/console/src/main/java/org/teiid/rhq/plugin/util/DeploymentUtils.java (rev 0)
+++ branches/JCA/console/src/main/java/org/teiid/rhq/plugin/util/DeploymentUtils.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -0,0 +1,146 @@
+/*
+ * 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.rhq.plugin.util;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Arrays;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.deployers.spi.management.deploy.DeploymentManager;
+import org.jboss.deployers.spi.management.deploy.DeploymentProgress;
+import org.jboss.deployers.spi.management.deploy.DeploymentStatus;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.util.exception.ThrowableUtil;
+
+/**
+ * A set of utility methods for deploying applications.
+ *
+ */
+public class DeploymentUtils {
+ private static final Log LOG = LogFactory.getLog(DeploymentUtils.class);
+
+ public static boolean hasCorrectExtension(String archiveFileName, ResourceType resourceType) {
+ String expectedExtension = "vdb";
+ int lastPeriod = archiveFileName.lastIndexOf(".");
+ String extension = (lastPeriod != -1) ? archiveFileName.substring(lastPeriod + 1) : null;
+ // Use File.equals() to compare the extensions so case-sensitivity is correct for this platform.
+ return (extension != null && new File(extension).equals(new File(expectedExtension)));
+ }
+
+ /**
+ * Deploys (i.e. distributes then starts) the specified archive file.
+ *
+ * @param deploymentManager
+ * @param archiveFile
+ * @param deployExploded
+ *
+ * @return
+ *
+ * @throws Exception if the deployment fails for any reason
+ */
+ public static void deployArchive(DeploymentManager deploymentManager, File archiveFile, boolean deployExploded)
+ throws Exception {
+ String archiveFileName = archiveFile.getName();
+ LOG.debug("Deploying '" + archiveFileName + "' (deployExploded=" + deployExploded + ")...");
+ URL contentURL;
+ try {
+ contentURL = archiveFile.toURI().toURL();
+ }
+ catch (MalformedURLException e) {
+ throw new IllegalArgumentException("Failed to convert archive file path '" + archiveFile + "' to URL.", e);
+ }
+
+ DeploymentProgress progress = null;
+ DeploymentStatus distributeStatus;
+ Exception distributeFailure = null;
+ try {
+ progress = deploymentManager.distribute(archiveFileName, contentURL, false);
+ distributeStatus = run(progress);
+ if (distributeStatus.isFailed()) {
+ distributeFailure = (distributeStatus.getFailure() != null) ? distributeStatus.getFailure() :
+ new Exception("Distribute failed for unknown reason.");
+ }
+ }
+ catch (Exception e) {
+ distributeFailure = e;
+ }
+ if (distributeFailure != null) {
+ throw new Exception("Failed to distribute '" + contentURL + "' to '" + archiveFileName + "' - cause: "
+ + ThrowableUtil.getAllMessages(distributeFailure));
+ }
+
+ // Now that we've successfully distributed the deployment, we need to start it.
+ String[] deploymentNames = progress.getDeploymentID().getRepositoryNames();
+ DeploymentStatus startStatus;
+ Exception startFailure = null;
+ try {
+ progress = deploymentManager.start(deploymentNames);
+ startStatus = run(progress);
+ if (startStatus.isFailed()) {
+ startFailure = (startStatus.getFailure() != null) ? startStatus.getFailure() :
+ new Exception("Start failed for unknown reason.");
+ }
+ }
+ catch (Exception e) {
+ startFailure = e;
+ }
+ if (startFailure != null) {
+ LOG.error("Failed to start deployment " + Arrays.asList(deploymentNames)
+ + " during deployment of '" + archiveFileName + "'. Backing out the deployment...", startFailure);
+ // If start failed, the app is invalid, so back out the deployment.
+ DeploymentStatus removeStatus;
+ Exception removeFailure = null;
+ try {
+ progress = deploymentManager.remove(deploymentNames);
+ removeStatus = run(progress);
+ if (removeStatus.isFailed()) {
+ removeFailure = (removeStatus.getFailure() != null) ? removeStatus.getFailure() :
+ new Exception("Remove failed for unknown reason.");
+ }
+ }
+ catch (Exception e) {
+ removeFailure = e;
+ }
+ if (removeFailure != null) {
+ LOG.error("Failed to remove deployment " + Arrays.asList(deploymentNames)
+ + " after start failure.", removeFailure);
+ }
+ throw new Exception("Failed to start deployment " + Arrays.asList(deploymentNames)
+ + " during deployment of '" + archiveFileName + "' - cause: " +
+ ThrowableUtil.getAllMessages(startFailure));
+ }
+ // If we made it this far, the deployment (distribution+start) was successful.
+ return;
+ }
+
+ public static DeploymentStatus run(DeploymentProgress progress) {
+ progress.run();
+ return progress.getDeploymentStatus();
+ }
+
+ private DeploymentUtils() {
+ }
+
+}
Modified: branches/JCA/console/src/main/java/org/teiid/rhq/plugin/util/ProfileServiceUtil.java
===================================================================
--- branches/JCA/console/src/main/java/org/teiid/rhq/plugin/util/ProfileServiceUtil.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/console/src/main/java/org/teiid/rhq/plugin/util/ProfileServiceUtil.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -1,17 +1,27 @@
package org.teiid.rhq.plugin.util;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.Set;
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.deployers.spi.management.KnownDeploymentTypes;
import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.deployers.spi.management.deploy.DeploymentManager;
import org.jboss.managed.api.ComponentType;
import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedDeployment;
import org.jboss.profileservice.spi.ProfileService;
public class ProfileServiceUtil {
+ protected final Log LOG = LogFactory.getLog(ProfileServiceUtil.class);
+
/**
* Get the passed in {@link ManagedComponent}
*
@@ -23,7 +33,7 @@
ComponentType componentType, String componentName)
throws NamingException, Exception {
ProfileService ps = getProfileService();
- ManagementView mv = getManagementView(ps);
+ ManagementView mv = getManagementView(ps, true);
ManagedComponent mc = mv.getComponent(componentName, componentType);
return mc;
@@ -34,13 +44,13 @@
* type.
*
* @return Set of {@link ManagedComponent}s
- * @throws NamingException
+ * @throws NamingException, Exception
* @throws Exception
*/
public static Set<ManagedComponent> getManagedComponents(
ComponentType componentType) throws NamingException, Exception {
ProfileService ps = getProfileService();
- ManagementView mv = getManagementView(ps);
+ ManagementView mv = getManagementView(ps, true);
Set<ManagedComponent> mcSet = mv.getComponentsForType(componentType);
@@ -51,21 +61,75 @@
* @param {@link ManagementView}
* @return
*/
- private static ManagementView getManagementView(ProfileService ps) {
+ public static ManagementView getManagementView(ProfileService ps, boolean load) {
ManagementView mv = ps.getViewManager();
- mv.load();
+ if (load) {
+ mv.load();
+ }
return mv;
}
/**
- * @return {@link ProfileService}
+ * Get the {@link DeploymentManager} from the ProfileService
+ *
+ * @return DeploymentManager
* @throws NamingException
+ * @throws Exception
*/
- private static ProfileService getProfileService() throws NamingException {
+ public static DeploymentManager getDeploymentManager()
+ throws NamingException, Exception {
+ ProfileService ps = getProfileService();
+ DeploymentManager deploymentManager = ps.getDeploymentManager();
+
+ return deploymentManager;
+ }
+
+ /**
+ * @return {@link ProfileService}
+ * @throws NamingException, Exception
+ */
+ public static ProfileService getProfileService() throws NamingException {
InitialContext ic = new InitialContext();
ProfileService ps = (ProfileService) ic
.lookup(PluginConstants.PROFILE_SERVICE);
return ps;
}
+ /**
+ * @return {@link File}
+ * @throws NamingException, Exception
+ */
+ public static File getDeployDirectory() throws NamingException, Exception {
+ ProfileService ps = getProfileService();
+ ManagementView mv = getManagementView(ps, false);
+ Set<ManagedDeployment> warDeployments;
+ try {
+ warDeployments = mv
+ .getDeploymentsForType(KnownDeploymentTypes.JavaEEWebApplication
+ .getType());
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ ManagedDeployment standaloneWarDeployment = null;
+ for (ManagedDeployment warDeployment : warDeployments) {
+ if (warDeployment.getParent() == null) {
+ standaloneWarDeployment = warDeployment;
+ break;
+ }
+ }
+ if (standaloneWarDeployment == null)
+ // This could happen if no standalone WARs, including the admin
+ // console WAR, have been fully deployed yet.
+ return null;
+ URL warUrl;
+ try {
+ warUrl = new URL(standaloneWarDeployment.getName());
+ } catch (MalformedURLException e) {
+ throw new IllegalStateException(e);
+ }
+ File warFile = new File(warUrl.getPath());
+ File deployDir = warFile.getParentFile();
+ return deployDir;
+ }
+
}
Modified: branches/JCA/console/src/resources/embedded/META-INF/rhq-plugin.xml
===================================================================
--- branches/JCA/console/src/resources/embedded/META-INF/rhq-plugin.xml 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/console/src/resources/embedded/META-INF/rhq-plugin.xml 2010-02-18 20:18:35 UTC (rev 1842)
@@ -26,21 +26,52 @@
<depends plugin="JMX" />
<depends plugin="JBossAS5" useClasses="true" />
-
<server name="Data Services" description="JBoss Enterprise Data Services"
- class="PlatformComponent" discovery="PlatformDiscoveryComponent"
- createDeletePolicy="both">
+ class="PlatformComponent" discovery="PlatformDiscoveryComponent">
-
<runs-inside>
<parent-resource-type name="JBossAS Server"
plugin="JBossAS5" />
</runs-inside>
- <service name="Virtual Database VDB(s)"
+ <!-- <metric displayName="Query Count" defaultOn="true" displayType="summary"
+ category="throughput" property="queryCount"
+ description="The number of queries for a given point in time" />
+
+ <metric displayName="Long Running Queries" defaultOn="true"
+ displayType="summary" category="performance" property="longRunningQueries"
+ description="The number of queries that have been running longer than the limit set for queries." />
+
+ <metric displayName="Session Count" defaultOn="true"
+ displayType="summary" category="throughput" property="sessionCount"
+ description="The number of user connections for a given point in time" />
+
+ <resource-configuration>
+ <c:group name="general" displayName="General"
+ hiddenByDefault="false">
+ <c:description>Query Configuration</c:description>
+ <c:simple-property name="longRunningQueryLimit"
+ type="integer" activationPolicy="immediate" units="seconds"
+ default="600" displayName="Long Running Query limit"
+ description="The value (in seconds) to use to determine if a query is to be considered 'long running'.">
+ <c:constraint>
+ <c:integer-constraint minimum="0" maximum="999999" />
+ </c:constraint>
+ </c:simple-property>
+ </c:group>
+ </resource-configuration>
+ -->
+ <service name="Virtual Database (VDB)s"
description="JBoss Enterprise Data Services Virtual Databases" class="VDBComponent"
- discovery="VDBDiscoveryComponent" createDeletePolicy="both">
+ discovery="VDBDiscoveryComponent" createDeletePolicy="both"
+ creationDataType="content">
+ <content name="vdb" displayName="VDB Archive" category="deployable"
+ isCreationType="true">
+
+ </content>
+
+
<resource-configuration>
<c:group name="general" displayName="General"
hiddenByDefault="false">
@@ -72,6 +103,7 @@
</c:group>
</resource-configuration>
+
<service name="Models" description="Models that map to a datasource"
class="ModelComponent" discovery="ModelDiscoveryComponent"
createDeletePolicy="both">
Modified: branches/JCA/engine/src/main/java/com/metamatrix/common/buffer/BufferManager.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/common/buffer/BufferManager.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/common/buffer/BufferManager.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -47,17 +47,23 @@
*/
FINAL
}
+
+ public enum BufferReserveMode {
+ WAIT,
+ FORCE,
+ NO_WAIT
+ }
- public static int DEFAULT_CONNECTOR_BATCH_SIZE = 2048;
- public static int DEFAULT_PROCESSOR_BATCH_SIZE = 1024;
- public static int DEFAULT_MAX_PROCESSING_BATCHES = 8;
+ public static int DEFAULT_CONNECTOR_BATCH_SIZE = 1024;
+ public static int DEFAULT_PROCESSOR_BATCH_SIZE = 512;
+ public static int DEFAULT_MAX_PROCESSING_BATCHES = 128;
+
/**
- * The BufferManager may maintain at least this many batch references in memory.
- *
- * Up to 2x this value may be held by soft references.
+ * This is the maximum number of batch columns used for processing.
+ * See {@link #reserveBuffers(int, boolean)}
*/
- public static int DEFAULT_RESERVE_BUFFERS = 64;
+ public static int DEFAULT_RESERVE_BUFFERS = 16384;
/**
* Get the batch size to use during query processing.
@@ -79,7 +85,7 @@
* across even a blocked exception.
* @return
*/
- int getMaxProcessingBatches();
+ int getMaxProcessingBatchColumns();
/**
* Creates a new {@link FileStore}. See {@link FileStore#setCleanupReference(Object)} to
@@ -90,14 +96,12 @@
FileStore createFileStore(String name);
/**
- * Reserve up to count buffers for use. Wait will cause the process to block until
- * all of the requested or half of the total buffers are available.
+ * Reserve up to count buffers for use.
* @param count
- * @param wait
+ * @param mode
* @return
- * @throws MetaMatrixComponentException
*/
- int reserveBuffers(int count, boolean wait) throws MetaMatrixComponentException;
+ int reserveBuffers(int count, BufferReserveMode mode);
/**
* Releases the buffers reserved by a call to {@link BufferManager#reserveBuffers(int, boolean)}
@@ -105,4 +109,9 @@
*/
void releaseBuffers(int count);
+ /**
+ * Get the size estimate for the given schema.
+ */
+ int getSchemaSize(List elements);
+
}
Modified: branches/JCA/engine/src/main/java/com/metamatrix/common/buffer/TupleBuffer.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/common/buffer/TupleBuffer.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/common/buffer/TupleBuffer.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -22,6 +22,7 @@
package com.metamatrix.common.buffer;
+import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -32,10 +33,13 @@
import java.util.concurrent.atomic.AtomicLong;
import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.common.log.LogManager;
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.common.types.Streamable;
+import com.metamatrix.core.log.MessageLevel;
import com.metamatrix.core.util.Assertion;
import com.metamatrix.dqp.DQPPlugin;
+import com.metamatrix.dqp.util.LogConstants;
import com.metamatrix.query.sql.symbol.Expression;
public class TupleBuffer {
@@ -75,15 +79,16 @@
private List<?> getCurrentTuple() throws MetaMatrixComponentException,
BlockedException {
if (currentRow <= rowCount) {
- if (forwardOnly) {
- if (batch == null || currentRow > batch.getEndRow()) {
+ //if (forwardOnly) {
+ if (batch == null || !batch.containsRow(currentRow)) {
batch = getBatch(currentRow);
}
return batch.getTuple(currentRow);
- }
+ //}
//TODO: determine if we should directly hold a soft reference here
- return getRow(currentRow);
+ //return getRow(currentRow);
}
+ batch = null;
if(isFinal) {
return null;
}
@@ -91,8 +96,7 @@
}
@Override
- public void closeSource()
- throws MetaMatrixComponentException{
+ public void closeSource() {
batch = null;
mark = 1;
reset();
@@ -210,21 +214,26 @@
* @throws MetaMatrixComponentException
*/
public void addTupleBatch(TupleBatch batch, boolean save) throws MetaMatrixComponentException {
- Assertion.assertTrue(this.rowCount < batch.getBeginRow());
- if (this.rowCount != batch.getBeginRow() - 1) {
- saveBatch(false, true);
- this.rowCount = batch.getBeginRow() - 1;
- }
+ setRowCount(batch.getBeginRow() - 1);
if (save) {
for (List<?> tuple : batch.getAllTuples()) {
addTuple(tuple);
}
}
}
+
+ public void setRowCount(int rowCount)
+ throws MetaMatrixComponentException {
+ assert this.rowCount <= rowCount;
+ if (this.rowCount != rowCount) {
+ saveBatch(false, true);
+ this.rowCount = rowCount;
+ }
+ }
public void purge() {
if (this.batchBuffer != null) {
- this.batchBuffer = null;
+ this.batchBuffer.clear();
}
for (BatchManager.ManagedBatch batch : this.batches.values()) {
batch.remove();
@@ -260,14 +269,6 @@
this.isFinal = true;
}
- List<?> getRow(int row) throws MetaMatrixComponentException {
- if (this.batchBuffer != null && row > rowCount - this.batchBuffer.size()) {
- return this.batchBuffer.get(row - rowCount + this.batchBuffer.size() - 1);
- }
- TupleBatch batch = getBatch(row);
- return batch.getTuple(row);
- }
-
/**
* Get the batch containing the given row.
* NOTE: the returned batch may be empty or may begin with a row other
@@ -311,8 +312,13 @@
public void remove() {
if (!removed) {
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
+ LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Removing TupleBuffer:", this.tupleSourceID); //$NON-NLS-1$
+ }
+ this.batchBuffer = null;
+ purge();
this.manager.remove();
- purge();
+ removed = true;
}
}
Modified: branches/JCA/engine/src/main/java/com/metamatrix/common/buffer/TupleSource.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/common/buffer/TupleSource.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/common/buffer/TupleSource.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -54,12 +54,8 @@
/**
* Closes the Tuple Source.
- * @throws MetaMatrixComponentException indicating a non-business
- * exception such as a communication exception, or other such
- * nondeterministic exception
*/
- void closeSource()
- throws MetaMatrixComponentException;
+ void closeSource();
/**
* Returns an estimate of the number of rows that can be read without blocking.
Modified: branches/JCA/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -27,17 +27,13 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.ref.Reference;
-import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
-import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
import java.util.TreeMap;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Condition;
@@ -62,7 +58,6 @@
import com.metamatrix.common.types.StandardXMLTranslator;
import com.metamatrix.common.types.Streamable;
import com.metamatrix.common.types.XMLType;
-import com.metamatrix.common.util.PropertiesUtils;
import com.metamatrix.core.MetaMatrixRuntimeException;
import com.metamatrix.core.log.MessageLevel;
import com.metamatrix.core.util.Assertion;
@@ -81,6 +76,10 @@
* with a simple LRU.
*
* TODO: allow for cached stores to use lru - (result set/mat view)
+ * TODO: account for row/content based sizing (difficult given value sharing)
+ * TODO: account for memory based lobs (it would be nice if the approximate buffer size matched at 100kB)
+ * TODO: add detection of pinned batches to prevent unnecessary purging of non-persistent batches
+ * - this is not necessary for already persistent batches, since we hold a weak reference
*/
public class BufferManagerImpl implements BufferManager, StorageManager {
@@ -96,10 +95,7 @@
ManagedBatchImpl removeBatch(int row) {
ManagedBatchImpl result = batches.remove(row);
if (result != null) {
- activeBatchCount--;
- if (toPersistCount > 0) {
- toPersistCount--;
- }
+ activeBatchColumnCount -= result.columnCount;
}
return result;
}
@@ -111,23 +107,30 @@
private long offset = -1;
private boolean persistent;
- private volatile TupleBatch pBatch;
- private Reference<TupleBatch> batchReference;
+ private volatile TupleBatch activeBatch;
+ private volatile Reference<TupleBatch> batchReference;
private int beginRow;
+ private int columnCount;
- public ManagedBatchImpl(String id, FileStore store, TupleBatch batch) throws MetaMatrixComponentException {
+ public ManagedBatchImpl(String id, FileStore store, TupleBatch batch) {
LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Add batch to BufferManager", batchAdded.incrementAndGet()); //$NON-NLS-1$
this.id = id;
this.store = store;
- this.pBatch = batch;
+ this.activeBatch = batch;
this.beginRow = batch.getBeginRow();
- addToCache(false);
- persistBatchReferences();
+ List[] allTuples = batch.getAllTuples();
+ if (allTuples.length > 0) {
+ columnCount = allTuples[0].size();
+ }
}
private void addToCache(boolean update) {
synchronized (activeBatches) {
- activeBatchCount++;
+ TupleBatch batch = this.activeBatch;
+ if (batch == null) {
+ return; //already removed
+ }
+ activeBatchColumnCount += columnCount;
TupleBufferInfo tbi = null;
if (update) {
tbi = activeBatches.remove(this.id);
@@ -164,35 +167,34 @@
}
}
}
+ persistBatchReferences();
synchronized (this) {
- if (this.batchReference != null && this.pBatch == null) {
- TupleBatch result = this.batchReference.get();
- if (result != null) {
- if (!cache) {
- softCache.remove(this);
- this.batchReference.clear();
+ TupleBatch batch = this.activeBatch;
+ if (batch != null){
+ return batch;
+ }
+ Reference<TupleBatch> ref = this.batchReference;
+ this.batchReference = null;
+ if (ref != null) {
+ batch = ref.get();
+ if (batch != null) {
+ if (cache) {
+ this.activeBatch = batch;
+ addToCache(true);
}
referenceHit.getAndIncrement();
- return result;
+ return batch;
}
}
-
- TupleBatch batch = this.pBatch;
- if (batch != null){
- return batch;
- }
- }
- persistBatchReferences();
- LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Reading batch from disk", readCount.incrementAndGet()); //$NON-NLS-1$
- synchronized (this) {
+ LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Reading batch from disk", readCount.incrementAndGet()); //$NON-NLS-1$
try {
ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(store.createInputStream(this.offset), IO_BUFFER_SIZE));
- TupleBatch batch = new TupleBatch();
+ batch = new TupleBatch();
batch.setDataTypes(types);
batch.readExternal(ois);
batch.setDataTypes(null);
if (cache) {
- this.pBatch = batch;
+ this.activeBatch = batch;
addToCache(true);
}
return batch;
@@ -204,71 +206,9 @@
}
}
- public void persistBatchReferences() throws MetaMatrixComponentException {
- ManagedBatchImpl mb = null;
- boolean createSoft = false;
- /*
- * If we are over our limit, collect half of the batches.
- */
- synchronized (activeBatches) {
- if (activeBatchCount > reserveBatches && toPersistCount == 0) {
- toPersistCount = activeBatchCount / 2;
- }
- }
- while (true) {
- synchronized (activeBatches) {
- if (activeBatchCount == 0 || toPersistCount == 0) {
- toPersistCount = 0;
- break;
- }
- Iterator<TupleBufferInfo> iter = activeBatches.values().iterator();
- TupleBufferInfo tbi = iter.next();
- Map.Entry<Integer, ManagedBatchImpl> entry = null;
- if (tbi.lastUsed != null) {
- entry = tbi.batches.floorEntry(tbi.lastUsed - 1);
- }
- if (entry == null) {
- entry = tbi.batches.pollLastEntry();
- } else {
- createSoft = true;
- tbi.batches.remove(entry.getKey());
- }
- if (tbi.batches.isEmpty()) {
- iter.remove();
- }
- activeBatchCount--;
- toPersistCount--;
- mb = entry.getValue();
- }
- persist(createSoft, mb);
- }
- synchronized (softCache) {
- if (softCache.size() > reserveBatches) {
- Iterator<ManagedBatchImpl> iter = softCache.iterator();
- mb = iter.next();
- iter.remove();
- }
- }
- persist(false, mb);
- }
-
- private void persist(boolean createSoft, ManagedBatchImpl mb)
- throws MetaMatrixComponentException {
+ public synchronized void persist() throws MetaMatrixComponentException {
try {
- if (mb != null) {
- mb.persist(createSoft);
- }
- } catch (MetaMatrixComponentException e) {
- if (mb == this) {
- throw e;
- }
- LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, e, "Error persisting batch, attempts to read that batch later will result in an exception"); //$NON-NLS-1$
- }
- }
-
- public synchronized void persist(boolean createSoft) throws MetaMatrixComponentException {
- try {
- TupleBatch batch = pBatch;
+ TupleBatch batch = activeBatch;
if (batch != null) {
if (!persistent) {
LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Writing batch to disk", writeCount.incrementAndGet()); //$NON-NLS-1$
@@ -282,18 +222,13 @@
fsos.flushBuffer();
}
}
- if (createSoft) {
- this.batchReference = new SoftReference<TupleBatch>(batch);
- softCache.add(this);
- } else {
- this.batchReference = new WeakReference<TupleBatch>(batch);
- }
+ this.batchReference = new WeakReference<TupleBatch>(batch);
}
} catch (IOException e) {
throw new MetaMatrixComponentException(e);
} finally {
persistent = true;
- pBatch = null;
+ activeBatch = null;
}
}
@@ -304,16 +239,13 @@
activeBatches.remove(this.id);
}
}
- softCache.remove(this);
- pBatch = null;
- if (batchReference != null) {
- batchReference.clear();
- }
+ activeBatch = null;
+ batchReference = null;
}
@Override
public String toString() {
- return "ManagedBatch " + id + " " + pBatch; //$NON-NLS-1$ //$NON-NLS-2$
+ return "ManagedBatch " + id + " " + activeBatch; //$NON-NLS-1$ //$NON-NLS-2$
}
}
@@ -321,16 +253,14 @@
private int connectorBatchSize = BufferManager.DEFAULT_CONNECTOR_BATCH_SIZE;
private int processorBatchSize = BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE;
private int maxProcessingBatches = BufferManager.DEFAULT_MAX_PROCESSING_BATCHES;
- private int reserveBatches = BufferManager.DEFAULT_RESERVE_BUFFERS;
- private int maxReserveBatches = BufferManager.DEFAULT_RESERVE_BUFFERS;
+ private int maxReserveBatchColumns = BufferManager.DEFAULT_RESERVE_BUFFERS;
+ private volatile int reserveBatchColumns = BufferManager.DEFAULT_RESERVE_BUFFERS;
private ReentrantLock lock = new ReentrantLock(true);
private Condition batchesFreed = lock.newCondition();
- private int toPersistCount = 0;
- private int activeBatchCount = 0;
+ private volatile int activeBatchColumnCount = 0;
private Map<String, TupleBufferInfo> activeBatches = new LinkedHashMap<String, TupleBufferInfo>();
- private Set<ManagedBatchImpl> softCache = Collections.synchronizedSet(new LinkedHashSet<ManagedBatchImpl>());
private StorageManager diskMgr;
@@ -341,18 +271,20 @@
private AtomicInteger readAttempts = new AtomicInteger();
private AtomicInteger referenceHit = new AtomicInteger();
- public int getMaxProcessingBatches() {
+ @Override
+ public int getMaxProcessingBatchColumns() {
return maxProcessingBatches;
}
- public void setMaxProcessingBatches(int maxProcessingBatches) {
- this.maxProcessingBatches = Math.max(2, maxProcessingBatches);
+ public void setMaxProcessingBatchColumns(int maxProcessingBatches) {
+ this.maxProcessingBatches = Math.max(0, maxProcessingBatches);
}
/**
* Get processor batch size
* @return Number of rows in a processor batch
*/
+ @Override
public int getProcessorBatchSize() {
return this.processorBatchSize;
}
@@ -361,6 +293,7 @@
* Get connector batch size
* @return Number of rows in a connector batch
*/
+ @Override
public int getConnectorBatchSize() {
return this.connectorBatchSize;
}
@@ -402,7 +335,10 @@
this.store = createFileStore(newID);
this.store.setCleanupReference(this);
}
- return new ManagedBatchImpl(newID, store, batch);
+ ManagedBatchImpl mbi = new ManagedBatchImpl(newID, store, batch);
+ mbi.addToCache(false);
+ persistBatchReferences();
+ return mbi;
}
@Override
@@ -450,9 +386,12 @@
@Override
public void releaseBuffers(int count) {
+ if (count < 1) {
+ return;
+ }
lock.lock();
try {
- this.reserveBatches += count;
+ this.reserveBatchColumns += count;
batchesFreed.signalAll();
} finally {
lock.unlock();
@@ -460,31 +399,83 @@
}
@Override
- public int reserveBuffers(int count, boolean wait) throws MetaMatrixComponentException {
+ public int reserveBuffers(int count, BufferReserveMode mode) {
lock.lock();
try {
- while (wait && count > this.reserveBatches && this.reserveBatches < this.maxReserveBatches / 2) {
- try {
- batchesFreed.await();
- } catch (InterruptedException e) {
- throw new MetaMatrixComponentException(e);
- }
- }
- this.reserveBatches -= count;
- if (this.reserveBatches >= 0) {
+ if (mode == BufferReserveMode.WAIT) {
+ int waitCount = 0;
+ while (count - waitCount > this.reserveBatchColumns) {
+ try {
+ batchesFreed.await(100, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ throw new MetaMatrixRuntimeException(e);
+ }
+ waitCount++;
+ }
+ }
+ if (this.reserveBatchColumns >= count || mode == BufferReserveMode.FORCE) {
+ this.reserveBatchColumns -= count;
return count;
}
- int result = count + this.reserveBatches;
- this.reserveBatches = 0;
+ int result = Math.max(0, this.reserveBatchColumns);
+ this.reserveBatchColumns -= result;
return result;
} finally {
lock.unlock();
+ persistBatchReferences();
}
}
- public void setMaxReserveBatches(int maxReserveBatches) {
- this.maxReserveBatches = maxReserveBatches;
+ void persistBatchReferences() {
+ if (activeBatchColumnCount == 0 || activeBatchColumnCount <= reserveBatchColumns) {
+ int memoryCount = activeBatchColumnCount + maxReserveBatchColumns - reserveBatchColumns;
+ if (DataTypeManager.isValueCacheEnabled()) {
+ if (memoryCount < maxReserveBatchColumns / 8) {
+ DataTypeManager.setValueCacheEnabled(false);
+ }
+ } else if (memoryCount > maxReserveBatchColumns / 4) {
+ DataTypeManager.setValueCacheEnabled(true);
+ }
+ return;
+ }
+ while (true) {
+ ManagedBatchImpl mb = null;
+ synchronized (activeBatches) {
+ if (activeBatchColumnCount == 0 || activeBatchColumnCount * 5 < reserveBatchColumns * 4) {
+ break;
+ }
+ Iterator<TupleBufferInfo> iter = activeBatches.values().iterator();
+ TupleBufferInfo tbi = iter.next();
+ Map.Entry<Integer, ManagedBatchImpl> entry = null;
+ if (tbi.lastUsed != null) {
+ entry = tbi.batches.floorEntry(tbi.lastUsed - 1);
+ }
+ if (entry == null) {
+ entry = tbi.batches.lastEntry();
+ }
+ tbi.removeBatch(entry.getKey());
+ if (tbi.batches.isEmpty()) {
+ iter.remove();
+ }
+ mb = entry.getValue();
+ }
+ try {
+ mb.persist();
+ } catch (MetaMatrixComponentException e) {
+ LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, e, "Error persisting batch, attempts to read that batch later will result in an exception"); //$NON-NLS-1$
+ }
+ }
}
+
+ @Override
+ public int getSchemaSize(List elements) {
+ return elements.size();
+ }
+
+ public void setMaxReserveBatchColumns(int maxReserve) {
+ this.maxReserveBatchColumns = maxReserve;
+ this.reserveBatchColumns = maxReserve;
+ }
public void shutdown() {
}
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -39,7 +39,6 @@
import com.metamatrix.api.exception.query.ExpressionEvaluationException;
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.types.Sequencable;
-import com.metamatrix.core.util.ArgCheck;
import com.metamatrix.core.util.Assertion;
import com.metamatrix.core.util.EquivalenceUtil;
import com.metamatrix.query.QueryPlugin;
@@ -224,8 +223,11 @@
}
private final int compareValues(Object leftValue, Object rightValue) {
- ArgCheck.isInstanceOf(Comparable.class, leftValue);
- ArgCheck.isInstanceOf(Comparable.class, rightValue);
+ assert leftValue instanceof Comparable<?>;
+ assert rightValue instanceof Comparable<?>;
+ if (leftValue == rightValue) {
+ return 0;
+ }
return ((Comparable)leftValue).compareTo(rightValue);
}
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -79,13 +79,11 @@
if (joinNode.getProperty(NodeConstants.Info.JOIN_TYPE) == JoinType.JOIN_INNER && context != null) {
float leftCost = NewCalculateCostUtil.computeCostForTree(joinNode.getFirstChild(), metadata);
float rightCost = NewCalculateCostUtil.computeCostForTree(joinNode.getLastChild(), metadata);
- boolean leftSmall = leftCost < context.getProcessorBatchSize() / 4;
- boolean rightSmall = rightCost < context.getProcessorBatchSize() / 4;
- boolean leftLarge = leftCost > context.getProcessorBatchSize();
- boolean rightLarge = rightCost > context.getProcessorBatchSize();
- if (leftLarge || rightLarge) {
- pushLeft = leftCost == NewCalculateCostUtil.UNKNOWN_VALUE || leftSmall || rightLarge;
- pushRight = rightCost == NewCalculateCostUtil.UNKNOWN_VALUE || rightSmall || leftLarge || joinNode.getProperty(NodeConstants.Info.DEPENDENT_VALUE_SOURCE) != null;
+ if (leftCost != NewCalculateCostUtil.UNKNOWN_VALUE && rightCost != NewCalculateCostUtil.UNKNOWN_VALUE
+ && (leftCost > context.getProcessorBatchSize() || rightCost > context.getProcessorBatchSize())) {
+ //we use a larger constant here to ensure that we don't unwisely prevent pushdown
+ pushLeft = leftCost < context.getProcessorBatchSize() || leftCost / rightCost < 16;
+ pushRight = rightCost < context.getProcessorBatchSize() || rightCost / leftCost < 16 || joinNode.getProperty(NodeConstants.Info.DEPENDENT_VALUE_SOURCE) != null;
}
}
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -140,6 +140,12 @@
CapabilitiesFinder capFinder, PlanNode critNode)
throws MetaMatrixComponentException, QueryMetadataException {
if (critNode.getGroups().isEmpty()) {
+ //check to see if pushing may impact cardinality
+ PlanNode groupNode = NodeEditor.findNodePreOrder(critNode, NodeConstants.Types.GROUP, NodeConstants.Types.SOURCE);
+ if (groupNode != null && !groupNode.hasCollectionProperty(NodeConstants.Info.GROUP_COLS)) {
+ return groupNode;
+ }
+
Object modelId = getSubqueryModelId(metadata, capFinder, critNode);
if (modelId != null) {
for (PlanNode node : NodeEditor.findAllNodes(critNode, NodeConstants.Types.SOURCE)) {
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/BatchCollector.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/BatchCollector.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/BatchCollector.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -95,7 +95,7 @@
add = this.batchHandler.batchProduced(batch);
}
// Add batch
- if(batch.getRowCount() > 0) {
+ if(batch.getRowCount() > 0 || batch.getTerminationFlag()) {
buffer.addTupleBatch(batch, add);
}
}
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/BatchIterator.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/BatchIterator.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/BatchIterator.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -103,7 +103,7 @@
}
@Override
- public void closeSource() throws MetaMatrixComponentException {
+ public void closeSource() {
if (this.buffer != null) {
this.buffer.remove();
this.buffer = null;
@@ -124,7 +124,8 @@
List result = currentTuple;
currentTuple = null;
if (mark && saveOnMark && this.currentRow - 1 > this.buffer.getRowCount()) {
- this.buffer.addTupleBatch(new TupleBatch(this.currentRow - 1, new List[] {result}), true);
+ this.buffer.setRowCount(this.currentRow - 2);
+ this.buffer.addTuple(result);
this.bufferedIndex = this.currentRow - 1;
}
return result;
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/QueryProcessor.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/QueryProcessor.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/QueryProcessor.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -30,6 +30,7 @@
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.buffer.BufferManager;
import com.metamatrix.common.buffer.TupleBatch;
+import com.metamatrix.common.buffer.BufferManager.BufferReserveMode;
import com.metamatrix.common.buffer.BufferManager.TupleSourceType;
import com.metamatrix.common.log.LogManager;
import com.metamatrix.core.MetaMatrixRuntimeException;
@@ -57,6 +58,7 @@
private BufferManager bufferMgr;
private ProcessorPlan processPlan;
private boolean initialized = false;
+ private int reserved;
/** Flag that marks whether the request has been canceled. */
private volatile boolean requestCanceled = false;
private static final int DEFAULT_WAIT = 50;
@@ -125,10 +127,12 @@
try {
// initialize if necessary
if(! initialized) {
+ if (reserved == 0) {
+ reserved = this.bufferMgr.reserveBuffers(this.bufferMgr.getSchemaSize(this.getOutputElements()), BufferReserveMode.FORCE);
+ }
// Open the top node for reading
processPlan.open();
-
- initialized = true;
+ initialized = true;
}
long currentTime = System.currentTimeMillis();
@@ -155,11 +159,7 @@
} catch (BlockedException e) {
throw e;
} catch (MetaMatrixException e) {
- try {
- closeProcessing();
- } catch (MetaMatrixException e1){
- LogManager.logDetail(LogConstants.CTX_DQP, e1, "Error closing processor"); //$NON-NLS-1$
- }
+ closeProcessing();
if (e instanceof MetaMatrixProcessingException) {
throw (MetaMatrixProcessingException)e;
}
@@ -180,18 +180,22 @@
/**
* Close processing and clean everything up. Should only be called by the same thread that called process.
- * @throws MetaMatrixComponentException
*/
- public void closeProcessing() throws MetaMatrixComponentException {
+ public void closeProcessing() {
if (processorClosed) {
return;
}
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
LogManager.logDetail(LogConstants.CTX_DQP, "QueryProcessor: closing processor"); //$NON-NLS-1$
}
+ this.bufferMgr.releaseBuffers(reserved);
+ reserved = 0;
processorClosed = true;
-
- processPlan.close();
+ try {
+ processPlan.close();
+ } catch (MetaMatrixComponentException e1){
+ LogManager.logDetail(LogConstants.CTX_DQP, e1, "Error closing processor"); //$NON-NLS-1$
+ }
}
@Override
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/AccessNode.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/AccessNode.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/AccessNode.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -103,7 +103,7 @@
isUpdate = RelationalNodeUtil.isUpdate(atomicCommand);
if(needProcessing) {
- this.tupleSource = getDataManager().registerRequest(this.getContext().getProcessorID(), atomicCommand, modelName, connectorBindingId, getID());
+ registerRequest(atomicCommand);
}
}
@@ -153,7 +153,7 @@
}
Command atomicCommand = (Command)command.clone();
if (prepareNextCommand(atomicCommand)) {
- tupleSource = getDataManager().registerRequest(this.getContext().getProcessorID(), atomicCommand, modelName, null, getID());
+ registerRequest(atomicCommand);
break;
}
}
@@ -168,6 +168,11 @@
terminateBatches();
return pullBatch();
}
+
+ private void registerRequest(Command atomicCommand)
+ throws MetaMatrixComponentException, MetaMatrixProcessingException {
+ tupleSource = getDataManager().registerRequest(this.getContext().getProcessorID(), atomicCommand, modelName, connectorBindingId, getID());
+ }
protected boolean processCommandsIndividually() {
return false;
@@ -177,15 +182,11 @@
return false;
}
- public void close() throws MetaMatrixComponentException {
- if (!isClosed()) {
- super.close();
-
- closeSources();
- }
+ public void closeDirect() {
+ closeSources();
}
- private void closeSources() throws MetaMatrixComponentException {
+ private void closeSources() {
if(this.tupleSource != null) {
this.tupleSource.closeSource();
tupleSource = null;
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/BatchedUpdateNode.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/BatchedUpdateNode.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/BatchedUpdateNode.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -144,14 +144,10 @@
* @see com.metamatrix.query.processor.relational.RelationalNode#close()
* @since 4.2
*/
- public void close() throws MetaMatrixComponentException {
- if (!isClosed()) {
- super.close();
-
- if (tupleSource != null) {
- tupleSource.closeSource();
- tupleSource = null;
- }
+ public void closeDirect() {
+ if (tupleSource != null) {
+ tupleSource.closeSource();
+ tupleSource = null;
}
}
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentAccessNode.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentAccessNode.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentAccessNode.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -54,11 +54,8 @@
/**
* @see com.metamatrix.query.processor.relational.AccessNode#close()
*/
- public void close() throws MetaMatrixComponentException {
- if (isClosed()) {
- return;
- }
- super.close();
+ public void closeDirect() {
+ super.closeDirect();
if (criteriaProcessor != null) {
criteriaProcessor.close();
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -90,7 +90,7 @@
DependentValueSource originalVs = (DependentValueSource)dependentNode.getContext().getVariableContext().getGlobalValue(valueSource);
this.sortUtility = new SortUtility(originalVs.getTupleBuffer().createIndexedTupleSource(), sortSymbols, sortDirection, Mode.DUP_REMOVE, dependentNode.getBufferManager(), dependentNode.getConnectionID());
}
- dvs = new DependentValueSource(sortUtility.sort(), dependentNode.getBufferManager().getProcessorBatchSize() / 2);
+ dvs = new DependentValueSource(sortUtility.sort());
for (SetState setState : dependentSetStates) {
setState.valueIterator = dvs.getValueIterator(setState.valueExpression);
}
@@ -176,7 +176,7 @@
}
}
- public void close() throws MetaMatrixComponentException {
+ public void close() {
if (dependentState != null) {
for (TupleState state : dependentState.values()) {
state.close();
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -77,11 +77,8 @@
criteriaProcessor = null;
}
- public void close() throws MetaMatrixComponentException {
- if (isClosed()) {
- return;
- }
- super.close();
+ public void closeDirect() {
+ super.closeDirect();
if (criteriaProcessor != null) {
criteriaProcessor.close();
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureExecutionNode.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureExecutionNode.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureExecutionNode.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -76,11 +76,8 @@
criteriaProcessor = null;
}
- public void close() throws MetaMatrixComponentException {
- if (isClosed()) {
- return;
- }
- super.close();
+ public void closeDirect() {
+ super.closeDirect();
if (criteriaProcessor != null) {
criteriaProcessor.close();
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentValueSource.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentValueSource.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DependentValueSource.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -45,17 +45,15 @@
public class DependentValueSource implements
ValueIteratorSource {
- private TupleBuffer tupleSourceID;
- private int maxSetSize;
+ private TupleBuffer buffer;
private Map<Expression, Set<Object>> cachedSets;
- public DependentValueSource(TupleBuffer tupleSourceID, int maxSetSize) {
- this.tupleSourceID = tupleSourceID;
- this.maxSetSize = maxSetSize;
+ public DependentValueSource(TupleBuffer tupleSourceID) {
+ this.buffer = tupleSourceID;
}
public TupleBuffer getTupleBuffer() {
- return tupleSourceID;
+ return buffer;
}
/**
@@ -63,7 +61,7 @@
* @see com.metamatrix.query.sql.util.ValueIteratorSource#getValueIterator(com.metamatrix.query.sql.symbol.Expression)
*/
public ValueIterator getValueIterator(Expression valueExpression) throws MetaMatrixComponentException {
- IndexedTupleSource its = tupleSourceID.createIndexedTupleSource();
+ IndexedTupleSource its = buffer.createIndexedTupleSource();
int index = 0;
if (valueExpression != null) {
index = its.getSchema().indexOf(valueExpression);
@@ -78,10 +76,10 @@
result = cachedSets.get(valueExpression);
}
if (result == null) {
- if (tupleSourceID.getRowCount() > maxSetSize) {
+ if (buffer.getRowCount() > buffer.getBatchSize()) {
return null;
}
- IndexedTupleSource its = tupleSourceID.createIndexedTupleSource();
+ IndexedTupleSource its = buffer.createIndexedTupleSource();
int index = 0;
if (valueExpression != null) {
index = its.getSchema().indexOf(valueExpression);
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DuplicateFilter.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DuplicateFilter.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/DuplicateFilter.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -125,7 +125,9 @@
this.collectionBuffer.close();
// Sort
- sortUtility = new SortUtility(collectionBuffer.createIndexedTupleSource(), elements, sortTypes, Mode.DUP_REMOVE, mgr, groupName);
+ if (sortUtility == null) {
+ sortUtility = new SortUtility(collectionBuffer.createIndexedTupleSource(), elements, sortTypes, Mode.DUP_REMOVE_SORT, mgr, groupName);
+ }
TupleBuffer sorted = sortUtility.sort();
sorted.setForwardOnly(true);
try {
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -212,9 +212,8 @@
return groupPhase();
}
- TupleBatch terminationBatch = new TupleBatch(1, Collections.EMPTY_LIST);
- terminationBatch.setTerminationFlag(true);
- return terminationBatch;
+ this.terminateBatches();
+ return pullBatch();
}
public TupleSource getCollectionTupleSource() {
@@ -265,7 +264,7 @@
}
@Override
- public void closeSource() throws MetaMatrixComponentException {
+ public void closeSource() {
}
@@ -390,14 +389,11 @@
}
}
- public void close() throws MetaMatrixComponentException {
- if (!isClosed()) {
- if (this.sortBuffer != null) {
- this.sortBuffer.remove();
- this.sortBuffer = null;
- }
- super.close();
- }
+ public void closeDirect() {
+ if (this.sortBuffer != null) {
+ this.sortBuffer.remove();
+ this.sortBuffer = null;
+ }
}
protected void getNodeString(StringBuffer str) {
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/InsertPlanExecutionNode.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/InsertPlanExecutionNode.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/InsertPlanExecutionNode.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -102,8 +102,7 @@
}
@Override
- public void close() throws MetaMatrixComponentException {
- super.close();
+ public void closeDirect() {
this.currentBatch = null;
}
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/JoinNode.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/JoinNode.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/JoinNode.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -36,6 +36,7 @@
import com.metamatrix.common.buffer.BufferManager;
import com.metamatrix.common.buffer.TupleBatch;
import com.metamatrix.common.buffer.TupleBuffer;
+import com.metamatrix.common.buffer.BufferManager.BufferReserveMode;
import com.metamatrix.query.processor.ProcessorDataManager;
import com.metamatrix.query.processor.relational.SourceState.ImplicitBuffer;
import com.metamatrix.query.sql.LanguageObject;
@@ -48,6 +49,10 @@
*/
public class JoinNode extends SubqueryAwareRelationalNode {
+ static class BatchAvailableException extends RuntimeException {}
+
+ static BatchAvailableException BATCH_AVILABLE = new BatchAvailableException();
+
public enum JoinStrategyType {
MERGE,
PARTITIONED_SORT,
@@ -59,6 +64,7 @@
private boolean leftOpened;
private boolean rightOpened;
+ private int reserved;
private JoinStrategy joinStrategy;
private JoinType joinType;
@@ -147,16 +153,25 @@
this.leftOpened = true;
}
- if(!isDependent() && !this.rightOpened) {
- // Open right child if non-dependent
- getChildren()[1].open();
- this.rightOpened = true;
+ if(!isDependent()) {
+ openRight();
}
this.state = State.LOAD_LEFT;
// Set Up Join Strategy
this.joinStrategy.initialize(this);
}
+
+ private void openRight() throws MetaMatrixComponentException,
+ MetaMatrixProcessingException {
+ if (!this.rightOpened) {
+ if (reserved == 0) {
+ reserved = getBufferManager().reserveBuffers(getBufferManager().getSchemaSize(getOutputElements()), BufferReserveMode.FORCE);
+ }
+ getChildren()[1].open();
+ this.rightOpened = true;
+ }
+ }
/**
* @see com.metamatrix.query.processor.relational.RelationalNode#clone()
@@ -194,33 +209,25 @@
}
//left child was already opened by the join node
this.joinStrategy.loadLeft();
+ if (isDependent()) {
+ TupleBuffer buffer = this.joinStrategy.leftSource.getTupleBuffer();
+ this.getContext().getVariableContext().setGlobalValue(this.dependentValueSource, new DependentValueSource(buffer));
+ }
state = State.LOAD_RIGHT;
}
if (state == State.LOAD_RIGHT) {
- if (isDependent() && !this.rightOpened) {
- TupleBuffer tsID = this.joinStrategy.leftSource.getTupleBuffer();
- this.getContext().getVariableContext().setGlobalValue(this.dependentValueSource, new DependentValueSource(tsID, this.getBufferManager().getProcessorBatchSize() / 2));
- //open the right side now that the tuples have been collected
- this.getChildren()[1].open();
- this.rightOpened = true;
- }
+ this.openRight();
this.joinStrategy.loadRight();
+ this.getContext().getVariableContext().setGlobalValue(this.dependentValueSource, null);
state = State.EXECUTE;
}
-
- while(true) {
- if(super.isBatchFull()) {
- return super.pullBatch();
- }
- List outputTuple = this.joinStrategy.nextTuple();
- if(outputTuple != null) {
- List projectTuple = projectTuple(this.projectionIndexes, outputTuple);
- super.addBatchRow(projectTuple);
- } else {
- super.terminateBatches();
- return super.pullBatch();
- }
+ try {
+ this.joinStrategy.process();
+ this.terminateBatches();
+ } catch (BatchAvailableException e) {
+ //pull the batch
}
+ return pullBatch();
}
/**
@@ -295,13 +302,12 @@
this.dependentValueSource = dependentValueSource;
}
- public void close()
- throws MetaMatrixComponentException {
- super.close();
+ public void closeDirect() {
+ getBufferManager().releaseBuffers(reserved);
+ reserved = 0;
+ super.closeDirect();
joinStrategy.close();
- if (this.isDependent()) {
- this.getContext().getVariableContext().setGlobalValue(this.dependentValueSource, null);
- }
+ this.getContext().getVariableContext().setGlobalValue(this.dependentValueSource, null);
}
public JoinType getJoinType() {
@@ -335,5 +341,14 @@
}
return Arrays.asList(this.joinCriteria);
}
+
+ @Override
+ protected void addBatchRow(List row) {
+ List projectTuple = projectTuple(this.projectionIndexes, row);
+ super.addBatchRow(projectTuple);
+ if (isBatchFull()) {
+ throw BATCH_AVILABLE;
+ }
+ }
}
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/JoinStrategy.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/JoinStrategy.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/JoinStrategy.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -79,7 +79,7 @@
return combinedRow;
}
- protected abstract List nextTuple() throws MetaMatrixComponentException, CriteriaEvaluationException, MetaMatrixProcessingException;
+ protected abstract void process() throws MetaMatrixComponentException, CriteriaEvaluationException, MetaMatrixProcessingException;
public abstract Object clone();
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/LimitNode.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/LimitNode.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/LimitNode.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -98,9 +98,6 @@
rowCounter += resultBatch.getRowCount();
if (rowCounter == limit || batch.getTerminationFlag()) {
resultBatch.setTerminationFlag(true);
- if (!batch.getTerminationFlag()){
- getChildren()[0].close();
- }
}
return resultBatch;
}
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/MergeJoinStrategy.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/MergeJoinStrategy.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/MergeJoinStrategy.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -135,7 +135,7 @@
}
@Override
- protected List nextTuple() throws MetaMatrixComponentException,
+ protected void process() throws MetaMatrixComponentException,
CriteriaEvaluationException, MetaMatrixProcessingException {
while (this.mergeState != MergeState.DONE) {
@@ -149,7 +149,7 @@
this.leftScanState = ScanState.DONE;
if (joinNode.getJoinType() != JoinType.JOIN_FULL_OUTER) {
mergeState = MergeState.DONE;
- return null;
+ return;
}
}
}
@@ -163,7 +163,7 @@
this.rightScanState = ScanState.DONE;
if (!this.joinNode.getJoinType().isOuter()) {
mergeState = MergeState.DONE;
- return null;
+ return;
}
}
}
@@ -173,7 +173,7 @@
if (this.leftScanState == ScanState.DONE) {
if (this.rightScanState == ScanState.DONE) {
this.mergeState = MergeState.DONE;
- return null;
+ return;
}
result = -1;
} else if (this.rightScanState == ScanState.DONE) {
@@ -191,12 +191,12 @@
} else if (result > 0) {
this.leftScanState = ScanState.READ;
if (this.joinNode.getJoinType().isOuter()) {
- return outputTuple(this.leftSource.getCurrentTuple(), this.rightSource.getOuterVals());
+ this.joinNode.addBatchRow(outputTuple(this.leftSource.getCurrentTuple(), this.rightSource.getOuterVals()));
}
} else {
this.rightScanState = ScanState.READ;
if (joinNode.getJoinType() == JoinType.JOIN_FULL_OUTER) {
- return outputTuple(this.leftSource.getOuterVals(), this.rightSource.getCurrentTuple());
+ this.joinNode.addBatchRow(outputTuple(this.leftSource.getOuterVals(), this.rightSource.getCurrentTuple()));
}
}
}
@@ -229,11 +229,11 @@
while (loopState == LoopState.LOAD_INNER || loopState == LoopState.EVALUATE_CRITERIA) {
if (loopState == LoopState.LOAD_INNER) {
- if (compareToPrevious(innerState)) {
- loopState = LoopState.EVALUATE_CRITERIA;
- } else {
- loopState = LoopState.LOAD_OUTER;
+ if (!compareToPrevious(innerState)) {
+ loopState = LoopState.LOAD_OUTER;
+ break;
}
+ loopState = LoopState.EVALUATE_CRITERIA;
}
if (loopState == LoopState.EVALUATE_CRITERIA) {
@@ -248,25 +248,25 @@
if (this.joinNode.getJoinType() == JoinType.JOIN_SEMI) {
this.loopState = LoopState.LOAD_OUTER; //only one match is needed for semi join
}
- return outputTuple;
+ this.joinNode.addBatchRow(outputTuple);
+ continue;
}
//right outer join || anti semi join can skip to the next outer value
this.loopState = LoopState.LOAD_OUTER;
+ break;
}
}
}
if (!outerMatched) {
if (matchState == MatchState.MATCH_RIGHT) {
- return outputTuple(this.leftSource.getOuterVals(), this.rightSource.getCurrentTuple());
+ this.joinNode.addBatchRow(outputTuple(this.leftSource.getOuterVals(), this.rightSource.getCurrentTuple()));
+ } else if (this.joinNode.getJoinType().isOuter()) {
+ this.joinNode.addBatchRow(outputTuple(this.leftSource.getCurrentTuple(), this.rightSource.getOuterVals()));
}
- if (this.joinNode.getJoinType().isOuter()) {
- return outputTuple(this.leftSource.getCurrentTuple(), this.rightSource.getOuterVals());
- }
}
}
}
- return null;
}
protected boolean compareToPrevious(SourceState target) throws MetaMatrixComponentException,
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/NullNode.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/NullNode.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/NullNode.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -22,7 +22,6 @@
package com.metamatrix.query.processor.relational;
-import java.util.Collections;
import java.util.Map;
import com.metamatrix.api.exception.MetaMatrixComponentException;
@@ -37,9 +36,8 @@
public TupleBatch nextBatchDirect()
throws MetaMatrixComponentException {
- TupleBatch batch = new TupleBatch(1, Collections.EMPTY_LIST);
- batch.setTerminationFlag(true);
- return batch;
+ this.terminateBatches();
+ return pullBatch();
}
protected void getNodeString(StringBuffer str) {
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/PartitionedSortJoin.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/PartitionedSortJoin.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/PartitionedSortJoin.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -32,6 +32,7 @@
import com.metamatrix.common.buffer.IndexedTupleSource;
import com.metamatrix.common.buffer.TupleBatch;
import com.metamatrix.common.buffer.TupleBuffer;
+import com.metamatrix.common.buffer.BufferManager.BufferReserveMode;
/**
* Extends the basic fully sorted merge join to check for conditions necessary
@@ -54,6 +55,7 @@
private List<?> partitionedTuple;
private int matchBegin = -1;
private int matchEnd = -1;
+ private int reserved;
public PartitionedSortJoin(SortOption sortLeft, SortOption sortRight) {
super(sortLeft, sortRight, false);
@@ -65,6 +67,7 @@
for (TupleBuffer tupleSourceID : this.partitions) {
tupleSourceID.remove();
}
+ releaseReserved();
this.endTuples = null;
this.overlap.clear();
this.endRows.clear();
@@ -117,14 +120,13 @@
protected void loadRight() throws MetaMatrixComponentException,
MetaMatrixProcessingException {
this.rightSource.getTupleBuffer();
- int maxRows = this.joinNode.getBatchSize() * getMaxProcessingBatches();
if (processingSortRight == SortOption.SORT
- && this.leftSource.getRowCount() < maxRows
- && this.leftSource.getRowCount() * 4 < this.rightSource.getRowCount()) {
+ && this.leftSource.getRowCount() * 4 < this.rightSource.getRowCount()
+ && testAndSetPartitions(this.rightSource.getRowCount(), this.rightSource.getSource().getOutputElements())) {
this.processingSortRight = SortOption.PARTITION;
} else if (processingSortLeft == SortOption.SORT
- && this.rightSource.getRowCount() < maxRows
- && this.rightSource.getRowCount() * 4 < this.leftSource.getRowCount()) {
+ && this.rightSource.getRowCount() * 4 < this.leftSource.getRowCount()
+ && testAndSetPartitions(this.leftSource.getRowCount(), this.leftSource.getSource().getOutputElements())) {
this.processingSortLeft = SortOption.PARTITION;
}
super.loadRight(); //sort right if needed
@@ -140,49 +142,52 @@
this.partitionedSource = this.rightSource;
}
if (this.processingSortLeft == SortOption.PARTITION) {
- partitionSource(true);
+ partitionSource();
}
if (this.processingSortRight == SortOption.PARTITION) {
- partitionSource(false);
- if (this.processingSortRight == SortOption.SORT) {
- //degrade to a merge join
- super.loadRight();
- }
+ partitionSource();
}
}
/**
* Since the source to be partitioned is already loaded, then there's no
- * chance of a blocked exception during partitioning, so double the max.
+ * chance of a blocked exception during partitioning, so reserve some batches.
*
* TODO: partition at the same time as the load to determine size
*
* @return
*/
- private int getMaxProcessingBatches() {
- return 2 * this.joinNode.getBufferManager().getMaxProcessingBatches();
+ private boolean testAndSetPartitions(int rowCount, List elements) {
+ int partitionCount = (rowCount / this.joinNode.getBatchSize() + rowCount % this.joinNode.getBatchSize() == 0 ? 0:1)
+ * this.joinNode.getBufferManager().getSchemaSize(elements);
+ if (partitionCount > this.joinNode.getBufferManager().getMaxProcessingBatchColumns() * 8) {
+ return false;
+ }
+ int toReserve = Math.max(1, (int)(partitionCount * .75));
+ int excess = Math.max(0, toReserve - this.joinNode.getBufferManager().getMaxProcessingBatchColumns());
+ reserved = this.joinNode.getBufferManager().reserveBuffers(toReserve - excess, BufferReserveMode.FORCE);
+ if (excess > 0) {
+ reserved += this.joinNode.getBufferManager().reserveBuffers(toReserve, BufferReserveMode.NO_WAIT);
+ }
+ if (reserved == toReserve) {
+ return true;
+ }
+ releaseReserved();
+ return false;
}
- private void partitionSource(boolean left) throws MetaMatrixComponentException,
+ private void partitionSource() throws MetaMatrixComponentException,
MetaMatrixProcessingException {
if (partitioned) {
return;
}
- if (endTuples.length > getMaxProcessingBatches() + 1) {
- if (left) {
- this.processingSortLeft = SortOption.SORT;
- } else {
- this.processingSortRight = SortOption.SORT;
- }
- return;
- }
if (endTuples.length < 2) {
partitions.add(this.partitionedSource.getTupleBuffer());
} else {
if (partitions.isEmpty()) {
for (int i = 0; i < endTuples.length; i++) {
TupleBuffer tc = this.partitionedSource.createSourceTupleBuffer();
- tc.setBatchSize(Math.max(1, this.joinNode.getBatchSize()));
+ tc.setForwardOnly(true);
this.partitions.add(tc);
}
}
@@ -204,18 +209,24 @@
for (TupleBuffer partition : this.partitions) {
partition.close();
}
+ releaseReserved();
}
partitioned = true;
}
+
+ private void releaseReserved() {
+ this.joinNode.getBufferManager().releaseBuffers(this.reserved);
+ this.reserved = 0;
+ }
@Override
- protected List nextTuple() throws MetaMatrixComponentException,
+ protected void process() throws MetaMatrixComponentException,
CriteriaEvaluationException, MetaMatrixProcessingException {
if (this.processingSortLeft != SortOption.PARTITION && this.processingSortRight != SortOption.PARTITION) {
- return super.nextTuple();
+ super.process();
}
if (endRows.isEmpty()) {
- return null; //no rows on the sorted side
+ return; //no rows on the sorted side
}
while (currentPartition < partitions.size()) {
if (currentSource == null) {
@@ -260,7 +271,7 @@
boolean matches = this.joinNode.matchesCriteria(outputTuple);
matchBegin++;
if (matches) {
- return outputTuple;
+ this.joinNode.addBatchRow(outputTuple);
}
}
matchBegin = -1;
@@ -271,7 +282,6 @@
currentSource = null;
currentPartition++;
}
- return null;
}
public int binarySearch(List<?> tuple, List[] tuples, int[] leftIndexes, int[] rightIndexes) {
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/PlanExecutionNode.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/PlanExecutionNode.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/PlanExecutionNode.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -30,10 +30,13 @@
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.buffer.TupleBatch;
+import com.metamatrix.common.log.LogManager;
+import com.metamatrix.dqp.util.LogConstants;
import com.metamatrix.query.processor.ProcessorPlan;
import com.metamatrix.query.sql.util.VariableContext;
import com.metamatrix.query.util.CommandContext;
+//TODO: consolidate with QueryProcessor
public class PlanExecutionNode extends RelationalNode {
// Initialization state
@@ -133,11 +136,12 @@
return false;
}
- public void close() throws MetaMatrixComponentException {
- if (!isClosed()) {
- super.close();
- plan.close();
- }
+ public void closeDirect() {
+ try {
+ plan.close();
+ } catch (MetaMatrixComponentException e1){
+ LogManager.logDetail(LogConstants.CTX_DQP, e1, "Error closing processor"); //$NON-NLS-1$
+ }
}
protected void getNodeString(StringBuffer str) {
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectIntoNode.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectIntoNode.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectIntoNode.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -191,7 +191,7 @@
tupleSource = getDataManager().registerRequest(this.getContext().getProcessorID(), command, this.modelName, null, getID());
}
- private void closeRequest() throws MetaMatrixComponentException {
+ private void closeRequest() {
if (this.tupleSource != null) {
tupleSource.closeSource();
@@ -253,8 +253,7 @@
return intoGroup.isTempGroupSymbol();
}
- public void close() throws MetaMatrixComponentException {
+ public void closeDirect() {
closeRequest();
- super.close();
}
}
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -252,17 +252,16 @@
* @throws MetaMatrixComponentException
* @since 4.2
*/
- public TupleBatch nextBatch() throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
+ public final TupleBatch nextBatch() throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
boolean recordStats = this.context != null && (this.context.getCollectNodeStatistics() || this.context.getProcessDebug());
- TupleBatch batch = null;
try {
while (true) {
//start timer for this batch
if(recordStats && this.context.getCollectNodeStatistics()) {
this.nodeStatistics.startBatchTimer();
}
- batch = nextBatchDirect();
+ TupleBatch batch = nextBatchDirect();
if (recordStats) {
if(this.context.getCollectNodeStatistics()) {
// stop timer for this batch (normal)
@@ -279,15 +278,17 @@
//there have been several instances in the code that have not correctly accounted for non-terminal zero length batches
//this processing style however against the spirit of batch processing (but was already utilized by Sort and Grouping nodes)
if (batch.getRowCount() != 0 || batch.getTerminationFlag()) {
- break;
+ if (batch.getTerminationFlag()) {
+ close();
+ }
+ return batch;
}
}
- return batch;
} catch (BlockedException e) {
if(recordStats && this.context.getCollectNodeStatistics()) {
// stop timer for this batch (BlockedException)
this.nodeStatistics.stopBatchTimer();
- this.nodeStatistics.collectCumulativeNodeStats(batch, RelationalNodeStatistics.BLOCKEDEXCEPTION_STOP);
+ this.nodeStatistics.collectCumulativeNodeStats(null, RelationalNodeStatistics.BLOCKEDEXCEPTION_STOP);
}
throw e;
} catch (MetaMatrixComponentException e) {
@@ -310,10 +311,11 @@
protected abstract TupleBatch nextBatchDirect()
throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException;
- public void close()
+ public final void close()
throws MetaMatrixComponentException {
if (!this.closed) {
+ closeDirect();
for(int i=0; i<children.length; i++) {
if(children[i] != null) {
children[i].close();
@@ -324,6 +326,10 @@
this.closed = true;
}
}
+
+ public void closeDirect() {
+
+ }
/**
* Check if the node has been already closed
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SortNode.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SortNode.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SortNode.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -126,14 +126,11 @@
return this.pullBatch();
}
- public void close() throws MetaMatrixComponentException {
- if (!isClosed()) {
- super.close();
- if(this.output != null) {
- this.output.remove();
- this.output = null;
- this.outputTs = null;
- }
+ public void closeDirect() {
+ if(this.output != null) {
+ this.output.remove();
+ this.output = null;
+ this.outputTs = null;
}
}
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SortUtility.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SortUtility.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SortUtility.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -36,6 +36,7 @@
import com.metamatrix.common.buffer.IndexedTupleSource;
import com.metamatrix.common.buffer.TupleBuffer;
import com.metamatrix.common.buffer.TupleSource;
+import com.metamatrix.common.buffer.BufferManager.BufferReserveMode;
import com.metamatrix.common.buffer.BufferManager.TupleSourceType;
import com.metamatrix.common.log.LogManager;
import com.metamatrix.core.log.MessageLevel;
@@ -87,6 +88,7 @@
private BufferManager bufferManager;
private String groupName;
private List<SingleElementSymbol> schema;
+ private int schemaSize;
private ListNestedSortComparator comparator;
private TupleBuffer output;
@@ -110,6 +112,7 @@
this.bufferManager = bufferMgr;
this.groupName = groupName;
this.schema = this.source.getSchema();
+ this.schemaSize = bufferManager.getSchemaSize(this.schema);
int distinctIndex = sortElements != null? sortElements.size() - 1:0;
if (mode != Mode.SORT) {
if (sortElements == null) {
@@ -175,26 +178,22 @@
workingTuples = new TreeSet<List<?>>(comparator);
}
}
+
int totalReservedBuffers = 0;
try {
- int maxRows = bufferManager.getMaxProcessingBatches() * bufferManager.getProcessorBatchSize();
+ int maxRows = this.bufferManager.getProcessorBatchSize();
while(!doneReading) {
//attempt to reserve more working memory if there are additional rows available before blocking
- if (workingTuples.size() == maxRows) {
- if (source.available() < 1) {
+ if (workingTuples.size() >= maxRows) {
+ int reserved = bufferManager.reserveBuffers(schemaSize,
+ (totalReservedBuffers + schemaSize <= bufferManager.getMaxProcessingBatchColumns())?BufferReserveMode.FORCE:BufferReserveMode.NO_WAIT);
+ if (reserved != schemaSize) {
break;
- }
- int reserved = bufferManager.reserveBuffers(1, false);
- if (reserved == 0) {
- break;
}
- totalReservedBuffers += 1;
+ totalReservedBuffers += reserved;
maxRows += bufferManager.getProcessorBatchSize();
}
try {
- if (totalReservedBuffers > 0 && source.available() == 0) {
- break;
- }
List<?> tuple = source.nextTuple();
if (tuple == null) {
@@ -205,6 +204,9 @@
this.collected++;
}
} catch(BlockedException e) {
+ if (workingTuples.size() >= bufferManager.getProcessorBatchSize()) {
+ break;
+ }
if (mode != Mode.DUP_REMOVE
|| (this.output != null && collected < this.output.getRowCount() * 2)
|| (this.output == null && this.workingTuples.isEmpty() && this.activeTupleBuffers.isEmpty())) {
@@ -231,7 +233,7 @@
sublist.saveBatch();
} finally {
- bufferManager.releaseBuffers(totalReservedBuffers);
+ bufferManager.releaseBuffers(totalReservedBuffers);
}
}
@@ -248,12 +250,17 @@
TupleBuffer merged = createTupleBuffer();
- int maxSortIndex = Math.min(activeTupleBuffers.size(), this.bufferManager.getMaxProcessingBatches());
- int reservedBuffers = 0;
- if (activeTupleBuffers.size() > maxSortIndex) {
- reservedBuffers = bufferManager.reserveBuffers(activeTupleBuffers.size() - maxSortIndex, true);
+ int desiredSpace = activeTupleBuffers.size() * schemaSize;
+ int reserved = Math.min(desiredSpace, this.bufferManager.getMaxProcessingBatchColumns());
+ bufferManager.reserveBuffers(reserved, BufferReserveMode.FORCE);
+ if (desiredSpace > reserved) {
+ reserved += bufferManager.reserveBuffers(desiredSpace - reserved, BufferReserveMode.WAIT);
}
- maxSortIndex += reservedBuffers;
+ int maxSortIndex = Math.max(2, reserved / schemaSize); //always allow progress
+ //release any partial excess
+ int release = reserved % schemaSize > 0 ? 1 : 0;
+ bufferManager.releaseBuffers(release);
+ reserved -= release;
try {
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.TRACE)) {
LogManager.logTrace(LogConstants.CTX_DQP, "Merging", maxSortIndex, "sublists out of", activeTupleBuffers.size()); //$NON-NLS-1$ //$NON-NLS-2$
@@ -294,16 +301,21 @@
masterSortIndex = this.activeTupleBuffers.size() - 1;
}
} finally {
- this.bufferManager.releaseBuffers(reservedBuffers);
+ this.bufferManager.releaseBuffers(reserved);
}
}
// Close sorted source (all others have been removed)
if (doneReading) {
- activeTupleBuffers.get(0).close();
- activeTupleBuffers.get(0).setForwardOnly(false);
if (this.output != null) {
this.output.close();
+ TupleBuffer last = activeTupleBuffers.remove(0);
+ if (output != last) {
+ last.remove();
+ }
+ } else {
+ activeTupleBuffers.get(0).close();
+ activeTupleBuffers.get(0).setForwardOnly(false);
}
this.phase = DONE;
return;
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SourceState.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SourceState.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SourceState.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -29,6 +29,7 @@
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.common.buffer.IndexedTupleSource;
import com.metamatrix.common.buffer.TupleBuffer;
+import com.metamatrix.common.buffer.TupleSource;
import com.metamatrix.common.buffer.BufferManager.TupleSourceType;
import com.metamatrix.query.processor.BatchCollector;
import com.metamatrix.query.processor.BatchIterator;
@@ -64,6 +65,10 @@
this.expressionIndexes = getExpressionIndecies(expressions, elements);
}
+ public RelationalNode getSource() {
+ return source;
+ }
+
public void setImplicitBuffer(ImplicitBuffer implicitBuffer) {
this.implicitBuffer = implicitBuffer;
}
@@ -101,10 +106,7 @@
this.buffer = null;
}
if (this.iterator != null) {
- try {
- this.iterator.closeSource();
- } catch (MetaMatrixComponentException e) {
- }
+ this.iterator.closeSource();
this.iterator = null;
}
}
@@ -173,9 +175,15 @@
public void sort(SortOption sortOption) throws MetaMatrixComponentException, MetaMatrixProcessingException {
if (sortOption == SortOption.SORT || sortOption == SortOption.SORT_DISTINCT) {
if (this.sortUtility == null) {
- this.sortUtility = new SortUtility(this.buffer != null ? this.buffer.createIndexedTupleSource() : new BatchIterator(this.source),
- expressions, Collections.nCopies(expressions.size(), OrderBy.ASC), sortOption == SortOption.SORT_DISTINCT?Mode.DUP_REMOVE_SORT:Mode.SORT,
- this.source.getBufferManager(), this.source.getConnectionID());
+ TupleSource ts = null;
+ if (this.buffer != null) {
+ this.buffer.setForwardOnly(true);
+ ts = this.buffer.createIndexedTupleSource();
+ } else {
+ ts = new BatchIterator(this.source);
+ }
+ this.sortUtility = new SortUtility(ts, expressions, Collections.nCopies(expressions.size(), OrderBy.ASC),
+ sortOption == SortOption.SORT_DISTINCT?Mode.DUP_REMOVE_SORT:Mode.SORT, this.source.getBufferManager(), this.source.getConnectionID());
this.markDistinct(sortOption == SortOption.SORT_DISTINCT && expressions.size() == this.getOuterVals().size());
}
this.buffer = sortUtility.sort();
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareEvaluator.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareEvaluator.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareEvaluator.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -56,7 +56,7 @@
List<?> tuple;
ProcessorPlan plan;
- void close() throws MetaMatrixComponentException {
+ void close() {
if (processor == null) {
return;
}
@@ -85,7 +85,7 @@
}
}
- public void close() throws MetaMatrixComponentException {
+ public void close() {
for (SubqueryState state : subqueries.values()) {
state.close();
}
@@ -123,9 +123,9 @@
state.collector = state.processor.createBatchCollector();
}
state.done = true;
- state.processor.getProcessorPlan().reset();
+ state.plan.reset();
}
- return new DependentValueSource(state.collector.collectTuples(), this.manager.getProcessorBatchSize() / 2).getValueIterator(ref.getValueExpression());
+ return new DependentValueSource(state.collector.collectTuples()).getValueIterator(ref.getValueExpression());
}
}
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareRelationalNode.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareRelationalNode.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareRelationalNode.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -2,7 +2,6 @@
import java.util.Map;
-import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.query.eval.Evaluator;
public abstract class SubqueryAwareRelationalNode extends RelationalNode {
@@ -31,8 +30,7 @@
}
@Override
- public void close() throws MetaMatrixComponentException {
- super.close();
+ public void closeDirect() {
if (evaluator != null) {
evaluator.close();
}
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/UnionAllNode.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/UnionAllNode.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/processor/relational/UnionAllNode.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -28,13 +28,19 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.common.buffer.BlockedException;
+import com.metamatrix.common.buffer.BufferManager;
import com.metamatrix.common.buffer.TupleBatch;
+import com.metamatrix.common.buffer.BufferManager.BufferReserveMode;
+import com.metamatrix.query.processor.ProcessorDataManager;
+import com.metamatrix.query.util.CommandContext;
public class UnionAllNode extends RelationalNode {
private boolean[] sourceDone;
private int outputRow = 1;
+ private int reserved;
+ private int schemaSize;
public UnionAllNode(int nodeID) {
super(nodeID);
@@ -47,12 +53,21 @@
outputRow = 1;
}
+ @Override
+ public void initialize(CommandContext context, BufferManager bufferManager,
+ ProcessorDataManager dataMgr) {
+ super.initialize(context, bufferManager, dataMgr);
+ this.schemaSize = getBufferManager().getSchemaSize(getOutputElements());
+ }
+
public void open()
throws MetaMatrixComponentException, MetaMatrixProcessingException {
// Initialize done flags
sourceDone = new boolean[getChildren().length];
-
+ if (reserved == 0) {
+ reserved = getBufferManager().reserveBuffers((getChildren().length - 1) * schemaSize, BufferReserveMode.FORCE);
+ }
// Open the children
super.open();
}
@@ -79,6 +94,10 @@
// Mark source as being done and decrement the activeSources counter
sourceDone[i] = true;
activeSources--;
+ if (reserved > 0) {
+ getBufferManager().releaseBuffers(schemaSize);
+ reserved-=schemaSize;
+ }
}
} catch(BlockedException e) {
if(i<children.length-1 && hasDependentProcedureExecutionNode(children[0])){
@@ -122,6 +141,12 @@
return outputBatch;
}
+
+ @Override
+ public void closeDirect() {
+ getBufferManager().releaseBuffers(reserved);
+ reserved = 0;
+ }
public Object clone(){
UnionAllNode clonedNode = new UnionAllNode(super.getID());
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/sql/lang/JoinType.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/sql/lang/JoinType.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/sql/lang/JoinType.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -36,38 +36,40 @@
// Constants defining join type - users will construct these
/** Represents an inner join: a INNER JOIN b */
- public static final JoinType JOIN_INNER = new JoinType(0);
+ public static final JoinType JOIN_INNER = new JoinType(0, false);
/** Represents a right outer join: a RIGHT OUTER JOIN b */
- public static final JoinType JOIN_RIGHT_OUTER = new JoinType(1);
+ public static final JoinType JOIN_RIGHT_OUTER = new JoinType(1, true);
/** Represents a left outer join: a LEFT OUTER JOIN b */
- public static final JoinType JOIN_LEFT_OUTER = new JoinType(2);
+ public static final JoinType JOIN_LEFT_OUTER = new JoinType(2, true);
/** Represents a full outer join: a FULL OUTER JOIN b */
- public static final JoinType JOIN_FULL_OUTER = new JoinType(3);
+ public static final JoinType JOIN_FULL_OUTER = new JoinType(3, true);
/** Represents a cross join: a CROSS JOIN b */
- public static final JoinType JOIN_CROSS = new JoinType(4);
+ public static final JoinType JOIN_CROSS = new JoinType(4, false);
/** Represents a union join: a UNION JOIN b - not used after rewrite */
- public static final JoinType JOIN_UNION = new JoinType(5);
+ public static final JoinType JOIN_UNION = new JoinType(5, true);
/** internal SEMI Join type */
- public static final JoinType JOIN_SEMI = new JoinType(6);
+ public static final JoinType JOIN_SEMI = new JoinType(6, false);
/** internal ANTI SEMI Join type */
- public static final JoinType JOIN_ANTI_SEMI = new JoinType(7);
+ public static final JoinType JOIN_ANTI_SEMI = new JoinType(7, true);
private int type;
+ private boolean outer;
/**
* Construct a join type object. This is private and is only called by
* the static constant objects in this class.
* @param type Type code for object
*/
- private JoinType(int type) {
+ private JoinType(int type, boolean outer) {
this.type = type;
+ this.outer = outer;
}
/**
@@ -97,7 +99,7 @@
* @return True if left/right/full outer, false if inner/cross
*/
public boolean isOuter() {
- return this.equals(JOIN_LEFT_OUTER) || this.equals(JOIN_FULL_OUTER) || this.equals(JOIN_RIGHT_OUTER) || this.equals(JOIN_ANTI_SEMI);
+ return outer;
}
public boolean isSemi() {
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/sql/lang/SetQuery.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/sql/lang/SetQuery.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/sql/lang/SetQuery.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -181,6 +181,10 @@
if(this.getLimit() != null) {
copy.setLimit( (Limit) this.getLimit().clone() );
}
+
+ if (this.projectedTypes != null) {
+ copy.setProjectedTypes(new ArrayList<Class<?>>(projectedTypes), this.metadata);
+ }
return copy;
}
Modified: branches/JCA/engine/src/main/java/com/metamatrix/query/tempdata/TempTableStoreImpl.java
===================================================================
--- branches/JCA/engine/src/main/java/com/metamatrix/query/tempdata/TempTableStoreImpl.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/com/metamatrix/query/tempdata/TempTableStoreImpl.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -77,6 +77,7 @@
private final Criteria crit;
protected int updateCount = 0;
private boolean done;
+ private List<?> currentTuple;
private UpdateTupleSource(String groupKey, TupleBuffer tsId, Criteria crit) throws MetaMatrixComponentException {
this.groupKey = groupKey;
@@ -96,14 +97,14 @@
return null;
}
- List<?> tuple = null;
//still have to worry about blocked exceptions...
- while ((tuple = ts.nextTuple()) != null) {
- if (eval.evaluate(crit, tuple)) {
- tuplePassed(tuple);
+ while (currentTuple != null || (currentTuple = ts.nextTuple()) != null) {
+ if (eval.evaluate(crit, currentTuple)) {
+ tuplePassed(currentTuple);
} else {
- tupleFailed(tuple);
+ tupleFailed(currentTuple);
}
+ currentTuple = null;
}
newBuffer.close();
groupToTupleSourceID.put(groupKey, newBuffer);
@@ -126,7 +127,7 @@
}
@Override
- public void closeSource() throws MetaMatrixComponentException {
+ public void closeSource() {
}
@@ -270,20 +271,12 @@
}
//allow implicit temp group definition
List columns = null;
- switch (command.getType()) {
- case Command.TYPE_QUERY:
- Query query = (Query)command;
- if(query.getInto() != null && query.getInto().getGroup().isImplicitTempGroupSymbol()) {
- columns = query.getSelect().getSymbols();
- }
- break;
- case Command.TYPE_INSERT:
+ if (command instanceof Insert) {
Insert insert = (Insert)command;
GroupSymbol group = insert.getGroup();
if(group.isImplicitTempGroupSymbol()) {
columns = insert.getVariables();
}
- break;
}
if (columns == null) {
throw new QueryProcessingException(QueryExecPlugin.Util.getString("TempTableStore.table_doesnt_exist_error", tempTableID)); //$NON-NLS-1$
Modified: branches/JCA/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItem.java
===================================================================
--- branches/JCA/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItem.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItem.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
import javax.resource.spi.work.WorkEvent;
@@ -102,7 +103,7 @@
protected RequestState requestState = RequestState.NEW;
- private volatile boolean isCancelled;
+ private AtomicBoolean isCancelled = new AtomicBoolean();
private volatile boolean moreRequested;
private volatile boolean closeRequested;
private boolean isClosed;
@@ -191,7 +192,7 @@
}
private void checkForCloseEvent() throws NeedsClosedException {
- if (this.isCancelled || this.closeRequested) {
+ if (this.isCancelled.get() || this.closeRequested) {
throw new NeedsClosedException();
}
}
@@ -232,7 +233,7 @@
manager.logSRCCommand(this.requestMsg, this.securityContext, CommandLogMessage.CMD_STATUS_ERROR, -1);
String msg = DQPPlugin.Util.getString("ConnectorWorker.process_failed", this.id); //$NON-NLS-1$
- if (isCancelled) {
+ if (isCancelled.get()) {
LogManager.logDetail(LogConstants.CTX_CONNECTOR, msg);
} else if (t instanceof ConnectorException || t instanceof MetaMatrixProcessingException) {
LogManager.logWarning(LogConstants.CTX_CONNECTOR, t, msg);
@@ -508,8 +509,7 @@
}
void asynchCancel() throws ConnectorException {
- if (!this.isCancelled) {
- this.isCancelled = true;
+ if (this.isCancelled.compareAndSet(false, true)) {
if(execution != null) {
execution.cancel();
}
@@ -518,7 +518,7 @@
}
boolean isCancelled() {
- return this.isCancelled;
+ return this.isCancelled.get();
}
@Override
Modified: branches/JCA/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/SynchConnectorWorkItem.java
===================================================================
--- branches/JCA/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/SynchConnectorWorkItem.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/SynchConnectorWorkItem.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -71,7 +71,9 @@
@Override
protected void pauseProcessing() {
try {
- this.wait();
+ while (isIdle()) {
+ this.wait();
+ }
} catch (InterruptedException e) {
interrupted(e);
}
Modified: branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/AbstractWorkItem.java
===================================================================
--- branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/AbstractWorkItem.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/AbstractWorkItem.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -54,7 +54,7 @@
}
}
- ThreadState getThreadState() {
+ synchronized ThreadState getThreadState() {
return this.threadState;
}
@@ -87,10 +87,14 @@
}
break;
default:
- throw new IllegalStateException("Should not END on IDLE or DONE"); //$NON-NLS-1$
+ throw new IllegalStateException("Should not END on " + this.threadState); //$NON-NLS-1$
}
}
+ protected boolean isIdle() {
+ return this.threadState == ThreadState.IDLE;
+ }
+
protected void moreWork() {
moreWork(true);
}
Modified: branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/CodeTableCache.java
===================================================================
--- branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/CodeTableCache.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/CodeTableCache.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -37,6 +37,7 @@
import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
import com.metamatrix.dqp.util.LogConstants;
import com.metamatrix.query.util.CommandContext;
+import com.metamatrix.vdb.runtime.VDBKey;
/**
* Code table cache. Heavily synchronized in-memory cache of code tables. There is no purging policy for this cache. Once the limits have been reached exceptions will occur.
@@ -189,32 +190,13 @@
}
return table.codeMap.get(keyValue);
}
-
- /**
- * Places the lookup results in the cache and marks the cache loaded
- * @param requestID
- * @param nodeID
- * @return the set of waiting requests
- * @since 4.2
- */
- public Set<Object> markCacheLoaded(CacheKey requestKey) {
- return markCacheDone(requestKey, false);
- }
-
- /**
- * Notifies the CodeTableCache that this code table had an error. Removes any existing cached results and clears any state
- * for this CacheKey.
- * @param requestID
- * @param nodeID
- * @return the set of waiting requests
- * @since 4.2
- */
- public Set<Object> errorLoadingCache(CacheKey requestKey) {
- return markCacheDone(requestKey, true);
- }
- private synchronized Set<Object> markCacheDone(CacheKey cacheKey, boolean errorOccurred) {
- if (errorOccurred) {
+ /**
+ * Notifies the CodeTableCache that this code is done. If the table had an error, it removes any temporary results.
+ * @return the set of waiting requests
+ */
+ public synchronized Set<Object> markCacheDone(CacheKey cacheKey, boolean success) {
+ if (!success) {
// Remove any results already cached
CodeTable table = codeTableCache.remove(cacheKey);
if (table != null) {
@@ -224,7 +206,7 @@
}
CodeTable table = codeTableCache.get(cacheKey);
if (table == null || table.codeMap == null) {
- return null;
+ return null; //can only happen if cache was cleared between load and now
}
rowCount += table.codeMap.size();
Set<Object> waiting = table.waitingRequests;
@@ -264,8 +246,7 @@
private String codeTable;
private String returnElement;
private String keyElement;
- private String vdbName;
- private int vdbVersion;
+ private VDBKey vdbKey;
private int hashCode;
@@ -273,15 +254,11 @@
this.codeTable = codeTable;
this.returnElement = returnElement;
this.keyElement = keyElement;
- this.vdbName = vdbName;
- this.vdbVersion = vdbVersion;
+ this.vdbKey = new VDBKey(vdbName, vdbVersion);
// Compute hash code and cache it
- hashCode = HashCodeUtil.hashCode(0, codeTable);
- hashCode = HashCodeUtil.hashCode(hashCode, returnElement);
- hashCode = HashCodeUtil.hashCode(hashCode, keyElement);
- hashCode = HashCodeUtil.hashCode(hashCode, vdbName);
- hashCode = HashCodeUtil.hashCode(hashCode, vdbVersion);
+ hashCode = HashCodeUtil.hashCode(codeTable.toUpperCase().hashCode(), returnElement.toUpperCase(),
+ keyElement.toUpperCase(), vdbKey);
}
public String getCodeTable() {
@@ -304,11 +281,10 @@
CacheKey other = (CacheKey) obj;
return (other.hashCode() == hashCode() &&
- this.codeTable.equals(other.codeTable) &&
- this.returnElement.equals(other.returnElement) &&
- this.keyElement.equals(other.keyElement) &&
- this.vdbName.equals(other.vdbName) &&
- this.vdbVersion ==other.vdbVersion);
+ this.codeTable.equalsIgnoreCase(other.codeTable) &&
+ this.returnElement.equalsIgnoreCase(other.returnElement) &&
+ this.keyElement.equalsIgnoreCase(other.keyElement) &&
+ this.vdbKey.equals(other.vdbKey));
}
return false;
}
Modified: branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java
===================================================================
--- branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -440,12 +440,7 @@
}
success = true;
} finally {
- Collection requests = null;
- if (success) {
- requests = codeTableCache.markCacheLoaded(codeRequestId);
- } else {
- requests = codeTableCache.errorLoadingCache(codeRequestId);
- }
+ Collection requests = codeTableCache.markCacheDone(codeRequestId, success);
notifyWaitingCodeTableRequests(requests);
}
}
Modified: branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java
===================================================================
--- branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -148,7 +148,7 @@
}
}
- public void fullyCloseSource() throws MetaMatrixComponentException {
+ public void fullyCloseSource() {
this.dataMgr.closeRequest(aqr.getAtomicRequestID(), this.connectorName);
}
@@ -159,7 +159,7 @@
/**
* @see TupleSource#closeSource()
*/
- public void closeSource() throws MetaMatrixComponentException {
+ public void closeSource() {
if (this.supportsImplicitClose) {
this.dataMgr.closeRequest(aqr.getAtomicRequestID(), this.connectorName);
}
Modified: branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -273,14 +273,8 @@
protected void attemptClose() {
int rowcount = -1;
if (this.resultsBuffer != null) {
- try {
- if (this.processor != null) {
- this.processor.closeProcessing();
- }
- } catch (MetaMatrixComponentException e) {
- if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
- LogManager.logDetail(LogConstants.CTX_DQP, e, e.getMessage());
- }
+ if (this.processor != null) {
+ this.processor.closeProcessing();
}
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
@@ -301,13 +295,7 @@
}
for (DataTierTupleSource connectorRequest : this.connectorInfo.values()) {
- try {
- connectorRequest.fullyCloseSource();
- } catch (MetaMatrixComponentException e) {
- if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
- LogManager.logDetail(LogConstants.CTX_DQP, e, e.getMessage());
- }
- }
+ connectorRequest.fullyCloseSource();
}
this.resultsBuffer = null;
@@ -374,16 +362,16 @@
if (this.transactionContext != null && this.transactionContext.getXid() != null) {
this.transactionState = TransactionState.ACTIVE;
}
+ if (analysisRecord.recordQueryPlan()) {
+ analysisRecord.setQueryPlan(processor.getProcessorPlan().getDescriptionProperties());
+ }
Option option = originalCommand.getOption();
if (option != null && option.getPlanOnly()) {
doneProducingBatches = true;
resultsBuffer.close();
this.cid = null;
+ this.processor = null;
}
-
- if (analysisRecord.recordQueryPlan()) {
- analysisRecord.setQueryPlan(processor.getProcessorPlan().getDescriptionProperties());
- }
this.returnsUpdateCount = request.returnsUpdateCount;
request = null;
}
Modified: branches/JCA/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
===================================================================
--- branches/JCA/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -40,6 +40,7 @@
import com.metamatrix.api.exception.query.QueryPlannerException;
import com.metamatrix.api.exception.query.QueryResolverException;
import com.metamatrix.api.exception.query.QueryValidatorException;
+import com.metamatrix.common.buffer.BufferManager;
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.core.MetaMatrixRuntimeException;
import com.metamatrix.query.analysis.AnalysisRecord;
@@ -3361,11 +3362,11 @@
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 500));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE / 4));
FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE));
FakeMetadataObject g3 = metadata.getStore().findObject("pm1.g3", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g3.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
+ g3.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE));
ProcessorPlan plan = helpPlan(sql, metadata,
null, capFinder,
Modified: branches/JCA/engine/src/test/java/com/metamatrix/query/optimizer/TestPartitionedJoinPlanning.java
===================================================================
--- branches/JCA/engine/src/test/java/com/metamatrix/query/optimizer/TestPartitionedJoinPlanning.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/test/java/com/metamatrix/query/optimizer/TestPartitionedJoinPlanning.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -27,6 +27,7 @@
import org.junit.Test;
+import com.metamatrix.common.buffer.BufferManager;
import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
@@ -47,13 +48,14 @@
caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+ caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, 100);
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, 600);
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE);
FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, 3000);
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE * 16);
ProcessorPlan plan = helpPlan(sql, metadata,
null, capFinder,
Modified: branches/JCA/engine/src/test/java/com/metamatrix/query/processor/FakeTupleSource.java
===================================================================
--- branches/JCA/engine/src/test/java/com/metamatrix/query/processor/FakeTupleSource.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/test/java/com/metamatrix/query/processor/FakeTupleSource.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -105,11 +105,7 @@
return null;
}
- public void closeSource()
- throws MetaMatrixComponentException {
- if (exceptionOnClose) {
- throw new FakeComponentException();
- }
+ public void closeSource() {
}
public void setBlockOnce(){
Modified: branches/JCA/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
===================================================================
--- branches/JCA/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -7573,6 +7573,20 @@
helpProcess(plan, dataManager, expected);
}
+
+ @Test public void testImplicitAggregateWithInlineView() {
+ String sql = "SELECT * FROM (SELECT b.count, enterprise_id FROM (SELECT COUNT(*), 2 AS enterprise_id FROM (SELECT 'A Name' AS Name, 1 AS enterprise_id) c ) b ) a WHERE enterprise_id = 1"; //$NON-NLS-1$
+
+ List[] expected = new List[] {};
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+
+ helpProcess(plan, dataManager, expected);
+ }
+
private static final boolean DEBUG = false;
}
Modified: branches/JCA/engine/src/test/java/com/metamatrix/query/processor/relational/TestBatchedUpdateNode.java
===================================================================
--- branches/JCA/engine/src/test/java/com/metamatrix/query/processor/relational/TestBatchedUpdateNode.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/test/java/com/metamatrix/query/processor/relational/TestBatchedUpdateNode.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -231,7 +231,7 @@
private FakeTupleSource(int numCommands) {
this.numCommands = numCommands;
}
- public void closeSource() throws MetaMatrixComponentException {}
+ public void closeSource() {}
public List getSchema() {return null;}
public List nextTuple() throws MetaMatrixComponentException {
if (first) {
Modified: branches/JCA/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectIntoNode.java
===================================================================
--- branches/JCA/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectIntoNode.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectIntoNode.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -36,7 +36,6 @@
import com.metamatrix.common.buffer.TupleSource;
import com.metamatrix.query.processor.FakeTupleSource;
import com.metamatrix.query.processor.ProcessorDataManager;
-import com.metamatrix.query.processor.FakeTupleSource.FakeComponentException;
import com.metamatrix.query.sql.lang.BatchedUpdateCommand;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.Insert;
@@ -120,24 +119,6 @@
helpTestNextBatch(20, true, false, false);
}
- public void testNextBatch_ExceptionOnClose() throws Exception {
- try {
- helpTestNextBatch(100, true, false, true);
- fail("expected exception"); //$NON-NLS-1$
- } catch (FakeComponentException e) {
- //expected
- }
- }
-
- public void testNextBatch_ExceptionOnClose1() throws Exception {
- try {
- helpTestNextBatch(100, false, false, true);
- fail("expected exception"); //$NON-NLS-1$
- } catch (FakeComponentException e) {
- //expected
- }
- }
-
private static final class FakePDM implements ProcessorDataManager {
private int expectedBatchSize;
private int callCount = 0;
@@ -205,7 +186,7 @@
private FakeDataTupleSource(int rows) {
this.rows = rows;
}
- public void closeSource() throws MetaMatrixComponentException {}
+ public void closeSource() {}
public List getSchema() {return null;}
public List nextTuple() throws MetaMatrixComponentException {
if (currentRow % 100 == 0 && block) {
Modified: branches/JCA/engine/src/test/java/com/metamatrix/query/processor/xml/TestXMLPlanningEnhancements.java
===================================================================
--- branches/JCA/engine/src/test/java/com/metamatrix/query/processor/xml/TestXMLPlanningEnhancements.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/test/java/com/metamatrix/query/processor/xml/TestXMLPlanningEnhancements.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -28,6 +28,7 @@
import junit.framework.TestCase;
+import com.metamatrix.common.buffer.BufferManager;
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.dqp.message.ParameterInfo;
import com.metamatrix.query.mapping.relational.QueryNode;
@@ -36,6 +37,7 @@
import com.metamatrix.query.mapping.xml.MappingElement;
import com.metamatrix.query.mapping.xml.MappingNode;
import com.metamatrix.query.optimizer.TestOptimizer;
+import com.metamatrix.query.optimizer.relational.rules.RuleChooseDependent;
import com.metamatrix.query.processor.FakeDataManager;
import com.metamatrix.query.processor.ProcessorPlan;
import com.metamatrix.query.unittest.FakeMetadataFacade;
@@ -483,8 +485,8 @@
FakeMetadataObject suppliers = metadata.getStore().findObject("stock.suppliers", FakeMetadataObject.GROUP); //$NON-NLS-1$
// supply the costing information for OrdersC
- orders.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(1000));
- suppliers.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(10));
+ orders.putProperty(FakeMetadataObject.Props.CARDINALITY, BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE - 1);
+ suppliers.putProperty(FakeMetadataObject.Props.CARDINALITY, RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY);
String expectedDoc = TestXMLProcessor.readFile("TestXMLProcessor-FullSuppliers.xml"); //$NON-NLS-1$
Modified: branches/JCA/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java
===================================================================
--- branches/JCA/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -2085,6 +2085,16 @@
assertEquals(DataTypeManager.DefaultDataClasses.INTEGER, ((SingleElementSymbol)command.getProjectedSymbols().get(0)).getType());
}
+ @Test public void testUnionQueryClone() throws Exception{
+ SetQuery command = (SetQuery)helpResolve("SELECT e2, e3 FROM pm1.g1 UNION SELECT e3, e2 from pm1.g1"); //$NON-NLS-1$
+
+ assertEquals(DataTypeManager.DefaultDataClasses.INTEGER, ((SingleElementSymbol)command.getProjectedSymbols().get(1)).getType());
+
+ command = (SetQuery)command.clone();
+
+ assertEquals(DataTypeManager.DefaultDataClasses.INTEGER, ((SingleElementSymbol)command.getProjectedSymbols().get(1)).getType());
+ }
+
@Test public void testSelectIntoNoFrom() {
helpResolve("SELECT 'a', 19, {b'true'}, 13.999 INTO pm1.g1"); //$NON-NLS-1$
}
Modified: branches/JCA/engine/src/test/java/org/teiid/dqp/internal/process/TestCodeTableCache.java
===================================================================
--- branches/JCA/engine/src/test/java/org/teiid/dqp/internal/process/TestCodeTableCache.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/engine/src/test/java/org/teiid/dqp/internal/process/TestCodeTableCache.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -73,11 +73,7 @@
} catch (MetaMatrixProcessingException e) {
throw new RuntimeException(e);
}
- if(setDone) {
- ctc.markCacheLoaded(nodeId);
- } else {
- ctc.errorLoadingCache(nodeId);
- }
+ ctc.markCacheDone(nodeId, setDone);
return ctc;
}
@@ -98,7 +94,7 @@
} catch (MetaMatrixProcessingException e) {
throw new RuntimeException(e);
}
- ctc.markCacheLoaded(nodeId);
+ ctc.markCacheDone(nodeId, true);
return ctc;
}
@@ -115,6 +111,10 @@
CacheState actualState = ctc.cacheExists("countrycode", "code", "country", TEST_CONTEXT); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertEquals("Actual cache state doesn't match with expected: ", CacheState.CACHE_EXISTS, actualState); //$NON-NLS-1$
+
+ //test case insensitive
+ actualState = ctc.cacheExists("countryCODE", "code", "Country", TEST_CONTEXT); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertEquals("Actual cache state doesn't match with expected: ", CacheState.CACHE_EXISTS, actualState); //$NON-NLS-1$
}
/** state = 1; loading state */
Modified: branches/JCA/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java
===================================================================
--- branches/JCA/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -45,6 +45,8 @@
* for file service access.
*/
public class BufferServiceImpl implements BufferService, Serializable {
+ private static final long serialVersionUID = -6217808623863643531L;
+
private static final int DEFAULT_MAX_OPEN_FILES = 256;
// Instance
@@ -58,8 +60,8 @@
private CacheFactory cacheFactory;
private int maxOpenFiles = DEFAULT_MAX_OPEN_FILES;
private long maxFileSize = 2L; // 2GB
- private int maxProcessingBatches = BufferManager.DEFAULT_MAX_PROCESSING_BATCHES;
- private int maxReserveBatches = BufferManager.DEFAULT_RESERVE_BUFFERS;
+ private int maxProcessingBatchesColumns = BufferManager.DEFAULT_MAX_PROCESSING_BATCHES;
+ private int maxReserveBatchColumns = BufferManager.DEFAULT_RESERVE_BUFFERS;
/**
* Clean the file storage directory on startup
@@ -82,8 +84,8 @@
this.bufferMgr = new BufferManagerImpl();
this.bufferMgr.setConnectorBatchSize(Integer.valueOf(connectorBatchSize));
this.bufferMgr.setProcessorBatchSize(Integer.valueOf(processorBatchSize));
- this.bufferMgr.setMaxReserveBatches(maxReserveBatches);
- this.bufferMgr.setMaxProcessingBatches(maxProcessingBatches);
+ this.bufferMgr.setMaxReserveBatchColumns(this.maxReserveBatchColumns);
+ this.bufferMgr.setMaxProcessingBatchColumns(this.maxProcessingBatchesColumns);
this.bufferMgr.initialize();
@@ -193,11 +195,11 @@
this.maxOpenFiles = maxOpenFiles;
}
- public void setMaxProcessingBatches(int maxProcessingBatches) {
- this.maxProcessingBatches = maxProcessingBatches;
+ public void setMaxReserveBatchColumns(int value) {
+ this.maxReserveBatchColumns = value;
}
- public void setMaxReserveBatches(int maxReserveBatches) {
- this.maxReserveBatches = maxReserveBatches;
- }
+ public void setMaxProcessingBatchesColumns(int value) {
+ this.maxProcessingBatchesColumns = value;
+ }
}
Modified: branches/JCA/test-integration/common/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java
===================================================================
--- branches/JCA/test-integration/common/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java 2010-02-18 20:12:13 UTC (rev 1841)
+++ branches/JCA/test-integration/common/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java 2010-02-18 20:18:35 UTC (rev 1842)
@@ -432,5 +432,14 @@
input,
output, TRANSLATOR);
}
+
+ @Test public void testNestedSetQuery3() throws Exception {
+ String input = "select part_id id FROM parts UNION (select part_name FROM parts Union ALL select part_id FROM parts)"; //$NON-NLS-1$
+ String output = "SELECT rtrim(PARTS.PART_ID) AS id FROM PARTS UNION SELECT PARTS.PART_NAME FROM PARTS UNION SELECT rtrim(PARTS.PART_ID) FROM PARTS"; //$NON-NLS-1$
+
+ TranslationHelper.helpTestVisitor(TranslationHelper.PARTS_VDB,
+ input,
+ output, TRANSLATOR);
+ }
}
13 years, 9 months
teiid SVN: r1841 - in trunk: connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase and 20 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-02-18 15:12:13 -0500 (Thu, 18 Feb 2010)
New Revision: 1841
Added:
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/OrderByItem.java
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/access/TestAccessSQLTranslator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/AliasGenerator.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanHints.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinRegion.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleMergeVirtual.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanSorts.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseNull.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/xml/XMLPlanner.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AbstractAssignmentInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/resolver/command/SetQueryResolver.java
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
trunk/engine/src/main/java/com/metamatrix/query/sql/LanguageObject.java
trunk/engine/src/main/java/com/metamatrix/query/sql/LanguageVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/OrderBy.java
trunk/engine/src/main/java/com/metamatrix/query/sql/navigator/PreOrPostOrderNavigator.java
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/language/LanguageBridgeFactory.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestAliasGenerator.java
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestOrderByRewrite.java
Log:
TEIID-989 cleaning up the handling of unrelated order by items. also introduced an order by item class into the engine.
Modified: trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java
===================================================================
--- trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -821,7 +821,7 @@
buffer.append(SQLReservedWords.SPACE);
append(obj.getOrderBy());
}
- if (obj.getLimit() != null) {
+ if (!useSelectLimit() && obj.getLimit() != null) {
buffer.append(SQLReservedWords.SPACE);
append(obj.getLimit());
}
@@ -860,12 +860,16 @@
visitSelect(obj, null);
}
- private void visitSelect(ISelect obj, ICommand command) {
+ private void visitSelect(ISelect obj, IQuery command) {
buffer.append(SQLReservedWords.SELECT).append(SQLReservedWords.SPACE);
buffer.append(getSourceComment(command));
if (obj.isDistinct()) {
buffer.append(SQLReservedWords.DISTINCT).append(SQLReservedWords.SPACE);
}
+ if (useSelectLimit() && command.getLimit() != null) {
+ append(command.getLimit());
+ buffer.append(SQLReservedWords.SPACE);
+ }
append(obj.getSelectSymbols());
}
@@ -1038,4 +1042,8 @@
protected boolean useParensForJoins() {
return false;
}
+
+ protected boolean useSelectLimit() {
+ return false;
+ }
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseSQLTranslator.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseSQLTranslator.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -43,7 +43,7 @@
import org.teiid.connector.language.IFunction;
import org.teiid.connector.language.ILimit;
import org.teiid.connector.language.IOrderBy;
-import org.teiid.connector.language.IQueryCommand;
+import org.teiid.connector.language.ISetQuery;
/**
@@ -166,12 +166,15 @@
return 3;
}
+ /**
+ * SetQueries don't have a concept of TOP, an inline view is needed.
+ */
@Override
public List<?> translateCommand(ICommand command, ExecutionContext context) {
- if (!(command instanceof IQueryCommand)) {
+ if (!(command instanceof ISetQuery)) {
return null;
}
- IQueryCommand queryCommand = (IQueryCommand)command;
+ ISetQuery queryCommand = (ISetQuery)command;
if (queryCommand.getLimit() == null) {
return null;
}
@@ -180,8 +183,8 @@
queryCommand.setLimit(null);
queryCommand.setOrderBy(null);
List<Object> parts = new ArrayList<Object>(6);
- parts.add("SELECT TOP "); //$NON-NLS-1$
- parts.add(limit.getRowLimit());
+ parts.add("SELECT "); //$NON-NLS-1$
+ parts.addAll(translateLimit(limit, context));
parts.add(" * FROM ("); //$NON-NLS-1$
parts.add(queryCommand);
parts.add(") AS X"); //$NON-NLS-1$
@@ -192,7 +195,18 @@
return parts;
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<?> translateLimit(ILimit limit, ExecutionContext context) {
+ return Arrays.asList("TOP ", limit.getRowLimit()); //$NON-NLS-1$
+ }
+
@Override
+ public boolean useSelectLimit() {
+ return true;
+ }
+
+ @Override
public Class<? extends ConnectorCapabilities> getDefaultCapabilities() {
return SybaseCapabilities.class;
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -374,4 +374,8 @@
return translator.useParensForJoins();
}
+ protected boolean useSelectLimit() {
+ return translator.useSelectLimit();
+ }
+
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -839,4 +839,12 @@
return false;
}
+ /**
+ *
+ * @return true if the limit clause is part of the select
+ */
+ public boolean useSelectLimit() {
+ return false;
+ }
+
}
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/access/TestAccessSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/access/TestAccessSQLTranslator.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/access/TestAccessSQLTranslator.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -66,7 +66,7 @@
public void testRowLimit() throws Exception {
String input = "select intkey from bqt1.smalla limit 100"; //$NON-NLS-1$
- String output = "SELECT TOP 100 * FROM (SELECT SmallA.IntKey FROM SmallA) AS X"; //$NON-NLS-1$
+ String output = "SELECT TOP 100 SmallA.IntKey FROM SmallA"; //$NON-NLS-1$
helpTestVisitor(
input,
@@ -76,7 +76,7 @@
public void testRowLimit1() throws Exception {
String input = "select distinct intkey from bqt1.smalla limit 100"; //$NON-NLS-1$
- String output = "SELECT TOP 100 * FROM (SELECT DISTINCT SmallA.IntKey FROM SmallA) AS X"; //$NON-NLS-1$
+ String output = "SELECT DISTINCT TOP 100 SmallA.IntKey FROM SmallA"; //$NON-NLS-1$
helpTestVisitor(
input,
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -335,8 +335,8 @@
}
@Test public void testBooleanToString() throws Exception {
- String input = "SELECT convert(INTKEY, boolean) FROM BQT1.SmallA ORDER BY INTKEY"; //$NON-NLS-1$
- String output = "SELECT CASE WHEN SmallA.IntKey = 0 THEN 0 WHEN SmallA.IntKey IS NOT NULL THEN 1 END FROM SmallA ORDER BY INTKEY"; //$NON-NLS-1$
+ String input = "SELECT convert(INTKEY, boolean) FROM BQT1.SmallA"; //$NON-NLS-1$
+ String output = "SELECT CASE WHEN SmallA.IntKey = 0 THEN 0 WHEN SmallA.IntKey IS NOT NULL THEN 1 END FROM SmallA"; //$NON-NLS-1$
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB,
input,
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -96,7 +96,7 @@
@Test
public void testRowLimit() throws Exception {
String input = "select intkey from bqt1.smalla limit 100"; //$NON-NLS-1$
- String output = "SELECT TOP 100 * FROM (SELECT SmallA.IntKey FROM SmallA) AS X"; //$NON-NLS-1$
+ String output = "SELECT TOP 100 SmallA.IntKey FROM SmallA"; //$NON-NLS-1$
helpTestVisitor(getBQTVDB(),
input,
@@ -113,6 +113,15 @@
output);
}
+ @Test public void testLimitWithOrderByUnrelated() throws Exception {
+ String input = "select intkey from bqt1.smalla order by intnum limit 100"; //$NON-NLS-1$
+ String output = "SELECT TOP 100 SmallA.IntKey FROM SmallA ORDER BY SmallA.IntNum"; //$NON-NLS-1$
+
+ helpTestVisitor(getBQTVDB(),
+ input,
+ output);
+ }
+
@Test
public void testDateFunctions() throws Exception {
String input = "select dayName(timestampValue), dayOfWeek(timestampValue), quarter(timestampValue) from bqt1.smalla"; //$NON-NLS-1$
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/AliasGenerator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/AliasGenerator.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/AliasGenerator.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -343,7 +343,7 @@
if (needsAlias) {
element = new AliasSymbol(element.getShortName(), (SingleElementSymbol)expr);
- obj.getVariables().set(i, element);
+ obj.getOrderByItems().get(i).setSymbol(element);
}
element.setOutputName(name);
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanHints.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanHints.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanHints.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -34,9 +34,6 @@
// This flag indicates that the plan has a virtual group somewhere
public boolean hasVirtualGroups = false;
- // This flag indicates that the plan has a sort somewhere
- public boolean hasSort = false;
-
// flag indicates that the plan has a union somewhere
public boolean hasSetQuery = false;
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -74,6 +74,7 @@
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.Insert;
import com.metamatrix.query.sql.lang.JoinType;
+import com.metamatrix.query.sql.lang.OrderBy;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.StoredProcedure;
import com.metamatrix.query.sql.lang.SetQuery.Operation;
@@ -321,11 +322,10 @@
case NodeConstants.Types.SORT:
case NodeConstants.Types.DUP_REMOVE:
SortNode sortNode = new SortNode(getID());
-
- List elements = (List) node.getProperty(NodeConstants.Info.SORT_ORDER);
- List sortTypes = (List) node.getProperty(NodeConstants.Info.ORDER_TYPES);
-
- sortNode.setSortElements(elements, sortTypes);
+ OrderBy orderBy = (OrderBy) node.getProperty(NodeConstants.Info.SORT_ORDER);
+ if (orderBy != null) {
+ sortNode.setSortElements(orderBy.getSortKeys(), orderBy.getTypes());
+ }
if (node.getType() == NodeConstants.Types.DUP_REMOVE) {
sortNode.setMode(Mode.DUP_REMOVE);
} else if (node.hasBooleanProperty(NodeConstants.Info.IS_DUP_REMOVAL)) {
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -65,6 +65,7 @@
import com.metamatrix.query.resolver.QueryResolver;
import com.metamatrix.query.resolver.util.BindVariableVisitor;
import com.metamatrix.query.rewriter.QueryRewriter;
+import com.metamatrix.query.sql.LanguageObject.Util;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.From;
@@ -156,7 +157,7 @@
connectSubqueryContainers(plan); //TODO: merge with node creation
// Set top column information on top node
- List<SingleElementSymbol> topCols = QueryRewriter.deepClone(command.getProjectedSymbols(), SingleElementSymbol.class);
+ List<SingleElementSymbol> topCols = Util.deepClone(command.getProjectedSymbols());
// Build rule set based on hints
RuleStack rules = RelationalPlanner.buildRules(hints);
@@ -530,7 +531,6 @@
if(command.getOrderBy() != null) {
node = attachSorting(node, command.getOrderBy());
- hints.hasSort = true;
}
if (command.getLimit() != null) {
@@ -786,8 +786,7 @@
private static PlanNode attachSorting(PlanNode plan, OrderBy orderBy) {
PlanNode sortNode = NodeFactory.getNewNode(NodeConstants.Types.SORT);
- sortNode.setProperty(NodeConstants.Info.SORT_ORDER, orderBy.getVariables());
- sortNode.setProperty(NodeConstants.Info.ORDER_TYPES, orderBy.getTypes());
+ sortNode.setProperty(NodeConstants.Info.SORT_ORDER, orderBy);
if (orderBy.hasUnrelated()) {
sortNode.setProperty(Info.UNRELATED_SORT, true);
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -108,8 +108,7 @@
IS_DEPENDENT_SET, // Boolean - only used with dependent joins
// Sort node properties
- ORDER_TYPES, // List <Boolean>
- SORT_ORDER, // List <SingleElementSymbol>
+ SORT_ORDER, // OrderBy
UNRELATED_SORT, // Boolean
IS_DUP_REMOVAL, // Boolean
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -235,10 +235,8 @@
convertAccessPatterns(symbolMap, node);
} else if(type == NodeConstants.Types.SORT) {
- List<SingleElementSymbol> sortCols = (List<SingleElementSymbol>)node.getProperty(NodeConstants.Info.SORT_ORDER);
- OrderBy orderBy = new OrderBy(sortCols);
+ OrderBy orderBy = (OrderBy)node.getProperty(NodeConstants.Info.SORT_ORDER);
ExpressionMappingVisitor.mapExpressions(orderBy, symbolMap);
- node.setProperty(NodeConstants.Info.SORT_ORDER, orderBy.getVariables());
if (!singleMapping) {
GroupsUsedByElementsVisitor.getGroups(orderBy, groups);
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinRegion.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinRegion.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinRegion.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -52,7 +52,7 @@
import com.metamatrix.query.sql.visitor.GroupsUsedByElementsVisitor;
/**
- * A join region is a set of cross and inner joins whose ordering is completely interchangable.
+ * A join region is a set of cross and inner joins whose ordering is completely interchangeable.
*
* It can be conceptually thought of as:
* Criteria node some combination of groups A, B, C
@@ -73,30 +73,30 @@
public static final int UNKNOWN_TUPLE_EST = 100000;
- private LinkedHashMap dependentJoinSourceNodes = new LinkedHashMap();
- private LinkedHashMap joinSourceNodes = new LinkedHashMap();
+ private LinkedHashMap<PlanNode, PlanNode> dependentJoinSourceNodes = new LinkedHashMap<PlanNode, PlanNode>();
+ private LinkedHashMap<PlanNode, PlanNode> joinSourceNodes = new LinkedHashMap<PlanNode, PlanNode>();
- private List dependentCritieraNodes = new ArrayList();
- private List criteriaNodes = new ArrayList();
+ private List<PlanNode> dependentCritieraNodes = new ArrayList<PlanNode>();
+ private List<PlanNode> criteriaNodes = new ArrayList<PlanNode>();
- private List unsatisfiedAccessPatterns = new LinkedList();
+ private List<Collection<AccessPattern>> unsatisfiedAccessPatterns = new LinkedList<Collection<AccessPattern>>();
private Map<ElementSymbol, Set<Collection<GroupSymbol>>> dependentCriteriaElements;
- private Map critieriaToSourceMap;
+ private Map<PlanNode, Set<PlanNode>> critieriaToSourceMap;
public PlanNode getJoinRoot() {
return joinRoot;
}
- public List getUnsatisfiedAccessPatterns() {
+ public List<Collection<AccessPattern>> getUnsatisfiedAccessPatterns() {
return unsatisfiedAccessPatterns;
}
- public Map getJoinSourceNodes() {
+ public Map<PlanNode, PlanNode> getJoinSourceNodes() {
return joinSourceNodes;
}
- public Map getDependentJoinSourceNodes() {
+ public Map<PlanNode, PlanNode> getDependentJoinSourceNodes() {
return dependentJoinSourceNodes;
}
@@ -104,7 +104,7 @@
return criteriaNodes;
}
- public List getDependentCriteriaNodes() {
+ public List<PlanNode> getDependentCriteriaNodes() {
return dependentCritieraNodes;
}
@@ -112,7 +112,7 @@
return this.dependentCriteriaElements;
}
- public Map getCritieriaToSourceMap() {
+ public Map<PlanNode, Set<PlanNode>> getCritieriaToSourceMap() {
return this.critieriaToSourceMap;
}
@@ -122,7 +122,7 @@
root = root.getParent();
}
if (sourceNode.hasCollectionProperty(NodeConstants.Info.ACCESS_PATTERNS)) {
- Collection aps = (Collection)sourceNode.getProperty(NodeConstants.Info.ACCESS_PATTERNS);
+ Collection<AccessPattern> aps = (Collection<AccessPattern>)sourceNode.getProperty(NodeConstants.Info.ACCESS_PATTERNS);
unsatisfiedAccessPatterns.add(aps);
dependentJoinSourceNodes.put(sourceNode, root);
} else {
@@ -146,12 +146,11 @@
}
}
- public void addJoinCriteriaList(List joinCriteria) {
+ public void addJoinCriteriaList(List<? extends Criteria> joinCriteria) {
if (joinCriteria == null || joinCriteria.isEmpty()) {
return;
}
- for (Iterator i = joinCriteria.iterator(); i.hasNext();) {
- Criteria crit = (Criteria)i.next();
+ for (Criteria crit : joinCriteria) {
criteriaNodes.add(RelationalPlanner.createSelectNode(crit, false));
}
}
@@ -167,20 +166,19 @@
*
*/
public void reconstructJoinRegoin() {
- LinkedHashMap combined = new LinkedHashMap(joinSourceNodes);
+ LinkedHashMap<PlanNode, PlanNode> combined = new LinkedHashMap<PlanNode, PlanNode>(joinSourceNodes);
combined.putAll(dependentJoinSourceNodes);
PlanNode root = null;
if (combined.size() < 2) {
- root = (PlanNode)combined.values().iterator().next();
+ root = combined.values().iterator().next();
root.removeProperty(NodeConstants.Info.EST_CARDINALITY);
} else {
root = RulePlanJoins.createJoinNode();
- for (Iterator i = combined.entrySet().iterator(); i.hasNext();) {
- Map.Entry entry = (Map.Entry)i.next();
- PlanNode joinSourceRoot = (PlanNode)entry.getValue();
+ for (Map.Entry<PlanNode, PlanNode> entry : combined.entrySet()) {
+ PlanNode joinSourceRoot = entry.getValue();
joinSourceRoot.removeProperty(NodeConstants.Info.EST_CARDINALITY);
if (root.getChildCount() == 2) {
PlanNode parentJoin = RulePlanJoins.createJoinNode();
@@ -189,10 +187,10 @@
root = parentJoin;
}
root.addLastChild(joinSourceRoot);
- root.addGroups(((PlanNode)entry.getKey()).getGroups());
+ root.addGroups(entry.getKey().getGroups());
}
}
- LinkedList criteria = new LinkedList(dependentCritieraNodes);
+ LinkedList<PlanNode> criteria = new LinkedList<PlanNode>(dependentCritieraNodes);
criteria.addAll(criteriaNodes);
PlanNode parent = this.joinRoot.getParent();
@@ -201,9 +199,7 @@
parent.removeChild(joinRoot);
- for (Iterator i = criteria.iterator(); i.hasNext();) {
- PlanNode critNode = (PlanNode)i.next();
-
+ for (PlanNode critNode : criteria) {
critNode.removeFromParent();
critNode.removeAllChildren();
critNode.addFirstChild(root);
@@ -229,24 +225,24 @@
* @return
*/
public double scoreRegion(Object[] joinOrder, QueryMetadataInterface metadata) {
- List joinSourceEntries = new ArrayList(joinSourceNodes.entrySet());
+ List<Map.Entry<PlanNode, PlanNode>> joinSourceEntries = new ArrayList<Map.Entry<PlanNode, PlanNode>>(joinSourceNodes.entrySet());
double totalIntermediatCost = 0;
double cost = 1;
- HashSet criteria = new HashSet(this.criteriaNodes);
- HashSet groups = new HashSet(this.joinSourceNodes.size());
+ HashSet<PlanNode> criteria = new HashSet<PlanNode>(this.criteriaNodes);
+ HashSet<GroupSymbol> groups = new HashSet<GroupSymbol>(this.joinSourceNodes.size());
for (int i = 0; i < joinOrder.length; i++) {
Integer source = (Integer)joinOrder[i];
- Map.Entry entry = (Map.Entry)joinSourceEntries.get(source.intValue());
- PlanNode joinSourceRoot = (PlanNode)entry.getValue();
+ Map.Entry<PlanNode, PlanNode> entry = joinSourceEntries.get(source.intValue());
+ PlanNode joinSourceRoot = entry.getValue();
//check to make sure that this group ordering satisfies the access patterns
if (!this.unsatisfiedAccessPatterns.isEmpty()) {
- PlanNode joinSource = (PlanNode)entry.getKey();
+ PlanNode joinSource = entry.getKey();
- Collection requiredGroups = (Collection)joinSource.getProperty(NodeConstants.Info.REQUIRED_ACCESS_PATTERN_GROUPS);
+ Collection<GroupSymbol> requiredGroups = (Collection<GroupSymbol>)joinSource.getProperty(NodeConstants.Info.REQUIRED_ACCESS_PATTERN_GROUPS);
if (requiredGroups != null && !groups.containsAll(requiredGroups)) {
return Double.MAX_VALUE;
@@ -266,11 +262,9 @@
cost *= sourceCost;
if (!criteria.isEmpty() && i > 0) {
- List applicableCriteria = getJoinCriteriaForGroups(groups, criteria);
+ List<PlanNode> applicableCriteria = getJoinCriteriaForGroups(groups, criteria);
- for (Iterator j = applicableCriteria.iterator(); j.hasNext();) {
- PlanNode criteriaNode = (PlanNode)j.next();
-
+ for (PlanNode criteriaNode : applicableCriteria) {
float filter = ((Float)criteriaNode.getProperty(NodeConstants.Info.EST_SELECTIVITY)).floatValue();
cost *= filter;
@@ -290,15 +284,9 @@
* This does not necessarily mean that a join tree will be successfully created
*/
public boolean isSatisfiable() {
- if (getUnsatisfiedAccessPatterns().isEmpty()) {
- return true;
- }
-
- for (Iterator i = getUnsatisfiedAccessPatterns().iterator(); i.hasNext();) {
- Collection accessPatterns = (Collection)i.next();
+ for (Collection<AccessPattern> accessPatterns : getUnsatisfiedAccessPatterns()) {
boolean matchedAll = false;
- for (Iterator j = accessPatterns.iterator(); j.hasNext();) {
- AccessPattern ap = (AccessPattern)j.next();
+ for (AccessPattern ap : accessPatterns) {
if (dependentCriteriaElements.keySet().containsAll(ap.getUnsatisfied())) {
matchedAll = true;
break;
@@ -313,8 +301,7 @@
}
public void initializeCostingInformation(QueryMetadataInterface metadata) throws QueryMetadataException, MetaMatrixComponentException {
- for (Iterator i = joinSourceNodes.values().iterator(); i.hasNext();) {
- PlanNode node = (PlanNode)i.next();
+ for (PlanNode node : joinSourceNodes.values()) {
NewCalculateCostUtil.computeCostForTree(node, metadata);
}
@@ -328,9 +315,7 @@
*/
private void estimateCriteriaSelectivity(QueryMetadataInterface metadata) throws QueryMetadataException,
MetaMatrixComponentException {
- for (Iterator i = criteriaNodes.iterator(); i.hasNext();) {
- PlanNode node = (PlanNode)i.next();
-
+ for (PlanNode node : criteriaNodes) {
Criteria crit = (Criteria)node.getProperty(NodeConstants.Info.SELECT_CRITERIA);
float[] baseCosts = new float[] {100, 10000, 1000000};
@@ -355,28 +340,21 @@
* TODO: assumptions are made here about how dependent criteria must look that are a little restrictive
*/
public void initializeJoinInformation() {
- critieriaToSourceMap = new HashMap();
+ critieriaToSourceMap = new HashMap<PlanNode, Set<PlanNode>>();
- LinkedList crits = new LinkedList(criteriaNodes);
+ LinkedList<PlanNode> crits = new LinkedList<PlanNode>(criteriaNodes);
crits.addAll(dependentCritieraNodes);
- LinkedHashMap source = new LinkedHashMap(joinSourceNodes);
+ LinkedHashMap<PlanNode, PlanNode> source = new LinkedHashMap<PlanNode, PlanNode>(joinSourceNodes);
source.putAll(dependentJoinSourceNodes);
- for (Iterator j = crits.iterator(); j.hasNext();) {
- PlanNode critNode = (PlanNode)j.next();
-
- for (Iterator k = critNode.getGroups().iterator(); k.hasNext();) {
-
- GroupSymbol group = (GroupSymbol)k.next();
-
- for (Iterator i = source.keySet().iterator(); i.hasNext();) {
- PlanNode node = (PlanNode)i.next();
-
+ for (PlanNode critNode : crits) {
+ for (GroupSymbol group : critNode.getGroups()) {
+ for (PlanNode node : source.keySet()) {
if (node.getGroups().contains(group)) {
- Set sources = (Set)critieriaToSourceMap.get(critNode);
+ Set<PlanNode> sources = critieriaToSourceMap.get(critNode);
if (sources == null) {
- sources = new HashSet();
+ sources = new HashSet<PlanNode>();
critieriaToSourceMap.put(critNode, sources);
}
sources.add(node);
@@ -390,22 +368,18 @@
return;
}
- Map dependentGroupToSourceMap = new HashMap();
+ Map<GroupSymbol, PlanNode> dependentGroupToSourceMap = new HashMap<GroupSymbol, PlanNode>();
- for (Iterator i = dependentJoinSourceNodes.keySet().iterator(); i.hasNext();) {
- PlanNode node = (PlanNode)i.next();
-
- for (Iterator j = node.getGroups().iterator(); j.hasNext();) {
- GroupSymbol symbol = (GroupSymbol)j.next();
+ for (PlanNode node : dependentJoinSourceNodes.keySet()) {
+ for (GroupSymbol symbol : node.getGroups()) {
dependentGroupToSourceMap.put(symbol, node);
}
}
- for (Iterator i = getCriteriaNodes().iterator(); i.hasNext();) {
- PlanNode node = (PlanNode)i.next();
+ for (Iterator<PlanNode> i = getCriteriaNodes().iterator(); i.hasNext();) {
+ PlanNode node = i.next();
- for (Iterator j = node.getGroups().iterator(); j.hasNext();) {
- GroupSymbol symbol = (GroupSymbol)j.next();
+ for (GroupSymbol symbol : node.getGroups()) {
if (dependentGroupToSourceMap.containsKey(symbol)) {
i.remove();
dependentCritieraNodes.add(node);
@@ -416,8 +390,7 @@
dependentCriteriaElements = new HashMap<ElementSymbol, Set<Collection<GroupSymbol>>>();
- for (Iterator i = dependentCritieraNodes.iterator(); i.hasNext();) {
- PlanNode critNode = (PlanNode)i.next();
+ for (PlanNode critNode : dependentCritieraNodes) {
Criteria crit = (Criteria)critNode.getProperty(NodeConstants.Info.SELECT_CRITERIA);
if(!(crit instanceof CompareCriteria)) {
continue;
@@ -479,17 +452,15 @@
return false;
}
- public List getJoinCriteriaForGroups(Set groups) {
+ public List<PlanNode> getJoinCriteriaForGroups(Set<GroupSymbol> groups) {
return getJoinCriteriaForGroups(groups, getCriteriaNodes());
}
//TODO: this should be better than a linear search
- protected List getJoinCriteriaForGroups(Set groups, Collection nodes) {
- List result = new LinkedList();
+ protected List<PlanNode> getJoinCriteriaForGroups(Set<GroupSymbol> groups, Collection<PlanNode> nodes) {
+ List<PlanNode> result = new LinkedList<PlanNode>();
- for (Iterator i = nodes.iterator(); i.hasNext();) {
- PlanNode critNode = (PlanNode)i.next();
-
+ for (PlanNode critNode : nodes) {
if (groups.containsAll(critNode.getGroups())) {
result.add(critNode);
}
@@ -499,12 +470,12 @@
}
public void changeJoinOrder(Object[] joinOrder) {
- List joinSourceEntries = new ArrayList(joinSourceNodes.entrySet());
+ List<Map.Entry<PlanNode, PlanNode>> joinSourceEntries = new ArrayList<Map.Entry<PlanNode, PlanNode>>(joinSourceNodes.entrySet());
for (int i = 0; i < joinOrder.length; i++) {
Integer source = (Integer)joinOrder[i];
- Map.Entry entry = (Map.Entry)joinSourceEntries.get(source.intValue());
+ Map.Entry<PlanNode, PlanNode> entry = joinSourceEntries.get(source.intValue());
this.joinSourceNodes.remove(entry.getKey());
this.joinSourceNodes.put(entry.getKey(), entry.getValue());
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -46,6 +46,8 @@
import com.metamatrix.query.resolver.util.ResolverUtil;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.Criteria;
+import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.OrderByItem;
import com.metamatrix.query.sql.lang.StoredProcedure;
import com.metamatrix.query.sql.symbol.AggregateSymbol;
import com.metamatrix.query.sql.symbol.AliasSymbol;
@@ -147,11 +149,11 @@
case NodeConstants.Types.SORT:
if (root.hasBooleanProperty(NodeConstants.Info.UNRELATED_SORT)) {
//add missing sort columns
- List<SingleElementSymbol> elements = (List<SingleElementSymbol>) root.getProperty(NodeConstants.Info.SORT_ORDER);
+ OrderBy elements = (OrderBy) root.getProperty(NodeConstants.Info.SORT_ORDER);
outputElements = new ArrayList<SingleElementSymbol>(outputElements);
- for (SingleElementSymbol singleElementSymbol : elements) {
- if (!outputElements.contains(singleElementSymbol)) {
- outputElements.add(singleElementSymbol);
+ for (OrderByItem item : elements.getOrderByItems()) {
+ if (!outputElements.contains(item.getSymbol())) {
+ outputElements.add(item.getSymbol());
}
}
}
@@ -235,15 +237,15 @@
if (sort == null) {
return outputElements;
}
- List sortOrder = (List)sort.getProperty(NodeConstants.Info.SORT_ORDER);
+ OrderBy sortOrder = (OrderBy)sort.getProperty(NodeConstants.Info.SORT_ORDER);
List<SingleElementSymbol> topCols = FrameUtil.findTopCols(sort);
SymbolMap symbolMap = (SymbolMap)root.getProperty(NodeConstants.Info.SYMBOL_MAP);
List<ElementSymbol> symbolOrder = symbolMap.getKeys();
- for (final Iterator iterator = sortOrder.iterator(); iterator.hasNext();) {
- final Expression expr = (Expression)iterator.next();
+ for (OrderByItem item : sortOrder.getOrderByItems()) {
+ final Expression expr = item.getSymbol();
int index = topCols.indexOf(expr);
ElementSymbol symbol = symbolOrder.get(index);
if (!outputElements.contains(symbol)) {
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -87,24 +87,21 @@
if(nonRelationalPlan != null) {
accessNode.setProperty(NodeConstants.Info.PROCESSOR_PLAN, nonRelationalPlan);
- } else {
- // Create command from access on down and save in access node
- if(command == null) {
- PlanNode commandRoot = accessNode;
- GroupSymbol intoGroup = (GroupSymbol)accessNode.getFirstChild().getProperty(NodeConstants.Info.INTO_GROUP);
- if (intoGroup != null) {
- commandRoot = NodeEditor.findNodePreOrder(accessNode, NodeConstants.Types.SOURCE).getFirstChild();
- }
- plan = removeUnnecessaryInlineView(plan, commandRoot);
- QueryCommand queryCommand = createQuery(metadata, capFinder, accessNode, commandRoot);
- addDistinct(metadata, capFinder, accessNode, queryCommand);
- command = queryCommand;
- if (intoGroup != null) {
- Insert insertCommand = new Insert(intoGroup, ResolverUtil.resolveElementsInGroup(intoGroup, metadata), null);
- insertCommand.setQueryExpression(queryCommand);
- command = insertCommand;
- }
- }
+ } else if(command == null) {
+ PlanNode commandRoot = accessNode;
+ GroupSymbol intoGroup = (GroupSymbol)accessNode.getFirstChild().getProperty(NodeConstants.Info.INTO_GROUP);
+ if (intoGroup != null) {
+ commandRoot = NodeEditor.findNodePreOrder(accessNode, NodeConstants.Types.SOURCE).getFirstChild();
+ }
+ plan = removeUnnecessaryInlineView(plan, commandRoot);
+ QueryCommand queryCommand = createQuery(metadata, capFinder, accessNode, commandRoot);
+ addDistinct(metadata, capFinder, accessNode, queryCommand);
+ command = queryCommand;
+ if (intoGroup != null) {
+ Insert insertCommand = new Insert(intoGroup, ResolverUtil.resolveElementsInGroup(intoGroup, metadata), null);
+ insertCommand.setQueryExpression(queryCommand);
+ command = insertCommand;
+ }
}
accessNode.setProperty(NodeConstants.Info.ATOMIC_REQUEST, command);
accessNode.removeAllChildren();
@@ -417,10 +414,7 @@
}
private void processOrderBy(PlanNode node, QueryCommand query) {
- List params = (List)node.getProperty(NodeConstants.Info.SORT_ORDER);
- List types = (List)node.getProperty(NodeConstants.Info.ORDER_TYPES);
- OrderBy orderBy = new OrderBy(params, types);
- query.setOrderBy(orderBy);
+ query.setOrderBy((OrderBy)node.getProperty(NodeConstants.Info.SORT_ORDER));
}
/**
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -24,7 +24,6 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -122,10 +121,8 @@
boolean needsCorrection = outputSymbols.size() > oldSize;
- List<Boolean> directions = Collections.nCopies(orderSymbols.size(), OrderBy.ASC);
+ PlanNode sortNode = createSortNode(new ArrayList<SingleElementSymbol>(orderSymbols), outputSymbols);
- PlanNode sortNode = createSortNode(orderSymbols, outputSymbols, directions);
-
if (sourceNode.getType() == NodeConstants.Types.ACCESS) {
if (NewCalculateCostUtil.usesKey(sourceNode, expressions, metadata)) {
joinNode.setProperty(joinNode.getFirstChild() == childNode ? NodeConstants.Info.IS_LEFT_DISTINCT : NodeConstants.Info.IS_RIGHT_DISTINCT, true);
@@ -151,13 +148,11 @@
return false;
}
- private static PlanNode createSortNode(Collection orderSymbols,
- Collection outputElements,
- List directions) {
+ private static PlanNode createSortNode(List<SingleElementSymbol> orderSymbols,
+ Collection outputElements) {
PlanNode sortNode = NodeFactory.getNewNode(NodeConstants.Types.SORT);
- sortNode.setProperty(NodeConstants.Info.SORT_ORDER, new ArrayList(orderSymbols));
+ sortNode.setProperty(NodeConstants.Info.SORT_ORDER, new OrderBy(orderSymbols));
sortNode.setProperty(NodeConstants.Info.OUTPUT_COLS, new ArrayList(outputElements));
- sortNode.setProperty(NodeConstants.Info.ORDER_TYPES, directions);
return sortNode;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleMergeVirtual.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleMergeVirtual.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleMergeVirtual.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -42,6 +42,8 @@
import com.metamatrix.query.optimizer.relational.plantree.NodeEditor;
import com.metamatrix.query.optimizer.relational.plantree.PlanNode;
import com.metamatrix.query.sql.lang.JoinType;
+import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.OrderByItem;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.Function;
@@ -244,14 +246,12 @@
PlanNode sort = NodeEditor.findParent(parentProject, NodeConstants.Types.SORT, NodeConstants.Types.SOURCE);
if (sort != null) { //special handling is needed since we are retaining the child aliases
List<SingleElementSymbol> childProject = (List<SingleElementSymbol>)NodeEditor.findNodePreOrder(frame, NodeConstants.Types.PROJECT).getProperty(NodeConstants.Info.PROJECT_COLS);
- List<SingleElementSymbol> elements = (List<SingleElementSymbol>)sort.getProperty(NodeConstants.Info.SORT_ORDER);
- List<SingleElementSymbol> newElements = new ArrayList<SingleElementSymbol>(elements.size());
- for (SingleElementSymbol singleElementSymbol : elements) {
- newElements.add(childProject.get(selectSymbols.indexOf(singleElementSymbol)));
+ OrderBy elements = (OrderBy)sort.getProperty(NodeConstants.Info.SORT_ORDER);
+ for (OrderByItem item : elements.getOrderByItems()) {
+ item.setSymbol(childProject.get(selectSymbols.indexOf(item.getSymbol())));
}
- sort.setProperty(NodeConstants.Info.SORT_ORDER, newElements);
sort.getGroups().clear();
- sort.addGroups(GroupsUsedByElementsVisitor.getGroups(newElements));
+ sort.addGroups(GroupsUsedByElementsVisitor.getGroups(elements));
}
prepareFrame(frame);
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanSorts.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanSorts.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanSorts.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -38,7 +38,9 @@
import com.metamatrix.query.optimizer.relational.plantree.NodeConstants.Info;
import com.metamatrix.query.processor.relational.JoinNode.JoinStrategyType;
import com.metamatrix.query.processor.relational.MergeJoinStrategy.SortOption;
+import com.metamatrix.query.sql.lang.OrderBy;
import com.metamatrix.query.sql.lang.SetQuery;
+import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.util.CommandContext;
/**
@@ -74,7 +76,7 @@
if (mergeSortWithDupRemoval(node)) {
node.setProperty(NodeConstants.Info.IS_DUP_REMOVAL, true);
}
- List orderColumns = (List)node.getProperty(NodeConstants.Info.SORT_ORDER);
+ List<SingleElementSymbol> orderColumns = ((OrderBy)node.getProperty(NodeConstants.Info.SORT_ORDER)).getSortKeys();
PlanNode possibleSort = NodeEditor.findNodePreOrder(node, NodeConstants.Types.GROUP, NodeConstants.Types.SOURCE | NodeConstants.Types.ACCESS);
if (possibleSort != null) {
List exprs = (List)possibleSort.getProperty(Info.GROUP_COLS);
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -58,10 +58,12 @@
import com.metamatrix.query.resolver.util.ResolverVisitor;
import com.metamatrix.query.rewriter.QueryRewriter;
import com.metamatrix.query.sql.ReservedWords;
+import com.metamatrix.query.sql.LanguageObject.Util;
import com.metamatrix.query.sql.lang.CompareCriteria;
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.IsNullCriteria;
import com.metamatrix.query.sql.lang.JoinType;
+import com.metamatrix.query.sql.lang.OrderBy;
import com.metamatrix.query.sql.lang.Select;
import com.metamatrix.query.sql.lang.SetQuery.Operation;
import com.metamatrix.query.sql.symbol.AggregateSymbol;
@@ -294,8 +296,10 @@
//branches other than the first need to have their projected column names updated
PlanNode sortNode = NodeEditor.findNodePreOrder(unionSource, NodeConstants.Types.SORT, NodeConstants.Types.SOURCE);
List<SingleElementSymbol> sortOrder = null;
+ OrderBy orderBy = null;
if (sortNode != null) {
- sortOrder = (List<SingleElementSymbol>)sortNode.getProperty(Info.SORT_ORDER);
+ orderBy = (OrderBy)sortNode.getProperty(Info.SORT_ORDER);
+ sortOrder = orderBy.getSortKeys();
}
List<SingleElementSymbol> projectCols = FrameUtil.findTopCols(unionSource);
for (int i = 0; i < virtualElements.size(); i++) {
@@ -306,6 +310,7 @@
int sortIndex = sortOrder.indexOf(projectedSymbol);
if (sortIndex > -1) {
updateSymbolName(sortOrder, sortIndex, virtualElem, sortOrder.get(sortIndex));
+ orderBy.getOrderByItems().get(sortIndex).setSymbol(sortOrder.get(sortIndex));
}
}
updateSymbolName(projectCols, i, virtualElem, projectedSymbol);
@@ -336,7 +341,7 @@
}
}
- List<SingleElementSymbol> projectedViewSymbols = QueryRewriter.deepClone(projectedSymbols, SingleElementSymbol.class);
+ List<SingleElementSymbol> projectedViewSymbols = Util.deepClone(projectedSymbols);
SymbolMap viewMapping = SymbolMap.createSymbolMap(NodeEditor.findParent(unionSource, NodeConstants.Types.SOURCE).getGroups().iterator().next(), projectedSymbols, metadata);
for (AggregateSymbol agg : aggregates) {
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -47,6 +47,7 @@
import com.metamatrix.query.sql.lang.CompareCriteria;
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.JoinType;
+import com.metamatrix.query.sql.lang.OrderBy;
import com.metamatrix.query.sql.lang.SetQuery.Operation;
import com.metamatrix.query.sql.symbol.AggregateSymbol;
import com.metamatrix.query.sql.symbol.ElementSymbol;
@@ -255,9 +256,9 @@
return false;
}
- List sortCols = (List)parentNode.getProperty(NodeConstants.Info.SORT_ORDER);
- for (int i = 0; i < sortCols.size(); i++) {
- SingleElementSymbol symbol = (SingleElementSymbol)sortCols.get(i);
+ //TODO: this check shouldn't be necessary, since the order by is not introducing new expressions
+ List<SingleElementSymbol> sortCols = ((OrderBy)parentNode.getProperty(NodeConstants.Info.SORT_ORDER)).getSortKeys();
+ for (SingleElementSymbol symbol : sortCols) {
if(! canPushSymbol(symbol, true, modelID, metadata, capFinder)) {
return false;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseNull.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseNull.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseNull.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -40,6 +40,8 @@
import com.metamatrix.query.optimizer.relational.plantree.NodeFactory;
import com.metamatrix.query.optimizer.relational.plantree.PlanNode;
import com.metamatrix.query.sql.lang.JoinType;
+import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.OrderByItem;
import com.metamatrix.query.sql.lang.SetQuery;
import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.ExpressionSymbol;
@@ -159,11 +161,11 @@
PlanNode sort = NodeEditor.findParent(firstProject, NodeConstants.Types.SORT, NodeConstants.Types.SOURCE);
if (sort != null) { //correct the sort to the new columns as well
- List<SingleElementSymbol> sortOrder = (List<SingleElementSymbol>)sort.getProperty(NodeConstants.Info.SORT_ORDER);
- for (int i = 0; i < sortOrder.size(); i++) {
- SingleElementSymbol sortElement = sortOrder.get(i);
+ OrderBy sortOrder = (OrderBy)sort.getProperty(NodeConstants.Info.SORT_ORDER);
+ for (OrderByItem item : sortOrder.getOrderByItems()) {
+ SingleElementSymbol sortElement = item.getSymbol();
sortElement = newProjectSymbols.get(oldProjectSymbols.indexOf(sortElement));
- sortOrder.set(i, sortElement);
+ item.setSymbol(sortElement);
}
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -45,6 +45,7 @@
import com.metamatrix.query.sql.ReservedWords;
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.JoinType;
+import com.metamatrix.query.sql.lang.OrderBy;
import com.metamatrix.query.sql.symbol.AggregateSymbol;
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
@@ -163,7 +164,7 @@
case NodeConstants.Types.SORT:
{
if (elements != null) {
- List sortOrder = (List)node.getProperty(NodeConstants.Info.SORT_ORDER);
+ OrderBy sortOrder = (OrderBy)node.getProperty(NodeConstants.Info.SORT_ORDER);
ElementCollectorVisitor.getElements(sortOrder, elements);
}
break;
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/xml/XMLPlanner.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/xml/XMLPlanner.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/xml/XMLPlanner.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -305,7 +305,7 @@
return;
}
- List elements = orderBy.getVariables();
+ List elements = orderBy.getSortKeys();
List types = orderBy.getTypes();
for (int i = 0; i< elements.size(); i++) {
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AbstractAssignmentInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AbstractAssignmentInstruction.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AbstractAssignmentInstruction.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -104,7 +104,7 @@
clone.setVariable(this.variable);
clone.setExpression(this.expression);
if (processPlan != null) {
- clone.setProcessPlan((ProcessorPlan)getProcessPlan().clone());
+ clone.setProcessPlan(getProcessPlan().clone());
}
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/command/SetQueryResolver.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/resolver/command/SetQueryResolver.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/resolver/command/SetQueryResolver.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -137,7 +137,7 @@
* @return True if the ORDER BY contains the element
*/
public static boolean orderByContainsVariable(OrderBy orderBy, SingleElementSymbol ses, int position) {
- for (final Iterator iterator = orderBy.getVariables().iterator(); iterator.hasNext();) {
+ for (final Iterator iterator = orderBy.getSortKeys().iterator(); iterator.hasNext();) {
final ElementSymbol element = (ElementSymbol)iterator.next();
if (position == ((TempMetadataID)element.getMetadataID()).getPosition()) {
return true;
Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -354,9 +354,6 @@
index = expressions.indexOf(SymbolMap.getExpression(sortKey));
}
orderBy.setExpressionPosition(i, index);
- if (index == -1) {
- orderBy.addUnrelated((ElementSymbol)sortKey);
- }
continue;
} else if (sortKey instanceof ExpressionSymbol) {
// check for legacy positional
@@ -369,6 +366,7 @@
throw new QueryResolverException(QueryPlugin.Util.getString("SQLParser.non_position_constant", c)); //$NON-NLS-1$
}
orderBy.setExpressionPosition(i, elementOrder - 1);
+ continue;
}
}
//handle order by expressions
@@ -380,13 +378,9 @@
isSimpleQuery, knownShortNames, symbol);
}
ResolverVisitor.resolveLanguageObject(sortKey, metadata);
- int index = expressions.indexOf(SymbolMap.getExpression(sortKey));
- if (index != -1) {
- //the query is using an derived column, but not through an alias
- orderBy.setExpressionPosition(i, index);
- }
- //must be an unrelated sort expression
+ int index = expressions.indexOf(SymbolMap.getExpression(sortKey));
+ orderBy.setExpressionPosition(i, index);
}
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -35,6 +35,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -64,6 +65,7 @@
import com.metamatrix.query.function.FunctionMethods;
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.metadata.TempMetadataAdapter;
+import com.metamatrix.query.metadata.TempMetadataID;
import com.metamatrix.query.metadata.TempMetadataStore;
import com.metamatrix.query.processor.ProcessorDataManager;
import com.metamatrix.query.processor.relational.DependentValueSource;
@@ -73,6 +75,7 @@
import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.ProcedureReservedWords;
import com.metamatrix.query.sql.ReservedWords;
+import com.metamatrix.query.sql.LanguageObject.Util;
import com.metamatrix.query.sql.lang.AbstractSetCriteria;
import com.metamatrix.query.sql.lang.BatchedUpdateCommand;
import com.metamatrix.query.sql.lang.BetweenCriteria;
@@ -95,6 +98,7 @@
import com.metamatrix.query.sql.lang.MatchCriteria;
import com.metamatrix.query.sql.lang.NotCriteria;
import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.OrderByItem;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.QueryCommand;
import com.metamatrix.query.sql.lang.SPParameter;
@@ -796,10 +800,12 @@
boolean hasUnrelatedExpression = false;
+ LinkedList<OrderByItem> unrelatedItems = new LinkedList<OrderByItem>();
for (int i = 0; i < orderBy.getVariableCount(); i++) {
SingleElementSymbol querySymbol = orderBy.getVariable(i);
int index = orderBy.getExpressionPosition(i);
if (index == -1) {
+ unrelatedItems.add(orderBy.getOrderByItems().get(i));
hasUnrelatedExpression |= (querySymbol instanceof ExpressionSymbol);
continue; // must be unrelated - but potentially contains references to the select clause
}
@@ -808,7 +814,7 @@
if (!previousExpressions.add(expr) || (queryCommand instanceof Query && EvaluatableVisitor.isFullyEvaluatable(expr, true))) {
orderBy.removeOrderByItem(i--);
} else {
- orderBy.getVariables().set(i, querySymbol.clone());
+ orderBy.getOrderByItems().get(i).setSymbol((SingleElementSymbol)querySymbol.clone());
}
}
@@ -824,7 +830,14 @@
int originalSymbolCount = select.getProjectedSymbols().size();
//add unrelated to select
- select.addSymbols(orderBy.getUnrelated());
+ for (OrderByItem orderByItem : unrelatedItems) {
+ Collection<ElementSymbol> elements = ElementCollectorVisitor.getElements(orderByItem.getSymbol(), true);
+ for (ElementSymbol elementSymbol : elements) {
+ if (!(elementSymbol.getMetadataID() instanceof TempMetadataID) || ((TempMetadataID)elementSymbol.getMetadataID()).getPosition() == -1) {
+ select.addSymbol(elementSymbol);
+ }
+ }
+ }
makeSelectUnique(select, false);
Query query = queryCommand.getProjectedQuery();
@@ -871,12 +884,7 @@
} catch (MetaMatrixComponentException e) {
throw new QueryValidatorException(e, e.getMessage());
}
- //filter back out the unrelated
- orderBy.getUnrelated().clear();
List symbols = top.getSelect().getSymbols();
- for (ElementSymbol symbol : (List<ElementSymbol>)symbols.subList(originalSymbolCount, symbols.size())) {
- orderBy.addUnrelated(symbol);
- }
top.getSelect().setSymbols(symbols.subList(0, originalSymbolCount));
top.setInto(into);
top.setLimit(limit);
@@ -894,7 +902,7 @@
private Insert rewriteSelectInto(Query query) throws QueryValidatorException {
Into into = query.getInto();
try {
- List<ElementSymbol> allIntoElements = deepClone(ResolverUtil.resolveElementsInGroup(into.getGroup(), metadata), ElementSymbol.class);
+ List<ElementSymbol> allIntoElements = Util.deepClone(ResolverUtil.resolveElementsInGroup(into.getGroup(), metadata));
Insert insert = new Insert(into.getGroup(), allIntoElements, Collections.emptyList());
query.setInto(null);
insert.setQueryExpression(query);
@@ -2408,14 +2416,6 @@
return query;
}
- public static <S extends Expression, T extends S> List<S> deepClone(List<T> collection, Class<S> clazz) {
- ArrayList<S> result = new ArrayList<S>(collection.size());
- for (Expression expression : collection) {
- result.add((S)expression.clone());
- }
- return result;
- }
-
public static void makeSelectUnique(Select select, boolean expressionSymbolsOnly) {
select.setSymbols(select.getProjectedSymbols());
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/LanguageObject.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/LanguageObject.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/LanguageObject.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -23,6 +23,8 @@
package com.metamatrix.query.sql;
import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
/**
* This is the primary interface for all language objects. It extends a few
@@ -43,5 +45,18 @@
* @return Deep clone of this object
*/
Object clone();
+
+ public static class Util {
+
+ @SuppressWarnings("unchecked")
+ public static <S extends LanguageObject, T extends S> ArrayList<S> deepClone(List<T> collection) {
+ ArrayList<S> result = new ArrayList<S>(collection.size());
+ for (LanguageObject obj : collection) {
+ result.add((S)obj.clone());
+ }
+ return result;
+ }
+
+ }
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/LanguageVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/LanguageVisitor.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/LanguageVisitor.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -125,4 +125,5 @@
public void visit(ProcedureContainer obj) {}
public void visit(SetClauseList obj) {}
public void visit(SetClause obj) {}
+ public void visit(OrderByItem obj) {}
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/OrderBy.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/OrderBy.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/OrderBy.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -23,22 +23,15 @@
package com.metamatrix.query.sql.lang;
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.Set;
import com.metamatrix.core.util.EquivalenceUtil;
import com.metamatrix.core.util.HashCodeUtil;
-import com.metamatrix.query.QueryPlugin;
import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.LanguageVisitor;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.visitor.SQLStringVisitor;
-import com.metamatrix.query.util.ErrorMessageKeys;
/**
* Represents the ORDER BY clause of a query. The ORDER BY clause states
@@ -55,42 +48,34 @@
/** Constant for the descending value */
public static final boolean DESC = false;
- private List sortOrder;
- private List orderTypes;
+ private List<OrderByItem> orderByItems = new ArrayList<OrderByItem>();
+
/**
- * set by the resolver to contain element symbol references
- * outside of the select clause
- */
- private Set<ElementSymbol> unrelated;
- private List<Integer> expressionPositions;
- /**
* Constructs a default instance of this class.
*/
public OrderBy() {
- sortOrder = new ArrayList();
- orderTypes = new ArrayList();
}
/**
- * Constructs an instance of this class from an ordered set of elements.
+ * Constructs an instance of this class from an ordered list of elements.
* @param parameters The ordered list of SingleElementSymbol
*/
- public OrderBy( List parameters ) {
- sortOrder = new ArrayList( parameters );
- orderTypes = new ArrayList(parameters.size());
- for( int i=0; i< parameters.size(); i++) {
- orderTypes.add(Boolean.TRUE);
- }
+ public OrderBy( List<? extends SingleElementSymbol> parameters ) {
+ for (SingleElementSymbol singleElementSymbol : parameters) {
+ orderByItems.add(new OrderByItem(singleElementSymbol, ASC));
+ }
}
-
+
/**
* Constructs an instance of this class from an ordered set of elements.
* @param parameters The ordered list of SingleElementSymbol
* @param types The list of directions by which the results are ordered (Boolean, true=ascending)
*/
- public OrderBy( List parameters, List types ) {
- sortOrder = new ArrayList( parameters );
- orderTypes = new ArrayList( types );
+ public OrderBy( List<? extends SingleElementSymbol> parameters, List<Boolean> types ) {
+ Iterator<Boolean> typeIter = types.iterator();
+ for (SingleElementSymbol singleElementSymbol : parameters) {
+ orderByItems.add(new OrderByItem(singleElementSymbol, typeIter.next()));
+ }
}
// =========================================================================
@@ -101,32 +86,20 @@
* @return Number of variables in ORDER BY
*/
public int getVariableCount() {
- return sortOrder.size();
+ return orderByItems.size();
}
-
- /**
- * Returns an ordered list of the symbols in ORDER BY
- * @param List of SingleElementSymbol in ORDER BY
- */
- public List getVariables() {
- return sortOrder;
+
+ public List<OrderByItem> getOrderByItems() {
+ return this.orderByItems;
}
/**
- * Returns an ordered list of sort direction for each order.
- * @param List of Boolean, Boolean.TRUE represents ascending
- */
- public List getTypes() {
- return orderTypes;
- }
-
- /**
* Returns the ORDER BY element at the specified index.
* @param index Index to get
* @return The element at the index
*/
public SingleElementSymbol getVariable( int index ) {
- return (SingleElementSymbol)sortOrder.get(index);
+ return orderByItems.get(index).getSymbol();
}
/**
@@ -135,7 +108,7 @@
* @return The sort order at the index
*/
public Boolean getOrderType( int index ) {
- return (Boolean)orderTypes.get(index);
+ return orderByItems.get(index).isAscending();
}
/**
@@ -143,10 +116,7 @@
* @param element Element to add
*/
public void addVariable( SingleElementSymbol element ) {
- if(element != null) {
- sortOrder.add(element);
- orderTypes.add(Boolean.valueOf(ASC));
- }
+ addVariable(element, ASC);
}
/**
@@ -157,28 +127,10 @@
*/
public void addVariable( SingleElementSymbol element, boolean type ) {
if(element != null) {
- sortOrder.add(element);
- orderTypes.add(Boolean.valueOf(type));
+ orderByItems.add(new OrderByItem(element, type));
}
}
- /**
- * Sets a new collection of variables to be used. The replacement
- * set must be of the same size as the previous set.
- * @param elements Collection of SingleElementSymbol
- * @throws IllegalArgumentException if element is null or size of elements != size of existing elements
- */
- public void replaceVariables( Collection elements ) {
- if(elements == null) {
- throw new IllegalArgumentException(QueryPlugin.Util.getString(ErrorMessageKeys.SQL_0004));
- }
- if(elements.size() != sortOrder.size()) {
- throw new IllegalArgumentException(QueryPlugin.Util.getString(ErrorMessageKeys.SQL_0005));
- }
-
- sortOrder = new ArrayList(elements);
- }
-
public void acceptVisitor(LanguageVisitor visitor) {
visitor.visit(this);
}
@@ -190,26 +142,10 @@
/**
* Return deep copy of this ORDER BY clause.
*/
- public Object clone() {
- List thisSymbols = getVariables();
- List copySymbols = new ArrayList(thisSymbols.size());
- Iterator iter = thisSymbols.iterator();
- while(iter.hasNext()) {
- SingleElementSymbol ses = (SingleElementSymbol) iter.next();
- copySymbols.add(ses.clone());
- }
- OrderBy result = new OrderBy(copySymbols, getTypes());
- if (this.unrelated != null) {
- HashSet<ElementSymbol> copyUnrelated = new HashSet<ElementSymbol>();
- for (ElementSymbol elementSymbol : this.unrelated) {
- copyUnrelated.add((ElementSymbol)elementSymbol.clone());
- }
- result.unrelated = copyUnrelated;
- }
- if (this.expressionPositions != null) {
- result.expressionPositions = new ArrayList<Integer>(expressionPositions);
- }
- return result;
+ public OrderBy clone() {
+ OrderBy clone = new OrderBy();
+ clone.orderByItems = LanguageObject.Util.deepClone(this.orderByItems);
+ return clone;
}
/**
@@ -228,8 +164,7 @@
}
OrderBy other = (OrderBy) obj;
- return EquivalenceUtil.areEqual(getVariables(), other.getVariables()) &&
- EquivalenceUtil.areEqual(getTypes(), other.getTypes());
+ return EquivalenceUtil.areEqual(orderByItems, other.orderByItems);
}
/**
@@ -240,10 +175,7 @@
* @return Hash code
*/
public int hashCode() {
- int hc = 0;
- hc = HashCodeUtil.hashCode(0, getVariables());
- hc = HashCodeUtil.hashCode(hc, getTypes());
- return hc;
+ return HashCodeUtil.hashCode(0, orderByItems);
}
/**
@@ -254,42 +186,45 @@
return SQLStringVisitor.getSQLString(this);
}
- public boolean hasUnrelated() {
- return this.unrelated != null;
- }
-
- public void addUnrelated(ElementSymbol symbol) {
- if (this.unrelated == null) {
- this.unrelated = new HashSet<ElementSymbol>();
- }
- this.unrelated.add(symbol);
- }
-
- public Set<ElementSymbol> getUnrelated() {
- if (this.unrelated == null) {
- return Collections.emptySet();
- }
- return unrelated;
- }
-
public void setExpressionPosition(int orderIndex, int selectIndex) {
- if (this.expressionPositions == null) {
- this.expressionPositions = new ArrayList<Integer>(Collections.nCopies(sortOrder.size(), -1));
- }
- this.expressionPositions.set(orderIndex, selectIndex);
+ this.orderByItems.get(orderIndex).setExpressionPosition(selectIndex);
}
public int getExpressionPosition(int orderIndex) {
- if (expressionPositions == null) {
- return -1;
- }
- return expressionPositions.get(orderIndex);
+ return this.orderByItems.get(orderIndex).getExpressionPosition();
}
public void removeOrderByItem(int index) {
- sortOrder.remove(index);
- orderTypes.remove(index);
- expressionPositions.remove(index);
+ this.orderByItems.remove(index);
}
+ public boolean hasUnrelated() {
+ for (OrderByItem item : orderByItems) {
+ if (item.isUnrelated()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Get the list or sort key symbols. Modifications to this list will not add or remove {@link OrderByItem}s.
+ * @return
+ */
+ public List<SingleElementSymbol> getSortKeys() {
+ ArrayList<SingleElementSymbol> result = new ArrayList<SingleElementSymbol>(orderByItems.size());
+ for (OrderByItem item : orderByItems) {
+ result.add(item.getSymbol());
+ }
+ return result;
+ }
+
+ public List<Boolean> getTypes() {
+ ArrayList<Boolean> result = new ArrayList<Boolean>(orderByItems.size());
+ for (OrderByItem item : orderByItems) {
+ result.add(item.isAscending());
+ }
+ return result;
+ }
+
}
Added: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/OrderByItem.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/OrderByItem.java (rev 0)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/OrderByItem.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -0,0 +1,109 @@
+/*
+ * 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 com.metamatrix.query.sql.lang;
+
+import com.metamatrix.query.sql.LanguageObject;
+import com.metamatrix.query.sql.LanguageVisitor;
+import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.visitor.SQLStringVisitor;
+
+public class OrderByItem implements LanguageObject {
+
+ private static final long serialVersionUID = 6937561370697819126L;
+
+ private Integer expressionPosition; //set during resolving to the select clause position
+ private boolean ascending = true;
+ private SingleElementSymbol symbol;
+
+ public OrderByItem(SingleElementSymbol symbol, boolean ascending) {
+ this.symbol = symbol;
+ this.ascending = ascending;
+ }
+
+ public int getExpressionPosition() {
+ return expressionPosition == null?-1:expressionPosition;
+ }
+
+ public void setExpressionPosition(int expressionPosition) {
+ this.expressionPosition = expressionPosition;
+ }
+
+ public boolean isAscending() {
+ return ascending;
+ }
+
+ public void setAscending(boolean ascending) {
+ this.ascending = ascending;
+ }
+
+ public SingleElementSymbol getSymbol() {
+ return symbol;
+ }
+
+ public void setSymbol(SingleElementSymbol symbol) {
+ this.symbol = symbol;
+ }
+
+ /**
+ *
+ * @return true if the expression does not appear in the select clause
+ */
+ public boolean isUnrelated() {
+ return expressionPosition != null && expressionPosition == -1;
+ }
+
+ @Override
+ public void acceptVisitor(LanguageVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ @Override
+ public OrderByItem clone() {
+ OrderByItem clone = new OrderByItem((SingleElementSymbol)this.symbol.clone(), ascending);
+ clone.expressionPosition = this.expressionPosition;
+ return clone;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof OrderByItem)) {
+ return false;
+ }
+ OrderByItem o = (OrderByItem)obj;
+ return o.symbol.equals(symbol) && o.ascending == this.ascending;
+ }
+
+ @Override
+ public int hashCode() {
+ return symbol.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return SQLStringVisitor.getSQLString(this);
+ }
+
+}
Property changes on: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/OrderByItem.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/navigator/PreOrPostOrderNavigator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/navigator/PreOrPostOrderNavigator.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/navigator/PreOrPostOrderNavigator.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -49,6 +49,7 @@
import com.metamatrix.query.sql.lang.NotCriteria;
import com.metamatrix.query.sql.lang.Option;
import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.OrderByItem;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.SPParameter;
import com.metamatrix.query.sql.lang.Select;
@@ -350,9 +351,15 @@
}
public void visit(OrderBy obj) {
preVisitVisitor(obj);
- visitNodes(obj.getVariables());
+ visitNodes(obj.getOrderByItems());
postVisitVisitor(obj);
}
+ @Override
+ public void visit(OrderByItem obj) {
+ preVisitVisitor(obj);
+ visitNode(obj.getSymbol());
+ postVisitVisitor(obj);
+ }
public void visit(Query obj) {
preVisitVisitor(obj);
visitNode(obj.getSelect());
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -41,7 +41,7 @@
import com.metamatrix.query.sql.lang.IsNullCriteria;
import com.metamatrix.query.sql.lang.Limit;
import com.metamatrix.query.sql.lang.MatchCriteria;
-import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.OrderByItem;
import com.metamatrix.query.sql.lang.SPParameter;
import com.metamatrix.query.sql.lang.Select;
import com.metamatrix.query.sql.lang.SetClause;
@@ -90,29 +90,35 @@
if (symbol instanceof SingleElementSymbol) {
SingleElementSymbol ses = (SingleElementSymbol)symbol;
- SingleElementSymbol replacmentSymbol = null;
-
- Expression expr = ses;
- if (ses instanceof ExpressionSymbol && !(ses instanceof AggregateSymbol)) {
- expr = ((ExpressionSymbol)ses).getExpression();
- }
+ SingleElementSymbol replacmentSymbol = replaceSymbol(ses, alias);
- Expression replacement = replaceExpression(expr);
-
- if (replacement instanceof SingleElementSymbol) {
- replacmentSymbol = (SingleElementSymbol)replacement;
- } else {
- replacmentSymbol = new ExpressionSymbol(ses.getName(), replacement);
- }
-
- if (alias && createAliases() && !replacmentSymbol.getShortCanonicalName().equals(ses.getShortCanonicalName())) {
- replacmentSymbol = new AliasSymbol(ses.getShortName(), replacmentSymbol);
- }
-
symbols.set(i, replacmentSymbol);
}
}
}
+
+ private SingleElementSymbol replaceSymbol(SingleElementSymbol ses,
+ boolean alias) {
+ SingleElementSymbol replacmentSymbol = null;
+
+ Expression expr = ses;
+ if (ses instanceof ExpressionSymbol && !(ses instanceof AggregateSymbol)) {
+ expr = ((ExpressionSymbol)ses).getExpression();
+ }
+
+ Expression replacement = replaceExpression(expr);
+
+ if (replacement instanceof SingleElementSymbol) {
+ replacmentSymbol = (SingleElementSymbol)replacement;
+ } else {
+ replacmentSymbol = new ExpressionSymbol(ses.getName(), replacement);
+ }
+
+ if (alias && createAliases() && !replacmentSymbol.getShortCanonicalName().equals(ses.getShortCanonicalName())) {
+ replacmentSymbol = new AliasSymbol(ses.getShortName(), replacmentSymbol);
+ }
+ return replacmentSymbol;
+ }
/**
* @see com.metamatrix.query.sql.LanguageVisitor#visit(com.metamatrix.query.sql.symbol.AliasSymbol)
@@ -265,12 +271,9 @@
replaceSymbols(obj.getSymbols(), false);
}
- /**
- * Swap each SingleElementSymbol in OrderBy (other symbols are ignored).
- * @param obj Object to remap
- */
- public void visit(OrderBy obj) {
- replaceSymbols(obj.getVariables(), true);
+ @Override
+ public void visit(OrderByItem obj) {
+ obj.setSymbol(replaceSymbol(obj.getSymbol(), true));
}
public void visit(Limit obj) {
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -58,6 +58,7 @@
import com.metamatrix.query.sql.lang.NotCriteria;
import com.metamatrix.query.sql.lang.Option;
import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.OrderByItem;
import com.metamatrix.query.sql.lang.PredicateCriteria;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.QueryCommand;
@@ -697,29 +698,28 @@
parts.add(SPACE);
parts.add(ReservedWords.BY);
parts.add(SPACE);
-
- List variables = obj.getVariables();
- List types = obj.getTypes();
- Iterator iter = variables.iterator();
- Iterator typeIter = types.iterator();
- while ( iter.hasNext() ) {
- SingleElementSymbol ses = (SingleElementSymbol)iter.next();
- if (ses instanceof AliasSymbol) {
- AliasSymbol as = (AliasSymbol)ses;
- outputDisplayName(as.getOutputName());
- } else {
- parts.add(registerNode(ses));
- }
- Boolean type = (Boolean) typeIter.next();
- if( type.booleanValue() == OrderBy.DESC ) {
- parts.add(SPACE);
- parts.add(ReservedWords.DESC);
- } // Don't print default "ASC"
-
- if (iter.hasNext()) {
- parts.add( ", " ); //$NON-NLS-1$
- }
+ for (Iterator<OrderByItem> iterator = obj.getOrderByItems().iterator(); iterator.hasNext();) {
+ OrderByItem item = iterator.next();
+ parts.add(registerNode(item));
+ if (iterator.hasNext()) {
+ parts.add( ", " ); //$NON-NLS-1$
+ }
+ }
+ }
+
+ @Override
+ public void visit(OrderByItem obj) {
+ SingleElementSymbol ses = obj.getSymbol();
+ if (ses instanceof AliasSymbol) {
+ AliasSymbol as = (AliasSymbol)ses;
+ outputDisplayName(as.getOutputName());
+ } else {
+ parts.add(registerNode(ses));
}
+ if(!obj.isAscending()) {
+ parts.add(SPACE);
+ parts.add(ReservedWords.DESC);
+ } // Don't print default "ASC"
}
public void visit(DynamicCommand obj) {
Modified: trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -64,6 +64,7 @@
import com.metamatrix.query.sql.lang.NotCriteria;
import com.metamatrix.query.sql.lang.Option;
import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.OrderByItem;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.QueryCommand;
import com.metamatrix.query.sql.lang.Select;
@@ -203,8 +204,9 @@
validateInsert(obj);
}
- public void visit(OrderBy obj) {
- validateSortable(obj.getVariables());
+ @Override
+ public void visit(OrderByItem obj) {
+ validateSortable(obj.getSymbol());
}
public void visit(Query obj) {
@@ -605,12 +607,16 @@
Iterator iter = symbols.iterator();
while(iter.hasNext()) {
SingleElementSymbol symbol = (SingleElementSymbol) iter.next();
- if (isNonComparable(symbol)) {
- handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0026, symbol), symbol);
- }
+ validateSortable(symbol);
}
}
+ private void validateSortable(SingleElementSymbol symbol) {
+ if (isNonComparable(symbol)) {
+ handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0026, symbol), symbol);
+ }
+ }
+
public static boolean isNonComparable(Expression symbol) {
return DataTypeManager.isNonComparable(DataTypeManager.getDataTypeName(symbol.getType()));
}
@@ -647,11 +653,8 @@
}
if (obj.getOrderBy() != null) {
OrderBy orderBy = obj.getOrderBy();
- if (orderBy.hasUnrelated()) {
- handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.unrelated_orderby_xml"), obj); //$NON-NLS-1$
- }
- for (SingleElementSymbol ses : (List<SingleElementSymbol>)orderBy.getVariables()) {
- if (!(ses instanceof ElementSymbol)) {
+ for (OrderByItem item : orderBy.getOrderByItems()) {
+ if (!(item.getSymbol() instanceof ElementSymbol)) {
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.orderby_expression_xml"), obj); //$NON-NLS-1$
}
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/language/LanguageBridgeFactory.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/language/LanguageBridgeFactory.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/language/LanguageBridgeFactory.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -97,6 +97,7 @@
import com.metamatrix.query.sql.lang.MatchCriteria;
import com.metamatrix.query.sql.lang.NotCriteria;
import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.OrderByItem;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.QueryCommand;
import com.metamatrix.query.sql.lang.SPParameter;
@@ -438,19 +439,15 @@
if(orderBy == null){
return null;
}
- List items = orderBy.getVariables();
- List types = orderBy.getTypes();
- List translatedItems = new ArrayList();
- for (int i = 0; i < items.size(); i++) {
- SingleElementSymbol symbol = (SingleElementSymbol)items.get(i);
- boolean direction = (((Boolean)types.get(i)).booleanValue() == OrderBy.DESC)
- ? IOrderByItem.DESC
- : IOrderByItem.ASC;
+ List<OrderByItemImpl> translatedItems = new ArrayList<OrderByItemImpl>();
+ for (OrderByItem item : orderBy.getOrderByItems()) {
+ SingleElementSymbol symbol = item.getSymbol();
+ boolean direction = item.isAscending()?IOrderByItem.ASC:IOrderByItem.DESC;
OrderByItemImpl orderByItem = null;
if(symbol instanceof ElementSymbol){
IElement innerElement = translate((ElementSymbol)symbol);
- if (symbol.getOutputName() != null && symbol.getOutputName().indexOf(ElementSymbol.SEPARATOR) != -1) {
+ if (item.isUnrelated() || (symbol.getOutputName() != null && symbol.getOutputName().indexOf(ElementSymbol.SEPARATOR) != -1)) {
orderByItem = new OrderByItemImpl(null, direction, innerElement);
} else {
orderByItem = new OrderByItemImpl(symbol.getOutputName(), direction, innerElement);
@@ -535,8 +532,7 @@
}
IElement translate(ElementSymbol symbol) throws MetaMatrixComponentException {
- ElementImpl element = null;
- element = new ElementImpl(translate(symbol.getGroupSymbol()), symbol.getOutputName(), null, symbol.getType());
+ ElementImpl element = new ElementImpl(translate(symbol.getGroupSymbol()), symbol.getOutputName(), null, symbol.getType());
if (element.getGroup().getMetadataObject() == null) {
return element;
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestAliasGenerator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestAliasGenerator.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestAliasGenerator.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -72,7 +72,7 @@
String sql = "select e1 from pm1.g1 order by e1"; //$NON-NLS-1$
String expected = "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0"; //$NON-NLS-1$
Query command = (Query)helpTest(sql, expected, true, FakeMetadataFactory.example1Cached());
- assertEquals(((SingleElementSymbol)command.getOrderBy().getVariables().get(0)).getName(), "e1"); //$NON-NLS-1$
+ assertEquals(command.getOrderBy().getSortKeys().get(0).getName(), "e1"); //$NON-NLS-1$
assertEquals(((SingleElementSymbol)command.getProjectedSymbols().get(0)).getShortName(), "e1"); //$NON-NLS-1$
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestOrderByRewrite.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestOrderByRewrite.java 2010-02-18 16:21:36 UTC (rev 1840)
+++ trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestOrderByRewrite.java 2010-02-18 20:12:13 UTC (rev 1841)
@@ -65,7 +65,7 @@
String[] elementNames,
String[] elementIDs) {
List elements = new ArrayList();
- for (Iterator i = langObj.getVariables().iterator(); i.hasNext();) {
+ for (Iterator i = langObj.getSortKeys().iterator(); i.hasNext();) {
ElementCollectorVisitor.getElements((LanguageObject)i.next(), elements);
}
@@ -84,7 +84,7 @@
private void helpCheckExpressionsSymbols(OrderBy langObj,
String[] functionsNames) {
int expCount = 0;
- for (Iterator i = langObj.getVariables().iterator(); i.hasNext();) {
+ for (Iterator i = langObj.getSortKeys().iterator(); i.hasNext();) {
SingleElementSymbol ses = (SingleElementSymbol)i.next();
if (ses instanceof ExpressionSymbol) {
assertEquals("Expression Symbols does not match: ", functionsNames[expCount++], ses.toString()); //$NON-NLS-1$
13 years, 9 months
teiid SVN: r1840 - in branches/JCA/connectors: connector-xmlsource-soap and 5 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2010-02-18 11:21:36 -0500 (Thu, 18 Feb 2010)
New Revision: 1840
Added:
branches/JCA/connectors/connector-xmlsource-soap/src/test/java/org/teiid/connector/xmlsource/soap/TestSoapConnector.java
Removed:
branches/JCA/connectors/connector-xml-common/
branches/JCA/connectors/connector-xmlsource-soap/src/test/java/org/teiid/connector/xmlsource/soap/TestSoapConnection.java
Modified:
branches/JCA/connectors/connector-xmlsource-soap/pom.xml
branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SecurityToken.java
branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/ServiceOperation.java
branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapConnection.java
branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapConnector.java
branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapManagedConnectionFactory.java
branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapProcedureExecution.java
branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapRequest.java
branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapService.java
branches/JCA/connectors/connector-xmlsource-soap/src/main/rar/META-INF/ra.xml
branches/JCA/connectors/connector-xmlsource-soap/src/main/resources/org/teiid/connector/xmlsource/i18n.properties
branches/JCA/connectors/connector-xmlsource-soap/src/test/java/com/metamatrix/connector/xmlsource/soap/service/StockQuotes.java
branches/JCA/connectors/connector-xmlsource-soap/src/test/java/org/teiid/connector/xmlsource/soap/TestSoapExecution.java
Log:
TEIID-861: TEIID-990: Converting to SOAP execution to use JAX-WS; WS-Security is still pending
Modified: branches/JCA/connectors/connector-xmlsource-soap/pom.xml
===================================================================
--- branches/JCA/connectors/connector-xmlsource-soap/pom.xml 2010-02-18 02:45:34 UTC (rev 1839)
+++ branches/JCA/connectors/connector-xmlsource-soap/pom.xml 2010-02-18 16:21:36 UTC (rev 1840)
@@ -51,6 +51,12 @@
</dependency>
<dependency>
+ <groupId>wsdl4j</groupId>
+ <artifactId>wsdl4j</artifactId>
+ <version>1.6.1</version>
+ </dependency>
+
+ <dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>1.3</version>
@@ -60,46 +66,49 @@
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>apache-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.2</version>
- <scope>runtime</scope>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.0</version>
- <scope>provided</scope>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>wss4j</groupId>
<artifactId>wss4j</artifactId>
<version>1.5.0</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>axis</groupId>
<artifactId>axis-saaj</artifactId>
<version>1.2</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>axis</groupId>
<artifactId>axis-schema</artifactId>
<version>1.3</version>
- <scope>runtime</scope>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>opensaml</groupId>
<artifactId>opensaml</artifactId>
<version>1.1b</version>
- <scope>runtime</scope>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>apache-xmlsec</groupId>
<artifactId>xmlsec</artifactId>
<version>1.3.0</version>
- <scope>runtime</scope>
+ <scope>test</scope>
</dependency>
</dependencies>
Modified: branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SecurityToken.java
===================================================================
--- branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SecurityToken.java 2010-02-18 02:45:34 UTC (rev 1839)
+++ branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SecurityToken.java 2010-02-18 16:21:36 UTC (rev 1840)
@@ -22,21 +22,8 @@
package org.teiid.connector.xmlsource.soap;
-import java.io.IOException;
-import java.security.MessageDigest;
-import java.util.StringTokenizer;
+import javax.xml.ws.Dispatch;
-import javax.security.auth.callback.Callback;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.callback.UnsupportedCallbackException;
-
-import org.apache.axis.client.Call;
-import org.apache.ws.security.WSConstants;
-import org.apache.ws.security.WSPasswordCallback;
-import org.apache.ws.security.handler.WSHandlerConstants;
-import org.apache.ws.security.message.token.UsernameToken;
-import org.apache.ws.security.util.Base64;
-import org.teiid.connector.xmlsource.TrustedPayloadHandler;
import org.teiid.connector.xmlsource.XMLSourcePlugin;
/**
@@ -67,17 +54,19 @@
String username;
String password;
- public static SecurityToken getSecurityToken(SecurityManagedConnectionFactory env, TrustedPayloadHandler trustedPayloadHandler) {
+ public static SecurityToken getSecurityToken(SecurityManagedConnectionFactory env) {
+
+ /*
// first find out what type of security we are going to handle
String securityType = env.getSecurityType();
if (securityType != null) {
// the first two are non-ws-security based; and they can not be nested.
if (securityType.equalsIgnoreCase(NONE_PROFILE)) {
- return new NoProvider(env, trustedPayloadHandler);
+ return new NoProvider(env);
}
else if (securityType.equalsIgnoreCase(HTTP_BASIC_AUTH)) {
- return new HTTPBasic(env, trustedPayloadHandler);
+ return new HTTPBasic(env);
}
else if (securityType.equalsIgnoreCase(WS_SECURITY)) {
@@ -85,7 +74,7 @@
if (wsSecurityType != null && wsSecurityType.length() > 0) {
// if this is WS-security then we need to find sub-category of it
- WSSecurityToken rootToken = new WSSecurityToken(env, trustedPayloadHandler);
+ WSSecurityToken rootToken = new WSSecurityToken(env);
WSSecurityToken nextToken = rootToken;
StringTokenizer st = new StringTokenizer(wsSecurityType);
@@ -94,25 +83,25 @@
String authType = st.nextToken();
if (authType.equalsIgnoreCase(USERNAME_TOKEN_PROFILE_CLEAR_TEXT)) {
- nextToken = nextToken.setNextToken(new UsernameTokenProfile(env, trustedPayloadHandler, false));
+ nextToken = nextToken.setNextToken(new UsernameTokenProfile(env, false));
}
else if (authType.equalsIgnoreCase(USERNAME_TOKEN_PROFILE_DIGEST)) {
- nextToken = nextToken.setNextToken( new UsernameTokenProfile(env, trustedPayloadHandler, true));
+ nextToken = nextToken.setNextToken( new UsernameTokenProfile(env, true));
}
else if (authType.equalsIgnoreCase(SAML_TOKEN_UNSIGNED)) {
- nextToken = nextToken.setNextToken( new SAMLTokenProfile(env, trustedPayloadHandler, false));
+ nextToken = nextToken.setNextToken( new SAMLTokenProfile(env, false));
}
else if (authType.equalsIgnoreCase(SAML_TOKEN_SIGNED)) {
- nextToken = nextToken.setNextToken( new SAMLTokenProfile(env, trustedPayloadHandler, true));
+ nextToken = nextToken.setNextToken( new SAMLTokenProfile(env, true));
}
else if (authType.equalsIgnoreCase(SIGNATURE)) {
- nextToken = nextToken.setNextToken( new SignatureProfile(env, trustedPayloadHandler));
+ nextToken = nextToken.setNextToken( new SignatureProfile(env));
}
else if (authType.equalsIgnoreCase(TIMESTAMP)) {
- nextToken = nextToken.setNextToken( new TimestampProfile(env, trustedPayloadHandler));
+ nextToken = nextToken.setNextToken( new TimestampProfile(env));
}
else if (authType.equalsIgnoreCase(ENCRYPT)) {
- nextToken = nextToken.setNextToken( new EncryptProfile(env, trustedPayloadHandler));
+ nextToken = nextToken.setNextToken( new EncryptProfile(env));
}
else {
throw new RuntimeException(XMLSourcePlugin.Util.getString("No_such_ws_security_type", new Object[] {authType})); //$NON-NLS-1$
@@ -126,23 +115,13 @@
throw new RuntimeException(XMLSourcePlugin.Util.getString("No_such_auth_type", new Object[] {securityType})); //$NON-NLS-1$
}
}
- return new NoProvider(env, trustedPayloadHandler);
+ */
+ return new NoProvider(env);
}
- SecurityToken(SecurityManagedConnectionFactory env, TrustedPayloadHandler trustedPayloadHandler) {
+ SecurityToken(SecurityManagedConnectionFactory env) {
this.env = env;
- if (null != trustedPayloadHandler) {
- String tempPassword = trustedPayloadHandler.getPassword();
- String tempUsername = trustedPayloadHandler.getUser();
- if(null != tempPassword && null != tempUsername) {
- password = tempPassword;
- username = tempUsername;
- } else {
- setCredentialsFromEnv();
- }
- } else {
- setCredentialsFromEnv();
- }
+ setCredentialsFromEnv();
}
private void setCredentialsFromEnv() {
@@ -172,22 +151,24 @@
throw new RuntimeException(XMLSourcePlugin.Util.getString("no_trust_type_defined")); //$NON-NLS-1$
}
- public abstract void handleSecurity(Call stub);
+ public abstract void handleSecurity(Dispatch stub);
}
/**
* A marker class to differentiate between WS-Security and non - WS-Secuirty like
* HTTP Based one
*/
+
+/*
class WSSecurityToken extends SecurityToken implements CallbackHandler {
WSSecurityToken nextToken;
- public WSSecurityToken(SecurityManagedConnectionFactory env, TrustedPayloadHandler trustedPayloadHandler) {
- super(env, trustedPayloadHandler);
+ public WSSecurityToken(SecurityManagedConnectionFactory env) {
+ super(env);
}
@Override
- public void handleSecurity(Call call) {
+ public void handleSecurity(Dispatch call) {
addSecurity(call);
if (nextToken != null) {
this.nextToken.handleSecurity(call);
@@ -206,11 +187,11 @@
// this needs to be extended by everybody toadd specific
// type of secuirty; should have been abstract but to minimize the code
// choose to have empty method.
- void addSecurity(Call call) {
+ void addSecurity(Dispatch call) {
// nothing to do.
}
- void setAction(Call call, String action) {
+ void setAction(Dispatch call, String action) {
String prev = (String)call.getProperty(WSHandlerConstants.ACTION);
if (prev == null || prev.length() == 0) {
call.setProperty(WSHandlerConstants.ACTION, action);
@@ -232,15 +213,17 @@
}
}
+*/
+
/**
* defines that there is no security provider
*/
class NoProvider extends SecurityToken{
- public NoProvider(SecurityManagedConnectionFactory env, TrustedPayloadHandler trustedPayloadHandler){
- super(env, trustedPayloadHandler);
+ public NoProvider(SecurityManagedConnectionFactory env){
+ super(env);
}
@Override
- public void handleSecurity(Call stub) {
+ public void handleSecurity(Dispatch stub) {
}
}
@@ -248,29 +231,35 @@
* This uses the HTTP Basic authentication; So the user credentials are sent over
* in HTTP Headers. Uses Basic-Relam.
*/
+
+/*
class HTTPBasic extends SecurityToken{
- public HTTPBasic(SecurityManagedConnectionFactory env, TrustedPayloadHandler trustedPayloadHandler){
- super(env, trustedPayloadHandler);
+ public HTTPBasic(SecurityManagedConnectionFactory env){
+ super(env);
}
@Override
- public void handleSecurity(Call stub) {
+ public void handleSecurity(Dispatch stub) {
stub.setUsername(getUsername());
stub.setPassword(getPassword());
this.env.getLogger().logDetail(XMLSourcePlugin.Util.getString( "using_http_basic")); //$NON-NLS-1$
}
}
+*/
+
/**
* Timestamp Profile using WSS4J
*/
+
+/*
class TimestampProfile extends WSSecurityToken {
- public TimestampProfile(SecurityManagedConnectionFactory env, TrustedPayloadHandler trustedPayloadHandler) {
- super(env, trustedPayloadHandler);
+ public TimestampProfile(SecurityManagedConnectionFactory env) {
+ super(env);
this.env.getLogger().logDetail(XMLSourcePlugin.Util.getString("using_timestamp_profile")); //$NON-NLS-1$
}
@Override
- public void addSecurity(Call call) {
+ public void addSecurity(Dispatch call) {
setAction(call, WSHandlerConstants.TIMESTAMP);
// How long ( in seconds ) message is valid since send.
@@ -279,22 +268,25 @@
//properties.setProperty(WSHandlerConstants.TIMESTAMP_PRECISION,"true");
}
}
+*/
/**
* This class uses the WS-Security using standard OASIS Web Services Security
* implemented by apache "WSS4J" Implements "Username Token Profile"
*/
+
+/*
class UsernameTokenProfile extends WSSecurityToken {
boolean encryptedPassword = false;
- public UsernameTokenProfile(SecurityManagedConnectionFactory env, TrustedPayloadHandler trustedPayloadHandler, boolean encryptedPassword){
- super(env, trustedPayloadHandler);
+ public UsernameTokenProfile(SecurityManagedConnectionFactory env, boolean encryptedPassword){
+ super(env);
this.encryptedPassword = encryptedPassword;
this.env.getLogger().logDetail(XMLSourcePlugin.Util.getString("using_username_profile")); //$NON-NLS-1$
}
@Override
- public void addSecurity(Call call) {
+ public void addSecurity(Dispatch call) {
setAction(call, WSHandlerConstants.USERNAME_TOKEN);
call.setProperty(WSHandlerConstants.USER, getUsername());
if (this.encryptedPassword) {
@@ -337,13 +329,13 @@
}
class EncryptProfile extends WSSecurityToken {
- public EncryptProfile(SecurityManagedConnectionFactory env, TrustedPayloadHandler trustedPayloadHandler){
- super(env, trustedPayloadHandler);
+ public EncryptProfile(SecurityManagedConnectionFactory env){
+ super(env);
this.env.getLogger().logDetail(XMLSourcePlugin.Util.getString("using_encrypt_profile")); //$NON-NLS-1$
}
@Override
- public void addSecurity(Call call) {
+ public void addSecurity(Dispatch call) {
setAction(call, WSHandlerConstants.ENCRYPT);
String user = this.env.getEncryptUserName();
if (user == null || user.length() == 0) {
@@ -363,19 +355,21 @@
call.setProperty(WSHandlerConstants.ENC_KEY_ID, "SKIKeyIdentifier"); //$NON-NLS-1$
}
}
+*/
/**
* Digital signature profile using WSS4J
- */
+ */
+/*
class SignatureProfile extends WSSecurityToken {
- public SignatureProfile(SecurityManagedConnectionFactory env, TrustedPayloadHandler trustedPayloadHandler) {
- super(env, trustedPayloadHandler);
+ public SignatureProfile(SecurityManagedConnectionFactory env) {
+ super(env);
this.env.getLogger().logDetail(XMLSourcePlugin.Util.getString("using_signature_profile")); //$NON-NLS-1$
}
@Override
- public void addSecurity(Call call) {
+ public void addSecurity(Dispatch call) {
setAction(call, WSHandlerConstants.SIGNATURE);
call.setProperty(WSHandlerConstants.USER, getUsername());
call.setProperty(WSHandlerConstants.PW_CALLBACK_REF, this);
@@ -389,20 +383,23 @@
call.setProperty(WSHandlerConstants.SIGNATURE_PARTS, "{}{http://schemas.xmlsoap.org/soap/envelope/}Body;STRTransform"); //$NON-NLS-1$
}
}
+*/
/**
* SAML Profile based authentication using WSS4J.
*/
+
+/*
class SAMLTokenProfile extends WSSecurityToken {
boolean signed = false;
- public SAMLTokenProfile(SecurityManagedConnectionFactory env, TrustedPayloadHandler trustedPayloadHandler, boolean signed){
- super(env, trustedPayloadHandler);
+ public SAMLTokenProfile(SecurityManagedConnectionFactory env, boolean signed){
+ super(env);
this.signed = signed;
}
@Override
- public void addSecurity(Call call) {
+ public void addSecurity(Dispatch call) {
if (signed) {
setAction(call, WSHandlerConstants.SAML_TOKEN_SIGNED);
@@ -432,5 +429,7 @@
throw new RuntimeException(XMLSourcePlugin.Util.getString("no_saml_property_file")); //$NON-NLS-1$
}
call.setProperty(WSHandlerConstants.SAML_PROP_FILE, samlPropertyFile);
- }
-}
\ No newline at end of file
+ }
+
+}
+ */
\ No newline at end of file
Modified: branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/ServiceOperation.java
===================================================================
--- branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/ServiceOperation.java 2010-02-18 02:45:34 UTC (rev 1839)
+++ branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/ServiceOperation.java 2010-02-18 16:21:36 UTC (rev 1840)
@@ -22,84 +22,58 @@
package org.teiid.connector.xmlsource.soap;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
import java.io.StringReader;
-import java.rmi.RemoteException;
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.Vector;
import javax.xml.transform.Source;
-import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.Dispatch;
-import org.apache.axis.client.Call;
-import org.apache.axis.encoding.ser.ElementDeserializerFactory;
-import org.apache.axis.encoding.ser.ElementSerializerFactory;
-import org.apache.axis.message.RPCElement;
-import org.apache.axis.message.SOAPBodyElement;
-import org.apache.axis.utils.XMLUtils;
-import org.apache.axis.wsdl.symbolTable.Parameter;
-import org.apache.axis.wsdl.symbolTable.Parameters;
-import org.apache.axis.wsdl.symbolTable.TypeEntry;
import org.teiid.connector.xmlsource.XMLSourcePlugin;
-import org.w3c.dom.Element;
+
/**
* Represents the operation of a service
*/
public class ServiceOperation {
private static final String DOCUMENT = "document"; //$NON-NLS-1$
- String name;
- Parameters parameters;
- Call stub;
- String portName;
- boolean usesComplexType = false;
- String style;
- SoapManagedConnectionFactory env;
+ private String name;
+ private String portName;
+ private String style;
+ private int queryTimeout;
+ private String endPoint;
+ private Dispatch<Source> dispatch;
+ private String targetNamespace;
- /**
- * ctor
- * @param name
- * @param parms
- */
- ServiceOperation(SoapManagedConnectionFactory env, String name, Parameters parms, String portName, String style) {
+ ServiceOperation(String name, String portName, String style, Dispatch<Source> dispatch, String targetNamespace) {
this.name = name;
- this.parameters = parms;
this.portName = portName;
this.style = style;
- this.env = env;
-
- // check the input parameters types if they are simple or complex
- // type;
- for (int i = 0; i < this.parameters.list.size(); i++) {
- Parameter p = (Parameter) this.parameters.list.get(i);
- TypeEntry type = p.getType();
- if (!type.isBaseType()) {
- this.usesComplexType = true;
- }
- }
+ this.dispatch = dispatch;
+ this.targetNamespace = targetNamespace;
}
+
+ String getName() {
+ return this.name;
+ }
- /**
- * A stub to procedure; for execution.
- * @param stub
- */
- void setStub(Call stub) {
- this.stub = stub;
+ int getQueryTimeout() {
+ return this.queryTimeout;
}
- int getQueryTimeout() {
- return this.env.getQueryTimeout();
+ void setQueryTimeout(int timeout) {
+ this.queryTimeout = timeout;
}
String getEndPoint() {
- return this.env.getEndPoint();
+ return this.endPoint;
}
+
+ void setEndPoint(String endPoint) {
+ this.endPoint = endPoint;
+ }
/**
* is this a doc literal service operation
@@ -114,96 +88,32 @@
* @param args - arguments to the service
* @return return value; null on void return
*/
- public Source execute(Object[] args, Map outs) throws ExcutionFailedException {
- Object doc = null;
- try {
- // If there is alternate endpoint use it.
- if (getEndPoint() != null && getEndPoint().length() > 0) {
- this.stub.setTargetEndpointAddress(getEndPoint());
+ public Source execute(Object[] args, SecurityToken token) throws ExcutionFailedException {
+ if (isDocLiteral()) {
+ if (args.length != 1) {
+ throw new ExcutionFailedException(XMLSourcePlugin.Util.getString("wrong_number_params", new Object[] {Integer.valueOf(1), Integer.valueOf(args.length)})); //$NON-NLS-1$
}
-
- // If query timeout is set use it
- if (getQueryTimeout() != -1) {
- this.stub.setTimeout(Integer.valueOf(getQueryTimeout()));
- }
-
- // check the param count of the submitted operation, in doc-literal
- // there should always be only one input
- if (isDocLiteral()) {
- if (args.length != 1) {
- throw new ExcutionFailedException(XMLSourcePlugin.Util.getString("wrong_number_params", new Object[] {Integer.valueOf(1), Integer.valueOf(args.length)})); //$NON-NLS-1$
- }
- }
- else {
- int requiredParamCount = this.stub.getOperation().getNumInParams();
- if (requiredParamCount != args.length) {
- throw new ExcutionFailedException(XMLSourcePlugin.Util.getString("wrong_number_params", new Object[] {Integer.valueOf(requiredParamCount), Integer.valueOf(args.length)})); //$NON-NLS-1$
- }
- }
+ }
+ else {
+ throw new ExcutionFailedException(XMLSourcePlugin.Util.getString("support_only_doc_literal")); //$NON-NLS-1$
+ }
+ return this.dispatch.invoke(buildRequest(args));
+ }
+
+ Source buildRequest(Object[] args){
+ StringBuilder sb = new StringBuilder();
+ sb.append("<tns1:").append(this.name);
+ sb.append(" xmlns:tns1=\"").append(this.targetNamespace).append("\">");
+
+ for (Object obj:args) {
+ sb.append(obj.toString());
+ }
+
+ sb.append("</tns1:").append(this.name).append(">");
- // set input types
- // if we are using complex types, since we do not know how to serialize
- // deserilize the objects, we need to pass them as the direct soap body
- // elements; this is useful for doc/litral stuff where we do not need to
- // put toghether soap envelope.
- boolean messageStyleInvoke = false;
- if (this.usesComplexType || isDocLiteral()) {
- ArrayList bodyElements = new ArrayList();
- for (int i = 0; i < args.length; i++) {
- // we may little sofisticated streamer here, but this will work for now.
- InputStream element = new ByteArrayInputStream(args[i].toString().getBytes());
- bodyElements.add(new SOAPBodyElement(element));
- }
- args = bodyElements.toArray(new Object[bodyElements.size()]);
- messageStyleInvoke = true;
- }
-
- // set output type; if it is complex type just use it as element object;
- Parameter returnParam = this.parameters.returnParam;
- if ( returnParam != null) {
- if(!returnParam.getType().isBaseType()) {
- this.stub.registerTypeMapping(org.w3c.dom.Element.class, returnParam.getType().getQName(), new ElementSerializerFactory(),new ElementDeserializerFactory());
- }
- }
-
- // invoke the service
- doc = this.stub.invoke(args);
- Map outputs = this.stub.getOutputParams();
- if(outputs != null) {
- outs.putAll(outputs);
- }
-
- // if the sevice is executed with message style, we would get back raw xml
- // in out message
- if (messageStyleInvoke) {
- doc = ((Vector)doc).get(0);
- }
-
- // if the result is an xml element convert into string
- if (doc instanceof RPCElement) {
- return new DOMSource((RPCElement)doc);
- }
- else if (doc instanceof Element) {
- return new DOMSource((Element)doc);
- }
-
- // if we executed a RPC service, and we received a scalar as output
- // then we need to wrap this in the xml type
- if (!isDocLiteral() && doc != null && returnParam != null
- && returnParam.getType().isBaseType()) {
- StringBuffer sb = new StringBuffer();
- sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><return type=\""); //$NON-NLS-1$
- sb.append(doc.getClass().getName());
- sb.append("\">"); //$NON-NLS-1$
- sb.append(XMLUtils.xmlEncodeString(doc.toString()));
- sb.append("</return>"); //$NON-NLS-1$
- return new StreamSource(new StringReader(sb.toString()));
- }
-
- } catch (RemoteException e) {
- throw new ExcutionFailedException(e);
- }
- return null;
+ System.out.println(sb.toString());
+
+ return new StreamSource(new StringReader(sb.toString()));
}
// marker class
Modified: branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapConnection.java
===================================================================
--- branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapConnection.java 2010-02-18 02:45:34 UTC (rev 1839)
+++ branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapConnection.java 2010-02-18 16:21:36 UTC (rev 1840)
@@ -22,31 +22,6 @@
package org.teiid.connector.xmlsource.soap;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Vector;
-
-import javax.wsdl.Binding;
-import javax.wsdl.BindingOperation;
-import javax.wsdl.Operation;
-import javax.wsdl.Port;
-import javax.wsdl.Service;
-import javax.wsdl.extensions.ExtensibilityElement;
-import javax.wsdl.extensions.soap.SOAPAddress;
-import javax.wsdl.extensions.soap.SOAPBinding;
-import javax.wsdl.extensions.soap.SOAPOperation;
-import javax.xml.namespace.QName;
-import javax.xml.rpc.ServiceException;
-
-import org.apache.axis.client.Call;
-import org.apache.axis.wsdl.gen.Parser;
-import org.apache.axis.wsdl.symbolTable.BindingEntry;
-import org.apache.axis.wsdl.symbolTable.Parameters;
-import org.apache.axis.wsdl.symbolTable.ServiceEntry;
-import org.apache.axis.wsdl.symbolTable.SymTabEntry;
-import org.apache.axis.wsdl.symbolTable.SymbolTable;
import org.teiid.connector.api.ConnectorException;
import org.teiid.connector.api.ExecutionContext;
import org.teiid.connector.api.ProcedureExecution;
@@ -57,7 +32,6 @@
import org.teiid.connector.language.IQuery;
import org.teiid.connector.language.IQueryCommand;
import org.teiid.connector.metadata.runtime.RuntimeMetadata;
-import org.teiid.connector.xmlsource.XMLSourcePlugin;
import com.metamatrix.connector.xml.IQueryPreprocessor;
@@ -68,25 +42,25 @@
*/
public class SoapConnection extends BasicConnection {
// instance variables
- boolean connected = false;
- SoapService service = null; // wsdl service
- Map operationsMap = new HashMap();
- SecurityToken securityToken = null;
+ private boolean connected = false;
+ private SoapService service = null; // wsdl service
private SoapManagedConnectionFactory config;
+ private SecurityToken securityToken;
/**
* @param env
* @throws ConnectorException
*/
- public SoapConnection(SoapManagedConnectionFactory env) throws ConnectorException {
+ public SoapConnection(SoapManagedConnectionFactory env, SoapService service, SecurityToken token) throws ConnectorException {
this.config = env;
- connect();
+ this.service = service;
+ this.securityToken = token;
}
@Override
public ProcedureExecution createProcedureExecution(IProcedure command, ExecutionContext executionContext, RuntimeMetadata metadata)
throws ConnectorException {
- return new SoapProcedureExecution(command, this.config, metadata, executionContext, this);
+ return new SoapProcedureExecution(command, this.config, metadata, executionContext, this.service, this.securityToken);
}
@Override
@@ -114,186 +88,5 @@
@Override
public void close() {
- disconnect();
- }
-
- void connect() throws ConnectorException {
- String wsdl = this.config.getWsdl();
- String portName = this.config.getPortName();
-
- // check if WSDL is supplied
- if (wsdl == null || wsdl.trim().length() == 0) {
- throw new ConnectorException(XMLSourcePlugin.Util.getString("wsdl_not_set")); //$NON-NLS-1$
- }
-
- try {
- this.config.getLogger().logDetail(XMLSourcePlugin.Util.getString("loading_wsdl", new Object[] {wsdl})); //$NON-NLS-1$
-
- // first parse the WSDL file
- Parser wsdlParser = new Parser();
- wsdlParser.run(wsdl);
-
- // Find the service from WSDL
- Service wsdlService = getService(wsdlParser.getSymbolTable());
-
- // WS-Security handler provider
- this.securityToken = SecurityToken.getSecurityToken(this.config, null);
-
- // now create a AXIS based service
- this.service = new SoapService(wsdlParser, wsdlService.getQName(), this.securityToken);
- Port port = selectPort(wsdlService.getPorts(), portName);
-
- // find all the available operations
- this.operationsMap = buildOperations(wsdlParser.getSymbolTable(), port);
-
- this.connected = true;
- } catch (Exception e) {
- throw new ConnectorException(e, XMLSourcePlugin.Util.getString("failed_loading_wsdl", new Object[] {wsdl})); //$NON-NLS-1$
- }
-
-
- }
-
- /**
- * Build a map of available operations in the WSDL
- * @param wsdlParser
- */
- private Map buildOperations(SymbolTable symbolTable, Port usePort) {
- HashMap map = new HashMap();
- Binding binding = usePort.getBinding();
- BindingEntry bEntry = symbolTable.getBindingEntry(binding.getQName());
-
- // find out from the soap binding style what type of service is this.
- // if the style is document then it is doc-litral
- String style = null;
- for (Iterator i = binding.getExtensibilityElements().iterator(); i.hasNext();) {
- final ExtensibilityElement extElement = (ExtensibilityElement)i.next();
- if (extElement instanceof SOAPBinding) {
- style = ((SOAPBinding)extElement).getStyle();
- }
- }
-
- // if the style not found on the binding then look for it on the operation.
- if (style == null) {
- for(Iterator i = binding.getBindingOperations().iterator(); i.hasNext();) {
- BindingOperation operation = (BindingOperation)i.next();
- List extElements = operation.getExtensibilityElements();
- for (final Iterator extIter = extElements.iterator(); extIter.hasNext();) {
- final ExtensibilityElement extElement = (ExtensibilityElement)extIter.next();
- if (extElement instanceof SOAPOperation) {
- style = ((SOAPOperation)extElement).getStyle();
- }
- } // for
- }
- }
-
- // now loop through all the available operations and make a note of them
- for (Iterator i = bEntry.getOperations().iterator(); i.hasNext();) {
- Operation operation = (Operation) i.next();
-
- Parameters parameters = bEntry.getParameters(operation);
-
- // create operation with the available details
- ServiceOperation so = new ServiceOperation(this.config, operation.getName(), parameters, usePort.getName(), style);
-
- // collect all the services available
- map.put(operation.getName(), so);
- }
-
- return map;
- }
-
- /**
- * disconnect the connection;
- */
- void disconnect() {
- this.connected = false;
- this.operationsMap.clear();
- }
-
- /**
- * Get system table entry from wsdl for given element.
- * @return
- */
- private Service getService(SymbolTable table) throws ServiceNotFoundException{
- Class serviceClazz = ServiceEntry.class;
- HashMap map = table.getHashMap();
- for (Iterator iter = map.values().iterator(); iter.hasNext();) {
- Vector v = (Vector) iter.next();
- for (int i = 0; i < v.size(); ++i) {
- SymTabEntry tabEntry = (SymTabEntry) v.elementAt(i);
- if (serviceClazz.isInstance(tabEntry)) {
- ServiceEntry serviceEntry = (ServiceEntry)tabEntry;
- return serviceEntry.getService();
- }
- }
- }
- throw new ServiceNotFoundException();
- }
-
- /**
- * Get Port to be used for the
- * @param ports
- * @param portName
- * @return
- * @throws Exception
- */
- private Port selectPort(Map ports, String portName) throws Exception {
- Iterator valueIterator = ports.keySet().iterator();
- while (valueIterator.hasNext()) {
- String name = (String) valueIterator.next();
-
- if ((portName == null) || (portName.length() == 0)) {
- Port port = (Port) ports.get(name);
- List list = port.getExtensibilityElements();
-
- for (int i = 0; (list != null) && (i < list.size()); i++) {
- Object obj = list.get(i);
- if (obj instanceof SOAPAddress) {
- return port;
- }
- }
- } else if ((name != null) && name.equals(portName)) {
- return (Port) ports.get(name);
- }
- }
- return null;
- }
-
- /**
- * Find the operation to execute
- * @param name
- * @return operation if found; exception otherwise
- * @throws OperationNotFoundException
- */
- public ServiceOperation findOperation(String procedureName) throws OperationNotFoundException{
-
- // Check the Operation Name
- ServiceOperation operation = (ServiceOperation)operationsMap.get(procedureName);
- if (operation == null) {
- throw new OperationNotFoundException(procedureName);
- }
- // now create a stub for the operation and set on the object.
- try {
- Call call = (Call)service.createCall(QName.valueOf(operation.portName), QName.valueOf(procedureName));
- securityToken.handleSecurity(call);
-
- // now assign this call to the operation object.
- operation.setStub(call);
- } catch (ServiceException e) {
- throw new OperationNotFoundException(e);
- }
- return operation;
- }
-
-
- //
- static class ServiceNotFoundException extends Exception{
- // nothing, just a marker
- }
- static class OperationNotFoundException extends Exception{
- public OperationNotFoundException(String e) {super(e);}
- public OperationNotFoundException(Throwable e) {super(e);}
- // nothing, just marker
- }
+ }
}
Modified: branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapConnector.java
===================================================================
--- branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapConnector.java 2010-02-18 02:45:34 UTC (rev 1839)
+++ branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapConnector.java 2010-02-18 16:21:36 UTC (rev 1840)
@@ -1,35 +1,88 @@
package org.teiid.connector.xmlsource.soap;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Set;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Service;
+import javax.wsdl.WSDLException;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+
import org.teiid.connector.api.Connection;
import org.teiid.connector.api.ConnectorCapabilities;
import org.teiid.connector.api.ConnectorEnvironment;
import org.teiid.connector.api.ConnectorException;
-import org.teiid.connector.api.ConnectorLogger;
import org.teiid.connector.basic.BasicConnector;
+import org.teiid.connector.xmlsource.XMLSourcePlugin;
public class SoapConnector extends BasicConnector {
private SoapManagedConnectionFactory config;
+ private SoapService service = null;
@Override
public void initialize(ConnectorEnvironment env) throws ConnectorException {
super.initialize(env);
this.config = (SoapManagedConnectionFactory)env;
+
+ String wsdl = this.config.getWsdl();
+ String portName = this.config.getPortName();
+ String serviceName = this.config.getServiceName();
+
+ // check if WSDL is supplied
+ if (wsdl == null || wsdl.trim().length() == 0) {
+ throw new ConnectorException(XMLSourcePlugin.Util.getString("wsdl_not_set")); //$NON-NLS-1$
+ }
+
+ this.config.getLogger().logDetail(XMLSourcePlugin.Util.getString("loading_wsdl", new Object[] {wsdl})); //$NON-NLS-1$
- ConnectorLogger logger = config.getLogger();
- logger.logInfo("Loaded for SoapConnector"); //$NON-NLS-1$
+ this.service = buildServiceStub(wsdl, serviceName, portName);
+
+ this.config.getLogger().logInfo("Loaded for SoapConnector"); //$NON-NLS-1$
}
public Connection getConnection() throws ConnectorException {
- return new SoapConnection(this.config);
+ return new SoapConnection(this.config, this.service, SecurityToken.getSecurityToken(this.config));
}
@Override
- public Class<? extends ConnectorCapabilities> getDefaultCapabilities() {
+ public Class<? extends ConnectorCapabilities> getDefaultCapabilities() {
return SoapSourceCapabilities.class;
}
+
+ private SoapService buildServiceStub(String wsdl, String serviceName, String portName) throws ConnectorException {
+ try {
+ // first parse the WSDL file
+ WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
+ Definition wsdlDefinition = wsdlReader.readWSDL(wsdl);
+
+
+ Map services = wsdlDefinition.getServices();
+ Service wsdlService = (Service)services.values().iterator().next();
+ if (serviceName != null) {
+ Set<String> keys = services.keySet();
+ for (String key:keys) {
+ if (key.equalsIgnoreCase(serviceName)) {
+ wsdlService = (Service)services.get(key);
+ }
+ }
+ }
+ return new SoapService(new URL(wsdl), wsdlService, portName, wsdlDefinition.getTargetNamespace());
+ } catch (WSDLException e) {
+ throw new ConnectorException(e, XMLSourcePlugin.Util.getString("failed_loading_wsdl", new Object[] {wsdl})); //$NON-NLS-1$
+ } catch (MalformedURLException e) {
+ throw new ConnectorException(e, XMLSourcePlugin.Util.getString("failed_loading_wsdl", new Object[] {wsdl})); //$NON-NLS-1$
+ }
+ }
+
+ SoapService getService() {
+ return this.service;
+ }
}
Modified: branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapManagedConnectionFactory.java
===================================================================
--- branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapManagedConnectionFactory.java 2010-02-18 02:45:34 UTC (rev 1839)
+++ branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapManagedConnectionFactory.java 2010-02-18 16:21:36 UTC (rev 1840)
@@ -146,6 +146,16 @@
this.portName = portName;
}
+ private String serviceName;
+
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
private int queryTimeout;
public int getQueryTimeout() {
Modified: branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapProcedureExecution.java
===================================================================
--- branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapProcedureExecution.java 2010-02-18 02:45:34 UTC (rev 1839)
+++ branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapProcedureExecution.java 2010-02-18 16:21:36 UTC (rev 1840)
@@ -46,23 +46,25 @@
public class SoapProcedureExecution extends BasicExecution implements ProcedureExecution {
// Connection object.
- SoapConnection connection;
+ SoapService service;
RuntimeMetadata metadata = null;
ExecutionContext context;
private IProcedure procedure;
private SoapManagedConnectionFactory env;
private boolean returnedResult;
private SQLXML returnValue;
+ private SecurityToken securityToken;
/**
* @param env
*/
- public SoapProcedureExecution(IProcedure procedure, SoapManagedConnectionFactory env, RuntimeMetadata metadata, ExecutionContext context, SoapConnection conn) {
- this.connection = conn;
+ public SoapProcedureExecution(IProcedure procedure, SoapManagedConnectionFactory env, RuntimeMetadata metadata, ExecutionContext context, SoapService service, SecurityToken securityToken) {
+ this.service = service;
this.metadata = metadata;
this.context = context;
this.procedure = procedure;
this.env = env;
+ this.securityToken = securityToken;
}
/**
@@ -70,7 +72,7 @@
*/
public void execute() throws ConnectorException {
- SoapRequest request = new SoapRequest(this.env, this.connection) {
+ SoapRequest request = new SoapRequest(this.env, this.service) {
@Override
protected String getProcedureName() {
@@ -97,6 +99,11 @@
}
return argsList;
}
+
+ @Override
+ protected SecurityToken getSecurityToken() {
+ return securityToken;
+ }
};
// execute the request
Modified: branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapRequest.java
===================================================================
--- branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapRequest.java 2010-02-18 02:45:34 UTC (rev 1839)
+++ branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapRequest.java 2010-02-18 16:21:36 UTC (rev 1840)
@@ -23,9 +23,7 @@
package org.teiid.connector.xmlsource.soap;
import java.sql.SQLXML;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import javax.xml.transform.Source;
@@ -33,7 +31,7 @@
import org.teiid.connector.api.ConnectorException;
import org.teiid.connector.xmlsource.XMLSourcePlugin;
import org.teiid.connector.xmlsource.soap.ServiceOperation.ExcutionFailedException;
-import org.teiid.connector.xmlsource.soap.SoapConnection.OperationNotFoundException;
+import org.teiid.connector.xmlsource.soap.SoapService.OperationNotFoundException;
@@ -43,22 +41,23 @@
public abstract class SoapRequest {
// Connection object.
- private SoapConnection connection;
- private Map outputValues = null;
private SoapManagedConnectionFactory env;
+ private SoapService service;
/**
* @param env
*/
- public SoapRequest(SoapManagedConnectionFactory env, SoapConnection conn) {
- this.connection = conn;
+ public SoapRequest(SoapManagedConnectionFactory env, SoapService service) {
this.env = env;
+ this.service = service;
}
protected abstract String getProcedureName();
protected abstract List getInputParameters();
+ protected abstract SecurityToken getSecurityToken();
+
/**
* @see org.teiid.connector.api.ProcedureExecution#execute(org.teiid.connector.language.IProcedure, int)
*/
@@ -82,21 +81,23 @@
Object[] args = argsList.toArray(new Object[argsList.size()]);
try {
- ServiceOperation operation = this.connection.findOperation(sourceProcedureName);
+ ServiceOperation operation = this.service.findOperation(sourceProcedureName);
- this.env.getLogger().logDetail(XMLSourcePlugin.Util.getString("service_execute", new Object[] {operation.name})); //$NON-NLS-1$
+ this.env.getLogger().logDetail(XMLSourcePlugin.Util.getString("service_execute", new Object[] {operation.getName()})); //$NON-NLS-1$
for (int i = 0; i < args.length; i++) {
this.env.getLogger().logDetail(XMLSourcePlugin.Util.getString( "service_params", new Object[] {args[i]})); //$NON-NLS-1$
}
- this.outputValues = new HashMap();
- Source returnValue = operation.execute(args, outputValues);
+ Source returnValue = operation.execute(args, getSecurityToken());
+
this.env.getLogger().logDetail(XMLSourcePlugin.Util.getString("xml_contents", new Object[] {returnValue})); //$NON-NLS-1$
+
return convertToXMLType(returnValue);
+
} catch (OperationNotFoundException e) {
throw new ConnectorException(e);
- } catch(ExcutionFailedException e) {
- throw new ConnectorException(e);
+ } catch (ExcutionFailedException e) {
+ throw new ConnectorException(e);
}
}
@@ -114,12 +115,4 @@
public List<?> getOutputParameterValues() throws ConnectorException {
throw new ConnectorException(XMLSourcePlugin.Util.getString("No_outputs_allowed")); //$NON-NLS-1$
}
-
- public void close() throws ConnectorException {
- // no-op
- }
-
- public void cancel() throws ConnectorException {
- // no-op
- }
}
Modified: branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapService.java
===================================================================
--- branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapService.java 2010-02-18 02:45:34 UTC (rev 1839)
+++ branches/JCA/connectors/connector-xmlsource-soap/src/main/java/org/teiid/connector/xmlsource/soap/SoapService.java 2010-02-18 16:21:36 UTC (rev 1840)
@@ -22,105 +22,136 @@
package org.teiid.connector.xmlsource.soap;
-import java.util.Hashtable;
+import java.net.URL;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import javax.wsdl.Binding;
+import javax.wsdl.BindingOperation;
+import javax.wsdl.Operation;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.extensions.soap.SOAPBinding;
+import javax.wsdl.extensions.soap.SOAPOperation;
import javax.xml.namespace.QName;
-import javax.xml.rpc.ServiceException;
+import javax.xml.transform.Source;
+import javax.xml.ws.Dispatch;
-import org.apache.axis.AxisEngine;
-import org.apache.axis.ConfigurationException;
-import org.apache.axis.EngineConfiguration;
-import org.apache.axis.Handler;
-import org.apache.axis.SimpleChain;
-import org.apache.axis.encoding.TypeMappingRegistry;
-import org.apache.axis.handlers.soap.SOAPService;
-import org.apache.axis.wsdl.gen.Parser;
-
/**
* This is SOAP Service which extends the Axis service call so that we can dynamically
* include the handlers into the request and response flows.
*/
-public class SoapService extends org.apache.axis.client.Service {
- SecurityToken securityToken;
+public class SoapService {
+ private URL wsdlLocation;
+ private Service wsdlService;
+ private Port port;
+ private String style;
+ private String targetnameSpace;
- public SoapService(Parser parser, QName serviceName, SecurityToken secToken) throws ServiceException {
- super(parser, serviceName);
- this.securityToken = secToken;
+ public SoapService(URL wsdlLocation, Service service, String portName, String namespace) {
+ this.wsdlService = service;
+ this.wsdlLocation = wsdlLocation;
+ this.port = selectPort(service.getPorts(), portName);
+ this.style = buildStyle(this.port);
+ this.targetnameSpace = namespace;
}
- @Override
- protected EngineConfiguration getEngineConfiguration() {
- EngineConfiguration config = super.getEngineConfiguration();
- return new ClientEngineConfiguration(config);
- }
-
+
+ public QName getServiceName() {
+ return this.wsdlService.getQName();
+ }
+
/**
- * Engine Configuration class which has the request and response flow handlers
+ * Get Port to be used for the
+ * @param ports
+ * @param portName
+ * @return
+ * @throws Exception
*/
- class ClientEngineConfiguration implements EngineConfiguration{
- EngineConfiguration config = null;
-
- public ClientEngineConfiguration(EngineConfiguration config) {
- this.config = config;
+ private Port selectPort(Map ports, String portName) {
+ Iterator valueIterator = ports.keySet().iterator();
+ while (valueIterator.hasNext()) {
+ String name = (String) valueIterator.next();
+
+ if ((portName == null) || (portName.length() == 0)) {
+ Port port = (Port) ports.get(name);
+ List list = port.getExtensibilityElements();
+
+ for (int i = 0; (list != null) && (i < list.size()); i++) {
+ Object obj = list.get(i);
+ if (obj instanceof SOAPAddress) {
+ return port;
+ }
+ }
+ } else if ((name != null) && name.equals(portName)) {
+ return (Port) ports.get(name);
+ }
}
+ return null;
+ }
+
+
+ /**
+ * Build a map of available operations in the WSDL
+ * @param wsdlParser
+ */
+ private String buildStyle(Port usePort) {
+ Binding binding = usePort.getBinding();
- public void configureEngine(AxisEngine engine) throws ConfigurationException {
- config.configureEngine(engine);
+ // find out from the soap binding style what type of service is this.
+ // if the style is document then it is doc-litral
+ String style = null;
+ for (Iterator i = binding.getExtensibilityElements().iterator(); i.hasNext();) {
+ final ExtensibilityElement extElement = (ExtensibilityElement)i.next();
+ if (extElement instanceof SOAPBinding) {
+ style = ((SOAPBinding)extElement).getStyle();
+ }
}
- public void writeEngineConfig(AxisEngine engine) throws ConfigurationException {
- config.writeEngineConfig(engine);
- }
-
- public Handler getHandler(QName name) throws ConfigurationException {
- return config.getHandler(name);
- }
-
- public SOAPService getService(QName name) throws ConfigurationException {
- return config.getService(name);
- }
-
- public SOAPService getServiceByNamespaceURI(String uri) throws ConfigurationException {
- return config.getServiceByNamespaceURI(uri);
- }
-
- public Handler getTransport(QName name) throws ConfigurationException {
- return config.getTransport(name);
- }
-
- public TypeMappingRegistry getTypeMappingRegistry() throws ConfigurationException {
- return config.getTypeMappingRegistry();
- }
-
- public Handler getGlobalRequest() throws ConfigurationException {
- SimpleChain requestHandler = (SimpleChain)config.getGlobalRequest();
- if (requestHandler == null) {
- requestHandler = new SimpleChain();
+ // if the style not found on the binding then look for it on the operation.
+ if (style == null) {
+ for(Iterator i = binding.getBindingOperations().iterator(); i.hasNext();) {
+ BindingOperation operation = (BindingOperation)i.next();
+ List extElements = operation.getExtensibilityElements();
+ for (final Iterator extIter = extElements.iterator(); extIter.hasNext();) {
+ final ExtensibilityElement extElement = (ExtensibilityElement)extIter.next();
+ if (extElement instanceof SOAPOperation) {
+ style = ((SOAPOperation)extElement).getStyle();
+ }
+ } // for
}
- // if the se
- if (securityToken instanceof WSSecurityToken) {
- requestHandler.addHandler(new org.apache.ws.axis.security.WSDoAllSender());
- }
- return requestHandler;
}
-
- public Handler getGlobalResponse() throws ConfigurationException {
- return config.getGlobalResponse();
- }
-
- public Hashtable getGlobalOptions() throws ConfigurationException {
- return config.getGlobalOptions();
- }
-
- public Iterator getDeployedServices() throws ConfigurationException {
- return config.getDeployedServices();
- }
-
- public List getRoles() {
- return config.getRoles();
- }
+ return style;
+ }
+
+ public ServiceOperation findOperation(String name) throws OperationNotFoundException {
+ Binding binding = this.port.getBinding();
+ List<BindingOperation> bindingOperations = binding.getBindingOperations();
+
+ for (BindingOperation bo:bindingOperations) {
+ Operation operation = bo.getOperation();
+ if (operation.getName().equals(name)) {
+ return new ServiceOperation(operation.getName(), this.port.getName(), this.style, createDispatch(), this.targetnameSpace);
+ }
+ }
+ throw new OperationNotFoundException(name);
}
+
+ private Dispatch<Source> createDispatch() {
+ // now create a stub for the operation and set on the object.
+ javax.xml.ws.Service executionService = javax.xml.ws.Service.create(this.wsdlLocation, this.wsdlService.getQName());
+ Dispatch<Source> dispatch = executionService.createDispatch(new QName(this.wsdlService.getQName().getNamespaceURI(), this.port.getName(), "teiid"), Source.class, javax.xml.ws.Service.Mode.PAYLOAD);
+ return dispatch;
+ }
+
+ static class OperationNotFoundException extends Exception{
+ public OperationNotFoundException(String e) {super(e);}
+ public OperationNotFoundException(Throwable e) {super(e);}
+ // nothing, just marker
+ }
+
}
\ No newline at end of file
Modified: branches/JCA/connectors/connector-xmlsource-soap/src/main/rar/META-INF/ra.xml
===================================================================
--- branches/JCA/connectors/connector-xmlsource-soap/src/main/rar/META-INF/ra.xml 2010-02-18 02:45:34 UTC (rev 1839)
+++ branches/JCA/connectors/connector-xmlsource-soap/src/main/rar/META-INF/ra.xml 2010-02-18 16:21:36 UTC (rev 1840)
@@ -156,6 +156,12 @@
<config-property-name>PortName</config-property-name>
<config-property-type>java.lang.String</config-property-type>
</config-property>
+
+ <config-property>
+ <description>{$display:"Service Name"}</description>
+ <config-property-name>ServiceName</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+ </config-property>
<config-property>
<description>{$display:"Query Timeout"}</description>
Modified: branches/JCA/connectors/connector-xmlsource-soap/src/main/resources/org/teiid/connector/xmlsource/i18n.properties
===================================================================
--- branches/JCA/connectors/connector-xmlsource-soap/src/main/resources/org/teiid/connector/xmlsource/i18n.properties 2010-02-18 02:45:34 UTC (rev 1839)
+++ branches/JCA/connectors/connector-xmlsource-soap/src/main/resources/org/teiid/connector/xmlsource/i18n.properties 2010-02-18 16:21:36 UTC (rev 1840)
@@ -54,4 +54,5 @@
No_such_auth_type=Requested Authorization support is currently not available:{0}; Or invalid type specified.
No_ws_security_type=Ws-Secuirty type selected for web service authentication, however the type of WS-Security being used not specified, Please provide "WSSecurityType" property in the connector binding properties
No_such_ws_security_type=The specified WS-Secuity type "{0}" is invalid or not currently supported, please correct the connector binding properties.
-XML_file_does_not_UTF8=XML File being read can not be converted to UTF-8 encoding.
\ No newline at end of file
+XML_file_does_not_UTF8=XML File being read can not be converted to UTF-8 encoding.
+support_only_doc_literal=Web service execution only supports DOC-Literal style of web services.
\ No newline at end of file
Modified: branches/JCA/connectors/connector-xmlsource-soap/src/test/java/com/metamatrix/connector/xmlsource/soap/service/StockQuotes.java
===================================================================
--- branches/JCA/connectors/connector-xmlsource-soap/src/test/java/com/metamatrix/connector/xmlsource/soap/service/StockQuotes.java 2010-02-18 02:45:34 UTC (rev 1839)
+++ branches/JCA/connectors/connector-xmlsource-soap/src/test/java/com/metamatrix/connector/xmlsource/soap/service/StockQuotes.java 2010-02-18 16:21:36 UTC (rev 1840)
@@ -26,11 +26,18 @@
/**
*/
public class StockQuotes {
-
- public String GetQuote(String symbol) throws Exception {
- if (symbol.equalsIgnoreCase("msft")) {//$NON-NLS-1$
+
+ public String GetSymbol(String name) throws Exception {
+ if (name.equalsIgnoreCase("Redhat")) {//$NON-NLS-1$
+ return "<symbol>RHT</symbol>"; //$NON-NLS-1$
+ }
+ throw new Exception("Invalid Symbol"); //$NON-NLS-1$
+ }
+
+ public String GetQuote(String foo) throws Exception {
+ if (foo.equalsIgnoreCase("msft")) {//$NON-NLS-1$
return "<company name=\"Microsoft Corp\">23.23</company>"; //$NON-NLS-1$
}
throw new Exception("Invalid Symbol"); //$NON-NLS-1$
- }
+ }
}
Deleted: branches/JCA/connectors/connector-xmlsource-soap/src/test/java/org/teiid/connector/xmlsource/soap/TestSoapConnection.java
===================================================================
--- branches/JCA/connectors/connector-xmlsource-soap/src/test/java/org/teiid/connector/xmlsource/soap/TestSoapConnection.java 2010-02-18 02:45:34 UTC (rev 1839)
+++ branches/JCA/connectors/connector-xmlsource-soap/src/test/java/org/teiid/connector/xmlsource/soap/TestSoapConnection.java 2010-02-18 16:21:36 UTC (rev 1840)
@@ -1,82 +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.connector.xmlsource.soap;
-
-import java.io.File;
-
-import junit.framework.TestCase;
-
-import org.mockito.Mockito;
-import org.teiid.connector.api.ConnectorException;
-import org.teiid.connector.api.ConnectorLogger;
-
-import com.metamatrix.core.util.UnitTestUtil;
-
-
-/**
- */
-public class TestSoapConnection extends TestCase{
-
- public void testNoWSDL() throws Exception {
- SoapManagedConnectionFactory env = Mockito.mock(SoapManagedConnectionFactory.class);
- Mockito.stub(env.getLogger()).toReturn(Mockito.mock(ConnectorLogger.class));
-
- try {
- new SoapConnection(env);
- fail("WSDL is not set; must have failed"); //$NON-NLS-1$
- } catch (ConnectorException e) {
- //pass
- }
- }
-
- public void testWSDLLoad() throws Exception {
- File wsdlFile = new File(UnitTestUtil.getTestDataPath()+"/stockquotes.xml"); //$NON-NLS-1$
-
- SoapManagedConnectionFactory env = Mockito.mock(SoapManagedConnectionFactory.class);
- Mockito.stub(env.getLogger()).toReturn(Mockito.mock(ConnectorLogger.class));
- Mockito.stub(env.getWsdl()).toReturn(wsdlFile.toURL().toString());
-
- SoapConnection conn = new SoapConnection(env);
- assertTrue(conn.isConnected());
- assertEquals("StockQuotes", conn.service.getServiceName().getLocalPart()); //$NON-NLS-1$
- assertTrue("Operation Not Found", conn.operationsMap.containsKey("GetQuote")); //$NON-NLS-1$ //$NON-NLS-2$
- assertFalse("Operation Should Not have Found", conn.operationsMap.containsKey("GetQuoteX")); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals(4, conn.operationsMap.size());
-
- // release connection
- conn.close();
- assertFalse(conn.isConnected());
- }
-
- public void testFindOperation() throws Exception {
- File wsdlFile = new File(UnitTestUtil.getTestDataPath()+"/stockquotes.xml"); //$NON-NLS-1$
-
- SoapManagedConnectionFactory env = Mockito.mock(SoapManagedConnectionFactory.class);
- Mockito.stub(env.getLogger()).toReturn(Mockito.mock(ConnectorLogger.class));
- Mockito.stub(env.getWsdl()).toReturn(wsdlFile.toURL().toString());
-
- SoapConnection conn = new SoapConnection(env);
- ServiceOperation operation = conn.findOperation("GetQuote"); //$NON-NLS-1$
- assertNotNull("failed to find the operation", operation); //$NON-NLS-1$
- }
-}
Copied: branches/JCA/connectors/connector-xmlsource-soap/src/test/java/org/teiid/connector/xmlsource/soap/TestSoapConnector.java (from rev 1826, branches/JCA/connectors/connector-xmlsource-soap/src/test/java/org/teiid/connector/xmlsource/soap/TestSoapConnection.java)
===================================================================
--- branches/JCA/connectors/connector-xmlsource-soap/src/test/java/org/teiid/connector/xmlsource/soap/TestSoapConnector.java (rev 0)
+++ branches/JCA/connectors/connector-xmlsource-soap/src/test/java/org/teiid/connector/xmlsource/soap/TestSoapConnector.java 2010-02-18 16:21:36 UTC (rev 1840)
@@ -0,0 +1,77 @@
+/*
+ * 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.connector.xmlsource.soap;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.fail;
+
+import java.io.File;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.teiid.connector.api.ConnectorException;
+import org.teiid.connector.api.ConnectorLogger;
+import org.teiid.connector.xmlsource.soap.SoapService.OperationNotFoundException;
+
+import com.metamatrix.core.util.UnitTestUtil;
+
+@Ignore
+public class TestSoapConnector {
+
+ @Test
+ public void testNoWSDL() throws Exception {
+ SoapManagedConnectionFactory env = Mockito.mock(SoapManagedConnectionFactory.class);
+ Mockito.stub(env.getLogger()).toReturn(Mockito.mock(ConnectorLogger.class));
+
+ try {
+ SoapConnector c = new SoapConnector();
+ c.initialize(env);
+ fail("WSDL is not set; must have failed"); //$NON-NLS-1$
+ } catch (ConnectorException e) {
+ //pass
+ }
+ }
+
+ @Test
+ public void testWSDLLoad() throws Exception {
+ File wsdlFile = new File(UnitTestUtil.getTestDataPath()+"/stockquotes.xml"); //$NON-NLS-1$
+
+ SoapManagedConnectionFactory env = Mockito.mock(SoapManagedConnectionFactory.class);
+ Mockito.stub(env.getLogger()).toReturn(Mockito.mock(ConnectorLogger.class));
+ Mockito.stub(env.getWsdl()).toReturn(wsdlFile.toURL().toString());
+
+ SoapConnector c = new SoapConnector();
+ c.initialize(env);
+
+ assertEquals("StockQuotes", c.getService().getServiceName().getLocalPart()); //$NON-NLS-1$
+ assertTrue("Operation Not Found", (c.getService().findOperation("GetQuote")!=null)); //$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ c.getService().findOperation("GetQuoteX");
+ fail("Operation Should Not have Found"); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch(OperationNotFoundException e) {
+
+ }
+ }
+}
Property changes on: branches/JCA/connectors/connector-xmlsource-soap/src/test/java/org/teiid/connector/xmlsource/soap/TestSoapConnector.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/JCA/connectors/connector-xmlsource-soap/src/test/java/org/teiid/connector/xmlsource/soap/TestSoapExecution.java
===================================================================
--- branches/JCA/connectors/connector-xmlsource-soap/src/test/java/org/teiid/connector/xmlsource/soap/TestSoapExecution.java 2010-02-18 02:45:34 UTC (rev 1839)
+++ branches/JCA/connectors/connector-xmlsource-soap/src/test/java/org/teiid/connector/xmlsource/soap/TestSoapExecution.java 2010-02-18 16:21:36 UTC (rev 1840)
@@ -33,6 +33,7 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.junit.Ignore;
import org.mockito.Mockito;
import org.teiid.connector.api.ConnectorException;
import org.teiid.connector.api.ExecutionContext;
@@ -47,9 +48,8 @@
import com.metamatrix.connector.xmlsource.soap.service.WebServiceServer;
import com.metamatrix.core.util.UnitTestUtil;
-
-/**
- */
+// All the security needs to redone using JBossWS-Native, until then do not run this class.
+@Ignore
public class TestSoapExecution extends TestCase {
private static WebServiceServer server = null;
@@ -69,6 +69,7 @@
}
public static void setUpOnce() throws Exception{
+ System.setProperty("javax.xml.transform.TransformerFactory", "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
server = new WebServiceServer();
server.startServer(7001);
}
@@ -127,7 +128,10 @@
SoapManagedConnectionFactory env = new SoapManagedConnectionFactory();
env.setLogWriter(Mockito.mock(PrintWriter.class));
env.setWsdl("http://localhost:7001/axis/services/StockQuotes?wsdl");
- String in = "<tns1:symbol xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:tns1=\"http://service.soap.xmlsource.connector.metamatrix.com\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">MSFT</tns1:symbol>"; //$NON-NLS-1$
+ //String in = "<tns1:symbol xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:tns1=\"http://service.soap.xmlsource.connector.metamatrix.com\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">MSFT</tns1:symbol>"; //$NON-NLS-1$
+ String in = "<symbol>MSFT</symbol>"; //$NON-NLS-1$
+
+ //String in = "<tns1:GetQuote xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:tns1=\"http://service.soap.xmlsource.connector.metamatrix.com\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"><symbol>MSFT</symbol></tns1:GetQuote>"; //$NON-NLS-1$
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><symbolReturn xmlns=\"http://service.soap.xmlsource.connector.metamatrix.com\"><company name=\"Microsoft Corp\">23.23</company></symbolReturn>"; //$NON-NLS-1$
executeSOAP("GetQuote", new Object[] {in}, env, expected); //$NON-NLS-1$
@@ -138,6 +142,20 @@
}
}
+ public void testDocLitralExecution2() throws Exception {
+ SoapManagedConnectionFactory env = new SoapManagedConnectionFactory();
+ env.setLogWriter(Mockito.mock(PrintWriter.class));
+ env.setWsdl("http://localhost:8080/teiid-ws/Echo?wsdl");
+ //String in = "<tns1:symbol xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:tns1=\"http://service.soap.xmlsource.connector.metamatrix.com\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">MSFT</tns1:symbol>"; //$NON-NLS-1$
+ String in = "<arg0>hello</arg0>"; //$NON-NLS-1$
+
+ //String in = "<tns1:GetQuote xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:tns1=\"http://service.soap.xmlsource.connector.metamatrix.com\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"><symbol>MSFT</symbol></tns1:GetQuote>"; //$NON-NLS-1$
+
+ String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><symbolReturn xmlns=\"http://service.soap.xmlsource.connector.metamatrix.com\"><company name=\"Microsoft Corp\">23.23</company></symbolReturn>"; //$NON-NLS-1$
+ executeSOAP("echo", new Object[] {in}, env, expected); //$NON-NLS-1$
+ // end of test
+ }
+
public void testRPCLitralExecution() throws Exception {
server.deployService(UnitTestUtil.getTestDataPath()+"/service/StockQuotes/rpc-literal-deploy.wsdd"); //$NON-NLS-1$
@@ -601,8 +619,10 @@
// utility method to execute a service
void executeSOAP(String procName, Object[] args, SoapManagedConnectionFactory env, String expected) throws Exception{
-
- SoapConnection conn = new SoapConnection(env);
+ SoapConnector connector = new SoapConnector();
+ connector.initialize(env);
+
+ SoapConnection conn =(SoapConnection) connector.getConnection();
RuntimeMetadata metadata = Mockito.mock(RuntimeMetadata.class);
ILanguageFactory fact = env.getLanguageFactory();
List parameters = new ArrayList();
13 years, 9 months
teiid SVN: r1839 - in trunk/connectors/connector-jdbc/src: main/java/org/teiid/connector/jdbc/translator and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-02-17 21:45:34 -0500 (Wed, 17 Feb 2010)
New Revision: 1839
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/LocateFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/LocateFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java
Log:
TEIID-988 correcting the locate position in the three argument form.
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/LocateFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/LocateFunctionModifier.java 2010-02-17 22:28:31 UTC (rev 1838)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/LocateFunctionModifier.java 2010-02-18 02:45:34 UTC (rev 1839)
@@ -29,6 +29,7 @@
import org.teiid.connector.language.IExpression;
import org.teiid.connector.language.IFunction;
import org.teiid.connector.language.ILanguageFactory;
+import org.teiid.connector.language.ILiteral;
public class LocateFunctionModifier extends org.teiid.connector.jdbc.translator.LocateFunctionModifier {
@@ -44,8 +45,29 @@
parts.add("position("); //$NON-NLS-1$
parts.add(params.get(0));
parts.add(" in "); //$NON-NLS-1$
+ boolean useSubStr = false;
if (params.size() == 3) {
+ useSubStr = true;
+ if (params.get(2) instanceof ILiteral && ((ILiteral)params.get(2)).getValue() instanceof Integer) {
+ Integer value = (Integer)((ILiteral)params.get(2)).getValue();
+ if (value > 1) {
+ ((ILiteral)params.get(2)).setValue(value - 1);
+ } else {
+ useSubStr = false;
+ }
+ }
+ }
+ if (useSubStr) {
+ parts.add(0, "("); //$NON-NLS-1$
parts.add(this.getLanguageFactory().createFunction("substr", params.subList(1, 3), TypeFacility.RUNTIME_TYPES.STRING)); //$NON-NLS-1$
+ parts.add(")"); //$NON-NLS-1$
+ parts.add(" + "); //$NON-NLS-1$
+ if (params.get(2) instanceof ILiteral && ((ILiteral)params.get(2)).getValue() instanceof Integer) {
+ parts.add(params.get(2));
+ } else {
+ parts.add(params.get(2));
+ parts.add(" - 1"); //$NON-NLS-1$
+ }
} else {
parts.add(params.get(1));
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/LocateFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/LocateFunctionModifier.java 2010-02-17 22:28:31 UTC (rev 1838)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/LocateFunctionModifier.java 2010-02-18 02:45:34 UTC (rev 1839)
@@ -160,7 +160,7 @@
private IExpression ensurePositiveStartIndex(IExpression startIndex) {
if (startIndex instanceof ILiteral) {
ILiteral literal = (ILiteral)startIndex;
- if (literal.getValue() != null && ((Integer)literal.getValue() < 1)) {
+ if (literal.getValue() instanceof Integer && ((Integer)literal.getValue() < 1)) {
literal.setValue(1);
}
} else {
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java 2010-02-17 22:28:31 UTC (rev 1838)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java 2010-02-18 02:45:34 UTC (rev 1839)
@@ -412,7 +412,7 @@
*/
@Test public void testLocate() throws Exception {
String input = "SELECT locate(INTNUM, 'chimp', 1) FROM BQT1.SMALLA"; //$NON-NLS-1$
- String output = "SELECT position(cast(SmallA.IntNum AS varchar(4000)) in substr('chimp', 1)) FROM SmallA"; //$NON-NLS-1$
+ String output = "SELECT position(cast(SmallA.IntNum AS varchar(4000)) in 'chimp') FROM SmallA"; //$NON-NLS-1$
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB,
input, output,
@@ -446,7 +446,7 @@
*/
@Test public void testLocate3() throws Exception {
String input = "SELECT locate(INTNUM, '234567890', 1) FROM BQT1.SMALLA WHERE INTKEY = 26"; //$NON-NLS-1$
- String output = "SELECT position(cast(SmallA.IntNum AS varchar(4000)) in substr('234567890', 1)) FROM SmallA WHERE SmallA.IntKey = 26"; //$NON-NLS-1$
+ String output = "SELECT position(cast(SmallA.IntNum AS varchar(4000)) in '234567890') FROM SmallA WHERE SmallA.IntKey = 26"; //$NON-NLS-1$
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB,
input, output,
@@ -480,7 +480,7 @@
*/
@Test public void testLocate5() throws Exception {
String input = "SELECT locate(STRINGNUM, 'chimp', -5) FROM BQT1.SMALLA"; //$NON-NLS-1$
- String output = "SELECT position(SmallA.StringNum in substr('chimp', 1)) FROM SmallA"; //$NON-NLS-1$
+ String output = "SELECT position(SmallA.StringNum in 'chimp') FROM SmallA"; //$NON-NLS-1$
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB,
input, output,
@@ -497,7 +497,7 @@
*/
@Test public void testLocate6() throws Exception {
String input = "SELECT locate(STRINGNUM, 'chimp', INTNUM) FROM BQT1.SMALLA"; //$NON-NLS-1$
- String output = "SELECT position(SmallA.StringNum in substr('chimp', CASE WHEN SmallA.IntNum < 1 THEN 1 ELSE SmallA.IntNum END)) FROM SmallA"; //$NON-NLS-1$
+ String output = "SELECT (position(SmallA.StringNum in substr('chimp', CASE WHEN SmallA.IntNum < 1 THEN 1 ELSE SmallA.IntNum END)) + CASE WHEN SmallA.IntNum < 1 THEN 1 ELSE SmallA.IntNum END - 1) FROM SmallA"; //$NON-NLS-1$
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB,
input, output,
@@ -514,7 +514,7 @@
*/
@Test public void testLocate7() throws Exception {
String input = "SELECT locate(STRINGNUM, 'chimp', LOCATE(STRINGNUM, 'chimp') + 1) FROM BQT1.SMALLA"; //$NON-NLS-1$
- String output = "SELECT position(SmallA.StringNum in substr('chimp', CASE WHEN (position(SmallA.StringNum in 'chimp') + 1) < 1 THEN 1 ELSE (position(SmallA.StringNum in 'chimp') + 1) END)) FROM SmallA"; //$NON-NLS-1$
+ String output = "SELECT (position(SmallA.StringNum in substr('chimp', CASE WHEN (position(SmallA.StringNum in 'chimp') + 1) < 1 THEN 1 ELSE (position(SmallA.StringNum in 'chimp') + 1) END)) + CASE WHEN (position(SmallA.StringNum in 'chimp') + 1) < 1 THEN 1 ELSE (position(SmallA.StringNum in 'chimp') + 1) END - 1) FROM SmallA"; //$NON-NLS-1$
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB,
input, output,
13 years, 9 months
teiid SVN: r1838 - branches/JCA/console.
by teiid-commits@lists.jboss.org
Author: tejones
Date: 2010-02-17 17:28:31 -0500 (Wed, 17 Feb 2010)
New Revision: 1838
Modified:
branches/JCA/console/pom.xml
Log:
TEIID-807: Added metrics for Platform component
Modified: branches/JCA/console/pom.xml
===================================================================
--- branches/JCA/console/pom.xml 2010-02-17 21:30:14 UTC (rev 1837)
+++ branches/JCA/console/pom.xml 2010-02-17 22:28:31 UTC (rev 1838)
@@ -19,6 +19,7 @@
<org.jboss.jopr.as4.version>1.2.0.GA</org.jboss.jopr.as4.version>
-->
<org.jboss.jopr.as5.version>1.2.0.GA</org.jboss.jopr.as5.version>
+ <org.rhq.version>1.3.0.GA</org.rhq.version>
<org.jboss.jopr.version>1.2.0.GA</org.jboss.jopr.version>
@@ -211,7 +212,7 @@
<dependency>
<groupId>org.rhq</groupId>
<artifactId>rhq-core-domain</artifactId>
- <version>${org.jboss.jopr.version}</version>
+ <version>${org.rhq.version}</version>
<scope>provided</scope>
<!--
provided by the agent/plugin-container
@@ -222,21 +223,21 @@
<dependency>
<groupId>org.rhq</groupId>
<artifactId>rhq-core-plugin-api</artifactId>
- <version>${org.jboss.jopr.version}</version>
+ <version>${org.rhq.version}</version>
<scope>provided</scope> <!-- provided by the agent/plugin-container -->
</dependency>
<dependency>
<groupId>org.rhq</groupId>
<artifactId>rhq-core-native-system</artifactId>
- <version>${org.jboss.jopr.version}</version>
+ <version>${org.rhq.version}</version>
<scope>provided</scope> <!-- provided by the agent/plugin-container -->
</dependency>
<dependency>
<groupId>org.rhq</groupId>
<artifactId>rhq-jmx-plugin</artifactId>
- <version>${org.jboss.jopr.version}</version>
+ <version>${org.rhq.version}</version>
</dependency>
<dependency>
@@ -304,12 +305,13 @@
<artifactId>teiid-common-core</artifactId>
<type>test-jar</type>
</dependency>
+ <dependency>
+ <groupId>org.jboss.jopr</groupId>
+ <artifactId>jopr-embedded-jbas5</artifactId>
+ <type>war</type>
+ <version>${org.jboss.jopr.as5.version}</version>
+ </dependency>
- <!--
- <dependency> <groupId>org.jboss.jopr</groupId>
- <artifactId>jopr-embedded-jbas4</artifactId> <type>war</type>
- <version>${org.jboss.jopr.as4.version}</version> </dependency>
- -->
<dependency>
<groupId>org.jboss.jopr</groupId>
<artifactId>jopr-embedded-jbas5</artifactId>
@@ -328,7 +330,17 @@
<artifactId>ant</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ <!-- <dependency>
+ <groupId>org.jboss.on</groupId>
+ <artifactId>jopr-jboss-as-5-plugin</artifactId>
+ <version>2.3.0.EmbJopr.1.2.0-1</version>
+ </dependency> -->
</dependencies>
13 years, 9 months
teiid SVN: r1837 - trunk/test-integration/db/src/main/java/org/teiid/test/client.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2010-02-17 16:30:14 -0500 (Wed, 17 Feb 2010)
New Revision: 1837
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/TestResultsSummary.java
Log:
Teiid-773 - change delimiter used in the the results summary file when printing the test errors
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/TestResultsSummary.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/TestResultsSummary.java 2010-02-17 18:42:42 UTC (rev 1836)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/TestResultsSummary.java 2010-02-17 21:30:14 UTC (rev 1837)
@@ -40,6 +40,7 @@
import org.teiid.test.framework.ConfigPropertyLoader;
import org.teiid.test.framework.TestLogger;
+import org.teiid.test.util.StringUtil;
public class TestResultsSummary {
@@ -226,7 +227,9 @@
case TestResult.RESULT_STATE.TEST_EXCEPTION:
++fail;
- this.failed_queries.add(stat.getQueryID() + "~" + stat.getExceptionMsg());
+ String msg = StringUtil.removeChars(stat.getExceptionMsg(), new char[] {'\r', '\n'});
+
+ this.failed_queries.add(stat.getQueryID() + "~" + msg);
break;
case TestResult.RESULT_STATE.TEST_SUCCESS:
++pass;
13 years, 9 months
teiid SVN: r1836 - branches/JCA/connector-api.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2010-02-17 13:42:42 -0500 (Wed, 17 Feb 2010)
New Revision: 1836
Modified:
branches/JCA/connector-api/pom.xml
Log:
Removing unnecessary dependency
Modified: branches/JCA/connector-api/pom.xml
===================================================================
--- branches/JCA/connector-api/pom.xml 2010-02-16 23:14:59 UTC (rev 1835)
+++ branches/JCA/connector-api/pom.xml 2010-02-17 18:42:42 UTC (rev 1836)
@@ -27,13 +27,6 @@
</dependency>
<dependency>
- <groupId>org.jboss.teiid</groupId>
- <artifactId>teiid-common-internal</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
-
- <dependency>
<groupId>javax.resource</groupId>
<artifactId>connector-api</artifactId>
<scope>provided</scope>
13 years, 9 months