Author: shawkins
Date: 2010-06-08 15:11:59 -0400 (Tue, 08 Jun 2010)
New Revision: 2202
Added:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/ws/
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/ws/SAXFilterProvider.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/ws/XMLExecutionFactory.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/ws/XMLProcedureExecution.java
Removed:
trunk/api/src/main/java/org/teiid/translator/MetadataProvider.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/CartesienCriteriaGenerator.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/CompositeExecution.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/Constants.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/CriteriaDesc.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/DocumentBuilder.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/ExecutionInfo.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/FileProcedureExecution.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/FileResultSetExecution.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/IDGeneratingXmlFilter.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/OutputXPathDesc.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/ParameterDescriptor.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/QueryAnalyzer.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/RequestGenerator.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/RequestPreprocessor.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/SAXFilterProvider.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/StremableDocument.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/XMLExecutionFactory.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/XMLPlugin.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/XMLProcedureExecution.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/MockQueryPreprocessor.java
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/ProxyObjectFactory.java
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestCartesianCriteriaGenerator.java
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestCriteriaDesc.java
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestElementCollector.java
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestExecutionInfo.java
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestOutputXPathDesc.java
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestParameterDescriptor.java
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestQueryAnalyzer.java
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestXMLCapabilities.java
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestXMLReaderFactory.java
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestXPathSplitter.java
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/file/
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/streaming/
trunk/engine/src/test/java/org/teiid/query/xquery/
Modified:
trunk/api/src/main/java/org/teiid/language/SQLConstants.java
trunk/api/src/main/java/org/teiid/resource/spi/BasicConnection.java
trunk/api/src/main/java/org/teiid/resource/spi/BasicManagedConnection.java
trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java
trunk/common-core/src/main/java/org/teiid/core/types/InputStreamFactory.java
trunk/common-core/src/main/java/org/teiid/core/types/SQLXMLImpl.java
trunk/common-core/src/main/java/org/teiid/core/types/XMLType.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToSQLXMLTransform.java
trunk/connectors/connector-salesforce/src/main/java/org/teiid/resource/adapter/salesforce/SalesforceConnectionImpl.java
trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnection.java
trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSManagedConnectionFactory.java
trunk/connectors/sandbox/translator-yahoo/src/main/java/org/teiid/translator/yahoo/YahooExecutionFactory.java
trunk/connectors/translator-file/src/test/java/org/teiid/translator/file/TestFileExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCBaseExecution.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPExecutionFactory.java
trunk/connectors/translator-loopback/src/main/java/org/teiid/translator/loopback/LoopbackExecutionFactory.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesforceConnection.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/AbstractUpdateExecution.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/QueryExecutionImpl.java
trunk/connectors/translator-xml/pom.xml
trunk/connectors/translator-xml/src/main/resources/org/teiid/translator/xml/i18n.properties
trunk/documentation/reference/src/main/docbook/en-US/content/datatypes.xml
trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml
trunk/documentation/reference/src/main/docbook/en-US/content/sql_support.xml
trunk/engine/pom.xml
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorManager.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItem.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java
trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java
trunk/engine/src/main/java/org/teiid/query/function/source/SystemSource.java
trunk/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/XMLTable.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLQuery.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java
trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
trunk/engine/src/main/resources/org/teiid/query/i18n.properties
trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/FakeConnector.java
trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java
trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
trunk/pom.xml
trunk/runtime/src/test/java/org/teiid/deployers/TestTranslatorUtil.java
trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/MockConnector.java
Log:
TEIID-1087 TEIID-171 TEIID-1005 TEIID-1114 refining xmltable/xmlquery (removing the
returing clause) and updating the docs, updating reserved words to 2006 sql/xml, initial
removal of xml/relational, and changing the model of connectionfactory/connection
interaction with the execution factory.
Modified: trunk/api/src/main/java/org/teiid/language/SQLConstants.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/SQLConstants.java 2010-06-08 18:36:09 UTC
(rev 2201)
+++ trunk/api/src/main/java/org/teiid/language/SQLConstants.java 2010-06-08 19:11:59 UTC
(rev 2202)
@@ -340,15 +340,22 @@
public static final String XMLAGG = "XMLAGG"; //$NON-NLS-1$
public static final String XMLATTRIBUTES = "XMLATTRIBUTES"; //$NON-NLS-1$
public static final String XMLBINARY = "XMLBINARY"; //$NON-NLS-1$
+ public static final String XMLCAST = "XMLCAST"; //$NON-NLS-1$
+ public static final String XMLCOMMENT = "XMLCOMMENT"; //$NON-NLS-1$
public static final String XMLCONCAT = "XMLCONCAT"; //$NON-NLS-1$
- public static final String XMLCOMMENT = "XMLCOMMENT"; //$NON-NLS-1$
+ public static final String XMLDOCUMENT = "XMLDOCUMENT"; //$NON-NLS-1$
public static final String XMLELEMENT = "XMLELEMENT"; //$NON-NLS-1$
+ public static final String XMLEXISTS = "XMLEXISTS"; //$NON-NLS-1$
public static final String XMLFOREST = "XMLFOREST"; //$NON-NLS-1$
+ public static final String XMLITERATE = "XMLITERATE"; //$NON-NLS-1$
public static final String XMLNAMESPACES = "XMLNAMESPACES"; //$NON-NLS-1$
public static final String XMLPARSE = "XMLPARSE"; //$NON-NLS-1$
public static final String XMLPI = "XMLPI"; //$NON-NLS-1$
- public static final String XMLROOT = "XMLROOT"; //$NON-NLS-1$
+ public static final String XMLQUERY = "XMLQUERY"; //$NON-NLS-1$
public static final String XMLSERIALIZE = "XMLSERIALIZE"; //$NON-NLS-1$
+ public static final String XMLTABLE = "XMLTABLE"; //$NON-NLS-1$
+ public static final String XMLTEXT = "XMLTEXT"; //$NON-NLS-1$
+ public static final String XMLVALIDATE = "XMLVALIDATE"; //$NON-NLS-1$
//SQL/MED
Modified: trunk/api/src/main/java/org/teiid/resource/spi/BasicConnection.java
===================================================================
--- trunk/api/src/main/java/org/teiid/resource/spi/BasicConnection.java 2010-06-08
18:36:09 UTC (rev 2201)
+++ trunk/api/src/main/java/org/teiid/resource/spi/BasicConnection.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -27,6 +27,7 @@
import javax.resource.cci.Interaction;
import javax.resource.cci.LocalTransaction;
import javax.resource.cci.ResultSetInfo;
+import javax.resource.spi.ManagedConnection;
public abstract class BasicConnection implements Connection {
@@ -50,8 +51,20 @@
throw new ResourceException("This operation not supported"); //$NON-NLS-1$
}
+ /**
+ * Tests the connection to see if it is still valid.
+ * @return
+ */
public boolean isAlive() {
return true;
}
+
+ /**
+ * Called by the {@link ManagedConnection} to indicate the physical connection
+ * should be cleaned up for reuse.
+ */
+ public void cleanUp() {
+
+ }
}
Modified: trunk/api/src/main/java/org/teiid/resource/spi/BasicManagedConnection.java
===================================================================
--- trunk/api/src/main/java/org/teiid/resource/spi/BasicManagedConnection.java 2010-06-08
18:36:09 UTC (rev 2201)
+++ trunk/api/src/main/java/org/teiid/resource/spi/BasicManagedConnection.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -67,6 +67,9 @@
}
handles.clear();
}
+ if (this.physicalConnection != null) {
+ this.physicalConnection.cleanUp();
+ }
ConnectionContext.setSubject(null);
}
Modified: trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java
===================================================================
--- trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2010-06-08 18:36:09
UTC (rev 2201)
+++ trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2010-06-08 19:11:59
UTC (rev 2202)
@@ -25,6 +25,10 @@
import java.util.Collection;
import java.util.List;
+import javax.resource.ResourceException;
+import javax.resource.cci.Connection;
+import javax.resource.cci.ConnectionFactory;
+
import org.teiid.core.TeiidException;
import org.teiid.core.util.ReflectionHelper;
import org.teiid.language.BatchedUpdates;
@@ -33,6 +37,9 @@
import org.teiid.language.LanguageFactory;
import org.teiid.language.QueryExpression;
import org.teiid.language.SetQuery;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.RuntimeMetadata;
@@ -43,7 +50,7 @@
* The deployer instantiates this class through reflection. So it is important to have
no-arg constructor. Once constructed
* the "start" method is called. This class represents the basic capabilities
of the translator.
*/
-public class ExecutionFactory {
+public class ExecutionFactory<F, C> {
public enum SupportedJoinCriteria {
/**
@@ -112,6 +119,54 @@
}
/**
+ * Return a connection object from the given connection factory.
+ *
+ * The default implementation assumes a JCA {@link ConnectionFactory}. Subclasses
should override, if they use
+ * another type of connection factory.
+ *
+ * @param factory
+ * @return
+ * @throws TranslatorException
+ */
+ @SuppressWarnings("unchecked")
+ public C getConnection(F factory) throws TranslatorException {
+ if (factory == null) {
+ return null;
+ }
+ if (factory instanceof ConnectionFactory) {
+ try {
+ return (C) ((ConnectionFactory)factory).getConnection();
+ } catch (ResourceException e) {
+ throw new TranslatorException(e);
+ }
+ }
+ throw new AssertionError("A connection factory was supplied, but no implementation
was provided getConnection"); //$NON-NLS-1$
+ }
+
+ /**
+ * Closes a connection object from the given connection factory.
+ *
+ * The default implementation assumes a JCA {@link Connection}. Subclasses should
override, if they use
+ * another type of connection.
+ *
+ * @param connection
+ * @param factory
+ */
+ public void closeConnection(C connection, F factory) {
+ if (connection == null) {
+ return;
+ }
+ if (connection instanceof Connection) {
+ try {
+ ((Connection)connection).close();
+ } catch (ResourceException e) {
+ LogManager.logDetail(LogConstants.CTX_CONNECTOR, e, "Error closing");
//$NON-NLS-1$
+ }
+ }
+ throw new AssertionError("A connection was created, but no implementation provided
for closeConnection"); //$NON-NLS-1$
+ }
+
+ /**
* Throw exception if there are more rows in the result set than specified in the
MaxResultRows setting.
* @return
*/
@@ -188,28 +243,28 @@
* @param connection connection factory object to the data source
* @return An execution object that can use to execute the command
*/
- public Execution createExecution(Command command, ExecutionContext executionContext,
RuntimeMetadata metadata, Object connectionFactory) throws TranslatorException {
+ public Execution createExecution(Command command, ExecutionContext executionContext,
RuntimeMetadata metadata, C connection) throws TranslatorException {
if (command instanceof QueryExpression) {
- return createResultSetExecution((QueryExpression)command, executionContext, metadata,
connectionFactory);
+ return createResultSetExecution((QueryExpression)command, executionContext, metadata,
connection);
}
if (command instanceof Call) {
- return createProcedureExecution((Call)command, executionContext, metadata,
connectionFactory);
+ return createProcedureExecution((Call)command, executionContext, metadata,
connection);
}
- return createUpdateExecution(command, executionContext, metadata, connectionFactory);
+ return createUpdateExecution(command, executionContext, metadata, connection);
}
@SuppressWarnings("unused")
- public ResultSetExecution createResultSetExecution(QueryExpression command,
ExecutionContext executionContext, RuntimeMetadata metadata, Object connectionFactory)
throws TranslatorException {
+ public ResultSetExecution createResultSetExecution(QueryExpression command,
ExecutionContext executionContext, RuntimeMetadata metadata, C connection) throws
TranslatorException {
throw new TranslatorException("Unsupported Execution"); //$NON-NLS-1$
}
@SuppressWarnings("unused")
- public ProcedureExecution createProcedureExecution(Call command, ExecutionContext
executionContext, RuntimeMetadata metadata, Object connectionFactory) throws
TranslatorException {
+ public ProcedureExecution createProcedureExecution(Call command, ExecutionContext
executionContext, RuntimeMetadata metadata, C connection) throws TranslatorException {
throw new TranslatorException("Unsupported Execution");//$NON-NLS-1$
}
@SuppressWarnings("unused")
- public UpdateExecution createUpdateExecution(Command command, ExecutionContext
executionContext, RuntimeMetadata metadata, Object connectionFactory) throws
TranslatorException {
+ public UpdateExecution createUpdateExecution(Command command, ExecutionContext
executionContext, RuntimeMetadata metadata, C connection) throws TranslatorException {
throw new TranslatorException("Unsupported Execution");//$NON-NLS-1$
}
@@ -690,7 +745,7 @@
return false;
}
- public static <T> T getInstance(Class<T> expectedType, String className,
Collection ctorObjs, Class defaultClass) throws TranslatorException {
+ public static <T> T getInstance(Class<T> expectedType, String className,
Collection<?> ctorObjs, Class<? extends T> defaultClass) throws
TranslatorException {
try {
if (className == null) {
if (defaultClass == null) {
@@ -706,5 +761,16 @@
} catch(InstantiationException e) {
throw new TranslatorException(e);
}
- }
+ }
+
+ /**
+ * Implement to provide metadata to the metadata for use by the engine. This is the
+ * primary method of creating metadata for dynamic VDBs.
+ * @param metadataFactory
+ * @param conn
+ * @throws TranslatorException
+ */
+ public void getMetadata(MetadataFactory metadataFactory, C conn) throws
TranslatorException {
+
+ }
}
Deleted: trunk/api/src/main/java/org/teiid/translator/MetadataProvider.java
===================================================================
--- trunk/api/src/main/java/org/teiid/translator/MetadataProvider.java 2010-06-08 18:36:09
UTC (rev 2201)
+++ trunk/api/src/main/java/org/teiid/translator/MetadataProvider.java 2010-06-08 19:11:59
UTC (rev 2202)
@@ -1,31 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator;
-
-import org.teiid.metadata.MetadataFactory;
-
-public interface MetadataProvider {
-
- void getConnectorMetadata(MetadataFactory metadataFactory, Object connectionFactory)
throws TranslatorException;
-
-}
Modified: trunk/common-core/src/main/java/org/teiid/core/types/InputStreamFactory.java
===================================================================
---
trunk/common-core/src/main/java/org/teiid/core/types/InputStreamFactory.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/common-core/src/main/java/org/teiid/core/types/InputStreamFactory.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -94,13 +94,13 @@
private File f;
public FileInputStreamFactory(File f) {
- super();
- this.f = f;
+ this(f, Charset.defaultCharset().displayName());
}
public FileInputStreamFactory(File f, String encoding) {
super(encoding);
this.f = f;
+ this.setSystemId(f.toURI().toASCIIString());
}
@Override
Modified: trunk/common-core/src/main/java/org/teiid/core/types/SQLXMLImpl.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/SQLXMLImpl.java 2010-06-08
18:36:09 UTC (rev 2201)
+++ trunk/common-core/src/main/java/org/teiid/core/types/SQLXMLImpl.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -73,7 +73,7 @@
@SuppressWarnings("unchecked")
public <T extends Source> T getSource(Class<T> sourceClass) throws
SQLException {
if (sourceClass == null || sourceClass == StreamSource.class) {
- return (T)new StreamSource(getBinaryStream());
+ return (T)new StreamSource(getBinaryStream(), this.getStreamFactory().getSystemId());
}
throw new SQLException("Unsupported source type " + sourceClass);
//$NON-NLS-1$
}
Modified: trunk/common-core/src/main/java/org/teiid/core/types/XMLType.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/XMLType.java 2010-06-08 18:36:09
UTC (rev 2201)
+++ trunk/common-core/src/main/java/org/teiid/core/types/XMLType.java 2010-06-08 19:11:59
UTC (rev 2202)
@@ -46,7 +46,7 @@
public final class XMLType extends Streamable<SQLXML> implements SQLXML {
public enum Type {
- UNKNOWN, DOCUMENT, FRAGMENT, SEQUENCE, COMMENT, PI, TEXT
+ UNKNOWN, DOCUMENT, CONTENT, ELEMENT, COMMENT, PI, TEXT
}
private static final long serialVersionUID = -7922647237095135723L;
Modified:
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToSQLXMLTransform.java
===================================================================
---
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToSQLXMLTransform.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToSQLXMLTransform.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -59,7 +59,7 @@
}
public static Type isXml(Reader reader) throws TransformationException {
- Type type = Type.FRAGMENT;
+ Type type = Type.ELEMENT;
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
try{
XMLEventReader xmlReader = inputFactory.createXMLEventReader(reader);
Modified:
trunk/connectors/connector-salesforce/src/main/java/org/teiid/resource/adapter/salesforce/SalesforceConnectionImpl.java
===================================================================
---
trunk/connectors/connector-salesforce/src/main/java/org/teiid/resource/adapter/salesforce/SalesforceConnectionImpl.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/connector-salesforce/src/main/java/org/teiid/resource/adapter/salesforce/SalesforceConnectionImpl.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -90,7 +90,7 @@
}
private void login(String username, String password, URL url, int timeout) throws
ResourceException {
- if (!isAlive()) {
+ if (!isValid()) {
LoginResult loginResult = null;
sfSoap = null;
sfService = null;
@@ -137,7 +137,7 @@
}
- public boolean isAlive() {
+ public boolean isValid() {
boolean result = true;
if(sfSoap == null) {
result = false;
Modified:
trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnection.java
===================================================================
---
trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnection.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnection.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -39,6 +39,10 @@
public WSConnection(WSManagedConnectionFactory mcf) {
this.mcf = mcf;
+ createDelegate();
+ }
+
+ private void createDelegate() {
if (mcf.getInvocationType() == WSManagedConnectionFactory.InvocationType.HTTP_GET) {
this.delegate = createHTTPDispatch("GET"); //$NON-NLS-1$
}
@@ -189,4 +193,11 @@
public void close() throws ResourceException {
this.delegate = null;
}
+
+ @Override
+ public void cleanUp() {
+ //recreate to ensure the proper state
+ //this isn't really a heavy-weight operation
+ createDelegate();
+ }
}
Modified:
trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSManagedConnectionFactory.java
===================================================================
---
trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSManagedConnectionFactory.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSManagedConnectionFactory.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -42,7 +42,7 @@
private String wsSecurityConfigName; // ws-security config name in the above file
private String authPassword; // httpbasic - password
private String authUserName; // httpbasic - username
- private String xmlParamName;
+ private String xmlParamName; // used only in the http get invocation
@Override
public Object createConnectionFactory() throws ResourceException {
Modified:
trunk/connectors/sandbox/translator-yahoo/src/main/java/org/teiid/translator/yahoo/YahooExecutionFactory.java
===================================================================
---
trunk/connectors/sandbox/translator-yahoo/src/main/java/org/teiid/translator/yahoo/YahooExecutionFactory.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/sandbox/translator-yahoo/src/main/java/org/teiid/translator/yahoo/YahooExecutionFactory.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -34,7 +34,7 @@
import org.teiid.translator.ExecutionFactory;
import org.teiid.translator.ResultSetExecution;
@Translator(name="yahoo")
-public class YahooExecutionFactory extends ExecutionFactory {
+public class YahooExecutionFactory extends ExecutionFactory<Object, Object> {
public static final int YAHOO_MAX_SET_SIZE = 100;
Modified:
trunk/connectors/translator-file/src/test/java/org/teiid/translator/file/TestFileExecutionFactory.java
===================================================================
---
trunk/connectors/translator-file/src/test/java/org/teiid/translator/file/TestFileExecutionFactory.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-file/src/test/java/org/teiid/translator/file/TestFileExecutionFactory.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -27,8 +27,6 @@
import java.io.File;
import java.util.Arrays;
-import javax.resource.cci.ConnectionFactory;
-
import org.junit.Test;
import org.mockito.Mockito;
import org.teiid.core.util.UnitTestUtil;
@@ -45,12 +43,10 @@
@Test public void testGetTextFiles() throws Exception {
FileExecutionFactory fef = new FileExecutionFactory();
- ConnectionFactory cf = Mockito.mock(ConnectionFactory.class);
FileConnection fc = Mockito.mock(FileConnection.class);
- Mockito.stub(cf.getConnection()).toReturn(fc);
Mockito.stub(fc.getFile("*.txt")).toReturn(new
File(UnitTestUtil.getTestDataPath(), "*.txt"));
Call call = fef.getLanguageFactory().createCall("getTextFiles",
Arrays.asList(new Argument(Direction.IN, new Literal("*.txt",
TypeFacility.RUNTIME_TYPES.STRING), TypeFacility.RUNTIME_TYPES.STRING, null)), null);
- ProcedureExecution pe = fef.createProcedureExecution(call, null, null, cf);
+ ProcedureExecution pe = fef.createProcedureExecution(call, null, null, fc);
pe.execute();
int count = 0;
while (true) {
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCBaseExecution.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCBaseExecution.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCBaseExecution.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -131,15 +131,7 @@
}
} catch (SQLException e) {
LogManager.logDetail(LogConstants.CTX_CONNECTOR, e, "Exception closing");
//$NON-NLS-1$
- } finally {
- try {
- if (connection != null) {
- connection.close();
- }
- } catch (SQLException e) {
- LogManager.logDetail(LogConstants.CTX_CONNECTOR, e, "Exception
closing"); //$NON-NLS-1$
- }
- }
+ }
}
/*
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -60,14 +60,13 @@
import org.teiid.logging.LogManager;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.RuntimeMetadata;
-import org.teiid.translator.Translator;
-import org.teiid.translator.TranslatorException;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.ExecutionFactory;
-import org.teiid.translator.MetadataProvider;
import org.teiid.translator.ProcedureExecution;
import org.teiid.translator.ResultSetExecution;
import org.teiid.translator.SourceSystemFunctions;
+import org.teiid.translator.Translator;
+import org.teiid.translator.TranslatorException;
import org.teiid.translator.TranslatorProperty;
import org.teiid.translator.TypeFacility;
import org.teiid.translator.UpdateExecution;
@@ -77,7 +76,7 @@
* JDBC implementation of Connector interface.
*/
@Translator(name="jdbc-ansi")
-public class JDBCExecutionFactory extends ExecutionFactory implements MetadataProvider {
+public class JDBCExecutionFactory extends ExecutionFactory<DataSource, Connection>
{
public static final int DEFAULT_MAX_IN_CRITERIA = 1000;
@@ -221,64 +220,54 @@
}
@Override
- public ResultSetExecution createResultSetExecution(QueryExpression command,
ExecutionContext executionContext, RuntimeMetadata metadata, Object connectionFactory)
+ public ResultSetExecution createResultSetExecution(QueryExpression command,
ExecutionContext executionContext, RuntimeMetadata metadata, Connection conn)
throws TranslatorException {
- try {
- DataSource ds = (DataSource)connectionFactory;
- Connection conn = ds.getConnection();
- //TODO: This is not correct; this should be only called once for connection
creation
- afterConnectionCreation(conn);
- return new JDBCQueryExecution(command, conn, executionContext, this);
- } catch(SQLException e) {
- throw new TranslatorException(e);
- }
+ //TODO: This is not correct; this should be only called once for connection creation
+ afterConnectionCreation(conn);
+ return new JDBCQueryExecution(command, conn, executionContext, this);
}
@Override
- public ProcedureExecution createProcedureExecution(Call command, ExecutionContext
executionContext, RuntimeMetadata metadata, Object connectionFactory)
+ public ProcedureExecution createProcedureExecution(Call command, ExecutionContext
executionContext, RuntimeMetadata metadata, Connection conn)
throws TranslatorException {
- try {
- DataSource ds = (DataSource)connectionFactory;
- Connection conn = ds.getConnection();
- //TODO: This is not correct; this should be only called once for connection creation
- afterConnectionCreation(conn);
- return new JDBCProcedureExecution(command, conn, executionContext, this);
+ //TODO: This is not correct; this should be only called once for connection creation
+ afterConnectionCreation(conn);
+ return new JDBCProcedureExecution(command, conn, executionContext, this);
+ }
+
+ @Override
+ public UpdateExecution createUpdateExecution(Command command, ExecutionContext
executionContext, RuntimeMetadata metadata, Connection conn)
+ throws TranslatorException {
+ //TODO: This is not correct; this should be only called once for connection creation
+ afterConnectionCreation(conn);
+ return new JDBCUpdateExecution(command, conn, executionContext, this);
+ }
+
+ @Override
+ public Connection getConnection(DataSource ds)
+ throws TranslatorException {
+ try {
+ return ds.getConnection();
} catch (SQLException e) {
throw new TranslatorException(e);
}
}
-
+
@Override
- public UpdateExecution createUpdateExecution(Command command, ExecutionContext
executionContext, RuntimeMetadata metadata, Object connectionFactory)
- throws TranslatorException {
+ public void closeConnection(Connection connection, DataSource factory) {
try {
- DataSource ds = (DataSource)connectionFactory;
- Connection conn = ds.getConnection();
-
- //TODO: This is not correct; this should be only called once for connection creation
- afterConnectionCreation(conn);
- return new JDBCUpdateExecution(command, conn, executionContext, this);
+ connection.close();
} catch (SQLException e) {
- throw new TranslatorException(e);
- }
- }
+ LogManager.logDetail(LogConstants.CTX_CONNECTOR, e, "Error closing");
//$NON-NLS-1$
+ }
+ }
@Override
- public void getConnectorMetadata(MetadataFactory metadataFactory, Object
connectionFactory) throws TranslatorException {
+ public void getMetadata(MetadataFactory metadataFactory, Connection conn) throws
TranslatorException {
try {
- Connection conn = null;
- try {
- DataSource ds = (DataSource)connectionFactory;
- conn = ds.getConnection();
-
- JDBCMetdataProcessor metadataProcessor = new JDBCMetdataProcessor();
- PropertiesUtils.setBeanProperties(metadataProcessor,
metadataFactory.getImportProperties(), "importer"); //$NON-NLS-1$
- metadataProcessor.getConnectorMetadata(conn, metadataFactory);
- } finally {
- if (conn != null) {
- conn.close();
- }
- }
+ JDBCMetdataProcessor metadataProcessor = new JDBCMetdataProcessor();
+ PropertiesUtils.setBeanProperties(metadataProcessor,
metadataFactory.getImportProperties(), "importer"); //$NON-NLS-1$
+ metadataProcessor.getConnectorMetadata(conn, metadataFactory);
} catch (SQLException e) {
throw new TranslatorException(e);
}
Modified:
trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPExecutionFactory.java
===================================================================
---
trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPExecutionFactory.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPExecutionFactory.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -22,18 +22,17 @@
package org.teiid.translator.ldap;
import javax.naming.ldap.LdapContext;
-import javax.resource.ResourceException;
import javax.resource.cci.ConnectionFactory;
import org.teiid.language.Command;
import org.teiid.language.QueryExpression;
import org.teiid.language.Select;
import org.teiid.metadata.RuntimeMetadata;
-import org.teiid.translator.Translator;
-import org.teiid.translator.TranslatorException;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.ExecutionFactory;
import org.teiid.translator.ResultSetExecution;
+import org.teiid.translator.Translator;
+import org.teiid.translator.TranslatorException;
import org.teiid.translator.TranslatorProperty;
import org.teiid.translator.UpdateExecution;
@@ -43,7 +42,7 @@
* a connection factory, and obtaining connections to LDAP.
*/
@Translator(name="ldap")
-public class LDAPExecutionFactory extends ExecutionFactory {
+public class LDAPExecutionFactory extends ExecutionFactory<ConnectionFactory,
LdapContext> {
public enum SearchDefaultScope {
SUBTREE_SCOPE,
@@ -83,25 +82,15 @@
}
@Override
- public ResultSetExecution createResultSetExecution(QueryExpression
command,ExecutionContext executionContext, RuntimeMetadata metadata, Object
connectionFactory)
+ public ResultSetExecution createResultSetExecution(QueryExpression
command,ExecutionContext executionContext, RuntimeMetadata metadata, LdapContext context)
throws TranslatorException {
- try {
- ConnectionFactory cf = (ConnectionFactory)connectionFactory;
- return new LDAPSyncQueryExecution((Select)command, this,
(LdapContext)cf.getConnection());
- } catch (ResourceException e) {
- throw new TranslatorException(e);
- }
+ return new LDAPSyncQueryExecution((Select)command, this, context);
}
@Override
- public UpdateExecution createUpdateExecution(Command command,ExecutionContext
executionContext, RuntimeMetadata metadata, Object connectionFactory)
+ public UpdateExecution createUpdateExecution(Command command,ExecutionContext
executionContext, RuntimeMetadata metadata, LdapContext context)
throws TranslatorException {
- try {
- ConnectionFactory cf = (ConnectionFactory)connectionFactory;
- return new LDAPUpdateExecution(command, (LdapContext)cf.getConnection());
- } catch (ResourceException e) {
- throw new TranslatorException(e);
- }
+ return new LDAPUpdateExecution(command, context);
}
@Override
Modified:
trunk/connectors/translator-loopback/src/main/java/org/teiid/translator/loopback/LoopbackExecutionFactory.java
===================================================================
---
trunk/connectors/translator-loopback/src/main/java/org/teiid/translator/loopback/LoopbackExecutionFactory.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-loopback/src/main/java/org/teiid/translator/loopback/LoopbackExecutionFactory.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -38,7 +38,7 @@
* Loopback translator.
*/
@Translator(name="loopback")
-public class LoopbackExecutionFactory extends ExecutionFactory {
+public class LoopbackExecutionFactory extends ExecutionFactory<Object, Object> {
private int waitTime = 0;
private int rowCount = 1;
@@ -53,6 +53,11 @@
setSupportsInnerJoins(true);
}
+ @Override
+ public Object getConnection(Object factory) throws TranslatorException {
+ return null;
+ }
+
@TranslatorProperty(display="Max Random Wait Time", advanced=true)
public int getWaitTime() {
return waitTime;
@@ -95,7 +100,7 @@
}
@Override
- public Execution createExecution(Command command, ExecutionContext executionContext,
RuntimeMetadata metadata, Object connectionfactory)
+ public Execution createExecution(Command command, ExecutionContext executionContext,
RuntimeMetadata metadata, Object connection)
throws TranslatorException {
return new LoopbackExecution(command, this);
}
Modified:
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java
===================================================================
---
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -25,6 +25,8 @@
import java.util.ArrayList;
import java.util.List;
+import javax.resource.cci.ConnectionFactory;
+
import org.teiid.language.Call;
import org.teiid.language.Command;
import org.teiid.language.QueryExpression;
@@ -32,13 +34,12 @@
import org.teiid.logging.LogManager;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.RuntimeMetadata;
-import org.teiid.translator.Translator;
-import org.teiid.translator.TranslatorException;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.ExecutionFactory;
-import org.teiid.translator.MetadataProvider;
import org.teiid.translator.ProcedureExecution;
import org.teiid.translator.ResultSetExecution;
+import org.teiid.translator.Translator;
+import org.teiid.translator.TranslatorException;
import org.teiid.translator.TranslatorProperty;
import org.teiid.translator.UpdateExecution;
import org.teiid.translator.salesforce.execution.DeleteExecutionImpl;
@@ -48,7 +49,7 @@
import org.teiid.translator.salesforce.execution.UpdateExecutionImpl;
@Translator(name="salesforce")
-public class SalesForceExecutionFactory extends ExecutionFactory implements
MetadataProvider {
+public class SalesForceExecutionFactory extends ExecutionFactory<ConnectionFactory,
SalesforceConnection> {
private String connectorStateClass;
private boolean auditModelFields = false;
@@ -85,33 +86,33 @@
@Override
- public ResultSetExecution createResultSetExecution(QueryExpression command,
ExecutionContext executionContext, RuntimeMetadata metadata, Object connectionFactory)
+ public ResultSetExecution createResultSetExecution(QueryExpression command,
ExecutionContext executionContext, RuntimeMetadata metadata, SalesforceConnection
connection)
throws TranslatorException {
- return new QueryExecutionImpl(command, (SalesforceConnection)connectionFactory,
metadata, executionContext);
+ return new QueryExecutionImpl(command, connection, metadata, executionContext);
}
@Override
- public UpdateExecution createUpdateExecution(Command command, ExecutionContext
executionContext, RuntimeMetadata metadata, Object connectionFactory) throws
TranslatorException {
+ public UpdateExecution createUpdateExecution(Command command, ExecutionContext
executionContext, RuntimeMetadata metadata, SalesforceConnection connection) throws
TranslatorException {
UpdateExecution result = null;
if(command instanceof org.teiid.language.Delete) {
- result = new DeleteExecutionImpl(command, (SalesforceConnection)connectionFactory,
metadata, executionContext);
+ result = new DeleteExecutionImpl(command, connection, metadata, executionContext);
} else if (command instanceof org.teiid.language.Insert) {
- result = new InsertExecutionImpl(command, (SalesforceConnection)connectionFactory,
metadata, executionContext);
+ result = new InsertExecutionImpl(command, connection, metadata, executionContext);
} else if (command instanceof org.teiid.language.Update) {
- result = new UpdateExecutionImpl(command, (SalesforceConnection)connectionFactory,
metadata, executionContext);
+ result = new UpdateExecutionImpl(command, connection, metadata, executionContext);
}
return result;
}
@Override
- public ProcedureExecution createProcedureExecution(Call command,ExecutionContext
executionContext, RuntimeMetadata metadata, Object connectionFactory)
+ public ProcedureExecution createProcedureExecution(Call command,ExecutionContext
executionContext, RuntimeMetadata metadata, SalesforceConnection connection)
throws TranslatorException {
- return new ProcedureExecutionParentImpl(command,
(SalesforceConnection)connectionFactory, metadata, executionContext);
+ return new ProcedureExecutionParentImpl(command, connection, metadata,
executionContext);
}
@Override
- public void getConnectorMetadata(MetadataFactory metadataFactory, Object
connectionFactory) throws TranslatorException {
- MetadataProcessor processor = new
MetadataProcessor((SalesforceConnection)connectionFactory,metadataFactory, this);
+ public void getMetadata(MetadataFactory metadataFactory, SalesforceConnection
connection) throws TranslatorException {
+ MetadataProcessor processor = new MetadataProcessor(connection,metadataFactory, this);
processor.processMetadata();
}
Modified:
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesforceConnection.java
===================================================================
---
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesforceConnection.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesforceConnection.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -41,7 +41,7 @@
public QueryResult queryMore(String queryLocator, int batchSize) throws
ResourceException;
- public boolean isAlive();
+ public boolean isValid();
public int delete(String[] ids) throws ResourceException ;
Modified:
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/AbstractUpdateExecution.java
===================================================================
---
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/AbstractUpdateExecution.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/AbstractUpdateExecution.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -72,11 +72,6 @@
@Override
public void close() {
- try {
- connection.close();
- } catch (ResourceException e) {
- LogManager.logDetail(LogConstants.CTX_CONNECTOR, e, "Exception closing");
//$NON-NLS-1$
- }
}
@Override
Modified:
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/QueryExecutionImpl.java
===================================================================
---
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/QueryExecutionImpl.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/QueryExecutionImpl.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -109,11 +109,6 @@
public void close() {
LogManager.logDetail(LogConstants.CTX_CONNECTOR,
Messages.getString("SalesforceQueryExecutionImpl.close")); //$NON-NLS-1$
- try {
- connection.close();
- } catch (ResourceException e) {
- LogManager.logDetail(LogConstants.CTX_CONNECTOR, e, "Exception closing");
//$NON-NLS-1$
- }
}
@Override
Modified: trunk/connectors/translator-xml/pom.xml
===================================================================
--- trunk/connectors/translator-xml/pom.xml 2010-06-08 18:36:09 UTC (rev 2201)
+++ trunk/connectors/translator-xml/pom.xml 2010-06-08 19:11:59 UTC (rev 2202)
@@ -42,18 +42,6 @@
<artifactId>connector-api</artifactId>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>xom</groupId>
- <artifactId>xom</artifactId>
- <version>1.2</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>nux</groupId>
- <artifactId>nux</artifactId>
- <version>1.6</version>
- <scope>provided</scope>
- </dependency>
</dependencies>
<build>
Added:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/ws/SAXFilterProvider.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/ws/SAXFilterProvider.java
(rev 0)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/ws/SAXFilterProvider.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.translator.ws;
+
+import org.xml.sax.XMLFilter;
+
+public interface SAXFilterProvider {
+ XMLFilter[] getExtendedFilters();
+}
Added:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/ws/XMLExecutionFactory.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/ws/XMLExecutionFactory.java
(rev 0)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/ws/XMLExecutionFactory.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -0,0 +1,145 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.translator.ws;
+
+import java.sql.SQLXML;
+import java.util.Collections;
+import java.util.List;
+
+import javax.resource.cci.ConnectionFactory;
+import javax.xml.transform.Source;
+import javax.xml.ws.Dispatch;
+
+import org.teiid.core.BundleUtil;
+import org.teiid.language.Call;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.logging.MessageLevel;
+import org.teiid.metadata.MetadataFactory;
+import org.teiid.metadata.Procedure;
+import org.teiid.metadata.ProcedureParameter;
+import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.metadata.BaseColumn.NullType;
+import org.teiid.metadata.ProcedureParameter.Type;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.ExecutionFactory;
+import org.teiid.translator.ProcedureExecution;
+import org.teiid.translator.Translator;
+import org.teiid.translator.TranslatorException;
+import org.teiid.translator.TranslatorProperty;
+import org.teiid.translator.TypeFacility;
+
+@Translator(name="ws")
+public class XMLExecutionFactory extends ExecutionFactory<ConnectionFactory,
Dispatch<Source>> {
+
+ public static BundleUtil UTIL = BundleUtil.getBundleUtil(XMLExecutionFactory.class);
+
+ private String saxFilterProviderClass;
+ private String encoding = "ISO-8859-1"; //$NON-NLS-1$
+ private boolean logRequestResponseDocs = false;
+
+ @TranslatorProperty(description="Encoding of the XML documents",
display="Encoding Scheme")
+ public String getCharacterEncodingScheme() {
+ return this.encoding;
+ }
+
+ public void setCharacterEncodingScheme(String encoding) {
+ this.encoding = encoding;
+ }
+
+ @TranslatorProperty(description="Must be extension of
org.teiid.translator.xml.SAXFilterProvider class", display="SAX Filter Provider
Class")
+ public String getSaxFilterProviderClass() {
+ return this.saxFilterProviderClass;
+ }
+
+ public void setSaxFilterProviderClass(String saxFilterProviderClass) {
+ this.saxFilterProviderClass = saxFilterProviderClass;
+ }
+
+ // Can we get rid of this?
+ private String inputStreamFilterClass;
+
+ public String getInputStreamFilterClass() {
+ return this.inputStreamFilterClass;
+ }
+
+ public void setInputStreamFilterClass(String inputStreamFilterClass) {
+ this.inputStreamFilterClass = inputStreamFilterClass;
+ }
+
+ @TranslatorProperty(description="Log the XML request/response documents",
display="Log Request/Response Documents")
+ public boolean isLogRequestResponseDocs() {
+ return logRequestResponseDocs &&
LogManager.isMessageToBeRecorded(LogConstants.CTX_CONNECTOR, MessageLevel.DETAIL);
+ }
+
+ public void setLogRequestResponseDocs(boolean logRequestResponseDocs) {
+ this.logRequestResponseDocs = logRequestResponseDocs;
+ }
+
+ @Override
+ public ProcedureExecution createProcedureExecution(Call command, ExecutionContext
executionContext, RuntimeMetadata metadata, Dispatch<Source> connection)
+ throws TranslatorException {
+ return new XMLProcedureExecution(command, metadata, executionContext, this,
connection);
+ }
+
+ public SAXFilterProvider getSaxFilterProvider() throws TranslatorException {
+ if (getSaxFilterProviderClass() == null) {
+ return null;
+ }
+ return getInstance(SAXFilterProvider.class, getSaxFilterProviderClass(), null, null);
+ }
+
+ public SQLXML convertToXMLType(Source value) {
+ /*XMLReader reader = XMLReaderFactory.createXMLReader();
+
+ if (getSaxFilterProvider() != null) {
+ XMLFilter[] filters = getSaxFilterProvider().getExtendedFilters();
+ for(int i = 0; i < filters.length; i++) {
+ XMLFilter filter = filters[i];
+ filter.setParent(reader);
+ reader = filter;
+ }
+ }
+
+ SAXSource saxSource = new SAXSource(reader, inputSource);*/
+
+ return (SQLXML)getTypeFacility().convertToRuntimeType(value);
+ }
+
+ @Override
+ public final List getSupportedFunctions() {
+ return Collections.EMPTY_LIST;
+ }
+
+ @Override
+ public void getMetadata(MetadataFactory metadataFactory,
+ Dispatch<Source> conn) throws TranslatorException {
+ Procedure p = metadataFactory.addProcedure("invoke"); //$NON-NLS-1$
+ metadataFactory.addProcedureParameter("request",
TypeFacility.RUNTIME_NAMES.OBJECT, Type.In, p); //$NON-NLS-1$
+ ProcedureParameter param = metadataFactory.addProcedureParameter("endpoint",
TypeFacility.RUNTIME_NAMES.STRING, Type.In, p); //$NON-NLS-1$
+ param.setNullType(NullType.Nullable);
+ param = metadataFactory.addProcedureParameter("soapaction",
TypeFacility.RUNTIME_NAMES.STRING, Type.In, p); //$NON-NLS-1$
+ param.setNullType(NullType.Nullable);
+ }
+
+}
Added:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/ws/XMLProcedureExecution.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/ws/XMLProcedureExecution.java
(rev 0)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/ws/XMLProcedureExecution.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -0,0 +1,154 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.translator.ws;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.sql.Clob;
+import java.sql.SQLException;
+import java.sql.SQLXML;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.Dispatch;
+
+import org.teiid.core.types.ClobType;
+import org.teiid.language.Argument;
+import org.teiid.language.Call;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.translator.DataNotAvailableException;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.ProcedureExecution;
+import org.teiid.translator.TranslatorException;
+
+/**
+ * A soap call executor - handles all styles doc/literal, rpc/encoded etc.
+ */
+public class XMLProcedureExecution implements ProcedureExecution {
+
+ RuntimeMetadata metadata;
+ ExecutionContext context;
+ private Call procedure;
+ private boolean returnedResult;
+ private SQLXML returnValue;
+ private Dispatch<Source> dispatch;
+ private XMLExecutionFactory executionFactory;
+
+ /**
+ * @param env
+ */
+ public XMLProcedureExecution(Call procedure, RuntimeMetadata metadata,
ExecutionContext context, XMLExecutionFactory executionFactory, Dispatch<Source>
dispatch) {
+ this.metadata = metadata;
+ this.context = context;
+ this.procedure = procedure;
+ this.dispatch = dispatch;
+ this.executionFactory = executionFactory;
+ }
+
+ /**
+ * @see
org.teiid.connector.api.ProcedureExecution#execute(org.teiid.connector.language.Call,
int)
+ */
+ public void execute() throws TranslatorException {
+ List<Argument> arguments = this.procedure.getArguments();
+
+ Object docObject = (Object)arguments.get(0).getArgumentValue().getValue();
+ Source source = null;
+ try {
+ if (docObject instanceof SQLXML) {
+ SQLXML xml = (SQLXML)docObject;
+ source = xml.getSource(null);
+ if (executionFactory.isLogRequestResponseDocs()) {
+ LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Request " +
xml.getString()); //$NON-NLS-1$
+ }
+ } else if (docObject instanceof Clob) {
+ Clob clob = (Clob)docObject;
+ source = new StreamSource(clob.getCharacterStream());
+ if (executionFactory.isLogRequestResponseDocs()) {
+ try {
+ LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Request " +
ClobType.getString(clob)); //$NON-NLS-1$
+ } catch (IOException e) {
+ }
+ }
+ } else if (docObject instanceof String) {
+ String string = (String)docObject;
+ source = new StreamSource(new StringReader(string));
+ if (executionFactory.isLogRequestResponseDocs()) {
+ LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Request " + string);
//$NON-NLS-1$
+ }
+ } else if (docObject != null) {
+ throw new TranslatorException("Unknown document type, should be one of
XML, CLOB, String");
+ }
+ } catch (SQLException e) {
+ throw new TranslatorException(e);
+ }
+
+ String endpoint = (String)arguments.get(1).getArgumentValue().getValue();
+ String soapAction = (String)arguments.get(2).getArgumentValue().getValue();
+
+ if (soapAction != null) {
+ dispatch.getRequestContext().put(Dispatch.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
+ dispatch.getRequestContext().put(Dispatch.SOAPACTION_URI_PROPERTY, soapAction);
+ }
+
+ if (endpoint != null) {
+ this.dispatch.getRequestContext().put(Dispatch.ENDPOINT_ADDRESS_PROPERTY, endpoint);
+ }
+
+ // execute the request
+ Source result = this.dispatch.invoke(source);
+ this.returnValue = this.executionFactory.convertToXMLType(result);
+ if (executionFactory.isLogRequestResponseDocs()) {
+ try {
+ LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Response " +
this.returnValue.getString()); //$NON-NLS-1$
+ } catch (SQLException e) {
+ }
+ }
+ }
+
+ @Override
+ public List<?> next() throws TranslatorException, DataNotAvailableException {
+ if (!returnedResult) {
+ returnedResult = true;
+ return Arrays.asList(this.returnValue);
+ }
+ return null;
+ }
+
+ @Override
+ public List<?> getOutputParameterValues() throws TranslatorException {
+ return Collections.emptyList();
+ }
+
+ public void close() {
+
+ }
+
+ public void cancel() throws TranslatorException {
+ // no-op
+ }
+}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/CartesienCriteriaGenerator.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/CartesienCriteriaGenerator.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/CartesienCriteriaGenerator.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,95 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-
-
-package org.teiid.translator.xml;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * creates a Cartesian product of the Criteria descriptions based on their values.
- */
-public class CartesienCriteriaGenerator {
-
- public static List<List<CriteriaDesc>>
generateCartesianCriteria(List<CriteriaDesc> params) {
- List<List<CriteriaDesc>> cartesianProduct = new
ArrayList<List<CriteriaDesc>>();
-
- for (CriteriaDesc desc : params) {
- createCartesionProduct(cartesianProduct, desc);
- }
-
- return cartesianProduct;
- }
-
- static void createCartesionProduct(List<List<CriteriaDesc>>
cartesianProduct, CriteriaDesc desc) {
-
- List<CriteriaDesc> firstLevel = new ArrayList<CriteriaDesc>();
- if (desc.isUnlimited()) {
- firstLevel.add(desc);
- }
- else {
- for (Object value: desc.getValues()) {
- CriteriaDesc cd = desc.cloneWithoutValues();
- cd.setValue(0, value);
- firstLevel.add(cd);
- }
- }
-
- if (cartesianProduct.isEmpty()) {
- for (CriteriaDesc cd:firstLevel) {
- List<CriteriaDesc> secondLevel = new ArrayList<CriteriaDesc>();
- secondLevel.add(cd);
- cartesianProduct.add(secondLevel);
- }
- }
- else {
- List<List<CriteriaDesc>> newcartesianProduct = new
ArrayList<List<CriteriaDesc>>();
-
- for (CriteriaDesc cd:firstLevel) {
- for (List<CriteriaDesc> secondLevel:cartesianProduct) {
-
- List<CriteriaDesc> colnedSecondLevel = makeClone(secondLevel);
- colnedSecondLevel.add(cd);
- newcartesianProduct.add(colnedSecondLevel);
- }
- }
- cartesianProduct.clear();
- cartesianProduct.addAll(newcartesianProduct);
- }
- }
-
- private static List<CriteriaDesc> makeClone(List<CriteriaDesc> original){
- List<CriteriaDesc> clonedList = new ArrayList<CriteriaDesc>();
-
- for (CriteriaDesc cd:original) {
- CriteriaDesc clone = cd.cloneWithoutValues();
- int i = 0;
- for (Object value:cd.getValues()) {
- clone.setValue(i++, value);
- }
- clonedList.add(clone);
- }
- return clonedList;
- }
-}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/CompositeExecution.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/CompositeExecution.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/CompositeExecution.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,85 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-package org.teiid.translator.xml;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.teiid.translator.DataNotAvailableException;
-import org.teiid.translator.ResultSetExecution;
-import org.teiid.translator.TranslatorException;
-
-public class CompositeExecution implements ResultSetExecution {
-
- private boolean closed = false;
- private List<ResultSetExecution> executions = new
ArrayList<ResultSetExecution>();
- private int currentExecutionNumber = 0;
- private ResultSetExecution currentExecution;
-
- public void addExecution(ResultSetExecution execution) {
- if (this.closed) {
- throw new IllegalStateException("This execution is already closed");
//$NON-NLS-1$
- }
- this.executions.add(execution);
- }
-
- @Override
- public List<?> next() throws TranslatorException, DataNotAvailableException {
- List result = null;
- if (this.currentExecution != null) {
- result = this.currentExecution.next();
- }
-
- if (result == null) {
- if(this.currentExecutionNumber < this.executions.size()) {
- this.currentExecution = this.executions.get(this.currentExecutionNumber++);
- result = this.currentExecution.next();
- }
- }
- return result;
- }
-
- @Override
- public void cancel() throws TranslatorException {
- this.closed = true;
- for(ResultSetExecution exec:this.executions) {
- exec.cancel();
- }
- }
-
- @Override
- public void close() {
- this.closed = true;
- for(ResultSetExecution exec:this.executions) {
- exec.close();
- }
- }
-
- @Override
- public void execute() throws TranslatorException {
- this.closed = true;
- for(ResultSetExecution exec:this.executions) {
- exec.execute();
- }
- }
-
-}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/Constants.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/Constants.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/Constants.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,11 +0,0 @@
-package org.teiid.translator.xml;
-
-public class Constants {
-
- static public final String NAMESPACE_PREFIX_PROPERTY_NAME =
"NamespacePrefixes"; //$NON-NLS-1$
- static public final String SERVICE_NAME = "ServiceName"; //$NON-NLS-1$
- static public final String SERVICE_NAMESPACE = "ServiceNamespace";
//$NON-NLS-1$
- static public final String PORT_NAME = "PortName"; //$NON-NLS-1$
- static public final String PORT_NAMESPACE = "PortNamespace"; //$NON-NLS-1$
-
-}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/CriteriaDesc.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/CriteriaDesc.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/CriteriaDesc.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,473 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator.xml;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-
-import org.teiid.language.BaseInCondition;
-import org.teiid.language.ColumnReference;
-import org.teiid.language.Comparison;
-import org.teiid.language.Condition;
-import org.teiid.language.Expression;
-import org.teiid.language.In;
-import org.teiid.language.LanguageUtil;
-import org.teiid.language.Literal;
-import org.teiid.language.Select;
-import org.teiid.language.Comparison.Operator;
-import org.teiid.metadata.Column;
-import org.teiid.metadata.Column.SearchType;
-import org.teiid.translator.TranslatorException;
-
-
-public class CriteriaDesc extends ParameterDescriptor {
- // TODO: a lot of this is HTTP/SOAP specific (i.e., do not apply to files).
- // There are various
- // places that we work around that (extension properties being null),
- // but it should be handled properly by moving the code into
- // HTTP and SOAP specific places
-
- // Describes an item in the parameter or criteria structure, and all the
- // attributes of it
- // Added to allow all the attributes of criteira to be managed in a single
- // structure,
- // and to make the code more manageable
-
- private List m_values;
-
- private int m_currentIndexInValuesList = 0;
-
- private Boolean m_parentAttribute = null;
-
- private Boolean m_enumeratedAttribute = null;
-
- private Boolean m_allowEmptyValue = null;
-
- private String m_dataAttributeName = null;
-
- private Properties m_additionalAttributes = null;
-
- private String m_inputXpath = null;
-
- private String nativeType = null;
-
- private boolean m_unlimited = false;
-
- private boolean m_enumerated = false;
-
- private boolean m_multiElement = false;
-
- private boolean m_soapArrayElement = false;
-
- private boolean m_simpleSoapElement;
-
- public static final String PARM_REQUIRED_VALUE_COLUMN_PROPERTY_NAME =
"RequiredValue"; //$NON-NLS-1$
-
- public static final String PARM_ALLOWS_EMPTY_VALUES_COLUMN_PROPERTY_NAME =
"AllowEmptyInputElement"; //$NON-NLS-1$
-
- public static final String PARM_HAS_MULTIPLE_VALUES_COLUMN_PROPERTY_NAME =
"MultipleValues"; //$NON-NLS-1$
-
- public static final String PARM_HAS_MULTIPLE_VALUES_COMMA_DELIMITED_NAME =
"CommaDelimited"; //$NON-NLS-1$
-
- public static final String PARM_HAS_MULTIPLE_VALUES_MULTI_ELEMENT_NAME =
"MultiElement"; //$NON-NLS-1$
-
- public static final String PARM_IS_SIMPLE_SOAP_ARRAY_ELEMENT_NAME =
"SimpleSoapArrayElement"; //$NON-NLS-1$
-
- public static final String PARM_IS_COMPLEX_SOAP_ARRAY_ELEMENT_NAME =
"ComplexSoapArrayElement"; //$NON-NLS-1$
-
- public static final String PARM_XPATH_INPUT_COLUMN_PROPERTY_NAME =
"XPathForInputParameter"; //$NON-NLS-1$
-
- public static final String PARM_AS_PARENT_ATTRIBUTE_COLUMN_PROPERTY_NAME =
"AttributeOfParent"; //$NON-NLS-1$
-
- public static final String PARM_AS_NAMED_ATTRIBUTE_COLUMN_PROPERTY_NAME =
"DataAttributeName"; //$NON-NLS-1$
-
- //use static method do see if a criteria object needs to be created
- public static CriteriaDesc getCriteriaDescForColumn(Column element,
- Select query) throws TranslatorException {
-
- CriteriaDesc retVal = null;
- List values = parseCriteriaToValues(element, query);
-
- if (values.size() == 0) {
- if (testForParam(element)) {
- //add default value to values if it exists
- //throws exception if no default specified and its required
- handleDefaultValue(element, values);
- }
- }
- //values.size may have changed if default value was added above
- //so we retest
- if (values.size() > 0 || findAllowEmptyValue(element)) {
- retVal = new CriteriaDesc(element, values);
- retVal.setNativeType(element.getNativeType());
- }
- return retVal;
- }
-
- private static void handleDefaultValue(Column element, List values) throws
TranslatorException {
- Object defaultVal = element.getDefaultValue();
- if (defaultVal != null) {
- values.add(defaultVal);
- } else if (findIsRequired(element)) {
- throw new TranslatorException(
-
XMLPlugin.getString("CriteriaDesc.value.not.found.for.param") //$NON-NLS-1$
- + element.getName());
- }
- }
-
- private static boolean findIsRequired(Column element)
- throws TranslatorException {
- String value = element.getProperties().get(
- PARM_REQUIRED_VALUE_COLUMN_PROPERTY_NAME);
- return Boolean.valueOf(value);
- }
-
- private static boolean findAllowEmptyValue(Column element)
- throws TranslatorException {
- String value = element.getProperties().get(
- PARM_ALLOWS_EMPTY_VALUES_COLUMN_PROPERTY_NAME);
- return Boolean.valueOf(value);
- }
-
- /**
- * @see
com.metamatrix.server.datatier.SynchConnectorConnection#submitRequest(java.lang.Object)
- */
- public CriteriaDesc(Column myElement, List myValues)
- throws TranslatorException {
-
- super(myElement);
- m_values = myValues;
- final String enumerated = PARM_HAS_MULTIPLE_VALUES_COMMA_DELIMITED_NAME;
- final String multiElement = PARM_HAS_MULTIPLE_VALUES_MULTI_ELEMENT_NAME;
- String multiplicityStr = getElement().getProperties().get(
- PARM_HAS_MULTIPLE_VALUES_COLUMN_PROPERTY_NAME);
- if (multiplicityStr == null) {
- multiplicityStr = ""; //$NON-NLS-1$
- }
- if (multiplicityStr.equals(enumerated)) {
- m_unlimited = true;
- m_enumerated = true;
- } else if (multiplicityStr.equals(multiElement)) {
- m_unlimited = true;
- m_enumerated = false;
- m_multiElement = true;
- } else if (multiplicityStr.equals(PARM_IS_SIMPLE_SOAP_ARRAY_ELEMENT_NAME) ||
- multiplicityStr.equals(PARM_IS_COMPLEX_SOAP_ARRAY_ELEMENT_NAME)) {
- m_unlimited = true;
- m_enumerated = false;
- m_multiElement = true;
- m_soapArrayElement = true;
- if (multiplicityStr.equals(PARM_IS_SIMPLE_SOAP_ARRAY_ELEMENT_NAME)) {
- m_simpleSoapElement = true;
- } else {
- m_simpleSoapElement = false;
- }
- } else {
- m_unlimited = false;
- m_enumerated = false;
- }
- }
-
- private CriteriaDesc(CriteriaDesc other) {
- //from ParameterDescriptor
- setXPath(other.getXPath());
- setIsParameter(other.isParameter());
- setIsResponseId(other.isResponseId());
- setIsLocation(other.isLocation());
- setColumnName(String.valueOf(other.getColumnName()));
- setColumnNumber(other.getColumnNumber());
- setElement(other.getElement());
- setNativeType(other.getNativeType());
-
- m_parentAttribute = other.m_parentAttribute == null ? null :
Boolean.valueOf(other.m_parentAttribute);
- m_enumeratedAttribute = other.m_enumeratedAttribute == null ? null :
Boolean.valueOf(other.m_enumeratedAttribute);
- m_allowEmptyValue = other.m_allowEmptyValue == null ? null :
Boolean.valueOf(other.m_allowEmptyValue);
- m_dataAttributeName = other.m_dataAttributeName == null ? null :
String.valueOf(other.m_dataAttributeName);
- m_additionalAttributes = other.m_additionalAttributes == null ? null : new
Properties(other.m_additionalAttributes);
- m_inputXpath = other.m_inputXpath == null ? null :
String.valueOf(other.m_inputXpath);
- m_unlimited = other.m_unlimited;
- m_enumerated = other.m_enumerated;
- m_multiElement = other.m_multiElement;
- m_soapArrayElement = other.m_soapArrayElement;
- //don't copy the values
- m_values = new ArrayList();
- }
-
- public String getInputXpath() throws TranslatorException {
- if (m_inputXpath == null) {
- findInputXPath();
- }
- return m_inputXpath;
- }
-
- private void findInputXPath() throws TranslatorException {
- m_inputXpath =
getElement().getProperties().get(PARM_XPATH_INPUT_COLUMN_PROPERTY_NAME);
- if (m_inputXpath == null || m_inputXpath.trim().length() == 0) {
- m_inputXpath = getColumnName();
- }
- }
-
- public boolean isUnlimited() {
- return m_unlimited;
- }
-
- public boolean isMultiElement() {
- return m_multiElement;
- }
-
- public boolean isSOAPArrayElement() {
- return m_soapArrayElement;
- }
-
- public boolean isAutoIncrement() throws TranslatorException {
- return getElement().isAutoIncremented();
- }
-
- //from model extensions
- public boolean isParentAttribute() throws TranslatorException {
- if (m_parentAttribute == null) {
- findParentAttribute();
- }
- return m_parentAttribute.booleanValue();
- }
-
- private void findParentAttribute() throws TranslatorException {
- String value = getElement().getProperties()
- .get(PARM_AS_PARENT_ATTRIBUTE_COLUMN_PROPERTY_NAME);
- m_parentAttribute = Boolean.valueOf(value);
- }
-
- //from model extensions
- public boolean isEnumeratedAttribute() throws TranslatorException {
- return m_enumerated;
- }
-
- //from model extensions
- public boolean allowEmptyValue() throws TranslatorException {
-
- if (m_allowEmptyValue == null) {
- findAllowEmptyValue();
- }
- return m_allowEmptyValue.booleanValue();
- }
-
- private void findAllowEmptyValue() throws TranslatorException {
- String value = getElement().getProperties()
- .get(PARM_ALLOWS_EMPTY_VALUES_COLUMN_PROPERTY_NAME);
- m_allowEmptyValue = Boolean.valueOf(value);
- }
-
- //from model extensions
- public boolean isDataInAttribute() throws TranslatorException {
- String dataAttribute = getDataAttributeName();
- if (dataAttribute.trim().length() == 0) {
- return false;
- }
- return true;
- }
-
- //from model extensions
- public String getDataAttributeName() throws TranslatorException {
-
- if (m_dataAttributeName == null) {
- findDataAttributeName();
- }
- return m_dataAttributeName;
- }
-
- private void findDataAttributeName() throws TranslatorException {
- m_dataAttributeName = getElement().getProperties().get(
- PARM_AS_NAMED_ATTRIBUTE_COLUMN_PROPERTY_NAME);
- if (m_dataAttributeName == null) {
- m_dataAttributeName = ""; //$NON-NLS-1$
- }
- }
-
- public List getValues() {
- return m_values;
- }
-
- public int getNumberOfValues() {
- return m_values.size();
- }
-
- //This code manages the looping of parameters to make multiple server
- // calls.
- //The current index is used to get a value to be added to the parmString
- public String getCurrentIndexValue() throws TranslatorException {
- final int initialBufferSize = 1000;
- if (m_values.size() == 0 && allowEmptyValue()) {
- return ""; //$NON-NLS-1$
- }
- if (isEnumeratedAttribute()) {
- StringBuffer sb = new StringBuffer(initialBufferSize);
- String startChar = ""; //$NON-NLS-1$
- for (int x = 0; x < m_values.size(); x++) {
- sb.append(startChar);
- sb.append(m_values.get(x));
- startChar = ","; //$NON-NLS-1$
- }
- return sb.toString();
- }
- if (m_values.size() > 0) {
- return (String) m_values.get(m_currentIndexInValuesList);
- }
- return null;
- }
- //if so, it is incremented
- public boolean incrementIndex() throws TranslatorException {
- if (isEnumeratedAttribute()) {
- return false;
- } else if (m_currentIndexInValuesList < m_values.size() - 1) {
- m_currentIndexInValuesList++;
- return true;
- } else {
- return false;
- }
- }
-
- public void resetIndex() {
- m_currentIndexInValuesList = 0;
- }
-
- private static ArrayList parseCriteriaToValues(Column element, Select query) throws
TranslatorException {
-
- String fullName = element.getFullName().trim().toUpperCase();
- ArrayList parmPair = new ArrayList();
- if (element.getSearchType() == SearchType.Searchable
- || element.getSearchType() == SearchType.All_Except_Like) {
- // Check and set criteria for the IData input
- Condition criteria = query.getWhere();
- List<Condition> criteriaList =
LanguageUtil.separateCriteriaByAnd(criteria);
- for(Condition criteriaSeg: criteriaList) {
- if (criteriaSeg instanceof Comparison) {
- Comparison compCriteria = (Comparison) criteriaSeg;
- if (compCriteria.getOperator() == Operator.EQ) {
- Expression lExpr = compCriteria.getLeftExpression();
- Expression rExpr = compCriteria.getRightExpression();
- handleCompareCriteria(lExpr, rExpr, fullName, parmPair);
- }
- } else if (criteriaSeg instanceof BaseInCondition) {
- handleInCriteria((BaseInCondition) criteriaSeg, fullName, parmPair);
-
- }
- }
- }
- return parmPair;
- }
-
- private static void handleInCriteria(BaseInCondition baseInCriteria, String fullName,
ArrayList parmPair) {
- Expression expr = baseInCriteria.getLeftExpression();
- if (expr instanceof ColumnReference) {
- if (nameMatch(expr, fullName)) {
- Iterator vIter = null;
-
- vIter = ((In) baseInCriteria).getRightExpressions().iterator();
- while (vIter.hasNext()) {
- Literal val = (Literal) vIter.next();
- String constantValue = val.getValue()
- .toString();
- constantValue = stringifyCriteria(constantValue);
- parmPair.add(constantValue);
- }
- }
- }
- }
-
- private static void handleCompareCriteria(Expression lExpr, Expression rExpr, String
fullName, ArrayList parmPair) {
- checkElement(lExpr, rExpr, fullName, parmPair);
- checkElement(rExpr, lExpr, fullName, parmPair);
- }
-
- private static void checkElement(Expression expression, Expression literalCandidate,
String fullName, ArrayList parmPair) {
- if (expression instanceof ColumnReference) {
- if ((nameMatch(expression, fullName))
- && (literalCandidate instanceof Literal)) {
- String constantValue = ((Literal) literalCandidate)
- .getValue().toString();
- constantValue = stringifyCriteria(constantValue);
- parmPair.add(constantValue);
- }
- }
- }
-
- public static boolean nameMatch(Expression expr, String elementName) {
- ColumnReference exprElement = (ColumnReference) expr;
- String symbolName = exprElement.getName().toUpperCase().trim();
- String tempElementName = elementName.toUpperCase();
- int indx = symbolName.lastIndexOf("."); //$NON-NLS-1$
- //. has to be there
- symbolName = symbolName.substring(indx + 1);
- indx = elementName.lastIndexOf("."); //$NON-NLS-1$
- //. has to be there
- tempElementName = tempElementName.substring(indx + 1);
- return symbolName.equals(tempElementName);
- }
-
- public static String stringifyCriteria(String startCriteria) {
- int indx = 0;
- String cStr = startCriteria;
- indx = cStr.indexOf("'"); //$NON-NLS-1$
- if (indx == 0) {
- int indx2 = cStr.substring(1).indexOf("'"); //$NON-NLS-1$
- if (indx2 >= 0) {
- return cStr.substring(1, indx2 + 1);
- }
- }
- indx = cStr.indexOf('"');
- if (indx == 0) {
- int indx2 = cStr.substring(1).indexOf('"');
- if (indx2 > 0) {
- return cStr.substring(1, indx2 + 1);
- }
- }
- return cStr;
- }
-
- public CriteriaDesc cloneWithoutValues() {
- CriteriaDesc newDesc = new CriteriaDesc(this);
- return newDesc;
- }
-
- public void setValue(int i, Object object) {
- if(m_values.size() <= i) {
- m_values.add(i, object);
- } else {
- m_values.set(i, object);
- }
- }
-
- private void setNativeType(String nativeType) {
- this.nativeType = nativeType;
- }
-
- public String getNativeType() {
- return nativeType;
- }
-
- public boolean isSimpleSoapElement() {
- return m_simpleSoapElement;
- }
-}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/DocumentBuilder.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/DocumentBuilder.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/DocumentBuilder.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,526 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator.xml;
-
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import org.jdom.Attribute;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.IllegalNameException;
-import org.jdom.Namespace;
-import org.jdom.output.XMLOutputter;
-import org.teiid.translator.TranslatorException;
-
-
-public class DocumentBuilder {
-
- public static final String PARM_INPUT_XPATH_TABLE_PROPERTY_NAME =
"XPathRootForInput"; //$NON-NLS-1$
- public static final String ENCODING_STYLE_URL =
"http://schemas.xmlsoap.org/soap/encoding/"; //$NON-NLS-1$
-
- private Map m_namespaceMap;
-
- private boolean m_useTypeAttributes;
-
- public DocumentBuilder() {
- m_namespaceMap = new HashMap();
- m_useTypeAttributes = false;
- }
-
- private Map getNamespaces() {
- return m_namespaceMap;
- }
-
- public String buildDocumentString(List contents, String topLevelXPath,
- String nsDecl) throws TranslatorException {
- Document doc = buildDocument(contents, topLevelXPath, nsDecl);
- return outputDocToString(doc);
- }
-
- public Document buildDocument(List contents, String topLevelXPath, String nsDecl)
throws TranslatorException {
- Document doc = null;
- setNamespaces(nsDecl);
- // assemble table-level elements
- org.jdom.Element curElement = null;
- try {
- curElement = makeElement(curElement, topLevelXPath, false);
- } catch(IllegalNameException ex) {
- throw new TranslatorException(topLevelXPath + " is not a valid XPath for
the root request node." + "Change the Request table " +
PARM_INPUT_XPATH_TABLE_PROPERTY_NAME);
- }
- if (curElement == null) {
- throw new
TranslatorException(XMLPlugin.getString("HTTPExecutor.root.element.required"));
//$NON-NLS-1$
- }
- doc = makeTableLevelElements(curElement);
-
- // loop through each parameter
- processParameters(contents, curElement);
-
- // add all of the namespaces
- Element nsHolder = doc.getRootElement();
- addAllNamespaces(nsHolder);
-
- return doc;
- }
-
- private void addAllNamespaces(Element nsHolder) {
- Map namespaceMap = getNamespaces();
- Iterator nsIter = namespaceMap.values().iterator();
- while (nsIter.hasNext()) {
- nsHolder.addNamespaceDeclaration((Namespace) nsIter.next());
- }
- }
-
- private Document makeTableLevelElements(Element curElement)
- throws TranslatorException {
-
- // this walks up from the current node to the root, so the root can be
- // assigned to a document
- Element walkupElement = curElement;
- Element parentElement;
- // why is this failing?
- // could be due to incompatibilities with core jdom version
- // and the one the connector uses
- while ((parentElement = (Element) walkupElement.getParent()) != null) {
- walkupElement = parentElement;
- }
- Document document = new Document(walkupElement);
- return document;
- }
-
- private void setNamespaces(String nsDecl) throws TranslatorException {
- if (nsDecl != null && nsDecl.trim().length() > 0) {
- String[] nsPairs = nsDecl.trim().replace('\"',
'\0').replace('\'',
- '\0').split("xmlns"); //$NON-NLS-1$
- // the first entry will be blank since the string starts with the
- // delimiter
- for (int i = 1; i < nsPairs.length; i++) {
- // remove the ':'
- if (nsPairs[i].startsWith(":"))
- nsPairs[i] = nsPairs[i].substring(1);
- String[] nsSplit = nsPairs[i].split("="); //$NON-NLS-1$
- if (nsSplit.length != 2) {
- throw new TranslatorException(
- XMLPlugin
-
.getString("DocumentBuilder.could.not.parse.namespaces")); //$NON-NLS-1$
- }
- Namespace ns = Namespace.getNamespace(nsSplit[0].trim(),
- nsSplit[1].trim());
- m_namespaceMap.put(nsSplit[0], ns);
- }
- }
- }
-
- private Element makeElement(Element colElement, String inputXPath,
- boolean dupLastElement) throws TranslatorException {
- if (inputXPath == null || inputXPath.trim().length() == 0) {
- return colElement;
- }
- Element tempElement = colElement;
- String tempXPath = inputXPath.trim();
- tempElement = visitXPath(colElement, tempXPath, dupLastElement);
- return tempElement;
- }
-
- private Element visitXPath(Element elem, String tempXPath,
- boolean dupLastElement) throws TranslatorException {
- // loop through, searching for path seperators
- int startParmIndx = 0;
- int endParmIndx = tempXPath.indexOf("/", startParmIndx); //$NON-NLS-1$
- int endOfTempXPath = tempXPath.length() - 1;
- while (endParmIndx >= 0 && endParmIndx < endOfTempXPath) {
- elem = setElement(elem, tempXPath, startParmIndx, endParmIndx);
- startParmIndx = endParmIndx + 1;
- endParmIndx = checkForIndexEnd(tempXPath, startParmIndx);
- }
- String finalXpath = getFinalXPath(tempXPath, startParmIndx, endParmIndx);
- if (finalXpath != null) {
- elem = addOneElement(elem, finalXpath, dupLastElement);
- }
- return elem;
-
- }
-
- private int checkForIndexEnd(String tempXPath, int startParmIndx) {
- int endParmIndx;
- if (startParmIndx < tempXPath.length() - 1) {
- endParmIndx = tempXPath.indexOf("/", startParmIndx); //$NON-NLS-1$
- } else {
- endParmIndx = -1;
- }
- return endParmIndx;
- }
-
- private String getFinalXPath(String tempXPath, int startParmIndx,
- int endParmIndx) {
- String finalXpath = null;
- if (endParmIndx > 0) {
- finalXpath = tempXPath.substring(startParmIndx, endParmIndx);
- } else {
- if (startParmIndx <= tempXPath.length() - 1) {
- finalXpath = tempXPath.substring(startParmIndx);
- }
- }
- return finalXpath;
- }
-
- private Element setElement(Element element, String tempXPath,
- int startParmIndx, int endParmIndx) throws TranslatorException {
- Element tempElement = element;
- if (endParmIndx > 0) {
- String tempXP = tempXPath.substring(startParmIndx, endParmIndx);
- if (tempXP.indexOf("..") >= 0) { //$NON-NLS-1$
- throw new TranslatorException(XMLPlugin
- .getString("HTTPExecutor.dot.notation.not.allowed"));
//$NON-NLS-1$
- }
-
- if (tempXP != null && tempXP.trim().length() > 0) {
- tempElement = addOneElement(tempElement, tempXP, false);
- }
- }
- return tempElement;
- }
-
- private void processParameters(List<CriteriaDesc> params, Element curElement)
- throws TranslatorException {
-
- for(CriteriaDesc parmCriteria: params) {
- try {
- boolean isAutoIncrement = parmCriteria.isAutoIncrement();
- createParameterXML(curElement, parmCriteria, isAutoIncrement);
- } catch (Exception ex) {
- throw new TranslatorException(XMLPlugin
- .getString("HTTPExecutor.error.building.column")
//$NON-NLS-1$
- + parmCriteria.getColumnName() + ": " + ex.toString());
//$NON-NLS-1$
- }
- }
-
- }
-
- private void createParameterXML(Element curElement,
- CriteriaDesc parmCriteria, boolean isAutoIncrement)
- throws TranslatorException {
- if (parmCriteria.isParentAttribute()) {
- // add parameter as attribute of connector
- curElement.setAttribute(parmCriteria.getInputXpath(), parmCriteria
- .getCurrentIndexValue());
- } else if (parmCriteria.isUnlimited()
- && !parmCriteria.isEnumeratedAttribute()) {
- // add parameter as mutliple elements
- createMultipleElementXML(curElement, parmCriteria, isAutoIncrement);
- } else {
- createSingleElementXML(curElement, parmCriteria, isAutoIncrement);
- }
-
- }
-
- private void createSingleElementXML(Element curElement,
- CriteriaDesc parmCriteria, boolean isAutoIncrement)
- throws TranslatorException {
- org.jdom.Element colElement = null;
- if (parmCriteria.isDataInAttribute()) {
- // add parameter as an element and an attribute in the
- // element
- colElement = makeElement(curElement, parmCriteria.getInputXpath(),
- false);
- String attName = parmCriteria.getDataAttributeName();
- String namePart = getNamePart(attName);
- String nsPart = getNamespacePart(attName);
- Namespace attNS = Namespace.NO_NAMESPACE;
- if (nsPart != null) {
- attNS = (Namespace) m_namespaceMap.get(nsPart);
- colElement.setAttribute(namePart, parmCriteria
- .getCurrentIndexValue(), attNS);
- } else {
- colElement.setAttribute(attName, parmCriteria
- .getCurrentIndexValue());
- }
- } else {
- // add parameter as a new element
- colElement = makeElement(curElement, parmCriteria.getInputXpath(),
- false);
- colElement.addContent(parmCriteria.getCurrentIndexValue());
- }
- if (isAutoIncrement) {
- String subscrValue = "[0]"; //$NON-NLS-1$
- colElement.setAttribute("SUBSCR", subscrValue); //$NON-NLS-1$
- }
-
- if (useTypeAttributes()) {
- // if there is a native type in the model use it, otherwise
- // if 5.0 or later, derive from the data type
- String xsdType = parmCriteria.getElement().getNativeType();
- if (xsdType == null) {
- // attempt use the data type
- // this method call does not exist before 5.0 so we have to
- // check for it before we call it.
- try {
- Method method = parmCriteria.getElement().getClass()
- .getMethod("getModeledType", new Class[] {});
- String type = parmCriteria.getElement().getDatatypeID();
- String nsPart = type.substring(0, type.indexOf('#'));
- String namePart = type.substring(type.indexOf('#') + 1);
- Iterator nsIter = getNamespaces().values().iterator();
- String prefix = null;
- while (nsIter.hasNext()) {
- Namespace ns = (Namespace) nsIter.next();
- if (ns.getURI().equals(nsPart))
- prefix = ns.getPrefix();
- }
- if (prefix == null) {
- int prefixInt = 0;
- while (getNamespaces().get("ns" + prefixInt) != null)
{
- ++prefixInt;
- }
- prefix = "ns" + prefixInt;
- Namespace newNS = Namespace
- .getNamespace(prefix, nsPart);
- getNamespaces().put(prefix, newNS);
- }
- xsdType = prefix + ":" + namePart;
- } catch (NoSuchMethodException nme) {
- throw new TranslatorException(
- "column "
- + colElement.getName()
- + XMLPlugin
-
.getString("DocumentBuilder.encoding.type.required"));
- }
- }
- final String xsiType = "type"; //$NON-NLS-1$
- final String xsiNS = "http://www.w3.org/1999/XMLSchema-instance";
//$NON-NLS-1$
- final String xsiPrefix = "xsi"; //$NON-NLS-1$
- Attribute type = new Attribute(xsiType, xsdType, Namespace
- .getNamespace(xsiPrefix, xsiNS));
- colElement.setAttribute(type);
- }
- }
-
- /**
- *
- */
- private void createMultipleElementXML(Element curElement,
- CriteriaDesc parmCriteria, boolean isAutoIncrement)
- throws TranslatorException {
- if(parmCriteria.isSOAPArrayElement()) {
- createSOAPArrayElement(curElement, parmCriteria);
- } else {
- parmCriteria.resetIndex();
- boolean moreParms = true;
- boolean isDataInAttribute = parmCriteria.isDataInAttribute();
- String inputXpath = parmCriteria.getInputXpath();
- for (int x = 0; moreParms; x++) {
- org.jdom.Element colElement = makeElement(curElement, inputXpath,
- true);
- if (isAutoIncrement) {
- String subscrValue = "[" + Integer.toString(x)
//$NON-NLS-1$
- + "]"; //$NON-NLS-1$
- colElement.setAttribute("SUBSCR", subscrValue);
//$NON-NLS-1$
- }
- if (isDataInAttribute) {
- colElement.setAttribute(parmCriteria.getDataAttributeName(),
- parmCriteria.getCurrentIndexValue());
- } else {
- colElement.setText(parmCriteria.getCurrentIndexValue());
- }
- moreParms = parmCriteria.incrementIndex();
- }
- }
- }
-
- private void createSOAPArrayElement(Element curElement, CriteriaDesc parmCriteria)
throws TranslatorException {
-
- /*
- * loop over the values in the criteriaDesc and create <item> nodes
containing them
- *
- * get the imformation for the soapArray element out of the criteriaDesc's
- * nativeType property and create the attributes including the number of items.
- *
- *
- */
- String inputXpath = parmCriteria.getInputXpath();
- curElement = visitXPath(curElement, inputXpath, false);
-
- parmCriteria.resetIndex();
- boolean moreParms = true;
-
- String nativeTypeInfo = parmCriteria.getNativeType();
- StringTokenizer tokenizer = new StringTokenizer(nativeTypeInfo, ";");
- String xsdTypeString = tokenizer.nextToken();
-
- int start,end;
- start = xsdTypeString.indexOf("\"");
- end = xsdTypeString.indexOf("\"", start +1);
- String xsdTypeValue = xsdTypeString.substring(start +1, end);
-
- String arrayType = tokenizer.nextToken();
- start = arrayType.indexOf("\"");
- end = arrayType.indexOf("\"", start +1);
- String arrayTypeValue = arrayType.substring(start +1, end);
-
- end = arrayType.indexOf(":");
- String soapEncodingPrefix = arrayType.substring(0, end);
-
- String arrayNamespace = tokenizer.nextToken();
- start = arrayNamespace.indexOf(":");
- end = arrayNamespace.indexOf("=", start +1);
- start = arrayNamespace.indexOf("\"");
- arrayTypeValue = arrayTypeValue + "[" +
parmCriteria.getNumberOfValues() + "]";
-
-
- if(!parmCriteria.isSimpleSoapElement()) {
- Element arrayElement = curElement.getParentElement();
- //See if we have already added the attributes to the array from
- //an earlier array element.
- if(null == arrayElement.getAttribute("type",
Namespace.XML_NAMESPACE)) {
- arrayElement.setAttribute("type", xsdTypeValue,
Namespace.XML_NAMESPACE);
- Namespace soapEncodingNamespace =
Namespace.getNamespace(soapEncodingPrefix, ENCODING_STYLE_URL);
- arrayElement.setAttribute("arrayType", arrayTypeValue,
soapEncodingNamespace);
- }
- curElement.detach();
- org.jdom.Element itemElement = arrayElement.getChild("item");
- if(null == itemElement) {
- itemElement = makeElement(arrayElement, "item", true);
- }
- itemElement.addContent(curElement);
- curElement.setText(parmCriteria.getCurrentIndexValue());
-
- } else {
- //See if we have already added the attributes to the array from
- //an earlier array element.
- if(null == curElement.getAttribute("type",
Namespace.XML_NAMESPACE)) {
- curElement.setAttribute("type", xsdTypeValue,
Namespace.XML_NAMESPACE);
- Namespace soapEncodingNamespace =
Namespace.getNamespace(soapEncodingPrefix, ENCODING_STYLE_URL);
- curElement.setAttribute("arrayType", arrayTypeValue,
soapEncodingNamespace);
- }
-
- for (int x = 0; moreParms; x++) {
- org.jdom.Element itemElement = makeElement(curElement, "item",
true);
- itemElement.setText(parmCriteria.getCurrentIndexValue());
- moreParms = parmCriteria.incrementIndex();
- }
- }
- }
-
- private Element addOneElement(org.jdom.Element colElement,
- String inputXPath, boolean allowDup) throws TranslatorException {
-
- // Create element namespace if needed and use in the get Child and
- // Element ctor
- String tempXPath = inputXPath.trim();
- String elementName = getElementName(tempXPath);
- String nsPart = getNamespacePart(elementName);
- String namePart = getNamePart(elementName);
- Namespace elemNS = Namespace.NO_NAMESPACE;
- if (nsPart != null) {
- elemNS = (Namespace) getNamespaces().get(nsPart);
- }
-
- org.jdom.Element childElement = null;
- if (colElement != null && !allowDup) {
- childElement = colElement.getChild(namePart, elemNS);
- }
-
- // element does not already exist, create it
- if (childElement == null) {
- childElement = new Element(namePart, elemNS);
- // add new element to connector
- if (colElement != null) {
- colElement.addContent(childElement);
- }
- }
-
- addAttributes(childElement, tempXPath);
- return childElement;
- }
-
- private String getNamespacePart(String elemName) {
- int colonIndex = elemName.indexOf(':');
- if (colonIndex < 0) {
- return null;
- }
- return elemName.substring(0, colonIndex);
- }
-
- private String getNamePart(String elemName) {
- int colonIndex = elemName.indexOf(':');
- if (colonIndex < 0) {
- return elemName;
- }
- return elemName.substring(colonIndex + 1);
- }
-
- private void addAttributes(Element childElement, String tempXPath)
- throws TranslatorException {
- // add attribute definitions
- int startAttIndx = tempXPath.indexOf("["); //$NON-NLS-1$
- while (startAttIndx > 0) {
- int equalIndx = tempXPath.indexOf("=", startAttIndx);
//$NON-NLS-1$
- int endAttIndx = tempXPath.indexOf("]", startAttIndx);
//$NON-NLS-1$
- if (equalIndx > 0 && equalIndx < endAttIndx) {
- String attName = tempXPath.substring(startAttIndx + 1,
- equalIndx);
- String namePart = getNamePart(attName);
- String nsPart = getNamespacePart(attName);
- Namespace attNS = Namespace.NO_NAMESPACE;
- if (nsPart != null) {
- attNS = (Namespace) m_namespaceMap.get(nsPart);
- }
- String attValue = tempXPath
- .substring(equalIndx + 1, endAttIndx);
- childElement.setAttribute(namePart, attValue, attNS);
- } else {
- throw new TranslatorException(XMLPlugin
- .getString("HTTPExecutor.bad.attribute.def"));
//$NON-NLS-1$
- }
- startAttIndx = tempXPath.indexOf("[", endAttIndx); //$NON-NLS-1$
- }
- }
-
- private String getElementName(String tempXPath) {
- String elementName;
- int startAttIndx = tempXPath.indexOf("["); //$NON-NLS-1$
- if (startAttIndx > 0) {
- elementName = tempXPath.substring(0, startAttIndx).trim();
- } else {
- elementName = tempXPath;
- }
- return elementName;
- }
-
- public static String outputDocToString(Document doc) {
- XMLOutputter out = new XMLOutputter();
- return out.outputString(doc).trim();
- }
-
- public void setUseTypeAttributes(boolean m_useTypeAttributes) {
- this.m_useTypeAttributes = m_useTypeAttributes;
- }
-
- private boolean useTypeAttributes() {
- return m_useTypeAttributes;
- }
-}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/ExecutionInfo.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/ExecutionInfo.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/ExecutionInfo.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,205 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator.xml;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.JDOMException;
-import org.jdom.Namespace;
-import org.jdom.input.SAXBuilder;
-import org.teiid.translator.TranslatorException;
-
-
-public class ExecutionInfo {
-// TODO:Refactor. This class was defined when the multiple reqests to an XML service
-// (read HTTP) to satisfy an IN clause were abstacted beneath a single call to
Executor.getResult().
-// This case is now satified within the execute call by making a single call to
Executor.getResult()
-// for each paramter of the IN clause.
-
- private List columns;
- private int columnCount;
- private List<CriteriaDesc> params;
- private List<CriteriaDesc> criteria;
- private Map<String, String> otherProps;
- private String tablePath;
- private String location;
- private Map<String, String> prefixToNamespace;
- private Map<String, String> namespaceToPrefix;
-
- public ExecutionInfo() {
- this.columnCount = 0;
- this.columns = new ArrayList();
- this.params = new ArrayList<CriteriaDesc>();
- this.criteria = new ArrayList<CriteriaDesc>();
- this.otherProps = new HashMap<String, String>();
- this.tablePath = ""; //$NON-NLS-1$
- }
-
-
- public String getTableXPath() {
- return this.tablePath;
- }
-
- public String getLocation() {
- return this.location;
- }
-
- public List getRequestedColumns() {
- return this.columns;
- }
-
-
- public int getColumnCount() {
- return this.columnCount;
- }
-
-
- public List<CriteriaDesc> getParameters() {
- return this.params;
- }
-
-
- public List<CriteriaDesc> getCriteria() {
- return this.criteria;
- }
-
-
- public Map<String, String> getOtherProperties() {
- return this.otherProps;
- }
-
- public void setTableXPath(String path) {
- if (path == null || path.trim().length() == 0) {
- this.tablePath = null;
- } else {
- this.tablePath = path;
- }
- }
-
- public void setLocation(String location) {
- this.location = location;
- }
-
- public void setRequestedColumns(List value) {
- this.columns = value;
- }
-
-
- public void setColumnCount(int count) {
- this.columnCount = count;
- }
-
-
- public void setParameters(List<CriteriaDesc> parameters) {
- this.params = parameters;
- }
-
-
- public void setCriteria(List<CriteriaDesc> criteria) {
- this.criteria = criteria;
- }
-
-
- public void setOtherProperties(Map<String, String> props) {
- if (props == null) {
- this.otherProps = new HashMap<String, String>();
- } else {
- this.otherProps = props;
- }
- }
-
- // It is not enforced that there is only one ResponseId in the parameters, but it is
- // a valid assumption and the modelgenerators will never create a model that has more
- // than one. We could enforce this with a real metamodel.
- public CriteriaDesc getResponseIDCriterion() {
- CriteriaDesc result = null;
- Iterator iter = this.params.iterator();
- while(iter.hasNext()) {
- CriteriaDesc criterion = (CriteriaDesc)iter.next();
- if(criterion.isResponseId()) {
- result = criterion;
- break;
- }
- }
- return result;
- }
-
- public Map<String, String> getNamespaceToPrefixMap() throws TranslatorException {
- if(this.namespaceToPrefix != null) {
- return this.namespaceToPrefix;
- }
- getPrefixToNamespacesMap();
- return this.namespaceToPrefix;
- }
-
- public Map<String, String> getPrefixToNamespacesMap() throws TranslatorException
{
- if (this.prefixToNamespace != null) {
- return this.prefixToNamespace;
- }
-
- this.prefixToNamespace = new HashMap<String, String>();
- this.namespaceToPrefix = new HashMap<String, String>();
- String namespacePrefixes =
getOtherProperties().get(Constants.NAMESPACE_PREFIX_PROPERTY_NAME);
- if (namespacePrefixes == null || namespacePrefixes.trim().length() == 0) {
- return null;
- }
- String prefix = null;
- String uri = null;
- try {
- String xml = "<e " + namespacePrefixes + "/>"; //$NON-NLS-1$
//$NON-NLS-2$
- Reader reader = new StringReader(xml);
- SAXBuilder builder = new SAXBuilder();
- Document domDoc = builder.build(reader);
- Element elem = domDoc.getRootElement();
- List namespaces = elem.getAdditionalNamespaces();
- for (Iterator iter = namespaces.iterator(); iter.hasNext();) {
- Object o = iter.next();
- Namespace namespace = (Namespace) o;
- prefix = namespace.getPrefix();
- uri = namespace.getURI();
- this.prefixToNamespace.put(prefix, uri);
- this.namespaceToPrefix.put(uri, prefix);
- }
- } catch (JDOMException e) {
- String rawMsg =
XMLPlugin.getString("Executor.jaxen.error.on.namespace.pairs"); //$NON-NLS-1$
- Object[] objs = new Object[2];
- objs[0] = prefix;
- objs[1] = uri;
- String msg = MessageFormat.format(rawMsg, objs);
- throw new TranslatorException(e, msg);
- } catch (IOException e) {
- throw new TranslatorException(e, e.getMessage());
- }
- return this.prefixToNamespace;
- }
-}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/FileProcedureExecution.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/FileProcedureExecution.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/FileProcedureExecution.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,117 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator.xml;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.sql.SQLXML;
-import java.util.Arrays;
-import java.util.List;
-
-import org.teiid.core.types.InputStreamFactory;
-import org.teiid.core.types.SQLXMLImpl;
-import org.teiid.language.Call;
-import org.teiid.logging.LogConstants;
-import org.teiid.logging.LogManager;
-import org.teiid.metadata.AbstractMetadataRecord;
-import org.teiid.translator.DataNotAvailableException;
-import org.teiid.translator.FileConnection;
-import org.teiid.translator.ProcedureExecution;
-import org.teiid.translator.TranslatorException;
-
-
-/**
- * Execution class for File based XML Source.
- */
-public class FileProcedureExecution implements ProcedureExecution {
-
- private Call procedure;
- private XMLExecutionFactory executionFactory;
- private boolean returnedResult;
- private SQLXML returnValue;
- private FileConnection connection;
-
- /**
- * @param env
- * @param conn
- * @param context
- * @param metadata
- */
- public FileProcedureExecution(Call proc, XMLExecutionFactory executionFactory,
FileConnection connection) {
- this.procedure = proc;
- this.executionFactory = executionFactory;
- this.connection = connection;
- }
-
- /**
- * @see
org.teiid.connector.api.ProcedureExecution#execute(org.teiid.connector.language.Call,
int)
- */
- @Override
- public void execute() throws TranslatorException {
-
- // look for the name of the file to return in the metadata, "Name in
Source" property
- AbstractMetadataRecord metaObject = procedure.getMetadataObject();
- String fileName = metaObject.getNameInSource();
-
- // if the source procedure name is not supplied then throw an exception
- if (fileName == null || fileName.length() == 0) {
- throw new
TranslatorException(XMLPlugin.Util.getString("source_name_not_supplied", new
Object[] {procedure.getProcedureName()})); //$NON-NLS-1$
- }
-
- final File[] files = FileConnection.Util.getFiles(fileName, this.connection);
- if (files.length == 0 || !files[0].exists()) {
- throw new
TranslatorException(XMLPlugin.Util.getString("file_not_supplied", new Object[]
{fileName, procedure.getProcedureName()})); //$NON-NLS-1$
- }
-
- String encoding = this.executionFactory.getCharacterEncodingScheme();
-
- returnValue = new SQLXMLImpl(new
InputStreamFactory.FileInputStreamFactory(files[0], encoding));
-
- LogManager.logDetail(LogConstants.CTX_CONNECTOR,
XMLPlugin.Util.getString("executing_procedure", new Object[]
{procedure.getProcedureName()})); //$NON-NLS-1$
- }
-
- @Override
- public List<?> next() throws TranslatorException, DataNotAvailableException {
- if (!returnedResult) {
- returnedResult = true;
- return Arrays.asList(returnValue);
- }
- return null;
- }
-
- @Override
- public List<?> getOutputParameterValues() throws TranslatorException {
- throw new
TranslatorException(XMLPlugin.Util.getString("No_outputs_allowed"));
//$NON-NLS-1$
- }
-
- public void close() {
- // no-op
- }
-
- public void cancel() throws TranslatorException {
- // no-op
- }
-}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/FileResultSetExecution.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/FileResultSetExecution.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/FileResultSetExecution.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,140 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-package org.teiid.translator.xml;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.teiid.core.types.InputStreamFactory;
-import org.teiid.translator.DataNotAvailableException;
-import org.teiid.translator.FileConnection;
-import org.teiid.translator.ResultSetExecution;
-import org.teiid.translator.TranslatorException;
-import org.teiid.translator.xml.streaming.InvalidPathException;
-import org.teiid.translator.xml.streaming.StreamingResultsProducer;
-import org.teiid.translator.xml.streaming.XPathSplitter;
-
-public class FileResultSetExecution implements ResultSetExecution {
- public static final String PARM_FILE_NAME_TABLE_PROPERTY_NAME = "FileName";
//$NON-NLS-1$
-
- private ExecutionInfo executionInfo;
- private int docNumber = 0;
- private File[] content;
- private XMLExecutionFactory executionFactory;
- private List<StremableDocument> resultDocuments = null;
- private StreamingResultsProducer streamProducer;
- private List<Object[]> currentRowSet;
- private int currentRow = 0;
-
-
- public FileResultSetExecution(List<CriteriaDesc> requestParams, ExecutionInfo
executionInfo, XMLExecutionFactory executionFactory, FileConnection connection) throws
TranslatorException {
-
- this.executionInfo = executionInfo;
-
- String tableName = this.executionInfo.getLocation();
- if (tableName == null) {
- tableName =
this.executionInfo.getOtherProperties().get(PARM_FILE_NAME_TABLE_PROPERTY_NAME);
- }
-
- this.content = FileConnection.Util.getFiles(tableName, connection);
-
- validateParams();
-
- this.executionInfo.setParameters(requestParams);
- this.executionFactory = executionFactory;
- this.streamProducer = new StreamingResultsProducer(this.executionInfo,
this.executionFactory.getSaxFilterProvider());
- }
-
- /**
- * Validates that the query can be supported. Probably better suited to a call out from
QueryAnalyzer.
- * @throws ConnectorException
- */
- private void validateParams() throws TranslatorException {
- for (int i = 0; i < this.executionInfo.getRequestedColumns().size(); i++) {
- OutputXPathDesc xPath =
(OutputXPathDesc)this.executionInfo.getRequestedColumns().get(i);
- if (xPath.isParameter()) {
- throw new
TranslatorException(XMLPlugin.getString("FileExecutor.input.not.supported.on.files"));
//$NON-NLS-1$
- }
- }
- }
-
- @Override
- public void execute() throws TranslatorException {
- if (this.content != null) {
- this.resultDocuments = new ArrayList<StremableDocument>();
- int i = 0;
- for(File f:this.content) {
- this.resultDocuments.add(getDocumentStream(f, i++));
- }
- }
- }
-
- @Override
- public List<?> next() throws TranslatorException, DataNotAvailableException {
- if (this.currentRowSet == null) {
- while(this.docNumber < resultDocuments.size()) {
- this.currentRowSet =
streamProducer.getResult(this.resultDocuments.get(this.docNumber++), getXPaths());
- this.currentRow = 0;
- if (this.currentRowSet.isEmpty()) {
- continue;
- }
- }
- }
-
- if (this.currentRowSet != null) {
- if (this.currentRow <= this.currentRowSet.size()) {
- List result = Arrays.asList(this.currentRowSet.get(this.currentRow++));
- if(this.currentRow == this.currentRowSet.size()) {
- this.currentRowSet = null;
- }
- return result;
- }
- }
- return null;
- }
-
- private List<String> getXPaths() throws TranslatorException {
- XPathSplitter splitter = new XPathSplitter();
- try {
- return splitter.split(this.executionInfo.getTableXPath());
- } catch (InvalidPathException e) {
- throw new TranslatorException(e);
- }
- }
-
- private StremableDocument getDocumentStream(final File xmlFile, int fileNumber) {
- InputStreamFactory isf = new InputStreamFactory.FileInputStreamFactory(xmlFile);
- return new StremableDocument(this.executionFactory.convertToXMLType(isf),
xmlFile.getName()+fileNumber);
- }
-
- @Override
- public void cancel() throws TranslatorException {
-
- }
-
- @Override
- public void close() {
-
- }
-}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/IDGeneratingXmlFilter.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/IDGeneratingXmlFilter.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/IDGeneratingXmlFilter.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,154 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator.xml;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.AttributesImpl;
-import org.xml.sax.helpers.XMLFilterImpl;
-
-
-public class IDGeneratingXmlFilter extends XMLFilterImpl
-{
- protected static class PathElement
- {
- protected PathElement(String name, int index)
- {
- this.name = name;
- this.index = index;
- predecessorCounts = new HashMap();
- }
- protected String name;
- protected int index;
- protected Map predecessorCounts; // keys: predecessor sibling names, values:
count of times it has appeared
- }
-
- public IDGeneratingXmlFilter(String documentId)
- {
- this.documentId = documentId;
- }
-
- public static final String MM_ID_ATTR_NAME_BY_PATH =
"com.metamatrix.xml.xpathpart";
- public static final String MM_ID_ATTR_NAME_BY_INDEX =
"com.metamatrix.xml.xpathpart.byindex";
- public static final String MM_ID_ATTR_NAME = MM_ID_ATTR_NAME_BY_PATH;
- public static final String MM_ID_ATTR_VALUE_PREFIX = "";
-
- String documentId;
-
- // This way of doing things seems like cheating, but it will produce the desired
results.
- // Only problem: the IDs are completely opaque and meaningless.
- int index = 0;
-
- // This way is nicer
- List path; // a list of PathElement objects
-
- @Override
- public void startDocument() throws SAXException
- {
- path = new ArrayList();
- PathElement newPathElement = new PathElement(documentId, -1);
- path.add(newPathElement);
-
- super.startDocument();
- }
-
- private String getIdFromIndex()
- {
- String retval = MM_ID_ATTR_VALUE_PREFIX + documentId + "/" + index;
- ++index;
- return retval;
- }
-
- private String getIdFromPath(String qName)
- {
- StringBuffer retval = new StringBuffer();
-
- Object oParentPath = path.get(path.size() - 1);
- PathElement parentPath = (PathElement)oParentPath;
- Map predecessorCounts = parentPath.predecessorCounts;
- Object oCount = predecessorCounts.get(qName);
- Integer count = (Integer)oCount;
- int index;
- if (count == null) {
- index = 0;
- }
- else {
- index = count.intValue() + 1;
- }
- predecessorCounts.put(qName, Integer.valueOf(index));
-
- PathElement newPathElement = new PathElement(qName, index);
- path.add(newPathElement);
-
- boolean first = true;
- for (Iterator iter = path.iterator(); iter.hasNext() ; ) {
- Object o = iter.next();
- PathElement pathElement = (PathElement)o;
- if (first) {
- first = false;
- }
- else {
- retval.append('/');
- }
- retval.append(pathElement.name);
- if (pathElement.index >= 0) {
- retval.append('[');
- retval.append(pathElement.index);
- retval.append(']');
- }
- }
-
- return retval.toString();
- }
-
- @Override
- public void startElement(String namespaceURI, String localName,
- String qName, Attributes atts) throws SAXException
- {
- String indexValue = getIdFromIndex();
- String pathValue = getIdFromPath(qName);
- Attributes newAtts = addAttributes(atts, indexValue, pathValue);
- super.startElement(namespaceURI, localName, qName, newAtts);
- }
-
- protected Attributes addAttributes(Attributes atts, String indexValue, String
pathValue)
- {
- AttributesImpl newAtts = new AttributesImpl(atts);
- newAtts.addAttribute("", MM_ID_ATTR_NAME, MM_ID_ATTR_NAME,
"CDATA", pathValue);
- newAtts.addAttribute("", MM_ID_ATTR_NAME_BY_INDEX,
MM_ID_ATTR_NAME_BY_INDEX, "CDATA", indexValue);
- return newAtts;
- }
-
- @Override
- public void endElement(String namespaceURI, String localName, String qName)
- throws SAXException {
- path.remove(path.size() - 1);
- super.endElement(namespaceURI, localName, qName);
- }
-}
\ No newline at end of file
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/OutputXPathDesc.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/OutputXPathDesc.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/OutputXPathDesc.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,84 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-
-package org.teiid.translator.xml;
-
-import java.text.MessageFormat;
-
-import org.teiid.language.Literal;
-import org.teiid.metadata.Column;
-import org.teiid.translator.TranslatorException;
-
-public class OutputXPathDesc extends ParameterDescriptor {
-
- // Describes an item in the xpath structure, and all the attributes of it
- // Added to allow all the attributes of an Xpath to be stored in a single structure,
- // and to make the code more manageable
- private Object m_currentValue = null;
- private Class m_dataType = null;
-
-
- /**
- * @see
com.metamatrix.server.datatier.SynchConnectorConnection#submitRequest(java.lang.Object)
- */
- public OutputXPathDesc (Column myElement) throws TranslatorException {
- super(myElement);
- m_dataType = myElement.getJavaType();
- if (getXPath() == null) {
- if (!isSpecial()) {
- String rawMsg =
XMLPlugin.getString("OutputXPathDesc.name.in.source.required.on.column");
//$NON-NLS-1$
- String msg = MessageFormat.format(rawMsg, new Object[] {getColumnName()});
- throw new TranslatorException(msg);
- }
- }
- }
-
- public boolean isSpecial() {
- return isParameter() || isResponseId() || isLocation();
- }
-
- public OutputXPathDesc (Literal literal) throws TranslatorException {
- super();
- if (literal.getValue() == null) {
- setCurrentValue(null);
- } else {
- setCurrentValue(literal.getValue().toString());
- }
- m_dataType = literal.getType();
- }
-
-
- public void setCurrentValue(Object obj) {
- m_currentValue = obj;
- }
-
- public Object getCurrentValue() {
- return m_currentValue;
- }
-
-
- public Class getDataType() throws TranslatorException {
- return m_dataType;
- }
-
-}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/ParameterDescriptor.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/ParameterDescriptor.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/ParameterDescriptor.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,156 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator.xml;
-
-import org.teiid.metadata.Column;
-import org.teiid.translator.TranslatorException;
-
-public abstract class ParameterDescriptor {
-
- private String m_xPath;
- private boolean m_param;
- private boolean m_responseId;
- private boolean m_location;
- private String m_columnName;
- private int m_columnNumber = -1;
- private Column m_element;
-
- public static final String PARM_INPUT_COLUMN_PROPERTY_NAME =
"IsInputParameter"; //$NON-NLS-1$
- public static final String ROLE_COLUMN_PROPERTY_NAME = "Role";
//$NON-NLS-1$
- public static final String ROLE_COLUMN_PROPERTY_NAME_RESPONSE_IN =
"ResponseIn"; //$NON-NLS-1$
- public static final String ROLE_COLUMN_PROPERTY_NAME_RESPONSE_OUT =
"ResponseOut"; //$NON-NLS-1$
- public static final String ROLE_COLUMN_PROPERTY_NAME_LOCATION = "Location";
//$NON-NLS-1$
- public static final String ROLE_COLUMN_PROPERTY_NAME_DATA = "Data";
//$NON-NLS-1$
-
- public ParameterDescriptor( Column element ) throws TranslatorException {
- setElement(element);
- setIsParameter(testForParam(m_element));
- testRole();
- if (getElement().getNameInSource() != null) {
- setColumnName(getElement().getNameInSource());
- } else {
- setColumnName(getElement().getName().trim());
- }
- String nis = getElement().getNameInSource();
- if (nis != null) {
- nis = nis.trim();
- }
- setXPath(nis);
- }
-
- protected ParameterDescriptor() {
- setIsParameter(false);
- setIsResponseId(false);
- setIsLocation(false);
- setColumnName(null);
- setXPath(null);
- }
-
- public final void setXPath( String xPath ) {
- m_xPath = xPath;
- }
-
- public String getXPath() {
- return m_xPath;
- }
-
- public final void setIsParameter( boolean param ) {
- m_param = param;
- }
-
- public final void setIsResponseId( boolean responseId ) {
- m_responseId = responseId;
- }
-
- public final void setIsLocation( boolean location ) {
- m_location = location;
- }
-
- public final boolean isParameter() {
- return m_param;
- }
-
- public final boolean isResponseId() {
- return m_responseId;
- }
-
- public final boolean isLocation() {
- return m_location;
- }
-
- public final void setColumnName( String columnName ) {
- m_columnName = columnName;
- }
-
- public final String getColumnName() {
- return m_columnName;
- }
-
- public final void setColumnNumber( int columnNumber ) {
- m_columnNumber = columnNumber;
- }
-
- public final int getColumnNumber() {
- return m_columnNumber;
- }
-
- protected void setElement( Column elem ) {
- m_element = elem;
- }
-
- public Column getElement() {
- return m_element;
- }
-
- protected static boolean testForParam( Column element ) throws TranslatorException {
- boolean param = false;
- param =
Boolean.valueOf(element.getProperties().get(PARM_INPUT_COLUMN_PROPERTY_NAME)).booleanValue();
- return param;
- }
-
- public String getRole() throws TranslatorException {
- return m_element.getProperties().get(ROLE_COLUMN_PROPERTY_NAME);
- }
-
- protected void testRole() throws TranslatorException {
- String role = getRole();
- if (role == null) {
- setIsResponseId(false);
- setIsLocation(false);
- } else {
- if (role.equalsIgnoreCase(ROLE_COLUMN_PROPERTY_NAME_RESPONSE_IN)) {
- setIsResponseId(true);
- setIsLocation(false);
- } else if (role.equalsIgnoreCase(ROLE_COLUMN_PROPERTY_NAME_RESPONSE_OUT)) {
- setIsResponseId(true);
- setIsLocation(false);
- } else if (role.equalsIgnoreCase(ROLE_COLUMN_PROPERTY_NAME_LOCATION)) {
- setIsResponseId(false);
- setIsLocation(true);
- } else { // if (role.equalsIgnoreCase(ROLE_COLUMN_PROPERTY_NAME_DATA))
- setIsResponseId(false);
- setIsLocation(false);
- }
- }
- }
-}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/QueryAnalyzer.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/QueryAnalyzer.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/QueryAnalyzer.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,208 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-
-package org.teiid.translator.xml;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.teiid.language.ColumnReference;
-import org.teiid.language.DerivedColumn;
-import org.teiid.language.Expression;
-import org.teiid.language.Literal;
-import org.teiid.language.NamedTable;
-import org.teiid.language.Select;
-import org.teiid.language.TableReference;
-import org.teiid.metadata.Column;
-import org.teiid.metadata.Table;
-import org.teiid.translator.TranslatorException;
-
-public class QueryAnalyzer {
-
- private Select command;
- private Table table;
- private ExecutionInfo executionInfo;
-
- public QueryAnalyzer(Select query) throws TranslatorException {
- this.command = query;
- executionInfo = new ExecutionInfo();
- analyze();
- }
-
- public final void analyze() throws TranslatorException {
- setGroupInfo();
- setRequestedColumns();
- setParametersAndCriteria();
- setProperties();
- }
-
-
-
- public ExecutionInfo getExecutionInfo() {
- return this.executionInfo;
- }
-
- private void setGroupInfo() {
- List<TableReference> fromItems = command.getFrom();
- //Can only be one because we do not support joins
- NamedTable group = (NamedTable) fromItems.get(0);
- this.table = group.getMetadataObject();
- this.executionInfo.setTableXPath(table.getNameInSource());
- }
-
- private void setRequestedColumns() throws TranslatorException {
-
- List<OutputXPathDesc> columns = new ArrayList<OutputXPathDesc>();
- //get the request items
- List<DerivedColumn> selectSymbols = this.command.getDerivedColumns();
-
- //setup column numbers
- int projectedColumnCount = 0;
-
- //add projected fields into XPath array and element array for later
- // lookup
-
- for(DerivedColumn selectSymbol : selectSymbols) {
- Expression expr = selectSymbol.getExpression();
- OutputXPathDesc xpath = null;
-
- //build the appropriate structure
- if (expr instanceof Literal) {
- xpath = new OutputXPathDesc((Literal) expr);
- } else if (expr instanceof ColumnReference) {
- Column element = ((ColumnReference)expr).getMetadataObject();
- xpath = new OutputXPathDesc(element);
- }
- if (xpath != null) {
- xpath.setColumnNumber(projectedColumnCount);
- }
-
- // put xpath object into linked list
- columns.add(xpath);
- ++projectedColumnCount;
- }
-
- //set the column count
- this.executionInfo.setColumnCount(projectedColumnCount);
- this.executionInfo.setRequestedColumns(columns);
- }
-
- private void setParametersAndCriteria() throws TranslatorException {
- //Build a linked list of parameters, and a linked list of equivilence
- // and set selection criteria.
- //Each parameter and criteria is itself represented by a linked list,
- // containing names, element (metadata), and equivilence value, or all
- // set values
-
- ArrayList<CriteriaDesc> params = new ArrayList<CriteriaDesc>();
- ArrayList<CriteriaDesc> crits = new ArrayList<CriteriaDesc>();
- ArrayList<CriteriaDesc> responses = new ArrayList<CriteriaDesc>();
- ArrayList<CriteriaDesc> locations = new ArrayList<CriteriaDesc>();
-
- //Iterate through each field in the table
- for (Column element : table.getColumns()) {
- CriteriaDesc criteria = CriteriaDesc.getCriteriaDescForColumn(
- element, command);
- if (criteria != null) {
- mapCriteriaToColumn(criteria, params, crits, responses, locations);
- }
- }
- this.executionInfo.setParameters(params);
- this.executionInfo.setCriteria(crits);
-
- String location = null;
- for (Iterator<CriteriaDesc> iter = locations.iterator(); iter.hasNext(); )
{
- Object o = iter.next();
- CriteriaDesc crtierion = (CriteriaDesc)o;
- List values = crtierion.getValues();
- for (Iterator valuesIter = values.iterator(); valuesIter.hasNext(); ) {
- Object oValue = valuesIter.next();
- String value = (String)oValue;
- if (location != null) {
- if (!(location.equals(value))) {
- throw new TranslatorException(XMLPlugin
-
.getString("QueryAnalyzer.multiple.locations.supplied")); //$NON-NLS-1$
- }
- }
- location = value;
- }
- }
- this.executionInfo.setLocation(location);
- }
-
- private void mapCriteriaToColumn(CriteriaDesc criteria, ArrayList<CriteriaDesc>
params,
- ArrayList<CriteriaDesc> crits, ArrayList<CriteriaDesc> responses,
ArrayList<CriteriaDesc> locations) throws TranslatorException {
- int totalColumnCount = this.executionInfo.getColumnCount();
- //check each criteria to see which projected column it maps to
- String criteriaColName = criteria.getColumnName();
- boolean matchedField = false;
- OutputXPathDesc xpath = null;
- for (int j = 0; j < this.executionInfo.getRequestedColumns().size(); j++) {
- xpath = (OutputXPathDesc) this.executionInfo.getRequestedColumns().get(j);
- String projColName = xpath.getColumnName();
- if (criteriaColName.equals(projColName)) {
- matchedField = true;
- criteria.setColumnNumber(j);
- break;
- }
- }
- if (criteria.isParameter() || criteria.isResponseId() &&
!criteria.isLocation()) {
- params.add(criteria);
- if (criteria.isResponseId()) {
- responses.add(criteria);
- }
- } else {
-
- // otherwise add a new column to the projected XPath list (don't
- // worry,
- // it will be removed later and not really projected.
- // match not found, add to project list
- if (!matchedField) {
- criteria.setColumnNumber(totalColumnCount);
- xpath = new OutputXPathDesc(criteria
- .getElement());
- xpath.setColumnNumber(totalColumnCount++);
- this.executionInfo.getRequestedColumns().add(xpath);
- }
- if (xpath.isResponseId()) {
- responses.add(criteria);
- }
- else if (xpath.isLocation()) {
- locations.add(criteria);
- }
- else {
- crits.add(criteria);
- }
- }
- }
-
- private void setProperties() {
- this.executionInfo.setOtherProperties(table.getProperties());
- }
-
- public List<List<CriteriaDesc>> getRequestPerms() {
- return
CartesienCriteriaGenerator.generateCartesianCriteria(this.executionInfo.getParameters());
- }
-
-}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/RequestGenerator.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/RequestGenerator.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/RequestGenerator.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,107 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-
-
-package org.teiid.translator.xml;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class RequestGenerator {
-
- // This method is misnamed. It generates cartesian products, not permutations.
- public static List<CriteriaDesc[]> getRequests(List<CriteriaDesc> params)
- {
- List<CriteriaDesc[]> soFar = new ArrayList<CriteriaDesc[]>();
-
- // Start off with a single "row" (with zero parameters)
- soFar.add(new CriteriaDesc[]{});
- for (CriteriaDesc desc: params){
- soFar = RequestGenerator.createCartesionProduct(soFar, desc);
- }
-
- return soFar;
- }
-
- // Create the cartesian product of a list of CriteriaDescs, and single CriteriaDesc
- // with (potentially) multiple values
- static List<CriteriaDesc[]> createCartesionProduct(List<CriteriaDesc[]>
permsSoFar, CriteriaDesc desc)
- {
- List<CriteriaDesc[]> retval = new ArrayList<CriteriaDesc[]>();
-
- // Get the 'simple' cartesian product
- List<List> rows = createCartesionProduct(permsSoFar, desc.getValues(),
desc.isUnlimited());
-
- // Merge the existing list of CriteriaDescs with the new value turned into a
CriteriaDesc)
- for (List row : rows) {
- Object oOperand1 = row.get(0);
- CriteriaDesc[] previousCriteriaDescs = (CriteriaDesc[])oOperand1;
-
- CriteriaDesc[] newRow = new CriteriaDesc[previousCriteriaDescs.length + 1];
- System.arraycopy(previousCriteriaDescs, 0, newRow, 0, previousCriteriaDescs.length);
- CriteriaDesc singleValueCriteriaDesc = desc.cloneWithoutValues();
- for (int i=1; i < row.size(); i++ ){
- Object value = row.get(i);
- singleValueCriteriaDesc.setValue((i - 1), value);
- }
- newRow[newRow.length - 1] = singleValueCriteriaDesc;
- retval.add(newRow);
- }
- return retval;
- }
-
- // Create the cartesian product of any two lists
- private static List<List> createCartesionProduct(List<CriteriaDesc[]>
operand1, List operand2, boolean multiElem)
- {
- if (operand1.size() == 0) {
- operand1 = new ArrayList<CriteriaDesc[]>();
- operand1.add(null);
- }
-
- if (operand2.size() == 0) {
- operand2 = new ArrayList();
- operand2.add(null);
- }
-
-
- List<List> cartesianProduct = new ArrayList<List>();
- for (CriteriaDesc[] operand1item : operand1) {
- List newRow = new ArrayList();
- if (! multiElem) {
- for (Object operand2item : operand2 ) {
- newRow.add(operand1item);
- newRow.add(operand2item);
- cartesianProduct.add(newRow);
- }
- } else {
- newRow.add(operand1item);
- for (Object operand2item : operand2 ) {
- newRow.add(operand2item);
- }
- cartesianProduct.add(newRow);
- }
- }
- return cartesianProduct;
- }
-
-}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/RequestPreprocessor.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/RequestPreprocessor.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/RequestPreprocessor.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,44 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-
-
-package org.teiid.translator.xml;
-
-import org.teiid.language.Select;
-import org.teiid.metadata.RuntimeMetadata;
-import org.teiid.translator.ExecutionContext;
-
-public interface RequestPreprocessor {
- /**
- *
- * This method is used for altering the query before it enters the XML connector's
processing
- *
- * @param query The IQuery passed from the connector
- * @param m_logger the connector logger
- * @param connectorEnv the connector environment
- * @param exeContext the execution context
- * @param m_metadata the runtime metadata
- * @return an IQuery object representing the altered query
- */
- public Select preprocessQuery(Select query, RuntimeMetadata m_metadata, ExecutionContext
exeContext);
-}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/SAXFilterProvider.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/SAXFilterProvider.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/SAXFilterProvider.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,32 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-
-
-package org.teiid.translator.xml;
-
-import org.xml.sax.helpers.XMLFilterImpl;
-
-
-public interface SAXFilterProvider {
- XMLFilterImpl[] getExtendedFilters();
-}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/StremableDocument.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/StremableDocument.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/StremableDocument.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,25 +0,0 @@
-package org.teiid.translator.xml;
-
-import java.io.InputStream;
-import java.sql.SQLException;
-import java.sql.SQLXML;
-
-public class StremableDocument {
-
- private SQLXML xml;
- private String cacheKey;
-
- public StremableDocument(SQLXML xml, String cacheKey) {
- this.xml = xml;
- this.cacheKey = cacheKey;
- }
-
- public InputStream getStream() throws SQLException{
- return xml.getBinaryStream();
- }
-
- public String getCachekey() {
- return cacheKey;
- }
-
-}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/XMLExecutionFactory.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/XMLExecutionFactory.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/XMLExecutionFactory.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,230 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator.xml;
-
-import java.sql.SQLXML;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.resource.ResourceException;
-import javax.resource.cci.Connection;
-import javax.resource.cci.ConnectionFactory;
-import javax.xml.transform.Source;
-import javax.xml.ws.Dispatch;
-
-import org.teiid.language.Call;
-import org.teiid.language.QueryExpression;
-import org.teiid.language.Select;
-import org.teiid.logging.LogConstants;
-import org.teiid.logging.LogManager;
-import org.teiid.logging.MessageLevel;
-import org.teiid.metadata.RuntimeMetadata;
-import org.teiid.translator.ExecutionContext;
-import org.teiid.translator.ExecutionFactory;
-import org.teiid.translator.FileConnection;
-import org.teiid.translator.ProcedureExecution;
-import org.teiid.translator.ResultSetExecution;
-import org.teiid.translator.Translator;
-import org.teiid.translator.TranslatorException;
-import org.teiid.translator.TranslatorProperty;
-import org.teiid.translator.xml.streaming.BaseStreamingExecution;
-
-@Translator(name="xml")
-public class XMLExecutionFactory extends ExecutionFactory {
-
- private String saxFilterProviderClass;
- private String encoding = "ISO-8859-1"; //$NON-NLS-1$
- private Map<String, List<SQLXML>> responses = new
ConcurrentHashMap<String, List<SQLXML>>();
- private boolean logRequestResponseDocs = false;
- private String queryPreprocessorClass;
-
- @TranslatorProperty(description="Encoding of the XML documents",
display="Encoding Scheme")
- public String getCharacterEncodingScheme() {
- return this.encoding;
- }
-
- public void setCharacterEncodingScheme(String encoding) {
- this.encoding = encoding;
- }
-
- @TranslatorProperty(description="Must be extension of
org.teiid.translator.xml.SAXFilterProvider class", display="SAX Filter Provider
Class")
- public String getSaxFilterProviderClass() {
- return this.saxFilterProviderClass;
- }
-
- public void setSaxFilterProviderClass(String saxFilterProviderClass) {
- this.saxFilterProviderClass = saxFilterProviderClass;
- }
-
- @TranslatorProperty(display="Request Preprocessor Class",
description="Must be extension of
org.teiid.translator.xml.RequestPreprocessor")
- public String getRequestPreprocessorClass() {
- return this.queryPreprocessorClass;
- }
-
- public void setRequestPreprocessorClass(String queryPreprocessorClass) {
- this.queryPreprocessorClass = queryPreprocessorClass;
- }
-
- // Can we get rid of this?
- private String inputStreamFilterClass;
-
- public String getInputStreamFilterClass() {
- return this.inputStreamFilterClass;
- }
-
- public void setInputStreamFilterClass(String inputStreamFilterClass) {
- this.inputStreamFilterClass = inputStreamFilterClass;
- }
-
- @TranslatorProperty(description="Log the XML request/response documents",
display="Log Request/Response Documents")
- public boolean isLogRequestResponseDocs() {
- return logRequestResponseDocs &&
LogManager.isMessageToBeRecorded(LogConstants.CTX_CONNECTOR, MessageLevel.DETAIL);
- }
-
- public void setLogRequestResponseDocs(boolean logRequestResponseDocs) {
- this.logRequestResponseDocs = logRequestResponseDocs;
- }
-
- public List<SQLXML> getResponse(String key) {
- return this.responses.get(key);
- }
-
- public void setResponse(String key, SQLXML xml) {
- List<SQLXML> results = this.responses.get(key);
- if (results == null) {
- results = new ArrayList<SQLXML>();
- this.responses.put(key, results);
- }
- results.add(xml);
- }
-
- public List<SQLXML> removeResponse(String key) {
- return this.responses.remove(key);
- }
-
-
- @Override
- public ProcedureExecution createProcedureExecution(Call command, ExecutionContext
executionContext, RuntimeMetadata metadata, Object connectionFactory)
- throws TranslatorException {
- try {
- ConnectionFactory cf = (ConnectionFactory)connectionFactory;
- Connection connection = cf.getConnection();
- if (connection instanceof FileConnection) {
- return new FileProcedureExecution(command, this, (FileConnection)connection);
- }
- else if (connection instanceof Dispatch<?>) {
- return new XMLProcedureExecution(command, metadata, executionContext, this,
(Dispatch)connection);
- }
- else {
- return null;
- }
-
- } catch (ResourceException e) {
- throw new TranslatorException(e);
- }
- }
-
- @Override
- public ResultSetExecution createResultSetExecution(QueryExpression command,
ExecutionContext executionContext, RuntimeMetadata metadata, Object connectionFactory)
- throws TranslatorException {
- RequestPreprocessor preProcessor = getRequestPreProcessor();
- if (preProcessor != null) {
- command = preProcessor.preprocessQuery((Select)command, metadata,
executionContext);
- }
-
- QueryAnalyzer analyzer = new QueryAnalyzer((Select)command);
- ExecutionInfo executionInfo = analyzer.getExecutionInfo();
- List<List<CriteriaDesc>> requestPerms = analyzer.getRequestPerms();
-
- if (requestPerms.size() > 1) {
- CompositeExecution compasiteExecution = new CompositeExecution();
- for (List<CriteriaDesc> cds: requestPerms) {
- compasiteExecution.addExecution(createExecution(cds, executionInfo,
executionContext,connectionFactory));
- }
- return compasiteExecution;
- }
- if (requestPerms.size() == 1) {
- return createExecution(requestPerms.get(0), executionInfo,
executionContext,connectionFactory);
- }
- return createExecution(Collections.EMPTY_LIST, executionInfo,
executionContext,connectionFactory);
- }
-
- private ResultSetExecution createExecution(List<CriteriaDesc> cds, ExecutionInfo
executionInfo, ExecutionContext executionContext, Object connectionFactory)
- throws TranslatorException {
- try {
- ConnectionFactory cf = (ConnectionFactory)connectionFactory;
- Connection connection = cf.getConnection();
- if (connection instanceof FileConnection) {
- return new FileResultSetExecution(cds, executionInfo, this,
(FileConnection)connection);
- }
- else if (connection instanceof Dispatch<?>) {
- return new BaseStreamingExecution(cds, executionInfo, executionContext, this,
(Dispatch)connection);
- }
- } catch (ResourceException e) {
- throw new TranslatorException(e);
- }
- return null;
- }
-
- private RequestPreprocessor getRequestPreProcessor() throws TranslatorException {
- String className = getRequestPreprocessorClass();
- if (className == null) {
- return null;
- }
- return getInstance(RequestPreprocessor.class, className, null, null);
- }
-
- public SAXFilterProvider getSaxFilterProvider() throws TranslatorException {
- if (getSaxFilterProviderClass() == null) {
- return null;
- }
- return getInstance(SAXFilterProvider.class, getSaxFilterProviderClass(), null, null);
- }
-
- public SQLXML convertToXMLType(Source value) {
- return (SQLXML)getTypeFacility().convertToRuntimeType(value);
- }
-
- @Override
- public final int getMaxInCriteriaSize() {
- return Integer.MAX_VALUE;
- }
-
- @Override
- public final List getSupportedFunctions() {
- return Collections.EMPTY_LIST;
- }
-
- @Override
- public final boolean supportsCompareCriteriaEquals() {
- return true;
- }
-
- @Override
- public final boolean supportsInCriteria() {
- return true;
- }
-}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/XMLPlugin.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/XMLPlugin.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/XMLPlugin.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,43 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator.xml;
-
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-import org.teiid.core.BundleUtil;
-
-public class XMLPlugin {
-
- private static final String PLUGIN_ID = XMLPlugin.class.getPackage().getName();
-
- public static final BundleUtil Util = new BundleUtil(PLUGIN_ID, PLUGIN_ID +
".i18n", ResourceBundle.getBundle(PLUGIN_ID + ".i18n")); //$NON-NLS-1$
//$NON-NLS-2$
-
- public static String getString(String key) {
- try {
- return Util.getString(key);
- } catch (MissingResourceException e) {
- return '!' + key + '!';
- }
- }
-}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/XMLProcedureExecution.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/XMLProcedureExecution.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/XMLProcedureExecution.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,138 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator.xml;
-
-import java.io.StringReader;
-import java.sql.Clob;
-import java.sql.SQLException;
-import java.sql.SQLXML;
-import java.util.Arrays;
-import java.util.List;
-
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.ws.Dispatch;
-
-import org.teiid.language.Argument;
-import org.teiid.language.Call;
-import org.teiid.logging.LogConstants;
-import org.teiid.logging.LogManager;
-import org.teiid.metadata.AbstractMetadataRecord;
-import org.teiid.metadata.RuntimeMetadata;
-import org.teiid.translator.DataNotAvailableException;
-import org.teiid.translator.ExecutionContext;
-import org.teiid.translator.ProcedureExecution;
-import org.teiid.translator.TranslatorException;
-
-/**
- * A soap call executor - handles all styles doc/literal, rpc/encoded etc.
- */
-public class XMLProcedureExecution implements ProcedureExecution {
-
- RuntimeMetadata metadata = null;
- ExecutionContext context;
- private Call procedure;
- private boolean returnedResult;
- private SQLXML returnValue;
- private Dispatch<Source> dispatch;
- private XMLExecutionFactory executionFactory;
-
- /**
- * @param env
- */
- public XMLProcedureExecution(Call procedure, RuntimeMetadata metadata,
ExecutionContext context, XMLExecutionFactory executionFactory, Dispatch<Source>
dispatch) {
- this.metadata = metadata;
- this.context = context;
- this.procedure = procedure;
- this.dispatch = dispatch;
- this.executionFactory = executionFactory;
- }
-
- /**
- * @see
org.teiid.connector.api.ProcedureExecution#execute(org.teiid.connector.language.Call,
int)
- */
- public void execute() throws TranslatorException {
-
- AbstractMetadataRecord metaObject = procedure.getMetadataObject();
- String procedureName = metaObject.getNameInSource();
- if (procedureName == null || procedureName.length() == 0) {
- throw new
TranslatorException(XMLPlugin.getString("source_name_not_supplied"));
//$NON-NLS-1$
- }
-
- // execute the request
- Source result;
- try {
- result = this.dispatch.invoke(buildRequest(procedure.getArguments()));
- } catch (SQLException e1) {
- throw new TranslatorException(e1);
- }
- this.returnValue = this.executionFactory.convertToXMLType(result);
- if (executionFactory.isLogRequestResponseDocs()) {
- try {
- LogManager.logDetail(LogConstants.CTX_CONNECTOR, this.returnValue.getString());
- } catch (SQLException e) {
- }
- }
-
- }
-
- Source buildRequest(List<Argument> args) throws SQLException,
TranslatorException{
- if (args.size() != 1) {
- throw new TranslatorException("Expected a single argument to the procedure
execution"); //$NON-NLS-1$
- }
- Argument arg = args.get(0);
- Object value = arg.getArgumentValue().getValue();
- if (value instanceof SQLXML) {
- return new StreamSource(((SQLXML)value).getCharacterStream());
- } else if (value instanceof Clob) {
- return new StreamSource(((Clob)value).getCharacterStream());
- } else if (value != null) {
- return new StreamSource(new StringReader(value.toString()));
- } else {
- //TODO: work around for JBoss native
- return new StreamSource(new StringReader("<none/>"));
//$NON-NLS-1$
- }
- }
-
- @Override
- public List<?> next() throws TranslatorException, DataNotAvailableException {
- if (!returnedResult) {
- returnedResult = true;
- return Arrays.asList(this.returnValue);
- }
- return null;
- }
-
- @Override
- public List<?> getOutputParameterValues() throws TranslatorException {
- throw new
TranslatorException(XMLPlugin.getString("No_outputs_allowed")); //$NON-NLS-1$
- }
-
- public void close() {
- // no-op
- }
-
- public void cancel() throws TranslatorException {
- // no-op
- }
-}
Modified:
trunk/connectors/translator-xml/src/main/resources/org/teiid/translator/xml/i18n.properties
===================================================================
---
trunk/connectors/translator-xml/src/main/resources/org/teiid/translator/xml/i18n.properties 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/main/resources/org/teiid/translator/xml/i18n.properties 2010-06-08
19:11:59 UTC (rev 2202)
@@ -20,57 +20,3 @@
# 02110-1301 USA.
#
-XMLConnection.update.not.supported=XML update is not supported at this time
-XMLConnection.no.xml.procedures=XML procedures are not supported at this time
-XMLConnection.invalid.execution.mode=Invalid execution mode
-XMLConnector.state.not.set=Cannot create a Connection if the Connector's state is not
set
-CriteriaDesc.value.not.found.for.param=Value not found for parameter
-CriteriaDesc.property.not.defaulted=Property value is not properly defaulted. System
error.
-CriteriaDesc.allow.empty.not.defaulted=Property value for allowing empty values is not
defaulted. System error.
-CriteriaDesc.input.xpath.not.defaulted=Property value for input XPath is not properly
defaulted. System error.
-CriteriaDesc.parent.attribute.not.defaulted=Property value for parent attribute flag is
not properly defaulted. System error.
-CriteriaDesc.attribute.name.not.defaulted=Property value for attribute name is not
properly defaulted. System error.
-Executor.name.in.source.required=Name in source is required for all XMLRequest tables
-Executor.xml.docs.not.found=no XML documents found for processing
-Executor.saxpath.error.on.column=SAXPath error on column-level XPath for column {0}
-Executor.jaxen.error.on.selectsinglenode=Jaxen error on column-level selectSingleNode for
column {0}
-Executor.saxpath.error.on.group=SAXPath error on group-level XPath
-Executor.jaxen.error.on.selectnodes=Jaxen error on group-level selectNodes
-Executor.jaxen.error.on.namespace.pairs=Jaxen error on namespace pairs {0} {1}
-Executor.unsupported.compound.xpath=Compound XPaths containing union operators (|) must
be delimited by parentheses.
-Executor.default.namespace.not.allowed.in.xpath=Default namespaces not allowed in xpath
queries; consider using an explicit prefix (see XPath spec section 2.3)
-Executor.IdTransform.xsl.not.found=Unable to find IdTransform.xsl file for unique ID
generation
-Executor.unknown.document.producer=The DocumentProduce is an unknown type. Type is {0}
-OutputXPathDesc.name.in.source.required.on.column=Missing 'name in source'
property for output column {0}
-OutputXPathDesc.property.value.not.defaulted=Property value is not properly defaulted.
System error.
-XMLConnector.could.not.create.state=could not create state class
-XMLExecution.type.conversion.failure=Data value {0} cannot be converted to {1}.
Processing will be terminated.
-XMLExecution.invalid.comparison=The following criteria cannot be executed because values
are of different types: {0} = {1}
-DocumentBuilder.could.not.parse.namespaces=could not parse namespaces
-ValueReferenceImpl.ValueChunk.class.not.compatible=Unable to find implementation of
ValueChunk for creating a CLOB
-HTTPExecutor.error.building.column=Error building input parameters
-QueryAnalyzer.multiple.responseid.supplied=Multiple different values for Response In
field(s) supplied
-QueryAnalyzer.multiple.locations.supplied=Multiple different values for Location field(s)
supplied
-document.expired.can.not.recreate=The cached document has expired and the connection
factory is set to not recreate it
-HTTPExecutor.root.element.required=All XML requests require a root input element.
-Executor.error.decoding.request.id=Unable to decode request id
-Executor.unable.to.encode.response.id=Unable to encode response id
-HTTPExecutor.unable.to.recreate.request=Unable to recreate the request
-HTTPExecutor.dot.notation.not.allowed=Illegal use of dot notation in input XPaths
-Executor.unable.to.encode.response.id=Unable to serialize request object
-XMLConnector.NoLicense=License not found for XML Connectors
-DocumentBuilder.encoding.type.required=Native types are required when using RPC-encoded
or Document-Encoded messages
-document.expired.can.not.recreate=The target document has expired from the cache.
-SecureConnectorState.error.loading.trust.deserializer=An error occured loading the Trust
Deserializer class.
-SecureConnectorState.empty.trust.deserializer=The Trust Deserializer field in the
connection factory is null or empty.
-SOAPConnectorStateImpl.empty.ENCODING_STYLE_PROPERTY_NAME=The Encoding Style in the
connection factory is null or empty.
-SOAPConnectorStateImpl.invalid.ENCODING_STYLE_PROPERTY_NAME=The Encoding Style in the
connection factory is not one of the expected values: {0}, {1}, {2}, {3}.
-SOAPConnectorStateImpl.empty.AUTH_USER_PROPERTY_NAME=Authentication is enabled but the
Authentication User Name is null or empty.
-SOAPConnectorStateImpl.empty.AUTH_PASSWORD_PROPERTY_NAME=Authentication is enabled but
the Authentication Password is null or empty.
-SOAPConnectorStateImpl.empty.CONNECTOR_EXCEPTION_ON_SOAP_FAULT=The Exception On
Intra-Query Cache Expiration field in the connection factory is null or empty.
-InputStream_reset_not_supported=Mark/Reset are not supported on the
InputStreamFilterClass
-No_outputs_allowed=No output parameter variables are allowed in the xml source
connectors.
-source_name_not_supplied=Name In the Source property is not specified for the operation
"{0}"; Failed to execute.
-executing_procedure=executing the procedure "{0}"
-file_not_supplied=XML file not found "{0}" for procedure execution
"{1}"
-failed_to_generate_xml_request=Failed to generate the XML request input for the
execution.
\ No newline at end of file
Deleted:
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/MockQueryPreprocessor.java
===================================================================
---
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/MockQueryPreprocessor.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/MockQueryPreprocessor.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,42 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-
-
-package org.teiid.translator.xml;
-
-import org.teiid.language.Select;
-import org.teiid.metadata.RuntimeMetadata;
-import org.teiid.translator.ExecutionContext;
-import org.teiid.translator.xml.RequestPreprocessor;
-
-public class MockQueryPreprocessor implements RequestPreprocessor {
-
- public MockQueryPreprocessor() {
- super();
- }
-
- public Select preprocessQuery(Select query, RuntimeMetadata m_metadata, ExecutionContext
exeContext) {
- return query;
- }
-
-}
Deleted:
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/ProxyObjectFactory.java
===================================================================
---
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/ProxyObjectFactory.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/ProxyObjectFactory.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,215 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator.xml;
-
-import java.io.File;
-import java.io.StringReader;
-import java.net.URISyntaxException;
-import java.net.URL;
-
-import org.jdom.Document;
-import org.jdom.input.SAXBuilder;
-import org.mockito.Mockito;
-import org.teiid.language.Select;
-import org.teiid.metadata.RuntimeMetadata;
-import org.teiid.translator.ExecutionContext;
-
-import com.metamatrix.cdk.api.TranslationUtility;
-/**
- *
- */
-public class ProxyObjectFactory {
-
- public static final String JMS_DESTINATION = "dynamicQueues/topic1";
- public static final String INITIAL_CONTEXT_FACTORY =
"org.apache.activemq.jndi.ActiveMQInitialContextFactory";
- private static String docFolder = null;
-
-
- private ProxyObjectFactory() {
-
- }
-
-
-// public static HTTPManagedConnectionFactory
getHTTPTestConnectorEnvironment(Properties props) {
-// if (props == null) {
-// props = getDefaultHTTPProps();
-// }
-// HTTPManagedConnectionFactory env = new HTTPManagedConnectionFactory();
-// PropertiesUtils.setBeanProperties(env, props, null);
-// return env;
-// }
-
- public static ExecutionContext getDefaultSecurityContext() {
- return Mockito.mock(ExecutionContext.class);
- }
-
- public static ExecutionContext getDefaultExecutionContext() {
- ExecutionContext ec = Mockito.mock(ExecutionContext.class);
- Mockito.stub(ec.getRequestIdentifier()).toReturn("request");
- Mockito.stub(ec.getPartIdentifier()).toReturn("testPartId");
-
- return ec;
- }
-
- public static ExecutionContext getExecutionContext(String requestID, String partId)
{
- ExecutionContext ec = Mockito.mock(ExecutionContext.class);
- Mockito.stub(ec.getRequestIdentifier()).toReturn(requestID);
- Mockito.stub(ec.getPartIdentifier()).toReturn(partId);
-
- return ec;
- }
-
-
-//
-// public static Properties getDefaultHTTPProps() {
-// Properties testHTTPProps = new Properties();
-// testHTTPProps.setProperty(XMLConnectorStateImpl.CACHE_ENABLED,
Boolean.TRUE.toString());
-// testHTTPProps.setProperty(HTTPConnectorState.URI,
"http://localhost:8673"); //$NON-NLS-1$
-// testHTTPProps.setProperty(HTTPConnectorState.REQUEST_TIMEOUT, "60");
//$NON-NLS-1$
-// testHTTPProps.setProperty(XMLConnectorState.STATE_CLASS_PROP,
"com.metamatrix.connector.xml.http.HTTPConnectorState"); //$NON-NLS-1$
-// testHTTPProps.setProperty(HTTPConnectorState.HTTP_BASIC_USER, "");
-// testHTTPProps.setProperty(HTTPConnectorState.HTTP_BASIC_PASSWORD,
"");
-// testHTTPProps.setProperty(SecureConnectorState.SECURITY_DESERIALIZER_CLASS,
"com.metamatrix.connector.xml.http.DefaultTrustDeserializer");
-// testHTTPProps.setProperty(HTTPConnectorState.PARAMETER_METHOD,
HTTPConnectorState.PARAMETER_NAME_VALUE);
-// testHTTPProps.setProperty(HTTPConnectorState.ACCESS_METHOD,
HTTPConnectorState.GET);
-// return testHTTPProps;
-// }
-
-
-//
-// public static Properties getDefaultNameValueRequestProps() {
-// Properties defaultHTTPProps = getDefaultHttpProps();
-// defaultHTTPProps.setProperty(HTTPConnectorState.PARAMETER_METHOD,
HTTPConnectorState.PARAMETER_NAME_VALUE);
-// return defaultHTTPProps;
-// }
-
-// public static Properties getDefaultHttpProps() {
-// Properties testHTTPProps = new Properties();
-// testHTTPProps.put(XMLConnectorStateImpl.CACHE_ENABLED, Boolean.TRUE);
-// testHTTPProps.put(XMLConnectorStateImpl.CONNECTOR_CAPABILITES,
"com.metamatrix.connector.xml.base.XMLCapabilities");
-// testHTTPProps.setProperty(XMLConnectorState.STATE_CLASS_PROP,
"com.metamatrix.connector.xml.http.HTTPConnectorState");
-// testHTTPProps.setProperty(XMLConnectorStateImpl.QUERY_PREPROCESS_CLASS,
"com.metamatrix.connector.xml.base.NoQueryPreprocessing");
-// testHTTPProps.setProperty(XMLConnectorStateImpl.SAX_FILTER_PROVIDER_CLASS,
"com.metamatrix.connector.xml.base.NoExtendedFilters");
-// testHTTPProps.setProperty(HTTPConnectorState.ACCESS_METHOD,
HTTPConnectorState.GET);
-// testHTTPProps.setProperty(HTTPConnectorState.PARAMETER_METHOD,
HTTPConnectorState.PARAMETER_XML_REQUEST);
-// testHTTPProps.setProperty(HTTPConnectorState.URI,
"http://0.0.0.0:8673");
-// //testHTTPProps.setProperty(HTTPConnectorState.PROXY_URI,
"http://0.0.0.0:8673");
-// testHTTPProps.setProperty(HTTPConnectorState.REQUEST_TIMEOUT,
"60");
-// testHTTPProps.setProperty(HTTPConnectorState.XML_PARAMETER_NAME,
"XMLRequest");
-// testHTTPProps.setProperty(HTTPConnectorState.HTTP_BASIC_USER, "");
-// testHTTPProps.setProperty(HTTPConnectorState.HTTP_BASIC_PASSWORD,
"");
-// testHTTPProps.setProperty(SecureConnectorState.SECURITY_DESERIALIZER_CLASS,
"com.metamatrix.connector.xml.http.DefaultTrustDeserializer");
-// return testHTTPProps;
-// }
-
-
-
-
-// public static XMLConnector getDefaultXMLConnector() {
-// XMLConnector conn;
-// try {
-// conn = new XMLConnector();
-// conn.initialize(getDefaultTestConnectorEnvironment());
-// } catch (ConnectorException ce) {
-// ce.printStackTrace();
-// conn = null;
-// }
-// return conn;
-// }
-
-// public static XMLConnector getDefaultHTTPConnector(Properties props) {
-// XMLConnector conn;
-// try {
-// conn = new XMLConnector();
-// conn.initialize(getHTTPTestConnectorEnvironment(props));
-// } catch (ConnectorException ce) {
-// ce.printStackTrace();
-// conn = null;
-// }
-// return conn;
-// }
-//
-// public static XMLConnectionImpl getDefaultXMLConnection() {
-// XMLConnectionImpl connection;
-// try {
-// ExecutionContext ctx = getDefaultSecurityContext();
-// connection = (XMLConnectionImpl) getDefaultXMLConnector().getConnection();
-// } catch (ConnectorException ce) {
-// connection = null;
-// } catch (NullPointerException ne) {
-// connection = null;
-// }
-// return connection;
-// }
-//
-// private static XMLConnectionImpl getHTTPXMLConnection(Properties props) {
-// XMLConnectionImpl connection;
-// try {
-// ExecutionContext ctx = getDefaultSecurityContext();
-// connection = (XMLConnectionImpl)
getDefaultHTTPConnector(props).getConnection();
-// } catch (ConnectorException ce) {
-// connection = null;
-// } catch (NullPointerException ne) {
-// connection = null;
-// }
-// return connection;
-// }
-
-
- public static Select getDefaultIQuery(String vdbPath, String queryString) {
- TranslationUtility transUtil = new TranslationUtility(vdbPath);
- Select query = (Select) transUtil.parseCommand(queryString);
- return query;
- }
-
- public static RuntimeMetadata getDefaultRuntimeMetadata(String vdbPath) {
- TranslationUtility transUtil = new TranslationUtility(vdbPath);
- RuntimeMetadata meta = transUtil.createRuntimeMetadata();
- return meta;
- }
-
- public static Document getDefaultDocument() throws Exception {
- Document doc = null;
- SAXBuilder builder = new SAXBuilder();
- StringReader reader = new
StringReader("<foo><bar>baz</bar></foo>");
- doc = builder.build(reader);
- return doc;
- }
-
- public static String getStateCollegeVDBLocation() {
- return getDocumentsFolder() + "/UnitTests.vdb";
- }
-
- public static String getDocumentsFolder() {
- //is the test running locally or in CruiseControl?
- if (docFolder == null) {
- URL url =
ProxyObjectFactory.class.getClassLoader().getResource("documents");
- try {
- docFolder = new File(url.toURI()).toString();
- } catch (URISyntaxException e) {
- }
- }
- return docFolder;
- }
-
-}
Deleted:
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestCartesianCriteriaGenerator.java
===================================================================
---
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestCartesianCriteriaGenerator.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestCartesianCriteriaGenerator.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,119 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-package org.teiid.translator.xml;
-
-import static org.junit.Assert.*;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.junit.Test;
-import org.teiid.metadata.Column;
-
-
-@SuppressWarnings("nls")
-public class TestCartesianCriteriaGenerator {
-
- @Test
- public void testCartesian() throws Exception {
- String[] validValues = {"ACE", "ADE", "BCE",
"BDE", "ACF", "ADF", "BCF", "BDF"};
-
- List<CriteriaDesc> list = new ArrayList<CriteriaDesc>();
-
- Column c1 = new Column();
- c1.setName("c1");
-
- Column c2 = new Column();
- c2.setName("c2");
-
- Column c3 = new Column();
- c3.setName("c3");
-
- CriteriaDesc desc1 = new CriteriaDesc(c1, Arrays.asList(new String[] {"A",
"B"}));
- CriteriaDesc desc2 = new CriteriaDesc(c2, Arrays.asList(new String[] {"C",
"D"}));
- CriteriaDesc desc3 = new CriteriaDesc(c3, Arrays.asList(new String[] {"E",
"F"}));
- list.add(desc1);
- list.add(desc2);
- list.add(desc3);
-
- List<List<CriteriaDesc>> catesianProduct =
CartesienCriteriaGenerator.generateCartesianCriteria(list);
-
- assertEquals(8, catesianProduct.size());
- for (List<CriteriaDesc> cds:catesianProduct) {
- assertEquals(3, cds.size());
-
- String value = "";
- for (CriteriaDesc cd:cds) {
- List values = cd.getValues();
- for (Object v:values) {
- value = value+v.toString();
- }
- }
- assertTrue(Arrays.asList(validValues).contains(value));
- }
- }
-
-
- @Test
- public void testCartesianWithMultiValue() throws Exception {
- // the brackets represent the grouping, how they come as multi values.
- String[] validValues = {"[A][C][EF]", "[A][D][EF]",
"[B][C][EF]", "[B][D][EF]"};
-
- List<CriteriaDesc> list = new ArrayList<CriteriaDesc>();
-
- Column c1 = new Column();
- c1.setName("c1");
-
- Column c2 = new Column();
- c2.setName("c2");
-
- // make this column takes multi values
- Column c3 = new Column();
- c3.setName("c3");
- c3.setProperty(CriteriaDesc.PARM_HAS_MULTIPLE_VALUES_COLUMN_PROPERTY_NAME,
CriteriaDesc.PARM_HAS_MULTIPLE_VALUES_MULTI_ELEMENT_NAME);
-
- CriteriaDesc desc1 = new CriteriaDesc(c1, Arrays.asList(new String[] {"[A]",
"[B]"}));
- CriteriaDesc desc2 = new CriteriaDesc(c2, Arrays.asList(new String[] {"[C]",
"[D]"}));
- CriteriaDesc desc3 = new CriteriaDesc(c3, Arrays.asList(new String[] {"[E",
"F]"}));
- list.add(desc1);
- list.add(desc2);
- list.add(desc3);
-
- List<List<CriteriaDesc>> catesianProduct =
CartesienCriteriaGenerator.generateCartesianCriteria(list);
-
- assertEquals(4, catesianProduct.size());
- for (List<CriteriaDesc> cds:catesianProduct) {
- assertEquals(3, cds.size());
-
- String value = "";
- for (CriteriaDesc cd:cds) {
- List values = cd.getValues();
- for (Object v:values) {
- value = value+v.toString();
- }
- }
- assertTrue(Arrays.asList(validValues).contains(value));
- }
- }
-
-}
Deleted:
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestCriteriaDesc.java
===================================================================
---
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestCriteriaDesc.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestCriteriaDesc.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,608 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator.xml;
-
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.teiid.language.BaseInCondition;
-import org.teiid.language.ColumnReference;
-import org.teiid.language.Comparison;
-import org.teiid.language.Condition;
-import org.teiid.language.DerivedColumn;
-import org.teiid.language.Expression;
-import org.teiid.language.LanguageUtil;
-import org.teiid.language.Select;
-import org.teiid.metadata.Column;
-import org.teiid.metadata.RuntimeMetadata;
-import org.teiid.translator.TranslatorException;
-import org.teiid.translator.xml.CriteriaDesc;
-
-
-/**
- *
- */
-public class TestCriteriaDesc extends TestCase {
-
- private static String vdbPath;
- private static final String QUERY = "select RequiredDefaultedParam from
CriteriaDescTable " //$NON-NLS-1$
- + "where RequiredDefaultedParam in ('foo') order by
RequiredDefaultedParam"; //$NON-NLS-1$
- private static final String VALUE = "value1"; //$NON-NLS-1$
-
-
-
- static {
- vdbPath = ProxyObjectFactory.getStateCollegeVDBLocation();
- }
-
- public void testGetCriteriaDescForColumn() throws Exception {
- //case 1: values provided
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select RequiredDefaultedParam from CriteriaDescTable where
RequiredDefaultedParam in ('foo')"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertNotNull("CriteriaDesc is null", desc); //$NON-NLS-1$
- }
-
- public void testGetCriteriaDescForColumnDefaultedValue() throws Exception {
- //case 2: param, required, defaulted
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select RequiredDefaultedParam from CriteriaDescTable";
//$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertNotNull("CriteriaDesc is null", desc); //$NON-NLS-1$
- }
-
- public void testGetCriteriaDescForColumnNoCriteria() throws Exception {
- //case 3: param, not required, not defaulted, not allowed empty
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select OptionalNotAllowedEmptyParam from
CriteriaDescTable"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertNull("CriteriaDesc is not null", desc); //$NON-NLS-1$
- }
-
- public void testGetCriteriaDescForColumnAllowEmpty() throws Exception {
- //case 4: param, not required, not defaulted, allowed empty
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select OptionalAllowedEmptyParam from CriteriaDescTable";
//$NON-NLS-1$
- final int colLocation = 0;
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertNotNull("CriteriaDesc is null", desc); //$NON-NLS-1$
- }
-
- public void testGetCriteriaDescForColumnError() {
- //case 5: param, required, not defaulted
- try {
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select RequiredUndefaultedParam from
CriteriaDescTable"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- fail("exception not thrown"); //$NON-NLS-1$
- } catch (TranslatorException ce) {
- }
- }
-
- public void testGetCriteriaDescForColumnNotParam() throws Exception {
- //case 6: not a param
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select OutputColumn from CriteriaDescTable";
//$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertNull("CriteriaDesc is not null", desc); //$NON-NLS-1$
- }
-
- public void testGetCriteriaDescForColumnCompare() throws Exception {
- //case 7: compare criteria
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select RequiredDefaultedParam from CriteriaDescTable where
RequiredDefaultedParam = 'foo'"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertNotNull("CriteriaDesc is null", desc); //$NON-NLS-1$
- }
-
-
- public void testGetCriteriaDescForColumnMultiElement() throws Exception {
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select MultiElementParam from CriteriaDescTable where
MultiElementParam in ('foo','bar')"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- String multiplicityStr = elem.getProperties().get(
- CriteriaDesc.PARM_HAS_MULTIPLE_VALUES_COLUMN_PROPERTY_NAME);
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertNotNull("CriteriaDesc is null", desc); //$NON-NLS-1$
- }
-
- public void testGetCriteriaDescForColumnDelimited() throws Exception {
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select DelimitedParam from CriteriaDescTable where
DelimitedParam in ('foo','bar')"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- String multiplicityStr = elem.getProperties().get(
- CriteriaDesc.PARM_HAS_MULTIPLE_VALUES_COLUMN_PROPERTY_NAME);
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertNotNull("CriteriaDesc is null", desc); //$NON-NLS-1$
- }
-
- public void testGetCriteriaDescForColumnLikeSearchable() {
- try {
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select LikeSearchableParam from CriteriaDescTable where
LikeSearchableParam in ('foo')"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- String multiplicityStr = elem.getProperties().get(
- CriteriaDesc.PARM_HAS_MULTIPLE_VALUES_COLUMN_PROPERTY_NAME);
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- fail("should not be able to handle default value"); //$NON-NLS-1$
- } catch (TranslatorException ce) {
- }
- }
-
- public void testGetCriteriaDescForColumnUnlikeSearchable() throws Exception {
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select UnlikeSearchableParam from CriteriaDescTable where
UnlikeSearchableParam in ('foo')"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- String multiplicityStr = elem.getProperties().get(
- CriteriaDesc.PARM_HAS_MULTIPLE_VALUES_COLUMN_PROPERTY_NAME);
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- }
-
- public void testGetCriteriaDescForColumnUnsearchable() {
- try {
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select UnsearchableParam from CriteriaDescTable where
UnsearchableParam in ('foo','bar')"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- String multiplicityStr = elem.getProperties().get(
- CriteriaDesc.PARM_HAS_MULTIPLE_VALUES_COLUMN_PROPERTY_NAME);
- CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- fail("should not be able to handle default value"); //$NON-NLS-1$
- } catch (TranslatorException ce) {
- }
- }
-
- public void testGetCriteriaDescForColumnLike() throws Exception {
- //case 1: values provided
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select RequiredDefaultedParam from CriteriaDescTable where
RequiredDefaultedParam like 'foo'"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertNotNull("CriteriaDesc is null", desc); //$NON-NLS-1$
- }
-
- public void testGetCriteriaDescForColumnNotEquals() throws Exception {
- //case 1: values provided
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select RequiredDefaultedParam from CriteriaDescTable where
RequiredDefaultedParam != 'foo'"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertNotNull("CriteriaDesc is null", desc); //$NON-NLS-1$
- }
-
- public void testGetCriteriaDescForColumnLiteral() throws Exception {
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select RequiredDefaultedParam from CriteriaDescTable where
concat(RequiredDefaultedParam, 'bar') in('foo')"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertNotNull("CriteriaDesc is null", desc); //$NON-NLS-1$
- }
-
- public void testGetCriteriaDescForColumnNameMatchFailure() throws Exception {
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select RequiredDefaultedParam from CriteriaDescTable where
AttributeParam in('foo')"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertNotNull("CriteriaDesc is null", desc); //$NON-NLS-1$
- }
-
-
- public void testGetCriteriaDescForColumnLeftLiteral() throws Exception {
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select RequiredDefaultedParam from CriteriaDescTable "
//$NON-NLS-1$
- + "where concat('bar', 'foo') = concat('bar',
RequiredDefaultedParam)"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertNotNull("CriteriaDesc is null", desc); //$NON-NLS-1$
- }
-
- public void testGetCriteriaDescForColumnTwoElements() throws Exception {
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select RequiredDefaultedParam from CriteriaDescTable where
OutputColumn = RequiredDefaultedParam"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertNotNull("CriteriaDesc is null", desc); //$NON-NLS-1$
- }
-
- public void testGetCriteriaDescForColumnLeftElementEqualsLiteral() throws Exception {
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select RequiredDefaultedParam from CriteriaDescTable where
AttributeParam = 'foo'"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertNotNull("CriteriaDesc is null", desc); //$NON-NLS-1$
- }
-
- public void testGetCriteriaDescForColumnLeftElementEqualsNonLiteral() throws
Exception {
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select RequiredDefaultedParam from CriteriaDescTable
where" //$NON-NLS-1$
- + " RequiredDefaultedParam = concat('foo', OutputColumn)";
//$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertNotNull("CriteriaDesc is null", desc); //$NON-NLS-1$
- }
-
- public void testGetInputXPathNoXpath() throws Exception {
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select BadNoInputXpath from CriteriaDescTable where
BadNoInputXpath in ('foo')"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertEquals(desc.getColumnName(), desc.getInputXpath());
- }
-
-
- public void testGetInputXPathEmptyXpath() throws Exception {
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select BadEmptyInputXPath from CriteriaDescTable where
BadEmptyInputXPath in ('foo')"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertEquals(desc.getColumnName(), desc.getInputXpath());
- }
-
- public void testGetDataAttributeNameEmptyName() throws Exception {
- assertNotNull("vdb path is null", vdbPath); //$NON-NLS-1$
- String query = "select BadNoDataAttributeName from CriteriaDescTable where
BadNoDataAttributeName in ('foo')"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertEquals("", desc.getDataAttributeName()); //$NON-NLS-1$
- }
-
- public void testGetInputXpath() throws TranslatorException {
- String query = "select RequiredDefaultedParam from CriteriaDescTable";
//$NON-NLS-1$
- String inputXPath = "/req/default/value"; //$NON-NLS-1$
- CriteriaDesc desc = createCriteriaDesc(query);
- assertNotNull("CriteriaDesc is null", desc.getInputXpath());
//$NON-NLS-1$
- assertEquals(inputXPath, desc.getInputXpath());
- }
-
- public void testIsUnlimited() throws TranslatorException {
- CriteriaDesc desc = createCriteriaDesc(QUERY);
- assertFalse("Criteria is flagged as unlimited", desc.isUnlimited());
//$NON-NLS-1$
- }
-
- public void testIsAutoIncrement() throws TranslatorException {
- CriteriaDesc desc = createCriteriaDesc(QUERY);
- assertFalse("criterion is flagged as autoIncrement",
desc.isAutoIncrement()); //$NON-NLS-1$
- }
-
- public void testIsParentAttribute() throws TranslatorException {
- CriteriaDesc desc = createCriteriaDesc(QUERY);
- //before its inited
- assertFalse("criterion is flagged as an attribute",
desc.isParentAttribute()); //$NON-NLS-1$
- //and after for code coverage
- assertFalse("criterion is flagged as an attribute",
desc.isParentAttribute()); //$NON-NLS-1$
- }
-
- public void testIsEnumeratedAttribute() throws TranslatorException {
- CriteriaDesc desc = createCriteriaDesc(QUERY);
- assertFalse("criterion is an enumerated attribute",
desc.isEnumeratedAttribute()); //$NON-NLS-1$
- }
-
- public void testAllowEmptyValueFalse() throws TranslatorException {
- String query = "select OptionalNotAllowedEmptyParam from
CriteriaDescTable"; //$NON-NLS-1$
- CriteriaDesc desc = createCriteriaDesc(query);
- assertFalse("criterion should not allow for empty values",
desc.allowEmptyValue()); //$NON-NLS-1$
- }
-
- public void testAllowEmptyValueTrue() throws TranslatorException {
- String query = "select OptionalAllowedEmptyParam from CriteriaDescTable";
//$NON-NLS-1$
- CriteriaDesc desc = createCriteriaDesc(query);
- //before init
- assertTrue("criterion should allow for empty values",
desc.allowEmptyValue()); //$NON-NLS-1$
- //and after for code coverage
- assertTrue("criterion should allow for empty values",
desc.allowEmptyValue()); //$NON-NLS-1$
- }
-
- public void testIsDataInAttributeFalse() throws TranslatorException {
- CriteriaDesc desc = createCriteriaDesc(QUERY);
- assertFalse("criterion is flagged as data in attribute",
desc.isDataInAttribute()); //$NON-NLS-1$
- }
-
- public void testIsDataInAttributeTrue() throws TranslatorException {
- String query = "select AttributeParam from CriteriaDescTable where
AttributeParam in ('foo')"; //$NON-NLS-1$
- CriteriaDesc desc = createCriteriaDesc(query);
- assertTrue("criterion is not flagged as data in attribute",
desc.isDataInAttribute()); //$NON-NLS-1$
- }
-
- public void testGetDataAttributeName() throws TranslatorException {
- String query = "select AttributeColumn from TestTable where AttributeColumn in
('foo')"; //$NON-NLS-1$
- Column elem = getElement(query);
- String attributeName = "myAttribute"; //$NON-NLS-1$
- ArrayList list = new ArrayList();
- list.add(VALUE);
- CriteriaDesc desc = new CriteriaDesc(elem, list);
- assertNotNull("CriteriaDesc is null", desc.getDataAttributeName());
//$NON-NLS-1$
- assertTrue("column name mismatch - expected " + attributeName
//$NON-NLS-1$
- + " returned " + desc.getDataAttributeName(), //$NON-NLS-1$
- desc.getDataAttributeName().equals(attributeName));
- }
-
- public void testGetValues() throws TranslatorException {
- CriteriaDesc desc = createCriteriaDesc(QUERY);
- List values = desc.getValues();
- assertNotNull("Values list is null", values); //$NON-NLS-1$
- assertEquals(values.get(0), VALUE);
- }
-
- public void testGetNumberOfValues() throws TranslatorException {
- CriteriaDesc desc = createCriteriaDesc(QUERY);
- assertEquals(1, desc.getNumberOfValues());
- }
-
- public void testGetCurrentIndexValue() throws TranslatorException {
- CriteriaDesc desc = createCriteriaDesc(QUERY);
- assertEquals(VALUE, desc.getCurrentIndexValue());
- }
-
- public void testGetCurrentIndexValueEnumerated() throws Exception {
- String query = "select DelimitedParam from CriteriaDescTable where
DelimitedParam in ('foo', 'bar')"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertEquals("There should be two values" , 2,
desc.getNumberOfValues()); //$NON-NLS-1$
- assertEquals("foo", desc.getCurrentIndexValue()); //$NON-NLS-1$
- desc.incrementIndex();
- assertEquals("bar", desc.getCurrentIndexValue()); //$NON-NLS-1$
- }
-
- public void testIncrementIndexEnumerated() throws Exception {
- String query = "select DelimitedParam from CriteriaDescTable where
DelimitedParam in ('foo', 'bar')"; //$NON-NLS-1$
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- RuntimeMetadata metadata = ProxyObjectFactory.getDefaultRuntimeMetadata(vdbPath);
- Column elem = ((ColumnReference) expr).getMetadataObject();
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, iquery);
- assertTrue("We should be able to increment this CriteriaDesc",
desc.incrementIndex()); //$NON-NLS-1$
- }
-
- public void testGetCurrentIndexValueNoValue() throws Exception {
- final String query = "select OptionalAllowedEmptyParam from
CriteriaDescTable"; //$NON-NLS-1$
- Column elem = getElement(query);
- ArrayList list = new ArrayList();
- CriteriaDesc desc = new CriteriaDesc(elem, list);
- assertEquals("", desc.getCurrentIndexValue()); //$NON-NLS-1$
- }
-
- public void testGetCurrentIndexValueNoValueNotEmpty() throws Exception {
- final String query = "select OptionalNotAllowedEmptyParam from
CriteriaDescTable"; //$NON-NLS-1$
- Column elem = getElement(query);
- ArrayList list = new ArrayList();
- CriteriaDesc desc = new CriteriaDesc(elem, list);
- assertNull(desc.getCurrentIndexValue());
- }
-
- public void testIncrementIndex() throws Exception {
- final String value2 = "value2"; //$NON-NLS-1$
- String query = "select MultiCol from MultiTable where MultiCol in
('" + VALUE + "', '" + value2 + "')";
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- Column elem = getElement(query);
- ArrayList list = new ArrayList();
- list.add(VALUE);
- list.add(value2);
- CriteriaDesc desc = new CriteriaDesc(elem, list);
- assertEquals(VALUE, desc.getCurrentIndexValue());
- assertTrue("index increment failed", desc.incrementIndex());
//$NON-NLS-1$
- assertEquals(value2, desc.getCurrentIndexValue());
- assertFalse("index went beyond number of values",
desc.incrementIndex()); //$NON-NLS-1$
- }
-
- public void testResetIndex() throws Exception {
- CriteriaDesc desc = createCriteriaDesc(QUERY);
- desc.resetIndex();
- }
-
- public void testNameMatch() {
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, QUERY);
- Condition crit = query.getWhere();
- List criteriaList = LanguageUtil.separateCriteriaByAnd(crit);
- Iterator criteriaIter = criteriaList.iterator();
- Expression expr = null;
- while (criteriaIter.hasNext()) {
- Condition criteriaSeg = (Condition) criteriaIter.next();
- if (criteriaSeg instanceof Comparison) {
- Comparison compCriteria = (Comparison) criteriaSeg;
- expr = compCriteria.getLeftExpression();
- break;
- } else if (criteriaSeg instanceof BaseInCondition) {
- expr = ((BaseInCondition) criteriaSeg).getLeftExpression();
- break;
- }
- }
- final String column = "CriteriaDescTable.RequiredDefaultedParam";
//$NON-NLS-1$
- assertTrue("column name mismatch - expected " + column + "
returned " + expr, //$NON-NLS-1$ //$NON-NLS-2$
- CriteriaDesc.nameMatch(expr, column));
- }
-
- public void testStringifyCriteria() {
- String withQuotes = "'foodle doodle'"; //$NON-NLS-1$
- String withoutQuotes = "foodle doodle"; //$NON-NLS-1$
- assertEquals("stringify failed", withoutQuotes,
CriteriaDesc.stringifyCriteria(withQuotes)); //$NON-NLS-1$
- }
-
- public void testStringifyCriteriaDoubleQuotes() {
- String control = "foodle doodle"; //$NON-NLS-1$
- String test = "\"foodle doodle\""; //$NON-NLS-1$
- assertEquals("stringify failed", control,
CriteriaDesc.stringifyCriteria(test)); //$NON-NLS-1$
- }
-
- public void testStringifyCriteriaSingleQuote() {
- String test = "'ello govnor."; //$NON-NLS-1$
- assertEquals("stringify failed", test,
CriteriaDesc.stringifyCriteria(test)); //$NON-NLS-1$
- }
-
- public void testStringifyCriteriaSingleDoubleQuote() {
- String test = "\"ello govnor."; //$NON-NLS-1$
- assertEquals("stringify failed", test,
CriteriaDesc.stringifyCriteria(test)); //$NON-NLS-1$
- }
-
-
- public void testBadTableSelect() throws TranslatorException {
- String tempVdbpath = vdbPath;
- vdbPath = ProxyObjectFactory.getDocumentsFolder() + "/UnitTests.vdb";
//$NON-NLS-1$
- try {
- createCriteriaDesc("select BadCol1 from BadTable"); //$NON-NLS-1$
- } finally {
- vdbPath = tempVdbpath;
- }
- }
-
- public void testElementAllowsEmpty() throws TranslatorException {
- String tempVdbpath = vdbPath;
- vdbPath = ProxyObjectFactory.getDocumentsFolder() + "/UnitTests.vdb";
//$NON-NLS-1$
- String strQuery = "Select Balance from Response"; //$NON-NLS-1$
- try {
- Column elem = getElement(strQuery);
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, strQuery);
- CriteriaDesc desc = CriteriaDesc.getCriteriaDescForColumn(elem, query);
- } finally {
- vdbPath = tempVdbpath;
- }
- }
-
-
- private CriteriaDesc createCriteriaDesc(String query) throws TranslatorException {
- Column elem = getElement(query);
- ArrayList list = new ArrayList();
- list.add(VALUE);
- CriteriaDesc desc = new CriteriaDesc(elem, list);
- return desc;
- }
-
- private Column getElement(String query) throws TranslatorException {
- return getElement(query, 0);
- }
-
- private Column getElement(String query, int colLocation)
- throws TranslatorException {
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- Column elem = ((ColumnReference) expr).getMetadataObject();
- return elem;
- }
-
-}
Deleted:
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestElementCollector.java
===================================================================
---
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestElementCollector.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestElementCollector.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,82 +0,0 @@
-package org.teiid.translator.xml;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.sql.SQLXML;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.teiid.core.types.InputStreamFactory;
-import org.teiid.core.types.SQLXMLImpl;
-import org.teiid.language.Select;
-import org.teiid.translator.xml.streaming.ElementProcessor;
-import org.teiid.translator.xml.streaming.ReaderFactory;
-import org.teiid.translator.xml.streaming.StreamingRowCollector;
-
-
-@SuppressWarnings("nls")
-public class TestElementCollector extends TestCase {
-
- StreamingRowCollector builder;
- String filename = ProxyObjectFactory.getDocumentsFolder() +
"/purchaseOrders.xml";
- String vdbPath = ProxyObjectFactory.getDocumentsFolder() +
"/File/purchase_orders.vdb";
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- Map prefixes = new HashMap<String, String>();
- prefixes.put("po", "http://www.example.com/PO1");
- prefixes.put("xsd", "http://www.w3.org/2001/XMLSchema");
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, "SELECT * FROM
po_list.ITEM");
- QueryAnalyzer analyzer = new QueryAnalyzer(query);
- analyzer.analyze();
- ExecutionInfo info = analyzer.getExecutionInfo();
- ElementProcessor processor = new ElementProcessor(info);
- builder = new StreamingRowCollector(prefixes, ReaderFactory.getXMLReader(null),
processor);
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- builder = null;
- }
-
- public void testGetTables1() {
- String path = "/po:purchaseOrders/order/items/item";
- int itemCount = 5968;
- try {
- StremableDocument doc = new StremableDocument(getSQLXML(new
FileInputStream(filename)), "foo");
- List result = builder.getElements(doc, Arrays.asList(path));
- assertEquals(itemCount, result.size());
- } catch (Exception e) {
- fail(e.getMessage());
- }
- }
-
- public void testGetRoot() {
- String path = "/";
- int itemCount = 1;
- try {
- StremableDocument doc = new StremableDocument(getSQLXML(new
FileInputStream(filename)), "foo");
- List result = builder.getElements(doc, Arrays.asList(path));
- assertEquals(itemCount, result.size());
- } catch (Exception e) {
- fail(e.getMessage());
- }
- }
-
- SQLXML getSQLXML(final InputStream in) {
- InputStreamFactory isf = new InputStreamFactory("ISO-8859-1") {
- @Override
- public InputStream getInputStream() throws IOException {
- return in;
- }
- };
- return new SQLXMLImpl(isf);
- }
-}
Deleted:
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestExecutionInfo.java
===================================================================
---
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestExecutionInfo.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestExecutionInfo.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,191 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator.xml;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.teiid.language.Select;
-import org.teiid.translator.TranslatorException;
-import org.teiid.translator.xml.ExecutionInfo;
-import org.teiid.translator.xml.QueryAnalyzer;
-
-/**
- *
- */
-public class TestExecutionInfo extends TestCase {
-
- /**
- * Constructor for ExecutionInfoTest.
- * @param arg0
- */
-
- private static final String QUERY = "select Company_id from Company where
Company_id = 'MetaMatrix' order by Company_id";
-
- private ExecutionInfo m_info;
-
- //removing hansel while testing clover
-/*
- public static Test suite() {
- return new CoverageDecorator(ExecutionInfoTest.class, new Class[]
{ExecutionInfo.class});
-
- }
-*/
-
- public TestExecutionInfo(String arg0) {
- super(arg0);
- }
-
- @Override
- public void setUp() throws TranslatorException {
- String vdbPath = ProxyObjectFactory.getStateCollegeVDBLocation();
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, QUERY);
- QueryAnalyzer analyzer = new QueryAnalyzer(query);
- analyzer.analyze();
- m_info = analyzer.getExecutionInfo();
-
- }
-
- @Override
- public void tearDown() {
- m_info = null;
- }
-
- public void testExecutionInfo() {
- ExecutionInfo info = new ExecutionInfo();
- assertNotNull("ExecutionInfo is null", info);
- assertEquals(0, info.getColumnCount());
- assertNotNull(info.getCriteria());
- assertNotNull(info.getOtherProperties());
- assertNotNull(info.getParameters());
- assertNotNull(info.getRequestedColumns());
- assertNotNull(info.getTableXPath());
- }
-
- public void testGetTableXPath() {
- assertEquals("/Mydata/company", m_info.getTableXPath());
- }
-
- public void testGetRequestedColumns() {
- List columns = m_info.getRequestedColumns();
- assertNotNull("requestedColumns list is null", columns);
- assertEquals(1, columns.size());
- }
-
- public void testGetColumnCount() {
- assertEquals(1, m_info.getColumnCount());
- }
-
- public void testGetParameters() {
- List params = m_info.getParameters();
- assertNotNull("Param list is null", params);
- assertEquals(0, params.size());
- }
-
- public void testGetCriteria() {
- String vdbPath = ProxyObjectFactory.getStateCollegeVDBLocation();
- //String query = "Select AttributeColumn from TestTable where AttributeColumn
in ('foo')";
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, QUERY);
- try {
- QueryAnalyzer analyzer = new QueryAnalyzer(iquery);
- analyzer.analyze();
- ExecutionInfo info = analyzer.getExecutionInfo();
- List crits = info.getCriteria();
- assertNotNull("Criteria list is null", crits);
- assertEquals(1, crits.size());
- } catch (TranslatorException ce) {
- ce.printStackTrace();
- fail(ce.getMessage());
- }
- }
-
- public void testGetOtherProperties() throws TranslatorException {
- String vdbPath = ProxyObjectFactory.getDocumentsFolder() +
"/UnitTests.vdb";
- String strQuery = "select * from Response";
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, strQuery);
- QueryAnalyzer analyzer = new QueryAnalyzer(query);
- analyzer.analyze();
- ExecutionInfo info = analyzer.getExecutionInfo();
- Map<String, String> props = info.getOtherProperties();
- assertFalse("properties are empty", props.isEmpty());
- info.setOtherProperties(null);
- assertNotNull(info.getOtherProperties());
- }
-
- public void testSetTableXPath() {
- String xpath = "/new/path";
- m_info.setTableXPath(xpath);
- assertEquals(xpath, m_info.getTableXPath());
- m_info.setTableXPath("");
- assertNull(m_info.getTableXPath());
- }
-
- public void testSetRequestedColumns() {
- String reqCol = "Company_id";
- ArrayList reqCols = new ArrayList();
- reqCols.add(reqCol);
- m_info.setRequestedColumns(reqCols);
- assertEquals(reqCol, m_info.getRequestedColumns().get(0));
- }
-
- public void testSetColumnCount() {
- final int count = 3;
- m_info.setColumnCount(count);
- assertEquals(count, m_info.getColumnCount());
-
- }
-
- public void testSetParameters() {
- String param = "[Company_id]";
- ArrayList params = new ArrayList();
- params.add(param);
- m_info.setParameters(params);
- assertEquals(param, m_info.getParameters().get(0));
- }
-
- public void testSetCriteria() {
- String crit = "Company_id";
- ArrayList crits = new ArrayList();
- crits.add(crit);
- m_info.setParameters(crits);
- assertEquals(crit, m_info.getParameters().get(0));
- }
-
- public void testSetOtherProperties() {
- String prop = "myProp";
- String key = "foo";
- Map<String, String> props = new HashMap<String, String>();
- props.put(key, prop);
- m_info.setOtherProperties(props);
- assertEquals(prop, m_info.getOtherProperties().get(key));
-
- m_info.setOtherProperties(null);
- assertNotNull("OtherProerties was set to null",
m_info.getOtherProperties());
- assertEquals(0, m_info.getOtherProperties().size());
- }
-
-}
Deleted:
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestOutputXPathDesc.java
===================================================================
---
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestOutputXPathDesc.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestOutputXPathDesc.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,172 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator.xml;
-
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.teiid.language.ColumnReference;
-import org.teiid.language.Comparison;
-import org.teiid.language.Condition;
-import org.teiid.language.DerivedColumn;
-import org.teiid.language.Expression;
-import org.teiid.language.LanguageUtil;
-import org.teiid.language.Literal;
-import org.teiid.language.Select;
-import org.teiid.metadata.Column;
-import org.teiid.translator.TranslatorException;
-import org.teiid.translator.xml.OutputXPathDesc;
-
-
-/**
- *
- */
-public class TestOutputXPathDesc extends TestCase {
-
-
- private static String vdbPath;
- private static final String QUERY = "select OutputColumn from CriteriaDescTable
where"
- + " OutputColumn in ('foo') order by OutputColumn";
-
- static {
- vdbPath = ProxyObjectFactory.getStateCollegeVDBLocation();
- }
-
-// removing hansel while testing clover
-
-/*
- public static Test suite() {
- return new CoverageDecorator(OutputXPathDescTest.class, new Class[]
{OutputXPathDesc.class});
- }
-*/
-
- /**
- * Constructor for OutputXPathDescTest.
- * @param arg0
- */
- public TestOutputXPathDesc(String arg0) {
- super(arg0);
- }
-
- /*
- * Class under test for void OutputXPathDesc(Element)
- */
- public void testOutputXPathDescElement() throws Exception {
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, QUERY);
- List symbols = query.getDerivedColumns();
- DerivedColumn selectSymbol = (DerivedColumn) symbols.get(0);
- Expression expr = selectSymbol.getExpression();
- assertTrue(expr instanceof ColumnReference);
- Column element = ((ColumnReference) expr).getMetadataObject();
- OutputXPathDesc desc = new OutputXPathDesc(element);
- assertNull(desc.getCurrentValue());
- assertNotNull(desc.getDataType());;
- }
-
- public void testOutputXPathDescParam() throws Exception {
- String query = "select RequiredDefaultedParam from CriteriaDescTable where
RequiredDefaultedParam in ('foo')";
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- assertTrue(expr instanceof ColumnReference);
- Column element = ((ColumnReference) expr).getMetadataObject();
- OutputXPathDesc desc = new OutputXPathDesc(element);
- assertNotNull("OutputXPathDesc is null", desc);
- }
-
-
- public void testOutputXPathDescNoXPath() throws Exception {
- try {
- String query = "select OutputColumnNoXPath from CriteriaDescTable";
- Select iquery = ProxyObjectFactory.getDefaultIQuery(vdbPath, query);
- final int colLocation = 0;
- DerivedColumn symbol = (DerivedColumn)
iquery.getDerivedColumns().get(colLocation);
- Expression expr = symbol.getExpression();
- assertTrue(expr instanceof ColumnReference);
- Column element = ((ColumnReference) expr).getMetadataObject();
- OutputXPathDesc desc = new OutputXPathDesc(element);
- fail("should not be able to create OuputXPathDesc with no XPath");
- } catch (TranslatorException ce) {
- return;
- }
- }
- /*
- * Class under test for void OutputXPathDesc(ILiteral)
- */
- public void testOutputXPathDescILiteral() throws Exception {
- String strLiteral = "MetaMatrix";
- String strQuery = "Select Company_id from Company where Company_id =
'" + strLiteral + "'";
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, strQuery);
- Condition crits = query.getWhere();
- List criteriaList = LanguageUtil.separateCriteriaByAnd(crits);
- Comparison compCriteria = (Comparison) criteriaList.get(0);
- Literal literal = (Literal) compCriteria.getRightExpression();
- OutputXPathDesc desc = new OutputXPathDesc(literal);
- assertNotNull(desc);
- assertEquals(strLiteral, desc.getCurrentValue().toString());
- assertEquals(strLiteral.getClass(), desc.getDataType());
- }
-
- public void testOutputXPathDescILiteralNullValue() throws Exception {
- String strLiteral = "MetaMatrix";
- String strQuery = "Select Company_id from Company where Company_id =
'" + strLiteral + "'";
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, strQuery);
- Condition crits = query.getWhere();
- List criteriaList = LanguageUtil.separateCriteriaByAnd(crits);
- Comparison compCriteria = (Comparison) criteriaList.get(0);
- Literal literal = (Literal) compCriteria.getRightExpression();
- literal.setValue(null);
- OutputXPathDesc desc = new OutputXPathDesc(literal);
- assertNotNull(desc);
- assertNull(desc.getCurrentValue());
- assertEquals(strLiteral.getClass(), desc.getDataType());
- }
-
- public void testSetAndGetCurrentValue() throws Exception {
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, QUERY);
- List symbols = query.getDerivedColumns();
- DerivedColumn selectSymbol = (DerivedColumn) symbols.get(0);
- Expression expr = selectSymbol.getExpression();
- assertTrue(expr instanceof ColumnReference);
- Column element = ((ColumnReference) expr).getMetadataObject();
- OutputXPathDesc desc = new OutputXPathDesc(element);
- String myVal = "myValue";
- desc.setCurrentValue(myVal);
- assertEquals(myVal, desc.getCurrentValue());
- }
-
- public void testGetDataType() throws Exception {
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, QUERY);
- List symbols = query.getDerivedColumns();
- DerivedColumn selectSymbol = (DerivedColumn) symbols.get(0);
- Expression expr = selectSymbol.getExpression();
- assertTrue(expr instanceof ColumnReference);
- Column element = ((ColumnReference) expr).getMetadataObject();
- OutputXPathDesc desc = new OutputXPathDesc(element);
- assertNotNull(desc.getDataType());
- assertEquals(String.class, desc.getDataType());
- }
-
-}
Deleted:
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestParameterDescriptor.java
===================================================================
---
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestParameterDescriptor.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestParameterDescriptor.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,200 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator.xml;
-
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.teiid.language.ColumnReference;
-import org.teiid.language.DerivedColumn;
-import org.teiid.language.Expression;
-import org.teiid.language.Select;
-import org.teiid.metadata.Column;
-import org.teiid.translator.TranslatorException;
-import org.teiid.translator.xml.ParameterDescriptor;
-
-
-/**
- *
- */
-public class TestParameterDescriptor extends TestCase {
-
- private static String vdbPath;
- private static final String QUERY = "select OutputColumn from CriteriaDescTable
where"
- + " OutputColumn in ('MetaMatrix') order by OutputColumn";
-
-
- static {
- vdbPath = ProxyObjectFactory.getStateCollegeVDBLocation();
- }
-
-
-// removing hansel while testing clover
-/*
- public static Test suite() {
- return new CoverageDecorator(ParameterDescriptorTest.class, new Class[]
{ParameterDescriptor.class});
- }
-
-*/
- /**
- * Constructor for ParameterDescriptorTest.
- * @param arg0
- */
- public TestParameterDescriptor(String arg0) {
- super(arg0);
- }
-
- /*
- * Class under test for void ParameterDescriptor(Element)
- */
- public void testParameterDescriptorElement() throws Exception {
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, QUERY);
- List symbols = query.getDerivedColumns();
- DerivedColumn selectSymbol = (DerivedColumn) symbols.get(0);
- Expression expr = selectSymbol.getExpression();
- assertTrue(expr instanceof ColumnReference);
- Column element = ((ColumnReference) expr).getMetadataObject();
- ParameterDescriptor desc = new ParameterDescriptorImpl(element);
- assertNotNull(desc);
- }
-
-
- public void testParameterDescriptorElementParameter() throws Exception {
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, "select
RequiredDefaultedParam from CriteriaDescTable");
- List symbols = query.getDerivedColumns();
- DerivedColumn selectSymbol = (DerivedColumn) symbols.get(0);
- Expression expr = selectSymbol.getExpression();
- assertTrue(expr instanceof ColumnReference);
- Column element = ((ColumnReference) expr).getMetadataObject();
- ParameterDescriptor desc = new ParameterDescriptorImpl(element);
- assertNotNull(desc);
- }
-
-
-
- public void testParameterDescriptorElementSpaceXPath() throws Exception {
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, "select
OutputColumnSpaceXPath from CriteriaDescTable");
- List symbols = query.getDerivedColumns();
- DerivedColumn selectSymbol = (DerivedColumn) symbols.get(0);
- Expression expr = selectSymbol.getExpression();
- assertTrue(expr instanceof ColumnReference);
- Column element = ((ColumnReference) expr).getMetadataObject();
- ParameterDescriptor desc = new ParameterDescriptorImpl(element);
- assertNotNull(desc);
- }
-
- /*
- * Class under test for void ParameterDescriptor(ILiteral)
- */
- public void testParameterDescriptor() {
- ParameterDescriptor desc = new ParameterDescriptorImpl();
- assertNotNull(desc);
- assertNull(desc.getXPath());
- assertFalse(desc.isParameter());
- assertNull(desc.getColumnName());
- }
-
- public void testSetGetXPath() throws Exception {
- ParameterDescriptor desc = getParameterDescriptor();
- String xpath = "/foo";
- desc.setXPath(xpath);
- assertEquals(xpath, desc.getXPath());
- }
-
- public void testSetIsParameter() throws Exception {
- ParameterDescriptor desc = getParameterDescriptor();
- boolean is = !desc.isParameter();
- desc.setIsParameter(is);
- assertEquals(is, desc.isParameter());
- }
-
- public void testSetGetColumnName() throws Exception {
- ParameterDescriptor desc = getParameterDescriptor();
- String name = "myColumn";
- desc.setColumnName(name);
- assertEquals(name, desc.getColumnName());
- }
-
- public void testSetGetColumnNumber() throws Exception {
- ParameterDescriptor desc = getParameterDescriptor();
- int number = desc.getColumnNumber() + 1;
- desc.setColumnNumber(number);
- assertEquals(number, desc.getColumnNumber());
- }
-
- public void testGetElement() throws Exception {
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, QUERY);
- List symbols = query.getDerivedColumns();
- DerivedColumn selectSymbol = (DerivedColumn) symbols.get(0);
- Expression expr = selectSymbol.getExpression();
- assertTrue(expr instanceof ColumnReference);
- Column element = ((ColumnReference) expr).getMetadataObject();
- ParameterDescriptor desc = new ParameterDescriptorImpl(element);
- assertEquals(element, desc.getElement());
- }
-
- public void testTestForParam() throws Exception {
- String trueQuery = "select EmptyCol from EmptyTable where EmptyCol =
'foo'";
- String falseQuery = "select Company_id from Company";
-
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, trueQuery);
- List symbols = query.getDerivedColumns();
- DerivedColumn selectSymbol = (DerivedColumn) symbols.get(0);
- Expression expr = selectSymbol.getExpression();
- assertTrue(expr instanceof ColumnReference);
- Column element = ((ColumnReference) expr).getMetadataObject();
- assertTrue(ParameterDescriptor.testForParam(element));
-
- query = ProxyObjectFactory.getDefaultIQuery(vdbPath, falseQuery);
- symbols = query.getDerivedColumns();
- selectSymbol = (DerivedColumn) symbols.get(0);
- expr = selectSymbol.getExpression();
- assertTrue(expr instanceof ColumnReference);
- element = ((ColumnReference) expr).getMetadataObject();
- assertFalse(ParameterDescriptor.testForParam(element));
- }
-
- private ParameterDescriptor getParameterDescriptor() throws Exception {
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, QUERY);
- List symbols = query.getDerivedColumns();
- DerivedColumn selectSymbol = (DerivedColumn) symbols.get(0);
- Expression expr = selectSymbol.getExpression();
- assertTrue(expr instanceof ColumnReference);
- Column element = ((ColumnReference) expr).getMetadataObject();
- ParameterDescriptor desc = new ParameterDescriptorImpl(element);
- assertNotNull(desc);
- return desc;
- }
-
- private class ParameterDescriptorImpl extends ParameterDescriptor {
- public ParameterDescriptorImpl() {
- super();
- }
-
- public ParameterDescriptorImpl(Column element) throws TranslatorException {
- super(element);
- }
-
- }
-}
Deleted:
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestQueryAnalyzer.java
===================================================================
---
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestQueryAnalyzer.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestQueryAnalyzer.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,165 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator.xml;
-
-
-
-import junit.framework.TestCase;
-
-import org.teiid.language.Select;
-import org.teiid.translator.TranslatorException;
-import org.teiid.translator.xml.ExecutionInfo;
-import org.teiid.translator.xml.QueryAnalyzer;
-
-/**
- *
- */
-public class TestQueryAnalyzer extends TestCase {
-
- private static String vdbPath;
- private static final String QUERY = "select SimpleOutput from SimpleTable where
SimpleOutput = 'MetaMatrix' order by SimpleOutput";
-
- static {
- vdbPath = ProxyObjectFactory.getStateCollegeVDBLocation();
- }
-
-// removing hansel while testing clover
-/*
- public static Test suite() {
- return new CoverageDecorator(QueryAnalyzerTest.class, new Class[]
{QueryAnalyzer.class});
- }
-
-*/
- /**
- * Constructor for QueryAnalyzerTest.
- * @param arg0
- */
- public TestQueryAnalyzer(String arg0) {
- super(arg0);
- }
-
- public void testQueryAnalyzer() {
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, QUERY);
- try {
- QueryAnalyzer analyzer = new QueryAnalyzer(query);
- assertNotNull("analyzer is null", analyzer);
- } catch (TranslatorException e) {
- fail(e.getMessage());
- }
- }
-
- public void testAnalyze() {
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, QUERY);
- try {
- QueryAnalyzer analyzer = new QueryAnalyzer(query);
- analyzer.analyze();
- } catch (TranslatorException e) {
- fail(e.getMessage());
- }
- }
-
- public void testAnalyzeSimpleSelect() {
- String strQuery = "select SimpleOutput from SimpleTable";
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, strQuery);
- try {
- QueryAnalyzer analyzer = new QueryAnalyzer(query);
- analyzer.analyze();
- } catch (TranslatorException e) {
- fail(e.getMessage());
- }
- }
-
- public void testAnalyzeLiteralSelect() {
- String strQuery = "select SimpleOutput, 'foo' from SimpleTable";
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, strQuery);
- try {
- QueryAnalyzer analyzer = new QueryAnalyzer(query);
- analyzer.analyze();
- } catch (TranslatorException e) {
- fail(e.getMessage());
- }
- }
-
- public void testAnalyzeFunctionSelect() {
- String strQuery = "select concat(SimpleOutput, 'foo') from
SimpleTable";
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, strQuery);
- try {
- QueryAnalyzer analyzer = new QueryAnalyzer(query);
- analyzer.analyze();
- } catch (TranslatorException e) {
- fail(e.getMessage());
- }
- }
-
- public void testAnalyzeParameterSelect() {
- String strQuery = "select SimpleParam from SimpleInput where SimpleParam in
('foo')";
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, strQuery);
- try {
- QueryAnalyzer analyzer = new QueryAnalyzer(query);
- analyzer.analyze();
- } catch (TranslatorException e) {
- fail(e.getMessage());
- }
- }
-
- public void testAnalyzeComplexQuery() {
- String strQuery = "select SimpleOut from SimpleInput where SimpleParam in
('foo')";
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, strQuery);
- try {
- QueryAnalyzer analyzer = new QueryAnalyzer(query);
- analyzer.analyze();
- } catch (TranslatorException e) {
- fail(e.getMessage());
- }
- }
-
- public void testAnalyzeComplexQuery2() {
- String strQuery = "select SimpleOut from SimpleInput where SimpleParam in
('foo') and OtherOut in ('bar')";
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, strQuery);
- try {
- QueryAnalyzer analyzer = new QueryAnalyzer(query);
- analyzer.analyze();
- } catch (TranslatorException e) {
- fail(e.getMessage());
- }
- }
-
- public void testGetExecutionInfo() {
- Select query = ProxyObjectFactory.getDefaultIQuery(vdbPath, QUERY);
- try {
- QueryAnalyzer analyzer = new QueryAnalyzer(query);
- assertNotNull("analyzer is null", analyzer);
- ExecutionInfo base = analyzer.getExecutionInfo();
- assertEquals(1, base.getColumnCount());
- analyzer.analyze();
- ExecutionInfo post = analyzer.getExecutionInfo();
- assertTrue(post.getColumnCount() > 0);
- assertEquals(1, post.getCriteria().size());
- assertEquals(1, post.getRequestedColumns().size());
- assertNotNull(post.getTableXPath());
- } catch (TranslatorException e) {
- fail(e.getMessage());
- }
-
- }
-}
Deleted:
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestXMLCapabilities.java
===================================================================
---
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestXMLCapabilities.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestXMLCapabilities.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,195 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator.xml;
-
-import org.teiid.translator.xml.XMLExecutionFactory;
-
-import junit.framework.TestCase;
-
-
-/**
- *
- */
-public class TestXMLCapabilities extends TestCase {
-
-
- private XMLExecutionFactory m_caps = null;
- /**
- * Constructor for XMLCapabilitiesTest.
- * @param arg0
- */
- public TestXMLCapabilities(String arg0) {
- super(arg0);
- }
-
- @Override
- public void setUp() {
- m_caps = new XMLExecutionFactory();
-
- }
-
- public void testGetMaxInCriteriaSize() {
- assertEquals(Integer.MAX_VALUE, m_caps.getMaxInCriteriaSize());
- }
-
- public void testSupportsCompareCriteriaEquals() {
- assertTrue(m_caps.supportsCompareCriteriaEquals());
- }
-
- public void testSupportsInCriteria() {
- assertTrue(m_caps.supportsInCriteria());
- }
-
- public void testXMLCapabilities() {
- XMLExecutionFactory caps = new XMLExecutionFactory();
- assertNotNull(caps);
- }
-
- /*
- * Class under test for List getSupportedFunctions()
- */
- public void testGetSupportedFunctions() {
- assertNotNull(m_caps.getSupportedFunctions());
- }
-
- public void testSupportsSelectDistinct() {
- assertFalse(m_caps.supportsSelectDistinct());
- }
-
- public void testSupportsAliasedGroup() {
- assertFalse(m_caps.supportsAliasedTable());
- }
-
- public void testSupportsJoins() {
- assertFalse(m_caps.supportsInnerJoins());
- }
-
- public void testSupportsSelfJoins() {
- assertFalse(m_caps.supportsSelfJoins());
- }
-
- public void testSupportsOuterJoins() {
- assertFalse(m_caps.supportsOuterJoins());
- }
-
- public void testSupportsFullOuterJoins() {
- assertFalse(m_caps.supportsFullOuterJoins());
- }
-
- public void testSupportsBetweenCriteria() {
- assertFalse(m_caps.supportsBetweenCriteria());
- }
-
- public void testSupportsLikeCriteria() {
- assertFalse(m_caps.supportsLikeCriteria());
- }
-
- public void testSupportsLikeCriteriaEscapeCharacter() {
- assertFalse(m_caps.supportsLikeCriteriaEscapeCharacter());
- }
-
- public void testSupportsInCriteriaSubquery() {
- assertFalse(m_caps.supportsInCriteriaSubquery());
- }
-
- public void testSupportsIsNullCriteria() {
- assertFalse(m_caps.supportsIsNullCriteria());
- }
-
- public void testSupportsOrCriteria() {
- assertFalse(m_caps.supportsOrCriteria());
- }
-
- public void testSupportsNotCriteria() {
- assertFalse(m_caps.supportsNotCriteria());
- }
-
- public void testSupportsExistsCriteria() {
- assertFalse(m_caps.supportsExistsCriteria());
- }
-
- public void testSupportsQuantifiedCompareCriteriaSome() {
- assertFalse(m_caps.supportsQuantifiedCompareCriteriaSome());
- }
-
- public void testSupportsQuantifiedCompareCriteriaAll() {
- assertFalse(m_caps.supportsQuantifiedCompareCriteriaAll());
- }
-
- public void testSupportsOrderBy() {
- assertFalse(m_caps.supportsOrderBy());
- }
-
- public void testSupportsAggregatesSum() {
- assertFalse(m_caps.supportsAggregatesSum());
- }
-
- public void testSupportsAggregatesAvg() {
- assertFalse(m_caps.supportsAggregatesAvg());
- }
-
- public void testSupportsAggregatesMin() {
- assertFalse(m_caps.supportsAggregatesMin());
- }
-
- public void testSupportsAggregatesMax() {
- assertFalse(m_caps.supportsAggregatesMax());
- }
-
- public void testSupportsAggregatesCount() {
- assertFalse(m_caps.supportsAggregatesCount());
- }
-
- public void testSupportsAggregatesCountStar() {
- assertFalse(m_caps.supportsAggregatesCountStar());
- }
-
- public void testSupportsAggregatesDistinct() {
- assertFalse(m_caps.supportsAggregatesDistinct());
- }
-
- public void testSupportsScalarSubqueries() {
- assertFalse(m_caps.supportsScalarSubqueries());
- }
-
- public void testSupportsCorrelatedSubqueries() {
- assertFalse(m_caps.supportsCorrelatedSubqueries());
- }
-
- public void testSupportsCaseExpressions() {
- assertFalse(m_caps.supportsCaseExpressions());
- }
-
- public void testSupportsSearchedCaseExpressions() {
- assertFalse(m_caps.supportsSearchedCaseExpressions());
- }
-
- public void testSupportsInlineViews() {
- assertFalse(m_caps.supportsInlineViews());
- }
-
- public void testSupportsUnions() {
- assertFalse(m_caps.supportsUnions());
- }
-
-}
Deleted:
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestXMLReaderFactory.java
===================================================================
---
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestXMLReaderFactory.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestXMLReaderFactory.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,19 +0,0 @@
-package org.teiid.translator.xml;
-
-import junit.framework.TestCase;
-
-import org.teiid.translator.xml.streaming.ReaderFactory;
-import org.xml.sax.XMLReader;
-
-
-public class TestXMLReaderFactory extends TestCase {
-
- public void testGetSAXBuilder() {
- try {
- XMLReader reader = ReaderFactory.getXMLReader(null);
- assertNotNull(reader);
- } catch (Exception e) {
- fail(e.getMessage());
- }
- }
-}
Deleted:
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestXPathSplitter.java
===================================================================
---
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestXPathSplitter.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestXPathSplitter.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1,88 +0,0 @@
-package org.teiid.translator.xml;
-
-import java.util.List;
-
-import org.teiid.translator.xml.streaming.InvalidPathException;
-import org.teiid.translator.xml.streaming.XPathSplitter;
-
-import junit.framework.TestCase;
-
-
-public class TestXPathSplitter extends TestCase {
-
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- /**
- * ((((/po:purchaseOrder) | (/po:purchaseOrders/order))/items) |
(/po:purchaseOrder/items3) | (/po:purchaseOrders/order/items4))/item
- *
- * becomes
- * /po:purchaseOrder/items/item
- * /po:purchaseOrders/order/items/item
- * /po:purchaseOrder/items/item
- * /po:purchaseOrders/order/items/item
- * becomes
- *
- * /po:purchaseOrder/items/item
- * /po:purchaseOrders/order/items/item
- */
- public void testSplit() {
- XPathSplitter splitter = new XPathSplitter();
- try {
- List paths = splitter.split("((((/po:purchaseOrder) |
(/po:purchaseOrders/order))/items) | (/po:purchaseOrder/items) |
(/po:purchaseOrders/order/items))/item");
- assertEquals(2, paths.size());
- } catch (InvalidPathException e) {
- fail(e.getMessage());
- }
- }
-
- public void testSplitSimple() {
- XPathSplitter splitter = new XPathSplitter();
- try {
- List paths = splitter.split("/po:purchaseOrders/order/items/item");
- assertEquals(1, paths.size());
- } catch (InvalidPathException e) {
- fail(e.getMessage());
- }
- }
-
- public void testSplitCompund() {
- XPathSplitter splitter = new XPathSplitter();
- try {
- List paths =
splitter.split("(/po:purchaseOrders/order/items/item)|(/po:purchaseOrders/order/items)");
- assertEquals(2, paths.size());
- } catch (InvalidPathException e) {
- fail(e.getMessage());
- }
- }
-
- public void testSplitCompund2() {
- XPathSplitter splitter = new XPathSplitter();
- try {
- List paths =
splitter.split("(/po:purchaseOrders/order/items/item)|((/po:purchaseOrders/order/items)|(/po:purchaseOrders/order/item))");
- assertEquals(3, paths.size());
- } catch (InvalidPathException e) {
- fail(e.getMessage());
- }
- }
-
- /**
- *
((/po:purchaseOrders/order/items)|(/po:purchaseOrders/order/item))|((/po:purchaseOrders/order/items)|(/po:purchaseOrders/order/item))
- *
- * /po:purchaseOrders/order/items
- * /po:purchaseOrders/order/item
- *
- */
- public void testSplitCompund3() {
- XPathSplitter splitter = new XPathSplitter();
- try {
- List paths =
splitter.split("((/po:purchaseOrders/order/items)|(/po:purchaseOrders/order/item))|((/po:purchaseOrders/order/items)|(/po:purchaseOrders/order/item))");
- assertEquals(2, paths.size());
- } catch (InvalidPathException e) {
- fail(e.getMessage());
- }
- }
-}
Modified: trunk/documentation/reference/src/main/docbook/en-US/content/datatypes.xml
===================================================================
--- trunk/documentation/reference/src/main/docbook/en-US/content/datatypes.xml 2010-06-08
18:36:09 UTC (rev 2201)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/datatypes.xml 2010-06-08
19:11:59 UTC (rev 2202)
@@ -471,25 +471,31 @@
<tbody>
<row>
<entry>BOOLEAN</entry>
- <entry>{b'true'} or {b'false'}</entry>
+ <entry>{b 'true'} or {b 'false'}</entry>
</row>
<row>
<entry>DATE</entry>
- <entry>{d'yyyy-mm-dd'}</entry>
+ <entry>{d 'yyyy-mm-dd'}</entry>
</row>
<row>
<entry>TIME</entry>
- <entry>{t'hh-mm-ss'}</entry>
+ <entry>{t 'hh-mm-ss'}</entry>
</row>
<row>
<entry>TIMESTAMP</entry>
<entry>
- {ts'yyyy-mm-dd hh:mm:ss.fffffffff'}
+ {ts 'yyyy-mm-dd hh:mm:ss.fffffffff'}
<footnote>
<para>fractional seconds are optional</para>
</footnote>
</entry>
</row>
+ <row>
+ <entry>XML</entry>
+ <entry>
+ {x 'well-formed doc'}
+ </entry>
+ </row>
</tbody>
</tgroup>
</table>
Modified:
trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml
===================================================================
---
trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1940,7 +1940,7 @@
meaningful result for non-text nodes.</para>
</entry>
<entry>
- <para>Doc in {string, xml} and xpath. Return value is a string.
+ <para>Doc in {string, clob, xml} and xpath. Return value is a
string.
</para>
</entry>
</row>
@@ -1952,20 +1952,42 @@
<para>Applies an xsl stylesheet to the given document. If either
argument is null, the result is null.</para>
</entry>
<entry>
- <para>Doc, xsl in {string, xml}. Return value is a clob.
+ <para>Doc, xsl in {string, clob, xml}. Return value is a clob.
</para>
</entry>
</row>
+ <row id="xmlquery">
+ <entry>
+ <para><code>XMLQUERY([<NSP>] xquery
[<PASSING>] [(NULL|EMPTY) ON EMPTY]]</code></para>
+ <para>PASSING:=<code>PASSING exp [AS name] [, exp [AS
name]]*</code></para>
+ </entry>
+ <entry>
+ <para>Returns the XML result from evaluating the given
xquery.</para>
+ <para>See XMLELEMENT for the definition of NSP - <link
linkend="xmlnamespaces">XMLNAMESPACES</link>.</para><para>Namespaces
may also be directly declared in the xquery prolog.</para>
+ <para id="passing">The optional PASSING clause is used to
provide the context item, which does not have a name, and named global variable values.
+ If the xquery uses a context item and none is provided, then an exception
will be raised.
+ Only one context item may be specified and should be an XML type. All
non-context non-XML passing values will be converted to an appropriate XML
type.</para>
+ <para>The ON EMPTY clause is used to specify the result when the
evaluted sequence is empty.
+ EMPTY ON EMPTY, the default, returns an empty XML result. NULL ON EMPTY
returns a null result.</para>
+ <para>See also <link
linkend="xmltable">XMLTABLE</link></para>
+ </entry>
+ <entry>
+ <para>xquery in string. Return value is xml.
+ </para>
+ </entry>
+ </row>
<row>
<entry>
<para><code>XMLELEMENT([NAME] name [, <NSP>] [,
<ATTR>][, exp]*)</code></para>
<para>ATTR:=<code>XMLATTRIBUTES(exp [AS name] [, exp [AS
name]]*)</code></para>
- <para>NSP:=<code>XMLNAMESPACES((uri AS prefix | DEFAULT uri |
NO DEFAULTS))+</code></para>
+ <para>NSP:=<code>XMLNAMESPACES((uri AS prefix | DEFAULT uri |
NO DEFAULT))+</code></para>
</entry>
<entry>
<para>Returns an XML element with the given name and content. If the
content value is of a type other than xml,
it will be escaped when added to the parent element. Null content values
are ignored.
Whitespace in XML or the string values of the content is preserved, but no
whitespace is added between content values.</para>
+ <para id="xmlnamespaces">XMLNAMESPACES is used provide
namespace information. NO DEFAULT is equivalent to defining the default namespace to the
null uri - xmlns="".
+ Only one DEFAULT or NO DEFAULT namespace item may be specified. The
namespace prefixes xmlns and xml are reserved.</para>
<para>If a attribute name is not supplied, the expression must be a
column reference, in which case the attribute name will be the column name. Null attribute
values are ignored.</para>
<para>Example: with an xml_value of <doc/>,
<code>xmlelement('elem', 1, '<2/>',
xml_value)</code>
Returns:
<code><elem>1&lt;2/&gt;<doc/><elem/></code>
@@ -1996,7 +2018,7 @@
<entry>
<para>Returns an concatination of an XML element for each non-null
expression exp. If a name is not supplied, the expression must be a column reference, in
which case the element name will be the column name.
</para>
- <para>See XMLELEMENT for the definition of NSP -
XMLNAMESPACES.</para>
+ <para>See XMLELEMENT for the definition of NSP - <link
linkend="xmlnamespaces">XMLNAMESPACES</link>.</para>
</entry>
<entry>
<para>Name is an identifier. Exp can be any type. Return value is
xml.
Modified: trunk/documentation/reference/src/main/docbook/en-US/content/sql_support.xml
===================================================================
---
trunk/documentation/reference/src/main/docbook/en-US/content/sql_support.xml 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/documentation/reference/src/main/docbook/en-US/content/sql_support.xml 2010-06-08
19:11:59 UTC (rev 2202)
@@ -710,6 +710,7 @@
<listitem><para>FROM table1 JOIN table2 MAKENOTDEP ON
join-criteria</para></listitem>
<listitem><para>FROM table1 left outer join <link
linkend="optional_join">/* optional */</link> table2 ON
join-criteria</para></listitem>
<listitem><para>FROM <link
linkend="texttable">TEXTTABLE...</link></para></listitem>
+ <listitem><para>FROM <link
linkend="xmltable">XMLTABLE...</link></para></listitem>
</itemizedlist>
<note>
<title>DEP Hints</title>
@@ -753,22 +754,10 @@
</para>
<para>
Usage:
- <synopsis label="Usage">TEXTTABLE(expression COLUMNS column, ...
[DELIMITER char] [(QUOTE|ESCAPE) char] [HEADER [integer]] [SKIP integer]) AS
identifier</synopsis>
- <synopsis label="Usage">column := identifier datatype [WIDTH
integer]</synopsis>
+ <synopsis label="Usage">TEXTTABLE(expression COLUMNS
<COLUMN>, ... [DELIMITER char] [(QUOTE|ESCAPE) char] [HEADER [integer]]
[SKIP integer]) AS name</synopsis>
+ <synopsis label="Usage">COLUMN := name datatype [WIDTH
integer]</synopsis>
</para>
<itemizedlist>
- <para>Syntax Rules:
- </para>
- <listitem>
- <para>If width is specified for one column it must be specified for all
columns.
- </para>
- </listitem>
- <listitem>
- <para>If width is specified, then fixed width parsing is used and ESCAPE,
QUOTE, and HEADER should not be specified.
- </para>
- </listitem>
- </itemizedlist>
- <itemizedlist>
<para>Parameters</para>
<listitem>
<para>expression - the text content to process, which should be
convertable to CLOB.
@@ -800,6 +789,22 @@
</listitem>
</itemizedlist>
<itemizedlist>
+ <para>Syntax Rules:
+ </para>
+ <listitem>
+ <para>If width is specified for one column it must be specified for all
columns.
+ </para>
+ </listitem>
+ <listitem>
+ <para>If width is specified, then fixed width parsing is used and ESCAPE,
QUOTE, and HEADER should not be specified.
+ </para>
+ </listitem>
+ <listitem>
+ <para>The columns names must be not contain duplicates.
+ </para>
+ </listitem>
+ </itemizedlist>
+ <itemizedlist>
<para>Examples</para>
<listitem>
<para>Use of the HEADER parameter, returns 1 row ['b']:
<programlisting>select * from texttable('col1,col2,col3\na,b,c' COLUMNS col2
string HEADER) x</programlisting>
@@ -817,9 +822,61 @@
<para>As a nested table: <programlisting>select x.* from t,
texttable(t.clobcolumn COLUMNS first string, second date SKIP 1) x</programlisting>
</para>
</listitem>
-
</itemizedlist>
</sect3>
+ <sect3 id="xmltable">
+ <title>XMLTABLE</title>
+ <para>The XMLTABLE funciton uses XQuery to produce tabular ouptut.
+ The XMLTABLE function is implicitly a nested table and may be correlated to
preceeding FROM clause entries.
+ </para>
+ <para>
+ Usage:
+ <synopsis label="Usage">XMLTABLE([<NSP>,]
xquery-expression [<PASSING>] [COLUMNS <COLUMN>, ... )] AS
name</synopsis>
+ <synopsis label="Usage">COLUMN := name (FOR ORDINALITY |
(datatype [PATH string] [DEFAULT expression]))</synopsis>
+ </para>
+ <para>See XMLELEMENT for the definition of NSP - <link
linkend="xmlnamespaces">XMLNAMESPACES</link>.</para>
+ <para>See XMLQUERY for the definition of <link
linkend="passing">PASSING</link>.</para>
+ <para>See also <link
linkend="xmlquery">XMLQUERY</link></para>
+ <itemizedlist>
+ <para>Parameters</para>
+ <listitem>
+ <para>The optional XMLNAMESPACES clause specifies the namepaces for use in
the XQuery and COLUMN path expressions.
+ </para>
+ </listitem>
+ <listitem>
+ <para>The xquery-expression should be a valid XQuery. Each sequence item
returned by the xquery will be used to create a row of values as defined by the COLUMNS
clause.
+ </para>
+ </listitem>
+ <listitem>
+ <para>If COLUMNS is not specified, then that is the same as having the
COLUMNS clause: "COLUMNS OBJECT_VALUE XML PATH '.'", which returns the
entire item as an XML value. Each non-ordinality column specifies a type and optionally a
PATH and a DEFAULT expression.
+ If PATH is not specified, then the path will be the same as the column name. A
FOR ORDINALITY column is typed as integer and will return the 1-based item number as its
value.
+ </para>
+ </listitem>
+ </itemizedlist>
+ <itemizedlist>
+ <para>Syntax Rules:
+ </para>
+ <listitem>
+ <para>Only 1 FOR ORDINALITY column may be specified.
+ </para>
+ </listitem>
+ <listitem>
+ <para>The columns names must be not contain duplicates.
+ </para>
+ </listitem>
+ </itemizedlist>
+ <itemizedlist>
+ <para>Examples</para>
+ <listitem>
+ <para>Use of passing, returns 1 row [1]: <programlisting>select *
from xmltable('/a' PASSING {x '<a id="1"/>'}
COLUMNS id integer PATH '@id') x</programlisting>
+ </para>
+ </listitem>
+ <listitem>
+ <para>As a nested table: <programlisting>select x.* from t,
xmltable('/x/y' PASSING t.doc COLUMNS first string, second FOR ORDINALITY)
x</programlisting>
+ </para>
+ </listitem>
+ </itemizedlist>
+ </sect3>
</sect2>
<sect2 id="where_clause">
<title>WHERE Clause</title>
Modified: trunk/engine/pom.xml
===================================================================
--- trunk/engine/pom.xml 2010-06-08 18:36:09 UTC (rev 2201)
+++ trunk/engine/pom.xml 2010-06-08 19:11:59 UTC (rev 2202)
@@ -93,15 +93,6 @@
<artifactId>saxon</artifactId>
</dependency>
- <dependency>
- <groupId>xom</groupId>
- <artifactId>xom</artifactId>
- </dependency>
- <dependency>
- <groupId>nux</groupId>
- <artifactId>nux</artifactId>
- </dependency>
-
</dependencies>
</project>
\ No newline at end of file
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorManager.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorManager.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorManager.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -58,7 +58,6 @@
import org.teiid.query.sql.lang.Command;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.ExecutionFactory;
-import org.teiid.translator.MetadataProvider;
import org.teiid.translator.TranslatorException;
@@ -133,8 +132,12 @@
public MetadataStore getMetadata(String modelName, Map<String, Datatype>
datatypes, Properties importProperties) throws TranslatorException {
MetadataFactory factory = new MetadataFactory(modelName, datatypes, importProperties);
ExecutionFactory executionFactory = getExecutionFactory();
- if (executionFactory instanceof MetadataProvider) {
- ((MetadataProvider)executionFactory).getConnectorMetadata(factory,
getConnectionFactory());
+ Object connectionFactory = getConnectionFactory();
+ Object connection = executionFactory.getConnection(executionFactory);
+ try {
+ executionFactory.getMetadata(factory, connection);
+ } finally {
+ executionFactory.closeConnection(connection, connectionFactory);
}
return factory.getMetadataStore();
}
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItem.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItem.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItem.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -79,6 +79,7 @@
/* Created on new request */
private Object connection;
+ private Object connectionFactory;
private ExecutionContextImpl securityContext;
private volatile ResultSetExecution execution;
private ProcedureBatchHandler procedureBatchHandler;
@@ -181,6 +182,7 @@
} catch (Throwable e) {
LogManager.logError(LogConstants.CTX_CONNECTOR, e, e.getMessage());
} finally {
+ this.connector.closeConnection(connection, connectionFactory);
manager.removeState(this.id);
LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] {this.id,
"Closed connection"}); //$NON-NLS-1$
}
@@ -226,8 +228,8 @@
LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[]
{this.requestMsg.getAtomicRequestID(), "Processing NEW request:",
this.requestMsg.getCommand()}); //$NON-NLS-1$
try {
- this.connection = this.manager.getConnectionFactory();
-
+ this.connectionFactory = this.manager.getConnectionFactory();
+ this.connection = this.connector.getConnection(this.connectionFactory);
// Translate the command
Command command = this.requestMsg.getCommand();
List<SingleElementSymbol> symbols =
this.requestMsg.getCommand().getProjectedSymbols();
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -29,8 +29,6 @@
import java.util.Map;
import java.util.Set;
-import nux.xom.xquery.XQuery;
-
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryParserException;
import org.teiid.api.exception.query.QueryResolverException;
@@ -230,15 +228,6 @@
return xmlMetadata;
}
- private Map createXQueryColumnMetadata(XQuery xqueryCommand) {
- Map xqueryMetadata = getDefaultColumn(null,
ResultsMetadataDefaults.XML_COLUMN_NAME, XMLType.class);
-
- // Override size as XML may be big
- xqueryMetadata.put(ResultsMetadataConstants.DISPLAY_SIZE,
ResultsMetadataDefaults.XML_COLUMN_LENGTH);
-
- return xqueryMetadata;
- }
-
private Map createColumnMetadata(String shortColumnName, SingleElementSymbol symbol)
throws QueryMetadataException, TeiidComponentException {
if(symbol instanceof ElementSymbol) {
return createElementMetadata(shortColumnName, (ElementSymbol) symbol);
Modified: trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java 2010-06-08 18:36:09 UTC
(rev 2201)
+++ trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java 2010-06-08 19:11:59 UTC
(rev 2202)
@@ -22,8 +22,6 @@
package org.teiid.query.eval;
-import java.io.IOException;
-import java.io.Writer;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
@@ -31,20 +29,12 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.TransformerException;
-
-import net.sf.saxon.expr.PathMap.PathMapRoot;
-import net.sf.saxon.om.Item;
-import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.om.SequenceIterator;
-import net.sf.saxon.query.QueryResult;
import net.sf.saxon.trans.XPathException;
import org.teiid.api.exception.query.CriteriaEvaluationException;
@@ -55,10 +45,8 @@
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.core.types.SQLXMLImpl;
import org.teiid.core.types.Sequencable;
import org.teiid.core.types.TransformationException;
-import org.teiid.core.types.XMLTranslator;
import org.teiid.core.types.XMLType;
import org.teiid.core.types.XMLType.Type;
import org.teiid.core.types.basic.StringToSQLXMLTransform;
@@ -71,7 +59,6 @@
import org.teiid.query.function.source.XMLSystemFunctions;
import org.teiid.query.function.source.XMLSystemFunctions.NameValuePair;
import org.teiid.query.processor.ProcessorDataManager;
-import org.teiid.query.processor.xml.XMLUtil;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.lang.AbstractSetCriteria;
import org.teiid.query.sql.lang.CollectionValueIterator;
@@ -632,7 +619,7 @@
Type type = StringToSQLXMLTransform.isXml(value.getCharacterStream());
value.setType(type);
}
- if (value.getType() == Type.DOCUMENT || value.getType() == Type.FRAGMENT) {
+ if (value.getType() == Type.DOCUMENT || value.getType() == Type.ELEMENT) {
return DataTypeManager.transformValue(value, xs.getType());
}
} catch (SQLException e) {
@@ -643,17 +630,13 @@
throw new
FunctionExecutionException(QueryPlugin.Util.getString("Evaluator.xmlserialize"));
//$NON-NLS-1$
} else if (expression instanceof XMLQuery) {
XMLQuery xmlQuery = (XMLQuery)expression;
- boolean contentOnly = true;
boolean emptyOnEmpty = true;
- if (xmlQuery.getReturningContent() != null) {
- contentOnly = xmlQuery.getReturningContent();
- }
if (xmlQuery.getEmptyOnEmpty() != null) {
emptyOnEmpty = xmlQuery.getEmptyOnEmpty();
}
try {
- SequenceIterator iter = evaluateXQuery(xmlQuery.getXQueryExpression(),
xmlQuery.getContextRoot(), xmlQuery.getPassing(), tuple);
- return createXMLType(iter, xmlQuery.getXQueryExpression(), contentOnly,
emptyOnEmpty);
+ SequenceIterator iter = evaluateXQuery(xmlQuery.getXQueryExpression(),
xmlQuery.getPassing(), tuple);
+ return xmlQuery.getXQueryExpression().createXMLType(iter, emptyOnEmpty);
} catch (TeiidProcessingException e) {
throw new FunctionExecutionException(e,
QueryPlugin.Util.getString("Evaluator.xmlquery", e.getMessage()));
//$NON-NLS-1$
} catch (XPathException e) {
@@ -664,56 +647,7 @@
}
}
- public XMLType createXMLType(final SequenceIterator iter, final SaxonXQueryExpression
expr, boolean contentOnly, boolean emptyOnEmpty) throws XPathException,
TeiidComponentException, TeiidProcessingException {
- Item item = iter.next();
- if (item == null) {
- if (contentOnly) {
- throw new
FunctionExecutionException(QueryPlugin.Util.getString("Evaluator.xmlquery_content_empty"));
//$NON-NLS-1$
- }
- if (!emptyOnEmpty) {
- return null;
- }
- }
- XMLType.Type type = Type.SEQUENCE;
- if (item instanceof NodeInfo) {
- NodeInfo info = (NodeInfo)item;
- switch (info.getNodeKind()) {
- case net.sf.saxon.type.Type.DOCUMENT:
- type = Type.DOCUMENT;
- break;
- case net.sf.saxon.type.Type.ELEMENT:
- type = Type.FRAGMENT;
- break;
- case net.sf.saxon.type.Type.TEXT:
- type = Type.TEXT;
- break;
- }
- }
- Item next = iter.next();
- if (next != null) {
- type = Type.SEQUENCE;
- }
- if (contentOnly && type != Type.DOCUMENT && type != Type.FRAGMENT) {
- throw new
FunctionExecutionException(QueryPlugin.Util.getString("Evaluator.xmlquery_content"));
//$NON-NLS-1$
- }
- SQLXMLImpl xml = XMLUtil.saveToBufferManager(new XMLTranslator() {
-
- @Override
- public void translate(Writer writer) throws TransformerException,
- IOException {
- Properties props = new Properties();
- props.setProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
- //props.setProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
- props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
//$NON-NLS-1$
- QueryResult.serializeSequence(iter.getAnother(), expr.getConfig(), writer,
props);
- }
- });
- XMLType value = new XMLType(xml);
- value.setType(type);
- return value;
- }
-
- public SequenceIterator evaluateXQuery(SaxonXQueryExpression xquery, PathMapRoot
contextRoot, List<DerivedColumn> cols, List<?> tuple)
+ public SequenceIterator evaluateXQuery(SaxonXQueryExpression xquery,
List<DerivedColumn> cols, List<?> tuple)
throws BlockedException, TeiidComponentException, TeiidProcessingException {
HashMap<String, Object> parameters = new HashMap<String, Object>();
Object contextItem = null;
@@ -725,7 +659,7 @@
parameters.put(passing.getAlias(), value);
}
}
- return xquery.evaluateXQuery(contextItem, contextRoot, parameters);
+ return xquery.evaluateXQuery(contextItem, parameters);
}
private NameValuePair<Object>[] getNameValuePairs(List tuple,
List<DerivedColumn> args)
Modified: trunk/engine/src/main/java/org/teiid/query/function/source/SystemSource.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/function/source/SystemSource.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/engine/src/main/java/org/teiid/query/function/source/SystemSource.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -23,6 +23,7 @@
package org.teiid.query.function.source;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -888,6 +889,12 @@
new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.xpathvalue_result")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
functions.add(new FunctionMethod(SourceSystemFunctions.XPATHVALUE,
QueryPlugin.Util.getString("SystemSource.xpathvalue_description"), XML,
XML_FUNCTION_CLASS, "xpathValue", //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionParameter[] {
+ new FunctionParameter("document",
DataTypeManager.DefaultDataTypes.CLOB,
QueryPlugin.Util.getString("SystemSource.xpath_param1")), //$NON-NLS-1$
//$NON-NLS-2$
+ new FunctionParameter("xpath",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.xpath_param2"))}, //$NON-NLS-1$
//$NON-NLS-2$
+ new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.xpathvalue_result")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
+
+ functions.add(new FunctionMethod(SourceSystemFunctions.XPATHVALUE,
QueryPlugin.Util.getString("SystemSource.xpathvalue_description"), XML,
XML_FUNCTION_CLASS, "xpathValue", //$NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter[] {
new FunctionParameter("document",
DataTypeManager.DefaultDataTypes.XML,
QueryPlugin.Util.getString("SystemSource.xpath_param1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("xpath",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.xpath_param2"))}, //$NON-NLS-1$
//$NON-NLS-2$
@@ -895,28 +902,15 @@
}
private void addXslTransformFunction() {
- functions.add(new FunctionMethod(SourceSystemFunctions.XSLTRANSFORM,
QueryPlugin.Util.getString("SystemSource.xsltransform_description"), XML,
XML_FUNCTION_CLASS, "xslTransform", //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter[] {
- new FunctionParameter("document",
DataTypeManager.DefaultDataTypes.XML,
QueryPlugin.Util.getString("SystemSource.xsltransform_param1")), //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("xsl",
DataTypeManager.DefaultDataTypes.XML,
QueryPlugin.Util.getString("SystemSource.xsltransform_param2"))}, //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.CLOB,
QueryPlugin.Util.getString("SystemSource.xsltransform_result")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
- functions.add(new FunctionMethod(SourceSystemFunctions.XSLTRANSFORM,
QueryPlugin.Util.getString("SystemSource.xsltransform_description"), XML,
XML_FUNCTION_CLASS, "xslTransform", //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter[] {
- new FunctionParameter("document",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.xsltransform_param1")), //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("xsl",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.xsltransform_param2"))}, //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.CLOB,
QueryPlugin.Util.getString("SystemSource.xsltransform_result")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
-
- functions.add(new FunctionMethod(SourceSystemFunctions.XSLTRANSFORM,
QueryPlugin.Util.getString("SystemSource.xsltransform_description"), XML,
XML_FUNCTION_CLASS, "xslTransform", //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter[] {
- new FunctionParameter("document",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.xsltransform_param1")), //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("xsl",
DataTypeManager.DefaultDataTypes.XML,
QueryPlugin.Util.getString("SystemSource.xsltransform_param2"))}, //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.CLOB,
QueryPlugin.Util.getString("SystemSource.xsltransform_result")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
-
- functions.add(new FunctionMethod(SourceSystemFunctions.XSLTRANSFORM,
QueryPlugin.Util.getString("SystemSource.xsltransform_description"), XML,
XML_FUNCTION_CLASS, "xslTransform", //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter[] {
- new FunctionParameter("document",
DataTypeManager.DefaultDataTypes.XML,
QueryPlugin.Util.getString("SystemSource.xsltransform_param1")), //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("xsl",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.xsltransform_param2"))}, //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.CLOB,
QueryPlugin.Util.getString("SystemSource.xsltransform_result")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
+ for (String type1 : Arrays.asList(DataTypeManager.DefaultDataTypes.STRING,
DataTypeManager.DefaultDataTypes.XML, DataTypeManager.DefaultDataTypes.CLOB)) {
+ for (String type2 : Arrays.asList(DataTypeManager.DefaultDataTypes.STRING,
DataTypeManager.DefaultDataTypes.XML, DataTypeManager.DefaultDataTypes.CLOB)) {
+ functions.add(new FunctionMethod(SourceSystemFunctions.XSLTRANSFORM,
QueryPlugin.Util.getString("SystemSource.xsltransform_description"), XML,
XML_FUNCTION_CLASS, "xslTransform", //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionParameter[] {
+ new FunctionParameter("document", type1,
QueryPlugin.Util.getString("SystemSource.xsltransform_param1")), //$NON-NLS-1$
//$NON-NLS-2$
+ new FunctionParameter("xsl", type2,
QueryPlugin.Util.getString("SystemSource.xsltransform_param2"))}, //$NON-NLS-1$
//$NON-NLS-2$
+ new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.CLOB,
QueryPlugin.Util.getString("SystemSource.xsltransform_result")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
}
private void addXmlComment() {
Modified:
trunk/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -28,6 +28,7 @@
import java.io.StringReader;
import java.io.Writer;
import java.nio.CharBuffer;
+import java.sql.Blob;
import java.sql.Clob;
import java.sql.SQLException;
import java.sql.SQLXML;
@@ -108,48 +109,52 @@
YEAR_ZERO = cal.getTimeInMillis();
}
- public static ClobType xslTransform(CommandContext context, String xmlResults, String
styleSheet) throws Exception {
- return xslTransform(context, DataTypeManager.transformValue(xmlResults,
DataTypeManager.DefaultDataClasses.XML), DataTypeManager.transformValue(styleSheet,
DataTypeManager.DefaultDataClasses.XML));
- }
-
- public static ClobType xslTransform(CommandContext context, String xmlResults, XMLType
styleSheet) throws Exception {
- return xslTransform(context, DataTypeManager.transformValue(xmlResults,
DataTypeManager.DefaultDataClasses.XML), styleSheet);
- }
-
- public static ClobType xslTransform(CommandContext context, XMLType xmlResults, String
styleSheet) throws Exception {
- return xslTransform(context, xmlResults, DataTypeManager.transformValue(styleSheet,
DataTypeManager.DefaultDataClasses.XML));
- }
-
- public static ClobType xslTransform(CommandContext context, XMLType xmlResults, XMLType
styleSheet) throws Exception {
- Reader styleSheetReader = styleSheet.getCharacterStream();
- final Source styleSource = new StreamSource(styleSheetReader);
- Reader reader = xmlResults.getCharacterStream();
- final Source xmlSource = new StreamSource(reader);
+ public static ClobType xslTransform(CommandContext context, Object xml, Object
styleSheet) throws Exception {
+ Source styleSource = null;
+ Source xmlSource = null;
try {
+ styleSource = convertToSource(styleSheet);
+ xmlSource = convertToSource(xml);
+ final Source xmlParam = xmlSource;
+ TransformerFactory factory = TransformerFactory.newInstance();
+ final Transformer transformer = factory.newTransformer(styleSource);
+
//this creates a non-validated sqlxml - it may not be valid xml/root-less xml
SQLXML result = XMLUtil.saveToBufferManager(context.getBufferManager(), new
XMLTranslator() {
@Override
public void translate(Writer writer) throws TransformerException {
- TransformerFactory factory = TransformerFactory.newInstance();
- Transformer transformer = factory.newTransformer(styleSource);
//transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
"yes"); //$NON-NLS-1$
// Feed the resultant I/O stream into the XSLT processor
- transformer.transform(xmlSource, new StreamResult(writer));
+ transformer.transform(xmlParam, new StreamResult(writer));
}
}, Streamable.STREAMING_BATCH_SIZE_IN_BYTES);
return DataTypeManager.transformValue(new XMLType(result),
DataTypeManager.DefaultDataClasses.CLOB);
} finally {
- try {
- reader.close();
- } catch (IOException e) {
+ closeSource(styleSource);
+ closeSource(xmlSource);
+ }
+ }
+
+ private static void closeSource(final Source source) {
+ if (!(source instanceof StreamSource)) {
+ return;
+ }
+
+ StreamSource stream = (StreamSource)source;
+ try {
+ if (stream.getInputStream() != null) {
+ stream.getInputStream().close();
}
- try {
- styleSheetReader.close();
- } catch (IOException e) {
+ } catch (IOException e) {
+ }
+ try {
+ if (stream.getReader() != null) {
+ stream.getReader().close();
}
+ } catch (IOException e) {
}
- }
+ }
public static XMLType xmlForest(final CommandContext context, final NameValuePair[]
namespaces, final NameValuePair[] values) throws TeiidComponentException,
TeiidProcessingException {
boolean valueExists = false;
@@ -183,7 +188,7 @@
}
}
}, context.getStreamingBatchSize()));
- result.setType(Type.SEQUENCE);
+ result.setType(Type.CONTENT);
return result;
}
@@ -214,7 +219,7 @@
}
}, context.getStreamingBatchSize()));
- result.setType(Type.FRAGMENT);
+ result.setType(Type.ELEMENT);
return result;
}
@@ -268,7 +273,7 @@
}
}
}, context.getStreamingBatchSize()));
- result.setType(Type.SEQUENCE);
+ result.setType(Type.CONTENT);
return result;
}
@@ -340,8 +345,8 @@
r = new BufferedReader(r);
}
switch(type) {
- case FRAGMENT:
- case SEQUENCE:
+ case CONTENT:
+ case ELEMENT:
case PI:
case COMMENT: //write the value directly to the writer
eventWriter.flush();
@@ -414,18 +419,34 @@
return resultBuffer.toString();
}
-
- public static String xpathValue(String document, String xpathStr) throws IOException,
XPathException {
- return xpathValue(new StringReader(document), xpathStr);
+
+ public static Source convertToSource(Object value) throws TeiidProcessingException {
+ if (value == null) {
+ return null;
+ }
+ try {
+ if (value instanceof SQLXML) {
+ return ((SQLXML)value).getSource(null);
+ }
+ if (value instanceof Clob) {
+ return new StreamSource(((Clob)value).getCharacterStream());
+ }
+ if (value instanceof Blob) {
+ return new StreamSource(((Blob)value).getBinaryStream());
+ }
+ if (value instanceof String) {
+ return new StreamSource(new StringReader((String)value));
+ }
+ } catch (SQLException e) {
+ throw new TeiidProcessingException(e);
+ }
+ throw new AssertionError("Unknown type"); //$NON-NLS-1$
}
-
- public static String xpathValue(XMLType document, String xpathStr) throws
IOException, SQLException, XPathException {
- return xpathValue(document.getCharacterStream(), xpathStr);
- }
- public static String xpathValue(Reader documentReader, String xpath) throws
IOException, XPathException {
+ public static String xpathValue(Object doc, String xpath) throws XPathException,
TeiidProcessingException {
+ Source s = null;
try {
- Source s = new StreamSource(documentReader);
+ s = convertToSource(doc);
XPathEvaluator eval = new XPathEvaluator();
// Wrap the string() function to force a string return
XPathExpression expr = eval.createExpression(xpath);
@@ -443,8 +464,7 @@
// Return string representation of non-node value
return o.toString();
} finally {
- // Always close the reader
- documentReader.close();
+ closeSource(s);
}
}
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -386,7 +386,7 @@
for (int col : projectionIndexes) {
filteredColumns.add(xt.getColumns().get(col));
}
- PathMapRoot root = xt.getXQueryExpression().useDocumentProjection(filteredColumns,
analysisRecord);
+ xt.getXQueryExpression().useDocumentProjection(filteredColumns, analysisRecord);
xtn.setProjectedColumns(filteredColumns);
xtn.setTable(xt);
processNode = xtn;
Modified:
trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -26,7 +26,6 @@
import java.util.Collections;
import java.util.List;
-import net.sf.saxon.expr.PathMap.PathMapRoot;
import net.sf.saxon.om.Item;
import net.sf.saxon.om.SequenceIterator;
import net.sf.saxon.sxpath.XPathDynamicContext;
@@ -52,10 +51,10 @@
private XMLTable table;
private List<XMLColumn> projectedColumns;
- private PathMapRoot contextRoot;
private SequenceIterator result;
private int rowCount = 0;
+ private Item item;
public XMLTableNode(int nodeID) {
super(nodeID);
@@ -74,6 +73,7 @@
result.close();
result = null;
}
+ item = null;
rowCount = 0;
}
@@ -85,10 +85,6 @@
this.projectedColumns = projectedColumns;
}
- public void setContextRoot(PathMapRoot contextRoot) {
- this.contextRoot = contextRoot;
- }
-
@Override
public XMLTableNode clone() {
XMLTableNode clone = new XMLTableNode(getID());
@@ -104,7 +100,7 @@
if (result == null) {
setReferenceValues(this.table);
- result =
getEvaluator(Collections.emptyMap()).evaluateXQuery(this.table.getXQueryExpression(),
this.contextRoot, this.table.getPassing(), null);
+ result =
getEvaluator(Collections.emptyMap()).evaluateXQuery(this.table.getXQueryExpression(),
this.table.getPassing(), null);
}
while (!isBatchFull() && !isLastBatch()) {
@@ -115,16 +111,17 @@
private void processRow() throws ExpressionEvaluationException, BlockedException,
TeiidComponentException, TeiidProcessingException {
- Item item;
- try {
- item = result.next();
- } catch (XPathException e) {
- throw new TeiidProcessingException(e,
QueryExecPlugin.Util.getString("XMLTableNode.error", e.getMessage()));
//$NON-NLS-1$
- }
- rowCount++;
if (item == null) {
- terminateBatches();
- return;
+ try {
+ item = result.next();
+ } catch (XPathException e) {
+ throw new TeiidProcessingException(e,
QueryExecPlugin.Util.getString("XMLTableNode.error", e.getMessage()));
//$NON-NLS-1$
+ }
+ rowCount++;
+ if (item == null) {
+ terminateBatches();
+ return;
+ }
}
List<Object> tuple = new ArrayList<Object>(projectedColumns.size());
for (XMLColumn proColumn : projectedColumns) {
@@ -145,7 +142,7 @@
continue;
}
if (proColumn.getSymbol().getType() == DataTypeManager.DefaultDataClasses.XML) {
- XMLType value =
getEvaluator(Collections.emptyMap()).createXMLType(pathIter.getAnother(),
table.getXQueryExpression(), false, false);
+ XMLType value = table.getXQueryExpression().createXMLType(pathIter.getAnother(),
false);
tuple.add(value);
continue;
}
@@ -164,6 +161,7 @@
}
}
}
+ item = null;
addBatchRow(tuple);
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/XMLTable.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/XMLTable.java 2010-06-08 18:36:09
UTC (rev 2201)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/XMLTable.java 2010-06-08 19:11:59
UTC (rev 2202)
@@ -187,7 +187,9 @@
}
}
clone.xquery = this.xquery;
- clone.xqueryExpression = this.xqueryExpression;
+ if (this.xqueryExpression != null) {
+ clone.xqueryExpression = this.xqueryExpression.clone();
+ }
return clone;
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLQuery.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLQuery.java 2010-06-08
18:36:09 UTC (rev 2201)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLQuery.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -3,8 +3,6 @@
import java.util.ArrayList;
import java.util.List;
-import net.sf.saxon.expr.PathMap.PathMapRoot;
-
import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.EquivalenceUtil;
@@ -19,10 +17,8 @@
private String xquery;
private List<DerivedColumn> passing = new ArrayList<DerivedColumn>();
private Boolean emptyOnEmpty;
- private Boolean returningContent;
private SaxonXQueryExpression xqueryExpression;
- private PathMapRoot contextRoot;
@Override
public Class<?> getType() {
@@ -37,14 +33,6 @@
this.emptyOnEmpty = emptyOnEmpty;
}
- public Boolean getReturningContent() {
- return returningContent;
- }
-
- public void setReturningContent(Boolean returningContent) {
- this.returningContent = returningContent;
- }
-
@Override
public boolean isResolved() {
return xqueryExpression != null;
@@ -57,17 +45,13 @@
//TODO: display the analysis record info
public void compileXqueryExpression() throws QueryResolverException {
this.xqueryExpression = new SaxonXQueryExpression(xquery, namespaces, passing,
null);
- this.contextRoot = this.xqueryExpression.useDocumentProjection(null, new
AnalysisRecord(false, false));
+ this.xqueryExpression.useDocumentProjection(null, new AnalysisRecord(false,
false));
}
public SaxonXQueryExpression getXQueryExpression() {
return xqueryExpression;
}
- public PathMapRoot getContextRoot() {
- return contextRoot;
- }
-
public void setPassing(List<DerivedColumn> passing) {
this.passing = passing;
}
@@ -105,9 +89,10 @@
}
}
clone.xquery = this.xquery;
- clone.xqueryExpression = this.xqueryExpression;
+ if (this.xqueryExpression != null) {
+ clone.xqueryExpression = this.xqueryExpression.clone();
+ }
clone.emptyOnEmpty = this.emptyOnEmpty;
- clone.returningContent = this.returningContent;
return clone;
}
@@ -123,8 +108,7 @@
return EquivalenceUtil.areEqual(this.namespaces, other.namespaces)
&& this.passing.equals(other.passing)
&& this.xquery.equals(other.xquery)
- && EquivalenceUtil.areEqual(this.emptyOnEmpty, other.emptyOnEmpty)
- && EquivalenceUtil.areEqual(this.returningContent, other.returningContent);
+ && EquivalenceUtil.areEqual(this.emptyOnEmpty, other.emptyOnEmpty);
}
@Override
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1762,27 +1762,17 @@
parts.add(SPACE);
registerNodes(obj.getPassing(), 0);
}
- if (obj.getReturningContent() != null) {
+ if (obj.getEmptyOnEmpty() != null) {
parts.add(SPACE);
- parts.add(NonReserved.RETURNING);
- parts.add(SPACE);
- if (obj.getReturningContent()) {
- parts.add(NonReserved.CONTENT);
+ if (obj.getEmptyOnEmpty()) {
+ parts.add(NonReserved.EMPTY);
} else {
- parts.add(NonReserved.SEQUENCE);
- if (obj.getEmptyOnEmpty() != null) {
- parts.add(SPACE);
- if (obj.getEmptyOnEmpty()) {
- parts.add(NonReserved.EMPTY);
- } else {
- parts.add(NULL);
- }
- parts.add(SPACE);
- parts.add(ON);
- parts.add(SPACE);
- parts.add(NonReserved.EMPTY);
- }
+ parts.add(NULL);
}
+ parts.add(SPACE);
+ parts.add(ON);
+ parts.add(SPACE);
+ parts.add(NonReserved.EMPTY);
}
parts.add(")");//$NON-NLS-1$
}
Modified: trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2010-06-08
18:36:09 UTC (rev 2201)
+++ trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -1188,8 +1188,7 @@
for (DerivedColumn dc : passing) {
if (dc.getAlias() == null) {
Class<?> type = dc.getExpression().getType();
- if (type != DataTypeManager.DefaultDataClasses.XML &&
- type != DataTypeManager.DefaultDataClasses.CLOB) {
+ if (type != DataTypeManager.DefaultDataClasses.XML) {
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.context_item_type"),
obj); //$NON-NLS-1$
}
if (context && !hadError) {
Modified:
trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -22,19 +22,20 @@
package org.teiid.query.xquery.saxon;
-import java.sql.Clob;
-import java.sql.SQLException;
+import java.io.IOException;
+import java.io.Writer;
import java.sql.SQLXML;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import javax.xml.transform.ErrorListener;
+import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
-import javax.xml.transform.stream.StreamSource;
import net.sf.saxon.AugmentedSource;
import net.sf.saxon.Configuration;
@@ -50,11 +51,14 @@
import net.sf.saxon.expr.PathMap.PathMapRoot;
import net.sf.saxon.om.Axis;
import net.sf.saxon.om.DocumentInfo;
+import net.sf.saxon.om.Item;
+import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.om.SequenceIterator;
import net.sf.saxon.om.StructuredQName;
import net.sf.saxon.pattern.AnyNodeTest;
import net.sf.saxon.pattern.NodeKindTest;
import net.sf.saxon.query.DynamicQueryContext;
+import net.sf.saxon.query.QueryResult;
import net.sf.saxon.query.StaticQueryContext;
import net.sf.saxon.sxpath.IndependentContext;
import net.sf.saxon.sxpath.XPathEvaluator;
@@ -66,13 +70,18 @@
import net.sf.saxon.value.SequenceType;
import org.teiid.api.exception.query.QueryResolverException;
+import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.TeiidRuntimeException;
-import org.teiid.core.types.ClobType;
import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.SQLXMLImpl;
+import org.teiid.core.types.XMLTranslator;
import org.teiid.core.types.XMLType;
+import org.teiid.core.types.XMLType.Type;
import org.teiid.query.QueryPlugin;
import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.function.source.XMLSystemFunctions;
+import org.teiid.query.processor.xml.XMLUtil;
import org.teiid.query.sql.lang.XMLTable;
import org.teiid.query.sql.lang.XMLTable.XMLColumn;
import org.teiid.query.sql.symbol.DerivedColumn;
@@ -122,6 +131,7 @@
private net.sf.saxon.query.XQueryExpression xQuery;
private Configuration config = new Configuration();
+ private PathMapRoot contextRoot;
public SaxonXQueryExpression(String xQueryString, XMLNamespaces namespaces,
List<DerivedColumn> passing, List<XMLTable.XMLColumn> columns)
throws QueryResolverException {
@@ -166,11 +176,24 @@
}
}
+ private SaxonXQueryExpression() {
+
+ }
+
+ public SaxonXQueryExpression clone() {
+ SaxonXQueryExpression clone = new SaxonXQueryExpression();
+ clone.xQuery = xQuery;
+ clone.config = config;
+ clone.contextRoot = contextRoot;
+ return clone;
+ }
+
public boolean usesContextItem() {
return this.xQuery.usesContextItem();
}
- public PathMapRoot useDocumentProjection(List<XMLTable.XMLColumn> columns,
AnalysisRecord record) {
+ public void useDocumentProjection(List<XMLTable.XMLColumn> columns, AnalysisRecord
record) {
+ this.contextRoot = null;
PathMap map = this.xQuery.getPathMap();
PathMapRoot parentRoot;
try {
@@ -179,7 +202,7 @@
if (record.recordDebug()) {
record.println("Document projection will not be used, since multiple context
item exist."); //$NON-NLS-1$
}
- return null;
+ return;
}
if (parentRoot == null) {
//TODO: this seems like we could omit the context item altogether
@@ -187,7 +210,7 @@
if (record.recordDebug()) {
record.println("Document projection will not be used, since no context item
reference was found in the XQuery"); //$NON-NLS-1$
}
- return null;
+ return;
}
HashSet<PathMapNode> finalNodes = new HashSet<PathMapNode>();
getReturnableNodes(parentRoot, finalNodes);
@@ -198,11 +221,11 @@
if (record.recordDebug()) {
record.println("Document projection will not be used, since multiple return
items exist"); //$NON-NLS-1$
}
- return null;
+ return;
}
parentRoot = projectColumns(parentRoot, columns, finalNodes.iterator().next(),
record);
if (parentRoot == null) {
- return null;
+ return;
}
} else {
for (Iterator iter = finalNodes.iterator(); iter.hasNext(); ) {
@@ -215,14 +238,14 @@
if (record.recordDebug()) {
record.println("Document projection will not be used since there are unknown
dependencies (most likely a user defined function)."); //$NON-NLS-1$
}
- return null;
+ return;
}
if (record.recordDebug()) {
StringBuilder sb = new StringBuilder();
showArcs(sb, parentRoot, 0);
record.println("Using path filtering for XQuery context item: \n" +
sb.toString()); //$NON-NLS-1$
}
- return parentRoot;
+ this.contextRoot = parentRoot;
}
private PathMapRoot projectColumns(PathMapRoot parentRoot,
List<XMLTable.XMLColumn> columns, PathMapNode finalNode, AnalysisRecord record) {
@@ -331,36 +354,19 @@
}
}
- public static Source convertToSource(Object value) throws TeiidProcessingException {
- if (value == null) {
- return null;
- }
- try {
- if (value instanceof XMLType) {
- return ((SQLXML)value).getSource(null);
- }
- if (value instanceof ClobType) {
- return new StreamSource(((Clob)value).getCharacterStream());
- }
- } catch (SQLException e) {
- throw new TeiidProcessingException(e);
- }
- throw new AssertionError("Unknown type"); //$NON-NLS-1$
- }
-
- public SequenceIterator evaluateXQuery(Object context, PathMapRoot contextRoot,
Map<String, Object> parameterValues) throws TeiidProcessingException {
+ public SequenceIterator evaluateXQuery(Object context, Map<String, Object>
parameterValues) throws TeiidProcessingException {
DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
for (Map.Entry<String, Object> entry : parameterValues.entrySet()) {
Object value = entry.getValue();
- if(value instanceof SQLXML || value instanceof Clob) {
- value = convertToSource(value);
+ if(value instanceof SQLXML) {
+ value = XMLSystemFunctions.convertToSource(value);
}
dynamicContext.setParameter(entry.getKey(), value);
}
if (context != null) {
- Source source = convertToSource(context);
+ Source source = XMLSystemFunctions.convertToSource(context);
if (contextRoot != null) {
//create our own filter as this logic is not provided in the free saxon
ProxyReceiver filter = new PathMapFilter(contextRoot);
@@ -383,6 +389,47 @@
}
}
+ public XMLType createXMLType(final SequenceIterator iter, boolean emptyOnEmpty) throws
XPathException, TeiidComponentException, TeiidProcessingException {
+ Item item = iter.next();
+ if (item == null && !emptyOnEmpty) {
+ return null;
+ }
+ XMLType.Type type = Type.CONTENT;
+ if (item instanceof NodeInfo) {
+ NodeInfo info = (NodeInfo)item;
+ switch (info.getNodeKind()) {
+ case net.sf.saxon.type.Type.DOCUMENT:
+ type = Type.DOCUMENT;
+ break;
+ case net.sf.saxon.type.Type.ELEMENT:
+ type = Type.ELEMENT;
+ break;
+ case net.sf.saxon.type.Type.TEXT:
+ type = Type.TEXT;
+ break;
+ }
+ }
+ Item next = iter.next();
+ if (next != null) {
+ type = Type.CONTENT;
+ }
+ SQLXMLImpl xml = XMLUtil.saveToBufferManager(new XMLTranslator() {
+
+ @Override
+ public void translate(Writer writer) throws TransformerException,
+ IOException {
+ Properties props = new Properties();
+ props.setProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
+ //props.setProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
+ props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
//$NON-NLS-1$
+ QueryResult.serializeSequence(iter.getAnother(), config, writer, props);
+ }
+ });
+ XMLType value = new XMLType(xml);
+ value.setType(type);
+ return value;
+ }
+
public Configuration getConfig() {
return config;
}
Modified: trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2010-06-08 18:36:09
UTC (rev 2201)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2010-06-08 19:11:59
UTC (rev 2202)
@@ -321,15 +321,22 @@
<XMLAGG: "xmlagg">
| <XMLATTRIBUTES: "xmlattributes">
| <XMLBINARY: "xmlbinary">
+| <XMLCAST: "xmlcast">
| <XMLCONCAT: "xmlconcat">
| <XMLCOMMENT: "xmlcomment">
+| <XMLDOCUMENT: "xmldocument">
| <XMLELEMENT: "xmlelement">
+| <XMLEXISTS: "xmlexists">
| <XMLFOREST: "xmlforest">
+| <XMLITERATE: "xmliterate">
| <XMLNAMESPACES: "xmlnamespaces">
| <XMLPARSE: "xmlparse">
| <XMLPI: "xmlpi">
-| <XMLROOT: "xmlroot">
+| <XMLQUERY: "xmlquery">
| <XMLSERIALIZE: "xmlserialize">
+| <XMLTABLE: "xmltable">
+| <XMLTEXT: "xmltext">
+| <XMLVALIDATE: "xmlvalidate">
}
TOKEN : /* SQL/MED Reserved words */
@@ -1883,7 +1890,7 @@
{
( LOOKAHEAD(<ID> <LPAREN>, {
"texttable".equalsIgnoreCase(getToken(1).image) }) clause = textTable(info)
|
- LOOKAHEAD(<ID> <LPAREN>, {
"xmltable".equalsIgnoreCase(getToken(1).image) }) clause = xmlTable(info)
+ clause = xmlTable(info)
|
clause = unaryFromClause(info)
|
@@ -2038,7 +2045,7 @@
Boolean empty = null;
}
{
- <ID> <LPAREN>
+ <XMLQUERY> <LPAREN>
[ xmlNamespaces = xmlNamespaces(info) <COMMA> ]
xquery = stringVal()
[
@@ -2056,20 +2063,20 @@
}
)*
]
- [
+/* [
LOOKAHEAD(<ID>, { "returning".equalsIgnoreCase(getToken(1).image) })
<ID>
(
LOOKAHEAD(<ID>, { "content".equalsIgnoreCase(getToken(1).image) })
<ID> { content = true; }
|
LOOKAHEAD(<ID>, { "sequence".equalsIgnoreCase(getToken(1).image) })
(<ID> { content = false; }
- [
- (<NULL> { empty = false; }
- |
- nonReserved("EMPTY") { empty = true; }
- )
- <ON> nonReserved("EMPTY")
- ])
)
+ ]*/
+ [
+ (<NULL> { empty = false; }
+ |
+ nonReserved("EMPTY") { empty = true; }
+ )
+ <ON> nonReserved("EMPTY")
]
<RPAREN>
{
@@ -2078,7 +2085,6 @@
result.setNamespaces(xmlNamespaces);
result.setPassing(passingValues);
result.setEmptyOnEmpty(empty);
- result.setReturningContent(content);
return result;
}
}
@@ -2094,7 +2100,7 @@
String aliasID = null;
}
{
- <ID> <LPAREN>
+ <XMLTABLE> <LPAREN>
[ xmlNamespaces = xmlNamespaces(info) <COMMA> ]
xquery = stringVal()
[
@@ -3339,7 +3345,7 @@
{
return expression;
}
- | LOOKAHEAD(<ID>, { "xmlQuery".equalsIgnoreCase(getToken(1).image) })
expression = xmlQuery(info)
+ | expression = xmlQuery(info)
{
return expression;
}
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2010-06-08 18:36:09
UTC (rev 2201)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2010-06-08 19:11:59
UTC (rev 2202)
@@ -819,7 +819,6 @@
Evaluator.xmlserialize=XMLSerialize: data exception - not an xml document
Evaluator.xmlquery=Error evaluating XMLQuery: {0}
Evaluator.xmlquery_content=XQuery evaluation was expected to return content, but it
returned a sequence.
-Evaluator.xmlquery_content_empty=XQuery evaluation was expected to return content, but
was empty.
FunctionDefinitionsReader.Read_error=Error reading FunctionDefinitions.xmi: {0}
FunctionDefinitionsSource.Read_error=Error reading {0}
ExecResolver.Param_convert_fail=Unable to convert procedural parameter of type {0} to
expected type {1}
@@ -895,7 +894,7 @@
ValidationVisitor.text_table_newline=Text table DELIMITER, QUOTE, and ESCAPE characters
cannot be the new line character.
ValidationVisitor.xml_namespaces=At most only one NO DEFAULT or DEFAULT namespace may be
specified.
ValidationVisitor.xml_namespaces_reserved=At most only one NO DEFAULT or DEFAULT
namespace may be specified.
-ValidationVisitor.context_item_type=XMLTABLE or XMLQUERY PASSING context item must be an
XML or CLOB value.
+ValidationVisitor.context_item_type=XMLTABLE or XMLQUERY PASSING context item must be an
XML value.
ValidationVisitor.passing_requires_name=XMLTABLE or XMLQUERY PASSING clause can only
contain at most 1 unnamed item.
ValidationVisitor.duplicate_passing=XMLTABLE or XMLQUERY PASSING clause duplicate item
name "{0}".
ValidationVisitor.one_ordinal=Only one FOR ORDINALITY column is allowed for an XMLTABLE.
Modified:
trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/FakeConnector.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/FakeConnector.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/FakeConnector.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -68,6 +68,15 @@
public Object getConnection() {
return new FakeConnection();
}
+
+ @Override
+ public Object getConnection(Object factory) throws TranslatorException {
+ return factory;
+ }
+
+ @Override
+ public void closeConnection(Object connection, Object factory) {
+ }
private class FakeConnection {
public FakeConnection() {
Modified:
trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -25,7 +25,6 @@
import static org.junit.Assert.*;
import java.io.File;
-import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.sql.Timestamp;
@@ -38,12 +37,12 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.teiid.core.TeiidProcessingException;
import org.teiid.core.types.SQLXMLImpl;
import org.teiid.core.types.XMLType;
import org.teiid.core.util.FileUtil;
import org.teiid.core.util.UnitTestUtil;
-
@SuppressWarnings("nls")
public class TestXMLSystemFunctions {
@@ -53,16 +52,15 @@
return util.read();
}
- public String helpTestXpathValue(final String xmlFilePath, final String xpath, final
String expected) throws IOException, XPathException {
+ public String helpTestXpathValue(final String xmlFilePath, final String xpath, final
String expected) throws XPathException, TeiidProcessingException {
final String actual = helpGetNode(xmlFilePath,xpath);
assertEquals(expected,actual);
return actual;
}
- public String helpGetNode(final String xmlFilePath, final String xpath ) throws
IOException, XPathException {
+ public String helpGetNode(final String xmlFilePath, final String xpath ) throws
XPathException, TeiidProcessingException {
final String xmlContent = getContentOfTestFile(xmlFilePath);
- final Reader docReader = new StringReader(xmlContent);
- return XMLSystemFunctions.xpathValue(docReader,xpath);
+ return XMLSystemFunctions.xpathValue(xmlContent,xpath);
}
public void helpCheckElement(final Object jdomNode, final String name, final String
prefix, final String namespaceUri,
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2010-06-08 18:36:09
UTC (rev 2201)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2010-06-08 19:11:59
UTC (rev 2202)
@@ -6819,9 +6819,8 @@
XMLQuery f = new XMLQuery();
f.setXquery("/x");
f.setEmptyOnEmpty(false);
- f.setReturningContent(false);
f.setPassing(Arrays.asList(new DerivedColumn(null, new
ElementSymbol("foo"))));
- helpTestExpression("xmlquery('/x' passing foo returning sequence null
on empty)", "XMLQUERY('/x' PASSING foo RETURNING SEQUENCE NULL ON
EMPTY)", f);
+ helpTestExpression("xmlquery('/x' passing foo null on empty)",
"XMLQUERY('/x' PASSING foo NULL ON EMPTY)", f);
}
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -328,7 +328,7 @@
}
@Test public void testXmlQuery() {
- String sql = "select xmlquery('for $i in (1 to 5) return $i'
returning sequence)"; //$NON-NLS-1$
+ String sql = "select xmlquery('for $i in (1 to 5) return $i')";
//$NON-NLS-1$
List<?>[] expected = new List<?>[] {
Arrays.asList("1 2 3 4 5"),
@@ -342,36 +342,8 @@
helpProcess(plan, dataManager, expected);
}
- @Test(expected=TeiidProcessingException.class) public void testXmlQueryContentError()
throws Exception {
- String sql = "select xmlquery('for $i in $e1 return $i' passing e1
as e1) from pm1.g1 order by e1 limit 1"; //$NON-NLS-1$
-
- List<?>[] expected = new List<?>[] {
- };
-
- FakeDataManager dataManager = new FakeDataManager();
- sampleData1(dataManager);
-
- ProcessorPlan plan = helpGetPlan(helpParse(sql),
FakeMetadataFactory.example1Cached());
-
- helpProcess(plan, createCommandContext(), dataManager, expected);
- }
-
- @Test(expected=TeiidProcessingException.class) public void testXmlQueryEmpty() throws
Exception {
- String sql = "select xmlquery('/a' passing xmlelement(x, e1)) from
pm1.g1 order by e1 limit 1"; //$NON-NLS-1$
-
- List<?>[] expected = new List<?>[] {
- };
-
- FakeDataManager dataManager = new FakeDataManager();
- sampleData1(dataManager);
-
- ProcessorPlan plan = helpGetPlan(helpParse(sql),
FakeMetadataFactory.example1Cached());
-
- helpProcess(plan, createCommandContext(), dataManager, expected);
- }
-
@Test public void testXmlQueryEmptyNull() throws Exception {
- String sql = "select xmlquery('/a' passing {x '<x/>'}
returning sequence null on empty)"; //$NON-NLS-1$
+ String sql = "select xmlquery('/a' passing {x '<x/>'}
null on empty)"; //$NON-NLS-1$
List<?>[] expected = new List<?>[] {
Arrays.asList((String)null)
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-06-08 18:36:09 UTC (rev 2201)
+++ trunk/pom.xml 2010-06-08 19:11:59 UTC (rev 2202)
@@ -473,17 +473,6 @@
<artifactId>ant</artifactId>
<version>${ant.version}</version>
</dependency>
- <dependency>
- <groupId>xom</groupId>
- <artifactId>xom</artifactId>
- <version>1.2</version>
- </dependency>
- <dependency>
- <groupId>nux</groupId>
- <artifactId>nux</artifactId>
- <version>1.6</version>
- </dependency>
-
</dependencies>
</dependencyManagement>
<modules>
Modified: trunk/runtime/src/test/java/org/teiid/deployers/TestTranslatorUtil.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/deployers/TestTranslatorUtil.java 2010-06-08
18:36:09 UTC (rev 2201)
+++ trunk/runtime/src/test/java/org/teiid/deployers/TestTranslatorUtil.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -43,7 +43,7 @@
assertEquals("correctly-assigned", my.getMyProperty());
}
- public static class MyTranslator extends ExecutionFactory {
+ public static class MyTranslator extends ExecutionFactory<Object, Object> {
String mine;
@TranslatorProperty(display="my-property")
Modified:
trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/MockConnector.java
===================================================================
---
trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/MockConnector.java 2010-06-08
18:36:09 UTC (rev 2201)
+++
trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/MockConnector.java 2010-06-08
19:11:59 UTC (rev 2202)
@@ -22,7 +22,7 @@
import org.teiid.translator.ResultSetExecution;
-public class MockConnector extends ExecutionFactory {
+public class MockConnector extends ExecutionFactory<Object, Object> {
@Override