teiid SVN: r499 - in trunk: connector-api/src/main/java/com/metamatrix/connector/visitor/util and 14 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-02-25 13:27:23 -0500 (Wed, 25 Feb 2009)
New Revision: 499
Added:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCExecutionException.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ReplacementVisitor.java
trunk/test-integration/teiid/
Removed:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/FunctionReplacementVisitor.java
Modified:
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/framework/HierarchyVisitor.java
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/util/SQLStringVisitor.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCBaseExecution.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCQueryExecution.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCUpdateExecution.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/access/AccessSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/TranslatedCommand.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/access/TestAccessSQLTranslator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/util/TestFunctionReplacementVisitor.java
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialSQLTranslator.java
trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java
Log:
TEIID-164 fixes from rewiring integration tests
Modified: trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/framework/HierarchyVisitor.java
===================================================================
--- trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/framework/HierarchyVisitor.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/framework/HierarchyVisitor.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -27,11 +27,9 @@
import com.metamatrix.connector.language.ICompareCriteria;
import com.metamatrix.connector.language.ICompoundCriteria;
import com.metamatrix.connector.language.IDelete;
-import com.metamatrix.connector.language.IElement;
import com.metamatrix.connector.language.IExistsCriteria;
import com.metamatrix.connector.language.IFrom;
import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.IGroup;
import com.metamatrix.connector.language.IGroupBy;
import com.metamatrix.connector.language.IInCriteria;
import com.metamatrix.connector.language.IInlineView;
@@ -39,11 +37,8 @@
import com.metamatrix.connector.language.IIsNullCriteria;
import com.metamatrix.connector.language.IJoin;
import com.metamatrix.connector.language.ILikeCriteria;
-import com.metamatrix.connector.language.ILiteral;
import com.metamatrix.connector.language.INotCriteria;
import com.metamatrix.connector.language.IOrderBy;
-import com.metamatrix.connector.language.IOrderByItem;
-import com.metamatrix.connector.language.IParameter;
import com.metamatrix.connector.language.IProcedure;
import com.metamatrix.connector.language.IQuery;
import com.metamatrix.connector.language.IScalarSubquery;
@@ -70,7 +65,14 @@
*/
public abstract class HierarchyVisitor extends AbstractLanguageVisitor {
- public HierarchyVisitor() {
+ private boolean visitSubcommands;
+
+ public HierarchyVisitor() {
+ this(true);
+ }
+
+ public HierarchyVisitor(boolean visitSubcommands) {
+ this.visitSubcommands = visitSubcommands;
}
public void visit(IAggregate obj) {
@@ -95,15 +97,14 @@
visitNode(obj.getCriteria());
}
- public void visit(IElement obj) {
- }
-
public void visit(IProcedure obj) {
visitNodes(obj.getParameters());
}
public void visit(IExistsCriteria obj) {
- visitNode(obj.getQuery());
+ if (visitSubcommands) {
+ visitNode(obj.getQuery());
+ }
}
public void visit(IFrom obj) {
@@ -114,12 +115,6 @@
visitNodes(obj.getParameters());
}
- public void visit(IGroup obj) {
- }
-
-// public void visit(IGroup obj) {
-// }
-
public void visit(IGroupBy obj) {
visitNodes(obj.getElements());
}
@@ -152,9 +147,6 @@
visitNode(obj.getRightExpression());
}
- public void visit(ILiteral obj) {
- }
-
public void visit(INotCriteria obj) {
visitNode(obj.getCriteria());
}
@@ -163,12 +155,6 @@
visitNodes(obj.getItems());
}
- public void visit(IOrderByItem obj) {
- }
-
- public void visit(IParameter obj) {
- }
-
public void visit(IQuery obj) {
visitNode(obj.getSelect());
visitNode(obj.getFrom());
@@ -180,7 +166,9 @@
}
public void visit(IScalarSubquery obj) {
- visitNode(obj.getQuery());
+ if (visitSubcommands) {
+ visitNode(obj.getQuery());
+ }
}
public void visit(ISearchedCaseExpression obj) {
@@ -202,17 +190,23 @@
public void visit(ISubqueryCompareCriteria obj) {
visitNode(obj.getLeftExpression());
- visitNode(obj.getQuery());
+ if (visitSubcommands) {
+ visitNode(obj.getQuery());
+ }
}
public void visit(ISubqueryInCriteria obj) {
visitNode(obj.getLeftExpression());
- visitNode(obj.getQuery());
+ if (visitSubcommands) {
+ visitNode(obj.getQuery());
+ }
}
public void visit(ISetQuery obj) {
- visitNode(obj.getLeftQuery());
- visitNode(obj.getRightQuery());
+ if (visitSubcommands) {
+ visitNode(obj.getLeftQuery());
+ visitNode(obj.getRightQuery());
+ }
visitNode(obj.getOrderBy());
visitNode(obj.getLimit());
}
@@ -225,7 +219,9 @@
@Override
public void visit(IInlineView obj) {
- visitNode(obj.getQuery());
+ if (visitSubcommands) {
+ visitNode(obj.getQuery());
+ }
}
@Override
Modified: trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/util/SQLStringVisitor.java
===================================================================
--- trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/util/SQLStringVisitor.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/util/SQLStringVisitor.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -780,7 +780,7 @@
String name = getShortName(obj.getName());
buffer.append(name);
} else if (obj.getElement() != null) {
- visit(obj.getElement());
+ append(obj.getElement());
} else {
buffer.append(UNDEFINED);
}
@@ -879,7 +879,6 @@
}
append(obj.getSelectSymbols());
}
-
protected String getSourceComment(ICommand command) {
return ""; //$NON-NLS-1$
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCBaseExecution.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCBaseExecution.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCBaseExecution.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -28,8 +28,7 @@
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
-import java.util.Iterator;
-import java.util.List;
+import java.util.Arrays;
import java.util.Properties;
import org.teiid.connector.jdbc.translator.TranslatedCommand;
@@ -95,91 +94,6 @@
// Methods
// ===========================================================================================================================
- private void addSql(TranslatedCommand command,
- StringBuffer message) {
- String sql = command.getSql();
- int ndx = sql.indexOf('?');
- if (ndx >= 0) {
- message.append(sql.substring(0, ndx));
- int len = sql.length();
- for (Iterator itr = command.getPreparedValues().iterator(); itr.hasNext() && ndx < len;) {
- message.append(itr.next());
- int nextNdx = sql.indexOf('?', ++ndx);
- if (nextNdx >= 0) {
- message.append(sql.substring(ndx, nextNdx));
- } else {
- message.append(sql.substring(ndx));
- }
- ndx = nextNdx;
- }
- } else {
- message.append(sql);
- }
- }
-
- /**
- * @param error
- * @param command
- * @return
- * @since 5.5
- */
- protected ConnectorException createAndLogError(SQLException error,
- TranslatedCommand command) {
- ConnectorException connectorErr = createError(error, command);
- this.logger.logError(connectorErr.getMessage());
- return connectorErr;
- }
-
- /**
- * @param error
- * @param messageKey
- * @param commands
- * @return
- * @throws ConnectorException
- * @since 5.5
- */
- protected ConnectorException createAndLogError(Throwable error,
- String messageKey,
- List commands) throws ConnectorException {
- String msg;
- if (commands.isEmpty()) {
- msg = error.getMessage();
- } else {
- msg = JDBCPlugin.Util.getString(messageKey, error.getMessage());
- StringBuffer buf = new StringBuffer(msg);
- for (Iterator itr = commands.iterator(); itr.hasNext();) {
- buf.append("\n "); //$NON-NLS-1$
- addSql((TranslatedCommand)itr.next(), buf);
- }
- msg = buf.toString();
- }
- this.logger.logError(msg);
- if (error instanceof ConnectorException) {
- error = ((ConnectorException)error).getCause();
- }
- throw new ConnectorException(error, msg);
- }
-
- /**
- * @param error
- * @param command
- * @return
- * @since 5.5
- */
- protected ConnectorException createError(SQLException error,
- TranslatedCommand command) {
- String msg = (command == null ? error.getMessage()
- : JDBCPlugin.Util.getString("JDBCQueryExecution.Error_executing_query__1", //$NON-NLS-1$
- error.getMessage(), createSql(command)));
- return new ConnectorException(error, msg);
- }
-
- private String createSql(TranslatedCommand command) {
- StringBuffer msg = new StringBuffer();
- addSql(command, msg);
- return msg.toString();
- }
-
protected TranslatedCommand translateCommand(ICommand command) throws ConnectorException {
TranslatedCommand translatedCommand = new TranslatedCommand(context, sqlTranslator);
translatedCommand.translateCommand(command);
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -20,8 +20,6 @@
* 02110-1301 USA.
*/
-/*
- */
package org.teiid.connector.jdbc;
import java.lang.reflect.InvocationHandler;
Added: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCExecutionException.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCExecutionException.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCExecutionException.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc;
+
+import java.sql.SQLException;
+import java.util.Arrays;
+
+import org.teiid.connector.jdbc.translator.TranslatedCommand;
+
+import com.metamatrix.connector.api.ConnectorException;
+
+public class JDBCExecutionException extends ConnectorException {
+
+ public JDBCExecutionException(SQLException error,
+ TranslatedCommand... commands) {
+ super(commands == null ? error.getMessage() : JDBCPlugin.Util
+ .getString("JDBCQueryExecution.Error_executing_query__1", //$NON-NLS-1$
+ error.getMessage(), Arrays.toString(commands)));
+ }
+
+}
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCExecutionException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCQueryExecution.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCQueryExecution.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCQueryExecution.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -105,7 +105,7 @@
initResultSetInfo();
} catch (SQLException e) {
- throw createAndLogError(e, translatedComm);
+ throw new JDBCExecutionException(e, translatedComm);
}
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCUpdateExecution.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCUpdateExecution.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCUpdateExecution.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -94,6 +94,8 @@
ICommand[] commands = (ICommand[])batchedCommand.getUpdateCommands().toArray(new ICommand[batchedCommand.getUpdateCommands().size()]);
int[] results = new int[commands.length];
+ TranslatedCommand command = null;
+
try {
// temporarily turn the auto commit off, and set it back to what it was
// before at the end of the command execution.
@@ -101,12 +103,12 @@
connection.setAutoCommit(false);
}
- List executedCmds = new ArrayList();
-
+ List<TranslatedCommand> executedCmds = new ArrayList<TranslatedCommand>();
+
TranslatedCommand previousCommand = null;
for (int i = 0; i < commands.length; i++) {
- TranslatedCommand command = translateCommand(commands[i]);
+ command = translateCommand(commands[i]);
if (command.isPrepared()) {
PreparedStatement pstmt = null;
if (previousCommand != null && previousCommand.isPrepared() && previousCommand.getSql().equals(command.getSql())) {
@@ -137,7 +139,7 @@
}
succeeded = true;
} catch (SQLException e) {
- throw createAndLogError(e, null);
+ throw new JDBCExecutionException(e, command);
} finally {
if (commitType) {
restoreAutoCommit(!succeeded, null);
@@ -176,7 +178,7 @@
addStatementWarnings();
succeeded = true;
} catch (SQLException e) {
- throw createAndLogError(e, translatedComm);
+ throw new JDBCExecutionException(e, translatedComm);
} finally {
if (commitType) {
restoreAutoCommit(!succeeded, translatedComm);
@@ -187,7 +189,7 @@
private void executeBatch(int commandCount,
int[] results,
- List commands) throws ConnectorException {
+ List<TranslatedCommand> commands) throws ConnectorException {
try {
int[] batchResults = statement.executeBatch();
addStatementWarnings();
@@ -196,7 +198,7 @@
}
commands.clear();
} catch (SQLException err) {
- throw createAndLogError(err, "JDBCQueryExecution.Error_executing_query__3", commands); //$NON-NLS-1$
+ throw new JDBCExecutionException(err, commands.toArray(new TranslatedCommand[commands.size()])); //$NON-NLS-1$
}
}
@@ -221,7 +223,7 @@
addStatementWarnings();
return updateCount;
} catch (SQLException err) {
- throw createError(err, translatedComm);
+ throw new JDBCExecutionException(err, translatedComm);
}
}
@@ -234,7 +236,7 @@
try {
return connection.getAutoCommit();
} catch (SQLException err) {
- throw createAndLogError(err, command);
+ throw new JDBCExecutionException(err, command);
}
}
@@ -253,7 +255,7 @@
}
connection.setAutoCommit(true);
} catch (SQLException err) {
- throw createAndLogError(err, command);
+ throw new JDBCExecutionException(err, command);
}
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/access/AccessSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/access/AccessSQLTranslator.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/access/AccessSQLTranslator.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -24,9 +24,16 @@
*/
package org.teiid.connector.jdbc.access;
+import java.util.ArrayList;
+import java.util.List;
+
import org.teiid.connector.jdbc.translator.Translator;
+import com.metamatrix.connector.api.ExecutionContext;
+import com.metamatrix.connector.language.ICommand;
import com.metamatrix.connector.language.ILimit;
+import com.metamatrix.connector.language.IOrderBy;
+import com.metamatrix.connector.language.IQueryCommand;
public class AccessSQLTranslator extends Translator {
@@ -44,12 +51,30 @@
}
@Override
- public String addLimitString(String queryCommand, ILimit limit) {
- int index = queryCommand.startsWith("SELECT DISTINCT")?15:6;
- return new StringBuffer(queryCommand.length() + 8).append(queryCommand)
- .insert(index, " TOP " + limit.getRowLimit()).toString();
+ public List<?> translateCommand(ICommand command, ExecutionContext context) {
+ if (!(command instanceof IQueryCommand)) {
+ return null;
+ }
+ IQueryCommand queryCommand = (IQueryCommand)command;
+ if (queryCommand.getLimit() == null) {
+ return null;
+ }
+ ILimit limit = queryCommand.getLimit();
+ IOrderBy orderBy = queryCommand.getOrderBy();
+ queryCommand.setLimit(null);
+ queryCommand.setOrderBy(null);
+ List<Object> parts = new ArrayList<Object>(6);
+ parts.add("SELECT TOP ");
+ parts.add(limit.getRowLimit());
+ parts.add(" * FROM (");
+ parts.add(queryCommand);
+ parts.add(") AS X");
+ if (orderBy != null) {
+ parts.add(orderBy);
+ }
+ return parts;
}
-
+
@Override
public boolean addSourceComment() {
return false;
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -20,10 +20,11 @@
* 02110-1301 USA.
*/
-/*
- */
package org.teiid.connector.jdbc.db2;
+import java.util.Arrays;
+import java.util.List;
+
import org.teiid.connector.jdbc.translator.AliasModifier;
import org.teiid.connector.jdbc.translator.Translator;
@@ -36,6 +37,7 @@
import com.metamatrix.connector.language.IJoin;
import com.metamatrix.connector.language.ILimit;
import com.metamatrix.connector.language.ILiteral;
+import com.metamatrix.connector.language.IQuery;
import com.metamatrix.connector.language.ICompareCriteria.Operator;
import com.metamatrix.connector.language.IJoin.JoinType;
import com.metamatrix.connector.visitor.framework.HierarchyVisitor;
@@ -53,28 +55,30 @@
registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("coalesce")); //$NON-NLS-1$ //$NON-NLS-2$
registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new AliasModifier("substr")); //$NON-NLS-1$ //$NON-NLS-2$
}
-
+
+ @SuppressWarnings("unchecked")
@Override
- public String addLimitString(String queryCommand, ILimit limit) {
- return queryCommand + " FETCH FIRST " + limit.getRowLimit() + " ROWS ONLY"; //$NON-NLS-1$
+ public List<?> translateLimit(ILimit limit, ExecutionContext context) {
+ return Arrays.asList("FETCH FIRST ", limit.getRowLimit(), " ROWS ONLY"); //$NON-NLS-1$ //$NON-NLS-2$
}
@Override
- public ICommand modifyCommand(ICommand command, ExecutionContext context)
- throws ConnectorException {
- HierarchyVisitor hierarchyVisitor = new HierarchyVisitor() {
- @Override
- public void visit(IJoin obj) {
- if (obj.getJoinType() != JoinType.CROSS_JOIN) {
- return;
+ public ICommand modifyCommand(ICommand command, ExecutionContext context) {
+ if (command instanceof IQuery) {
+ HierarchyVisitor hierarchyVisitor = new HierarchyVisitor(false) {
+ @Override
+ public void visit(IJoin obj) {
+ if (obj.getJoinType() != JoinType.CROSS_JOIN) {
+ return;
+ }
+ ILiteral one = getLanguageFactory().createLiteral(1, TypeFacility.RUNTIME_TYPES.INTEGER);
+ obj.getCriteria().add(getLanguageFactory().createCompareCriteria(Operator.EQ, one, one));
+ obj.setJoinType(JoinType.INNER_JOIN);
}
- ILiteral one = getLanguageFactory().createLiteral(1, TypeFacility.RUNTIME_TYPES.INTEGER);
- obj.getCriteria().add(getLanguageFactory().createCompareCriteria(Operator.EQ, one, one));
- obj.setJoinType(JoinType.INNER_JOIN);
- }
- };
-
- command.acceptVisitor(hierarchyVisitor);
+ };
+
+ command.acceptVisitor(hierarchyVisitor);
+ }
return command;
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -30,6 +30,7 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
+import java.util.ArrayList;
import java.util.List;
import org.teiid.connector.jdbc.JDBCPlugin;
@@ -45,6 +46,7 @@
import com.metamatrix.connector.language.IGroup;
import com.metamatrix.connector.language.IInsert;
import com.metamatrix.connector.language.ILimit;
+import com.metamatrix.connector.language.IQueryCommand;
import com.metamatrix.connector.language.ISetQuery.Operation;
import com.metamatrix.connector.metadata.runtime.Element;
import com.metamatrix.connector.visitor.util.SQLReservedWords;
@@ -88,8 +90,7 @@
}
@Override
- public ICommand modifyCommand(ICommand command, ExecutionContext context)
- throws ConnectorException {
+ public ICommand modifyCommand(ICommand command, ExecutionContext context) throws ConnectorException {
if (!(command instanceof IInsert)) {
return command;
}
@@ -143,28 +144,38 @@
insert.getValues().add(index, sequenceElement);
}
return command;
- }
-
+ }
+
@Override
- public String addLimitString(String queryCommand, ILimit limit) {
- StringBuffer limitQuery = new StringBuffer(queryCommand.length());
+ public List<?> translateCommand(ICommand command, ExecutionContext context) {
+ if (!(command instanceof IQueryCommand)) {
+ return null;
+ }
+ IQueryCommand queryCommand = (IQueryCommand)command;
+ if (queryCommand.getLimit() == null) {
+ return null;
+ }
+ ILimit limit = queryCommand.getLimit();
+ queryCommand.setLimit(null);
+ List<Object> parts = new ArrayList<Object>();
if (limit.getRowOffset() > 0) {
- limitQuery.append("SELECT * FROM (SELECT VIEW_FOR_LIMIT.*, ROWNUM ROWNUM_ FROM (");
+ parts.add("SELECT * FROM (SELECT VIEW_FOR_LIMIT.*, ROWNUM ROWNUM_ FROM (");
} else {
- limitQuery.append("SELECT * FROM (");
+ parts.add("SELECT * FROM (");
}
- limitQuery.append(queryCommand);
+ parts.add(queryCommand);
if (limit.getRowOffset() > 0) {
- limitQuery.append(") VIEW_FOR_LIMIT WHERE ROWNUM <= ").append(
- limit.getRowLimit() + limit.getRowOffset()).append(") WHERE ROWNUM_ > ").append(
- limit.getRowOffset());
+ parts.add(") VIEW_FOR_LIMIT WHERE ROWNUM <= ");
+ parts.add(limit.getRowLimit() + limit.getRowOffset());
+ parts.add(") WHERE ROWNUM_ > ");
+ parts.add(limit.getRowOffset());
} else {
- limitQuery.append(") WHERE ROWNUM <= ").append(
- limit.getRowLimit());
+ parts.add(") WHERE ROWNUM <= ");
+ parts.add(limit.getRowLimit());
}
- return limitQuery.toString();
+ return parts;
}
-
+
@Override
public boolean useAsInGroupAlias(){
return false;
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -25,6 +25,8 @@
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.List;
import org.teiid.connector.jdbc.oracle.LeftOrRightFunctionModifier;
import org.teiid.connector.jdbc.oracle.MonthOrDayNameFunctionModifier;
@@ -39,6 +41,8 @@
import com.metamatrix.connector.language.IAggregate;
import com.metamatrix.connector.language.ICommand;
import com.metamatrix.connector.language.ILimit;
+import com.metamatrix.connector.language.IOrderBy;
+import com.metamatrix.connector.language.ISetQuery;
import com.metamatrix.connector.visitor.framework.HierarchyVisitor;
import com.metamatrix.connector.visitor.util.SQLReservedWords;
@@ -107,14 +111,13 @@
return 6;
}
- @Override
- public String addLimitString(String queryCommand, ILimit limit) {
- StringBuffer sb = new StringBuffer(queryCommand);
- sb.append(" LIMIT ").append(limit.getRowLimit());
- if (limit.getRowOffset() > 0) {
- sb.append(" OFFSET ").append(limit.getRowOffset());
- }
- return sb.toString();
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<?> translateLimit(ILimit limit, ExecutionContext context) {
+ if (limit.getRowOffset() > 0) {
+ return Arrays.asList("LIMIT ", limit.getRowLimit(), " OFFSET ", limit.getRowOffset()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return null;
}
/**
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseSQLTranslator.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseSQLTranslator.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -24,14 +24,21 @@
*/
package org.teiid.connector.jdbc.sybase;
+import java.util.ArrayList;
+import java.util.List;
+
import org.teiid.connector.jdbc.translator.AliasModifier;
import org.teiid.connector.jdbc.translator.SubstringFunctionModifier;
import org.teiid.connector.jdbc.translator.Translator;
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
+import com.metamatrix.connector.api.ExecutionContext;
import com.metamatrix.connector.api.SourceSystemFunctions;
+import com.metamatrix.connector.language.ICommand;
import com.metamatrix.connector.language.ILimit;
+import com.metamatrix.connector.language.IOrderBy;
+import com.metamatrix.connector.language.IQueryCommand;
/**
*/
@@ -67,8 +74,28 @@
}
@Override
- public String addLimitString(String queryCommand, ILimit limit) {
- return "SELECT TOP " + limit.getRowLimit() + " * FROM (" + queryCommand + ") AS X"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ public List<?> translateCommand(ICommand command, ExecutionContext context) {
+ if (!(command instanceof IQueryCommand)) {
+ return null;
+ }
+ IQueryCommand queryCommand = (IQueryCommand)command;
+ if (queryCommand.getLimit() == null) {
+ return null;
+ }
+ ILimit limit = queryCommand.getLimit();
+ IOrderBy orderBy = queryCommand.getOrderBy();
+ queryCommand.setLimit(null);
+ queryCommand.setOrderBy(null);
+ List<Object> parts = new ArrayList<Object>(6);
+ parts.add("SELECT TOP ");
+ parts.add(limit.getRowLimit());
+ parts.add(" * FROM (");
+ parts.add(queryCommand);
+ parts.add(") AS X");
+ if (orderBy != null) {
+ parts.add(orderBy);
+ }
+ return parts;
}
}
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/FunctionReplacementVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/FunctionReplacementVisitor.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/FunctionReplacementVisitor.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -1,204 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.connector.jdbc.translator;
-
-import java.util.List;
-import java.util.Map;
-
-
-import com.metamatrix.connector.language.IAggregate;
-import com.metamatrix.connector.language.ICompareCriteria;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.IGroupBy;
-import com.metamatrix.connector.language.IInCriteria;
-import com.metamatrix.connector.language.IInlineView;
-import com.metamatrix.connector.language.IInsert;
-import com.metamatrix.connector.language.IIsNullCriteria;
-import com.metamatrix.connector.language.ILikeCriteria;
-import com.metamatrix.connector.language.ISearchedCaseExpression;
-import com.metamatrix.connector.language.ISelectSymbol;
-import com.metamatrix.connector.language.ISubqueryCompareCriteria;
-import com.metamatrix.connector.language.ISubqueryInCriteria;
-import com.metamatrix.connector.visitor.framework.HierarchyVisitor;
-
-/**
- */
-public class FunctionReplacementVisitor extends HierarchyVisitor {
-
- private Map functionModifiers;
-
- /**
- * Set the functon modifiers.
- * @param Map of function names to function modifiers.
- */
- public FunctionReplacementVisitor(Map functionModifiers){
- super();
- this.functionModifiers = functionModifiers;
- }
-
- /*
- * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.IAggregate)
- */
- public void visit(IAggregate obj) {
- super.visit(obj);
- obj.setExpression(replaceFunction(obj.getExpression()));
- }
-
- public void visit(IInlineView obj) {
- visitNode(obj.getQuery());
- }
-
- /*
- * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ICompareCriteria)
- */
- public void visit(ICompareCriteria obj) {
- super.visit(obj);
- obj.setLeftExpression(replaceFunction(obj.getLeftExpression()));
- obj.setRightExpression(replaceFunction(obj.getRightExpression()));
- }
-
- /**
- * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.connector.language.IFunction)
- */
- public void visit(IFunction obj) {
- super.visit(obj);
- List<IExpression> args = obj.getParameters();
- for(int i=0; i<args.size(); i++) {
- args.set(i, replaceFunction(args.get(i)));
- }
- }
-
- /**
- * @see com.metamatrix.connector.visitor.framework.HierarchyVisitor#visit(com.metamatrix.connector.language.IGroupBy)
- * @since 4.3
- */
- public void visit(IGroupBy obj) {
- super.visit(obj);
- List<IExpression> expressions = obj.getElements();
-
- for (int i=0; i<expressions.size(); i++) {
- IExpression expression = (IExpression)expressions.get(i);
- expressions.set(i, replaceFunction(expression));
- }
- }
-
- /*
- * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.IInCriteria)
- */
- public void visit(IInCriteria obj) {
- super.visit(obj);
- obj.setLeftExpression(replaceFunction(obj.getLeftExpression()));
- List<IExpression> rightExprs = obj.getRightExpressions();
-
- for(int i=0; i<rightExprs.size(); i++) {
- IExpression expr = (IExpression) rightExprs.get(i);
- rightExprs.set(i, replaceFunction(expr));
- }
- }
-
- /**
- * @see com.metamatrix.data.visitor.SQLStringVisitor#visit(com.metamatrix.connector.language.IInsert)
- */
- public void visit(IInsert obj) {
- super.visit(obj);
- List<IExpression> values = obj.getValues();
-
- for(int i=0; i<values.size(); i++) {
- IExpression expr = (IExpression) values.get(i);
- values.set(i, replaceFunction(expr));
- }
- }
-
- /*
- * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.IIsNullCriteria)
- */
- public void visit(IIsNullCriteria obj) {
- super.visit(obj);
- obj.setExpression(replaceFunction(obj.getExpression()));
- }
-
- /*
- * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ILikeCriteria)
- */
- public void visit(ILikeCriteria obj) {
- super.visit(obj);
- obj.setLeftExpression(replaceFunction(obj.getLeftExpression()));
- obj.setRightExpression(replaceFunction(obj.getRightExpression()));
- }
-
- /*
- * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ISearchedCaseExpression)
- */
- public void visit(ISearchedCaseExpression obj) {
- super.visit(obj);
- int whenCount = obj.getWhenCount();
- for(int i=0; i<whenCount; i++) {
- obj.setThenExpression(i, replaceFunction(obj.getThenExpression(i)));
- }
- obj.setElseExpression(replaceFunction(obj.getElseExpression()));
- }
-
- /*
- * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ISelectSymbol)
- */
- public void visit(ISelectSymbol obj) {
- super.visit(obj);
- obj.setExpression(replaceFunction(obj.getExpression()));
- }
-
- /*
- * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ISubqueryCompareCriteria)
- */
- public void visit(ISubqueryCompareCriteria obj) {
- super.visit(obj);
- obj.setLeftExpression(replaceFunction(obj.getLeftExpression()));
- }
-
- /*
- * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ISubqueryInCriteria)
- */
- public void visit(ISubqueryInCriteria obj) {
- super.visit(obj);
- obj.setLeftExpression(replaceFunction(obj.getLeftExpression()));
- }
-
- private IExpression replaceFunction(IExpression expression) {
- if(functionModifiers != null && expression != null && expression instanceof IFunction){
- // Look for function modifier
- IFunction function = (IFunction) expression;
- String key = function.getName().toLowerCase();
- if(functionModifiers.containsKey(key)) {
- FunctionModifier modifier = (FunctionModifier) functionModifiers.get(key);
-
- // Modify function and return it
- return modifier.modify(function);
- }
- }
-
- // Fall through and return original expression
- return expression;
- }
-
-
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ReplacementVisitor.java (from rev 493, trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/FunctionReplacementVisitor.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ReplacementVisitor.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ReplacementVisitor.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -0,0 +1,221 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.translator;
+
+import java.util.List;
+import java.util.Map;
+
+import com.metamatrix.connector.api.ConnectorException;
+import com.metamatrix.connector.api.ExecutionContext;
+import com.metamatrix.connector.language.IAggregate;
+import com.metamatrix.connector.language.ICompareCriteria;
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.IGroupBy;
+import com.metamatrix.connector.language.IInCriteria;
+import com.metamatrix.connector.language.IInlineView;
+import com.metamatrix.connector.language.IInsert;
+import com.metamatrix.connector.language.IIsNullCriteria;
+import com.metamatrix.connector.language.ILikeCriteria;
+import com.metamatrix.connector.language.IQueryCommand;
+import com.metamatrix.connector.language.IScalarSubquery;
+import com.metamatrix.connector.language.ISearchedCaseExpression;
+import com.metamatrix.connector.language.ISelectSymbol;
+import com.metamatrix.connector.language.ISubqueryCompareCriteria;
+import com.metamatrix.connector.language.ISubqueryInCriteria;
+import com.metamatrix.connector.visitor.framework.AbstractLanguageVisitor;
+import com.metamatrix.core.MetaMatrixRuntimeException;
+
+/**
+ */
+public class ReplacementVisitor extends AbstractLanguageVisitor {
+
+ private Translator translator;
+ private Map<String, FunctionModifier> functionModifiers;
+ private ExecutionContext context;
+
+ /**
+ * Set the functon modifiers.
+ * @param Map of function names to function modifiers.
+ */
+ public ReplacementVisitor(ExecutionContext context, Translator translator){
+ this.translator = translator;
+ this.functionModifiers = translator.getFunctionModifiers();
+ this.context = context;
+ }
+
+ /*
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.IAggregate)
+ */
+ public void visit(IAggregate obj) {
+ obj.setExpression(replaceFunction(obj.getExpression()));
+ }
+
+ public void visit(IInlineView obj) {
+ try {
+ obj.setQuery((IQueryCommand)translator.modifyCommand(obj.getQuery(), context));
+ } catch (ConnectorException e) {
+ throw new MetaMatrixRuntimeException(e);
+ }
+ }
+
+ /*
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ICompareCriteria)
+ */
+ public void visit(ICompareCriteria obj) {
+ obj.setLeftExpression(replaceFunction(obj.getLeftExpression()));
+ obj.setRightExpression(replaceFunction(obj.getRightExpression()));
+ }
+
+ /**
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.connector.language.IFunction)
+ */
+ public void visit(IFunction obj) {
+ List<IExpression> args = obj.getParameters();
+ for(int i=0; i<args.size(); i++) {
+ args.set(i, replaceFunction(args.get(i)));
+ }
+ }
+
+ /**
+ * @see com.metamatrix.connector.visitor.framework.HierarchyVisitor#visit(com.metamatrix.connector.language.IGroupBy)
+ * @since 4.3
+ */
+ public void visit(IGroupBy obj) {
+ List<IExpression> expressions = obj.getElements();
+
+ for (int i=0; i<expressions.size(); i++) {
+ IExpression expression = (IExpression)expressions.get(i);
+ expressions.set(i, replaceFunction(expression));
+ }
+ }
+
+ /*
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.IInCriteria)
+ */
+ public void visit(IInCriteria obj) {
+ obj.setLeftExpression(replaceFunction(obj.getLeftExpression()));
+ List<IExpression> rightExprs = obj.getRightExpressions();
+
+ for(int i=0; i<rightExprs.size(); i++) {
+ IExpression expr = (IExpression) rightExprs.get(i);
+ rightExprs.set(i, replaceFunction(expr));
+ }
+ }
+
+ /**
+ * @see com.metamatrix.data.visitor.SQLStringVisitor#visit(com.metamatrix.connector.language.IInsert)
+ */
+ public void visit(IInsert obj) {
+ List<IExpression> values = obj.getValues();
+
+ for(int i=0; i<values.size(); i++) {
+ IExpression expr = (IExpression) values.get(i);
+ values.set(i, replaceFunction(expr));
+ }
+ }
+
+ /*
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.IIsNullCriteria)
+ */
+ public void visit(IIsNullCriteria obj) {
+ obj.setExpression(replaceFunction(obj.getExpression()));
+ }
+
+ /*
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ILikeCriteria)
+ */
+ public void visit(ILikeCriteria obj) {
+ obj.setLeftExpression(replaceFunction(obj.getLeftExpression()));
+ obj.setRightExpression(replaceFunction(obj.getRightExpression()));
+ }
+
+ /*
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ISearchedCaseExpression)
+ */
+ public void visit(ISearchedCaseExpression obj) {
+ int whenCount = obj.getWhenCount();
+ for(int i=0; i<whenCount; i++) {
+ obj.setThenExpression(i, replaceFunction(obj.getThenExpression(i)));
+ }
+ obj.setElseExpression(replaceFunction(obj.getElseExpression()));
+ }
+
+ /*
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ISelectSymbol)
+ */
+ public void visit(ISelectSymbol obj) {
+ obj.setExpression(replaceFunction(obj.getExpression()));
+ }
+
+ /*
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ISubqueryCompareCriteria)
+ */
+ public void visit(ISubqueryCompareCriteria obj) {
+ try {
+ obj.setQuery((IQueryCommand)translator.modifyCommand(obj.getQuery(), context));
+ } catch (ConnectorException e) {
+ throw new MetaMatrixRuntimeException(e);
+ }
+ obj.setLeftExpression(replaceFunction(obj.getLeftExpression()));
+ }
+
+ @Override
+ public void visit(IScalarSubquery obj) {
+ try {
+ obj.setQuery((IQueryCommand)translator.modifyCommand(obj.getQuery(), context));
+ } catch (ConnectorException e) {
+ throw new MetaMatrixRuntimeException(e);
+ }
+ }
+
+ /*
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ISubqueryInCriteria)
+ */
+ public void visit(ISubqueryInCriteria obj) {
+ try {
+ obj.setQuery((IQueryCommand)translator.modifyCommand(obj.getQuery(), context));
+ } catch (ConnectorException e) {
+ throw new MetaMatrixRuntimeException(e);
+ }
+ obj.setLeftExpression(replaceFunction(obj.getLeftExpression()));
+ }
+
+ private IExpression replaceFunction(IExpression expression) {
+ if(functionModifiers != null && expression != null && expression instanceof IFunction){
+ // Look for function modifier
+ IFunction function = (IFunction) expression;
+ String key = function.getName().toLowerCase();
+ if(functionModifiers.containsKey(key)) {
+ FunctionModifier modifier = (FunctionModifier) functionModifiers.get(key);
+
+ // Modify function and return it
+ return modifier.modify(function);
+ }
+ }
+
+ // Fall through and return original expression
+ return expression;
+ }
+
+}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -28,9 +28,12 @@
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import com.metamatrix.connector.api.ExecutionContext;
import com.metamatrix.connector.api.TypeFacility;
@@ -43,9 +46,6 @@
import com.metamatrix.connector.language.ILiteral;
import com.metamatrix.connector.language.IParameter;
import com.metamatrix.connector.language.IProcedure;
-import com.metamatrix.connector.language.IQuery;
-import com.metamatrix.connector.language.IQueryCommand;
-import com.metamatrix.connector.language.ISetQuery;
import com.metamatrix.connector.language.IParameter.Direction;
import com.metamatrix.connector.language.ISetQuery.Operation;
import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
@@ -64,7 +64,6 @@
private static double SCIENTIC_LOW = Math.pow(10, -3);
private static double SCIENTIC_HIGH = Math.pow(10, 7);
- private Map<String, FunctionModifier> modifiers;
private ExecutionContext context;
private Translator translator;
@@ -73,11 +72,55 @@
private List preparedValues = new ArrayList();
private List preparedTypes = new ArrayList();
+ private Set<ILanguageObject> recursionObjects = Collections.newSetFromMap(new IdentityHashMap<ILanguageObject, Boolean>());
+
public SQLConversionVisitor(Translator translator) {
this.translator = translator;
this.prepared = translator.usePreparedStatements();
- this.modifiers = translator.getFunctionModifiers();
}
+
+ @Override
+ public void append(ILanguageObject obj) {
+ if ((obj instanceof IFunction || obj instanceof ICommand || obj instanceof ILimit) && !recursionObjects.contains(obj)) {
+ recursionObjects.add(obj);
+ try {
+ List<?> parts = null;
+ if (obj instanceof IFunction) {
+ IFunction function = (IFunction)obj;
+ Map<String, FunctionModifier> functionModifiers = translator.getFunctionModifiers();
+ if (functionModifiers != null) {
+ FunctionModifier modifier = functionModifiers.get(function.getName().toLowerCase());
+ if (modifier != null) {
+ parts = modifier.translate(function);
+ }
+ }
+ } else if (obj instanceof ICommand) {
+ parts = translator.translateCommand((ICommand)obj, context);
+ } else if (obj instanceof ILimit) {
+ parts = translator.translateLimit((ILimit)obj, context);
+ }
+ if (parts != null) {
+ this.appendParts(parts);
+ return;
+ }
+ } finally {
+ recursionObjects.remove(obj);
+ }
+ }
+ super.append(obj);
+ }
+
+ private void appendParts(List parts) {
+ Iterator iter = parts.iterator();
+ while(iter.hasNext()) {
+ Object part = iter.next();
+ if(part instanceof ILanguageObject) {
+ append((ILanguageObject)part);
+ } else {
+ buffer.append(part);
+ }
+ }
+ }
public void visit(IBulkInsert obj) {
this.prepared = true;
@@ -150,37 +193,10 @@
* preparedValues is now a list of procedure params instead of just values
*/
this.preparedValues = obj.getParameters();
- super.buffer.append(generateSqlForStoredProcedure(obj));
+ buffer.append(generateSqlForStoredProcedure(obj));
}
/**
- * @see com.metamatrix.connector.visitor.util.SQLStringVisitor#visit(com.metamatrix.connector.language.IFunction)
- */
- public void visit(IFunction obj) {
- if(this.modifiers != null) {
- FunctionModifier functionModifier = (FunctionModifier)this.modifiers.get(obj.getName().toLowerCase());
- if(functionModifier != null) {
- List parts = functionModifier.translate(obj);
-
- // null means the FunctionModifier will rely on default translation
- if (parts != null) {
- Iterator iter = parts.iterator();
- while(iter.hasNext()) {
- Object part = iter.next();
- if(part instanceof String) {
- buffer.append(part);
- } else {
- append((ILanguageObject)part);
- }
- }
- return;
- }
- }
- }
- super.visit(obj);
- }
-
- /**
* @see com.metamatrix.connector.visitor.util.SQLStringVisitor#visit(com.metamatrix.connector.language.ILiteral)
*/
public void visit(ILiteral obj) {
@@ -292,41 +308,12 @@
protected boolean useAsInGroupAlias() {
return this.translator.useAsInGroupAlias();
}
-
+
@Override
- public void visit(IQuery obj) {
- if (obj.getLimit() != null) {
- handleLimit(obj);
- } else {
- super.visit(obj);
- }
- }
-
- @Override
- public void visit(ISetQuery obj) {
- if (obj.getLimit() != null) {
- handleLimit(obj);
- } else {
- super.visit(obj);
- }
- }
-
- @Override
protected boolean useParensForSetQueries() {
return translator.useParensForSetQueries();
}
-
- private void handleLimit(IQueryCommand obj) {
- ILimit limit = obj.getLimit();
- obj.setLimit(null);
- StringBuffer current = this.buffer;
- this.buffer = new StringBuffer();
- append(obj);
- current.append(this.translator.addLimitString(this.buffer.toString(), limit));
- this.buffer = current;
- obj.setLimit(limit);
- }
-
+
@Override
protected String replaceElementName(String group, String element) {
return translator.replaceElementName(group, element);
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/TranslatedCommand.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/TranslatedCommand.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/TranslatedCommand.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -25,14 +25,13 @@
package org.teiid.connector.jdbc.translator;
import java.util.List;
-import java.util.Map;
-
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.ExecutionContext;
import com.metamatrix.connector.api.TypeFacility;
import com.metamatrix.connector.language.ICommand;
import com.metamatrix.connector.language.ILiteral;
+import com.metamatrix.connector.visitor.framework.DelegatingHierarchyVisitor;
import com.metamatrix.connector.visitor.util.CollectorVisitor;
/**
@@ -48,7 +47,7 @@
private List preparedTypes;
private SQLConversionVisitor sqlConversionVisitor;
- private FunctionReplacementVisitor functionVisitor;
+ private ReplacementVisitor functionVisitor;
private ExecutionContext context;
private Translator sqlTranslator;
@@ -59,20 +58,11 @@
public TranslatedCommand(ExecutionContext context, Translator sqlTranslator){
this.context = context;
this.sqlTranslator = sqlTranslator;
-
- Map<String, FunctionModifier> modifiers = sqlTranslator.getFunctionModifiers();
this.sqlConversionVisitor = sqlTranslator.getSQLConversionVisitor();
- sqlConversionVisitor.setExecutionContext(context);
- this.functionVisitor = new FunctionReplacementVisitor(modifiers);
+ this.sqlConversionVisitor.setExecutionContext(context);
+ this.functionVisitor = new ReplacementVisitor(context, sqlTranslator);
}
- public TranslatedCommand(ExecutionContext context, Translator sqlTranslator, SQLConversionVisitor sqlConversionVisitor, FunctionReplacementVisitor functionVisitor) {
- this.context = context;
- this.sqlTranslator = sqlTranslator;
- this.sqlConversionVisitor = sqlConversionVisitor;
- this.functionVisitor = functionVisitor;
- }
-
/**
* The method to cause this object to do it's thing. This method should
* be called right after the constructor; afterward, all of the getter methods
@@ -89,7 +79,7 @@
private String getSQL(ICommand command) throws ConnectorException {
command = sqlTranslator.modifyCommand(command, context);
- command.acceptVisitor(functionVisitor);
+ command.acceptVisitor(new DelegatingHierarchyVisitor(null, this.functionVisitor));
if (sqlTranslator.usePreparedStatements() || hasBindValue(command)) {
this.sqlConversionVisitor.setPrepared(true);
@@ -167,5 +157,15 @@
public boolean isPrepared() {
return prepared;
}
+
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ if (prepared) {
+ sb.append("Prepared Values: ").append(preparedValues).append(" "); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ sb.append("SQL: ").append(sql); //$NON-NLS-1$
+ return sb.toString();
+ }
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -52,7 +52,9 @@
import com.metamatrix.connector.api.ValueTranslator;
import com.metamatrix.connector.internal.ConnectorPropertyNames;
import com.metamatrix.connector.language.ICommand;
+import com.metamatrix.connector.language.IFunction;
import com.metamatrix.connector.language.ILanguageFactory;
+import com.metamatrix.connector.language.ILanguageObject;
import com.metamatrix.connector.language.ILimit;
import com.metamatrix.connector.language.IParameter;
import com.metamatrix.connector.language.ISetQuery;
@@ -192,6 +194,14 @@
return command;
}
+ public List<?> translateCommand(ICommand command, ExecutionContext context) {
+ return null;
+ }
+
+ public List<?> translateLimit(ILimit limit, ExecutionContext context) {
+ return null;
+ }
+
/**
* Return a map of function name in lower case to FunctionModifier.
* @return Map of function name to FunctionModifier.
@@ -287,10 +297,6 @@
return useComments;
}
- public String addLimitString(String queryCommand, ILimit limit) {
- return queryCommand + " " + limit.toString(); //$NON-NLS-1$
- }
-
/**
* Indicates whether group alias should be of the form
* "...FROM groupA AS X" or "...FROM groupA X". Certain
@@ -562,13 +568,25 @@
return new Float(value);
}
case TIME_CODE: {
- return results.getTime(columnIndex, getDatabaseCalendar());
+ Calendar cal = getDatabaseCalendar();
+ if (cal != null) {
+ return results.getTime(columnIndex, cal);
+ }
+ return results.getTime(columnIndex);
}
case DATE_CODE: {
- return results.getDate(columnIndex, getDatabaseCalendar());
+ Calendar cal = getDatabaseCalendar();
+ if (cal != null) {
+ return results.getDate(columnIndex, cal);
+ }
+ return results.getDate(columnIndex);
}
case TIMESTAMP_CODE: {
- return results.getTimestamp(columnIndex, getDatabaseCalendar());
+ Calendar cal = getDatabaseCalendar();
+ if (cal != null) {
+ return results.getTimestamp(columnIndex, cal);
+ }
+ return results.getTimestamp(columnIndex);
}
case BLOB_CODE: {
try {
@@ -635,13 +653,25 @@
return new Float(value);
}
case TIME_CODE: {
- return results.getTime(parameterIndex, getDatabaseCalendar());
+ Calendar cal = getDatabaseCalendar();
+ if (cal != null) {
+ return results.getTime(parameterIndex, cal);
+ }
+ return results.getTime(parameterIndex);
}
case DATE_CODE: {
- return results.getDate(parameterIndex, getDatabaseCalendar());
+ Calendar cal = getDatabaseCalendar();
+ if (cal != null) {
+ return results.getDate(parameterIndex, cal);
+ }
+ return results.getDate(parameterIndex);
}
case TIMESTAMP_CODE: {
- return results.getTimestamp(parameterIndex, getDatabaseCalendar());
+ Calendar cal = getDatabaseCalendar();
+ if (cal != null) {
+ return results.getTimestamp(parameterIndex, cal);
+ }
+ return results.getTimestamp(parameterIndex);
}
case BLOB_CODE: {
try {
@@ -703,5 +733,5 @@
public SQLConversionVisitor getSQLConversionVisitor() {
return new SQLConversionVisitor(this);
}
-
+
}
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/access/TestAccessSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/access/TestAccessSQLTranslator.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/access/TestAccessSQLTranslator.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -66,7 +66,7 @@
public void testRowLimit() throws Exception {
String input = "select intkey from bqt1.smalla limit 100"; //$NON-NLS-1$
- String output = "SELECT TOP 100 SmallA.IntKey FROM SmallA"; //$NON-NLS-1$
+ String output = "SELECT TOP 100 * FROM (SELECT SmallA.IntKey FROM SmallA) AS X"; //$NON-NLS-1$
helpTestVisitor(
input,
@@ -76,7 +76,7 @@
public void testRowLimit1() throws Exception {
String input = "select distinct intkey from bqt1.smalla limit 100"; //$NON-NLS-1$
- String output = "SELECT DISTINCT TOP 100 SmallA.IntKey FROM SmallA"; //$NON-NLS-1$
+ String output = "SELECT TOP 100 * FROM (SELECT DISTINCT SmallA.IntKey FROM SmallA) AS X"; //$NON-NLS-1$
helpTestVisitor(
input,
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -22,48 +22,29 @@
package org.teiid.connector.jdbc.sqlserver;
-import java.util.Map;
import java.util.Properties;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
import org.teiid.connector.jdbc.MetadataFactory;
-import org.teiid.connector.jdbc.sqlserver.SqlServerSQLTranslator;
-import org.teiid.connector.jdbc.translator.FunctionReplacementVisitor;
-import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
import org.teiid.connector.jdbc.translator.TranslatedCommand;
-import junit.framework.TestCase;
-
import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.language.ICommand;
/**
*/
-public class TestSqlServerConversionVisitor extends TestCase {
+public class TestSqlServerConversionVisitor {
- private static final Properties EMPTY_PROPERTIES = new Properties();
- private static Map MODIFIERS;
+ private static SqlServerSQLTranslator trans = new SqlServerSQLTranslator();
- static {
- SqlServerSQLTranslator trans = new SqlServerSQLTranslator();
-
- try {
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
- } catch(ConnectorException e) {
- e.printStackTrace();
- }
-
- MODIFIERS = trans.getFunctionModifiers();
+ @BeforeClass
+ public static void setup() throws ConnectorException {
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
}
- /**
- * Constructor for TestSqlServerConversionVisitor.
- * @param name
- */
- public TestSqlServerConversionVisitor(String name) {
- super(name);
- }
-
public String getTestVDB() {
return MetadataFactory.PARTS_VDB;
}
@@ -72,67 +53,54 @@
return MetadataFactory.BQT_VDB;
}
- public void helpTestVisitor(String vdb, String input, Map modifiers, String expectedOutput) throws ConnectorException {
- helpTestVisitor(vdb, input, modifiers, new String[] {expectedOutput}, EMPTY_PROPERTIES);
+ public void helpTestVisitor(String vdb, String input, String expectedOutput) throws ConnectorException {
+ helpTestVisitor(vdb, input, new String[] {expectedOutput});
}
- public void helpTestVisitor(String vdb, String input, Map modifiers, String[] expectedOutputs, Properties props) throws ConnectorException {
- // Convert from sql to objects
+ public void helpTestVisitor(String vdb, String input, String[] expectedOutputs) throws ConnectorException {
ICommand obj = MetadataFactory.helpTranslate(vdb, input);
-
- // Apply function replacement
- FunctionReplacementVisitor funcVisitor = new FunctionReplacementVisitor(modifiers);
-
- SqlServerSQLTranslator trans = new SqlServerSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(props, false));
- // Convert back to SQL
- SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
-
- TranslatedCommand tc = new TranslatedCommand(EnvironmentUtility.createSecurityContext("user"), trans, sqlVisitor, funcVisitor); //$NON-NLS-1$
+ TranslatedCommand tc = new TranslatedCommand(EnvironmentUtility.createSecurityContext("user"), trans); //$NON-NLS-1$
tc.translateCommand(obj);
-
- // Check stuff
-
- assertEquals("Did not get correct sql", expectedOutputs[0], tc.getSql()); //$NON-NLS-1$
+ Assert.assertEquals("Did not get correct sql", expectedOutputs[0], tc.getSql()); //$NON-NLS-1$
}
+ @Test
public void testModFunction() throws Exception {
String input = "SELECT mod(CONVERT(PART_ID, INTEGER), 13) FROM parts"; //$NON-NLS-1$
String output = "SELECT (convert(int, PARTS.PART_ID) % 13) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
+ @Test
public void testConcatFunction() throws Exception {
String input = "SELECT concat(part_name, 'b') FROM PARTS"; //$NON-NLS-1$
String output = "SELECT (PARTS.PART_NAME + 'b') FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
+ @Test
public void testDayOfMonthFunction() throws Exception {
String input = "SELECT dayofmonth(convert(PARTS.PART_ID, date)) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT day(convert(datetime, PARTS.PART_ID)) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
+ @Test
public void testRowLimit() throws Exception {
String input = "select intkey from bqt1.smalla limit 100"; //$NON-NLS-1$
String output = "SELECT TOP 100 * FROM (SELECT SmallA.IntKey FROM SmallA) AS X"; //$NON-NLS-1$
helpTestVisitor(getBQTVDB(),
input,
- MODIFIERS,
output);
}
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -22,30 +22,28 @@
package org.teiid.connector.jdbc.sybase;
+import static org.junit.Assert.assertEquals;
+
import java.util.Properties;
+import org.junit.BeforeClass;
+import org.junit.Test;
import org.teiid.connector.jdbc.MetadataFactory;
-import org.teiid.connector.jdbc.sybase.SybaseSQLTranslator;
-import org.teiid.connector.jdbc.translator.FunctionReplacementVisitor;
-import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
import org.teiid.connector.jdbc.translator.TranslatedCommand;
-import junit.framework.TestCase;
-
import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.language.ICommand;
/**
*/
-public class TestSybaseSQLConversionVisitor extends TestCase {
+public class TestSybaseSQLConversionVisitor {
- /**
- * Constructor for TestSqlServerConversionVisitor.
- * @param name
- */
- public TestSybaseSQLConversionVisitor(String name) {
- super(name);
+ private static SybaseSQLTranslator trans = new SybaseSQLTranslator();
+
+ @BeforeClass
+ public static void setup() throws ConnectorException {
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
}
public String getTestVDB() {
@@ -60,30 +58,17 @@
// Convert from sql to objects
ICommand obj = MetadataFactory.helpTranslate(vdb, input);
- // Apply function replacement
- SybaseSQLTranslator trans = new SybaseSQLTranslator();
- try {
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
- } catch (ConnectorException e1) {
- throw new RuntimeException(e1);
- }
- FunctionReplacementVisitor funcVisitor = new FunctionReplacementVisitor(trans.getFunctionModifiers());
-
- // Convert back to SQL
- SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
- TranslatedCommand tc = new TranslatedCommand(EnvironmentUtility.createSecurityContext("user"), trans, sqlVisitor, funcVisitor);
+ TranslatedCommand tc = new TranslatedCommand(EnvironmentUtility.createSecurityContext("user"), trans);
try {
tc.translateCommand(obj);
} catch (ConnectorException e) {
throw new RuntimeException(e);
}
- // Check stuff
-// System.out.println("in: " + input); //$NON-NLS-1$
- //System.out.println("out: " + tc.getSql()); //$NON-NLS-1$
assertEquals("Did not get correct sql", expectedOutput, tc.getSql()); //$NON-NLS-1$
}
+ @Test
public void testModFunction() {
String input = "SELECT mod(CONVERT(PART_ID, INTEGER), 13) FROM parts"; //$NON-NLS-1$
//String output = "SELECT (PARTS.PART_ID % 13) FROM PARTS"; //$NON-NLS-1$
@@ -94,6 +79,7 @@
output);
}
+ @Test
public void testConcatFunction() {
String input = "SELECT concat(part_name, 'b') FROM PARTS"; //$NON-NLS-1$
String output = "SELECT (PARTS.PART_NAME + 'b') FROM PARTS"; //$NON-NLS-1$
@@ -103,6 +89,7 @@
output);
}
+ @Test
public void testLcaseFunction() {
String input = "SELECT lcase(PART_NAME) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT lower(PARTS.PART_NAME) FROM PARTS"; //$NON-NLS-1$
@@ -111,6 +98,7 @@
output);
}
+ @Test
public void testUcaseFunction() {
String input = "SELECT ucase(PART_NAME) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT upper(PARTS.PART_NAME) FROM PARTS"; //$NON-NLS-1$
@@ -120,6 +108,7 @@
output);
}
+ @Test
public void testLengthFunction() {
String input = "SELECT length(PART_NAME) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT char_length(PARTS.PART_NAME) FROM PARTS"; //$NON-NLS-1$
@@ -129,6 +118,7 @@
output);
}
+ @Test
public void testSubstring2ArgFunction() {
String input = "SELECT substring(PART_NAME, 3) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT substring(PARTS.PART_NAME, 3, char_length(PARTS.PART_NAME)) FROM PARTS"; //$NON-NLS-1$
@@ -138,6 +128,7 @@
output);
}
+ @Test
public void testSubstring3ArgFunction() {
String input = "SELECT substring(PART_NAME, 3, 5) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT substring(PARTS.PART_NAME, 3, 5) FROM PARTS"; //$NON-NLS-1$
@@ -147,6 +138,7 @@
output);
}
+ @Test
public void testConvertFunctionInteger() {
String input = "SELECT convert(PARTS.PART_ID, integer) FROM PARTS"; //$NON-NLS-1$
//String output = "SELECT PARTS.PART_ID FROM PARTS"; //$NON-NLS-1$
@@ -157,6 +149,7 @@
output);
}
+ @Test
public void testConvertFunctionChar() {
String input = "SELECT convert(PART_NAME, char) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT convert(char, PARTS.PART_NAME) FROM PARTS"; //$NON-NLS-1$
@@ -166,6 +159,7 @@
output);
}
+ @Test
public void testConvertFunctionBoolean() {
String input = "SELECT convert(PART_ID, boolean) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT convert(bit, PARTS.PART_ID) FROM PARTS"; //$NON-NLS-1$
@@ -175,6 +169,7 @@
output);
}
+ @Test
public void testIfNullFunction() {
String input = "SELECT ifnull(PART_NAME, 'abc') FROM PARTS"; //$NON-NLS-1$
String output = "SELECT isnull(PARTS.PART_NAME, 'abc') FROM PARTS"; //$NON-NLS-1$
@@ -184,24 +179,28 @@
output);
}
+ @Test
public void testDateLiteral() {
helpTestVisitor(getTestVDB(),
"select {d'2002-12-31'} FROM parts", //$NON-NLS-1$
"SELECT {d'2002-12-31'} FROM PARTS"); //$NON-NLS-1$
}
+ @Test
public void testTimeLiteral() {
helpTestVisitor(getTestVDB(),
"select {t'13:59:59'} FROM parts", //$NON-NLS-1$
"SELECT {ts'1970-01-01 13:59:59'} FROM PARTS"); //$NON-NLS-1$
}
+ @Test
public void testTimestampLiteral() {
helpTestVisitor(getTestVDB(),
"select {ts'2002-12-31 13:59:59'} FROM parts", //$NON-NLS-1$
"SELECT {ts'2002-12-31 13:59:59.0'} FROM PARTS"); //$NON-NLS-1$
}
+ @Test
public void testDefect12120() {
helpTestVisitor(getBQTVDB(),
"SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA WHERE BQT1.SmallA.BooleanValue IN ({b'false'}, {b'true'}) ORDER BY IntKey", //$NON-NLS-1$
@@ -209,6 +208,7 @@
}
+ @Test
public void testConvertFunctionString() throws Exception {
String input = "SELECT convert(PARTS.PART_ID, integer) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT convert(int, PARTS.PART_ID) FROM PARTS"; //$NON-NLS-1$
@@ -217,7 +217,8 @@
input,
output);
}
-
+
+ @Test
public void testNonIntMod() throws Exception {
String input = "select mod(intkey/1.5, 3) from bqt1.smalla"; //$NON-NLS-1$
String output = "SELECT ((convert(float, SmallA.IntKey) / 1.5) - (floor(((convert(float, SmallA.IntKey) / 1.5) / 3.0)) * 3.0)) FROM SmallA"; //$NON-NLS-1$
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/util/TestFunctionReplacementVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/util/TestFunctionReplacementVisitor.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/util/TestFunctionReplacementVisitor.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -27,11 +27,14 @@
import org.teiid.connector.jdbc.MetadataFactory;
import org.teiid.connector.jdbc.translator.DropFunctionModifier;
-import org.teiid.connector.jdbc.translator.FunctionReplacementVisitor;
+import org.teiid.connector.jdbc.translator.FunctionModifier;
+import org.teiid.connector.jdbc.translator.ReplacementVisitor;
+import org.teiid.connector.jdbc.translator.Translator;
import junit.framework.TestCase;
import com.metamatrix.connector.language.ICommand;
+import com.metamatrix.connector.visitor.framework.DelegatingHierarchyVisitor;
/**
*/
@@ -43,7 +46,6 @@
*/
public TestFunctionReplacementVisitor(String name) {
super(name);
- System.setProperty("metamatrix.config.none", "true");
}
public Map getModifierSet1() {
@@ -58,11 +60,16 @@
return MetadataFactory.PARTS_VDB;
}
- public void helpTestVisitor(String vdb, String input, Map modifiers, String expectedOutput) {
+ public void helpTestVisitor(String vdb, String input, final Map modifiers, String expectedOutput) {
ICommand obj = MetadataFactory.helpTranslate(vdb, input);
- FunctionReplacementVisitor visitor = new FunctionReplacementVisitor(modifiers);
- obj.acceptVisitor(visitor);
+ ReplacementVisitor visitor = new ReplacementVisitor(null, new Translator() {
+ @Override
+ public Map<String, FunctionModifier> getFunctionModifiers() {
+ return modifiers;
+ }
+ });
+ obj.acceptVisitor(new DelegatingHierarchyVisitor(null, visitor));
//System.out.println(obj);
assertEquals("Did not get expected sql", expectedOutput, obj.toString()); //$NON-NLS-1$
Modified: trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialSQLTranslator.java
===================================================================
--- trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialSQLTranslator.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialSQLTranslator.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -70,7 +70,7 @@
* This method is overridden to modify the incoming command to add the hint to the ISelect in the command.
*/
@Override
- public ICommand modifyCommand(ICommand command, com.metamatrix.connector.api.ExecutionContext context) throws ConnectorException {
+ public ICommand modifyCommand(ICommand command, ExecutionContext context) throws ConnectorException {
if (command instanceof IQuery) {
IQuery query = (IQuery)command;
Modified: trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java
===================================================================
--- trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java 2009-02-25 18:12:40 UTC (rev 498)
+++ trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java 2009-02-25 18:27:23 UTC (rev 499)
@@ -22,18 +22,15 @@
package com.metamatrix.connector.jdbc.extension;
-import java.util.HashMap;
-import java.util.Map;
import java.util.Properties;
+import junit.framework.TestCase;
+
import org.teiid.connector.jdbc.JDBCPropertyNames;
-import org.teiid.connector.jdbc.translator.FunctionReplacementVisitor;
import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
import org.teiid.connector.jdbc.translator.TranslatedCommand;
import org.teiid.connector.jdbc.translator.Translator;
-import junit.framework.TestCase;
-
import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.cdk.api.TranslationUtility;
import com.metamatrix.connector.api.ConnectorException;
@@ -96,20 +93,20 @@
return util.parseCommand(sql);
}
- public void helpTestVisitor(String vdb, String input, Map modifiers, String expectedOutput) {
- helpTestVisitor(vdb, input, modifiers, expectedOutput, false);
+ public void helpTestVisitor(String vdb, String input, String expectedOutput) {
+ helpTestVisitor(vdb, input, expectedOutput, false);
}
- public void helpTestVisitor(String vdb, String input, Map modifiers, String expectedOutput, boolean useMetadata) {
- helpTestVisitor(vdb, input, modifiers, expectedOutput, useMetadata, false);
+ public void helpTestVisitor(String vdb, String input, String expectedOutput, boolean useMetadata) {
+ helpTestVisitor(vdb, input, expectedOutput, useMetadata, false);
}
- public void helpTestVisitor(String vdb, String input, Map modifiers, String expectedOutput, boolean useMetadata, boolean usePreparedStatement) {
+ public void helpTestVisitor(String vdb, String input, String expectedOutput, boolean useMetadata, boolean usePreparedStatement) {
// Convert from sql to objects
ICommand obj = helpTranslate(vdb, input);
try {
- helpTestVisitorWithCommand(modifiers, expectedOutput, obj, useMetadata, usePreparedStatement);
+ helpTestVisitorWithCommand(expectedOutput, obj, useMetadata, usePreparedStatement);
} catch (ConnectorException e) {
throw new RuntimeException(e);
}
@@ -128,28 +125,24 @@
}
/**
- * @param modifiers
* @param expectedOutput
- * @param obj
+ * @param obj
* @throws ConnectorException
* @since 4.2
*/
- private void helpTestVisitorWithCommand(Map modifiers,
- String expectedOutput,
+ private void helpTestVisitorWithCommand(String expectedOutput,
ICommand obj,
- boolean useMetadata, boolean usePreparedStatement) throws ConnectorException {
+ boolean useMetadata,
+ boolean usePreparedStatement) throws ConnectorException {
// Apply function replacement
- FunctionReplacementVisitor funcVisitor = new FunctionReplacementVisitor(modifiers);
Translator trans = new Translator();
Properties p = new Properties();
if (usePreparedStatement) {
p.setProperty(JDBCPropertyNames.USE_BIND_VARIABLES, Boolean.TRUE.toString());
}
trans.initialize(EnvironmentUtility.createEnvironment(p, false));
- // Convert back to SQL
- SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
- TranslatedCommand tc = new TranslatedCommand(new FakeExecutionContextImpl(), trans, sqlVisitor, funcVisitor);
+ TranslatedCommand tc = new TranslatedCommand(new FakeExecutionContextImpl(), trans);
tc.translateCommand(obj);
assertEquals("Did not get correct sql", expectedOutput, tc.getSql()); //$NON-NLS-1$
@@ -158,252 +151,216 @@
public void testSimple() {
helpTestVisitor(getTestVDB(),
"select part_name from parts", //$NON-NLS-1$
- new HashMap(),
"SELECT PARTS.PART_NAME FROM PARTS"); //$NON-NLS-1$
}
public void testAliasInSelect() {
helpTestVisitor(getTestVDB(),
"select part_name as x from parts", //$NON-NLS-1$
- new HashMap(),
"SELECT PARTS.PART_NAME AS x FROM PARTS"); //$NON-NLS-1$
}
public void testAliasedGroup() {
helpTestVisitor(getTestVDB(),
"select y.part_name from parts y", //$NON-NLS-1$
- new HashMap(),
"SELECT y.PART_NAME FROM PARTS AS y"); //$NON-NLS-1$
}
public void testAliasedGroupAndElement() {
helpTestVisitor(getTestVDB(),
"select y.part_name AS z from parts y", //$NON-NLS-1$
- new HashMap(),
"SELECT y.PART_NAME AS z FROM PARTS AS y"); //$NON-NLS-1$
}
public void testLiteralString() {
helpTestVisitor(getTestVDB(),
"select 'x' from parts", //$NON-NLS-1$
- new HashMap(),
"SELECT 'x' FROM PARTS"); //$NON-NLS-1$
}
public void testLiteralInteger() {
helpTestVisitor(getTestVDB(),
"select 5 from parts", //$NON-NLS-1$
- new HashMap(),
"SELECT 5 FROM PARTS"); //$NON-NLS-1$
}
public void testLiteralFloat() {
helpTestVisitor(getTestVDB(),
"select 5.2 from parts", //$NON-NLS-1$
- new HashMap(),
"SELECT 5.2 FROM PARTS"); //$NON-NLS-1$
}
public void testLiteralLowFloat() {
helpTestVisitor(getTestVDB(),
"select 0.012 from parts", //$NON-NLS-1$
- new HashMap(),
"SELECT 0.012 FROM PARTS"); //$NON-NLS-1$
}
public void testLiteralLowFloat2() {
helpTestVisitor(getTestVDB(),
"select 0.00012 from parts", //$NON-NLS-1$
- new HashMap(),
"SELECT 0.00012 FROM PARTS"); //$NON-NLS-1$
}
public void testLiteralHighFloat() {
helpTestVisitor(getTestVDB(),
"select 12345.123 from parts", //$NON-NLS-1$
- new HashMap(),
"SELECT 12345.123 FROM PARTS"); //$NON-NLS-1$
}
public void testLiteralHighFloat2() {
helpTestVisitor(getTestVDB(),
"select 1234567890.1234567 from parts", //$NON-NLS-1$
- new HashMap(),
"SELECT 1234567890.1234567 FROM PARTS"); //$NON-NLS-1$
}
public void testLiteralBoolean() {
helpTestVisitor(getTestVDB(),
"select {b'true'}, {b'false'} from parts", //$NON-NLS-1$
- new HashMap(),
"SELECT 1, 0 FROM PARTS"); //$NON-NLS-1$
}
public void testLiteralDate() {
helpTestVisitor(getTestVDB(),
"select {d'2003-12-31'} from parts", //$NON-NLS-1$
- new HashMap(),
"SELECT {d'2003-12-31'} FROM PARTS"); //$NON-NLS-1$
}
public void testLiteralTime() {
helpTestVisitor(getTestVDB(),
"select {t'23:59:59'} from parts", //$NON-NLS-1$
- new HashMap(),
"SELECT {t'23:59:59'} FROM PARTS"); //$NON-NLS-1$
}
public void testLiteralNull() {
helpTestVisitor(getTestVDB(),
"select null from parts", //$NON-NLS-1$
- new HashMap(),
"SELECT NULL FROM PARTS"); //$NON-NLS-1$
}
public void testLiteralTimestamp() {
helpTestVisitor(getTestVDB(),
"select {ts'2003-12-31 23:59:59.123'} from parts", //$NON-NLS-1$
- new HashMap(),
"SELECT {ts'2003-12-31 23:59:59.123'} FROM PARTS"); //$NON-NLS-1$
}
public void testSQL89Join() {
helpTestVisitor(getTestVDB(),
"select p.part_name from parts p, supplier_parts s where p.part_id = s.part_id", //$NON-NLS-1$
- new HashMap(),
"SELECT p.PART_NAME FROM PARTS AS p, SUPPLIER_PARTS AS s WHERE p.PART_ID = s.PART_ID"); //$NON-NLS-1$
}
public void testSQL92Join() {
helpTestVisitor(getTestVDB(),
"select p.part_name from parts p join supplier_parts s on p.part_id = s.part_id", //$NON-NLS-1$
- new HashMap(),
"SELECT p.PART_NAME FROM PARTS AS p INNER JOIN SUPPLIER_PARTS AS s ON p.PART_ID = s.PART_ID"); //$NON-NLS-1$
}
public void testSelfJoin() {
helpTestVisitor(getTestVDB(),
"select p.part_name from parts p join parts p2 on p.part_id = p2.part_id", //$NON-NLS-1$
- new HashMap(),
"SELECT p.PART_NAME FROM PARTS AS p INNER JOIN PARTS AS p2 ON p.PART_ID = p2.PART_ID"); //$NON-NLS-1$
}
public void testRightOuterJoin() {
helpTestVisitor(getTestVDB(),
"select p.part_name from parts p right join supplier_parts s on p.part_id = s.part_id", //$NON-NLS-1$
- new HashMap(),
"SELECT p.PART_NAME FROM SUPPLIER_PARTS AS s LEFT OUTER JOIN PARTS AS p ON p.PART_ID = s.PART_ID"); //$NON-NLS-1$
}
public void testLeftOuterJoin() {
helpTestVisitor(getTestVDB(),
"select p.part_name from parts p left join supplier_parts s on p.part_id = s.part_id", //$NON-NLS-1$
- new HashMap(),
"SELECT p.PART_NAME FROM PARTS AS p LEFT OUTER JOIN SUPPLIER_PARTS AS s ON p.PART_ID = s.PART_ID"); //$NON-NLS-1$
}
public void testFullOuterJoin() {
helpTestVisitor(getTestVDB(),
"select p.part_name from parts p full join supplier_parts s on p.part_id = s.part_id", //$NON-NLS-1$
- new HashMap(),
"SELECT p.PART_NAME FROM PARTS AS p FULL OUTER JOIN SUPPLIER_PARTS AS s ON p.PART_ID = s.PART_ID"); //$NON-NLS-1$
}
public void testCompare1() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id = 'x'", //$NON-NLS-1$
- new HashMap(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID = 'x'"); //$NON-NLS-1$
}
public void testCompare2() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id <> 'x'", //$NON-NLS-1$
- new HashMap(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID <> 'x'"); //$NON-NLS-1$
}
public void testCompare3() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id < 'x'", //$NON-NLS-1$
- new HashMap(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID < 'x'"); //$NON-NLS-1$
}
public void testCompare4() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id <= 'x'", //$NON-NLS-1$
- new HashMap(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID <= 'x'"); //$NON-NLS-1$
}
public void testCompare5() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id > 'x'", //$NON-NLS-1$
- new HashMap(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID > 'x'"); //$NON-NLS-1$
}
public void testCompare6() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id >= 'x'", //$NON-NLS-1$
- new HashMap(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID >= 'x'"); //$NON-NLS-1$
}
public void testIn1() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id in ('x')", //$NON-NLS-1$
- new HashMap(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID = 'x'"); //$NON-NLS-1$
}
public void testIn2() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id in ('x', 'y')", //$NON-NLS-1$
- new HashMap(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID IN ('x', 'y')"); //$NON-NLS-1$
}
public void testIn3() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id not in ('x', 'y')", //$NON-NLS-1$
- new HashMap(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID NOT IN ('x', 'y')"); //$NON-NLS-1$
}
public void testIsNull1() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id is null", //$NON-NLS-1$
- new HashMap(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID IS NULL"); //$NON-NLS-1$
}
public void testIsNull2() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id is not null", //$NON-NLS-1$
- new HashMap(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID IS NOT NULL"); //$NON-NLS-1$
}
public void testInsertNull() {
helpTestVisitor(getTestVDB(),
"insert into parts (part_id, part_name, part_color, part_weight) values ('a', null, 'c', 'd')", //$NON-NLS-1$
- new HashMap(),
"INSERT INTO PARTS (PART_ID, PART_NAME, PART_COLOR, PART_WEIGHT) VALUES ('a', NULL, 'c', 'd')"); //$NON-NLS-1$
}
public void testUpdateNull() {
helpTestVisitor(getTestVDB(),
"update parts set part_weight = null where part_color = 'b'", //$NON-NLS-1$
- new HashMap(),
"UPDATE PARTS SET PART_WEIGHT = NULL WHERE PARTS.PART_COLOR = 'b'"); //$NON-NLS-1$
}
public void testUpdateWhereNull() {
helpTestVisitor(getTestVDB(),
"update parts set part_weight = 'a' where part_weight = null", //$NON-NLS-1$
- new HashMap(),
"UPDATE PARTS SET PART_WEIGHT = 'a' WHERE NULL <> NULL"); //$NON-NLS-1$
}
@@ -427,41 +384,41 @@
ICommand result = new LanguageBridgeFactory(metadata).translate(command);
- helpTestVisitorWithCommand(new HashMap(), "SELECT PARTS.PART_NAME FROM PARTS GROUP BY concat(PARTS.PART_ID, 'a')",
- result, //$NON-NLS-1$
- false, false);
+ helpTestVisitorWithCommand("SELECT PARTS.PART_NAME FROM PARTS GROUP BY concat(PARTS.PART_ID, 'a')", result,
+ false, //$NON-NLS-1$
+ false);
}
public void testPreparedStatementCreationWithUpdate() {
helpTestVisitor(getTestVDB(),
"update parts set part_weight = 'a' where part_weight < 5", //$NON-NLS-1$
- new HashMap(),
"UPDATE PARTS SET PART_WEIGHT = ? WHERE PARTS.PART_WEIGHT < ?",
- false, true); //$NON-NLS-1$
+ false,
+ true); //$NON-NLS-1$
}
public void testPreparedStatementCreationWithInsert() {
helpTestVisitor(getTestVDB(),
"insert into parts (part_weight) values (5)", //$NON-NLS-1$
- new HashMap(),
"INSERT INTO PARTS (PART_WEIGHT) VALUES (?)",
- false, true); //$NON-NLS-1$
+ false,
+ true); //$NON-NLS-1$
}
public void testPreparedStatementCreationWithSelect() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id not in ('x', 'y') and part_weight < 6", //$NON-NLS-1$
- new HashMap(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE (PARTS.PART_ID NOT IN (?, ?)) AND (PARTS.PART_WEIGHT < ?)",
- false, true); //$NON-NLS-1$
+ false,
+ true); //$NON-NLS-1$
}
public void testPreparedStatementCreationWithLike() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_name like '%foo'", //$NON-NLS-1$
- new HashMap(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_NAME LIKE ?",
- false, true); //$NON-NLS-1$
+ false,
+ true); //$NON-NLS-1$
}
/**
@@ -471,9 +428,9 @@
public void testPreparedStatementCreationWithLeftConstant() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where 'x' = 'y'", //$NON-NLS-1$
- new HashMap(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE 1 = ?",
- false, true); //$NON-NLS-1$
+ false,
+ true); //$NON-NLS-1$
}
/**
@@ -483,17 +440,17 @@
public void testPreparedStatementCreationWithFunction() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where concat(part_name, 'x') = concat('y', part_weight)", //$NON-NLS-1$
- new HashMap(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE concat(PARTS.PART_NAME, 'x') = concat('y', PARTS.PART_WEIGHT)",
- false, true); //$NON-NLS-1$
+ false,
+ true); //$NON-NLS-1$
}
public void testPreparedStatementCreationWithCase() {
helpTestVisitor(getTestVDB(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_WEIGHT = CASE WHEN PARTS.PART_NAME='a' THEN 'b' ELSE 'c' END", //$NON-NLS-1$
- new HashMap(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_WEIGHT = CASE WHEN PARTS.PART_NAME = ? THEN 'b' ELSE 'c' END",
- false, true); //$NON-NLS-1$
+ false,
+ true); //$NON-NLS-1$
}
public void testVisitIDeleteWithComment() throws Exception {
15 years, 10 months
teiid SVN: r498 - in trunk: common-internal/src/main/java/com/metamatrix/common/config/api and 7 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2009-02-25 13:12:40 -0500 (Wed, 25 Feb 2009)
New Revision: 498
Modified:
trunk/client/src/main/java/com/metamatrix/admin/api/objects/Host.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/api/Host.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/api/HostType.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicHost.java
trunk/common-internal/src/main/java/com/metamatrix/platform/service/api/ServiceState.java
trunk/console/src/main/java/com/metamatrix/console/models/SummaryManager.java
trunk/console/src/main/java/com/metamatrix/console/ui/views/deploy/util/PropertyConstants.java
trunk/console/src/main/java/com/metamatrix/console/ui/views/summary/SummaryHostInfo.java
trunk/console/src/main/java/com/metamatrix/console/ui/views/summary/SummaryPanel.java
trunk/server/src/test/java/com/metamatrix/admin/server/TestServerConfigAdminImpl.java
trunk/server/src/test/java/com/metamatrix/platform/config/spi/xml/HelperTestConfiguration.java
Log:
TEIID-283: removing port information from the Host properties.
Modified: trunk/client/src/main/java/com/metamatrix/admin/api/objects/Host.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/admin/api/objects/Host.java 2009-02-25 17:45:32 UTC (rev 497)
+++ trunk/client/src/main/java/com/metamatrix/admin/api/objects/Host.java 2009-02-25 18:12:40 UTC (rev 498)
@@ -32,15 +32,8 @@
* @since 4.3
*/
public interface Host extends AdminObject {
-
-
/**
- * Port Number Property
- */
- public static final String PORT_NUMBER = "hostControllerPortNumber"; //$NON-NLS-1$
-
- /**
* Install Directory Property
*/
public static final String INSTALL_DIR = "metamatrix.installationDir"; //$NON-NLS-1$
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/config/api/Host.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/config/api/Host.java 2009-02-25 17:45:32 UTC (rev 497)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/config/api/Host.java 2009-02-25 18:12:40 UTC (rev 498)
@@ -55,17 +55,8 @@
*/
String getTempDirectory();
-
+
/**
- * returns the host controller port number;
- * @return
- * @since 4.3
- */
- String getPort();
-
-
-
- /**
* Return the address that should be used to bind to the host
* @return
* @since 4.3
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/config/api/HostType.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/config/api/HostType.java 2009-02-25 17:45:32 UTC (rev 497)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/config/api/HostType.java 2009-02-25 18:12:40 UTC (rev 498)
@@ -30,8 +30,6 @@
public static final String COMPONENT_TYPE_NAME = "Host"; //$NON-NLS-1$
- public static final String PORT_NUMBER = com.metamatrix.admin.api.objects.Host.PORT_NUMBER;
-
public static final String INSTALL_DIR = com.metamatrix.admin.api.objects.Host.INSTALL_DIR;
public static final String LOG_DIRECTORY = com.metamatrix.admin.api.objects.Host.LOG_DIRECTORY;
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicHost.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicHost.java 2009-02-25 17:45:32 UTC (rev 497)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicHost.java 2009-02-25 18:12:40 UTC (rev 498)
@@ -70,13 +70,7 @@
return FileUtils.buildDirectoryPath(new String[] {datadir, "temp"}); //$NON-NLS-1$
}
- /**
- * @see com.metamatrix.common.config.api.Host#getPort()
- * @since 4.3
- */
- public String getPort() {
- return getProperty(HostType.PORT_NUMBER);
- }
+
/**
* Return a deep cloned instance of this object. Subclasses must override
* this method.
Modified: trunk/common-internal/src/main/java/com/metamatrix/platform/service/api/ServiceState.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/platform/service/api/ServiceState.java 2009-02-25 17:45:32 UTC (rev 497)
+++ trunk/common-internal/src/main/java/com/metamatrix/platform/service/api/ServiceState.java 2009-02-25 18:12:40 UTC (rev 498)
@@ -30,4 +30,12 @@
public static final int STATE_INIT_FAILED = 4;
public static final int STATE_NOT_REGISTERED = 5;
public static final int STATE_DATA_SOURCE_UNAVAILABLE = 6;
+
+ public final static String[] stateAsString = {"Not_Initialized", //$NON-NLS-1$
+ "Running", //$NON-NLS-1$
+ "Closed", //$NON-NLS-1$
+ "Failed", //$NON-NLS-1$
+ "Init_Failed", //$NON-NLS-1$
+ "Not_Registered", //$NON-NLS-1$
+ "Data_Source_Unavailable"}; //$NON-NLS-1$
}
Modified: trunk/console/src/main/java/com/metamatrix/console/models/SummaryManager.java
===================================================================
--- trunk/console/src/main/java/com/metamatrix/console/models/SummaryManager.java 2009-02-25 17:45:32 UTC (rev 497)
+++ trunk/console/src/main/java/com/metamatrix/console/models/SummaryManager.java 2009-02-25 18:12:40 UTC (rev 498)
@@ -120,9 +120,7 @@
it = hosts.iterator();
for (int i = 0; it.hasNext(); i++) {
Host curHost = (Host)it.next();
- info[i] = new SummaryHostInfo(curHost.getName(),
- curHost.getProperty(HostType.PORT_NUMBER),
- hostStatus(curHost.getName(), hostData));
+ info[i] = new SummaryHostInfo(curHost.getName(), hostStatus(curHost.getName(), hostData));
}
return info;
}
Modified: trunk/console/src/main/java/com/metamatrix/console/ui/views/deploy/util/PropertyConstants.java
===================================================================
--- trunk/console/src/main/java/com/metamatrix/console/ui/views/deploy/util/PropertyConstants.java 2009-02-25 17:45:32 UTC (rev 497)
+++ trunk/console/src/main/java/com/metamatrix/console/ui/views/deploy/util/PropertyConstants.java 2009-02-25 18:12:40 UTC (rev 498)
@@ -37,21 +37,7 @@
static final String ESSENTIAL_PROP =
DeployPkgUtils.getString("property.service.essential"); //$NON-NLS-1$
- //
- // Process
- //
-// static final String LOG_PROP =
-// DeployPkgUtils.getString("property.process.logfile"); //$NON-NLS-1$
-// static final String MAX_HEAP_PROP =
-// DeployPkgUtils.getString("property.process.maxheap"); //$NON-NLS-1$
-// static final String MIN_HEAP_PROP =
-// DeployPkgUtils.getString("property.process.minheap"); //$NON-NLS-1$
- //
- // Host
- //
- static final String PORT_PROP = HostType.PORT_NUMBER;
-// DeployPkgUtils.getString("property.host.portnumber"); //$NON-NLS-1$
}
Modified: trunk/console/src/main/java/com/metamatrix/console/ui/views/summary/SummaryHostInfo.java
===================================================================
--- trunk/console/src/main/java/com/metamatrix/console/ui/views/summary/SummaryHostInfo.java 2009-02-25 17:45:32 UTC (rev 497)
+++ trunk/console/src/main/java/com/metamatrix/console/ui/views/summary/SummaryHostInfo.java 2009-02-25 18:12:40 UTC (rev 498)
@@ -29,12 +29,10 @@
public static final int NOT_RUNNING = 2;
private String hostName;
- private String hostPortNum;
private int hostStatus;
- public SummaryHostInfo(String hostName, String hostPortNum, int status){
+ public SummaryHostInfo(String hostName, int status){
this.hostName = hostName;
- this.hostPortNum = hostPortNum;
this.hostStatus = status;
}
@@ -42,10 +40,6 @@
return hostName;
}
- public String getHostPortNum(){
- return hostPortNum;
- }
-
public int getHostStatus(){
return hostStatus;
}
Modified: trunk/console/src/main/java/com/metamatrix/console/ui/views/summary/SummaryPanel.java
===================================================================
--- trunk/console/src/main/java/com/metamatrix/console/ui/views/summary/SummaryPanel.java 2009-02-25 17:45:32 UTC (rev 497)
+++ trunk/console/src/main/java/com/metamatrix/console/ui/views/summary/SummaryPanel.java 2009-02-25 18:12:40 UTC (rev 498)
@@ -92,7 +92,7 @@
private JPanel stopLightPanel;
private String[] connectionsTableColumns = {"Product", "Connections"};
private TableWidget hostTable;
- private String[] hostTableColumns = {"Host Identifier", "Port Number", "Status"};
+ private String[] hostTableColumns = {"Host Identifier", "Status"};
private GridBagLayout sysStateLayout;
private AutoRefresher arRefresher;
@@ -314,17 +314,15 @@
data = new Object[1][3];
data[0][0] = "";
data[0][1] = "";
- data[0][2] = "";
} else {
data = new Object[hostInfo.length][3];
for (int i = 0; i < hostInfo.length; i++) {
data[i][0] = hostInfo[i].getHostName();
- data[i][1] = hostInfo[i].getHostPortNum();
if (hostInfo[i].getHostStatus() == SummaryHostInfo.RUNNING) {
- data[i][2] = "Running";
+ data[i][1] = "Running";
} else if (hostInfo[i].getHostStatus() ==
SummaryHostInfo.NOT_RUNNING) {
- data[i][2] = "Not Running";
+ data[i][1] = "Not Running";
}
}
}
Modified: trunk/server/src/test/java/com/metamatrix/admin/server/TestServerConfigAdminImpl.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/admin/server/TestServerConfigAdminImpl.java 2009-02-25 17:45:32 UTC (rev 497)
+++ trunk/server/src/test/java/com/metamatrix/admin/server/TestServerConfigAdminImpl.java 2009-02-25 18:12:40 UTC (rev 498)
@@ -151,7 +151,6 @@
public void testAddHost() throws Exception {
String hostIdentifier = BOGUS_HOST;
Properties hostProperties = new Properties();
- hostProperties.setProperty(Host.PORT_NUMBER, String.valueOf(15001));
hostProperties.setProperty(Host.INSTALL_DIR, "D:\\MetaMatrix\\s43401\\"); //$NON-NLS-1$
hostProperties.setProperty(Host.DATA_DIRECTORY, "D:\\MetaMatrix\\s43401\\data"); //$NON-NLS-1$
hostProperties.setProperty(Host.LOG_DIRECTORY, "D:\\MetaMatrix\\s43401\\log"); //$NON-NLS-1$
@@ -162,7 +161,6 @@
public void testAddHostIP() throws Exception {
String hostIdentifier = BOGUS_HOST_IP;
Properties hostProperties = new Properties();
- hostProperties.setProperty(Host.PORT_NUMBER, String.valueOf(15001));
hostProperties.setProperty(Host.INSTALL_DIR, "D:\\MetaMatrix\\s43401\\"); //$NON-NLS-1$
hostProperties.setProperty(Host.DATA_DIRECTORY, "D:\\MetaMatrix\\s43401\\data"); //$NON-NLS-1$
hostProperties.setProperty(Host.LOG_DIRECTORY, "D:\\MetaMatrix\\s43401\\log"); //$NON-NLS-1$
@@ -173,7 +171,6 @@
public void testAddHostFullyQualifiedName() throws Exception {
String hostIdentifier = BOGUS_HOST_FULLY_QUALIFIED;
Properties hostProperties = new Properties();
- hostProperties.setProperty(Host.PORT_NUMBER, String.valueOf(15001));
hostProperties.setProperty(Host.INSTALL_DIR, "D:\\MetaMatrix\\s43401\\"); //$NON-NLS-1$
hostProperties.setProperty(Host.DATA_DIRECTORY, "D:\\MetaMatrix\\s43401\\data"); //$NON-NLS-1$
hostProperties.setProperty(Host.LOG_DIRECTORY, "D:\\MetaMatrix\\s43401\\log"); //$NON-NLS-1$
Modified: trunk/server/src/test/java/com/metamatrix/platform/config/spi/xml/HelperTestConfiguration.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/platform/config/spi/xml/HelperTestConfiguration.java 2009-02-25 17:45:32 UTC (rev 497)
+++ trunk/server/src/test/java/com/metamatrix/platform/config/spi/xml/HelperTestConfiguration.java 2009-02-25 18:12:40 UTC (rev 498)
@@ -113,10 +113,6 @@
validateComponentObject(h);
ArgCheck.isNotNull(h.getProperties(), "Host does not have any properties"); //$NON-NLS-1$
- String hostPortNumber = h.getProperty(HostType.PORT_NUMBER);
- ArgCheck.isNotNull(hostPortNumber, "Host " + h.getFullName() + " does not have a host port number"); //$NON-NLS-1$ //$NON-NLS-2$
-
-
}
public static void validateAuthenticationProviders(Collection providers) throws ConfigurationException {
15 years, 10 months
teiid SVN: r497 - trunk/server/src/main/java/com/metamatrix/server.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2009-02-25 12:45:32 -0500 (Wed, 25 Feb 2009)
New Revision: 497
Modified:
trunk/server/src/main/java/com/metamatrix/server/HostControllerGuiceModule.java
trunk/server/src/main/java/com/metamatrix/server/ServiceManagerGuiceModule.java
Log:
TEIID-383
Modified: trunk/server/src/main/java/com/metamatrix/server/HostControllerGuiceModule.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/HostControllerGuiceModule.java 2009-02-25 15:28:27 UTC (rev 496)
+++ trunk/server/src/main/java/com/metamatrix/server/HostControllerGuiceModule.java 2009-02-25 17:45:32 UTC (rev 497)
@@ -53,6 +53,21 @@
@Override
protected void configure() {
+ commonComponents();
+
+ bind(LogConfiguration.class).toProvider(LogConfigurationProvider.class).in(Scopes.SINGLETON);
+
+ bind(LogListener.class).toProvider(FileLogListenerProvider.class).in(Scopes.SINGLETON);
+
+ // this needs to be removed.
+ binder().requestStaticInjection(LogManager.class);
+ }
+
+ /**
+ * These resources are common between hostcontroller and svcmgr.
+ */
+ protected void commonComponents() {
+
String systemName = null;
try {
systemName = CurrentConfiguration.getInstance().getClusterName();
@@ -66,7 +81,6 @@
bindConstant().annotatedWith(Names.named(Configuration.CLUSTERNAME)).to(systemName);
bindConstant().annotatedWith(Names.named(Configuration.LOGFILE)).to(StringUtil.replaceAll(host.getFullName(), ".", "_")+"_hc.log"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
bindConstant().annotatedWith(Names.named(Configuration.LOGDIR)).to(host.getLogDirectory());
-
Names.bindProperties(binder(), CurrentConfiguration.getInstance().getProperties());
@@ -76,14 +90,7 @@
bind(CacheFactory.class).to(JBossCacheFactory.class).in(Scopes.SINGLETON);
bind(ClusteredRegistryState.class).in(Scopes.SINGLETON);
bind(MessageBus.class).to(VMMessageBus.class).in(Scopes.SINGLETON); // VM Message bus is in common-internal
- bind(HostMonitor.class).in(Scopes.SINGLETON);
-
- bind(LogConfiguration.class).toProvider(LogConfigurationProvider.class).in(Scopes.SINGLETON);
-
- bind(LogListener.class).toProvider(FileLogListenerProvider.class).in(Scopes.SINGLETON);
-
- // this needs to be removed.
- binder().requestStaticInjection(LogManager.class);
+ bind(HostMonitor.class).in(Scopes.SINGLETON);
}
}
Modified: trunk/server/src/main/java/com/metamatrix/server/ServiceManagerGuiceModule.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/ServiceManagerGuiceModule.java 2009-02-25 15:28:27 UTC (rev 496)
+++ trunk/server/src/main/java/com/metamatrix/server/ServiceManagerGuiceModule.java 2009-02-25 17:45:32 UTC (rev 497)
@@ -34,7 +34,13 @@
@Override
protected void configure() {
- super.configure();
+
+ super.commonComponents();
+
bind(HostManagement.class).toProvider(HostManagementProvider.class).in(Scopes.SINGLETON);
+
+ // no logging is required for svcmgr, as it writes using the system.out any log
+ // messages will be sent to null logger. One thing we do not want to do is capture
+ // the system streams for svcmgr.
}
}
15 years, 10 months
teiid SVN: r496 - in trunk: common-internal/src/main/java/com/metamatrix/common/config and 7 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2009-02-25 10:28:27 -0500 (Wed, 25 Feb 2009)
New Revision: 496
Modified:
trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnection.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/CurrentConfiguration.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/api/VMComponentDefnType.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicHost.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/xml/XMLConfig_42_HelperImpl.java
trunk/server/src/main/java/com/metamatrix/admin/server/ServerMonitoringAdminImpl.java
trunk/server/src/main/java/com/metamatrix/server/HostController.java
trunk/server/src/main/java/com/metamatrix/server/Main.java
trunk/server/src/main/resources/com/metamatrix/platform/i18n.properties
trunk/server/src/test/java/com/metamatrix/platform/config/spi/xml/TestCurrentConfiguration.java
Log:
TEIID-309: The host specific properties are moved to bootstrap properties, since host properties are specific to a given host not to the entire system. This way they can be configured correctly during the setupmm.
Modified: trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnection.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnection.java 2009-02-25 03:49:52 UTC (rev 495)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnection.java 2009-02-25 15:28:27 UTC (rev 496)
@@ -117,7 +117,7 @@
List<HostInfo> hostKeys = new ArrayList<HostInfo>(this.serverDiscovery.getKnownHosts());
List<HostInfo> hostCopy = new ArrayList<HostInfo>(hostKeys);
int knownHosts = hostKeys.size();
- for (int i = 0; i < hostKeys.size(); i++) {
+ while (hostKeys.size() > 0) {
HostInfo hostInfo = hostKeys.remove((int) (Math.random() * hostKeys.size()));
SocketServerInstance instance = existingConnections.get(hostInfo);
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/config/CurrentConfiguration.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/config/CurrentConfiguration.java 2009-02-25 03:49:52 UTC (rev 495)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/config/CurrentConfiguration.java 2009-02-25 15:28:27 UTC (rev 496)
@@ -28,12 +28,16 @@
import java.util.Properties;
import com.metamatrix.common.CommonPlugin;
+import com.metamatrix.common.config.api.ComponentTypeID;
import com.metamatrix.common.config.api.Configuration;
+import com.metamatrix.common.config.api.ConfigurationID;
import com.metamatrix.common.config.api.ConfigurationModelContainer;
import com.metamatrix.common.config.api.Host;
+import com.metamatrix.common.config.api.HostID;
import com.metamatrix.common.config.api.ResourceModel;
import com.metamatrix.common.config.api.SharedResource;
import com.metamatrix.common.config.api.exceptions.ConfigurationException;
+import com.metamatrix.common.config.model.BasicHost;
import com.metamatrix.common.config.reader.CurrentConfigurationReader;
import com.metamatrix.common.config.reader.PropertiesConfigurationReader;
import com.metamatrix.common.properties.UnmodifiableProperties;
@@ -69,7 +73,7 @@
public static final String BOOTSTRAP_FILE_NAME = "metamatrix.properties"; //$NON-NLS-1$
public static final String CONFIGURATION_READER_CLASS_PROPERTY_NAME = "metamatrix.config.reader"; //$NON-NLS-1$
public static final String CLUSTER_NAME = "metamatrix.cluster.name"; //$NON-NLS-1$
- private static final String CONFIGURATION_NAME= "configuration.name"; //$NON-NLS-1$
+ public static final String CONFIGURATION_NAME= "configuration.name"; //$NON-NLS-1$
private CurrentConfigurationReader reader;
private Properties bootstrapProperties;
@@ -212,12 +216,11 @@
*/
public Host getDefaultHost() throws ConfigurationException {
String name = getBootStrapProperties().getProperty(CONFIGURATION_NAME);
- return getReader().getConfigurationModel().getHost(name);
+ BasicHost host = new BasicHost(new ConfigurationID(name), new HostID(name), new ComponentTypeID(name));
+ host.setProperties(getBootStrapProperties());
+ return host;
}
- public Host getHost(String name) throws ConfigurationException {
- return getReader().getConfigurationModel().getHost(name);
- }
/**
* Reset causes not just a refresh, but the bootstrapping process
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/config/api/VMComponentDefnType.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/config/api/VMComponentDefnType.java 2009-02-25 03:49:52 UTC (rev 495)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/config/api/VMComponentDefnType.java 2009-02-25 15:28:27 UTC (rev 496)
@@ -62,10 +62,4 @@
*/
public static final String JAVA_OPTS = "vm.starter.cmd.java_opts"; //$NON-NLS-1$
- public static final String JAVA_MAIN = "vm.starter.cmd.java_main"; //$NON-NLS-1$
- public static final String JAVA_ARGS = "vm.starter.cmd.java_args"; //$NON-NLS-1$
-
-
-
-
}
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicHost.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicHost.java 2009-02-25 03:49:52 UTC (rev 495)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicHost.java 2009-02-25 15:28:27 UTC (rev 496)
@@ -23,7 +23,9 @@
package com.metamatrix.common.config.model;
+import java.io.File;
import java.io.Serializable;
+import java.util.Properties;
import com.metamatrix.common.config.api.ComponentTypeID;
import com.metamatrix.common.config.api.ConfigurationID;
@@ -49,7 +51,7 @@
* @since 4.3
*/
public String getDataDirectory() {
- return getProperty(HostType.DATA_DIRECTORY);
+ return getProperty(HostType.HOST_DIRECTORY)+File.separator+ "data"; //$NON-NLS-1$
}
/**
* @see com.metamatrix.common.config.api.Host#getLogDirectory()
@@ -103,4 +105,8 @@
public String getHostAddress() {
return getProperty(HostType.HOST_PHYSICAL_ADDRESS);
}
+
+ public void setProperties(Properties props) {
+ super.setProperties(props);
+ }
}
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/config/xml/XMLConfig_42_HelperImpl.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/config/xml/XMLConfig_42_HelperImpl.java 2009-02-25 03:49:52 UTC (rev 495)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/config/xml/XMLConfig_42_HelperImpl.java 2009-02-25 15:28:27 UTC (rev 496)
@@ -2377,23 +2377,22 @@
public ComponentObject addProperties(Element propertiesElement, ComponentObject object, ConfigurationObjectEditor editor) throws InvalidConfigurationElementException{
if (!propertiesElement.getName().equals(XMLConfig_42_ElementNames.Properties.ELEMENT)) {
-
propertiesElement = propertiesElement.getChild(XMLConfig_42_ElementNames.Properties.ELEMENT);
+ }
- if (propertiesElement == null) {
- throw new InvalidConfigurationElementException("A Properties object cannot be created from a null properties element", null); //$NON-NLS-1$
-
- }
+ Properties props = null;
+ if (propertiesElement == null) {
+ props = new Properties();
}
+ else {
+ props = getProperties(propertiesElement);
+ }
- Properties props = getProperties(propertiesElement);
-
object = editor.modifyProperties(object, props, ConfigurationObjectEditor.ADD);
return object;
}
-
private Properties getProperties(Element propertiesElement) {
Properties props = new Properties();
Modified: trunk/server/src/main/java/com/metamatrix/admin/server/ServerMonitoringAdminImpl.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/admin/server/ServerMonitoringAdminImpl.java 2009-02-25 03:49:52 UTC (rev 495)
+++ trunk/server/src/main/java/com/metamatrix/admin/server/ServerMonitoringAdminImpl.java 2009-02-25 15:28:27 UTC (rev 496)
@@ -628,6 +628,7 @@
process.setQueueWorkerPool(workerPool);
}
}
+ process.setInetAddress(getRuntimeStateAdminAPIHelper().getVMHostName(processID));
} catch (MetaMatrixComponentException e) {
//do nothing: sometimes when the process is just starting the RMI stub
//for SocketVMController is not initialized yet
@@ -635,7 +636,6 @@
}
process.setDeployed(false);
- process.setInetAddress(getRuntimeStateAdminAPIHelper().getVMHostName(processID));
String key = MMAdminObject.buildIdentifier(identifierParts).toUpperCase();
runtimeMap.put(key, process);
results.add(process);
Modified: trunk/server/src/main/java/com/metamatrix/server/HostController.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/HostController.java 2009-02-25 03:49:52 UTC (rev 495)
+++ trunk/server/src/main/java/com/metamatrix/server/HostController.java 2009-02-25 15:28:27 UTC (rev 496)
@@ -23,7 +23,6 @@
package com.metamatrix.server;
import java.io.File;
-import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
@@ -39,7 +38,6 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.common.config.CurrentConfiguration;
import com.metamatrix.common.config.StartupStateController;
-import com.metamatrix.common.config.StartupStateException;
import com.metamatrix.common.config.api.ConfigurationModelContainer;
import com.metamatrix.common.config.api.Host;
import com.metamatrix.common.config.api.VMComponentDefn;
@@ -82,7 +80,7 @@
this.messageBus = bus;
}
- public void run(boolean startProcesses) throws ConfigurationException, IOException, StartupStateException {
+ public void run(boolean startProcesses) throws Throwable {
if (isHostRunning()) {
System.err.println(PlatformPlugin.Util.getString("HostController.Host_is_already_running_startprocesses", host.getFullName())); //$NON-NLS-1$
@@ -101,8 +99,9 @@
if (startProcesses ) {
try {
startServers(host.getFullName());
- } catch (MetaMatrixComponentException e) {
+ } catch (Throwable e) {
LogManager.logError(LogCommonConstants.CTX_CONTROLLER, e, e.getMessage());
+ shutdown(this.host.getFullName());
}
}
}
@@ -146,7 +145,7 @@
return null;
}
- private void createTempDirectories() throws ConfigurationException, IOException {
+ private void createTempDirectories() {
// If the java-i-tmp directory doesn't exist, it needs to be created
// because extension jars class loading will fail because
// java internals can' write to a non-existent directory.
@@ -280,6 +279,7 @@
} catch (Throwable e) {
LogManager.logError(LogCommonConstants.CTX_CONTROLLER, e, "ERROR " + PlatformPlugin.Util.getString(ErrorMessageKeys.HOST_0011));//$NON-NLS-1$
+ e.printStackTrace();
System.exit(1);
}
}
@@ -291,12 +291,12 @@
}
private Process startDeployVM( String vmName, String hostName, Properties vmprops) {
- LogManager.logInfo(LogCommonConstants.CTX_CONTROLLER, "Start deploy VM " + vmName + " on host"+ hostName); //$NON-NLS-1$ //$NON-NLS-2$
- String command = buildVMCommand(vmprops);
+ LogManager.logInfo(LogCommonConstants.CTX_CONTROLLER, "Start deploy VM = " + vmName + " on host = "+ hostName); //$NON-NLS-1$ //$NON-NLS-2$
+ String command = buildVMCommand(vmName, vmprops);
return execCommand(command);
}
- private String buildVMCommand(Properties vmprops) {
+ private String buildVMCommand(String vmName, Properties vmprops) {
String java = null;
String java_home = System.getProperty("java.home"); //$NON-NLS-1$
if (java_home != null) {
@@ -306,15 +306,11 @@
}
String java_opts = vmprops.getProperty(VMComponentDefnType.JAVA_OPTS, ""); //$NON-NLS-1$
java_opts = java_opts + " -Dcom.sun.management.jmxremote " + System.getProperty(VMComponentDefnType.JAVA_OPTS, ""); //$NON-NLS-1$ //$NON-NLS-2$
- String java_main = vmprops.getProperty(VMComponentDefnType.JAVA_MAIN, DEFAULT_JAVA_MAIN);
- String java_args = vmprops.getProperty(VMComponentDefnType.JAVA_ARGS, ""); //$NON-NLS-1$
java = replaceToken(java, vmprops);
java_opts = replaceToken(java_opts, vmprops);
- java_main = replaceToken(java_main, vmprops);
- java_args = replaceToken(java_args, vmprops);
- String cmd = java + " " +java_opts+ " " +java_main + " " +java_args; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ String cmd = java + " " +java_opts+ " " + DEFAULT_JAVA_MAIN + " " + vmName; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return cmd;
}
@@ -332,7 +328,7 @@
if (endidx < startidx) return rtn;
String tokenprop = rtn.substring(startidx + 2, endidx);
- String tokenvalue = props.getProperty(tokenprop);
+ String tokenvalue = props.getProperty(tokenprop).trim();
StringBuffer buf = new StringBuffer(rtn);
rtn = buf.replace(startidx, endidx + 1, tokenvalue).toString();
}
Modified: trunk/server/src/main/java/com/metamatrix/server/Main.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/Main.java 2009-02-25 03:49:52 UTC (rev 495)
+++ trunk/server/src/main/java/com/metamatrix/server/Main.java 2009-02-25 15:28:27 UTC (rev 496)
@@ -58,26 +58,25 @@
public static void main(String[] args) {
try {
- if (args.length < 2 || args.length > 4) {
- System.out.println("Usage: java com.metamatrix.server.Main <vm_name> <host_name>"); //$NON-NLS-1$
+ if (args.length != 1) {
+ System.out.println("Usage: java com.metamatrix.server.Main <vm_name>"); //$NON-NLS-1$
System.exit(1);
}
String vmName = args[0];
- String hostName = args[1];
Host host = null;
try {
- host = CurrentConfiguration.getInstance().getHost(hostName);
+ host = CurrentConfiguration.getInstance().getDefaultHost();
} catch (ConfigurationException e) {
}
if (host == null) {
- System.err.println(PlatformPlugin.Util.getString("SocketVMController.5", hostName)); //$NON-NLS-1$
+ System.err.println(PlatformPlugin.Util.getString("SocketVMController.5")); //$NON-NLS-1$
System.exit(-1);
}
- VMComponentDefn deployedVM = CurrentConfiguration.getInstance().getConfiguration().getVMForHost(hostName, vmName);
+ VMComponentDefn deployedVM = CurrentConfiguration.getInstance().getConfiguration().getVMForHost(host.getName(), vmName);
String bindAddress = deployedVM.getBindAddress();
VMNaming.setVMName(vmName);
Modified: trunk/server/src/main/resources/com/metamatrix/platform/i18n.properties
===================================================================
--- trunk/server/src/main/resources/com/metamatrix/platform/i18n.properties 2009-02-25 03:49:52 UTC (rev 495)
+++ trunk/server/src/main/resources/com/metamatrix/platform/i18n.properties 2009-02-25 15:28:27 UTC (rev 496)
@@ -1281,7 +1281,7 @@
SocketVMController.2=Problem starting server binding to address {0} and listening on port {1}
SocketVMController.3=Setting Server Listener listenerFilter={0}
SocketVMController.4=Getting ServerListener Registry: {0}
-SocketVMController.5=Could not find host <{0}> in configuration.
+SocketVMController.5=Could not find host information. Run the "setupmm" to configure the server before trying to start.
RemoteProxy.localCallFailed=Remote client could not invoke local service method {0} on {1}
JGroupsMessageBus.noResponse=No response for remote method call
\ No newline at end of file
Modified: trunk/server/src/test/java/com/metamatrix/platform/config/spi/xml/TestCurrentConfiguration.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/platform/config/spi/xml/TestCurrentConfiguration.java 2009-02-25 03:49:52 UTC (rev 495)
+++ trunk/server/src/test/java/com/metamatrix/platform/config/spi/xml/TestCurrentConfiguration.java 2009-02-25 15:28:27 UTC (rev 496)
@@ -135,30 +135,7 @@
printMsg("Completed testCurrentHost"); //$NON-NLS-1$
}
- public void testFindHostByFullyQualifiedName() {
-
- printMsg("Starting testFindHostByFullyQualifiedName"); //$NON-NLS-1$
-
- try {
- init(CONFIG_FILE);
-
- CurrentConfiguration.getInstance().performSystemInitialization(true);
-
- Host host = CurrentConfiguration.getInstance().getHost("slwxp141.quadrian.com"); //$NON-NLS-1$
-
- if (host == null) {
- fail(" host was not found in configuration");//$NON-NLS-1$
- }
-
-
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- printMsg("Completed testFindHostByFullyQualifiedName"); //$NON-NLS-1$
- }
-
+
public void test30SystemInitialization() {
printMsg("**** Starting test30SystemInitialization"); //$NON-NLS-1$
15 years, 10 months
teiid SVN: r494 - in trunk: connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc and 15 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-02-24 22:49:48 -0500 (Tue, 24 Feb 2009)
New Revision: 494
Added:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCConnector.java
Modified:
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/util/SQLStringVisitor.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ConcatFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/ModFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/BasicFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/EscapeSyntaxModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2SqlTranslator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyConvertModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestEscapeSyntaxModifier.java
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/NnDistanceFunctionModifier.java
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialFunctionModifier.java
trunk/server/src/main/java/com/metamatrix/metadata/runtime/spi/jdbc/JDBCConnector.java
trunk/test-integration/src/test/java/com/metamatrix/cdk/api/TestTranslationUtility.java
trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java
trunk/test-integration/src/test/java/com/metamatrix/data/visitor/util/TestSQLStringVisitor.java
Log:
TEIID-164 fixes from rewiring integration tests
Modified: trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/util/SQLStringVisitor.java
===================================================================
--- trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/util/SQLStringVisitor.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/util/SQLStringVisitor.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -437,12 +437,9 @@
buffer.append(((ILiteral)args.get(0)).getValue());
for(int i=1; i<args.size(); i++) {
- append(args.get(i));
- if(i < (args.size()-1)) {
- buffer.append(SPACE);
- buffer.append(name);
- buffer.append(SPACE);
- }
+ buffer.append(COMMA);
+ buffer.append(SPACE);
+ append(args.get(i));
}
}
buffer.append(RPAREN);
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -102,7 +102,7 @@
logger.logInfo(JDBCPlugin.Util.getString("JDBCConnector.JDBCConnector_initialized._1")); //$NON-NLS-1$
- capabilities = createCapabilities(environment, Thread.currentThread().getContextClassLoader());
+ capabilities = createCapabilities(environment.getProperties(), Thread.currentThread().getContextClassLoader());
Properties connectionProps = environment.getProperties();
@@ -129,6 +129,8 @@
}
sqlTranslator.initialize(environment);
+ createDataSources(dataSourceClassName, connectionProps);
+
if (areAdminConnectionsAllowed()) {
testConnection();
}
@@ -232,14 +234,14 @@
return capabilities;
}
- static ConnectorCapabilities createCapabilities(ConnectorEnvironment environment, ClassLoader loader)
+ static ConnectorCapabilities createCapabilities(Properties p, ClassLoader loader)
throws ConnectorException {
//create Capabilities
- String className = environment.getProperties().getProperty(JDBCPropertyNames.EXT_CAPABILITY_CLASS, JDBCCapabilities.class.getName());
+ String className = p.getProperty(JDBCPropertyNames.EXT_CAPABILITY_CLASS, JDBCCapabilities.class.getName());
try {
ConnectorCapabilities result = (ConnectorCapabilities)ReflectionHelper.create(className, null, loader);
if(result instanceof JDBCCapabilities) {
- String setCriteriaBatchSize = environment.getProperties().getProperty(JDBCPropertyNames.SET_CRITERIA_BATCH_SIZE);
+ String setCriteriaBatchSize = p.getProperty(JDBCPropertyNames.SET_CRITERIA_BATCH_SIZE);
if(setCriteriaBatchSize != null) {
int maxInCriteriaSize = Integer.parseInt(setCriteriaBatchSize);
if(maxInCriteriaSize > 0) {
@@ -277,13 +279,21 @@
Object[] args) throws Throwable {
if (method.getName().equals("getConnection")) {
Properties p = new Properties();
- if (args.length == 2) {
- p.put("user", args[0]);
- p.put("password", args[1]);
+ String user = null;
+ String password = null;
+ if (args != null && args.length == 2) {
+ user = (String)args[0];
+ password = (String)args[1];
} else {
- p.put("user", connectionProps.getProperty(JDBCPropertyNames.USERNAME));
- p.put("password", connectionProps.getProperty(JDBCPropertyNames.PASSWORD));
+ user = connectionProps.getProperty(JDBCPropertyNames.USERNAME);
+ password = connectionProps.getProperty(JDBCPropertyNames.PASSWORD);
}
+ if (user != null) {
+ p.put("user", user);
+ }
+ if (password != null) {
+ p.put("password", password);
+ }
return driver.connect(url, p);
}
throw new UnsupportedOperationException("Driver DataSource proxy only provides Connections");
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyConvertModifier.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyConvertModifier.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -46,25 +46,6 @@
this.langFactory = langFactory;
}
- /**
- * @see org.teiid.connector.jdbc.translator.BasicFunctionModifier#translate(com.metamatrix.connector.language.IFunction)
- * @since 5.0
- */
- public List translate(IFunction function) {
- // For anything that doesn't get modified to some other function, translate the convert(expr, type)
- // to cast(expr as type).
-
- List parts = new ArrayList();
- parts.add("cast("); //$NON-NLS-1$
- parts.add(function.getParameters().get(0));
- parts.add(" as "); //$NON-NLS-1$
- ILiteral type = (ILiteral) function.getParameters().get(1);
- parts.add(type.getValue());
- parts.add(")"); //$NON-NLS-1$
-
- return parts;
- }
-
public IExpression modify(IFunction function) {
List<IExpression> args = function.getParameters();
Class sourceType = args.get(0).getType();
@@ -252,11 +233,11 @@
// BEFORE: convert(string_expr, float)
// AFTER: cast(cast(string_expr as decimal) as float)
- IFunction inner = langFactory.createFunction("convert", //$NON-NLS-1$
+ IFunction inner = langFactory.createFunction("cast", //$NON-NLS-1$
Arrays.asList( expression, langFactory.createLiteral("decimal", TypeFacility.RUNTIME_TYPES.STRING) ), //$NON-NLS-1$
TypeFacility.RUNTIME_TYPES.BIG_DECIMAL);
- IFunction outer = langFactory.createFunction("convert", //$NON-NLS-1$
+ IFunction outer = langFactory.createFunction("cast", //$NON-NLS-1$
Arrays.asList( inner, langFactory.createLiteral("float", TypeFacility.RUNTIME_TYPES.STRING) ), //$NON-NLS-1$
TypeFacility.RUNTIME_TYPES.FLOAT);
@@ -267,7 +248,7 @@
// BEFORE: convert(num_expr, float)
// AFTER: cast(num_expr as float)
- return langFactory.createFunction("convert", //$NON-NLS-1$
+ return langFactory.createFunction("cast", //$NON-NLS-1$
Arrays.asList( expression, langFactory.createLiteral("float", TypeFacility.RUNTIME_TYPES.STRING) ), //$NON-NLS-1$
TypeFacility.RUNTIME_TYPES.FLOAT);
}
@@ -281,11 +262,11 @@
if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)){
// BEFORE: convert(string_expr, double)
// AFTER: cast(cast(string_expr as decimal) as double)
- IFunction inner = langFactory.createFunction("convert", //$NON-NLS-1$
+ IFunction inner = langFactory.createFunction("cast", //$NON-NLS-1$
Arrays.asList( expression, langFactory.createLiteral("decimal", TypeFacility.RUNTIME_TYPES.STRING) ), //$NON-NLS-1$
TypeFacility.RUNTIME_TYPES.BIG_DECIMAL);
- return langFactory.createFunction("convert", //$NON-NLS-1$
+ return langFactory.createFunction("cast", //$NON-NLS-1$
Arrays.asList( inner, langFactory.createLiteral("double", TypeFacility.RUNTIME_TYPES.STRING) ), //$NON-NLS-1$
TypeFacility.RUNTIME_TYPES.DOUBLE);
}
@@ -299,7 +280,7 @@
if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)){
// BEFORE: convert(string_expr, bigdecimal)
// AFTER: cast(string_expr as decimal)
- return langFactory.createFunction("convert", //$NON-NLS-1$
+ return langFactory.createFunction("cast", //$NON-NLS-1$
Arrays.asList( expression, langFactory.createLiteral("decimal", TypeFacility.RUNTIME_TYPES.STRING) ), //$NON-NLS-1$
TypeFacility.RUNTIME_TYPES.BIG_DECIMAL);
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLConvertModifier.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLConvertModifier.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -29,7 +29,6 @@
import org.teiid.connector.jdbc.translator.DropFunctionModifier;
import com.metamatrix.connector.language.ICompareCriteria;
-import com.metamatrix.connector.language.ICriteria;
import com.metamatrix.connector.language.IExpression;
import com.metamatrix.connector.language.IFunction;
import com.metamatrix.connector.language.ILanguageFactory;
@@ -50,10 +49,6 @@
this.langFactory = langFactory;
}
- public List translate(IFunction function) {
- return null;
- }
-
public IExpression modify(IFunction function) {
List<IExpression> args = function.getParameters();
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ConcatFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ConcatFunctionModifier.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ConcatFunctionModifier.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -58,7 +58,7 @@
/**
* @see org.teiid.connector.jdbc.translator.BasicFunctionModifier#modify(com.metamatrix.connector.language.IFunction)
*/
- public IExpression modify(IFunction function) {
+ public IExpression modify(IFunction function) {
List when = new ArrayList();
IExpression a = function.getParameters().get(0);
IExpression b = function.getParameters().get(1);
@@ -98,7 +98,7 @@
if (expr instanceof IFunction) {
IFunction function = (IFunction)expr;
if (function.getName().equalsIgnoreCase("NVL") || function.getName().equalsIgnoreCase(SourceSystemFunctions.IFNULL)) { //$NON-NLS-1$
- return isNotNull(function.getParameters().get(0));
+ return isNotNull(function.getParameters().get(1));
}
}
return false;
@@ -112,10 +112,4 @@
return false;
}
- /**
- * @see org.teiid.connector.jdbc.translator.BasicFunctionModifier#translate(com.metamatrix.connector.language.IFunction)
- */
- public List translate(IFunction function) {
- return null; //allow default translation
- }
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleConvertModifier.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleConvertModifier.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -45,15 +45,6 @@
this.langFactory = langFactory;
}
- /**
- * Intentionally return null, rely on the SQLStringVisitor being used by caller
- * (Oracle or Oracle8 SQLConversionVisitor (SQLConversionVisitor))
- * @see org.teiid.connector.jdbc.translator.FunctionModifier#translate(com.metamatrix.connector.language.IFunction)
- */
- public List translate(IFunction function) {
- return null;
- }
-
public IExpression modify(IFunction function) {
List<IExpression> args = function.getParameters();
IExpression modified = null;
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -156,7 +156,7 @@
limitQuery.append(queryCommand);
if (limit.getRowOffset() > 0) {
limitQuery.append(") VIEW_FOR_LIMIT WHERE ROWNUM <= ").append(
- limit.getRowLimit()).append(") WHERE ROWNUM_ > ").append(
+ limit.getRowLimit() + limit.getRowOffset()).append(") WHERE ROWNUM_ > ").append(
limit.getRowOffset());
} else {
limitQuery.append(") WHERE ROWNUM <= ").append(
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLConvertModifier.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLConvertModifier.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -47,10 +47,6 @@
this.langFactory = langFactory;
}
- public List translate(IFunction function) {
- return null;
- }
-
public IExpression modify(IFunction function) {
List<IExpression> args = function.getParameters();
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/ModFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/ModFunctionModifier.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/ModFunctionModifier.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -61,9 +61,4 @@
return langFactory.createFunction("-", minusArgs, minusArgs.get(0).getType()); //$NON-NLS-1$
}
- @Override
- public List translate(IFunction function) {
- return null;
- }
-
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/BasicFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/BasicFunctionModifier.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/BasicFunctionModifier.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -24,10 +24,9 @@
*/
package org.teiid.connector.jdbc.translator;
-import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.HashMap;
import com.metamatrix.connector.api.TypeFacility;
import com.metamatrix.connector.language.IExpression;
@@ -95,22 +94,7 @@
* @see org.teiid.connector.jdbc.translator.FunctionModifier#translate(com.metamatrix.connector.language.IFunction)
*/
public List translate(IFunction function) {
- List objs = new ArrayList();
- objs.add(function.getName());
- objs.add("("); //$NON-NLS-1$
- List<IExpression> params = function.getParameters();
- if(params.size() > 0) {
- objs.add(params.get(0));
- if(params.size() > 1) {
- for(int i=1; i<params.size(); i++) {
- objs.add(", "); //$NON-NLS-1$
- objs.add(params.get(i));
- }
- }
- }
- objs.add(")"); //$NON-NLS-1$
-
- return objs;
+ return null;
}
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/EscapeSyntaxModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/EscapeSyntaxModifier.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/EscapeSyntaxModifier.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -43,12 +43,11 @@
* @since 5.0
*/
public List translate(IFunction function) {
- List normalParts = super.translate(function);
- List wrappedParts = new ArrayList(normalParts.size() + 2);
- wrappedParts.add("{fn "); //$NON-NLS-1$
- wrappedParts.addAll(normalParts);
- wrappedParts.add("}"); //$NON-NLS-1$
- return wrappedParts;
+ List objs = new ArrayList();
+ objs.add("{fn "); //$NON-NLS-1$
+ objs.add(function);
+ objs.add("}"); //$NON-NLS-1$
+ return objs;
}
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -635,25 +635,13 @@
return new Float(value);
}
case TIME_CODE: {
- try {
- return results.getTime(parameterIndex, getDatabaseCalendar());
- } catch (SQLException e) {
- //ignore
- }
+ return results.getTime(parameterIndex, getDatabaseCalendar());
}
case DATE_CODE: {
- try {
- return results.getDate(parameterIndex, getDatabaseCalendar());
- } catch (SQLException e) {
- //ignore
- }
+ return results.getDate(parameterIndex, getDatabaseCalendar());
}
case TIMESTAMP_CODE: {
- try {
- return results.getTimestamp(parameterIndex, getDatabaseCalendar());
- } catch (SQLException e) {
- //ignore
- }
+ return results.getTimestamp(parameterIndex, getDatabaseCalendar());
}
case BLOB_CODE: {
try {
Added: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCConnector.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCConnector.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCConnector.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc;
+
+import java.util.Properties;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.metamatrix.connector.api.ConnectorCapabilities;
+
+public class TestJDBCConnector {
+
+ public void helpTestMaxIn(int setting, int expected) throws Exception {
+ Properties connProps = new Properties();
+ connProps.setProperty(JDBCPropertyNames.SET_CRITERIA_BATCH_SIZE, String.valueOf(setting));
+ connProps.setProperty(JDBCPropertyNames.EXT_CAPABILITY_CLASS, SimpleCapabilities.class.getName());
+ ConnectorCapabilities caps = JDBCConnector.createCapabilities(connProps, this.getClass().getClassLoader());
+ int maxIn = caps.getMaxInCriteriaSize();
+ Assert.assertEquals(expected, maxIn);
+ }
+
+ @Test
+ public void test1() throws Exception {
+ helpTestMaxIn(-1, 250);
+ }
+
+ @Test
+ public void test2() throws Exception {
+ helpTestMaxIn(0, 250);
+ }
+
+ @Test
+ public void test3() throws Exception {
+ helpTestMaxIn(1, 1);
+ }
+}
Property changes on: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCConnector.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2SqlTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2SqlTranslator.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2SqlTranslator.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -22,14 +22,14 @@
package org.teiid.connector.jdbc.db2;
-import java.util.Map;
+import static org.junit.Assert.assertEquals;
+
import java.util.Properties;
-import org.teiid.connector.jdbc.db2.DB2SQLTranslator;
+import org.junit.BeforeClass;
+import org.junit.Test;
import org.teiid.connector.jdbc.translator.TranslatedCommand;
-import junit.framework.TestCase;
-
import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.cdk.api.TranslationUtility;
import com.metamatrix.cdk.unittest.FakeTranslationFactory;
@@ -40,34 +40,21 @@
/**
*/
-public class TestDB2SqlTranslator extends TestCase {
+public class TestDB2SqlTranslator {
- private static Map MODIFIERS;
private static DB2SQLTranslator TRANSLATOR;
- static {
- try {
- TRANSLATOR = new DB2SQLTranslator();
- TRANSLATOR.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
- MODIFIERS = TRANSLATOR.getFunctionModifiers();
- } catch(ConnectorException e) {
- e.printStackTrace();
- }
+ @BeforeClass
+ public static void setUp() throws ConnectorException {
+ TRANSLATOR = new DB2SQLTranslator();
+ TRANSLATOR.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
}
-
- /**
- * Constructor for TestSqlServerConversionVisitor.
- * @param name
- */
- public TestDB2SqlTranslator(String name) {
- super(name);
- }
public String getTestVDB() {
return UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb"; //$NON-NLS-1$
}
- public void helpTestVisitor(TranslationUtility util, String input, Map modifiers, String expectedOutput) throws ConnectorException {
+ public void helpTestVisitor(TranslationUtility util, String input, String expectedOutput) throws ConnectorException {
// Convert from sql to objects
ICommand obj = util.parseCommand(input);
@@ -78,24 +65,46 @@
assertEquals("Did not get correct sql", expectedOutput, tc.getSql()); //$NON-NLS-1$
}
-
+
+ @Test
public void testRowLimit() throws Exception {
String input = "select intkey from bqt1.smalla limit 100"; //$NON-NLS-1$
String output = "SELECT SmallA.IntKey FROM SmallA FETCH FIRST 100 ROWS ONLY"; //$NON-NLS-1$
helpTestVisitor(FakeTranslationFactory.getInstance().getBQTTranslationUtility(),
input,
- MODIFIERS,
output);
}
+ @Test
public void testCrossJoin() throws Exception{
String input = "SELECT bqt1.smalla.stringkey FROM bqt1.smalla cross join bqt1.smallb"; //$NON-NLS-1$
String output = "SELECT SmallA.StringKey FROM SmallA INNER JOIN SmallB ON 1 = 1"; //$NON-NLS-1$
helpTestVisitor(FakeTranslationFactory.getInstance().getBQTTranslationUtility(),
input,
- MODIFIERS,
output);
}
+
+ @Test
+ public void testConcat2_useLiteral() throws Exception {
+ String input = "select concat2(stringnum,'_xx') from BQT1.Smalla"; //$NON-NLS-1$
+ String output = "SELECT concat(coalesce(SmallA.StringNum, ''), '_xx') FROM SmallA"; //$NON-NLS-1$
+
+ helpTestVisitor(FakeTranslationFactory.getInstance().getBQTTranslationUtility(),
+ input,
+ output);
+
+ }
+
+ @Test
+ public void testConcat2() throws Exception {
+ String input = "select concat2(stringnum, stringnum) from BQT1.Smalla"; //$NON-NLS-1$
+ String output = "SELECT CASE WHEN SmallA.StringNum IS NULL THEN NULL ELSE concat(coalesce(SmallA.StringNum, ''), coalesce(SmallA.StringNum, '')) END FROM SmallA"; //$NON-NLS-1$
+
+ helpTestVisitor(FakeTranslationFactory.getInstance().getBQTTranslationUtility(),
+ input,
+ output);
+ }
+
}
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyConvertModifier.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyConvertModifier.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -111,11 +111,11 @@
}
public void testStringToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "float", "cast(cast('5' as decimal) as float)");//$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "float", "cast(cast('5' AS decimal) AS float)");//$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
}
public void testStringToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "double", "cast(cast('5' as decimal) as double)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "double", "cast(cast('5' AS decimal) AS double)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
public void testStringToDate() throws Exception {
@@ -131,7 +131,7 @@
}
public void testStringToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "bigdecimal", "cast('5' as decimal)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "bigdecimal", "cast('5' AS decimal)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
// Source = CHAR
@@ -437,7 +437,7 @@
}
public void testDoubleToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "float", "cast(1.2 as float)"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "float", "cast(1.2 AS float)"); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testDoubleToBigDecimal() throws Exception {
@@ -475,7 +475,7 @@
}
public void testBigDecimalToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "float", "cast(1.0 as float)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "float", "cast(1.0 AS float)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
public void testBigDecimalToDoublel() throws Exception {
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestEscapeSyntaxModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestEscapeSyntaxModifier.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestEscapeSyntaxModifier.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -22,6 +22,7 @@
package org.teiid.connector.jdbc.extension.impl;
+import java.sql.Timestamp;
import java.util.Arrays;
import java.util.List;
@@ -32,6 +33,8 @@
import com.metamatrix.cdk.CommandBuilder;
import com.metamatrix.connector.language.IFunction;
import com.metamatrix.connector.language.ILiteral;
+import com.metamatrix.connector.visitor.util.SQLReservedWords;
+import com.metamatrix.query.unittest.TimestampUtil;
/**
*/
@@ -46,17 +49,32 @@
}
public void testEscape() {
- EscapeSyntaxModifier mod = new EscapeSyntaxModifier();
-
ILiteral arg1 = CommandBuilder.getLanuageFactory().createLiteral("arg1", String.class); //$NON-NLS-1$
ILiteral arg2 = CommandBuilder.getLanuageFactory().createLiteral("arg2", String.class);//$NON-NLS-1$
IFunction func = CommandBuilder.getLanuageFactory().createFunction("concat", Arrays.asList( arg1, arg2), Integer.class); //$NON-NLS-1$
- func = (IFunction) mod.modify(func);
- List parts = mod.translate(func);
-
- List expected = Arrays.asList(new Object[] { "{fn ", "concat", "(", arg1, ", ", arg2, ")", "}"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- assertEquals(expected, parts);
+ helpTest(func, "{fn concat('arg1', 'arg2')}");
}
+ public void testTimestampAdd() {
+ ILiteral arg1 = CommandBuilder.getLanuageFactory().createLiteral(SQLReservedWords.SQL_TSI_HOUR, String.class); //$NON-NLS-1$
+ ILiteral arg2 = CommandBuilder.getLanuageFactory().createLiteral(Integer.valueOf(1), Integer.class);//$NON-NLS-1$
+ ILiteral arg3 = CommandBuilder.getLanuageFactory().createLiteral(TimestampUtil.createTimestamp(0, 0, 0, 0, 0, 0, 0), Timestamp.class);//$NON-NLS-1$
+ IFunction func = CommandBuilder.getLanuageFactory().createFunction("timestampadd", Arrays.asList( arg1, arg2, arg3), Timestamp.class); //$NON-NLS-1$
+
+ helpTest(func, "{fn timestampadd(SQL_TSI_HOUR, 1, {ts'1899-12-31 00:00:00.0'})}");
+ }
+
+ private void helpTest(IFunction func, String expected) {
+ EscapeSyntaxModifier mod = new EscapeSyntaxModifier();
+
+ func = (IFunction) mod.modify(func);
+ List parts = mod.translate(func);
+ StringBuffer sb = new StringBuffer();
+ for (Object object : parts) {
+ sb.append(object);
+ }
+ assertEquals(expected, sb.toString());
+ }
+
}
Modified: trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/NnDistanceFunctionModifier.java
===================================================================
--- trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/NnDistanceFunctionModifier.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/NnDistanceFunctionModifier.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -38,7 +38,4 @@
return function;
}
- public List translate(IFunction function) {
- return super.translate(function);
- }
}
Modified: trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialFunctionModifier.java
===================================================================
--- trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialFunctionModifier.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialFunctionModifier.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -27,19 +27,10 @@
import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
import com.metamatrix.connector.language.ILiteral;
public class OracleSpatialFunctionModifier extends BasicFunctionModifier {
- public IExpression modify(IFunction function) {
- return super.modify(function);
- }
-
- public List translate(IFunction function) {
- return super.translate(function);
- }
-
protected void addParamWithConversion(List objs,
IExpression expression) {
if ((expression instanceof ILiteral) && (((ILiteral)expression).getType() == String.class))
Modified: trunk/server/src/main/java/com/metamatrix/metadata/runtime/spi/jdbc/JDBCConnector.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/metadata/runtime/spi/jdbc/JDBCConnector.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/server/src/main/java/com/metamatrix/metadata/runtime/spi/jdbc/JDBCConnector.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -27,7 +27,6 @@
import java.sql.SQLException;
import java.util.Collection;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import com.metamatrix.common.connection.BaseTransaction;
Modified: trunk/test-integration/src/test/java/com/metamatrix/cdk/api/TestTranslationUtility.java
===================================================================
--- trunk/test-integration/src/test/java/com/metamatrix/cdk/api/TestTranslationUtility.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/test-integration/src/test/java/com/metamatrix/cdk/api/TestTranslationUtility.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -81,7 +81,6 @@
public void testGetRMD() throws Exception {
TranslationUtility util = new TranslationUtility(getTestVDB());
- RuntimeMetadata rmd = util.createRuntimeMetadata();
// Translate command to get some ids
IQuery query = (IQuery) util.parseCommand("select * from partssupplier.parts"); //$NON-NLS-1$
Modified: trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java
===================================================================
--- trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -22,18 +22,14 @@
package com.metamatrix.connector.jdbc.oracle;
-import java.util.Map;
import java.util.Properties;
+import junit.framework.TestCase;
+
import org.teiid.connector.jdbc.JDBCPropertyNames;
-import org.teiid.connector.jdbc.oracle.ExtractFunctionModifier;
import org.teiid.connector.jdbc.oracle.OracleSQLTranslator;
-import org.teiid.connector.jdbc.translator.FunctionReplacementVisitor;
-import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
import org.teiid.connector.jdbc.translator.TranslatedCommand;
-import junit.framework.TestCase;
-
import com.metamatrix.cdk.CommandBuilder;
import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.cdk.api.TranslationUtility;
@@ -43,7 +39,6 @@
import com.metamatrix.connector.language.ICommand;
import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.dqp.internal.datamgr.impl.ConnectorEnvironmentImpl;
import com.metamatrix.dqp.internal.datamgr.impl.ExecutionContextImpl;
import com.metamatrix.dqp.internal.datamgr.impl.FakeExecutionContextImpl;
import com.metamatrix.dqp.internal.datamgr.metadata.RuntimeMetadataImpl;
@@ -56,24 +51,8 @@
/**
*/
public class TestOracleSQLConversionVisitor extends TestCase {
- private static Map MODIFIERS;
private static ExecutionContext EMPTY_CONTEXT = new FakeExecutionContextImpl();
- static {
- OracleSQLTranslator trans = new OracleSQLTranslator();
-
- try {
- trans.initialize(new ConnectorEnvironmentImpl(new Properties(), null, null));
- } catch(ConnectorException e) {
- e.printStackTrace();
- }
-
- MODIFIERS = trans.getFunctionModifiers();
-
- ExtractFunctionModifier extractMod = new ExtractFunctionModifier ("month"); //$NON-NLS-1$
- MODIFIERS.put("extract", extractMod); //$NON-NLS-1$
- }
-
/**
* Constructor for TestOracleSQLConversionVisitor.
* @param name
@@ -86,37 +65,36 @@
return UnitTestUtil.getTestDataPath() + "/PartsSupplierOracle.vdb"; //$NON-NLS-1$
}
- private void helpTestVisitor(String vdb, String input, Map modifiers, String dbmsTimeZone, String expectedOutput) throws ConnectorException {
- helpTestVisitor(vdb, input, modifiers, EMPTY_CONTEXT, dbmsTimeZone, expectedOutput, false);
+ private void helpTestVisitor(String vdb, String input, String dbmsTimeZone, String expectedOutput) throws ConnectorException {
+ helpTestVisitor(vdb, input, EMPTY_CONTEXT, dbmsTimeZone, expectedOutput, false);
}
- private void helpTestVisitor(String vdb, String input, Map modifiers, String dbmsTimeZone, String expectedOutput, boolean correctNaming) throws ConnectorException {
- helpTestVisitor(vdb, input, modifiers, EMPTY_CONTEXT, dbmsTimeZone, expectedOutput, correctNaming);
+ private void helpTestVisitor(String vdb, String input, String dbmsTimeZone, String expectedOutput, boolean correctNaming) throws ConnectorException {
+ helpTestVisitor(vdb, input, EMPTY_CONTEXT, dbmsTimeZone, expectedOutput, correctNaming);
}
- private void helpTestVisitor(String vdb, String input, Map modifiers, ExecutionContext context, String dbmsTimeZone, String expectedOutput, boolean correctNaming) throws ConnectorException {
+ private void helpTestVisitor(String vdb, String input, ExecutionContext context, String dbmsTimeZone, String expectedOutput, boolean correctNaming) throws ConnectorException {
// Convert from sql to objects
TranslationUtility util = new TranslationUtility(vdb);
ICommand obj = util.parseCommand(input, correctNaming, true);
- this.helpTestVisitor(obj, util.createRuntimeMetadata(), modifiers, context, dbmsTimeZone, expectedOutput);
+ this.helpTestVisitor(obj, util.createRuntimeMetadata(), context, dbmsTimeZone, expectedOutput);
}
/** Helper method takes a QueryMetadataInterface impl instead of a VDB filename
* @throws ConnectorException
*/
- private void helpTestVisitor(QueryMetadataInterface metadata, String input, Map modifiers, ExecutionContext context, String dbmsTimeZone, String expectedOutput) throws ConnectorException {
+ private void helpTestVisitor(QueryMetadataInterface metadata, String input, ExecutionContext context, String dbmsTimeZone, String expectedOutput) throws ConnectorException {
// Convert from sql to objects
CommandBuilder commandBuilder = new CommandBuilder(metadata);
ICommand obj = commandBuilder.getCommand(input);
RuntimeMetadata runtimeMetadata = new RuntimeMetadataImpl(metadata);
- this.helpTestVisitor(obj, runtimeMetadata, modifiers, context, dbmsTimeZone, expectedOutput);
+ this.helpTestVisitor(obj, runtimeMetadata, context, dbmsTimeZone, expectedOutput);
}
- private void helpTestVisitor(ICommand obj, RuntimeMetadata metadata, Map modifiers, ExecutionContext context, String dbmsTimeZone, String expectedOutput) throws ConnectorException {
+ private void helpTestVisitor(ICommand obj, RuntimeMetadata metadata, ExecutionContext context, String dbmsTimeZone, String expectedOutput) throws ConnectorException {
// Apply function replacement
- FunctionReplacementVisitor funcVisitor = new FunctionReplacementVisitor(modifiers);
OracleSQLTranslator translator = new OracleSQLTranslator();
Properties p = new Properties();
if (dbmsTimeZone != null) {
@@ -124,9 +102,7 @@
}
translator.initialize(EnvironmentUtility.createEnvironment(p, false));
// Convert back to SQL
- SQLConversionVisitor sqlVisitor = translator.getSQLConversionVisitor();
- sqlVisitor.setExecutionContext(context);
- TranslatedCommand tc = new TranslatedCommand(context, translator, sqlVisitor, funcVisitor);
+ TranslatedCommand tc = new TranslatedCommand(context, translator);
tc.translateCommand(obj);
// Check stuff
@@ -144,19 +120,17 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS, null,
- output);
+ null, output);
}
- /** defect 21775 */
+ /** defect 21775 */
public void testDateStuff() throws Exception {
String input = "SELECT ((CASE WHEN month(datevalue) < 10 THEN ('0' || convert(month(datevalue), string)) ELSE convert(month(datevalue), string) END || CASE WHEN dayofmonth(datevalue) < 10 THEN ('0' || convert(dayofmonth(datevalue), string)) ELSE convert(dayofmonth(datevalue), string) END) || convert(year(datevalue), string)), SUM(intkey) FROM bqt1.SMALLA GROUP BY datevalue"; //$NON-NLS-1$
String output = "SELECT CASE WHEN (CASE WHEN (CASE WHEN EXTRACT(MONTH FROM SmallA.DateValue) < 10 THEN CASE WHEN to_char(EXTRACT(MONTH FROM SmallA.DateValue)) IS NULL THEN NULL ELSE concat('0', to_char(EXTRACT(MONTH FROM SmallA.DateValue))) END ELSE to_char(EXTRACT(MONTH FROM SmallA.DateValue)) END IS NULL) OR (CASE WHEN EXTRACT(DAY FROM SmallA.DateValue) < 10 THEN CASE WHEN to_char(EXTRACT(DAY FROM SmallA.DateValue)) IS NULL THEN NULL ELSE concat('0', to_char(EXTRACT(DAY FROM SmallA.DateValue))) END ELSE to_char(EXTRACT(DAY FROM SmallA.DateValue)) END IS NULL) THEN NULL ELSE concat(CASE WHEN EXTRACT(MONTH FROM SmallA.DateValue) < 10 THEN CASE WHEN to_char(EXTRACT(MONTH FROM SmallA.DateValue)) IS NULL THEN NULL ELSE concat('0', to_char(EXTRACT(MONTH FROM SmallA.DateValue))) END ELSE to_char(EXTRACT(MONTH FROM SmallA.DateValue)) END, CASE WHEN EXTRACT(DAY FROM SmallA.DateValue) < 10 THEN CASE WHEN to_char(EXTRACT(DAY FROM SmallA.DateValue)) IS NULL THEN NULL ELSE con!
cat('0', to_char(EXTRACT(DAY FROM SmallA.DateValue))) END ELSE to_char(EXTRACT(DAY FROM SmallA.DateValue)) END) END IS NULL) OR (to_char(EXTRACT(YEAR FROM SmallA.DateValue)) IS NULL) THEN NULL ELSE concat(CASE WHEN (CASE WHEN EXTRACT(MONTH FROM SmallA.DateValue) < 10 THEN CASE WHEN to_char(EXTRACT(MONTH FROM SmallA.DateValue)) IS NULL THEN NULL ELSE concat('0', to_char(EXTRACT(MONTH FROM SmallA.DateValue))) END ELSE to_char(EXTRACT(MONTH FROM SmallA.DateValue)) END IS NULL) OR (CASE WHEN EXTRACT(DAY FROM SmallA.DateValue) < 10 THEN CASE WHEN to_char(EXTRACT(DAY FROM SmallA.DateValue)) IS NULL THEN NULL ELSE concat('0', to_char(EXTRACT(DAY FROM SmallA.DateValue))) END ELSE to_char(EXTRACT(DAY FROM SmallA.DateValue)) END IS NULL) THEN NULL ELSE concat(CASE WHEN EXTRACT(MONTH FROM SmallA.DateValue) < 10 THEN CASE WHEN to_char(EXTRACT(MONTH FROM SmallA.DateValue)) IS NULL THEN NULL ELSE concat('0', to_char(EXTRACT(MONTH FROM SmallA.DateValue))) END ELSE to_char(EXTRACT(MONTH FR!
OM SmallA.DateValue)) END, CASE WHEN EXTRACT(DAY FROM SmallA.DateValue
) < 10 THEN CASE WHEN to_char(EXTRACT(DAY FROM SmallA.DateValue)) IS NULL THEN NULL ELSE concat('0', to_char(EXTRACT(DAY FROM SmallA.DateValue))) END ELSE to_char(EXTRACT(DAY FROM SmallA.DateValue)) END) END, to_char(EXTRACT(YEAR FROM SmallA.DateValue))) END, SUM(SmallA.IntKey) FROM SmallA GROUP BY SmallA.DateValue"; //$NON-NLS-1$
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
input,
- MODIFIERS, EMPTY_CONTEXT, null,
- output);
+ EMPTY_CONTEXT, null, output);
}
/**
@@ -171,8 +145,7 @@
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
input,
- MODIFIERS, EMPTY_CONTEXT, null,
- output);
+ EMPTY_CONTEXT, null, output);
}
public void testCharFunction() throws Exception {
@@ -181,7 +154,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
null,
output);
}
@@ -192,7 +164,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
null,
output);
}
@@ -203,7 +174,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
null,
output);
}
@@ -214,7 +184,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
null,
output);
}
@@ -225,7 +194,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
null,
output);
}
@@ -236,7 +204,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
null,
output);
}
@@ -248,7 +215,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
null,
output);
}
@@ -259,7 +225,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
null,
output);
}
@@ -271,7 +236,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
null,
output);
}
@@ -282,7 +246,6 @@
String output = "SELECT to_date(PARTS.PART_ID, 'YYYY-MM-DD') FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
null,
output);
}
@@ -294,7 +257,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
null,
output);
}
@@ -306,7 +268,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
null,
output);
}
@@ -317,14 +278,12 @@
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
input,
- MODIFIERS, EMPTY_CONTEXT, null,
- output);
+ EMPTY_CONTEXT, null, output);
}
public void testAliasedGroup() throws Exception {
helpTestVisitor(getTestVDB(),
"select y.part_name from parts as y", //$NON-NLS-1$
- MODIFIERS,
null,
"SELECT y.PART_NAME FROM PARTS y"); //$NON-NLS-1$
}
@@ -332,7 +291,6 @@
public void testDateLiteral() throws Exception {
helpTestVisitor(getTestVDB(),
"select {d'2002-12-31'} FROM parts", //$NON-NLS-1$
- MODIFIERS,
null,
"SELECT {d'2002-12-31'} FROM PARTS"); //$NON-NLS-1$
}
@@ -340,7 +298,6 @@
public void testTimeLiteral() throws Exception {
helpTestVisitor(getTestVDB(),
"select {t'13:59:59'} FROM parts", //$NON-NLS-1$
- MODIFIERS,
null,
"SELECT {ts'1970-01-01 13:59:59'} FROM PARTS"); //$NON-NLS-1$
}
@@ -348,7 +305,6 @@
public void testTimestampLiteral() throws Exception {
helpTestVisitor(getTestVDB(),
"select {ts'2002-12-31 13:59:59'} FROM parts", //$NON-NLS-1$
- MODIFIERS,
null,
"SELECT {ts'2002-12-31 13:59:59.0'} FROM PARTS"); //$NON-NLS-1$
}
@@ -356,23 +312,22 @@
public void testUnionOrderByWithThreeBranches() throws Exception {
helpTestVisitor(getTestVDB(),
"select part_id id FROM parts UNION ALL select part_name FROM parts UNION ALL select part_id FROM parts ORDER BY id", //$NON-NLS-1$
- MODIFIERS,
null,
- "(SELECT g_2.PART_ID AS c_0 FROM PARTS g_2 UNION ALL SELECT g_1.PART_NAME AS c_0 FROM PARTS g_1) UNION ALL SELECT g_0.PART_ID AS c_0 FROM PARTS g_0 ORDER BY c_0", true); //$NON-NLS-1$
+ "(SELECT g_2.PART_ID AS c_0 FROM PARTS g_2 UNION ALL SELECT g_1.PART_NAME AS c_0 FROM PARTS g_1) UNION ALL SELECT g_0.PART_ID AS c_0 FROM PARTS g_0 ORDER BY c_0",
+ true); //$NON-NLS-1$
}
public void testUnionOrderBy() throws Exception {
helpTestVisitor(getTestVDB(),
"select part_id FROM parts UNION ALL select part_name FROM parts ORDER BY part_id", //$NON-NLS-1$
- MODIFIERS,
null,
- "SELECT g_1.PART_ID AS c_0 FROM PARTS g_1 UNION ALL SELECT g_0.PART_NAME AS c_0 FROM PARTS g_0 ORDER BY c_0", true); //$NON-NLS-1$
+ "SELECT g_1.PART_ID AS c_0 FROM PARTS g_1 UNION ALL SELECT g_0.PART_NAME AS c_0 FROM PARTS g_0 ORDER BY c_0",
+ true); //$NON-NLS-1$
}
public void testUnionOrderBy2() throws Exception {
helpTestVisitor(getTestVDB(),
"select part_id as p FROM parts UNION ALL select part_name FROM parts ORDER BY p", //$NON-NLS-1$
- MODIFIERS,
null,
"SELECT PARTS.PART_ID AS p FROM PARTS UNION ALL SELECT PARTS.PART_NAME FROM PARTS ORDER BY p"); //$NON-NLS-1$
}
@@ -383,8 +338,7 @@
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
input,
- MODIFIERS, EMPTY_CONTEXT, null,
- output);
+ EMPTY_CONTEXT, null, output);
}
@@ -403,7 +357,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
null,
output);
}
@@ -422,7 +375,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
null,
output);
}
@@ -440,7 +392,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
null,
output);
}
@@ -460,10 +411,10 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
context,
null,
- output, false);
+ output,
+ false);
}
/**
@@ -477,7 +428,7 @@
FakeMetadataFacade metadata = exampleCase3845();
- helpTestVisitor(metadata, input, MODIFIERS, EMPTY_CONTEXT, null, output);
+ helpTestVisitor(metadata, input, EMPTY_CONTEXT, null, output);
}
/** create fake BQT metadata to test this case, name in source is important */
@@ -496,7 +447,7 @@
}
public void helpTestVisitor(String vdb, String input, String expectedOutput) throws ConnectorException {
- helpTestVisitor(vdb, input, MODIFIERS, null, expectedOutput);
+ helpTestVisitor(vdb, input, null, expectedOutput);
}
public void testRowLimit2() throws Exception {
@@ -505,18 +456,16 @@
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
input,
- MODIFIERS, EMPTY_CONTEXT, null,
- output);
+ EMPTY_CONTEXT, null, output);
}
public void testRowLimit3() throws Exception {
String input = "select intkey from bqt1.smalla limit 50, 100"; //$NON-NLS-1$
- String output = "SELECT * FROM (SELECT VIEW_FOR_LIMIT.*, ROWNUM ROWNUM_ FROM (SELECT SmallA.IntKey FROM SmallA) VIEW_FOR_LIMIT WHERE ROWNUM <= 100) WHERE ROWNUM_ > 50"; //$NON-NLS-1$
+ String output = "SELECT * FROM (SELECT VIEW_FOR_LIMIT.*, ROWNUM ROWNUM_ FROM (SELECT SmallA.IntKey FROM SmallA) VIEW_FOR_LIMIT WHERE ROWNUM <= 150) WHERE ROWNUM_ > 50"; //$NON-NLS-1$
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
input,
- MODIFIERS, EMPTY_CONTEXT, null,
- output);
+ EMPTY_CONTEXT, null, output);
}
public void testLimitWithNestedInlineView() throws Exception {
@@ -525,8 +474,7 @@
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
input,
- MODIFIERS, EMPTY_CONTEXT, null,
- output);
+ EMPTY_CONTEXT, null, output);
}
public void testExceptAsMinus() throws Exception {
@@ -535,8 +483,31 @@
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
input,
- MODIFIERS, EMPTY_CONTEXT, null,
- output);
+ EMPTY_CONTEXT, null, output);
+ }
+
+ public void testConcat2_useLiteral() throws Exception {
+ String sql = "select concat2(stringnum,'_xx') from BQT1.Smalla"; //$NON-NLS-1$
+ String expected = "SELECT concat(nvl(SmallA.StringNum, ''), '_xx') FROM SmallA"; //$NON-NLS-1$
+ helpTestVisitor(FakeMetadataFactory.exampleBQTCached(), sql, EMPTY_CONTEXT, null, expected);
+ }
+
+ public void testConcat2() throws Exception {
+ String sql = "select concat2(stringnum, stringnum) from BQT1.Smalla"; //$NON-NLS-1$
+ String expected = "SELECT CASE WHEN SmallA.StringNum IS NULL THEN NULL ELSE concat(nvl(SmallA.StringNum, ''), nvl(SmallA.StringNum, '')) END FROM SmallA";
+ helpTestVisitor(FakeMetadataFactory.exampleBQTCached(), sql, EMPTY_CONTEXT, null, expected);
+ }
+
+ public void testConcat() throws Exception {
+ String sql = "select concat(stringnum, stringkey) from BQT1.Smalla"; //$NON-NLS-1$
+ String expected = "SELECT CASE WHEN (SmallA.StringNum IS NULL) OR (SmallA.StringKey IS NULL) THEN NULL ELSE concat(SmallA.StringNum, SmallA.StringKey) END FROM SmallA";
+ helpTestVisitor(FakeMetadataFactory.exampleBQTCached(), sql, EMPTY_CONTEXT, null, expected);
+ }
+
+ public void testConcat_withLiteral() throws Exception {
+ String sql = "select stringnum || '1' from BQT1.Smalla"; //$NON-NLS-1$
+ String expected = "SELECT CASE WHEN SmallA.StringNum IS NULL THEN NULL ELSE concat(SmallA.StringNum, '1') END FROM SmallA";
+ helpTestVisitor(FakeMetadataFactory.exampleBQTCached(), sql, EMPTY_CONTEXT, null, expected);
}
}
Modified: trunk/test-integration/src/test/java/com/metamatrix/data/visitor/util/TestSQLStringVisitor.java
===================================================================
--- trunk/test-integration/src/test/java/com/metamatrix/data/visitor/util/TestSQLStringVisitor.java 2009-02-24 21:55:33 UTC (rev 493)
+++ trunk/test-integration/src/test/java/com/metamatrix/data/visitor/util/TestSQLStringVisitor.java 2009-02-25 03:49:48 UTC (rev 494)
@@ -30,13 +30,16 @@
import junit.framework.TestCase;
+import com.metamatrix.cdk.unittest.FakeTranslationFactory;
import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.connector.language.ICommand;
import com.metamatrix.connector.language.IElement;
import com.metamatrix.connector.language.IExpression;
import com.metamatrix.connector.language.IFunction;
import com.metamatrix.connector.language.IGroup;
import com.metamatrix.connector.language.ILanguageObject;
import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
+import com.metamatrix.connector.visitor.util.SQLReservedWords;
import com.metamatrix.connector.visitor.util.SQLStringVisitor;
import com.metamatrix.dqp.internal.datamgr.language.AggregateImpl;
import com.metamatrix.dqp.internal.datamgr.language.ElementImpl;
@@ -445,4 +448,11 @@
String expected = "EXEC sq3(, x, 1)"; //$NON-NLS-1$
assertEquals(expected, getString(TestProcedureImpl.example()));
}
+
+ public void testTimestampAddFunction() throws Exception {
+ String sql = "select timestampadd(" +SQLReservedWords.SQL_TSI_DAY+ ", 2, timestampvalue) from bqt1.smalla"; //$NON-NLS-1$
+
+ ICommand command = FakeTranslationFactory.getInstance().getBQTTranslationUtility().parseCommand(sql);
+ assertEquals("SELECT timestampadd(SQL_TSI_DAY, 2, SmallA.TimestampValue) FROM SmallA", command.toString()); //$NON-NLS-1$
+ }
}
15 years, 10 months
teiid SVN: r493 - trunk/engine/src/main/java/com/metamatrix/query/resolver/util.
by teiid-commits@lists.jboss.org
Author: ghelblin
Date: 2009-02-24 16:55:33 -0500 (Tue, 24 Feb 2009)
New Revision: 493
Modified:
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
Log:
TEIID-61 - Fix for exception when CASE resoves to NULL [reviewed by Steve H]
Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2009-02-24 21:52:30 UTC (rev 492)
+++ trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2009-02-24 21:55:33 UTC (rev 493)
@@ -51,6 +51,7 @@
import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.lang.Limit;
import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.symbol.AbstractCaseExpression;
import com.metamatrix.query.sql.symbol.AggregateSymbol;
import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.Constant;
@@ -60,6 +61,7 @@
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.Reference;
+import com.metamatrix.query.sql.symbol.ScalarSubquery;
import com.metamatrix.query.sql.symbol.SelectSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.util.ErrorMessageKeys;
@@ -597,18 +599,33 @@
*/
public static void resolveNullLiterals(List symbols) {
for (int i = 0; i < symbols.size(); i++) {
- SelectSymbol symbol = (SelectSymbol) symbols.get(i);
+ SelectSymbol selectSymbol = (SelectSymbol) symbols.get(i);
+
+ if (!(selectSymbol instanceof SingleElementSymbol)) {
+ continue;
+ }
+
+ SingleElementSymbol symbol = (SingleElementSymbol)selectSymbol;
+
+ if(!DataTypeManager.DefaultDataClasses.NULL.equals(symbol.getType()) && symbol.getType() != null) {
+ continue;
+ }
if(symbol instanceof AliasSymbol) {
symbol = ((AliasSymbol)symbol).getSymbol();
}
-
+
Class replacement = DataTypeManager.DefaultDataClasses.STRING;
if(symbol instanceof ExpressionSymbol && !(symbol instanceof AggregateSymbol)) {
ExpressionSymbol exprSymbol = (ExpressionSymbol) symbol;
Expression expr = exprSymbol.getExpression();
- if(expr != null && expr instanceof Constant && ((Constant)expr).isNull()) {
+
+ if(expr instanceof Constant) {
exprSymbol.setExpression(new Constant(null, replacement));
+ } else if (expr instanceof AbstractCaseExpression) {
+ ((AbstractCaseExpression)expr).setType(replacement);
+ } else if (expr instanceof ScalarSubquery) {
+ ((ScalarSubquery)expr).setType(replacement);
} else {
try {
ResolverUtil.setTypeIfReference(expr, replacement, symbol);
15 years, 10 months
teiid SVN: r492 - in trunk/engine/src: main/java/com/metamatrix/query/optimizer/relational/rules and 9 other directories.
by teiid-commits@lists.jboss.org
Author: ghelblin
Date: 2009-02-24 16:52:30 -0500 (Tue, 24 Feb 2009)
New Revision: 492
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/proc/ProcedurePlanner.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanProcedures.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureCriteriaProcessor.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureExecutionNode.java
trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
trunk/engine/src/main/java/com/metamatrix/query/rewriter/VariableSubstitutionVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Delete.java
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Insert.java
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/ProcedureContainer.java
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/StoredProcedure.java
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Update.java
trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/Reference.java
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java
trunk/engine/src/main/resources/com/metamatrix/query/execution/i18n.properties
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcedureRelational.java
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
Log:
TEIID-148 - Allow runtime checking of NULL values
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/proc/ProcedurePlanner.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/proc/ProcedurePlanner.java 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/proc/ProcedurePlanner.java 2009-02-24 21:52:30 UTC (rev 492)
@@ -25,6 +25,7 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.query.QueryMetadataException;
@@ -54,6 +55,7 @@
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.DynamicCommand;
import com.metamatrix.query.sql.lang.Into;
+import com.metamatrix.query.sql.lang.ProcedureContainer;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.proc.AssignmentStatement;
import com.metamatrix.query.sql.proc.Block;
@@ -107,6 +109,7 @@
// get the current command on the current node of the tree
Command procCommand = node.getCommand();
+
// set state of the planner with child nodes
// to be used while planning
List childNodes = node.getChildren();
@@ -135,6 +138,16 @@
ProcedureEnvironment env = new ProcedureEnvironment();
env.getProgramStack().push(programBlock);
ProcedurePlan plan = new ProcedurePlan(env);
+
+ // propagate procedure parameters to the plan to allow runtime type checking
+ ProcedureContainer container = (ProcedureContainer)((CreateUpdateProcedureCommand) procCommand).getUserCommand();
+
+ if (container != null) {
+ Map params = container.getProcedureParameters();
+ plan.setParams(params);
+ plan.setMetadata(metadata);
+ }
+
env.initialize(plan);
env.setUpdateProcedure(((CreateUpdateProcedureCommand)procCommand).isUpdateProcedure());
env.setOutputElements(((CreateUpdateProcedureCommand)procCommand).getProjectedSymbols());
@@ -265,9 +278,9 @@
intoGroup = into.getGroup();
}
}
- List references = ReferenceCollectorVisitor.getReferences(command);
- ProcessorPlan commandPlan = ((CommandTreeNode)childNodes.get(childIndex.getChildIndex())).getProcessorPlan();
- childIndex.incrementChildIndex();
+ List references = ReferenceCollectorVisitor.getReferences(command);
+ ProcessorPlan commandPlan = ((CommandTreeNode)childNodes.get(childIndex.getChildIndex())).getProcessorPlan();
+ childIndex.incrementChildIndex();
if (command.getType() == Command.TYPE_DYNAMIC){
instruction = new ExecDynamicSqlInstruction(parentProcCommand,((DynamicCommand)command), references, metadata, idGenerator, capFinder );
@@ -343,7 +356,7 @@
}
return instruction;
}
-
+
static class ChildIndexHolder{
private int childIndex;
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanProcedures.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanProcedures.java 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanProcedures.java 2009-02-24 21:52:30 UTC (rev 492)
@@ -32,11 +32,9 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.query.QueryMetadataException;
import com.metamatrix.api.exception.query.QueryPlannerException;
-import com.metamatrix.common.log.LogManager;
import com.metamatrix.query.analysis.AnalysisRecord;
import com.metamatrix.query.execution.QueryExecPlugin;
import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.metadata.SupportConstants;
import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
import com.metamatrix.query.optimizer.relational.OptimizerRule;
import com.metamatrix.query.optimizer.relational.RuleStack;
@@ -60,7 +58,6 @@
import com.metamatrix.query.sql.symbol.Reference;
import com.metamatrix.query.sql.visitor.ReferenceCollectorVisitor;
import com.metamatrix.query.util.CommandContext;
-import com.metamatrix.query.util.LogConstants;
public class RulePlanProcedures implements OptimizerRule {
@@ -95,9 +92,6 @@
List conjuncts = new LinkedList();
HashSet coveredParams = new HashSet();
//List preExecNodes = new LinkedList();
-
- // Case 6395 - maintain a list of non-nullable elements that are set IS NULL.
- List nonNullableElems = new LinkedList();
if (!proc.isProcedureRelational()) {
continue;
@@ -111,13 +105,8 @@
inputSymbols.add(symbol);
}
- findInputNodes(inputSymbols, critNode, conjuncts, coveredParams, nonNullableElems, metadata);
+ findInputNodes(inputSymbols, critNode, conjuncts, coveredParams);
- // Check for non-nullable elements that are set IS NULL. throws exception if any found.
- if(!nonNullableElems.isEmpty()) {
- throw new QueryPlannerException(QueryExecPlugin.Util.getString("RulePlanProcedures.nonNullableParam", nonNullableElems.get(0))); //$NON-NLS-1$
- }
-
List defaults = new LinkedList();
for (Iterator params = inputReferences.iterator(); params.hasNext();) {
@@ -162,8 +151,7 @@
private void findInputNodes(final HashSet inputs,
PlanNode critNode,
- final List conjuncts, final Set params, final List nonNullableElems,
- final QueryMetadataInterface metadata) throws QueryMetadataException, MetaMatrixComponentException {
+ final List conjuncts, final Set params) {
while (critNode.getType() == NodeConstants.Types.SELECT) {
final PlanNode currentNode = critNode;
@@ -201,24 +189,10 @@
setAbort(true);
}
- // method to add invalid isNull element
- private void addInvalidElem(ElementSymbol symbol) {
- nonNullableElems.add(symbol);
- }
-
- public void visit(IsNullCriteria isNull) {
+ public void visit(IsNullCriteria isNull){
if (isNull.isNegated()) {
return;
}
- // Case 6395 - check for non-nullable Elems that are IS NULL
- Expression expr = isNull.getExpression();
- if(expr instanceof Reference) {
- expr = ((Reference)expr).getExpression();
- }
- if(expr instanceof ElementSymbol &&!isNullable((ElementSymbol)expr,metadata)) {
- addInvalidElem((ElementSymbol)expr);
- }
-
if (checkForInput(isNull.getExpression())) {
addInputNode((Reference)isNull.getExpression());
}
@@ -262,24 +236,13 @@
}
return false;
}
-
- boolean isNullable(ElementSymbol element, QueryMetadataInterface metadata) {
- Object elemID = element.getMetadataID();
- try {
- return metadata.elementSupports(elemID, SupportConstants.Element.NULL) ||
- metadata.elementSupports(elemID, SupportConstants.Element.NULL_UNKNOWN);
- } catch (Exception e){
- LogManager.logWarning(LogConstants.CTX_QUERY_PLANNER, e , "Error getting isNullable on element: "+element.getShortName()); //$NON-NLS-1$
- return false;
- }
- }
};
PreOrderNavigator.doVisit(crit, visitor);
}
}
-
+
/**
* @see java.lang.Object#toString()
*/
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java 2009-02-24 21:52:30 UTC (rev 492)
@@ -43,6 +43,7 @@
import com.metamatrix.query.eval.Evaluator;
import com.metamatrix.query.execution.QueryExecPlugin;
import com.metamatrix.query.metadata.QueryMetadataInterface;
+import com.metamatrix.query.metadata.TempMetadataAdapter;
import com.metamatrix.query.metadata.TempMetadataStore;
import com.metamatrix.query.optimizer.QueryOptimizer;
import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
@@ -66,6 +67,7 @@
import com.metamatrix.query.sql.lang.Select;
import com.metamatrix.query.sql.lang.SetClause;
import com.metamatrix.query.sql.lang.SubqueryFromClause;
+import com.metamatrix.query.sql.lang.UnaryFromClause;
import com.metamatrix.query.sql.proc.CreateUpdateProcedureCommand;
import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.Constant;
@@ -212,7 +214,7 @@
// validation visitor?
- VariableSubstitutionVisitor.substituteVariables(command, command.getVariableValues(), command.getType(), false);
+ VariableSubstitutionVisitor.substituteVariables(command, command.getVariableValues(), command.getType());
QueryRewriter.rewrite(command, parentProcCommand, metadata,
procEnv.getContext());
@@ -334,14 +336,30 @@
Query query = new Query();
query.setSelect(select);
From from = new From();
- SubqueryFromClause sqfc = new SubqueryFromClause(subquery_group_name,
- command);
- from.addClause(sqfc);
- query.setFrom(from);
+
+ GroupSymbol inlineGroup = new GroupSymbol(subquery_group_name);
+
+ from.addClause(new UnaryFromClause(inlineGroup));
+ TempMetadataStore store = new TempMetadataStore();
+ TempMetadataAdapter tma = new TempMetadataAdapter(metadata, store);
+
+ store.addTempGroup(inlineGroup.getName(), command.getProjectedSymbols());
+ inlineGroup.setMetadataID(store.getTempGroupID(inlineGroup.getName()));
+ query.setFrom(from);
+ QueryResolver.resolveCommand(query, tma);
+ query.setOption(command.getOption());
+
+ from.getClauses().clear();
+ SubqueryFromClause sqfc = new SubqueryFromClause(inlineGroup.getName());
+ sqfc.setCommand(command);
+ sqfc.getGroupSymbol().setMetadataID(inlineGroup.getMetadataID());
+ from.addClause(sqfc);
+ //copy the metadata onto the new query so that temp metadata adapters will be used in later calls
+ query.getTemporaryMetadata().putAll(store.getData());
+
if (dynamicCommand.getIntoGroup() != null) {
query.setInto(new Into(dynamicCommand.getIntoGroup()));
}
- QueryResolver.resolveCommand(query, metadata);
return query;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java 2009-02-24 21:52:30 UTC (rev 492)
@@ -25,11 +25,13 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import com.metamatrix.api.exception.query.QueryValidatorException;
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.buffer.BufferManager;
import com.metamatrix.common.buffer.TupleBatch;
@@ -39,9 +41,11 @@
import com.metamatrix.common.buffer.BufferManager.TupleSourceType;
import com.metamatrix.common.log.LogManager;
import com.metamatrix.core.MetaMatrixCoreException;
-import com.metamatrix.core.log.MessageLevel;
import com.metamatrix.core.util.Assertion;
+import com.metamatrix.query.eval.Evaluator;
import com.metamatrix.query.execution.QueryExecPlugin;
+import com.metamatrix.query.metadata.QueryMetadataInterface;
+import com.metamatrix.query.metadata.SupportConstants;
import com.metamatrix.query.processor.BaseProcessorPlan;
import com.metamatrix.query.processor.DescribableUtil;
import com.metamatrix.query.processor.ProcessorDataManager;
@@ -51,6 +55,9 @@
import com.metamatrix.query.processor.program.Program;
import com.metamatrix.query.processor.program.ProgramInstruction;
import com.metamatrix.query.processor.program.ProgramUtil;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
+import com.metamatrix.query.sql.symbol.Expression;
+import com.metamatrix.query.sql.util.VariableContext;
import com.metamatrix.query.tempdata.TempTableStore;
import com.metamatrix.query.tempdata.TempTableStoreImpl;
import com.metamatrix.query.util.CommandContext;
@@ -79,7 +86,9 @@
private TupleSource finalTupleSource;
private int beginBatch = 1;
private List batchRows;
- private boolean lastBatch = false;
+ private boolean lastBatch = false;
+ private Map params;
+ private QueryMetadataInterface metadata;
/**
* Constructor for ProcedurePlan.
@@ -187,8 +196,8 @@
return env.getOutputElements();
}
- public void open()
- throws MetaMatrixComponentException {
+ public void open() throws MetaMatrixProcessingException, MetaMatrixComponentException {
+ evaluateParams();
}
/**
@@ -336,7 +345,11 @@
clonedEnv.getProgramStack().push(originalProgram.clone());
clonedEnv.setUpdateProcedure(this.env.isUpdateProcedure());
clonedEnv.setOutputElements(this.env.getOutputElements());
- return new ProcedurePlan(clonedEnv);
+ ProcedurePlan plan = new ProcedurePlan(clonedEnv);
+ plan.setParams(params);
+ plan.setMetadata(metadata);
+
+ return plan;
}
protected void addBatchRow(List row) {
@@ -388,4 +401,35 @@
public Collection getChildPlans() {
return this.originalProgram.getChildPlans();
}
+
+ public void setMetadata( QueryMetadataInterface metadata ) {
+ this.metadata = metadata;
+ }
+
+ public void setParams( Map params ) {
+ this.params = params;
+ }
+
+ public void evaluateParams() throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
+
+ if ( params == null ) {
+ return;
+ }
+
+ for (Iterator iter = params.entrySet().iterator(); iter.hasNext();) {
+ Map.Entry entry = (Map.Entry)iter.next();
+ ElementSymbol param = (ElementSymbol)entry.getKey();
+ Expression expr = (Expression)entry.getValue();
+
+ VariableContext context = env.getCurrentVariableContext();
+ Object value = new Evaluator(null, null, getContext()).evaluate(expr, null);
+
+ //check constraint
+ if (value == null && !metadata.elementSupports(param.getMetadataID(), SupportConstants.Element.NULL)) {
+ throw new QueryValidatorException(QueryExecPlugin.Util.getString("ProcedurePlan.nonNullableParam", expr)); //$NON-NLS-1$
+ }
+ context.setValue(param, value);
+ }
+
+ }
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java 2009-02-24 21:52:30 UTC (rev 492)
@@ -28,6 +28,7 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import com.metamatrix.query.eval.Evaluator;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.Criteria;
@@ -93,7 +94,7 @@
protected boolean prepareNextCommand(Command atomicCommand) throws MetaMatrixComponentException, MetaMatrixProcessingException {
if (this.criteriaProcessor == null) {
- this.criteriaProcessor = new DependentProcedureCriteriaProcessor(this, (Criteria)inputCriteria.clone(), inputReferences, inputDefaults);
+ this.criteriaProcessor = new DependentProcedureCriteriaProcessor(this, (Criteria)inputCriteria.clone(), inputReferences, inputDefaults, new Evaluator(null, null, getContext()));
}
return criteriaProcessor.prepareNextCommand();
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureCriteriaProcessor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureCriteriaProcessor.java 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureCriteriaProcessor.java 2009-02-24 21:52:30 UTC (rev 492)
@@ -44,13 +44,15 @@
private List inputReferences;
private List inputDefaults;
private Criteria critInProgress;
+ private Evaluator eval;
public DependentProcedureCriteriaProcessor(RelationalNode dependentNode,
Criteria dependentCriteria,
List references,
- List defaults) {
+ List defaults,
+ Evaluator eval) {
super(1, dependentNode, dependentCriteria);
-
+ this.eval = eval;
this.inputDefaults = defaults;
this.inputReferences = references;
}
@@ -106,7 +108,7 @@
}
if (value instanceof Expression) {
- value = Evaluator.evaluate((Expression)value);
+ value = eval.evaluate((Expression)value, null);
}
if (value == null && !nullAllowed) {
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureExecutionNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureExecutionNode.java 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureExecutionNode.java 2009-02-24 21:52:30 UTC (rev 492)
@@ -30,6 +30,7 @@
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.buffer.TupleSourceNotFoundException;
+import com.metamatrix.query.eval.Evaluator;
import com.metamatrix.query.sql.lang.Criteria;
public class DependentProcedureExecutionNode extends PlanExecutionNode {
@@ -96,7 +97,7 @@
MetaMatrixComponentException, MetaMatrixProcessingException {
if (this.criteriaProcessor == null) {
- this.criteriaProcessor = new DependentProcedureCriteriaProcessor(this, (Criteria)inputCriteria.clone(), inputReferences, inputDefaults);
+ this.criteriaProcessor = new DependentProcedureCriteriaProcessor(this, (Criteria)inputCriteria.clone(), inputReferences, inputDefaults, new Evaluator(null, null, getContext()));
}
return criteriaProcessor.prepareNextCommand();
Modified: trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-02-24 21:52:30 UTC (rev 492)
@@ -48,8 +48,10 @@
import com.metamatrix.api.exception.query.FunctionExecutionException;
import com.metamatrix.api.exception.query.InvalidFunctionException;
import com.metamatrix.api.exception.query.QueryMetadataException;
+import com.metamatrix.api.exception.query.QueryProcessingException;
import com.metamatrix.api.exception.query.QueryResolverException;
import com.metamatrix.api.exception.query.QueryValidatorException;
+import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.common.types.Transform;
import com.metamatrix.common.util.TimestampWithTimezone;
@@ -62,6 +64,7 @@
import com.metamatrix.query.function.FunctionLibrary;
import com.metamatrix.query.function.FunctionLibraryManager;
import com.metamatrix.query.metadata.QueryMetadataInterface;
+import com.metamatrix.query.metadata.SupportConstants;
import com.metamatrix.query.metadata.TempMetadataAdapter;
import com.metamatrix.query.metadata.TempMetadataID;
import com.metamatrix.query.metadata.TempMetadataStore;
@@ -188,8 +191,6 @@
*/
private static Command rewriteCommand(Command command, Command procCommand, final QueryMetadataInterface metadata, final CommandContext context) throws QueryValidatorException {
- boolean referencesRequired = false;
-
//TODO: this should be merged with the normal functioning of the rewriter
CorrelatedVariableSubstitutionVisitor.substituteVariables(command);
@@ -234,11 +235,9 @@
if (command instanceof ProcedureContainer) {
try {
- Map variables = QueryResolver.getVariableValues(command, metadata);
- //if we know at this point that the procedure wrapper can be removed, then references will be forwarded in the call below
- boolean forwardReferences = canRemoveProceduralWrapper((ProcedureContainer)command);
-
- referencesRequired |= VariableSubstitutionVisitor.substituteVariables(subCommand, variables, command.getType(), forwardReferences);
+ Map variables = QueryResolver.getVariableValues(command, metadata);
+ VariableSubstitutionVisitor.substituteVariables(subCommand, variables, command.getType());
+
} catch (QueryMetadataException err) {
throw new QueryValidatorException(err, err.getMessage());
} catch (QueryResolverException err) {
@@ -253,24 +252,7 @@
}
}
- //there's a chance that rewriting caused the procedure to simplify, which means that we should check again if the wrapper can be removed
- //TODO: handle empty procedure blocks
- if (!referencesRequired && (command instanceof ProcedureContainer) && canRemoveProceduralWrapper((ProcedureContainer)command)) {
- ProcedureContainer container = (ProcedureContainer)command;
- Block block = ((CreateUpdateProcedureCommand)container.getSubCommand()).getBlock();
- Command subCommand = ((CommandStatement)(block.getStatements().get(0))).getCommand();
-
- if ( subCommand.getOption() == null ) {
- subCommand.setOption( command.getOption() );
- } else {
- Option merged = mergeOptions( command.getOption(), subCommand.getOption() );
- subCommand.setOption(merged);
- }
-
- return subCommand;
- }
-
- return command;
+ return removeProceduralWrapper(command, metadata);
}
private static Option mergeOptions( Option sourceOption, Option targetOption ) {
@@ -291,38 +273,70 @@
}
- private static boolean canRemoveProceduralWrapper(ProcedureContainer container) throws QueryValidatorException {
+ private static Command removeProceduralWrapper(Command command, QueryMetadataInterface metadata) throws QueryValidatorException {
- if (container instanceof StoredProcedure && ((StoredProcedure)container).isProcedureRelational()) {
- return false;
+ if (!(command instanceof StoredProcedure)) {
+ return command;
}
+ StoredProcedure container = (StoredProcedure)command;
+ if (container.isProcedureRelational()) {
+ return command;
+ }
+
if (!(container.getSubCommand() instanceof CreateUpdateProcedureCommand)) {
- return false;
+ return command;
}
CreateUpdateProcedureCommand subCommand = (CreateUpdateProcedureCommand)container.getSubCommand();
if (subCommand == null) {
- return false;
+ return command;
}
+
+ //if all parameters can be evaluated, we need to validate their values before removing the procedure wrapper
+ for (Iterator iter = container.getInputParameters().iterator(); iter.hasNext();) {
+ SPParameter param = (SPParameter)iter.next();
+ Expression expr = param.getExpression();
+ if (!EvaluateExpressionVisitor.isFullyEvaluatable(expr, true)) {
+ return command;
+ }
+ try {
+ Object value = Evaluator.evaluate(expr);
+
+ //check contraint
+ if (value == null && !metadata.elementSupports(param.getMetadataID(), SupportConstants.Element.NULL)) {
+ throw new QueryValidatorException(QueryExecPlugin.Util.getString("ProcedurePlan.nonNullableParam", expr)); //$NON-NLS-1$
+ }
+ } catch (ExpressionEvaluationException err) {
+ } catch (BlockedException err) {
+ } catch (MetaMatrixComponentException err) {
+ }
+ }
+
Block block = subCommand.getBlock();
if (block.getStatements().size() != 1) {
- return false;
+ return command;
}
Statement statement = (Statement)block.getStatements().get(0);
if (statement.getType() != Statement.TYPE_COMMAND) {
- return false;
+ return command;
}
- Command command = (((CommandStatement)statement).getCommand());
+ Command child = (((CommandStatement)statement).getCommand());
- if (command != null && command.getType() != Command.TYPE_DYNAMIC) {
- return true;
+ if (child != null && child.getType() != Command.TYPE_DYNAMIC) {
+ if ( child.getOption() == null ) {
+ child.setOption( command.getOption() );
+ } else {
+ Option merged = mergeOptions( command.getOption(), child.getOption() );
+ child.setOption(merged);
+ }
+
+ return child;
}
-
- return false;
+ return command;
}
private static Command rewriteUpdateProcedure(CreateUpdateProcedureCommand procCommand, QueryMetadataInterface metadata, CommandContext context)
Modified: trunk/engine/src/main/java/com/metamatrix/query/rewriter/VariableSubstitutionVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/rewriter/VariableSubstitutionVisitor.java 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/main/java/com/metamatrix/query/rewriter/VariableSubstitutionVisitor.java 2009-02-24 21:52:30 UTC (rev 492)
@@ -74,8 +74,6 @@
// substitution
private Collection invalidInput;
private int commandType;
- private boolean forwardReferences;
- private boolean referenceRequired;
private QueryResolverException conversionException = null;
@@ -83,10 +81,9 @@
* Construct a new visitor with the list of references.
* @param references A list of references on to be collected
*/
- public VariableSubstitutionVisitor(Map variableValues, int commandType, boolean forwardReferences) {
+ public VariableSubstitutionVisitor(Map variableValues, int commandType) {
super(variableValues);
this.commandType = commandType;
- this.forwardReferences = forwardReferences;
}
// ############### Visitor methods for language objects ##################
@@ -196,21 +193,16 @@
Expression value = (Expression)this.getVariableValues().get(symbol.getCanonicalName());
if (value != null) {
- expr = value;
- //don't forward references, instead wrap in a new reference
- //that will prevent setting the reference value by any other scope than the what
- //created the reference
- if (!forwardReferences && !ReferenceCollectorVisitor.getReferences(expr).isEmpty()) {
- expr = new Reference(0, value);
- referenceRequired = true;
+ //don't forward references
+ if (!ReferenceCollectorVisitor.getReferences(value).isEmpty()) {
+ return expr;
}
+ expr = value;
} else if (grpName.equals(ProcedureReservedWords.INPUT)) {
expr = new Constant(null, symbol.getType());
} else if (grpName.equals(ProcedureReservedWords.CHANGING)) {
Assertion.failed("Changing value should not be null"); //$NON-NLS-1$
- } else if (grpName.equals(ProcedureReservedWords.VARIABLES) || !GroupSymbol.isTempGroupName(grpName)) {
- expr = new Reference(0, symbol);
- }
+ }
}
}
@@ -234,14 +226,14 @@
* @throws QueryValidatorException
* @throws QueryValidatorException
*/
- public static final boolean substituteVariables(
+ public static final void substituteVariables(
LanguageObject obj,
Map variableValues,
- int commandType, boolean forwardReferences) throws QueryValidatorException {
+ int commandType) throws QueryValidatorException {
VariableSubstitutionVisitor visitor =
- new VariableSubstitutionVisitor(variableValues, commandType, forwardReferences);
+ new VariableSubstitutionVisitor(variableValues, commandType);
if (obj == null) {
- return false;
+ return;
}
DeepPreOrderNavigator.doVisit(obj, visitor);
@@ -252,7 +244,6 @@
if (visitor.conversionException != null) {
throw new QueryValidatorException(visitor.conversionException, visitor.conversionException.getMessage());
}
-
- return visitor.referenceRequired;
- }
+ }
+
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Delete.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Delete.java 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Delete.java 2009-02-24 21:52:30 UTC (rev 492)
@@ -22,7 +22,9 @@
package com.metamatrix.query.sql.lang;
+import java.util.Collections;
import java.util.List;
+import java.util.Map;
import com.metamatrix.core.util.EquivalenceUtil;
import com.metamatrix.core.util.HashCodeUtil;
@@ -159,6 +161,14 @@
return EquivalenceUtil.areEqual(getGroup(), other.getGroup()) &&
EquivalenceUtil.areEqual(getCriteria(), other.getCriteria());
}
+
+ /**
+ * @see com.metamatrix.query.sql.lang.ProcedureContainer#getParameters()
+ * @since 5.0
+ */
+ public Map getProcedureParameters() {
+ return Collections.EMPTY_MAP;
+ }
/**
* Return a copy of this Delete.
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Insert.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Insert.java 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Insert.java 2009-02-24 21:52:30 UTC (rev 492)
@@ -23,16 +23,20 @@
package com.metamatrix.query.sql.lang;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import com.metamatrix.core.util.EquivalenceUtil;
import com.metamatrix.core.util.HashCodeUtil;
import com.metamatrix.query.sql.LanguageVisitor;
+import com.metamatrix.query.sql.ProcedureReservedWords;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.GroupSymbol;
+import com.metamatrix.query.sql.symbol.SingleElementSymbol;
/**
* Represents a SQL Insert statement of the form:
@@ -210,6 +214,23 @@
EquivalenceUtil.areEqual(getVariables(), other.getVariables()) &&
EquivalenceUtil.areEqual(getQueryExpression(), other.getQueryExpression());
}
+
+ /**
+ * @see com.metamatrix.query.sql.lang.ProcedureContainer#getParameters()
+ * @since 5.0
+ */
+ public Map getProcedureParameters() {
+
+ int iSize = getVariables().size();
+ HashMap map = new HashMap();
+
+ for (int j = 0; j < iSize; j++) {
+ ElementSymbol symbol = (ElementSymbol)((ElementSymbol)variables.get( j )).clone();
+ symbol.setName(ProcedureReservedWords.INPUT + SingleElementSymbol.SEPARATOR + symbol.getShortCanonicalName());
+ map.put(symbol, values.get( j ) );
+ } // for
+ return map;
+ }
/**
* Return a deep copy of this Insert.
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/ProcedureContainer.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/ProcedureContainer.java 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/ProcedureContainer.java 2009-02-24 21:52:30 UTC (rev 492)
@@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.query.QueryMetadataException;
@@ -128,5 +129,6 @@
}
this.updateCount = updateCount;
}
-
+
+ public abstract Map getProcedureParameters();
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/StoredProcedure.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/StoredProcedure.java 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/StoredProcedure.java 2009-02-24 21:52:30 UTC (rev 492)
@@ -414,6 +414,22 @@
public void setCallableStatement(boolean isCallableStatement) {
this.isCallableStatement = isCallableStatement;
}
+
+ /**
+ * @see com.metamatrix.query.sql.lang.ProcedureContainer#getProcedureParameters()
+ * @since 5.0
+ */
+ public Map getProcedureParameters() {
+
+ HashMap map = new HashMap();
+ for (Iterator iter = this.getInputParameters().iterator(); iter.hasNext();) {
+
+ SPParameter element = (SPParameter)iter.next();
+ map.put(element.getParameterSymbol(), element.getExpression());
+ } // for
+
+ return map;
+ }
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Update.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Update.java 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Update.java 2009-02-24 21:52:30 UTC (rev 492)
@@ -22,14 +22,19 @@
package com.metamatrix.query.sql.lang;
+import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import com.metamatrix.core.util.EquivalenceUtil;
import com.metamatrix.core.util.HashCodeUtil;
import com.metamatrix.query.sql.LanguageVisitor;
+import com.metamatrix.query.sql.ProcedureReservedWords;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.GroupSymbol;
+import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.visitor.SQLStringVisitor;
/**
@@ -250,6 +255,25 @@
return false;
}
+ /**
+ * @see com.metamatrix.query.sql.lang.ProcedureContainer#getProcedureParameters()
+ * @since 5.0
+ */
+ public Map getProcedureParameters() {
+
+ HashMap map = new HashMap();
+
+ for (Iterator iter = getChangeList().getClauses().iterator(); iter.hasNext();) {
+ SetClause setClause = (SetClause)iter.next();
+ ElementSymbol symbol = (ElementSymbol)(setClause.getSymbol()).clone();
+ symbol.setName(ProcedureReservedWords.INPUT + SingleElementSymbol.SEPARATOR + symbol.getShortCanonicalName());
+ map.put( symbol, setClause.getValue() );
+
+ } // for
+
+ return map;
+ }
+
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/Reference.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/Reference.java 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/Reference.java 2009-02-24 21:52:30 UTC (rev 492)
@@ -23,6 +23,7 @@
package com.metamatrix.query.sql.symbol;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -109,6 +110,10 @@
}
public Object getValue(LookupEvaluator dataMgr, CommandContext context) throws ExpressionEvaluationException, MetaMatrixComponentException {
+ if ( elements == null ) {
+ elements = Collections.EMPTY_MAP;
+ }
+
return new Evaluator(elements, dataMgr, context).evaluate(expression, tuple);
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java 2009-02-24 21:52:30 UTC (rev 492)
@@ -278,26 +278,7 @@
}
obj.setRowLimit(replaceExpression(obj.getRowLimit()));
}
-
- public void visit(Insert obj) {
- // iterate over the list containing virtual elements/constants
- Iterator valuesIter = obj.getValues().iterator();
-
- // create a new list containing physical elements and constants
- List valuesList = new ArrayList(obj.getValues().size());
- while(valuesIter.hasNext()) {
- Expression exp = (Expression) valuesIter.next();
- valuesList.add( replaceExpression(exp) );
- }
- obj.setValues(valuesList);
- }
-
- public void visit(AssignmentStatement obj) {
- if (obj.hasExpression()) {
- obj.setExpression(replaceExpression(obj.getExpression()));
- }
- }
-
+
public void visit(DynamicCommand obj) {
obj.setSql(replaceExpression(obj.getSql()));
if (obj.getUsing() != null) {
@@ -342,5 +323,25 @@
protected Map getVariableValues() {
return symbolMap;
}
-
+
+ /**
+ * @see com.metamatrix.query.sql.LanguageVisitor#visit(com.metamatrix.query.sql.proc.AssignmentStatement)
+ * @since 5.0
+ */
+ public void visit(AssignmentStatement obj) {
+ if (obj.hasExpression()) {
+ obj.setExpression(replaceExpression(obj.getExpression()));
+ }
+ }
+
+ /**
+ * @see com.metamatrix.query.sql.LanguageVisitor#visit(com.metamatrix.query.sql.lang.Insert)
+ * @since 5.0
+ */
+ public void visit(Insert obj) {
+ for (int i = 0; i < obj.getValues().size(); i++) {
+ obj.getValues().set(i, replaceExpression((Expression)obj.getValues().get(i)));
+ }
+ }
+
}
Modified: trunk/engine/src/main/resources/com/metamatrix/query/execution/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/com/metamatrix/query/execution/i18n.properties 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/main/resources/com/metamatrix/query/execution/i18n.properties 2009-02-24 21:52:30 UTC (rev 492)
@@ -195,8 +195,8 @@
tuple_not_found=Tuple source results for the mapping class {0} are not found;
unmapped_reference=Reference value for {0} is not supplied; can not continue.
RulePlanProcedures.no_values=No valid criteria specified for procedure parameter {0}
-RulePlanProcedures.nonNullableParam=The procedure parameter is not nullable, but is set to null: {0}
-
+ProcedurePlan.nonNullableParam=The procedure parameter is not nullable, but is set to null: {0}
+
BufferManagerImpl.no_memory_available=No memory available
BufferManagerImpl.tuple_source_not_found=Tuple source does not exist: {0}
FileStoreageManager.file_exists=Unable to create {0} as it already exists
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcedureRelational.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcedureRelational.java 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcedureRelational.java 2009-02-24 21:52:30 UTC (rev 492)
@@ -27,6 +27,7 @@
import junit.framework.TestCase;
+import com.metamatrix.api.exception.query.QueryValidatorException;
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.dqp.message.ParameterInfo;
import com.metamatrix.query.mapping.relational.QueryNode;
@@ -523,7 +524,24 @@
TestProcedureProcessor.helpTestProcess(plan, expected, new FakeDataManager());
}
-
+
+ //virtual group with procedure in transformation
+ public void testCase6395ProcAsVirtualGroup9(){
+ String sql = "SELECT P.e2 as ve3, P.e1 as ve4 FROM pm1.vsp47 as P where param1=1 and param2='a' OPTION DEBUG"; //$NON-NLS-1$
+
+ // Create expected results
+ List[] expected = new List[] {
+ Arrays.asList(new Object[] { new Integer(1), "FOO" }), //$NON-NLS-1$
+ };
+ // Construct data manager with data
+ FakeDataManager dataManager = new FakeDataManager();
+ TestProcessor.sampleData1(dataManager);
+ // Plan query
+ ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+ // Run query
+ TestProcessor.helpProcess(plan, dataManager, expected);
+ }
+
/**
* Case 6395 - This test case will now raise a QueryPlannerException. param2 is required
* and not nullable. This case is expected to fail because of 'param2 is null'
@@ -538,16 +556,14 @@
FakeDataManager dataManager = new FakeDataManager();
TestProcessor.sampleData1(dataManager);
// Plan query
- ProcessorPlan plan = null;
try {
- plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+ ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
// Run query
- TestProcessor.helpProcess(plan, dataManager, expected);
- } catch (Exception e) {
+ TestProcessor.doProcess(plan, dataManager, expected, TestProcessor.createCommandContext());
+ fail("QueryPlannerException was expected."); //$NON-NLS-1$
+ } catch (QueryValidatorException e) {
assertEquals("The procedure parameter is not nullable, but is set to null: pm1.vsp26.param2",e.getMessage()); //$NON-NLS-1$
- return;
}
- fail("QueryPlannerException was expected."); //$NON-NLS-1$
}
/**
@@ -569,6 +585,24 @@
// Run query
TestProcessor.helpProcess(plan, dataManager, expected);
}
+
+ /**
+ * Case 6395 - This will not throw an exception and the proc will not be invoked.
+ */
+ public void testProcAsVirtualGroup2WithNull3() throws Exception {
+ String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where param1=1 and param2 = commandpayload()"; //$NON-NLS-1$
+
+ // Create expected results
+ List[] expected = new List[] {
+ };
+ // Construct data manager with data
+ FakeDataManager dataManager = new FakeDataManager();
+ TestProcessor.sampleData1(dataManager);
+ // Plan query
+ ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+ // Run query
+ TestProcessor.helpProcess(plan, dataManager, expected);
+ }
/*
* The following are tests that were removed from the validator. We are no longer trying to validate a priori whether
Modified: trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-02-24 18:28:11 UTC (rev 491)
+++ trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-02-24 21:52:30 UTC (rev 492)
@@ -22,54 +22,55 @@
package com.metamatrix.query.rewriter;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Properties;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Properties;
import java.util.TimeZone;
+
+import junit.framework.TestCase;
+
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixException;
+import com.metamatrix.api.exception.query.QueryMetadataException;
+import com.metamatrix.api.exception.query.QueryParserException;
+import com.metamatrix.api.exception.query.QueryResolverException;
+import com.metamatrix.api.exception.query.QueryValidatorException;
+import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.core.MetaMatrixRuntimeException;
+import com.metamatrix.dqp.message.ParameterInfo;
+import com.metamatrix.query.metadata.QueryMetadataInterface;
+import com.metamatrix.query.parser.QueryParser;
+import com.metamatrix.query.resolver.QueryResolver;
+import com.metamatrix.query.sql.lang.Command;
+import com.metamatrix.query.sql.lang.CompareCriteria;
+import com.metamatrix.query.sql.lang.CompoundCriteria;
+import com.metamatrix.query.sql.lang.Criteria;
+import com.metamatrix.query.sql.lang.MatchCriteria;
+import com.metamatrix.query.sql.lang.Query;
+import com.metamatrix.query.sql.lang.QueryCommand;
+import com.metamatrix.query.sql.lang.SPParameter;
+import com.metamatrix.query.sql.lang.SetCriteria;
+import com.metamatrix.query.sql.lang.SetQuery;
+import com.metamatrix.query.sql.lang.StoredProcedure;
+import com.metamatrix.query.sql.lang.Update;
+import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
+import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import com.metamatrix.query.sql.symbol.Function;
+import com.metamatrix.query.sql.symbol.GroupSymbol;
+import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.visitor.CorrelatedReferenceCollectorVisitor;
+import com.metamatrix.query.unittest.FakeMetadataFacade;
+import com.metamatrix.query.unittest.FakeMetadataFactory;
+import com.metamatrix.query.unittest.FakeMetadataObject;
+import com.metamatrix.query.util.CommandContext;
+import com.metamatrix.query.util.ContextProperties;
-import junit.framework.TestCase;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.dqp.message.ParameterInfo;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.CompoundCriteria;
-import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.lang.MatchCriteria;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.QueryCommand;
-import com.metamatrix.query.sql.lang.SPParameter;
-import com.metamatrix.query.sql.lang.SetCriteria;
-import com.metamatrix.query.sql.lang.SetQuery;
-import com.metamatrix.query.sql.lang.StoredProcedure;
-import com.metamatrix.query.sql.lang.Update;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
-import com.metamatrix.query.sql.visitor.CorrelatedReferenceCollectorVisitor;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-import com.metamatrix.query.util.CommandContext;
-import com.metamatrix.query.util.ContextProperties;
-
public class TestQueryRewriter extends TestCase {
private static final String TRUE_STR = "1 = 1"; //$NON-NLS-1$
@@ -176,7 +177,7 @@
private Command helpTestRewriteCommand(String original, String expected, QueryMetadataInterface metadata) throws MetaMatrixException {
Command command = QueryParser.getQueryParser().parseCommand(original);
QueryResolver.resolveCommand(command, metadata);
- Command rewriteCommand = QueryRewriter.rewrite(command, null, FakeMetadataFactory.example1Cached(), null);
+ Command rewriteCommand = QueryRewriter.rewrite(command, null, metadata, null);
assertEquals("Rewritten command was not expected", expected, rewriteCommand.toString()); //$NON-NLS-1$
return rewriteCommand;
}
@@ -1733,6 +1734,17 @@
public void testDefect16879_7(){
helpTestRewriteCommand("SELECT decodeinteger(e1, 'a, b, null, d, e') FROM pm1.g1", "SELECT CASE WHEN e1 = 'a' THEN 'b' WHEN e1 IS NULL THEN 'd' ELSE 'e' END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
}
+
+ public void testCaseExpressionThatResolvesToNull() {
+ String sqlBefore = "SELECT CASE 'x' WHEN 'Old Inventory System' THEN NULL WHEN 'New Inventory System' THEN NULL END"; //$NON-NLS-1$
+ String sqlAfter = "SELECT null"; //$NON-NLS-1$
+
+ Command cmd = helpTestRewriteCommand( sqlBefore, sqlAfter );
+
+ ExpressionSymbol es = (ExpressionSymbol)cmd.getProjectedSymbols().get(0);
+ assertEquals( DataTypeManager.DefaultDataClasses.STRING, es.getType() );
+ }
+
//note that the env is now treated as deterministic, however it is really only deterministic within a session
public void testRewriteExecEnv() throws Exception {
@@ -2097,5 +2109,17 @@
public void testRewriteCoalesce() throws Exception {
helpTestRewriteCriteria("coalesce(convert(pm1.g1.e2, double), pm1.g1.e4) = 1", "ifnull(convert(pm1.g1.e2, double), pm1.g1.e4) = 1", true); //$NON-NLS-1$ //$NON-NLS-2$
}
+
+ public void testProcWithNull() throws Exception {
+ String sql = "exec pm1.vsp26(1, null)"; //$NON-NLS-1$
+
+ try {
+ helpTestRewriteCommand(sql, "", FakeMetadataFactory.example1Cached());
+ fail("expected exception");
+ } catch (QueryValidatorException e) {
+
+ }
+
+ }
}
15 years, 10 months
teiid SVN: r491 - in trunk: connector-api/src/main/java/com/metamatrix/connector/visitor/util and 51 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-02-24 13:28:11 -0500 (Tue, 24 Feb 2009)
New Revision: 491
Added:
trunk/connectors/connector-jdbc/src/main/java/org/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCBaseExecution.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCExecutionHelper.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCPlugin.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCProcedureExecution.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCPropertyNames.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCQueryExecution.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCSourceConnection.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCUpdateExecution.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/SimpleCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/access/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2ConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/informix/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mm/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ConcatFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/DayWeekQuarterFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ExtractFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/LeftOrRightFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/LocateFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/Log10FunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/MonthOrDayNameFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/DatePartFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/ModifiedDatePartFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/ssl/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/ModFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/teradata/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/BasicFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/DropFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/FunctionReplacementVisitor.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SubstringFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/xa/
trunk/connectors/connector-jdbc/src/main/resources/org/
trunk/connectors/connector-jdbc/src/main/resources/org/teiid/
trunk/connectors/connector-jdbc/src/main/resources/org/teiid/connector/
trunk/connectors/connector-jdbc/src/main/resources/org/teiid/connector/jdbc/
trunk/connectors/connector-jdbc/src/test/java/org/
trunk/connectors/connector-jdbc/src/test/java/org/teiid/
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/FakeConnection.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/MetadataFactory.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCSourceConnection.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/access/
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2ConvertModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyConvertModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestDropFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestEscapeSyntaxModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestDayWeekQuarterFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestExtractFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLeftOrRightFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLocateFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLog10FunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestMonthOrDayNameFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleConvertModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestSubstringFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/util/
Removed:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCBaseExecution.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCConnector.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCPlugin.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCProcedureExecution.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCPropertyNames.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCQueryExecution.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCSourceConnection.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCUpdateExecution.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/SimpleCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/access/
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mm/
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/ssl/
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/teradata/
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/translator/
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/util/
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/xa/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2ConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ConcatFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/DayWeekQuarterFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ExtractFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/LeftOrRightFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/LocateFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/Log10FunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/MonthOrDayNameFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/DatePartFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/ModifiedDatePartFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/ModFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/BasicFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/DropFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SubstringFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/resources/com/
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/FakeConnection.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/MetadataFactory.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/TestJDBCSourceConnection.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/access/
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/db2/
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/derby/
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/extension/impl/
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/mysql/
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/postgresql/
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sqlserver/
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/util/
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2ConvertModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyConvertModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestDropFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestEscapeSyntaxModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestDayWeekQuarterFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestExtractFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLeftOrRightFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLocateFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLog10FunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestMonthOrDayNameFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleConvertModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestSubstringFunctionModifier.java
Modified:
trunk/connector-api/src/main/java/com/metamatrix/connector/api/ConnectorAnnotations.java
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/util/CollectorVisitor.java
trunk/connector-api/src/main/java/com/metamatrix/connector/xa/api/TransactionContext.java
trunk/connector-api/src/main/java/com/metamatrix/connector/xa/api/XAConnection.java
trunk/connector-api/src/main/java/com/metamatrix/connector/xa/api/XAConnector.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/access/AccessCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/access/AccessSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2Capabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbySQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/informix/InformixCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/informix/InformixSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mm/MMCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/ssl/SequeLinkOracleCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/teradata/TeradataCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/AliasModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/BindValueVisitor.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/EscapeSyntaxModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/FunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/TranslatedCommand.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/xa/JDBCSourceXAConnection.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/xa/XAJDBCPropertyNames.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/access/TestAccessSQLTranslator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2SqlTranslator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleTranslator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseConvertModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/util/TestFunctionReplacementVisitor.java
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialCapabilities.java
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialConnector.java
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialFunctionModifier.java
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialSQLTranslator.java
trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/Request.java
trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/RequestWorkItem.java
trunk/engine/src/main/java/com/metamatrix/dqp/internal/transaction/TransactionContextImpl.java
trunk/engine/src/main/java/com/metamatrix/dqp/internal/transaction/TransactionServerImpl.java
trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java
trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java
trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/util/TestJDBCExecutionHelper.java
trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestTPCR.java
trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestXMLTypeTranslations.java
Log:
TEIID-164 repackaging the JDBC connector classes
Modified: trunk/connector-api/src/main/java/com/metamatrix/connector/api/ConnectorAnnotations.java
===================================================================
--- trunk/connector-api/src/main/java/com/metamatrix/connector/api/ConnectorAnnotations.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connector-api/src/main/java/com/metamatrix/connector/api/ConnectorAnnotations.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -51,12 +51,4 @@
boolean enabled() default true;
}
- @Retention(RetentionPolicy.RUNTIME)
- @Target({ElementType.TYPE})
- public @interface ConnectorConfiguration {
- boolean userIdentityCapable() default false;
- boolean useSynchronousWorkers() default true;
- boolean useConnectionPooling() default true;
- }
-
}
Modified: trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/util/CollectorVisitor.java
===================================================================
--- trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/util/CollectorVisitor.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/util/CollectorVisitor.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -42,7 +42,8 @@
this.type = type;
}
- private void checkInstance(ILanguageObject obj) {
+ @SuppressWarnings("unchecked")
+ private void checkInstance(ILanguageObject obj) {
if(type.isInstance(obj)) {
this.objects.add((T)obj);
}
Modified: trunk/connector-api/src/main/java/com/metamatrix/connector/xa/api/TransactionContext.java
===================================================================
--- trunk/connector-api/src/main/java/com/metamatrix/connector/xa/api/TransactionContext.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connector-api/src/main/java/com/metamatrix/connector/xa/api/TransactionContext.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -29,12 +29,14 @@
*/
public interface TransactionContext {
- public static final int TRANSACTION_GLOBAL = 0;
- public static final int TRANSACTION_LOCAL = 1;
- public static final int TRANSACTION_REQUEST = 2;
- public static final int TRANSACTION_BLOCK = 3;
- public static final int TRANSACTION_NONE = 4;
-
+ public enum Scope {
+ TRANSACTION_BLOCK,
+ TRANSACTION_GLOBAL,
+ TRANSACTION_LOCAL,
+ TRANSACTION_NONE,
+ TRANSACTION_REQUEST
+ }
+
public boolean isInTransaction();
/**
@@ -47,5 +49,5 @@
*/
public String getTxnID();
- public int getTransactionType();
+ public Scope getTransactionType();
}
Modified: trunk/connector-api/src/main/java/com/metamatrix/connector/xa/api/XAConnection.java
===================================================================
--- trunk/connector-api/src/main/java/com/metamatrix/connector/xa/api/XAConnection.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connector-api/src/main/java/com/metamatrix/connector/xa/api/XAConnection.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -31,9 +31,8 @@
public interface XAConnection extends Connection{
/**
- * Get XAResource for this connection if the underlining data source is to be
- * involved in a distributed transaction.
- * @return
+ * Get XAResource for this connection
+ * @return the XAResource, never null
*/
XAResource getXAResource() throws ConnectorException;
Modified: trunk/connector-api/src/main/java/com/metamatrix/connector/xa/api/XAConnector.java
===================================================================
--- trunk/connector-api/src/main/java/com/metamatrix/connector/xa/api/XAConnector.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connector-api/src/main/java/com/metamatrix/connector/xa/api/XAConnector.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -32,9 +32,7 @@
/**
* Obtain a connection with the connector. The connection must have XAResource in
* order to participate in distributed transaction. The connection typically is associated
- * with a particular security context. The connection is assumed to be pooled in
- * the underlying source if pooling is necessary - the connection will be closed
- * when execution has completed against it.
+ * with a particular context.
* @param context The context of the current user that will be using this connection,
* may be null if this connection is for an administrative operation.
* @param transactionContext The context of the transaction under which the connection will be used. May be null.
Deleted: trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCBaseExecution.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCBaseExecution.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCBaseExecution.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,286 +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 com.metamatrix.connector.jdbc;
-
-import java.sql.CallableStatement;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.sql.SQLWarning;
-import java.sql.Statement;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-
-import com.metamatrix.common.util.PropertiesUtils;
-import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.api.ConnectorIdentity;
-import com.metamatrix.connector.api.ConnectorLogger;
-import com.metamatrix.connector.api.ExecutionContext;
-import com.metamatrix.connector.basic.BasicExecution;
-import com.metamatrix.connector.jdbc.translator.TranslatedCommand;
-import com.metamatrix.connector.jdbc.translator.Translator;
-import com.metamatrix.connector.language.ICommand;
-
-/**
- */
-public abstract class JDBCBaseExecution extends BasicExecution {
-
- // ===========================================================================================================================
- // Fields
- // ===========================================================================================================================
-
- // Passed to constructor
- protected Connection connection;
- protected Translator sqlTranslator;
- protected ConnectorIdentity id;
- protected ConnectorLogger logger;
- protected ExecutionContext context;
-
- // Derived from properties
- protected boolean trimString;
- protected int fetchSize;
-
- // Set during execution
- protected Statement statement;
-
- // ===========================================================================================================================
- // Constructors
- // ===========================================================================================================================
-
- protected JDBCBaseExecution(Connection connection,
- Translator sqlTranslator,
- ConnectorLogger logger,
- Properties props,
- ExecutionContext context) {
- this.connection = connection;
- this.sqlTranslator = sqlTranslator;
- this.logger = logger;
- this.context = context;
-
- String propStr = props.getProperty(JDBCPropertyNames.TRIM_STRINGS);
- if (propStr != null) {
- trimString = Boolean.valueOf(propStr).booleanValue();
- }
-
- fetchSize = PropertiesUtils.getIntProperty(props, JDBCPropertyNames.FETCH_SIZE, context.getBatchSize());
- int max = sqlTranslator.getMaxResultRows();
- if (max > 0) {
- fetchSize = Math.min(fetchSize, max);
- }
- }
-
- // ===========================================================================================================================
- // Methods
- // ===========================================================================================================================
-
- private void addSql(TranslatedCommand command,
- StringBuffer message) {
- String sql = command.getSql();
- int ndx = sql.indexOf('?');
- if (ndx >= 0) {
- message.append(sql.substring(0, ndx));
- int len = sql.length();
- for (Iterator itr = command.getPreparedValues().iterator(); itr.hasNext() && ndx < len;) {
- message.append(itr.next());
- int nextNdx = sql.indexOf('?', ++ndx);
- if (nextNdx >= 0) {
- message.append(sql.substring(ndx, nextNdx));
- } else {
- message.append(sql.substring(ndx));
- }
- ndx = nextNdx;
- }
- } else {
- message.append(sql);
- }
- }
-
- /**
- * @param error
- * @param command
- * @return
- * @since 5.5
- */
- protected ConnectorException createAndLogError(SQLException error,
- TranslatedCommand command) {
- ConnectorException connectorErr = createError(error, command);
- this.logger.logError(connectorErr.getMessage());
- return connectorErr;
- }
-
- /**
- * @param error
- * @param messageKey
- * @param commands
- * @return
- * @throws ConnectorException
- * @since 5.5
- */
- protected ConnectorException createAndLogError(Throwable error,
- String messageKey,
- List commands) throws ConnectorException {
- String msg;
- if (commands.isEmpty()) {
- msg = error.getMessage();
- } else {
- msg = JDBCPlugin.Util.getString(messageKey, error.getMessage());
- StringBuffer buf = new StringBuffer(msg);
- for (Iterator itr = commands.iterator(); itr.hasNext();) {
- buf.append("\n "); //$NON-NLS-1$
- addSql((TranslatedCommand)itr.next(), buf);
- }
- msg = buf.toString();
- }
- this.logger.logError(msg);
- if (error instanceof ConnectorException) {
- error = ((ConnectorException)error).getCause();
- }
- throw new ConnectorException(error, msg);
- }
-
- /**
- * @param error
- * @param command
- * @return
- * @since 5.5
- */
- protected ConnectorException createError(SQLException error,
- TranslatedCommand command) {
- String msg = (command == null ? error.getMessage()
- : JDBCPlugin.Util.getString("JDBCQueryExecution.Error_executing_query__1", //$NON-NLS-1$
- error.getMessage(), createSql(command)));
- return new ConnectorException(error, msg);
- }
-
- private String createSql(TranslatedCommand command) {
- StringBuffer msg = new StringBuffer();
- addSql(command, msg);
- return msg.toString();
- }
-
- protected TranslatedCommand translateCommand(ICommand command) throws ConnectorException {
- TranslatedCommand translatedCommand = new TranslatedCommand(context, sqlTranslator);
- translatedCommand.translateCommand(command);
-
- if (translatedCommand.getSql() != null && this.logger.isDetailEnabled()) {
- this.logger.logDetail("Source-specific command: " + translatedCommand.getSql()); //$NON-NLS-1$
- }
-
- return translatedCommand;
- }
-
- /*
- * @see com.metamatrix.data.Execution#close()
- */
- public synchronized void close() throws ConnectorException {
- try {
- if (statement != null) {
- statement.close();
- }
- } catch (SQLException e) {
- throw new ConnectorException(e);
- }
- }
-
- /*
- * @see com.metamatrix.data.Execution#cancel()
- */
- public synchronized void cancel() throws ConnectorException {
- // if both the DBMS and driver support aborting an SQL
- try {
- if (statement != null) {
- statement.cancel();
- }
- } catch (SQLException e) {
- // Defect 16187 - DataDirect does not support the cancel() method for
- // Statement.cancel() for DB2 and Informix. Here we are tolerant
- // of these and other JDBC drivers that do not support the cancel() operation.
- }
- }
-
- protected void setSizeContraints(Statement statement) throws SQLException {
- if (sqlTranslator.getMaxResultRows() > 0) {
- statement.setMaxRows(sqlTranslator.getMaxResultRows());
- }
- statement.setFetchSize(fetchSize);
- }
-
- protected synchronized Statement getStatement() throws SQLException {
- if (statement != null) {
- statement.close();
- statement = null;
- }
- statement = connection.createStatement();
- setSizeContraints(statement);
- return statement;
- }
-
- protected synchronized CallableStatement getCallableStatement(String sql) throws SQLException {
- if (statement != null) {
- statement.close();
- statement = null;
- }
- statement = connection.prepareCall(sql);
- setSizeContraints(statement);
- return (CallableStatement)statement;
- }
-
- protected synchronized PreparedStatement getPreparedStatement(String sql) throws SQLException {
- if (statement != null) {
- statement.close();
- statement = null;
- }
- statement = connection.prepareStatement(sql);
- setSizeContraints(statement);
- return (PreparedStatement)statement;
- }
-
- /**
- * Returns the JDBC connection used by the execution object.
- *
- * @return Returns the connection.
- * @since 4.1.1
- */
- public Connection getConnection() {
- return this.connection;
- }
-
- public Translator getSqlTranslator() {
- return sqlTranslator;
- }
-
- public void addStatementWarnings() throws SQLException {
- SQLWarning warning = this.statement.getWarnings();
- while (warning != null) {
- SQLWarning toAdd = warning;
- warning = toAdd.getNextWarning();
- toAdd.setNextException(null);
- if (logger.isDetailEnabled()) {
- logger.logDetail(context.getRequestIdentifier() + " Warning: ", warning); //$NON-NLS-1$
- }
- context.addWarning(toAdd);
- }
- this.statement.clearWarnings();
- }
-}
Deleted: trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCCapabilities.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCCapabilities.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,399 +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 com.metamatrix.connector.jdbc;
-
-import java.util.Arrays;
-import java.util.List;
-
-import com.metamatrix.connector.basic.BasicConnectorCapabilities;
-
-/**
- */
-public class JDBCCapabilities extends BasicConnectorCapabilities {
-
- public static final int DEFAULT_JDBC_MAX_IN_CRITERIA_SIZE = 1000;
-
- /**
- *
- */
- public JDBCCapabilities() {
- this.setMaxInCriteriaSize(DEFAULT_JDBC_MAX_IN_CRITERIA_SIZE);
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#getSupportedFunctions()
- */
- public List getSupportedFunctions() {
- return Arrays.asList(new String[] { "+", "-", "*", "/" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- }
-
- /**
- * @see com.metamatrix.connector.basic.BasicConnectorCapabilities#getMaxInCriteriaSize()
- * @since 4.2
- */
- public int getMaxInCriteriaSize() {
- return maxInCriteriaSize;
- }
-
- public void setMaxInCriteriaSize(int maxInCriteriaSize) {
- this.maxInCriteriaSize = maxInCriteriaSize;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsAggregates()
- */
- public boolean supportsAggregates() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsAggregatesAvg()
- */
- public boolean supportsAggregatesAvg() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsAggregatesCount()
- */
- public boolean supportsAggregatesCount() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsAggregatesCountStar()
- */
- public boolean supportsAggregatesCountStar() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsAggregatesDistinct()
- */
- public boolean supportsAggregatesDistinct() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsAggregatesMax()
- */
- public boolean supportsAggregatesMax() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsAggregatesMin()
- */
- public boolean supportsAggregatesMin() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsAggregatesSum()
- */
- public boolean supportsAggregatesSum() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsAliasedGroup()
- */
- public boolean supportsAliasedGroup() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsAndCriteria()
- */
- public boolean supportsAndCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsBetweenCriteria()
- */
- public boolean supportsBetweenCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsCaseExpressions()
- */
- public boolean supportsCaseExpressions() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsCompareCriteria()
- */
- public boolean supportsCompareCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsCompareCriteriaEquals()
- */
- public boolean supportsCompareCriteriaEquals() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsCompareCriteriaGreaterThan()
- */
- public boolean supportsCompareCriteriaGreaterThan() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsCompareCriteriaGreaterThanOrEqual()
- */
- public boolean supportsCompareCriteriaGreaterThanOrEqual() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsCompareCriteriaLessThan()
- */
- public boolean supportsCompareCriteriaLessThan() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsCompareCriteriaLessThanOrEqual()
- */
- public boolean supportsCompareCriteriaLessThanOrEqual() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsCompareCriteriaNotEquals()
- */
- public boolean supportsCompareCriteriaNotEquals() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsCorrelatedSubqueries()
- */
- public boolean supportsCorrelatedSubqueries() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsCriteria()
- */
- public boolean supportsCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsExistsCriteria()
- */
- public boolean supportsExistsCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsFullOuterJoins()
- */
- public boolean supportsFullOuterJoins() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsInCriteria()
- */
- public boolean supportsInCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsInCriteriaSubquery()
- */
- public boolean supportsInCriteriaSubquery() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsIsNullCriteria()
- */
- public boolean supportsIsNullCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsJoins()
- */
- public boolean supportsJoins() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsLikeCriteria()
- */
- public boolean supportsLikeCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsLikeCriteriaEscapeCharacter()
- */
- public boolean supportsLikeCriteriaEscapeCharacter() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsNotCriteria()
- */
- public boolean supportsNotCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsOrCriteria()
- */
- public boolean supportsOrCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsOrderBy()
- */
- public boolean supportsOrderBy() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsOuterJoins()
- */
- public boolean supportsOuterJoins() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsQuantifiedCompareCriteria()
- */
- public boolean supportsQuantifiedCompareCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsQuantifiedCompareCriteriaAll()
- */
- public boolean supportsQuantifiedCompareCriteriaAll() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsScalarFunctions()
- */
- public boolean supportsScalarFunctions() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsScalarSubqueries()
- */
- public boolean supportsScalarSubqueries() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsSearchedCaseExpressions()
- */
- public boolean supportsSearchedCaseExpressions() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsSelectDistinct()
- */
- public boolean supportsSelectDistinct() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsSelectLiterals()
- */
- public boolean supportsSelectLiterals() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.ConnectorCapabilities#supportsSelfJoins()
- */
- public boolean supportsSelfJoins() {
- return true;
- }
-
- /**
- * @see com.metamatrix.connector.api.ConnectorCapabilities#supportsInlineViews()
- */
- public boolean supportsInlineViews() {
- return false;
- }
-
- public boolean supportsOrderByInInlineViews() {
- return false;
- }
-
- /**
- * @see com.metamatrix.connector.api.ConnectorCapabilities#supportsQuantifiedCompareCriteriaSome()
- */
- public boolean supportsQuantifiedCompareCriteriaSome() {
- return true;
- }
-
- /**
- * @see com.metamatrix.connector.api.ConnectorCapabilities#supportsUnionOrderBy()
- */
- public boolean supportsUnionOrderBy() {
- return true;
- }
-
- /**
- * @see com.metamatrix.connector.basic.BasicConnectorCapabilities#supportsSetQueryOrderBy()
- */
- @Override
- public boolean supportsSetQueryOrderBy() {
- return true;
- }
-
- /**
- * @see com.metamatrix.connector.api.ConnectorCapabilities#supportsUnions()
- */
- public boolean supportsUnions() {
- return true;
- }
-
- @Override
- public boolean supportsBulkInsert() {
- return true;
- }
-
- @Override
- public boolean supportsBatchedUpdates() {
- return true;
- }
-
-}
Deleted: trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCConnector.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCConnector.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCConnector.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,390 +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 com.metamatrix.connector.jdbc;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.sql.Driver;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.Enumeration;
-import java.util.Properties;
-
-import javax.sql.DataSource;
-import javax.sql.XADataSource;
-
-import com.metamatrix.common.util.PropertiesUtils;
-import com.metamatrix.connector.api.Connection;
-import com.metamatrix.connector.api.ConnectorCapabilities;
-import com.metamatrix.connector.api.ConnectorEnvironment;
-import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.api.ConnectorLogger;
-import com.metamatrix.connector.api.ExecutionContext;
-import com.metamatrix.connector.api.SingleIdentity;
-import com.metamatrix.connector.api.MappedUserIdentity;
-import com.metamatrix.connector.api.ConnectorAnnotations.ConnectionPooling;
-import com.metamatrix.connector.basic.BasicConnector;
-import com.metamatrix.connector.internal.ConnectorPropertyNames;
-import com.metamatrix.connector.jdbc.translator.Translator;
-import com.metamatrix.connector.jdbc.xa.JDBCSourceXAConnection;
-import com.metamatrix.connector.jdbc.xa.XAJDBCPropertyNames;
-import com.metamatrix.connector.xa.api.TransactionContext;
-import com.metamatrix.connector.xa.api.XAConnection;
-import com.metamatrix.connector.xa.api.XAConnector;
-import com.metamatrix.core.MetaMatrixCoreException;
-import com.metamatrix.core.util.ReflectionHelper;
-
-/**
- * JDBC implementation of Connector interface.
- */
-@ConnectionPooling
-public class JDBCConnector extends BasicConnector implements XAConnector {
-
- public static final String INVALID_AUTHORIZATION_SPECIFICATION_NO_SUBCLASS = "28000"; //$NON-NLS-1$
-
- static final int NO_ISOLATION_LEVEL_SET = Integer.MIN_VALUE;
-
- enum TransactionIsolationLevel {
- TRANSACTION_READ_UNCOMMITTED(java.sql.Connection.TRANSACTION_READ_UNCOMMITTED),
- TRANSACTION_READ_COMMITTED(java.sql.Connection.TRANSACTION_READ_COMMITTED),
- TRANSACTION_REPEATABLE_READ(java.sql.Connection.TRANSACTION_REPEATABLE_READ),
- TRANSACTION_SERIALIZABLE(java.sql.Connection.TRANSACTION_SERIALIZABLE),
- TRANSACTION_NONE(java.sql.Connection.TRANSACTION_NONE);
-
- private int connectionContant;
-
- private TransactionIsolationLevel(int connectionConstant) {
- this.connectionContant = connectionConstant;
- }
-
- public int getConnectionConstant() {
- return connectionContant;
- }
- }
-
- protected ConnectorEnvironment environment;
- private ConnectorLogger logger;
- private ConnectorCapabilities capabilities;
- private Translator sqlTranslator;
- private DataSource ds;
- private XADataSource xaDs;
- private int transIsoLevel = NO_ISOLATION_LEVEL_SET;
-
- @Override
- public void start(ConnectorEnvironment environment)
- throws ConnectorException {
- logger = environment.getLogger();
- this.environment = environment;
-
- logger.logInfo(JDBCPlugin.Util.getString("JDBCConnector.JDBCConnector_initialized._1")); //$NON-NLS-1$
-
- capabilities = createCapabilities(environment, Thread.currentThread().getContextClassLoader());
-
- Properties connectionProps = environment.getProperties();
-
- // Get the JDBC properties ...
- String dataSourceClassName = connectionProps.getProperty(JDBCPropertyNames.CONNECTION_SOURCE_CLASS);
-
- // Verify required items
- if (dataSourceClassName == null || dataSourceClassName.trim().length() == 0) {
- throw new ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.Missing_JDBC_driver_class_name_1")); //$NON-NLS-1$
- }
- dataSourceClassName = dataSourceClassName.trim();
-
- String levelStr = connectionProps.getProperty(JDBCPropertyNames.TRANSACTION_ISOLATION_LEVEL);
-
- if(levelStr != null && levelStr.trim().length() != 0){
- transIsoLevel = TransactionIsolationLevel.valueOf(levelStr.toUpperCase()).getConnectionConstant();
- }
-
- try {
- String className = environment.getProperties().getProperty(JDBCPropertyNames.EXT_TRANSLATOR_CLASS, Translator.class.getName());
- this.sqlTranslator = (Translator)ReflectionHelper.create(className, null, Thread.currentThread().getContextClassLoader());
- } catch (MetaMatrixCoreException e) {
- throw new ConnectorException(e);
- }
- sqlTranslator.initialize(environment);
-
- if (areAdminConnectionsAllowed()) {
- testConnection();
- }
-
- logger.logInfo(JDBCPlugin.Util.getString("JDBCConnector.JDBCConnector_started._4")); //$NON-NLS-1$
- }
-
- private void testConnection() throws ConnectorException {
- Connection connection = null;
- try {
- connection = getConnection(null);
- } catch (ConnectorException e) {
- SQLException ex = (SQLException)e.getCause();
- String sqlState = ex.getSQLState();
- if (sqlState != null && INVALID_AUTHORIZATION_SPECIFICATION_NO_SUBCLASS.equals(sqlState)) {
- throw e;
- }
- this.logger.logError(e.getMessage(), e);
- } finally {
- if (connection != null) {
- connection.close();
- }
- }
- }
-
- @Override
- public void stop() {
- /*
- * attempt to deregister drivers that may have been implicitly registered
- * with the driver manager
- */
- Enumeration drivers = DriverManager.getDrivers();
-
- String driverClassname = this.environment.getProperties().getProperty(JDBCPropertyNames.CONNECTION_SOURCE_CLASS);
- boolean usingCustomClassLoader = PropertiesUtils.getBooleanProperty(this.environment.getProperties(), ConnectorPropertyNames.USING_CUSTOM_CLASSLOADER, false);
-
- while(drivers.hasMoreElements()){
- Driver tempdriver = (Driver)drivers.nextElement();
- if(tempdriver.getClass().getClassLoader() != this.getClass().getClassLoader()) {
- continue;
- }
- if(usingCustomClassLoader || tempdriver.getClass().getName().equals(driverClassname)) {
- try {
- DriverManager.deregisterDriver(tempdriver);
- } catch (Throwable e) {
- this.environment.getLogger().logError(e.getMessage());
- }
- }
- }
-
- logger.logInfo(JDBCPlugin.Util.getString("JDBCConnector.JDBCConnector_stopped._3")); //$NON-NLS-1$
- }
-
- @Override
- public Connection getConnection(ExecutionContext context) throws ConnectorException {
- DataSource dataSource = getDataSource();
- if (dataSource == null) {
- return getXAConnection(context, null);
- }
- java.sql.Connection conn = null;
- try {
- if (context == null || context.getConnectorIdentity() instanceof SingleIdentity) {
- conn = dataSource.getConnection();
- } else if (context.getConnectorIdentity() instanceof MappedUserIdentity) {
- MappedUserIdentity id = (MappedUserIdentity)context.getConnectorIdentity();
- conn = dataSource.getConnection(id.getMappedUser(), id.getPassword());
- }
- setDefaultTransactionIsolationLevel(conn);
- } catch (SQLException e) {
- throw new ConnectorException(e);
- }
- return new JDBCSourceConnection(conn, this.environment, sqlTranslator);
- }
-
- @Override
- public XAConnection getXAConnection(
- ExecutionContext context,
- TransactionContext transactionContext) throws ConnectorException {
- XADataSource xaDataSource = getXADataSource();
- if (xaDataSource == null) {
- throw new UnsupportedOperationException("Connector is not XA capable");
- }
- javax.sql.XAConnection conn = null;
- try {
- if (context == null || context.getConnectorIdentity() instanceof SingleIdentity) {
- conn = xaDataSource.getXAConnection();
- } else if (context.getConnectorIdentity() instanceof MappedUserIdentity) {
- MappedUserIdentity id = (MappedUserIdentity)context.getConnectorIdentity();
- conn = xaDataSource.getXAConnection(id.getMappedUser(), id.getPassword());
- }
- java.sql.Connection c = conn.getConnection();
- setDefaultTransactionIsolationLevel(c);
- return new JDBCSourceXAConnection(c, conn, this.environment, sqlTranslator);
- } catch (SQLException e) {
- throw new ConnectorException(e);
- }
- }
-
- @Override
- public ConnectorCapabilities getCapabilities() {
- return capabilities;
- }
-
- static ConnectorCapabilities createCapabilities(ConnectorEnvironment environment, ClassLoader loader)
- throws ConnectorException {
- //create Capabilities
- String className = environment.getProperties().getProperty(JDBCPropertyNames.EXT_CAPABILITY_CLASS, JDBCCapabilities.class.getName());
- try {
- ConnectorCapabilities result = (ConnectorCapabilities)ReflectionHelper.create(className, null, loader);
- if(result instanceof JDBCCapabilities) {
- String setCriteriaBatchSize = environment.getProperties().getProperty(JDBCPropertyNames.SET_CRITERIA_BATCH_SIZE);
- if(setCriteriaBatchSize != null) {
- int maxInCriteriaSize = Integer.parseInt(setCriteriaBatchSize);
- if(maxInCriteriaSize > 0) {
- ((JDBCCapabilities)result).setMaxInCriteriaSize(maxInCriteriaSize);
- }
- }
- }
- return result;
- } catch (Exception e) {
- throw new ConnectorException(e);
- }
- }
-
- protected void createDataSources(String dataSourceClassName, final Properties connectionProps) throws ConnectorException {
- // create data source
- Object temp = null;
- try {
- temp = ReflectionHelper.create(dataSourceClassName, null, Thread.currentThread().getContextClassLoader());
- } catch (MetaMatrixCoreException e) {
- throw new ConnectorException(e,JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.Unable_to_load_the_JDBC_driver_class_6", dataSourceClassName)); //$NON-NLS-1$
- }
-
- final String url = connectionProps.getProperty(JDBCPropertyNames.URL);
- if (url == null || url.trim().length() == 0) {
- throw new ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.Missing_JDBC_database_name_3")); //$NON-NLS-1$
- }
-
- if (temp instanceof Driver) {
- final Driver driver = (Driver)temp;
- // check URL if there is one
- validateURL(driver, url);
- this.ds = (DataSource)Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] {DataSource.class}, new InvocationHandler() {
- @Override
- public Object invoke(Object proxy, Method method,
- Object[] args) throws Throwable {
- if (method.getName().equals("getConnection")) {
- Properties p = new Properties();
- if (args.length == 2) {
- p.put("user", args[0]);
- p.put("password", args[1]);
- } else {
- p.put("user", connectionProps.getProperty(JDBCPropertyNames.USERNAME));
- p.put("password", connectionProps.getProperty(JDBCPropertyNames.PASSWORD));
- }
- return driver.connect(url, p);
- }
- throw new UnsupportedOperationException("Driver DataSource proxy only provides Connections");
- }
- });
- } else {
- parseURL(url, connectionProps);
- if (temp instanceof DataSource) {
- this.ds = (DataSource)temp;
- PropertiesUtils.setBeanProperties(this.ds, connectionProps, null);
- } else if (temp instanceof XADataSource) {
- this.xaDs = (XADataSource)temp;
- PropertiesUtils.setBeanProperties(this.xaDs, connectionProps, null);
- } else {
- throw new ConnectorException("Specified class is not a XADataSource, DataSource, or Driver " + dataSourceClassName);
- }
- }
- if (this.ds instanceof XADataSource) {
- this.xaDs = (XADataSource)this.ds;
- }
- }
-
- public DataSource getDataSource() {
- return ds;
- }
-
- public XADataSource getXADataSource() {
- return xaDs;
- }
-
- private void validateURL(Driver driver, String url) throws ConnectorException {
- boolean acceptsURL = false;
- try {
- acceptsURL = driver.acceptsURL(url);
- } catch ( SQLException e ) {
- throw new ConnectorException(e);
- }
- if(!acceptsURL ){
- throw new ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.Driver__7", driver.getClass().getName(), url)); //$NON-NLS-1$
- }
- }
-
- /**
- * Parse URL for DataSource connection properties and add to connectionProps.
- * @param url
- * @param connectionProps
- * @throws ConnectorException
- */
- static void parseURL(final String url, final Properties connectionProps) throws ConnectorException {
- // Will be: [jdbc:mmx:dbType://aHost:aPort], [DatabaseName=aDataBase], [CollectionID=aCollectionID], ...
- final String[] urlParts = url.split(";"); //$NON-NLS-1$
-
- // Will be: [jdbc:mmx:dbType:], [aHost:aPort]
- final String[] protoHost = urlParts[0].split("//"); //$NON-NLS-1$
-
- // Will be: [aHost], [aPort]
- final String[] hostPort = protoHost[1].split(":"); //$NON-NLS-1$
- connectionProps.setProperty(XAJDBCPropertyNames.SERVER_NAME, (String)hostPort[0]);
- connectionProps.setProperty(XAJDBCPropertyNames.PORT_NUMBER, (String)hostPort[1]);
-
- // For "databaseName", "SID", and all optional props
- // (<propName1>=<propValue1>;<propName2>=<propValue2>;...)
- for ( int i = 1; i < urlParts.length; i++ ) {
- final String nameVal = (String) urlParts[i];
- // Will be: [propName], [propVal]
- final String[] aProp = nameVal.split("="); //$NON-NLS-1$
- if ( aProp.length > 1) {
- // Set optional prop names lower case so that we can find
- // set method names for them when we introspect the DataSource
- connectionProps.setProperty(aProp[0].toLowerCase(), aProp[1]);
- }
- }
-
- String serverName = connectionProps.getProperty(XAJDBCPropertyNames.SERVER_NAME);
- String serverPort = connectionProps.getProperty(XAJDBCPropertyNames.PORT_NUMBER);
- if ( serverName == null || serverName.trim().length() == 0 ) {
- throw new ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.MissingProp", //$NON-NLS-1$
- XAJDBCPropertyNames.SERVER_NAME));
- }
- if ( serverPort == null || serverPort.trim().length() == 0 ) {
- throw new ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.MissingProp", //$NON-NLS-1$
- XAJDBCPropertyNames.PORT_NUMBER));
- }
-
- // Unique resource name for this connector
- final StringBuffer dataSourceResourceName = new StringBuffer(connectionProps.getProperty(XAJDBCPropertyNames.DATASOURCE_NAME, "XADS")); //$NON-NLS-1$
- dataSourceResourceName.append('_');
- dataSourceResourceName.append(serverName);
- dataSourceResourceName.append('_');
- dataSourceResourceName.append(connectionProps.getProperty(ConnectorPropertyNames.CONNECTOR_ID));
- connectionProps.setProperty( XAJDBCPropertyNames.DATASOURCE_NAME, dataSourceResourceName.toString());
- }
-
- public int getDefaultTransactionIsolationLevel() {
- return this.transIsoLevel;
- }
-
- protected void setDefaultTransactionIsolationLevel(java.sql.Connection sqlConn)
- throws SQLException {
- if(getDefaultTransactionIsolationLevel() != NO_ISOLATION_LEVEL_SET && getDefaultTransactionIsolationLevel() != java.sql.Connection.TRANSACTION_NONE){
- sqlConn.setTransactionIsolation(getDefaultTransactionIsolationLevel());
- }
- }
-
-}
Deleted: trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCPlugin.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCPlugin.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCPlugin.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,45 +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 com.metamatrix.connector.jdbc;
-
-import java.util.ResourceBundle;
-import com.metamatrix.core.BundleUtil;
-
-/**
- * CommonPlugin
- * <p>Used here in <code>data</code> to have access to the new
- * logging framework for <code>LogManager</code>.</p>
- */
-public class JDBCPlugin { // extends Plugin {
-
- /**
- * The plug-in identifier of this plugin
- * (value <code>"com.metamatrix.data"</code>).
- */
- public static final String PLUGIN_ID = "com.metamatrix.connector.jdbc" ; //$NON-NLS-1$
-
- public static final BundleUtil Util = new BundleUtil(PLUGIN_ID,
- PLUGIN_ID + ".i18n", ResourceBundle.getBundle(PLUGIN_ID + ".i18n")); //$NON-NLS-1$ //$NON-NLS-2$
-}
Deleted: trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCProcedureExecution.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCProcedureExecution.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCProcedureExecution.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,197 +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 com.metamatrix.connector.jdbc;
-
-import java.sql.CallableStatement;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import com.metamatrix.connector.api.ConnectorEnvironment;
-import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.api.ConnectorLogger;
-import com.metamatrix.connector.api.DataNotAvailableException;
-import com.metamatrix.connector.api.ExecutionContext;
-import com.metamatrix.connector.api.ProcedureExecution;
-import com.metamatrix.connector.jdbc.translator.TranslatedCommand;
-import com.metamatrix.connector.jdbc.translator.Translator;
-import com.metamatrix.connector.jdbc.util.JDBCExecutionHelper;
-import com.metamatrix.connector.language.ICommand;
-import com.metamatrix.connector.language.IParameter;
-import com.metamatrix.connector.language.IProcedure;
-import com.metamatrix.connector.language.IParameter.Direction;
-import com.metamatrix.connector.metadata.runtime.Element;
-import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
-
-/**
- */
-public class JDBCProcedureExecution extends JDBCQueryExecution implements ProcedureExecution {
-
- private Map parameterIndexMap;
- private RuntimeMetadata metadata;
-
- /**
- * @param connection
- * @param sqlTranslator
- * @param logger
- * @param props
- * @param id
- */
- public JDBCProcedureExecution(ICommand command,
- Connection connection,
- Translator sqlTranslator,
- ConnectorLogger logger,
- Properties props,
- RuntimeMetadata metadata, ExecutionContext context,
- ConnectorEnvironment env) {
- super(command, connection, sqlTranslator, logger, props, context, env);
- this.metadata = metadata;
- }
-
- @Override
- public void execute() throws ConnectorException {
- IProcedure procedure = (IProcedure)command;
- columnDataTypes = getColumnDataTypes(procedure.getParameters(), metadata);
-
- //translate command
- TranslatedCommand translatedComm = translateCommand(procedure);
-
- //create statement or CallableStatement and execute
- String sql = translatedComm.getSql();
- try{
- //create parameter index map
- parameterIndexMap = createParameterIndexMap(procedure.getParameters(), sql);
- CallableStatement cstmt = getCallableStatement(sql);
- results = sqlTranslator.executeStoredProcedure(cstmt, translatedComm);
- if (results != null) {
- initResultSetInfo();
- }
- addStatementWarnings();
- }catch(SQLException e){
- throw new ConnectorException(e, JDBCPlugin.Util.getString("JDBCQueryExecution.Error_executing_query__1", sql));
- }
-
- }
-
- @Override
- public List next() throws ConnectorException, DataNotAvailableException {
- if (results == null) {
- return null;
- }
- return super.next();
- }
-
- /**
- * @param results
- * @return
- */
- public static Class[] getColumnDataTypes(List params, RuntimeMetadata metadata) throws ConnectorException {
- if (params != null) {
- IParameter resultSet = null;
- Iterator iter = params.iterator();
- while(iter.hasNext()){
- IParameter param = (IParameter)iter.next();
- if(param.getDirection() == Direction.RESULT_SET){
- resultSet = param;
- break;
- }
- }
-
- if(resultSet != null){
- List<Element> columnMetadata = resultSet.getMetadataObject().getChildren();
-
- int size = columnMetadata.size();
- Class[] coulmnDTs = new Class[size];
- for(int i =0; i<size; i++ ){
- coulmnDTs[i] = columnMetadata.get(i).getJavaType();
- }
- return coulmnDTs;
- }
-
- }
- return new Class[0];
- }
-
- /**
- * @param parameters List of IParameter
- * @param sql
- * @return Map of IParameter to index in sql.
- */
- public static Map createParameterIndexMap(List parameters, String sql) {
- if(parameters == null || parameters.isEmpty()){
- return Collections.EMPTY_MAP;
- }
- Map paramsIndexes = new HashMap();
- int index = 1;
-
- //return parameter, if there is any, is the first parameter
- Iterator iter = parameters.iterator();
- while(iter.hasNext()){
- IParameter param = (IParameter)iter.next();
- if(param.getDirection() == Direction.RETURN){
- paramsIndexes.put(param, new Integer(index++));
- break;
- }
- }
-
- iter = parameters.iterator();
- while(iter.hasNext()){
- IParameter param = (IParameter)iter.next();
- if(param.getDirection() != Direction.RESULT_SET && param.getDirection() != Direction.RETURN){
- paramsIndexes.put(param, new Integer(index++));
- }
- }
- return paramsIndexes;
- }
-
- /*
- * @see com.metamatrix.data.ProcedureExecution#getOutputValue(com.metamatrix.data.language.IParameter)
- */
- public Object getOutputValue(IParameter parameter) throws ConnectorException {
- if(parameter.getDirection() != Direction.OUT && parameter.getDirection() != Direction.INOUT && parameter.getDirection() != Direction.RETURN){
- throw new ConnectorException(JDBCPlugin.Util.getString("JDBCProcedureExecution.The_parameter_direction_must_be_out_or_inout_1")); //$NON-NLS-1$
- }
-
- Integer index = (Integer)this.parameterIndexMap.get(parameter);
- if(index == null){
- //should not come here
- throw new ConnectorException(JDBCPlugin.Util.getString("JDBCProcedureExecution.Unexpected_exception_1")); //$NON-NLS-1$
- }
- try {
- Object value = sqlTranslator.retrieveValue((CallableStatement)this.statement, index.intValue(), parameter.getType());
- if(value == null){
- return null;
- }
- Object result = JDBCExecutionHelper.convertValue(value, parameter.getType(), this.sqlTranslator.getValueTranslators(), this.sqlTranslator.getTypeFacility(), trimString, context);
- return result;
- } catch (SQLException e) {
- throw new ConnectorException(e);
- }
- }
-
-}
Deleted: trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCPropertyNames.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCPropertyNames.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCPropertyNames.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,101 +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 com.metamatrix.connector.jdbc;
-
-public class JDBCPropertyNames {
- public static final String CONNECTION_SOURCE_CLASS = "Driver"; //$NON-NLS-1$
- public static final String URL = "URL"; //$NON-NLS-1$
- public static final String USERNAME = "User"; //$NON-NLS-1$
- public static final String PASSWORD = "Password"; //$NON-NLS-1$
-
- /**
- * This is the property name of the ConnectorService property that defines
- * whether or not String type values in Criteria statements in SQL queries to
- * the data source should have spaces trimmed from them.
- */
- public static final String TRIM_STRINGS = "TrimStrings"; //$NON-NLS-1$
-
- /**
- * This is the property name of the ConnectorService property that defines
- * the size of a SetCriteria (IN criteria) before the criteria is broken into
- * multiple queries and the results are aggregated. 0 indicates that set
- * criteria should never be broken. The default value should be 0.
- */
- public static final String SET_CRITERIA_BATCH_SIZE = "SetCriteriaBatchSize"; //$NON-NLS-1$
-
- /**
- * This is the property name used to set the transaction isolation level on
- * a connector's data source. The value string must be the the same as one of the
- * names of the values of the transaction isolation levels defined in
- * <code>java.sql.Connection</code>.
- * @see java.sql.Connection#setTransactionIsolation(int)
- */
- public static final String TRANSACTION_ISOLATION_LEVEL = "TransactionIsolationLevel"; //$NON-NLS-1$
-
- /**
- * This is the property name of the ConnectorService property that defines
- * the time zone of the source database. This property should only be used in
- * cases where the source database is in a different time zone than the
- * ConnectorService VM and the database/driver is not already handling
- * time zones correctly.
- */
- public static final String DATABASE_TIME_ZONE = "DatabaseTimeZone"; //$NON-NLS-1$
-
- //***** Extension properties *****//
- /**
- * This property is used to specify the implementation of
- * com.metamatrix.data.ConnectorCapabilities.
- */
- public static final String EXT_CAPABILITY_CLASS= "ExtensionCapabilityClass"; //$NON-NLS-1$
-
- /**
- * This property is used to specify the implementation of
- * com.metamatrix.connector.jdbc.extension.Translator
- */
- public static final String EXT_TRANSLATOR_CLASS= "ExtensionTranslationClass"; //$NON-NLS-1$
-
- /**
- * This property can be used to specify the fetch size used from the connector to
- * its underlying source.
- */
- public static final String FETCH_SIZE = "FetchSize"; //$NON-NLS-1$
-
- /**
- * This property can be used to indicate that prepared statements should be used.
- * This means Literals will be substituted for
- * bind variables.
- * @since 5.0.1
- */
- public static final String USE_BIND_VARIABLES = "UseBindVariables"; //$NON-NLS-1$
-
- /**
- * This property is used to turn on/off the use of the default comments like
- * connection id and requestid in the source SQL query.
- */
- public static final String USE_COMMENTS_SOURCE_QUERY= "UseCommentsInSourceQuery"; //$NON-NLS-1$
-
- public static final String CONNECTION_TEST_QUERY = "ConnectionTestQuery"; //$NON-NLS-1$
-
- public static final String IS_VALID_TIMEOUT = "IsValidTimeout"; //$NON-NLS-1$
-
-}
Deleted: trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCQueryExecution.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCQueryExecution.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCQueryExecution.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -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 com.metamatrix.connector.jdbc;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-import com.metamatrix.connector.api.ConnectorEnvironment;
-import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.api.ConnectorLogger;
-import com.metamatrix.connector.api.DataNotAvailableException;
-import com.metamatrix.connector.api.ExecutionContext;
-import com.metamatrix.connector.api.ResultSetExecution;
-import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.api.ValueTranslator;
-import com.metamatrix.connector.jdbc.translator.TranslatedCommand;
-import com.metamatrix.connector.jdbc.translator.Translator;
-import com.metamatrix.connector.jdbc.util.JDBCExecutionHelper;
-import com.metamatrix.connector.language.ICommand;
-import com.metamatrix.connector.language.IQueryCommand;
-
-/**
- *
- */
-public class JDBCQueryExecution extends JDBCBaseExecution implements ResultSetExecution {
-
- // ===========================================================================================================================
- // Fields
- // ===========================================================================================================================
-
- protected ResultSet results;
- protected Class[] columnDataTypes;
- protected ConnectorEnvironment env;
- protected ICommand command;
- private boolean[] transformKnown;
- private ValueTranslator[] transforms;
- private boolean[] trimColumn;
- private int[] nativeTypes;
-
- // ===========================================================================================================================
- // Constructors
- // ===========================================================================================================================
-
- public JDBCQueryExecution(ICommand command, Connection connection,
- Translator sqlTranslator,
- ConnectorLogger logger,
- Properties props,
- ExecutionContext context,
- ConnectorEnvironment env) {
- super(connection, sqlTranslator, logger, props, context);
- this.command = command;
- this.env = env;
- }
-
- @Override
- public void execute() throws ConnectorException {
- // get column types
- columnDataTypes = ((IQueryCommand)command).getColumnTypes();
-
- // translate command
- TranslatedCommand translatedComm = translateCommand(command);
-
- String sql = translatedComm.getSql();
-
- try {
-
- if (!translatedComm.isPrepared()) {
- results = getStatement().executeQuery(sql);
- } else {
- PreparedStatement pstatement = getPreparedStatement(sql);
- sqlTranslator.bindPreparedStatementValues(this.connection, pstatement, translatedComm);
- results = pstatement.executeQuery();
- }
- addStatementWarnings();
- initResultSetInfo();
-
- } catch (SQLException e) {
- throw createAndLogError(e, translatedComm);
- }
- }
-
- protected void initResultSetInfo() throws SQLException {
- trimColumn = new boolean[columnDataTypes.length];
- nativeTypes = new int[columnDataTypes.length];
- ResultSetMetaData rsmd = results.getMetaData();
- for(int i=0; i<columnDataTypes.length; i++) {
-
- nativeTypes[i] = rsmd.getColumnType(i+1);
- if ((nativeTypes[i] == Types.BLOB && (columnDataTypes[i] == TypeFacility.RUNTIME_TYPES.BLOB || columnDataTypes[i] == TypeFacility.RUNTIME_TYPES.OBJECT))
- || (nativeTypes[i] == Types.CLOB && (columnDataTypes[i] == TypeFacility.RUNTIME_TYPES.CLOB || columnDataTypes[i] == TypeFacility.RUNTIME_TYPES.OBJECT))) {
- context.keepExecutionAlive(true);
- }
-
- if(columnDataTypes[i].equals(String.class)) {
- if(trimString || nativeTypes[i] == Types.CHAR) {
- trimColumn[i] = true;
- }
- }
- }
-
- transformKnown = new boolean[columnDataTypes.length];
- transforms = new ValueTranslator[columnDataTypes.length];
- }
-
- @Override
- public List next() throws ConnectorException, DataNotAvailableException {
- try {
- if (results.next()) {
- // New row for result set
- List vals = new ArrayList(columnDataTypes.length);
-
- for (int i = 0; i < columnDataTypes.length; i++) {
- // Convert from 0-based to 1-based
- Object value = sqlTranslator.retrieveValue(results, i+1, columnDataTypes[i]);
- if(value != null) {
- // Determine transformation if unknown
- if(! transformKnown[i]) {
- Class valueType = value.getClass();
- if(!columnDataTypes[i].isAssignableFrom(valueType)) {
- transforms[i] = JDBCExecutionHelper.determineTransformation(valueType, columnDataTypes[i], sqlTranslator.getValueTranslators(), sqlTranslator.getTypeFacility());
- }
- transformKnown[i] = true;
- }
-
- // Transform value if necessary
- if(transforms[i] != null) {
- value = transforms[i].translate(value, context);
- }
-
- // Trim string column if necessary
- if(trimColumn[i]) {
- value = JDBCExecutionHelper.trimString((String) value);
- }
- }
- vals.add(value);
- }
-
- return vals;
- }
- } catch (SQLException e) {
- throw new ConnectorException(e,
- JDBCPlugin.Util.getString("JDBCTranslator.Unexpected_exception_translating_results___8", e.getMessage())); //$NON-NLS-1$
- }
-
- return null;
- }
-
- /**
- * @see com.metamatrix.connector.jdbc.JDBCBaseExecution#close()
- */
- public void close() throws ConnectorException {
- // first we would need to close the result set here then we can close
- // the statement, using the base class.
- if (results != null) {
- try {
- results.close();
- results = null;
- } catch (SQLException e) {
- throw new ConnectorException(e);
- }
- }
- super.close();
- }
-
-}
Deleted: trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCSourceConnection.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCSourceConnection.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCSourceConnection.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,130 +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 com.metamatrix.connector.jdbc;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import com.metamatrix.connector.api.ConnectorEnvironment;
-import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.api.ConnectorLogger;
-import com.metamatrix.connector.api.ExecutionContext;
-import com.metamatrix.connector.api.ProcedureExecution;
-import com.metamatrix.connector.api.ResultSetExecution;
-import com.metamatrix.connector.api.UpdateExecution;
-import com.metamatrix.connector.jdbc.translator.Translator;
-import com.metamatrix.connector.language.ICommand;
-import com.metamatrix.connector.language.IProcedure;
-import com.metamatrix.connector.language.IQueryCommand;
-import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
-
-/**
- *
- */
-public class JDBCSourceConnection extends com.metamatrix.connector.basic.BasicConnection {
- protected java.sql.Connection physicalConnection;
- protected ConnectorEnvironment environment;
- private ConnectorLogger logger;
- private Translator sqlTranslator;
-
- public JDBCSourceConnection(java.sql.Connection connection, ConnectorEnvironment environment, Translator sqlTranslator) throws ConnectorException {
- this.physicalConnection = connection;
- this.environment = environment;
- this.logger = environment.getLogger();
- this.sqlTranslator = sqlTranslator;
- this.sqlTranslator.afterConnectionCreation(connection);
- }
-
- @Override
- public ResultSetExecution createResultSetExecution(IQueryCommand command,
- ExecutionContext executionContext, RuntimeMetadata metadata)
- throws ConnectorException {
- return new JDBCQueryExecution(command, this.physicalConnection, sqlTranslator, logger, this.environment.getProperties(), executionContext, this.environment);
- }
-
- @Override
- public ProcedureExecution createProcedureExecution(IProcedure command,
- ExecutionContext executionContext, RuntimeMetadata metadata)
- throws ConnectorException {
- return new JDBCProcedureExecution(command, this.physicalConnection, sqlTranslator, logger, this.environment.getProperties(), metadata, executionContext, this.environment);
- }
-
- @Override
- public UpdateExecution createUpdateExecution(ICommand command,
- ExecutionContext executionContext, RuntimeMetadata metadata)
- throws ConnectorException {
- return new JDBCUpdateExecution(command, this.physicalConnection, sqlTranslator, logger, this.environment.getProperties(), executionContext);
- }
-
- @Override
- public void close() {
- closeSourceConnection();
- }
-
- protected void closeSourceConnection() {
- try {
- this.physicalConnection.close();
- } catch(SQLException e) {
- logger.logDetail("Exception during close: " + e.getMessage());
- }
- }
-
- @Override
- public boolean isAlive() {
- Connection connection = this.physicalConnection;
- Statement statement = null;
- try {
- int timeout = this.sqlTranslator.getIsValidTimeout();
- if (timeout >= 0) {
- return connection.isValid(timeout);
- }
- if(connection.isClosed()){
- return false;
- }
- String connectionTestQuery = sqlTranslator.getConnectionTestQuery();
- if (connectionTestQuery != null) {
- statement = connection.createStatement();
- statement.executeQuery(connectionTestQuery);
- }
- } catch(SQLException e) {
- return false;
- } finally {
- if ( statement != null ) {
- try {
- statement.close();
- } catch ( SQLException e ) {
- }
- }
- }
- return true;
- }
-
- @Override
- public void closeCalled() {
-
- }
-
-}
Deleted: trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCUpdateExecution.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCUpdateExecution.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCUpdateExecution.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,264 +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 com.metamatrix.connector.jdbc;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.api.ConnectorLogger;
-import com.metamatrix.connector.api.DataNotAvailableException;
-import com.metamatrix.connector.api.ExecutionContext;
-import com.metamatrix.connector.api.UpdateExecution;
-import com.metamatrix.connector.jdbc.translator.TranslatedCommand;
-import com.metamatrix.connector.jdbc.translator.Translator;
-import com.metamatrix.connector.language.IBatchedUpdates;
-import com.metamatrix.connector.language.IBulkInsert;
-import com.metamatrix.connector.language.ICommand;
-
-/**
- */
-public class JDBCUpdateExecution extends JDBCBaseExecution implements
- UpdateExecution {
-
- private ICommand command;
- private int[] result;
-
- /**
- * @param connection
- * @param sqlTranslator
- * @param logger
- * @param props
- * @param id
- */
- public JDBCUpdateExecution(ICommand command, Connection connection,
- Translator sqlTranslator,
- ConnectorLogger logger,
- Properties props,
- ExecutionContext context) {
- super(connection, sqlTranslator, logger, props, context);
- this.command = command;
- }
-
- // ===========================================================================================================================
- // Methods
- // ===========================================================================================================================
-
- @Override
- public void execute() throws ConnectorException {
- if (command instanceof IBulkInsert) {
- result = new int [] {execute((IBulkInsert)command)};
- } else if (command instanceof IBatchedUpdates) {
- result = execute(((IBatchedUpdates)command));
- } else {
- // translate command
- TranslatedCommand translatedComm = translateCommand(command);
-
- result = new int [] {executeTranslatedCommand(translatedComm)};
- }
- }
-
- /**
- * @see com.metamatrix.data.api.BatchedUpdatesExecution#execute(com.metamatrix.connector.language.ICommand[])
- * @since 4.2
- */
- public int[] execute(IBatchedUpdates batchedCommand) throws ConnectorException {
- boolean succeeded = false;
-
- boolean commitType = getAutoCommit(null);
- ICommand[] commands = (ICommand[])batchedCommand.getUpdateCommands().toArray(new ICommand[batchedCommand.getUpdateCommands().size()]);
- int[] results = new int[commands.length];
-
- try {
- // temporarily turn the auto commit off, and set it back to what it was
- // before at the end of the command execution.
- if (commitType) {
- connection.setAutoCommit(false);
- }
-
- List executedCmds = new ArrayList();
-
- TranslatedCommand previousCommand = null;
-
- for (int i = 0; i < commands.length; i++) {
- TranslatedCommand command = translateCommand(commands[i]);
- if (command.isPrepared()) {
- PreparedStatement pstmt = null;
- if (previousCommand != null && previousCommand.isPrepared() && previousCommand.getSql().equals(command.getSql())) {
- pstmt = (PreparedStatement)statement;
- } else {
- if (!executedCmds.isEmpty()) {
- executeBatch(i, results, executedCmds);
- }
- pstmt = getPreparedStatement(command.getSql());
- }
- sqlTranslator.bindPreparedStatementValues(this.connection, pstmt, command);
- pstmt.addBatch();
- } else {
- if (previousCommand != null && previousCommand.isPrepared()) {
- executeBatch(i, results, executedCmds);
- getStatement();
- }
- if (statement == null) {
- getStatement();
- }
- statement.addBatch(command.getSql());
- }
- executedCmds.add(command);
- previousCommand = command;
- }
- if (!executedCmds.isEmpty()) {
- executeBatch(commands.length, results, executedCmds);
- }
- succeeded = true;
- } catch (SQLException e) {
- throw createAndLogError(e, null);
- } finally {
- if (commitType) {
- restoreAutoCommit(!succeeded, null);
- }
- }
-
- return results;
- }
-
- /**
- * An implementation to bulk insert rows into single table.
- *
- * @param command
- * @return
- * @throws ConnectorException
- */
- public int execute(IBulkInsert command) throws ConnectorException {
- boolean succeeded = false;
-
- // translate command
- TranslatedCommand translatedComm = translateCommand(command);
-
- // create statement or PreparedStatement and execute
- String sql = translatedComm.getSql();
-
- boolean commitType = getAutoCommit(translatedComm);
- int updateCount = -1;
- try {
- // temporarily turn the auto commit off, and set it back to what it was
- // before at the end of the command execution.
- if (commitType) {
- connection.setAutoCommit(false);
- }
- PreparedStatement stmt = getPreparedStatement(sql);
- updateCount = sqlTranslator.executeStatementForBulkInsert(this.connection, stmt, translatedComm);
- addStatementWarnings();
- succeeded = true;
- } catch (SQLException e) {
- throw createAndLogError(e, translatedComm);
- } finally {
- if (commitType) {
- restoreAutoCommit(!succeeded, translatedComm);
- }
- }
- return updateCount;
- }
-
- private void executeBatch(int commandCount,
- int[] results,
- List commands) throws ConnectorException {
- try {
- int[] batchResults = statement.executeBatch();
- addStatementWarnings();
- for (int j = 0; j < batchResults.length; j++) {
- results[commandCount - 1 - j] = batchResults[batchResults.length - 1 - j];
- }
- commands.clear();
- } catch (SQLException err) {
- throw createAndLogError(err, "JDBCQueryExecution.Error_executing_query__3", commands); //$NON-NLS-1$
- }
- }
-
- /**
- * @param translatedComm
- * @throws ConnectorException
- * @since 4.3
- */
- private int executeTranslatedCommand(TranslatedCommand translatedComm) throws ConnectorException {
- // create statement or PreparedStatement and execute
- String sql = translatedComm.getSql();
-
- try {
- int updateCount;
- if (!translatedComm.isPrepared()) {
- updateCount = getStatement().executeUpdate(sql);
- } else {
- PreparedStatement pstatement = getPreparedStatement(sql);
- sqlTranslator.bindPreparedStatementValues(this.connection, pstatement, translatedComm);
- updateCount = pstatement.executeUpdate();
- }
- addStatementWarnings();
- return updateCount;
- } catch (SQLException err) {
- throw createError(err, translatedComm);
- }
- }
-
- /**
- * @param command
- * @return
- * @throws ConnectorException
- */
- private boolean getAutoCommit(TranslatedCommand command) throws ConnectorException {
- try {
- return connection.getAutoCommit();
- } catch (SQLException err) {
- throw createAndLogError(err, command);
- }
- }
-
- /**
- * If the auto comm
- *
- * @param exceptionOccurred
- * @param command
- * @throws ConnectorException
- */
- private void restoreAutoCommit(boolean exceptionOccurred,
- TranslatedCommand command) throws ConnectorException {
- try {
- if (exceptionOccurred) {
- connection.rollback();
- }
- connection.setAutoCommit(true);
- } catch (SQLException err) {
- throw createAndLogError(err, command);
- }
- }
-
- @Override
- public int[] getUpdateCounts() throws DataNotAvailableException,
- ConnectorException {
- return result;
- }
-}
Deleted: trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/SimpleCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/SimpleCapabilities.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/SimpleCapabilities.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,371 +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 com.metamatrix.connector.jdbc;
-
-import java.util.List;
-
-import com.metamatrix.connector.api.ConnectorCapabilities;
-
-/**
- * This is a "simple" capabilities class that allows criteria but no
- * complicated joins, subqueries, etc to be passed to the connector.
- * This capabilities class may come in handy for testing and for
- * sources that support JDBC but don't support extended JDBC capabilities.
- */
-public class SimpleCapabilities extends JDBCCapabilities implements ConnectorCapabilities {
-
- public SimpleCapabilities() {
- // Max acceptable by all BQT dbs (Sybase=250, Oracle=1000)
- setMaxInCriteriaSize(250);
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAndCriteria()
- */
- public boolean supportsAndCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCompareCriteria()
- */
- public boolean supportsCompareCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCompareCriteriaEquals()
- */
- public boolean supportsCompareCriteriaEquals() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCompareCriteriaGreaterThan()
- */
- public boolean supportsCompareCriteriaGreaterThan() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCompareCriteriaGreaterThanOrEqual()
- */
- public boolean supportsCompareCriteriaGreaterThanOrEqual() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCompareCriteriaLessThan()
- */
- public boolean supportsCompareCriteriaLessThan() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCompareCriteriaLessThanOrEqual()
- */
- public boolean supportsCompareCriteriaLessThanOrEqual() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCompareCriteriaNotEquals()
- */
- public boolean supportsCompareCriteriaNotEquals() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCriteria()
- */
- public boolean supportsCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsInCriteria()
- */
- public boolean supportsInCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsIsNullCriteria()
- */
- public boolean supportsIsNullCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsJoins()
- */
- public boolean supportsJoins() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsLikeCriteria()
- */
- public boolean supportsLikeCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsNotCriteria()
- */
- public boolean supportsNotCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsOrCriteria()
- */
- public boolean supportsOrCriteria() {
- return true;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsSelectDistinct()
- */
- public boolean supportsSelectDistinct() {
- return true;
- }
-
- /**
- * @see com.metamatrix.connector.api.ConnectorCapabilities#supportsSelectLiterals()
- * @since 4.2
- */
- public boolean supportsSelectLiterals() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAliasedGroup()
- */
- public boolean supportsAliasedGroup() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsSelfJoins()
- */
- public boolean supportsSelfJoins() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsOuterJoins()
- */
- public boolean supportsOuterJoins() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsFullOuterJoins()
- */
- public boolean supportsFullOuterJoins() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsBetweenCriteria()
- */
- public boolean supportsBetweenCriteria() {
- return false;
- }
-
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsLikeCriteriaEscapeCharacter()
- */
- public boolean supportsLikeCriteriaEscapeCharacter() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsInCriteriaSubquery()
- */
- public boolean supportsInCriteriaSubquery() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsExistsCriteria()
- */
- public boolean supportsExistsCriteria() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsQuantifiedCompareCriteria()
- */
- public boolean supportsQuantifiedCompareCriteria() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsQuantifiedCompareCriteriaSome()
- */
- public boolean supportsQuantifiedCompareCriteriaSome() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsQuantifiedCompareCriteriaAll()
- */
- public boolean supportsQuantifiedCompareCriteriaAll() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsOrderBy()
- */
- public boolean supportsOrderBy() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAggregates()
- */
- public boolean supportsAggregates() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAggregatesSum()
- */
- public boolean supportsAggregatesSum() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAggregatesAvg()
- */
- public boolean supportsAggregatesAvg() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAggregatesMin()
- */
- public boolean supportsAggregatesMin() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAggregatesMax()
- */
- public boolean supportsAggregatesMax() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAggregatesCount()
- */
- public boolean supportsAggregatesCount() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAggregatesCountStar()
- */
- public boolean supportsAggregatesCountStar() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAggregatesDistinct()
- */
- public boolean supportsAggregatesDistinct() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsScalarSubqueries()
- */
- public boolean supportsScalarSubqueries() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCorrelatedSubqueries()
- */
- public boolean supportsCorrelatedSubqueries() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCaseExpressions()
- */
- public boolean supportsCaseExpressions() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsSearchedCaseExpressions()
- */
- public boolean supportsSearchedCaseExpressions() {
- return false;
- }
-
- /*
- * @see com.metamatrix.data.api.ConnectorCapabilities#supportsScalarFunctions()
- */
- public boolean supportsScalarFunctions() {
- return false;
- }
-
- /**
- * Return null to indicate no functions are supported.
- * @return null
- * @see com.metamatrix.connector.api.ConnectorCapabilities#getSupportedFunctions()
- */
- public List getSupportedFunctions() {
- return null;
- }
-
- public boolean supportsInlineViews() {
- return false;
- }
-
- public boolean supportsOrderByInInlineViews() {
- return false;
- }
-
- /**
- * @see com.metamatrix.connector.api.ConnectorCapabilities#supportsUnionOrderBy()
- * @since 4.2
- */
- public boolean supportsUnionOrderBy() {
- return false;
- }
-
- /**
- * @see com.metamatrix.connector.api.ConnectorCapabilities#supportsUnions()
- * @since 4.2
- */
- public boolean supportsUnions() {
- return false;
- }
-
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCBaseExecution.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCBaseExecution.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCBaseExecution.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCBaseExecution.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,287 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc;
+
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Statement;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import org.teiid.connector.jdbc.translator.TranslatedCommand;
+import org.teiid.connector.jdbc.translator.Translator;
+
+import com.metamatrix.common.util.PropertiesUtils;
+import com.metamatrix.connector.api.ConnectorException;
+import com.metamatrix.connector.api.ConnectorIdentity;
+import com.metamatrix.connector.api.ConnectorLogger;
+import com.metamatrix.connector.api.ExecutionContext;
+import com.metamatrix.connector.basic.BasicExecution;
+import com.metamatrix.connector.language.ICommand;
+
+/**
+ */
+public abstract class JDBCBaseExecution extends BasicExecution {
+
+ // ===========================================================================================================================
+ // Fields
+ // ===========================================================================================================================
+
+ // Passed to constructor
+ protected Connection connection;
+ protected Translator sqlTranslator;
+ protected ConnectorIdentity id;
+ protected ConnectorLogger logger;
+ protected ExecutionContext context;
+
+ // Derived from properties
+ protected boolean trimString;
+ protected int fetchSize;
+
+ // Set during execution
+ protected Statement statement;
+
+ // ===========================================================================================================================
+ // Constructors
+ // ===========================================================================================================================
+
+ protected JDBCBaseExecution(Connection connection,
+ Translator sqlTranslator,
+ ConnectorLogger logger,
+ Properties props,
+ ExecutionContext context) {
+ this.connection = connection;
+ this.sqlTranslator = sqlTranslator;
+ this.logger = logger;
+ this.context = context;
+
+ String propStr = props.getProperty(JDBCPropertyNames.TRIM_STRINGS);
+ if (propStr != null) {
+ trimString = Boolean.valueOf(propStr).booleanValue();
+ }
+
+ fetchSize = PropertiesUtils.getIntProperty(props, JDBCPropertyNames.FETCH_SIZE, context.getBatchSize());
+ int max = sqlTranslator.getMaxResultRows();
+ if (max > 0) {
+ fetchSize = Math.min(fetchSize, max);
+ }
+ }
+
+ // ===========================================================================================================================
+ // Methods
+ // ===========================================================================================================================
+
+ private void addSql(TranslatedCommand command,
+ StringBuffer message) {
+ String sql = command.getSql();
+ int ndx = sql.indexOf('?');
+ if (ndx >= 0) {
+ message.append(sql.substring(0, ndx));
+ int len = sql.length();
+ for (Iterator itr = command.getPreparedValues().iterator(); itr.hasNext() && ndx < len;) {
+ message.append(itr.next());
+ int nextNdx = sql.indexOf('?', ++ndx);
+ if (nextNdx >= 0) {
+ message.append(sql.substring(ndx, nextNdx));
+ } else {
+ message.append(sql.substring(ndx));
+ }
+ ndx = nextNdx;
+ }
+ } else {
+ message.append(sql);
+ }
+ }
+
+ /**
+ * @param error
+ * @param command
+ * @return
+ * @since 5.5
+ */
+ protected ConnectorException createAndLogError(SQLException error,
+ TranslatedCommand command) {
+ ConnectorException connectorErr = createError(error, command);
+ this.logger.logError(connectorErr.getMessage());
+ return connectorErr;
+ }
+
+ /**
+ * @param error
+ * @param messageKey
+ * @param commands
+ * @return
+ * @throws ConnectorException
+ * @since 5.5
+ */
+ protected ConnectorException createAndLogError(Throwable error,
+ String messageKey,
+ List commands) throws ConnectorException {
+ String msg;
+ if (commands.isEmpty()) {
+ msg = error.getMessage();
+ } else {
+ msg = JDBCPlugin.Util.getString(messageKey, error.getMessage());
+ StringBuffer buf = new StringBuffer(msg);
+ for (Iterator itr = commands.iterator(); itr.hasNext();) {
+ buf.append("\n "); //$NON-NLS-1$
+ addSql((TranslatedCommand)itr.next(), buf);
+ }
+ msg = buf.toString();
+ }
+ this.logger.logError(msg);
+ if (error instanceof ConnectorException) {
+ error = ((ConnectorException)error).getCause();
+ }
+ throw new ConnectorException(error, msg);
+ }
+
+ /**
+ * @param error
+ * @param command
+ * @return
+ * @since 5.5
+ */
+ protected ConnectorException createError(SQLException error,
+ TranslatedCommand command) {
+ String msg = (command == null ? error.getMessage()
+ : JDBCPlugin.Util.getString("JDBCQueryExecution.Error_executing_query__1", //$NON-NLS-1$
+ error.getMessage(), createSql(command)));
+ return new ConnectorException(error, msg);
+ }
+
+ private String createSql(TranslatedCommand command) {
+ StringBuffer msg = new StringBuffer();
+ addSql(command, msg);
+ return msg.toString();
+ }
+
+ protected TranslatedCommand translateCommand(ICommand command) throws ConnectorException {
+ TranslatedCommand translatedCommand = new TranslatedCommand(context, sqlTranslator);
+ translatedCommand.translateCommand(command);
+
+ if (translatedCommand.getSql() != null && this.logger.isDetailEnabled()) {
+ this.logger.logDetail("Source-specific command: " + translatedCommand.getSql()); //$NON-NLS-1$
+ }
+
+ return translatedCommand;
+ }
+
+ /*
+ * @see com.metamatrix.data.Execution#close()
+ */
+ public synchronized void close() throws ConnectorException {
+ try {
+ if (statement != null) {
+ statement.close();
+ }
+ } catch (SQLException e) {
+ throw new ConnectorException(e);
+ }
+ }
+
+ /*
+ * @see com.metamatrix.data.Execution#cancel()
+ */
+ public synchronized void cancel() throws ConnectorException {
+ // if both the DBMS and driver support aborting an SQL
+ try {
+ if (statement != null) {
+ statement.cancel();
+ }
+ } catch (SQLException e) {
+ // Defect 16187 - DataDirect does not support the cancel() method for
+ // Statement.cancel() for DB2 and Informix. Here we are tolerant
+ // of these and other JDBC drivers that do not support the cancel() operation.
+ }
+ }
+
+ protected void setSizeContraints(Statement statement) throws SQLException {
+ if (sqlTranslator.getMaxResultRows() > 0) {
+ statement.setMaxRows(sqlTranslator.getMaxResultRows());
+ }
+ statement.setFetchSize(fetchSize);
+ }
+
+ protected synchronized Statement getStatement() throws SQLException {
+ if (statement != null) {
+ statement.close();
+ statement = null;
+ }
+ statement = connection.createStatement();
+ setSizeContraints(statement);
+ return statement;
+ }
+
+ protected synchronized CallableStatement getCallableStatement(String sql) throws SQLException {
+ if (statement != null) {
+ statement.close();
+ statement = null;
+ }
+ statement = connection.prepareCall(sql);
+ setSizeContraints(statement);
+ return (CallableStatement)statement;
+ }
+
+ protected synchronized PreparedStatement getPreparedStatement(String sql) throws SQLException {
+ if (statement != null) {
+ statement.close();
+ statement = null;
+ }
+ statement = connection.prepareStatement(sql);
+ setSizeContraints(statement);
+ return (PreparedStatement)statement;
+ }
+
+ /**
+ * Returns the JDBC connection used by the execution object.
+ *
+ * @return Returns the connection.
+ * @since 4.1.1
+ */
+ public Connection getConnection() {
+ return this.connection;
+ }
+
+ public Translator getSqlTranslator() {
+ return sqlTranslator;
+ }
+
+ public void addStatementWarnings() throws SQLException {
+ SQLWarning warning = this.statement.getWarnings();
+ while (warning != null) {
+ SQLWarning toAdd = warning;
+ warning = toAdd.getNextWarning();
+ toAdd.setNextException(null);
+ if (logger.isDetailEnabled()) {
+ logger.logDetail(context.getRequestIdentifier() + " Warning: ", warning); //$NON-NLS-1$
+ }
+ context.addWarning(toAdd);
+ }
+ this.statement.clearWarnings();
+ }
+}
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCBaseExecution.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCCapabilities.java (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCCapabilities.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCCapabilities.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCCapabilities.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,399 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc;
+
+import java.util.Arrays;
+import java.util.List;
+
+import com.metamatrix.connector.basic.BasicConnectorCapabilities;
+
+/**
+ */
+public class JDBCCapabilities extends BasicConnectorCapabilities {
+
+ public static final int DEFAULT_JDBC_MAX_IN_CRITERIA_SIZE = 1000;
+
+ /**
+ *
+ */
+ public JDBCCapabilities() {
+ this.setMaxInCriteriaSize(DEFAULT_JDBC_MAX_IN_CRITERIA_SIZE);
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#getSupportedFunctions()
+ */
+ public List getSupportedFunctions() {
+ return Arrays.asList(new String[] { "+", "-", "*", "/" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
+
+ /**
+ * @see com.metamatrix.connector.basic.BasicConnectorCapabilities#getMaxInCriteriaSize()
+ * @since 4.2
+ */
+ public int getMaxInCriteriaSize() {
+ return maxInCriteriaSize;
+ }
+
+ public void setMaxInCriteriaSize(int maxInCriteriaSize) {
+ this.maxInCriteriaSize = maxInCriteriaSize;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsAggregates()
+ */
+ public boolean supportsAggregates() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsAggregatesAvg()
+ */
+ public boolean supportsAggregatesAvg() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsAggregatesCount()
+ */
+ public boolean supportsAggregatesCount() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsAggregatesCountStar()
+ */
+ public boolean supportsAggregatesCountStar() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsAggregatesDistinct()
+ */
+ public boolean supportsAggregatesDistinct() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsAggregatesMax()
+ */
+ public boolean supportsAggregatesMax() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsAggregatesMin()
+ */
+ public boolean supportsAggregatesMin() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsAggregatesSum()
+ */
+ public boolean supportsAggregatesSum() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsAliasedGroup()
+ */
+ public boolean supportsAliasedGroup() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsAndCriteria()
+ */
+ public boolean supportsAndCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsBetweenCriteria()
+ */
+ public boolean supportsBetweenCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsCaseExpressions()
+ */
+ public boolean supportsCaseExpressions() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsCompareCriteria()
+ */
+ public boolean supportsCompareCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsCompareCriteriaEquals()
+ */
+ public boolean supportsCompareCriteriaEquals() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsCompareCriteriaGreaterThan()
+ */
+ public boolean supportsCompareCriteriaGreaterThan() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsCompareCriteriaGreaterThanOrEqual()
+ */
+ public boolean supportsCompareCriteriaGreaterThanOrEqual() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsCompareCriteriaLessThan()
+ */
+ public boolean supportsCompareCriteriaLessThan() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsCompareCriteriaLessThanOrEqual()
+ */
+ public boolean supportsCompareCriteriaLessThanOrEqual() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsCompareCriteriaNotEquals()
+ */
+ public boolean supportsCompareCriteriaNotEquals() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsCorrelatedSubqueries()
+ */
+ public boolean supportsCorrelatedSubqueries() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsCriteria()
+ */
+ public boolean supportsCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsExistsCriteria()
+ */
+ public boolean supportsExistsCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsFullOuterJoins()
+ */
+ public boolean supportsFullOuterJoins() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsInCriteria()
+ */
+ public boolean supportsInCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsInCriteriaSubquery()
+ */
+ public boolean supportsInCriteriaSubquery() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsIsNullCriteria()
+ */
+ public boolean supportsIsNullCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsJoins()
+ */
+ public boolean supportsJoins() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsLikeCriteria()
+ */
+ public boolean supportsLikeCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsLikeCriteriaEscapeCharacter()
+ */
+ public boolean supportsLikeCriteriaEscapeCharacter() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsNotCriteria()
+ */
+ public boolean supportsNotCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsOrCriteria()
+ */
+ public boolean supportsOrCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsOrderBy()
+ */
+ public boolean supportsOrderBy() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsOuterJoins()
+ */
+ public boolean supportsOuterJoins() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsQuantifiedCompareCriteria()
+ */
+ public boolean supportsQuantifiedCompareCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsQuantifiedCompareCriteriaAll()
+ */
+ public boolean supportsQuantifiedCompareCriteriaAll() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsScalarFunctions()
+ */
+ public boolean supportsScalarFunctions() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsScalarSubqueries()
+ */
+ public boolean supportsScalarSubqueries() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsSearchedCaseExpressions()
+ */
+ public boolean supportsSearchedCaseExpressions() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsSelectDistinct()
+ */
+ public boolean supportsSelectDistinct() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsSelectLiterals()
+ */
+ public boolean supportsSelectLiterals() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.ConnectorCapabilities#supportsSelfJoins()
+ */
+ public boolean supportsSelfJoins() {
+ return true;
+ }
+
+ /**
+ * @see com.metamatrix.connector.api.ConnectorCapabilities#supportsInlineViews()
+ */
+ public boolean supportsInlineViews() {
+ return false;
+ }
+
+ public boolean supportsOrderByInInlineViews() {
+ return false;
+ }
+
+ /**
+ * @see com.metamatrix.connector.api.ConnectorCapabilities#supportsQuantifiedCompareCriteriaSome()
+ */
+ public boolean supportsQuantifiedCompareCriteriaSome() {
+ return true;
+ }
+
+ /**
+ * @see com.metamatrix.connector.api.ConnectorCapabilities#supportsUnionOrderBy()
+ */
+ public boolean supportsUnionOrderBy() {
+ return true;
+ }
+
+ /**
+ * @see com.metamatrix.connector.basic.BasicConnectorCapabilities#supportsSetQueryOrderBy()
+ */
+ @Override
+ public boolean supportsSetQueryOrderBy() {
+ return true;
+ }
+
+ /**
+ * @see com.metamatrix.connector.api.ConnectorCapabilities#supportsUnions()
+ */
+ public boolean supportsUnions() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsBulkInsert() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsBatchedUpdates() {
+ return true;
+ }
+
+}
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCCapabilities.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCConnector.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,391 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+/*
+ */
+package org.teiid.connector.jdbc;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import javax.sql.DataSource;
+import javax.sql.XADataSource;
+
+import org.teiid.connector.jdbc.translator.Translator;
+import org.teiid.connector.jdbc.xa.JDBCSourceXAConnection;
+import org.teiid.connector.jdbc.xa.XAJDBCPropertyNames;
+
+import com.metamatrix.common.util.PropertiesUtils;
+import com.metamatrix.connector.api.Connection;
+import com.metamatrix.connector.api.ConnectorCapabilities;
+import com.metamatrix.connector.api.ConnectorEnvironment;
+import com.metamatrix.connector.api.ConnectorException;
+import com.metamatrix.connector.api.ConnectorLogger;
+import com.metamatrix.connector.api.ExecutionContext;
+import com.metamatrix.connector.api.SingleIdentity;
+import com.metamatrix.connector.api.MappedUserIdentity;
+import com.metamatrix.connector.api.ConnectorAnnotations.ConnectionPooling;
+import com.metamatrix.connector.basic.BasicConnector;
+import com.metamatrix.connector.internal.ConnectorPropertyNames;
+import com.metamatrix.connector.xa.api.TransactionContext;
+import com.metamatrix.connector.xa.api.XAConnection;
+import com.metamatrix.connector.xa.api.XAConnector;
+import com.metamatrix.core.MetaMatrixCoreException;
+import com.metamatrix.core.util.ReflectionHelper;
+
+/**
+ * JDBC implementation of Connector interface.
+ */
+@ConnectionPooling
+public class JDBCConnector extends BasicConnector implements XAConnector {
+
+ public static final String INVALID_AUTHORIZATION_SPECIFICATION_NO_SUBCLASS = "28000"; //$NON-NLS-1$
+
+ static final int NO_ISOLATION_LEVEL_SET = Integer.MIN_VALUE;
+
+ enum TransactionIsolationLevel {
+ TRANSACTION_READ_UNCOMMITTED(java.sql.Connection.TRANSACTION_READ_UNCOMMITTED),
+ TRANSACTION_READ_COMMITTED(java.sql.Connection.TRANSACTION_READ_COMMITTED),
+ TRANSACTION_REPEATABLE_READ(java.sql.Connection.TRANSACTION_REPEATABLE_READ),
+ TRANSACTION_SERIALIZABLE(java.sql.Connection.TRANSACTION_SERIALIZABLE),
+ TRANSACTION_NONE(java.sql.Connection.TRANSACTION_NONE);
+
+ private int connectionContant;
+
+ private TransactionIsolationLevel(int connectionConstant) {
+ this.connectionContant = connectionConstant;
+ }
+
+ public int getConnectionConstant() {
+ return connectionContant;
+ }
+ }
+
+ protected ConnectorEnvironment environment;
+ private ConnectorLogger logger;
+ private ConnectorCapabilities capabilities;
+ private Translator sqlTranslator;
+ private DataSource ds;
+ private XADataSource xaDs;
+ private int transIsoLevel = NO_ISOLATION_LEVEL_SET;
+
+ @Override
+ public void start(ConnectorEnvironment environment)
+ throws ConnectorException {
+ logger = environment.getLogger();
+ this.environment = environment;
+
+ logger.logInfo(JDBCPlugin.Util.getString("JDBCConnector.JDBCConnector_initialized._1")); //$NON-NLS-1$
+
+ capabilities = createCapabilities(environment, Thread.currentThread().getContextClassLoader());
+
+ Properties connectionProps = environment.getProperties();
+
+ // Get the JDBC properties ...
+ String dataSourceClassName = connectionProps.getProperty(JDBCPropertyNames.CONNECTION_SOURCE_CLASS);
+
+ // Verify required items
+ if (dataSourceClassName == null || dataSourceClassName.trim().length() == 0) {
+ throw new ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.Missing_JDBC_driver_class_name_1")); //$NON-NLS-1$
+ }
+ dataSourceClassName = dataSourceClassName.trim();
+
+ String levelStr = connectionProps.getProperty(JDBCPropertyNames.TRANSACTION_ISOLATION_LEVEL);
+
+ if(levelStr != null && levelStr.trim().length() != 0){
+ transIsoLevel = TransactionIsolationLevel.valueOf(levelStr.toUpperCase()).getConnectionConstant();
+ }
+
+ try {
+ String className = environment.getProperties().getProperty(JDBCPropertyNames.EXT_TRANSLATOR_CLASS, Translator.class.getName());
+ this.sqlTranslator = (Translator)ReflectionHelper.create(className, null, Thread.currentThread().getContextClassLoader());
+ } catch (MetaMatrixCoreException e) {
+ throw new ConnectorException(e);
+ }
+ sqlTranslator.initialize(environment);
+
+ if (areAdminConnectionsAllowed()) {
+ testConnection();
+ }
+
+ logger.logInfo(JDBCPlugin.Util.getString("JDBCConnector.JDBCConnector_started._4")); //$NON-NLS-1$
+ }
+
+ private void testConnection() throws ConnectorException {
+ Connection connection = null;
+ try {
+ connection = getConnection(null);
+ } catch (ConnectorException e) {
+ SQLException ex = (SQLException)e.getCause();
+ String sqlState = ex.getSQLState();
+ if (sqlState != null && INVALID_AUTHORIZATION_SPECIFICATION_NO_SUBCLASS.equals(sqlState)) {
+ throw e;
+ }
+ this.logger.logError(e.getMessage(), e);
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ }
+ }
+
+ @Override
+ public void stop() {
+ /*
+ * attempt to deregister drivers that may have been implicitly registered
+ * with the driver manager
+ */
+ Enumeration drivers = DriverManager.getDrivers();
+
+ String driverClassname = this.environment.getProperties().getProperty(JDBCPropertyNames.CONNECTION_SOURCE_CLASS);
+ boolean usingCustomClassLoader = PropertiesUtils.getBooleanProperty(this.environment.getProperties(), ConnectorPropertyNames.USING_CUSTOM_CLASSLOADER, false);
+
+ while(drivers.hasMoreElements()){
+ Driver tempdriver = (Driver)drivers.nextElement();
+ if(tempdriver.getClass().getClassLoader() != this.getClass().getClassLoader()) {
+ continue;
+ }
+ if(usingCustomClassLoader || tempdriver.getClass().getName().equals(driverClassname)) {
+ try {
+ DriverManager.deregisterDriver(tempdriver);
+ } catch (Throwable e) {
+ this.environment.getLogger().logError(e.getMessage());
+ }
+ }
+ }
+
+ logger.logInfo(JDBCPlugin.Util.getString("JDBCConnector.JDBCConnector_stopped._3")); //$NON-NLS-1$
+ }
+
+ @Override
+ public Connection getConnection(ExecutionContext context) throws ConnectorException {
+ DataSource dataSource = getDataSource();
+ if (dataSource == null) {
+ return getXAConnection(context, null);
+ }
+ java.sql.Connection conn = null;
+ try {
+ if (context == null || context.getConnectorIdentity() instanceof SingleIdentity) {
+ conn = dataSource.getConnection();
+ } else if (context.getConnectorIdentity() instanceof MappedUserIdentity) {
+ MappedUserIdentity id = (MappedUserIdentity)context.getConnectorIdentity();
+ conn = dataSource.getConnection(id.getMappedUser(), id.getPassword());
+ }
+ setDefaultTransactionIsolationLevel(conn);
+ } catch (SQLException e) {
+ throw new ConnectorException(e);
+ }
+ return new JDBCSourceConnection(conn, this.environment, sqlTranslator);
+ }
+
+ @Override
+ public XAConnection getXAConnection(
+ ExecutionContext context,
+ TransactionContext transactionContext) throws ConnectorException {
+ XADataSource xaDataSource = getXADataSource();
+ if (xaDataSource == null) {
+ throw new UnsupportedOperationException("Connector is not XA capable");
+ }
+ javax.sql.XAConnection conn = null;
+ try {
+ if (context == null || context.getConnectorIdentity() instanceof SingleIdentity) {
+ conn = xaDataSource.getXAConnection();
+ } else if (context.getConnectorIdentity() instanceof MappedUserIdentity) {
+ MappedUserIdentity id = (MappedUserIdentity)context.getConnectorIdentity();
+ conn = xaDataSource.getXAConnection(id.getMappedUser(), id.getPassword());
+ }
+ java.sql.Connection c = conn.getConnection();
+ setDefaultTransactionIsolationLevel(c);
+ return new JDBCSourceXAConnection(c, conn, this.environment, sqlTranslator);
+ } catch (SQLException e) {
+ throw new ConnectorException(e);
+ }
+ }
+
+ @Override
+ public ConnectorCapabilities getCapabilities() {
+ return capabilities;
+ }
+
+ static ConnectorCapabilities createCapabilities(ConnectorEnvironment environment, ClassLoader loader)
+ throws ConnectorException {
+ //create Capabilities
+ String className = environment.getProperties().getProperty(JDBCPropertyNames.EXT_CAPABILITY_CLASS, JDBCCapabilities.class.getName());
+ try {
+ ConnectorCapabilities result = (ConnectorCapabilities)ReflectionHelper.create(className, null, loader);
+ if(result instanceof JDBCCapabilities) {
+ String setCriteriaBatchSize = environment.getProperties().getProperty(JDBCPropertyNames.SET_CRITERIA_BATCH_SIZE);
+ if(setCriteriaBatchSize != null) {
+ int maxInCriteriaSize = Integer.parseInt(setCriteriaBatchSize);
+ if(maxInCriteriaSize > 0) {
+ ((JDBCCapabilities)result).setMaxInCriteriaSize(maxInCriteriaSize);
+ }
+ }
+ }
+ return result;
+ } catch (Exception e) {
+ throw new ConnectorException(e);
+ }
+ }
+
+ protected void createDataSources(String dataSourceClassName, final Properties connectionProps) throws ConnectorException {
+ // create data source
+ Object temp = null;
+ try {
+ temp = ReflectionHelper.create(dataSourceClassName, null, Thread.currentThread().getContextClassLoader());
+ } catch (MetaMatrixCoreException e) {
+ throw new ConnectorException(e,JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.Unable_to_load_the_JDBC_driver_class_6", dataSourceClassName)); //$NON-NLS-1$
+ }
+
+ final String url = connectionProps.getProperty(JDBCPropertyNames.URL);
+ if (url == null || url.trim().length() == 0) {
+ throw new ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.Missing_JDBC_database_name_3")); //$NON-NLS-1$
+ }
+
+ if (temp instanceof Driver) {
+ final Driver driver = (Driver)temp;
+ // check URL if there is one
+ validateURL(driver, url);
+ this.ds = (DataSource)Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] {DataSource.class}, new InvocationHandler() {
+ @Override
+ public Object invoke(Object proxy, Method method,
+ Object[] args) throws Throwable {
+ if (method.getName().equals("getConnection")) {
+ Properties p = new Properties();
+ if (args.length == 2) {
+ p.put("user", args[0]);
+ p.put("password", args[1]);
+ } else {
+ p.put("user", connectionProps.getProperty(JDBCPropertyNames.USERNAME));
+ p.put("password", connectionProps.getProperty(JDBCPropertyNames.PASSWORD));
+ }
+ return driver.connect(url, p);
+ }
+ throw new UnsupportedOperationException("Driver DataSource proxy only provides Connections");
+ }
+ });
+ } else {
+ parseURL(url, connectionProps);
+ if (temp instanceof DataSource) {
+ this.ds = (DataSource)temp;
+ PropertiesUtils.setBeanProperties(this.ds, connectionProps, null);
+ } else if (temp instanceof XADataSource) {
+ this.xaDs = (XADataSource)temp;
+ PropertiesUtils.setBeanProperties(this.xaDs, connectionProps, null);
+ } else {
+ throw new ConnectorException("Specified class is not a XADataSource, DataSource, or Driver " + dataSourceClassName);
+ }
+ }
+ if (this.ds instanceof XADataSource) {
+ this.xaDs = (XADataSource)this.ds;
+ }
+ }
+
+ public DataSource getDataSource() {
+ return ds;
+ }
+
+ public XADataSource getXADataSource() {
+ return xaDs;
+ }
+
+ private void validateURL(Driver driver, String url) throws ConnectorException {
+ boolean acceptsURL = false;
+ try {
+ acceptsURL = driver.acceptsURL(url);
+ } catch ( SQLException e ) {
+ throw new ConnectorException(e);
+ }
+ if(!acceptsURL ){
+ throw new ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.Driver__7", driver.getClass().getName(), url)); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Parse URL for DataSource connection properties and add to connectionProps.
+ * @param url
+ * @param connectionProps
+ * @throws ConnectorException
+ */
+ static void parseURL(final String url, final Properties connectionProps) throws ConnectorException {
+ // Will be: [jdbc:mmx:dbType://aHost:aPort], [DatabaseName=aDataBase], [CollectionID=aCollectionID], ...
+ final String[] urlParts = url.split(";"); //$NON-NLS-1$
+
+ // Will be: [jdbc:mmx:dbType:], [aHost:aPort]
+ final String[] protoHost = urlParts[0].split("//"); //$NON-NLS-1$
+
+ // Will be: [aHost], [aPort]
+ final String[] hostPort = protoHost[1].split(":"); //$NON-NLS-1$
+ connectionProps.setProperty(XAJDBCPropertyNames.SERVER_NAME, (String)hostPort[0]);
+ connectionProps.setProperty(XAJDBCPropertyNames.PORT_NUMBER, (String)hostPort[1]);
+
+ // For "databaseName", "SID", and all optional props
+ // (<propName1>=<propValue1>;<propName2>=<propValue2>;...)
+ for ( int i = 1; i < urlParts.length; i++ ) {
+ final String nameVal = (String) urlParts[i];
+ // Will be: [propName], [propVal]
+ final String[] aProp = nameVal.split("="); //$NON-NLS-1$
+ if ( aProp.length > 1) {
+ // Set optional prop names lower case so that we can find
+ // set method names for them when we introspect the DataSource
+ connectionProps.setProperty(aProp[0].toLowerCase(), aProp[1]);
+ }
+ }
+
+ String serverName = connectionProps.getProperty(XAJDBCPropertyNames.SERVER_NAME);
+ String serverPort = connectionProps.getProperty(XAJDBCPropertyNames.PORT_NUMBER);
+ if ( serverName == null || serverName.trim().length() == 0 ) {
+ throw new ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.MissingProp", //$NON-NLS-1$
+ XAJDBCPropertyNames.SERVER_NAME));
+ }
+ if ( serverPort == null || serverPort.trim().length() == 0 ) {
+ throw new ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.MissingProp", //$NON-NLS-1$
+ XAJDBCPropertyNames.PORT_NUMBER));
+ }
+
+ // Unique resource name for this connector
+ final StringBuffer dataSourceResourceName = new StringBuffer(connectionProps.getProperty(XAJDBCPropertyNames.DATASOURCE_NAME, "XADS")); //$NON-NLS-1$
+ dataSourceResourceName.append('_');
+ dataSourceResourceName.append(serverName);
+ dataSourceResourceName.append('_');
+ dataSourceResourceName.append(connectionProps.getProperty(ConnectorPropertyNames.CONNECTOR_ID));
+ connectionProps.setProperty( XAJDBCPropertyNames.DATASOURCE_NAME, dataSourceResourceName.toString());
+ }
+
+ public int getDefaultTransactionIsolationLevel() {
+ return this.transIsoLevel;
+ }
+
+ protected void setDefaultTransactionIsolationLevel(java.sql.Connection sqlConn)
+ throws SQLException {
+ if(getDefaultTransactionIsolationLevel() != NO_ISOLATION_LEVEL_SET && getDefaultTransactionIsolationLevel() != java.sql.Connection.TRANSACTION_NONE){
+ sqlConn.setTransactionIsolation(getDefaultTransactionIsolationLevel());
+ }
+ }
+
+}
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCExecutionHelper.java (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/util/JDBCExecutionHelper.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCExecutionHelper.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCExecutionHelper.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+/*
+ */
+package org.teiid.connector.jdbc;
+
+import java.util.Iterator;
+import java.util.List;
+
+import com.metamatrix.connector.api.ConnectorException;
+import com.metamatrix.connector.api.ExecutionContext;
+import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.api.ValueTranslator;
+import com.metamatrix.connector.basic.BasicValueTranslator;
+
+/**
+ */
+public class JDBCExecutionHelper {
+
+
+ public static Object convertValue(Object value, Class expectedType, List valueTranslators, TypeFacility typeFacility, boolean trimStrings, ExecutionContext context) throws ConnectorException {
+ if(expectedType.isAssignableFrom(value.getClass())){
+ return value;
+ }
+ ValueTranslator translator = determineTransformation(value.getClass(), expectedType, valueTranslators, typeFacility);
+ Object result = translator.translate(value, context);
+ if(trimStrings && result instanceof String){
+ result = trimString((String)result);
+ }
+ return result;
+ }
+
+ /**
+ * @param actualType
+ * @param expectedType
+ * @return Transformation between actual and expected type
+ */
+ public static ValueTranslator determineTransformation(Class actualType, Class expectedType, List valueTranslators, TypeFacility typeFacility) throws ConnectorException {
+ ValueTranslator valueTranslator = null;
+
+ //check valueTranslators first
+ if(valueTranslators != null && !valueTranslators.isEmpty()){
+ Iterator iter = valueTranslators.iterator();
+ while(iter.hasNext()){
+ ValueTranslator translator = (ValueTranslator)iter.next();
+
+ //Evaluate expressions in this order for performance.
+ if(expectedType.equals(translator.getTargetType()) && translator.getSourceType().isAssignableFrom(actualType)){
+ valueTranslator = translator;
+ break;
+ }
+ }
+ }
+
+ if(valueTranslator == null){
+ valueTranslator = new BasicValueTranslator(actualType, expectedType, typeFacility);
+ }
+ return valueTranslator;
+ }
+
+ /**
+ * Expects string to never be null
+ * @param value Incoming value
+ * @return Right trimmed value
+ * @since 4.2
+ */
+ public static String trimString(String value) {
+ for(int i=value.length()-1; i>=0; i--) {
+ if(value.charAt(i) != ' ') {
+ // end of trim, return what's left
+ return value.substring(0, i+1);
+ }
+ }
+
+ // All spaces, so trim it all
+ return ""; //$NON-NLS-1$
+ }
+
+}
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCExecutionHelper.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCPlugin.java (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCPlugin.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCPlugin.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCPlugin.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+/*
+ */
+package org.teiid.connector.jdbc;
+
+import java.util.ResourceBundle;
+import com.metamatrix.core.BundleUtil;
+
+/**
+ * CommonPlugin
+ * <p>Used here in <code>data</code> to have access to the new
+ * logging framework for <code>LogManager</code>.</p>
+ */
+public class JDBCPlugin { // extends Plugin {
+
+ public static final String PLUGIN_ID = "org.teiid.connector.jdbc" ; //$NON-NLS-1$
+
+ public static final BundleUtil Util = new BundleUtil(PLUGIN_ID,
+ PLUGIN_ID + ".i18n", ResourceBundle.getBundle(PLUGIN_ID + ".i18n")); //$NON-NLS-1$ //$NON-NLS-2$
+}
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCPlugin.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCProcedureExecution.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCProcedureExecution.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCProcedureExecution.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCProcedureExecution.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,197 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc;
+
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.teiid.connector.jdbc.translator.TranslatedCommand;
+import org.teiid.connector.jdbc.translator.Translator;
+
+import com.metamatrix.connector.api.ConnectorEnvironment;
+import com.metamatrix.connector.api.ConnectorException;
+import com.metamatrix.connector.api.ConnectorLogger;
+import com.metamatrix.connector.api.DataNotAvailableException;
+import com.metamatrix.connector.api.ExecutionContext;
+import com.metamatrix.connector.api.ProcedureExecution;
+import com.metamatrix.connector.language.ICommand;
+import com.metamatrix.connector.language.IParameter;
+import com.metamatrix.connector.language.IProcedure;
+import com.metamatrix.connector.language.IParameter.Direction;
+import com.metamatrix.connector.metadata.runtime.Element;
+import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
+
+/**
+ */
+public class JDBCProcedureExecution extends JDBCQueryExecution implements ProcedureExecution {
+
+ private Map parameterIndexMap;
+ private RuntimeMetadata metadata;
+
+ /**
+ * @param connection
+ * @param sqlTranslator
+ * @param logger
+ * @param props
+ * @param id
+ */
+ public JDBCProcedureExecution(ICommand command,
+ Connection connection,
+ Translator sqlTranslator,
+ ConnectorLogger logger,
+ Properties props,
+ RuntimeMetadata metadata, ExecutionContext context,
+ ConnectorEnvironment env) {
+ super(command, connection, sqlTranslator, logger, props, context, env);
+ this.metadata = metadata;
+ }
+
+ @Override
+ public void execute() throws ConnectorException {
+ IProcedure procedure = (IProcedure)command;
+ columnDataTypes = getColumnDataTypes(procedure.getParameters(), metadata);
+
+ //translate command
+ TranslatedCommand translatedComm = translateCommand(procedure);
+
+ //create statement or CallableStatement and execute
+ String sql = translatedComm.getSql();
+ try{
+ //create parameter index map
+ parameterIndexMap = createParameterIndexMap(procedure.getParameters(), sql);
+ CallableStatement cstmt = getCallableStatement(sql);
+ results = sqlTranslator.executeStoredProcedure(cstmt, translatedComm);
+ if (results != null) {
+ initResultSetInfo();
+ }
+ addStatementWarnings();
+ }catch(SQLException e){
+ throw new ConnectorException(e, JDBCPlugin.Util.getString("JDBCQueryExecution.Error_executing_query__1", sql));
+ }
+
+ }
+
+ @Override
+ public List next() throws ConnectorException, DataNotAvailableException {
+ if (results == null) {
+ return null;
+ }
+ return super.next();
+ }
+
+ /**
+ * @param results
+ * @return
+ */
+ public static Class[] getColumnDataTypes(List params, RuntimeMetadata metadata) throws ConnectorException {
+ if (params != null) {
+ IParameter resultSet = null;
+ Iterator iter = params.iterator();
+ while(iter.hasNext()){
+ IParameter param = (IParameter)iter.next();
+ if(param.getDirection() == Direction.RESULT_SET){
+ resultSet = param;
+ break;
+ }
+ }
+
+ if(resultSet != null){
+ List<Element> columnMetadata = resultSet.getMetadataObject().getChildren();
+
+ int size = columnMetadata.size();
+ Class[] coulmnDTs = new Class[size];
+ for(int i =0; i<size; i++ ){
+ coulmnDTs[i] = columnMetadata.get(i).getJavaType();
+ }
+ return coulmnDTs;
+ }
+
+ }
+ return new Class[0];
+ }
+
+ /**
+ * @param parameters List of IParameter
+ * @param sql
+ * @return Map of IParameter to index in sql.
+ */
+ public static Map createParameterIndexMap(List parameters, String sql) {
+ if(parameters == null || parameters.isEmpty()){
+ return Collections.EMPTY_MAP;
+ }
+ Map paramsIndexes = new HashMap();
+ int index = 1;
+
+ //return parameter, if there is any, is the first parameter
+ Iterator iter = parameters.iterator();
+ while(iter.hasNext()){
+ IParameter param = (IParameter)iter.next();
+ if(param.getDirection() == Direction.RETURN){
+ paramsIndexes.put(param, new Integer(index++));
+ break;
+ }
+ }
+
+ iter = parameters.iterator();
+ while(iter.hasNext()){
+ IParameter param = (IParameter)iter.next();
+ if(param.getDirection() != Direction.RESULT_SET && param.getDirection() != Direction.RETURN){
+ paramsIndexes.put(param, new Integer(index++));
+ }
+ }
+ return paramsIndexes;
+ }
+
+ /*
+ * @see com.metamatrix.data.ProcedureExecution#getOutputValue(com.metamatrix.data.language.IParameter)
+ */
+ public Object getOutputValue(IParameter parameter) throws ConnectorException {
+ if(parameter.getDirection() != Direction.OUT && parameter.getDirection() != Direction.INOUT && parameter.getDirection() != Direction.RETURN){
+ throw new ConnectorException(JDBCPlugin.Util.getString("JDBCProcedureExecution.The_parameter_direction_must_be_out_or_inout_1")); //$NON-NLS-1$
+ }
+
+ Integer index = (Integer)this.parameterIndexMap.get(parameter);
+ if(index == null){
+ //should not come here
+ throw new ConnectorException(JDBCPlugin.Util.getString("JDBCProcedureExecution.Unexpected_exception_1")); //$NON-NLS-1$
+ }
+ try {
+ Object value = sqlTranslator.retrieveValue((CallableStatement)this.statement, index.intValue(), parameter.getType());
+ if(value == null){
+ return null;
+ }
+ Object result = JDBCExecutionHelper.convertValue(value, parameter.getType(), this.sqlTranslator.getValueTranslators(), this.sqlTranslator.getTypeFacility(), trimString, context);
+ return result;
+ } catch (SQLException e) {
+ throw new ConnectorException(e);
+ }
+ }
+
+}
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCProcedureExecution.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCPropertyNames.java (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCPropertyNames.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCPropertyNames.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCPropertyNames.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc;
+
+public class JDBCPropertyNames {
+ public static final String CONNECTION_SOURCE_CLASS = "Driver"; //$NON-NLS-1$
+ public static final String URL = "URL"; //$NON-NLS-1$
+ public static final String USERNAME = "User"; //$NON-NLS-1$
+ public static final String PASSWORD = "Password"; //$NON-NLS-1$
+
+ /**
+ * This is the property name of the ConnectorService property that defines
+ * whether or not String type values in Criteria statements in SQL queries to
+ * the data source should have spaces trimmed from them.
+ */
+ public static final String TRIM_STRINGS = "TrimStrings"; //$NON-NLS-1$
+
+ /**
+ * This is the property name of the ConnectorService property that defines
+ * the size of a SetCriteria (IN criteria) before the criteria is broken into
+ * multiple queries and the results are aggregated. 0 indicates that set
+ * criteria should never be broken. The default value should be 0.
+ */
+ public static final String SET_CRITERIA_BATCH_SIZE = "SetCriteriaBatchSize"; //$NON-NLS-1$
+
+ /**
+ * This is the property name used to set the transaction isolation level on
+ * a connector's data source. The value string must be the the same as one of the
+ * names of the values of the transaction isolation levels defined in
+ * <code>java.sql.Connection</code>.
+ * @see java.sql.Connection#setTransactionIsolation(int)
+ */
+ public static final String TRANSACTION_ISOLATION_LEVEL = "TransactionIsolationLevel"; //$NON-NLS-1$
+
+ /**
+ * This is the property name of the ConnectorService property that defines
+ * the time zone of the source database. This property should only be used in
+ * cases where the source database is in a different time zone than the
+ * ConnectorService VM and the database/driver is not already handling
+ * time zones correctly.
+ */
+ public static final String DATABASE_TIME_ZONE = "DatabaseTimeZone"; //$NON-NLS-1$
+
+ //***** Extension properties *****//
+ /**
+ * This property is used to specify the implementation of
+ * com.metamatrix.data.ConnectorCapabilities.
+ */
+ public static final String EXT_CAPABILITY_CLASS= "ExtensionCapabilityClass"; //$NON-NLS-1$
+
+ /**
+ * This property is used to specify the implementation of
+ * com.metamatrix.connector.jdbc.extension.Translator
+ */
+ public static final String EXT_TRANSLATOR_CLASS= "ExtensionTranslationClass"; //$NON-NLS-1$
+
+ /**
+ * This property can be used to specify the fetch size used from the connector to
+ * its underlying source.
+ */
+ public static final String FETCH_SIZE = "FetchSize"; //$NON-NLS-1$
+
+ /**
+ * This property can be used to indicate that prepared statements should be used.
+ * This means Literals will be substituted for
+ * bind variables.
+ * @since 5.0.1
+ */
+ public static final String USE_BIND_VARIABLES = "UseBindVariables"; //$NON-NLS-1$
+
+ /**
+ * This property is used to turn on/off the use of the default comments like
+ * connection id and requestid in the source SQL query.
+ */
+ public static final String USE_COMMENTS_SOURCE_QUERY= "UseCommentsInSourceQuery"; //$NON-NLS-1$
+
+ public static final String CONNECTION_TEST_QUERY = "ConnectionTestQuery"; //$NON-NLS-1$
+
+ public static final String IS_VALID_TIMEOUT = "IsValidTimeout"; //$NON-NLS-1$
+
+}
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCPropertyNames.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCQueryExecution.java (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCQueryExecution.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCQueryExecution.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCQueryExecution.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,195 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+/*
+ */
+
+package org.teiid.connector.jdbc;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.teiid.connector.jdbc.translator.TranslatedCommand;
+import org.teiid.connector.jdbc.translator.Translator;
+
+import com.metamatrix.connector.api.ConnectorEnvironment;
+import com.metamatrix.connector.api.ConnectorException;
+import com.metamatrix.connector.api.ConnectorLogger;
+import com.metamatrix.connector.api.DataNotAvailableException;
+import com.metamatrix.connector.api.ExecutionContext;
+import com.metamatrix.connector.api.ResultSetExecution;
+import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.api.ValueTranslator;
+import com.metamatrix.connector.language.ICommand;
+import com.metamatrix.connector.language.IQueryCommand;
+
+/**
+ *
+ */
+public class JDBCQueryExecution extends JDBCBaseExecution implements ResultSetExecution {
+
+ // ===========================================================================================================================
+ // Fields
+ // ===========================================================================================================================
+
+ protected ResultSet results;
+ protected Class[] columnDataTypes;
+ protected ConnectorEnvironment env;
+ protected ICommand command;
+ private boolean[] transformKnown;
+ private ValueTranslator[] transforms;
+ private boolean[] trimColumn;
+ private int[] nativeTypes;
+
+ // ===========================================================================================================================
+ // Constructors
+ // ===========================================================================================================================
+
+ public JDBCQueryExecution(ICommand command, Connection connection,
+ Translator sqlTranslator,
+ ConnectorLogger logger,
+ Properties props,
+ ExecutionContext context,
+ ConnectorEnvironment env) {
+ super(connection, sqlTranslator, logger, props, context);
+ this.command = command;
+ this.env = env;
+ }
+
+ @Override
+ public void execute() throws ConnectorException {
+ // get column types
+ columnDataTypes = ((IQueryCommand)command).getColumnTypes();
+
+ // translate command
+ TranslatedCommand translatedComm = translateCommand(command);
+
+ String sql = translatedComm.getSql();
+
+ try {
+
+ if (!translatedComm.isPrepared()) {
+ results = getStatement().executeQuery(sql);
+ } else {
+ PreparedStatement pstatement = getPreparedStatement(sql);
+ sqlTranslator.bindPreparedStatementValues(this.connection, pstatement, translatedComm);
+ results = pstatement.executeQuery();
+ }
+ addStatementWarnings();
+ initResultSetInfo();
+
+ } catch (SQLException e) {
+ throw createAndLogError(e, translatedComm);
+ }
+ }
+
+ protected void initResultSetInfo() throws SQLException {
+ trimColumn = new boolean[columnDataTypes.length];
+ nativeTypes = new int[columnDataTypes.length];
+ ResultSetMetaData rsmd = results.getMetaData();
+ for(int i=0; i<columnDataTypes.length; i++) {
+
+ nativeTypes[i] = rsmd.getColumnType(i+1);
+ if ((nativeTypes[i] == Types.BLOB && (columnDataTypes[i] == TypeFacility.RUNTIME_TYPES.BLOB || columnDataTypes[i] == TypeFacility.RUNTIME_TYPES.OBJECT))
+ || (nativeTypes[i] == Types.CLOB && (columnDataTypes[i] == TypeFacility.RUNTIME_TYPES.CLOB || columnDataTypes[i] == TypeFacility.RUNTIME_TYPES.OBJECT))) {
+ context.keepExecutionAlive(true);
+ }
+
+ if(columnDataTypes[i].equals(String.class)) {
+ if(trimString || nativeTypes[i] == Types.CHAR) {
+ trimColumn[i] = true;
+ }
+ }
+ }
+
+ transformKnown = new boolean[columnDataTypes.length];
+ transforms = new ValueTranslator[columnDataTypes.length];
+ }
+
+ @Override
+ public List next() throws ConnectorException, DataNotAvailableException {
+ try {
+ if (results.next()) {
+ // New row for result set
+ List vals = new ArrayList(columnDataTypes.length);
+
+ for (int i = 0; i < columnDataTypes.length; i++) {
+ // Convert from 0-based to 1-based
+ Object value = sqlTranslator.retrieveValue(results, i+1, columnDataTypes[i]);
+ if(value != null) {
+ // Determine transformation if unknown
+ if(! transformKnown[i]) {
+ Class valueType = value.getClass();
+ if(!columnDataTypes[i].isAssignableFrom(valueType)) {
+ transforms[i] = JDBCExecutionHelper.determineTransformation(valueType, columnDataTypes[i], sqlTranslator.getValueTranslators(), sqlTranslator.getTypeFacility());
+ }
+ transformKnown[i] = true;
+ }
+
+ // Transform value if necessary
+ if(transforms[i] != null) {
+ value = transforms[i].translate(value, context);
+ }
+
+ // Trim string column if necessary
+ if(trimColumn[i]) {
+ value = JDBCExecutionHelper.trimString((String) value);
+ }
+ }
+ vals.add(value);
+ }
+
+ return vals;
+ }
+ } catch (SQLException e) {
+ throw new ConnectorException(e,
+ JDBCPlugin.Util.getString("JDBCTranslator.Unexpected_exception_translating_results___8", e.getMessage())); //$NON-NLS-1$
+ }
+
+ return null;
+ }
+
+ /**
+ * @see org.teiid.connector.jdbc.JDBCBaseExecution#close()
+ */
+ public void close() throws ConnectorException {
+ // first we would need to close the result set here then we can close
+ // the statement, using the base class.
+ if (results != null) {
+ try {
+ results.close();
+ results = null;
+ } catch (SQLException e) {
+ throw new ConnectorException(e);
+ }
+ }
+ super.close();
+ }
+
+}
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCQueryExecution.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCSourceConnection.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCSourceConnection.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCSourceConnection.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCSourceConnection.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+/*
+ */
+package org.teiid.connector.jdbc;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.teiid.connector.jdbc.translator.Translator;
+
+import com.metamatrix.connector.api.ConnectorEnvironment;
+import com.metamatrix.connector.api.ConnectorException;
+import com.metamatrix.connector.api.ConnectorLogger;
+import com.metamatrix.connector.api.ExecutionContext;
+import com.metamatrix.connector.api.ProcedureExecution;
+import com.metamatrix.connector.api.ResultSetExecution;
+import com.metamatrix.connector.api.UpdateExecution;
+import com.metamatrix.connector.language.ICommand;
+import com.metamatrix.connector.language.IProcedure;
+import com.metamatrix.connector.language.IQueryCommand;
+import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
+
+/**
+ *
+ */
+public class JDBCSourceConnection extends com.metamatrix.connector.basic.BasicConnection {
+ protected java.sql.Connection physicalConnection;
+ protected ConnectorEnvironment environment;
+ private ConnectorLogger logger;
+ private Translator sqlTranslator;
+
+ public JDBCSourceConnection(java.sql.Connection connection, ConnectorEnvironment environment, Translator sqlTranslator) throws ConnectorException {
+ this.physicalConnection = connection;
+ this.environment = environment;
+ this.logger = environment.getLogger();
+ this.sqlTranslator = sqlTranslator;
+ this.sqlTranslator.afterConnectionCreation(connection);
+ }
+
+ @Override
+ public ResultSetExecution createResultSetExecution(IQueryCommand command,
+ ExecutionContext executionContext, RuntimeMetadata metadata)
+ throws ConnectorException {
+ return new JDBCQueryExecution(command, this.physicalConnection, sqlTranslator, logger, this.environment.getProperties(), executionContext, this.environment);
+ }
+
+ @Override
+ public ProcedureExecution createProcedureExecution(IProcedure command,
+ ExecutionContext executionContext, RuntimeMetadata metadata)
+ throws ConnectorException {
+ return new JDBCProcedureExecution(command, this.physicalConnection, sqlTranslator, logger, this.environment.getProperties(), metadata, executionContext, this.environment);
+ }
+
+ @Override
+ public UpdateExecution createUpdateExecution(ICommand command,
+ ExecutionContext executionContext, RuntimeMetadata metadata)
+ throws ConnectorException {
+ return new JDBCUpdateExecution(command, this.physicalConnection, sqlTranslator, logger, this.environment.getProperties(), executionContext);
+ }
+
+ @Override
+ public void close() {
+ closeSourceConnection();
+ }
+
+ protected void closeSourceConnection() {
+ try {
+ this.physicalConnection.close();
+ } catch(SQLException e) {
+ logger.logDetail("Exception during close: " + e.getMessage());
+ }
+ }
+
+ @Override
+ public boolean isAlive() {
+ Connection connection = this.physicalConnection;
+ Statement statement = null;
+ try {
+ int timeout = this.sqlTranslator.getIsValidTimeout();
+ if (timeout >= 0) {
+ return connection.isValid(timeout);
+ }
+ if(connection.isClosed()){
+ return false;
+ }
+ String connectionTestQuery = sqlTranslator.getConnectionTestQuery();
+ if (connectionTestQuery != null) {
+ statement = connection.createStatement();
+ statement.executeQuery(connectionTestQuery);
+ }
+ } catch(SQLException e) {
+ return false;
+ } finally {
+ if ( statement != null ) {
+ try {
+ statement.close();
+ } catch ( SQLException e ) {
+ }
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public void closeCalled() {
+
+ }
+
+}
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCSourceConnection.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCUpdateExecution.java (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCUpdateExecution.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCUpdateExecution.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCUpdateExecution.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,265 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.teiid.connector.jdbc.translator.TranslatedCommand;
+import org.teiid.connector.jdbc.translator.Translator;
+
+import com.metamatrix.connector.api.ConnectorException;
+import com.metamatrix.connector.api.ConnectorLogger;
+import com.metamatrix.connector.api.DataNotAvailableException;
+import com.metamatrix.connector.api.ExecutionContext;
+import com.metamatrix.connector.api.UpdateExecution;
+import com.metamatrix.connector.language.IBatchedUpdates;
+import com.metamatrix.connector.language.IBulkInsert;
+import com.metamatrix.connector.language.ICommand;
+
+/**
+ */
+public class JDBCUpdateExecution extends JDBCBaseExecution implements
+ UpdateExecution {
+
+ private ICommand command;
+ private int[] result;
+
+ /**
+ * @param connection
+ * @param sqlTranslator
+ * @param logger
+ * @param props
+ * @param id
+ */
+ public JDBCUpdateExecution(ICommand command, Connection connection,
+ Translator sqlTranslator,
+ ConnectorLogger logger,
+ Properties props,
+ ExecutionContext context) {
+ super(connection, sqlTranslator, logger, props, context);
+ this.command = command;
+ }
+
+ // ===========================================================================================================================
+ // Methods
+ // ===========================================================================================================================
+
+ @Override
+ public void execute() throws ConnectorException {
+ if (command instanceof IBulkInsert) {
+ result = new int [] {execute((IBulkInsert)command)};
+ } else if (command instanceof IBatchedUpdates) {
+ result = execute(((IBatchedUpdates)command));
+ } else {
+ // translate command
+ TranslatedCommand translatedComm = translateCommand(command);
+
+ result = new int [] {executeTranslatedCommand(translatedComm)};
+ }
+ }
+
+ /**
+ * @see com.metamatrix.data.api.BatchedUpdatesExecution#execute(com.metamatrix.connector.language.ICommand[])
+ * @since 4.2
+ */
+ public int[] execute(IBatchedUpdates batchedCommand) throws ConnectorException {
+ boolean succeeded = false;
+
+ boolean commitType = getAutoCommit(null);
+ ICommand[] commands = (ICommand[])batchedCommand.getUpdateCommands().toArray(new ICommand[batchedCommand.getUpdateCommands().size()]);
+ int[] results = new int[commands.length];
+
+ try {
+ // temporarily turn the auto commit off, and set it back to what it was
+ // before at the end of the command execution.
+ if (commitType) {
+ connection.setAutoCommit(false);
+ }
+
+ List executedCmds = new ArrayList();
+
+ TranslatedCommand previousCommand = null;
+
+ for (int i = 0; i < commands.length; i++) {
+ TranslatedCommand command = translateCommand(commands[i]);
+ if (command.isPrepared()) {
+ PreparedStatement pstmt = null;
+ if (previousCommand != null && previousCommand.isPrepared() && previousCommand.getSql().equals(command.getSql())) {
+ pstmt = (PreparedStatement)statement;
+ } else {
+ if (!executedCmds.isEmpty()) {
+ executeBatch(i, results, executedCmds);
+ }
+ pstmt = getPreparedStatement(command.getSql());
+ }
+ sqlTranslator.bindPreparedStatementValues(this.connection, pstmt, command);
+ pstmt.addBatch();
+ } else {
+ if (previousCommand != null && previousCommand.isPrepared()) {
+ executeBatch(i, results, executedCmds);
+ getStatement();
+ }
+ if (statement == null) {
+ getStatement();
+ }
+ statement.addBatch(command.getSql());
+ }
+ executedCmds.add(command);
+ previousCommand = command;
+ }
+ if (!executedCmds.isEmpty()) {
+ executeBatch(commands.length, results, executedCmds);
+ }
+ succeeded = true;
+ } catch (SQLException e) {
+ throw createAndLogError(e, null);
+ } finally {
+ if (commitType) {
+ restoreAutoCommit(!succeeded, null);
+ }
+ }
+
+ return results;
+ }
+
+ /**
+ * An implementation to bulk insert rows into single table.
+ *
+ * @param command
+ * @return
+ * @throws ConnectorException
+ */
+ public int execute(IBulkInsert command) throws ConnectorException {
+ boolean succeeded = false;
+
+ // translate command
+ TranslatedCommand translatedComm = translateCommand(command);
+
+ // create statement or PreparedStatement and execute
+ String sql = translatedComm.getSql();
+
+ boolean commitType = getAutoCommit(translatedComm);
+ int updateCount = -1;
+ try {
+ // temporarily turn the auto commit off, and set it back to what it was
+ // before at the end of the command execution.
+ if (commitType) {
+ connection.setAutoCommit(false);
+ }
+ PreparedStatement stmt = getPreparedStatement(sql);
+ updateCount = sqlTranslator.executeStatementForBulkInsert(this.connection, stmt, translatedComm);
+ addStatementWarnings();
+ succeeded = true;
+ } catch (SQLException e) {
+ throw createAndLogError(e, translatedComm);
+ } finally {
+ if (commitType) {
+ restoreAutoCommit(!succeeded, translatedComm);
+ }
+ }
+ return updateCount;
+ }
+
+ private void executeBatch(int commandCount,
+ int[] results,
+ List commands) throws ConnectorException {
+ try {
+ int[] batchResults = statement.executeBatch();
+ addStatementWarnings();
+ for (int j = 0; j < batchResults.length; j++) {
+ results[commandCount - 1 - j] = batchResults[batchResults.length - 1 - j];
+ }
+ commands.clear();
+ } catch (SQLException err) {
+ throw createAndLogError(err, "JDBCQueryExecution.Error_executing_query__3", commands); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * @param translatedComm
+ * @throws ConnectorException
+ * @since 4.3
+ */
+ private int executeTranslatedCommand(TranslatedCommand translatedComm) throws ConnectorException {
+ // create statement or PreparedStatement and execute
+ String sql = translatedComm.getSql();
+
+ try {
+ int updateCount;
+ if (!translatedComm.isPrepared()) {
+ updateCount = getStatement().executeUpdate(sql);
+ } else {
+ PreparedStatement pstatement = getPreparedStatement(sql);
+ sqlTranslator.bindPreparedStatementValues(this.connection, pstatement, translatedComm);
+ updateCount = pstatement.executeUpdate();
+ }
+ addStatementWarnings();
+ return updateCount;
+ } catch (SQLException err) {
+ throw createError(err, translatedComm);
+ }
+ }
+
+ /**
+ * @param command
+ * @return
+ * @throws ConnectorException
+ */
+ private boolean getAutoCommit(TranslatedCommand command) throws ConnectorException {
+ try {
+ return connection.getAutoCommit();
+ } catch (SQLException err) {
+ throw createAndLogError(err, command);
+ }
+ }
+
+ /**
+ * If the auto comm
+ *
+ * @param exceptionOccurred
+ * @param command
+ * @throws ConnectorException
+ */
+ private void restoreAutoCommit(boolean exceptionOccurred,
+ TranslatedCommand command) throws ConnectorException {
+ try {
+ if (exceptionOccurred) {
+ connection.rollback();
+ }
+ connection.setAutoCommit(true);
+ } catch (SQLException err) {
+ throw createAndLogError(err, command);
+ }
+ }
+
+ @Override
+ public int[] getUpdateCounts() throws DataNotAvailableException,
+ ConnectorException {
+ return result;
+ }
+}
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCUpdateExecution.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/SimpleCapabilities.java (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/SimpleCapabilities.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/SimpleCapabilities.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/SimpleCapabilities.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,371 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc;
+
+import java.util.List;
+
+import com.metamatrix.connector.api.ConnectorCapabilities;
+
+/**
+ * This is a "simple" capabilities class that allows criteria but no
+ * complicated joins, subqueries, etc to be passed to the connector.
+ * This capabilities class may come in handy for testing and for
+ * sources that support JDBC but don't support extended JDBC capabilities.
+ */
+public class SimpleCapabilities extends JDBCCapabilities implements ConnectorCapabilities {
+
+ public SimpleCapabilities() {
+ // Max acceptable by all BQT dbs (Sybase=250, Oracle=1000)
+ setMaxInCriteriaSize(250);
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAndCriteria()
+ */
+ public boolean supportsAndCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCompareCriteria()
+ */
+ public boolean supportsCompareCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCompareCriteriaEquals()
+ */
+ public boolean supportsCompareCriteriaEquals() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCompareCriteriaGreaterThan()
+ */
+ public boolean supportsCompareCriteriaGreaterThan() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCompareCriteriaGreaterThanOrEqual()
+ */
+ public boolean supportsCompareCriteriaGreaterThanOrEqual() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCompareCriteriaLessThan()
+ */
+ public boolean supportsCompareCriteriaLessThan() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCompareCriteriaLessThanOrEqual()
+ */
+ public boolean supportsCompareCriteriaLessThanOrEqual() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCompareCriteriaNotEquals()
+ */
+ public boolean supportsCompareCriteriaNotEquals() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCriteria()
+ */
+ public boolean supportsCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsInCriteria()
+ */
+ public boolean supportsInCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsIsNullCriteria()
+ */
+ public boolean supportsIsNullCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsJoins()
+ */
+ public boolean supportsJoins() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsLikeCriteria()
+ */
+ public boolean supportsLikeCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsNotCriteria()
+ */
+ public boolean supportsNotCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsOrCriteria()
+ */
+ public boolean supportsOrCriteria() {
+ return true;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsSelectDistinct()
+ */
+ public boolean supportsSelectDistinct() {
+ return true;
+ }
+
+ /**
+ * @see com.metamatrix.connector.api.ConnectorCapabilities#supportsSelectLiterals()
+ * @since 4.2
+ */
+ public boolean supportsSelectLiterals() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAliasedGroup()
+ */
+ public boolean supportsAliasedGroup() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsSelfJoins()
+ */
+ public boolean supportsSelfJoins() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsOuterJoins()
+ */
+ public boolean supportsOuterJoins() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsFullOuterJoins()
+ */
+ public boolean supportsFullOuterJoins() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsBetweenCriteria()
+ */
+ public boolean supportsBetweenCriteria() {
+ return false;
+ }
+
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsLikeCriteriaEscapeCharacter()
+ */
+ public boolean supportsLikeCriteriaEscapeCharacter() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsInCriteriaSubquery()
+ */
+ public boolean supportsInCriteriaSubquery() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsExistsCriteria()
+ */
+ public boolean supportsExistsCriteria() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsQuantifiedCompareCriteria()
+ */
+ public boolean supportsQuantifiedCompareCriteria() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsQuantifiedCompareCriteriaSome()
+ */
+ public boolean supportsQuantifiedCompareCriteriaSome() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsQuantifiedCompareCriteriaAll()
+ */
+ public boolean supportsQuantifiedCompareCriteriaAll() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsOrderBy()
+ */
+ public boolean supportsOrderBy() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAggregates()
+ */
+ public boolean supportsAggregates() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAggregatesSum()
+ */
+ public boolean supportsAggregatesSum() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAggregatesAvg()
+ */
+ public boolean supportsAggregatesAvg() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAggregatesMin()
+ */
+ public boolean supportsAggregatesMin() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAggregatesMax()
+ */
+ public boolean supportsAggregatesMax() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAggregatesCount()
+ */
+ public boolean supportsAggregatesCount() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAggregatesCountStar()
+ */
+ public boolean supportsAggregatesCountStar() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsAggregatesDistinct()
+ */
+ public boolean supportsAggregatesDistinct() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsScalarSubqueries()
+ */
+ public boolean supportsScalarSubqueries() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCorrelatedSubqueries()
+ */
+ public boolean supportsCorrelatedSubqueries() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsCaseExpressions()
+ */
+ public boolean supportsCaseExpressions() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsSearchedCaseExpressions()
+ */
+ public boolean supportsSearchedCaseExpressions() {
+ return false;
+ }
+
+ /*
+ * @see com.metamatrix.data.api.ConnectorCapabilities#supportsScalarFunctions()
+ */
+ public boolean supportsScalarFunctions() {
+ return false;
+ }
+
+ /**
+ * Return null to indicate no functions are supported.
+ * @return null
+ * @see com.metamatrix.connector.api.ConnectorCapabilities#getSupportedFunctions()
+ */
+ public List getSupportedFunctions() {
+ return null;
+ }
+
+ public boolean supportsInlineViews() {
+ return false;
+ }
+
+ public boolean supportsOrderByInInlineViews() {
+ return false;
+ }
+
+ /**
+ * @see com.metamatrix.connector.api.ConnectorCapabilities#supportsUnionOrderBy()
+ * @since 4.2
+ */
+ public boolean supportsUnionOrderBy() {
+ return false;
+ }
+
+ /**
+ * @see com.metamatrix.connector.api.ConnectorCapabilities#supportsUnions()
+ * @since 4.2
+ */
+ public boolean supportsUnions() {
+ return false;
+ }
+
+}
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/SimpleCapabilities.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/access (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/access)
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/access
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/access/AccessCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/access/AccessCapabilities.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/access/AccessCapabilities.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -22,9 +22,9 @@
/*
*/
-package com.metamatrix.connector.jdbc.access;
+package org.teiid.connector.jdbc.access;
-import com.metamatrix.connector.jdbc.JDBCCapabilities;
+import org.teiid.connector.jdbc.JDBCCapabilities;
public class AccessCapabilities extends JDBCCapabilities{
/*
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/access/AccessSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/access/AccessSQLTranslator.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/access/AccessSQLTranslator.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -22,9 +22,10 @@
/*
*/
-package com.metamatrix.connector.jdbc.access;
+package org.teiid.connector.jdbc.access;
-import com.metamatrix.connector.jdbc.translator.Translator;
+import org.teiid.connector.jdbc.translator.Translator;
+
import com.metamatrix.connector.language.ILimit;
public class AccessSQLTranslator extends Translator {
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2 (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2)
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2Capabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2Capabilities.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2Capabilities.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -22,12 +22,13 @@
/*
*/
-package com.metamatrix.connector.jdbc.db2;
+package org.teiid.connector.jdbc.db2;
import java.util.ArrayList;
import java.util.List;
+
+import org.teiid.connector.jdbc.JDBCCapabilities;
-import com.metamatrix.connector.jdbc.JDBCCapabilities;
/**
*/
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2ConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2ConvertModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2ConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,332 +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 com.metamatrix.connector.jdbc.db2;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.jdbc.translator.BasicFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.DropFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.FunctionModifier;
-import com.metamatrix.connector.language.*;
-import com.metamatrix.connector.language.ICompareCriteria.Operator;
-
-/**
- */
-public class DB2ConvertModifier extends BasicFunctionModifier implements FunctionModifier {
-
- private static DropFunctionModifier DROP_MODIFIER = new DropFunctionModifier();
-
- private ILanguageFactory langFactory;
-
- public DB2ConvertModifier(ILanguageFactory langFactory) {
- this.langFactory = langFactory;
- }
-
- public IExpression modify(IFunction function) {
- IExpression[] args = function.getParameters();
- Class sourceType = args[0].getType();
- String targetTypeString = getTargetType(args[1]);
- Class targetType = TypeFacility.getDataTypeClass(targetTypeString);
- IExpression returnExpr = null;
-
- if(targetType != null) {
-
- // targetType is always lower-case due to getTargetType implementation
- if(targetType.equals(TypeFacility.RUNTIME_TYPES.STRING)) {
- returnExpr = convertToString(args[0], sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.TIMESTAMP)) {
- returnExpr = convertToTimestamp(args[0], sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.DATE)) {
- returnExpr = convertToDate(args[0], sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.TIME)) {
- returnExpr = convertToTime(args[0], sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN) ||
- targetType.equals(TypeFacility.RUNTIME_TYPES.BYTE) ||
- targetType.equals(TypeFacility.RUNTIME_TYPES.SHORT)) {
- returnExpr = convertToSmallInt(args[0], sourceType, targetType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.INTEGER)) {
- returnExpr = convertToInteger(args[0], sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.LONG) ||
- targetType.equals(TypeFacility.RUNTIME_TYPES.BIG_INTEGER)) {
- returnExpr = convertToBigInt(args[0], sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.FLOAT)) {
- returnExpr = convertToReal(args[0], sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.DOUBLE)) {
- returnExpr = convertToDouble(args[0], sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL)) {
- returnExpr = convertToBigDecimal(args[0], sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.CHAR)) {
- returnExpr = convertToChar(args[0], sourceType);
- }
-
- if(returnExpr != null) {
- return returnExpr;
- }
- }
-
- // Last resort - just drop the convert and let the db figure it out
- return DROP_MODIFIER.modify(function);
- }
-
- /**
- * @param expression
- * @return
- * @since 4.2
- */
- private String getTargetType(IExpression expression) {
- if(expression != null && expression instanceof ILiteral) {
- String target = (String) ((ILiteral)expression).getValue();
- return target.toLowerCase();
- }
-
- return null;
- }
-
-
- /**
- * @param expression
- * @param sourceType
- * @return
- * @since 4.2
- */
- private IExpression convertToString(IExpression expression,
- Class sourceType) {
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN)) {
- // BEFORE: convert(booleanExpression, string)
- // AFTER: CASE WHEN booleanExpression = 0 THEN 'false' ELSE 'true' END
-
- ILiteral literalZero = this.langFactory.createLiteral(new Integer(0), TypeFacility.RUNTIME_TYPES.INTEGER);
- ICompareCriteria when = this.langFactory.createCompareCriteria(Operator.EQ, expression, literalZero);
- List whens = new ArrayList(1);
- whens.add(when);
-
- ILiteral literalFalse = this.langFactory.createLiteral("false", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
- List thens = new ArrayList(1);
- thens.add(literalFalse);
-
- ILiteral literalTrue = this.langFactory.createLiteral("true", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
-
- return this.langFactory.createSearchedCaseExpression(whens, thens, literalTrue, TypeFacility.RUNTIME_TYPES.STRING);
-
- } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.CHAR)) {
- // Drop convert entirely for char
- return null;
-
- } else {
- // BEFORE: convert(EXPR, string)
- // AFTER: char(EXPR)
- return wrapNewFunction(expression, "char", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
- }
- }
-
- private IExpression convertToChar(IExpression expression,
- Class sourceType) {
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)) {
- ILiteral literalOne = this.langFactory.createLiteral(new Integer(1), TypeFacility.RUNTIME_TYPES.INTEGER);
- return this.langFactory.createFunction("char", new IExpression[] { expression, literalOne }, TypeFacility.RUNTIME_TYPES.CHAR); //$NON-NLS-1$
- }
-
- return null;
- }
-
- private IExpression convertToSmallInt(IExpression expression,
- Class sourceType, Class targetType) {
-
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING) && targetType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN)) {
- // BEFORE: convert(stringExpression, boolean)
- // AFTER: CASE WHEN stringExpression = 'true' THEN 1 ELSE 0 END
- ILiteral literalTrue = this.langFactory.createLiteral("true", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
- ICompareCriteria when = this.langFactory.createCompareCriteria(Operator.EQ, expression, literalTrue);
- List whens = new ArrayList(1);
- whens.add(when);
-
- ILiteral literalOne = this.langFactory.createLiteral(new Integer(1), TypeFacility.RUNTIME_TYPES.INTEGER);
- List thens = new ArrayList(1);
- thens.add(literalOne);
-
- ILiteral literalZero = this.langFactory.createLiteral(new Integer(0), TypeFacility.RUNTIME_TYPES.INTEGER);
-
- return this.langFactory.createSearchedCaseExpression(whens, thens, literalZero, TypeFacility.RUNTIME_TYPES.STRING);
-
- } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.BYTE) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.SHORT)){
-
- // Just drop these
- return null;
- }
-
- // BEFORE: convert(expression, [boolean,byte,short])
- // AFTER: smallint(expression)
- return wrapNewFunction(expression, "smallint", targetType); //$NON-NLS-1$
- }
-
- private IExpression convertToInteger(IExpression expression, Class sourceType) {
-
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.BYTE) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.SHORT)){
-
- // Just drop these
- return null;
- }
-
- // BEFORE: convert(expression, integer)
- // AFTER: integer(expression)
- return wrapNewFunction(expression, "integer", TypeFacility.RUNTIME_TYPES.INTEGER); //$NON-NLS-1$
- }
-
- private IExpression convertToBigInt(IExpression expression, Class sourceType) {
-
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.FLOAT) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.DOUBLE) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL)){
-
- // BEFORE: convert(expression, [long, biginteger])
- // AFTER: bigint(expression)
- return wrapNewFunction(expression, "bigint", TypeFacility.RUNTIME_TYPES.LONG); //$NON-NLS-1$
-
- }
-
- // Just drop anything else
- return null;
- }
-
- private IExpression convertToReal(IExpression expression, Class sourceType) {
-
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.DOUBLE) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL)){
-
- // BEFORE: convert(expression, [double, bigdecimal])
- // AFTER: real(expression)
- return wrapNewFunction(expression, "real", TypeFacility.RUNTIME_TYPES.FLOAT); //$NON-NLS-1$
-
- }
-
- // Just drop anything else
- return null;
- }
-
- private IExpression convertToDouble(IExpression expression, Class sourceType) {
-
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)){
-
- // BEFORE: convert(expression, double)
- // AFTER: double(expression)
- return wrapNewFunction(expression, "double", TypeFacility.RUNTIME_TYPES.DOUBLE); //$NON-NLS-1$
-
- }
-
- // Just drop anything else
- return null;
- }
-
- private IExpression convertToBigDecimal(IExpression expression, Class sourceType) {
-
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)){
-
- // BEFORE: convert(expression, bigdecimal)
- // AFTER: decimal(expression)
- return wrapNewFunction(expression, "decimal", TypeFacility.RUNTIME_TYPES.BIG_DECIMAL); //$NON-NLS-1$
-
- }
-
- // Just drop anything else
- return null;
- }
-
- /**
- * @param expression
- * @param sourceType
- * @return
- * @since 4.2
- */
- private IExpression convertToDate(IExpression expression,
- Class sourceType) {
-
- // BEFORE: convert(EXPR, date)
- // AFTER: date(EXPR)
- return wrapNewFunction(expression, "date", TypeFacility.RUNTIME_TYPES.DATE); //$NON-NLS-1$
- }
-
- private IExpression convertToTime(IExpression expression, Class sourceType) {
-
- // BEFORE: convert(EXPR, time)
- // AFTER: time(EXPR)
- return wrapNewFunction(expression, "time", TypeFacility.RUNTIME_TYPES.DATE); //$NON-NLS-1$
- }
-
- private IExpression convertToTimestamp(IExpression expression,
- Class sourceType) {
-
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)) {
- // BEFORE: convert(EXPR, timestamp)
- // AFTER: timestamp(expr)
- return wrapNewFunction(expression, "timestamp", TypeFacility.RUNTIME_TYPES.TIMESTAMP); //$NON-NLS-1$
-
- } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.DATE)) {
- // BEFORE: convert(EXPR, timestamp)
- // AFTER: timestamp(EXPR, '00:00:00')
- ILiteral timeString = this.langFactory.createLiteral("00:00:00", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
- return this.langFactory.createFunction("timestamp", new IExpression[] {expression, timeString}, TypeFacility.RUNTIME_TYPES.TIMESTAMP); //$NON-NLS-1$
-
- } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.TIME)) {
- // BEFORE: convert(EXPR, timestamp)
- // AFTER: timestamp('1970-01-01', EXPR)
- ILiteral dateString = this.langFactory.createLiteral("1970-01-01", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
- return this.langFactory.createFunction("timestamp", new IExpression[] {dateString, expression}, TypeFacility.RUNTIME_TYPES.TIMESTAMP); //$NON-NLS-1$
- }
-
- return null;
- }
-
- /**
- * @param expression
- * @param functionName
- * @param outputType
- * @return
- * @since 4.2
- */
- private IFunction wrapNewFunction(IExpression expression,
- String functionName,
- Class outputType) {
- return langFactory.createFunction(functionName,
- new IExpression[] { expression },
- outputType);
- }
-
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2ConvertModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2ConvertModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2ConvertModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2ConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,334 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.db2;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
+import org.teiid.connector.jdbc.translator.DropFunctionModifier;
+import org.teiid.connector.jdbc.translator.FunctionModifier;
+
+import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.language.*;
+import com.metamatrix.connector.language.ICompareCriteria.Operator;
+
+/**
+ */
+public class DB2ConvertModifier extends BasicFunctionModifier implements FunctionModifier {
+
+ private static DropFunctionModifier DROP_MODIFIER = new DropFunctionModifier();
+
+ private ILanguageFactory langFactory;
+
+ public DB2ConvertModifier(ILanguageFactory langFactory) {
+ this.langFactory = langFactory;
+ }
+
+ public IExpression modify(IFunction function) {
+ List<IExpression> args = function.getParameters();
+ Class sourceType = args.get(0).getType();
+ String targetTypeString = getTargetType(args.get(1));
+ Class targetType = TypeFacility.getDataTypeClass(targetTypeString);
+ IExpression returnExpr = null;
+
+ if(targetType != null) {
+
+ // targetType is always lower-case due to getTargetType implementation
+ if(targetType.equals(TypeFacility.RUNTIME_TYPES.STRING)) {
+ returnExpr = convertToString(args.get(0), sourceType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.TIMESTAMP)) {
+ returnExpr = convertToTimestamp(args.get(0), sourceType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.DATE)) {
+ returnExpr = convertToDate(args.get(0), sourceType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.TIME)) {
+ returnExpr = convertToTime(args.get(0), sourceType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN) ||
+ targetType.equals(TypeFacility.RUNTIME_TYPES.BYTE) ||
+ targetType.equals(TypeFacility.RUNTIME_TYPES.SHORT)) {
+ returnExpr = convertToSmallInt(args.get(0), sourceType, targetType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.INTEGER)) {
+ returnExpr = convertToInteger(args.get(0), sourceType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.LONG) ||
+ targetType.equals(TypeFacility.RUNTIME_TYPES.BIG_INTEGER)) {
+ returnExpr = convertToBigInt(args.get(0), sourceType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.FLOAT)) {
+ returnExpr = convertToReal(args.get(0), sourceType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.DOUBLE)) {
+ returnExpr = convertToDouble(args.get(0), sourceType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL)) {
+ returnExpr = convertToBigDecimal(args.get(0), sourceType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.CHAR)) {
+ returnExpr = convertToChar(args.get(0), sourceType);
+ }
+
+ if(returnExpr != null) {
+ return returnExpr;
+ }
+ }
+
+ // Last resort - just drop the convert and let the db figure it out
+ return DROP_MODIFIER.modify(function);
+ }
+
+ /**
+ * @param expression
+ * @return
+ * @since 4.2
+ */
+ private String getTargetType(IExpression expression) {
+ if(expression != null && expression instanceof ILiteral) {
+ String target = (String) ((ILiteral)expression).getValue();
+ return target.toLowerCase();
+ }
+
+ return null;
+ }
+
+
+ /**
+ * @param expression
+ * @param sourceType
+ * @return
+ * @since 4.2
+ */
+ private IExpression convertToString(IExpression expression,
+ Class sourceType) {
+ if(sourceType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN)) {
+ // BEFORE: convert(booleanExpression, string)
+ // AFTER: CASE WHEN booleanExpression = 0 THEN 'false' ELSE 'true' END
+
+ ILiteral literalZero = this.langFactory.createLiteral(new Integer(0), TypeFacility.RUNTIME_TYPES.INTEGER);
+ ICompareCriteria when = this.langFactory.createCompareCriteria(Operator.EQ, expression, literalZero);
+ List whens = new ArrayList(1);
+ whens.add(when);
+
+ ILiteral literalFalse = this.langFactory.createLiteral("false", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
+ List thens = new ArrayList(1);
+ thens.add(literalFalse);
+
+ ILiteral literalTrue = this.langFactory.createLiteral("true", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
+
+ return this.langFactory.createSearchedCaseExpression(whens, thens, literalTrue, TypeFacility.RUNTIME_TYPES.STRING);
+
+ } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.CHAR)) {
+ // Drop convert entirely for char
+ return null;
+
+ } else {
+ // BEFORE: convert(EXPR, string)
+ // AFTER: char(EXPR)
+ return wrapNewFunction(expression, "char", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
+ }
+ }
+
+ private IExpression convertToChar(IExpression expression,
+ Class sourceType) {
+ if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)) {
+ ILiteral literalOne = this.langFactory.createLiteral(new Integer(1), TypeFacility.RUNTIME_TYPES.INTEGER);
+ return this.langFactory.createFunction("char", Arrays.asList(expression, literalOne), TypeFacility.RUNTIME_TYPES.CHAR); //$NON-NLS-1$
+ }
+
+ return null;
+ }
+
+ private IExpression convertToSmallInt(IExpression expression,
+ Class sourceType, Class targetType) {
+
+ if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING) && targetType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN)) {
+ // BEFORE: convert(stringExpression, boolean)
+ // AFTER: CASE WHEN stringExpression = 'true' THEN 1 ELSE 0 END
+ ILiteral literalTrue = this.langFactory.createLiteral("true", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
+ ICompareCriteria when = this.langFactory.createCompareCriteria(Operator.EQ, expression, literalTrue);
+ List whens = new ArrayList(1);
+ whens.add(when);
+
+ ILiteral literalOne = this.langFactory.createLiteral(new Integer(1), TypeFacility.RUNTIME_TYPES.INTEGER);
+ List thens = new ArrayList(1);
+ thens.add(literalOne);
+
+ ILiteral literalZero = this.langFactory.createLiteral(new Integer(0), TypeFacility.RUNTIME_TYPES.INTEGER);
+
+ return this.langFactory.createSearchedCaseExpression(whens, thens, literalZero, TypeFacility.RUNTIME_TYPES.STRING);
+
+ } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN) ||
+ sourceType.equals(TypeFacility.RUNTIME_TYPES.BYTE) ||
+ sourceType.equals(TypeFacility.RUNTIME_TYPES.SHORT)){
+
+ // Just drop these
+ return null;
+ }
+
+ // BEFORE: convert(expression, [boolean,byte,short])
+ // AFTER: smallint(expression)
+ return wrapNewFunction(expression, "smallint", targetType); //$NON-NLS-1$
+ }
+
+ private IExpression convertToInteger(IExpression expression, Class sourceType) {
+
+ if(sourceType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN) ||
+ sourceType.equals(TypeFacility.RUNTIME_TYPES.BYTE) ||
+ sourceType.equals(TypeFacility.RUNTIME_TYPES.SHORT)){
+
+ // Just drop these
+ return null;
+ }
+
+ // BEFORE: convert(expression, integer)
+ // AFTER: integer(expression)
+ return wrapNewFunction(expression, "integer", TypeFacility.RUNTIME_TYPES.INTEGER); //$NON-NLS-1$
+ }
+
+ private IExpression convertToBigInt(IExpression expression, Class sourceType) {
+
+ if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING) ||
+ sourceType.equals(TypeFacility.RUNTIME_TYPES.FLOAT) ||
+ sourceType.equals(TypeFacility.RUNTIME_TYPES.DOUBLE) ||
+ sourceType.equals(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL)){
+
+ // BEFORE: convert(expression, [long, biginteger])
+ // AFTER: bigint(expression)
+ return wrapNewFunction(expression, "bigint", TypeFacility.RUNTIME_TYPES.LONG); //$NON-NLS-1$
+
+ }
+
+ // Just drop anything else
+ return null;
+ }
+
+ private IExpression convertToReal(IExpression expression, Class sourceType) {
+
+ if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING) ||
+ sourceType.equals(TypeFacility.RUNTIME_TYPES.DOUBLE) ||
+ sourceType.equals(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL)){
+
+ // BEFORE: convert(expression, [double, bigdecimal])
+ // AFTER: real(expression)
+ return wrapNewFunction(expression, "real", TypeFacility.RUNTIME_TYPES.FLOAT); //$NON-NLS-1$
+
+ }
+
+ // Just drop anything else
+ return null;
+ }
+
+ private IExpression convertToDouble(IExpression expression, Class sourceType) {
+
+ if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)){
+
+ // BEFORE: convert(expression, double)
+ // AFTER: double(expression)
+ return wrapNewFunction(expression, "double", TypeFacility.RUNTIME_TYPES.DOUBLE); //$NON-NLS-1$
+
+ }
+
+ // Just drop anything else
+ return null;
+ }
+
+ private IExpression convertToBigDecimal(IExpression expression, Class sourceType) {
+
+ if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)){
+
+ // BEFORE: convert(expression, bigdecimal)
+ // AFTER: decimal(expression)
+ return wrapNewFunction(expression, "decimal", TypeFacility.RUNTIME_TYPES.BIG_DECIMAL); //$NON-NLS-1$
+
+ }
+
+ // Just drop anything else
+ return null;
+ }
+
+ /**
+ * @param expression
+ * @param sourceType
+ * @return
+ * @since 4.2
+ */
+ private IExpression convertToDate(IExpression expression,
+ Class sourceType) {
+
+ // BEFORE: convert(EXPR, date)
+ // AFTER: date(EXPR)
+ return wrapNewFunction(expression, "date", TypeFacility.RUNTIME_TYPES.DATE); //$NON-NLS-1$
+ }
+
+ private IExpression convertToTime(IExpression expression, Class sourceType) {
+
+ // BEFORE: convert(EXPR, time)
+ // AFTER: time(EXPR)
+ return wrapNewFunction(expression, "time", TypeFacility.RUNTIME_TYPES.DATE); //$NON-NLS-1$
+ }
+
+ private IExpression convertToTimestamp(IExpression expression,
+ Class sourceType) {
+
+ if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)) {
+ // BEFORE: convert(EXPR, timestamp)
+ // AFTER: timestamp(expr)
+ return wrapNewFunction(expression, "timestamp", TypeFacility.RUNTIME_TYPES.TIMESTAMP); //$NON-NLS-1$
+
+ } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.DATE)) {
+ // BEFORE: convert(EXPR, timestamp)
+ // AFTER: timestamp(EXPR, '00:00:00')
+ ILiteral timeString = this.langFactory.createLiteral("00:00:00", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
+ return this.langFactory.createFunction("timestamp", Arrays.asList(expression, timeString), TypeFacility.RUNTIME_TYPES.TIMESTAMP); //$NON-NLS-1$
+
+ } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.TIME)) {
+ // BEFORE: convert(EXPR, timestamp)
+ // AFTER: timestamp('1970-01-01', EXPR)
+ ILiteral dateString = this.langFactory.createLiteral("1970-01-01", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
+ return this.langFactory.createFunction("timestamp", Arrays.asList(dateString, expression), TypeFacility.RUNTIME_TYPES.TIMESTAMP); //$NON-NLS-1$
+ }
+
+ return null;
+ }
+
+ /**
+ * @param expression
+ * @param functionName
+ * @param outputType
+ * @return
+ * @since 4.2
+ */
+ private IFunction wrapNewFunction(IExpression expression,
+ String functionName,
+ Class outputType) {
+ return langFactory.createFunction(functionName,
+ Arrays.asList(expression),
+ outputType);
+ }
+
+}
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2SQLTranslator.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,87 +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 com.metamatrix.connector.jdbc.db2;
-
-import java.util.Arrays;
-
-import com.metamatrix.connector.api.ConnectorEnvironment;
-import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.api.ExecutionContext;
-import com.metamatrix.connector.api.SourceSystemFunctions;
-import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.jdbc.translator.AliasModifier;
-import com.metamatrix.connector.jdbc.translator.Translator;
-import com.metamatrix.connector.language.ICommand;
-import com.metamatrix.connector.language.IJoin;
-import com.metamatrix.connector.language.ILimit;
-import com.metamatrix.connector.language.ILiteral;
-import com.metamatrix.connector.language.ICompareCriteria.Operator;
-import com.metamatrix.connector.language.IJoin.JoinType;
-import com.metamatrix.connector.visitor.framework.HierarchyVisitor;
-
-/**
- */
-public class DB2SQLTranslator extends Translator {
-
- @Override
- public void initialize(ConnectorEnvironment env) throws ConnectorException {
- super.initialize(env);
- registerFunctionModifier(SourceSystemFunctions.CONVERT, new DB2ConvertModifier(getLanguageFactory())); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.CHAR, new AliasModifier("chr")); //$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new AliasModifier("day")); //$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("coalesce")); //$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new AliasModifier("substr")); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- @Override
- public String addLimitString(String queryCommand, ILimit limit) {
- return queryCommand + " FETCH FIRST " + limit.getRowLimit() + " ROWS ONLY"; //$NON-NLS-1$
- }
-
- @Override
- public ICommand modifyCommand(ICommand command, ExecutionContext context)
- throws ConnectorException {
- HierarchyVisitor hierarchyVisitor = new HierarchyVisitor() {
- @Override
- public void visit(IJoin obj) {
- if (obj.getJoinType() != JoinType.CROSS_JOIN) {
- return;
- }
- ILiteral one = getLanguageFactory().createLiteral(1, TypeFacility.RUNTIME_TYPES.INTEGER);
- obj.setCriteria(Arrays.asList(getLanguageFactory().createCompareCriteria(Operator.EQ, one, one)));
- obj.setJoinType(JoinType.INNER_JOIN);
- }
- };
-
- command.acceptVisitor(hierarchyVisitor);
- return command;
- }
-
- @Override
- public String getDefaultConnectionTestQuery() {
- return "Select 'x' from sysibm.systables where 1 = 2"; //$NON-NLS-1$
- }
-
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2SQLTranslator.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+/*
+ */
+package org.teiid.connector.jdbc.db2;
+
+import org.teiid.connector.jdbc.translator.AliasModifier;
+import org.teiid.connector.jdbc.translator.Translator;
+
+import com.metamatrix.connector.api.ConnectorEnvironment;
+import com.metamatrix.connector.api.ConnectorException;
+import com.metamatrix.connector.api.ExecutionContext;
+import com.metamatrix.connector.api.SourceSystemFunctions;
+import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.language.ICommand;
+import com.metamatrix.connector.language.IJoin;
+import com.metamatrix.connector.language.ILimit;
+import com.metamatrix.connector.language.ILiteral;
+import com.metamatrix.connector.language.ICompareCriteria.Operator;
+import com.metamatrix.connector.language.IJoin.JoinType;
+import com.metamatrix.connector.visitor.framework.HierarchyVisitor;
+
+/**
+ */
+public class DB2SQLTranslator extends Translator {
+
+ @Override
+ public void initialize(ConnectorEnvironment env) throws ConnectorException {
+ super.initialize(env);
+ registerFunctionModifier(SourceSystemFunctions.CONVERT, new DB2ConvertModifier(getLanguageFactory())); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.CHAR, new AliasModifier("chr")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new AliasModifier("day")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("coalesce")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new AliasModifier("substr")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ @Override
+ public String addLimitString(String queryCommand, ILimit limit) {
+ return queryCommand + " FETCH FIRST " + limit.getRowLimit() + " ROWS ONLY"; //$NON-NLS-1$
+ }
+
+ @Override
+ public ICommand modifyCommand(ICommand command, ExecutionContext context)
+ throws ConnectorException {
+ HierarchyVisitor hierarchyVisitor = new HierarchyVisitor() {
+ @Override
+ public void visit(IJoin obj) {
+ if (obj.getJoinType() != JoinType.CROSS_JOIN) {
+ return;
+ }
+ ILiteral one = getLanguageFactory().createLiteral(1, TypeFacility.RUNTIME_TYPES.INTEGER);
+ obj.getCriteria().add(getLanguageFactory().createCompareCriteria(Operator.EQ, one, one));
+ obj.setJoinType(JoinType.INNER_JOIN);
+ }
+ };
+
+ command.acceptVisitor(hierarchyVisitor);
+ return command;
+ }
+
+ @Override
+ public String getDefaultConnectionTestQuery() {
+ return "Select 'x' from sysibm.systables where 1 = 2"; //$NON-NLS-1$
+ }
+
+}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby)
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyCapabilities.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyCapabilities.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,12 +20,13 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.derby;
+package org.teiid.connector.jdbc.derby;
import java.util.ArrayList;
import java.util.List;
+
+import org.teiid.connector.jdbc.JDBCCapabilities;
-import com.metamatrix.connector.jdbc.JDBCCapabilities;
/**
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyConvertModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,370 +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 com.metamatrix.connector.jdbc.derby;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.jdbc.translator.BasicFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.DropFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.FunctionModifier;
-import com.metamatrix.connector.language.*;
-import com.metamatrix.connector.language.ICompareCriteria.Operator;
-
-/**
- */
-public class DerbyConvertModifier extends BasicFunctionModifier implements FunctionModifier {
-
- private static DropFunctionModifier DROP_MODIFIER = new DropFunctionModifier();
-
- private ILanguageFactory langFactory;
-
- public DerbyConvertModifier(ILanguageFactory langFactory) {
- this.langFactory = langFactory;
- }
-
- /**
- * @see com.metamatrix.connector.jdbc.translator.BasicFunctionModifier#translate(com.metamatrix.connector.language.IFunction)
- * @since 5.0
- */
- public List translate(IFunction function) {
- // For anything that doesn't get modified to some other function, translate the convert(expr, type)
- // to cast(expr as type).
-
- List parts = new ArrayList();
- parts.add("cast("); //$NON-NLS-1$
- parts.add(function.getParameters()[0]);
- parts.add(" as "); //$NON-NLS-1$
- ILiteral type = (ILiteral) function.getParameters()[1];
- parts.add(type.getValue());
- parts.add(")"); //$NON-NLS-1$
-
- return parts;
- }
-
- public IExpression modify(IFunction function) {
- IExpression[] args = function.getParameters();
- Class sourceType = args[0].getType();
- String targetTypeString = getTargetType(args[1]);
- Class targetType = TypeFacility.getDataTypeClass(targetTypeString);
- IExpression returnExpr = null;
-
- if(targetType != null) {
-
- // targetType is always lower-case due to getTargetType implementation
- if(targetType.equals(TypeFacility.RUNTIME_TYPES.STRING)) {
- returnExpr = convertToString(args[0], sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.TIMESTAMP)) {
- returnExpr = convertToTimestamp(args[0], sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.DATE)) {
- returnExpr = convertToDate(args[0], sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.TIME)) {
- returnExpr = convertToTime(args[0], sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN) ||
- targetType.equals(TypeFacility.RUNTIME_TYPES.BYTE) ||
- targetType.equals(TypeFacility.RUNTIME_TYPES.SHORT)) {
- returnExpr = convertToSmallInt(args[0], sourceType, targetType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.INTEGER)) {
- returnExpr = convertToInteger(args[0], sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.LONG) ||
- targetType.equals(TypeFacility.RUNTIME_TYPES.BIG_INTEGER)) {
- returnExpr = convertToBigInt(args[0], sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.FLOAT)) {
- returnExpr = convertToFloat(args[0], sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.DOUBLE)) {
- returnExpr = convertToDouble(args[0], sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL)) {
- returnExpr = convertToBigDecimal(args[0], sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.CHAR)) {
- returnExpr = convertToChar(args[0], sourceType);
- }
-
- if(returnExpr != null) {
- return returnExpr;
- }
- }
-
- // Last resort - just drop the convert and let the db figure it out
- return DROP_MODIFIER.modify(function);
- }
-
- /**
- * @param expression
- * @return
- * @since 4.2
- */
- private String getTargetType(IExpression expression) {
- if(expression != null && expression instanceof ILiteral) {
- String target = (String) ((ILiteral)expression).getValue();
- return target.toLowerCase();
- }
-
- return null;
- }
-
-
- /**
- * @param expression
- * @param sourceType
- * @return
- * @since 4.2
- */
- private IExpression convertToString(IExpression expression,
- Class sourceType) {
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN)) {
- // BEFORE: convert(booleanExpression, string)
- // AFTER: CASE WHEN booleanExpression = 0 THEN 'false' ELSE 'true' END
-
- ILiteral literalZero = this.langFactory.createLiteral(new Integer(0), TypeFacility.RUNTIME_TYPES.INTEGER);
- ICompareCriteria when = this.langFactory.createCompareCriteria(Operator.EQ, expression, literalZero);
- List whens = new ArrayList(1);
- whens.add(when);
-
- ILiteral literalFalse = this.langFactory.createLiteral("false", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
- List thens = new ArrayList(1);
- thens.add(literalFalse);
-
- ILiteral literalTrue = this.langFactory.createLiteral("true", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
-
- return this.langFactory.createSearchedCaseExpression(whens, thens, literalTrue, TypeFacility.RUNTIME_TYPES.STRING);
-
- } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.CHAR)) {
- // Drop convert entirely for char
- return null;
-
- } else {
- // BEFORE: convert(EXPR, string)
- // AFTER: char(EXPR)
- return wrapNewFunction(expression, "char", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
- }
- }
-
- private IExpression convertToChar(IExpression expression,
- Class sourceType) {
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)) {
- ILiteral literalOne = this.langFactory.createLiteral(new Integer(1), TypeFacility.RUNTIME_TYPES.INTEGER);
- return this.langFactory.createFunction("char", new IExpression[] { expression, literalOne }, TypeFacility.RUNTIME_TYPES.CHAR); //$NON-NLS-1$
- }
-
- return null;
- }
-
- private IExpression convertToSmallInt(IExpression expression,
- Class sourceType, Class targetType) {
-
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING) && targetType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN)) {
- // BEFORE: convert(stringExpression, boolean)
- // AFTER: CASE WHEN stringExpression = 'true' THEN 1 ELSE 0 END
- ILiteral literalTrue = this.langFactory.createLiteral("true", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
- ICompareCriteria when = this.langFactory.createCompareCriteria(Operator.EQ, expression, literalTrue);
- List whens = new ArrayList(1);
- whens.add(when);
-
- ILiteral literalOne = this.langFactory.createLiteral(new Integer(1), TypeFacility.RUNTIME_TYPES.INTEGER);
- List thens = new ArrayList(1);
- thens.add(literalOne);
-
- ILiteral literalZero = this.langFactory.createLiteral(new Integer(0), TypeFacility.RUNTIME_TYPES.INTEGER);
-
- return this.langFactory.createSearchedCaseExpression(whens, thens, literalZero, TypeFacility.RUNTIME_TYPES.STRING);
-
- } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.BYTE) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.SHORT)){
-
- // Just drop these
- return null;
- }
-
- // BEFORE: convert(expression, [boolean,byte,short])
- // AFTER: smallint(expression)
- return wrapNewFunction(expression, "smallint", targetType); //$NON-NLS-1$
- }
-
- private IExpression convertToInteger(IExpression expression, Class sourceType) {
-
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.BYTE) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.SHORT)){
-
- // Just drop these
- return null;
- }
-
- // BEFORE: convert(expression, integer)
- // AFTER: integer(expression)
- return wrapNewFunction(expression, "integer", TypeFacility.RUNTIME_TYPES.INTEGER); //$NON-NLS-1$
- }
-
- private IExpression convertToBigInt(IExpression expression, Class sourceType) {
-
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.FLOAT) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.DOUBLE) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL)){
-
- // BEFORE: convert(expression, [long, biginteger])
- // AFTER: bigint(expression)
- return wrapNewFunction(expression, "bigint", TypeFacility.RUNTIME_TYPES.LONG); //$NON-NLS-1$
-
- }
-
- // Just drop anything else
- return null;
- }
-
- private IExpression convertToFloat(IExpression expression, Class sourceType) {
-
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)){
-
- // BEFORE: convert(string_expr, float)
- // AFTER: cast(cast(string_expr as decimal) as float)
- IFunction inner = langFactory.createFunction("convert", //$NON-NLS-1$
- new IExpression[] { expression, langFactory.createLiteral("decimal", TypeFacility.RUNTIME_TYPES.STRING) }, //$NON-NLS-1$
- TypeFacility.RUNTIME_TYPES.BIG_DECIMAL);
-
- IFunction outer = langFactory.createFunction("convert", //$NON-NLS-1$
- new IExpression[] { inner, langFactory.createLiteral("float", TypeFacility.RUNTIME_TYPES.STRING) }, //$NON-NLS-1$
- TypeFacility.RUNTIME_TYPES.FLOAT);
-
- return outer;
-
- } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.DOUBLE) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL)) {
-
- // BEFORE: convert(num_expr, float)
- // AFTER: cast(num_expr as float)
- return langFactory.createFunction("convert", //$NON-NLS-1$
- new IExpression[] { expression, langFactory.createLiteral("float", TypeFacility.RUNTIME_TYPES.STRING) }, //$NON-NLS-1$
- TypeFacility.RUNTIME_TYPES.FLOAT);
- }
-
- // Just drop anything else
- return null;
- }
-
- private IExpression convertToDouble(IExpression expression, Class sourceType) {
-
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)){
- // BEFORE: convert(string_expr, double)
- // AFTER: cast(cast(string_expr as decimal) as double)
- IFunction inner = langFactory.createFunction("convert", //$NON-NLS-1$
- new IExpression[] { expression, langFactory.createLiteral("decimal", TypeFacility.RUNTIME_TYPES.STRING) }, //$NON-NLS-1$
- TypeFacility.RUNTIME_TYPES.BIG_DECIMAL);
-
- return langFactory.createFunction("convert", //$NON-NLS-1$
- new IExpression[] { inner, langFactory.createLiteral("double", TypeFacility.RUNTIME_TYPES.STRING) }, //$NON-NLS-1$
- TypeFacility.RUNTIME_TYPES.DOUBLE);
- }
-
- // Just drop anything else
- return null;
- }
-
- private IExpression convertToBigDecimal(IExpression expression, Class sourceType) {
-
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)){
- // BEFORE: convert(string_expr, bigdecimal)
- // AFTER: cast(string_expr as decimal)
- return langFactory.createFunction("convert", //$NON-NLS-1$
- new IExpression[] { expression, langFactory.createLiteral("decimal", TypeFacility.RUNTIME_TYPES.STRING) }, //$NON-NLS-1$
- TypeFacility.RUNTIME_TYPES.BIG_DECIMAL);
- }
-
- // Just drop anything else
- return null;
- }
-
- /**
- * @param expression
- * @param sourceType
- * @return
- * @since 4.2
- */
- private IExpression convertToDate(IExpression expression,
- Class sourceType) {
-
- // BEFORE: convert(EXPR, date)
- // AFTER: date(EXPR)
- return wrapNewFunction(expression, "date", TypeFacility.RUNTIME_TYPES.DATE); //$NON-NLS-1$
- }
-
- private IExpression convertToTime(IExpression expression,
- Class sourceType) {
-
- // BEFORE: convert(EXPR, time)
- // AFTER: time(EXPR)
- return wrapNewFunction(expression, "time", TypeFacility.RUNTIME_TYPES.DATE); //$NON-NLS-1$
- }
-
- private IExpression convertToTimestamp(IExpression expression,
- Class sourceType) {
-
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)) {
- // BEFORE: convert(EXPR, timestamp)
- // AFTER: timestamp(expr)
- return wrapNewFunction(expression, "timestamp", TypeFacility.RUNTIME_TYPES.TIMESTAMP); //$NON-NLS-1$
-
- } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.DATE)) {
- // BEFORE: convert(EXPR, timestamp)
- // AFTER: timestamp(EXPR, '00:00:00')
- ILiteral timeString = this.langFactory.createLiteral("00:00:00", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
- return this.langFactory.createFunction("timestamp", new IExpression[] {expression, timeString}, TypeFacility.RUNTIME_TYPES.TIMESTAMP); //$NON-NLS-1$
-
- } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.TIME)) {
- // BEFORE: convert(EXPR, timestamp)
- // AFTER: timestamp(EXPR, '1970-01-01', EXPR)
- ILiteral dateString = this.langFactory.createLiteral("1970-01-01", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
- return this.langFactory.createFunction("timestamp", new IExpression[] {dateString, expression}, TypeFacility.RUNTIME_TYPES.TIMESTAMP); //$NON-NLS-1$
- }
-
- return null;
- }
-
- /**
- * @param expression
- * @param functionName
- * @param outputType
- * @return
- * @since 4.2
- */
- private IFunction wrapNewFunction(IExpression expression,
- String functionName,
- Class outputType) {
- return langFactory.createFunction(functionName,
- new IExpression[] { expression },
- outputType);
- }
-
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyConvertModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyConvertModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyConvertModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,372 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.derby;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
+import org.teiid.connector.jdbc.translator.DropFunctionModifier;
+import org.teiid.connector.jdbc.translator.FunctionModifier;
+
+import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.language.*;
+import com.metamatrix.connector.language.ICompareCriteria.Operator;
+
+/**
+ */
+public class DerbyConvertModifier extends BasicFunctionModifier implements FunctionModifier {
+
+ private static DropFunctionModifier DROP_MODIFIER = new DropFunctionModifier();
+
+ private ILanguageFactory langFactory;
+
+ public DerbyConvertModifier(ILanguageFactory langFactory) {
+ this.langFactory = langFactory;
+ }
+
+ /**
+ * @see org.teiid.connector.jdbc.translator.BasicFunctionModifier#translate(com.metamatrix.connector.language.IFunction)
+ * @since 5.0
+ */
+ public List translate(IFunction function) {
+ // For anything that doesn't get modified to some other function, translate the convert(expr, type)
+ // to cast(expr as type).
+
+ List parts = new ArrayList();
+ parts.add("cast("); //$NON-NLS-1$
+ parts.add(function.getParameters().get(0));
+ parts.add(" as "); //$NON-NLS-1$
+ ILiteral type = (ILiteral) function.getParameters().get(1);
+ parts.add(type.getValue());
+ parts.add(")"); //$NON-NLS-1$
+
+ return parts;
+ }
+
+ public IExpression modify(IFunction function) {
+ List<IExpression> args = function.getParameters();
+ Class sourceType = args.get(0).getType();
+ String targetTypeString = getTargetType(args.get(1));
+ Class targetType = TypeFacility.getDataTypeClass(targetTypeString);
+ IExpression returnExpr = null;
+
+ if(targetType != null) {
+
+ // targetType is always lower-case due to getTargetType implementation
+ if(targetType.equals(TypeFacility.RUNTIME_TYPES.STRING)) {
+ returnExpr = convertToString(args.get(0), sourceType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.TIMESTAMP)) {
+ returnExpr = convertToTimestamp(args.get(0), sourceType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.DATE)) {
+ returnExpr = convertToDate(args.get(0), sourceType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.TIME)) {
+ returnExpr = convertToTime(args.get(0), sourceType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN) ||
+ targetType.equals(TypeFacility.RUNTIME_TYPES.BYTE) ||
+ targetType.equals(TypeFacility.RUNTIME_TYPES.SHORT)) {
+ returnExpr = convertToSmallInt(args.get(0), sourceType, targetType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.INTEGER)) {
+ returnExpr = convertToInteger(args.get(0), sourceType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.LONG) ||
+ targetType.equals(TypeFacility.RUNTIME_TYPES.BIG_INTEGER)) {
+ returnExpr = convertToBigInt(args.get(0), sourceType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.FLOAT)) {
+ returnExpr = convertToFloat(args.get(0), sourceType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.DOUBLE)) {
+ returnExpr = convertToDouble(args.get(0), sourceType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL)) {
+ returnExpr = convertToBigDecimal(args.get(0), sourceType);
+
+ } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.CHAR)) {
+ returnExpr = convertToChar(args.get(0), sourceType);
+ }
+
+ if(returnExpr != null) {
+ return returnExpr;
+ }
+ }
+
+ // Last resort - just drop the convert and let the db figure it out
+ return DROP_MODIFIER.modify(function);
+ }
+
+ /**
+ * @param expression
+ * @return
+ * @since 4.2
+ */
+ private String getTargetType(IExpression expression) {
+ if(expression != null && expression instanceof ILiteral) {
+ String target = (String) ((ILiteral)expression).getValue();
+ return target.toLowerCase();
+ }
+
+ return null;
+ }
+
+
+ /**
+ * @param expression
+ * @param sourceType
+ * @return
+ * @since 4.2
+ */
+ private IExpression convertToString(IExpression expression,
+ Class sourceType) {
+ if(sourceType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN)) {
+ // BEFORE: convert(booleanExpression, string)
+ // AFTER: CASE WHEN booleanExpression = 0 THEN 'false' ELSE 'true' END
+
+ ILiteral literalZero = this.langFactory.createLiteral(new Integer(0), TypeFacility.RUNTIME_TYPES.INTEGER);
+ ICompareCriteria when = this.langFactory.createCompareCriteria(Operator.EQ, expression, literalZero);
+ List whens = new ArrayList(1);
+ whens.add(when);
+
+ ILiteral literalFalse = this.langFactory.createLiteral("false", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
+ List thens = new ArrayList(1);
+ thens.add(literalFalse);
+
+ ILiteral literalTrue = this.langFactory.createLiteral("true", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
+
+ return this.langFactory.createSearchedCaseExpression(whens, thens, literalTrue, TypeFacility.RUNTIME_TYPES.STRING);
+
+ } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.CHAR)) {
+ // Drop convert entirely for char
+ return null;
+
+ } else {
+ // BEFORE: convert(EXPR, string)
+ // AFTER: char(EXPR)
+ return wrapNewFunction(expression, "char", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
+ }
+ }
+
+ private IExpression convertToChar(IExpression expression,
+ Class sourceType) {
+ if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)) {
+ ILiteral literalOne = this.langFactory.createLiteral(new Integer(1), TypeFacility.RUNTIME_TYPES.INTEGER);
+ return this.langFactory.createFunction("char", Arrays.asList( expression, literalOne ), TypeFacility.RUNTIME_TYPES.CHAR); //$NON-NLS-1$
+ }
+
+ return null;
+ }
+
+ private IExpression convertToSmallInt(IExpression expression,
+ Class sourceType, Class targetType) {
+
+ if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING) && targetType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN)) {
+ // BEFORE: convert(stringExpression, boolean)
+ // AFTER: CASE WHEN stringExpression = 'true' THEN 1 ELSE 0 END
+ ILiteral literalTrue = this.langFactory.createLiteral("true", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
+ ICompareCriteria when = this.langFactory.createCompareCriteria(Operator.EQ, expression, literalTrue);
+ List whens = new ArrayList(1);
+ whens.add(when);
+
+ ILiteral literalOne = this.langFactory.createLiteral(new Integer(1), TypeFacility.RUNTIME_TYPES.INTEGER);
+ List thens = new ArrayList(1);
+ thens.add(literalOne);
+
+ ILiteral literalZero = this.langFactory.createLiteral(new Integer(0), TypeFacility.RUNTIME_TYPES.INTEGER);
+
+ return this.langFactory.createSearchedCaseExpression(whens, thens, literalZero, TypeFacility.RUNTIME_TYPES.STRING);
+
+ } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN) ||
+ sourceType.equals(TypeFacility.RUNTIME_TYPES.BYTE) ||
+ sourceType.equals(TypeFacility.RUNTIME_TYPES.SHORT)){
+
+ // Just drop these
+ return null;
+ }
+
+ // BEFORE: convert(expression, [boolean,byte,short])
+ // AFTER: smallint(expression)
+ return wrapNewFunction(expression, "smallint", targetType); //$NON-NLS-1$
+ }
+
+ private IExpression convertToInteger(IExpression expression, Class sourceType) {
+
+ if(sourceType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN) ||
+ sourceType.equals(TypeFacility.RUNTIME_TYPES.BYTE) ||
+ sourceType.equals(TypeFacility.RUNTIME_TYPES.SHORT)){
+
+ // Just drop these
+ return null;
+ }
+
+ // BEFORE: convert(expression, integer)
+ // AFTER: integer(expression)
+ return wrapNewFunction(expression, "integer", TypeFacility.RUNTIME_TYPES.INTEGER); //$NON-NLS-1$
+ }
+
+ private IExpression convertToBigInt(IExpression expression, Class sourceType) {
+
+ if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING) ||
+ sourceType.equals(TypeFacility.RUNTIME_TYPES.FLOAT) ||
+ sourceType.equals(TypeFacility.RUNTIME_TYPES.DOUBLE) ||
+ sourceType.equals(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL)){
+
+ // BEFORE: convert(expression, [long, biginteger])
+ // AFTER: bigint(expression)
+ return wrapNewFunction(expression, "bigint", TypeFacility.RUNTIME_TYPES.LONG); //$NON-NLS-1$
+
+ }
+
+ // Just drop anything else
+ return null;
+ }
+
+ private IExpression convertToFloat(IExpression expression, Class sourceType) {
+
+ if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)){
+
+ // BEFORE: convert(string_expr, float)
+ // AFTER: cast(cast(string_expr as decimal) as float)
+ IFunction inner = langFactory.createFunction("convert", //$NON-NLS-1$
+ Arrays.asList( expression, langFactory.createLiteral("decimal", TypeFacility.RUNTIME_TYPES.STRING) ), //$NON-NLS-1$
+ TypeFacility.RUNTIME_TYPES.BIG_DECIMAL);
+
+ IFunction outer = langFactory.createFunction("convert", //$NON-NLS-1$
+ Arrays.asList( inner, langFactory.createLiteral("float", TypeFacility.RUNTIME_TYPES.STRING) ), //$NON-NLS-1$
+ TypeFacility.RUNTIME_TYPES.FLOAT);
+
+ return outer;
+
+ } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.DOUBLE) ||
+ sourceType.equals(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL)) {
+
+ // BEFORE: convert(num_expr, float)
+ // AFTER: cast(num_expr as float)
+ return langFactory.createFunction("convert", //$NON-NLS-1$
+ Arrays.asList( expression, langFactory.createLiteral("float", TypeFacility.RUNTIME_TYPES.STRING) ), //$NON-NLS-1$
+ TypeFacility.RUNTIME_TYPES.FLOAT);
+ }
+
+ // Just drop anything else
+ return null;
+ }
+
+ private IExpression convertToDouble(IExpression expression, Class sourceType) {
+
+ if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)){
+ // BEFORE: convert(string_expr, double)
+ // AFTER: cast(cast(string_expr as decimal) as double)
+ IFunction inner = langFactory.createFunction("convert", //$NON-NLS-1$
+ Arrays.asList( expression, langFactory.createLiteral("decimal", TypeFacility.RUNTIME_TYPES.STRING) ), //$NON-NLS-1$
+ TypeFacility.RUNTIME_TYPES.BIG_DECIMAL);
+
+ return langFactory.createFunction("convert", //$NON-NLS-1$
+ Arrays.asList( inner, langFactory.createLiteral("double", TypeFacility.RUNTIME_TYPES.STRING) ), //$NON-NLS-1$
+ TypeFacility.RUNTIME_TYPES.DOUBLE);
+ }
+
+ // Just drop anything else
+ return null;
+ }
+
+ private IExpression convertToBigDecimal(IExpression expression, Class sourceType) {
+
+ if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)){
+ // BEFORE: convert(string_expr, bigdecimal)
+ // AFTER: cast(string_expr as decimal)
+ return langFactory.createFunction("convert", //$NON-NLS-1$
+ Arrays.asList( expression, langFactory.createLiteral("decimal", TypeFacility.RUNTIME_TYPES.STRING) ), //$NON-NLS-1$
+ TypeFacility.RUNTIME_TYPES.BIG_DECIMAL);
+ }
+
+ // Just drop anything else
+ return null;
+ }
+
+ /**
+ * @param expression
+ * @param sourceType
+ * @return
+ * @since 4.2
+ */
+ private IExpression convertToDate(IExpression expression,
+ Class sourceType) {
+
+ // BEFORE: convert(EXPR, date)
+ // AFTER: date(EXPR)
+ return wrapNewFunction(expression, "date", TypeFacility.RUNTIME_TYPES.DATE); //$NON-NLS-1$
+ }
+
+ private IExpression convertToTime(IExpression expression,
+ Class sourceType) {
+
+ // BEFORE: convert(EXPR, time)
+ // AFTER: time(EXPR)
+ return wrapNewFunction(expression, "time", TypeFacility.RUNTIME_TYPES.DATE); //$NON-NLS-1$
+ }
+
+ private IExpression convertToTimestamp(IExpression expression,
+ Class sourceType) {
+
+ if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)) {
+ // BEFORE: convert(EXPR, timestamp)
+ // AFTER: timestamp(expr)
+ return wrapNewFunction(expression, "timestamp", TypeFacility.RUNTIME_TYPES.TIMESTAMP); //$NON-NLS-1$
+
+ } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.DATE)) {
+ // BEFORE: convert(EXPR, timestamp)
+ // AFTER: timestamp(EXPR, '00:00:00')
+ ILiteral timeString = this.langFactory.createLiteral("00:00:00", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
+ return this.langFactory.createFunction("timestamp", Arrays.asList(expression, timeString), TypeFacility.RUNTIME_TYPES.TIMESTAMP); //$NON-NLS-1$
+
+ } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.TIME)) {
+ // BEFORE: convert(EXPR, timestamp)
+ // AFTER: timestamp(EXPR, '1970-01-01', EXPR)
+ ILiteral dateString = this.langFactory.createLiteral("1970-01-01", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
+ return this.langFactory.createFunction("timestamp", Arrays.asList(dateString, expression), TypeFacility.RUNTIME_TYPES.TIMESTAMP); //$NON-NLS-1$
+ }
+
+ return null;
+ }
+
+ /**
+ * @param expression
+ * @param functionName
+ * @param outputType
+ * @return
+ * @since 4.2
+ */
+ private IFunction wrapNewFunction(IExpression expression,
+ String functionName,
+ Class outputType) {
+ return langFactory.createFunction(functionName,
+ Arrays.asList( expression ),
+ outputType);
+ }
+
+}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbySQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbySQLTranslator.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbySQLTranslator.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,14 +20,15 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.derby;
+package org.teiid.connector.jdbc.derby;
+import org.teiid.connector.jdbc.translator.AliasModifier;
+import org.teiid.connector.jdbc.translator.EscapeSyntaxModifier;
+import org.teiid.connector.jdbc.translator.Translator;
+
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.SourceSystemFunctions;
-import com.metamatrix.connector.jdbc.translator.AliasModifier;
-import com.metamatrix.connector.jdbc.translator.EscapeSyntaxModifier;
-import com.metamatrix.connector.jdbc.translator.Translator;
/**
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/informix (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix)
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/informix
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/informix/InformixCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/InformixCapabilities.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/informix/InformixCapabilities.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -22,12 +22,13 @@
/*
*/
-package com.metamatrix.connector.jdbc.informix;
+package org.teiid.connector.jdbc.informix;
import java.util.*;
-import com.metamatrix.connector.jdbc.JDBCCapabilities;
+import org.teiid.connector.jdbc.JDBCCapabilities;
+
/**
*/
public class InformixCapabilities extends JDBCCapabilities {
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/informix/InformixSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/InformixSQLTranslator.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/informix/InformixSQLTranslator.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -22,13 +22,14 @@
/*
*/
-package com.metamatrix.connector.jdbc.informix;
+package org.teiid.connector.jdbc.informix;
+import org.teiid.connector.jdbc.translator.DropFunctionModifier;
+import org.teiid.connector.jdbc.translator.Translator;
+
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.SourceSystemFunctions;
-import com.metamatrix.connector.jdbc.translator.DropFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.Translator;
/**
*/
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mm (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mm)
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mm
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mm/MMCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mm/MMCapabilities.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mm/MMCapabilities.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -22,13 +22,14 @@
/*
*/
-package com.metamatrix.connector.jdbc.mm;
+package org.teiid.connector.jdbc.mm;
import java.util.ArrayList;
import java.util.List;
-import com.metamatrix.connector.jdbc.JDBCCapabilities;
+import org.teiid.connector.jdbc.JDBCCapabilities;
+
/**
* @since 4.3
*/
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql)
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLCapabilities.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLCapabilities.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,12 +20,13 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.mysql;
+package org.teiid.connector.jdbc.mysql;
import java.util.ArrayList;
import java.util.List;
+
+import org.teiid.connector.jdbc.JDBCCapabilities;
-import com.metamatrix.connector.jdbc.JDBCCapabilities;
/**
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLConvertModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,184 +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 com.metamatrix.connector.jdbc.mysql;
-
-import java.util.Arrays;
-import java.util.List;
-
-import com.metamatrix.connector.jdbc.translator.BasicFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.DropFunctionModifier;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.connector.language.ILiteral;
-import com.metamatrix.connector.language.ICompareCriteria.Operator;
-
-
-/**
- * @since 4.3
- */
-class MySQLConvertModifier extends BasicFunctionModifier {
-
- private static DropFunctionModifier DROP_MODIFIER = new DropFunctionModifier();
-
- private ILanguageFactory langFactory;
-
- MySQLConvertModifier(ILanguageFactory langFactory) {
- this.langFactory = langFactory;
- }
-
- public List translate(IFunction function) {
- return null;
- }
-
- public IExpression modify(IFunction function) {
- IExpression[] args = function.getParameters();
-
- if (args[0] != null && args[0] instanceof ILiteral && ((ILiteral)args[0]).getValue() == null ) {
- if (args[1] != null && args[1] instanceof ILiteral) {
- // This is a convert(null, ...) or cast(null as ...)
- return DROP_MODIFIER.modify(function);
- }
- }
-
- if (args[1] != null && args[1] instanceof ILiteral) {
- String target = ((String)((ILiteral)args[1]).getValue()).toLowerCase();
- if (target.equals("string")) { //$NON-NLS-1$
- return convertToString(function);
- } else if (target.equals("byte") || //$NON-NLS-1$
- target.equals("short") || //$NON-NLS-1$
- target.equals("integer")) { //$NON-NLS-1$
- return convertToNativeType(function, "SIGNED INTEGER"); //$NON-NLS-1$
- } else if (target.equals("long") || //$NON-NLS-1$
- target.equals("biginteger")) { //$NON-NLS-1$
- return convertToNativeType(function, "SIGNED"); //$NON-NLS-1$
- } else if (target.equals("float") || //$NON-NLS-1$
- target.equals("double") || //$NON-NLS-1$
- target.equals("bigdecimal")) { //$NON-NLS-1$
- return convertToNumeric(function);
- } else if (target.equals("date")) { //$NON-NLS-1$
- return convertToDateTime("DATE", args[0], java.sql.Date.class); //$NON-NLS-1$
- } else if (target.equals("time")) { //$NON-NLS-1$
- return convertToDateTime("TIME", args[0], java.sql.Time.class); //$NON-NLS-1$
- } else if (target.equals("timestamp")) { //$NON-NLS-1$
- return convertToDateTime("TIMESTAMP", args[0], java.sql.Timestamp.class); //$NON-NLS-1$
- } else if (target.equals("char")) { //$NON-NLS-1$
- return convertToNativeType(function, "CHAR (1)"); //$NON-NLS-1$
- } else if (target.equals("boolean")) { //$NON-NLS-1$
- return convertToBoolean(function);
- }
- }
- return DROP_MODIFIER.modify(function);
- }
-
- private IExpression convertToString(IFunction function) {
- int srcCode = getSrcCode(function);
- switch(srcCode) {
- case BOOLEAN:
- // convert(booleanSrc, string) --> CASE WHEN booleanSrc THEN '1' ELSE '0' END
- List when = Arrays.asList(langFactory.createCompareCriteria(Operator.EQ, function.getParameters()[0], langFactory.createLiteral(Boolean.TRUE, Boolean.class)));
- List then = Arrays.asList(new IExpression[] {langFactory.createLiteral("1", String.class)}); //$NON-NLS-1$
- IExpression elseExpr = langFactory.createLiteral("0", String.class); //$NON-NLS-1$
- return langFactory.createSearchedCaseExpression(when, then, elseExpr, String.class);
- case BYTE:
- case SHORT:
- case INTEGER:
- case LONG:
- case BIGINTEGER:
- case FLOAT:
- case DOUBLE:
- case BIGDECIMAL:
- // convert(src, string) --> convert(src, CHAR)
- return convertToNativeType(function, "CHAR"); //$NON-NLS-1$
- case DATE:
- // convert (dateSrc, string) --> date_format(dateSrc, '%Y-%m-%d')
- return convertDateTimeToString(function, "%Y-%m-%d"); //$NON-NLS-1$
- case TIME:
- // convert (timeSrc, string) --> date_format(timeSrc, '%H:%i:%S')
- return convertDateTimeToString(function, "%H:%i:%S"); //$NON-NLS-1$
- case TIMESTAMP:
- // convert (tsSrc, string) --> date_format(tsSrc, '%Y-%m-%d %H:%i:%S.%f')
- return convertDateTimeToString(function, "%Y-%m-%d %H:%i:%S.%f"); //$NON-NLS-1$
- default:
- return DROP_MODIFIER.modify(function);
- }
- }
-
- private IExpression convertToNativeType(IFunction function, String targetType) {
- IExpression[] args = function.getParameters();
- function.setName("convert"); //$NON-NLS-1$
- args[1] = langFactory.createLiteral(targetType, String.class);
- function.setParameters(args);
- return function;
- }
-
- /**
- * In version 5.1 and after, we can simple use convert(x, DECIMAL), but for backward compatibility we must do (x + 0.0)
- * @param function
- * @return
- * @since 4.3
- */
- private IExpression convertToNumeric(IFunction function) {
- // convert(x, float/double/bigdecimal) --> (x + 0.0)
- return langFactory.createFunction("+", //$NON-NLS-1$
- new IExpression[] {function.getParameters()[0],
- langFactory.createLiteral(new Double(0.0), Double.class)},
- Double.class);
- }
-
- private IExpression convertToDateTime(String functionName, IExpression value, Class targetType) {
- return langFactory.createFunction(functionName,
- new IExpression[] {value},
- targetType);
- }
-
- private IExpression convertToBoolean(IFunction function) {
- int srcCode = getSrcCode(function);
- switch(srcCode) {
- case STRING:
- // convert(src, boolean) --> CASE src WHEN 'true' THEN 1 ELSE 0 END
- // convert(booleanSrc, string) --> CASE WHEN booleanSrc THEN '1' ELSE '0' END
- List when = Arrays.asList(langFactory.createCompareCriteria(Operator.EQ, function.getParameters()[0], langFactory.createLiteral("true", String.class)));
- List then = Arrays.asList(new IExpression[] {langFactory.createLiteral(Integer.valueOf(1), Integer.class)}); //$NON-NLS-1$
- IExpression elseExpr = langFactory.createLiteral(Integer.valueOf(0), Integer.class); //$NON-NLS-1$
- return langFactory.createSearchedCaseExpression(when, then, elseExpr, String.class);
- default:
- return DROP_MODIFIER.modify(function);
- }
- }
-
- private IFunction convertDateTimeToString(IFunction function, String format) {
- // convert (date, string) --> date_format(date, format)
- IExpression[] args = function.getParameters();
- function.setName("date_format"); //$NON-NLS-1$
- args[1] = langFactory.createLiteral(format, String.class);
- function.setParameters(args);
- return function;
- }
-
- private int getSrcCode(IFunction function) {
- IExpression[] args = function.getParameters();
- Class srcType = args[0].getType();
- return ((Integer) typeMap.get(srcType)).intValue();
- }
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLConvertModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLConvertModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLConvertModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,185 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.mysql;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
+import org.teiid.connector.jdbc.translator.DropFunctionModifier;
+
+import com.metamatrix.connector.language.ICompareCriteria;
+import com.metamatrix.connector.language.ICriteria;
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+import com.metamatrix.connector.language.ILiteral;
+import com.metamatrix.connector.language.ICompareCriteria.Operator;
+
+
+/**
+ * @since 4.3
+ */
+class MySQLConvertModifier extends BasicFunctionModifier {
+
+ private static DropFunctionModifier DROP_MODIFIER = new DropFunctionModifier();
+
+ private ILanguageFactory langFactory;
+
+ MySQLConvertModifier(ILanguageFactory langFactory) {
+ this.langFactory = langFactory;
+ }
+
+ public List translate(IFunction function) {
+ return null;
+ }
+
+ public IExpression modify(IFunction function) {
+ List<IExpression> args = function.getParameters();
+
+ if (args.get(0) != null && args.get(0) instanceof ILiteral && ((ILiteral)args.get(0)).getValue() == null ) {
+ if (args.get(1) != null && args.get(1) instanceof ILiteral) {
+ // This is a convert(null, ...) or cast(null as ...)
+ return DROP_MODIFIER.modify(function);
+ }
+ }
+
+ if (args.get(1) != null && args.get(1) instanceof ILiteral) {
+ String target = ((String)((ILiteral)args.get(1)).getValue()).toLowerCase();
+ if (target.equals("string")) { //$NON-NLS-1$
+ return convertToString(function);
+ } else if (target.equals("byte") || //$NON-NLS-1$
+ target.equals("short") || //$NON-NLS-1$
+ target.equals("integer")) { //$NON-NLS-1$
+ return convertToNativeType(function, "SIGNED INTEGER"); //$NON-NLS-1$
+ } else if (target.equals("long") || //$NON-NLS-1$
+ target.equals("biginteger")) { //$NON-NLS-1$
+ return convertToNativeType(function, "SIGNED"); //$NON-NLS-1$
+ } else if (target.equals("float") || //$NON-NLS-1$
+ target.equals("double") || //$NON-NLS-1$
+ target.equals("bigdecimal")) { //$NON-NLS-1$
+ return convertToNumeric(function);
+ } else if (target.equals("date")) { //$NON-NLS-1$
+ return convertToDateTime("DATE", args.get(0), java.sql.Date.class); //$NON-NLS-1$
+ } else if (target.equals("time")) { //$NON-NLS-1$
+ return convertToDateTime("TIME", args.get(0), java.sql.Time.class); //$NON-NLS-1$
+ } else if (target.equals("timestamp")) { //$NON-NLS-1$
+ return convertToDateTime("TIMESTAMP", args.get(0), java.sql.Timestamp.class); //$NON-NLS-1$
+ } else if (target.equals("char")) { //$NON-NLS-1$
+ return convertToNativeType(function, "CHAR (1)"); //$NON-NLS-1$
+ } else if (target.equals("boolean")) { //$NON-NLS-1$
+ return convertToBoolean(function);
+ }
+ }
+ return DROP_MODIFIER.modify(function);
+ }
+
+ private IExpression convertToString(IFunction function) {
+ int srcCode = getSrcCode(function);
+ switch(srcCode) {
+ case BOOLEAN:
+ // convert(booleanSrc, string) --> CASE WHEN booleanSrc THEN '1' ELSE '0' END
+ List<ICompareCriteria> when = Arrays.asList(langFactory.createCompareCriteria(Operator.EQ, function.getParameters().get(0), langFactory.createLiteral(Boolean.TRUE, Boolean.class)));
+ List<ILiteral> then = Arrays.asList(langFactory.createLiteral("1", String.class)); //$NON-NLS-1$
+ IExpression elseExpr = langFactory.createLiteral("0", String.class); //$NON-NLS-1$
+ return langFactory.createSearchedCaseExpression(when, then, elseExpr, String.class);
+ case BYTE:
+ case SHORT:
+ case INTEGER:
+ case LONG:
+ case BIGINTEGER:
+ case FLOAT:
+ case DOUBLE:
+ case BIGDECIMAL:
+ // convert(src, string) --> convert(src, CHAR)
+ return convertToNativeType(function, "CHAR"); //$NON-NLS-1$
+ case DATE:
+ // convert (dateSrc, string) --> date_format(dateSrc, '%Y-%m-%d')
+ return convertDateTimeToString(function, "%Y-%m-%d"); //$NON-NLS-1$
+ case TIME:
+ // convert (timeSrc, string) --> date_format(timeSrc, '%H:%i:%S')
+ return convertDateTimeToString(function, "%H:%i:%S"); //$NON-NLS-1$
+ case TIMESTAMP:
+ // convert (tsSrc, string) --> date_format(tsSrc, '%Y-%m-%d %H:%i:%S.%f')
+ return convertDateTimeToString(function, "%Y-%m-%d %H:%i:%S.%f"); //$NON-NLS-1$
+ default:
+ return DROP_MODIFIER.modify(function);
+ }
+ }
+
+ private IExpression convertToNativeType(IFunction function, String targetType) {
+ List<IExpression> args = function.getParameters();
+ function.setName("convert"); //$NON-NLS-1$
+ args.set(1, langFactory.createLiteral(targetType, String.class));
+ return function;
+ }
+
+ /**
+ * In version 5.1 and after, we can simple use convert(x, DECIMAL), but for backward compatibility we must do (x + 0.0)
+ * @param function
+ * @return
+ * @since 4.3
+ */
+ private IExpression convertToNumeric(IFunction function) {
+ // convert(x, float/double/bigdecimal) --> (x + 0.0)
+ return langFactory.createFunction("+", //$NON-NLS-1$
+ Arrays.asList(function.getParameters().get(0),
+ langFactory.createLiteral(new Double(0.0), Double.class)),
+ Double.class);
+ }
+
+ private IExpression convertToDateTime(String functionName, IExpression value, Class targetType) {
+ return langFactory.createFunction(functionName,
+ Arrays.asList(value),
+ targetType);
+ }
+
+ private IExpression convertToBoolean(IFunction function) {
+ int srcCode = getSrcCode(function);
+ switch(srcCode) {
+ case STRING:
+ // convert(src, boolean) --> CASE src WHEN 'true' THEN 1 ELSE 0 END
+ // convert(booleanSrc, string) --> CASE WHEN booleanSrc THEN '1' ELSE '0' END
+ List<ICompareCriteria> when = Arrays.asList(langFactory.createCompareCriteria(Operator.EQ, function.getParameters().get(0), langFactory.createLiteral("true", String.class)));
+ List<ILiteral> then = Arrays.asList(langFactory.createLiteral(Integer.valueOf(1), Integer.class)); //$NON-NLS-1$
+ IExpression elseExpr = langFactory.createLiteral(Integer.valueOf(0), Integer.class); //$NON-NLS-1$
+ return langFactory.createSearchedCaseExpression(when, then, elseExpr, String.class);
+ default:
+ return DROP_MODIFIER.modify(function);
+ }
+ }
+
+ private IFunction convertDateTimeToString(IFunction function, String format) {
+ // convert (date, string) --> date_format(date, format)
+ List<IExpression> args = function.getParameters();
+ function.setName("date_format"); //$NON-NLS-1$
+ args.set(1, langFactory.createLiteral(format, String.class));
+ return function;
+ }
+
+ private int getSrcCode(IFunction function) {
+ List<IExpression> args = function.getParameters();
+ Class srcType = args.get(0).getType();
+ return ((Integer) typeMap.get(srcType)).intValue();
+ }
+}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLTranslator.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLTranslator.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.mysql;
+package org.teiid.connector.jdbc.mysql;
import java.sql.Connection;
import java.sql.Date;
@@ -29,10 +29,11 @@
import java.sql.Time;
import java.sql.Timestamp;
+import org.teiid.connector.jdbc.translator.Translator;
+
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.SourceSystemFunctions;
-import com.metamatrix.connector.jdbc.translator.Translator;
/**
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle)
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ConcatFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/ConcatFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ConcatFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -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 com.metamatrix.connector.jdbc.oracle;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.jdbc.translator.BasicFunctionModifier;
-import com.metamatrix.connector.language.ICriteria;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.connector.language.ILiteral;
-import com.metamatrix.connector.language.ICompoundCriteria.Operator;
-
-
-/**
- * This Function modifier used to support ANSI concat on Oracle 9i.
- * TODO: this is no longer necessary on Oracle 10g and later.
- * <code>
- * CONCAT(a, b) ==> CASE WHEN (a is NULL OR b is NULL) THEN NULL ELSE CONCAT(a, b)
- * </code>
- */
-public class ConcatFunctionModifier extends BasicFunctionModifier {
- private ILanguageFactory langFactory;
-
- /**
- * @param langFactory
- */
- public ConcatFunctionModifier(ILanguageFactory langFactory) {
- this.langFactory = langFactory;
- }
-
- /**
- * @see com.metamatrix.connector.jdbc.translator.BasicFunctionModifier#modify(com.metamatrix.connector.language.IFunction)
- */
- public IExpression modify(IFunction function) {
- List when = new ArrayList();
- IExpression a = function.getParameters()[0];
- IExpression b = function.getParameters()[1];
- List crits = new ArrayList();
-
- ILiteral nullValue = langFactory.createLiteral(null, TypeFacility.RUNTIME_TYPES.STRING);
- if (isNull(a)) {
- return nullValue;
- } else if (!isNotNull(a)) {
- crits.add(langFactory.createIsNullCriteria(a, false));
- }
- if (isNull(b)) {
- return nullValue;
- } else if (!isNotNull(b)) {
- crits.add(langFactory.createIsNullCriteria(b, false));
- }
-
- ICriteria crit = null;
-
- if (crits.isEmpty()) {
- return function;
- } else if (crits.size() == 1) {
- crit = (ICriteria)crits.get(0);
- } else {
- crit = langFactory.createCompoundCriteria(Operator.OR, crits);
- }
- when.add(crit);
- List then = Arrays.asList(new IExpression[] {nullValue});
- return langFactory.createSearchedCaseExpression(when, then, function, TypeFacility.RUNTIME_TYPES.STRING);
- }
-
- private boolean isNotNull(IExpression expr) {
- if (expr instanceof ILiteral) {
- ILiteral literal = (ILiteral)expr;
- return literal.getValue() != null;
- }
- if (expr instanceof IFunction) {
- IFunction function = (IFunction)expr;
- if (function.getName().equalsIgnoreCase("NVL") || function.getName().equalsIgnoreCase("IFNULL")) { //$NON-NLS-1$ //$NON-NLS-2$
- return isNotNull(function.getParameters()[1]);
- }
- }
- return false;
- }
-
- private boolean isNull(IExpression expr) {
- if (expr instanceof ILiteral) {
- ILiteral literal = (ILiteral)expr;
- return literal.getValue() == null;
- }
- return false;
- }
-
- /**
- * @see com.metamatrix.connector.jdbc.translator.BasicFunctionModifier#translate(com.metamatrix.connector.language.IFunction)
- */
- public List translate(IFunction function) {
- return null; //allow default translation
- }
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ConcatFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/ConcatFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ConcatFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ConcatFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,121 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.oracle;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
+
+import com.metamatrix.connector.api.SourceSystemFunctions;
+import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.language.ICriteria;
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+import com.metamatrix.connector.language.ILiteral;
+import com.metamatrix.connector.language.ICompoundCriteria.Operator;
+
+
+/**
+ * This Function modifier used to support ANSI concat on Oracle 9i.
+ * TODO: this is no longer necessary on Oracle 10g and later.
+ * <code>
+ * CONCAT(a, b) ==> CASE WHEN (a is NULL OR b is NULL) THEN NULL ELSE CONCAT(a, b)
+ * </code>
+ */
+public class ConcatFunctionModifier extends BasicFunctionModifier {
+ private ILanguageFactory langFactory;
+
+ /**
+ * @param langFactory
+ */
+ public ConcatFunctionModifier(ILanguageFactory langFactory) {
+ this.langFactory = langFactory;
+ }
+
+ /**
+ * @see org.teiid.connector.jdbc.translator.BasicFunctionModifier#modify(com.metamatrix.connector.language.IFunction)
+ */
+ public IExpression modify(IFunction function) {
+ List when = new ArrayList();
+ IExpression a = function.getParameters().get(0);
+ IExpression b = function.getParameters().get(1);
+ List crits = new ArrayList();
+
+ ILiteral nullValue = langFactory.createLiteral(null, TypeFacility.RUNTIME_TYPES.STRING);
+ if (isNull(a)) {
+ return nullValue;
+ } else if (!isNotNull(a)) {
+ crits.add(langFactory.createIsNullCriteria(a, false));
+ }
+ if (isNull(b)) {
+ return nullValue;
+ } else if (!isNotNull(b)) {
+ crits.add(langFactory.createIsNullCriteria(b, false));
+ }
+
+ ICriteria crit = null;
+
+ if (crits.isEmpty()) {
+ return function;
+ } else if (crits.size() == 1) {
+ crit = (ICriteria)crits.get(0);
+ } else {
+ crit = langFactory.createCompoundCriteria(Operator.OR, crits);
+ }
+ when.add(crit);
+ List then = Arrays.asList(new IExpression[] {nullValue});
+ return langFactory.createSearchedCaseExpression(when, then, function, TypeFacility.RUNTIME_TYPES.STRING);
+ }
+
+ private boolean isNotNull(IExpression expr) {
+ if (expr instanceof ILiteral) {
+ ILiteral literal = (ILiteral)expr;
+ return literal.getValue() != null;
+ }
+ if (expr instanceof IFunction) {
+ IFunction function = (IFunction)expr;
+ if (function.getName().equalsIgnoreCase("NVL") || function.getName().equalsIgnoreCase(SourceSystemFunctions.IFNULL)) { //$NON-NLS-1$
+ return isNotNull(function.getParameters().get(0));
+ }
+ }
+ return false;
+ }
+
+ private boolean isNull(IExpression expr) {
+ if (expr instanceof ILiteral) {
+ ILiteral literal = (ILiteral)expr;
+ return literal.getValue() == null;
+ }
+ return false;
+ }
+
+ /**
+ * @see org.teiid.connector.jdbc.translator.BasicFunctionModifier#translate(com.metamatrix.connector.language.IFunction)
+ */
+ public List translate(IFunction function) {
+ return null; //allow default translation
+ }
+}
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/DayWeekQuarterFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/DayWeekQuarterFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/DayWeekQuarterFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,65 +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 com.metamatrix.connector.jdbc.oracle;
-
-import com.metamatrix.connector.jdbc.translator.BasicFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.FunctionModifier;
-import com.metamatrix.connector.language.*;
-
-/**
- * This a method for multiple use. It can be used for:
- * 1) dayofyear
- * 2) dayofmonth
- * 3) dayofweek
- * 4) week
- * 5) quarter
- */
-public class DayWeekQuarterFunctionModifier extends BasicFunctionModifier implements FunctionModifier {
- private ILanguageFactory langFactory;
- private String format;
-
- public DayWeekQuarterFunctionModifier(ILanguageFactory langFactory, String format) {
- this.langFactory = langFactory;
- this.format = format;
- }
-
- /*
- * @see com.metamatrix.connector.jdbc.extension.FunctionModifier#modify(com.metamatrix.data.language.IFunction)
- */
- public IExpression modify(IFunction function) {
- IExpression[] args = function.getParameters();
-
- IFunction inner = langFactory.createFunction("TO_CHAR", //$NON-NLS-1$
- new IExpression[] {
- args[0],
- langFactory.createLiteral(format, String.class)},
- String.class);
-
- IFunction outer = langFactory.createFunction("TO_NUMBER", //$NON-NLS-1$
- new IExpression[] {inner},
- Integer.class);
-
- return outer;
- }
-}
-
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/DayWeekQuarterFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/DayWeekQuarterFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/DayWeekQuarterFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/DayWeekQuarterFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.oracle;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
+import org.teiid.connector.jdbc.translator.FunctionModifier;
+
+import com.metamatrix.connector.language.*;
+
+/**
+ * This a method for multiple use. It can be used for:
+ * 1) dayofyear
+ * 2) dayofmonth
+ * 3) dayofweek
+ * 4) week
+ * 5) quarter
+ */
+public class DayWeekQuarterFunctionModifier extends BasicFunctionModifier implements FunctionModifier {
+ private ILanguageFactory langFactory;
+ private String format;
+
+ public DayWeekQuarterFunctionModifier(ILanguageFactory langFactory, String format) {
+ this.langFactory = langFactory;
+ this.format = format;
+ }
+
+ /*
+ * @see com.metamatrix.connector.jdbc.extension.FunctionModifier#modify(com.metamatrix.data.language.IFunction)
+ */
+ public IExpression modify(IFunction function) {
+ List<IExpression> args = function.getParameters();
+
+ IFunction inner = langFactory.createFunction("TO_CHAR", //$NON-NLS-1$
+ Arrays.asList(
+ args.get(0),
+ langFactory.createLiteral(format, String.class)),
+ String.class);
+
+ IFunction outer = langFactory.createFunction("TO_NUMBER", //$NON-NLS-1$
+ Arrays.asList(inner),
+ Integer.class);
+
+ return outer;
+ }
+}
+
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ExtractFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/ExtractFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ExtractFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,62 +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 com.metamatrix.connector.jdbc.oracle;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.metamatrix.connector.jdbc.translator.BasicFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.FunctionModifier;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-
-/**
- * Convert the YEAR/MONTH/DAY etc. function into an equivalent Oracle function.
- * Format: EXTRACT(YEAR from Element) or EXTRACT(YEAR from DATE '2004-03-03')
- */
-public class ExtractFunctionModifier extends BasicFunctionModifier implements FunctionModifier {
- public static final String SPACE = " "; //$NON-NLS-1$
-
- private String target;
-
- public ExtractFunctionModifier(String target) {
- this.target = target;
- }
-
- public List translate(IFunction function) {
- StringBuffer buffer = new StringBuffer();
- IExpression[] args = function.getParameters();
-
- List objs = new ArrayList();
- buffer.append("EXTRACT("); //$NON-NLS-1$
- buffer.append(target);
- buffer.append(SPACE);
- buffer.append("FROM"); //$NON-NLS-1$
-
- buffer.append(SPACE);
- buffer.append(args[0]);
- buffer.append(")"); //$NON-NLS-1$
- objs.add(buffer.toString());
- return objs;
- }
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ExtractFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/ExtractFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ExtractFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ExtractFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.oracle;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
+import org.teiid.connector.jdbc.translator.FunctionModifier;
+
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+
+/**
+ * Convert the YEAR/MONTH/DAY etc. function into an equivalent Oracle function.
+ * Format: EXTRACT(YEAR from Element) or EXTRACT(YEAR from DATE '2004-03-03')
+ */
+public class ExtractFunctionModifier extends BasicFunctionModifier implements FunctionModifier {
+ public static final String SPACE = " "; //$NON-NLS-1$
+
+ private String target;
+
+ public ExtractFunctionModifier(String target) {
+ this.target = target;
+ }
+
+ public List translate(IFunction function) {
+ StringBuffer buffer = new StringBuffer();
+ List<IExpression> args = function.getParameters();
+
+ List objs = new ArrayList();
+ buffer.append("EXTRACT("); //$NON-NLS-1$
+ buffer.append(target);
+ buffer.append(SPACE);
+ buffer.append("FROM"); //$NON-NLS-1$
+
+ buffer.append(SPACE);
+ buffer.append(args.get(0));
+ buffer.append(")"); //$NON-NLS-1$
+ objs.add(buffer.toString());
+ return objs;
+ }
+}
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/LeftOrRightFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/LeftOrRightFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/LeftOrRightFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,69 +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 com.metamatrix.connector.jdbc.oracle;
-
-import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.jdbc.translator.BasicFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.FunctionModifier;
-import com.metamatrix.connector.language.*;
-
-/**
- * Convert left(string, count) --> substr(string, 1, count)
- * or right(string, count) --> substr(string, -1 * count) - we lack a way to express a unary negation
- */
-public class LeftOrRightFunctionModifier extends BasicFunctionModifier implements FunctionModifier {
- private ILanguageFactory langFactory;
-
- public LeftOrRightFunctionModifier(ILanguageFactory langFactory) {
- this.langFactory = langFactory;
- }
-
- /*
- * @see com.metamatrix.connector.jdbc.extension.FunctionModifier#modify(com.metamatrix.data.language.IFunction)
- */
- public IExpression modify(IFunction function) {
- IExpression[] args = function.getParameters();
- IFunction func = null;
-
- if (function.getName().equalsIgnoreCase("left")) { //$NON-NLS-1$
- func = langFactory.createFunction("SUBSTR", //$NON-NLS-1$
- new IExpression[] {
- args[0],
- langFactory.createLiteral(Integer.valueOf(1), TypeFacility.RUNTIME_TYPES.INTEGER),
- args[1]},
- String.class);
- } else if (function.getName().equalsIgnoreCase("right")) { //$NON-NLS-1$
- IFunction negIndex = langFactory.createFunction("*", //$NON-NLS-1$
- new IExpression[] {langFactory.createLiteral(Integer.valueOf(-1), TypeFacility.RUNTIME_TYPES.INTEGER), args[1]},
- Integer.class);
-
- func = langFactory.createFunction("SUBSTR", //$NON-NLS-1$
- new IExpression[] {
- args[0],
- negIndex},
- String.class);
- }
-
- return func;
- }
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/LeftOrRightFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/LeftOrRightFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/LeftOrRightFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/LeftOrRightFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.oracle;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
+import org.teiid.connector.jdbc.translator.FunctionModifier;
+
+import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.language.*;
+
+/**
+ * Convert left(string, count) --> substr(string, 1, count)
+ * or right(string, count) --> substr(string, -1 * count) - we lack a way to express a unary negation
+ */
+public class LeftOrRightFunctionModifier extends BasicFunctionModifier implements FunctionModifier {
+ private ILanguageFactory langFactory;
+
+ public LeftOrRightFunctionModifier(ILanguageFactory langFactory) {
+ this.langFactory = langFactory;
+ }
+
+ /*
+ * @see com.metamatrix.connector.jdbc.extension.FunctionModifier#modify(com.metamatrix.data.language.IFunction)
+ */
+ public IExpression modify(IFunction function) {
+ List<IExpression> args = function.getParameters();
+ IFunction func = null;
+
+ if (function.getName().equalsIgnoreCase("left")) { //$NON-NLS-1$
+ func = langFactory.createFunction("SUBSTR", //$NON-NLS-1$
+ Arrays.asList(
+ args.get(0),
+ langFactory.createLiteral(Integer.valueOf(1), TypeFacility.RUNTIME_TYPES.INTEGER),
+ args.get(1)),
+ String.class);
+ } else if (function.getName().equalsIgnoreCase("right")) { //$NON-NLS-1$
+ IFunction negIndex = langFactory.createFunction("*", //$NON-NLS-1$
+ Arrays.asList(langFactory.createLiteral(Integer.valueOf(-1), TypeFacility.RUNTIME_TYPES.INTEGER), args.get(1)),
+ Integer.class);
+
+ func = langFactory.createFunction("SUBSTR", //$NON-NLS-1$
+ Arrays.asList(
+ args.get(0),
+ negIndex),
+ String.class);
+ }
+
+ return func;
+ }
+}
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/LocateFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/LocateFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/LocateFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,77 +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 com.metamatrix.connector.jdbc.oracle;
-
-import com.metamatrix.connector.jdbc.translator.BasicFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.FunctionModifier;
-import com.metamatrix.connector.language.*;
-
-/**
- * Modify the locate function to use the Oracle instr function.
- *
- * locate(sub, str) -> instr(str, sub)
- *
- * locate(sub, str, start) -> instr(str, sub, start+1)
- */
-public class LocateFunctionModifier extends BasicFunctionModifier implements FunctionModifier {
-
- private ILanguageFactory langFactory;
-
- public LocateFunctionModifier(ILanguageFactory langFactory) {
- this.langFactory = langFactory;
- }
-
- /*
- * @see com.metamatrix.connector.jdbc.extension.FunctionModifier#modify(com.metamatrix.data.language.IFunction)
- */
- public IExpression modify(IFunction function) {
- IExpression[] args = function.getParameters();
- IExpression[] instrArgs = new IExpression[args.length];
- instrArgs[0] = args[1];
- instrArgs[1] = args[0];
-
- if(args.length == 3) {
- if(args[2] instanceof ILiteral) {
- ILiteral indexConst = (ILiteral)args[2];
- if(indexConst.getValue() == null) {
- instrArgs[2] = args[2];
- } else {
- // Just modify the constant
- Integer index = (Integer) ((ILiteral)args[2]).getValue();
- instrArgs[2] = langFactory.createLiteral(new Integer(index.intValue()+1), Integer.class);
- }
- } else {
- // Make plus function since this involves an element or function
- IFunction plusFunction = langFactory.createFunction("+", //$NON-NLS-1$
- new IExpression[] { args[2], langFactory.createLiteral(new Integer(1), Integer.class) },
- Integer.class);
- instrArgs[2] = plusFunction;
- }
- }
-
- IFunction instrFunction = langFactory.createFunction("instr", instrArgs, Integer.class); //$NON-NLS-1$
-
- return instrFunction;
- }
-
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/LocateFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/LocateFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/LocateFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/LocateFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.oracle;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
+import org.teiid.connector.jdbc.translator.FunctionModifier;
+
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+import com.metamatrix.connector.language.ILiteral;
+
+/**
+ * Modify the locate function to use the Oracle instr function.
+ *
+ * locate(sub, str) -> instr(str, sub)
+ *
+ * locate(sub, str, start) -> instr(str, sub, start+1)
+ */
+public class LocateFunctionModifier extends BasicFunctionModifier implements FunctionModifier {
+
+ private ILanguageFactory langFactory;
+
+ public LocateFunctionModifier(ILanguageFactory langFactory) {
+ this.langFactory = langFactory;
+ }
+
+ /*
+ * @see com.metamatrix.connector.jdbc.extension.FunctionModifier#modify(com.metamatrix.data.language.IFunction)
+ */
+ public IExpression modify(IFunction function) {
+ function.setName("instr"); //$NON-NLS-1$
+ List<IExpression> args = function.getParameters();
+ IExpression expr = args.get(0);
+ args.set(0, args.get(1));
+ args.set(1, expr);
+ if(args.size() == 3) {
+ if(args.get(2) instanceof ILiteral) {
+ ILiteral indexConst = (ILiteral)args.get(2);
+ if(indexConst.getValue() != null) {
+ // Just modify the constant
+ Integer index = (Integer) indexConst.getValue();
+ args.set(2, langFactory.createLiteral(new Integer(index.intValue()+1), Integer.class));
+ }
+ } else {
+ // Make plus function since this involves an element or function
+ IFunction plusFunction = langFactory.createFunction("+", //$NON-NLS-1$
+ Arrays.asList( args.get(2), langFactory.createLiteral(new Integer(1), Integer.class) ),
+ Integer.class);
+ args.set(2, plusFunction);
+ }
+ }
+ return function;
+ }
+
+}
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/Log10FunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/Log10FunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/Log10FunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,49 +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 com.metamatrix.connector.jdbc.oracle;
-
-import com.metamatrix.connector.jdbc.translator.BasicFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.FunctionModifier;
-import com.metamatrix.connector.language.*;
-
-public class Log10FunctionModifier extends BasicFunctionModifier implements FunctionModifier {
-
- private ILanguageFactory languageFactory;
-
- public Log10FunctionModifier(ILanguageFactory languageFactory) {
- this.languageFactory = languageFactory;
- }
-
- public IExpression modify(IFunction function) {
- function.setName("log"); //$NON-NLS-1$
-
- IExpression[] args = function.getParameters();
- IExpression[] newArgs = new IExpression[args.length+1];
- newArgs[1] = args[0];
- newArgs[0] = languageFactory.createLiteral(new Integer(10), Integer.class);
- function.setParameters(newArgs);
-
- return function;
- }
-
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/Log10FunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/Log10FunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/Log10FunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/Log10FunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.oracle;
+
+import java.util.List;
+
+import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
+import org.teiid.connector.jdbc.translator.FunctionModifier;
+
+import com.metamatrix.connector.language.*;
+
+public class Log10FunctionModifier extends BasicFunctionModifier implements FunctionModifier {
+
+ private ILanguageFactory languageFactory;
+
+ public Log10FunctionModifier(ILanguageFactory languageFactory) {
+ this.languageFactory = languageFactory;
+ }
+
+ public IExpression modify(IFunction function) {
+ function.setName("log"); //$NON-NLS-1$
+
+ List<IExpression> args = function.getParameters();
+ args.add(args.get(0));
+ args.set(0, languageFactory.createLiteral(new Integer(10), Integer.class));
+ return function;
+ }
+
+}
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/MonthOrDayNameFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/MonthOrDayNameFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/MonthOrDayNameFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,60 +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 com.metamatrix.connector.jdbc.oracle;
-
-import com.metamatrix.connector.jdbc.translator.BasicFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.FunctionModifier;
-import com.metamatrix.connector.language.*;
-
-/**
- * Convert the MONTHNAME etc. function into an equivalent Oracle function.
- * Format: to_char(timestampvalue/dayvalue, 'Month'/'Day')
- */
-public class MonthOrDayNameFunctionModifier extends BasicFunctionModifier implements FunctionModifier {
- private ILanguageFactory langFactory;
- private String format;
-
- public MonthOrDayNameFunctionModifier(ILanguageFactory langFactory, String format) {
- this.langFactory = langFactory;
- this.format = format;
- }
-
- /*
- * @see com.metamatrix.connector.jdbc.extension.FunctionModifier#modify(com.metamatrix.data.language.IFunction)
- */
- public IExpression modify(IFunction function) {
- IExpression[] args = function.getParameters();
-
- IFunction func = langFactory.createFunction("TO_CHAR", //$NON-NLS-1$
- new IExpression[] {
- args[0],
- langFactory.createLiteral(format, String.class)},
- String.class);
-
- // For some reason, these values have trailing spaces
- IFunction trimFunc = langFactory.createFunction("RTRIM", //$NON-NLS-1$
- new IExpression[] { func }, String.class);
-
- return trimFunc;
- }
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/MonthOrDayNameFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/MonthOrDayNameFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/MonthOrDayNameFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/MonthOrDayNameFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.oracle;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
+import org.teiid.connector.jdbc.translator.FunctionModifier;
+
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+
+/**
+ * Convert the MONTHNAME etc. function into an equivalent Oracle function.
+ * Format: to_char(timestampvalue/dayvalue, 'Month'/'Day')
+ */
+public class MonthOrDayNameFunctionModifier extends BasicFunctionModifier implements FunctionModifier {
+ private ILanguageFactory langFactory;
+ private String format;
+
+ public MonthOrDayNameFunctionModifier(ILanguageFactory langFactory, String format) {
+ this.langFactory = langFactory;
+ this.format = format;
+ }
+
+ /*
+ * @see com.metamatrix.connector.jdbc.extension.FunctionModifier#modify(com.metamatrix.data.language.IFunction)
+ */
+ public IExpression modify(IFunction function) {
+ List<IExpression> args = function.getParameters();
+
+ IFunction func = langFactory.createFunction("TO_CHAR", //$NON-NLS-1$
+ Arrays.asList(
+ args.get(0),
+ langFactory.createLiteral(format, String.class)),
+ String.class);
+
+ // For some reason, these values have trailing spaces
+ IFunction trimFunc = langFactory.createFunction("RTRIM", //$NON-NLS-1$
+ Arrays.asList( func ), String.class);
+
+ return trimFunc;
+ }
+}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleCapabilities.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleCapabilities.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -22,11 +22,12 @@
/*
*/
-package com.metamatrix.connector.jdbc.oracle;
+package org.teiid.connector.jdbc.oracle;
import java.util.*;
+
+import org.teiid.connector.jdbc.JDBCCapabilities;
-import com.metamatrix.connector.jdbc.JDBCCapabilities;
/**
*/
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleConvertModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,541 +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 com.metamatrix.connector.jdbc.oracle;
-
-import java.util.List;
-
-import com.metamatrix.connector.api.ConnectorLogger;
-import com.metamatrix.connector.jdbc.translator.BasicFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.DropFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.FunctionModifier;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.connector.language.ILiteral;
-
-/**
- */
-public class OracleConvertModifier extends BasicFunctionModifier implements FunctionModifier {
- private static DropFunctionModifier DROP_MODIFIER = new DropFunctionModifier();
- private ILanguageFactory langFactory;
-
- public OracleConvertModifier(ILanguageFactory langFactory, ConnectorLogger logger) {
- this.langFactory = langFactory;
- }
-
- /**
- * Intentionally return null, rely on the SQLStringVisitor being used by caller
- * (Oracle or Oracle8 SQLConversionVisitor (SQLConversionVisitor))
- * @see com.metamatrix.connector.jdbc.translator.FunctionModifier#translate(com.metamatrix.connector.language.IFunction)
- */
- public List translate(IFunction function) {
- return null;
- }
-
- public IExpression modify(IFunction function) {
- IExpression[] args = function.getParameters();
- IExpression modified = null;
-
- String target = ((String)((ILiteral)args[1]).getValue()).toLowerCase();
- if (target.equals("string")) { //$NON-NLS-1$
- modified = convertToString(function);
- } else if (target.equals("short")) { //$NON-NLS-1$
- modified = convertToShort(function);
- } else if (target.equals("integer")) { //$NON-NLS-1$
- modified = convertToInteger(function);
- } else if (target.equals("long")) { //$NON-NLS-1$
- modified = convertToLong(function);
- } else if (target.equals("biginteger")) { //$NON-NLS-1$
- modified = convertToBigInteger(function);
- } else if (target.equals("float")) { //$NON-NLS-1$
- modified = convertToFloat(function);
- } else if (target.equals("double")) { //$NON-NLS-1$
- modified = convertToDouble(function);
- } else if (target.equals("bigdecimal")) { //$NON-NLS-1$
- modified = convertToBigDecimal(function);
- } else if (target.equals("date")) { //$NON-NLS-1$
- modified = convertToDate(function);
- } else if (target.equals("time")) { //$NON-NLS-1$
- modified = convertToTime(function);
- } else if (target.equals("timestamp")) { //$NON-NLS-1$
- modified = convertToTimestamp(function);
- } else if (target.equals("char")) { //$NON-NLS-1$
- modified = convertToChar(function);
- } else if (target.equals("boolean")) { //$NON-NLS-1$
- modified = convertToBoolean(function);
- } else if (target.equals("byte")) { //$NON-NLS-1$
- modified = convertToByte(function);
- } else {
- modified = DROP_MODIFIER.modify(function);
- }
- return modified;
- }
-
- private IExpression convertToDate(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- Class srcType = args[0].getType();
- int srcCode = getSrcCode(srcType);
-
- switch(srcCode) {
- case STRING:
- // convert(STRING, date) --> to_date(STRING, format)
- String format = "YYYY-MM-DD"; //$NON-NLS-1$
- convert = dateTypeHelper("to_date", new IExpression[] {args[0], //$NON-NLS-1$
- langFactory.createLiteral(format, String.class)}, java.sql.Date.class);
- break;
- case TIMESTAMP:
- // convert(TSELEMENT, date) --> trunc(TSELEMENT)
- convert = dateTypeHelper("trunc", new IExpression[] {args[0]}, java.sql.Date.class); //$NON-NLS-1$
- break;
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- /**
- * TODO: need to remove the prepend 1970-01-01 and the {ts''}
- * @param function
- * @return IExpression
- */
- private IExpression convertToTime(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- Class srcType = args[0].getType();
- String format = "YYYY-MM-DD HH24:MI:SS"; //$NON-NLS-1$
-
- int srcCode = getSrcCode(srcType);
- switch(srcCode) {
- case STRING:
- //convert(STRING, time) --> to_date('1970-01-01 ' || to_char(timevalue, 'HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS')
- IFunction inner0 = langFactory.createFunction("to_char", //$NON-NLS-1$
- new IExpression[] {
- args[0],
- langFactory.createLiteral("HH24:MI:SS", String.class)}, //$NON-NLS-1$
- String.class);
-
- IExpression prependedPart0 = langFactory.createFunction("||", //$NON-NLS-1$
- new IExpression[] {
- langFactory.createLiteral("1970-01-01 ", String.class), //$NON-NLS-1$
- inner0},
- String.class);
-
- convert = langFactory.createFunction("to_date", //$NON-NLS-1$
- new IExpression[] {prependedPart0,
- langFactory.createLiteral(format, String.class)},
- java.sql.Time.class);
- break;
- case TIMESTAMP:
- // convert(timestamp, time)
- // --> to_date(('1970-01-01 ' || to_char(timestampvalue, 'HH24:MI:SS'))),
- // 'YYYY-MM-DD HH24:MI:SS')
- IFunction inner = langFactory.createFunction("to_char", //$NON-NLS-1$
- new IExpression[] {
- args[0],
- langFactory.createLiteral("HH24:MI:SS", String.class)}, //$NON-NLS-1$
- String.class);
-
- IExpression prependedPart = langFactory.createFunction("||", //$NON-NLS-1$
- new IExpression[] {
- langFactory.createLiteral("1970-01-01 ", String.class), //$NON-NLS-1$
- inner},
- String.class);
-
- convert = langFactory.createFunction("to_date", //$NON-NLS-1$
- new IExpression[] {prependedPart,
- langFactory.createLiteral(format, String.class)},
- java.sql.Time.class);
- break;
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToTimestamp(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- Class srcType = args[0].getType();
- int srcCode = getSrcCode(srcType);
- switch(srcCode) {
- case STRING:
- // convert(STRING, timestamp) --> to_date(timestampvalue, 'YYYY-MM-DD HH24:MI:SS.FF')))
- String format = "YYYY-MM-DD HH24:MI:SS.FF"; //$NON-NLS-1$
- convert = dateTypeHelper("to_timestamp", new IExpression[] {args[0], //$NON-NLS-1$
- langFactory.createLiteral(format, String.class)}, java.sql.Timestamp.class);
- break;
- case TIME:
- case DATE:
- convert = dateTypeHelper("cast", new IExpression[] {args[0], //$NON-NLS-1$
- langFactory.createLiteral("timestamp", String.class)}, java.sql.Timestamp.class); //$NON-NLS-1$
- break;
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToChar(IFunction function) {
- // two cases:
- // 1) 2-byte: convert(string, char) --> cast(stringkey AS char(2))
- // 2) single bit: just drop
- // TODO: case 1)
- return DROP_MODIFIER.modify(function);
- }
-
- private IExpression convertToString(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- String format = null;
-
- int srcCode = getSrcCode(function);
- switch(srcCode) { // convert(input, string) --> to_char(input)
- case BOOLEAN:
- convert = langFactory.createFunction("decode", new IExpression[] //$NON-NLS-1$
- { args[0],
- langFactory.createLiteral(new Integer(0), Integer.class),
- langFactory.createLiteral("false", String.class), //$NON-NLS-1$
- langFactory.createLiteral(new Integer(1), Integer.class),
- langFactory.createLiteral("true", String.class) }, //$NON-NLS-1$
- String.class);
-
- break;
- case BYTE:
- case SHORT:
- case INTEGER:
- case LONG:
- case BIGINTEGER:
- case FLOAT:
- case DOUBLE:
- case BIGDECIMAL:
- convert = createStringFunction(args[0]);
- break;
- // convert(input, string) --> to_char(input, format)
- case DATE:
- format = "YYYY-MM-DD"; //$NON-NLS-1$
- convert = createStringFunction(args[0], format);
- break;
- case TIME:
- format = "HH24:MI:SS"; //$NON-NLS-1$
- convert = createStringFunction(args[0], format);
- break;
- case TIMESTAMP:
- convert = createStringFunction(args[0], "YYYY-MM-DD HH24:MI:SS.FF"); //$NON-NLS-1$
- break;
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToBoolean(IFunction function) {
- IExpression convert = null;
- int srcCode = getSrcCode(function);
- switch(srcCode) {
- case STRING:
- // convert(src, boolean) --> decode(string, 'true', 1, 'false', 0)
- convert = booleanHelper(function);
- break;
- case BYTE:
- case SHORT:
- case INTEGER:
- case LONG:
- case BIGINTEGER:
- case FLOAT:
- case DOUBLE:
- case BIGDECIMAL:
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToByte(IFunction function) {
- IExpression convert = null;
- int srcCode = getSrcCode(function);
-
- switch(srcCode) {
- case STRING:
- convert = stringSrcHelper(function);
- break;
- case BOOLEAN:
- case SHORT:
- case INTEGER:
- case LONG:
- case BIGINTEGER:
- case FLOAT:
- case DOUBLE:
- case BIGDECIMAL:
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToShort(IFunction function) {
- IExpression convert = null;
- int srcCode = getSrcCode(function);
-
- switch(srcCode) {
- case STRING:
- convert = stringSrcHelper(function);
- break;
- case BOOLEAN:
- case BYTE:
- case INTEGER:
- case LONG:
- case BIGINTEGER:
- case FLOAT:
- case DOUBLE:
- case BIGDECIMAL:
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToInteger(IFunction function) {
- IExpression convert = null;
- int srcCode = getSrcCode(function);
-
- switch(srcCode) {
- case STRING:
- convert = stringSrcHelper(function);
- break;
- case BOOLEAN:
- case LONG:
- case BIGINTEGER:
- case FLOAT:
- case DOUBLE:
- case BIGDECIMAL:
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToLong(IFunction function) {
- IExpression convert = null;
- int srcCode = getSrcCode(function);
-
- switch(srcCode) {
- case STRING:
- convert = stringSrcHelper(function);
- break;
- case BOOLEAN:
- case BIGINTEGER:
- case FLOAT:
- case DOUBLE:
- case BIGDECIMAL:
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToBigInteger(IFunction function) {
- IExpression convert = null;
- int srcCode = getSrcCode(function);
-
- switch(srcCode) {
- case STRING:
- convert = stringSrcHelper(function);
- break;
- case BOOLEAN:
- case FLOAT:
- case DOUBLE:
- case BIGDECIMAL:
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToFloat(IFunction function) {
- IExpression convert = null;
- int srcCode = getSrcCode(function);
-
- switch(srcCode) {
- case STRING:
- convert = stringSrcHelper(function);
- break;
- case BOOLEAN:
- case DOUBLE:
- case BIGDECIMAL:
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToDouble(IFunction function) {
- IExpression convert = null;
- int srcCode = getSrcCode(function);
-
- switch(srcCode) {
- case STRING:
- convert = stringSrcHelper(function);
- break;
- case BOOLEAN:
- case BIGDECIMAL:
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToBigDecimal(IFunction function) {
- IExpression convert = null;
- int srcCode = getSrcCode(function);
-
- switch(srcCode) {
- case STRING:
- convert = stringSrcHelper(function);
- break;
- case BOOLEAN:
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IFunction dateTypeHelper(String functionName, IExpression[] args, Class target) {
- IFunction convert = langFactory.createFunction(functionName,
- args, target);
- return convert;
- }
-
- private IFunction booleanHelper(IFunction function) {
- // using decode(value, 'true', 1, 'false', 0)
- IExpression[] args = function.getParameters();
-
- IExpression[] modified = new IExpression[] {
- args[0],
- langFactory.createLiteral("true", String.class), //$NON-NLS-1$
- langFactory.createLiteral(new Byte((byte)1), Byte.class),
- langFactory.createLiteral("false", String.class), //$NON-NLS-1$
- langFactory.createLiteral(new Byte((byte)0), Byte.class)
- };
-
- return langFactory.createFunction("decode", //$NON-NLS-1$
- modified, java.lang.Boolean.class);
- }
-
- private IExpression stringSrcHelper(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- // switch the target type
- String functionName = "to_number"; //$NON-NLS-1$
- int targetCode = getTargetCode(function.getType());
- switch(targetCode) {
- case BYTE:
- convert = createFunction(functionName, args[0], Byte.class);
- break;
- case SHORT:
- convert = createFunction(functionName, args[0], Short.class);
- break;
- case INTEGER:
- convert = createFunction(functionName, args[0], Integer.class);
- break;
- case LONG:
- convert = createFunction(functionName, args[0], Long.class);
- break;
- case BIGINTEGER:
- convert = createFunction(functionName, args[0], java.math.BigInteger.class);
- break;
- case FLOAT:
- convert = createFunction(functionName, args[0], Float.class);
- break;
- case DOUBLE:
- convert = createFunction(functionName, args[0], Double.class);
- break;
- case BIGDECIMAL:
- convert = createFunction(functionName, args[0], java.math.BigDecimal.class);
- break;
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
- return convert;
- }
-
- private IFunction createFunction(String functionName, IExpression args0, Class targetClass) {
- IFunction created = langFactory.createFunction(functionName,
- new IExpression[] {args0}, targetClass);
- return created;
- }
-
- private IFunction createStringFunction(IExpression args0, String format) {
- IFunction created = langFactory.createFunction("to_char", //$NON-NLS-1$
- new IExpression[] {args0, langFactory.createLiteral(format, String.class)},
- String.class);
- return created;
- }
-
- private IFunction createStringFunction(IExpression args) {
- IFunction created = langFactory.createFunction("to_char", //$NON-NLS-1$
- new IExpression[] { args }, String.class);
- return created;
- }
-
- private int getSrcCode(IFunction function) {
- IExpression[] args = function.getParameters();
- Class srcType = args[0].getType();
- return ((Integer) typeMap.get(srcType)).intValue();
- }
-
- private int getSrcCode(Class source) {
- return ((Integer) typeMap.get(source)).intValue();
- }
-
- private int getTargetCode(Class target) {
- return ((Integer) typeMap.get(target)).intValue();
- }
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleConvertModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleConvertModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleConvertModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,541 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.oracle;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
+import org.teiid.connector.jdbc.translator.DropFunctionModifier;
+import org.teiid.connector.jdbc.translator.FunctionModifier;
+
+import com.metamatrix.connector.api.ConnectorLogger;
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+import com.metamatrix.connector.language.ILiteral;
+
+/**
+ */
+public class OracleConvertModifier extends BasicFunctionModifier implements FunctionModifier {
+ private static DropFunctionModifier DROP_MODIFIER = new DropFunctionModifier();
+ private ILanguageFactory langFactory;
+
+ public OracleConvertModifier(ILanguageFactory langFactory, ConnectorLogger logger) {
+ this.langFactory = langFactory;
+ }
+
+ /**
+ * Intentionally return null, rely on the SQLStringVisitor being used by caller
+ * (Oracle or Oracle8 SQLConversionVisitor (SQLConversionVisitor))
+ * @see org.teiid.connector.jdbc.translator.FunctionModifier#translate(com.metamatrix.connector.language.IFunction)
+ */
+ public List translate(IFunction function) {
+ return null;
+ }
+
+ public IExpression modify(IFunction function) {
+ List<IExpression> args = function.getParameters();
+ IExpression modified = null;
+
+ String target = ((String)((ILiteral)args.get(1)).getValue()).toLowerCase();
+ if (target.equals("string")) { //$NON-NLS-1$
+ modified = convertToString(function);
+ } else if (target.equals("short")) { //$NON-NLS-1$
+ modified = convertToShort(function);
+ } else if (target.equals("integer")) { //$NON-NLS-1$
+ modified = convertToInteger(function);
+ } else if (target.equals("long")) { //$NON-NLS-1$
+ modified = convertToLong(function);
+ } else if (target.equals("biginteger")) { //$NON-NLS-1$
+ modified = convertToBigInteger(function);
+ } else if (target.equals("float")) { //$NON-NLS-1$
+ modified = convertToFloat(function);
+ } else if (target.equals("double")) { //$NON-NLS-1$
+ modified = convertToDouble(function);
+ } else if (target.equals("bigdecimal")) { //$NON-NLS-1$
+ modified = convertToBigDecimal(function);
+ } else if (target.equals("date")) { //$NON-NLS-1$
+ modified = convertToDate(function);
+ } else if (target.equals("time")) { //$NON-NLS-1$
+ modified = convertToTime(function);
+ } else if (target.equals("timestamp")) { //$NON-NLS-1$
+ modified = convertToTimestamp(function);
+ } else if (target.equals("char")) { //$NON-NLS-1$
+ modified = convertToChar(function);
+ } else if (target.equals("boolean")) { //$NON-NLS-1$
+ modified = convertToBoolean(function);
+ } else if (target.equals("byte")) { //$NON-NLS-1$
+ modified = convertToByte(function);
+ } else {
+ modified = DROP_MODIFIER.modify(function);
+ }
+ return modified;
+ }
+
+ private IExpression convertToDate(IFunction function) {
+ IExpression convert = null;
+ List<IExpression> args = function.getParameters();
+ Class srcType = args.get(0).getType();
+ int srcCode = getSrcCode(srcType);
+
+ switch(srcCode) {
+ case STRING:
+ // convert(STRING, date) --> to_date(STRING, format)
+ String format = "YYYY-MM-DD"; //$NON-NLS-1$
+ convert = dateTypeHelper("to_date", Arrays.asList(args.get(0), //$NON-NLS-1$
+ langFactory.createLiteral(format, String.class)), java.sql.Date.class);
+ break;
+ case TIMESTAMP:
+ // convert(TSELEMENT, date) --> trunc(TSELEMENT)
+ convert = dateTypeHelper("trunc", Arrays.asList(args.get(0)), java.sql.Date.class); //$NON-NLS-1$
+ break;
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ /**
+ * TODO: need to remove the prepend 1970-01-01 and the {ts''}
+ * @param function
+ * @return IExpression
+ */
+ private IExpression convertToTime(IFunction function) {
+ IExpression convert = null;
+ List<IExpression> args = function.getParameters();
+ Class srcType = args.get(0).getType();
+ String format = "YYYY-MM-DD HH24:MI:SS"; //$NON-NLS-1$
+
+ int srcCode = getSrcCode(srcType);
+ switch(srcCode) {
+ case STRING:
+ //convert(STRING, time) --> to_date('1970-01-01 ' || to_char(timevalue, 'HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS')
+ IFunction inner0 = langFactory.createFunction("to_char", //$NON-NLS-1$
+ Arrays.asList(
+ args.get(0),
+ langFactory.createLiteral("HH24:MI:SS", String.class)), //$NON-NLS-1$
+ String.class);
+
+ IExpression prependedPart0 = langFactory.createFunction("||", //$NON-NLS-1$
+ Arrays.asList(
+ langFactory.createLiteral("1970-01-01 ", String.class), //$NON-NLS-1$
+ inner0),
+ String.class);
+
+ convert = langFactory.createFunction("to_date", //$NON-NLS-1$
+ Arrays.asList(prependedPart0,
+ langFactory.createLiteral(format, String.class)),
+ java.sql.Time.class);
+ break;
+ case TIMESTAMP:
+ // convert(timestamp, time)
+ // --> to_date(('1970-01-01 ' || to_char(timestampvalue, 'HH24:MI:SS'))),
+ // 'YYYY-MM-DD HH24:MI:SS')
+ IFunction inner = langFactory.createFunction("to_char", //$NON-NLS-1$
+ Arrays.asList(
+ args.get(0),
+ langFactory.createLiteral("HH24:MI:SS", String.class)), //$NON-NLS-1$
+ String.class);
+
+ IExpression prependedPart = langFactory.createFunction("||", //$NON-NLS-1$
+ Arrays.asList(
+ langFactory.createLiteral("1970-01-01 ", String.class), //$NON-NLS-1$
+ inner),
+ String.class);
+
+ convert = langFactory.createFunction("to_date", //$NON-NLS-1$
+ Arrays.asList(prependedPart,
+ langFactory.createLiteral(format, String.class)),
+ java.sql.Time.class);
+ break;
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToTimestamp(IFunction function) {
+ IExpression convert = null;
+ List<IExpression> args = function.getParameters();
+ Class srcType = args.get(0).getType();
+ int srcCode = getSrcCode(srcType);
+ switch(srcCode) {
+ case STRING:
+ // convert(STRING, timestamp) --> to_date(timestampvalue, 'YYYY-MM-DD HH24:MI:SS.FF')))
+ String format = "YYYY-MM-DD HH24:MI:SS.FF"; //$NON-NLS-1$
+ convert = dateTypeHelper("to_timestamp", Arrays.asList(args.get(0), //$NON-NLS-1$
+ langFactory.createLiteral(format, String.class)), java.sql.Timestamp.class);
+ break;
+ case TIME:
+ case DATE:
+ convert = dateTypeHelper("cast", Arrays.asList(args.get(0), //$NON-NLS-1$
+ langFactory.createLiteral("timestamp", String.class)), java.sql.Timestamp.class); //$NON-NLS-1$
+ break;
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToChar(IFunction function) {
+ // two cases:
+ // 1) 2-byte: convert(string, char) --> cast(stringkey AS char(2))
+ // 2) single bit: just drop
+ // TODO: case 1)
+ return DROP_MODIFIER.modify(function);
+ }
+
+ private IExpression convertToString(IFunction function) {
+ IExpression convert = null;
+ List<IExpression> args = function.getParameters();
+ String format = null;
+
+ int srcCode = getSrcCode(function);
+ switch(srcCode) { // convert(input, string) --> to_char(input)
+ case BOOLEAN:
+ convert = langFactory.createFunction("decode", Arrays.asList( //$NON-NLS-1$
+ args.get(0),
+ langFactory.createLiteral(new Integer(0), Integer.class),
+ langFactory.createLiteral("false", String.class), //$NON-NLS-1$
+ langFactory.createLiteral(new Integer(1), Integer.class),
+ langFactory.createLiteral("true", String.class) ), //$NON-NLS-1$
+ String.class);
+
+ break;
+ case BYTE:
+ case SHORT:
+ case INTEGER:
+ case LONG:
+ case BIGINTEGER:
+ case FLOAT:
+ case DOUBLE:
+ case BIGDECIMAL:
+ convert = createStringFunction(args.get(0));
+ break;
+ // convert(input, string) --> to_char(input, format)
+ case DATE:
+ format = "YYYY-MM-DD"; //$NON-NLS-1$
+ convert = createStringFunction(args.get(0), format);
+ break;
+ case TIME:
+ format = "HH24:MI:SS"; //$NON-NLS-1$
+ convert = createStringFunction(args.get(0), format);
+ break;
+ case TIMESTAMP:
+ convert = createStringFunction(args.get(0), "YYYY-MM-DD HH24:MI:SS.FF"); //$NON-NLS-1$
+ break;
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToBoolean(IFunction function) {
+ IExpression convert = null;
+ int srcCode = getSrcCode(function);
+ switch(srcCode) {
+ case STRING:
+ // convert(src, boolean) --> decode(string, 'true', 1, 'false', 0)
+ convert = booleanHelper(function);
+ break;
+ case BYTE:
+ case SHORT:
+ case INTEGER:
+ case LONG:
+ case BIGINTEGER:
+ case FLOAT:
+ case DOUBLE:
+ case BIGDECIMAL:
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToByte(IFunction function) {
+ IExpression convert = null;
+ int srcCode = getSrcCode(function);
+
+ switch(srcCode) {
+ case STRING:
+ convert = stringSrcHelper(function);
+ break;
+ case BOOLEAN:
+ case SHORT:
+ case INTEGER:
+ case LONG:
+ case BIGINTEGER:
+ case FLOAT:
+ case DOUBLE:
+ case BIGDECIMAL:
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToShort(IFunction function) {
+ IExpression convert = null;
+ int srcCode = getSrcCode(function);
+
+ switch(srcCode) {
+ case STRING:
+ convert = stringSrcHelper(function);
+ break;
+ case BOOLEAN:
+ case BYTE:
+ case INTEGER:
+ case LONG:
+ case BIGINTEGER:
+ case FLOAT:
+ case DOUBLE:
+ case BIGDECIMAL:
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToInteger(IFunction function) {
+ IExpression convert = null;
+ int srcCode = getSrcCode(function);
+
+ switch(srcCode) {
+ case STRING:
+ convert = stringSrcHelper(function);
+ break;
+ case BOOLEAN:
+ case LONG:
+ case BIGINTEGER:
+ case FLOAT:
+ case DOUBLE:
+ case BIGDECIMAL:
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToLong(IFunction function) {
+ IExpression convert = null;
+ int srcCode = getSrcCode(function);
+
+ switch(srcCode) {
+ case STRING:
+ convert = stringSrcHelper(function);
+ break;
+ case BOOLEAN:
+ case BIGINTEGER:
+ case FLOAT:
+ case DOUBLE:
+ case BIGDECIMAL:
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToBigInteger(IFunction function) {
+ IExpression convert = null;
+ int srcCode = getSrcCode(function);
+
+ switch(srcCode) {
+ case STRING:
+ convert = stringSrcHelper(function);
+ break;
+ case BOOLEAN:
+ case FLOAT:
+ case DOUBLE:
+ case BIGDECIMAL:
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToFloat(IFunction function) {
+ IExpression convert = null;
+ int srcCode = getSrcCode(function);
+
+ switch(srcCode) {
+ case STRING:
+ convert = stringSrcHelper(function);
+ break;
+ case BOOLEAN:
+ case DOUBLE:
+ case BIGDECIMAL:
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToDouble(IFunction function) {
+ IExpression convert = null;
+ int srcCode = getSrcCode(function);
+
+ switch(srcCode) {
+ case STRING:
+ convert = stringSrcHelper(function);
+ break;
+ case BOOLEAN:
+ case BIGDECIMAL:
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToBigDecimal(IFunction function) {
+ IExpression convert = null;
+ int srcCode = getSrcCode(function);
+
+ switch(srcCode) {
+ case STRING:
+ convert = stringSrcHelper(function);
+ break;
+ case BOOLEAN:
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IFunction dateTypeHelper(String functionName, List<IExpression> args, Class target) {
+ IFunction convert = langFactory.createFunction(functionName,
+ args, target);
+ return convert;
+ }
+
+ private IFunction booleanHelper(IFunction function) {
+ // using decode(value, 'true', 1, 'false', 0)
+ List<IExpression> args = function.getParameters();
+
+ return langFactory.createFunction("decode", //$NON-NLS-1$
+ Arrays.asList(
+ args.get(0),
+ langFactory.createLiteral("true", String.class), //$NON-NLS-1$
+ langFactory.createLiteral(new Byte((byte)1), Byte.class),
+ langFactory.createLiteral("false", String.class), //$NON-NLS-1$
+ langFactory.createLiteral(new Byte((byte)0), Byte.class)
+ ), java.lang.Boolean.class);
+ }
+
+ private IExpression stringSrcHelper(IFunction function) {
+ IExpression convert = null;
+ List<IExpression> args = function.getParameters();
+ // switch the target type
+ String functionName = "to_number"; //$NON-NLS-1$
+ int targetCode = getTargetCode(function.getType());
+ switch(targetCode) {
+ case BYTE:
+ convert = createFunction(functionName, args.get(0), Byte.class);
+ break;
+ case SHORT:
+ convert = createFunction(functionName, args.get(0), Short.class);
+ break;
+ case INTEGER:
+ convert = createFunction(functionName, args.get(0), Integer.class);
+ break;
+ case LONG:
+ convert = createFunction(functionName, args.get(0), Long.class);
+ break;
+ case BIGINTEGER:
+ convert = createFunction(functionName, args.get(0), java.math.BigInteger.class);
+ break;
+ case FLOAT:
+ convert = createFunction(functionName, args.get(0), Float.class);
+ break;
+ case DOUBLE:
+ convert = createFunction(functionName, args.get(0), Double.class);
+ break;
+ case BIGDECIMAL:
+ convert = createFunction(functionName, args.get(0), java.math.BigDecimal.class);
+ break;
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+ return convert;
+ }
+
+ private IFunction createFunction(String functionName, IExpression args0, Class targetClass) {
+ IFunction created = langFactory.createFunction(functionName,
+ Arrays.asList(args0), targetClass);
+ return created;
+ }
+
+ private IFunction createStringFunction(IExpression args0, String format) {
+ IFunction created = langFactory.createFunction("to_char", //$NON-NLS-1$
+ Arrays.asList(args0, langFactory.createLiteral(format, String.class)),
+ String.class);
+ return created;
+ }
+
+ private IFunction createStringFunction(IExpression args) {
+ IFunction created = langFactory.createFunction("to_char", //$NON-NLS-1$
+ Arrays.asList( args ), String.class);
+ return created;
+ }
+
+ private int getSrcCode(IFunction function) {
+ List<IExpression> args = function.getParameters();
+ Class srcType = args.get(0).getType();
+ return ((Integer) typeMap.get(srcType)).intValue();
+ }
+
+ private int getSrcCode(Class source) {
+ return ((Integer) typeMap.get(source)).intValue();
+ }
+
+ private int getTargetCode(Class target) {
+ return ((Integer) typeMap.get(target)).intValue();
+ }
+}
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleSQLTranslator.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,281 +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 com.metamatrix.connector.jdbc.oracle;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Types;
-import java.util.List;
-
-import com.metamatrix.connector.api.ConnectorEnvironment;
-import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.api.ExecutionContext;
-import com.metamatrix.connector.api.SourceSystemFunctions;
-import com.metamatrix.connector.jdbc.JDBCPlugin;
-import com.metamatrix.connector.jdbc.translator.AliasModifier;
-import com.metamatrix.connector.jdbc.translator.Translator;
-import com.metamatrix.connector.language.ICommand;
-import com.metamatrix.connector.language.IElement;
-import com.metamatrix.connector.language.IGroup;
-import com.metamatrix.connector.language.IInsert;
-import com.metamatrix.connector.language.ILimit;
-import com.metamatrix.connector.language.ISetQuery.Operation;
-import com.metamatrix.connector.metadata.runtime.Element;
-import com.metamatrix.connector.metadata.runtime.MetadataID;
-import com.metamatrix.connector.visitor.util.SQLReservedWords;
-
-/**
- */
-public class OracleSQLTranslator extends Translator {
-
- public final static String HINT_PREFIX = "/*+"; //$NON-NLS-1$
- public final static String DUAL = "DUAL"; //$NON-NLS-1$
- public final static String ROWNUM = "ROWNUM"; //$NON-NLS-1$
- public final static String SEQUENCE = ":SEQUENCE="; //$NON-NLS-1$
-
- public void initialize(ConnectorEnvironment env) throws ConnectorException {
- super.initialize(env);
- registerFunctionModifier(SourceSystemFunctions.CHAR, new AliasModifier("chr")); //$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.LCASE, new AliasModifier("lower")); //$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.UCASE, new AliasModifier("upper")); //$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("nvl")); //$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.LOG, new AliasModifier("ln")); //$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.CEILING, new AliasModifier("ceil")); //$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.LOG10, new Log10FunctionModifier(getLanguageFactory())); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.CONVERT, new OracleConvertModifier(getLanguageFactory(), getEnvironment().getLogger())); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.HOUR, new ExtractFunctionModifier("HOUR"));//$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.YEAR, new ExtractFunctionModifier("YEAR"));//$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.MINUTE, new ExtractFunctionModifier("MINUTE"));//$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.SECOND, new ExtractFunctionModifier("SECOND"));//$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.MONTH, new ExtractFunctionModifier("MONTH"));//$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new ExtractFunctionModifier("DAY"));//$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.MONTHNAME, new MonthOrDayNameFunctionModifier(getLanguageFactory(), "Month"));//$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.DAYNAME, new MonthOrDayNameFunctionModifier(getLanguageFactory(), "Day"));//$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.WEEK, new DayWeekQuarterFunctionModifier(getLanguageFactory(), "WW"));//$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.QUARTER, new DayWeekQuarterFunctionModifier(getLanguageFactory(), "Q"));//$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new DayWeekQuarterFunctionModifier(getLanguageFactory(), "D"));//$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new DayWeekQuarterFunctionModifier(getLanguageFactory(), "DDD"));//$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.LOCATE, new LocateFunctionModifier(getLanguageFactory()));//$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new AliasModifier("substr"));//$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.LEFT, new LeftOrRightFunctionModifier(getLanguageFactory()));//$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.RIGHT, new LeftOrRightFunctionModifier(getLanguageFactory()));//$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.CONCAT, new ConcatFunctionModifier(getLanguageFactory())); //$NON-NLS-1$
- }
-
- @Override
- public ICommand modifyCommand(ICommand command, ExecutionContext context)
- throws ConnectorException {
- if (!(command instanceof IInsert)) {
- return command;
- }
-
- /*
- * If a missing auto_increment column is modeled with name in source indicating that an Oracle Sequence
- * then pull the Sequence name out of the name in source of the column.
- */
- IInsert insert = (IInsert)command;
- List<MetadataID> allElements = insert.getGroup().getMetadataID().getChildIDs();
- if (allElements.size() == insert.getValues().size()) {
- return command;
- }
-
- int index = 0;
- List<IElement> elements = insert.getElements();
-
- for (MetadataID metadataID : allElements) {
- Element element = (Element)metadataID.getMetadataObject();
- if (!element.isAutoIncremented()) {
- continue;
- }
- String name = element.getNameInSource();
- int seqIndex = name.indexOf(SEQUENCE);
- if (seqIndex == -1) {
- continue;
- }
- boolean found = false;
- while (index < elements.size()) {
- if (metadataID.equals(elements.get(index).getMetadataID())) {
- found = true;
- break;
- }
- index++;
- }
- if (found) {
- continue;
- }
-
- String sequence = name.substring(seqIndex + SEQUENCE.length());
-
- int delimiterIndex = sequence.indexOf(SQLReservedWords.DOT);
- if (delimiterIndex == -1) {
- throw new ConnectorException("Invalid name in source sequence format. Expected <element name>" + SEQUENCE + "<sequence name>.<sequence value>, but was " + name);
- }
- String sequenceGroupName = sequence.substring(0, delimiterIndex);
- String sequenceElementName = sequence.substring(delimiterIndex + 1);
-
- IGroup sequenceGroup = this.getLanguageFactory().createGroup(sequenceGroupName, null, null);
- IElement sequenceElement = this.getLanguageFactory().createElement(sequenceElementName, sequenceGroup, null, element.getJavaType());
- insert.getElements().add(index, this.getLanguageFactory().createElement(element.getMetadataID().getName(), insert.getGroup(), metadataID, element.getJavaType()));
- insert.getValues().add(index, sequenceElement);
- }
- return command;
- }
-
- @Override
- public String addLimitString(String queryCommand, ILimit limit) {
- StringBuffer limitQuery = new StringBuffer(queryCommand.length());
- if (limit.getRowOffset() > 0) {
- limitQuery.append("SELECT * FROM (SELECT VIEW_FOR_LIMIT.*, ROWNUM ROWNUM_ FROM (");
- } else {
- limitQuery.append("SELECT * FROM (");
- }
- limitQuery.append(queryCommand);
- if (limit.getRowOffset() > 0) {
- limitQuery.append(") VIEW_FOR_LIMIT WHERE ROWNUM <= ").append(
- limit.getRowLimit()).append(") WHERE ROWNUM_ > ").append(
- limit.getRowOffset());
- } else {
- limitQuery.append(") WHERE ROWNUM <= ").append(
- limit.getRowLimit());
- }
- return limitQuery.toString();
- }
-
- @Override
- public boolean useAsInGroupAlias(){
- return false;
- }
-
- @Override
- public String getSetOperationString(Operation operation) {
- if (operation == Operation.EXCEPT) {
- return "MINUS"; //$NON-NLS-1$
- }
- return super.getSetOperationString(operation);
- }
-
- @Override
- public String getSourceComment(ExecutionContext context, ICommand command) {
- String comment = super.getSourceComment(context, command);
-
- if (context != null) {
- // Check for db hints
- Object payload = context.getExecutionPayload();
- if (payload instanceof String) {
- String payloadString = (String)payload;
- if (payloadString.startsWith(HINT_PREFIX)) {
- comment += payloadString + " "; //$NON-NLS-1$
- }
- }
- }
- return comment;
- }
-
- /**
- * Don't fully qualify elements if table = DUAL or element = ROWNUM or special stuff is packed into name in source value.
- *
- * @see com.metamatrix.connector.visitor.util.SQLStringVisitor#skipGroupInElement(java.lang.String, java.lang.String)
- * @since 5.0
- */
- @Override
- public String replaceElementName(String group, String element) {
-
- // Check if the element was modeled as using a Sequence
- int useIndex = element.indexOf(SEQUENCE);
- if (useIndex >= 0) {
- String name = element.substring(0, useIndex);
- if (group != null) {
- return group + SQLReservedWords.DOT + name;
- }
- return name;
- }
-
- // Check if the group name should be discarded
- if((group != null && group.equalsIgnoreCase(DUAL)) || element.equalsIgnoreCase(ROWNUM)) {
- // Strip group if group or element are pseudo-columns
- return element;
- }
-
- return null;
- }
-
- @Override
- public boolean hasTimeType() {
- return false;
- }
-
- @Override
- public String getDefaultConnectionTestQuery() {
- return "Select 'x' from DUAL"; //$NON-NLS-1$
- }
-
- @Override
- public void bindValue(PreparedStatement stmt, Object param, Class paramType, int i) throws SQLException {
- if(param == null && Object.class.equals(paramType)){
- //Oracle drive does not support JAVA_OBJECT type
- stmt.setNull(i, Types.LONGVARBINARY);
- return;
- }
- super.bindValue(stmt, param, paramType, i);
- }
-
- @Override
- public void afterInitialConnectionCreation(Connection connection) {
- String errorStr = JDBCPlugin.Util.getString("ConnectionListener.failed_to_report_oracle_connection_details"); //$NON-NLS-1$
- ResultSet rs = null;
- Statement stmt = null;
- try {
- stmt = connection.createStatement();
- rs = stmt.executeQuery("select * from v$instance");
-
- int columnCount = rs.getMetaData().getColumnCount();
- while (rs.next()) {
- StringBuffer sb = new StringBuffer();
- for (int i = 1; i <= columnCount; i++) {
- sb.append(rs.getMetaData().getColumnName(i)).append("=").append(rs.getString(i)).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- // log the queried information
- getEnvironment().getLogger().logInfo(sb.toString());
- }
-
- } catch (SQLException e) {
- getEnvironment().getLogger().logInfo(errorStr);
- }finally {
- try {
- if (rs != null) {
- rs.close();
- }
- if (stmt != null) {
- stmt.close();
- }
- } catch (SQLException e1) {
- getEnvironment().getLogger().logInfo(errorStr);
- }
- }
- }
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleSQLTranslator.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,280 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+/*
+ */
+package org.teiid.connector.jdbc.oracle;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Types;
+import java.util.List;
+
+import org.teiid.connector.jdbc.JDBCPlugin;
+import org.teiid.connector.jdbc.translator.AliasModifier;
+import org.teiid.connector.jdbc.translator.Translator;
+
+import com.metamatrix.connector.api.ConnectorEnvironment;
+import com.metamatrix.connector.api.ConnectorException;
+import com.metamatrix.connector.api.ExecutionContext;
+import com.metamatrix.connector.api.SourceSystemFunctions;
+import com.metamatrix.connector.language.ICommand;
+import com.metamatrix.connector.language.IElement;
+import com.metamatrix.connector.language.IGroup;
+import com.metamatrix.connector.language.IInsert;
+import com.metamatrix.connector.language.ILimit;
+import com.metamatrix.connector.language.ISetQuery.Operation;
+import com.metamatrix.connector.metadata.runtime.Element;
+import com.metamatrix.connector.visitor.util.SQLReservedWords;
+
+/**
+ */
+public class OracleSQLTranslator extends Translator {
+
+ public final static String HINT_PREFIX = "/*+"; //$NON-NLS-1$
+ public final static String DUAL = "DUAL"; //$NON-NLS-1$
+ public final static String ROWNUM = "ROWNUM"; //$NON-NLS-1$
+ public final static String SEQUENCE = ":SEQUENCE="; //$NON-NLS-1$
+
+ public void initialize(ConnectorEnvironment env) throws ConnectorException {
+ super.initialize(env);
+ registerFunctionModifier(SourceSystemFunctions.CHAR, new AliasModifier("chr")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.LCASE, new AliasModifier("lower")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.UCASE, new AliasModifier("upper")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("nvl")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.LOG, new AliasModifier("ln")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.CEILING, new AliasModifier("ceil")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.LOG10, new Log10FunctionModifier(getLanguageFactory())); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.CONVERT, new OracleConvertModifier(getLanguageFactory(), getEnvironment().getLogger())); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.HOUR, new ExtractFunctionModifier("HOUR"));//$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.YEAR, new ExtractFunctionModifier("YEAR"));//$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.MINUTE, new ExtractFunctionModifier("MINUTE"));//$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.SECOND, new ExtractFunctionModifier("SECOND"));//$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.MONTH, new ExtractFunctionModifier("MONTH"));//$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new ExtractFunctionModifier("DAY"));//$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.MONTHNAME, new MonthOrDayNameFunctionModifier(getLanguageFactory(), "Month"));//$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.DAYNAME, new MonthOrDayNameFunctionModifier(getLanguageFactory(), "Day"));//$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.WEEK, new DayWeekQuarterFunctionModifier(getLanguageFactory(), "WW"));//$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.QUARTER, new DayWeekQuarterFunctionModifier(getLanguageFactory(), "Q"));//$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new DayWeekQuarterFunctionModifier(getLanguageFactory(), "D"));//$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new DayWeekQuarterFunctionModifier(getLanguageFactory(), "DDD"));//$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.LOCATE, new LocateFunctionModifier(getLanguageFactory()));//$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new AliasModifier("substr"));//$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.LEFT, new LeftOrRightFunctionModifier(getLanguageFactory()));//$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.RIGHT, new LeftOrRightFunctionModifier(getLanguageFactory()));//$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.CONCAT, new ConcatFunctionModifier(getLanguageFactory())); //$NON-NLS-1$
+ }
+
+ @Override
+ public ICommand modifyCommand(ICommand command, ExecutionContext context)
+ throws ConnectorException {
+ if (!(command instanceof IInsert)) {
+ return command;
+ }
+
+ /*
+ * If a missing auto_increment column is modeled with name in source indicating that an Oracle Sequence
+ * then pull the Sequence name out of the name in source of the column.
+ */
+ IInsert insert = (IInsert)command;
+ List<Element> allElements = insert.getGroup().getMetadataObject().getChildren();
+ if (allElements.size() == insert.getValues().size()) {
+ return command;
+ }
+
+ int index = 0;
+ List<IElement> elements = insert.getElements();
+
+ for (Element element : allElements) {
+ if (!element.isAutoIncremented()) {
+ continue;
+ }
+ String name = element.getNameInSource();
+ int seqIndex = name.indexOf(SEQUENCE);
+ if (seqIndex == -1) {
+ continue;
+ }
+ boolean found = false;
+ while (index < elements.size()) {
+ if (element.equals(elements.get(index).getMetadataObject())) {
+ found = true;
+ break;
+ }
+ index++;
+ }
+ if (found) {
+ continue;
+ }
+
+ String sequence = name.substring(seqIndex + SEQUENCE.length());
+
+ int delimiterIndex = sequence.indexOf(SQLReservedWords.DOT);
+ if (delimiterIndex == -1) {
+ throw new ConnectorException("Invalid name in source sequence format. Expected <element name>" + SEQUENCE + "<sequence name>.<sequence value>, but was " + name);
+ }
+ String sequenceGroupName = sequence.substring(0, delimiterIndex);
+ String sequenceElementName = sequence.substring(delimiterIndex + 1);
+
+ IGroup sequenceGroup = this.getLanguageFactory().createGroup(sequenceGroupName, null, null);
+ IElement sequenceElement = this.getLanguageFactory().createElement(sequenceElementName, sequenceGroup, null, element.getJavaType());
+ insert.getElements().add(index, this.getLanguageFactory().createElement(element.getName(), insert.getGroup(), element, element.getJavaType()));
+ insert.getValues().add(index, sequenceElement);
+ }
+ return command;
+ }
+
+ @Override
+ public String addLimitString(String queryCommand, ILimit limit) {
+ StringBuffer limitQuery = new StringBuffer(queryCommand.length());
+ if (limit.getRowOffset() > 0) {
+ limitQuery.append("SELECT * FROM (SELECT VIEW_FOR_LIMIT.*, ROWNUM ROWNUM_ FROM (");
+ } else {
+ limitQuery.append("SELECT * FROM (");
+ }
+ limitQuery.append(queryCommand);
+ if (limit.getRowOffset() > 0) {
+ limitQuery.append(") VIEW_FOR_LIMIT WHERE ROWNUM <= ").append(
+ limit.getRowLimit()).append(") WHERE ROWNUM_ > ").append(
+ limit.getRowOffset());
+ } else {
+ limitQuery.append(") WHERE ROWNUM <= ").append(
+ limit.getRowLimit());
+ }
+ return limitQuery.toString();
+ }
+
+ @Override
+ public boolean useAsInGroupAlias(){
+ return false;
+ }
+
+ @Override
+ public String getSetOperationString(Operation operation) {
+ if (operation == Operation.EXCEPT) {
+ return "MINUS"; //$NON-NLS-1$
+ }
+ return super.getSetOperationString(operation);
+ }
+
+ @Override
+ public String getSourceComment(ExecutionContext context, ICommand command) {
+ String comment = super.getSourceComment(context, command);
+
+ if (context != null) {
+ // Check for db hints
+ Object payload = context.getExecutionPayload();
+ if (payload instanceof String) {
+ String payloadString = (String)payload;
+ if (payloadString.startsWith(HINT_PREFIX)) {
+ comment += payloadString + " "; //$NON-NLS-1$
+ }
+ }
+ }
+ return comment;
+ }
+
+ /**
+ * Don't fully qualify elements if table = DUAL or element = ROWNUM or special stuff is packed into name in source value.
+ *
+ * @see com.metamatrix.connector.visitor.util.SQLStringVisitor#skipGroupInElement(java.lang.String, java.lang.String)
+ * @since 5.0
+ */
+ @Override
+ public String replaceElementName(String group, String element) {
+
+ // Check if the element was modeled as using a Sequence
+ int useIndex = element.indexOf(SEQUENCE);
+ if (useIndex >= 0) {
+ String name = element.substring(0, useIndex);
+ if (group != null) {
+ return group + SQLReservedWords.DOT + name;
+ }
+ return name;
+ }
+
+ // Check if the group name should be discarded
+ if((group != null && group.equalsIgnoreCase(DUAL)) || element.equalsIgnoreCase(ROWNUM)) {
+ // Strip group if group or element are pseudo-columns
+ return element;
+ }
+
+ return null;
+ }
+
+ @Override
+ public boolean hasTimeType() {
+ return false;
+ }
+
+ @Override
+ public String getDefaultConnectionTestQuery() {
+ return "Select 'x' from DUAL"; //$NON-NLS-1$
+ }
+
+ @Override
+ public void bindValue(PreparedStatement stmt, Object param, Class paramType, int i) throws SQLException {
+ if(param == null && Object.class.equals(paramType)){
+ //Oracle drive does not support JAVA_OBJECT type
+ stmt.setNull(i, Types.LONGVARBINARY);
+ return;
+ }
+ super.bindValue(stmt, param, paramType, i);
+ }
+
+ @Override
+ public void afterInitialConnectionCreation(Connection connection) {
+ String errorStr = JDBCPlugin.Util.getString("ConnectionListener.failed_to_report_oracle_connection_details"); //$NON-NLS-1$
+ ResultSet rs = null;
+ Statement stmt = null;
+ try {
+ stmt = connection.createStatement();
+ rs = stmt.executeQuery("select * from v$instance");
+
+ int columnCount = rs.getMetaData().getColumnCount();
+ while (rs.next()) {
+ StringBuffer sb = new StringBuffer();
+ for (int i = 1; i <= columnCount; i++) {
+ sb.append(rs.getMetaData().getColumnName(i)).append("=").append(rs.getString(i)).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ // log the queried information
+ getEnvironment().getLogger().logInfo(sb.toString());
+ }
+
+ } catch (SQLException e) {
+ getEnvironment().getLogger().logInfo(errorStr);
+ }finally {
+ try {
+ if (rs != null) {
+ rs.close();
+ }
+ if (stmt != null) {
+ stmt.close();
+ }
+ } catch (SQLException e1) {
+ getEnvironment().getLogger().logInfo(errorStr);
+ }
+ }
+ }
+}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql)
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/DatePartFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/DatePartFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/DatePartFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,49 +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 com.metamatrix.connector.jdbc.postgresql;
-
-import com.metamatrix.connector.jdbc.translator.BasicFunctionModifier;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageFactory;
-
-
-/**
- * @since 4.3
- */
-class DatePartFunctionModifier extends BasicFunctionModifier {
-
- protected ILanguageFactory factory;
- private String part;
-
- DatePartFunctionModifier(ILanguageFactory langFactory, String partName) {
- this.factory = langFactory;
- this.part = partName;
- }
-
- public IExpression modify(IFunction function) {
- return factory.createFunction("date_part", //$NON-NLS-1$
- new IExpression[] {factory.createLiteral(part, String.class), function.getParameters()[0]},
- Integer.class);
- }
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/DatePartFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/DatePartFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/DatePartFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/DatePartFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.postgresql;
+
+import java.util.Arrays;
+
+import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
+
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+
+
+/**
+ * @since 4.3
+ */
+class DatePartFunctionModifier extends BasicFunctionModifier {
+
+ protected ILanguageFactory factory;
+ private String part;
+
+ DatePartFunctionModifier(ILanguageFactory langFactory, String partName) {
+ this.factory = langFactory;
+ this.part = partName;
+ }
+
+ public IExpression modify(IFunction function) {
+ return factory.createFunction("date_part", //$NON-NLS-1$
+ Arrays.asList(factory.createLiteral(part, String.class), function.getParameters().get(0)),
+ Integer.class);
+ }
+}
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/ModifiedDatePartFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/ModifiedDatePartFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/ModifiedDatePartFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,52 +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 com.metamatrix.connector.jdbc.postgresql;
-
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageFactory;
-
-
-/**
- * @since 4.3
- */
-class ModifiedDatePartFunctionModifier extends DatePartFunctionModifier {
-
- private String modifier;
- private Object arg;
-
- ModifiedDatePartFunctionModifier(ILanguageFactory factory, String partName, String modifierFunctionName, Object modifierArgument) {
- super(factory, partName);
- this.modifier = modifierFunctionName;
- this.arg = modifierArgument;
- }
-
- public IExpression modify(IFunction function) {
- IExpression expr = super.modify(function);
- return factory.createFunction(modifier,
- new IExpression[] {expr, factory.createLiteral(arg, arg.getClass())},
- arg.getClass());
- }
-
-
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/ModifiedDatePartFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/ModifiedDatePartFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/ModifiedDatePartFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/ModifiedDatePartFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.postgresql;
+
+import java.util.Arrays;
+
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+
+
+/**
+ * @since 4.3
+ */
+class ModifiedDatePartFunctionModifier extends DatePartFunctionModifier {
+
+ private String modifier;
+ private Object arg;
+
+ ModifiedDatePartFunctionModifier(ILanguageFactory factory, String partName, String modifierFunctionName, Object modifierArgument) {
+ super(factory, partName);
+ this.modifier = modifierFunctionName;
+ this.arg = modifierArgument;
+ }
+
+ public IExpression modify(IFunction function) {
+ IExpression expr = super.modify(function);
+ return factory.createFunction(modifier,
+ Arrays.asList(expr, factory.createLiteral(arg, arg.getClass())),
+ arg.getClass());
+ }
+
+
+}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLCapabilities.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,12 +20,13 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.postgresql;
+package org.teiid.connector.jdbc.postgresql;
import java.util.ArrayList;
import java.util.List;
+
+import org.teiid.connector.jdbc.JDBCCapabilities;
-import com.metamatrix.connector.jdbc.JDBCCapabilities;
/**
@@ -241,7 +242,7 @@
* This is true only after Postgre version 7.1
* However, since version 7 was released in 2000 we'll assume a post 7 instance.
*
- * @see com.metamatrix.connector.jdbc.JDBCCapabilities#supportsInlineViews()
+ * @see org.teiid.connector.jdbc.JDBCCapabilities#supportsInlineViews()
*/
public boolean supportsInlineViews() {
return true;
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLConvertModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,204 +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 com.metamatrix.connector.jdbc.postgresql;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Arrays;
-import java.util.List;
-
-import com.metamatrix.connector.jdbc.translator.BasicFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.DropFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.FunctionModifier;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.connector.language.ILiteral;
-import com.metamatrix.connector.language.ICompareCriteria.Operator;
-
-/**
- */
-class PostgreSQLConvertModifier extends BasicFunctionModifier implements FunctionModifier {
- private static DropFunctionModifier DROP_MODIFIER = new DropFunctionModifier();
- private ILanguageFactory langFactory;
-
- PostgreSQLConvertModifier(ILanguageFactory langFactory) {
- this.langFactory = langFactory;
- }
-
- public List translate(IFunction function) {
- return null;
- }
-
- public IExpression modify(IFunction function) {
- IExpression[] args = function.getParameters();
-
- if (args[0] != null && args[0] instanceof ILiteral && ((ILiteral)args[0]).getValue() == null ) {
- if (args[1] != null && args[1] instanceof ILiteral) {
- // This is a convert(null, ...) or cast(null as ...)
- return DROP_MODIFIER.modify(function);
- }
- }
-
- if (args[1] != null && args[1] instanceof ILiteral) {
- String target = ((String)((ILiteral)args[1]).getValue()).toLowerCase();
- if (target.equals("string")) { //$NON-NLS-1$
- return convertToString(function);
- } else if (target.equals("short")) { //$NON-NLS-1$
- return createCastFunction(args[0], "smallint", Short.class); //$NON-NLS-1$
- } else if (target.equals("integer")) { //$NON-NLS-1$
- return createCastFunction(args[0], "integer", Integer.class); //$NON-NLS-1$
- } else if (target.equals("long")) { //$NON-NLS-1$
- return createCastFunction(args[0], "bigint", Long.class); //$NON-NLS-1$
- } else if (target.equals("biginteger")) { //$NON-NLS-1$
- return createCastFunction(args[0], "numeric", BigInteger.class); //$NON-NLS-1$
- } else if (target.equals("float")) { //$NON-NLS-1$
- return createCastFunction(args[0], "real", Float.class); //$NON-NLS-1$
- } else if (target.equals("double")) { //$NON-NLS-1$
- return createCastFunction(args[0], "float8", Double.class); //$NON-NLS-1$
- } else if (target.equals("bigdecimal")) { //$NON-NLS-1$
- return createCastFunction(args[0], "decimal", BigDecimal.class); //$NON-NLS-1$
- } else if (target.equals("date")) { //$NON-NLS-1$
- return convertToDate(function);
- } else if (target.equals("time")) { //$NON-NLS-1$
- return convertToTime(function);
- } else if (target.equals("timestamp")) { //$NON-NLS-1$
- return convertToTimestamp(function);
- } else if (target.equals("char")) { //$NON-NLS-1$
- return createCastFunction(args[0], "varchar", String.class); //$NON-NLS-1$
- } else if (target.equals("boolean")) { //$NON-NLS-1$
- return createCastFunction(args[0], "boolean", Boolean.class); //$NON-NLS-1$
- } else if (target.equals("byte")) { //$NON-NLS-1$
- return createCastFunction(args[0], "smallint", Byte.class); //$NON-NLS-1$
- }
- }
- return DROP_MODIFIER.modify(function);
- }
-
- private IExpression convertToDate(IFunction function) {
- IExpression[] args = function.getParameters();
- int srcCode = getSrcCode(function);
-
- switch(srcCode) {
- case STRING:
- return createConversionFunction("to_date", args[0], "YYYY-MM-DD", java.sql.Date.class); //$NON-NLS-1$//$NON-NLS-2$
- case TIMESTAMP:
- return createCastFunction(args[0], "date", java.sql.Date.class); //$NON-NLS-1$
- default:
- return DROP_MODIFIER.modify(function);
- }
- }
-
- private IExpression convertToTime(IFunction function) {
- IExpression[] args = function.getParameters();
-
- int srcCode = getSrcCode(function);
- switch(srcCode) {
- case STRING:
- //convert(STRING, time) --> to_timestamp('1970-01-01 ' || timevalue, 'YYYY-MM-DD HH24:MI:SS')
- IExpression prependedPart0 = langFactory.createFunction("||", //$NON-NLS-1$
- new IExpression[] {langFactory.createLiteral("1970-01-01 ", String.class), args[0]}, //$NON-NLS-1$
- String.class);
-
- return createConversionFunction("to_timestamp", prependedPart0, "YYYY-MM-DD HH24:MI:SS", java.sql.Time.class); //$NON-NLS-1$ //$NON-NLS-2$
- case TIMESTAMP:
- return createCastFunction(args[0], "time", java.sql.Time.class); //$NON-NLS-1$
- default:
- return DROP_MODIFIER.modify(function);
- }
- }
-
- /**
- * This works only for Oracle 9i.
- * @param src
- * @return IFunction
- */
- private IExpression convertToTimestamp(IFunction function) {
- IExpression[] args = function.getParameters();
- int srcCode = getSrcCode(function);
- switch(srcCode) {
- case STRING:
- // convert(STRING, timestamp) --> to_date(timestampvalue, 'YYYY-MM-DD HH24:MI:SS'))) from smalla
- return createConversionFunction("to_timestamp", args[0], "YYYY-MM-DD HH24:MI:SS.UF", java.sql.Timestamp.class); //$NON-NLS-1$ //$NON-NLS-2$
- case TIME:
- case DATE:
- // convert(DATE, timestamp) --> to_date(to_char(DATE, 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS')
- IFunction inner = createStringFunction(args[0], "YYYY-MM-DD HH24:MI:SS"); //$NON-NLS-1$
-
- return createConversionFunction("to_timestamp", inner, "YYYY-MM-DD HH24:MI:SS", java.sql.Timestamp.class); //$NON-NLS-1$ //$NON-NLS-2$
- default:
- return DROP_MODIFIER.modify(function);
- }
- }
-
- private IExpression convertToString(IFunction function) {
- IExpression[] args = function.getParameters();
-
- int srcCode = getSrcCode(function);
- switch(srcCode) {
- case BOOLEAN:
- // convert(booleanSrc, string) --> CASE WHEN booleanSrc THEN '1' ELSE '0' END
- List when = Arrays.asList(langFactory.createCompareCriteria(Operator.EQ, function.getParameters()[0], langFactory.createLiteral(Boolean.TRUE, Boolean.class)));
- List then = Arrays.asList(new IExpression[] {langFactory.createLiteral("1", String.class)}); //$NON-NLS-1$
- IExpression elseExpr = langFactory.createLiteral("0", String.class); //$NON-NLS-1$
- return langFactory.createSearchedCaseExpression(when, then, elseExpr, String.class);
- case BYTE:
- case SHORT:
- case INTEGER:
- case LONG:
- case BIGINTEGER:
- case FLOAT:
- case DOUBLE:
- case BIGDECIMAL:
- // convert(src, string) --> cast (src AS varchar)
- return createCastFunction(args[0], "varchar", String.class); //$NON-NLS-1$
- // convert(input, string) --> to_char(input, format)
- case DATE:
- return createStringFunction(args[0], "YYYY-MM-DD"); //$NON-NLS-1$
- case TIME:
- return createStringFunction(args[0], "HH24:MI:SS"); //$NON-NLS-1$
- case TIMESTAMP:
- return createStringFunction(args[0], "YYYY-MM-DD HH24:MI:SS.US"); //$NON-NLS-1$
- default:
- return DROP_MODIFIER.modify(function);
- }
- }
-
- private IFunction createStringFunction(IExpression args0, String format) {
- return createConversionFunction("to_char", args0, format, String.class); //$NON-NLS-1$
- }
-
- private IFunction createCastFunction(IExpression value, String typeName, Class targetClass) {
- return createConversionFunction("cast", value, typeName, targetClass); //$NON-NLS-1$
- }
-
- private IFunction createConversionFunction(String functionName, IExpression value, String target, Class targetClass) {
- return langFactory.createFunction(functionName, new IExpression[] {value, langFactory.createLiteral(target, String.class)}, targetClass);
- }
-
- private int getSrcCode(IFunction function) {
- IExpression[] args = function.getParameters();
- Class srcType = args[0].getType();
- return ((Integer) typeMap.get(srcType)).intValue();
- }
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLConvertModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLConvertModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLConvertModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,205 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.postgresql;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
+import org.teiid.connector.jdbc.translator.DropFunctionModifier;
+import org.teiid.connector.jdbc.translator.FunctionModifier;
+
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+import com.metamatrix.connector.language.ILiteral;
+import com.metamatrix.connector.language.ICompareCriteria.Operator;
+
+/**
+ */
+class PostgreSQLConvertModifier extends BasicFunctionModifier implements FunctionModifier {
+ private static DropFunctionModifier DROP_MODIFIER = new DropFunctionModifier();
+ private ILanguageFactory langFactory;
+
+ PostgreSQLConvertModifier(ILanguageFactory langFactory) {
+ this.langFactory = langFactory;
+ }
+
+ public List translate(IFunction function) {
+ return null;
+ }
+
+ public IExpression modify(IFunction function) {
+ List<IExpression> args = function.getParameters();
+
+ if (args.get(0) != null && args.get(0) instanceof ILiteral && ((ILiteral)args.get(0)).getValue() == null ) {
+ if (args.get(1) != null && args.get(1) instanceof ILiteral) {
+ // This is a convert(null, ...) or cast(null as ...)
+ return DROP_MODIFIER.modify(function);
+ }
+ }
+
+ if (args.get(1) != null && args.get(1) instanceof ILiteral) {
+ String target = ((String)((ILiteral)args.get(1)).getValue()).toLowerCase();
+ if (target.equals("string")) { //$NON-NLS-1$
+ return convertToString(function);
+ } else if (target.equals("short")) { //$NON-NLS-1$
+ return createCastFunction(args.get(0), "smallint", Short.class); //$NON-NLS-1$
+ } else if (target.equals("integer")) { //$NON-NLS-1$
+ return createCastFunction(args.get(0), "integer", Integer.class); //$NON-NLS-1$
+ } else if (target.equals("long")) { //$NON-NLS-1$
+ return createCastFunction(args.get(0), "bigint", Long.class); //$NON-NLS-1$
+ } else if (target.equals("biginteger")) { //$NON-NLS-1$
+ return createCastFunction(args.get(0), "numeric", BigInteger.class); //$NON-NLS-1$
+ } else if (target.equals("float")) { //$NON-NLS-1$
+ return createCastFunction(args.get(0), "real", Float.class); //$NON-NLS-1$
+ } else if (target.equals("double")) { //$NON-NLS-1$
+ return createCastFunction(args.get(0), "float8", Double.class); //$NON-NLS-1$
+ } else if (target.equals("bigdecimal")) { //$NON-NLS-1$
+ return createCastFunction(args.get(0), "decimal", BigDecimal.class); //$NON-NLS-1$
+ } else if (target.equals("date")) { //$NON-NLS-1$
+ return convertToDate(function);
+ } else if (target.equals("time")) { //$NON-NLS-1$
+ return convertToTime(function);
+ } else if (target.equals("timestamp")) { //$NON-NLS-1$
+ return convertToTimestamp(function);
+ } else if (target.equals("char")) { //$NON-NLS-1$
+ return createCastFunction(args.get(0), "varchar", String.class); //$NON-NLS-1$
+ } else if (target.equals("boolean")) { //$NON-NLS-1$
+ return createCastFunction(args.get(0), "boolean", Boolean.class); //$NON-NLS-1$
+ } else if (target.equals("byte")) { //$NON-NLS-1$
+ return createCastFunction(args.get(0), "smallint", Byte.class); //$NON-NLS-1$
+ }
+ }
+ return DROP_MODIFIER.modify(function);
+ }
+
+ private IExpression convertToDate(IFunction function) {
+ List<IExpression> args = function.getParameters();
+ int srcCode = getSrcCode(function);
+
+ switch(srcCode) {
+ case STRING:
+ return createConversionFunction("to_date", args.get(0), "YYYY-MM-DD", java.sql.Date.class); //$NON-NLS-1$//$NON-NLS-2$
+ case TIMESTAMP:
+ return createCastFunction(args.get(0), "date", java.sql.Date.class); //$NON-NLS-1$
+ default:
+ return DROP_MODIFIER.modify(function);
+ }
+ }
+
+ private IExpression convertToTime(IFunction function) {
+ List<IExpression> args = function.getParameters();
+
+ int srcCode = getSrcCode(function);
+ switch(srcCode) {
+ case STRING:
+ //convert(STRING, time) --> to_timestamp('1970-01-01 ' || timevalue, 'YYYY-MM-DD HH24:MI:SS')
+ IExpression prependedPart0 = langFactory.createFunction("||", //$NON-NLS-1$
+ Arrays.asList(langFactory.createLiteral("1970-01-01 ", String.class), args.get(0)), //$NON-NLS-1$
+ String.class);
+
+ return createConversionFunction("to_timestamp", prependedPart0, "YYYY-MM-DD HH24:MI:SS", java.sql.Time.class); //$NON-NLS-1$ //$NON-NLS-2$
+ case TIMESTAMP:
+ return createCastFunction(args.get(0), "time", java.sql.Time.class); //$NON-NLS-1$
+ default:
+ return DROP_MODIFIER.modify(function);
+ }
+ }
+
+ /**
+ * This works only for Oracle 9i.
+ * @param src
+ * @return IFunction
+ */
+ private IExpression convertToTimestamp(IFunction function) {
+ List<IExpression> args = function.getParameters();
+ int srcCode = getSrcCode(function);
+ switch(srcCode) {
+ case STRING:
+ // convert(STRING, timestamp) --> to_date(timestampvalue, 'YYYY-MM-DD HH24:MI:SS'))) from smalla
+ return createConversionFunction("to_timestamp", args.get(0), "YYYY-MM-DD HH24:MI:SS.UF", java.sql.Timestamp.class); //$NON-NLS-1$ //$NON-NLS-2$
+ case TIME:
+ case DATE:
+ // convert(DATE, timestamp) --> to_date(to_char(DATE, 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS')
+ IFunction inner = createStringFunction(args.get(0), "YYYY-MM-DD HH24:MI:SS"); //$NON-NLS-1$
+
+ return createConversionFunction("to_timestamp", inner, "YYYY-MM-DD HH24:MI:SS", java.sql.Timestamp.class); //$NON-NLS-1$ //$NON-NLS-2$
+ default:
+ return DROP_MODIFIER.modify(function);
+ }
+ }
+
+ private IExpression convertToString(IFunction function) {
+ List<IExpression> args = function.getParameters();
+
+ int srcCode = getSrcCode(function);
+ switch(srcCode) {
+ case BOOLEAN:
+ // convert(booleanSrc, string) --> CASE WHEN booleanSrc THEN '1' ELSE '0' END
+ List when = Arrays.asList(langFactory.createCompareCriteria(Operator.EQ, function.getParameters().get(0), langFactory.createLiteral(Boolean.TRUE, Boolean.class)));
+ List then = Arrays.asList(langFactory.createLiteral("1", String.class)); //$NON-NLS-1$
+ IExpression elseExpr = langFactory.createLiteral("0", String.class); //$NON-NLS-1$
+ return langFactory.createSearchedCaseExpression(when, then, elseExpr, String.class);
+ case BYTE:
+ case SHORT:
+ case INTEGER:
+ case LONG:
+ case BIGINTEGER:
+ case FLOAT:
+ case DOUBLE:
+ case BIGDECIMAL:
+ // convert(src, string) --> cast (src AS varchar)
+ return createCastFunction(args.get(0), "varchar", String.class); //$NON-NLS-1$
+ // convert(input, string) --> to_char(input, format)
+ case DATE:
+ return createStringFunction(args.get(0), "YYYY-MM-DD"); //$NON-NLS-1$
+ case TIME:
+ return createStringFunction(args.get(0), "HH24:MI:SS"); //$NON-NLS-1$
+ case TIMESTAMP:
+ return createStringFunction(args.get(0), "YYYY-MM-DD HH24:MI:SS.US"); //$NON-NLS-1$
+ default:
+ return DROP_MODIFIER.modify(function);
+ }
+ }
+
+ private IFunction createStringFunction(IExpression args0, String format) {
+ return createConversionFunction("to_char", args0, format, String.class); //$NON-NLS-1$
+ }
+
+ private IFunction createCastFunction(IExpression value, String typeName, Class targetClass) {
+ return createConversionFunction("cast", value, typeName, targetClass); //$NON-NLS-1$
+ }
+
+ private IFunction createConversionFunction(String functionName, IExpression value, String target, Class targetClass) {
+ return langFactory.createFunction(functionName, Arrays.asList(value, langFactory.createLiteral(target, String.class)), targetClass);
+ }
+
+ private int getSrcCode(IFunction function) {
+ List<IExpression> args = function.getParameters();
+ Class srcType = args.get(0).getType();
+ return ((Integer) typeMap.get(srcType)).intValue();
+ }
+}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLTranslator.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,21 +20,22 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.postgresql;
+package org.teiid.connector.jdbc.postgresql;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
+import org.teiid.connector.jdbc.oracle.LeftOrRightFunctionModifier;
+import org.teiid.connector.jdbc.oracle.MonthOrDayNameFunctionModifier;
+import org.teiid.connector.jdbc.translator.AliasModifier;
+import org.teiid.connector.jdbc.translator.Translator;
+
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.ExecutionContext;
import com.metamatrix.connector.api.SourceSystemFunctions;
import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.jdbc.oracle.LeftOrRightFunctionModifier;
-import com.metamatrix.connector.jdbc.oracle.MonthOrDayNameFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.AliasModifier;
-import com.metamatrix.connector.jdbc.translator.Translator;
import com.metamatrix.connector.language.IAggregate;
import com.metamatrix.connector.language.ICommand;
import com.metamatrix.connector.language.ILimit;
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver)
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerCapabilities.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerCapabilities.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -22,11 +22,12 @@
/*
*/
-package com.metamatrix.connector.jdbc.sqlserver;
+package org.teiid.connector.jdbc.sqlserver;
import java.util.*;
+
+import org.teiid.connector.jdbc.JDBCCapabilities;
-import com.metamatrix.connector.jdbc.JDBCCapabilities;
/**
*/
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerSQLTranslator.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerSQLTranslator.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -22,13 +22,14 @@
/*
*/
-package com.metamatrix.connector.jdbc.sqlserver;
+package org.teiid.connector.jdbc.sqlserver;
+import org.teiid.connector.jdbc.sybase.SybaseSQLTranslator;
+import org.teiid.connector.jdbc.translator.AliasModifier;
+
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.SourceSystemFunctions;
-import com.metamatrix.connector.jdbc.sybase.SybaseSQLTranslator;
-import com.metamatrix.connector.jdbc.translator.AliasModifier;
/**
*/
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/ssl (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/ssl)
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/ssl
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/ssl/SequeLinkOracleCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/ssl/SequeLinkOracleCapabilities.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/ssl/SequeLinkOracleCapabilities.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,9 +20,9 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.ssl;
+package org.teiid.connector.jdbc.ssl;
-import com.metamatrix.connector.jdbc.oracle.OracleCapabilities;
+import org.teiid.connector.jdbc.oracle.OracleCapabilities;
/**
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase)
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/ModFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/ModFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/ModFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,71 +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 com.metamatrix.connector.jdbc.sybase;
-
-import java.util.List;
-
-import com.metamatrix.connector.api.TypeFacility.RUNTIME_TYPES;
-import com.metamatrix.connector.jdbc.translator.AliasModifier;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageFactory;
-
-public class ModFunctionModifier extends AliasModifier {
-
- private ILanguageFactory langFactory;
-
- public ModFunctionModifier(ILanguageFactory langFactory) {
- super("%"); //$NON-NLS-1$
- this.langFactory = langFactory;
- }
-
- @Override
- public IExpression modify(IFunction function) {
- IExpression[] expressions = function.getParameters();
- if (RUNTIME_TYPES.INTEGER.equals(expressions[0].getType())) {
- return super.modify(function);
- }
- //x % y => x - floor(x / y) * y
- IExpression[] divideArgs = new IExpression[2];
- System.arraycopy(expressions, 0, divideArgs, 0, 2);
- IFunction divide = langFactory.createFunction("/", divideArgs, divideArgs[0].getType()); //$NON-NLS-1$
-
- IFunction floor = langFactory.createFunction("floor", new IExpression[] {divide}, divide.getType()); //$NON-NLS-1$
-
- IExpression[] multArgs = new IExpression[] {
- floor, expressions[1]
- };
- IFunction mult = langFactory.createFunction("*", multArgs, multArgs[1].getType()); //$NON-NLS-1$
-
- IExpression[] minusArgs = new IExpression[] {
- expressions[0], mult
- };
- return langFactory.createFunction("-", minusArgs, minusArgs[0].getType()); //$NON-NLS-1$
- }
-
- @Override
- public List translate(IFunction function) {
- return null;
- }
-
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/ModFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/ModFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/ModFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/ModFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.sybase;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.connector.jdbc.translator.AliasModifier;
+
+import com.metamatrix.connector.api.TypeFacility.RUNTIME_TYPES;
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+
+public class ModFunctionModifier extends AliasModifier {
+
+ private ILanguageFactory langFactory;
+
+ public ModFunctionModifier(ILanguageFactory langFactory) {
+ super("%"); //$NON-NLS-1$
+ this.langFactory = langFactory;
+ }
+
+ @Override
+ public IExpression modify(IFunction function) {
+ List<IExpression> expressions = function.getParameters();
+ if (RUNTIME_TYPES.INTEGER.equals(expressions.get(0).getType())) {
+ return super.modify(function);
+ }
+ //x % y => x - floor(x / y) * y
+ IFunction divide = langFactory.createFunction("/", new ArrayList<IExpression>(expressions), expressions.get(0).getType()); //$NON-NLS-1$
+
+ IFunction floor = langFactory.createFunction("floor", Arrays.asList(divide), divide.getType()); //$NON-NLS-1$
+
+ List<IExpression> multArgs = Arrays.asList(floor, expressions.get(1));
+ IFunction mult = langFactory.createFunction("*", multArgs, multArgs.get(1).getType()); //$NON-NLS-1$
+
+ List<IExpression> minusArgs = Arrays.asList(expressions.get(0), mult);
+
+ return langFactory.createFunction("-", minusArgs, minusArgs.get(0).getType()); //$NON-NLS-1$
+ }
+
+ @Override
+ public List translate(IFunction function) {
+ return null;
+ }
+
+}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseCapabilities.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseCapabilities.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -22,12 +22,13 @@
/*
*/
-package com.metamatrix.connector.jdbc.sybase;
+package org.teiid.connector.jdbc.sybase;
import java.util.ArrayList;
import java.util.List;
+
+import org.teiid.connector.jdbc.JDBCCapabilities;
-import com.metamatrix.connector.jdbc.JDBCCapabilities;
/**
*/
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseConvertModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,509 +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 com.metamatrix.connector.jdbc.sybase;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.metamatrix.connector.jdbc.translator.BasicFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.DropFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.FunctionModifier;
-import com.metamatrix.connector.language.*;
-
-/**
- */
-public class SybaseConvertModifier extends BasicFunctionModifier implements FunctionModifier {
-
- private static DropFunctionModifier DROP_MODIFIER = new DropFunctionModifier();
- static {
- // index of expressions in convert functions in Sybase is one, not zero
- DROP_MODIFIER.setReplaceIndex(1);
- }
-
- private ILanguageFactory langFactory;
-
- public SybaseConvertModifier(ILanguageFactory langFactory) {
- this.langFactory = langFactory;
- }
-
- public IExpression modify(IFunction function) {
- IExpression[] args = function.getParameters();
- IExpression modified = null;
-
- if (args[1] != null && args[1] instanceof ILiteral) {
- String target = ((String)((ILiteral)args[1]).getValue()).toLowerCase();
- if (target.equals("string")) { //$NON-NLS-1$
- modified = convertToString(function);
- } else if (target.equals("short")) { //$NON-NLS-1$
- modified = convertToShort(function);
- } else if (target.equals("integer")) { //$NON-NLS-1$
- modified = convertToInteger(function);
- } else if (target.equals("long")) { //$NON-NLS-1$
- modified = convertToLong(function);
- } else if (target.equals("biginteger")) { //$NON-NLS-1$
- modified = convertToBigInteger(function);
- } else if (target.equals("float")) { //$NON-NLS-1$
- modified = convertToFloat(function);
- } else if (target.equals("double")) { //$NON-NLS-1$
- modified = convertToDouble(function);
- } else if (target.equals("bigdecimal")) { //$NON-NLS-1$
- modified = convertToBigDecimal(function);
- } else if (target.equals("date")) { //$NON-NLS-1$
- modified = convertToDate(function);
- } else if (target.equals("time")) { //$NON-NLS-1$
- modified = convertToTime(function);
- } else if (target.equals("timestamp")) { //$NON-NLS-1$
- modified = convertToTimestamp(function);
- } else if (target.equals("char")) { //$NON-NLS-1$
- modified = convertToChar(function);
- } else if (target.equals("boolean")) { //$NON-NLS-1$
- modified = convertToBoolean(function);
- } else if (target.equals("byte")) { //$NON-NLS-1$
- modified = convertToByte(function);
- } else {
- modified = DROP_MODIFIER.modify(function);
- }
- return modified;
-
- }
- return DROP_MODIFIER.modify(function);
- }
-
- /*
- * @see com.metamatrix.connector.jdbc.extension.FunctionModifier#translate(com.metamatrix.data.language.IFunction)
- */
- public List translate(IFunction function) {
- List parts = new ArrayList();
- parts.add("convert("); //$NON-NLS-1$
-
- IExpression[] args = function.getParameters();
-
- if(args != null && args.length > 0) {
- ILiteral type = (ILiteral) args[0];
- String typeStr = type.getValue().toString();
-
- parts.add(typeStr);
-
- for(int i=1; i<args.length; i++) {
- parts.add(", "); //$NON-NLS-1$
- parts.add(args[i]);
- }
- }
- parts.add(")"); //$NON-NLS-1$
- return parts;
- }
-
- private IExpression convertToBoolean(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- Class src = args[0].getType();
- int srcCode = getSrcCode(src);
-
- switch(srcCode) {
- case STRING:
- //TODO: how to map the 'true' to '1' before it is translated to bit
- case BYTE:
- case SHORT:
- case INTEGER:
- case LONG:
- case BIGINTEGER:
- case FLOAT:
- case DOUBLE:
- case BIGDECIMAL:
- convert = createFunction(args[0], "bit", Boolean.class); //$NON-NLS-1$
- break;
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToByte(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- Class src = args[0].getType();
- int srcCode = getSrcCode(src);
-
- switch(srcCode) {
- case STRING:
- case BOOLEAN:
- case SHORT:
- case INTEGER:
- case LONG:
- case BIGINTEGER:
- case FLOAT:
- case DOUBLE:
- case BIGDECIMAL:
- convert = createFunction(args[0], "tinyint", String.class); //$NON-NLS-1$
- break;
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToString(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- Class src = args[0].getType();
- int srcCode = getSrcCode(src);
-
- switch(srcCode) {
- case CHAR:
- case BOOLEAN:
- case BYTE:
- case SHORT:
- case INTEGER:
- case LONG:
- case BIGINTEGER:
- case FLOAT:
- case DOUBLE:
- case BIGDECIMAL:
- convert = createFunction(args[0], "varchar", String.class); //$NON-NLS-1$
- break;
- case DATE: // convert(date, string) --> convert(varchar, date, 112)
- //TODO: what is the best format 111/110/101?
- convert = createFunction(args[0], 101, String.class);
- break;
- case TIME: // convert(time, string) --> convert(varchar, time, 108)
- convert = createFunction(args[0], 108, String.class);
- break;
- case TIMESTAMP: // convert(time, string) --> convert(varchar, timestamp, 109)
- convert = createFunction(args[0], 109, String.class);
- break;
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToShort(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- Class src = args[0].getType();
- int srcCode = getSrcCode(src);
-
- switch(srcCode) {
- case STRING:
- case BOOLEAN:
- case BYTE:
- case INTEGER:
- case LONG:
- case BIGINTEGER:
- case FLOAT:
- case DOUBLE:
- case BIGDECIMAL:
- convert = createFunction(args[0], "smallint", Short.class); //$NON-NLS-1$
- break;
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToInteger(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- Class src = args[0].getType();
- int srcCode = getSrcCode(src);
-
- switch(srcCode) {
- case STRING:
- case BOOLEAN:
- case BYTE:
- case SHORT:
- case LONG:
- case BIGINTEGER:
- case FLOAT:
- case DOUBLE:
- case BIGDECIMAL:
- convert = createFunction(args[0], "int", Integer.class); //$NON-NLS-1$
- break;
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToLong(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- Class src = args[0].getType();
- int srcCode = getSrcCode(src);
-
- switch(srcCode) {
- case STRING:
- case BOOLEAN:
- case BYTE:
- case SHORT:
- case INTEGER:
- case BIGINTEGER:
- case FLOAT:
- case DOUBLE:
- case BIGDECIMAL:
- convert = createFunction(args[0], "numeric", Long.class); //$NON-NLS-1$
- break;
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToBigInteger(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- Class src = args[0].getType();
- int srcCode = getSrcCode(src);
-
- switch(srcCode) {
- case STRING:
- case BOOLEAN:
- case BYTE:
- case SHORT:
- case INTEGER:
- case LONG:
- case FLOAT:
- case DOUBLE:
- case BIGDECIMAL:
- convert = createFunction(args[0], "numeric", java.math.BigInteger.class); //$NON-NLS-1$
- break;
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToFloat(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- Class src = args[0].getType();
- int srcCode = getSrcCode(src);
-
- switch(srcCode) {
- case STRING:
- case BOOLEAN:
- case BYTE:
- case SHORT:
- case INTEGER:
- case LONG:
- case BIGINTEGER:
- case DOUBLE:
- case BIGDECIMAL:
- convert = createFunction(args[0], "real", Float.class); //$NON-NLS-1$
- break;
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToDouble(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- Class src = args[0].getType();
- int srcCode = getSrcCode(src);
-
- switch(srcCode) {
- case STRING:
- case BOOLEAN:
- case BYTE:
- case SHORT:
- case INTEGER:
- case LONG:
- case BIGINTEGER:
- case FLOAT:
- case BIGDECIMAL:
- convert = createFunction(args[0], "float", Double.class); //$NON-NLS-1$
- break;
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToBigDecimal(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- Class src = args[0].getType();
- int srcCode = getSrcCode(src);
-
- switch(srcCode) {
- case STRING:
- case BOOLEAN:
- case BYTE:
- case SHORT:
- case INTEGER:
- case LONG:
- case BIGINTEGER:
- case FLOAT:
- case DOUBLE:
- convert = createFunction(args[0], "float", java.math.BigDecimal.class); //$NON-NLS-1$
- break;
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToChar(IFunction function) {
- IExpression[] args = function.getParameters();
- return createFunction(args[0], "char", Character.class); //$NON-NLS-1$
- }
-
- private IExpression convertToDate(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- Class srcType = args[0].getType();
- int srcCode = getSrcCode(srcType);
-
- switch(srcCode) {
- case STRING:
- // convert(STRING, date) --> convert(datetime, STRING)
- convert = createFunction(args[0], "datetime", java.sql.Date.class); //$NON-NLS-1$
- break;
- case TIMESTAMP:
- // convert(TIMESTAMP, date) --> convert(datetime, convert(varchar, TIMESTAMP, 1/101))
- // Build inner convert
- IFunction innerConvert = langFactory.createFunction("convert", //$NON-NLS-1$
- new IExpression[] {
- langFactory.createLiteral("varchar", String.class), //$NON-NLS-1$
- args[0],
- langFactory.createLiteral(new Integer(109), Integer.class) },
- String.class);
-
- // Build outer convert
- convert = langFactory.createFunction("convert", //$NON-NLS-1$
- new IExpression[] {
- langFactory.createLiteral("datetime", String.class), //$NON-NLS-1$
- innerConvert },
- java.sql.Timestamp.class);
-
- break;
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToTime(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- Class srcType = args[0].getType();
-
- int srcCode = getSrcCode(srcType);
- switch(srcCode) {
- case STRING:
- //convert(STRING, time) --> convert(datetime, STRING)
- convert = createFunction(args[0], "datetime", java.sql.Time.class); //$NON-NLS-1$
- break;
- case TIMESTAMP:
- // convert(TIMESTAMP, time) --> convert(datetime, convert(varchar, TIMESTAMP, 108/8)
- // Build inner convert
- IFunction innerConvert = langFactory.createFunction("convert", //$NON-NLS-1$
- new IExpression[] {
- langFactory.createLiteral("varchar", String.class), //$NON-NLS-1$
- args[0],
- langFactory.createLiteral(new Integer(108), Integer.class) },
- String.class);
-
- // Build outer convert
- convert = langFactory.createFunction("convert", //$NON-NLS-1$
- new IExpression[] {
- langFactory.createLiteral("datetime", String.class), //$NON-NLS-1$
- innerConvert },
- java.sql.Time.class);
-
- break;
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IExpression convertToTimestamp(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- Class srcType = args[0].getType();
- int srcCode = getSrcCode(srcType);
- switch(srcCode) {
- case STRING:
- case TIME:
- case DATE:
- // convert(DATE/TIME/STRING, timestamp) --> convert(datetime, DATE)
- convert = createFunction(args[0], "datetime", java.sql.Timestamp.class); //$NON-NLS-1$
- break;
- default:
- convert = DROP_MODIFIER.modify(function);
- break;
- }
-
- return convert;
- }
-
- private IFunction createFunction(IExpression args0, String targetType, Class targetClass) {
- IFunction created = langFactory.createFunction("convert", //$NON-NLS-1$
- new IExpression[] {
- langFactory.createLiteral(targetType, String.class),
- args0},
- targetClass);
- return created;
- }
-
- private IFunction createFunction(IExpression args0, int formatNumber, Class targetClass) {
- IFunction created = langFactory.createFunction("convert", //$NON-NLS-1$
- new IExpression[] { langFactory.createLiteral("varchar", String.class), //$NON-NLS-1$
- args0,
- langFactory.createLiteral(new Integer(formatNumber), Integer.class) },
- targetClass);
- return created;
- }
-
- private int getSrcCode(Class source) {
- return ((Integer) typeMap.get(source)).intValue();
- }
-
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseConvertModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseConvertModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseConvertModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,514 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.sybase;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
+import org.teiid.connector.jdbc.translator.DropFunctionModifier;
+import org.teiid.connector.jdbc.translator.FunctionModifier;
+
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+import com.metamatrix.connector.language.ILiteral;
+
+/**
+ */
+public class SybaseConvertModifier extends BasicFunctionModifier implements FunctionModifier {
+
+ private static DropFunctionModifier DROP_MODIFIER = new DropFunctionModifier();
+ static {
+ // index of expressions in convert functions in Sybase is one, not zero
+ DROP_MODIFIER.setReplaceIndex(1);
+ }
+
+ private ILanguageFactory langFactory;
+
+ public SybaseConvertModifier(ILanguageFactory langFactory) {
+ this.langFactory = langFactory;
+ }
+
+ public IExpression modify(IFunction function) {
+ List<IExpression> args = function.getParameters();
+ IExpression modified = null;
+
+ if (args.get(1) != null && args.get(1) instanceof ILiteral) {
+ String target = ((String)((ILiteral)args.get(1)).getValue()).toLowerCase();
+ if (target.equals("string")) { //$NON-NLS-1$
+ modified = convertToString(function);
+ } else if (target.equals("short")) { //$NON-NLS-1$
+ modified = convertToShort(function);
+ } else if (target.equals("integer")) { //$NON-NLS-1$
+ modified = convertToInteger(function);
+ } else if (target.equals("long")) { //$NON-NLS-1$
+ modified = convertToLong(function);
+ } else if (target.equals("biginteger")) { //$NON-NLS-1$
+ modified = convertToBigInteger(function);
+ } else if (target.equals("float")) { //$NON-NLS-1$
+ modified = convertToFloat(function);
+ } else if (target.equals("double")) { //$NON-NLS-1$
+ modified = convertToDouble(function);
+ } else if (target.equals("bigdecimal")) { //$NON-NLS-1$
+ modified = convertToBigDecimal(function);
+ } else if (target.equals("date")) { //$NON-NLS-1$
+ modified = convertToDate(function);
+ } else if (target.equals("time")) { //$NON-NLS-1$
+ modified = convertToTime(function);
+ } else if (target.equals("timestamp")) { //$NON-NLS-1$
+ modified = convertToTimestamp(function);
+ } else if (target.equals("char")) { //$NON-NLS-1$
+ modified = convertToChar(function);
+ } else if (target.equals("boolean")) { //$NON-NLS-1$
+ modified = convertToBoolean(function);
+ } else if (target.equals("byte")) { //$NON-NLS-1$
+ modified = convertToByte(function);
+ } else {
+ modified = DROP_MODIFIER.modify(function);
+ }
+ return modified;
+
+ }
+ return DROP_MODIFIER.modify(function);
+ }
+
+ /*
+ * @see com.metamatrix.connector.jdbc.extension.FunctionModifier#translate(com.metamatrix.data.language.IFunction)
+ */
+ public List translate(IFunction function) {
+ List parts = new ArrayList();
+ parts.add("convert("); //$NON-NLS-1$
+
+ List<IExpression> args = function.getParameters();
+
+ if(args != null && args.size() > 0) {
+ ILiteral type = (ILiteral) args.get(0);
+ String typeStr = type.getValue().toString();
+
+ parts.add(typeStr);
+
+ for(int i=1; i<args.size(); i++) {
+ parts.add(", "); //$NON-NLS-1$
+ parts.add(args.get(i));
+ }
+ }
+ parts.add(")"); //$NON-NLS-1$
+ return parts;
+ }
+
+ private IExpression convertToBoolean(IFunction function) {
+ IExpression convert = null;
+ List<IExpression> args = function.getParameters();
+ Class src = args.get(0).getType();
+ int srcCode = getSrcCode(src);
+
+ switch(srcCode) {
+ case STRING:
+ //TODO: how to map the 'true' to '1' before it is translated to bit
+ case BYTE:
+ case SHORT:
+ case INTEGER:
+ case LONG:
+ case BIGINTEGER:
+ case FLOAT:
+ case DOUBLE:
+ case BIGDECIMAL:
+ convert = createFunction(args.get(0), "bit", Boolean.class); //$NON-NLS-1$
+ break;
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToByte(IFunction function) {
+ IExpression convert = null;
+ List<IExpression> args = function.getParameters();
+ Class src = args.get(0).getType();
+ int srcCode = getSrcCode(src);
+
+ switch(srcCode) {
+ case STRING:
+ case BOOLEAN:
+ case SHORT:
+ case INTEGER:
+ case LONG:
+ case BIGINTEGER:
+ case FLOAT:
+ case DOUBLE:
+ case BIGDECIMAL:
+ convert = createFunction(args.get(0), "tinyint", String.class); //$NON-NLS-1$
+ break;
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToString(IFunction function) {
+ IExpression convert = null;
+ List<IExpression> args = function.getParameters();
+ Class src = args.get(0).getType();
+ int srcCode = getSrcCode(src);
+
+ switch(srcCode) {
+ case CHAR:
+ case BOOLEAN:
+ case BYTE:
+ case SHORT:
+ case INTEGER:
+ case LONG:
+ case BIGINTEGER:
+ case FLOAT:
+ case DOUBLE:
+ case BIGDECIMAL:
+ convert = createFunction(args.get(0), "varchar", String.class); //$NON-NLS-1$
+ break;
+ case DATE: // convert(date, string) --> convert(varchar, date, 112)
+ //TODO: what is the best format 111/110/101?
+ convert = createFunction(args.get(0), 101, String.class);
+ break;
+ case TIME: // convert(time, string) --> convert(varchar, time, 108)
+ convert = createFunction(args.get(0), 108, String.class);
+ break;
+ case TIMESTAMP: // convert(time, string) --> convert(varchar, timestamp, 109)
+ convert = createFunction(args.get(0), 109, String.class);
+ break;
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToShort(IFunction function) {
+ IExpression convert = null;
+ List<IExpression> args = function.getParameters();
+ Class src = args.get(0).getType();
+ int srcCode = getSrcCode(src);
+
+ switch(srcCode) {
+ case STRING:
+ case BOOLEAN:
+ case BYTE:
+ case INTEGER:
+ case LONG:
+ case BIGINTEGER:
+ case FLOAT:
+ case DOUBLE:
+ case BIGDECIMAL:
+ convert = createFunction(args.get(0), "smallint", Short.class); //$NON-NLS-1$
+ break;
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToInteger(IFunction function) {
+ IExpression convert = null;
+ List<IExpression> args = function.getParameters();
+ Class src = args.get(0).getType();
+ int srcCode = getSrcCode(src);
+
+ switch(srcCode) {
+ case STRING:
+ case BOOLEAN:
+ case BYTE:
+ case SHORT:
+ case LONG:
+ case BIGINTEGER:
+ case FLOAT:
+ case DOUBLE:
+ case BIGDECIMAL:
+ convert = createFunction(args.get(0), "int", Integer.class); //$NON-NLS-1$
+ break;
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToLong(IFunction function) {
+ IExpression convert = null;
+ List<IExpression> args = function.getParameters();
+ Class src = args.get(0).getType();
+ int srcCode = getSrcCode(src);
+
+ switch(srcCode) {
+ case STRING:
+ case BOOLEAN:
+ case BYTE:
+ case SHORT:
+ case INTEGER:
+ case BIGINTEGER:
+ case FLOAT:
+ case DOUBLE:
+ case BIGDECIMAL:
+ convert = createFunction(args.get(0), "numeric", Long.class); //$NON-NLS-1$
+ break;
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToBigInteger(IFunction function) {
+ IExpression convert = null;
+ List<IExpression> args = function.getParameters();
+ Class src = args.get(0).getType();
+ int srcCode = getSrcCode(src);
+
+ switch(srcCode) {
+ case STRING:
+ case BOOLEAN:
+ case BYTE:
+ case SHORT:
+ case INTEGER:
+ case LONG:
+ case FLOAT:
+ case DOUBLE:
+ case BIGDECIMAL:
+ convert = createFunction(args.get(0), "numeric", java.math.BigInteger.class); //$NON-NLS-1$
+ break;
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToFloat(IFunction function) {
+ IExpression convert = null;
+ List<IExpression> args = function.getParameters();
+ Class src = args.get(0).getType();
+ int srcCode = getSrcCode(src);
+
+ switch(srcCode) {
+ case STRING:
+ case BOOLEAN:
+ case BYTE:
+ case SHORT:
+ case INTEGER:
+ case LONG:
+ case BIGINTEGER:
+ case DOUBLE:
+ case BIGDECIMAL:
+ convert = createFunction(args.get(0), "real", Float.class); //$NON-NLS-1$
+ break;
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToDouble(IFunction function) {
+ IExpression convert = null;
+ List<IExpression> args = function.getParameters();
+ Class src = args.get(0).getType();
+ int srcCode = getSrcCode(src);
+
+ switch(srcCode) {
+ case STRING:
+ case BOOLEAN:
+ case BYTE:
+ case SHORT:
+ case INTEGER:
+ case LONG:
+ case BIGINTEGER:
+ case FLOAT:
+ case BIGDECIMAL:
+ convert = createFunction(args.get(0), "float", Double.class); //$NON-NLS-1$
+ break;
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToBigDecimal(IFunction function) {
+ IExpression convert = null;
+ List<IExpression> args = function.getParameters();
+ Class src = args.get(0).getType();
+ int srcCode = getSrcCode(src);
+
+ switch(srcCode) {
+ case STRING:
+ case BOOLEAN:
+ case BYTE:
+ case SHORT:
+ case INTEGER:
+ case LONG:
+ case BIGINTEGER:
+ case FLOAT:
+ case DOUBLE:
+ convert = createFunction(args.get(0), "float", java.math.BigDecimal.class); //$NON-NLS-1$
+ break;
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToChar(IFunction function) {
+ List<IExpression> args = function.getParameters();
+ return createFunction(args.get(0), "char", Character.class); //$NON-NLS-1$
+ }
+
+ private IExpression convertToDate(IFunction function) {
+ IExpression convert = null;
+ List<IExpression> args = function.getParameters();
+ Class srcType = args.get(0).getType();
+ int srcCode = getSrcCode(srcType);
+
+ switch(srcCode) {
+ case STRING:
+ // convert(STRING, date) --> convert(datetime, STRING)
+ convert = createFunction(args.get(0), "datetime", java.sql.Date.class); //$NON-NLS-1$
+ break;
+ case TIMESTAMP:
+ // convert(TIMESTAMP, date) --> convert(datetime, convert(varchar, TIMESTAMP, 1/101))
+ // Build inner convert
+ IFunction innerConvert = langFactory.createFunction("convert", //$NON-NLS-1$
+ Arrays.asList(
+ langFactory.createLiteral("varchar", String.class), //$NON-NLS-1$
+ args.get(0),
+ langFactory.createLiteral(new Integer(109), Integer.class) ),
+ String.class);
+
+ // Build outer convert
+ convert = langFactory.createFunction("convert", //$NON-NLS-1$
+ Arrays.asList(
+ langFactory.createLiteral("datetime", String.class), //$NON-NLS-1$
+ innerConvert ),
+ java.sql.Timestamp.class);
+
+ break;
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToTime(IFunction function) {
+ IExpression convert = null;
+ List<IExpression> args = function.getParameters();
+ Class srcType = args.get(0).getType();
+
+ int srcCode = getSrcCode(srcType);
+ switch(srcCode) {
+ case STRING:
+ //convert(STRING, time) --> convert(datetime, STRING)
+ convert = createFunction(args.get(0), "datetime", java.sql.Time.class); //$NON-NLS-1$
+ break;
+ case TIMESTAMP:
+ // convert(TIMESTAMP, time) --> convert(datetime, convert(varchar, TIMESTAMP, 108/8)
+ // Build inner convert
+ IFunction innerConvert = langFactory.createFunction("convert", //$NON-NLS-1$
+ Arrays.asList(
+ langFactory.createLiteral("varchar", String.class), //$NON-NLS-1$
+ args.get(0),
+ langFactory.createLiteral(new Integer(108), Integer.class) ),
+ String.class);
+
+ // Build outer convert
+ convert = langFactory.createFunction("convert", //$NON-NLS-1$
+ Arrays.asList(
+ langFactory.createLiteral("datetime", String.class), //$NON-NLS-1$
+ innerConvert ),
+ java.sql.Time.class);
+
+ break;
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IExpression convertToTimestamp(IFunction function) {
+ IExpression convert = null;
+ List<IExpression> args = function.getParameters();
+ Class srcType = args.get(0).getType();
+ int srcCode = getSrcCode(srcType);
+ switch(srcCode) {
+ case STRING:
+ case TIME:
+ case DATE:
+ // convert(DATE/TIME/STRING, timestamp) --> convert(datetime, DATE)
+ convert = createFunction(args.get(0), "datetime", java.sql.Timestamp.class); //$NON-NLS-1$
+ break;
+ default:
+ convert = DROP_MODIFIER.modify(function);
+ break;
+ }
+
+ return convert;
+ }
+
+ private IFunction createFunction(IExpression args0, String targetType, Class targetClass) {
+ IFunction created = langFactory.createFunction("convert", //$NON-NLS-1$
+ Arrays.asList(
+ langFactory.createLiteral(targetType, String.class),
+ args0),
+ targetClass);
+ return created;
+ }
+
+ private IFunction createFunction(IExpression args0, int formatNumber, Class targetClass) {
+ IFunction created = langFactory.createFunction("convert", //$NON-NLS-1$
+ Arrays.asList( langFactory.createLiteral("varchar", String.class), //$NON-NLS-1$
+ args0,
+ langFactory.createLiteral(new Integer(formatNumber), Integer.class) ),
+ targetClass);
+ return created;
+ }
+
+ private int getSrcCode(Class source) {
+ return ((Integer) typeMap.get(source)).intValue();
+ }
+
+}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseSQLTranslator.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseSQLTranslator.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -22,14 +22,15 @@
/*
*/
-package com.metamatrix.connector.jdbc.sybase;
+package org.teiid.connector.jdbc.sybase;
+import org.teiid.connector.jdbc.translator.AliasModifier;
+import org.teiid.connector.jdbc.translator.SubstringFunctionModifier;
+import org.teiid.connector.jdbc.translator.Translator;
+
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.SourceSystemFunctions;
-import com.metamatrix.connector.jdbc.translator.AliasModifier;
-import com.metamatrix.connector.jdbc.translator.SubstringFunctionModifier;
-import com.metamatrix.connector.jdbc.translator.Translator;
import com.metamatrix.connector.language.ILimit;
/**
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/teradata (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/teradata)
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/teradata
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/teradata/TeradataCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/teradata/TeradataCapabilities.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/teradata/TeradataCapabilities.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,14 +20,15 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.teradata;
+package org.teiid.connector.jdbc.teradata;
import java.util.ArrayList;
import java.util.List;
-import com.metamatrix.connector.jdbc.JDBCCapabilities;
+import org.teiid.connector.jdbc.JDBCCapabilities;
+
/**
* for Teradata database Release V2R5.1
*/
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/translator)
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/AliasModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/translator/AliasModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/AliasModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -22,7 +22,7 @@
/*
*/
-package com.metamatrix.connector.jdbc.translator;
+package org.teiid.connector.jdbc.translator;
import com.metamatrix.connector.language.*;
@@ -41,7 +41,7 @@
}
/**
- * @see com.metamatrix.connector.jdbc.translator.FunctionModifier#modify(com.metamatrix.connector.language.IFunction)
+ * @see org.teiid.connector.jdbc.translator.FunctionModifier#modify(com.metamatrix.connector.language.IFunction)
*/
public IExpression modify(IFunction function) {
function.setName(alias);
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/BasicFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/translator/BasicFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/BasicFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,116 +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 com.metamatrix.connector.jdbc.translator;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.HashMap;
-
-import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-
-/**
- */
-public abstract class BasicFunctionModifier implements FunctionModifier {
-
- /*
- * Public sharing part for the mapping between class and type in format of Map<class->Integer>.
- */
- public static final int STRING = 0;
- public static final int CHAR = 1;
- public static final int BOOLEAN = 2;
- public static final int BYTE = 3;
- public static final int SHORT = 4;
- public static final int INTEGER = 5;
- public static final int LONG = 6;
- public static final int BIGINTEGER = 7;
- public static final int FLOAT = 8;
- public static final int DOUBLE = 9;
- public static final int BIGDECIMAL = 10;
- public static final int DATE = 11;
- public static final int TIME = 12;
- public static final int TIMESTAMP = 13;
- public static final int OBJECT = 14;
- public static final int BLOB = 15;
- public static final int CLOB = 16;
- public static final int XML = 17;
-
- public static final Map typeMap = new HashMap();
-
- static {
- typeMap.put(TypeFacility.RUNTIME_TYPES.STRING, new Integer(STRING));
- typeMap.put(TypeFacility.RUNTIME_TYPES.CHAR, new Integer(CHAR));
- typeMap.put(TypeFacility.RUNTIME_TYPES.BOOLEAN, new Integer(BOOLEAN));
- typeMap.put(TypeFacility.RUNTIME_TYPES.BYTE, new Integer(BYTE));
- typeMap.put(TypeFacility.RUNTIME_TYPES.SHORT, new Integer(SHORT));
- typeMap.put(TypeFacility.RUNTIME_TYPES.INTEGER, new Integer(INTEGER));
- typeMap.put(TypeFacility.RUNTIME_TYPES.LONG, new Integer(LONG));
- typeMap.put(TypeFacility.RUNTIME_TYPES.BIG_INTEGER, new Integer(BIGINTEGER));
- typeMap.put(TypeFacility.RUNTIME_TYPES.FLOAT, new Integer(FLOAT));
- typeMap.put(TypeFacility.RUNTIME_TYPES.DOUBLE, new Integer(DOUBLE));
- typeMap.put(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL, new Integer(BIGDECIMAL));
- typeMap.put(TypeFacility.RUNTIME_TYPES.DATE, new Integer(DATE));
- typeMap.put(TypeFacility.RUNTIME_TYPES.TIME, new Integer(TIME));
- typeMap.put(TypeFacility.RUNTIME_TYPES.TIMESTAMP, new Integer(TIMESTAMP));
- typeMap.put(TypeFacility.RUNTIME_TYPES.OBJECT, new Integer(OBJECT));
- typeMap.put(TypeFacility.RUNTIME_TYPES.BLOB, new Integer(BLOB));
- typeMap.put(TypeFacility.RUNTIME_TYPES.CLOB, new Integer(CLOB));
- typeMap.put(TypeFacility.RUNTIME_TYPES.XML, new Integer(XML));
- }
-
- /**
- * Subclass should override this method as needed.
- * @see com.metamatrix.connector.jdbc.translator.FunctionModifier#modify(com.metamatrix.connector.language.IFunction)
- */
- public IExpression modify(IFunction function) {
- return function;
- }
-
- /**
- * Subclass should override this method as needed.
- * @see com.metamatrix.connector.jdbc.translator.FunctionModifier#translate(com.metamatrix.connector.language.IFunction)
- */
- public List translate(IFunction function) {
- List objs = new ArrayList();
- objs.add(function.getName());
- objs.add("("); //$NON-NLS-1$
- IExpression[] params = function.getParameters();
- if(params.length > 0) {
- objs.add(params[0]);
- if(params.length > 1) {
- for(int i=1; i<params.length; i++) {
- objs.add(", "); //$NON-NLS-1$
- objs.add(params[i]);
- }
- }
- }
- objs.add(")"); //$NON-NLS-1$
-
- return objs;
- }
-
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/BasicFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/translator/BasicFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/BasicFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/BasicFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+/*
+ */
+package org.teiid.connector.jdbc.translator;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+
+import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+
+/**
+ */
+public abstract class BasicFunctionModifier implements FunctionModifier {
+
+ /*
+ * Public sharing part for the mapping between class and type in format of Map<class->Integer>.
+ */
+ public static final int STRING = 0;
+ public static final int CHAR = 1;
+ public static final int BOOLEAN = 2;
+ public static final int BYTE = 3;
+ public static final int SHORT = 4;
+ public static final int INTEGER = 5;
+ public static final int LONG = 6;
+ public static final int BIGINTEGER = 7;
+ public static final int FLOAT = 8;
+ public static final int DOUBLE = 9;
+ public static final int BIGDECIMAL = 10;
+ public static final int DATE = 11;
+ public static final int TIME = 12;
+ public static final int TIMESTAMP = 13;
+ public static final int OBJECT = 14;
+ public static final int BLOB = 15;
+ public static final int CLOB = 16;
+ public static final int XML = 17;
+
+ public static final Map typeMap = new HashMap();
+
+ static {
+ typeMap.put(TypeFacility.RUNTIME_TYPES.STRING, new Integer(STRING));
+ typeMap.put(TypeFacility.RUNTIME_TYPES.CHAR, new Integer(CHAR));
+ typeMap.put(TypeFacility.RUNTIME_TYPES.BOOLEAN, new Integer(BOOLEAN));
+ typeMap.put(TypeFacility.RUNTIME_TYPES.BYTE, new Integer(BYTE));
+ typeMap.put(TypeFacility.RUNTIME_TYPES.SHORT, new Integer(SHORT));
+ typeMap.put(TypeFacility.RUNTIME_TYPES.INTEGER, new Integer(INTEGER));
+ typeMap.put(TypeFacility.RUNTIME_TYPES.LONG, new Integer(LONG));
+ typeMap.put(TypeFacility.RUNTIME_TYPES.BIG_INTEGER, new Integer(BIGINTEGER));
+ typeMap.put(TypeFacility.RUNTIME_TYPES.FLOAT, new Integer(FLOAT));
+ typeMap.put(TypeFacility.RUNTIME_TYPES.DOUBLE, new Integer(DOUBLE));
+ typeMap.put(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL, new Integer(BIGDECIMAL));
+ typeMap.put(TypeFacility.RUNTIME_TYPES.DATE, new Integer(DATE));
+ typeMap.put(TypeFacility.RUNTIME_TYPES.TIME, new Integer(TIME));
+ typeMap.put(TypeFacility.RUNTIME_TYPES.TIMESTAMP, new Integer(TIMESTAMP));
+ typeMap.put(TypeFacility.RUNTIME_TYPES.OBJECT, new Integer(OBJECT));
+ typeMap.put(TypeFacility.RUNTIME_TYPES.BLOB, new Integer(BLOB));
+ typeMap.put(TypeFacility.RUNTIME_TYPES.CLOB, new Integer(CLOB));
+ typeMap.put(TypeFacility.RUNTIME_TYPES.XML, new Integer(XML));
+ }
+
+ /**
+ * Subclass should override this method as needed.
+ * @see org.teiid.connector.jdbc.translator.FunctionModifier#modify(com.metamatrix.connector.language.IFunction)
+ */
+ public IExpression modify(IFunction function) {
+ return function;
+ }
+
+ /**
+ * Subclass should override this method as needed.
+ * @see org.teiid.connector.jdbc.translator.FunctionModifier#translate(com.metamatrix.connector.language.IFunction)
+ */
+ public List translate(IFunction function) {
+ List objs = new ArrayList();
+ objs.add(function.getName());
+ objs.add("("); //$NON-NLS-1$
+ List<IExpression> params = function.getParameters();
+ if(params.size() > 0) {
+ objs.add(params.get(0));
+ if(params.size() > 1) {
+ for(int i=1; i<params.size(); i++) {
+ objs.add(", "); //$NON-NLS-1$
+ objs.add(params.get(i));
+ }
+ }
+ }
+ objs.add(")"); //$NON-NLS-1$
+
+ return objs;
+ }
+
+}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/BindValueVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/translator/BindValueVisitor.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/BindValueVisitor.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.translator;
+package org.teiid.connector.jdbc.translator;
import com.metamatrix.connector.language.ICompareCriteria;
import com.metamatrix.connector.language.IExistsCriteria;
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/DropFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/translator/DropFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/DropFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,50 +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 com.metamatrix.connector.jdbc.translator;
-
-import com.metamatrix.connector.jdbc.JDBCPlugin;
-import com.metamatrix.connector.language.*;
-
-/**
- * This FunctionModifier will cause this function to be dropped by replacing the function
- * with (by default) the first argument of the function. Optionally, the replacement index
- * can be overridden. This modifier should only be used with functions having the
- * minimum or more number of arguments.
- */
-public class DropFunctionModifier extends BasicFunctionModifier implements FunctionModifier {
-
- private int replaceIndex = 0;
-
- public void setReplaceIndex(int index) {
- this.replaceIndex = index;
- }
-
- public IExpression modify(IFunction function) {
- IExpression[] args = function.getParameters();
- if(args.length <= replaceIndex) {
- throw new IllegalArgumentException(JDBCPlugin.Util.getString("DropFunctionModifier.DropFunctionModifier_can_only_be_used_on_functions_with___1") + function); //$NON-NLS-1$
- }
-
- return args[replaceIndex];
- }
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/DropFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/translator/DropFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/DropFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/DropFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.translator;
+
+import java.util.List;
+
+import org.teiid.connector.jdbc.JDBCPlugin;
+
+import com.metamatrix.connector.language.*;
+
+/**
+ * This FunctionModifier will cause this function to be dropped by replacing the function
+ * with (by default) the first argument of the function. Optionally, the replacement index
+ * can be overridden. This modifier should only be used with functions having the
+ * minimum or more number of arguments.
+ */
+public class DropFunctionModifier extends BasicFunctionModifier implements FunctionModifier {
+
+ private int replaceIndex = 0;
+
+ public void setReplaceIndex(int index) {
+ this.replaceIndex = index;
+ }
+
+ public IExpression modify(IFunction function) {
+ List<IExpression> args = function.getParameters();
+ if(args.size() <= replaceIndex) {
+ throw new IllegalArgumentException(JDBCPlugin.Util.getString("DropFunctionModifier.DropFunctionModifier_can_only_be_used_on_functions_with___1") + function); //$NON-NLS-1$
+ }
+
+ return args.get(replaceIndex);
+ }
+}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/EscapeSyntaxModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/translator/EscapeSyntaxModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/EscapeSyntaxModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.translator;
+package org.teiid.connector.jdbc.translator;
import java.util.ArrayList;
import java.util.List;
@@ -39,7 +39,7 @@
}
/**
- * @see com.metamatrix.connector.jdbc.translator.BasicFunctionModifier#translate(com.metamatrix.connector.language.IFunction)
+ * @see org.teiid.connector.jdbc.translator.BasicFunctionModifier#translate(com.metamatrix.connector.language.IFunction)
* @since 5.0
*/
public List translate(IFunction function) {
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/FunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/translator/FunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/FunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -22,7 +22,7 @@
/*
*/
-package com.metamatrix.connector.jdbc.translator;
+package org.teiid.connector.jdbc.translator;
import java.util.List;
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/FunctionReplacementVisitor.java (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/util/FunctionReplacementVisitor.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/FunctionReplacementVisitor.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/FunctionReplacementVisitor.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,204 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.translator;
+
+import java.util.List;
+import java.util.Map;
+
+
+import com.metamatrix.connector.language.IAggregate;
+import com.metamatrix.connector.language.ICompareCriteria;
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.IGroupBy;
+import com.metamatrix.connector.language.IInCriteria;
+import com.metamatrix.connector.language.IInlineView;
+import com.metamatrix.connector.language.IInsert;
+import com.metamatrix.connector.language.IIsNullCriteria;
+import com.metamatrix.connector.language.ILikeCriteria;
+import com.metamatrix.connector.language.ISearchedCaseExpression;
+import com.metamatrix.connector.language.ISelectSymbol;
+import com.metamatrix.connector.language.ISubqueryCompareCriteria;
+import com.metamatrix.connector.language.ISubqueryInCriteria;
+import com.metamatrix.connector.visitor.framework.HierarchyVisitor;
+
+/**
+ */
+public class FunctionReplacementVisitor extends HierarchyVisitor {
+
+ private Map functionModifiers;
+
+ /**
+ * Set the functon modifiers.
+ * @param Map of function names to function modifiers.
+ */
+ public FunctionReplacementVisitor(Map functionModifiers){
+ super();
+ this.functionModifiers = functionModifiers;
+ }
+
+ /*
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.IAggregate)
+ */
+ public void visit(IAggregate obj) {
+ super.visit(obj);
+ obj.setExpression(replaceFunction(obj.getExpression()));
+ }
+
+ public void visit(IInlineView obj) {
+ visitNode(obj.getQuery());
+ }
+
+ /*
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ICompareCriteria)
+ */
+ public void visit(ICompareCriteria obj) {
+ super.visit(obj);
+ obj.setLeftExpression(replaceFunction(obj.getLeftExpression()));
+ obj.setRightExpression(replaceFunction(obj.getRightExpression()));
+ }
+
+ /**
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.connector.language.IFunction)
+ */
+ public void visit(IFunction obj) {
+ super.visit(obj);
+ List<IExpression> args = obj.getParameters();
+ for(int i=0; i<args.size(); i++) {
+ args.set(i, replaceFunction(args.get(i)));
+ }
+ }
+
+ /**
+ * @see com.metamatrix.connector.visitor.framework.HierarchyVisitor#visit(com.metamatrix.connector.language.IGroupBy)
+ * @since 4.3
+ */
+ public void visit(IGroupBy obj) {
+ super.visit(obj);
+ List<IExpression> expressions = obj.getElements();
+
+ for (int i=0; i<expressions.size(); i++) {
+ IExpression expression = (IExpression)expressions.get(i);
+ expressions.set(i, replaceFunction(expression));
+ }
+ }
+
+ /*
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.IInCriteria)
+ */
+ public void visit(IInCriteria obj) {
+ super.visit(obj);
+ obj.setLeftExpression(replaceFunction(obj.getLeftExpression()));
+ List<IExpression> rightExprs = obj.getRightExpressions();
+
+ for(int i=0; i<rightExprs.size(); i++) {
+ IExpression expr = (IExpression) rightExprs.get(i);
+ rightExprs.set(i, replaceFunction(expr));
+ }
+ }
+
+ /**
+ * @see com.metamatrix.data.visitor.SQLStringVisitor#visit(com.metamatrix.connector.language.IInsert)
+ */
+ public void visit(IInsert obj) {
+ super.visit(obj);
+ List<IExpression> values = obj.getValues();
+
+ for(int i=0; i<values.size(); i++) {
+ IExpression expr = (IExpression) values.get(i);
+ values.set(i, replaceFunction(expr));
+ }
+ }
+
+ /*
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.IIsNullCriteria)
+ */
+ public void visit(IIsNullCriteria obj) {
+ super.visit(obj);
+ obj.setExpression(replaceFunction(obj.getExpression()));
+ }
+
+ /*
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ILikeCriteria)
+ */
+ public void visit(ILikeCriteria obj) {
+ super.visit(obj);
+ obj.setLeftExpression(replaceFunction(obj.getLeftExpression()));
+ obj.setRightExpression(replaceFunction(obj.getRightExpression()));
+ }
+
+ /*
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ISearchedCaseExpression)
+ */
+ public void visit(ISearchedCaseExpression obj) {
+ super.visit(obj);
+ int whenCount = obj.getWhenCount();
+ for(int i=0; i<whenCount; i++) {
+ obj.setThenExpression(i, replaceFunction(obj.getThenExpression(i)));
+ }
+ obj.setElseExpression(replaceFunction(obj.getElseExpression()));
+ }
+
+ /*
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ISelectSymbol)
+ */
+ public void visit(ISelectSymbol obj) {
+ super.visit(obj);
+ obj.setExpression(replaceFunction(obj.getExpression()));
+ }
+
+ /*
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ISubqueryCompareCriteria)
+ */
+ public void visit(ISubqueryCompareCriteria obj) {
+ super.visit(obj);
+ obj.setLeftExpression(replaceFunction(obj.getLeftExpression()));
+ }
+
+ /*
+ * @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ISubqueryInCriteria)
+ */
+ public void visit(ISubqueryInCriteria obj) {
+ super.visit(obj);
+ obj.setLeftExpression(replaceFunction(obj.getLeftExpression()));
+ }
+
+ private IExpression replaceFunction(IExpression expression) {
+ if(functionModifiers != null && expression != null && expression instanceof IFunction){
+ // Look for function modifier
+ IFunction function = (IFunction) expression;
+ String key = function.getName().toLowerCase();
+ if(functionModifiers.containsKey(key)) {
+ FunctionModifier modifier = (FunctionModifier) functionModifiers.get(key);
+
+ // Modify function and return it
+ return modifier.modify(function);
+ }
+ }
+
+ // Fall through and return original expression
+ return expression;
+ }
+
+
+}
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/FunctionReplacementVisitor.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/translator/SQLConversionVisitor.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,340 +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 com.metamatrix.connector.jdbc.translator;
-
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import com.metamatrix.connector.api.ExecutionContext;
-import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.language.IBulkInsert;
-import com.metamatrix.connector.language.ICommand;
-import com.metamatrix.connector.language.IElement;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageObject;
-import com.metamatrix.connector.language.ILimit;
-import com.metamatrix.connector.language.ILiteral;
-import com.metamatrix.connector.language.IParameter;
-import com.metamatrix.connector.language.IProcedure;
-import com.metamatrix.connector.language.IQuery;
-import com.metamatrix.connector.language.IQueryCommand;
-import com.metamatrix.connector.language.ISetQuery;
-import com.metamatrix.connector.language.IParameter.Direction;
-import com.metamatrix.connector.language.ISetQuery.Operation;
-import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
-import com.metamatrix.connector.visitor.util.SQLStringVisitor;
-
-/**
- * This visitor takes an ICommand and does DBMS-specific conversion on it
- * to produce a SQL String. This class is expected to be subclassed.
- * Specialized instances of this class can be gotten from a SQL Translator
- * {@link Translator#getTranslationVisitor(RuntimeMetadata) using this method}.
- */
-public class SQLConversionVisitor extends SQLStringVisitor{
-
- private static DecimalFormat DECIMAL_FORMAT =
- new DecimalFormat("#############################0.0#############################"); //$NON-NLS-1$
- private static double SCIENTIC_LOW = Math.pow(10, -3);
- private static double SCIENTIC_HIGH = Math.pow(10, 7);
-
- private Map<String, FunctionModifier> modifiers;
- private ExecutionContext context;
- private Translator translator;
-
- private boolean prepared;
-
- private List preparedValues = new ArrayList();
- private List preparedTypes = new ArrayList();
-
- public SQLConversionVisitor(Translator translator) {
- this.translator = translator;
- this.prepared = translator.usePreparedStatements();
- this.modifiers = translator.getFunctionModifiers();
- }
-
- public void visit(IBulkInsert obj) {
- this.prepared = true;
-
- super.visit(obj);
-
- for (int i = 0; i < obj.getElements().size(); i++) {
- IElement element = (IElement) obj.getElements().get(i);
- this.preparedTypes.add(element.getType());
- }
-
- this.preparedValues = obj.getRows();
- }
-
- /**
- * @param type
- * @param object
- * @param valuesbuffer
- */
- private void translateSQLType(Class type, Object obj, StringBuffer valuesbuffer) {
- if (obj == null) {
- valuesbuffer.append(NULL);
- } else {
- if(Number.class.isAssignableFrom(type)) {
- boolean useFormatting = false;
-
- if (Double.class.isAssignableFrom(type)){
- double value = ((Double)obj).doubleValue();
- useFormatting = (value <= SCIENTIC_LOW || value >= SCIENTIC_HIGH);
- }
- else if (Float.class.isAssignableFrom(type)){
- float value = ((Float)obj).floatValue();
- useFormatting = (value <= SCIENTIC_LOW || value >= SCIENTIC_HIGH);
- }
- // The formatting is to avoid the so-called "scientic-notation"
- // where toString will use for numbers greater than 10p7 and
- // less than 10p-3, where database may not understand.
- if (useFormatting) {
- synchronized (DECIMAL_FORMAT) {
- valuesbuffer.append(DECIMAL_FORMAT.format(obj));
- }
- }
- else {
- valuesbuffer.append(obj);
- }
- } else if(type.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN)) {
- valuesbuffer.append(translator.translateLiteralBoolean((Boolean)obj));
- } else if(type.equals(TypeFacility.RUNTIME_TYPES.TIMESTAMP)) {
- valuesbuffer.append(translator.translateLiteralTimestamp((Timestamp)obj));
- } else if(type.equals(TypeFacility.RUNTIME_TYPES.TIME)) {
- valuesbuffer.append(translator.translateLiteralTime((Time)obj));
- } else if(type.equals(TypeFacility.RUNTIME_TYPES.DATE)) {
- valuesbuffer.append(translator.translateLiteralDate((java.sql.Date)obj));
- } else {
- // If obj is string, toSting() will not create a new String
- // object, it returns it self, so new object creation.
- valuesbuffer.append("'") //$NON-NLS-1$
- .append(escapeString(obj.toString()))
- .append("'"); //$NON-NLS-1$
- }
- }
- }
-
- /**
- * @see com.metamatrix.connector.visitor.util.SQLStringVisitor#visit(com.metamatrix.connector.language.IProcedure)
- */
- public void visit(IProcedure obj) {
- this.prepared = true;
- /*
- * preparedValues is now a list of procedure params instead of just values
- */
- this.preparedValues = obj.getParameters();
- super.buffer.append(generateSqlForStoredProcedure(obj));
- }
-
- /**
- * @see com.metamatrix.connector.visitor.util.SQLStringVisitor#visit(com.metamatrix.connector.language.IFunction)
- */
- public void visit(IFunction obj) {
- if(this.modifiers != null) {
- FunctionModifier functionModifier = (FunctionModifier)this.modifiers.get(obj.getName().toLowerCase());
- if(functionModifier != null) {
- List parts = functionModifier.translate(obj);
-
- // null means the FunctionModifier will rely on default translation
- if (parts != null) {
- Iterator iter = parts.iterator();
- while(iter.hasNext()) {
- Object part = iter.next();
- if(part instanceof String) {
- buffer.append(part);
- } else {
- append((ILanguageObject)part);
- }
- }
- return;
- }
- }
- }
- super.visit(obj);
- }
-
- /**
- * @see com.metamatrix.connector.visitor.util.SQLStringVisitor#visit(com.metamatrix.connector.language.ILiteral)
- */
- public void visit(ILiteral obj) {
- if (this.prepared && obj.isBindValue()) {
- buffer.append(UNDEFINED_PARAM);
- preparedValues.add(obj.getValue());
- preparedTypes.add(obj.getType());
- } else {
- translateSQLType(obj.getType(), obj.getValue(), buffer);
- }
- }
-
- /**
- * Set the per-command execution context on this visitor.
- * @param context ExecutionContext
- * @since 4.3
- */
- public void setExecutionContext(ExecutionContext context) {
- this.context = context;
- }
-
- /**
- * Retrieve the per-command execution context for this visitor
- * (intended for subclasses to use).
- * @return
- * @since 4.3
- */
- protected ExecutionContext getExecutionContext() {
- return this.context;
- }
-
- protected String getSourceComment(ICommand command) {
- return this.translator.getSourceComment(this.context, command);
- }
-
- /**
- * This is a generic implementation. Subclass should override this method
- * if necessary.
- * @param exec The command for the stored procedure.
- * @return String to be executed by CallableStatement.
- */
- protected String generateSqlForStoredProcedure(IProcedure exec) {
- StringBuffer prepareCallBuffer = new StringBuffer();
- prepareCallBuffer.append("{ "); //$NON-NLS-1$
-
- List params = exec.getParameters();
-
- //check whether a "?" is needed if there are returns
- boolean needQuestionMark = false;
- Iterator iter = params.iterator();
- while(iter.hasNext()){
- IParameter param = (IParameter)iter.next();
- if(param.getDirection() == Direction.RETURN){
- needQuestionMark = true;
- break;
- }
- }
-
- prepareCallBuffer.append(getSourceComment(exec));
-
- if(needQuestionMark){
- prepareCallBuffer.append("?="); //$NON-NLS-1$
- }
-
- prepareCallBuffer.append(" call ");//$NON-NLS-1$
- prepareCallBuffer.append(exec.getMetadataID() != null ? getName(exec.getMetadataID()) : exec.getProcedureName());
- prepareCallBuffer.append("("); //$NON-NLS-1$
-
- int numberOfParameters = 0;
- iter = params.iterator();
- while(iter.hasNext()){
- IParameter param = (IParameter)iter.next();
- if(param.getDirection() == Direction.IN || param.getDirection() == Direction.OUT || param.getDirection() == Direction.INOUT){
- if(numberOfParameters > 0){
- prepareCallBuffer.append(","); //$NON-NLS-1$
- }
- prepareCallBuffer.append("?"); //$NON-NLS-1$
- numberOfParameters++;
- }
- }
- prepareCallBuffer.append(")"); //$NON-NLS-1$
- prepareCallBuffer.append("}"); //$NON-NLS-1$
- return prepareCallBuffer.toString();
- }
-
- /**
- * @return the preparedValues
- */
- List getPreparedValues() {
- return this.preparedValues;
- }
-
- /**
- * @return the preparedValues
- */
- List getPreparedTypes() {
- return this.preparedTypes;
- }
-
- public boolean isPrepared() {
- return prepared;
- }
-
- public void setPrepared(boolean prepared) {
- this.prepared = prepared;
- }
-
- @Override
- protected boolean useAsInGroupAlias() {
- return this.translator.useAsInGroupAlias();
- }
-
- @Override
- public void visit(IQuery obj) {
- if (obj.getLimit() != null) {
- handleLimit(obj);
- } else {
- super.visit(obj);
- }
- }
-
- @Override
- public void visit(ISetQuery obj) {
- if (obj.getLimit() != null) {
- handleLimit(obj);
- } else {
- super.visit(obj);
- }
- }
-
- @Override
- protected boolean useParensForSetQueries() {
- return translator.useParensForSetQueries();
- }
-
- private void handleLimit(IQueryCommand obj) {
- ILimit limit = obj.getLimit();
- obj.setLimit(null);
- StringBuffer current = this.buffer;
- this.buffer = new StringBuffer();
- append(obj);
- current.append(this.translator.addLimitString(this.buffer.toString(), limit));
- this.buffer = current;
- obj.setLimit(limit);
- }
-
- @Override
- protected String replaceElementName(String group, String element) {
- return translator.replaceElementName(group, element);
- }
-
- @Override
- protected void appendSetOperation(Operation operation) {
- buffer.append(translator.getSetOperationString(operation));
- }
-
-}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/translator/SQLConversionVisitor.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,340 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+/*
+ */
+package org.teiid.connector.jdbc.translator;
+
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import com.metamatrix.connector.api.ExecutionContext;
+import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.language.IBulkInsert;
+import com.metamatrix.connector.language.ICommand;
+import com.metamatrix.connector.language.IElement;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageObject;
+import com.metamatrix.connector.language.ILimit;
+import com.metamatrix.connector.language.ILiteral;
+import com.metamatrix.connector.language.IParameter;
+import com.metamatrix.connector.language.IProcedure;
+import com.metamatrix.connector.language.IQuery;
+import com.metamatrix.connector.language.IQueryCommand;
+import com.metamatrix.connector.language.ISetQuery;
+import com.metamatrix.connector.language.IParameter.Direction;
+import com.metamatrix.connector.language.ISetQuery.Operation;
+import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
+import com.metamatrix.connector.visitor.util.SQLStringVisitor;
+
+/**
+ * This visitor takes an ICommand and does DBMS-specific conversion on it
+ * to produce a SQL String. This class is expected to be subclassed.
+ * Specialized instances of this class can be gotten from a SQL Translator
+ * {@link Translator#getTranslationVisitor(RuntimeMetadata) using this method}.
+ */
+public class SQLConversionVisitor extends SQLStringVisitor{
+
+ private static DecimalFormat DECIMAL_FORMAT =
+ new DecimalFormat("#############################0.0#############################"); //$NON-NLS-1$
+ private static double SCIENTIC_LOW = Math.pow(10, -3);
+ private static double SCIENTIC_HIGH = Math.pow(10, 7);
+
+ private Map<String, FunctionModifier> modifiers;
+ private ExecutionContext context;
+ private Translator translator;
+
+ private boolean prepared;
+
+ private List preparedValues = new ArrayList();
+ private List preparedTypes = new ArrayList();
+
+ public SQLConversionVisitor(Translator translator) {
+ this.translator = translator;
+ this.prepared = translator.usePreparedStatements();
+ this.modifiers = translator.getFunctionModifiers();
+ }
+
+ public void visit(IBulkInsert obj) {
+ this.prepared = true;
+
+ super.visit(obj);
+
+ for (int i = 0; i < obj.getElements().size(); i++) {
+ IElement element = (IElement) obj.getElements().get(i);
+ this.preparedTypes.add(element.getType());
+ }
+
+ this.preparedValues = obj.getRows();
+ }
+
+ /**
+ * @param type
+ * @param object
+ * @param valuesbuffer
+ */
+ private void translateSQLType(Class type, Object obj, StringBuffer valuesbuffer) {
+ if (obj == null) {
+ valuesbuffer.append(NULL);
+ } else {
+ if(Number.class.isAssignableFrom(type)) {
+ boolean useFormatting = false;
+
+ if (Double.class.isAssignableFrom(type)){
+ double value = ((Double)obj).doubleValue();
+ useFormatting = (value <= SCIENTIC_LOW || value >= SCIENTIC_HIGH);
+ }
+ else if (Float.class.isAssignableFrom(type)){
+ float value = ((Float)obj).floatValue();
+ useFormatting = (value <= SCIENTIC_LOW || value >= SCIENTIC_HIGH);
+ }
+ // The formatting is to avoid the so-called "scientic-notation"
+ // where toString will use for numbers greater than 10p7 and
+ // less than 10p-3, where database may not understand.
+ if (useFormatting) {
+ synchronized (DECIMAL_FORMAT) {
+ valuesbuffer.append(DECIMAL_FORMAT.format(obj));
+ }
+ }
+ else {
+ valuesbuffer.append(obj);
+ }
+ } else if(type.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN)) {
+ valuesbuffer.append(translator.translateLiteralBoolean((Boolean)obj));
+ } else if(type.equals(TypeFacility.RUNTIME_TYPES.TIMESTAMP)) {
+ valuesbuffer.append(translator.translateLiteralTimestamp((Timestamp)obj));
+ } else if(type.equals(TypeFacility.RUNTIME_TYPES.TIME)) {
+ valuesbuffer.append(translator.translateLiteralTime((Time)obj));
+ } else if(type.equals(TypeFacility.RUNTIME_TYPES.DATE)) {
+ valuesbuffer.append(translator.translateLiteralDate((java.sql.Date)obj));
+ } else {
+ // If obj is string, toSting() will not create a new String
+ // object, it returns it self, so new object creation.
+ valuesbuffer.append("'") //$NON-NLS-1$
+ .append(escapeString(obj.toString()))
+ .append("'"); //$NON-NLS-1$
+ }
+ }
+ }
+
+ /**
+ * @see com.metamatrix.connector.visitor.util.SQLStringVisitor#visit(com.metamatrix.connector.language.IProcedure)
+ */
+ public void visit(IProcedure obj) {
+ this.prepared = true;
+ /*
+ * preparedValues is now a list of procedure params instead of just values
+ */
+ this.preparedValues = obj.getParameters();
+ super.buffer.append(generateSqlForStoredProcedure(obj));
+ }
+
+ /**
+ * @see com.metamatrix.connector.visitor.util.SQLStringVisitor#visit(com.metamatrix.connector.language.IFunction)
+ */
+ public void visit(IFunction obj) {
+ if(this.modifiers != null) {
+ FunctionModifier functionModifier = (FunctionModifier)this.modifiers.get(obj.getName().toLowerCase());
+ if(functionModifier != null) {
+ List parts = functionModifier.translate(obj);
+
+ // null means the FunctionModifier will rely on default translation
+ if (parts != null) {
+ Iterator iter = parts.iterator();
+ while(iter.hasNext()) {
+ Object part = iter.next();
+ if(part instanceof String) {
+ buffer.append(part);
+ } else {
+ append((ILanguageObject)part);
+ }
+ }
+ return;
+ }
+ }
+ }
+ super.visit(obj);
+ }
+
+ /**
+ * @see com.metamatrix.connector.visitor.util.SQLStringVisitor#visit(com.metamatrix.connector.language.ILiteral)
+ */
+ public void visit(ILiteral obj) {
+ if (this.prepared && obj.isBindValue()) {
+ buffer.append(UNDEFINED_PARAM);
+ preparedValues.add(obj.getValue());
+ preparedTypes.add(obj.getType());
+ } else {
+ translateSQLType(obj.getType(), obj.getValue(), buffer);
+ }
+ }
+
+ /**
+ * Set the per-command execution context on this visitor.
+ * @param context ExecutionContext
+ * @since 4.3
+ */
+ public void setExecutionContext(ExecutionContext context) {
+ this.context = context;
+ }
+
+ /**
+ * Retrieve the per-command execution context for this visitor
+ * (intended for subclasses to use).
+ * @return
+ * @since 4.3
+ */
+ protected ExecutionContext getExecutionContext() {
+ return this.context;
+ }
+
+ protected String getSourceComment(ICommand command) {
+ return this.translator.getSourceComment(this.context, command);
+ }
+
+ /**
+ * This is a generic implementation. Subclass should override this method
+ * if necessary.
+ * @param exec The command for the stored procedure.
+ * @return String to be executed by CallableStatement.
+ */
+ protected String generateSqlForStoredProcedure(IProcedure exec) {
+ StringBuffer prepareCallBuffer = new StringBuffer();
+ prepareCallBuffer.append("{ "); //$NON-NLS-1$
+
+ List params = exec.getParameters();
+
+ //check whether a "?" is needed if there are returns
+ boolean needQuestionMark = false;
+ Iterator iter = params.iterator();
+ while(iter.hasNext()){
+ IParameter param = (IParameter)iter.next();
+ if(param.getDirection() == Direction.RETURN){
+ needQuestionMark = true;
+ break;
+ }
+ }
+
+ prepareCallBuffer.append(getSourceComment(exec));
+
+ if(needQuestionMark){
+ prepareCallBuffer.append("?="); //$NON-NLS-1$
+ }
+
+ prepareCallBuffer.append(" call ");//$NON-NLS-1$
+ prepareCallBuffer.append(exec.getMetadataObject() != null ? getName(exec.getMetadataObject()) : exec.getProcedureName());
+ prepareCallBuffer.append("("); //$NON-NLS-1$
+
+ int numberOfParameters = 0;
+ iter = params.iterator();
+ while(iter.hasNext()){
+ IParameter param = (IParameter)iter.next();
+ if(param.getDirection() == Direction.IN || param.getDirection() == Direction.OUT || param.getDirection() == Direction.INOUT){
+ if(numberOfParameters > 0){
+ prepareCallBuffer.append(","); //$NON-NLS-1$
+ }
+ prepareCallBuffer.append("?"); //$NON-NLS-1$
+ numberOfParameters++;
+ }
+ }
+ prepareCallBuffer.append(")"); //$NON-NLS-1$
+ prepareCallBuffer.append("}"); //$NON-NLS-1$
+ return prepareCallBuffer.toString();
+ }
+
+ /**
+ * @return the preparedValues
+ */
+ List getPreparedValues() {
+ return this.preparedValues;
+ }
+
+ /**
+ * @return the preparedValues
+ */
+ List getPreparedTypes() {
+ return this.preparedTypes;
+ }
+
+ public boolean isPrepared() {
+ return prepared;
+ }
+
+ public void setPrepared(boolean prepared) {
+ this.prepared = prepared;
+ }
+
+ @Override
+ protected boolean useAsInGroupAlias() {
+ return this.translator.useAsInGroupAlias();
+ }
+
+ @Override
+ public void visit(IQuery obj) {
+ if (obj.getLimit() != null) {
+ handleLimit(obj);
+ } else {
+ super.visit(obj);
+ }
+ }
+
+ @Override
+ public void visit(ISetQuery obj) {
+ if (obj.getLimit() != null) {
+ handleLimit(obj);
+ } else {
+ super.visit(obj);
+ }
+ }
+
+ @Override
+ protected boolean useParensForSetQueries() {
+ return translator.useParensForSetQueries();
+ }
+
+ private void handleLimit(IQueryCommand obj) {
+ ILimit limit = obj.getLimit();
+ obj.setLimit(null);
+ StringBuffer current = this.buffer;
+ this.buffer = new StringBuffer();
+ append(obj);
+ current.append(this.translator.addLimitString(this.buffer.toString(), limit));
+ this.buffer = current;
+ obj.setLimit(limit);
+ }
+
+ @Override
+ protected String replaceElementName(String group, String element) {
+ return translator.replaceElementName(group, element);
+ }
+
+ @Override
+ protected void appendSetOperation(Operation operation) {
+ buffer.append(translator.getSetOperationString(operation));
+ }
+
+}
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SubstringFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/translator/SubstringFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SubstringFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,63 +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 com.metamatrix.connector.jdbc.translator;
-
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageFactory;
-
-/**
- * Common logic for Substring modifiers requiring 3 parameters
- */
-public class SubstringFunctionModifier extends BasicFunctionModifier {
-
- private ILanguageFactory languageFactory;
- private String length_function;
-
- public SubstringFunctionModifier(ILanguageFactory languageFactory, String substring_function, String length_function) {
- this.languageFactory = languageFactory;
- this.length_function = length_function;
- }
-
- /**
- * @see com.metamatrix.connector.jdbc.translator.FunctionModifier#modify(com.metamatrix.query.sql.symbol.Function)
- */
- public IExpression modify(IFunction function) {
- IExpression[] args = function.getParameters();
- IExpression[] newArgs = new IExpression[3];
- function.setParameters(newArgs);
-
- newArgs[0] = args[0];
- newArgs[1] = args[1];
-
- if(args.length == 2) {
- newArgs[2] = languageFactory.createFunction(length_function, new IExpression[] { args[0] }, Integer.class);
- } else {
- newArgs[2] = args[2];
- }
-
- function.setParameters(newArgs);
-
- return function;
- }
-}
\ No newline at end of file
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SubstringFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/translator/SubstringFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SubstringFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SubstringFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.translator;
+
+import java.util.Arrays;
+import java.util.List;
+
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+
+/**
+ * Common logic for Substring modifiers requiring 3 parameters
+ */
+public class SubstringFunctionModifier extends BasicFunctionModifier {
+
+ private ILanguageFactory languageFactory;
+ private String length_function;
+
+ public SubstringFunctionModifier(ILanguageFactory languageFactory, String substring_function, String length_function) {
+ this.languageFactory = languageFactory;
+ this.length_function = length_function;
+ }
+
+ /**
+ * @see org.teiid.connector.jdbc.translator.FunctionModifier#modify(com.metamatrix.query.sql.symbol.Function)
+ */
+ public IExpression modify(IFunction function) {
+ List<IExpression> args = function.getParameters();
+
+ if(args.size() == 2) {
+ args.add(languageFactory.createFunction(length_function, Arrays.asList(args.get(0)), Integer.class));
+ }
+
+ return function;
+ }
+}
\ No newline at end of file
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/TranslatedCommand.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/translator/TranslatedCommand.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/TranslatedCommand.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -22,15 +22,15 @@
/*
*/
-package com.metamatrix.connector.jdbc.translator;
+package org.teiid.connector.jdbc.translator;
import java.util.List;
import java.util.Map;
+
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.ExecutionContext;
import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.jdbc.util.FunctionReplacementVisitor;
import com.metamatrix.connector.language.ICommand;
import com.metamatrix.connector.language.ILiteral;
import com.metamatrix.connector.visitor.util.CollectorVisitor;
@@ -61,7 +61,7 @@
this.sqlTranslator = sqlTranslator;
Map<String, FunctionModifier> modifiers = sqlTranslator.getFunctionModifiers();
- this.sqlConversionVisitor = new SQLConversionVisitor(sqlTranslator);
+ this.sqlConversionVisitor = sqlTranslator.getSQLConversionVisitor();
sqlConversionVisitor.setExecutionContext(context);
this.functionVisitor = new FunctionReplacementVisitor(modifiers);
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/translator/Translator.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.translator;
+package org.teiid.connector.jdbc.translator;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -41,6 +41,9 @@
import java.util.Map;
import java.util.TimeZone;
+import org.teiid.connector.jdbc.JDBCPlugin;
+import org.teiid.connector.jdbc.JDBCPropertyNames;
+
import com.metamatrix.common.util.PropertiesUtils;
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
@@ -48,8 +51,6 @@
import com.metamatrix.connector.api.TypeFacility;
import com.metamatrix.connector.api.ValueTranslator;
import com.metamatrix.connector.internal.ConnectorPropertyNames;
-import com.metamatrix.connector.jdbc.JDBCPlugin;
-import com.metamatrix.connector.jdbc.JDBCPropertyNames;
import com.metamatrix.connector.language.ICommand;
import com.metamatrix.connector.language.ILanguageFactory;
import com.metamatrix.connector.language.ILimit;
@@ -419,7 +420,7 @@
* values, so subclasses should override that method if necessery to change the binding
* behavior.
*
- * @see com.metamatrix.connector.jdbc.extension.ResultsTranslator#bindPreparedStatementValues(java.sql.Connection, java.sql.PreparedStatement, com.metamatrix.connector.jdbc.translator.TranslatedCommand)
+ * @see com.metamatrix.connector.jdbc.extension.ResultsTranslator#bindPreparedStatementValues(java.sql.Connection, java.sql.PreparedStatement, org.teiid.connector.jdbc.translator.TranslatedCommand)
*/
public void bindPreparedStatementValues(Connection conn, PreparedStatement stmt, TranslatedCommand command) throws SQLException {
List params = command.getPreparedValues();
@@ -710,5 +711,9 @@
public int getIsValidTimeout() {
return isValidTimeout;
}
+
+ public SQLConversionVisitor getSQLConversionVisitor() {
+ return new SQLConversionVisitor(this);
+ }
}
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/xa (from rev 486, trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/xa)
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/xa
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/xa/JDBCSourceXAConnection.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/xa/JDBCSourceXAConnection.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/xa/JDBCSourceXAConnection.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -22,7 +22,7 @@
/*
*/
-package com.metamatrix.connector.jdbc.xa;
+package org.teiid.connector.jdbc.xa;
import java.sql.Connection;
import java.sql.SQLException;
@@ -31,10 +31,11 @@
import javax.sql.ConnectionEventListener;
import javax.transaction.xa.XAResource;
+import org.teiid.connector.jdbc.JDBCSourceConnection;
+import org.teiid.connector.jdbc.translator.Translator;
+
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.jdbc.JDBCSourceConnection;
-import com.metamatrix.connector.jdbc.translator.Translator;
import com.metamatrix.connector.xa.api.XAConnection;
public class JDBCSourceXAConnection extends JDBCSourceConnection implements XAConnection {
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/xa/XAJDBCPropertyNames.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/xa/XAJDBCPropertyNames.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/xa/XAJDBCPropertyNames.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -24,7 +24,7 @@
* Date: Jan 23, 2003
* Time: 5:38:40 PM
*/
-package com.metamatrix.connector.jdbc.xa;
+package org.teiid.connector.jdbc.xa;
/**
* XAJDBCPropertyNames.
Copied: trunk/connectors/connector-jdbc/src/main/resources/org/teiid/connector/jdbc (from rev 486, trunk/connectors/connector-jdbc/src/main/resources/com/metamatrix/connector/jdbc)
Property changes on: trunk/connectors/connector-jdbc/src/main/resources/org/teiid/connector/jdbc
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/FakeConnection.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/FakeConnection.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/FakeConnection.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,55 +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 com.metamatrix.connector.jdbc;
-
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import com.metamatrix.core.util.SimpleMock;
-
-/**
- * FakeConnection for unit testing
- */
-public class FakeConnection {
-
- boolean closed;
- boolean fail;
-
- /* (non-Javadoc)
- * @see java.sql.Connection#createStatement()
- */
- public Statement createStatement() throws SQLException {
- if (fail) {
- throw new SQLException();
- }
- return SimpleMock.createSimpleMock(Statement.class);
- }
-
- /* (non-Javadoc)
- * @see java.sql.Connection#isClosed()
- */
- public boolean isClosed() {
- return closed;
- }
-
-}
Deleted: trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/MetadataFactory.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/MetadataFactory.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/MetadataFactory.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,48 +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 com.metamatrix.connector.jdbc;
-
-import junit.framework.Assert;
-
-import com.metamatrix.cdk.api.TranslationUtility;
-import com.metamatrix.cdk.unittest.FakeTranslationFactory;
-import com.metamatrix.connector.language.ICommand;
-
-public class MetadataFactory {
-
- public static final String PARTS_VDB = "/PartsSupplier.vdb"; //$NON-NLS-1$
- public static final String BQT_VDB = "/bqt.vdb"; //$NON-NLS-1$
-
- public static ICommand helpTranslate(String vdbFileName, String sql) {
- TranslationUtility util = null;
- if (PARTS_VDB.equals(vdbFileName)) {
- util = new TranslationUtility(MetadataFactory.class.getResource(vdbFileName));
- } else if (BQT_VDB.equals(vdbFileName)){
- util = FakeTranslationFactory.getInstance().getBQTTranslationUtility();
- } else {
- Assert.fail("unknown vdb"); //$NON-NLS-1$
- }
- return util.parseCommand(sql);
- }
-
-}
Deleted: trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/TestJDBCSourceConnection.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/TestJDBCSourceConnection.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/TestJDBCSourceConnection.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,115 +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 com.metamatrix.connector.jdbc;
-
-import java.sql.Connection;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.api.EnvironmentUtility;
-import com.metamatrix.connector.api.ConnectorEnvironment;
-import com.metamatrix.connector.basic.BasicConnectorCapabilities;
-import com.metamatrix.connector.jdbc.translator.Translator;
-import com.metamatrix.core.util.SimpleMock;
-
-
-/**
- * Test case for JDBCSourceConnection
- * @since 4.3
- */
-public class TestJDBCSourceConnection extends TestCase {
-
- private FakeConnection fakeConnection;
- private Connection connection;
- private ConnectorEnvironment environment;
-
-
- public TestJDBCSourceConnection(String name) {
- super(name);
- }
-
- public void setUp() throws Exception {
- fakeConnection = new FakeConnection();
- connection = SimpleMock.createSimpleMock(fakeConnection, Connection.class);
-
- final Properties properties = new Properties();
- properties.setProperty(JDBCPropertyNames.EXT_CAPABILITY_CLASS, BasicConnectorCapabilities.class.getName());
-
- environment = EnvironmentUtility.createEnvironment(properties, false);
- }
-
-
- /**
- * Tests JDBCSourceConnection.isConnectionAlive() with a ConnectionQueryStrategy
- * @since 4.3
- */
- public void testIsAlive() throws Exception {
- JDBCSourceConnection sourceConnection = new JDBCSourceConnection(connection, environment, new Translator() {
- @Override
- public String getConnectionTestQuery() {
- return "select 1";
- }
- });
-
- //closed connections should not be 'alive'
- fakeConnection.closed = true;
- assertFalse(sourceConnection.isAlive());
-
- //open connections should be 'alive'
- fakeConnection.closed = false;
- assertTrue(sourceConnection.isAlive());
-
- //failed connections should not be 'alive'
- fakeConnection.fail = true;
- assertFalse(sourceConnection.isAlive());
-
- }
-
- /**
- * Tests JDBCSourceConnection.isConnectionAlive() with a null ConnectionStrategy
- * @since 4.3
- */
- public void testIsAliveNullStrategy() throws Exception {
- JDBCSourceConnection sourceConnection = new JDBCSourceConnection(connection, environment, new Translator() {
- @Override
- public String getConnectionTestQuery() {
- return null;
- }
- });
-
- //closed connections should not be 'alive'
- fakeConnection.closed = true;
- assertFalse(sourceConnection.isAlive());
-
- //open connections should be 'alive'
- fakeConnection.closed = false;
- assertTrue(sourceConnection.isAlive());
-
- //without a strategy, failed connections are detected as 'alive'
- fakeConnection.fail = true;
- assertTrue(sourceConnection.isAlive());
-
- }
-
-}
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/FakeConnection.java (from rev 486, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/FakeConnection.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/FakeConnection.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/FakeConnection.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc;
+
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import com.metamatrix.core.util.SimpleMock;
+
+/**
+ * FakeConnection for unit testing
+ */
+public class FakeConnection {
+
+ boolean closed;
+ boolean fail;
+
+ /* (non-Javadoc)
+ * @see java.sql.Connection#createStatement()
+ */
+ public Statement createStatement() throws SQLException {
+ if (fail) {
+ throw new SQLException();
+ }
+ return SimpleMock.createSimpleMock(Statement.class);
+ }
+
+ /* (non-Javadoc)
+ * @see java.sql.Connection#isClosed()
+ */
+ public boolean isClosed() {
+ return closed;
+ }
+
+}
Property changes on: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/FakeConnection.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/MetadataFactory.java (from rev 486, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/MetadataFactory.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/MetadataFactory.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/MetadataFactory.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc;
+
+import junit.framework.Assert;
+
+import com.metamatrix.cdk.api.TranslationUtility;
+import com.metamatrix.cdk.unittest.FakeTranslationFactory;
+import com.metamatrix.connector.language.ICommand;
+
+public class MetadataFactory {
+
+ public static final String PARTS_VDB = "/PartsSupplier.vdb"; //$NON-NLS-1$
+ public static final String BQT_VDB = "/bqt.vdb"; //$NON-NLS-1$
+
+ public static ICommand helpTranslate(String vdbFileName, String sql) {
+ TranslationUtility util = null;
+ if (PARTS_VDB.equals(vdbFileName)) {
+ util = new TranslationUtility(MetadataFactory.class.getResource(vdbFileName));
+ } else if (BQT_VDB.equals(vdbFileName)){
+ util = FakeTranslationFactory.getInstance().getBQTTranslationUtility();
+ } else {
+ Assert.fail("unknown vdb"); //$NON-NLS-1$
+ }
+ return util.parseCommand(sql);
+ }
+
+}
Property changes on: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/MetadataFactory.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCSourceConnection.java (from rev 486, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/TestJDBCSourceConnection.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCSourceConnection.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCSourceConnection.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc;
+
+import java.sql.Connection;
+import java.util.Properties;
+
+import org.teiid.connector.jdbc.JDBCPropertyNames;
+import org.teiid.connector.jdbc.JDBCSourceConnection;
+import org.teiid.connector.jdbc.translator.Translator;
+
+import junit.framework.TestCase;
+
+import com.metamatrix.cdk.api.EnvironmentUtility;
+import com.metamatrix.connector.api.ConnectorEnvironment;
+import com.metamatrix.connector.basic.BasicConnectorCapabilities;
+import com.metamatrix.core.util.SimpleMock;
+
+
+/**
+ * Test case for JDBCSourceConnection
+ * @since 4.3
+ */
+public class TestJDBCSourceConnection extends TestCase {
+
+ private FakeConnection fakeConnection;
+ private Connection connection;
+ private ConnectorEnvironment environment;
+
+
+ public TestJDBCSourceConnection(String name) {
+ super(name);
+ }
+
+ public void setUp() throws Exception {
+ fakeConnection = new FakeConnection();
+ connection = SimpleMock.createSimpleMock(fakeConnection, Connection.class);
+
+ final Properties properties = new Properties();
+ properties.setProperty(JDBCPropertyNames.EXT_CAPABILITY_CLASS, BasicConnectorCapabilities.class.getName());
+
+ environment = EnvironmentUtility.createEnvironment(properties, false);
+ }
+
+
+ /**
+ * Tests JDBCSourceConnection.isConnectionAlive() with a ConnectionQueryStrategy
+ * @since 4.3
+ */
+ public void testIsAlive() throws Exception {
+ JDBCSourceConnection sourceConnection = new JDBCSourceConnection(connection, environment, new Translator() {
+ @Override
+ public String getConnectionTestQuery() {
+ return "select 1";
+ }
+ });
+
+ //closed connections should not be 'alive'
+ fakeConnection.closed = true;
+ assertFalse(sourceConnection.isAlive());
+
+ //open connections should be 'alive'
+ fakeConnection.closed = false;
+ assertTrue(sourceConnection.isAlive());
+
+ //failed connections should not be 'alive'
+ fakeConnection.fail = true;
+ assertFalse(sourceConnection.isAlive());
+
+ }
+
+ /**
+ * Tests JDBCSourceConnection.isConnectionAlive() with a null ConnectionStrategy
+ * @since 4.3
+ */
+ public void testIsAliveNullStrategy() throws Exception {
+ JDBCSourceConnection sourceConnection = new JDBCSourceConnection(connection, environment, new Translator() {
+ @Override
+ public String getConnectionTestQuery() {
+ return null;
+ }
+ });
+
+ //closed connections should not be 'alive'
+ fakeConnection.closed = true;
+ assertFalse(sourceConnection.isAlive());
+
+ //open connections should be 'alive'
+ fakeConnection.closed = false;
+ assertTrue(sourceConnection.isAlive());
+
+ //without a strategy, failed connections are detected as 'alive'
+ fakeConnection.fail = true;
+ assertTrue(sourceConnection.isAlive());
+
+ }
+
+}
Property changes on: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCSourceConnection.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/access (from rev 486, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/access)
Property changes on: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/access
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/access/TestAccessSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/access/TestAccessSQLTranslator.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/access/TestAccessSQLTranslator.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,17 +20,19 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.access;
+package org.teiid.connector.jdbc.access;
import java.util.Properties;
+import org.teiid.connector.jdbc.access.AccessSQLTranslator;
+import org.teiid.connector.jdbc.translator.TranslatedCommand;
+import org.teiid.connector.jdbc.translator.Translator;
+
import junit.framework.TestCase;
import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.cdk.unittest.FakeTranslationFactory;
import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.jdbc.translator.TranslatedCommand;
-import com.metamatrix.connector.jdbc.translator.Translator;
import com.metamatrix.connector.language.ICommand;
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2 (from rev 486, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/db2)
Property changes on: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2ConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/db2/TestDB2ConvertModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2ConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,518 +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 com.metamatrix.connector.jdbc.db2;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.sql.Timestamp;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.CommandBuilder;
-import com.metamatrix.cdk.api.EnvironmentUtility;
-import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.jdbc.translator.SQLConversionVisitor;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.query.unittest.TimestampUtil;
-
-/**
- */
-public class TestDB2ConvertModifier extends TestCase {
-
- private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
-
- /**
- * Constructor for TestSybaseConvertModifier.
- * @param name
- */
- public TestDB2ConvertModifier(String name) {
- super(name);
- }
-
- public String helpGetString(IExpression expr) throws Exception {
- DB2SQLTranslator trans = new DB2SQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
-
- SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
- sqlVisitor.append(expr);
-
- return sqlVisitor.toString();
- }
-
- public void helpTest(IExpression srcExpression, String tgtType, String expectedExpression) throws Exception {
- IFunction func = LANG_FACTORY.createFunction("convert", //$NON-NLS-1$
- new IExpression[] {
- srcExpression,
- LANG_FACTORY.createLiteral(tgtType, String.class)},
- TypeFacility.getDataTypeClass(tgtType));
-
- DB2ConvertModifier mod = new DB2ConvertModifier(LANG_FACTORY);
- IExpression expr = mod.modify(func);
-
- assertEquals("Error converting from " + srcExpression.getType() + " to " + tgtType, //$NON-NLS-1$ //$NON-NLS-2$
- expectedExpression, helpGetString(expr));
- }
-
- // Source = STRING
-
- public void testStringToChar() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "char", "char('5', 1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "boolean", "CASE WHEN '5' = 'true' THEN 1 ELSE 0 END"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "byte", "smallint('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "short", "smallint('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "integer", "integer('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "long", "bigint('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "biginteger", "bigint('5')"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "float", "real('5')");//$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "double", "double('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToDate() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("2004-06-29", String.class), "date", "date('2004-06-29')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToTime() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("23:59:59", String.class), "time", "time('23:59:59')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToTimestamp() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("2004-06-29 23:59:59.987", String.class), "timestamp", "timestamp('2004-06-29 23:59:59.987')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "bigdecimal", "decimal('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- // Source = CHAR
-
- public void testCharToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Character('5'), Character.class), "string", "'5'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = BOOLEAN
-
- public void testBooleanToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "string", "CASE WHEN 1 = 0 THEN 'false' ELSE 'true' END"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "byte", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "short", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = BYTE
-
- public void testByteToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "boolean", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "short", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = SHORT
-
- public void testShortToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "boolean", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "byte", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = INTEGER
-
- public void testIntegerToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "boolean", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "byte", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "short", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = LONG
-
- public void testLongToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "boolean", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "byte", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "short", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "integer", "integer(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = BIGINTEGER
-
- public void testBigIntegerToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "boolean", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "byte", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "short", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "integer", "integer(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- // Source = FLOAT
-
- public void testFloatToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "string", "char(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "boolean", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "byte", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "short", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "integer", "integer(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "long", "bigint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "biginteger", "bigint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "double", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "bigdecimal", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = DOUBLE
-
- public void testDoubleToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "string", "char(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "boolean", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "byte", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "short", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "integer", "integer(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "long", "bigint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "biginteger", "bigint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "float", "real(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "bigdecimal", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = BIGDECIMAL
-
- public void testBigDecimalToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "string", "char(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "boolean", "smallint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "byte", "smallint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "short", "smallint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "integer", "integer(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "long", "bigint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "biginteger", "bigint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "float", "real(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToDoublel() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "double", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- // Source = DATE
-
- public void testDateToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createDate(103, 10, 1), java.sql.Date.class), "string", "char({d'2003-11-01'})"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDateToTimestamp() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createDate(103, 10, 1), java.sql.Date.class), "timestamp", "timestamp({d'2003-11-01'}, '00:00:00')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = TIME
-
- public void testTimeToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createTime(23, 59, 59), java.sql.Time.class), "string", "char({t'23:59:59'})"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testTimeToTimestamp() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createTime(23, 59, 59), java.sql.Time.class), "timestamp", "timestamp('1970-01-01', {t'23:59:59'})"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = TIMESTAMP
-
- public void testTimestampToString() throws Exception {
- Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
- helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "string", "char({ts'2003-11-01 12:05:02.0'})"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testTimestampToDate() throws Exception {
- Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
- helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "date", "date({ts'2003-11-01 12:05:02.0'})"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testTimestampToTime() throws Exception {
- Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
- helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "time", "time({ts'2003-11-01 12:05:02.0'})"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-}
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2ConvertModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/db2/TestDB2ConvertModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2ConvertModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2ConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,520 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.db2;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.Properties;
+
+import org.teiid.connector.jdbc.db2.DB2ConvertModifier;
+import org.teiid.connector.jdbc.db2.DB2SQLTranslator;
+import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
+
+import junit.framework.TestCase;
+
+import com.metamatrix.cdk.CommandBuilder;
+import com.metamatrix.cdk.api.EnvironmentUtility;
+import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+import com.metamatrix.query.unittest.TimestampUtil;
+
+/**
+ */
+public class TestDB2ConvertModifier extends TestCase {
+
+ private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
+
+ /**
+ * Constructor for TestSybaseConvertModifier.
+ * @param name
+ */
+ public TestDB2ConvertModifier(String name) {
+ super(name);
+ }
+
+ public String helpGetString(IExpression expr) throws Exception {
+ DB2SQLTranslator trans = new DB2SQLTranslator();
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
+ SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
+ sqlVisitor.append(expr);
+
+ return sqlVisitor.toString();
+ }
+
+ public void helpTest(IExpression srcExpression, String tgtType, String expectedExpression) throws Exception {
+ IFunction func = LANG_FACTORY.createFunction("convert", //$NON-NLS-1$
+ Arrays.asList(
+ srcExpression,
+ LANG_FACTORY.createLiteral(tgtType, String.class)),
+ TypeFacility.getDataTypeClass(tgtType));
+
+ DB2ConvertModifier mod = new DB2ConvertModifier(LANG_FACTORY);
+ IExpression expr = mod.modify(func);
+
+ assertEquals("Error converting from " + srcExpression.getType() + " to " + tgtType, //$NON-NLS-1$ //$NON-NLS-2$
+ expectedExpression, helpGetString(expr));
+ }
+
+ // Source = STRING
+ public void testStringToChar() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "char", "char('5', 1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "boolean", "CASE WHEN '5' = 'true' THEN 1 ELSE 0 END"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "byte", "smallint('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "short", "smallint('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "integer", "integer('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "long", "bigint('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "biginteger", "bigint('5')"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "float", "real('5')");//$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "double", "double('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToDate() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("2004-06-29", String.class), "date", "date('2004-06-29')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToTime() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("23:59:59", String.class), "time", "time('23:59:59')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToTimestamp() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("2004-06-29 23:59:59.987", String.class), "timestamp", "timestamp('2004-06-29 23:59:59.987')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "bigdecimal", "decimal('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ // Source = CHAR
+
+ public void testCharToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Character('5'), Character.class), "string", "'5'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = BOOLEAN
+
+ public void testBooleanToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "string", "CASE WHEN 1 = 0 THEN 'false' ELSE 'true' END"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "byte", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "short", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = BYTE
+
+ public void testByteToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "boolean", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "short", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = SHORT
+
+ public void testShortToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "boolean", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "byte", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = INTEGER
+
+ public void testIntegerToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "boolean", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "byte", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "short", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = LONG
+
+ public void testLongToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "boolean", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "byte", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "short", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "integer", "integer(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = BIGINTEGER
+
+ public void testBigIntegerToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "boolean", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "byte", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "short", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "integer", "integer(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ // Source = FLOAT
+
+ public void testFloatToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "string", "char(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "boolean", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "byte", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "short", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "integer", "integer(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "long", "bigint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "biginteger", "bigint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "double", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "bigdecimal", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = DOUBLE
+
+ public void testDoubleToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "string", "char(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "boolean", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "byte", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "short", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "integer", "integer(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "long", "bigint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "biginteger", "bigint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "float", "real(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "bigdecimal", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = BIGDECIMAL
+
+ public void testBigDecimalToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "string", "char(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "boolean", "smallint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "byte", "smallint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "short", "smallint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "integer", "integer(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "long", "bigint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "biginteger", "bigint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "float", "real(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToDoublel() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "double", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ // Source = DATE
+
+ public void testDateToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createDate(103, 10, 1), java.sql.Date.class), "string", "char({d'2003-11-01'})"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDateToTimestamp() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createDate(103, 10, 1), java.sql.Date.class), "timestamp", "timestamp({d'2003-11-01'}, '00:00:00')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = TIME
+
+ public void testTimeToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createTime(23, 59, 59), java.sql.Time.class), "string", "char({t'23:59:59'})"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testTimeToTimestamp() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createTime(23, 59, 59), java.sql.Time.class), "timestamp", "timestamp('1970-01-01', {t'23:59:59'})"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = TIMESTAMP
+
+ public void testTimestampToString() throws Exception {
+ Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
+ helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "string", "char({ts'2003-11-01 12:05:02.0'})"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testTimestampToDate() throws Exception {
+ Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
+ helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "date", "date({ts'2003-11-01 12:05:02.0'})"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testTimestampToTime() throws Exception {
+ Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
+ helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "time", "time({ts'2003-11-01 12:05:02.0'})"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+}
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2SqlTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/db2/TestDB2SqlTranslator.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2SqlTranslator.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,11 +20,14 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.db2;
+package org.teiid.connector.jdbc.db2;
import java.util.Map;
import java.util.Properties;
+import org.teiid.connector.jdbc.db2.DB2SQLTranslator;
+import org.teiid.connector.jdbc.translator.TranslatedCommand;
+
import junit.framework.TestCase;
import com.metamatrix.cdk.api.EnvironmentUtility;
@@ -32,7 +35,6 @@
import com.metamatrix.cdk.unittest.FakeTranslationFactory;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.ExecutionContext;
-import com.metamatrix.connector.jdbc.translator.TranslatedCommand;
import com.metamatrix.connector.language.ICommand;
import com.metamatrix.core.util.UnitTestUtil;
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby (from rev 486, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/derby)
Property changes on: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/derby/TestDerbyConvertModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,519 +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 com.metamatrix.connector.jdbc.derby;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.sql.Timestamp;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.CommandBuilder;
-import com.metamatrix.cdk.api.EnvironmentUtility;
-import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.jdbc.translator.SQLConversionVisitor;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.query.unittest.TimestampUtil;
-
-/**
- */
-public class TestDerbyConvertModifier extends TestCase {
-
- private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
-
- /**
- * Constructor for TestSybaseConvertModifier.
- * @param name
- */
- public TestDerbyConvertModifier(String name) {
- super(name);
- }
-
- public String helpGetString(IExpression expr) throws Exception {
- DerbySQLTranslator trans = new DerbySQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
-
- SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
- sqlVisitor.append(expr);
-
- return sqlVisitor.toString();
- }
-
- public void helpTest(IExpression srcExpression, String tgtType, String expectedExpression) throws Exception {
- IFunction func = LANG_FACTORY.createFunction("convert", //$NON-NLS-1$
- new IExpression[] {
- srcExpression,
- LANG_FACTORY.createLiteral(tgtType, String.class)},
- TypeFacility.getDataTypeClass(tgtType));
-
- DerbyConvertModifier mod = new DerbyConvertModifier(LANG_FACTORY);
- IExpression expr = mod.modify(func);
-
- assertEquals("Error converting from " + srcExpression.getType() + " to " + tgtType, //$NON-NLS-1$ //$NON-NLS-2$
- expectedExpression, helpGetString(expr));
- }
-
- // Source = STRING
-
- public void testStringToChar() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "char", "char('5', 1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "boolean", "CASE WHEN '5' = 'true' THEN 1 ELSE 0 END"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "byte", "smallint('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "short", "smallint('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "integer", "integer('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "long", "bigint('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "biginteger", "bigint('5')"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "float", "cast(cast('5' as decimal) as float)");//$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "double", "cast(cast('5' as decimal) as double)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToDate() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("2004-06-29", String.class), "date", "date('2004-06-29')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToTime() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("23:59:59", String.class), "time", "time('23:59:59')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToTimestamp() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("2004-06-29 23:59:59.987", String.class), "timestamp", "timestamp('2004-06-29 23:59:59.987')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "bigdecimal", "cast('5' as decimal)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- // Source = CHAR
-
- public void testCharToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Character('5'), Character.class), "string", "'5'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = BOOLEAN
-
- public void testBooleanToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "string", "CASE WHEN 1 = 0 THEN 'false' ELSE 'true' END"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "byte", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "short", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = BYTE
-
- public void testByteToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "boolean", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "short", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = SHORT
-
- public void testShortToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "boolean", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "byte", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = INTEGER
-
- public void testIntegerToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "boolean", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "byte", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "short", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = LONG
-
- public void testLongToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "boolean", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "byte", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "short", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "integer", "integer(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = BIGINTEGER
-
- public void testBigIntegerToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "boolean", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "byte", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "short", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "integer", "integer(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- // Source = FLOAT
-
- public void testFloatToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "string", "char(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "boolean", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "byte", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "short", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "integer", "integer(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "long", "bigint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "biginteger", "bigint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "double", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "bigdecimal", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = DOUBLE
-
- public void testDoubleToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "string", "char(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "boolean", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "byte", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "short", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "integer", "integer(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "long", "bigint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "biginteger", "bigint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "float", "cast(1.2 as float)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "bigdecimal", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = BIGDECIMAL
-
- public void testBigDecimalToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "string", "char(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "boolean", "smallint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "byte", "smallint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "short", "smallint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "integer", "integer(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "long", "bigint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "biginteger", "bigint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "float", "cast(1.0 as float)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToDoublel() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "double", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- // Source = DATE
-
- public void testDateToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createDate(103, 10, 1), java.sql.Date.class), "string", "char({d'2003-11-01'})"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDateToTimestamp() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createDate(103, 10, 1), java.sql.Date.class), "timestamp", "timestamp({d'2003-11-01'}, '00:00:00')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = TIME
-
- public void testTimeToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createTime(23, 59, 59), java.sql.Time.class), "string", "char({t'23:59:59'})"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testTimeToTimestamp() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createTime(23, 59, 59), java.sql.Time.class), "timestamp", "timestamp('1970-01-01', {t'23:59:59'})"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = TIMESTAMP
-
- public void testTimestampToString() throws Exception {
- Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
- helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "string", "char({ts'2003-11-01 12:05:02.0'})"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testTimestampToDate() throws Exception {
- Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
- helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "date", "date({ts'2003-11-01 12:05:02.0'})"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testTimestampToTime() throws Exception {
- Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
- helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "time", "time({ts'2003-11-01 12:05:02.0'})"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-
-}
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyConvertModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/derby/TestDerbyConvertModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyConvertModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,523 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.derby;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.Properties;
+
+import org.teiid.connector.jdbc.derby.DerbyConvertModifier;
+import org.teiid.connector.jdbc.derby.DerbySQLTranslator;
+import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
+
+import junit.framework.TestCase;
+
+import com.metamatrix.cdk.CommandBuilder;
+import com.metamatrix.cdk.api.EnvironmentUtility;
+import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+import com.metamatrix.query.unittest.TimestampUtil;
+
+/**
+ */
+public class TestDerbyConvertModifier extends TestCase {
+
+ private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
+
+ /**
+ * Constructor for TestSybaseConvertModifier.
+ * @param name
+ */
+ public TestDerbyConvertModifier(String name) {
+ super(name);
+ }
+
+ public String helpGetString(IExpression expr) throws Exception {
+ DerbySQLTranslator trans = new DerbySQLTranslator();
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
+
+ SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
+ sqlVisitor.append(expr);
+
+ return sqlVisitor.toString();
+ }
+
+ public void helpTest(IExpression srcExpression, String tgtType, String expectedExpression) throws Exception {
+ IFunction func = LANG_FACTORY.createFunction("convert", //$NON-NLS-1$
+ Arrays.asList(
+ srcExpression,
+ LANG_FACTORY.createLiteral(tgtType, String.class)),
+ TypeFacility.getDataTypeClass(tgtType));
+
+ DerbyConvertModifier mod = new DerbyConvertModifier(LANG_FACTORY);
+ IExpression expr = mod.modify(func);
+
+ assertEquals("Error converting from " + srcExpression.getType() + " to " + tgtType, //$NON-NLS-1$ //$NON-NLS-2$
+ expectedExpression, helpGetString(expr));
+ }
+
+ // Source = STRING
+
+ public void testStringToChar() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "char", "char('5', 1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "boolean", "CASE WHEN '5' = 'true' THEN 1 ELSE 0 END"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "byte", "smallint('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "short", "smallint('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "integer", "integer('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "long", "bigint('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "biginteger", "bigint('5')"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "float", "cast(cast('5' as decimal) as float)");//$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "double", "cast(cast('5' as decimal) as double)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToDate() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("2004-06-29", String.class), "date", "date('2004-06-29')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToTime() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("23:59:59", String.class), "time", "time('23:59:59')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToTimestamp() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("2004-06-29 23:59:59.987", String.class), "timestamp", "timestamp('2004-06-29 23:59:59.987')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "bigdecimal", "cast('5' as decimal)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ // Source = CHAR
+
+ public void testCharToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Character('5'), Character.class), "string", "'5'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = BOOLEAN
+
+ public void testBooleanToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "string", "CASE WHEN 1 = 0 THEN 'false' ELSE 'true' END"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "byte", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "short", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = BYTE
+
+ public void testByteToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "boolean", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "short", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = SHORT
+
+ public void testShortToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "boolean", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "byte", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = INTEGER
+
+ public void testIntegerToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "boolean", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "byte", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "short", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = LONG
+
+ public void testLongToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "boolean", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "byte", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "short", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "integer", "integer(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = BIGINTEGER
+
+ public void testBigIntegerToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "string", "char(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "boolean", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "byte", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "short", "smallint(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "integer", "integer(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ // Source = FLOAT
+
+ public void testFloatToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "string", "char(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "boolean", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "byte", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "short", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "integer", "integer(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "long", "bigint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "biginteger", "bigint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "double", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "bigdecimal", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = DOUBLE
+
+ public void testDoubleToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "string", "char(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "boolean", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "byte", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "short", "smallint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "integer", "integer(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "long", "bigint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "biginteger", "bigint(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "float", "cast(1.2 as float)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "bigdecimal", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = BIGDECIMAL
+
+ public void testBigDecimalToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "string", "char(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "boolean", "smallint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "byte", "smallint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "short", "smallint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "integer", "integer(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "long", "bigint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "biginteger", "bigint(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "float", "cast(1.0 as float)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToDoublel() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "double", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ // Source = DATE
+
+ public void testDateToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createDate(103, 10, 1), java.sql.Date.class), "string", "char({d'2003-11-01'})"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDateToTimestamp() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createDate(103, 10, 1), java.sql.Date.class), "timestamp", "timestamp({d'2003-11-01'}, '00:00:00')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = TIME
+
+ public void testTimeToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createTime(23, 59, 59), java.sql.Time.class), "string", "char({t'23:59:59'})"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testTimeToTimestamp() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createTime(23, 59, 59), java.sql.Time.class), "timestamp", "timestamp('1970-01-01', {t'23:59:59'})"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = TIMESTAMP
+
+ public void testTimestampToString() throws Exception {
+ Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
+ helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "string", "char({ts'2003-11-01 12:05:02.0'})"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testTimestampToDate() throws Exception {
+ Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
+ helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "date", "date({ts'2003-11-01 12:05:02.0'})"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testTimestampToTime() throws Exception {
+ Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
+ helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "time", "time({ts'2003-11-01 12:05:02.0'})"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+
+}
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl (from rev 486, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/extension/impl)
Property changes on: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestDropFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/extension/impl/TestDropFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestDropFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,73 +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 com.metamatrix.connector.jdbc.extension.impl;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.CommandBuilder;
-import com.metamatrix.connector.jdbc.translator.DropFunctionModifier;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILiteral;
-
-/**
- */
-public class TestDropFunctionModifier extends TestCase {
-
- /**
- * Constructor for TestDropFunctionModifier.
- * @param name
- */
- public TestDropFunctionModifier(String name) {
- super(name);
- }
-
- public void testDrop() {
- DropFunctionModifier mod = new DropFunctionModifier();
-
- ILiteral arg1 = CommandBuilder.getLanuageFactory().createLiteral(new Integer(5), Integer.class);
- ILiteral arg2 = CommandBuilder.getLanuageFactory().createLiteral("string", String.class);//$NON-NLS-1$
- IFunction func = CommandBuilder.getLanuageFactory().createFunction("convert", new IExpression[] { arg1, arg2}, Integer.class); //$NON-NLS-1$
-
- IExpression output = mod.modify(func);
- assertEquals("Did not get expected function after using drop modifier", arg1, output); //$NON-NLS-1$
- }
-
- /**
- * In SQL Server convert(), the type arg is the first arg, and the column name
- * is the second arg. DropFunctionModifier needs to be able to handle the column name
- * arg being in different indices.
- */
- public void testDrop2() {
- DropFunctionModifier mod = new DropFunctionModifier();
- mod.setReplaceIndex(1);
-
- ILiteral arg1 = CommandBuilder.getLanuageFactory().createLiteral("string", String.class);//$NON-NLS-1$
- ILiteral arg2 = CommandBuilder.getLanuageFactory().createLiteral(new Integer(5), Integer.class);
- IFunction func = CommandBuilder.getLanuageFactory().createFunction("convert", new IExpression[] { arg1, arg2}, Integer.class); //$NON-NLS-1$
-
- IExpression output = mod.modify(func);
- assertEquals("Did not get expected function after using drop modifier", arg2, output); //$NON-NLS-1$
- }
-
-}
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestDropFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/extension/impl/TestDropFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestDropFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestDropFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.extension.impl;
+
+import java.util.Arrays;
+
+import org.teiid.connector.jdbc.translator.DropFunctionModifier;
+
+import junit.framework.TestCase;
+
+import com.metamatrix.cdk.CommandBuilder;
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILiteral;
+
+/**
+ */
+public class TestDropFunctionModifier extends TestCase {
+
+ /**
+ * Constructor for TestDropFunctionModifier.
+ * @param name
+ */
+ public TestDropFunctionModifier(String name) {
+ super(name);
+ }
+
+ public void testDrop() {
+ DropFunctionModifier mod = new DropFunctionModifier();
+
+ ILiteral arg1 = CommandBuilder.getLanuageFactory().createLiteral(new Integer(5), Integer.class);
+ ILiteral arg2 = CommandBuilder.getLanuageFactory().createLiteral("string", String.class);//$NON-NLS-1$
+ IFunction func = CommandBuilder.getLanuageFactory().createFunction("convert", Arrays.asList(arg1, arg2), Integer.class); //$NON-NLS-1$
+
+ IExpression output = mod.modify(func);
+ assertEquals("Did not get expected function after using drop modifier", arg1, output); //$NON-NLS-1$
+ }
+
+ /**
+ * In SQL Server convert(), the type arg is the first arg, and the column name
+ * is the second arg. DropFunctionModifier needs to be able to handle the column name
+ * arg being in different indices.
+ */
+ public void testDrop2() {
+ DropFunctionModifier mod = new DropFunctionModifier();
+ mod.setReplaceIndex(1);
+
+ ILiteral arg1 = CommandBuilder.getLanuageFactory().createLiteral("string", String.class);//$NON-NLS-1$
+ ILiteral arg2 = CommandBuilder.getLanuageFactory().createLiteral(new Integer(5), Integer.class);
+ IFunction func = CommandBuilder.getLanuageFactory().createFunction("convert", Arrays.asList(arg1, arg2), Integer.class); //$NON-NLS-1$
+
+ IExpression output = mod.modify(func);
+ assertEquals("Did not get expected function after using drop modifier", arg2, output); //$NON-NLS-1$
+ }
+
+}
Deleted: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestEscapeSyntaxModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/extension/impl/TestEscapeSyntaxModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestEscapeSyntaxModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,62 +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 com.metamatrix.connector.jdbc.extension.impl;
-
-import java.util.Arrays;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.CommandBuilder;
-import com.metamatrix.connector.jdbc.translator.EscapeSyntaxModifier;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILiteral;
-
-/**
- */
-public class TestEscapeSyntaxModifier extends TestCase {
-
- /**
- * Constructor for TestDropFunctionModifier.
- * @param name
- */
- public TestEscapeSyntaxModifier(String name) {
- super(name);
- }
-
- public void testEscape() {
- EscapeSyntaxModifier mod = new EscapeSyntaxModifier();
-
- ILiteral arg1 = CommandBuilder.getLanuageFactory().createLiteral("arg1", String.class); //$NON-NLS-1$
- ILiteral arg2 = CommandBuilder.getLanuageFactory().createLiteral("arg2", String.class);//$NON-NLS-1$
- IFunction func = CommandBuilder.getLanuageFactory().createFunction("concat", new IExpression[] { arg1, arg2}, Integer.class); //$NON-NLS-1$
-
- func = (IFunction) mod.modify(func);
- List parts = mod.translate(func);
-
- List expected = Arrays.asList(new Object[] { "{fn ", "concat", "(", arg1, ", ", arg2, ")", "}"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- assertEquals(expected, parts);
- }
-
-}
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestEscapeSyntaxModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/extension/impl/TestEscapeSyntaxModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestEscapeSyntaxModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestEscapeSyntaxModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.extension.impl;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.connector.jdbc.translator.EscapeSyntaxModifier;
+
+import junit.framework.TestCase;
+
+import com.metamatrix.cdk.CommandBuilder;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILiteral;
+
+/**
+ */
+public class TestEscapeSyntaxModifier extends TestCase {
+
+ /**
+ * Constructor for TestDropFunctionModifier.
+ * @param name
+ */
+ public TestEscapeSyntaxModifier(String name) {
+ super(name);
+ }
+
+ public void testEscape() {
+ EscapeSyntaxModifier mod = new EscapeSyntaxModifier();
+
+ ILiteral arg1 = CommandBuilder.getLanuageFactory().createLiteral("arg1", String.class); //$NON-NLS-1$
+ ILiteral arg2 = CommandBuilder.getLanuageFactory().createLiteral("arg2", String.class);//$NON-NLS-1$
+ IFunction func = CommandBuilder.getLanuageFactory().createFunction("concat", Arrays.asList( arg1, arg2), Integer.class); //$NON-NLS-1$
+
+ func = (IFunction) mod.modify(func);
+ List parts = mod.translate(func);
+
+ List expected = Arrays.asList(new Object[] { "{fn ", "concat", "(", arg1, ", ", arg2, ")", "}"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
+ assertEquals(expected, parts);
+ }
+
+}
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql (from rev 486, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/mysql)
Property changes on: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/mysql/TestMySQLTranslator.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,17 +20,19 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.mysql;
+package org.teiid.connector.jdbc.mysql;
import java.util.Map;
import java.util.Properties;
+import org.teiid.connector.jdbc.MetadataFactory;
+import org.teiid.connector.jdbc.mysql.MySQLTranslator;
+import org.teiid.connector.jdbc.translator.TranslatedCommand;
+
import junit.framework.TestCase;
import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.jdbc.MetadataFactory;
-import com.metamatrix.connector.jdbc.translator.TranslatedCommand;
import com.metamatrix.connector.language.ICommand;
/**
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle (from rev 486, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle)
Property changes on: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestDayWeekQuarterFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestDayWeekQuarterFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestDayWeekQuarterFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,130 +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 com.metamatrix.connector.jdbc.oracle;
-
-import java.sql.Timestamp;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.CommandBuilder;
-import com.metamatrix.cdk.api.EnvironmentUtility;
-import com.metamatrix.connector.jdbc.translator.SQLConversionVisitor;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.connector.language.ILiteral;
-import com.metamatrix.query.unittest.TimestampUtil;
-
-/**
- */
-public class TestDayWeekQuarterFunctionModifier extends TestCase {
-
- private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
-
- /**
- * Constructor for TestHourFunctionModifier.
- * @param name
- */
- public TestDayWeekQuarterFunctionModifier(String name) {
- super(name);
- }
-
- public IExpression helpTestMod(ILiteral c, String format, String expectedStr) throws Exception {
- IFunction func = LANG_FACTORY.createFunction("dayweekquarter", //$NON-NLS-1$
- new IExpression[] { c },
- String.class);
-
- DayWeekQuarterFunctionModifier mod = new DayWeekQuarterFunctionModifier (LANG_FACTORY, format);
- IExpression expr = mod.modify(func);
-
- OracleSQLTranslator trans = new OracleSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
-
- SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
- sqlVisitor.append(expr);
- assertEquals(expectedStr, sqlVisitor.toString());
-
- return expr;
- }
-
- public void test1() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 10, 5, 0, 0), Timestamp.class);
- helpTestMod(arg1, "DDD", //$NON-NLS-1$
- "TO_NUMBER(TO_CHAR({ts'2004-01-21 10:05:00.0'}, 'DDD'))"); //$NON-NLS-1$
- }
-
- public void test2() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
- helpTestMod(arg1, "DDD", //$NON-NLS-1$
- "TO_NUMBER(TO_CHAR({d'2004-01-21'}, 'DDD'))"); //$NON-NLS-1$
- }
-
- public void test3() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 10, 5, 0, 0), Timestamp.class);
- helpTestMod(arg1, "D", //$NON-NLS-1$
- "TO_NUMBER(TO_CHAR({ts'2004-01-21 10:05:00.0'}, 'D'))"); //$NON-NLS-1$
- }
-
- public void test4() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
- helpTestMod(arg1, "D", //$NON-NLS-1$
- "TO_NUMBER(TO_CHAR({d'2004-01-21'}, 'D'))"); //$NON-NLS-1$
- }
-
- public void test5() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 10, 5, 0, 0), Timestamp.class);
- helpTestMod(arg1, "DD", //$NON-NLS-1$
- "TO_NUMBER(TO_CHAR({ts'2004-01-21 10:05:00.0'}, 'DD'))"); //$NON-NLS-1$
- }
-
- public void test6() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
- helpTestMod(arg1, "DD", //$NON-NLS-1$
- "TO_NUMBER(TO_CHAR({d'2004-01-21'}, 'DD'))"); //$NON-NLS-1$
- }
-
- public void test7() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 10, 5, 0, 0), Timestamp.class);
- helpTestMod(arg1, "WW", //$NON-NLS-1$
- "TO_NUMBER(TO_CHAR({ts'2004-01-21 10:05:00.0'}, 'WW'))"); //$NON-NLS-1$
- }
-
- public void test8() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
- helpTestMod(arg1, "WW", //$NON-NLS-1$
- "TO_NUMBER(TO_CHAR({d'2004-01-21'}, 'WW'))"); //$NON-NLS-1$
- }
-
- public void test9() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 10, 5, 0, 0), Timestamp.class);
- helpTestMod(arg1, "Q", //$NON-NLS-1$
- "TO_NUMBER(TO_CHAR({ts'2004-01-21 10:05:00.0'}, 'Q'))"); //$NON-NLS-1$
- }
-
- public void test10() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
- helpTestMod(arg1, "Q", //$NON-NLS-1$
- "TO_NUMBER(TO_CHAR({d'2004-01-21'}, 'Q'))"); //$NON-NLS-1$
- }
-}
\ No newline at end of file
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestDayWeekQuarterFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestDayWeekQuarterFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestDayWeekQuarterFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestDayWeekQuarterFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,134 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.oracle;
+
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.Properties;
+
+import org.teiid.connector.jdbc.oracle.DayWeekQuarterFunctionModifier;
+import org.teiid.connector.jdbc.oracle.OracleSQLTranslator;
+import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
+
+import junit.framework.TestCase;
+
+import com.metamatrix.cdk.CommandBuilder;
+import com.metamatrix.cdk.api.EnvironmentUtility;
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+import com.metamatrix.connector.language.ILiteral;
+import com.metamatrix.query.unittest.TimestampUtil;
+
+/**
+ */
+public class TestDayWeekQuarterFunctionModifier extends TestCase {
+
+ private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
+
+ /**
+ * Constructor for TestHourFunctionModifier.
+ * @param name
+ */
+ public TestDayWeekQuarterFunctionModifier(String name) {
+ super(name);
+ }
+
+ public IExpression helpTestMod(ILiteral c, String format, String expectedStr) throws Exception {
+ IFunction func = LANG_FACTORY.createFunction("dayweekquarter", //$NON-NLS-1$
+ Arrays.asList(c),
+ String.class);
+
+ DayWeekQuarterFunctionModifier mod = new DayWeekQuarterFunctionModifier (LANG_FACTORY, format);
+ IExpression expr = mod.modify(func);
+
+ OracleSQLTranslator trans = new OracleSQLTranslator();
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
+
+ SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
+ sqlVisitor.append(expr);
+ assertEquals(expectedStr, sqlVisitor.toString());
+
+ return expr;
+ }
+
+ public void test1() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 10, 5, 0, 0), Timestamp.class);
+ helpTestMod(arg1, "DDD", //$NON-NLS-1$
+ "TO_NUMBER(TO_CHAR({ts'2004-01-21 10:05:00.0'}, 'DDD'))"); //$NON-NLS-1$
+ }
+
+ public void test2() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
+ helpTestMod(arg1, "DDD", //$NON-NLS-1$
+ "TO_NUMBER(TO_CHAR({d'2004-01-21'}, 'DDD'))"); //$NON-NLS-1$
+ }
+
+ public void test3() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 10, 5, 0, 0), Timestamp.class);
+ helpTestMod(arg1, "D", //$NON-NLS-1$
+ "TO_NUMBER(TO_CHAR({ts'2004-01-21 10:05:00.0'}, 'D'))"); //$NON-NLS-1$
+ }
+
+ public void test4() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
+ helpTestMod(arg1, "D", //$NON-NLS-1$
+ "TO_NUMBER(TO_CHAR({d'2004-01-21'}, 'D'))"); //$NON-NLS-1$
+ }
+
+ public void test5() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 10, 5, 0, 0), Timestamp.class);
+ helpTestMod(arg1, "DD", //$NON-NLS-1$
+ "TO_NUMBER(TO_CHAR({ts'2004-01-21 10:05:00.0'}, 'DD'))"); //$NON-NLS-1$
+ }
+
+ public void test6() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
+ helpTestMod(arg1, "DD", //$NON-NLS-1$
+ "TO_NUMBER(TO_CHAR({d'2004-01-21'}, 'DD'))"); //$NON-NLS-1$
+ }
+
+ public void test7() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 10, 5, 0, 0), Timestamp.class);
+ helpTestMod(arg1, "WW", //$NON-NLS-1$
+ "TO_NUMBER(TO_CHAR({ts'2004-01-21 10:05:00.0'}, 'WW'))"); //$NON-NLS-1$
+ }
+
+ public void test8() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
+ helpTestMod(arg1, "WW", //$NON-NLS-1$
+ "TO_NUMBER(TO_CHAR({d'2004-01-21'}, 'WW'))"); //$NON-NLS-1$
+ }
+
+ public void test9() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 10, 5, 0, 0), Timestamp.class);
+ helpTestMod(arg1, "Q", //$NON-NLS-1$
+ "TO_NUMBER(TO_CHAR({ts'2004-01-21 10:05:00.0'}, 'Q'))"); //$NON-NLS-1$
+ }
+
+ public void test10() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
+ helpTestMod(arg1, "Q", //$NON-NLS-1$
+ "TO_NUMBER(TO_CHAR({d'2004-01-21'}, 'Q'))"); //$NON-NLS-1$
+ }
+}
\ No newline at end of file
Deleted: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestExtractFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestExtractFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestExtractFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,114 +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 com.metamatrix.connector.jdbc.oracle;
-
-import java.sql.Timestamp;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.CommandBuilder;
-import com.metamatrix.cdk.api.EnvironmentUtility;
-import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.jdbc.translator.SQLConversionVisitor;
-import com.metamatrix.connector.language.IElement;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.IGroup;
-import com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.connector.language.ILiteral;
-import com.metamatrix.query.unittest.TimestampUtil;
-
-/**
- */
-public class TestExtractFunctionModifier extends TestCase {
-
- private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
-
- /**
- * Constructor for TestMonthFunctionModifier.
- * @param name
- */
- public TestExtractFunctionModifier(String name) {
- super(name);
- }
-
- public IExpression helpTestMod(IExpression c, String expectedStr, String target) throws Exception {
- IFunction func = LANG_FACTORY.createFunction(target,
- new IExpression[] { c },
- Integer.class);
-
- ExtractFunctionModifier mod = new ExtractFunctionModifier (target);
- IExpression expr = mod.modify(func);
-
- OracleSQLTranslator trans = new OracleSQLTranslator();
- trans.registerFunctionModifier("extract", mod);
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
-
- SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
-
- //sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
- sqlVisitor.append(expr);
- //System.out.println(" expected: " + expectedStr + " \t actual: " + sqlVisitor.toString());
- assertEquals(expectedStr, sqlVisitor.toString());
-
- return expr;
- }
- public void test1() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
- helpTestMod(arg1, "EXTRACT(MONTH FROM {d'2004-01-21'})" , "month"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void test2() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 17, 5, 0, 0), Timestamp.class);
- helpTestMod(arg1, "EXTRACT(MONTH FROM {ts'2004-01-21 17:05:00.0'})", "month"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void test3() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
- helpTestMod(arg1, "EXTRACT(YEAR FROM {d'2004-01-21'})", "year"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void test4() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 17, 5, 0, 0), Timestamp.class);
- helpTestMod(arg1, "EXTRACT(YEAR FROM {ts'2004-01-21 17:05:00.0'})", "year"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void test5() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
- helpTestMod(arg1, "EXTRACT(DAY FROM {d'2004-01-21'})", "dayofmonth"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void test6() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 17, 5, 0, 0), Timestamp.class);
- helpTestMod(arg1, "EXTRACT(DAY FROM {ts'2004-01-21 17:05:00.0'})", "dayofmonth"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void test11() throws Exception {
- IGroup group = LANG_FACTORY.createGroup(null, "group", null); //$NON-NLS-1$
- IElement elem = LANG_FACTORY.createElement("col", group, null, TypeFacility.RUNTIME_TYPES.DATE); //$NON-NLS-1$
- helpTestMod(elem, "EXTRACT(DAY FROM col)", "dayofmonth"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-}
-
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestExtractFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestExtractFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestExtractFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestExtractFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.oracle;
+
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.Properties;
+
+import org.teiid.connector.jdbc.oracle.ExtractFunctionModifier;
+import org.teiid.connector.jdbc.oracle.OracleSQLTranslator;
+import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
+
+import junit.framework.TestCase;
+
+import com.metamatrix.cdk.CommandBuilder;
+import com.metamatrix.cdk.api.EnvironmentUtility;
+import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.language.IElement;
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.IGroup;
+import com.metamatrix.connector.language.ILanguageFactory;
+import com.metamatrix.connector.language.ILiteral;
+import com.metamatrix.query.unittest.TimestampUtil;
+
+/**
+ */
+public class TestExtractFunctionModifier extends TestCase {
+
+ private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
+
+ /**
+ * Constructor for TestMonthFunctionModifier.
+ * @param name
+ */
+ public TestExtractFunctionModifier(String name) {
+ super(name);
+ }
+
+ public IExpression helpTestMod(IExpression c, String expectedStr, String target) throws Exception {
+ IFunction func = LANG_FACTORY.createFunction(target,
+ Arrays.asList(c),
+ Integer.class);
+
+ ExtractFunctionModifier mod = new ExtractFunctionModifier (target);
+ IExpression expr = mod.modify(func);
+
+ OracleSQLTranslator trans = new OracleSQLTranslator();
+ trans.registerFunctionModifier("extract", mod);
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
+
+ SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
+
+ //sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
+ sqlVisitor.append(expr);
+ //System.out.println(" expected: " + expectedStr + " \t actual: " + sqlVisitor.toString());
+ assertEquals(expectedStr, sqlVisitor.toString());
+
+ return expr;
+ }
+ public void test1() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
+ helpTestMod(arg1, "EXTRACT(MONTH FROM {d'2004-01-21'})" , "month"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void test2() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 17, 5, 0, 0), Timestamp.class);
+ helpTestMod(arg1, "EXTRACT(MONTH FROM {ts'2004-01-21 17:05:00.0'})", "month"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void test3() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
+ helpTestMod(arg1, "EXTRACT(YEAR FROM {d'2004-01-21'})", "year"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void test4() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 17, 5, 0, 0), Timestamp.class);
+ helpTestMod(arg1, "EXTRACT(YEAR FROM {ts'2004-01-21 17:05:00.0'})", "year"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void test5() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
+ helpTestMod(arg1, "EXTRACT(DAY FROM {d'2004-01-21'})", "dayofmonth"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void test6() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 17, 5, 0, 0), Timestamp.class);
+ helpTestMod(arg1, "EXTRACT(DAY FROM {ts'2004-01-21 17:05:00.0'})", "dayofmonth"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void test11() throws Exception {
+ IGroup group = LANG_FACTORY.createGroup(null, "group", null); //$NON-NLS-1$
+ IElement elem = LANG_FACTORY.createElement("col", group, null, TypeFacility.RUNTIME_TYPES.DATE); //$NON-NLS-1$
+ helpTestMod(elem, "EXTRACT(DAY FROM col)", "dayofmonth"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+}
+
Deleted: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLeftOrRightFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestLeftOrRightFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLeftOrRightFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,83 +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 com.metamatrix.connector.jdbc.oracle;
-
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.CommandBuilder;
-import com.metamatrix.cdk.api.EnvironmentUtility;
-import com.metamatrix.connector.jdbc.translator.SQLConversionVisitor;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.connector.language.ILiteral;
-
-/**
- */
-public class TestLeftOrRightFunctionModifier extends TestCase {
-
- private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
-
- /**
- * Constructor for TestHourFunctionModifier.
- * @param name
- */
- public TestLeftOrRightFunctionModifier(String name) {
- super(name);
- }
-
- public IExpression helpTestMod(ILiteral c, ILiteral d, String target, String expectedStr) throws Exception {
- IFunction func = LANG_FACTORY.createFunction(target,
- new IExpression[] { c, d },
- String.class);
-
- LeftOrRightFunctionModifier mod = new LeftOrRightFunctionModifier (LANG_FACTORY);
- IExpression expr = mod.modify(func);
-
- OracleSQLTranslator trans = new OracleSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
-
- SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
- sqlVisitor.append(expr);
- //System.out.println(" expected: " + expectedStr + " \t actual: " + sqlVisitor.toString());
- assertEquals(expectedStr, sqlVisitor.toString());
-
- return expr;
- }
-
- public void test1() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral("1234214", String.class); //$NON-NLS-1$
- ILiteral count = LANG_FACTORY.createLiteral(new Integer(11), Integer.class);
- helpTestMod(arg1, count, "left", //$NON-NLS-1$
- "SUBSTR('1234214', 1, 11)"); //$NON-NLS-1$
- }
-
- public void test2() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral("1234214", String.class); //$NON-NLS-1$
- ILiteral count = LANG_FACTORY.createLiteral(new Integer(2), Integer.class);
- helpTestMod(arg1, count, "right", //$NON-NLS-1$
- "SUBSTR('1234214', (-1 * 2))"); //$NON-NLS-1$
- }
-}
\ No newline at end of file
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLeftOrRightFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestLeftOrRightFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLeftOrRightFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLeftOrRightFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.oracle;
+
+import java.util.Arrays;
+import java.util.Properties;
+
+import org.teiid.connector.jdbc.oracle.LeftOrRightFunctionModifier;
+import org.teiid.connector.jdbc.oracle.OracleSQLTranslator;
+import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
+
+import junit.framework.TestCase;
+
+import com.metamatrix.cdk.CommandBuilder;
+import com.metamatrix.cdk.api.EnvironmentUtility;
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+import com.metamatrix.connector.language.ILiteral;
+
+/**
+ */
+public class TestLeftOrRightFunctionModifier extends TestCase {
+
+ private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
+
+ /**
+ * Constructor for TestHourFunctionModifier.
+ * @param name
+ */
+ public TestLeftOrRightFunctionModifier(String name) {
+ super(name);
+ }
+
+ public IExpression helpTestMod(ILiteral c, ILiteral d, String target, String expectedStr) throws Exception {
+ IFunction func = LANG_FACTORY.createFunction(target,
+ Arrays.asList( c, d ),
+ String.class);
+
+ LeftOrRightFunctionModifier mod = new LeftOrRightFunctionModifier (LANG_FACTORY);
+ IExpression expr = mod.modify(func);
+
+ OracleSQLTranslator trans = new OracleSQLTranslator();
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
+
+ SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
+ sqlVisitor.append(expr);
+ //System.out.println(" expected: " + expectedStr + " \t actual: " + sqlVisitor.toString());
+ assertEquals(expectedStr, sqlVisitor.toString());
+
+ return expr;
+ }
+
+ public void test1() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral("1234214", String.class); //$NON-NLS-1$
+ ILiteral count = LANG_FACTORY.createLiteral(new Integer(11), Integer.class);
+ helpTestMod(arg1, count, "left", //$NON-NLS-1$
+ "SUBSTR('1234214', 1, 11)"); //$NON-NLS-1$
+ }
+
+ public void test2() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral("1234214", String.class); //$NON-NLS-1$
+ ILiteral count = LANG_FACTORY.createLiteral(new Integer(2), Integer.class);
+ helpTestMod(arg1, count, "right", //$NON-NLS-1$
+ "SUBSTR('1234214', (-1 * 2))"); //$NON-NLS-1$
+ }
+}
\ No newline at end of file
Deleted: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLocateFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestLocateFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLocateFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,104 +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 com.metamatrix.connector.jdbc.oracle;
-
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.CommandBuilder;
-import com.metamatrix.cdk.api.EnvironmentUtility;
-import com.metamatrix.connector.jdbc.translator.SQLConversionVisitor;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageFactory;
-
-/**
- */
-public class TestLocateFunctionModifier extends TestCase {
-
- private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
-
- /**
- * Constructor for TestLocateFunctionModifier.
- * @param name
- */
- public TestLocateFunctionModifier(String name) {
- super(name);
- }
-
- public IExpression helpTestMod(IExpression[] args, String expectedStr) throws Exception {
- IFunction func = LANG_FACTORY.createFunction("hour", //$NON-NLS-1$
- args,
- Integer.class);
-
- LocateFunctionModifier mod = new LocateFunctionModifier(LANG_FACTORY);
- IExpression expr = mod.modify(func);
-
- OracleSQLTranslator trans = new OracleSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
-
- SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
- sqlVisitor.append(expr);
-
- assertEquals(expectedStr, sqlVisitor.toString());
-
- return expr;
- }
-
- public void testTwoArgs() throws Exception {
- IExpression[] args = new IExpression[] {
- LANG_FACTORY.createLiteral(".", String.class), //$NON-NLS-1$
- LANG_FACTORY.createLiteral("a.b.c", String.class) //$NON-NLS-1$
- };
- helpTestMod(args, "instr('a.b.c', '.')"); //$NON-NLS-1$
- }
-
- public void testThreeArgsWithConstant() throws Exception {
- IExpression[] args = new IExpression[] {
- LANG_FACTORY.createLiteral(".", String.class), //$NON-NLS-1$
- LANG_FACTORY.createLiteral("a.b.c", String.class), //$NON-NLS-1$
- LANG_FACTORY.createLiteral(new Integer(2), Integer.class)
- };
- helpTestMod(args, "instr('a.b.c', '.', 3)"); //$NON-NLS-1$
- }
-
- public void testThreeArgsWithElement() throws Exception {
- IExpression[] args = new IExpression[] {
- LANG_FACTORY.createLiteral(".", String.class), //$NON-NLS-1$
- LANG_FACTORY.createLiteral("a.b.c", String.class), //$NON-NLS-1$
- LANG_FACTORY.createElement("e1", null, null, Integer.class) //$NON-NLS-1$
- };
- helpTestMod(args, "instr('a.b.c', '.', (e1 + 1))"); //$NON-NLS-1$
- }
-
- public void testThreeArgsWithNull() throws Exception {
- IExpression[] args = new IExpression[] {
- LANG_FACTORY.createLiteral(".", String.class), //$NON-NLS-1$
- LANG_FACTORY.createLiteral("a.b.c", String.class), //$NON-NLS-1$
- LANG_FACTORY.createLiteral(null, Integer.class)
- };
- helpTestMod(args, "instr('a.b.c', '.', NULL)"); //$NON-NLS-1$
- }
-
-}
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLocateFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestLocateFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLocateFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLocateFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.oracle;
+
+import java.util.Arrays;
+import java.util.Properties;
+
+import org.teiid.connector.jdbc.oracle.LocateFunctionModifier;
+import org.teiid.connector.jdbc.oracle.OracleSQLTranslator;
+import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
+
+import junit.framework.TestCase;
+
+import com.metamatrix.cdk.CommandBuilder;
+import com.metamatrix.cdk.api.EnvironmentUtility;
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+
+/**
+ */
+public class TestLocateFunctionModifier extends TestCase {
+
+ private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
+
+ /**
+ * Constructor for TestLocateFunctionModifier.
+ * @param name
+ */
+ public TestLocateFunctionModifier(String name) {
+ super(name);
+ }
+
+ public IExpression helpTestMod(IExpression[] args, String expectedStr) throws Exception {
+ IFunction func = LANG_FACTORY.createFunction("hour", //$NON-NLS-1$
+ Arrays.asList(args),
+ Integer.class);
+
+ LocateFunctionModifier mod = new LocateFunctionModifier(LANG_FACTORY);
+ IExpression expr = mod.modify(func);
+
+ OracleSQLTranslator trans = new OracleSQLTranslator();
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
+
+ SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
+ sqlVisitor.append(expr);
+
+ assertEquals(expectedStr, sqlVisitor.toString());
+
+ return expr;
+ }
+
+ public void testTwoArgs() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(".", String.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral("a.b.c", String.class) //$NON-NLS-1$
+ };
+ helpTestMod(args, "instr('a.b.c', '.')"); //$NON-NLS-1$
+ }
+
+ public void testThreeArgsWithConstant() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(".", String.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral("a.b.c", String.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new Integer(2), Integer.class)
+ };
+ helpTestMod(args, "instr('a.b.c', '.', 3)"); //$NON-NLS-1$
+ }
+
+ public void testThreeArgsWithElement() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(".", String.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral("a.b.c", String.class), //$NON-NLS-1$
+ LANG_FACTORY.createElement("e1", null, null, Integer.class) //$NON-NLS-1$
+ };
+ helpTestMod(args, "instr('a.b.c', '.', (e1 + 1))"); //$NON-NLS-1$
+ }
+
+ public void testThreeArgsWithNull() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(".", String.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral("a.b.c", String.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(null, Integer.class)
+ };
+ helpTestMod(args, "instr('a.b.c', '.', NULL)"); //$NON-NLS-1$
+ }
+
+}
Deleted: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLog10FunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestLog10FunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLog10FunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,69 +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 com.metamatrix.connector.jdbc.oracle;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.CommandBuilder;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILiteral;
-import com.metamatrix.connector.visitor.util.SQLStringVisitor;
-
-/**
- */
-public class TestLog10FunctionModifier extends TestCase {
-
- /**
- * Constructor for TestLog10FunctionModifier.
- * @param name
- */
- public TestLog10FunctionModifier(String name) {
- super(name);
- }
-
- public void testModifier() {
- ILiteral arg = CommandBuilder.getLanuageFactory().createLiteral(new Double(5.2), Double.class);
- IFunction func = CommandBuilder.getLanuageFactory().createFunction("log10", new IExpression[] {arg}, Double.class); //$NON-NLS-1$
-
- Log10FunctionModifier modifier = new Log10FunctionModifier(CommandBuilder.getLanuageFactory());
- IExpression outExpr = modifier.modify(func);
-
- assertTrue(outExpr instanceof IFunction);
- IFunction outFunc = (IFunction) outExpr;
-
- assertEquals("log", outFunc.getName()); //$NON-NLS-1$
- assertEquals(func.getType(), outFunc.getType());
-
- IExpression[] outArgs = func.getParameters();
- assertEquals(2, outArgs.length);
- assertEquals(arg, outArgs[1]);
-
- assertTrue(outArgs[1] instanceof ILiteral);
- ILiteral newArg = (ILiteral) outArgs[0];
- assertEquals(Integer.class, newArg.getType());
- assertEquals(new Integer(10), newArg.getValue());
-
- assertEquals("log(10, 5.2)", SQLStringVisitor.getSQLString(outFunc)); //$NON-NLS-1$
- }
-}
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLog10FunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestLog10FunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLog10FunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLog10FunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.oracle;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.connector.jdbc.oracle.Log10FunctionModifier;
+
+import junit.framework.TestCase;
+
+import com.metamatrix.cdk.CommandBuilder;
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILiteral;
+import com.metamatrix.connector.visitor.util.SQLStringVisitor;
+
+/**
+ */
+public class TestLog10FunctionModifier extends TestCase {
+
+ /**
+ * Constructor for TestLog10FunctionModifier.
+ * @param name
+ */
+ public TestLog10FunctionModifier(String name) {
+ super(name);
+ }
+
+ public void testModifier() {
+ ILiteral arg = CommandBuilder.getLanuageFactory().createLiteral(new Double(5.2), Double.class);
+ IFunction func = CommandBuilder.getLanuageFactory().createFunction("log10", Arrays.asList(arg), Double.class); //$NON-NLS-1$
+
+ Log10FunctionModifier modifier = new Log10FunctionModifier(CommandBuilder.getLanuageFactory());
+ IExpression outExpr = modifier.modify(func);
+
+ assertTrue(outExpr instanceof IFunction);
+ IFunction outFunc = (IFunction) outExpr;
+
+ assertEquals("log", outFunc.getName()); //$NON-NLS-1$
+ assertEquals(func.getType(), outFunc.getType());
+
+ List<IExpression> outArgs = func.getParameters();
+ assertEquals(2, outArgs.size());
+ assertEquals(arg, outArgs.get(1));
+
+ assertTrue(outArgs.get(1) instanceof ILiteral);
+ ILiteral newArg = (ILiteral) outArgs.get(0);
+ assertEquals(Integer.class, newArg.getType());
+ assertEquals(new Integer(10), newArg.getValue());
+
+ assertEquals("log(10, 5.2)", SQLStringVisitor.getSQLString(outFunc)); //$NON-NLS-1$
+ }
+}
Deleted: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestMonthOrDayNameFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestMonthOrDayNameFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestMonthOrDayNameFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,93 +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 com.metamatrix.connector.jdbc.oracle;
-
-import java.sql.Timestamp;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.CommandBuilder;
-import com.metamatrix.cdk.api.EnvironmentUtility;
-import com.metamatrix.connector.jdbc.translator.SQLConversionVisitor;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.connector.language.ILiteral;
-import com.metamatrix.query.unittest.TimestampUtil;
-
-/**
- */
-public class TestMonthOrDayNameFunctionModifier extends TestCase {
-
- private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
-
- /**
- * Constructor for TestHourFunctionModifier.
- * @param name
- */
- public TestMonthOrDayNameFunctionModifier(String name) {
- super(name);
- }
-
- public IExpression helpTestMod(ILiteral c, String format, String expectedStr) throws Exception {
- IFunction func = LANG_FACTORY.createFunction(format.toLowerCase()+"name", // "monthname" //$NON-NLS-1$
- new IExpression[] { c },
- String.class);
-
- MonthOrDayNameFunctionModifier mod = new MonthOrDayNameFunctionModifier (LANG_FACTORY, format);
- IExpression expr = mod.modify(func);
-
- OracleSQLTranslator trans = new OracleSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
-
- SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
- sqlVisitor.append(expr);
- assertEquals(expectedStr, sqlVisitor.toString());
- return expr;
- }
-
- public void test1() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 10, 5, 0, 0), Timestamp.class);
- helpTestMod(arg1, "Month", //$NON-NLS-1$
- "RTRIM(TO_CHAR({ts'2004-01-21 10:05:00.0'}, 'Month'))"); //$NON-NLS-1$
- }
-
- public void test2() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
- helpTestMod(arg1, "Month", //$NON-NLS-1$
- "RTRIM(TO_CHAR({d'2004-01-21'}, 'Month'))"); //$NON-NLS-1$
- }
-
- public void test3() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 10, 5, 0, 0), Timestamp.class);
- helpTestMod(arg1, "Day", //$NON-NLS-1$
- "RTRIM(TO_CHAR({ts'2004-01-21 10:05:00.0'}, 'Day'))"); //$NON-NLS-1$
- }
-
- public void test4() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
- helpTestMod(arg1, "Day", //$NON-NLS-1$
- "RTRIM(TO_CHAR({d'2004-01-21'}, 'Day'))"); //$NON-NLS-1$
- }
-}
\ No newline at end of file
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestMonthOrDayNameFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestMonthOrDayNameFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestMonthOrDayNameFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestMonthOrDayNameFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.oracle;
+
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.Properties;
+
+import org.teiid.connector.jdbc.oracle.MonthOrDayNameFunctionModifier;
+import org.teiid.connector.jdbc.oracle.OracleSQLTranslator;
+import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
+
+import junit.framework.TestCase;
+
+import com.metamatrix.cdk.CommandBuilder;
+import com.metamatrix.cdk.api.EnvironmentUtility;
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+import com.metamatrix.connector.language.ILiteral;
+import com.metamatrix.query.unittest.TimestampUtil;
+
+/**
+ */
+public class TestMonthOrDayNameFunctionModifier extends TestCase {
+
+ private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
+
+ /**
+ * Constructor for TestHourFunctionModifier.
+ * @param name
+ */
+ public TestMonthOrDayNameFunctionModifier(String name) {
+ super(name);
+ }
+
+ public IExpression helpTestMod(ILiteral c, String format, String expectedStr) throws Exception {
+ IFunction func = LANG_FACTORY.createFunction(format.toLowerCase()+"name", // "monthname" //$NON-NLS-1$
+ Arrays.asList( c ),
+ String.class);
+
+ MonthOrDayNameFunctionModifier mod = new MonthOrDayNameFunctionModifier (LANG_FACTORY, format);
+ IExpression expr = mod.modify(func);
+
+ OracleSQLTranslator trans = new OracleSQLTranslator();
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
+
+ SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
+ sqlVisitor.append(expr);
+ assertEquals(expectedStr, sqlVisitor.toString());
+ return expr;
+ }
+
+ public void test1() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 10, 5, 0, 0), Timestamp.class);
+ helpTestMod(arg1, "Month", //$NON-NLS-1$
+ "RTRIM(TO_CHAR({ts'2004-01-21 10:05:00.0'}, 'Month'))"); //$NON-NLS-1$
+ }
+
+ public void test2() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
+ helpTestMod(arg1, "Month", //$NON-NLS-1$
+ "RTRIM(TO_CHAR({d'2004-01-21'}, 'Month'))"); //$NON-NLS-1$
+ }
+
+ public void test3() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 10, 5, 0, 0), Timestamp.class);
+ helpTestMod(arg1, "Day", //$NON-NLS-1$
+ "RTRIM(TO_CHAR({ts'2004-01-21 10:05:00.0'}, 'Day'))"); //$NON-NLS-1$
+ }
+
+ public void test4() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
+ helpTestMod(arg1, "Day", //$NON-NLS-1$
+ "RTRIM(TO_CHAR({d'2004-01-21'}, 'Day'))"); //$NON-NLS-1$
+ }
+}
\ No newline at end of file
Deleted: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleConvertModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,518 +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 com.metamatrix.connector.jdbc.oracle;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.sql.Timestamp;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.CommandBuilder;
-import com.metamatrix.cdk.api.EnvironmentUtility;
-import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.jdbc.translator.SQLConversionVisitor;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.query.unittest.TimestampUtil;
-
-/**
- */
-public class TestOracleConvertModifier extends TestCase {
-
- private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
-
- /**
- * Constructor for TestSybaseConvertModifier.
- * @param name
- */
- public TestOracleConvertModifier(String name) {
- super(name);
- }
-
- public String helpGetString(IExpression expr) throws Exception {
- OracleSQLTranslator trans = new OracleSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
-
- SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
- sqlVisitor.append(expr);
-
- return sqlVisitor.toString();
- }
-
- public void helpTest(IExpression srcExpression, String tgtType, String expectedExpression) throws Exception {
- IFunction func = LANG_FACTORY.createFunction("convert", //$NON-NLS-1$
- new IExpression[] {
- srcExpression,
- LANG_FACTORY.createLiteral(tgtType, String.class)},
- TypeFacility.getDataTypeClass(tgtType));
-
- OracleConvertModifier mod = new OracleConvertModifier(LANG_FACTORY, null);
- IExpression expr = mod.modify(func);
-
- assertEquals("Error converting from " + srcExpression.getType() + " to " + tgtType, //$NON-NLS-1$ //$NON-NLS-2$
- expectedExpression, helpGetString(expr));
- }
-
- // Source = STRING
-
- public void testStringToChar() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "char", "'5'"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "boolean", "decode('5', 'true', 1, 'false', 0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "byte", "to_number('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "short", "to_number('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "integer", "to_number('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "long", "to_number('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "biginteger", "to_number('5')"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "float", "to_number('5')");//$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "double", "to_number('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToDate() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("2004-06-29", String.class), "date", "to_date('2004-06-29', 'YYYY-MM-DD')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToTime() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("23:59:59", String.class), "time", "to_date(('1970-01-01 ' || to_char('23:59:59', 'HH24:MI:SS')), 'YYYY-MM-DD HH24:MI:SS')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToTimestamp() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("2004-06-29 23:59:59.987", String.class), "timestamp", "to_timestamp('2004-06-29 23:59:59.987', 'YYYY-MM-DD HH24:MI:SS.FF')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "bigdecimal", "to_number('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- // Source = CHAR
-
- public void testCharToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Character('5'), Character.class), "string", "'5'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = BOOLEAN
-
- public void testBooleanToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "string", "decode(1, 0, 'false', 1, 'true')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "byte", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "short", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = BYTE
-
- public void testByteToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "string", "to_char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "boolean", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "short", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = SHORT
-
- public void testShortToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "string", "to_char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "boolean", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "byte", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = INTEGER
-
- public void testIntegerToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "string", "to_char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "boolean", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "byte", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "short", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = LONG
-
- public void testLongToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "string", "to_char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "boolean", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "byte", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "short", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = BIGINTEGER
-
- public void testBigIntegerToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "string", "to_char(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "boolean", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "byte", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "short", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigIntegerToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- // Source = FLOAT
-
- public void testFloatToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "string", "to_char(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "boolean", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "byte", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "short", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "integer", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "long", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "biginteger", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "double", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "bigdecimal", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = DOUBLE
-
- public void testDoubleToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "string", "to_char(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "boolean", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "byte", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "short", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "integer", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "long", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "biginteger", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "float", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "bigdecimal", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = BIGDECIMAL
-
- public void testBigDecimalToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "string", "to_char(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "boolean", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "byte", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "short", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "integer", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "long", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "biginteger", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "float", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testBigDecimalToDoublel() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "double", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- // Source = DATE
-
- public void testDateToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createDate(103, 10, 1), java.sql.Date.class), "string", "to_char({d'2003-11-01'}, 'YYYY-MM-DD')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDateToTimestamp() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createDate(103, 10, 1), java.sql.Date.class), "timestamp", "cast({d'2003-11-01'} AS timestamp)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = TIME
-
- public void testTimeToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createTime(23, 59, 59), java.sql.Time.class), "string", "to_char({ts'1970-01-01 23:59:59'}, 'HH24:MI:SS')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testTimeToTimestamp() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createTime(23, 59, 59), java.sql.Time.class), "timestamp", "cast({ts'1970-01-01 23:59:59'} AS timestamp)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = TIMESTAMP
-
- public void testTimestampToString() throws Exception {
- Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
- helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "string", "to_char({ts'2003-11-01 12:05:02.0'}, 'YYYY-MM-DD HH24:MI:SS.FF')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testTimestampToDate() throws Exception {
- Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
- helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "date", "trunc({ts'2003-11-01 12:05:02.0'})"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testTimestampToTime() throws Exception {
- Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
- helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "time", "to_date(('1970-01-01 ' || to_char({ts'2003-11-01 12:05:02.0'}, 'HH24:MI:SS')), 'YYYY-MM-DD HH24:MI:SS')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-}
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleConvertModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleConvertModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleConvertModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,522 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.oracle;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.Properties;
+
+import org.teiid.connector.jdbc.oracle.OracleConvertModifier;
+import org.teiid.connector.jdbc.oracle.OracleSQLTranslator;
+import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
+
+import junit.framework.TestCase;
+
+import com.metamatrix.cdk.CommandBuilder;
+import com.metamatrix.cdk.api.EnvironmentUtility;
+import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+import com.metamatrix.query.unittest.TimestampUtil;
+
+/**
+ */
+public class TestOracleConvertModifier extends TestCase {
+
+ private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
+
+ /**
+ * Constructor for TestSybaseConvertModifier.
+ * @param name
+ */
+ public TestOracleConvertModifier(String name) {
+ super(name);
+ }
+
+ public String helpGetString(IExpression expr) throws Exception {
+ OracleSQLTranslator trans = new OracleSQLTranslator();
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
+
+ SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
+ sqlVisitor.append(expr);
+
+ return sqlVisitor.toString();
+ }
+
+ public void helpTest(IExpression srcExpression, String tgtType, String expectedExpression) throws Exception {
+ IFunction func = LANG_FACTORY.createFunction("convert", //$NON-NLS-1$
+ Arrays.asList(
+ srcExpression,
+ LANG_FACTORY.createLiteral(tgtType, String.class)),
+ TypeFacility.getDataTypeClass(tgtType));
+
+ OracleConvertModifier mod = new OracleConvertModifier(LANG_FACTORY, null);
+ IExpression expr = mod.modify(func);
+
+ assertEquals("Error converting from " + srcExpression.getType() + " to " + tgtType, //$NON-NLS-1$ //$NON-NLS-2$
+ expectedExpression, helpGetString(expr));
+ }
+
+ // Source = STRING
+
+ public void testStringToChar() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "char", "'5'"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "boolean", "decode('5', 'true', 1, 'false', 0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "byte", "to_number('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "short", "to_number('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "integer", "to_number('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "long", "to_number('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "biginteger", "to_number('5')"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "float", "to_number('5')");//$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "double", "to_number('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToDate() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("2004-06-29", String.class), "date", "to_date('2004-06-29', 'YYYY-MM-DD')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToTime() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("23:59:59", String.class), "time", "to_date(('1970-01-01 ' || to_char('23:59:59', 'HH24:MI:SS')), 'YYYY-MM-DD HH24:MI:SS')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToTimestamp() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("2004-06-29 23:59:59.987", String.class), "timestamp", "to_timestamp('2004-06-29 23:59:59.987', 'YYYY-MM-DD HH24:MI:SS.FF')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testStringToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "bigdecimal", "to_number('5')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ // Source = CHAR
+
+ public void testCharToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Character('5'), Character.class), "string", "'5'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = BOOLEAN
+
+ public void testBooleanToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "string", "decode(1, 0, 'false', 1, 'true')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "byte", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "short", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = BYTE
+
+ public void testByteToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "string", "to_char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "boolean", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "short", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = SHORT
+
+ public void testShortToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "string", "to_char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "boolean", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "byte", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = INTEGER
+
+ public void testIntegerToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "string", "to_char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "boolean", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "byte", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "short", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = LONG
+
+ public void testLongToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "string", "to_char(1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "boolean", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "byte", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "short", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "biginteger", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = BIGINTEGER
+
+ public void testBigIntegerToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "string", "to_char(1)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "boolean", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "byte", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "short", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "integer", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "long", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "float", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigIntegerToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "bigdecimal", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ // Source = FLOAT
+
+ public void testFloatToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "string", "to_char(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "boolean", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "byte", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "short", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "integer", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "long", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "biginteger", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "double", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "bigdecimal", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = DOUBLE
+
+ public void testDoubleToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "string", "to_char(1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "boolean", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "byte", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "short", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "integer", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "long", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "biginteger", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "float", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "bigdecimal", "1.2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = BIGDECIMAL
+
+ public void testBigDecimalToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "string", "to_char(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "boolean", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "byte", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "short", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "integer", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "long", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "biginteger", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "float", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testBigDecimalToDoublel() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "double", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ // Source = DATE
+
+ public void testDateToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createDate(103, 10, 1), java.sql.Date.class), "string", "to_char({d'2003-11-01'}, 'YYYY-MM-DD')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDateToTimestamp() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createDate(103, 10, 1), java.sql.Date.class), "timestamp", "cast({d'2003-11-01'} AS timestamp)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = TIME
+
+ public void testTimeToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createTime(23, 59, 59), java.sql.Time.class), "string", "to_char({ts'1970-01-01 23:59:59'}, 'HH24:MI:SS')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testTimeToTimestamp() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createTime(23, 59, 59), java.sql.Time.class), "timestamp", "cast({ts'1970-01-01 23:59:59'} AS timestamp)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = TIMESTAMP
+
+ public void testTimestampToString() throws Exception {
+ Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
+ helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "string", "to_char({ts'2003-11-01 12:05:02.0'}, 'YYYY-MM-DD HH24:MI:SS.FF')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testTimestampToDate() throws Exception {
+ Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
+ helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "date", "trunc({ts'2003-11-01 12:05:02.0'})"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testTimestampToTime() throws Exception {
+ Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
+ helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "time", "to_date(('1970-01-01 ' || to_char({ts'2003-11-01 12:05:02.0'}, 'HH24:MI:SS')), 'YYYY-MM-DD HH24:MI:SS')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+}
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleTranslator.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleTranslator.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,18 +20,20 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.oracle;
+package org.teiid.connector.jdbc.oracle;
import java.util.Properties;
+import org.teiid.connector.jdbc.access.AccessSQLTranslator;
+import org.teiid.connector.jdbc.oracle.OracleSQLTranslator;
+import org.teiid.connector.jdbc.translator.TranslatedCommand;
+import org.teiid.connector.jdbc.translator.Translator;
+
import junit.framework.TestCase;
import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.cdk.unittest.FakeTranslationFactory;
import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.jdbc.access.AccessSQLTranslator;
-import com.metamatrix.connector.jdbc.translator.TranslatedCommand;
-import com.metamatrix.connector.jdbc.translator.Translator;
import com.metamatrix.connector.language.ICommand;
public class TestOracleTranslator extends TestCase {
Deleted: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestSubstringFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestSubstringFunctionModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestSubstringFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -1,105 +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 com.metamatrix.connector.jdbc.oracle;
-
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.CommandBuilder;
-import com.metamatrix.cdk.api.EnvironmentUtility;
-import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.jdbc.translator.FunctionModifier;
-import com.metamatrix.connector.jdbc.translator.SQLConversionVisitor;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageFactory;
-
-/**
- */
-public class TestSubstringFunctionModifier extends TestCase {
-
- private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
-
-
- /**
- * Constructor for TestSubstringFunctionModifier.
- * @param name
- */
- public TestSubstringFunctionModifier(String name) {
- super(name);
- }
-
- public IExpression helpTestMod(IExpression[] args, String expectedStr) throws Exception {
- IFunction func = LANG_FACTORY.createFunction("substring", //$NON-NLS-1$
- args, TypeFacility.RUNTIME_TYPES.STRING);
-
- OracleSQLTranslator trans = new OracleSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
-
- IExpression expr = ((FunctionModifier)trans.getFunctionModifiers().get("substring")).modify(func); //$NON-NLS-1$
-
- SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
- sqlVisitor.append(expr);
-
- assertEquals(expectedStr, sqlVisitor.toString());
-
- return expr;
- }
-
- public void testTwoArgs() throws Exception {
- IExpression[] args = new IExpression[] {
- LANG_FACTORY.createLiteral("a.b.c", String.class), //$NON-NLS-1$
- LANG_FACTORY.createLiteral(new Integer(1), Integer.class)
- };
- helpTestMod(args, "substr('a.b.c', 1)"); //$NON-NLS-1$
- }
-
- public void testThreeArgsWithConstant() throws Exception {
- IExpression[] args = new IExpression[] {
- LANG_FACTORY.createLiteral("a.b.c", String.class), //$NON-NLS-1$
- LANG_FACTORY.createLiteral(new Integer(3), Integer.class),
- LANG_FACTORY.createLiteral(new Integer(1), Integer.class)
- };
- helpTestMod(args, "substr('a.b.c', 3, 1)"); //$NON-NLS-1$
- }
-
- public void testThreeArgsWithElement() throws Exception {
- IExpression[] args = new IExpression[] {
- LANG_FACTORY.createLiteral("a.b.c", String.class), //$NON-NLS-1$
- LANG_FACTORY.createElement("e1", null, null, Integer.class), //$NON-NLS-1$
- LANG_FACTORY.createLiteral(new Integer(1), Integer.class)
- };
- helpTestMod(args, "substr('a.b.c', e1, 1)"); //$NON-NLS-1$
- }
-
- public void testThreeArgsWithNull() throws Exception {
- IExpression[] args = new IExpression[] {
- LANG_FACTORY.createLiteral("a.b.c", String.class), //$NON-NLS-1$
- LANG_FACTORY.createLiteral(null, Integer.class),
- LANG_FACTORY.createLiteral(new Integer(5), Integer.class)
- };
- helpTestMod(args, "substr('a.b.c', NULL, 5)"); //$NON-NLS-1$
- }
-
-}
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestSubstringFunctionModifier.java (from rev 488, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestSubstringFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestSubstringFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestSubstringFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.oracle;
+
+import java.util.Arrays;
+import java.util.Properties;
+
+import org.teiid.connector.jdbc.oracle.OracleSQLTranslator;
+import org.teiid.connector.jdbc.translator.FunctionModifier;
+import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
+
+import junit.framework.TestCase;
+
+import com.metamatrix.cdk.CommandBuilder;
+import com.metamatrix.cdk.api.EnvironmentUtility;
+import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.language.IExpression;
+import com.metamatrix.connector.language.IFunction;
+import com.metamatrix.connector.language.ILanguageFactory;
+
+/**
+ */
+public class TestSubstringFunctionModifier extends TestCase {
+
+ private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
+
+
+ /**
+ * Constructor for TestSubstringFunctionModifier.
+ * @param name
+ */
+ public TestSubstringFunctionModifier(String name) {
+ super(name);
+ }
+
+ public IExpression helpTestMod(IExpression[] args, String expectedStr) throws Exception {
+ IFunction func = LANG_FACTORY.createFunction("substring", //$NON-NLS-1$
+ Arrays.asList(args), TypeFacility.RUNTIME_TYPES.STRING);
+
+ OracleSQLTranslator trans = new OracleSQLTranslator();
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
+
+ IExpression expr = ((FunctionModifier)trans.getFunctionModifiers().get("substring")).modify(func); //$NON-NLS-1$
+
+ SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
+ sqlVisitor.append(expr);
+
+ assertEquals(expectedStr, sqlVisitor.toString());
+
+ return expr;
+ }
+
+ public void testTwoArgs() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral("a.b.c", String.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new Integer(1), Integer.class)
+ };
+ helpTestMod(args, "substr('a.b.c', 1)"); //$NON-NLS-1$
+ }
+
+ public void testThreeArgsWithConstant() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral("a.b.c", String.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new Integer(3), Integer.class),
+ LANG_FACTORY.createLiteral(new Integer(1), Integer.class)
+ };
+ helpTestMod(args, "substr('a.b.c', 3, 1)"); //$NON-NLS-1$
+ }
+
+ public void testThreeArgsWithElement() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral("a.b.c", String.class), //$NON-NLS-1$
+ LANG_FACTORY.createElement("e1", null, null, Integer.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new Integer(1), Integer.class)
+ };
+ helpTestMod(args, "substr('a.b.c', e1, 1)"); //$NON-NLS-1$
+ }
+
+ public void testThreeArgsWithNull() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral("a.b.c", String.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(null, Integer.class),
+ LANG_FACTORY.createLiteral(new Integer(5), Integer.class)
+ };
+ helpTestMod(args, "substr('a.b.c', NULL, 5)"); //$NON-NLS-1$
+ }
+
+}
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql (from rev 486, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/postgresql)
Property changes on: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/postgresql/TestPostgreSQLTranslator.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,17 +20,19 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.postgresql;
+package org.teiid.connector.jdbc.postgresql;
import java.util.Map;
import java.util.Properties;
+import org.teiid.connector.jdbc.MetadataFactory;
+import org.teiid.connector.jdbc.postgresql.PostgreSQLTranslator;
+import org.teiid.connector.jdbc.translator.TranslatedCommand;
+
import junit.framework.TestCase;
import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.jdbc.MetadataFactory;
-import com.metamatrix.connector.jdbc.translator.TranslatedCommand;
import com.metamatrix.connector.language.ICommand;
/**
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver (from rev 486, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sqlserver)
Property changes on: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,19 +20,21 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.sqlserver;
+package org.teiid.connector.jdbc.sqlserver;
import java.util.Map;
import java.util.Properties;
+import org.teiid.connector.jdbc.MetadataFactory;
+import org.teiid.connector.jdbc.sqlserver.SqlServerSQLTranslator;
+import org.teiid.connector.jdbc.translator.FunctionReplacementVisitor;
+import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
+import org.teiid.connector.jdbc.translator.TranslatedCommand;
+
import junit.framework.TestCase;
import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.jdbc.MetadataFactory;
-import com.metamatrix.connector.jdbc.translator.SQLConversionVisitor;
-import com.metamatrix.connector.jdbc.translator.TranslatedCommand;
-import com.metamatrix.connector.jdbc.util.FunctionReplacementVisitor;
import com.metamatrix.connector.language.ICommand;
/**
@@ -84,7 +86,7 @@
SqlServerSQLTranslator trans = new SqlServerSQLTranslator();
trans.initialize(EnvironmentUtility.createEnvironment(props, false));
// Convert back to SQL
- SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
+ SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
TranslatedCommand tc = new TranslatedCommand(EnvironmentUtility.createSecurityContext("user"), trans, sqlVisitor, funcVisitor); //$NON-NLS-1$
tc.translateCommand(obj);
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase (from rev 486, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase)
Property changes on: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/TestSybaseConvertModifier.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseConvertModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,19 +20,22 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.sybase;
+package org.teiid.connector.jdbc.sybase;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Timestamp;
import java.util.Properties;
+import org.teiid.connector.jdbc.sybase.SybaseConvertModifier;
+import org.teiid.connector.jdbc.sybase.SybaseSQLTranslator;
+import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
+
import junit.framework.TestCase;
import com.metamatrix.cdk.CommandBuilder;
import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.connector.jdbc.translator.SQLConversionVisitor;
import com.metamatrix.connector.language.IExpression;
import com.metamatrix.connector.language.IFunction;
import com.metamatrix.connector.language.ILanguageFactory;
@@ -57,7 +60,7 @@
SybaseSQLTranslator trans = new SybaseSQLTranslator();
trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
- SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
+ SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
sqlVisitor.append(expr);
return sqlVisitor.toString();
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,18 +20,20 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.sybase;
+package org.teiid.connector.jdbc.sybase;
import java.util.Properties;
+import org.teiid.connector.jdbc.MetadataFactory;
+import org.teiid.connector.jdbc.sybase.SybaseSQLTranslator;
+import org.teiid.connector.jdbc.translator.FunctionReplacementVisitor;
+import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
+import org.teiid.connector.jdbc.translator.TranslatedCommand;
+
import junit.framework.TestCase;
import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.jdbc.MetadataFactory;
-import com.metamatrix.connector.jdbc.translator.SQLConversionVisitor;
-import com.metamatrix.connector.jdbc.translator.TranslatedCommand;
-import com.metamatrix.connector.jdbc.util.FunctionReplacementVisitor;
import com.metamatrix.connector.language.ICommand;
/**
@@ -68,7 +70,7 @@
FunctionReplacementVisitor funcVisitor = new FunctionReplacementVisitor(trans.getFunctionModifiers());
// Convert back to SQL
- SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
+ SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
TranslatedCommand tc = new TranslatedCommand(EnvironmentUtility.createSecurityContext("user"), trans, sqlVisitor, funcVisitor);
try {
tc.translateCommand(obj);
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/util (from rev 486, trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/util)
Property changes on: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/util
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/util/TestFunctionReplacementVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/util/TestFunctionReplacementVisitor.java 2009-02-24 14:21:49 UTC (rev 486)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/util/TestFunctionReplacementVisitor.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -20,15 +20,17 @@
* 02110-1301 USA.
*/
-package com.metamatrix.connector.jdbc.util;
+package org.teiid.connector.jdbc.util;
import java.util.HashMap;
import java.util.Map;
+import org.teiid.connector.jdbc.MetadataFactory;
+import org.teiid.connector.jdbc.translator.DropFunctionModifier;
+import org.teiid.connector.jdbc.translator.FunctionReplacementVisitor;
+
import junit.framework.TestCase;
-import com.metamatrix.connector.jdbc.MetadataFactory;
-import com.metamatrix.connector.jdbc.translator.DropFunctionModifier;
import com.metamatrix.connector.language.ICommand;
/**
Modified: trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialCapabilities.java
===================================================================
--- trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialCapabilities.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialCapabilities.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -22,9 +22,10 @@
package com.metamatrix.connector.jdbc.oracle.spatial;
-import com.metamatrix.connector.jdbc.oracle.*;
import java.util.*;
+import org.teiid.connector.jdbc.oracle.*;
+
public class OracleSpatialCapabilities extends OracleCapabilities {
public List getSupportedFunctions() {
Modified: trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialConnector.java
===================================================================
--- trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialConnector.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialConnector.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -28,10 +28,11 @@
*/
package com.metamatrix.connector.jdbc.oracle.spatial;
+import org.teiid.connector.jdbc.JDBCConnector;
+
import com.metamatrix.connector.api.ConnectorCapabilities;
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.jdbc.JDBCConnector;
public class OracleSpatialConnector extends JDBCConnector {
Modified: trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialFunctionModifier.java
===================================================================
--- trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialFunctionModifier.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialFunctionModifier.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -24,7 +24,8 @@
import java.util.List;
-import com.metamatrix.connector.jdbc.translator.BasicFunctionModifier;
+import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
+
import com.metamatrix.connector.language.IExpression;
import com.metamatrix.connector.language.IFunction;
import com.metamatrix.connector.language.ILiteral;
Modified: trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialSQLTranslator.java
===================================================================
--- trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialSQLTranslator.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialSQLTranslator.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -26,11 +26,12 @@
import java.util.Iterator;
import java.util.List;
+import org.teiid.connector.jdbc.translator.Translator;
+
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.ExecutionContext;
import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.jdbc.translator.Translator;
import com.metamatrix.connector.language.ICommand;
import com.metamatrix.connector.language.ICriteria;
import com.metamatrix.connector.language.IFunction;
Modified: trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/Request.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/Request.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/Request.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -416,7 +416,7 @@
}
if (tc != null){
- Assertion.assertTrue(tc.getTransactionType() != TransactionContext.TRANSACTION_REQUEST);
+ Assertion.assertTrue(tc.getTransactionType() != TransactionContext.Scope.TRANSACTION_REQUEST, "Transaction already associated with request."); //$NON-NLS-1$
}
if (tc == null || !tc.isInTransaction()) {
Modified: trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/RequestWorkItem.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/RequestWorkItem.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/RequestWorkItem.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -285,7 +285,7 @@
this.transactionState = TransactionState.END;
}
}
- if (this.transactionState == TransactionState.END && transactionContext.getTransactionType() == TransactionContext.TRANSACTION_REQUEST) {
+ if (this.transactionState == TransactionState.END && transactionContext.getTransactionType() == TransactionContext.Scope.TRANSACTION_REQUEST) {
this.transactionService.getTransactionServer().commit(transactionContext);
this.transactionState = TransactionState.DONE;
}
@@ -345,7 +345,7 @@
this.transactionState = TransactionState.END;
}
- if (this.transactionState == TransactionState.END && transactionContext.getTransactionType() == TransactionContext.TRANSACTION_REQUEST) {
+ if (this.transactionState == TransactionState.END && transactionContext.getTransactionType() == TransactionContext.Scope.TRANSACTION_REQUEST) {
this.transactionState = TransactionState.DONE;
try {
this.transactionService.getTransactionServer().rollback(transactionContext);
Modified: trunk/engine/src/main/java/com/metamatrix/dqp/internal/transaction/TransactionContextImpl.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/internal/transaction/TransactionContextImpl.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/internal/transaction/TransactionContextImpl.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -45,7 +45,7 @@
private MMXid xid;
private String txnID;
private Transaction transaction;
- private int transactionType = TRANSACTION_NONE;
+ private Scope transactionType = Scope.TRANSACTION_NONE;
private Set suspendedBy = Collections.newSetFromMap(new ConcurrentHashMap());
private int transactionTimeout = -1;
private Set xaResources = Collections.newSetFromMap(new ConcurrentHashMap());
@@ -79,11 +79,11 @@
return this.txnID;
}
- void setTransactionType(int transactionType) {
+ void setTransactionType(Scope transactionType) {
this.transactionType = transactionType;
}
- public int getTransactionType() {
+ public Scope getTransactionType() {
return transactionType;
}
Modified: trunk/engine/src/main/java/com/metamatrix/dqp/internal/transaction/TransactionServerImpl.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/internal/transaction/TransactionServerImpl.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/internal/transaction/TransactionServerImpl.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -42,7 +42,6 @@
import com.metamatrix.common.xa.MMXid;
import com.metamatrix.common.xa.XATransactionException;
import com.metamatrix.connector.xa.api.TransactionContext;
-import com.metamatrix.connector.xa.api.XAConnector;
import com.metamatrix.core.util.Assertion;
import com.metamatrix.dqp.DQPPlugin;
import com.metamatrix.dqp.internal.transaction.TransactionProvider.XAConnectionSource;
@@ -228,7 +227,7 @@
case XAResource.TMNOFLAGS: {
checkXAState(threadId, xid, false, false);
tc = transactions.getOrCreateTransactionContext(threadId);
- if (tc.getTransactionType() != TransactionContext.TRANSACTION_NONE) {
+ if (tc.getTransactionType() != TransactionContext.Scope.TRANSACTION_NONE) {
throw new XATransactionException(XAException.XAER_PROTO, DQPPlugin.Util.getString("TransactionServer.existing_transaction")); //$NON-NLS-1$
}
Transaction tx;
@@ -255,14 +254,14 @@
tc.setTransaction(tx, provider.getTransactionID(tx));
tc.setTransactionTimeout(timeout);
tc.setXid(xid);
- tc.setTransactionType(TransactionContext.TRANSACTION_GLOBAL);
+ tc.setTransactionType(TransactionContext.Scope.TRANSACTION_GLOBAL);
break;
}
case XAResource.TMJOIN:
case XAResource.TMRESUME: {
tc = checkXAState(threadId, xid, true, false);
TransactionContextImpl threadContext = transactions.getOrCreateTransactionContext(threadId);
- if (threadContext.getTransactionType() != TransactionContext.TRANSACTION_NONE) {
+ if (threadContext.getTransactionType() != TransactionContext.Scope.TRANSACTION_NONE) {
throw new XATransactionException(XAException.XAER_PROTO, DQPPlugin.Util.getString("TransactionServer.existing_transaction")); //$NON-NLS-1$
}
@@ -323,7 +322,7 @@
}
if (!threadBound) {
tc = transactions.getOrCreateTransactionContext(threadId);
- if (tc.getTransactionType() != TransactionContext.TRANSACTION_NONE) {
+ if (tc.getTransactionType() != TransactionContext.Scope.TRANSACTION_NONE) {
throw new XATransactionException(XAException.XAER_PROTO, DQPPlugin.Util.getString("TransactionServer.existing_transaction", new Object[] {xid, threadId})); //$NON-NLS-1$
}
}
@@ -350,8 +349,8 @@
final TransactionManager tm = getTransactionManager();
- if (tc.getTransactionType() != TransactionContext.TRANSACTION_NONE) {
- if (tc.getTransactionType() != TransactionContext.TRANSACTION_LOCAL) {
+ if (tc.getTransactionType() != TransactionContext.Scope.TRANSACTION_NONE) {
+ if (tc.getTransactionType() != TransactionContext.Scope.TRANSACTION_LOCAL) {
throw new NotSupportedException(DQPPlugin.Util.getString("TransactionServer.existing_transaction")); //$NON-NLS-1$
}
if (!transactionExpected) {
@@ -372,7 +371,7 @@
tm.begin();
Transaction tx = tm.suspend();
tc.setTransaction(tx, provider.getTransactionID(tx));
- tc.setTransactionType(TransactionContext.TRANSACTION_LOCAL);
+ tc.setTransactionType(TransactionContext.Scope.TRANSACTION_LOCAL);
return tc;
} catch (InvalidTransactionException err) {
throw new XATransactionException(err);
@@ -446,14 +445,14 @@
TransactionContextImpl tc = (TransactionContextImpl)context;
try {
- if (tc.getTransactionType() != TransactionContext.TRANSACTION_NONE) {
+ if (tc.getTransactionType() != TransactionContext.Scope.TRANSACTION_NONE) {
throw new XATransactionException(DQPPlugin.Util.getString("TransactionServer.existing_transaction")); //$NON-NLS-1$
}
tm.begin();
Transaction tx = tm.suspend();
tc.setTransaction(tx, provider.getTransactionID(tx));
- tc.setTransactionType(TransactionContext.TRANSACTION_REQUEST);
+ tc.setTransactionType(TransactionContext.Scope.TRANSACTION_REQUEST);
return tc;
} catch (NotSupportedException e) {
throw new XATransactionException(e);
@@ -461,13 +460,13 @@
}
public TransactionContext commit(TransactionContext context) throws XATransactionException, SystemException {
- Assertion.assertTrue(context.getTransactionType() == TransactionContext.TRANSACTION_REQUEST);
+ Assertion.assertTrue(context.getTransactionType() == TransactionContext.Scope.TRANSACTION_REQUEST);
TransactionContextImpl tc = (TransactionContextImpl)context;
//commit may be called multiple times by the processworker, if this is a subsequent call, then the current
//context will not be active
TransactionContextImpl currentContext = transactions.getTransactionContext(tc.getThreadId());
- if (currentContext == null || currentContext.getTransactionType() == TransactionContext.TRANSACTION_NONE) {
+ if (currentContext == null || currentContext.getTransactionType() == TransactionContext.Scope.TRANSACTION_NONE) {
return currentContext;
}
TransactionManager tm = getTransactionManager();
@@ -494,7 +493,7 @@
}
public TransactionContext rollback(TransactionContext context) throws XATransactionException, SystemException {
- Assertion.assertTrue(context.getTransactionType() == TransactionContext.TRANSACTION_REQUEST);
+ Assertion.assertTrue(context.getTransactionType() == TransactionContext.Scope.TRANSACTION_REQUEST);
TransactionManager tm = getTransactionManager();
try {
tm.resume(context.getTransaction());
@@ -584,11 +583,11 @@
public void cancelTransactions(String threadId, boolean requestOnly) throws InvalidTransactionException, SystemException {
TransactionContextImpl tc = transactions.getTransactionContext(threadId);
- if (tc == null || tc.getTransactionType() == TransactionContext.TRANSACTION_NONE) {
+ if (tc == null || tc.getTransactionType() == TransactionContext.Scope.TRANSACTION_NONE) {
return;
}
- if (requestOnly && tc.getTransactionType() != TransactionContext.TRANSACTION_REQUEST) {
+ if (requestOnly && tc.getTransactionType() != TransactionContext.Scope.TRANSACTION_REQUEST) {
return;
}
Modified: trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java
===================================================================
--- trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -26,17 +26,18 @@
import java.util.Map;
import java.util.Properties;
+import org.teiid.connector.jdbc.JDBCPropertyNames;
+import org.teiid.connector.jdbc.translator.FunctionReplacementVisitor;
+import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
+import org.teiid.connector.jdbc.translator.TranslatedCommand;
+import org.teiid.connector.jdbc.translator.Translator;
+
import junit.framework.TestCase;
import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.cdk.api.TranslationUtility;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.ExecutionContext;
-import com.metamatrix.connector.jdbc.JDBCPropertyNames;
-import com.metamatrix.connector.jdbc.translator.SQLConversionVisitor;
-import com.metamatrix.connector.jdbc.translator.TranslatedCommand;
-import com.metamatrix.connector.jdbc.translator.Translator;
-import com.metamatrix.connector.jdbc.util.FunctionReplacementVisitor;
import com.metamatrix.connector.language.ICommand;
import com.metamatrix.connector.language.ILanguageObject;
import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
@@ -120,7 +121,7 @@
props.setProperty(JDBCPropertyNames.USE_COMMENTS_SOURCE_QUERY, Boolean.TRUE.toString());
Translator trans = new Translator();
trans.initialize(EnvironmentUtility.createEnvironment(props, false));
- SQLConversionVisitor visitor = new SQLConversionVisitor(trans);
+ SQLConversionVisitor visitor = trans.getSQLConversionVisitor();
visitor.setExecutionContext(context);
visitor.append(obj);
return visitor.toString();
@@ -146,7 +147,7 @@
}
trans.initialize(EnvironmentUtility.createEnvironment(p, false));
// Convert back to SQL
- SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
+ SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
TranslatedCommand tc = new TranslatedCommand(new FakeExecutionContextImpl(), trans, sqlVisitor, funcVisitor);
tc.translateCommand(obj);
Modified: trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java
===================================================================
--- trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -25,6 +25,13 @@
import java.util.Map;
import java.util.Properties;
+import org.teiid.connector.jdbc.JDBCPropertyNames;
+import org.teiid.connector.jdbc.oracle.ExtractFunctionModifier;
+import org.teiid.connector.jdbc.oracle.OracleSQLTranslator;
+import org.teiid.connector.jdbc.translator.FunctionReplacementVisitor;
+import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
+import org.teiid.connector.jdbc.translator.TranslatedCommand;
+
import junit.framework.TestCase;
import com.metamatrix.cdk.CommandBuilder;
@@ -33,10 +40,6 @@
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.ExecutionContext;
-import com.metamatrix.connector.jdbc.JDBCPropertyNames;
-import com.metamatrix.connector.jdbc.translator.SQLConversionVisitor;
-import com.metamatrix.connector.jdbc.translator.TranslatedCommand;
-import com.metamatrix.connector.jdbc.util.FunctionReplacementVisitor;
import com.metamatrix.connector.language.ICommand;
import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
import com.metamatrix.core.util.UnitTestUtil;
@@ -121,7 +124,7 @@
}
translator.initialize(EnvironmentUtility.createEnvironment(p, false));
// Convert back to SQL
- SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(translator);
+ SQLConversionVisitor sqlVisitor = translator.getSQLConversionVisitor();
sqlVisitor.setExecutionContext(context);
TranslatedCommand tc = new TranslatedCommand(context, translator, sqlVisitor, funcVisitor);
tc.translateCommand(obj);
Modified: trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/util/TestJDBCExecutionHelper.java
===================================================================
--- trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/util/TestJDBCExecutionHelper.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/util/TestJDBCExecutionHelper.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -28,6 +28,8 @@
import java.util.ArrayList;
import java.util.List;
+import org.teiid.connector.jdbc.JDBCExecutionHelper;
+
import junit.framework.TestCase;
import com.metamatrix.common.types.DataTypeManager;
Modified: trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestTPCR.java
===================================================================
--- trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestTPCR.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestTPCR.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -25,8 +25,9 @@
import java.util.Arrays;
import java.util.List;
-import com.metamatrix.connector.jdbc.oracle.OracleCapabilities;
-import com.metamatrix.connector.jdbc.sqlserver.SqlServerCapabilities;
+import org.teiid.connector.jdbc.oracle.OracleCapabilities;
+import org.teiid.connector.jdbc.sqlserver.SqlServerCapabilities;
+
import com.metamatrix.core.util.UnitTestUtil;
import com.metamatrix.dqp.internal.datamgr.CapabilitiesConverter;
import com.metamatrix.query.metadata.QueryMetadataInterface;
Modified: trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestXMLTypeTranslations.java
===================================================================
--- trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestXMLTypeTranslations.java 2009-02-24 16:41:35 UTC (rev 490)
+++ trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestXMLTypeTranslations.java 2009-02-24 18:28:11 UTC (rev 491)
@@ -28,7 +28,8 @@
import java.util.List;
import java.util.Set;
-import com.metamatrix.connector.jdbc.oracle.OracleCapabilities;
+import org.teiid.connector.jdbc.oracle.OracleCapabilities;
+
import com.metamatrix.core.util.UnitTestUtil;
import com.metamatrix.dqp.internal.datamgr.CapabilitiesConverter;
import com.metamatrix.query.metadata.QueryMetadataInterface;
15 years, 10 months
teiid SVN: r490 - in trunk: adminshell and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-02-24 11:41:35 -0500 (Tue, 24 Feb 2009)
New Revision: 490
Added:
trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/Util.java
Removed:
trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestHelper.java
Modified:
trunk/adminshell/pom.xml
trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestMultiFileTextSynchExecution.java
trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestRowHeaderTextSynchExecution.java
trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestTextSynchExecution.java
trunk/pom.xml
Log:
TEIID-380 upgrade to junit 4.4
Modified: trunk/adminshell/pom.xml
===================================================================
--- trunk/adminshell/pom.xml 2009-02-24 16:16:49 UTC (rev 489)
+++ trunk/adminshell/pom.xml 2009-02-24 16:41:35 UTC (rev 490)
@@ -29,6 +29,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
+ <version>3.8.1</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
Deleted: trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestHelper.java
===================================================================
--- trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestHelper.java 2009-02-24 16:16:49 UTC (rev 489)
+++ trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestHelper.java 2009-02-24 16:41:35 UTC (rev 490)
@@ -1,61 +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 com.metamatrix.connector.text;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.util.List;
-import java.util.Properties;
-
-import junit.framework.Assert;
-
-import com.metamatrix.cdk.api.ConnectorHost;
-import com.metamatrix.cdk.unittest.FakeTranslationFactory;
-import com.metamatrix.core.util.UnitTestUtil;
-
-public class TestHelper {
-
- static void helpTestExecution(String vdb, String descriptorFile, String sql, int maxBatchSize, int expectedRowCount) throws Exception {
- descriptorFile = UnitTestUtil.getTestDataPath() + File.separator + descriptorFile;
- Properties connProps = new Properties();
- connProps.load(new FileInputStream(descriptorFile));
- connProps.put(TextPropertyNames.DESCRIPTOR_FILE, descriptorFile);
- connProps.put(TextPropertyNames.DATE_RESULT_FORMATS, "yyyy-MM-dd,hh:mm:ss,hh:mm,dd/mm/yyyy"); //$NON-NLS-1$
- connProps.put(TextPropertyNames.DATE_RESULT_FORMATS_DELIMITER, ","); //$NON-NLS-1$
- ConnectorHost host = new ConnectorHost(new TextConnector(), connProps, UnitTestUtil.getTestDataPath() + File.separator + vdb, false);
- List results = host.executeCommand(sql);
- Assert.assertEquals("Total row count doesn't match expected size. ", expectedRowCount, results.size()); //$NON-NLS-1$
- }
-
- public static ConnectorHost getConnectorHostWithFakeMetadata(String descriptorFile) throws Exception {
- Properties connProps = new Properties();
- connProps.load(new FileInputStream(descriptorFile));
- connProps.put(TextPropertyNames.DESCRIPTOR_FILE, descriptorFile);
- connProps.put(TextPropertyNames.COLUMN_CNT_MUST_MATCH_MODEL, "true");
- connProps.put(TextPropertyNames.DATE_RESULT_FORMATS, "yyyy-MM-dd,hh:mm:ss,hh:mm,dd/mm/yyyy"); //$NON-NLS-1$
- connProps.put(TextPropertyNames.DATE_RESULT_FORMATS_DELIMITER, ","); //$NON-NLS-1$
- ConnectorHost host = new ConnectorHost(new TextConnector(), connProps, FakeTranslationFactory.getInstance().getTextTranslationUtility(), false);
- return host;
- }
-
-}
Modified: trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestMultiFileTextSynchExecution.java
===================================================================
--- trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestMultiFileTextSynchExecution.java 2009-02-24 16:16:49 UTC (rev 489)
+++ trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestMultiFileTextSynchExecution.java 2009-02-24 16:41:35 UTC (rev 490)
@@ -45,7 +45,7 @@
public void testSubmitRequest() throws Exception {
String sql = "SELECT ID FROM Library"; //$NON-NLS-1$
try {
- TestHelper.getConnectorHostWithFakeMetadata(BAD_COUNT_FILE).executeCommand(sql);
+ Util.getConnectorHostWithFakeMetadata(BAD_COUNT_FILE).executeCommand(sql);
fail("Should have failed due to extra column defined in .csv file");//$NON-NLS-1$
} catch (ConnectorException e) {
assertEquals("Expected input file to have 3 columns based on model, but found 4. This could be caused by misplaced quotes, causing multiple columns to be treated as one.", e.getMessage()); //$NON-NLS-1$
@@ -55,7 +55,7 @@
public void testNextBatch3() throws Exception {
String sql = "SELECT ID FROM Library WHERE Author = 'Blind'"; //$NON-NLS-1$
try {
- TestHelper.getConnectorHostWithFakeMetadata(BAD_COUNT_FILE).executeCommand(sql);
+ Util.getConnectorHostWithFakeMetadata(BAD_COUNT_FILE).executeCommand(sql);
fail("Should have failed due to extra column defined in .csv file");//$NON-NLS-1$
} catch (ConnectorException e) {
assertEquals("Expected input file to have 3 columns based on model, but found 4. This could be caused by misplaced quotes, causing multiple columns to be treated as one.", e.getMessage()); //$NON-NLS-1$
@@ -64,7 +64,7 @@
public void testNextBatch2() throws Exception {
String sql = "SELECT ID, PDate, Author FROM Library"; //$NON-NLS-1$
- ConnectorHost host = TestHelper.getConnectorHostWithFakeMetadata(DEFAULT_DESC_FILE);
+ ConnectorHost host = Util.getConnectorHostWithFakeMetadata(DEFAULT_DESC_FILE);
int expectedRows = 4;
List results = host.executeCommand(sql);
assertEquals("Get batch size doesn't match expected one. ", expectedRows, results.size()); //$NON-NLS-1$
@@ -102,7 +102,7 @@
*/
public void testDefect13066() throws Exception {
String sql = "SELECT TRADEID FROM SummitData.SUMMITDATA"; //$NON-NLS-1$
- TestHelper.helpTestExecution("summitData/TextFileTest_1.vdb", "SummitData_Descriptor.txt", sql, 500, 4139); //$NON-NLS-1$ //$NON-NLS-2$
+ Util.helpTestExecution("summitData/TextFileTest_1.vdb", "SummitData_Descriptor.txt", sql, 500, 4139); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
@@ -112,7 +112,7 @@
*/
public void testDefect13368() throws Exception {
String sql = "SELECT RATE, DESK FROM SummitData.SUMMITDATA"; //$NON-NLS-1$
- TestHelper.helpTestExecution("summitData/TextFileTest_1.vdb", "SummitData_Descriptor.txt", sql, 5, 4139); //$NON-NLS-1$ //$NON-NLS-2$
+ Util.helpTestExecution("summitData/TextFileTest_1.vdb", "SummitData_Descriptor.txt", sql, 5, 4139); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
@@ -122,18 +122,18 @@
*/
public void testDefect13371() throws Exception {
String sql = " SELECT SUMMITEXTRACTCDM.START, SUMMITEXTRACTCDM.SUMMIT_ID, SUMMITEXTRACTCDM.CURRENCY, SUMMITEXTRACTCDM.AMOUNT, SUMMITEXTRACTCDM.MATURITY, SUMMITEXTRACTCDM.RATE, SUMMITEXTRACTCDM.DESK, SUMMITEXTRACTCDM.CDM_ID FROM SUMMITEXTRACTCDM"; //$NON-NLS-1$
- TestHelper.helpTestExecution("summitData/TextFiles.vdb", "SummitExtractCDM_Descriptor.txt", sql, 500, 52); //$NON-NLS-1$ //$NON-NLS-2$
+ Util.helpTestExecution("summitData/TextFiles.vdb", "SummitExtractCDM_Descriptor.txt", sql, 500, 52); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testDefect11402() throws Exception {
String sql = "SELECT Part_ID, Part_Name, Part_Color, Part_Weight from PARTS.PARTS"; //$NON-NLS-1$
- TestHelper.helpTestExecution("TextParts/TextParts.vdb", "/TextParts/PartsDescriptor.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
+ Util.helpTestExecution("TextParts/TextParts.vdb", "/TextParts/PartsDescriptor.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
}
/** test case 4151 */
public void testCase4151() throws Exception {
String sql = "SELECT COLA, COLB, COLC FROM ThreeColString_Text.testfile"; //$NON-NLS-1$
- TestHelper.helpTestExecution("case4151/MM_00004151.vdb", "testfile-descriptor.txt", sql, 15000, 5); //$NON-NLS-1$ //$NON-NLS-2$
+ Util.helpTestExecution("case4151/MM_00004151.vdb", "testfile-descriptor.txt", sql, 15000, 5); //$NON-NLS-1$ //$NON-NLS-2$
}
}
Modified: trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestRowHeaderTextSynchExecution.java
===================================================================
--- trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestRowHeaderTextSynchExecution.java 2009-02-24 16:16:49 UTC (rev 489)
+++ trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestRowHeaderTextSynchExecution.java 2009-02-24 16:41:35 UTC (rev 490)
@@ -40,7 +40,7 @@
*/
public void testRowHeader() throws Exception {
String sql = "SELECT Part_ID, Part_Name, Part_Color, Part_Weight from PARTS.PARTS"; //$NON-NLS-1$
- TestHelper.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
+ Util.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
@@ -50,7 +50,7 @@
*/
public void testRowHeader2() throws Exception {
String sql = "SELECT Part_ID, Part_Name, Part_Color, Part_Weight from PARTS.PARTS_NoNameInSource"; //$NON-NLS-1$
- TestHelper.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
+ Util.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
@@ -60,7 +60,7 @@
*/
public void testRowHeader3() throws Exception {
String sql = "SELECT Part_ID, Part_Name, Part_Color, Part_Weight from PARTS.PARTS_AlphaNameInSource"; //$NON-NLS-1$
- TestHelper.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
+ Util.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
@@ -71,7 +71,7 @@
*/
public void testRowHeader4() throws Exception {
String sql = "SELECT Part_ID, Part_Name, Part_Color, Part_Weight from PARTS.PARTS_AlphaDiffNameInSource"; //$NON-NLS-1$
- TestHelper.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
+ Util.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
@@ -81,7 +81,7 @@
*/
public void testRowHeader5() throws Exception {
String sql = "SELECT Part_ID, Part_Name, Part_Color, Part_Weight from PARTS.PARTS_NoNameInSource"; //$NON-NLS-1$
- TestHelper.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor_HeaderRowTest.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
+ Util.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor_HeaderRowTest.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
@@ -91,7 +91,7 @@
*/
public void testRowHeader6() throws Exception {
String sql = "SELECT Part_ID, Part_Name, Part_Color, Part_Weight from PARTS.PARTS_AlphaDiffNameInSource"; //$NON-NLS-1$
- TestHelper.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor_HeaderRowTest.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
+ Util.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor_HeaderRowTest.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
@@ -101,7 +101,7 @@
*/
public void testRowHeader7() throws Exception {
String sql = "SELECT Part_ID, Part_Name, Part_Color, Part_Weight from PARTS.PARTS_NoNameInSource"; //$NON-NLS-1$
- TestHelper.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor3.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
+ Util.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor3.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
@@ -111,7 +111,7 @@
*/
public void testRowHeader8() throws Exception {
String sql = "SELECT Part_ID, Part_Name, Part_Color, Part_Weight from PARTS.PARTS_SpaceNameInSource"; //$NON-NLS-1$
- TestHelper.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor4.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
+ Util.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor4.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
@@ -123,7 +123,7 @@
public void testRowHeader_Error() throws Exception {
String sql = "SELECT Part_ID, Part_Name, Part_Color, Part_Weight from PARTS.PARTS_AlphaNameInSource"; //$NON-NLS-1$
try {
- TestHelper.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor4.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
+ Util.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor4.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
fail("Should have received ConnectorException due to an invalid header row being defined."); //$NON-NLS-1$
} catch (ConnectorException ce ) {
assertEquals("'SELECT PARTS_AlphaNameInSource.Part_Id, PARTS_AlphaNameInSource.Part_Name, PARTS_AlphaNameInSource.Part_Color, PARTS_AlphaNameInSource.Part_Weight FROM PARTS_AlphaNameInSource' cannot be translated by the TextTranslator. Column Part_Id not found for element Parts.PARTS_AlphaNameInSource.Part_Id. Verify column name \"Part_Id\" is defined in the header row of the text file and that the header row number is correctly defined in the descriptor file.", ce.getMessage()); //$NON-NLS-1$
@@ -140,7 +140,7 @@
*/
public void testRowHeader_Error2() throws Exception {
String sql = "SELECT Part_ID, Part_Name, Part_Color, Part_Weight from PARTS.PARTS_NoNameInSource"; //$NON-NLS-1$
- TestHelper.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor4.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
+ Util.helpTestExecution("TextParts/TextParts.vdb", "TextParts/PartsDescriptor4.txt", sql, 15000, 21); //$NON-NLS-1$ //$NON-NLS-2$
}
}
Modified: trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestTextSynchExecution.java
===================================================================
--- trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestTextSynchExecution.java 2009-02-24 16:16:49 UTC (rev 489)
+++ trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestTextSynchExecution.java 2009-02-24 16:41:35 UTC (rev 490)
@@ -45,7 +45,7 @@
public void testNextBatch2() throws Exception {
String sql = "SELECT ID, PDate, Author FROM Library"; //$NON-NLS-1$
- ConnectorHost host = TestHelper.getConnectorHostWithFakeMetadata(DEFAULT_DESC_FILE);
+ ConnectorHost host = Util.getConnectorHostWithFakeMetadata(DEFAULT_DESC_FILE);
int expectedRows = 2;
List results = host.executeCommand(sql);
assertEquals("Get batch size doesn't match expected one. ", expectedRows, results.size()); //$NON-NLS-1$
@@ -76,7 +76,7 @@
*/
public void testDefect13066() throws Exception {
String sql = "SELECT TRADEID FROM SummitData.SUMMITDATA"; //$NON-NLS-1$
- TestHelper.helpTestExecution("summitData/TextFileTest_1.vdb", "SummitData_Descriptor.txt", sql, 500, 4139); //$NON-NLS-1$
+ Util.helpTestExecution("summitData/TextFileTest_1.vdb", "SummitData_Descriptor.txt", sql, 500, 4139); //$NON-NLS-1$
}
/**
@@ -86,7 +86,7 @@
*/
public void testDefect13368() throws Exception {
String sql = "SELECT RATE, DESK FROM SummitData.SUMMITDATA"; //$NON-NLS-1$
- TestHelper.helpTestExecution("summitData/TextFileTest_1.vdb", "SummitData_Descriptor.txt", sql, 5, 4139); //$NON-NLS-1$
+ Util.helpTestExecution("summitData/TextFileTest_1.vdb", "SummitData_Descriptor.txt", sql, 5, 4139); //$NON-NLS-1$
}
/**
@@ -96,18 +96,18 @@
*/
public void testDefect13371() throws Exception {
String sql = " SELECT SUMMITEXTRACTCDM.START, SUMMITEXTRACTCDM.SUMMIT_ID, SUMMITEXTRACTCDM.CURRENCY, SUMMITEXTRACTCDM.AMOUNT, SUMMITEXTRACTCDM.MATURITY, SUMMITEXTRACTCDM.RATE, SUMMITEXTRACTCDM.DESK, SUMMITEXTRACTCDM.CDM_ID FROM SUMMITEXTRACTCDM"; //$NON-NLS-1$
- TestHelper.helpTestExecution("summitData/TextFiles.vdb", "SummitExtractCDM_Descriptor.txt", sql, 500, 52); //$NON-NLS-1$
+ Util.helpTestExecution("summitData/TextFiles.vdb", "SummitExtractCDM_Descriptor.txt", sql, 500, 52); //$NON-NLS-1$
}
public void testDefect11402() throws Exception {
String sql = "SELECT Part_ID, Part_Name, Part_Color, Part_Weight from PARTS.PARTS"; //$NON-NLS-1$
- TestHelper.helpTestExecution("TextParts/TextParts.vdb", "/TextParts/PartsDescriptor.txt", sql, 15000, 21); //$NON-NLS-1$
+ Util.helpTestExecution("TextParts/TextParts.vdb", "/TextParts/PartsDescriptor.txt", sql, 15000, 21); //$NON-NLS-1$
}
/** test case 4151 */
public void testCase4151() throws Exception {
String sql = "SELECT COLA, COLB, COLC FROM ThreeColString_Text.testfile"; //$NON-NLS-1$
- TestHelper.helpTestExecution("case4151/MM_00004151.vdb", "testfile-descriptor.txt", sql, 15000, 5); //$NON-NLS-1$
+ Util.helpTestExecution("case4151/MM_00004151.vdb", "testfile-descriptor.txt", sql, 15000, 5); //$NON-NLS-1$
}
}
Copied: trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/Util.java (from rev 486, trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestHelper.java)
===================================================================
--- trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/Util.java (rev 0)
+++ trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/Util.java 2009-02-24 16:41:35 UTC (rev 490)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.connector.text;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.List;
+import java.util.Properties;
+
+import junit.framework.Assert;
+
+import com.metamatrix.cdk.api.ConnectorHost;
+import com.metamatrix.cdk.unittest.FakeTranslationFactory;
+import com.metamatrix.core.util.UnitTestUtil;
+
+public class Util {
+
+ static void helpTestExecution(String vdb, String descriptorFile, String sql, int maxBatchSize, int expectedRowCount) throws Exception {
+ descriptorFile = UnitTestUtil.getTestDataPath() + File.separator + descriptorFile;
+ Properties connProps = new Properties();
+ connProps.load(new FileInputStream(descriptorFile));
+ connProps.put(TextPropertyNames.DESCRIPTOR_FILE, descriptorFile);
+ connProps.put(TextPropertyNames.DATE_RESULT_FORMATS, "yyyy-MM-dd,hh:mm:ss,hh:mm,dd/mm/yyyy"); //$NON-NLS-1$
+ connProps.put(TextPropertyNames.DATE_RESULT_FORMATS_DELIMITER, ","); //$NON-NLS-1$
+ ConnectorHost host = new ConnectorHost(new TextConnector(), connProps, UnitTestUtil.getTestDataPath() + File.separator + vdb, false);
+ List results = host.executeCommand(sql);
+ Assert.assertEquals("Total row count doesn't match expected size. ", expectedRowCount, results.size()); //$NON-NLS-1$
+ }
+
+ public static ConnectorHost getConnectorHostWithFakeMetadata(String descriptorFile) throws Exception {
+ Properties connProps = new Properties();
+ connProps.load(new FileInputStream(descriptorFile));
+ connProps.put(TextPropertyNames.DESCRIPTOR_FILE, descriptorFile);
+ connProps.put(TextPropertyNames.COLUMN_CNT_MUST_MATCH_MODEL, "true");
+ connProps.put(TextPropertyNames.DATE_RESULT_FORMATS, "yyyy-MM-dd,hh:mm:ss,hh:mm,dd/mm/yyyy"); //$NON-NLS-1$
+ connProps.put(TextPropertyNames.DATE_RESULT_FORMATS_DELIMITER, ","); //$NON-NLS-1$
+ ConnectorHost host = new ConnectorHost(new TextConnector(), connProps, FakeTranslationFactory.getInstance().getTextTranslationUtility(), false);
+ return host;
+ }
+
+}
Property changes on: trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/Util.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-02-24 16:16:49 UTC (rev 489)
+++ trunk/pom.xml 2009-02-24 16:41:35 UTC (rev 490)
@@ -173,7 +173,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.1</version>
+ <version>4.4</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -397,11 +397,6 @@
<version>3.0</version>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- </dependency>
- <dependency>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
<version>3.0.2.GA</version>
15 years, 10 months