Author: shawkins
Date: 2009-02-19 12:59:09 -0500 (Thu, 19 Feb 2009)
New Revision: 476
Added:
trunk/connector-api/src/main/java/com/metamatrix/connector/api/SourceSystemFunctions.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/access/AccessSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/LeftOrRightFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/ModFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleTranslator.java
Removed:
trunk/connector-api/src/main/java/com/metamatrix/connector/language/ICaseExpression.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/access/AccessSQLConversionVisitor.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/access/AccessSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2ResultsTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2SQLConversionVisitor.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2SQLModificationVisitor.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2SingleIdentityConnectionFactory.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2UserIdentityConnectionFactory.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyConversionVisitor.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyResultsTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbySingleIdentityConnectionFactory.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyTimestampFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyUserIdentityConnectionFactory.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/impl/BasicSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/InformixResultsTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/InformixSingleIdentityConnectionFactory.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/InformixUserIdentityConnectionFactory.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLConversionVisitor.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLResultsTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLSingleIdentityConnectionFactory.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLUserIdentityConnectionFactory.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/FormatFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/HourFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/LeftOrRightFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleSQLConversionVisitor.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/ParseFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLConversionVisitor.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLResultsTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLSingleIdentityConnectionFactory.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLUserIdentityConnectionFactory.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/SubstringFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerModModifier.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerResultsTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerSQLConversionVisitor.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerSingleIdentityConnectionFactory.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerUserIdentityConnectionFactory.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/FormatTimestampModifier.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/ModFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseResultsTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseSQLConversionVisitor.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseSingleIdentityConnectionFactory.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseUserIdentityConnectionFactory.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestFormatFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestHourFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestParseFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sqlserver/TestSqlServerConvertModifier.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/TestFormatTimestampModifier.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/TestModFunctionModifier.java
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialConversionVisitor.java
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/SpatialHint.java
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/SpatialSelectProxy.java
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/CaseExpressionImpl.java
trunk/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/language/TestCaseExpressionImpl.java
Modified:
trunk/connector-api/src/main/java/com/metamatrix/connector/api/TypeFacility.java
trunk/connector-api/src/main/java/com/metamatrix/connector/language/IJoin.java
trunk/connector-api/src/main/java/com/metamatrix/connector/language/ILanguageFactory.java
trunk/connector-api/src/main/java/com/metamatrix/connector/language/ILimit.java
trunk/connector-api/src/main/java/com/metamatrix/connector/metadata/runtime/MetadataID.java
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/framework/AbstractLanguageVisitor.java
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/framework/DelegatingHierarchyVisitor.java
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/framework/HierarchyVisitor.java
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/framework/LanguageObjectVisitor.java
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/util/CollectorVisitor.java
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/util/SQLStringVisitor.java
trunk/connector-api/src/test/java/com/metamatrix/data/transform/TestBasicValueTranslator.java
trunk/connector-sdk/src/test/java/com/metamatrix/cdk/unittest/FakeTranslationFactory.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/JDBCProcedureExecution.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/JDBCSourceConnectionFactory.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/db2/DB2Capabilities.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2SQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbySQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/BindValueVisitor.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/ResultsTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/SQLConversionVisitor.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/SQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/TranslatedCommand.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/ValueRetriever.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/impl/BasicResultsTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/impl/BasicValueRetriever.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/InformixSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/ssl/JDBCSequeLinkSingleIdentityConnectionFactory.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/util/FunctionReplacementVisitor.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/xa/JDBCSingleIdentityDSConnectionFactory.java
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/xa/JDBCSourceXAConnection.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/TestAccessSQLTranslator.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/db2/TestDB2ConvertModifier.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/db2/TestDB2SqlTranslator.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/derby/TestDerbyConvertModifier.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/mysql/TestMySQLTranslator.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestDayWeekQuarterFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestExtractFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestLeftOrRightFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestLocateFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestLog10FunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestMonthOrDayNameFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleConvertModifier.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestSubstringFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/postgresql/TestPostgreSQLTranslator.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/TestSybaseConvertModifier.java
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java
trunk/connectors/connector-ldap/src/main/java/com/metamatrix/connector/ldap/IQueryToLdapSearchParser.java
trunk/connectors/connector-ldap/src/test/java/com/metamatrix/connector/ldap/TestIQueryToLdapSearchParser.java
trunk/connectors/connector-xml-common/
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/datamgr/impl/TypeFacilityImpl.java
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/BaseLanguageObject.java
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/LanguageBridgeFactory.java
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/LanguageFactoryImpl.java
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/MetadataFactory.java
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/MetadataIDImpl.java
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/MetadataObjectImpl.java
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/ParameterIDImpl.java
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/ProcedureIDImpl.java
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/RuntimeMetadataImpl.java
trunk/engine/src/main/java/com/metamatrix/query/function/FunctionLibrary.java
trunk/engine/src/main/java/com/metamatrix/query/function/FunctionMethods.java
trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/AliasGenerator.java
trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/Function.java
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java
trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties
trunk/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/language/TestElementImpl.java
trunk/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/language/TestInsertImpl.java
trunk/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/metadata/TestMetadataFactory.java
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunction.java
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinOptimization.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestAliasGenerator.java
trunk/engine/src/test/java/com/metamatrix/query/parser/TestParser.java
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
trunk/engine/src/test/java/com/metamatrix/query/sql/util/TestUpdateProcedureGenerator.java
trunk/engine/src/test/java/com/metamatrix/query/sql/visitor/TestSQLStringVisitor.java
trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.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/data/metadata/runtime/TestMetadataID.java
trunk/test-integration/src/test/java/com/metamatrix/data/metadata/runtime/TestParams.java
trunk/test-integration/src/test/java/com/metamatrix/data/metadata/runtime/TestProcedure.java
trunk/test-integration/src/test/java/com/metamatrix/data/visitor/util/TestSQLStringVisitor.java
Log:
TEIID-360 TEIID-359 TEIID-357 TEIID-356 TEIID-354 TEIID-353 TEIID-352 TEIID-164 jdbc
connector api cleanup. created canonical push-down function list, changed the
SQLTranslator to handle the tasks that were previously in specific SQLConversionVisitors.
Added:
trunk/connector-api/src/main/java/com/metamatrix/connector/api/SourceSystemFunctions.java
===================================================================
---
trunk/connector-api/src/main/java/com/metamatrix/connector/api/SourceSystemFunctions.java
(rev 0)
+++
trunk/connector-api/src/main/java/com/metamatrix/connector/api/SourceSystemFunctions.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -0,0 +1,144 @@
+/*
+ * 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.api;
+
+/**
+ * Constants for all the possible standard system push down functions.
+ * The names and function forms follow the Open Group CLI functions, with a few
exceptions
+ * (such as lpad, rpad, bitand, bitor, etc. which are most notably supported by Oracle).
+ *
+ */
+public class SourceSystemFunctions {
+
+ //arithmetic
+ public static final String MULTIPLY_OP = "*";
+ public static final String ADD_OP = "+";
+ public static final String SUBTRACT_OP = "-";
+ public static final String DIVIDE_OP = "/";
+
+ //String
+ public static final String ASCII = "ascii";
+ public static final String CHAR = "char";
+ public static final String CONCAT = "concat";
+ //public static final String DIFFERENCE = "difference";
+ public static final String INITCAP = "initcap";
+ public static final String INSERT = "insert";
+ public static final String LCASE = "lcase";
+ public static final String LPAD = "lpad";
+ public static final String LEFT = "left";
+ public static final String LENGTH = "length";
+ public static final String LOCATE = "locate";
+ public static final String LTRIM = "ltrim";
+ public static final String REPEAT = "repeat";
+ public static final String REPLACE = "replace";
+ public static final String RIGHT = "right";
+ public static final String RPAD = "rpad";
+ public static final String RTRIM = "rtrim";
+ //public static final String SOUNDEX = "soundex";
+ public static final String SUBSTRING = "substring";
+ public static final String UCASE = "ucase";
+
+ //numeric
+ public static final String ABS = "abs";
+ public static final String ACOS = "acos";
+ public static final String ASIN = "asin";
+ public static final String ATAN = "atan";
+ public static final String ATAN2 = "atan2";
+ public static final String CEILING = "ceiling";
+ public static final String COS = "cos";
+ public static final String COT = "cot";
+ public static final String DEGREES = "degrees";
+ public static final String EXP = "exp";
+ public static final String FLOOR = "floor";
+ public static final String FORMATINTEGER = "formatinteger";
+ public static final String FORMATLONG = "formatlong";
+ public static final String FORMATDOUBLE = "formatdouble";
+ public static final String FORMATFLOAT = "formatfloat";
+ public static final String FORMATBIGINTEGER = "formatbiginteger";
+ public static final String FORMATBIGDECIMAL = "formatbigdecimal";
+ public static final String LOG = "log";
+ public static final String LOG10 = "log10";
+ public static final String MOD = "mod";
+ public static final String PARSEINTEGER = "parseinteger";
+ public static final String PARSELONG = "parselong";
+ public static final String PARSEDOUBLE = "parsedouble";
+ public static final String PARSEFLOAT = "parsefloat";
+ public static final String PARSEBIGINTEGER = "parsebiginteger";
+ public static final String PARSEBIGDECIMAL = "parsebigdecimal";
+ public static final String PI = "pi";
+ public static final String POWER = "power";
+ public static final String RADIANS = "radians";
+ public static final String RAND = "rand";
+ public static final String ROUND = "round";
+ public static final String SIGN = "sign";
+ public static final String SIN = "sin";
+ public static final String SQRT = "sqrt";
+ public static final String TAN = "tan";
+ public static final String TRANSLATE = "translate";
+ public static final String TRUNCATE = "truncate";
+
+ //bit
+ public static final String BITAND = "bitand";
+ public static final String BITOR = "bitor";
+ public static final String BITNOT = "bitnot";
+ public static final String BITXOR = "bitxor";
+
+ //date functions
+ public static final String CURDATE = "curdate";
+ public static final String CURTIME = "curtime";
+ public static final String DAYNAME = "dayname";
+ public static final String DAYOFMONTH = "dayofmonth";
+ public static final String DAYOFWEEK = "dayofweek";
+ public static final String DAYOFYEAR = "dayofyear";
+ public static final String FORMATDATE = "formatdate";
+ public static final String FORMATTIME = "formattime";
+ public static final String FORMATTIMESTAMP = "formattimestamp";
+ public static final String HOUR = "hour";
+ public static final String MINUTE = "minute";
+ public static final String MODIFYTIMEZONE = "modifytimezone";
+ public static final String MONTH = "month";
+ public static final String MONTHNAME = "monthname";
+ public static final String NOW = "now";
+ public static final String PARSEDATE = "parsedate";
+ public static final String PARSETIME = "parsetime";
+ public static final String PARSETIMESTAMP = "parsetimestamp";
+ public static final String QUARTER = "quarter";
+ public static final String SECOND = "second";
+ public static final String TIMESTAMPADD = "timestampadd";
+ public static final String TIMESTAMPCREATE = "timestampcreate";
+ public static final String TIMESTAMPDIFF = "timestampdiff";
+ public static final String WEEK = "week";
+ public static final String YEAR = "year";
+
+ //system functions
+ public static final String IFNULL = "ifnull";
+ public static final String COALESCE = "coalesce";
+ public static final String NULLIF = "nullif";
+
+ //conversion functions
+ public static final String CONVERT = "convert";
+
+ //xml
+ public static final String XPATHVALUE = "xpathvalue";
+
+}
Property changes on:
trunk/connector-api/src/main/java/com/metamatrix/connector/api/SourceSystemFunctions.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/connector-api/src/main/java/com/metamatrix/connector/api/TypeFacility.java
===================================================================
---
trunk/connector-api/src/main/java/com/metamatrix/connector/api/TypeFacility.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connector-api/src/main/java/com/metamatrix/connector/api/TypeFacility.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -22,6 +22,9 @@
package com.metamatrix.connector.api;
+import java.util.Calendar;
+import java.util.TimeZone;
+
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.common.types.MMJDBCSQLTypeInfo;
@@ -72,18 +75,61 @@
public static final String XML = DataTypeManager.DefaultDataTypes.XML;
}
- public static Class getDataTypeClass(String type) {
+ /**
+ * Get the Class constant for the given String type name
+ */
+ public static Class<?> getDataTypeClass(String type) {
return DataTypeManager.getDataTypeClass(type);
}
- public static final int getSQLTypeFromRuntimeType(Class type) {
+ /**
+ * Get the SQL type for the given runtime type Class constant
+ * @param type
+ * @return
+ */
+ public static final int getSQLTypeFromRuntimeType(Class<?> type) {
return MMJDBCSQLTypeInfo.getSQLTypeFromRuntimeType(type);
}
- public abstract boolean hasTransformation(Class sourceClass, Class targetClass);
+ /**
+ * Checks if the given transformation exists.
+ * @param <S>
+ * @param <T>
+ * @param sourceClass
+ * @param targetClass
+ * @return
+ */
+ public abstract <S, T> boolean hasTransformation(Class<S> sourceClass,
Class<T> targetClass);
- public abstract <T> T transformValue(Object value, Class sourceClass,
Class<T> targetClass) throws ConnectorException;
+ /**
+ * Transform the given value into the target type, or throw an exception if this is
not
+ * possible.
+ * @param <S>
+ * @param <T>
+ * @param value
+ * @param sourceClass
+ * @param targetClass
+ * @return
+ * @throws ConnectorException
+ */
+ public abstract <S, T> T transformValue(S value, Class<S> sourceClass,
Class<T> targetClass) throws ConnectorException;
+ /**
+ * Convert the given value to the closest runtime type see {@link RUNTIME_TYPES}
+ * @param value
+ * @return
+ */
public abstract Object convertToRuntimeType(Object value);
+ /**
+ * Convert the given date to a target type, optionally adjusting its display
+ * for a given target Calendar.
+ * @param date
+ * @param initial
+ * @param target
+ * @param targetType
+ * @return
+ */
+ public abstract Object convertDate(java.util.Date date, TimeZone initial, Calendar
target, Class targetType);
+
}
Deleted:
trunk/connector-api/src/main/java/com/metamatrix/connector/language/ICaseExpression.java
===================================================================
---
trunk/connector-api/src/main/java/com/metamatrix/connector/language/ICaseExpression.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connector-api/src/main/java/com/metamatrix/connector/language/ICaseExpression.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,89 +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.language;
-
-/**
- * Represents a non-searched CASE expression:
- * <br/> CASE expression WHEN expression THEN expression ... END
- */
-public interface ICaseExpression extends IExpression {
-
- /**
- * Gets the expression whose evaluation is tested against the WHEN expressions
- * @return the expression
- */
- IExpression getExpression();
-
- /**
- * Sets the expression whose evaluation is tested against the WHEN expressions
- * @param expression The expression
- */
- void setExpression(IExpression expression);
-
- /**
- * Gets the number of WHEN and THEN clauses in the CASE expression
- * @return the number of WHEN ... THEN ... parts
- */
- int getWhenCount();
-
- /**
- * Gets the WHEN expression at the specified index
- * @param index the 0-based index
- * @return the WHEN expression at the index
- */
- IExpression getWhenExpression(int index);
-
- /**
- * Sets the WHEN expression at the specified index
- * @param index the 0-based index
- * @param expression The new WHEN expression at the index
- */
- void setWhenExpression(int index, IExpression expression);
-
- /**
- * Gets the THEN expression at the specified index
- * @param index the 0-based index
- * @return the THEN expression at the index
- */
- IExpression getThenExpression(int index);
-
- /**
- * Sets the THEN expression at the specified index
- * @param index the 0-based index
- * @param expression The new THEN expression at the index
- */
- void setThenExpression(int index, IExpression expression);
-
- /**
- * Gets the ELSE expression, if defined. Can be null.
- * @return the ELSE expression.
- */
- IExpression getElseExpression();
-
- /**
- * Sets the ELSE expression
- * @param expression The new ELSE expression
- */
- void setElseExpression(IExpression expression);
-
-}
Modified: trunk/connector-api/src/main/java/com/metamatrix/connector/language/IJoin.java
===================================================================
---
trunk/connector-api/src/main/java/com/metamatrix/connector/language/IJoin.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connector-api/src/main/java/com/metamatrix/connector/language/IJoin.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -94,5 +94,5 @@
* Set List of CompareCriteria specifying join criteria.
* @param criteria List of Criteria
*/
- void setCriteria(List<ICriteria> criteria);
+ void setCriteria(List<? extends ICriteria> criteria);
}
Modified:
trunk/connector-api/src/main/java/com/metamatrix/connector/language/ILanguageFactory.java
===================================================================
---
trunk/connector-api/src/main/java/com/metamatrix/connector/language/ILanguageFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connector-api/src/main/java/com/metamatrix/connector/language/ILanguageFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -46,17 +46,6 @@
IAggregate createAggregate(String name, boolean isDistinct, IExpression expression,
Class type);
/**
- * Create case expression.
- * @param mainExpression First expression in the case, used to choose WHEN clause
- * @param whenExpressions List of when expressions, should match thenExpressions
- * @param thenExpressions List of then expressions, should match whenExpressions
- * @param elseExpression Else expression, may be null
- * @param type Data type
- * @return New ICaseExpression
- */
- ICaseExpression createCaseExpression(IExpression mainExpression,
List<IExpression> whenExpressions, List<IExpression> thenExpressions,
IExpression elseExpression, Class type);
-
- /**
* Create compare criteria.
* @param operator Operator, as defined in constants in {@link ICompareCriteria}
* @param leftExpression Left expression
Modified: trunk/connector-api/src/main/java/com/metamatrix/connector/language/ILimit.java
===================================================================
---
trunk/connector-api/src/main/java/com/metamatrix/connector/language/ILimit.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connector-api/src/main/java/com/metamatrix/connector/language/ILimit.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -37,8 +37,8 @@
int getRowLimit();
/**
- * Gets the offset (relative to the sarting row of the produced resultset) of the
- * first row returned by the connector.
+ * Gets the offset (relative to the starting row of the produced resultset) of the
+ * first row returned by the connector. 0 or less indicates no offset.
* @return
* @since 5.0 SP1
*/
Modified:
trunk/connector-api/src/main/java/com/metamatrix/connector/metadata/runtime/MetadataID.java
===================================================================
---
trunk/connector-api/src/main/java/com/metamatrix/connector/metadata/runtime/MetadataID.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connector-api/src/main/java/com/metamatrix/connector/metadata/runtime/MetadataID.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -31,11 +31,12 @@
*/
public interface MetadataID {
- public static final int TYPE_ELEMENT = 0;
- public static final int TYPE_GROUP = 1;
- public static final int TYPE_PROCEDURE = 2;
- public static final int TYPE_PARAMETER = 3;
-
+ public enum Type {
+ TYPE_ELEMENT,
+ TYPE_GROUP,
+ TYPE_PARAMETER,
+ TYPE_PROCEDURE
+ }
/**
* Get the type of metadataID
* @return ID type
@@ -44,7 +45,7 @@
* @see #TYPE_PROCEDURE
* @see #TYPE_PARAMETER
*/
- int getType();
+ Type getType();
/**
* Get a list of child IDs from this ID. A group metadata ID will
@@ -71,4 +72,10 @@
* @return String fullName
*/
String getFullName();
+
+ /**
+ * Get the {@link MetadataObject} for this id
+ * @return
+ */
+ MetadataObject getMetadataObject() throws ConnectorException;
}
Modified:
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/framework/AbstractLanguageVisitor.java
===================================================================
---
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/framework/AbstractLanguageVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/framework/AbstractLanguageVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -27,7 +27,6 @@
import com.metamatrix.connector.language.IAggregate;
import com.metamatrix.connector.language.IBatchedUpdates;
import com.metamatrix.connector.language.IBulkInsert;
-import com.metamatrix.connector.language.ICaseExpression;
import com.metamatrix.connector.language.ICompareCriteria;
import com.metamatrix.connector.language.ICompoundCriteria;
import com.metamatrix.connector.language.IDelete;
@@ -116,7 +115,6 @@
public void visit(IAggregate obj) {}
public void visit(IBatchedUpdates obj) {}
- public void visit(ICaseExpression obj) {}
public void visit(ICompareCriteria obj) {}
public void visit(ICompoundCriteria obj) {}
public void visit(IDelete obj) {}
Modified:
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/framework/DelegatingHierarchyVisitor.java
===================================================================
---
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/framework/DelegatingHierarchyVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/framework/DelegatingHierarchyVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -23,7 +23,42 @@
package com.metamatrix.connector.visitor.framework;
import com.metamatrix.connector.DataPlugin;
-import com.metamatrix.connector.language.*;
+import com.metamatrix.connector.language.IAggregate;
+import com.metamatrix.connector.language.IBatchedUpdates;
+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;
+import com.metamatrix.connector.language.IInsert;
+import com.metamatrix.connector.language.IIsNullCriteria;
+import com.metamatrix.connector.language.IJoin;
+import com.metamatrix.connector.language.ILanguageObject;
+import com.metamatrix.connector.language.ILikeCriteria;
+import com.metamatrix.connector.language.ILimit;
+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;
+import com.metamatrix.connector.language.ISearchedCaseExpression;
+import com.metamatrix.connector.language.ISelect;
+import com.metamatrix.connector.language.ISelectSymbol;
+import com.metamatrix.connector.language.ISetClause;
+import com.metamatrix.connector.language.ISetClauseList;
+import com.metamatrix.connector.language.ISetQuery;
+import com.metamatrix.connector.language.ISubqueryCompareCriteria;
+import com.metamatrix.connector.language.ISubqueryInCriteria;
+import com.metamatrix.connector.language.IUpdate;
/**
* Delegates pre- and post-processing for each node in the hierarchy to
@@ -70,15 +105,7 @@
postVisitor.visit(obj);
}
}
- public void visit(ICaseExpression obj) {
- if (preVisitor != null) {
- preVisitor.visit(obj);
- }
- super.visit(obj);
- if (postVisitor != null) {
- postVisitor.visit(obj);
- }
- }
+
public void visit(ICompareCriteria obj) {
if (preVisitor != null) {
preVisitor.visit(obj);
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-16
21:35:28 UTC (rev 475)
+++
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/framework/HierarchyVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -24,7 +24,6 @@
import com.metamatrix.connector.language.IAggregate;
import com.metamatrix.connector.language.IBatchedUpdates;
-import com.metamatrix.connector.language.ICaseExpression;
import com.metamatrix.connector.language.ICompareCriteria;
import com.metamatrix.connector.language.ICompoundCriteria;
import com.metamatrix.connector.language.IDelete;
@@ -82,16 +81,6 @@
visitNodes(obj.getUpdateCommands());
}
- public void visit(ICaseExpression obj) {
- visitNode(obj.getExpression());
- int whenCount = obj.getWhenCount();
- for (int i = 0; i < whenCount; i++) {
- visitNode(obj.getWhenExpression(i));
- visitNode(obj.getThenExpression(i));
- }
- visitNode(obj.getElseExpression());
- }
-
public void visit(ICompareCriteria obj) {
visitNode(obj.getLeftExpression());
visitNode(obj.getRightExpression());
Modified:
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/framework/LanguageObjectVisitor.java
===================================================================
---
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/framework/LanguageObjectVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/framework/LanguageObjectVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -30,7 +30,6 @@
public void visit(IAggregate obj);
public void visit(IBatchedUpdates obj);
public void visit(IBulkInsert obj);
- public void visit(ICaseExpression obj);
public void visit(ICompareCriteria obj);
public void visit(ICompoundCriteria obj);
public void visit(IDelete obj);
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-16
21:35:28 UTC (rev 475)
+++
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/util/CollectorVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -68,13 +68,6 @@
}
/*
- * @see
com.metamatrix.data.visitor.framework.LanguageObjectVisitor#visit(com.metamatrix.data.language.ICaseExpression)
- */
- public void visit(ICaseExpression obj) {
- checkInstance(obj);
- }
-
- /*
* @see
com.metamatrix.data.visitor.framework.LanguageObjectVisitor#visit(com.metamatrix.data.language.ICompareCriteria)
*/
public void visit(ICompareCriteria obj) {
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-16
21:35:28 UTC (rev 475)
+++
trunk/connector-api/src/main/java/com/metamatrix/connector/visitor/util/SQLStringVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -29,7 +29,7 @@
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.language.IAggregate;
import com.metamatrix.connector.language.IBulkInsert;
-import com.metamatrix.connector.language.ICaseExpression;
+import com.metamatrix.connector.language.ICommand;
import com.metamatrix.connector.language.ICompareCriteria;
import com.metamatrix.connector.language.ICompoundCriteria;
import com.metamatrix.connector.language.ICriteria;
@@ -72,7 +72,6 @@
import com.metamatrix.connector.language.IParameter.Direction;
import com.metamatrix.connector.metadata.runtime.MetadataID;
import com.metamatrix.connector.metadata.runtime.MetadataObject;
-import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
import com.metamatrix.connector.visitor.framework.AbstractLanguageVisitor;
import com.metamatrix.core.util.StringUtil;
@@ -87,7 +86,6 @@
protected static final String UNDEFINED = "<undefined>";
//$NON-NLS-1$
protected static final String UNDEFINED_PARAM = "?"; //$NON-NLS-1$
- protected RuntimeMetadata metadata;
protected StringBuffer buffer = new StringBuffer();
/**
@@ -96,12 +94,8 @@
* @return the name of that element or group as defined in the source
*/
protected String getName(MetadataID id) {
- if (metadata == null) {
- return id.getName();
- }
-
try {
- MetadataObject obj = metadata.getObject(id);
+ MetadataObject obj = id.getMetadataObject();
if (obj == null) {
return id.getName();
}
@@ -193,84 +187,6 @@
}
/**
- * @see
com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.connector.language.ICaseExpression)
- */
- public void visit(ICaseExpression obj) {
- final IElement element = obj.getExpression() instanceof IElement ?
(IElement)obj.getExpression() : null;
- final IFunction function = obj.getExpression() instanceof IFunction ?
(IFunction)obj.getExpression() : null ;
-
- buffer.append(CASE);
- buffer.append(SPACE);
-
- // checking for null compare in decode string case 2969 GCSS
- for (int i =0; i < obj.getWhenCount(); i++) {
- if (NULL.equalsIgnoreCase(obj.getWhenExpression(i).toString() ) ) {
- buffer.append(WHEN);
- buffer.append(SPACE);
-
- if(element != null) {
- visit(element);
- }else if(function != null) {
- visit(function);
- }else {
- append(obj.getExpression() );
- }
-
- buffer.append(SPACE);
- buffer.append(IS);
- buffer.append(SPACE);
- buffer.append(NULL);
- buffer.append(SPACE);
- buffer.append(THEN);
- buffer.append(SPACE);
- append(obj.getThenExpression(i));
- buffer.append(SPACE);
- }
- }
-
- for (int i = 0; i < obj.getWhenCount(); i++) {
- if(!NULL.equalsIgnoreCase(obj.getWhenExpression(i).toString() ) ) {
- buffer.append(WHEN);
- buffer.append(SPACE);
-
- if(element != null) {
- visit(element);
- }else if(function != null) {
- visit(function);
- }else {
- append(obj.getExpression() );
- }
-
- buffer.append(EQ);
- append(obj.getWhenExpression(i));
- buffer.append(SPACE);
- buffer.append(THEN);
- buffer.append(SPACE);
- append(obj.getThenExpression(i));
- buffer.append(SPACE);
- }
- }
-
- if (obj.getElseExpression() != null) {
- buffer.append(ELSE);
- buffer.append(SPACE);
- if(obj.getElseExpression() instanceof IElement || obj.getElseExpression()
instanceof IFunction) {
- if(element != null) {
- visit(element);
- }else if(function != null) {
- visit(function);
- }else {
- append(obj.getExpression() );
- }
- }else {
- append(obj.getElseExpression());
- }
- buffer.append(SPACE);
- }
- buffer.append(END);
- }
-
- /**
* @see
com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.connector.language.ICompareCriteria)
*/
public void visit(ICompareCriteria obj) {
@@ -329,7 +245,7 @@
public void visit(IDelete obj) {
buffer.append(DELETE)
.append(SPACE);
- buffer.append(addProcessComment());
+ buffer.append(getSourceComment(obj));
buffer.append(FROM)
.append(SPACE);
append(obj.getGroup());
@@ -365,9 +281,13 @@
* @see
com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.connector.language.IElement)
*/
public void visit(IElement obj) {
- String groupName = null;
+ buffer.append(getElementName(obj, true));
+ }
+
+ private String getElementName(IElement obj, boolean qualify) {
+ String groupName = null;
IGroup group = obj.getGroup();
- if (group != null) {
+ if (group != null && qualify) {
if(group.getDefinition() != null) {
groupName = group.getContext();
} else {
@@ -380,24 +300,6 @@
}
}
- String elemShortName = getElementShortName(obj);
-
- // Check whether a subclass wants to replace the element name to use in special
circumstances
- String replacementElement = replaceElementName(groupName, elemShortName);
- if(replacementElement != null) {
- // If so, use it as is
- buffer.append(replacementElement);
- } else {
- // If not, do normal logic: [group + "."] + element
- if(groupName != null) {
- buffer.append(groupName);
- buffer.append(DOT);
- }
- buffer.append(elemShortName);
- }
- }
-
- public String getElementShortName(IElement obj) {
String elemShortName = null;
MetadataID elementID = obj.getMetadataID();
if(elementID != null) {
@@ -406,19 +308,29 @@
String elementName = obj.getName();
elemShortName = getShortName(elementName);
}
- return elemShortName;
- }
+ // Check whether a subclass wants to replace the element name to use in special
circumstances
+ String replacementElement = replaceElementName(groupName, elemShortName);
+ if(replacementElement != null) {
+ // If so, use it as is
+ return replacementElement;
+ }
+ StringBuffer elementName = new StringBuffer(elemShortName.length());
+ // If not, do normal logic: [group + "."] + element
+ if(groupName != null) {
+ elementName.append(groupName);
+ elementName.append(DOT);
+ }
+ elementName.append(elemShortName);
+ return elementName.toString();
+ }
+
/**
* @param elementName
* @return
* @since 4.3
*/
- public String getShortName(String elementName) {
- return getElementShortName(elementName);
- }
-
- public static String getElementShortName(String elementName) {
+ public static String getShortName(String elementName) {
int lastDot = elementName.lastIndexOf("."); //$NON-NLS-1$
if(lastDot >= 0) {
elementName = elementName.substring(lastDot+1);
@@ -490,30 +402,12 @@
IExpression[] args = obj.getParameters();
if(name.equalsIgnoreCase(CONVERT) || name.equalsIgnoreCase(CAST)) {
- // Need to support both Oracle style convert - convert(expression, type)
- // and SQL Server style convert - convert(type, expression)
- Object firstArg = null;
- Object secondArg = null;
- if (args[1] instanceof IElement) {
- Object typeValue = ((ILiteral)args[0]).getValue();
- Object expression = args[1];
- firstArg = typeValue;
- secondArg = expression;
- } else {
- Object typeValue = ((ILiteral)args[1]).getValue();
- Object expression = args[0];
- firstArg = expression;
- secondArg = typeValue;
- }
+ Object typeValue = ((ILiteral)args[1]).getValue();
buffer.append(name);
buffer.append(LPAREN);
- if(firstArg instanceof IExpression) {
- this.append( (IExpression)firstArg);
- }else {
- buffer.append(firstArg);
- }
+ append(args[0]);
if(name.equalsIgnoreCase(CONVERT)) {
buffer.append(COMMA);
@@ -523,15 +417,9 @@
buffer.append(AS);
buffer.append(SPACE);
}
-
- if(secondArg instanceof IExpression) {
- this.append( (IExpression)secondArg);
- }else {
- buffer.append(secondArg);
- }
+ buffer.append(typeValue);
buffer.append(RPAREN);
-
- } else if(name.equals("+") || name.equals("-") ||
name.equals("*") || name.equals("/") || name.equals("||")) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ } else if(name.equals("%") || name.equals("+") ||
name.equals("-") || name.equals("*") || name.equals("/") ||
name.equals("||")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
//$NON-NLS-5$
buffer.append(LPAREN);
if(args != null) {
@@ -669,7 +557,7 @@
private void formatBasicInsert(IInsert obj) {
buffer.append(INSERT)
.append(SPACE);
- buffer.append(addProcessComment());
+ buffer.append(getSourceComment(obj));
buffer.append(INTO)
.append(SPACE);
append(obj.getGroup());
@@ -679,13 +567,7 @@
int elementCount= obj.getElements().size();
for(int i=0; i<elementCount; i++) {
- String elementShortNmae =
getElementShortName((IElement)obj.getElements().get( i ));
- String replacedEmentShortNmae = getElementTrueName(elementShortNmae);
- if(replacedEmentShortNmae != null){
- buffer.append(replacedEmentShortNmae);
- }else{
- buffer.append(elementShortNmae);
- }
+ buffer.append(getElementName(obj.getElements().get(i), false));
if (i<elementCount-1) {
buffer.append(COMMA);
buffer.append(SPACE);
@@ -696,10 +578,6 @@
}
}
- protected String getElementTrueName(String element) {
- return null;
- }
-
public void visit(IBulkInsert obj) {
formatBasicInsert(obj);
buffer.append(SPACE)
@@ -934,11 +812,7 @@
* @see
com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.connector.language.IQuery)
*/
public void visit(IQuery obj) {
- appendQuery(obj);
- }
-
- protected void appendQuery(IQuery obj) {
- append(obj.getSelect());
+ visitSelect(obj.getSelect(), obj);
if (obj.getFrom() != null) {
buffer.append(SPACE);
append(obj.getFrom());
@@ -999,29 +873,23 @@
* @see
com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.connector.language.ISelect)
*/
public void visit(ISelect obj) {
- visitSelect(obj);
+ visitSelect(obj, null);
}
-
- protected String addProcessComment() {
- return ""; //$NON-NLS-1$
- }
-
- /**
- * This method outputs the 'SELECT' keyword and select symbols. Subclasses
- * should override to change/add behavior.
- * @param obj ISelect object
- * @since 4.3
- */
- protected void visitSelect(ISelect obj) {
- buffer.append(SELECT).append(SPACE);
- buffer.append(addProcessComment());
+ private void visitSelect(ISelect obj, ICommand command) {
+ buffer.append(SELECT).append(SPACE);
+ buffer.append(getSourceComment(command));
if (obj.isDistinct()) {
buffer.append(DISTINCT).append(SPACE);
}
append(obj.getSelectSymbols());
- }
+ }
+
+ protected String getSourceComment(ICommand command) {
+ return ""; //$NON-NLS-1$
+ }
+
/*
* @see
com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.IScalarSubquery)
*/
@@ -1095,7 +963,7 @@
public void visit(IUpdate obj) {
buffer.append(UPDATE)
.append(SPACE);
- buffer.append(addProcessComment());
+ buffer.append(getSourceComment(obj));
append(obj.getGroup());
buffer.append(SPACE)
.append(SET)
@@ -1114,7 +982,7 @@
}
public void visit(ISetClause clause) {
- buffer.append(getElementShortName(clause.getSymbol()));
+ buffer.append(getElementName(clause.getSymbol(), false));
buffer.append(SPACE).append(EQ).append(SPACE);
append(clause.getValue());
}
@@ -1123,6 +991,7 @@
appendSetQuery(obj.getLeftQuery());
buffer.append(SPACE);
+
appendSetOperation(obj.getOperation());
if(obj.isAll()) {
@@ -1149,14 +1018,18 @@
protected void appendSetOperation(ISetQuery.Operation operation) {
buffer.append(operation);
}
+
+ protected boolean useParensForSetQueries() {
+ return false;
+ }
protected void appendSetQuery(IQueryCommand obj) {
- if(obj instanceof ISetQuery) {
+ if(obj instanceof ISetQuery || useParensForSetQueries()) {
buffer.append(LPAREN);
append(obj);
buffer.append(RPAREN);
} else {
- appendQuery((IQuery)obj);
+ append(obj);
}
}
@@ -1167,15 +1040,10 @@
* command
* @return the SQL representation of that ILanguageObject hierarchy
*/
- public static String getSQLString(ILanguageObject obj, RuntimeMetadata metadata) {
+ public static String getSQLString(ILanguageObject obj) {
SQLStringVisitor visitor = new SQLStringVisitor();
- visitor.setRuntimeMetadata(metadata);
visitor.append(obj);
return visitor.toString();
}
- public void setRuntimeMetadata(RuntimeMetadata metadata) {
- this.metadata = metadata;
- }
-
}
Modified:
trunk/connector-api/src/test/java/com/metamatrix/data/transform/TestBasicValueTranslator.java
===================================================================
---
trunk/connector-api/src/test/java/com/metamatrix/data/transform/TestBasicValueTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connector-api/src/test/java/com/metamatrix/data/transform/TestBasicValueTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -37,9 +37,8 @@
*/
public class TestBasicValueTranslator extends TestCase {
-
public void testExceptionFromTransform() throws Exception {
- BasicValueTranslator<String, Short> adaptor =
BasicValueTranslator.createTranslator(String.class, Short.class, new FakeTypeFacility());
+ BasicValueTranslator<String, Short> adaptor =
BasicValueTranslator.createTranslator(String.class, Short.class,
Mockito.mock(TypeFacility.class));
try {
adaptor.translate("mmuuid:blah",
Mockito.mock(ExecutionContext.class)); //$NON-NLS-1$
fail("exceptoin expected"); //$NON-NLS-1$
@@ -48,22 +47,4 @@
}
}
- static class FakeTypeFacility extends TypeFacility{
-
- @Override
- public boolean hasTransformation(Class sourceClass, Class targetClass) {
- return false;
- }
-
- @Override
- public Object transformValue(Object value, Class sourceClass, Class targetClass) throws
ConnectorException {
- throw new ConnectorException("not supported");
- }
-
- @Override
- public Object convertToRuntimeType(Object value) {
- return value;
- }
- }
-
}
Modified:
trunk/connector-sdk/src/test/java/com/metamatrix/cdk/unittest/FakeTranslationFactory.java
===================================================================
---
trunk/connector-sdk/src/test/java/com/metamatrix/cdk/unittest/FakeTranslationFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connector-sdk/src/test/java/com/metamatrix/cdk/unittest/FakeTranslationFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -24,6 +24,7 @@
import com.metamatrix.cdk.api.TranslationUtility;
import com.metamatrix.query.unittest.FakeMetadataFactory;
+import com.metamatrix.query.validator.TestValidator;
public class FakeTranslationFactory {
@@ -45,4 +46,8 @@
return new TranslationUtility(FakeMetadataFactory.exampleText());
}
+ public TranslationUtility getAutoIncrementTranslationUtility() {
+ return new TranslationUtility(TestValidator.exampleMetadata3());
+ }
+
}
Modified:
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-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCConnector.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -43,7 +43,6 @@
protected ConnectorEnvironment environment;
private ConnectorLogger logger;
private JDBCSourceConnectionFactory factory;
-
private ConnectorCapabilities capabilities;
static ConnectorCapabilities createCapabilities(ConnectorEnvironment environment,
ClassLoader loader)
Modified:
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-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCProcedureExecution.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -50,7 +50,6 @@
import com.metamatrix.connector.metadata.runtime.Element;
import com.metamatrix.connector.metadata.runtime.MetadataID;
import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
-import com.metamatrix.core.util.StringUtil;
/**
*/
@@ -90,9 +89,6 @@
//create statement or CallableStatement and execute
String sql = translatedComm.getSql();
try{
- if(translatedComm.getStatementType() !=
TranslatedCommand.STMT_TYPE_CALLABLE_STATEMENT){
- throw new
ConnectorException(JDBCPlugin.Util.getString("JDBCSynchExecution.Statement_type_not_support_for_command_1",
new Integer(translatedComm.getStatementType()), sql)); //$NON-NLS-1$
- }
//create parameter index map
parameterIndexMap = createParameterIndexMap(procedure.getParameters(), sql);
CallableStatement cstmt = getCallableStatement(sql);
@@ -200,7 +196,7 @@
if(value == null){
return null;
}
- Object result = JDBCExecutionHelper.convertValue(value, parameter.getType(),
this.resultsTranslator.getValueTranslators(), this.resultsTranslator.getTypefacility(),
trimString, context);
+ Object result = JDBCExecutionHelper.convertValue(value, parameter.getType(),
this.resultsTranslator.getValueTranslators(), this.resultsTranslator.getTypeFacility(),
trimString, context);
return result;
} catch (SQLException e) {
throw new ConnectorException(e);
Modified:
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-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCQueryExecution.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -107,16 +107,13 @@
try {
- if (translatedComm.getStatementType() ==
TranslatedCommand.STMT_TYPE_STATEMENT) {
+ if (!translatedComm.isPrepared()) {
results = getStatement().executeQuery(sql);
- } else if (translatedComm.getStatementType() ==
TranslatedCommand.STMT_TYPE_PREPARED_STATEMENT) {
- PreparedStatement pstatement = getPreparedStatement(sql);
+ } else {
+ PreparedStatement pstatement = getPreparedStatement(sql);
resultsTranslator.bindPreparedStatementValues(this.connection,
pstatement, translatedComm);
results = pstatement.executeQuery();
- } else {
- throw new ConnectorException(
-
JDBCPlugin.Util.getString("JDBCSynchExecution.Statement_type_not_support_for_command_1",
new Integer(translatedComm.getStatementType()), sql)); //$NON-NLS-1$
- }
+ }
addStatementWarnings();
initResultSetInfo();
@@ -157,13 +154,13 @@
for (int i = 0; i < columnDataTypes.length; i++) {
// Convert from 0-based to 1-based
- Object value =
resultsTranslator.getValueRetriever().retrieveValue(results, i+1, columnDataTypes[i],
nativeTypes[i], calendar, env.getTypeFacility());
+ Object value =
resultsTranslator.getValueRetriever().retrieveValue(results, i+1, columnDataTypes[i],
calendar, env.getTypeFacility());
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],
resultsTranslator.getValueTranslators(), resultsTranslator.getTypefacility());
+ transforms[i] =
JDBCExecutionHelper.determineTransformation(valueType, columnDataTypes[i],
resultsTranslator.getValueTranslators(), resultsTranslator.getTypeFacility());
}
transformKnown[i] = true;
}
Modified:
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-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCSourceConnection.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -25,7 +25,6 @@
package com.metamatrix.connector.jdbc;
import java.sql.SQLException;
-import java.util.Properties;
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
@@ -50,87 +49,51 @@
protected java.sql.Connection physicalConnection;
protected ConnectorEnvironment environment;
private ConnectorLogger logger;
- private ResultsTranslator resultsTranslator;
private ConnectionStrategy connectionStrategy;
private ConnectionListener connectionListener;
- private Class sqlTransClass;
+ private SQLTranslator sqlTranslator;
+ private ResultsTranslator resultsTranslator;
+
/**
* @param connection
*/
- public JDBCSourceConnection(java.sql.Connection connection, ConnectorEnvironment
environment, ConnectionStrategy connectionStrategy) throws ConnectorException{
- this(connection, environment, connectionStrategy, null);
+ public JDBCSourceConnection(java.sql.Connection connection, ConnectorEnvironment
environment, ConnectionStrategy connectionStrategy, ResultsTranslator resultsTranslator,
SQLTranslator sqlTranslator) throws ConnectorException{
+ this(connection, environment, connectionStrategy, null, resultsTranslator,
sqlTranslator);
}
- public JDBCSourceConnection(java.sql.Connection connection, ConnectorEnvironment
environment, ConnectionStrategy connectionStrategy, ConnectionListener connectionListener)
throws ConnectorException {
+ public JDBCSourceConnection(java.sql.Connection connection, ConnectorEnvironment
environment, ConnectionStrategy connectionStrategy, ConnectionListener connectionListener,
ResultsTranslator resultsTranslator, SQLTranslator sqlTranslator) throws
ConnectorException {
physicalConnection = connection;
this.environment = environment;
this.logger = environment.getLogger();
this.connectionStrategy = connectionStrategy;
this.connectionListener = connectionListener;
- try {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
- Properties connectorProps = environment.getProperties();
- //create SQLTranslator
- String className =
connectorProps.getProperty(JDBCPropertyNames.EXT_SQL_TRANSLATOR_CLASS);
- if(className == null){
- throw new
ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnection.Property_{0}_is_required,_but_not_defined_1",
JDBCPropertyNames.EXT_SQL_TRANSLATOR_CLASS)); //$NON-NLS-1$
- }
- sqlTransClass = Thread.currentThread().getContextClassLoader().loadClass(className);
-
- //create ResultsTranslator
- className =
connectorProps.getProperty(JDBCPropertyNames.EXT_RESULTS_TRANSLATOR_CLASS);
- if(className == null){
- throw new
ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnection.Property_{0}_is_required,_but_not_defined_1",
JDBCPropertyNames.EXT_RESULTS_TRANSLATOR_CLASS)); //$NON-NLS-1$
- }
- Class resultsTransClass = loader.loadClass(className);
- resultsTranslator = (ResultsTranslator) resultsTransClass.newInstance();
- resultsTranslator.initialize(environment);
- } catch (ClassNotFoundException e1) {
- throw new ConnectorException(e1);
- } catch (InstantiationException e2) {
- throw new ConnectorException(e2);
- } catch (IllegalAccessException e3) {
- throw new ConnectorException(e3);
- }
-
// notify the listner that coneection created
if (this.connectionListener != null) {
this.connectionListener.afterConnectionCreation(this.physicalConnection,
this.environment);
}
}
- private SQLTranslator getSQLTranslator(RuntimeMetadata metadata) throws
ConnectorException {
- try {
- SQLTranslator sqlTranslator = (SQLTranslator) sqlTransClass.newInstance();
- sqlTranslator.initialize(environment, metadata);
- return sqlTranslator;
- } catch (InstantiationException e) {
- throw new ConnectorException(e);
- } catch (IllegalAccessException e) {
- throw new ConnectorException(e);
- }
- }
-
@Override
public ResultSetExecution createResultSetExecution(IQueryCommand command,
ExecutionContext executionContext, RuntimeMetadata metadata)
throws ConnectorException {
- return new JDBCQueryExecution(command, this.physicalConnection,
getSQLTranslator(metadata), resultsTranslator, logger, this.environment.getProperties(),
executionContext, this.environment);
+ return new JDBCQueryExecution(command, this.physicalConnection, sqlTranslator,
resultsTranslator, 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,
getSQLTranslator(metadata), resultsTranslator, logger, this.environment.getProperties(),
metadata, executionContext, this.environment);
+ return new JDBCProcedureExecution(command, this.physicalConnection, sqlTranslator,
resultsTranslator, 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,
getSQLTranslator(metadata), resultsTranslator, logger, this.environment.getProperties(),
executionContext);
+ return new JDBCUpdateExecution(command, this.physicalConnection, sqlTranslator,
resultsTranslator, logger, this.environment.getProperties(), executionContext);
}
@Override
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCSourceConnectionFactory.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCSourceConnectionFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCSourceConnectionFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -35,6 +35,8 @@
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.ExecutionContext;
import com.metamatrix.connector.internal.ConnectorPropertyNames;
+import com.metamatrix.connector.jdbc.extension.ResultsTranslator;
+import com.metamatrix.connector.jdbc.extension.SQLTranslator;
import com.metamatrix.connector.pool.ConnectorIdentity;
import com.metamatrix.connector.pool.ConnectorIdentityFactory;
@@ -53,6 +55,8 @@
private String deregisterType;
private ConnectorIdentityFactory connectorIdentityFactory;
+ private SQLTranslator sqlTranslator;
+ private ResultsTranslator resultsTranslator;
/**
*
@@ -65,6 +69,34 @@
this.environment = env;
Properties props = env.getProperties();
this.deregisterType = props.getProperty(ConnectorPropertyNames.DEREGISTER_DRIVER,
ConnectorPropertyNames.DEREGISTER_BY_CLASSLOADER);
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+ Properties connectorProps = environment.getProperties();
+ //create SQLTranslator
+ String className =
connectorProps.getProperty(JDBCPropertyNames.EXT_SQL_TRANSLATOR_CLASS);
+ if(className == null){
+ throw new
ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnection.Property_{0}_is_required,_but_not_defined_1",
JDBCPropertyNames.EXT_SQL_TRANSLATOR_CLASS)); //$NON-NLS-1$
+ }
+ try {
+ Class sqlTransClass =
Thread.currentThread().getContextClassLoader().loadClass(className);
+ sqlTranslator = (SQLTranslator) sqlTransClass.newInstance();
+ sqlTranslator.initialize(environment);
+
+ //create ResultsTranslator
+ className =
connectorProps.getProperty(JDBCPropertyNames.EXT_RESULTS_TRANSLATOR_CLASS);
+ if(className == null){
+ throw new
ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnection.Property_{0}_is_required,_but_not_defined_1",
JDBCPropertyNames.EXT_RESULTS_TRANSLATOR_CLASS)); //$NON-NLS-1$
+ }
+ Class resultsTransClass = loader.loadClass(className);
+ resultsTranslator = (ResultsTranslator) resultsTransClass.newInstance();
+ resultsTranslator.initialize(environment);
+ } catch (ClassNotFoundException e) {
+ throw new ConnectorException(e);
+ } catch (InstantiationException e) {
+ throw new ConnectorException(e);
+ } catch (IllegalAccessException e) {
+ throw new ConnectorException(e);
+ }
}
protected ConnectorEnvironment getConnectorEnvironment() {
@@ -117,7 +149,7 @@
throw new ConnectorException(e);
}
- return new JDBCSourceConnection(connection, this.environment,
createConnectionStrategy(), getConnectionListener());
+ return new JDBCSourceConnection(connection, this.environment,
createConnectionStrategy(), getConnectionListener(), resultsTranslator, sqlTranslator);
}
/**
@@ -187,4 +219,12 @@
return this.connectorIdentityFactory.createIdentity(context);
}
+ public ResultsTranslator getResultsTranslator() {
+ return resultsTranslator;
+ }
+
+ public SQLTranslator getSqlTranslator() {
+ return sqlTranslator;
+ }
+
}
Modified:
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-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/JDBCUpdateExecution.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -109,16 +109,9 @@
for (int i = 0; i < commands.length; i++) {
TranslatedCommand command = translateCommand(commands[i]);
- if (command.getStatementType() ==
TranslatedCommand.STMT_TYPE_CALLABLE_STATEMENT) {
- throw new ConnectorException(
-
JDBCPlugin.Util.getString("JDBCSynchExecution.Statement_type_not_support_for_command_1",
//$NON-NLS-1$
- new
Integer(command.getStatementType()),
-
command.getSql()));
- }
- if (command.getStatementType() ==
TranslatedCommand.STMT_TYPE_PREPARED_STATEMENT) {
+ if (command.isPrepared()) {
PreparedStatement pstmt = null;
- if (previousCommand != null &&
previousCommand.getStatementType() == TranslatedCommand.STMT_TYPE_PREPARED_STATEMENT
- &&
previousCommand.getSql().equals(command.getSql())) {
+ if (previousCommand != null && previousCommand.isPrepared()
&& previousCommand.getSql().equals(command.getSql())) {
pstmt = (PreparedStatement)statement;
} else {
if (!executedCmds.isEmpty()) {
@@ -129,7 +122,7 @@
resultsTranslator.bindPreparedStatementValues(this.connection, pstmt,
command);
pstmt.addBatch();
} else {
- if (previousCommand != null &&
previousCommand.getStatementType() == TranslatedCommand.STMT_TYPE_PREPARED_STATEMENT) {
+ if (previousCommand != null && previousCommand.isPrepared())
{
executeBatch(i, results, executedCmds);
getStatement();
}
@@ -220,18 +213,13 @@
try {
int updateCount;
- if (translatedComm.getStatementType() ==
TranslatedCommand.STMT_TYPE_STATEMENT) {
+ if (!translatedComm.isPrepared()) {
updateCount = getStatement().executeUpdate(sql);
- } else if (translatedComm.getStatementType() ==
TranslatedCommand.STMT_TYPE_PREPARED_STATEMENT) {
- PreparedStatement pstatement = getPreparedStatement(sql);
+ } else {
+ PreparedStatement pstatement = getPreparedStatement(sql);
resultsTranslator.bindPreparedStatementValues(this.connection,
pstatement, translatedComm);
updateCount = pstatement.executeUpdate();
- } else {
- throw new ConnectorException(
-
JDBCPlugin.Util.getString("JDBCSynchExecution.Statement_type_not_support_for_command_1",
//$NON-NLS-1$
- new
Integer(translatedComm.getStatementType()),
- sql));
- }
+ }
addStatementWarnings();
return updateCount;
} catch (SQLException err) {
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/access/AccessSQLConversionVisitor.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/access/AccessSQLConversionVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/access/AccessSQLConversionVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,99 +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.access;
-
-import java.sql.Time;
-
-import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
-import com.metamatrix.connector.language.IQuery;
-import com.metamatrix.connector.language.ISelect;
-
-public class AccessSQLConversionVisitor extends SQLConversionVisitor{
-
- private int limit = 0;
- /*
- * @see
com.metamatrix.connector.jdbc.extension.SQLConversionVisitor#translateLiteralTime(java.sql.Time)
- */
- protected String translateLiteralTime(Time timeValue) {
- return "{ts'1900-01-01 " + formatDateValue(timeValue) +
"'}"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- protected String translateLiteralBoolean(Boolean booleanValue) {
- if(booleanValue.booleanValue()) {
- return "-1"; //$NON-NLS-1$
- }
- return "0"; //$NON-NLS-1$
- }
-
- protected void appendQuery(IQuery obj) {
- if (obj.getLimit() != null) {
- limit = obj.getLimit().getRowLimit();
- }
- append(obj.getSelect());
- if (obj.getFrom() != null) {
- buffer.append(SPACE);
- append(obj.getFrom());
- }
- if (obj.getWhere() != null) {
- buffer.append(SPACE)
- .append(WHERE)
- .append(SPACE);
- append(obj.getWhere());
- }
- if (obj.getGroupBy() != null) {
- buffer.append(SPACE);
- append(obj.getGroupBy());
- }
- if (obj.getHaving() != null) {
- buffer.append(SPACE)
- .append(HAVING)
- .append(SPACE);
- append(obj.getHaving());
- }
- if (obj.getOrderBy() != null) {
- buffer.append(SPACE);
- append(obj.getOrderBy());
- }
- }
-
- protected void visitSelect(ISelect obj) {
- buffer.append(SELECT).append(SPACE);
- if (limit > 0) {
- buffer.append("TOP") //$NON-NLS-1$
- .append(SPACE)
- .append(limit)
- .append(SPACE);
- limit = 0;
- }
- if (obj.isDistinct()) {
- buffer.append(DISTINCT).append(SPACE);
- }
- append(obj.getSelectSymbols());
- }
-
- protected boolean supportsComments() {
- return false;
- }
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/access/AccessSQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/access/AccessSQLTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/access/AccessSQLTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -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.jdbc.access;
-
-import java.util.Properties;
-
-import com.metamatrix.connector.api.ConnectorEnvironment;
-import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
-import com.metamatrix.connector.jdbc.extension.impl.BasicSQLTranslator;
-import com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
-
-public class AccessSQLTranslator extends BasicSQLTranslator {
- private Properties connectorProperties;
- private ILanguageFactory languageFactory;
-
- /**
- * @see
com.metamatrix.connector.jdbc.extension.SQLTranslator#getTranslationVisitor()
- */
- public SQLConversionVisitor getTranslationVisitor() {
- SQLConversionVisitor visitor = new AccessSQLConversionVisitor();
- visitor.setRuntimeMetadata(getRuntimeMetadata());
- visitor.setFunctionModifiers(getFunctionModifiers());
- visitor.setProperties(connectorProperties);
- visitor.setLanguageFactory(languageFactory);
- visitor.setDatabaseTimeZone(getDatabaseTimeZone());
- return visitor;
- }
-
- /*
- * @see
com.metamatrix.connector.jdbc.extension.SQLTranslator#initialize(com.metamatrix.data.api.ConnectorEnvironment,
com.metamatrix.data.metadata.runtime.RuntimeMetadata)
- */
- public void initialize(ConnectorEnvironment env, RuntimeMetadata metadata) throws
ConnectorException {
- super.initialize(env, metadata);
- connectorProperties = getConnectorEnvironment().getProperties();
- languageFactory = getConnectorEnvironment().getLanguageFactory();
- }
-}
Added:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/access/AccessSQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/access/AccessSQLTranslator.java
(rev 0)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/access/AccessSQLTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -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 com.metamatrix.connector.jdbc.access;
+
+import com.metamatrix.connector.jdbc.extension.SQLTranslator;
+import com.metamatrix.connector.language.ILimit;
+
+public class AccessSQLTranslator extends SQLTranslator {
+
+ @Override
+ public boolean hasTimeType() {
+ return false;
+ }
+
+ @Override
+ public String translateLiteralBoolean(Boolean booleanValue) {
+ if(booleanValue.booleanValue()) {
+ return "-1"; //$NON-NLS-1$
+ }
+ return "0"; //$NON-NLS-1$
+ }
+
+ @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();
+ }
+
+ @Override
+ public boolean addSourceComment() {
+ return false;
+ }
+
+}
Property changes on:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/access/AccessSQLTranslator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2Capabilities.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2Capabilities.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2Capabilities.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -104,7 +104,7 @@
supportedFunctions.add("CONVERT"); //$NON-NLS-1$
supportedFunctions.add("IFNULL"); //$NON-NLS-1$
supportedFunctions.add("NVL"); //$NON-NLS-1$
-
+ supportedFunctions.add("COALESCE"); //$NON-NLS-1$
return supportedFunctions;
}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2ResultsTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2ResultsTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2ResultsTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,33 +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 com.metamatrix.connector.jdbc.extension.impl.BasicResultsTranslator;
-
-/**
- */
-public class DB2ResultsTranslator extends BasicResultsTranslator {
- //TODO
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2SQLConversionVisitor.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2SQLConversionVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2SQLConversionVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,109 +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 com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
-import com.metamatrix.connector.language.IFromItem;
-import com.metamatrix.connector.language.IJoin;
-import com.metamatrix.connector.language.ILimit;
-import com.metamatrix.connector.language.IJoin.JoinType;
-
-/**
- * @since 4.3
- */
-public class DB2SQLConversionVisitor extends SQLConversionVisitor {
-
- private final int MAX_SELECT_ALIAS_LENGTH = 30;
-
- private final int MAX_TABLE_ALIAS_LENGTH = 128;
-
- /**
- * Convert limit clause to DB2 ...FETCH FIRST rowlimit ROWS ONLY syntax
- * @see
com.metamatrix.connector.visitor.framework.LanguageObjectVisitor#visit(com.metamatrix.connector.language.IQuery)
- * @since 5.0 SP1
- */
- public void visit(ILimit obj) {
- buffer.append("FETCH") //$NON-NLS-1$
- .append(SPACE)
- .append("FIRST") //$NON-NLS-1$
- .append(SPACE)
- .append(obj.getRowLimit())
- .append(SPACE)
- .append("ROWS") //$NON-NLS-1$
- .append(SPACE)
- .append("ONLY"); //$NON-NLS-1$
- }
-
- /**
- * @see
com.metamatrix.connector.jdbc.extension.SQLConversionVisitor#getMaxSelectAliasLength()
- * @since 4.3
- */
- protected int getMaxSelectAliasLength() {
- return MAX_SELECT_ALIAS_LENGTH;
- }
-
- /**
- * @see
com.metamatrix.connector.jdbc.extension.SQLConversionVisitor#getMaxTableAliasLength()
- * @since 4.3
- */
- protected int getMaxTableAliasLength() {
- return MAX_TABLE_ALIAS_LENGTH;
- }
-
- /**
- * @see
com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.connector.language.IJoin)
- */
- public void visit(IJoin obj) {
- if(obj.getJoinType() != JoinType.CROSS_JOIN) {
- super.visit(obj);
- return;
- }
-
- IFromItem leftItem = obj.getLeftItem();
- if(leftItem instanceof IJoin) {
- buffer.append(LPAREN);
- append(leftItem);
- buffer.append(RPAREN);
- } else {
- append(leftItem);
- }
- buffer.append(SPACE)
- .append(INNER)
- .append(SPACE)
- .append(JOIN)
- .append(SPACE);
-
- IFromItem rightItem = obj.getRightItem();
- if(rightItem instanceof IJoin) {
- buffer.append(LPAREN);
- append(rightItem);
- buffer.append(RPAREN);
- } else {
- append(rightItem);
- }
-
- buffer.append(SPACE)
- .append(ON).append(SPACE)
- .append("1=1");//$NON-NLS-1$
- }
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2SQLModificationVisitor.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2SQLModificationVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2SQLModificationVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,39 +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 com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.connector.visitor.framework.HierarchyVisitor;
-
-
-/**
- */
-public class DB2SQLModificationVisitor extends HierarchyVisitor {
-
- private ILanguageFactory languageFactory;
-
- public DB2SQLModificationVisitor(ILanguageFactory languageFactory) {
- this.languageFactory = languageFactory;
- }
-
-}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2SQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2SQLTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2SQLTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -24,75 +24,64 @@
*/
package com.metamatrix.connector.jdbc.db2;
-import java.util.HashMap;
-import java.util.Map;
-
+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.jdbc.extension.SQLConversionVisitor;
-import com.metamatrix.connector.jdbc.extension.impl.AliasModifier;
-import com.metamatrix.connector.jdbc.extension.impl.BasicSQLTranslator;
+import com.metamatrix.connector.api.SourceSystemFunctions;
+import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.jdbc.extension.SQLTranslator;
+import com.metamatrix.connector.jdbc.extension.impl.AliasModifier;
import com.metamatrix.connector.language.ICommand;
-import com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
+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 BasicSQLTranslator {
-
- private Map functionModifiers;
- private ILanguageFactory languageFactory;
-
- /*
- * @see
com.metamatrix.connector.jdbc.extension.SQLTranslator#initialize(com.metamatrix.data.api.ConnectorEnvironment,
com.metamatrix.data.metadata.runtime.RuntimeMetadata)
- */
- public void initialize(ConnectorEnvironment env, RuntimeMetadata metadata) throws
ConnectorException {
- super.initialize(env, metadata);
- languageFactory = getConnectorEnvironment().getLanguageFactory();
- initializeFunctionModifiers();
- }
-
- private void initializeFunctionModifiers() {
- functionModifiers = new HashMap();
- functionModifiers.putAll(super.getFunctionModifiers());
- functionModifiers.put("cast", new DB2ConvertModifier(languageFactory));
//$NON-NLS-1$
- functionModifiers.put("char", new AliasModifier("chr"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("convert", new
DB2ConvertModifier(languageFactory)); //$NON-NLS-1$
- functionModifiers.put("dayofmonth", new
AliasModifier("day")); //$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("ifnull", new
AliasModifier("coalesce")); //$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("nvl", new AliasModifier("coalesce"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("substring", new
AliasModifier("substr")); //$NON-NLS-1$ //$NON-NLS-2$
- }
+public class DB2SQLTranslator extends SQLTranslator {
+
+ @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 getConnectionTestQuery() {
+ return "Select 'x' from sysibm.systables where 1 = 2"; //$NON-NLS-1$
+ }
- /**
- * @see com.metamatrix.connector.jdbc.extension.SQLTranslator#getFunctionModifiers()
- */
- public Map getFunctionModifiers() {
- return functionModifiers;
- }
-
- /**
- * @see
com.metamatrix.connector.jdbc.extension.SQLTranslator#modifyCommand(com.metamatrix.connector.language.ICommand,
com.metamatrix.data.SecurityContext)
- */
- public ICommand modifyCommand(ICommand command, ExecutionContext context) throws
ConnectorException {
- // DB2-specific modification
- DB2SQLModificationVisitor visitor = new
DB2SQLModificationVisitor(getConnectorEnvironment().getLanguageFactory());
- command.acceptVisitor(visitor);
- return command;
- }
-
- /**
- * @see
com.metamatrix.connector.jdbc.extension.SQLTranslator#getTranslationVisitor()
- */
- public SQLConversionVisitor getTranslationVisitor() {
- SQLConversionVisitor visitor = new DB2SQLConversionVisitor();
- visitor.setRuntimeMetadata(getRuntimeMetadata());
- visitor.setFunctionModifiers(functionModifiers);
- visitor.setProperties(super.getConnectorEnvironment().getProperties());
- visitor.setLanguageFactory(languageFactory);
- visitor.setDatabaseTimeZone(getDatabaseTimeZone());
- return visitor;
- }
-
}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2SingleIdentityConnectionFactory.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2SingleIdentityConnectionFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2SingleIdentityConnectionFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,38 +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 com.metamatrix.connector.jdbc.*;
-import com.metamatrix.connector.jdbc.ConnectionStrategy;
-import com.metamatrix.connector.jdbc.JDBCSingleIdentityConnectionFactory;
-
-public class DB2SingleIdentityConnectionFactory extends
JDBCSingleIdentityConnectionFactory{
- private String queryTest = "Select 'x' from sysibm.systables where 1 =
2"; //$NON-NLS-1$
-
- protected ConnectionStrategy createConnectionStrategy() {
- return new ConnectionQueryStrategy(queryTest);
- }
-
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2UserIdentityConnectionFactory.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2UserIdentityConnectionFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/db2/DB2UserIdentityConnectionFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,38 +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 com.metamatrix.connector.jdbc.*;
-import com.metamatrix.connector.jdbc.ConnectionStrategy;
-import com.metamatrix.connector.jdbc.JDBCUserIdentityConnectionFactory;
-
-public class DB2UserIdentityConnectionFactory extends JDBCUserIdentityConnectionFactory{
- private String queryTest = "Select 'x' from sysibm.systables where 1 =
2"; //$NON-NLS-1$
-
- protected ConnectionStrategy createConnectionStrategy() {
- return new ConnectionQueryStrategy(queryTest);
- }
-
-}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyCapabilities.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyCapabilities.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyCapabilities.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -120,7 +120,7 @@
supportedFunctions.add("CONVERT"); //$NON-NLS-1$
supportedFunctions.add("IFNULL"); //$NON-NLS-1$
supportedFunctions.add("NVL"); //$NON-NLS-1$
-
+ supportedFunctions.add("COALESCE"); //$NON-NLS-1$
return supportedFunctions;
}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyConversionVisitor.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyConversionVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyConversionVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -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.derby;
-
-import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
-
-/**
- */
-class DerbyConversionVisitor extends SQLConversionVisitor {
-
- private final int MAX_TABLE_ALIAS_LENGTH = 128;
-
- /**
- * @see
com.metamatrix.connector.visitor.util.SQLStringVisitor#getMaxTableAliasLength()
- */
- protected int getMaxTableAliasLength() {
- return MAX_TABLE_ALIAS_LENGTH;
- }
-
- protected boolean supportsComments() {
- return false;
- }
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyResultsTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyResultsTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyResultsTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,33 +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 com.metamatrix.connector.jdbc.extension.impl.BasicResultsTranslator;
-
-
-/**
- * @since 4.3
- */
-public class DerbyResultsTranslator extends BasicResultsTranslator {
-
-}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbySQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbySQLTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbySQLTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -22,66 +22,40 @@
package com.metamatrix.connector.jdbc.derby;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
-import com.metamatrix.connector.jdbc.extension.impl.AliasModifier;
-import com.metamatrix.connector.jdbc.extension.impl.BasicSQLTranslator;
-import com.metamatrix.connector.jdbc.extension.impl.EscapeSyntaxModifier;
-import com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
+import com.metamatrix.connector.api.SourceSystemFunctions;
+import com.metamatrix.connector.jdbc.extension.SQLTranslator;
+import com.metamatrix.connector.jdbc.extension.impl.AliasModifier;
+import com.metamatrix.connector.jdbc.extension.impl.EscapeSyntaxModifier;
/**
* @since 4.3
*/
-public class DerbySQLTranslator extends BasicSQLTranslator {
-
- private Map functionModifiers;
- private Properties connectorProperties;
- private ILanguageFactory languageFactory;
-
- public void initialize(ConnectorEnvironment env,
- RuntimeMetadata metadata) throws ConnectorException {
-
- super.initialize(env, metadata);
- ConnectorEnvironment connEnv = getConnectorEnvironment();
- this.connectorProperties = connEnv.getProperties();
- this.languageFactory = connEnv.getLanguageFactory();
- initializeFunctionModifiers();
-
- }
-
- private void initializeFunctionModifiers() {
- functionModifiers = new HashMap();
- functionModifiers.putAll(super.getFunctionModifiers());
-
- functionModifiers.put("concat", new EscapeSyntaxModifier());
//$NON-NLS-1$
- functionModifiers.put("substring", new
AliasModifier("substr")); //$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("dayofmonth", new
AliasModifier("day")); //$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("timestampadd", new
DerbyTimestampFunctionModifier()); //$NON-NLS-1$
- functionModifiers.put("timestampdiff", new
DerbyTimestampFunctionModifier()); //$NON-NLS-1$
- functionModifiers.put("cast", new
DerbyConvertModifier(languageFactory)); //$NON-NLS-1$
- functionModifiers.put("convert", new
DerbyConvertModifier(languageFactory)); //$NON-NLS-1$
- functionModifiers.put("ifnull", new
AliasModifier("coalesce")); //$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("nvl", new AliasModifier("coalesce"));
//$NON-NLS-1$ //$NON-NLS-2$
+public class DerbySQLTranslator extends SQLTranslator {
+
+ @Override
+ public void initialize(ConnectorEnvironment env) throws ConnectorException {
+ super.initialize(env);
+ registerFunctionModifier(SourceSystemFunctions.CONCAT, new
EscapeSyntaxModifier()); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new
AliasModifier("substr")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new
AliasModifier("day")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new
EscapeSyntaxModifier()); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new
EscapeSyntaxModifier()); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.CONVERT, new
DerbyConvertModifier(getLanguageFactory())); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.IFNULL, new
AliasModifier("coalesce")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.COALESCE, new
AliasModifier("coalesce")); //$NON-NLS-1$ //$NON-NLS-2$
}
-
- public Map getFunctionModifiers() {
- return functionModifiers;
+
+ @Override
+ public boolean addSourceComment() {
+ return false;
+ }
+
+ @Override
+ public String getConnectionTestQuery() {
+ return "Select 0 from sys.systables where 1 = 2"; //$NON-NLS-1$
}
- public SQLConversionVisitor getTranslationVisitor() {
- SQLConversionVisitor visitor = new DerbyConversionVisitor();
- visitor.setRuntimeMetadata(getRuntimeMetadata());
- visitor.setFunctionModifiers(functionModifiers);
- visitor.setProperties(connectorProperties);
- visitor.setLanguageFactory(languageFactory);
- visitor.setDatabaseTimeZone(getDatabaseTimeZone());
- return visitor;
- }
}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbySingleIdentityConnectionFactory.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbySingleIdentityConnectionFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbySingleIdentityConnectionFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,43 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.connector.jdbc.derby;
-
-import com.metamatrix.connector.jdbc.ConnectionQueryStrategy;
-import com.metamatrix.connector.jdbc.ConnectionStrategy;
-import com.metamatrix.connector.jdbc.JDBCSingleIdentityConnectionFactory;
-
-
-/**
- * @since 4.3
- */
-public class DerbySingleIdentityConnectionFactory extends
JDBCSingleIdentityConnectionFactory {
- private String queryTest = "Select 0 from sys.systables where 1 = 2";
//$NON-NLS-1$
-
- /**
- * @see
com.metamatrix.connector.jdbc.JDBCSourceConnectionFactory#createConnectionStrategy()
- * @since 4.3
- */
- protected ConnectionStrategy createConnectionStrategy() {
- return new ConnectionQueryStrategy(queryTest);
- }
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyTimestampFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyTimestampFunctionModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyTimestampFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -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.derby;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.metamatrix.connector.jdbc.extension.impl.BasicFunctionModifier;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILiteral;
-
-
-public class DerbyTimestampFunctionModifier extends BasicFunctionModifier {
-
- public DerbyTimestampFunctionModifier() {
- super();
- }
-
-/**
- * @see
com.metamatrix.connector.jdbc.extension.impl.BasicFunctionModifier#translate(com.metamatrix.connector.language.IFunction)
- * @since 4.3
- */
- public List translate(IFunction function) {
- List objs = new ArrayList();
- objs.add("{fn "); //$NON-NLS-1$
- objs.add(function.getName());
- objs.add("("); //$NON-NLS-1$
-
- IExpression[] args = function.getParameters();
- if(args != null && args.length > 0) {
- objs.add(((ILiteral)args[0]).getValue());
-
- for(int i=1; i<args.length; i++) {
- objs.add(", "); //$NON-NLS-1$
- objs.add(args[i]);
- }
- }
- objs.add(")}"); //$NON-NLS-1$
- return objs;
- }
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyUserIdentityConnectionFactory.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyUserIdentityConnectionFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/derby/DerbyUserIdentityConnectionFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,43 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.connector.jdbc.derby;
-
-import com.metamatrix.connector.jdbc.ConnectionQueryStrategy;
-import com.metamatrix.connector.jdbc.ConnectionStrategy;
-import com.metamatrix.connector.jdbc.JDBCUserIdentityConnectionFactory;
-
-
-/**
- * @since 4.3
- */
-public class DerbyUserIdentityConnectionFactory extends JDBCUserIdentityConnectionFactory
{
- private String queryTest = "Select 0 from sys.systables where 1 = 2";
//$NON-NLS-1$
-
- /**
- * @see
com.metamatrix.connector.jdbc.JDBCSourceConnectionFactory#createConnectionStrategy()
- * @since 4.3
- */
- protected ConnectionStrategy createConnectionStrategy() {
- return new ConnectionQueryStrategy(queryTest);
- }
-}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/BindValueVisitor.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/BindValueVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/BindValueVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -22,7 +22,6 @@
package com.metamatrix.connector.jdbc.extension;
-import com.metamatrix.connector.language.ICaseExpression;
import com.metamatrix.connector.language.ICompareCriteria;
import com.metamatrix.connector.language.IExistsCriteria;
import com.metamatrix.connector.language.IFunction;
@@ -101,20 +100,8 @@
}
/**
- * Will look for bind values in the when expressions.
- * The actual restriction for case statements seems to be that at least on branch
must
- * not contain a bind variable.
- */
- public void visit(ICaseExpression obj) {
- replaceWithBinding = true;
- for (int i = 0; i < obj.getWhenCount(); i++) {
- visitNode(obj.getWhenExpression(i));
- }
- }
-
- /**
* Will look for bind values in the when criteria.
- * The actual restriction for case statements seems to be that at least on branch
must
+ * The actual restriction for case statements seems to be that at least one branch
must
* not contain a bind variable.
*/
public void visit(ISearchedCaseExpression obj) {
@@ -122,7 +109,8 @@
visitNode(obj.getWhenCriteria(i));
}
}
-
+
+ @Override
public void visit(IInsert obj) {
replaceWithBinding = true;
visitNodes(obj.getValues());
@@ -139,7 +127,7 @@
obj.setBindValue(true);
}
}
-
+
public void visitNode(ILanguageObject obj) {
boolean replacementMode = replaceWithBinding;
super.visitNode(obj);
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/ResultsTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/ResultsTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/ResultsTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -122,5 +122,5 @@
int getMaxResultRows();
- TypeFacility getTypefacility();
+ TypeFacility getTypeFacility();
}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/SQLConversionVisitor.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/SQLConversionVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/SQLConversionVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -27,74 +27,67 @@
import java.sql.Time;
import java.sql.Timestamp;
import java.text.DecimalFormat;
-import java.text.FieldPosition;
-import java.text.MessageFormat;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.TimeZone;
import com.metamatrix.connector.api.ExecutionContext;
import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.jdbc.JDBCPropertyNames;
import com.metamatrix.connector.language.IBulkInsert;
-import com.metamatrix.connector.language.IDelete;
+import com.metamatrix.connector.language.ICommand;
import com.metamatrix.connector.language.IElement;
import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.IInsert;
-import com.metamatrix.connector.language.ILanguageFactory;
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.IUpdate;
+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 SQLTranslator#getTranslationVisitor() using this method}.
+ * {@link SQLTranslator#getTranslationVisitor(RuntimeMetadata) using this method}.
*/
public class SQLConversionVisitor extends SQLStringVisitor{
- private static DecimalFormat decimalFormatter =
+ 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 static final MessageFormat COMMENT = new MessageFormat("/*metamatrix
sessionid:{0}, requestid:{1}.{2}*/ "); //$NON-NLS-1$
- private boolean useComment = false;
- private Map modifiers;
+ private Map<String, FunctionModifier> modifiers;
private ExecutionContext context;
- private ILanguageFactory languageFactory;
- private TimeZone databaseTimeZone;
+ private SQLTranslator translator;
+ private Calendar cal;
- private int execType = TranslatedCommand.EXEC_TYPE_QUERY;
- private int stmtType = TranslatedCommand.STMT_TYPE_STATEMENT;
+ private boolean prepared;
private List preparedValues = new ArrayList();
private List preparedTypes = new ArrayList();
- public SQLConversionVisitor() {
- super();
+ public SQLConversionVisitor(SQLTranslator translator) {
+ this.translator = translator;
+ this.prepared = translator.usePreparedStatements();
+ this.modifiers = translator.getFunctionModifiers();
+ TimeZone tz = translator.getDatabaseTimeZone();
+ if (tz != null) {
+ this.cal = Calendar.getInstance(tz);
+ }
}
- /**
- * @see
com.metamatrix.connector.visitor.util.SQLStringVisitor#visit(com.metamatrix.connector.language.IInsert)
- */
- public void visit(IInsert obj) {
- this.execType = TranslatedCommand.EXEC_TYPE_UPDATE;
- super.visit(obj);
- }
-
public void visit(IBulkInsert obj) {
- this.stmtType = TranslatedCommand.STMT_TYPE_PREPARED_STATEMENT;
+ this.prepared = true;
super.visit(obj);
@@ -130,19 +123,21 @@
// where toString will use for numbers greater than 10p7 and
// less than 10p-3, where database may not understand.
if (useFormatting) {
- valuesbuffer.append(decimalFormatter.format(obj));
+ synchronized (DECIMAL_FORMAT) {
+ valuesbuffer.append(DECIMAL_FORMAT.format(obj));
+ }
}
else {
valuesbuffer.append(obj);
}
} else if(type.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN)) {
- valuesbuffer.append(translateLiteralBoolean((Boolean)obj));
+ valuesbuffer.append(translator.translateLiteralBoolean((Boolean)obj));
} else if(type.equals(TypeFacility.RUNTIME_TYPES.TIMESTAMP)) {
- valuesbuffer.append(translateLiteralTimestamp((Timestamp)obj));
+ valuesbuffer.append(translator.translateLiteralTimestamp((Timestamp)obj,
cal));
} else if(type.equals(TypeFacility.RUNTIME_TYPES.TIME)) {
- valuesbuffer.append(translateLiteralTime((Time)obj));
+ valuesbuffer.append(translator.translateLiteralTime((Time)obj, cal));
} else if(type.equals(TypeFacility.RUNTIME_TYPES.DATE)) {
- valuesbuffer.append(translateLiteralDate((java.sql.Date)obj));
+ valuesbuffer.append(translator.translateLiteralDate((java.sql.Date)obj,
cal));
} else {
// If obj is string, toSting() will not create a new String
// object, it returns it self, so new object creation.
@@ -154,27 +149,10 @@
}
/**
- * @see
com.metamatrix.connector.visitor.util.SQLStringVisitor#visit(com.metamatrix.connector.language.IUpdate)
- */
- public void visit(IUpdate obj) {
- this.execType = TranslatedCommand.EXEC_TYPE_UPDATE;
- super.visit(obj);
- }
-
- /**
- * @see
com.metamatrix.connector.visitor.util.SQLStringVisitor#visit(com.metamatrix.connector.language.IQuery)
- */
- public void visit(IQuery obj) {
- this.execType = TranslatedCommand.EXEC_TYPE_QUERY;
- super.visit(obj);
- }
-
- /**
* @see
com.metamatrix.connector.visitor.util.SQLStringVisitor#visit(com.metamatrix.connector.language.IProcedure)
*/
public void visit(IProcedure obj) {
- this.execType = TranslatedCommand.EXEC_TYPE_EXECUTE;
- this.stmtType = TranslatedCommand.STMT_TYPE_CALLABLE_STATEMENT;
+ this.prepared = true;
/*
* preparedValues is now a list of procedure params instead of just values
*/
@@ -183,14 +161,6 @@
}
/**
- * @see
com.metamatrix.connector.visitor.util.SQLStringVisitor#visit(com.metamatrix.connector.language.IDelete)
- */
- public void visit(IDelete obj) {
- this.execType = TranslatedCommand.EXEC_TYPE_UPDATE;
- super.visit(obj);
- }
-
- /**
* @see
com.metamatrix.connector.visitor.util.SQLStringVisitor#visit(com.metamatrix.connector.language.IFunction)
*/
public void visit(IFunction obj) {
@@ -221,7 +191,7 @@
* @see
com.metamatrix.connector.visitor.util.SQLStringVisitor#visit(com.metamatrix.connector.language.ILiteral)
*/
public void visit(ILiteral obj) {
- if (this.stmtType == TranslatedCommand.STMT_TYPE_PREPARED_STATEMENT &&
obj.isBindValue()) {
+ if (this.prepared && obj.isBindValue()) {
buffer.append(UNDEFINED_PARAM);
preparedValues.add(obj.getValue());
preparedTypes.add(obj.getType());
@@ -231,102 +201,6 @@
}
/**
- * Subclasses should override this method to provide a different sql translation
- * of the literal boolean value. By default, a boolean literal is represented as:
- * <code>'0'</code> or <code>'1'</code>.
- * @param booleanValue Boolean value, never null
- * @return Translated string
- */
- protected String translateLiteralBoolean(Boolean booleanValue) {
- if(booleanValue.booleanValue()) {
- return "1"; //$NON-NLS-1$
- }
- return "0"; //$NON-NLS-1$
- }
-
- /**
- * Subclasses should override this method to provide a different sql translation
- * of the literal date value. By default, a date literal is represented as:
- * <code>{d'2002-12-31'}</code>
- * @param dateValue Date value, never null
- * @return Translated string
- */
- protected String translateLiteralDate(java.sql.Date dateValue) {
- return "{d'" + formatDateValue(dateValue) + "'}";
//$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Subclasses should override this method to provide a different sql translation
- * of the literal time value. By default, a time literal is represented as:
- * <code>{t'23:59:59'}</code>
- * @param timeValue Time value, never null
- * @return Translated string
- */
- protected String translateLiteralTime(Time timeValue) {
- return "{t'" + formatDateValue(timeValue) + "'}";
//$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Subclasses should override this method to provide a different sql translation
- * of the literal timestamp value. By default, a timestamp literal is
- * represented as: <code>{ts'2002-12-31 23:59:59'}</code>.
- * @param timestampValue Timestamp value, never null
- * @return Translated string
- */
- protected String translateLiteralTimestamp(Timestamp timestampValue) {
- return "{ts'" + formatDateValue(timestampValue) +
"'}"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Format the dateObject (of type date, time, or timestamp) into a string
- * using the DatabaseTimeZone format.
- * @param dateObject
- * @return Formatted string
- */
- protected String formatDateValue(Object dateObject) {
- if(this.databaseTimeZone == null) {
- return dateObject.toString();
- }
-
-//System.out.println("!!! translating timestamp value " + dateObject + "
(" + ((java.util.Date)dateObject).getTime() + " in " +
this.databaseTimeZone);
-
- if(dateObject instanceof Timestamp) {
- SimpleDateFormat timestampFormatter = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss"); //$NON-NLS-1$
- timestampFormatter.setTimeZone(this.databaseTimeZone);
-
- Timestamp ts = (Timestamp) dateObject;
- String nanoStr = "" + (1000000000L + ts.getNanos()); //$NON-NLS-1$
- while(nanoStr.length() > 2 && nanoStr.charAt(nanoStr.length()-1)
== '0') {
- nanoStr = nanoStr.substring(0, nanoStr.length()-1);
- }
- String tsStr = timestampFormatter.format(ts) + "." +
nanoStr.substring(1); //$NON-NLS-1$
-
-//System.out.println("!!! returning " + tsStr);
-
- return tsStr;
-
- } else if(dateObject instanceof java.sql.Date) {
- SimpleDateFormat dateFormatter = new
SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$
- dateFormatter.setTimeZone(this.databaseTimeZone);
- return dateFormatter.format((java.sql.Date)dateObject);
-
- } else if(dateObject instanceof Time) {
- SimpleDateFormat timeFormatter = new SimpleDateFormat("HH:mm:ss");
//$NON-NLS-1$
- timeFormatter.setTimeZone(this.databaseTimeZone);
- return timeFormatter.format((java.sql.Time)dateObject);
-
- } else {
- return dateObject.toString();
- }
- }
-
- /**
- */
- public void setFunctionModifiers(Map modifiers) {
- this.modifiers = modifiers;
- }
-
- /**
* Set the per-command execution context on this visitor.
* @param context ExecutionContext
* @since 4.3
@@ -345,39 +219,11 @@
return this.context;
}
- public void setProperties(Properties props) {
- String useBindVariables = props.getProperty(JDBCPropertyNames.USE_BIND_VARIABLES,
Boolean.FALSE.toString());
- if (useBindVariables.equals(Boolean.TRUE.toString())) {
- this.stmtType = TranslatedCommand.STMT_TYPE_PREPARED_STATEMENT;
- }
-
- String useCommentInSource =
props.getProperty(JDBCPropertyNames.USE_COMMENTS_SOURCE_QUERY);
- if (useCommentInSource != null) {
- this.useComment = Boolean.valueOf(useCommentInSource).booleanValue();
- }
+ protected String getSourceComment(ICommand command) {
+ return this.translator.getSourceComment(this.context, command);
}
/**
- * inserting the comments is the source SQL supported or not by the
- * source data source. By default it is turned on; user has choice to
- * turn off by setting the connector property; the data base source has
- * option to turn off by overloading this.
- * @return true if yes; false otherwise.
- */
- protected boolean supportsComments() {
- return this.useComment;
- }
-
- static final FieldPosition FIELD_ZERO = new FieldPosition(0);
- protected String addProcessComment() {
- if (supportsComments() && this.context != null) {
- return COMMENT.format(new Object[] {this.context.getConnectionIdentifier(),
this.context.getRequestIdentifier(), this.context.getPartIdentifier()});
- }
- return super.addProcessComment();
- }
-
-
- /**
* This is a generic implementation. Subclass should override this method
* if necessary.
* @param exec The command for the stored procedure.
@@ -400,7 +246,7 @@
}
}
- prepareCallBuffer.append(addProcessComment());
+ prepareCallBuffer.append(getSourceComment(exec));
if(needQuestionMark){
prepareCallBuffer.append("?="); //$NON-NLS-1$
@@ -427,36 +273,7 @@
return prepareCallBuffer.toString();
}
- /**
- * @param factory
- */
- public void setLanguageFactory(ILanguageFactory factory) {
- languageFactory = factory;
- }
-
- /**
- * @return
- */
- public ILanguageFactory getLanguageFactory() {
- return languageFactory;
- }
-
- public void setDatabaseTimeZone(TimeZone zone) {
- databaseTimeZone = zone;
- }
-
- protected TimeZone getDatabaseTimeZone() {
- return databaseTimeZone;
- }
-
/**
- * @return the execType
- */
- protected int getExecType() {
- return this.execType;
- }
-
- /**
* @return the preparedValues
*/
List getPreparedValues() {
@@ -470,15 +287,61 @@
return this.preparedTypes;
}
- /**
- * @return the stmtType
- */
- int getStmtType() {
- return this.stmtType;
+ public boolean isPrepared() {
+ return prepared;
+ }
+
+ public void setPrepared(boolean prepared) {
+ this.prepared = prepared;
+ }
+
+ @Override
+ protected boolean useAsInGroupAlias() {
+ return this.translator.useAsInGroupAlias();
}
- protected void setStmtType(int stmtType) {
- this.stmtType = stmtType;
+ @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));
+ }
+
}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/SQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/SQLTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/SQLTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -20,48 +20,229 @@
* 02110-1301 USA.
*/
-/*
- */
package com.metamatrix.connector.jdbc.extension;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.text.MessageFormat;
+import java.util.Calendar;
+import java.util.HashMap;
import java.util.Map;
+import java.util.TimeZone;
+import com.metamatrix.common.util.PropertiesUtils;
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.ExecutionContext;
+import com.metamatrix.connector.jdbc.JDBCPropertyNames;
import com.metamatrix.connector.language.ICommand;
-import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
+import com.metamatrix.connector.language.ILanguageFactory;
+import com.metamatrix.connector.language.ILimit;
+import com.metamatrix.connector.language.ISetQuery;
/**
+ * Base class for creating source SQL queries and retrieving results.
+ * Specific databases should override as necessary.
*/
-public interface SQLTranslator {
+public class SQLTranslator {
+
+ private static final MessageFormat COMMENT = new MessageFormat("/*teiid
sessionid:{0}, requestid:{1}.{2}*/ "); //$NON-NLS-1$
+
+ public final static TimeZone DEFAULT_TIME_ZONE = TimeZone.getDefault();
+
+ private Map<String, FunctionModifier> functionModifiers = new HashMap<String,
FunctionModifier>();
+ private TimeZone databaseTimeZone;
+ private ConnectorEnvironment environment;
+ private boolean useComments;
+ private boolean usePreparedStatements;
+
/**
* Initialize the SQLTranslator.
* @param env
* @param metadata
* @throws ConnectorException
*/
- void initialize(ConnectorEnvironment env, RuntimeMetadata metadata) throws
ConnectorException;
+ public void initialize(ConnectorEnvironment env) throws ConnectorException {
+ this.environment = env;
+
+ String timeZone =
env.getProperties().getProperty(JDBCPropertyNames.DATABASE_TIME_ZONE);
+ if(timeZone != null && timeZone.trim().length() > 0) {
+ TimeZone tz = TimeZone.getTimeZone(timeZone);
+ // Check that the dbms time zone is really different than the local time
zone
+ if(!DEFAULT_TIME_ZONE.hasSameRules(tz)) {
+ this.databaseTimeZone = tz;
+ }
+ }
+
+ this.useComments = PropertiesUtils.getBooleanProperty(env.getProperties(),
JDBCPropertyNames.USE_COMMENTS_SOURCE_QUERY, false);
+ this.usePreparedStatements =
PropertiesUtils.getBooleanProperty(env.getProperties(),
JDBCPropertyNames.USE_BIND_VARIABLES, false);
+ }
+ public TimeZone getDatabaseTimeZone() {
+ return databaseTimeZone;
+ }
+
+ public ConnectorEnvironment getEnvironment() {
+ return environment;
+ }
+
+ public ILanguageFactory getLanguageFactory() {
+ return environment.getLanguageFactory();
+ }
+
/**
* Modify the command.
* @param command
* @param context
* @return
*/
- ICommand modifyCommand(ICommand command, ExecutionContext context) throws
ConnectorException;
+ public ICommand modifyCommand(ICommand command, ExecutionContext context) throws
ConnectorException {
+ return command;
+ }
/**
- * Return the SQLConversionVisitor used for converting the command objects to
- * a sql string.
- * @return
+ * Return a map of function name in lower case to FunctionModifier.
+ * @return Map of function name to FunctionModifier.
*/
- SQLConversionVisitor getTranslationVisitor();
+ public Map<String, FunctionModifier> getFunctionModifiers() {
+ return functionModifiers;
+ }
+ public void registerFunctionModifier(String name, FunctionModifier modifier) {
+ this.functionModifiers.put(name, modifier);
+ }
+
/**
- * Return a map of function name in lower case to FunctionModifier.
- * @return Map of function name to FunctionModifier.
+ * Subclasses should override this method to provide a different sql translation
+ * of the literal boolean value. By default, a boolean literal is represented as:
+ * <code>'0'</code> or <code>'1'</code>.
+ * @param booleanValue Boolean value, never null
+ * @return Translated string
*/
- Map getFunctionModifiers();
+ public String translateLiteralBoolean(Boolean booleanValue) {
+ if(booleanValue.booleanValue()) {
+ return "1"; //$NON-NLS-1$
+ }
+ return "0"; //$NON-NLS-1$
+ }
+
+ /**
+ * Subclasses should override this method to provide a different sql translation
+ * of the literal date value. By default, a date literal is represented as:
+ * <code>{d'2002-12-31'}</code>
+ * @param dateValue Date value, never null
+ * @return Translated string
+ */
+ public String translateLiteralDate(java.sql.Date dateValue, Calendar cal) {
+ return "{d'" + formatDateValue(dateValue, cal) +
"'}"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Subclasses should override this method to provide a different sql translation
+ * of the literal time value. By default, a time literal is represented as:
+ * <code>{t'23:59:59'}</code>
+ * @param timeValue Time value, never null
+ * @return Translated string
+ */
+ public String translateLiteralTime(Time timeValue, Calendar cal) {
+ if (!hasTimeType()) {
+ return "{ts'1970-01-01 " + formatDateValue(timeValue, cal) +
"'}"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return "{t'" + formatDateValue(timeValue, cal) +
"'}"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Subclasses should override this method to provide a different sql translation
+ * of the literal timestamp value. By default, a timestamp literal is
+ * represented as: <code>{ts'2002-12-31 23:59:59'}</code>.
+ * @param timestampValue Timestamp value, never null
+ * @return Translated string
+ */
+ public String translateLiteralTimestamp(Timestamp timestampValue, Calendar cal) {
+ return "{ts'" + formatDateValue(timestampValue, cal) +
"'}"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Format the dateObject (of type date, time, or timestamp) into a string
+ * using the DatabaseTimeZone format.
+ * @param dateObject
+ * @param cal
+ * @return Formatted string
+ */
+ public String formatDateValue(java.util.Date dateObject, Calendar cal) {
+ if (dateObject instanceof Timestamp && getTimestampNanoSecondPrecision()
< 9) {
+ Timestamp ts = (Timestamp)dateObject;
+ Timestamp newTs = new Timestamp(ts.getTime());
+ if (getTimestampNanoSecondPrecision() > 0) {
+ int mask = 10^(9-getTimestampNanoSecondPrecision());
+ newTs.setNanos(ts.getNanos()/mask*mask);
+ }
+ dateObject = newTs;
+ }
+
+ if(cal == null) {
+ return dateObject.toString();
+ }
+
+ return getEnvironment().getTypeFacility().convertDate(dateObject,
+ DEFAULT_TIME_ZONE, cal, dateObject.getClass()).toString();
+ }
+
+ public boolean addSourceComment() {
+ 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
+ * data sources (such as Oracle) may not support the first
+ * form.
+ * @return boolean
+ */
+ public boolean useAsInGroupAlias(){
+ return true;
+ }
+
+ public boolean usePreparedStatements() {
+ return this.usePreparedStatements;
+ }
+
+ public boolean useParensForSetQueries() {
+ return false;
+ }
+
+ public boolean hasTimeType() {
+ return true;
+ }
+
+ public String getSetOperationString(ISetQuery.Operation operation) {
+ return operation.toString();
+ }
+
+ public String getSourceComment(ExecutionContext context, ICommand command) {
+ if (addSourceComment() && context != null) {
+ synchronized (COMMENT) {
+ return COMMENT.format(new Object[] {context.getConnectionIdentifier(),
context.getRequestIdentifier(), context.getPartIdentifier()});
+ }
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ public String replaceElementName(String group, String element) {
+ return null;
+ }
+
+ public int getTimestampNanoSecondPrecision() {
+ return 9;
+ }
+
+ public String getConnectionTestQuery() {
+ return "select 1"; //$NON-NLS-1$
+ }
+
}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/TranslatedCommand.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/TranslatedCommand.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/TranslatedCommand.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -42,27 +42,8 @@
*/
public class TranslatedCommand {
- /** the translated command is a query */
- public static final int EXEC_TYPE_QUERY = 0;
-
- /** the translated command is an insert, update, or delete */
- public static final int EXEC_TYPE_UPDATE = 1;
-
- /** the translated command is an execute-type command */
- public static final int EXEC_TYPE_EXECUTE = 2;
-
- /** execution of translated command requires a jdbc Statement */
- public static final int STMT_TYPE_STATEMENT = 0;
-
- /** execution of translated command requires a jdbc Prepared Statement */
- public static final int STMT_TYPE_PREPARED_STATEMENT = 1;
-
- /** execution of translated command requires a jdbc Callable Statement */
- public static final int STMT_TYPE_CALLABLE_STATEMENT = 2;
-
private String sql;
- private int executionType;
- private int statementType;
+ private boolean prepared;
private List preparedValues;
private List preparedTypes;
@@ -79,9 +60,8 @@
this.context = context;
this.sqlTranslator = sqlTranslator;
- Map modifiers = sqlTranslator.getFunctionModifiers();
- this.sqlConversionVisitor = sqlTranslator.getTranslationVisitor();
- sqlConversionVisitor.setFunctionModifiers(modifiers);
+ Map<String, FunctionModifier> modifiers =
sqlTranslator.getFunctionModifiers();
+ this.sqlConversionVisitor = new SQLConversionVisitor(sqlTranslator);
sqlConversionVisitor.setExecutionContext(context);
this.functionVisitor = new FunctionReplacementVisitor(modifiers);
}
@@ -102,18 +82,17 @@
*/
public void translateCommand(ICommand command) throws ConnectorException {
this.sql = getSQL(command);
- this.statementType = this.sqlConversionVisitor.getStmtType();
- this.executionType = this.sqlConversionVisitor.getExecType();
this.preparedValues = this.sqlConversionVisitor.getPreparedValues();
this.preparedTypes = this.sqlConversionVisitor.getPreparedTypes();
+ this.prepared = this.sqlConversionVisitor.isPrepared();
}
private String getSQL(ICommand command) throws ConnectorException {
command = sqlTranslator.modifyCommand(command, context);
command.acceptVisitor(functionVisitor);
- if (this.sqlConversionVisitor.getStmtType() == STMT_TYPE_PREPARED_STATEMENT ||
hasBindValue(command)) {
- this.sqlConversionVisitor.setStmtType(STMT_TYPE_PREPARED_STATEMENT);
+ if (sqlTranslator.usePreparedStatements() || hasBindValue(command)) {
+ this.sqlConversionVisitor.setPrepared(true);
command.acceptVisitor(new BindValueVisitor());
}
@@ -151,16 +130,6 @@
}
/**
- * Return the execution type, one of {@link #EXEC_TYPE_QUERY},
- * {@link #EXEC_TYPE_UPDATE}, or
- * {@link #EXEC_TYPE_EXECUTE}
- * @return execution type of translated command
- */
- public int getExecutionType() {
- return executionType;
- }
-
- /**
* Return List of values to set on a prepared statement, if
* necessary (see {@link #getStatementType})
* @return List of values to be set on a prepared statement
@@ -195,8 +164,8 @@
* {@link #STMT_TYPE_CALLABLE_STATEMENT}
* @return statement type of translated command
*/
- public int getStatementType() {
- return statementType;
+ public boolean isPrepared() {
+ return prepared;
}
}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/ValueRetriever.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/ValueRetriever.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/ValueRetriever.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -47,7 +47,7 @@
* @return The object that was retrieved
* @throws SQLException If an error occurred retrieving the value
*/
- Object retrieveValue(ResultSet results, int columnIndex, Class expectedType, int
nativeSQLType, Calendar cal, TypeFacility typeFacility) throws SQLException;
+ Object retrieveValue(ResultSet results, int columnIndex, Class expectedType, Calendar
cal, TypeFacility typeFacility) throws SQLException;
/**
* Retrieve the value at <code>parameterIndex</code> from the callable
statement
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/impl/BasicResultsTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/impl/BasicResultsTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/impl/BasicResultsTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -93,8 +93,7 @@
}
}
-
- public TypeFacility getTypefacility() {
+ public TypeFacility getTypeFacility() {
return typeFacility;
}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/impl/BasicSQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/impl/BasicSQLTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/impl/BasicSQLTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,109 +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.HashMap;
-import java.util.Map;
-import java.util.TimeZone;
-
-import com.metamatrix.connector.api.ConnectorEnvironment;
-import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.api.ExecutionContext;
-import com.metamatrix.connector.jdbc.JDBCPropertyNames;
-import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
-import com.metamatrix.connector.jdbc.extension.SQLTranslator;
-import com.metamatrix.connector.language.ICommand;
-import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
-
-/**
- */
-public class BasicSQLTranslator implements SQLTranslator {
- public final static TimeZone DEFAULT_TIME_ZONE = TimeZone.getDefault();
-
- private RuntimeMetadata metadata;
- private ConnectorEnvironment environment;
- private Map functionModifiers = new HashMap();
- private TimeZone databaseTimeZone;
-
-
- /**
- * @see
com.metamatrix.connector.jdbc.extension.SQLTranslator#initialize(com.metamatrix.data.ConnectorEnvironment)
- */
- public void initialize(ConnectorEnvironment env, RuntimeMetadata metadata) throws
ConnectorException {
- this.metadata = metadata;
- this.environment = env;
-
- String timeZone =
env.getProperties().getProperty(JDBCPropertyNames.DATABASE_TIME_ZONE);
- if(timeZone != null && timeZone.trim().length() > 0) {
- TimeZone tz = TimeZone.getTimeZone(timeZone);
- // Check that the dbms time zone is really different than the local time
zone
- if(!DEFAULT_TIME_ZONE.hasSameRules(tz)) {
- this.databaseTimeZone = tz;
- }
- }
-
- }
-
- /**
- * Subclass should override this methods to modify the command if necessary.
- * @see
com.metamatrix.connector.jdbc.extension.SQLTranslator#modifyCommand(com.metamatrix.connector.language.ICommand,
com.metamatrix.data.ExecutionContext)
- */
- public ICommand modifyCommand(ICommand command, ExecutionContext context) throws
ConnectorException {
- return command;
- }
-
- /**
- * @see
com.metamatrix.connector.jdbc.extension.SQLTranslator#getTranslationVisitor()
- */
- public SQLConversionVisitor getTranslationVisitor() {
- SQLConversionVisitor visitor = new SQLConversionVisitor();
- visitor.setRuntimeMetadata(metadata);
- visitor.setFunctionModifiers(getFunctionModifiers());
- visitor.setProperties(environment.getProperties());
- visitor.setLanguageFactory(environment.getLanguageFactory());
- visitor.setDatabaseTimeZone(databaseTimeZone);
-
- return visitor;
- }
-
- /**
- * @see com.metamatrix.connector.jdbc.extension.SQLTranslator#getFunctionModifiers()
- */
- public Map getFunctionModifiers() {
- return functionModifiers;
- }
-
- protected RuntimeMetadata getRuntimeMetadata(){
- return this.metadata;
- }
-
- protected ConnectorEnvironment getConnectorEnvironment(){
- return this.environment;
- }
-
- protected TimeZone getDatabaseTimeZone() {
- return this.databaseTimeZone;
- }
-}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/impl/BasicValueRetriever.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/impl/BasicValueRetriever.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/extension/impl/BasicValueRetriever.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -25,7 +25,6 @@
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.sql.Types;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
@@ -78,7 +77,7 @@
/*
* @see
com.metamatrix.connector.jdbc.extension.ValueRetriever#retrieveValue(java.sql.ResultSet,
int, java.lang.Class, java.util.Calendar)
*/
- public Object retrieveValue(ResultSet results, int columnIndex, Class expectedType,
int nativeSQLType, Calendar cal, TypeFacility typeFacility) throws SQLException {
+ public Object retrieveValue(ResultSet results, int columnIndex, Class expectedType,
Calendar cal, TypeFacility typeFacility) throws SQLException {
Integer code = (Integer) TYPE_CODE_MAP.get(expectedType);
if(code != null) {
// Calling the specific methods here is more likely to get uniform (and fast)
results from different
@@ -153,20 +152,7 @@
}
}
- // otherwise fall through and call getObject() and rely on the normal translation
routines
- switch(nativeSQLType) {
- case Types.BLOB:
- return typeFacility.convertToRuntimeType(results.getBlob(columnIndex));
- case Types.CLOB:
- return typeFacility.convertToRuntimeType(results.getClob(columnIndex));
- case Types.BINARY:
- case Types.VARBINARY:
- case Types.LONGVARBINARY:
- return typeFacility.convertToRuntimeType(results.getBytes(columnIndex));
- }
-
return typeFacility.convertToRuntimeType(results.getObject(columnIndex));
-
}
public Object retrieveValue(CallableStatement results, int parameterIndex, Class
expectedType, Calendar cal, TypeFacility typeFacility) throws SQLException{
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/InformixResultsTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/InformixResultsTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/InformixResultsTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,33 +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.informix;
-
-import com.metamatrix.connector.jdbc.extension.impl.BasicResultsTranslator;
-
-/**
- */
-public class InformixResultsTranslator extends BasicResultsTranslator {
- //TODO
-}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/InformixSQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/InformixSQLTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/InformixSQLTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -24,37 +24,25 @@
*/
package com.metamatrix.connector.jdbc.informix;
-import java.util.*;
-
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.jdbc.extension.impl.*;
-import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
+import com.metamatrix.connector.api.SourceSystemFunctions;
+import com.metamatrix.connector.jdbc.extension.SQLTranslator;
+import com.metamatrix.connector.jdbc.extension.impl.DropFunctionModifier;
/**
*/
-public class InformixSQLTranslator extends BasicSQLTranslator {
+public class InformixSQLTranslator extends SQLTranslator {
- private Map functionModifiers;
-
- public void initialize(ConnectorEnvironment env,
- RuntimeMetadata metadata) throws ConnectorException {
-
- super.initialize(env, metadata);
- initializeFunctionModifiers();
+ @Override
+ public void initialize(ConnectorEnvironment env) throws ConnectorException {
+ super.initialize(env);
+ registerFunctionModifier(SourceSystemFunctions.CONVERT, new DropFunctionModifier());
//$NON-NLS-1$
}
-
- private void initializeFunctionModifiers() {
- functionModifiers = new HashMap();
- functionModifiers.putAll(super.getFunctionModifiers());
- functionModifiers.put("cast", new DropFunctionModifier());
//$NON-NLS-1$
- functionModifiers.put("convert", new DropFunctionModifier());
//$NON-NLS-1$
- }
+
+ @Override
+ public String getConnectionTestQuery() {
+ return "select 'x' from informix.sysusers where 1=0"; //$NON-NLS-1$
+ }
- /**
- * @see com.metamatrix.connector.jdbc.extension.SQLTranslator#getFunctionModifiers()
- */
- public Map getFunctionModifiers() {
- return this.functionModifiers;
- }
}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/InformixSingleIdentityConnectionFactory.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/InformixSingleIdentityConnectionFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/InformixSingleIdentityConnectionFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,38 +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.informix;
-
-import com.metamatrix.connector.jdbc.*;
-import com.metamatrix.connector.jdbc.ConnectionStrategy;
-import com.metamatrix.connector.jdbc.JDBCSingleIdentityConnectionFactory;
-
-public class InformixSingleIdentityConnectionFactory extends
JDBCSingleIdentityConnectionFactory{
- private String queryTest = "select 'x' from informix.sysusers where
1=0"; //$NON-NLS-1$
-
- protected ConnectionStrategy createConnectionStrategy() {
- return new ConnectionQueryStrategy(queryTest);
- }
-
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/InformixUserIdentityConnectionFactory.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/InformixUserIdentityConnectionFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/informix/InformixUserIdentityConnectionFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,38 +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.informix;
-
-import com.metamatrix.connector.jdbc.*;
-import com.metamatrix.connector.jdbc.ConnectionStrategy;
-import com.metamatrix.connector.jdbc.JDBCUserIdentityConnectionFactory;
-
-public class InformixUserIdentityConnectionFactory extends
JDBCUserIdentityConnectionFactory{
- private String queryTest = "select 'x' from informix.sysusers where
1=0"; //$NON-NLS-1$
-
- protected ConnectionStrategy createConnectionStrategy() {
- return new ConnectionQueryStrategy(queryTest);
- }
-
-}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLCapabilities.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLCapabilities.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLCapabilities.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -124,7 +124,7 @@
// ADDITIONAL functions supported by MySQL
// // Comparison
-// supportedFunctions.add("COALESCE"); //$NON-NLS-1$
+ supportedFunctions.add("COALESCE"); //$NON-NLS-1$
// supportedFunctions.add("GREATEST"); //$NON-NLS-1$
// supportedFunctions.add("ISNULL"); //$NON-NLS-1$
// supportedFunctions.add("LEAST"); //$NON-NLS-1$
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLConversionVisitor.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLConversionVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLConversionVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,90 +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.sql.Date;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.text.SimpleDateFormat;
-
-import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
-import com.metamatrix.connector.language.ILimit;
-import com.metamatrix.connector.language.IQueryCommand;
-
-/**
- */
-class MySQLConversionVisitor extends SQLConversionVisitor {
-
- /**
- * Some very large row count. This number is from the mysql documentation for the
LIMIT clause
- */
- static final String NO_LIMIT = "18446744073709551615"; //$NON-NLS-1$
-
- protected String translateLiteralDate(Date dateValue) {
- return "DATE('" + formatDateValue(dateValue) + "')";
//$NON-NLS-1$//$NON-NLS-2$
- }
-
- protected String translateLiteralTime(Time timeValue) {
- return "TIME('" + formatDateValue(timeValue) + "')";
//$NON-NLS-1$//$NON-NLS-2$
- }
-
- protected String translateLiteralTimestamp(Timestamp timestampValue) {
- return "TIMESTAMP('" + formatDateValue(timestampValue) +
"')"; //$NON-NLS-1$//$NON-NLS-2$
- }
-
- protected String formatDateValue(Object dateObject) {
- if(dateObject instanceof Timestamp) {
- SimpleDateFormat timestampFormatter = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss"); //$NON-NLS-1$
- if (getDatabaseTimeZone() != null) {
- timestampFormatter.setTimeZone(getDatabaseTimeZone());
- }
-
- Timestamp ts = (Timestamp) dateObject;
- int nanos = ts.getNanos();
- int micros = nanos/1000; // truncate for microseconds
- String microsStr = "" + (1000000 + micros); //$NON-NLS-1$ // Add a
number at the beginning, so that we can print leading zeros
-
- return timestampFormatter.format(ts) + "." +
microsStr.substring(1); //$NON-NLS-1$ // show all digits except the number we just added
- }
- return super.formatDateValue(dateObject);
- }
-
- protected void appendSetQuery(IQueryCommand obj) {
- buffer.append(LPAREN);
- append(obj);
- buffer.append(RPAREN);
- }
-
- public void visit(ILimit obj) {
- buffer.append(LIMIT)
- .append(SPACE);
- if (obj.getRowOffset() > 0) {
- buffer.append(obj.getRowOffset())
- .append(COMMA)
- .append(SPACE);
- }
- buffer.append(obj.getRowLimit());
- }
-}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLConvertModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLConvertModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLConvertModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -31,6 +31,7 @@
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;
/**
@@ -94,11 +95,11 @@
int srcCode = getSrcCode(function);
switch(srcCode) {
case BOOLEAN:
- // convert(booleanSrc, string) --> CASE booleanSrc WHEN 1 THEN
'1' ELSE '0' END
- List when = Arrays.asList(new IExpression[]
{langFactory.createLiteral(new Integer(1), Integer.class)});
+ // 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.createCaseExpression(function.getParameters()[0],
when, then, elseExpr, String.class);
+ return langFactory.createSearchedCaseExpression(when, then, elseExpr,
String.class);
case BYTE:
case SHORT:
case INTEGER:
@@ -156,10 +157,11 @@
switch(srcCode) {
case STRING:
// convert(src, boolean) --> CASE src WHEN 'true' THEN 1 ELSE
0 END
- List when = Arrays.asList(new IExpression[]
{langFactory.createLiteral("true", String.class)}); //$NON-NLS-1$
- List then = Arrays.asList(new IExpression[]
{langFactory.createLiteral(new Integer(1), Integer.class)});
- IExpression elseExpr = langFactory.createLiteral(new Integer(0),
Integer.class);
- return langFactory.createCaseExpression(function.getParameters()[0],
when, then, elseExpr, Integer.class);
+ // 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);
}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLResultsTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLResultsTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLResultsTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,33 +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 com.metamatrix.connector.jdbc.extension.impl.BasicResultsTranslator;
-
-
-/**
- * @since 4.3
- */
-public class MySQLResultsTranslator extends BasicResultsTranslator {
-
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLSingleIdentityConnectionFactory.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLSingleIdentityConnectionFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLSingleIdentityConnectionFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,43 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.connector.jdbc.mysql;
-
-import com.metamatrix.connector.jdbc.ConnectionQueryStrategy;
-import com.metamatrix.connector.jdbc.ConnectionStrategy;
-import com.metamatrix.connector.jdbc.JDBCSingleIdentityConnectionFactory;
-
-
-/**
- * @since 4.3
- */
-public class MySQLSingleIdentityConnectionFactory extends
JDBCSingleIdentityConnectionFactory {
- private String queryTest = "Select 1"; //$NON-NLS-1$
-
- /**
- * @see
com.metamatrix.connector.jdbc.JDBCSourceConnectionFactory#createConnectionStrategy()
- * @since 4.3
- */
- protected ConnectionStrategy createConnectionStrategy() {
- return new ConnectionQueryStrategy(queryTest);
- }
-}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -22,59 +22,51 @@
package com.metamatrix.connector.jdbc.mysql;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
-import com.metamatrix.connector.jdbc.extension.impl.AliasModifier;
-import com.metamatrix.connector.jdbc.extension.impl.BasicSQLTranslator;
-import com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
+import com.metamatrix.connector.api.SourceSystemFunctions;
+import com.metamatrix.connector.jdbc.extension.SQLTranslator;
/**
* @since 4.3
*/
-public class MySQLTranslator extends BasicSQLTranslator {
-
- private Map functionModifiers;
- private Properties connectorProperties;
- private ILanguageFactory languageFactory;
-
- public void initialize(ConnectorEnvironment env,
- RuntimeMetadata metadata) throws ConnectorException {
-
- super.initialize(env, metadata);
- ConnectorEnvironment connEnv = getConnectorEnvironment();
- this.connectorProperties = connEnv.getProperties();
- this.languageFactory = connEnv.getLanguageFactory();
- initializeFunctionModifiers();
-
- }
-
- private void initializeFunctionModifiers() {
- functionModifiers = new HashMap();
- functionModifiers.putAll(super.getFunctionModifiers());
-
- functionModifiers.put("cast", new
MySQLConvertModifier(languageFactory)); //$NON-NLS-1$
- functionModifiers.put("convert", new
MySQLConvertModifier(languageFactory)); //$NON-NLS-1$
- functionModifiers.put("nvl", new AliasModifier("ifnull"));
//$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public Map getFunctionModifiers() {
- return functionModifiers;
- }
-
- public SQLConversionVisitor getTranslationVisitor() {
- SQLConversionVisitor visitor = new MySQLConversionVisitor();
- visitor.setRuntimeMetadata(getRuntimeMetadata());
- visitor.setFunctionModifiers(functionModifiers);
- visitor.setProperties(connectorProperties);
- visitor.setLanguageFactory(languageFactory);
- visitor.setDatabaseTimeZone(getDatabaseTimeZone());
- return visitor;
- }
+public class MySQLTranslator extends SQLTranslator {
+
+ @Override
+ public void initialize(ConnectorEnvironment env) throws ConnectorException {
+ super.initialize(env);
+ registerFunctionModifier(SourceSystemFunctions.CONVERT, new
MySQLConvertModifier(getLanguageFactory())); //$NON-NLS-1$
+ }
+
+ @Override
+ public String translateLiteralDate(Date dateValue, Calendar cal) {
+ return "DATE('" + formatDateValue(dateValue, cal) +
"')"; //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ @Override
+ public String translateLiteralTime(Time timeValue, Calendar cal) {
+ return "TIME('" + formatDateValue(timeValue, cal) +
"')"; //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ @Override
+ public String translateLiteralTimestamp(Timestamp timestampValue, Calendar cal) {
+ return "TIMESTAMP('" + formatDateValue(timestampValue, cal) +
"')"; //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ @Override
+ public boolean useParensForSetQueries() {
+ return true;
+ }
+
+ @Override
+ public int getTimestampNanoSecondPrecision() {
+ return 6;
+ }
+
}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLUserIdentityConnectionFactory.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLUserIdentityConnectionFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/mysql/MySQLUserIdentityConnectionFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,43 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.connector.jdbc.mysql;
-
-import com.metamatrix.connector.jdbc.ConnectionQueryStrategy;
-import com.metamatrix.connector.jdbc.ConnectionStrategy;
-import com.metamatrix.connector.jdbc.JDBCUserIdentityConnectionFactory;
-
-
-/**
- * @since 4.3
- */
-public class MySQLUserIdentityConnectionFactory extends JDBCUserIdentityConnectionFactory
{
- private String queryTest = "Select 1"; //$NON-NLS-1$
-
- /**
- * @see
com.metamatrix.connector.jdbc.JDBCSourceConnectionFactory#createConnectionStrategy()
- * @since 4.3
- */
- protected ConnectionStrategy createConnectionStrategy() {
- return new ConnectionQueryStrategy(queryTest);
- }
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/FormatFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/FormatFunctionModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/FormatFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,53 +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.extension.FunctionModifier;
-import com.metamatrix.connector.jdbc.extension.impl.BasicFunctionModifier;
-import com.metamatrix.connector.language.*;
-/**
- */
-public class FormatFunctionModifier extends BasicFunctionModifier implements
FunctionModifier {
- private ILanguageFactory langFactory;
-
- public FormatFunctionModifier(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();
- String format = (String) ((ILiteral)args[1]).getValue();
-
- IFunction func = langFactory.createFunction("to_char", //$NON-NLS-1$
- new IExpression[] {
- args[0],
- langFactory.createLiteral(format, String.class),
- },
- String.class);
-
- return func;
- }
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/HourFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/HourFunctionModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/HourFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -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.extension.FunctionModifier;
-import com.metamatrix.connector.jdbc.extension.impl.BasicFunctionModifier;
-import com.metamatrix.connector.language.*;
-
-/**
- * Convert the HOUR function into an equivalent Oracle function.
- * HOUR(ts) --> TO_NUMBER(TO_CHAR(ts, 'HH24'))
- */
-public class HourFunctionModifier extends BasicFunctionModifier implements
FunctionModifier {
-
- private ILanguageFactory langFactory;
-
- public HourFunctionModifier(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 innerFunction = langFactory.createFunction("TO_CHAR",
//$NON-NLS-1$
- new IExpression[] {
- args[0],
- langFactory.createLiteral("HH24", String.class)},
//$NON-NLS-1$
- String.class);
-
- IFunction outerFunction = langFactory.createFunction("TO_NUMBER",
//$NON-NLS-1$
- new IExpression[] { innerFunction },
- Integer.class);
-
- return outerFunction;
- }
-
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/LeftOrRightFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/LeftOrRightFunctionModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/LeftOrRightFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,74 +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.extension.FunctionModifier;
-import com.metamatrix.connector.jdbc.extension.impl.BasicFunctionModifier;
-import com.metamatrix.connector.language.*;
-
-/**
- * Convert left(string, count) --> substr(string, 0, count)
- * or right(string, count) --> substr(string, length(string) - count)
- */
-public class LeftOrRightFunctionModifier extends BasicFunctionModifier implements
FunctionModifier {
- private ILanguageFactory langFactory;
- private String target;
-
- public LeftOrRightFunctionModifier(ILanguageFactory langFactory, String target) {
- this.langFactory = langFactory;
- this.target = target;
- }
-
- /*
- * @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 (target.equalsIgnoreCase("left")) { //$NON-NLS-1$
- func = langFactory.createFunction("SUBSTR", //$NON-NLS-1$
- new IExpression[] {
- args[0],
- langFactory.createLiteral(new Integer(0), Integer.class),
- args[1]},
- String.class);
- } else if (target.equalsIgnoreCase("right")) { //$NON-NLS-1$
- IFunction inner = langFactory.createFunction("LENGTH",
//$NON-NLS-1$
- new IExpression[] {args[0]},
- Integer.class);
-
- IExpression substrArgs = langFactory.createFunction("-",
//$NON-NLS-1$
- new IExpression[] {inner, args[1] },
- Integer.class);
-
- func = langFactory.createFunction("SUBSTR", //$NON-NLS-1$
- new IExpression[] {
- args[0],
- substrArgs},
- String.class);
- }
-
- return func;
- }
-}
Added:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/LeftOrRightFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/LeftOrRightFunctionModifier.java
(rev 0)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/LeftOrRightFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -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 com.metamatrix.connector.jdbc.oracle;
+
+import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.jdbc.extension.FunctionModifier;
+import com.metamatrix.connector.jdbc.extension.impl.BasicFunctionModifier;
+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;
+ }
+}
Property changes on:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/LeftOrRightFunctionModifier.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleCapabilities.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleCapabilities.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleCapabilities.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -106,7 +106,7 @@
supportedFunctions.add("CONVERT"); //$NON-NLS-1$
supportedFunctions.add("IFNULL"); //$NON-NLS-1$
supportedFunctions.add("NVL"); //$NON-NLS-1$
-
+ supportedFunctions.add("COALESCE"); //$NON-NLS-1$
return supportedFunctions;
}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleConvertModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleConvertModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleConvertModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -22,42 +22,29 @@
package com.metamatrix.connector.jdbc.oracle;
-import java.util.Iterator;
import java.util.List;
-import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.ConnectorLogger;
-import com.metamatrix.connector.api.TypeFacility;
import com.metamatrix.connector.jdbc.extension.FunctionModifier;
import com.metamatrix.connector.jdbc.extension.impl.BasicFunctionModifier;
import com.metamatrix.connector.jdbc.extension.impl.DropFunctionModifier;
-import com.metamatrix.connector.language.IElement;
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.IScalarSubquery;
-import com.metamatrix.connector.language.ISelectSymbol;
-import com.metamatrix.connector.metadata.runtime.Element;
-import com.metamatrix.connector.metadata.runtime.MetadataID;
-import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
/**
*/
public class OracleConvertModifier extends BasicFunctionModifier implements
FunctionModifier {
private static DropFunctionModifier DROP_MODIFIER = new DropFunctionModifier();
private ILanguageFactory langFactory;
- private RuntimeMetadata metadata;
- private ConnectorLogger logger;
- public OracleConvertModifier(ILanguageFactory langFactory, RuntimeMetadata metadata,
ConnectorLogger logger) {
+ public OracleConvertModifier(ILanguageFactory langFactory, ConnectorLogger logger) {
this.langFactory = langFactory;
- this.metadata = metadata;
- this.logger = logger;
}
/**
- * Intentially return null, rely on the SQLStringVisitor being used by caller
+ * Intentionally return null, rely on the SQLStringVisitor being used by caller
* (Oracle or Oracle8 SQLConversionVisitor (SQLConversionVisitor))
* @see
com.metamatrix.connector.jdbc.extension.FunctionModifier#translate(com.metamatrix.connector.language.IFunction)
*/
@@ -69,140 +56,41 @@
IExpression[] args = function.getParameters();
IExpression modified = null;
- 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 ...)
- modified = convertNull(function);
- return modified;
- }
- }
-
- 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);
- }
-
- /**
- * In Oracle 8i only, there are cases where a null in the select clause
- * must be wrapped by a cast function, casting to the appropriate type.
- * This happens when a Union is submitted to Oracle 8i. A null must
- * be explicitly casted to the type of it's corresponding symbol in
- * another branch of the Union.
- *
- * For example, the following query would fail in 8i:
- *
- * <code>select null from TableX Union select dateColumn from
TableY</code>
- *
- * The above query would have to be rewritten as
- *
- * <code>select cast(null as date) from TableX Union select dateColumn from
TableY</code>
- *
- * This isn't necessary, though, for textual types (string, char, etc.) so the
- * cast/convert function will be dropped.
- *
- * (Date is Oracle type for timestamps and dates.)
- *
- * @param function IFunction to be converted
- */
- private IExpression convertNull(IFunction function) {
- IExpression convert = null;
- IExpression[] args = function.getParameters();
- String typeName = null;
- Class functionClass = null;
-
String target = ((String)((ILiteral)args[1]).getValue()).toLowerCase();
if (target.equals("string")) { //$NON-NLS-1$
- convert = DROP_MODIFIER.modify(function);
+ modified = convertToString(function);
} else if (target.equals("short")) { //$NON-NLS-1$
- typeName = "Number"; //$NON-NLS-1$
- functionClass = Integer.class;
+ modified = convertToShort(function);
} else if (target.equals("integer")) { //$NON-NLS-1$
- typeName = "Number"; //$NON-NLS-1$
- functionClass = Integer.class;
+ modified = convertToInteger(function);
} else if (target.equals("long")) { //$NON-NLS-1$
- typeName = "Number"; //$NON-NLS-1$
- functionClass = Integer.class;
+ modified = convertToLong(function);
} else if (target.equals("biginteger")) { //$NON-NLS-1$
- typeName = "Number"; //$NON-NLS-1$
- functionClass = Integer.class;
+ modified = convertToBigInteger(function);
} else if (target.equals("float")) { //$NON-NLS-1$
- typeName = "float"; //$NON-NLS-1$
- functionClass = Float.class;
+ modified = convertToFloat(function);
} else if (target.equals("double")) { //$NON-NLS-1$
- typeName = "Number"; //$NON-NLS-1$
- functionClass = Integer.class;
+ modified = convertToDouble(function);
} else if (target.equals("bigdecimal")) { //$NON-NLS-1$
- typeName = "float"; //$NON-NLS-1$
- functionClass = Float.class;
+ modified = convertToBigDecimal(function);
} else if (target.equals("date")) { //$NON-NLS-1$
- typeName = TypeFacility.RUNTIME_NAMES.DATE;
- functionClass = java.sql.Date.class;
+ modified = convertToDate(function);
} else if (target.equals("time")) { //$NON-NLS-1$
- typeName = TypeFacility.RUNTIME_NAMES.DATE;
- functionClass = java.sql.Time.class;
+ modified = convertToTime(function);
} else if (target.equals("timestamp")) { //$NON-NLS-1$
- typeName = TypeFacility.RUNTIME_NAMES.DATE;
- functionClass = java.sql.Timestamp.class;
+ modified = convertToTimestamp(function);
} else if (target.equals("char")) { //$NON-NLS-1$
- convert = DROP_MODIFIER.modify(function);
+ modified = convertToChar(function);
} else if (target.equals("boolean")) { //$NON-NLS-1$
- typeName = "Number"; //$NON-NLS-1$
- functionClass = Integer.class;
+ modified = convertToBoolean(function);
} else if (target.equals("byte")) { //$NON-NLS-1$
- typeName = "Number"; //$NON-NLS-1$
- functionClass = Integer.class;
+ modified = convertToByte(function);
} else {
- convert = DROP_MODIFIER.modify(function);
+ modified = DROP_MODIFIER.modify(function);
}
-
- if (convert == null) {
- // cast (NULL as ...) -- > cast(NULL as ...)
- // or
- // convert (NULL, ...) -- > cast(NULL as ...)
- convert = langFactory.createFunction("cast", //$NON-NLS-1$
- new IExpression[] {
- args[0],
- langFactory.createLiteral(typeName, String.class)},
- functionClass);
- }
-
- return convert;
+ return modified;
}
-
+
private IExpression convertToDate(IFunction function) {
IExpression convert = null;
IExpression[] args = function.getParameters();
@@ -262,24 +150,18 @@
break;
case TIMESTAMP:
// convert(timestamp, time)
- // --> to_date(('1970-01-01 ' ||substr(to_char(timestampvalue,
'YYYY-MM-DD HH24:MI:SS'), 12)),
+ // --> 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("FXYYYY-MM-DD HH24:MI:SS",
String.class)}, //$NON-NLS-1$
+ langFactory.createLiteral("HH24:MI:SS", String.class)},
//$NON-NLS-1$
String.class);
- IFunction intermediate = langFactory.createFunction("substr",
//$NON-NLS-1$
- new IExpression[] {
- inner,
- langFactory.createLiteral(new Integer(12), Integer.class)},
- String.class);
-
IExpression prependedPart = langFactory.createFunction("||",
//$NON-NLS-1$
new IExpression[] {
langFactory.createLiteral("1970-01-01 ", String.class),
//$NON-NLS-1$
- intermediate},
+ inner},
String.class);
convert = langFactory.createFunction("to_date", //$NON-NLS-1$
@@ -295,40 +177,22 @@
return convert;
}
- /**
- * This works only for Oracle 9i.
- * @param src
- * @return IFunction
- */
private IExpression convertToTimestamp(IFunction function) {
IExpression convert = null;
IExpression[] args = function.getParameters();
Class srcType = args[0].getType();
int srcCode = getSrcCode(srcType);
- //TODO: what is the best format for timestamp
- //String format = "YYYY-MM-DD HH24:MI:SS.fffffffff"; //$NON-NLS-1$
- String format = "YYYY-MM-DD HH24:MI:SS"; //$NON-NLS-1$
switch(srcCode) {
case STRING:
- // convert(STRING, timestamp) --> to_date(timestampvalue,
'YYYY-MM-DD HH24:MI:SS'))) from smalla
- format = "YYYY-MM-DD HH24:MI:SS.FF"; //$NON-NLS-1$
+ // 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(DATE, timestamp) --> to_date(to_char(DATE, 'YYYY-MM-DD
HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS')
- IFunction inner = langFactory.createFunction("to_char",
//$NON-NLS-1$
- new IExpression[] {
- args[0],
- langFactory.createLiteral(format, String.class)},
- String.class);
-
- convert = langFactory.createFunction("to_date", //$NON-NLS-1$
- new IExpression[] {
- inner,
- langFactory.createLiteral(format, String.class)},
- java.sql.Timestamp.class);
+ 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);
@@ -350,7 +214,6 @@
IExpression convert = null;
IExpression[] args = function.getParameters();
String format = null;
- boolean dateTypeFound = false;
int srcCode = getSrcCode(function);
switch(srcCode) { // convert(input, string) --> to_char(input)
@@ -384,56 +247,7 @@
convert = createStringFunction(args[0], format);
break;
case TIMESTAMP:
- if (args[0] instanceof IElement) {
- IElement element = (IElement) args[0];
- MetadataID id = element.getMetadataID();
- RuntimeMetadata rmd = this.metadata;
- try {
- Element elemMetadata = (Element)rmd.getObject(id);
- String nativeType = elemMetadata.getNativeType();
- if (nativeType != null &&
nativeType.equalsIgnoreCase("DATE")) { //$NON-NLS-1$
- dateTypeFound = true;
- }
- }
- catch (ConnectorException e) {
- logger.logError(e.getMessage());
- }
- }
- else if (args[0] instanceof IScalarSubquery) {
- IScalarSubquery scalar = (IScalarSubquery) args[0];
- List symList =
scalar.getQuery().getProjectedQuery().getSelect().getSelectSymbols();
- Iterator iter = symList.iterator();
- while(iter.hasNext()) {
- ISelectSymbol symObj = (ISelectSymbol)iter.next();
- IExpression expObj = symObj.getExpression();
- if (expObj instanceof IElement) {
- IElement element = (IElement)expObj;
- MetadataID id = element.getMetadataID();
- RuntimeMetadata rmd = this.metadata;
- try {
- Element elemMetadata = (Element)rmd.getObject(id);
- String nativeType = elemMetadata.getNativeType();
- if (nativeType != null &&
nativeType.equalsIgnoreCase("DATE")) { //$NON-NLS-1$
- dateTypeFound = true;
- }
- }
- catch (ConnectorException e) {
- logger.logError(e.getMessage());
-
- }
- }
- }
-
- }
-
- if (dateTypeFound) {
- format = "YYYY-MM-DD HH24:MI:SS"; //$NON-NLS-1$
- }
- else {
- format = "YYYY-MM-DD HH24:MI:SS.FF"; //$NON-NLS-1$
- }
-
- convert = createStringFunction(args[0], format);
+ convert = createStringFunction(args[0], "YYYY-MM-DD
HH24:MI:SS.FF"); //$NON-NLS-1$
break;
default:
convert = DROP_MODIFIER.modify(function);
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleSQLConversionVisitor.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleSQLConversionVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleSQLConversionVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,282 +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.Time;
-import java.util.Iterator;
-
-import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
-import com.metamatrix.connector.language.ICompareCriteria;
-import com.metamatrix.connector.language.IElement;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IGroup;
-import com.metamatrix.connector.language.IInsert;
-import com.metamatrix.connector.language.ILanguageObject;
-import com.metamatrix.connector.language.ILimit;
-import com.metamatrix.connector.language.ILiteral;
-import com.metamatrix.connector.language.ISelect;
-import com.metamatrix.connector.language.ISetQuery.Operation;
-import com.metamatrix.connector.metadata.runtime.Element;
-import com.metamatrix.connector.metadata.runtime.MetadataID;
-
-/**
- */
-public class OracleSQLConversionVisitor extends SQLConversionVisitor {
-
- private final int MAX_SELECT_ALIAS_LENGTH = 30;
-
- private final int MAX_TABLE_ALIAS_LENGTH = 30;
-
- protected final static String DUAL = "DUAL"; //$NON-NLS-1$
- protected final static String ROWNUM = "ROWNUM"; //$NON-NLS-1$
- protected final static String SEQUENCE = ":SEQUENCE="; //$NON-NLS-1$
- protected final static String HINT_PREFIX = "/*+"; //$NON-NLS-1$
-
-
- /**
- * Overriden to check for Oracle SQL hints
- * @param obj ISelect object
- * @since 4.3
- */
- protected void visitSelect(ISelect obj) {
- buffer.append(SELECT).append(SPACE);
- buffer.append(addProcessComment());
-
- // Check for db hints
- Object payload = this.getExecutionContext().getExecutionPayload();
- if (payload instanceof String) {
- String payloadString = (String)payload;
- if (payloadString.startsWith(HINT_PREFIX)) {
- buffer.append(payloadString).append(SPACE);
- }
- }
-
- if (obj.isDistinct()) {
- buffer.append(DISTINCT).append(SPACE);
- }
- append(obj.getSelectSymbols());
- }
-
- /**
- * @see
com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.connector.language.IGroup)
- */
- protected boolean useAsInGroupAlias(){
- return false;
- }
-
- /**
- * 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
- */
- protected String replaceElementName(String group, String element) {
-
- // Check if the element was modeled as using a Sequence
- String elementTrueName = getElementTrueName(element);
- if (elementTrueName != null) {
- return group + DOT + elementTrueName;
- }
-
- // 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;
- }
-
- /**
- * Check if the element was modeled as using a Sequence to
- * generate a unique value for Inserting - strip off everything
- * except the element name. Otherwise return null.
- * @param element
- * @return
- * @since 4.3
- */
- protected String getElementTrueName(String element) {
-
- int useIndex = element.indexOf(SEQUENCE);
- if (useIndex >= 0) {
- return element.substring(0, useIndex);
- }
-
- return null;
- }
-
- /*
- * @see
com.metamatrix.connector.jdbc.extension.SQLConversionVisitor#translateLiteralTime(java.sql.Time)
- */
- protected String translateLiteralTime(Time timeValue) {
- return "{ts'1970-01-01 " + formatDateValue(timeValue) +
"'}"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- private static final String DATE_TYPE = "DATE"; //$NON-NLS-1$
-
- public void visit(ICompareCriteria obj) {
- IExpression leftExpression = obj.getLeftExpression();
- append(leftExpression);
- buffer.append(SPACE);
-
- switch(obj.getOperator()) {
- case EQ: buffer.append(EQ); break;
- case GE: buffer.append(GE); break;
- case GT: buffer.append(GT); break;
- case LE: buffer.append(LE); break;
- case LT: buffer.append(LT); break;
- case NE: buffer.append(NE); break;
- }
- buffer.append(SPACE);
-
- IExpression rightExpression = obj.getRightExpression();
- if(leftExpression instanceof IElement && rightExpression instanceof
ILiteral &&
((ILiteral)rightExpression).getType().equals(TypeFacility.RUNTIME_TYPES.TIMESTAMP)
&& ((ILiteral)rightExpression).getValue() != null) {
- translateStringToTimestampConversion(leftExpression, rightExpression);
-
- } else {
- append(rightExpression);
- }
- }
-
- /**
- * If a column is modeled with name in source indicating that an Oracle Sequence
should
- * be used to generate the value to insert, then pull the Sequence name out of the
name
- * in source of the column, discard the (dummy) literal value from the user-entered
value list,
- * and replace with the Sequence (as an IElement).
- * Implementation note: An IGroup will be used for the Sequence name, and an IElement
will be used
- * for the Sequence operation (i.e. "nextVal").
- * This nasty kludge is brought to you by Tier 3.
- * @see
com.metamatrix.connector.jdbc.extension.SQLConversionVisitor#visit(com.metamatrix.connector.language.IInsert)
- * @since 4.3
- */
- public void visit(IInsert obj) {
-
- Iterator iter = obj.getElements().iterator();
- for (int i=0; i<obj.getElements().size(); i++) {
-
- IElement element = (IElement)iter.next();
- MetadataID metadataID = element.getMetadataID();
- if (metadataID != null) {
- String name = getName(metadataID);
-
- //Check whether a Sequence should be used to insert value for this
column
- String upperName = name.toUpperCase();
- int index = upperName.indexOf(SEQUENCE);
- if (index >= 0) {
-
- String sequence = name.substring(index + SEQUENCE.length());
-
- int delimiterIndex = sequence.indexOf(DOT);
- if (delimiterIndex >= 0) {
- String sequenceGroupName = sequence.substring(0,
delimiterIndex);
- String sequenceElementName = sequence.substring(delimiterIndex +
1);
-
- ILanguageObject previousValue =
(ILanguageObject)obj.getValues().get(i);
- IGroup sequenceGroup =
this.getLanguageFactory().createGroup(sequenceGroupName, null, null);
- IElement sequenceElement =
this.getLanguageFactory().createElement(sequenceElementName, sequenceGroup, null,
previousValue.getClass());
-
- obj.getValues().set(i, sequenceElement);
-
- }
- }
-
- }
-
- }
-
- super.visit(obj);
- }
-
- protected void translateStringToTimestampConversion(IExpression leftExpression,
- IExpression rightExpression) {
- String nativeType = DATE_TYPE;
-
- try {
- // Determine native type of left element
- IElement element = (IElement) leftExpression;
- MetadataID metadataID = element.getMetadataID();
- Element elem = (Element) super.metadata.getObject(metadataID);
- nativeType = elem.getNativeType();
- } catch(ConnectorException e) {
- // ignore, use default
- }
-
- // Translate timestamp based on native type of compared element - Oracle will
- // only use an index for date or timestamp type columns if the proper function
- // is used. The importer will import date types as type=DATE and timestamp
types
- // as type=TIMESTAMP(0), etc.
- ILiteral timestamp = (ILiteral) rightExpression;
- if(nativeType != null && nativeType.equalsIgnoreCase(DATE_TYPE)) {
- buffer.append("to_date('"); //$NON-NLS-1$
-
- String tsValue = formatDateValue(timestamp.getValue());
- int decimalIndex = tsValue.lastIndexOf("."); //$NON-NLS-1$
- if(decimalIndex >= 0) {
- buffer.append(tsValue.substring(0, decimalIndex));
- } else {
- buffer.append(tsValue);
- }
- buffer.append("','YYYY-MM-DD
HH24:MI:SS')");//$NON-NLS-1$
- } else {
- buffer.append("to_timestamp('"); //$NON-NLS-1$
- buffer.append(formatDateValue(timestamp.getValue()));
- buffer.append("','YYYY-MM-DD
HH24:MI:SS.FF')");//$NON-NLS-1$
- }
- }
-
- public void visit(ILimit obj) {
- //limits should be removed by the translator
- }
-
- /**
- * @see
com.metamatrix.connector.visitor.util.SQLStringVisitor#appendSetOperation(com.metamatrix.connector.language.ISetQuery.Operation)
- */
- @Override
- protected void appendSetOperation(Operation operation) {
- if (operation.equals(Operation.EXCEPT)) {
- buffer.append("MINUS"); //$NON-NLS-1$
- } else {
- super.appendSetOperation(operation);
- }
- }
-
- /**
- * @see
com.metamatrix.connector.jdbc.extension.SQLConversionVisitor#getMaxSelectAliasLength()
- * @since 4.3
- */
- protected int getMaxSelectAliasLength() {
- return MAX_SELECT_ALIAS_LENGTH;
- }
-
- /**
- * @see
com.metamatrix.connector.jdbc.extension.SQLConversionVisitor#getMaxTableAliasLength()
- * @since 4.3
- */
- protected int getMaxTableAliasLength() {
- return MAX_TABLE_ALIAS_LENGTH;
- }
-}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleSQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleSQLTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/OracleSQLTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -24,272 +24,207 @@
*/
package com.metamatrix.connector.jdbc.oracle;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
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.ExecutionContext;
-import com.metamatrix.connector.api.TypeFacility;
-import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
+import com.metamatrix.connector.api.SourceSystemFunctions;
+import com.metamatrix.connector.jdbc.extension.SQLTranslator;
import com.metamatrix.connector.jdbc.extension.impl.AliasModifier;
-import com.metamatrix.connector.jdbc.extension.impl.BasicSQLTranslator;
import com.metamatrix.connector.language.ICommand;
-import com.metamatrix.connector.language.ICriteria;
import com.metamatrix.connector.language.IElement;
-import com.metamatrix.connector.language.IFrom;
-import com.metamatrix.connector.language.IFromItem;
import com.metamatrix.connector.language.IGroup;
-import com.metamatrix.connector.language.IInlineView;
-import com.metamatrix.connector.language.ILanguageFactory;
+import com.metamatrix.connector.language.IInsert;
import com.metamatrix.connector.language.ILimit;
-import com.metamatrix.connector.language.ILiteral;
-import com.metamatrix.connector.language.IOrderBy;
-import com.metamatrix.connector.language.IOrderByItem;
-import com.metamatrix.connector.language.IQuery;
-import com.metamatrix.connector.language.IQueryCommand;
-import com.metamatrix.connector.language.ISelect;
-import com.metamatrix.connector.language.ISelectSymbol;
-import com.metamatrix.connector.language.ISetQuery;
-import com.metamatrix.connector.language.ICompareCriteria.Operator;
-import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
-import com.metamatrix.connector.visitor.util.CollectorVisitor;
-import com.metamatrix.connector.visitor.util.SQLStringVisitor;
+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 BasicSQLTranslator {
-
- protected final static String ROWNUM = "ROWNUM"; //$NON-NLS-1$
- protected final static String ROWNUM_ALIAS = "MM_ROWNUM"; //$NON-NLS-1$
- protected final static String INLINE_VIEW_ALIAS = "MM_VIEW_FOR_LIMIT";
//$NON-NLS-1$
- protected final static String ROOT_EXPRESSION_NAME = "expr"; //$NON-NLS-1$
-
-
-
- private Map functionModifiers;
- private Properties connectorProperties;
- private ILanguageFactory languageFactory;
-
- public void initialize(ConnectorEnvironment env,
- RuntimeMetadata metadata) throws ConnectorException {
-
- super.initialize(env, metadata);
- ConnectorEnvironment connEnv = getConnectorEnvironment();
- this.connectorProperties = connEnv.getProperties();
- this.languageFactory = connEnv.getLanguageFactory();
- initializeFunctionModifiers();
-
+public class OracleSQLTranslator extends SQLTranslator {
+
+ 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;
}
-
- /**
- * @see
com.metamatrix.connector.jdbc.extension.impl.BasicSQLTranslator#modifyCommand(com.metamatrix.connector.language.ICommand,
com.metamatrix.connector.api.ExecutionContext)
- * @since 5.0
- */
- public ICommand modifyCommand(ICommand command, ExecutionContext context) throws
ConnectorException {
- command = super.modifyCommand(command, context);
- Collection subCommands = CollectorVisitor.collectObjects(IInlineView.class,
command);
- for (Iterator i = subCommands.iterator(); i.hasNext();) {
- IInlineView inlineView = (IInlineView)i.next();
- inlineView.setQuery((IQueryCommand)modifyCommand(inlineView.getQuery(),
context));
- }
-
- if (!(command instanceof IQueryCommand)) {
- return command;
- }
-
- return modifySingleCommand((IQueryCommand)command, context);
- }
-
- protected IQueryCommand modifySingleCommand(IQueryCommand command, ExecutionContext
context) {
- if (command instanceof ISetQuery) {
- ISetQuery union = (ISetQuery)command;
- union.setLeftQuery(modifySingleCommand(union.getLeftQuery(), context));
- union.setRightQuery(modifySingleCommand(union.getRightQuery(), context));
- return union;
- }
-
- if (command.getLimit() == null) {
- return command;
- }
-
- ILimit limit = command.getLimit();
- command.setLimit(null);
-
- List<ICriteria> lstCriteria = new ArrayList<ICriteria>();
-
- if (limit.getRowOffset() > 0) {
- IGroup group = languageFactory.createGroup(INLINE_VIEW_ALIAS, null, null);
- IElement eleRowNum = languageFactory.createElement(ROWNUM_ALIAS, group, null,
TypeFacility.RUNTIME_TYPES.INTEGER);
- ILiteral litOffset = languageFactory.createLiteral(new Integer(
limit.getRowOffset() ), TypeFacility.RUNTIME_TYPES.INTEGER);
- ICriteria criteria = languageFactory.createCompareCriteria(Operator.GT,
eleRowNum, litOffset);
- lstCriteria.add( criteria );
- }
-
- IGroup group = languageFactory.createGroup(INLINE_VIEW_ALIAS, null, null);
- IElement eleRowNum = languageFactory.createElement(ROWNUM_ALIAS, group, null,
TypeFacility.RUNTIME_TYPES.INTEGER);
- ILiteral litLimit = languageFactory.createLiteral(new Integer(
limit.getRowOffset() + limit.getRowLimit() ),TypeFacility.RUNTIME_TYPES.INTEGER);
- ICriteria criteria = languageFactory.createCompareCriteria(Operator.LE,
eleRowNum, litLimit);
- lstCriteria.add( criteria );
-
- if ( lstCriteria.size() == 1 ) {
- criteria = lstCriteria.get( 0 );
- } else {
- criteria =
languageFactory.createCompoundCriteria(com.metamatrix.connector.language.ICompoundCriteria.Operator.AND,
lstCriteria );
- }
-
- IQuery intermediate = createLimitQuery(command, null, true);
-
- IQuery result = createLimitQuery(intermediate, criteria, false);
-
- eleRowNum = languageFactory.createElement(OracleSQLConversionVisitor.ROWNUM,
null, null, TypeFacility.RUNTIME_TYPES.INTEGER);
- ISelectSymbol newSelectSymbol = languageFactory.createSelectSymbol(ROWNUM_ALIAS,
eleRowNum);
- newSelectSymbol.setAlias(true);
- intermediate.getSelect().getSelectSymbols().add(newSelectSymbol);
-
- return result;
- }
-
- /**
- * @param query
- * @param criteria
- * @return
- * @since 5.0
- */
- private IQuery createLimitQuery(IQueryCommand query,
- ICriteria criteria, boolean alias) {
- IInlineView view = languageFactory.createInlineView(query, INLINE_VIEW_ALIAS);
-
- IFrom from = languageFactory.createFrom(Arrays.asList(new IFromItem[] {view}));
-
- LinkedHashMap<String, Class<?>> names = new LinkedHashMap<String,
Class<?>>();
-
- List symbols = query.getProjectedQuery().getSelect().getSelectSymbols();
- IOrderBy orderBy = query.getOrderBy();
- HashMap<String, IOrderByItem> orderByNames = null;
- if (orderBy != null) {
- orderByNames = new HashMap<String, IOrderByItem>();
- for (IOrderByItem item : (List<IOrderByItem>)orderBy.getItems()) {
- if (item.getName() != null) {
- orderByNames.put(item.getName().toLowerCase(), item);
- }
+
+ @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;
}
-
- for (int i = 0; i < symbols.size(); i++) {
- ISelectSymbol symbol = (ISelectSymbol)symbols.get(i);
-
- String originalName = null;
-
- if (symbol.getExpression() instanceof IElement || symbol.hasAlias()) {
- originalName =
SQLStringVisitor.getElementShortName(symbol.getOutputName()).toLowerCase();
- } else if (alias) {
- originalName = ROOT_EXPRESSION_NAME;
- }
-
- String name = originalName;
-
- int j = 0;
- while (names.containsKey(name)) {
- name = originalName + j++;
- }
-
- if (alias) {
- symbol.setAlias(true);
- symbol.setOutputName(name);
- if (orderByNames != null) {
- IOrderByItem item = orderByNames.get(originalName);
- if (item != null) {
- item.setName(name);
- }
- }
- }
- names.put(name, symbol.getExpression().getType());
- }
- List<ISelectSymbol> lstSelect = new ArrayList<ISelectSymbol>();
-
- for (Map.Entry<String, Class<?>> entry : names.entrySet()) {
- IGroup group = languageFactory.createGroup(INLINE_VIEW_ALIAS, null, null);
- IElement expression = languageFactory.createElement(entry.getKey(), group,
null, entry.getValue());
- ISelectSymbol newSymbol = languageFactory.createSelectSymbol(entry.getKey(),
expression);
- lstSelect.add(newSymbol);
- }
-
- ISelect select = languageFactory.createSelect(false, lstSelect);
-
- IQuery result = languageFactory.createQuery(select, from, criteria, null, null,
null);
- return result;
- }
-
- /**
- * @param modifier
- * @since 4.2
- */
- private void initializeFunctionModifiers() {
- functionModifiers = new HashMap();
- functionModifiers.putAll(super.getFunctionModifiers());
- functionModifiers.put("char", new AliasModifier("chr"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("lcase", new AliasModifier("lower"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("ucase", new AliasModifier("upper"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("ifnull", new AliasModifier("nvl"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("log", new AliasModifier("ln"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("ceiling", new AliasModifier("ceil"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("log10", new
Log10FunctionModifier(languageFactory)); //$NON-NLS-1$
- functionModifiers.put("convert", new
OracleConvertModifier(languageFactory, getRuntimeMetadata(),
getConnectorEnvironment().getLogger())); //$NON-NLS-1$
- functionModifiers.put("cast", new
OracleConvertModifier(languageFactory, getRuntimeMetadata(),
getConnectorEnvironment().getLogger())); //$NON-NLS-1$
- functionModifiers.put("hour", new
HourFunctionModifier(languageFactory));//$NON-NLS-1$
- functionModifiers.put("month", new
ExtractFunctionModifier("MONTH"));//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("year", new
ExtractFunctionModifier("YEAR"));//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("day", new
ExtractFunctionModifier("DAY"));//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("minute", new
DayWeekQuarterFunctionModifier(languageFactory, "MI"));//$NON-NLS-1$
//$NON-NLS-2$
- functionModifiers.put("second", new
DayWeekQuarterFunctionModifier(languageFactory, "SS"));//$NON-NLS-1$
//$NON-NLS-2$
- functionModifiers.put("monthname", new
MonthOrDayNameFunctionModifier(languageFactory, "Month"));//$NON-NLS-1$
//$NON-NLS-2$
- functionModifiers.put("dayname", new
MonthOrDayNameFunctionModifier(languageFactory, "Day"));//$NON-NLS-1$
//$NON-NLS-2$
- functionModifiers.put("week", new
DayWeekQuarterFunctionModifier(languageFactory, "WW"));//$NON-NLS-1$
//$NON-NLS-2$
- functionModifiers.put("quarter", new
DayWeekQuarterFunctionModifier(languageFactory, "Q"));//$NON-NLS-1$
//$NON-NLS-2$
- functionModifiers.put("dayofweek", new
DayWeekQuarterFunctionModifier(languageFactory, "D"));//$NON-NLS-1$
//$NON-NLS-2$
- functionModifiers.put("dayofmonth", new
DayWeekQuarterFunctionModifier(languageFactory, "DD"));//$NON-NLS-1$
//$NON-NLS-2$
- functionModifiers.put("dayofyear", new
DayWeekQuarterFunctionModifier(languageFactory, "DDD"));//$NON-NLS-1$
//$NON-NLS-2$
- functionModifiers.put("formatdate", new
FormatFunctionModifier(languageFactory));//$NON-NLS-1$
- functionModifiers.put("formattime", new
FormatFunctionModifier(languageFactory));//$NON-NLS-1$
- functionModifiers.put("formattimestamp", new
FormatFunctionModifier(languageFactory));//$NON-NLS-1$
- functionModifiers.put("parsedate", new
ParseFunctionModifier(languageFactory, java.sql.Date.class));//$NON-NLS-1$
- functionModifiers.put("parsetime", new
ParseFunctionModifier(languageFactory, java.sql.Time.class));//$NON-NLS-1$
- functionModifiers.put("parsetimestamp", new
ParseFunctionModifier(languageFactory, java.sql.Timestamp.class));//$NON-NLS-1$
- functionModifiers.put("locate", new
LocateFunctionModifier(languageFactory));//$NON-NLS-1$
- functionModifiers.put("substring", new
AliasModifier("substr"));//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("left", new
LeftOrRightFunctionModifier(languageFactory, "left"));//$NON-NLS-1$
//$NON-NLS-2$
- functionModifiers.put("right", new
LeftOrRightFunctionModifier(languageFactory, "right"));//$NON-NLS-1$
//$NON-NLS-2$
- functionModifiers.put("concat", new
ConcatFunctionModifier(languageFactory)); //$NON-NLS-1$
- functionModifiers.put("||", new
ConcatFunctionModifier(languageFactory)); //$NON-NLS-1$
- }
-
-
- /**
- * @see
com.metamatrix.connector.jdbc.extension.SQLTranslator#getTranslationVisitor()
- */
- public SQLConversionVisitor getTranslationVisitor() {
- SQLConversionVisitor visitor = new OracleSQLConversionVisitor();
- visitor.setRuntimeMetadata(getRuntimeMetadata());
- visitor.setFunctionModifiers(functionModifiers);
- visitor.setProperties(connectorProperties);
- visitor.setLanguageFactory(languageFactory);
- visitor.setDatabaseTimeZone(getDatabaseTimeZone());
- return visitor;
- }
-
- /**
- * @see com.metamatrix.connector.jdbc.extension.SQLTranslator#getFunctionModifiers()
- */
- public Map getFunctionModifiers() {
- return functionModifiers;
- }
-
+
+ // 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 getConnectionTestQuery() {
+ return "Select 'x' from DUAL"; //$NON-NLS-1$
+ }
+
}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/ParseFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/ParseFunctionModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/oracle/ParseFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -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.oracle;
-
-import com.metamatrix.connector.jdbc.extension.FunctionModifier;
-import com.metamatrix.connector.jdbc.extension.impl.BasicFunctionModifier;
-import com.metamatrix.connector.language.*;
-/**
- */
-public class ParseFunctionModifier extends BasicFunctionModifier implements
FunctionModifier {
- private ILanguageFactory langFactory;
- private Class targetClass;
-
- public ParseFunctionModifier(ILanguageFactory langFactory, Class targetClass) {
- this.langFactory = langFactory;
- this.targetClass = targetClass;
- }
-
- /*
- * @see
com.metamatrix.connector.jdbc.extension.FunctionModifier#modify(com.metamatrix.data.language.IFunction)
- */
- public IExpression modify(IFunction function) {
- IExpression[] args = function.getParameters();
- String format = (String) ((ILiteral)args[1]).getValue();
-
- IFunction func = langFactory.createFunction("to_date", //$NON-NLS-1$
- new IExpression[] {
- args[0],
- langFactory.createLiteral(format, String.class),
- },
- targetClass);
-
- return func;
- }
-}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLCapabilities.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLCapabilities.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLCapabilities.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -200,7 +200,7 @@
// supportedFunctions.add("TIMEOFDAY"); //$NON-NLS-1$
//
// // Conditional
-// supportedFunctions.add("COALESCE"); //$NON-NLS-1$
+ supportedFunctions.add("COALESCE"); //$NON-NLS-1$
// supportedFunctions.add("NULLIF"); //$NON-NLS-1$
// supportedFunctions.add("GREATEST"); //$NON-NLS-1$
// supportedFunctions.add("LEAST"); //$NON-NLS-1$
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLConversionVisitor.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLConversionVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLConversionVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,123 +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.sql.Date;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.text.SimpleDateFormat;
-
-import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
-import com.metamatrix.connector.language.IAggregate;
-import com.metamatrix.connector.language.ILimit;
-
-/**
- */
-class PostgreSQLConversionVisitor extends SQLConversionVisitor {
-
- protected String translateLiteralBoolean(Boolean booleanValue) {
- if(booleanValue.booleanValue()) {
- return "TRUE"; //$NON-NLS-1$
- }
- return "FALSE"; //$NON-NLS-1$
- }
-
- protected String translateLiteralDate(Date dateValue) {
- return "DATE '" + dateValue.toString() + "'";
//$NON-NLS-1$//$NON-NLS-2$
- }
-
- protected String translateLiteralTime(Time timeValue) {
- return "TIME '" + timeValue.toString() + "'";
//$NON-NLS-1$//$NON-NLS-2$
- }
-
- protected String translateLiteralTimestamp(Timestamp timestampValue) {
- SimpleDateFormat timestampFormatter = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss"); //$NON-NLS-1$
- if (getDatabaseTimeZone() != null) {
- timestampFormatter.setTimeZone(getDatabaseTimeZone());
- }
- int nanos = timestampValue.getNanos();
- int micros = nanos/1000; // truncate for microseconds
- String microsStr = "" + (1000000 + micros); //$NON-NLS-1$ // Add a
number at the beginning, so that we can print leading zeros
-
- return "to_timestamp('" + timestampFormatter.format(timestampValue)
+ "." + microsStr.substring(1) + "', 'YYYY-MM-DD
HH24:MI:SS.UF')"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
- }
-
- /**
- * Postgres doesn't provide min/max(boolean), so this conversion writes a
min(booleanval) as
- * CASE MIN(CASE B.BooleanValue WHEN TRUE THEN 1 ELSE 0 END) WHEN 1 THEN TRUE ELSE
FALSE END
- * TODO: This conversion implementation does not handle null values in the boolean
column.
- * @see
com.metamatrix.connector.visitor.framework.LanguageObjectVisitor#visit(com.metamatrix.connector.language.IAggregate)
- * @since 4.3
- */
- public void visit(IAggregate obj) {
- if ((obj.getName().equalsIgnoreCase("min") ||
obj.getName().equalsIgnoreCase("max")) //$NON-NLS-1$//$NON-NLS-2$
- && obj.getExpression().getType().equals(Boolean.class))
{
- buffer.append(CASE)
- .append(SPACE).append(obj.getName())
- // Inner case
- .append(LPAREN).append(CASE)
- .append(SPACE);
- append(obj.getExpression());
- buffer.append(SPACE).append(WHEN)
- .append(SPACE).append(TRUE)
- .append(SPACE).append(THEN)
- .append(SPACE).append(1)
- .append(SPACE).append(ELSE)
- .append(SPACE).append(0)
- .append(SPACE).append(END)
- .append(RPAREN)
-
- .append(SPACE).append(WHEN)
- .append(SPACE).append(1)
- .append(SPACE).append(THEN)
- .append(SPACE).append(TRUE)
- .append(SPACE).append(ELSE)
- .append(SPACE).append(FALSE)
- .append(SPACE).append(END);
- } else {
- super.visit(obj);
- }
- }
-
- /**
- * Convert limit clause to PostgreSQL ...[LIMIT rowlimit] [OFFSET offset] syntax
- * @see
com.metamatrix.connector.visitor.framework.LanguageObjectVisitor#visit(com.metamatrix.connector.language.IQuery)
- * @since 5.0 SP1
- */
- public void visit(ILimit obj) {
- buffer.append(LIMIT)
- .append(SPACE)
- .append(obj.getRowLimit());
-
- if (obj.getRowOffset() > 0) {
- if (obj.getRowLimit() > 0) {
- buffer.append(SPACE);
- }
- buffer.append("OFFSET") //$NON-NLS-1$
- .append(SPACE)
- .append(obj.getRowOffset());
- }
- }
-}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLConvertModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLConvertModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLConvertModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -34,6 +34,7 @@
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;
/**
*/
@@ -157,10 +158,10 @@
switch(srcCode) {
case BOOLEAN:
// convert(booleanSrc, string) --> CASE WHEN booleanSrc THEN
'1' ELSE '0' END
- List when = Arrays.asList(new IExpression[]
{langFactory.createLiteral(Boolean.TRUE, Boolean.class)});
+ 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.createCaseExpression(function.getParameters()[0],
when, then, elseExpr, String.class);
+ return langFactory.createSearchedCaseExpression(when, then, elseExpr,
String.class);
case BYTE:
case SHORT:
case INTEGER:
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLResultsTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLResultsTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLResultsTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,33 +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.extension.impl.BasicResultsTranslator;
-
-
-/**
- * @since 4.3
- */
-public class PostgreSQLResultsTranslator extends BasicResultsTranslator {
-
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLSingleIdentityConnectionFactory.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLSingleIdentityConnectionFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLSingleIdentityConnectionFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,43 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.connector.jdbc.postgresql;
-
-import com.metamatrix.connector.jdbc.ConnectionQueryStrategy;
-import com.metamatrix.connector.jdbc.ConnectionStrategy;
-import com.metamatrix.connector.jdbc.JDBCSingleIdentityConnectionFactory;
-
-
-/**
- * @since 4.3
- */
-public class PostgreSQLSingleIdentityConnectionFactory extends
JDBCSingleIdentityConnectionFactory {
- private String queryTest = "Select 1"; //$NON-NLS-1$
-
- /**
- * @see
com.metamatrix.connector.jdbc.JDBCSourceConnectionFactory#createConnectionStrategy()
- * @since 4.3
- */
- protected ConnectionStrategy createConnectionStrategy() {
- return new ConnectionQueryStrategy(queryTest);
- }
-}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -22,96 +22,125 @@
package com.metamatrix.connector.jdbc.postgresql;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
-import com.metamatrix.connector.jdbc.extension.impl.AliasModifier;
-import com.metamatrix.connector.jdbc.extension.impl.BasicSQLTranslator;
-import com.metamatrix.connector.jdbc.oracle.MonthOrDayNameFunctionModifier;
-import com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
+import com.metamatrix.connector.api.ExecutionContext;
+import com.metamatrix.connector.api.SourceSystemFunctions;
+import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.jdbc.extension.SQLTranslator;
+import com.metamatrix.connector.jdbc.extension.impl.AliasModifier;
+import com.metamatrix.connector.jdbc.oracle.LeftOrRightFunctionModifier;
+import com.metamatrix.connector.jdbc.oracle.MonthOrDayNameFunctionModifier;
+import com.metamatrix.connector.language.IAggregate;
+import com.metamatrix.connector.language.ICommand;
+import com.metamatrix.connector.language.ILimit;
+import com.metamatrix.connector.visitor.framework.HierarchyVisitor;
+import com.metamatrix.connector.visitor.util.SQLReservedWords;
/**
* @since 4.3
*/
-public class PostgreSQLTranslator extends BasicSQLTranslator {
+public class PostgreSQLTranslator extends SQLTranslator {
- private Map functionModifiers;
- private Properties connectorProperties;
- private ILanguageFactory languageFactory;
-
- public void initialize(ConnectorEnvironment env,
- RuntimeMetadata metadata) throws ConnectorException {
+ public void initialize(ConnectorEnvironment env) throws ConnectorException {
- super.initialize(env, metadata);
- ConnectorEnvironment connEnv = getConnectorEnvironment();
- this.connectorProperties = connEnv.getProperties();
- this.languageFactory = connEnv.getLanguageFactory();
- initializeFunctionModifiers();
-
- }
-
- /**
- * @param modifier
- * @since 4.2
- */
- private void initializeFunctionModifiers() {
- functionModifiers = new HashMap();
- functionModifiers.putAll(super.getFunctionModifiers());
- functionModifiers.put("log", new AliasModifier("ln"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("log10", new AliasModifier("log"));
//$NON-NLS-1$ //$NON-NLS-2$
+ super.initialize(env);
+ registerFunctionModifier(SourceSystemFunctions.LOG, new
AliasModifier("ln")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.LOG10, new
AliasModifier("log")); //$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("char", new AliasModifier("chr"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("concat", new AliasModifier("||"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("lcase", new AliasModifier("lower"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("left", new
SubstringFunctionModifier(languageFactory, true));//$NON-NLS-1$
- functionModifiers.put("right", new
SubstringFunctionModifier(languageFactory, false));//$NON-NLS-1$
- functionModifiers.put("substring", new
AliasModifier("substr")); //$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("ucase", new AliasModifier("upper"));
//$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.CHAR, new
AliasModifier("chr")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.CONCAT, new
AliasModifier("||")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.LCASE, new
AliasModifier("lower")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.LEFT, new
LeftOrRightFunctionModifier(getLanguageFactory()));//$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.RIGHT, new
LeftOrRightFunctionModifier(getLanguageFactory()));//$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new
AliasModifier("substr")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.UCASE, new
AliasModifier("upper")); //$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("dayname", new
MonthOrDayNameFunctionModifier(languageFactory, "Day"));//$NON-NLS-1$
//$NON-NLS-2$
- functionModifiers.put("dayofweek", new
ModifiedDatePartFunctionModifier(languageFactory, "dow", "+", new
Integer(1)));//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- functionModifiers.put("dayofmonth", new
DatePartFunctionModifier(languageFactory, "day"));//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("dayofyear", new
DatePartFunctionModifier(languageFactory, "doy"));//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("hour", new
DatePartFunctionModifier(languageFactory, "hour"));//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("minute", new
DatePartFunctionModifier(languageFactory, "minute"));//$NON-NLS-1$
//$NON-NLS-2$
- functionModifiers.put("month", new
DatePartFunctionModifier(languageFactory, "month"));//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("monthname", new
MonthOrDayNameFunctionModifier(languageFactory, "Month"));//$NON-NLS-1$
//$NON-NLS-2$
- functionModifiers.put("quarter", new
DatePartFunctionModifier(languageFactory, "quarter"));//$NON-NLS-1$
//$NON-NLS-2$
- functionModifiers.put("second", new
DatePartFunctionModifier(languageFactory, "second"));//$NON-NLS-1$
//$NON-NLS-2$
- functionModifiers.put("week", new
DatePartFunctionModifier(languageFactory, "week"));//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("year", new
DatePartFunctionModifier(languageFactory, "year"));//$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.DAYNAME, new
MonthOrDayNameFunctionModifier(getLanguageFactory(), "Day"));//$NON-NLS-1$
//$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new
ModifiedDatePartFunctionModifier(getLanguageFactory(), "dow", "+", new
Integer(1)));//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new
DatePartFunctionModifier(getLanguageFactory(), "day"));//$NON-NLS-1$
//$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new
DatePartFunctionModifier(getLanguageFactory(), "doy"));//$NON-NLS-1$
//$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.HOUR, new
DatePartFunctionModifier(getLanguageFactory(), "hour"));//$NON-NLS-1$
//$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.MINUTE, new
DatePartFunctionModifier(getLanguageFactory(), "minute"));//$NON-NLS-1$
//$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.MONTH, new
DatePartFunctionModifier(getLanguageFactory(), "month"));//$NON-NLS-1$
//$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.MONTHNAME, new
MonthOrDayNameFunctionModifier(getLanguageFactory(), "Month"));//$NON-NLS-1$
//$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.QUARTER, new
DatePartFunctionModifier(getLanguageFactory(), "quarter"));//$NON-NLS-1$
//$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.SECOND, new
DatePartFunctionModifier(getLanguageFactory(), "second"));//$NON-NLS-1$
//$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.WEEK, new
DatePartFunctionModifier(getLanguageFactory(), "week"));//$NON-NLS-1$
//$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.YEAR, new
DatePartFunctionModifier(getLanguageFactory(), "year"));//$NON-NLS-1$
//$NON-NLS-2$
- functionModifiers.put("ifnull", new
AliasModifier("coalesce")); //$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("nvl", new AliasModifier("coalesce"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("convert", new
PostgreSQLConvertModifier(languageFactory)); //$NON-NLS-1$
- functionModifiers.put("cast", new
PostgreSQLConvertModifier(languageFactory)); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.IFNULL, new
AliasModifier("coalesce")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.CONVERT, new
PostgreSQLConvertModifier(getLanguageFactory())); //$NON-NLS-1$
}
-
+
+ @Override
+ public String translateLiteralBoolean(Boolean booleanValue) {
+ if(booleanValue.booleanValue()) {
+ return "TRUE"; //$NON-NLS-1$
+ }
+ return "FALSE"; //$NON-NLS-1$
+ }
+
+ @Override
+ public String translateLiteralDate(Date dateValue, Calendar cal) {
+ return "DATE '" + formatDateValue(dateValue, cal) +
"'"; //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ @Override
+ public String translateLiteralTime(Time timeValue, Calendar cal) {
+ return "TIME '" + formatDateValue(timeValue, cal) +
"'"; //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ @Override
+ public String translateLiteralTimestamp(Timestamp timestampValue, Calendar cal) {
+ return "to_timestamp('" + formatDateValue(timestampValue, cal) +
"', 'YYYY-MM-DD HH24:MI:SS.US')"; //$NON-NLS-1$//$NON-NLS-2$
//$NON-NLS-3$
+ }
+
+ @Override
+ public int getTimestampNanoSecondPrecision() {
+ 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();
+ }
+
+ /**
+ * Postgres doesn't provide min/max(boolean), so this conversion writes a
min(BooleanValue) as
+ * bool_and(BooleanValue)
+ * @see
com.metamatrix.connector.visitor.framework.LanguageObjectVisitor#visit(com.metamatrix.connector.language.IAggregate)
+ * @since 4.3
+ */
+ @Override
+ public ICommand modifyCommand(ICommand command, ExecutionContext context)
+ throws ConnectorException {
+ HierarchyVisitor visitor = new HierarchyVisitor() {
+ @Override
+ public void visit(IAggregate obj) {
+ if
(TypeFacility.RUNTIME_TYPES.BOOLEAN.equals(obj.getExpression().getType())) {
+ if (obj.getName().equalsIgnoreCase(SQLReservedWords.MIN)) {
+ obj.setName("bool_and"); //$NON-NLS-1$
+ } else if (obj.getName().equalsIgnoreCase(SQLReservedWords.MAX)) {
+ obj.setName("bool_or"); //$NON-NLS-1$
+ }
+ }
+ }
+ };
+
+ command.acceptVisitor(visitor);
+ return command;
+ }
- /**
- * @see
com.metamatrix.connector.jdbc.extension.SQLTranslator#getTranslationVisitor()
- */
- public SQLConversionVisitor getTranslationVisitor() {
- SQLConversionVisitor visitor = new PostgreSQLConversionVisitor();
- visitor.setRuntimeMetadata(getRuntimeMetadata());
- visitor.setFunctionModifiers(functionModifiers);
- visitor.setProperties(connectorProperties);
- visitor.setLanguageFactory(languageFactory);
- visitor.setDatabaseTimeZone(getDatabaseTimeZone());
- return visitor;
- }
-
- /**
- * @see com.metamatrix.connector.jdbc.extension.SQLTranslator#getFunctionModifiers()
- */
- public Map getFunctionModifiers() {
- return functionModifiers;
- }
-
}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLUserIdentityConnectionFactory.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLUserIdentityConnectionFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/PostgreSQLUserIdentityConnectionFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,43 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.connector.jdbc.postgresql;
-
-import com.metamatrix.connector.jdbc.ConnectionQueryStrategy;
-import com.metamatrix.connector.jdbc.ConnectionStrategy;
-import com.metamatrix.connector.jdbc.JDBCUserIdentityConnectionFactory;
-
-
-/**
- * @since 4.3
- */
-public class PostgreSQLUserIdentityConnectionFactory extends
JDBCUserIdentityConnectionFactory {
- private String queryTest = "Select 1"; //$NON-NLS-1$
-
- /**
- * @see
com.metamatrix.connector.jdbc.JDBCSourceConnectionFactory#createConnectionStrategy()
- * @since 4.3
- */
- protected ConnectionStrategy createConnectionStrategy() {
- return new ConnectionQueryStrategy(queryTest);
- }
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/SubstringFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/SubstringFunctionModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/postgresql/SubstringFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,75 +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.extension.FunctionModifier;
-import com.metamatrix.connector.jdbc.extension.impl.BasicFunctionModifier;
-import com.metamatrix.connector.language.*;
-
-/**
- * Convert left(string, count) --> substr(string, 0, count)
- * or right(string, count) --> substr(string, length(string) - count)
- */
-class SubstringFunctionModifier extends BasicFunctionModifier implements FunctionModifier
{
- private ILanguageFactory langFactory;
- private boolean isLeft;
-
- SubstringFunctionModifier(ILanguageFactory langFactory, boolean isLeft) {
- this.langFactory = langFactory;
- this.isLeft = isLeft;
- }
-
- /*
- * @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 (isLeft) {
- func = langFactory.createFunction("substr", //$NON-NLS-1$
- new IExpression[] {
- args[0],
- langFactory.createLiteral(new Integer(1), Integer.class),
- args[1]},
- String.class);
- } else {
- IFunction inner = langFactory.createFunction("LENGTH",
//$NON-NLS-1$
- new IExpression[] {args[0]},
- Integer.class);
-
- IExpression addOne = langFactory.createFunction("+", new
IExpression[] {inner, langFactory.createLiteral(new Integer(1), Integer.class)},
Integer.class); //$NON-NLS-1$
- IExpression substrArgs = langFactory.createFunction("-",
//$NON-NLS-1$
- new IExpression[] {addOne, args[1] },
- Integer.class);
-
- func = langFactory.createFunction("substr", //$NON-NLS-1$
- new IExpression[] {
- args[0],
- substrArgs},
- String.class);
- }
-
- return func;
- }
-}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerCapabilities.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerCapabilities.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerCapabilities.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -77,7 +77,7 @@
supportedFunctions.add("LOWER"); //$NON-NLS-1$
//supportedFunctons.add("LPAD"); //$NON-NLS-1$
supportedFunctions.add("LTRIM"); //$NON-NLS-1$
- //supportedFunctons.add("REPEAT"); //$NON-NLS-1$
+ supportedFunctions.add("REPEAT"); //$NON-NLS-1$
//supportedFunctions.add("RAND"); //$NON-NLS-1$
supportedFunctions.add("REPLACE"); //$NON-NLS-1$
supportedFunctions.add("RIGHT"); //$NON-NLS-1$
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerConvertModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerConvertModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerConvertModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,516 +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.sqlserver;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.metamatrix.connector.jdbc.extension.FunctionModifier;
-import com.metamatrix.connector.jdbc.extension.impl.BasicFunctionModifier;
-import com.metamatrix.connector.jdbc.extension.impl.DropFunctionModifier;
-import com.metamatrix.connector.language.*;
-
-/**
- * Sql Server based Convert modifier, taken from Sybase, so far they are same
- * classes.
- */
-public class SqlServerConvertModifier extends BasicFunctionModifier implements
FunctionModifier {
-
- private static DropFunctionModifier DROP_MODIFIER = new DropFunctionModifier();
- static {
- // index of expressions in convert functions in SQL Server is one, not zero
- DROP_MODIFIER.setReplaceIndex(1);
- }
-
- private ILanguageFactory langFactory;
-
- public SqlServerConvertModifier(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;
- }
-
- /**
- * Target type to String.
- * @param function
- * @return
- */
- 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();
- }
-
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerModModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerModModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerModModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,64 +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.sqlserver;
-
-import com.metamatrix.connector.api.TypeFacility.RUNTIME_TYPES;
-import com.metamatrix.connector.jdbc.extension.impl.AliasModifier;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageFactory;
-
-public class SqlServerModModifier extends AliasModifier {
-
- private ILanguageFactory langFactory;
-
- public SqlServerModModifier(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$
- }
-
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerResultsTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerResultsTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerResultsTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,32 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-/*
- */
-package com.metamatrix.connector.jdbc.sqlserver;
-
-import com.metamatrix.connector.jdbc.extension.impl.BasicResultsTranslator;
-
-
-public class SqlServerResultsTranslator extends BasicResultsTranslator {
-
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerSQLConversionVisitor.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerSQLConversionVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerSQLConversionVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,117 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-/*
- */
-package com.metamatrix.connector.jdbc.sqlserver;
-
-import java.sql.Time;
-
-import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
-import com.metamatrix.connector.language.*;
-
-/**
- */
-public class SqlServerSQLConversionVisitor extends SQLConversionVisitor {
-
- private final int MAX_SELECT_ALIAS_LENGTH = 30;
-
- private final int MAX_TABLE_ALIAS_LENGTH = 128;
-
- private int limit = 0;
- /**
- * Override to handle % operator.
- */
- public void visit(IFunction obj) {
- if(obj.getName().equals("%")) { //$NON-NLS-1$
- String name = obj.getName();
- IExpression[] args = obj.getParameters();
-
- buffer.append(LPAREN);
-
- if(args != null) {
- for(int i=0; i<args.length; i++) {
- append(args[i]);
- if(i < (args.length-1)) {
- buffer.append(SPACE);
- buffer.append(name);
- buffer.append(SPACE);
- }
- }
- }
- buffer.append(RPAREN);
- } else {
- super.visit(obj);
- }
- }
-
- public void visit(ILimit obj) {
- // Don't attach limit at the end
- // See appendQuery() below
- }
-
- protected void appendQuery(IQuery obj) {
- if (obj.getLimit() != null) {
- limit = obj.getLimit().getRowLimit();
- }
- super.appendQuery(obj);
- }
-
- protected void visitSelect(ISelect obj) {
- buffer.append(SELECT).append(SPACE);
- buffer.append(addProcessComment());
- if (limit > 0) {
- buffer.append("TOP") //$NON-NLS-1$
- .append(SPACE)
- .append(limit)
- .append(SPACE);
- limit = 0;
- }
- if (obj.isDistinct()) {
- buffer.append(DISTINCT).append(SPACE);
- }
- append(obj.getSelectSymbols());
- }
-
- /*
- * @see
com.metamatrix.connector.jdbc.extension.SQLConversionVisitor#translateLiteralTime(java.sql.Time)
- */
- protected String translateLiteralTime(Time timeValue) {
- return "{ts'1900-01-01 " + formatDateValue(timeValue) +
"'}"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * @see
com.metamatrix.connector.jdbc.extension.SQLConversionVisitor#getMaxSelectAliasLength()
- * @since 4.3
- */
- protected int getMaxSelectAliasLength() {
- return MAX_SELECT_ALIAS_LENGTH;
- }
-
- /**
- * @see
com.metamatrix.connector.jdbc.extension.SQLConversionVisitor#getMaxTableAliasLength()
- * @since 4.3
- */
- protected int getMaxTableAliasLength() {
- return MAX_TABLE_ALIAS_LENGTH;
- }
-}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerSQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerSQLTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerSQLTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -24,75 +24,32 @@
*/
package com.metamatrix.connector.jdbc.sqlserver;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
-import com.metamatrix.connector.jdbc.extension.impl.AliasModifier;
-import com.metamatrix.connector.jdbc.extension.impl.BasicSQLTranslator;
-import com.metamatrix.connector.jdbc.extension.impl.SubstringFunctionModifier;
-import com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
+import com.metamatrix.connector.api.SourceSystemFunctions;
+import com.metamatrix.connector.jdbc.extension.impl.AliasModifier;
+import com.metamatrix.connector.jdbc.sybase.SybaseSQLTranslator;
+import com.metamatrix.connector.language.ILimit;
/**
*/
-public class SqlServerSQLTranslator extends BasicSQLTranslator {
+public class SqlServerSQLTranslator extends SybaseSQLTranslator {
- private Map functionModifiers;
- private Properties connectorProperties;
- private ILanguageFactory languageFactory;
+ public void initialize(ConnectorEnvironment env) throws ConnectorException {
+ super.initialize(env);
+ //FEDERATE-168 remove mod modifier for SQL Server 2008
+ registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new
AliasModifier("day")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.REPEAT, new
AliasModifier("replicate")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ @Override
+ public String getLengthFunctionName() {
+ return "len"; //$NON-NLS-1$
+ }
+
+ @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 void initialize(ConnectorEnvironment env,
- RuntimeMetadata metadata) throws ConnectorException {
-
- super.initialize(env, metadata);
- ConnectorEnvironment connEnv = getConnectorEnvironment();
- this.connectorProperties = connEnv.getProperties();
- this.languageFactory = connEnv.getLanguageFactory();
- initializeFunctionModifiers();
- }
-
- private void initializeFunctionModifiers() {
- functionModifiers = new HashMap();
- functionModifiers.putAll(super.getFunctionModifiers());
- //FEDERATE-168 this is not necessary for SQL Server 2008
- functionModifiers.put("mod", new
SqlServerModModifier(languageFactory)); //$NON-NLS-1$
- functionModifiers.put("chr", new AliasModifier("char"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("concat", new AliasModifier("+"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("||", new AliasModifier("+"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("ifnull", new AliasModifier("isnull"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("nvl", new AliasModifier("isnull"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("lcase", new AliasModifier("lower"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("length", new AliasModifier("len"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("dayofmonth", new
AliasModifier("day")); //$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("ucase", new AliasModifier("upper"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("substring", new
SubstringFunctionModifier(languageFactory, "substring", "len"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- functionModifiers.put("cast", new
SqlServerConvertModifier(languageFactory)); //$NON-NLS-1$
- functionModifiers.put("convert", new
SqlServerConvertModifier(languageFactory)); //$NON-NLS-1$
- }
-
- /**
- * @see com.metamatrix.connector.jdbc.extension.SQLTranslator#getFunctionModifiers()
- */
- public Map getFunctionModifiers() {
- return functionModifiers;
- }
-
- /**
- * @see
com.metamatrix.connector.jdbc.extension.SQLTranslator#getTranslationVisitor()
- */
- public SQLConversionVisitor getTranslationVisitor() {
- SQLConversionVisitor visitor = new SqlServerSQLConversionVisitor();
- visitor.setRuntimeMetadata(getRuntimeMetadata());
- visitor.setFunctionModifiers(functionModifiers);
- visitor.setProperties(connectorProperties);
- visitor.setLanguageFactory(languageFactory);
- visitor.setDatabaseTimeZone(getDatabaseTimeZone());
- return visitor;
- }
-
-
}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerSingleIdentityConnectionFactory.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerSingleIdentityConnectionFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerSingleIdentityConnectionFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,38 +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.sqlserver;
-
-import com.metamatrix.connector.jdbc.*;
-import com.metamatrix.connector.jdbc.ConnectionStrategy;
-import com.metamatrix.connector.jdbc.JDBCSingleIdentityConnectionFactory;
-
-public class SqlServerSingleIdentityConnectionFactory extends
JDBCSingleIdentityConnectionFactory{
- private String queryTest = "Select 'x'"; //$NON-NLS-1$
-
- protected ConnectionStrategy createConnectionStrategy() {
- return new ConnectionQueryStrategy(queryTest);
- }
-
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerUserIdentityConnectionFactory.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerUserIdentityConnectionFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerUserIdentityConnectionFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,38 +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.sqlserver;
-
-import com.metamatrix.connector.jdbc.*;
-import com.metamatrix.connector.jdbc.ConnectionStrategy;
-import com.metamatrix.connector.jdbc.JDBCUserIdentityConnectionFactory;
-
-public class SqlServerUserIdentityConnectionFactory extends
JDBCUserIdentityConnectionFactory{
- private String queryTest = "Select 'x'"; //$NON-NLS-1$
-
- protected ConnectionStrategy createConnectionStrategy() {
- return new ConnectionQueryStrategy(queryTest);
- }
-
-}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/ssl/JDBCSequeLinkSingleIdentityConnectionFactory.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/ssl/JDBCSequeLinkSingleIdentityConnectionFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/ssl/JDBCSequeLinkSingleIdentityConnectionFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -92,6 +92,6 @@
throw new ConnectorException(e);
}
- return new JDBCSourceConnection(connection, getConnectorEnvironment(),
createConnectionStrategy(), getConnectionListener());
+ return new JDBCSourceConnection(connection, getConnectorEnvironment(),
createConnectionStrategy(), getConnectionListener(), getResultsTranslator(),
getSqlTranslator());
}
}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/FormatTimestampModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/FormatTimestampModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/FormatTimestampModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,98 +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.*;
-
-import com.metamatrix.connector.jdbc.extension.FunctionModifier;
-import com.metamatrix.connector.jdbc.extension.impl.BasicFunctionModifier;
-import com.metamatrix.connector.language.*;
-
-/**
- */
-public class FormatTimestampModifier extends BasicFunctionModifier implements
FunctionModifier {
-
- private Map styleMappings;
- private ILanguageFactory langFactory;
-
- public FormatTimestampModifier(ILanguageFactory langFactory) {
- this.langFactory = langFactory;
- loadStyleMappings();
- }
-
- private void loadStyleMappings() {
- styleMappings = new HashMap();
- styleMappings.put("yyyy-MM-dd", new Integer(1)); // standard SQL
format //$NON-NLS-1$
- styleMappings.put("MM/dd/yyyy", new Integer(1)); //$NON-NLS-1$
- styleMappings.put("yy/MM/dd", new Integer(2)); //$NON-NLS-1$
- styleMappings.put("dd/MM/yy", new Integer(3)); //$NON-NLS-1$
- styleMappings.put("dd.mm.yy", new Integer(4)); //$NON-NLS-1$
- styleMappings.put("dd-mm-yy", new Integer(5)); //$NON-NLS-1$
- styleMappings.put("dd mm yy", new Integer(6)); //$NON-NLS-1$
- styleMappings.put("MMM dd, yy", new Integer(7)); //$NON-NLS-1$
- styleMappings.put("HH:mm:ss", new Integer(8)); //$NON-NLS-1$
- styleMappings.put("MM dd yy hh:mm:ss:zzza", new Integer(9));
//$NON-NLS-1$
- styleMappings.put("MM-dd-yy", new Integer(10)); //$NON-NLS-1$
- styleMappings.put("yy/MM/dd", new Integer(11)); //$NON-NLS-1$
- styleMappings.put("yyMMdd", new Integer(12)); //$NON-NLS-1$
- styleMappings.put("yy/dd/MM", new Integer(13)); //$NON-NLS-1$
- styleMappings.put("MM/yy/dd", new Integer(14)); //$NON-NLS-1$
- styleMappings.put("dd/yy/MM", new Integer(15)); //$NON-NLS-1$
- styleMappings.put("MMM dd yy HH:mm:ss", new Integer(16));
//$NON-NLS-1$
- styleMappings.put("hh:mma", new Integer(17)); //$NON-NLS-1$
- styleMappings.put("HH:mm", new Integer(18)); //$NON-NLS-1$
- styleMappings.put("hh:mm:ss:zzza", new Integer(19)); //$NON-NLS-1$
- styleMappings.put("HH:mm:ss:zzz", new Integer(20)); //$NON-NLS-1$
- }
-
- /*
- * @see
com.metamatrix.connector.jdbc.extension.FunctionModifier#modify(com.metamatrix.data.language.IFunction)
- */
- public IExpression modify(IFunction function) {
- IExpression[] args = function.getParameters();
-
- String format = (String) ((ILiteral)args[1]).getValue();
-
- Integer styleCode = (Integer) styleMappings.get(format);
- IFunction func = null;
- if(styleCode != null) {
- func = langFactory.createFunction("convert", //$NON-NLS-1$
- new IExpression[] {
- langFactory.createLiteral("varchar",
String.class),//$NON-NLS-1$
- args[0],
- langFactory.createLiteral(styleCode, Integer.class)
- },
- String.class);
-
- } else {
- func = langFactory.createFunction("convert", //$NON-NLS-1$
- new IExpression[] {
- langFactory.createLiteral("varchar",
String.class),//$NON-NLS-1$
- args[0]
- },
- String.class);
- }
- return func;
- }
-
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/ModFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/ModFunctionModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/ModFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,59 +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.extension.FunctionModifier;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-
-/**
- */
-public class ModFunctionModifier implements FunctionModifier {
-
- /*
- * @see
com.metamatrix.connector.jdbc.extension.FunctionModifier#modify(com.metamatrix.data.language.IFunction)
- */
- public IExpression modify(IFunction function) {
- return 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("(");//$NON-NLS-1$
-
- IExpression[] args = function.getParameters();
- parts.add(args[0]);
- parts.add(" % "); //$NON-NLS-1$
- parts.add(args[1]);
- parts.add(")"); //$NON-NLS-1$
-
- return parts;
- }
-
-}
Copied:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/ModFunctionModifier.java
(from rev 472,
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sqlserver/SqlServerModModifier.java)
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/ModFunctionModifier.java
(rev 0)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/ModFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -0,0 +1,71 @@
+/*
+ * 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.extension.impl.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;
+ }
+
+}
Property changes on:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/ModFunctionModifier.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:mergeinfo
+
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseConvertModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseConvertModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseConvertModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -408,7 +408,7 @@
new IExpression[] {
langFactory.createLiteral("varchar", String.class),
//$NON-NLS-1$
args[0],
- langFactory.createLiteral(new Integer(1), Integer.class) },
+ langFactory.createLiteral(new Integer(109), Integer.class) },
String.class);
// Build outer convert
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseResultsTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseResultsTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseResultsTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,33 +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 com.metamatrix.connector.jdbc.extension.impl.BasicResultsTranslator;
-
-/**
- */
-public class SybaseResultsTranslator extends BasicResultsTranslator {
-
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseSQLConversionVisitor.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseSQLConversionVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseSQLConversionVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,59 +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 com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
-
-/**
- */
-public class SybaseSQLConversionVisitor extends SQLConversionVisitor {
-
- private static final int MAX_SELECT_ALIAS_LENGTH = 30;
-
- private static final int MAX_TABLE_ALIAS_LENGTH = 30;
-
- /*
- * @see com.metamatrix.data.visitor.util.SQLStringVisitor#useAsInGroupAlias()
- */
- protected boolean useAsInGroupAlias() {
- return false;
- }
-
- /**
- * @see
com.metamatrix.connector.jdbc.extension.SQLConversionVisitor#getMaxSelectAliasLength()
- * @since 4.3
- */
- protected int getMaxSelectAliasLength() {
- return MAX_SELECT_ALIAS_LENGTH;
- }
-
- /**
- * @see
com.metamatrix.connector.jdbc.extension.SQLConversionVisitor#getMaxTableAliasLength()
- * @since 4.3
- */
- protected int getMaxTableAliasLength() {
- return MAX_TABLE_ALIAS_LENGTH;
- }
-}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseSQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseSQLTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseSQLTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -24,76 +24,44 @@
*/
package com.metamatrix.connector.jdbc.sybase;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
-import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
-import com.metamatrix.connector.jdbc.extension.impl.AliasModifier;
-import com.metamatrix.connector.jdbc.extension.impl.BasicSQLTranslator;
-import com.metamatrix.connector.jdbc.extension.impl.SubstringFunctionModifier;
-import com.metamatrix.connector.language.ILanguageFactory;
-import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
+import com.metamatrix.connector.api.SourceSystemFunctions;
+import com.metamatrix.connector.jdbc.extension.SQLTranslator;
+import com.metamatrix.connector.jdbc.extension.impl.AliasModifier;
+import com.metamatrix.connector.jdbc.extension.impl.SubstringFunctionModifier;
/**
*/
-public class SybaseSQLTranslator extends BasicSQLTranslator {
+public class SybaseSQLTranslator extends SQLTranslator {
- private Map functionModifiers;
- private Properties connectorProperties;
- private ILanguageFactory languageFactory;
-
- public SybaseSQLTranslator() {
- }
-
/*
* @see
com.metamatrix.connector.jdbc.extension.SQLTranslator#initialize(com.metamatrix.data.api.ConnectorEnvironment,
com.metamatrix.data.metadata.runtime.RuntimeMetadata)
*/
- public void initialize(ConnectorEnvironment env, RuntimeMetadata metadata) throws
ConnectorException {
- super.initialize(env, metadata);
- connectorProperties = getConnectorEnvironment().getProperties();
- languageFactory = getConnectorEnvironment().getLanguageFactory();
- initializeFunctionModifiers();
- }
-
- private void initializeFunctionModifiers() {
- functionModifiers = new HashMap();
- functionModifiers.putAll(super.getFunctionModifiers());
- functionModifiers.put("mod", new ModFunctionModifier()); //$NON-NLS-1$
- functionModifiers.put("chr", new AliasModifier("char"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("concat", new AliasModifier("+"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("||", new AliasModifier("+"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("lcase", new AliasModifier("lower"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("length", new
AliasModifier("char_length")); //$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("ifnull", new AliasModifier("isnull"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("ucase", new AliasModifier("upper"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("nvl", new AliasModifier("isnull"));
//$NON-NLS-1$ //$NON-NLS-2$
- functionModifiers.put("substring", new
SubstringFunctionModifier(languageFactory, "substring",
"char_length")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- functionModifiers.put("cast", new
SybaseConvertModifier(languageFactory)); //$NON-NLS-1$
- functionModifiers.put("convert", new
SybaseConvertModifier(languageFactory)); //$NON-NLS-1$
- functionModifiers.put("formattimestamp", new
FormatTimestampModifier(languageFactory)); //$NON-NLS-1$
+ public void initialize(ConnectorEnvironment env) throws ConnectorException {
+ super.initialize(env);
+ registerFunctionModifier(SourceSystemFunctions.MOD, new
ModFunctionModifier(getLanguageFactory())); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.CONCAT, new
AliasModifier("+")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.LCASE, new
AliasModifier("lower")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.LENGTH, new
AliasModifier(getLengthFunctionName())); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.IFNULL, new
AliasModifier("isnull")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.UCASE, new
AliasModifier("upper")); //$NON-NLS-1$ //$NON-NLS-2$
+ registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new
SubstringFunctionModifier(getLanguageFactory(), "substring",
getLengthFunctionName())); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ registerFunctionModifier(SourceSystemFunctions.CONVERT, new
SybaseConvertModifier(getLanguageFactory())); //$NON-NLS-1$
+ }
+
+ public String getLengthFunctionName() {
+ return "char_length"; //$NON-NLS-1$
+ }
+
+ @Override
+ public boolean useAsInGroupAlias() {
+ return false;
+ }
+
+ @Override
+ public boolean hasTimeType() {
+ return false;
}
-
- /**
- * @see com.metamatrix.connector.jdbc.extension.SQLTranslator#getFunctionModifiers()
- */
- public Map getFunctionModifiers() {
- return functionModifiers;
- }
-
- /**
- * @see
com.metamatrix.connector.jdbc.extension.SQLTranslator#getTranslationVisitor()
- */
- public SQLConversionVisitor getTranslationVisitor() {
- SQLConversionVisitor visitor = new SybaseSQLConversionVisitor();
- visitor.setRuntimeMetadata(getRuntimeMetadata());
- visitor.setFunctionModifiers(functionModifiers);
- visitor.setProperties(connectorProperties);
- visitor.setLanguageFactory(languageFactory);
- visitor.setDatabaseTimeZone(getDatabaseTimeZone());
- return visitor;
- }
-
+
}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseSingleIdentityConnectionFactory.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseSingleIdentityConnectionFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseSingleIdentityConnectionFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,38 +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 com.metamatrix.connector.jdbc.*;
-import com.metamatrix.connector.jdbc.ConnectionStrategy;
-import com.metamatrix.connector.jdbc.JDBCSingleIdentityConnectionFactory;
-
-public class SybaseSingleIdentityConnectionFactory extends
JDBCSingleIdentityConnectionFactory{
- private String queryTest = "Select 'x'"; //$NON-NLS-1$
-
- protected ConnectionStrategy createConnectionStrategy() {
- return new ConnectionQueryStrategy(queryTest);
- }
-
-}
Deleted:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseUserIdentityConnectionFactory.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseUserIdentityConnectionFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/sybase/SybaseUserIdentityConnectionFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,38 +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 com.metamatrix.connector.jdbc.*;
-import com.metamatrix.connector.jdbc.ConnectionStrategy;
-import com.metamatrix.connector.jdbc.JDBCUserIdentityConnectionFactory;
-
-public class SybaseUserIdentityConnectionFactory extends
JDBCUserIdentityConnectionFactory{
- private String queryTest = "Select 'x'"; //$NON-NLS-1$
-
- protected ConnectionStrategy createConnectionStrategy() {
- return new ConnectionQueryStrategy(queryTest);
- }
-
-}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/util/FunctionReplacementVisitor.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/util/FunctionReplacementVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/util/FunctionReplacementVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -22,10 +22,25 @@
package com.metamatrix.connector.jdbc.util;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import com.metamatrix.connector.jdbc.extension.FunctionModifier;
-import com.metamatrix.connector.language.*;
+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;
/**
@@ -56,22 +71,6 @@
}
/*
- * @see
com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.ICaseExpression)
- */
- public void visit(ICaseExpression obj) {
- super.visit(obj);
- obj.setExpression(replaceFunction(obj.getExpression()));
- int whenCount = obj.getWhenCount();
- for(int i=0; i<whenCount; i++) {
- obj.setWhenExpression(i, replaceFunction(obj.getWhenExpression(i)));
- }
- 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.ICompareCriteria)
*/
public void visit(ICompareCriteria obj) {
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/xa/JDBCSingleIdentityDSConnectionFactory.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/xa/JDBCSingleIdentityDSConnectionFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/xa/JDBCSingleIdentityDSConnectionFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -111,7 +111,7 @@
if(getTransactionIsolation() != NO_ISOLATION_LEVEL_SET &&
getTransactionIsolation() != Connection.TRANSACTION_NONE){
sqlConn.setTransactionIsolation(getTransactionIsolation());
}
- return new JDBCSourceXAConnection(sqlConn, conn, getConnectorEnvironment(),
createConnectionStrategy(), getConnectionListener());
+ return new JDBCSourceXAConnection(sqlConn, conn, getConnectorEnvironment(),
createConnectionStrategy(), getConnectionListener(), getResultsTranslator(),
getSqlTranslator());
}catch(SQLException se){
throw new ConnectorException(se);
}
Modified:
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/xa/JDBCSourceXAConnection.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/xa/JDBCSourceXAConnection.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/main/java/com/metamatrix/connector/jdbc/xa/JDBCSourceXAConnection.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -36,6 +36,8 @@
import com.metamatrix.connector.jdbc.ConnectionListener;
import com.metamatrix.connector.jdbc.ConnectionStrategy;
import com.metamatrix.connector.jdbc.JDBCSourceConnection;
+import com.metamatrix.connector.jdbc.extension.ResultsTranslator;
+import com.metamatrix.connector.jdbc.extension.SQLTranslator;
import com.metamatrix.connector.xa.api.XAConnection;
public class JDBCSourceXAConnection extends JDBCSourceConnection implements XAConnection
{
@@ -43,8 +45,8 @@
private XAResource resource;
private boolean errorOccurred;
- public JDBCSourceXAConnection(Connection conn, javax.sql.XAConnection xaConn,
ConnectorEnvironment environment, ConnectionStrategy connectionStrategy,
ConnectionListener connectionListener) throws ConnectorException, SQLException {
- super(conn, environment, connectionStrategy, connectionListener);
+ public JDBCSourceXAConnection(Connection conn, javax.sql.XAConnection xaConn,
ConnectorEnvironment environment, ConnectionStrategy connectionStrategy,
ConnectionListener connectionListener, ResultsTranslator resultsTranslator, SQLTranslator
sqlTranslator) throws ConnectorException, SQLException {
+ super(conn, environment, connectionStrategy, connectionListener,
resultsTranslator, sqlTranslator);
this.xaConn = xaConn;
this.xaConn.addConnectionEventListener(new ConnectionEventListener() {
@Override
Modified:
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-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/TestJDBCSourceConnection.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -27,17 +27,11 @@
import junit.framework.TestCase;
-import org.mockito.Mockito;
-
import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.connector.api.ConnectorEnvironment;
-import com.metamatrix.connector.api.ExecutionContext;
import com.metamatrix.connector.basic.BasicConnectorCapabilities;
-import com.metamatrix.connector.jdbc.extension.SQLTranslator;
import com.metamatrix.connector.jdbc.extension.impl.BasicResultsTranslator;
import com.metamatrix.connector.jdbc.oracle.OracleSQLTranslator;
-import com.metamatrix.connector.language.IQuery;
-import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
import com.metamatrix.core.util.SimpleMock;
@@ -81,7 +75,7 @@
* @since 4.3
*/
public void testIsAlive() throws Exception {
- JDBCSourceConnection sourceConnection = new JDBCSourceConnection(connection,
environment, strategy);
+ JDBCSourceConnection sourceConnection = new JDBCSourceConnection(connection,
environment, strategy, null, null);
//closed connections should not be 'alive'
fakeConnection.closed = true;
@@ -102,7 +96,7 @@
* @since 4.3
*/
public void testIsAliveNullStrategy() throws Exception {
- JDBCSourceConnection sourceConnection = new JDBCSourceConnection(connection,
environment, null);
+ JDBCSourceConnection sourceConnection = new JDBCSourceConnection(connection,
environment, null, null, null);
//closed connections should not be 'alive'
fakeConnection.closed = true;
@@ -118,11 +112,4 @@
}
- public void testSqlTranslatorInit() throws Exception {
- JDBCSourceConnection sourceConnection = new JDBCSourceConnection(connection,
environment, null);
- JDBCQueryExecution exec =
(JDBCQueryExecution)sourceConnection.createExecution(Mockito.mock(IQuery.class),
Mockito.mock(ExecutionContext.class), Mockito.mock(RuntimeMetadata.class));
- SQLTranslator trans = exec.getSqlTranslator();
- assertTrue(trans.getFunctionModifiers().size() > 0);
- }
-
}
Modified:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/access/TestAccessSQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/access/TestAccessSQLTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/access/TestAccessSQLTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -44,13 +44,13 @@
static {
try {
TRANSLATOR = new AccessSQLTranslator();
- TRANSLATOR.initialize(EnvironmentUtility.createEnvironment(new Properties(),
false), null);
+ TRANSLATOR.initialize(EnvironmentUtility.createEnvironment(new Properties(),
false));
} catch(ConnectorException e) {
e.printStackTrace();
}
}
- public void helpTestVisitor(String input, int expectedType, String expectedOutput)
throws ConnectorException {
+ public void helpTestVisitor(String input, String expectedOutput) throws
ConnectorException {
// Convert from sql to objects
ICommand obj =
FakeTranslationFactory.getInstance().getBQTTranslationUtility().parseCommand(input);
@@ -60,7 +60,6 @@
// Check stuff
assertEquals("Did not get correct sql", expectedOutput, tc.getSql());
//$NON-NLS-1$
- assertEquals("Did not get expected command type", expectedType,
tc.getExecutionType()); //$NON-NLS-1$
}
public void testRowLimit() throws Exception {
@@ -69,8 +68,17 @@
helpTestVisitor(
input,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
+
+ 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$
+
+ helpTestVisitor(
+ input,
+ output);
+
+ }
}
Modified:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/db2/TestDB2ConvertModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/db2/TestDB2ConvertModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/db2/TestDB2ConvertModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -54,11 +54,9 @@
public String helpGetString(IExpression expr) throws Exception {
DB2SQLTranslator trans = new DB2SQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false),
null);
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
- SQLConversionVisitor sqlVisitor = new SQLConversionVisitor();
- sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
- sqlVisitor.setLanguageFactory(LANG_FACTORY);
+ SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
sqlVisitor.append(expr);
return sqlVisitor.toString();
Modified:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/db2/TestDB2SqlTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/db2/TestDB2SqlTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/db2/TestDB2SqlTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -32,7 +32,6 @@
import com.metamatrix.cdk.unittest.FakeTranslationFactory;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.ExecutionContext;
-import com.metamatrix.connector.jdbc.extension.SQLTranslator;
import com.metamatrix.connector.jdbc.extension.TranslatedCommand;
import com.metamatrix.connector.language.ICommand;
import com.metamatrix.core.util.UnitTestUtil;
@@ -42,12 +41,12 @@
public class TestDB2SqlTranslator extends TestCase {
private static Map MODIFIERS;
- private static SQLTranslator TRANSLATOR;
+ private static DB2SQLTranslator TRANSLATOR;
static {
try {
TRANSLATOR = new DB2SQLTranslator();
- TRANSLATOR.initialize(EnvironmentUtility.createEnvironment(new Properties(),
false), null);
+ TRANSLATOR.initialize(EnvironmentUtility.createEnvironment(new Properties(),
false));
MODIFIERS = TRANSLATOR.getFunctionModifiers();
} catch(ConnectorException e) {
e.printStackTrace();
@@ -66,7 +65,7 @@
return UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb";
//$NON-NLS-1$
}
- public void helpTestVisitor(TranslationUtility util, String input, Map modifiers, int
expectedType, String expectedOutput) throws ConnectorException {
+ public void helpTestVisitor(TranslationUtility util, String input, Map modifiers,
String expectedOutput) throws ConnectorException {
// Convert from sql to objects
ICommand obj = util.parseCommand(input);
@@ -76,7 +75,6 @@
tc.translateCommand(obj);
assertEquals("Did not get correct sql", expectedOutput, tc.getSql());
//$NON-NLS-1$
- assertEquals("Did not get expected command type", expectedType,
tc.getExecutionType()); //$NON-NLS-1$
}
public void testRowLimit() throws Exception {
@@ -86,18 +84,16 @@
helpTestVisitor(FakeTranslationFactory.getInstance().getBQTTranslationUtility(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
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$
+ String output = "SELECT SmallA.StringKey FROM SmallA INNER JOIN SmallB ON 1
= 1"; //$NON-NLS-1$
helpTestVisitor(FakeTranslationFactory.getInstance().getBQTTranslationUtility(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
}
Modified:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/derby/TestDerbyConvertModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/derby/TestDerbyConvertModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/derby/TestDerbyConvertModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -54,11 +54,9 @@
public String helpGetString(IExpression expr) throws Exception {
DerbySQLTranslator trans = new DerbySQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false),
null);
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
- SQLConversionVisitor sqlVisitor = new SQLConversionVisitor();
- sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
- sqlVisitor.setLanguageFactory(LANG_FACTORY);
+ SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
sqlVisitor.append(expr);
return sqlVisitor.toString();
Modified:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/mysql/TestMySQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/mysql/TestMySQLTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/mysql/TestMySQLTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -22,16 +22,15 @@
package com.metamatrix.connector.jdbc.mysql;
-import java.util.Map;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.api.EnvironmentUtility;
+import java.util.Map;
+import java.util.Properties;
+
+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.extension.SQLTranslator;
-import com.metamatrix.connector.jdbc.extension.TranslatedCommand;
+import com.metamatrix.connector.jdbc.MetadataFactory;
+import com.metamatrix.connector.jdbc.extension.TranslatedCommand;
import com.metamatrix.connector.language.ICommand;
/**
@@ -39,12 +38,12 @@
public class TestMySQLTranslator extends TestCase {
private static Map MODIFIERS;
- private static SQLTranslator TRANSLATOR;
+ private static MySQLTranslator TRANSLATOR;
static {
try {
TRANSLATOR = new MySQLTranslator();
- TRANSLATOR.initialize(EnvironmentUtility.createEnvironment(new Properties(),
false), null);
+ TRANSLATOR.initialize(EnvironmentUtility.createEnvironment(new Properties(),
false));
MODIFIERS = TRANSLATOR.getFunctionModifiers();
} catch(ConnectorException e) {
e.printStackTrace();
@@ -63,7 +62,7 @@
return MetadataFactory.BQT_VDB;
}
- public void helpTestVisitor(String vdb, String input, Map modifiers, int
expectedType, String expectedOutput) throws ConnectorException {
+ public void helpTestVisitor(String vdb, String input, Map modifiers, String
expectedOutput) throws ConnectorException {
// Convert from sql to objects
ICommand obj = MetadataFactory.helpTranslate(vdb, input);
@@ -73,7 +72,6 @@
// Check stuff
assertEquals("Did not get correct sql", expectedOutput, tc.getSql());
//$NON-NLS-1$
- assertEquals("Did not get expected command type", expectedType,
tc.getExecutionType()); //$NON-NLS-1$
}
public void testRewriteConversion1() throws Exception {
@@ -83,7 +81,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -94,7 +91,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -105,7 +101,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -116,7 +111,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion5() throws Exception {
@@ -126,7 +120,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion6() throws Exception {
@@ -136,17 +129,15 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion8() throws Exception {
- String input = "SELECT nvl(PART_WEIGHT, 'otherString') FROM
PARTS"; //$NON-NLS-1$
+ String input = "SELECT ifnull(PART_WEIGHT, 'otherString') FROM
PARTS"; //$NON-NLS-1$
String output = "SELECT ifnull(PARTS.PART_WEIGHT, 'otherString')
FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion7() throws Exception {
@@ -156,7 +147,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteInsert() throws Exception {
@@ -166,7 +156,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteLocate() throws Exception {
@@ -176,7 +165,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteSubstring1() throws Exception {
@@ -186,7 +174,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteSubstring2() throws Exception {
@@ -196,7 +183,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteUnionWithOrderBy() throws Exception {
@@ -206,7 +192,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -217,7 +202,7 @@
helpTestVisitor(getTestBQTVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
public void testRowLimit3() throws Exception {
String input = "select intkey from bqt1.smalla limit 50, 100";
//$NON-NLS-1$
@@ -226,7 +211,7 @@
helpTestVisitor(getTestBQTVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
}
Modified:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestDayWeekQuarterFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestDayWeekQuarterFunctionModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestDayWeekQuarterFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -29,6 +29,7 @@
import com.metamatrix.cdk.CommandBuilder;
import com.metamatrix.cdk.api.EnvironmentUtility;
+import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
import com.metamatrix.connector.language.IExpression;
import com.metamatrix.connector.language.IFunction;
import com.metamatrix.connector.language.ILanguageFactory;
@@ -58,13 +59,10 @@
IExpression expr = mod.modify(func);
OracleSQLTranslator trans = new OracleSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false),
null);
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
- OracleSQLConversionVisitor sqlVisitor = new OracleSQLConversionVisitor();
- sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
- sqlVisitor.setLanguageFactory(LANG_FACTORY);
+ SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
sqlVisitor.append(expr);
- //System.out.println(" expected: " + expectedStr + " \t actual:
" + sqlVisitor.toString());
assertEquals(expectedStr, sqlVisitor.toString());
return expr;
Modified:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestExtractFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestExtractFunctionModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestExtractFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -23,7 +23,6 @@
package com.metamatrix.connector.jdbc.oracle;
import java.sql.Timestamp;
-import java.util.Map;
import java.util.Properties;
import junit.framework.TestCase;
@@ -31,6 +30,7 @@
import com.metamatrix.cdk.CommandBuilder;
import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
import com.metamatrix.connector.language.IElement;
import com.metamatrix.connector.language.IExpression;
import com.metamatrix.connector.language.IFunction;
@@ -62,17 +62,12 @@
IExpression expr = mod.modify(func);
OracleSQLTranslator trans = new OracleSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false),
null);
+ trans.registerFunctionModifier("extract", mod);
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
- OracleSQLConversionVisitor sqlVisitor = new OracleSQLConversionVisitor();
+ SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
- // register this ExtractFunctionModifier with the OracleSQLConversionVisitor
- Map modifier = trans.getFunctionModifiers();
- modifier.put("extract", mod); //$NON-NLS-1$
- sqlVisitor.setFunctionModifiers(modifier);
-
//sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
- sqlVisitor.setLanguageFactory(LANG_FACTORY);
sqlVisitor.append(expr);
//System.out.println(" expected: " + expectedStr + " \t actual:
" + sqlVisitor.toString());
assertEquals(expectedStr, sqlVisitor.toString());
@@ -101,18 +96,18 @@
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'})",
"day"); //$NON-NLS-1$ //$NON-NLS-2$
+ 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'})", "day"); //$NON-NLS-1$ //$NON-NLS-2$
+ 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)", "day");
//$NON-NLS-1$ //$NON-NLS-2$
+ helpTestMod(elem, "EXTRACT(DAY FROM col)", "dayofmonth");
//$NON-NLS-1$ //$NON-NLS-2$
}
}
Deleted:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestFormatFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestFormatFunctionModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestFormatFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,98 +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.Map;
-import java.util.Properties;
-
-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 TestFormatFunctionModifier extends TestCase {
-
- private static final ILanguageFactory LANG_FACTORY =
CommandBuilder.getLanuageFactory();
-
- /**
- * Constructor for TestMonthFunctionModifier.
- * @param name
- */
- public TestFormatFunctionModifier(String name) {
- super(name);
- }
-
- public IExpression helpTestMod(ILiteral datetime, ILiteral format, String
expectedStr) throws Exception {
- IFunction func = LANG_FACTORY.createFunction("format", //$NON-NLS-1$
- new IExpression[] { datetime, format },
- String.class);
-
- FormatFunctionModifier mod = new FormatFunctionModifier (LANG_FACTORY);
- IExpression expr = mod.modify(func);
-
- OracleSQLTranslator trans = new OracleSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false),
null);
-
- OracleSQLConversionVisitor sqlVisitor = new OracleSQLConversionVisitor();
-
- // register this ExtractFunctionModifier with the OracleSQLConversionVisitor
- Map modifier = trans.getFunctionModifiers();
- modifier.put("format", mod); //$NON-NLS-1$
- sqlVisitor.setFunctionModifiers(modifier);
-
- //sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
- sqlVisitor.setLanguageFactory(LANG_FACTORY);
- 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);
- ILiteral arg2 = LANG_FACTORY.createLiteral("YYYY-MM-DD", String.class);
//$NON-NLS-1$
- helpTestMod(arg1, arg2, "to_char({d'2004-01-21'},
'YYYY-MM-DD')" ); //$NON-NLS-1$
- }
-
- public void test2() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0,
21, 17, 5, 0, 0), Timestamp.class);
- ILiteral arg2 = LANG_FACTORY.createLiteral("YYYY-MM-DD
HH24:MI:SS.fffffffff", String.class); //$NON-NLS-1$
- helpTestMod(arg1, arg2, "to_char({ts'2004-01-21 17:05:00.0'},
'YYYY-MM-DD HH24:MI:SS.fffffffff')"); //$NON-NLS-1$
- }
-
- public void test3() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTime(12, 1, 21),
java.sql.Time.class);
- ILiteral arg2 = LANG_FACTORY.createLiteral("HH24:MI:SS", String.class);
//$NON-NLS-1$
- helpTestMod(arg1, arg2, "to_char({ts'1970-01-01 12:01:21'},
'HH24:MI:SS')"); //$NON-NLS-1$
- }
-
-}
-
Deleted:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestHourFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestHourFunctionModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestHourFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,82 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package 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.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 TestHourFunctionModifier extends TestCase {
-
- private static final ILanguageFactory LANG_FACTORY =
CommandBuilder.getLanuageFactory();
-
- /**
- * Constructor for TestHourFunctionModifier.
- * @param name
- */
- public TestHourFunctionModifier(String name) {
- super(name);
- }
-
- public IExpression helpTestMod(ILiteral c, String expectedStr) throws Exception {
- IFunction func = LANG_FACTORY.createFunction("hour", //$NON-NLS-1$
- new IExpression[] { c },
- Integer.class);
-
- HourFunctionModifier mod = new HourFunctionModifier (LANG_FACTORY);
- IExpression expr = mod.modify(func);
-
- OracleSQLTranslator trans = new OracleSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false),
null);
-
- OracleSQLConversionVisitor sqlVisitor = new OracleSQLConversionVisitor();
- sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
- sqlVisitor.setLanguageFactory(LANG_FACTORY);
- 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, "TO_NUMBER(TO_CHAR({ts'2004-01-21 10:05:00.0'},
'HH24'))"); //$NON-NLS-1$
- }
-
- public void test2() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0,
21, 17, 5, 0, 0), Timestamp.class);
- helpTestMod(arg1, "TO_NUMBER(TO_CHAR({ts'2004-01-21 17:05:00.0'},
'HH24'))"); //$NON-NLS-1$
- }
-}
Modified:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestLeftOrRightFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestLeftOrRightFunctionModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestLeftOrRightFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -28,6 +28,7 @@
import com.metamatrix.cdk.CommandBuilder;
import com.metamatrix.cdk.api.EnvironmentUtility;
+import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
import com.metamatrix.connector.language.IExpression;
import com.metamatrix.connector.language.IFunction;
import com.metamatrix.connector.language.ILanguageFactory;
@@ -52,15 +53,13 @@
new IExpression[] { c, d },
String.class);
- LeftOrRightFunctionModifier mod = new LeftOrRightFunctionModifier (LANG_FACTORY,
target);
+ LeftOrRightFunctionModifier mod = new LeftOrRightFunctionModifier
(LANG_FACTORY);
IExpression expr = mod.modify(func);
OracleSQLTranslator trans = new OracleSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false),
null);
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
- OracleSQLConversionVisitor sqlVisitor = new OracleSQLConversionVisitor();
- sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
- sqlVisitor.setLanguageFactory(LANG_FACTORY);
+ SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
sqlVisitor.append(expr);
//System.out.println(" expected: " + expectedStr + " \t actual:
" + sqlVisitor.toString());
assertEquals(expectedStr, sqlVisitor.toString());
@@ -72,13 +71,13 @@
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', 0, 11)"); //$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', (LENGTH('1234214') - 2))");
//$NON-NLS-1$
+ "SUBSTR('1234214', (-1 * 2))"); //$NON-NLS-1$
}
}
\ No newline at end of file
Modified:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestLocateFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestLocateFunctionModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestLocateFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -28,6 +28,7 @@
import com.metamatrix.cdk.CommandBuilder;
import com.metamatrix.cdk.api.EnvironmentUtility;
+import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
import com.metamatrix.connector.language.IExpression;
import com.metamatrix.connector.language.IFunction;
import com.metamatrix.connector.language.ILanguageFactory;
@@ -55,11 +56,9 @@
IExpression expr = mod.modify(func);
OracleSQLTranslator trans = new OracleSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false),
null);
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
- OracleSQLConversionVisitor sqlVisitor = new OracleSQLConversionVisitor();
- sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
- sqlVisitor.setLanguageFactory(LANG_FACTORY);
+ SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
sqlVisitor.append(expr);
assertEquals(expectedStr, sqlVisitor.toString());
Modified:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestLog10FunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestLog10FunctionModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestLog10FunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -64,6 +64,6 @@
assertEquals(Integer.class, newArg.getType());
assertEquals(new Integer(10), newArg.getValue());
- assertEquals("log(10, 5.2)", SQLStringVisitor.getSQLString(outFunc,
null)); //$NON-NLS-1$
+ assertEquals("log(10, 5.2)", SQLStringVisitor.getSQLString(outFunc));
//$NON-NLS-1$
}
}
Modified:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestMonthOrDayNameFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestMonthOrDayNameFunctionModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestMonthOrDayNameFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -29,6 +29,7 @@
import com.metamatrix.cdk.CommandBuilder;
import com.metamatrix.cdk.api.EnvironmentUtility;
+import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
import com.metamatrix.connector.language.IExpression;
import com.metamatrix.connector.language.IFunction;
import com.metamatrix.connector.language.ILanguageFactory;
@@ -58,15 +59,11 @@
IExpression expr = mod.modify(func);
OracleSQLTranslator trans = new OracleSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false),
null);
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
- OracleSQLConversionVisitor sqlVisitor = new OracleSQLConversionVisitor();
- sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
- sqlVisitor.setLanguageFactory(LANG_FACTORY);
+ SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
sqlVisitor.append(expr);
- //System.out.println(" expected: " + expectedStr + " \t actual:
" + sqlVisitor.toString());
assertEquals(expectedStr, sqlVisitor.toString());
-
return expr;
}
Modified:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleConvertModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleConvertModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleConvertModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -54,11 +54,9 @@
public String helpGetString(IExpression expr) throws Exception {
OracleSQLTranslator trans = new OracleSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false),
null);
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
- SQLConversionVisitor sqlVisitor = trans.getTranslationVisitor();
- sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
- sqlVisitor.setLanguageFactory(LANG_FACTORY);
+ SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
sqlVisitor.append(expr);
return sqlVisitor.toString();
@@ -71,7 +69,7 @@
LANG_FACTORY.createLiteral(tgtType, String.class)},
TypeFacility.getDataTypeClass(tgtType));
- OracleConvertModifier mod = new OracleConvertModifier(LANG_FACTORY, null, null);
+ 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$
@@ -487,7 +485,7 @@
}
public void testDateToTimestamp() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createDate(103, 10, 1),
java.sql.Date.class), "timestamp",
"to_date(to_char({d'2003-11-01'}, 'YYYY-MM-DD HH24:MI:SS'),
'YYYY-MM-DD HH24:MI:SS')"); //$NON-NLS-1$ //$NON-NLS-2$
+ 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
@@ -497,7 +495,7 @@
}
public void testTimeToTimestamp() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createTime(23, 59, 59),
java.sql.Time.class), "timestamp", "to_date(to_char({ts'1970-01-01
23:59:59'}, 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS')");
//$NON-NLS-1$ //$NON-NLS-2$
+ 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
@@ -514,7 +512,7 @@
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 ' || substr(to_char({ts'2003-11-01
12:05:02.0'}, 'FXYYYY-MM-DD HH24:MI:SS'), 12)), 'YYYY-MM-DD
HH24:MI:SS')"); //$NON-NLS-1$ //$NON-NLS-2$
+ 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$
}
}
Added:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleTranslator.java
(rev 0)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -0,0 +1,68 @@
+/*
+ * 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.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.extension.SQLTranslator;
+import com.metamatrix.connector.jdbc.extension.TranslatedCommand;
+import com.metamatrix.connector.language.ICommand;
+
+public class TestOracleTranslator extends TestCase {
+
+ private static SQLTranslator TRANSLATOR;
+
+ static {
+ try {
+ TRANSLATOR = new OracleSQLTranslator();
+ TRANSLATOR.initialize(EnvironmentUtility.createEnvironment(new Properties(),
false));
+ } catch(ConnectorException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void helpTestVisitor(String input, String expectedOutput) throws
ConnectorException {
+ // Convert from sql to objects
+ ICommand obj =
FakeTranslationFactory.getInstance().getAutoIncrementTranslationUtility().parseCommand(input);
+
+ TranslatedCommand tc = new
TranslatedCommand(EnvironmentUtility.createSecurityContext("user"),
TRANSLATOR);
+ tc.translateCommand(obj);
+
+ // Check stuff
+ assertEquals("Did not get correct sql", expectedOutput, tc.getSql());
//$NON-NLS-1$
+ }
+
+ public void testInsertWithSequnce() throws Exception {
+ helpTestVisitor("insert into test.group (e0) values (1)", "INSERT INTO
group (e0, e1) VALUES (1, MYSEQUENCE.nextVal)");
+ }
+
+ public void testInsertWithSequnce1() throws Exception {
+ helpTestVisitor("insert into test.group (e0, e1) values (1, 'x')",
"INSERT INTO group (e0, e1) VALUES (1, 'x')");
+ }
+}
Property changes on:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleTranslator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestParseFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestParseFunctionModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestParseFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,97 +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.Map;
-import java.util.Properties;
-
-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 TestParseFunctionModifier extends TestCase {
-
- private static final ILanguageFactory LANG_FACTORY =
CommandBuilder.getLanuageFactory();
-
- /**
- * Constructor for TestMonthFunctionModifier.
- * @param name
- */
- public TestParseFunctionModifier(String name) {
- super(name);
- }
-
- public IExpression helpTestMod(ILiteral datetime, ILiteral format, Class targetClass,
String expectedStr) throws Exception {
- IFunction func = LANG_FACTORY.createFunction("parse", //$NON-NLS-1$
- new IExpression[] { datetime, format },
- targetClass);
-
- ParseFunctionModifier mod = new ParseFunctionModifier (LANG_FACTORY,
targetClass);
- IExpression expr = mod.modify(func);
-
- OracleSQLTranslator trans = new OracleSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false),
null);
-
- OracleSQLConversionVisitor sqlVisitor = new OracleSQLConversionVisitor();
-
- // register this ExtractFunctionModifier with the OracleSQLConversionVisitor
- Map modifier = trans.getFunctionModifiers();
- modifier.put("parse", mod); //$NON-NLS-1$
- sqlVisitor.setFunctionModifiers(modifier);
-
- //sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
- sqlVisitor.setLanguageFactory(LANG_FACTORY);
- 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("2004-01-21", String.class);
//$NON-NLS-1$
- ILiteral arg2 = LANG_FACTORY.createLiteral("YYYY-MM-DD", String.class);
//$NON-NLS-1$
- helpTestMod(arg1, arg2, java.sql.Date.class, "to_date('2004-01-21',
'YYYY-MM-DD')" ); //$NON-NLS-1$
- }
-
- public void test2() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral("2004-01-21 17:05:00.0",
String.class); //$NON-NLS-1$
- ILiteral arg2 = LANG_FACTORY.createLiteral("YYYY-MM-DD
HH24:MI:SS.fffffffff", String.class); //$NON-NLS-1$
- helpTestMod(arg1, arg2, java.sql.Timestamp.class, "to_date('2004-01-21
17:05:00.0', 'YYYY-MM-DD HH24:MI:SS.fffffffff')"); //$NON-NLS-1$
- }
-
- public void test3() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral("12:01:21", String.class);
//$NON-NLS-1$
- ILiteral arg2 = LANG_FACTORY.createLiteral("HH24:MI:SS", String.class);
//$NON-NLS-1$
- helpTestMod(arg1, arg2, java.sql.Time.class, "to_date('12:01:21',
'HH24:MI:SS')"); //$NON-NLS-1$
- }
-
-}
-
-
Modified:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestSubstringFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestSubstringFunctionModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/oracle/TestSubstringFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -30,6 +30,7 @@
import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.connector.api.TypeFacility;
import com.metamatrix.connector.jdbc.extension.FunctionModifier;
+import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
import com.metamatrix.connector.language.IExpression;
import com.metamatrix.connector.language.IFunction;
import com.metamatrix.connector.language.ILanguageFactory;
@@ -54,13 +55,11 @@
args, TypeFacility.RUNTIME_TYPES.STRING);
OracleSQLTranslator trans = new OracleSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false),
null);
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
IExpression expr =
((FunctionModifier)trans.getFunctionModifiers().get("substring")).modify(func);
//$NON-NLS-1$
- OracleSQLConversionVisitor sqlVisitor = new OracleSQLConversionVisitor();
- sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
- sqlVisitor.setLanguageFactory(LANG_FACTORY);
+ SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
sqlVisitor.append(expr);
assertEquals(expectedStr, sqlVisitor.toString());
Modified:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/postgresql/TestPostgreSQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/postgresql/TestPostgreSQLTranslator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/postgresql/TestPostgreSQLTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -22,16 +22,15 @@
package com.metamatrix.connector.jdbc.postgresql;
-import java.util.Map;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.api.EnvironmentUtility;
+import java.util.Map;
+import java.util.Properties;
+
+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.extension.SQLTranslator;
-import com.metamatrix.connector.jdbc.extension.TranslatedCommand;
+import com.metamatrix.connector.jdbc.MetadataFactory;
+import com.metamatrix.connector.jdbc.extension.TranslatedCommand;
import com.metamatrix.connector.language.ICommand;
/**
@@ -39,12 +38,12 @@
public class TestPostgreSQLTranslator extends TestCase {
private static Map MODIFIERS;
- private static SQLTranslator TRANSLATOR;
+ private static PostgreSQLTranslator TRANSLATOR;
static {
try {
TRANSLATOR = new PostgreSQLTranslator();
- TRANSLATOR.initialize(EnvironmentUtility.createEnvironment(new Properties(),
false), null);
+ TRANSLATOR.initialize(EnvironmentUtility.createEnvironment(new Properties(),
false));
MODIFIERS = TRANSLATOR.getFunctionModifiers();
} catch(ConnectorException e) {
e.printStackTrace();
@@ -63,7 +62,7 @@
return MetadataFactory.BQT_VDB;
}
- public void helpTestVisitor(String vdb, String input, Map modifiers, int
expectedType, String expectedOutput) throws ConnectorException {
+ public void helpTestVisitor(String vdb, String input, Map modifiers, String
expectedOutput) throws ConnectorException {
// Convert from sql to objects
ICommand obj = MetadataFactory.helpTranslate(vdb, input);
@@ -73,7 +72,6 @@
// Check stuff
assertEquals("Did not get correct sql", expectedOutput, tc.getSql());
//$NON-NLS-1$
- assertEquals("Did not get expected command type", expectedType,
tc.getExecutionType()); //$NON-NLS-1$
}
public void testRewriteConversion1() throws Exception {
@@ -83,7 +81,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -94,7 +91,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -105,7 +101,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -116,7 +111,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion5() throws Exception {
@@ -126,7 +120,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion6() throws Exception {
@@ -136,7 +129,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion7() throws Exception {
@@ -146,7 +138,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion8() throws Exception {
@@ -156,7 +147,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion9() throws Exception {
@@ -166,7 +156,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion10() throws Exception {
@@ -176,7 +165,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion11() throws Exception {
@@ -186,7 +174,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion12() throws Exception {
@@ -196,7 +183,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion13() throws Exception {
@@ -206,7 +192,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion14() throws Exception {
@@ -216,7 +201,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion15() throws Exception {
@@ -226,7 +210,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion16() throws Exception {
@@ -236,7 +219,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion17() throws Exception {
@@ -246,7 +228,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion18() throws Exception {
@@ -256,17 +237,15 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteConversion19() throws Exception {
String input = "SELECT convert(convert(PART_WEIGHT, boolean), string) FROM
PARTS"; //$NON-NLS-1$
- String output = "SELECT CASE WHEN cast(PARTS.PART_WEIGHT AS boolean)=TRUE
THEN '1' ELSE '0' END FROM PARTS"; //$NON-NLS-1$
+ String output = "SELECT CASE WHEN cast(PARTS.PART_WEIGHT AS boolean) = TRUE
THEN '1' ELSE '0' END FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -277,7 +256,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
input = "SELECT log10(convert(PART_WEIGHT, double)) FROM PARTS";
//$NON-NLS-1$
output = "SELECT log(cast(PARTS.PART_WEIGHT AS float8)) FROM PARTS";
//$NON-NLS-1$
@@ -285,28 +263,25 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteLeft() throws Exception {
String input = "SELECT left(PART_WEIGHT, 2) FROM PARTS"; //$NON-NLS-1$
- String output = "SELECT substr(PARTS.PART_WEIGHT, 1, 2) FROM PARTS";
//$NON-NLS-1$
+ String output = "SELECT SUBSTR(PARTS.PART_WEIGHT, 1, 2) FROM PARTS";
//$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRewriteRight() throws Exception {
String input = "SELECT right(PART_WEIGHT, 2) FROM PARTS";
//$NON-NLS-1$
- String output = "SELECT substr(PARTS.PART_WEIGHT,
((LENGTH(PARTS.PART_WEIGHT) + 1) - 2)) FROM PARTS"; //$NON-NLS-1$
+ String output = "SELECT SUBSTR(PARTS.PART_WEIGHT, (-1 * 2)) FROM
PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -317,7 +292,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testDayOfMonth() throws Exception {
@@ -327,7 +301,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testDayOfYear() throws Exception {
@@ -337,7 +310,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testHour() throws Exception {
@@ -347,7 +319,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testMinute() throws Exception {
@@ -357,7 +328,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testMonth() throws Exception {
@@ -367,7 +337,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testQuarter() throws Exception {
@@ -377,7 +346,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testSecond() throws Exception {
@@ -387,7 +355,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testWeek() throws Exception {
@@ -397,7 +364,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testYear() throws Exception {
@@ -407,7 +373,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testDayName() throws Exception {
@@ -417,7 +382,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testMonthName() throws Exception {
@@ -427,17 +391,15 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
- public void testNVL() throws Exception {
- String input = "SELECT nvl(PART_WEIGHT, 'otherString') FROM
PARTS"; //$NON-NLS-1$
+ public void testIfnull() throws Exception {
+ String input = "SELECT ifnull(PART_WEIGHT, 'otherString') FROM
PARTS"; //$NON-NLS-1$
String output = "SELECT coalesce(PARTS.PART_WEIGHT, 'otherString')
FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testSubstring1() throws Exception {
@@ -447,7 +409,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testSubstring2() throws Exception {
@@ -457,17 +418,15 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testBooleanAggregate() throws Exception {
String input = "SELECT MIN(convert(PART_WEIGHT, boolean)) FROM PARTS";
//$NON-NLS-1$
- String output = "SELECT CASE MIN(CASE cast(PARTS.PART_WEIGHT AS boolean)
WHEN TRUE THEN 1 ELSE 0 END) WHEN 1 THEN TRUE ELSE FALSE END FROM PARTS";
//$NON-NLS-1$
+ String output = "SELECT bool_and(cast(PARTS.PART_WEIGHT AS boolean)) FROM
PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRowLimit2() throws Exception {
@@ -477,7 +436,7 @@
helpTestVisitor(getTestBQTVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
public void testRowLimit3() throws Exception {
String input = "select intkey from bqt1.smalla limit 50, 100";
//$NON-NLS-1$
@@ -486,7 +445,7 @@
helpTestVisitor(getTestBQTVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
}
Modified:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -27,10 +27,10 @@
import junit.framework.TestCase;
-import com.metamatrix.cdk.CommandBuilder;
import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.jdbc.MetadataFactory;
+import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
import com.metamatrix.connector.jdbc.extension.TranslatedCommand;
import com.metamatrix.connector.jdbc.util.FunctionReplacementVisitor;
import com.metamatrix.connector.language.ICommand;
@@ -46,7 +46,7 @@
SqlServerSQLTranslator trans = new SqlServerSQLTranslator();
try {
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(),
false), null);
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(),
false));
} catch(ConnectorException e) {
e.printStackTrace();
}
@@ -70,30 +70,28 @@
return MetadataFactory.BQT_VDB;
}
- public void helpTestVisitor(String vdb, String input, Map modifiers, int
expectedType, String expectedOutput) throws ConnectorException {
- helpTestVisitor(vdb, input, modifiers, expectedType, new String[] {expectedOutput},
EMPTY_PROPERTIES);
+ 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, Map modifiers, int
expectedType, String[] expectedOutputs, Properties props) throws ConnectorException {
+ public void helpTestVisitor(String vdb, String input, Map modifiers, String[]
expectedOutputs, Properties props) throws ConnectorException {
// Convert from sql to objects
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
- SqlServerSQLConversionVisitor sqlVisitor = new SqlServerSQLConversionVisitor();
- sqlVisitor.setProperties(props);
- sqlVisitor.setLanguageFactory(CommandBuilder.getLanuageFactory());
- sqlVisitor.setFunctionModifiers(modifiers);
+ SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
- TranslatedCommand tc = new
TranslatedCommand(EnvironmentUtility.createSecurityContext("user"), new
SqlServerSQLTranslator(), sqlVisitor, funcVisitor); //$NON-NLS-1$
+ TranslatedCommand tc = new
TranslatedCommand(EnvironmentUtility.createSecurityContext("user"), trans,
sqlVisitor, funcVisitor); //$NON-NLS-1$
tc.translateCommand(obj);
// Check stuff
assertEquals("Did not get correct sql", expectedOutputs[0],
tc.getSql()); //$NON-NLS-1$
- assertEquals("Did not get expected command type", expectedType,
tc.getExecutionType()); //$NON-NLS-1$
}
public void testModFunction() throws Exception {
@@ -103,7 +101,6 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -114,64 +111,9 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
- public void testConcatOperatorFunction() throws Exception {
- String input = "SELECT PART_NAME || 'b' FROM PARTS";
//$NON-NLS-1$
- String output = "SELECT (PARTS.PART_NAME + 'b') FROM PARTS";
//$NON-NLS-1$
-
- helpTestVisitor(getTestVDB(),
- input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
- output);
- }
-
- public void testChrFunction() throws Exception {
- String input = "SELECT chr(CONVERT(PART_ID, INTEGER)) FROM PARTS";
//$NON-NLS-1$
- String output = "SELECT char(convert(int, PARTS.PART_ID)) FROM PARTS";
//$NON-NLS-1$
-
- helpTestVisitor(getTestVDB(),
- input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
- output);
- }
-
- public void testLcaseFunction() throws Exception {
- String input = "SELECT lcase(PART_NAME) FROM PARTS"; //$NON-NLS-1$
- String output = "SELECT lower(PARTS.PART_NAME) FROM PARTS";
//$NON-NLS-1$
- helpTestVisitor(getTestVDB(),
- input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
- output);
- }
-
- public void testUcaseFunction() throws Exception {
- String input = "SELECT ucase(PART_NAME) FROM PARTS"; //$NON-NLS-1$
- String output = "SELECT upper(PARTS.PART_NAME) FROM PARTS";
//$NON-NLS-1$
-
- helpTestVisitor(getTestVDB(),
- input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
- output);
- }
-
- public void testLengthFunction() throws Exception {
- String input = "SELECT length(PART_NAME) FROM PARTS"; //$NON-NLS-1$
- String output = "SELECT len(PARTS.PART_NAME) FROM PARTS";
//$NON-NLS-1$
-
- helpTestVisitor(getTestVDB(),
- input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
- output);
- }
-
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$
@@ -179,110 +121,17 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
- public void testSubstring2ArgFunction() throws Exception {
- String input = "SELECT substring(PART_NAME, 3) FROM PARTS";
//$NON-NLS-1$
- String output = "SELECT substring(PARTS.PART_NAME, 3, len(PARTS.PART_NAME))
FROM PARTS"; //$NON-NLS-1$
-
- helpTestVisitor(getTestVDB(),
- input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
- output);
- }
-
- public void testSubstring3ArgFunction() throws Exception {
- 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$
-
- helpTestVisitor(getTestVDB(),
- input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
- output);
- }
-
- 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$
-
- helpTestVisitor(getTestVDB(),
- input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
- output);
- }
-
- public void testConvertFunctionChar() throws Exception {
- 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$
-
- helpTestVisitor(getTestVDB(),
- input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
- output);
- }
-
- public void testConvertFunctionBoolean() throws Exception {
- 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$
-
- helpTestVisitor(getTestVDB(),
- input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
- output);
- }
-
- public void testDateLiteral() throws Exception {
- helpTestVisitor(getTestVDB(),
- "select {d'2002-12-31'} FROM parts", //$NON-NLS-1$
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
- "SELECT {d'2002-12-31'} FROM PARTS"); //$NON-NLS-1$
- }
-
- public void testTimeLiteral() throws Exception {
- helpTestVisitor(getTestVDB(),
- "select {t'13:59:59'} FROM parts", //$NON-NLS-1$
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
- "SELECT {ts'1900-01-01 13:59:59'} FROM PARTS");
//$NON-NLS-1$
- }
-
- public void testTimestampLiteral() throws Exception {
- helpTestVisitor(getTestVDB(),
- "select {ts'2002-12-31 13:59:59'} FROM parts",
//$NON-NLS-1$
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
- "SELECT {ts'2002-12-31 13:59:59.0'} FROM PARTS");
//$NON-NLS-1$
- }
-
- public void helpTestVisitor(String vdb, String input, String expectedOutput) throws
ConnectorException {
- helpTestVisitor(vdb, input, MODIFIERS, TranslatedCommand.EXEC_TYPE_QUERY,
expectedOutput);
- }
-
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(getBQTVDB(),
input,
MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
- 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$
-
- helpTestVisitor(getBQTVDB(),
- input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
- }
}
Deleted:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sqlserver/TestSqlServerConvertModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sqlserver/TestSqlServerConvertModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sqlserver/TestSqlServerConvertModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,520 +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.sqlserver;
-
-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.common.types.DataTypeManager;
-import com.metamatrix.connector.jdbc.extension.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 TestSqlServerConvertModifier extends TestCase {
-
- private static final ILanguageFactory LANG_FACTORY =
CommandBuilder.getLanuageFactory();
-
- /**
- * Constructor for TestSybaseConvertModifier.
- * @param name
- */
- public TestSqlServerConvertModifier(String name) {
- super(name);
- }
-
- public String helpGetString(IExpression expr) throws Exception {
- SqlServerSQLTranslator trans = new SqlServerSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false),
null);
-
- SQLConversionVisitor sqlVisitor = trans.getTranslationVisitor();
- sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
- sqlVisitor.setLanguageFactory(LANG_FACTORY);
- 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)},
- DataTypeManager.getDataTypeClass(tgtType));
-
- SqlServerConvertModifier mod = new SqlServerConvertModifier(LANG_FACTORY);
- IExpression expr = mod.modify(func);
-
- assertEquals("Error converting from " +
DataTypeManager.getDataTypeName(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", "convert(char, '5')"); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
- }
-
- public void testStringToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class),
"boolean", "convert(bit, '5')"); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
- }
-
- public void testStringToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class),
"byte", "convert(tinyint, '5')"); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
- }
-
- public void testStringToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class),
"short", "convert(smallint, '5')"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class),
"integer", "convert(int, '5')"); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
- }
-
- public void testStringToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class),
"long", "convert(numeric, '5')"); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
- }
-
- public void testStringToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class),
"biginteger", "convert(numeric, '5')");
//$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testStringToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class),
"float", "convert(real, '5')");//$NON-NLS-1$//$NON-NLS-2$
//$NON-NLS-3$
- }
-
- public void testStringToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class),
"double", "convert(float, '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", "convert(datetime, '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", "convert(datetime, '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", "convert(datetime, '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", "convert(float, '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", "convert(varchar, '5')"); //$NON-NLS-1$
//$NON-NLS-2$
- }
-
- // Source = BOOLEAN
-
- public void testBooleanToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"string", "convert(varchar, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"byte", "convert(tinyint, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"short", "convert(smallint, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"integer", "convert(int, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"long", "convert(numeric, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"biginteger", "convert(numeric, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"float", "convert(real, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"double", "convert(float, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBooleanToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"bigdecimal", "convert(float, 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", "convert(varchar, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class),
"boolean", "convert(bit, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class),
"short", "convert(smallint, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class),
"integer", "convert(int, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class),
"long", "convert(numeric, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class),
"biginteger", "convert(numeric, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class),
"float", "convert(real, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class),
"double", "convert(float, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testByteToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class),
"bigdecimal", "convert(float, 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", "convert(varchar, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class),
"boolean", "convert(bit, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class),
"byte", "convert(tinyint, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class),
"integer", "convert(int, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class),
"long", "convert(numeric, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class),
"biginteger", "convert(numeric, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class),
"float", "convert(real, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class),
"double", "convert(float, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testShortToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class),
"bigdecimal", "convert(float, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = INTEGER
-
- public void testIntegerToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class),
"string", "convert(varchar, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class),
"boolean", "convert(bit, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class),
"byte", "convert(tinyint, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class),
"short", "convert(smallint, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class),
"long", "convert(numeric, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class),
"biginteger", "convert(numeric, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class),
"float", "convert(real, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class),
"double", "convert(float, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testIntegerToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class),
"bigdecimal", "convert(float, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = LONG
-
- public void testLongToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "string",
"convert(varchar, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class),
"boolean", "convert(bit, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "byte",
"convert(tinyint, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "short",
"convert(smallint, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class),
"integer", "convert(int, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class),
"biginteger", "convert(numeric, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "float",
"convert(real, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "double",
"convert(float, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testLongToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class),
"bigdecimal", "convert(float, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = BIGINTEGER
-
- public void testBigIntegerToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"),
BigInteger.class), "string", "convert(varchar, 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", "convert(bit, 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", "convert(tinyint, 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", "convert(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", "convert(int, 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", "convert(numeric, 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", "convert(real, 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", "convert(float, 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", "convert(float, 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", "convert(varchar, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class),
"boolean", "convert(bit, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class),
"byte", "convert(tinyint, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class),
"short", "convert(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", "convert(int, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class),
"long", "convert(numeric, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class),
"biginteger", "convert(numeric, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class),
"double", "convert(float, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testFloatToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class),
"bigdecimal", "convert(float, 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", "convert(varchar, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class),
"boolean", "convert(bit, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class),
"byte", "convert(tinyint, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class),
"short", "convert(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", "convert(int, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class),
"long", "convert(numeric, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToBigInteger() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class),
"biginteger", "convert(numeric, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDoubleToFloat() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class),
"float", "convert(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", "convert(float, 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", "convert(varchar, 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", "convert(bit, 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", "convert(tinyint, 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", "convert(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", "convert(int, 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", "convert(numeric, 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", "convert(numeric, 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", "convert(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", "convert(float, 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", "convert(varchar, {d'2003-11-01'},
101)"); //$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", "convert(datetime,
{d'2003-11-01'})"); //$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", "convert(varchar, {ts'1900-01-01
23:59:59'}, 108)"); //$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", "convert(datetime, {ts'1900-01-01
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",
"convert(varchar, {ts'2003-11-01 12:05:02.0'}, 109)"); //$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",
"convert(datetime, convert(varchar, {ts'2003-11-01 12:05:02.0'},
109))"); //$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",
"convert(datetime, convert(varchar, {ts'2003-11-01 12:05:02.0'},
108))"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-}
Deleted:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/TestFormatTimestampModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/TestFormatTimestampModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/TestFormatTimestampModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,78 +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.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.language.IExpression;
-import com.metamatrix.connector.language.IFunction;
-import com.metamatrix.connector.language.ILanguageFactory;
-
-/**
- */
-public class TestFormatTimestampModifier extends TestCase {
-
- private static final ILanguageFactory LANG_FACTORY =
CommandBuilder.getLanuageFactory();
-
- /**
- * Constructor for TestFormatTimestampModifier.
- * @param name
- */
- public TestFormatTimestampModifier(String name) {
- super(name);
- }
-
- public void helpTestMod(String format, String expectedStr) throws Exception {
- Timestamp ts = new Timestamp(103, 10, 1, 12, 5, 2, 0);
- IFunction func = LANG_FACTORY.createFunction("formattimestamp",
//$NON-NLS-1$
- new IExpression[] { LANG_FACTORY.createLiteral(ts, Timestamp.class),
- LANG_FACTORY.createLiteral(format, String.class) },
- String.class);
-
- FormatTimestampModifier mod = new FormatTimestampModifier(LANG_FACTORY);
- IExpression expr = mod.modify(func);
-
- SybaseSQLTranslator trans = new SybaseSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false),
null);
-
- SybaseSQLConversionVisitor sqlVisitor = new SybaseSQLConversionVisitor();
- sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
- sqlVisitor.setLanguageFactory(LANG_FACTORY);
- sqlVisitor.append(expr);
- assertEquals(expectedStr, sqlVisitor.toString());
- }
-
- public void testModStyle1() throws Exception {
- helpTestMod("MM/dd/yyyy", "convert(varchar, {ts'2003-11-01
12:05:02.0'}, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testModUnknownFormat() throws Exception {
- helpTestMod("MM:yyy", "convert(varchar, {ts'2003-11-01
12:05:02.0'})"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-}
Deleted:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/TestModFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/TestModFunctionModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/TestModFunctionModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -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.sybase;
-
-import java.util.Properties;
-
-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 TestModFunctionModifier extends TestCase {
-
- private static final ILanguageFactory LANG_FACTORY =
CommandBuilder.getLanuageFactory();
-
-
- /**
- * Constructor for TestModFunctionModifier.
- * @param name
- */
- public TestModFunctionModifier(String name) {
- super(name);
- }
-
- public void helpTestMod(int first, int second, String expectedStr) throws Exception
{
- IFunction func = LANG_FACTORY.createFunction("mod", //$NON-NLS-1$
- new IExpression[] { LANG_FACTORY.createLiteral(new Integer(first),
Integer.class),
- LANG_FACTORY.createLiteral(new Integer(second), Integer.class) },
- String.class);
-
- ModFunctionModifier mod = new ModFunctionModifier();
- IExpression expr = mod.modify(func);
-
- SybaseSQLTranslator trans = new SybaseSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false),
null);
-
- SybaseSQLConversionVisitor sqlVisitor = new SybaseSQLConversionVisitor();
- sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
- sqlVisitor.setLanguageFactory(LANG_FACTORY);
- sqlVisitor.append(expr);
- assertEquals(expectedStr, sqlVisitor.toString());
- }
-
- public void testMod1() throws Exception {
- helpTestMod(5, 5, "(5 % 5)"); //$NON-NLS-1$
- }
-
-}
Modified:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/TestSybaseConvertModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/TestSybaseConvertModifier.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/TestSybaseConvertModifier.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -22,6 +22,8 @@
package com.metamatrix.connector.jdbc.sybase;
+import java.math.BigDecimal;
+import java.math.BigInteger;
import java.sql.Timestamp;
import java.util.Properties;
@@ -29,12 +31,12 @@
import com.metamatrix.cdk.CommandBuilder;
import com.metamatrix.cdk.api.EnvironmentUtility;
-import com.metamatrix.connector.jdbc.util.FunctionReplacementVisitor;
+import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.connector.jdbc.extension.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.connector.language.ISelectSymbol;
import com.metamatrix.query.unittest.TimestampUtil;
/**
@@ -53,11 +55,9 @@
public String helpGetString(IExpression expr) throws Exception {
SybaseSQLTranslator trans = new SybaseSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false),
null);
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
- SybaseSQLConversionVisitor sqlVisitor = new SybaseSQLConversionVisitor();
- sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
- sqlVisitor.setLanguageFactory(LANG_FACTORY);
+ SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
sqlVisitor.append(expr);
return sqlVisitor.toString();
@@ -67,15 +67,21 @@
SybaseConvertModifier mod = new SybaseConvertModifier(LANG_FACTORY);
IExpression expr = mod.modify(func);
- SybaseSQLTranslator trans = new SybaseSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false),
null);
+ assertEquals(expectedStr, helpGetString(expr));
+ }
+
+ 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)},
+ DataTypeManager.getDataTypeClass(tgtType));
- SybaseSQLConversionVisitor sqlVisitor = new SybaseSQLConversionVisitor();
- sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
- sqlVisitor.setLanguageFactory(LANG_FACTORY);
- sqlVisitor.append(expr);
-
- assertEquals(expectedStr, sqlVisitor.toString());
+ SybaseConvertModifier mod = new SybaseConvertModifier(LANG_FACTORY);
+ IExpression expr = mod.modify(func);
+
+ assertEquals("Error converting from " +
DataTypeManager.getDataTypeName(srcExpression.getType()) + " to " + tgtType,
//$NON-NLS-1$ //$NON-NLS-2$
+ expectedExpression, helpGetString(expr));
}
// original test -- this is not a drop one anymore
@@ -115,35 +121,9 @@
LANG_FACTORY.createLiteral("date", String.class)},
//$NON-NLS-1$
java.sql.Date.class);
- helpGetString1(func, "convert(datetime, convert(varchar, {ts'1989-03-03
07:08:12.000099999'}, 1))"); //$NON-NLS-1$
+ helpGetString1(func, "convert(datetime, convert(varchar, {ts'1989-03-03
07:08:12.000099999'}, 109))"); //$NON-NLS-1$
}
- public void testConvertFormat() throws Exception {
-
- Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
- IFunction func1 = LANG_FACTORY.createFunction("formattimestamp",
//$NON-NLS-1$
- new IExpression[] {
- LANG_FACTORY.createLiteral(ts, Timestamp.class),
- LANG_FACTORY.createLiteral("MM/dd/yyyy", String.class)},
//$NON-NLS-1$
- String.class);
-
- IFunction func2 = LANG_FACTORY.createFunction("convert",
//$NON-NLS-1$
- new IExpression[] {
- func1,
- LANG_FACTORY.createLiteral("date", String.class)},
//$NON-NLS-1$
- java.sql.Date.class);
-
- SybaseSQLTranslator trans = new SybaseSQLTranslator();
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false),
null);
-
- // Perform function replacement, per standard function modifiers
- FunctionReplacementVisitor functionVisitor = new
FunctionReplacementVisitor(trans.getFunctionModifiers());
- ISelectSymbol holder = LANG_FACTORY.createSelectSymbol("holder",
func2); //$NON-NLS-1$
- holder.acceptVisitor(functionVisitor);
- IExpression expr = holder.getExpression();
-
- assertEquals("convert(datetime, convert(varchar, {ts'2003-11-01
12:05:02.0'}, 1))", helpGetString(expr)); //$NON-NLS-1$
- }
/********************END of convert(INPUT, date) ******************/
/********************Beginning of convert(INPUT, time) ******************/
public void testStringToTime() throws Exception {
@@ -188,7 +168,7 @@
LANG_FACTORY.createLiteral("timestamp", String.class)},
//$NON-NLS-1$
java.sql.Timestamp.class);
- helpGetString1(func, "convert(datetime, {t'12:02:03'})");
//$NON-NLS-1$
+ helpGetString1(func, "convert(datetime, {ts'1970-01-01
12:02:03'})"); //$NON-NLS-1$
}
public void testDateToTimestamp() throws Exception {
@@ -253,7 +233,7 @@
LANG_FACTORY.createLiteral("string", String.class)},
//$NON-NLS-1$
String.class);
- helpGetString1(func, "convert(varchar, {t'03:10:01'}, 108)");
//$NON-NLS-1$
+ helpGetString1(func, "convert(varchar, {ts'1970-01-01 03:10:01'},
108)"); //$NON-NLS-1$
}
public void testBigDecimalToString() throws Exception {
@@ -829,6 +809,233 @@
java.math.BigDecimal.class);
helpGetString1(func, "convert(float, 0)"); //$NON-NLS-1$
+ }
+
+ // Source = CHAR
+
+ public void testCharToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Character('5'), Character.class),
"string", "convert(varchar, '5')"); //$NON-NLS-1$
//$NON-NLS-2$
}
+
+ // Source = BOOLEAN
+
+ public void testBooleanToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"string", "convert(varchar, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"byte", "convert(tinyint, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"short", "convert(smallint, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"integer", "convert(int, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"long", "convert(numeric, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"biginteger", "convert(numeric, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"float", "convert(real, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"double", "convert(float, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBooleanToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"bigdecimal", "convert(float, 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", "convert(varchar, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class),
"long", "convert(numeric, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class),
"biginteger", "convert(numeric, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class),
"float", "convert(real, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class),
"double", "convert(float, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testByteToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class),
"bigdecimal", "convert(float, 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", "convert(varchar, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class),
"long", "convert(numeric, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class),
"biginteger", "convert(numeric, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class),
"float", "convert(real, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class),
"double", "convert(float, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testShortToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Short((short)1), Short.class),
"bigdecimal", "convert(float, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = INTEGER
+
+ public void testIntegerToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class),
"string", "convert(varchar, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class),
"long", "convert(numeric, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class),
"biginteger", "convert(numeric, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class),
"float", "convert(real, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class),
"double", "convert(float, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testIntegerToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Integer(1), Integer.class),
"bigdecimal", "convert(float, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = LONG
+
+ public void testLongToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "string",
"convert(varchar, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class),
"biginteger", "convert(numeric, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "float",
"convert(real, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class), "double",
"convert(float, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testLongToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Long(1), Long.class),
"bigdecimal", "convert(float, 1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = BIGINTEGER
+
+ public void testBigIntegerToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"),
BigInteger.class), "string", "convert(varchar, 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", "convert(numeric, 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", "convert(real, 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", "convert(float, 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", "convert(float, 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", "convert(varchar, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class),
"long", "convert(numeric, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class),
"biginteger", "convert(numeric, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class),
"double", "convert(float, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testFloatToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class),
"bigdecimal", "convert(float, 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", "convert(varchar, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class),
"long", "convert(numeric, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToBigInteger() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class),
"biginteger", "convert(numeric, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDoubleToFloat() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class),
"float", "convert(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", "convert(float, 1.2)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBigDecimalToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"),
BigDecimal.class), "long", "convert(numeric, 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", "convert(numeric, 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", "convert(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", "convert(float, 1.0)"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
+ }
+
}
Modified:
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-jdbc/src/test/java/com/metamatrix/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -22,7 +22,6 @@
package com.metamatrix.connector.jdbc.sybase;
-import java.util.Map;
import java.util.Properties;
import junit.framework.TestCase;
@@ -30,6 +29,7 @@
import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.jdbc.MetadataFactory;
+import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
import com.metamatrix.connector.jdbc.extension.TranslatedCommand;
import com.metamatrix.connector.jdbc.util.FunctionReplacementVisitor;
import com.metamatrix.connector.language.ICommand;
@@ -38,19 +38,6 @@
*/
public class TestSybaseSQLConversionVisitor extends TestCase {
- private static Map MODIFIERS;
-
- static {
- SybaseSQLTranslator trans = new SybaseSQLTranslator();
-
- try {
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(),
false), null);
- } catch(ConnectorException e) {
- e.printStackTrace();
- }
-
- MODIFIERS = trans.getFunctionModifiers();
- }
/**
* Constructor for TestSqlServerConversionVisitor.
* @param name
@@ -67,17 +54,22 @@
return MetadataFactory.BQT_VDB;
}
- public void helpTestVisitor(String vdb, String input, Map modifiers, int
expectedType, String expectedOutput) {
+ public void helpTestVisitor(String vdb, String input, String expectedOutput) {
// Convert from sql to objects
ICommand obj = MetadataFactory.helpTranslate(vdb, input);
// Apply function replacement
- FunctionReplacementVisitor funcVisitor = new
FunctionReplacementVisitor(modifiers);
-
+ 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
- SybaseSQLConversionVisitor sqlVisitor = new SybaseSQLConversionVisitor();
- sqlVisitor.setFunctionModifiers(modifiers);
- TranslatedCommand tc = new
TranslatedCommand(EnvironmentUtility.createSecurityContext("user"), new
SybaseSQLTranslator(), sqlVisitor, funcVisitor);
+ SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
+ TranslatedCommand tc = new
TranslatedCommand(EnvironmentUtility.createSecurityContext("user"), trans,
sqlVisitor, funcVisitor);
try {
tc.translateCommand(obj);
} catch (ConnectorException e) {
@@ -88,7 +80,6 @@
// 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$
- assertEquals("Did not get expected command type", expectedType,
tc.getExecutionType()); //$NON-NLS-1$
}
public void testModFunction() {
@@ -98,8 +89,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -109,40 +98,14 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
- public void testConcatOperatorFunction() {
- String input = "SELECT PART_NAME || 'b' FROM PARTS";
//$NON-NLS-1$
- String output = "SELECT (PARTS.PART_NAME + 'b') FROM PARTS";
//$NON-NLS-1$
-
- helpTestVisitor(getTestVDB(),
- input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
- output);
- }
-
- public void testChrFunction() {
- String input = "SELECT chr(CONVERT(PART_ID, INTEGER)) FROM PARTS";
//$NON-NLS-1$
- String output = "SELECT char(convert(int, PARTS.PART_ID)) FROM PARTS";
//$NON-NLS-1$
-
- helpTestVisitor(getTestVDB(),
- input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
- output);
- }
-
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$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -152,8 +115,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -163,8 +124,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -174,8 +133,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -185,8 +142,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -197,8 +152,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -208,8 +161,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -219,8 +170,6 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -230,57 +179,50 @@
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
- public void testNvlFunction() {
- String input = "SELECT nvl(PART_NAME, 'abc') FROM PARTS";
//$NON-NLS-1$
- String output = "SELECT isnull(PARTS.PART_NAME, 'abc') FROM
PARTS"; //$NON-NLS-1$
-
- helpTestVisitor(getTestVDB(),
- input,
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
- output);
- }
-
public void testDateLiteral() {
helpTestVisitor(getTestVDB(),
"select {d'2002-12-31'} FROM parts", //$NON-NLS-1$
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT {d'2002-12-31'} FROM PARTS"); //$NON-NLS-1$
}
public void testTimeLiteral() {
helpTestVisitor(getTestVDB(),
"select {t'13:59:59'} FROM parts", //$NON-NLS-1$
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
- "SELECT {t'13:59:59'} FROM PARTS"); //$NON-NLS-1$
+ "SELECT {ts'1970-01-01 13:59:59'} FROM PARTS");
//$NON-NLS-1$
}
public void testTimestampLiteral() {
helpTestVisitor(getTestVDB(),
"select {ts'2002-12-31 13:59:59'} FROM parts",
//$NON-NLS-1$
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT {ts'2002-12-31 13:59:59.0'} FROM PARTS");
//$NON-NLS-1$
}
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$
- MODIFIERS,
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT SmallA.IntKey FROM SmallA WHERE SmallA.BooleanValue IN (0, 1)
ORDER BY IntKey"); //$NON-NLS-1$
}
+
+ 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$
+
+ helpTestVisitor(getTestVDB(),
+ input,
+ output);
+ }
+
+ 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$
+
+ helpTestVisitor(getBQTVDB(),
+ input,
+ output);
+ }
- public void helpTestVisitor(String vdb, String input, String expectedOutput) throws
ConnectorException {
- helpTestVisitor(vdb, input, MODIFIERS, TranslatedCommand.EXEC_TYPE_QUERY,
expectedOutput);
-
- }
}
Modified:
trunk/connectors/connector-ldap/src/main/java/com/metamatrix/connector/ldap/IQueryToLdapSearchParser.java
===================================================================
---
trunk/connectors/connector-ldap/src/main/java/com/metamatrix/connector/ldap/IQueryToLdapSearchParser.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-ldap/src/main/java/com/metamatrix/connector/ldap/IQueryToLdapSearchParser.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -45,15 +45,14 @@
import java.util.ListIterator;
import java.util.Properties;
+import javax.naming.NamingException;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.SearchControls;
import javax.naming.ldap.SortKey;
-import javax.naming.NamingException;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.ConnectorLogger;
import com.metamatrix.connector.language.IAggregate;
-import com.metamatrix.connector.language.ICaseExpression;
import com.metamatrix.connector.language.ICompareCriteria;
import com.metamatrix.connector.language.ICompoundCriteria;
import com.metamatrix.connector.language.ICriteria;
@@ -412,8 +411,6 @@
} else {
if(e instanceof IAggregate) {
logger.logError("Received IAggregate, but it is not supported. Check
capabilities."); //$NON-NLS-1$
- } else if(e instanceof ICaseExpression) {
- logger.logError("Received ICaseExpression, but it is not supported. Check
capabilties."); //$NON-NLS-1$
} else if(e instanceof IFunction) {
logger.logError("Received IFunction, but it is not supported. Check
capabilties."); //$NON-NLS-1$
} else if(e instanceof IScalarSubquery) {
Modified:
trunk/connectors/connector-ldap/src/test/java/com/metamatrix/connector/ldap/TestIQueryToLdapSearchParser.java
===================================================================
---
trunk/connectors/connector-ldap/src/test/java/com/metamatrix/connector/ldap/TestIQueryToLdapSearchParser.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/connector-ldap/src/test/java/com/metamatrix/connector/ldap/TestIQueryToLdapSearchParser.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -203,7 +203,7 @@
private LDAPSearchDetails helpGetSearchDetails(String queryString) throws
ConnectorException {
ConnectorLogger logger = new SysLogger(false);
QueryMetadataInterface metadata = exampleLdap();
- RuntimeMetadata rm = new MetadataFactory(metadata).createRuntimeMetadata();
+ RuntimeMetadata rm = new MetadataFactory(metadata).getRuntimeMetadata();
Properties props = new Properties();
IQueryToLdapSearchParser searchParser = new
IQueryToLdapSearchParser(logger,rm,props);
Property changes on: trunk/connectors/connector-xml-common
___________________________________________________________________
Name: svn:ignore
- target
+ target
.project
bin
Deleted:
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialConversionVisitor.java
===================================================================
---
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialConversionVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialConversionVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,70 +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.
- */
-
-/*
- * Created on Mar 23, 2004
- */
-package com.metamatrix.connector.jdbc.oracle.spatial;
-
-import java.util.Iterator;
-
-import com.metamatrix.connector.jdbc.oracle.OracleSQLConversionVisitor;
-import com.metamatrix.connector.language.ISelect;
-import com.metamatrix.connector.language.ISelectSymbol;
-
-public class OracleSpatialConversionVisitor extends OracleSQLConversionVisitor {
-
- public void visit(ISelect obj) {
- buffer.append(SELECT);
- buffer.append(SPACE);
-
- // Add a hint here if one is in the SELECT
- if (obj instanceof SpatialHint) {
- SpatialHint hint = (SpatialHint)obj;
- buffer.append(hint.getHint());
- buffer.append(SPACE);
- }
-
- // Add DISTINCT if necessary
- if (obj.isDistinct()) {
- buffer.append(DISTINCT).append(SPACE);
- }
-
- // Add select symbols
- Iterator iter = obj.getSelectSymbols().iterator();
- while (iter.hasNext()) {
- ISelectSymbol sSymbol = (ISelectSymbol)iter.next();
- if (sSymbol.getExpression().getType().equals(Object.class)) {
- buffer.append(NULL).append(SPACE);
- buffer.append(AS).append(SPACE);
- String outName = sSymbol.getOutputName();
- int lIndx = outName.lastIndexOf("."); //$NON-NLS-1$
- buffer.append(outName.substring(lIndx + 1)).append(SPACE);
- } else {
- append(sSymbol);
- }
- if (iter.hasNext())
- buffer.append(COMMA).append(SPACE);
- }
- }
-
-}
\ No newline at end of file
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-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/OracleSpatialSQLTranslator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -25,132 +25,113 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
+import com.metamatrix.connector.api.ConnectorEnvironment;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.ExecutionContext;
-import com.metamatrix.connector.jdbc.extension.SQLConversionVisitor;
-import com.metamatrix.connector.jdbc.oracle.OracleSQLTranslator;
+import com.metamatrix.connector.api.TypeFacility;
+import com.metamatrix.connector.jdbc.extension.SQLTranslator;
import com.metamatrix.connector.language.ICommand;
import com.metamatrix.connector.language.ICriteria;
import com.metamatrix.connector.language.IFunction;
import com.metamatrix.connector.language.IQuery;
import com.metamatrix.connector.language.ISelect;
+import com.metamatrix.connector.language.ISelectSymbol;
import com.metamatrix.connector.visitor.util.CollectorVisitor;
-public class OracleSpatialSQLTranslator extends OracleSQLTranslator {
+public class OracleSpatialSQLTranslator extends SQLTranslator {
- /**
- * This method is overridden to find function modifiers that modify functions in the
incoming command.
- */
- public Map getFunctionModifiers() {
- Map modifiers = super.getFunctionModifiers();
- Iterator iter = OracleSpatialFunctions.relateFunctions.iterator();
+ @Override
+ public void initialize(ConnectorEnvironment env) throws ConnectorException {
+ Iterator<String> iter = OracleSpatialFunctions.relateFunctions.iterator();
while (iter.hasNext()) {
- modifiers.put(iter.next(), new RelateFunctionModifier());
+ registerFunctionModifier(iter.next(), new RelateFunctionModifier());
}
iter = OracleSpatialFunctions.nearestNeighborFunctions.iterator();
while (iter.hasNext()) {
- modifiers.put(iter.next(), new NearestNeighborFunctionModifier());
+ registerFunctionModifier(iter.next(), new
NearestNeighborFunctionModifier());
}
iter = OracleSpatialFunctions.filterFunctions.iterator();
while (iter.hasNext()) {
- modifiers.put(iter.next(), new FilterFunctionModifier());
+ registerFunctionModifier(iter.next(), new FilterFunctionModifier());
}
iter = OracleSpatialFunctions.withinDistanceFunctions.iterator();
while (iter.hasNext()) {
- modifiers.put(iter.next(), new WithinDistanceFunctionModifier());
+ registerFunctionModifier(iter.next(), new WithinDistanceFunctionModifier());
}
iter = OracleSpatialFunctions.nnDistanceFunctions.iterator();
while (iter.hasNext()) {
- modifiers.put(iter.next(), new NnDistanceFunctionModifier());
+ registerFunctionModifier(iter.next(), new NnDistanceFunctionModifier());
}
- return modifiers;
}
/**
* This method is overridden to modify the incoming command to add the hint to the
ISelect in the command.
*/
-public ICommand modifyCommand(ICommand command, ExecutionContext context) throws
ConnectorException {
+ @Override
+ public ICommand modifyCommand(ICommand command,
com.metamatrix.connector.api.ExecutionContext context) throws ConnectorException {
if (command instanceof IQuery) {
IQuery query = (IQuery)command;
- String hint = getHint(query);
ISelect select = ((IQuery)command).getSelect();
- List symbols = select.getSelectSymbols();
- if(symbols.toString().indexOf("SDO_NN_DISTANCE") != -1){
//$NON-NLS-1$
- ICriteria criteria = query.getWhere();
- if(criteria != null &&
criteria.toString().indexOf("SDO_NN") == -1){ //$NON-NLS-1$
- throw(new ConnectorException(
-
Messages.getString("OracleSpatialSQLTranslator.SDO_NN_DEPENDENCY_ERROR")));
//$NON-NLS-1$
- }
- }
- /*Iterator iter = symbols.iterator();
- while(iter.hasNext()){
-
if(((ISelectSymbol)iter.next()).getExpression().compareToIgnoreCase("SDO_NN_DISTANCE")
!= 0){ //$NON-NLS-1$
+ List<ISelectSymbol> symbols = select.getSelectSymbols();
+
+ Collection<IFunction> functions =
CollectorVisitor.collectObjects(IFunction.class, select);
+ for (IFunction function : functions) {
+ if (function.getName().equalsIgnoreCase("SDO_NN_DISTANCE")) {//$NON-NLS-1$
ICriteria criteria = query.getWhere();
- if(criteria != null &&
criteria.toString().compareToIgnoreCase("SDO_NN") != 0){ //$NON-NLS-1$
- break;
- } else{
+ if(criteria == null ||
criteria.toString().indexOf("SDO_NN") == -1){ //$NON-NLS-1$
throw(new ConnectorException(
Messages.getString("OracleSpatialSQLTranslator.SDO_NN_DEPENDENCY_ERROR")));
//$NON-NLS-1$
}
- }
+ break;
+ }
+ }
+
+ for (int i = 0; i < symbols.size(); i++) {
+ ISelectSymbol symbol = symbols.get(i);
+ if (symbol.getExpression().getType().equals(Object.class)) {
+ String outName = symbol.getOutputName();
+ int lIndx = outName.lastIndexOf("."); //$NON-NLS-1$
+ symbol.setOutputName(outName.substring(lIndx + 1));
+ symbol.setExpression(getLanguageFactory().createLiteral(null,
TypeFacility.RUNTIME_TYPES.OBJECT));
+ symbol.setAlias(true);
+ }
}
- */
- if (hint != null) {
- SpatialSelectProxy proxy = new SpatialSelectProxy(select, hint);
- query.setSelect(proxy);
- }
}
return command;
}
- /**
- * This method is overridden to use a special variant of the SQL conversion visitor
so that the hint can be inserted into the
- * SQL.
- */
- public SQLConversionVisitor getTranslationVisitor() {
- OracleSpatialConversionVisitor visitor = new OracleSpatialConversionVisitor();
- visitor.setRuntimeMetadata(getRuntimeMetadata());
- visitor.setFunctionModifiers(getFunctionModifiers());
- visitor.setProperties(getConnectorEnvironment().getProperties());
- visitor.setLanguageFactory(getConnectorEnvironment().getLanguageFactory());
- return visitor;
- }
/**
* This method figures out what the hint is by looking at the query and returns it.
- *
* @param query
+ *
* @return The hint or null for no hint
*/
- private String getHint(IQuery query) {
- //
- // This simple algorithm determines the hint which will be added to the
- // query.
- // Right now, we look through all functions passed in the query
- // (returned as a collection)
- // Then we check if any of those functions contain the strings 'sdo' and
- // 'relate'
- // If so, the ORDERED hint is added, if not, it isn't
- Class iFunction = null;
- try {
- iFunction =
Class.forName("com.metamatrix.data.language.IFunction"); //$NON-NLS-1$
- } catch (ClassNotFoundException cex) {
- System.err.println("BML: IFunction Class Missing"); //$NON-NLS-1$
- }
- Collection col = CollectorVisitor.collectObjects(iFunction, query);
- Iterator it = col.iterator();
- while (it.hasNext()) {
- IFunction func = (IFunction)it.next();
- String funcName = func.getName().toUpperCase();
- int indx1 = funcName.indexOf("SDO"); //$NON-NLS-1$
- int indx2 = funcName.indexOf("RELATE"); //$NON-NLS-1$
- if (indx1 >= 0 && indx2 > indx1)
- return "/* + ORDERED */"; //$NON-NLS-1$
- }
- return " "; //$NON-NLS-1$
+ @Override
+ public String getSourceComment(ExecutionContext context, ICommand command) {
+ String comment = super.getSourceComment(context, command);
+
+ if (command instanceof IQuery) {
+ //
+ // This simple algorithm determines the hint which will be added to the
+ // query.
+ // Right now, we look through all functions passed in the query
+ // (returned as a collection)
+ // Then we check if any of those functions contain the strings 'sdo'
and
+ // 'relate'
+ // If so, the ORDERED hint is added, if not, it isn't
+ Collection<IFunction> col =
CollectorVisitor.collectObjects(IFunction.class, command);
+ for (IFunction func : col) {
+ String funcName = func.getName().toUpperCase();
+ int indx1 = funcName.indexOf("SDO"); //$NON-NLS-1$
+ int indx2 = funcName.indexOf("RELATE"); //$NON-NLS-1$
+ if (indx1 >= 0 && indx2 > indx1)
+ return comment + " /* + ORDERED */"; //$NON-NLS-1$
+ }
+ }
+ return comment; //$NON-NLS-1$
}
}
\ No newline at end of file
Deleted:
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/SpatialHint.java
===================================================================
---
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/SpatialHint.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/SpatialHint.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,31 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-/*
- * Created on Mar 23, 2004
- */
-package com.metamatrix.connector.jdbc.oracle.spatial;
-
-public interface SpatialHint {
-
- String getHint();
-}
\ No newline at end of file
Deleted:
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/SpatialSelectProxy.java
===================================================================
---
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/SpatialSelectProxy.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/connectors/sandbox/connector-oracle-spatial/src/main/java/com/metamatrix/connector/jdbc/oracle/spatial/SpatialSelectProxy.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,76 +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.
- */
-
-/*
- * Created on Mar 23, 2004
- */
-package com.metamatrix.connector.jdbc.oracle.spatial;
-
-import java.util.List;
-
-import com.metamatrix.connector.language.ISelect;
-import com.metamatrix.connector.visitor.framework.LanguageObjectVisitor;
-
-public class SpatialSelectProxy implements
- ISelect,
- SpatialHint {
-
- private ISelect delegate;
-
- private String hint;
-
- public SpatialSelectProxy(ISelect delegate,
- String hint) {
- this.delegate = delegate;
- this.hint = hint;
- }
-
- public List getSelectSymbols() {
- return this.delegate.getSelectSymbols();
- }
-
- public boolean isDistinct() {
- return this.delegate.isDistinct();
- }
-
- public void setSelectSymbols(List symbols) {
- this.delegate.setSelectSymbols(symbols);
- }
-
- public void setDistinct(boolean distinct) {
- this.setDistinct(distinct);
- }
-
- public String getHint() {
- return this.hint;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
com.metamatrix.data.language.ILanguageObject#acceptVisitor(com.metamatrix.data.visitor.framework.LanguageObjectVisitor)
- */
- public void acceptVisitor(LanguageObjectVisitor visitor) {
- visitor.visit(this);
- }
-
-}
\ No newline at end of file
Modified:
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/impl/TypeFacilityImpl.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/impl/TypeFacilityImpl.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/impl/TypeFacilityImpl.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -22,7 +22,12 @@
package com.metamatrix.dqp.internal.datamgr.impl;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+
import com.metamatrix.common.types.*;
+import com.metamatrix.common.util.TimestampWithTimezone;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.api.TypeFacility;
@@ -49,5 +54,11 @@
public Object convertToRuntimeType(Object value) {
return DataTypeManager.convertToRuntimeType(value);
}
+
+ @Override
+ public Object convertDate(Date date, TimeZone initial, Calendar target,
+ Class targetType) {
+ return TimestampWithTimezone.create(date, initial, target, targetType);
+ }
}
Modified:
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/BaseLanguageObject.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/BaseLanguageObject.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/BaseLanguageObject.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -36,7 +36,7 @@
}
public String toString() {
- return SQLStringVisitor.getSQLString(this, null);
+ return SQLStringVisitor.getSQLString(this);
}
}
Deleted:
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/CaseExpressionImpl.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/CaseExpressionImpl.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/CaseExpressionImpl.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -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.dqp.internal.datamgr.language;
-
-import java.util.List;
-
-import com.metamatrix.connector.language.ICaseExpression;
-import com.metamatrix.connector.language.IExpression;
-import com.metamatrix.connector.visitor.framework.LanguageObjectVisitor;
-
-public class CaseExpressionImpl extends BaseLanguageObject implements ICaseExpression {
-
- private IExpression expression = null;
- private List whenExpressions = null;
- private List thenExpressions = null;
- private IExpression elseExpression = null;
- private Class type = null;
-
- public CaseExpressionImpl(IExpression expression,
- List whens, List thens, IExpression elseExpression,
- Class type) {
-
- this.expression = expression;
- this.whenExpressions = whens;
- this.thenExpressions = thens;
- this.elseExpression = elseExpression;
- this.type = type;
- }
- /**
- * @see com.metamatrix.connector.language.ICaseExpression#getElseExpression()
- */
- public IExpression getElseExpression() {
- return elseExpression;
- }
-
- /**
- * @see com.metamatrix.connector.language.ICaseExpression#getExpression()
- */
- public IExpression getExpression() {
- return expression;
- }
-
- /**
- * @see com.metamatrix.connector.language.ICaseExpression#getThenExpression(int)
- */
- public IExpression getThenExpression(int index) {
- return (IExpression)thenExpressions.get(index);
- }
-
- /**
- * @see com.metamatrix.connector.language.ICaseExpression#getWhenCount()
- */
- public int getWhenCount() {
- return whenExpressions.size();
- }
-
- /**
- * @see com.metamatrix.connector.language.ICaseExpression#getWhenExpression(int)
- */
- public IExpression getWhenExpression(int index) {
- return (IExpression)whenExpressions.get(index);
- }
-
- /**
- * @see
com.metamatrix.connector.language.ILanguageObject#acceptVisitor(com.metamatrix.data.visitor.LanguageObjectVisitor)
- */
- public void acceptVisitor(LanguageObjectVisitor visitor) {
- visitor.visit(this);
- }
- /*
- * @see
com.metamatrix.data.language.ICaseExpression#setExpression(com.metamatrix.data.language.IExpression)
- */
- public void setExpression(IExpression expression) {
- this.expression = expression;
- }
- /*
- * @see com.metamatrix.data.language.ICaseExpression#setWhenExpression(int,
com.metamatrix.data.language.IExpression)
- */
- public void setWhenExpression(int index, IExpression expression) {
- this.whenExpressions.set(index, expression);
- }
-
- /*
- * @see com.metamatrix.data.language.ICaseExpression#setThenExpression(int,
com.metamatrix.data.language.IExpression)
- */
- public void setThenExpression(int index, IExpression expression) {
- this.thenExpressions.set(index, expression);
- }
-
- /*
- * @see
com.metamatrix.data.language.ICaseExpression#setElseExpression(com.metamatrix.data.language.IExpression)
- */
- public void setElseExpression(IExpression expression) {
- this.elseExpression = expression;
- }
-
- /*
- * @see com.metamatrix.data.language.IExpression#getType()
- */
- public Class getType() {
- return this.type;
- }
- /*
- * @see com.metamatrix.data.language.IExpression#setType(java.lang.Class)
- */
- public void setType(Class type) {
- this.type = type;
- }
-
-}
Modified:
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/LanguageBridgeFactory.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/LanguageBridgeFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/LanguageBridgeFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -31,7 +31,6 @@
import com.metamatrix.common.log.LogManager;
import com.metamatrix.connector.language.IAggregate;
import com.metamatrix.connector.language.IBatchedUpdates;
-import com.metamatrix.connector.language.ICaseExpression;
import com.metamatrix.connector.language.ICommand;
import com.metamatrix.connector.language.ICompareCriteria;
import com.metamatrix.connector.language.ICompoundCriteria;
@@ -71,6 +70,7 @@
import com.metamatrix.connector.language.IParameter.Direction;
import com.metamatrix.connector.language.ISubqueryCompareCriteria.Quantifier;
import com.metamatrix.connector.metadata.runtime.MetadataID;
+import com.metamatrix.connector.metadata.runtime.MetadataID.Type;
import com.metamatrix.dqp.DQPPlugin;
import com.metamatrix.dqp.internal.datamgr.metadata.MetadataFactory;
import com.metamatrix.dqp.internal.datamgr.metadata.ProcedureIDImpl;
@@ -483,19 +483,6 @@
return null;
}
- ICaseExpression translate(CaseExpression expr) throws MetaMatrixComponentException {
- ArrayList whens = new ArrayList();
- ArrayList thens = new ArrayList();
- for (int i = 0; i < expr.getWhenCount(); i++) {
- whens.add(translate(expr.getWhenExpression(i)));
- thens.add(translate(expr.getThenExpression(i)));
- }
- return new CaseExpressionImpl(translate(expr.getExpression()),
- whens,
- thens,
- translate(expr.getElseExpression()),
expr.getType());
- }
-
ILiteral translate(Constant constant) {
return new LiteralImpl(constant.getValue(), constant.getType());
}
@@ -563,7 +550,7 @@
if(! (mid instanceof TempMetadataID)) {
try {
- element.setMetadataID(metadataFactory.createMetadataID(mid,
MetadataID.TYPE_ELEMENT));
+ element.setMetadataID(metadataFactory.createMetadataID(mid,
Type.TYPE_ELEMENT));
} catch(QueryMetadataException e) {
LogManager.logWarning(LogConstants.CTX_CONNECTOR, e,
DQPPlugin.Util.getString("LanguageBridgeFactory.Unable_to_set_the_metadata_ID_for_element_{0}._10",
symbol.getName())); //$NON-NLS-1$
throw new MetaMatrixComponentException(e);
@@ -700,7 +687,7 @@
return group;
}
try {
- group.setMetadataID(metadataFactory.createMetadataID(symbol.getMetadataID(),
MetadataID.TYPE_GROUP));
+ group.setMetadataID(metadataFactory.createMetadataID(symbol.getMetadataID(),
Type.TYPE_GROUP));
} catch(Exception e) {
LogManager.logWarning(LogConstants.CTX_CONNECTOR, e,
DQPPlugin.Util.getString("LanguageBridgeFactory.Unable_to_set_the_metadata_ID_for_group_{0}._11",
symbol.getName())); //$NON-NLS-1$
throw new MetaMatrixComponentException(e);
Modified:
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/LanguageFactoryImpl.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/LanguageFactoryImpl.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/LanguageFactoryImpl.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -46,18 +46,6 @@
}
/*
- * @see
com.metamatrix.data.language.ILanguageFactory#createCaseExpression(com.metamatrix.data.language.IExpression,
java.util.List, java.util.List, com.metamatrix.data.language.IExpression,
java.lang.Class)
- */
- public ICaseExpression createCaseExpression(
- IExpression mainExpression,
- List whenExpressions,
- List thenExpressions,
- IExpression elseExpression,
- Class type) {
- return new CaseExpressionImpl(mainExpression, whenExpressions, thenExpressions,
elseExpression, type);
- }
-
- /*
* @see com.metamatrix.data.language.ILanguageFactory#createCompareCriteria(int,
com.metamatrix.data.language.IExpression, com.metamatrix.data.language.IExpression)
*/
public ICompareCriteria createCompareCriteria(
Modified:
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/MetadataFactory.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/MetadataFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/MetadataFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -30,6 +30,7 @@
import com.metamatrix.api.exception.query.QueryMetadataException;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.metadata.runtime.*;
+import com.metamatrix.connector.metadata.runtime.MetadataID.Type;
import com.metamatrix.core.util.ArgCheck;
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.metadata.StoredProcedureInfo;
@@ -38,14 +39,16 @@
*/
public class MetadataFactory {
private QueryMetadataInterface metadata;
+ private RuntimeMetadataImpl runtimeMetadata;
public MetadataFactory (QueryMetadataInterface metadata){
ArgCheck.isNotNull(metadata);
this.metadata = metadata;
+ this.runtimeMetadata = new RuntimeMetadataImpl(this);
}
- public RuntimeMetadata createRuntimeMetadata(){
- return new RuntimeMetadataImpl(this);
+ public RuntimeMetadataImpl getRuntimeMetadata(){
+ return this.runtimeMetadata;
}
/**
@@ -56,11 +59,11 @@
* @throws QueryMetadataException
* @throws MetaMatrixComponentException
*/
- public MetadataID createMetadataID(Object metadataID, int type) throws
QueryMetadataException, MetaMatrixComponentException{
- if (type == MetadataID.TYPE_GROUP && metadata.isVirtualGroup(metadataID)) {
+ public MetadataID createMetadataID(Object metadataID, Type type) throws
QueryMetadataException, MetaMatrixComponentException{
+ if (type == Type.TYPE_GROUP && metadata.isVirtualGroup(metadataID)) {
return null;
}
- MetadataIDImpl id = new MetadataIDImpl(metadataID, metadata);
+ MetadataIDImpl id = new MetadataIDImpl(metadataID, getRuntimeMetadata());
id.setType(type);
return id;
}
@@ -75,8 +78,8 @@
public MetadataID createProcedureID(Object metadataID) throws QueryMetadataException,
MetaMatrixComponentException{
String procName = metadata.getFullName(metadataID);
StoredProcedureInfo info = metadata.getStoredProcedureInfoForProcedure(procName);
- MetadataIDImpl id = new ProcedureIDImpl(metadataID, info, this, metadata);
- id.setType(MetadataID.TYPE_PROCEDURE);
+ MetadataIDImpl id = new ProcedureIDImpl(metadataID, info, this);
+ id.setType(Type.TYPE_PROCEDURE);
return id;
}
@@ -88,8 +91,8 @@
* @throws MetaMatrixComponentException
*/
public MetadataID createParameterID(ProcedureIDImpl procedureID, Object metadataID)
throws QueryMetadataException, MetaMatrixComponentException{
- ParameterIDImpl id = new ParameterIDImpl(metadataID, procedureID, metadata);
- id.setType(MetadataID.TYPE_PARAMETER);
+ ParameterIDImpl id = new ParameterIDImpl(metadataID, procedureID,
getRuntimeMetadata());
+ id.setType(Type.TYPE_PARAMETER);
return id;
}
@@ -101,25 +104,25 @@
* @throws MetaMatrixComponentException
*/
public MetadataID createResultSetID(ProcedureIDImpl procedureID, Object metadataID,
List resultSetColumns) throws QueryMetadataException, MetaMatrixComponentException{
- ParameterIDImpl id = new ParameterIDImpl(metadataID, procedureID, metadata,
resultSetColumns);
- id.setType(MetadataID.TYPE_PARAMETER);
+ ParameterIDImpl id = new ParameterIDImpl(metadataID, procedureID,
getRuntimeMetadata(), resultSetColumns);
+ id.setType(Type.TYPE_PARAMETER);
return id;
}
public MetadataObject createMetadataObject(MetadataID id) throws
QueryMetadataException, MetaMatrixComponentException, ConnectorException {
- int type = id.getType();
+ Type type = id.getType();
MetadataIDImpl idImpl = (MetadataIDImpl) id;
MetadataObject mObj = null;
- if(type == MetadataID.TYPE_GROUP){
+ if(type == Type.TYPE_GROUP){
mObj = new GroupImpl(idImpl);
- } else if(type == MetadataID.TYPE_ELEMENT){
+ } else if(type == Type.TYPE_ELEMENT){
mObj = new ElementImpl(idImpl);
- } else if(type == MetadataID.TYPE_PROCEDURE){
+ } else if(type == Type.TYPE_PROCEDURE){
mObj = new ProcedureImpl(idImpl);
- } else if(type == MetadataID.TYPE_PARAMETER) {
+ } else if(type == Type.TYPE_PARAMETER) {
mObj = new ParameterImpl(idImpl);
} else{
@@ -139,4 +142,8 @@
public String[] getVDBResourcePaths() throws MetaMatrixComponentException,
QueryMetadataException {
return metadata.getVDBResourcePaths();
}
+
+ public QueryMetadataInterface getMetadata() {
+ return metadata;
+ }
}
Modified:
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/MetadataIDImpl.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/MetadataIDImpl.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/MetadataIDImpl.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -24,50 +24,55 @@
*/
package com.metamatrix.dqp.internal.datamgr.metadata;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.query.QueryMetadataException;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.metadata.runtime.MetadataID;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
+import com.metamatrix.connector.metadata.runtime.MetadataObject;
/**
*/
public class MetadataIDImpl implements MetadataID {
- private int type;
+ private Type type;
private Object actualMetadataID;
private String fullName;
- private QueryMetadataInterface metadata;
+ private RuntimeMetadataImpl metadata;
- MetadataIDImpl(Object actualMetadataID, QueryMetadataInterface metadata) throws
MetaMatrixComponentException {
+ MetadataIDImpl(Object actualMetadataID, RuntimeMetadataImpl metadata) throws
MetaMatrixComponentException {
this.actualMetadataID = actualMetadataID;
this.metadata = metadata;
- try {
- fullName = metadata.getFullName(getActualMetadataID());
- } catch (QueryMetadataException ex) {
- throw new MetaMatrixComponentException(ex, ex.getMessage());
+ if (actualMetadataID != null) {
+ try {
+ fullName = metadata.getMetadata().getFullName(actualMetadataID);
+ } catch (QueryMetadataException ex) {
+ throw new MetaMatrixComponentException(ex, ex.getMessage());
+ }
}
}
- QueryMetadataInterface getMetadata() {
+ RuntimeMetadataImpl getMetadata() {
return this.metadata;
}
- public int getType() {
+ public Type getType() {
return type;
}
public List getChildIDs() throws ConnectorException {
- if(type == MetadataID.TYPE_GROUP){
+ if(type == Type.TYPE_GROUP && actualMetadataID != null){
try {
- List children = metadata.getElementIDsInGroupID(actualMetadataID);
+ List children =
metadata.getMetadata().getElementIDsInGroupID(actualMetadataID);
List childIDs = new ArrayList(children.size());
Iterator iter = children.iterator();
while(iter.hasNext()){
MetadataIDImpl id = new MetadataIDImpl(iter.next(), metadata);
- id.setType(MetadataID.TYPE_ELEMENT);
+ id.setType(Type.TYPE_ELEMENT);
childIDs.add(id);
}
return childIDs;
@@ -81,10 +86,10 @@
}
public MetadataID getParentID() throws ConnectorException {
- if(type == MetadataID.TYPE_ELEMENT) {
+ if(type == Type.TYPE_ELEMENT && actualMetadataID != null) {
try {
- MetadataIDImpl id = new
MetadataIDImpl(metadata.getGroupIDForElementID(actualMetadataID), metadata);
- id.setType(MetadataID.TYPE_GROUP);
+ MetadataIDImpl id = new
MetadataIDImpl(metadata.getMetadata().getGroupIDForElementID(actualMetadataID),
metadata);
+ id.setType(Type.TYPE_GROUP);
return id;
} catch(QueryMetadataException e) {
throw new ConnectorException(e);
@@ -113,7 +118,7 @@
return actualMetadataID.hashCode();
}
- void setType(int type){
+ void setType(Type type){
this.type = type;
}
@@ -142,4 +147,9 @@
}
return shortName;
}
+
+ @Override
+ public MetadataObject getMetadataObject() throws ConnectorException {
+ return this.metadata.getObject(this);
+ }
}
Modified:
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/MetadataObjectImpl.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/MetadataObjectImpl.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/MetadataObjectImpl.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -51,7 +51,7 @@
}
QueryMetadataInterface getMetadata() {
- return metadataID.getMetadata();
+ return metadataID.getMetadata().getMetadata();
}
public String getNameInSource() throws ConnectorException {
Modified:
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/ParameterIDImpl.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/ParameterIDImpl.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/ParameterIDImpl.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -22,12 +22,14 @@
package com.metamatrix.dqp.internal.datamgr.metadata;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.metadata.runtime.MetadataID;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
/**
*/
@@ -36,14 +38,14 @@
private ProcedureIDImpl procID;
private List resultSetColumns;
- public ParameterIDImpl(Object actualMetadataID, ProcedureIDImpl procedureID,
QueryMetadataInterface metadata)
+ public ParameterIDImpl(Object actualMetadataID, ProcedureIDImpl procedureID,
RuntimeMetadataImpl metadata)
throws MetaMatrixComponentException {
super(actualMetadataID, metadata);
this.procID = procedureID;
}
- public ParameterIDImpl(Object actualMetadataID, ProcedureIDImpl procedureID,
QueryMetadataInterface metadata, List resultSetColumns)
+ public ParameterIDImpl(Object actualMetadataID, ProcedureIDImpl procedureID,
RuntimeMetadataImpl metadata, List resultSetColumns)
throws MetaMatrixComponentException {
super(actualMetadataID, metadata);
@@ -67,7 +69,7 @@
while(iter.hasNext()){
Object colID = iter.next();
MetadataIDImpl id = new MetadataIDImpl(colID, getMetadata());
- id.setType(MetadataID.TYPE_ELEMENT);
+ id.setType(Type.TYPE_ELEMENT);
childIDs.add(id);
}
return childIDs;
Modified:
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/ProcedureIDImpl.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/ProcedureIDImpl.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/ProcedureIDImpl.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -22,13 +22,14 @@
package com.metamatrix.dqp.internal.datamgr.metadata;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.query.QueryMetadataException;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.dqp.message.ParameterInfo;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.metadata.StoredProcedureInfo;
import com.metamatrix.query.sql.lang.SPParameter;
@@ -44,10 +45,10 @@
* @param metadata
* @throws MetaMatrixComponentException
*/
- public ProcedureIDImpl(Object actualMetadataID, StoredProcedureInfo procInfo,
MetadataFactory factory, QueryMetadataInterface metadata)
+ public ProcedureIDImpl(Object actualMetadataID, StoredProcedureInfo procInfo,
MetadataFactory factory)
throws MetaMatrixComponentException {
- super(actualMetadataID, metadata);
+ super(actualMetadataID, factory.getRuntimeMetadata());
this.procInfo = procInfo;
this.factory = factory;
}
Modified:
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/RuntimeMetadataImpl.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/RuntimeMetadataImpl.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/metadata/RuntimeMetadataImpl.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -28,6 +28,7 @@
import com.metamatrix.api.exception.query.QueryMetadataException;
import com.metamatrix.connector.api.ConnectorException;
import com.metamatrix.connector.metadata.runtime.*;
+import com.metamatrix.query.metadata.QueryMetadataInterface;
/**
*/
@@ -78,4 +79,9 @@
throw new ConnectorException(e);
}
}
+
+ QueryMetadataInterface getMetadata() {
+ return this.factory.getMetadata();
+ }
+
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/function/FunctionLibrary.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/function/FunctionLibrary.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/main/java/com/metamatrix/query/function/FunctionLibrary.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -83,6 +83,8 @@
public static final String NULLIF = "nullif"; //$NON-NLS-1$
public static final String COALESCE = "coalesce"; //$NON-NLS-1$
+ public static final String SPACE = "space"; //$NON-NLS-1$
+
// Function tree for system functions (never reloaded)
private FunctionTree systemFunctions;
Modified: trunk/engine/src/main/java/com/metamatrix/query/function/FunctionMethods.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/function/FunctionMethods.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/main/java/com/metamatrix/query/function/FunctionMethods.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -33,13 +33,11 @@
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;
-import java.util.StringTokenizer;
import java.util.TimeZone;
import com.metamatrix.api.exception.query.ExpressionEvaluationException;
import com.metamatrix.api.exception.query.FunctionExecutionException;
import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.Transform;
import com.metamatrix.common.types.TransformationException;
import com.metamatrix.common.util.TimestampWithTimezone;
import com.metamatrix.query.QueryPlugin;
@@ -49,8 +47,6 @@
public final class FunctionMethods {
- private static final String DEFAULT_DECODE_STRING_DELIMITER = ",";
//$NON-NLS-1$
-
// ================== Function = plus =====================
public static Object plus(Object x, Object y) throws FunctionExecutionException {
@@ -1206,10 +1202,12 @@
int repeatCount = ((Integer) count).intValue();
StringBuffer result = new StringBuffer();
- for (int i = 0; i < repeatCount; i++) {
+ for (int i = 0; i < repeatCount && result.length() <=
DataTypeManager.MAX_STRING_LENGTH; i++) {
result.append((String)str);
}
-
+ if (result.length() > DataTypeManager.MAX_STRING_LENGTH) {
+ return result.substring(0, DataTypeManager.MAX_STRING_LENGTH);
+ }
return result.toString();
}
@@ -1217,26 +1215,6 @@
new Object[] {"repeat", str.getClass().getName(),
count.getClass().getName()})); //$NON-NLS-1$
}
- // ================== Function = space =====================
- public static Object space(Object count)
- throws FunctionExecutionException {
- if (count == null) {
- return null;
- } else if (count instanceof Integer) {
- int repeatCount = ((Integer) count).intValue();
- StringBuffer result = new StringBuffer();
-
- for (int i = 0; i < repeatCount; i++) {
- result.append(" "); //$NON-NLS-1$
- }
-
- return result.toString();
- }
-
- throw new FunctionExecutionException(ErrorMessageKeys.FUNCTION_0066,
QueryPlugin.Util.getString(ErrorMessageKeys.FUNCTION_0066,
- new Object[] {"space", count.getClass().getName()})); //$NON-NLS-1$
- }
-
// ================== Function = ascii =====================
public static Object ascii(Object ch)
@@ -1309,46 +1287,53 @@
// ================== Function = lpad =====================
- public static Object lpad(Object inputString, Object padLength, Object padChar)
+ public static Object lpad(Object inputString, Object padLength, Object padStr)
throws FunctionExecutionException {
- if(inputString == null || padLength == null || padChar == null) {
- return null;
- }
+ return pad(inputString, padLength, padStr, true);
+ }
- String str = (String) inputString;
- int length = ((Integer)padLength).intValue();
- if(length < 1) {
- throw new FunctionExecutionException(ErrorMessageKeys.FUNCTION_0025,
QueryPlugin.Util.getString(ErrorMessageKeys.FUNCTION_0025));
- }
+ public static Object pad(Object inputString, Object padLength, Object padStr, boolean
left)
+ throws FunctionExecutionException {
- int numPadChar = length - str.length();
- if(numPadChar <= 0) {
- return str;
- }
- // Get pad character
- char ch = 0;
- if(padChar instanceof String) {
- String charStr = (String) padChar;
- if(charStr.length() != 1) {
- throw new FunctionExecutionException(ErrorMessageKeys.FUNCTION_0027,
QueryPlugin.Util.getString(ErrorMessageKeys.FUNCTION_0027));
- }
- ch = charStr.charAt(0);
- } else {
- ch = ((Character)padChar).charValue();
- }
+ if(inputString == null || padLength == null || padStr == null) {
+ return null;
+ }
+
+ String str = (String) inputString;
+ int length = ((Integer)padLength).intValue();
+ if(length < 1) {
+ throw new FunctionExecutionException(ErrorMessageKeys.FUNCTION_0025,
QueryPlugin.Util.getString(ErrorMessageKeys.FUNCTION_0025));
+ }
+ if(length < str.length()) {
+ return str.substring(0, length);
+ }
+ if(length > DataTypeManager.MAX_STRING_LENGTH) {
+ length = DataTypeManager.MAX_STRING_LENGTH;
+ }
+ // Get pad character
+ String pad = (String) padStr;
+ if(pad.length() == 0) {
+ throw new FunctionExecutionException(ErrorMessageKeys.FUNCTION_0027,
QueryPlugin.Util.getString(ErrorMessageKeys.FUNCTION_0027));
+ }
+ // Pad string
+ StringBuffer outStr = new StringBuffer(str);
+ while(outStr.length() < length) {
+ if (left) {
+ outStr.insert(0, pad);
+ } else {
+ outStr.append(pad);
+ }
+ }
+ if (left) {
+ return outStr.substring(outStr.length() - length);
+ }
+ return outStr.substring(0, length);
+ }
- // Pad string
- StringBuffer outStr = new StringBuffer();
- for(int i=0; i<numPadChar; i++) {
- outStr.append(ch);
- }
- outStr.append(str);
- return outStr.toString();
- }
+
+ public static final String SPACE_CHAR = " "; //$NON-NLS-1$
- public static final Character SPACE_CHAR = new Character(' ');
-
public static Object lpad(Object inputString, Object padLength)
throws FunctionExecutionException {
@@ -1357,42 +1342,10 @@
// ================== Function = rpad =====================
- public static Object rpad(Object inputString, Object padLength, Object padChar)
+ public static Object rpad(Object inputString, Object padLength, Object padStr)
throws FunctionExecutionException {
- if(inputString == null || padLength == null || padChar == null) {
- return null;
- }
-
- String str = (String) inputString;
- int length = ((Integer)padLength).intValue();
- if(length < 1) {
- throw new FunctionExecutionException(ErrorMessageKeys.FUNCTION_0025,
QueryPlugin.Util.getString(ErrorMessageKeys.FUNCTION_0025));
- }
-
- int numPadChar = length - str.length();
- if(numPadChar <= 0) {
- return str;
- }
- // Get pad character
- char ch = 0;
- if(padChar instanceof String) {
- String charStr = (String) padChar;
- if(charStr.length() != 1) {
- throw new FunctionExecutionException(ErrorMessageKeys.FUNCTION_0029,
QueryPlugin.Util.getString(ErrorMessageKeys.FUNCTION_0029));
- }
- ch = charStr.charAt(0);
- } else {
- ch = ((Character)padChar).charValue();
- }
-
- // Pad string
- StringBuffer outStr = new StringBuffer();
- outStr.append(str);
- for(int i=0; i<numPadChar; i++) {
- outStr.append(ch);
- }
- return outStr.toString();
+ return pad(inputString, padLength, padStr, false);
}
public static Object rpad(Object inputString, Object padLength)
@@ -1520,246 +1473,9 @@
throw new UnsupportedOperationException("This method should never be
called."); //$NON-NLS-1$
}
- // ================== Function = decodeInteger =====================
-
- public static Object decodeInteger(
- Object columnValue,
- Object decodeObject)
- throws FunctionExecutionException {
- return decode(
- columnValue,
- decodeObject,
- DEFAULT_DECODE_STRING_DELIMITER,
- Integer.class);
- }
-
- public static Object decodeString(
- Object columnValue,
- Object decodeObject)
- throws FunctionExecutionException {
- return decode(
- columnValue,
- decodeObject,
- DEFAULT_DECODE_STRING_DELIMITER,
- String.class);
- }
-
- public static Object decodeInteger(
- Object columnValue,
- Object decodeObject,
- Object decodeDelimiter)
- throws FunctionExecutionException {
- return decode(
- columnValue,
- decodeObject,
- decodeDelimiter,
- Integer.class);
- }
-
- public static Object decodeString(
- Object columnValue,
- Object decodeObject,
- Object decodeDelimiter)
- throws FunctionExecutionException {
-
- return decode(columnValue, decodeObject, decodeDelimiter, String.class);
-
- }
-
- private static Object decode(
- Object columnValue,
- Object decodeObject,
- Object decodeDelimiter,
- Class returnType)
- throws FunctionExecutionException {
-
- Object returnObject = null;
-
- if (decodeObject == null) {
- throw new FunctionExecutionException(ErrorMessageKeys.FUNCTION_0036,
QueryPlugin.Util.getString(ErrorMessageKeys.FUNCTION_0036));
- }
-
- if(decodeDelimiter==null){
- throw new FunctionExecutionException(ErrorMessageKeys.FUNCTION_0037,
QueryPlugin.Util.getString(ErrorMessageKeys.FUNCTION_0037));
- }
-
- if (decodeObject instanceof String
- && decodeDelimiter instanceof String) {
-
- String decodeDelimiterString = (String) decodeDelimiter;
- String decodeString = (String) decodeObject;
- StringTokenizer tokenizer =
- new StringTokenizer(decodeString, decodeDelimiterString);
-
- while (tokenizer.hasMoreTokens()) {
- String resultString;
- String compareString =
- convertString(tokenizer.nextToken().trim());
- if (tokenizer.hasMoreTokens()) {
- resultString = convertString(tokenizer.nextToken().trim());
- } else {
- /*
- * if there are no more tokens in the decode string, the last token
in
- * the String is considered to be the 'default' value for
the
- * return from this function. If we reach this point in this loop,
then
- * we just return this string as the return value from this function
as
- * there are no more decode compare strings to be processed.
- */
- try {
- returnObject =
- convertType(returnType, compareString);
- } catch (TransformationException e) {
- throw new FunctionExecutionException(e,
ErrorMessageKeys.FUNCTION_0038, QueryPlugin.Util.getString(ErrorMessageKeys.FUNCTION_0038,
compareString, returnType!=null?returnType.getName():"null")); //$NON-NLS-1$
- }
-
- // we break out of the while if we find an endpoint.
- break;
-
- }
-
- boolean match;
-
- match = areSemanticallyEqual(columnValue, compareString);
-
- if (match) {
- try {
- returnObject = convertType(returnType, resultString);
- } catch (TransformationException e) {
- throw new FunctionExecutionException(e,
ErrorMessageKeys.FUNCTION_0038, QueryPlugin.Util.getString(ErrorMessageKeys.FUNCTION_0038,
resultString, returnType!=null?returnType.getName():"null")); //$NON-NLS-1$
- }
- break;
- }else if (!tokenizer.hasMoreTokens()) {
- /*
- * if we get to this point and there are no more tokens in the
- * decode string, this means that we have run out of strings to
- * compare against the column value. In this case we simply return
- * the column value itself. We are safe doing that here because
- * this loop will be exited and the specified default value will
have
- * already been returned if there is one.
- */
- try {
- returnObject = convertType(returnType, columnValue);
- } catch (TransformationException e) {
- throw new FunctionExecutionException(e,
ErrorMessageKeys.FUNCTION_0039, QueryPlugin.Util.getString(ErrorMessageKeys.FUNCTION_0039,
columnValue ));
- }
- }
-
- }
-
- return returnObject;
-
- }
- throw new FunctionExecutionException(ErrorMessageKeys.FUNCTION_0040,
QueryPlugin.Util.getString(ErrorMessageKeys.FUNCTION_0040));
- }
-
- private static boolean areSemanticallyEqual(Object object1, String string){
- if(object1==null) {
- if(string==null) {
- return true;
- }
- return false;
- }
- if(string == null) {
- return false;
- } else if(object1.equals(string)) {
- return true;
- }
-
- Class targetClass = object1.getClass();
-
- if(DataTypeManager.isTransformable(String.class, targetClass)){
- Transform transform =
- DataTypeManager.getPreferredTransform(String.class, targetClass);
- Object result = null;
- try {
- if (transform.getSourceType().equals(String.class)) {
- result = transform.transform(string);
- } else {
- result = transform.transform(object1);
- }
- } catch (TransformationException e) {
- /* if the attempt to convert the types to be compatible so that
- * they can be propertly compared fails, then we consider these
- * two objects to be not semantically equal.
- */
- return false;
- }
- return result.equals(object1);
- }
- return false;
- }
-
- private static Object convertType(Class targetType, Object objectToConvert)
- throws TransformationException, FunctionExecutionException {
-
- if(objectToConvert==null){
- return null;
- }
-
- if(targetType==objectToConvert.getClass()){
- return objectToConvert;
- }
-
- Transform transform = null;
- if(DataTypeManager.isTransformable(targetType, objectToConvert.getClass())){
- transform =
- DataTypeManager.getTransform(
- objectToConvert.getClass(),
- targetType);
- }else{
- throw new FunctionExecutionException(ErrorMessageKeys.FUNCTION_0041,
QueryPlugin.Util.getString(ErrorMessageKeys.FUNCTION_0041, new Object[]{objectToConvert,
objectToConvert.getClass().getName(), targetType.getName()}));
- }
- return transform.transform(objectToConvert);
- }
-
- public static String convertString(String string) {
- /*
- * if there are no characters in the compare string we designate that as
- * an indication of null. ie if the decode string looks like this:
- *
- * "'this', 1,,'null'"
- *
- * Then if the value in the first argument is null then the String 'null'
is
- * returned from the function.
- */
- if (string.equals("")) { //$NON-NLS-1$
- return null;
- }
-
- /*
- * we also allow the use of the keyword null in the decode string. if it
- * wished to match on the string 'null' then the string must be qualified
by
- * ' designators.
- */
- if(string.equalsIgnoreCase("null")){ //$NON-NLS-1$
- return null;
- }
-
- /*
- * Here we check to see if the String in the decode String submitted
- * was surrounded by String literal characters. In this case we strip
- * these literal characters from the String.
- */
- if ((string.startsWith("\"") &&
string.endsWith("\"")) //$NON-NLS-1$ //$NON-NLS-2$
- || (string.startsWith("'") &&
string.endsWith("'"))) { //$NON-NLS-1$ //$NON-NLS-2$
- if (string.length() == 2) {
- /*
- * This is an indication that the desired string to be compared is
- * the "" empty string, so we return it as such.
- */
- string = ""; //$NON-NLS-1$
- } else if (!string.equalsIgnoreCase("'") &&
!string.equalsIgnoreCase("\"")){ //$NON-NLS-1$ //$NON-NLS-2$
- string = string.substring(1);
- string = string.substring(0, string.length()-1);
- }
- }
-
- return string;
- }
-
// ================== Function = nvl =====================
- public static Object nvl(Object value, Object valueIfNull) {
+ public static Object ifnull(Object value, Object valueIfNull) {
if(value == null) {
return valueIfNull;
Modified:
trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -29,6 +29,7 @@
import java.util.List;
import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.connector.api.SourceSystemFunctions;
import com.metamatrix.query.QueryPlugin;
import com.metamatrix.query.function.FunctionLibrary;
import com.metamatrix.query.function.FunctionMetadataSource;
@@ -56,10 +57,10 @@
*/
public SystemSource() {
// +, -, *, /
- addArithmeticFunction("+",
QueryPlugin.Util.getString("SystemSource.Add_desc"), "plus",
QueryPlugin.Util.getString("SystemSource.Add_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- addArithmeticFunction("-",
QueryPlugin.Util.getString("SystemSource.Subtract_desc"), "minus",
QueryPlugin.Util.getString("SystemSource.Subtract_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- addArithmeticFunction("*",
QueryPlugin.Util.getString("SystemSource.Multiply_desc"), "multiply",
QueryPlugin.Util.getString("SystemSource.Multiply_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- addArithmeticFunction("/",
QueryPlugin.Util.getString("SystemSource.Divide_desc"), "divide",
QueryPlugin.Util.getString("SystemSource.Divide_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ addArithmeticFunction(SourceSystemFunctions.ADD_OP,
QueryPlugin.Util.getString("SystemSource.Add_desc"), "plus",
QueryPlugin.Util.getString("SystemSource.Add_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ addArithmeticFunction(SourceSystemFunctions.SUBTRACT_OP,
QueryPlugin.Util.getString("SystemSource.Subtract_desc"), "minus",
QueryPlugin.Util.getString("SystemSource.Subtract_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ addArithmeticFunction(SourceSystemFunctions.MULTIPLY_OP,
QueryPlugin.Util.getString("SystemSource.Multiply_desc"), "multiply",
QueryPlugin.Util.getString("SystemSource.Multiply_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ addArithmeticFunction(SourceSystemFunctions.DIVIDE_OP,
QueryPlugin.Util.getString("SystemSource.Divide_desc"), "divide",
QueryPlugin.Util.getString("SystemSource.Divide_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
// numeric
addAbsFunction();
@@ -69,45 +70,45 @@
addRoundFunction();
addSignFunction();
addSqrtFunction();
- addDoubleFunction("acos",
QueryPlugin.Util.getString("SystemSource.Acos_desc")); //$NON-NLS-1$
//$NON-NLS-2$
- addDoubleFunction("asin",
QueryPlugin.Util.getString("SystemSource.Asin_desc")); //$NON-NLS-1$
//$NON-NLS-2$
- addDoubleFunction("atan",
QueryPlugin.Util.getString("SystemSource.Atan_desc")); //$NON-NLS-1$
//$NON-NLS-2$
- addAtan2Function("atan2",
QueryPlugin.Util.getString("SystemSource.Atan2_desc")); //$NON-NLS-1$
//$NON-NLS-2$
- addDoubleFunction("cos",
QueryPlugin.Util.getString("SystemSource.Cos_desc")); //$NON-NLS-1$
//$NON-NLS-2$
- addDoubleFunction("cot",
QueryPlugin.Util.getString("SystemSource.Cot_desc")); //$NON-NLS-1$
//$NON-NLS-2$
- addDoubleFunction("degrees",
QueryPlugin.Util.getString("SystemSource.Degrees_desc")); //$NON-NLS-1$
//$NON-NLS-2$
- addPiFunction("pi",
QueryPlugin.Util.getString("SystemSource.Pi_desc")); //$NON-NLS-1$
//$NON-NLS-2$
- addDoubleFunction("radians",
QueryPlugin.Util.getString("SystemSource.Radians_desc")); //$NON-NLS-1$
//$NON-NLS-2$
- addDoubleFunction("sin",
QueryPlugin.Util.getString("SystemSource.Sin_desc")); //$NON-NLS-1$
//$NON-NLS-2$
- addDoubleFunction("tan",
QueryPlugin.Util.getString("SystemSource.Tan_desc")); //$NON-NLS-1$
//$NON-NLS-2$
- addDoubleFunction("log",
QueryPlugin.Util.getString("SystemSource.Log_desc")); //$NON-NLS-1$
//$NON-NLS-2$
- addDoubleFunction("log10",
QueryPlugin.Util.getString("SystemSource.Log10_desc")); //$NON-NLS-1$
//$NON-NLS-2$
- addDoubleFunction("ceiling",
QueryPlugin.Util.getString("SystemSource.Ceiling_desc")); //$NON-NLS-1$
//$NON-NLS-2$
- addDoubleFunction("exp",
QueryPlugin.Util.getString("SystemSource.Exp_desc")); //$NON-NLS-1$
//$NON-NLS-2$
- addDoubleFunction("floor",
QueryPlugin.Util.getString("SystemSource.Floor_desc")); //$NON-NLS-1$
//$NON-NLS-2$
+ addDoubleFunction(SourceSystemFunctions.ACOS,
QueryPlugin.Util.getString("SystemSource.Acos_desc")); //$NON-NLS-1$
//$NON-NLS-2$
+ addDoubleFunction(SourceSystemFunctions.ASIN,
QueryPlugin.Util.getString("SystemSource.Asin_desc")); //$NON-NLS-1$
//$NON-NLS-2$
+ addDoubleFunction(SourceSystemFunctions.ATAN,
QueryPlugin.Util.getString("SystemSource.Atan_desc")); //$NON-NLS-1$
//$NON-NLS-2$
+ addAtan2Function(SourceSystemFunctions.ATAN2,
QueryPlugin.Util.getString("SystemSource.Atan2_desc")); //$NON-NLS-1$
//$NON-NLS-2$
+ addDoubleFunction(SourceSystemFunctions.COS,
QueryPlugin.Util.getString("SystemSource.Cos_desc")); //$NON-NLS-1$
//$NON-NLS-2$
+ addDoubleFunction(SourceSystemFunctions.COT,
QueryPlugin.Util.getString("SystemSource.Cot_desc")); //$NON-NLS-1$
//$NON-NLS-2$
+ addDoubleFunction(SourceSystemFunctions.DEGREES,
QueryPlugin.Util.getString("SystemSource.Degrees_desc")); //$NON-NLS-1$
//$NON-NLS-2$
+ addPiFunction(SourceSystemFunctions.PI,
QueryPlugin.Util.getString("SystemSource.Pi_desc")); //$NON-NLS-1$
//$NON-NLS-2$
+ addDoubleFunction(SourceSystemFunctions.RADIANS,
QueryPlugin.Util.getString("SystemSource.Radians_desc")); //$NON-NLS-1$
//$NON-NLS-2$
+ addDoubleFunction(SourceSystemFunctions.SIN,
QueryPlugin.Util.getString("SystemSource.Sin_desc")); //$NON-NLS-1$
//$NON-NLS-2$
+ addDoubleFunction(SourceSystemFunctions.TAN,
QueryPlugin.Util.getString("SystemSource.Tan_desc")); //$NON-NLS-1$
//$NON-NLS-2$
+ addDoubleFunction(SourceSystemFunctions.LOG,
QueryPlugin.Util.getString("SystemSource.Log_desc")); //$NON-NLS-1$
//$NON-NLS-2$
+ addDoubleFunction(SourceSystemFunctions.LOG10,
QueryPlugin.Util.getString("SystemSource.Log10_desc")); //$NON-NLS-1$
//$NON-NLS-2$
+ addDoubleFunction(SourceSystemFunctions.CEILING,
QueryPlugin.Util.getString("SystemSource.Ceiling_desc")); //$NON-NLS-1$
//$NON-NLS-2$
+ addDoubleFunction(SourceSystemFunctions.EXP,
QueryPlugin.Util.getString("SystemSource.Exp_desc")); //$NON-NLS-1$
//$NON-NLS-2$
+ addDoubleFunction(SourceSystemFunctions.FLOOR,
QueryPlugin.Util.getString("SystemSource.Floor_desc")); //$NON-NLS-1$
//$NON-NLS-2$
// bit
- addBitFunction("bitand",
QueryPlugin.Util.getString("SystemSource.Bitand_desc"), "bitand", 2,
QueryPlugin.Util.getString("SystemSource.Bitand_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- addBitFunction("bitor",
QueryPlugin.Util.getString("SystemSource.Bitor_desc"), "bitor", 2,
QueryPlugin.Util.getString("SystemSource.Bitor_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- addBitFunction("bitxor",
QueryPlugin.Util.getString("SystemSource.Bitxor_desc"), "bitxor", 2,
QueryPlugin.Util.getString("SystemSource.Bitxor_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- addBitFunction("bitnot",
QueryPlugin.Util.getString("SystemSource.Bitnot_desc"), "bitnot", 1,
QueryPlugin.Util.getString("SystemSource.Bitnot_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ addBitFunction(SourceSystemFunctions.BITAND,
QueryPlugin.Util.getString("SystemSource.Bitand_desc"), "bitand", 2,
QueryPlugin.Util.getString("SystemSource.Bitand_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ addBitFunction(SourceSystemFunctions.BITOR,
QueryPlugin.Util.getString("SystemSource.Bitor_desc"), "bitor", 2,
QueryPlugin.Util.getString("SystemSource.Bitor_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ addBitFunction(SourceSystemFunctions.BITXOR,
QueryPlugin.Util.getString("SystemSource.Bitxor_desc"), "bitxor", 2,
QueryPlugin.Util.getString("SystemSource.Bitxor_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ addBitFunction(SourceSystemFunctions.BITNOT,
QueryPlugin.Util.getString("SystemSource.Bitnot_desc"), "bitnot", 1,
QueryPlugin.Util.getString("SystemSource.Bitnot_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
// date
- addConstantDateFunction("curdate",
QueryPlugin.Util.getString("SystemSource.Curdate_desc"),
"currentDate", DataTypeManager.DefaultDataTypes.DATE); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
- addConstantDateFunction("curtime",
QueryPlugin.Util.getString("SystemSource.Curtime_desc"),
"currentTime", DataTypeManager.DefaultDataTypes.TIME); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
- addConstantDateFunction("now",
QueryPlugin.Util.getString("SystemSource.Now_desc"),
"currentTimestamp", DataTypeManager.DefaultDataTypes.TIMESTAMP); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
- addDateFunction("dayname", "dayName",
QueryPlugin.Util.getString("SystemSource.Dayname_result_d_desc"),
QueryPlugin.Util.getString("SystemSource.Dayname_result_ts_desc"),
DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
- addDateFunction("dayofmonth", "dayOfMonth",
QueryPlugin.Util.getString("SystemSource.Dayofmonth_result_d_desc"),
QueryPlugin.Util.getString("SystemSource.Dayofmonth_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
- addDateFunction("dayofweek", "dayOfWeek",
QueryPlugin.Util.getString("SystemSource.Dayofweek_result_d_desc"),
QueryPlugin.Util.getString("SystemSource.Dayofweek_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
- addDateFunction("dayofyear", "dayOfYear",
QueryPlugin.Util.getString("SystemSource.Dayofyear_result_d_desc"),
QueryPlugin.Util.getString("SystemSource.Dayofyear_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
- addDateFunction("month", "month",
QueryPlugin.Util.getString("SystemSource.Month_result_d_desc"),
QueryPlugin.Util.getString("SystemSource.Month_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
- addDateFunction("monthname", "monthName",
QueryPlugin.Util.getString("SystemSource.Monthname_result_d_desc"),
QueryPlugin.Util.getString("SystemSource.Monthname_result_ts_desc"),
DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
- addDateFunction("week", "week",
QueryPlugin.Util.getString("SystemSource.Week_result_d_desc"),
QueryPlugin.Util.getString("SystemSource.Week_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
- addDateFunction("year", "year",
QueryPlugin.Util.getString("SystemSource.Year_result_d_desc"),
QueryPlugin.Util.getString("SystemSource.Year_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
- addTimeFunction("hour", "hour",
QueryPlugin.Util.getString("SystemSource.Hour_result_t_desc"),
QueryPlugin.Util.getString("SystemSource.Hour_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
- addTimeFunction("minute", "minute",
QueryPlugin.Util.getString("SystemSource.Minute_result_t_desc"),
QueryPlugin.Util.getString("SystemSource.Minute_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
- addTimeFunction("second", "second",
QueryPlugin.Util.getString("SystemSource.Second_result_t_desc"),
QueryPlugin.Util.getString("SystemSource.Second_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
- addQuarterFunction("quarter", "quarter",
QueryPlugin.Util.getString("SystemSource.Quarter_result_d_desc"),
QueryPlugin.Util.getString("SystemSource.Quarter_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
+ addConstantDateFunction(SourceSystemFunctions.CURDATE,
QueryPlugin.Util.getString("SystemSource.Curdate_desc"),
"currentDate", DataTypeManager.DefaultDataTypes.DATE); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
+ addConstantDateFunction(SourceSystemFunctions.CURTIME,
QueryPlugin.Util.getString("SystemSource.Curtime_desc"),
"currentTime", DataTypeManager.DefaultDataTypes.TIME); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
+ addConstantDateFunction(SourceSystemFunctions.NOW,
QueryPlugin.Util.getString("SystemSource.Now_desc"),
"currentTimestamp", DataTypeManager.DefaultDataTypes.TIMESTAMP); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
+ addDateFunction(SourceSystemFunctions.DAYNAME, "dayName",
QueryPlugin.Util.getString("SystemSource.Dayname_result_d_desc"),
QueryPlugin.Util.getString("SystemSource.Dayname_result_ts_desc"),
DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
+ addDateFunction(SourceSystemFunctions.DAYOFMONTH, "dayOfMonth",
QueryPlugin.Util.getString("SystemSource.Dayofmonth_result_d_desc"),
QueryPlugin.Util.getString("SystemSource.Dayofmonth_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
+ addDateFunction(SourceSystemFunctions.DAYOFWEEK, "dayOfWeek",
QueryPlugin.Util.getString("SystemSource.Dayofweek_result_d_desc"),
QueryPlugin.Util.getString("SystemSource.Dayofweek_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
+ addDateFunction(SourceSystemFunctions.DAYOFYEAR, "dayOfYear",
QueryPlugin.Util.getString("SystemSource.Dayofyear_result_d_desc"),
QueryPlugin.Util.getString("SystemSource.Dayofyear_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
+ addDateFunction(SourceSystemFunctions.MONTH, "month",
QueryPlugin.Util.getString("SystemSource.Month_result_d_desc"),
QueryPlugin.Util.getString("SystemSource.Month_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
+ addDateFunction(SourceSystemFunctions.MONTHNAME, "monthName",
QueryPlugin.Util.getString("SystemSource.Monthname_result_d_desc"),
QueryPlugin.Util.getString("SystemSource.Monthname_result_ts_desc"),
DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
+ addDateFunction(SourceSystemFunctions.WEEK, "week",
QueryPlugin.Util.getString("SystemSource.Week_result_d_desc"),
QueryPlugin.Util.getString("SystemSource.Week_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
+ addDateFunction(SourceSystemFunctions.YEAR, "year",
QueryPlugin.Util.getString("SystemSource.Year_result_d_desc"),
QueryPlugin.Util.getString("SystemSource.Year_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
+ addTimeFunction(SourceSystemFunctions.HOUR, "hour",
QueryPlugin.Util.getString("SystemSource.Hour_result_t_desc"),
QueryPlugin.Util.getString("SystemSource.Hour_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
+ addTimeFunction(SourceSystemFunctions.MINUTE, "minute",
QueryPlugin.Util.getString("SystemSource.Minute_result_t_desc"),
QueryPlugin.Util.getString("SystemSource.Minute_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
+ addTimeFunction(SourceSystemFunctions.SECOND, "second",
QueryPlugin.Util.getString("SystemSource.Second_result_t_desc"),
QueryPlugin.Util.getString("SystemSource.Second_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
+ addQuarterFunction(SourceSystemFunctions.QUARTER, "quarter",
QueryPlugin.Util.getString("SystemSource.Quarter_result_d_desc"),
QueryPlugin.Util.getString("SystemSource.Quarter_result_ts_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
addTimestampAddFunction();
addTimestampDiffFunction();
addTimeZoneFunctions();
@@ -115,20 +116,19 @@
addUnixTimeFunctions();
// string
- addStringFunction("length",
QueryPlugin.Util.getString("SystemSource.Length_result"), "length",
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- addStringFunction("ucase",
QueryPlugin.Util.getString("SystemSource.Ucase_result"), "upperCase",
DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- addStringFunction("lcase",
QueryPlugin.Util.getString("SystemSource.Lcase_result"), "lowerCase",
DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ addStringFunction(SourceSystemFunctions.LENGTH,
QueryPlugin.Util.getString("SystemSource.Length_result"), "length",
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ addStringFunction(SourceSystemFunctions.UCASE,
QueryPlugin.Util.getString("SystemSource.Ucase_result"), "upperCase",
DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ addStringFunction(SourceSystemFunctions.LCASE,
QueryPlugin.Util.getString("SystemSource.Lcase_result"), "lowerCase",
DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
addStringFunction("lower",
QueryPlugin.Util.getString("SystemSource.Lower_result"), "lowerCase",
DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
addStringFunction("upper",
QueryPlugin.Util.getString("SystemSource.Upper_result"), "upperCase",
DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- addStringFunction("ltrim",
QueryPlugin.Util.getString("SystemSource.Left_result"), "leftTrim",
DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- addStringFunction("rtrim",
QueryPlugin.Util.getString("SystemSource.Right_result"), "rightTrim",
DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ addStringFunction(SourceSystemFunctions.LTRIM,
QueryPlugin.Util.getString("SystemSource.Left_result"), "leftTrim",
DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ addStringFunction(SourceSystemFunctions.RTRIM,
QueryPlugin.Util.getString("SystemSource.Right_result"), "rightTrim",
DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
addConcatFunction();
addSubstringFunction();
addLeftRightFunctions();
addLocateFunction();
addReplaceFunction();
addAsciiFunction();
- addChrFunction();
addCharFunction();
addInitCapFunction();
addLpadFunction();
@@ -139,8 +139,8 @@
addInsertFunction();
// clob
- addClobFunction("ucase",
QueryPlugin.Util.getString("SystemSource.UcaseClob_result"),
"upperCase", DataTypeManager.DefaultDataTypes.CLOB); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
- addClobFunction("lcase",
QueryPlugin.Util.getString("SystemSource.LcaseClob_result"),
"lowerCase", DataTypeManager.DefaultDataTypes.CLOB); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
+ addClobFunction(SourceSystemFunctions.UCASE,
QueryPlugin.Util.getString("SystemSource.UcaseClob_result"),
"upperCase", DataTypeManager.DefaultDataTypes.CLOB); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
+ addClobFunction(SourceSystemFunctions.LCASE,
QueryPlugin.Util.getString("SystemSource.LcaseClob_result"),
"lowerCase", DataTypeManager.DefaultDataTypes.CLOB); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
addClobFunction("lower",
QueryPlugin.Util.getString("SystemSource.LowerClob_result"),
"lowerCase", DataTypeManager.DefaultDataTypes.CLOB); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
addClobFunction("upper",
QueryPlugin.Util.getString("SystemSource.UpperClob_result"),
"upperCase", DataTypeManager.DefaultDataTypes.CLOB); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
@@ -156,20 +156,19 @@
addUserFunction();
addEnvFunction();
addCommandPayloadFunctions();
- addNvlFunctions();
addIfNullFunctions();
// format
- addFormatTimeFunction("formatTime",
QueryPlugin.Util.getString("SystemSource.Formattime_desc"),
"formatTime",
QueryPlugin.Util.getString("SystemSource.Formattime_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- addFormatDateFunction("formatDate",
QueryPlugin.Util.getString("SystemSource.Formatdate_desc"),
"formatDate",
QueryPlugin.Util.getString("SystemSource.Formatdate_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- addFormatTimestampFunction("formatTimestamp",
QueryPlugin.Util.getString("SystemSource.Formattimestamp_desc"),
"formatTimestamp",
QueryPlugin.Util.getString("SystemSource.Formattimestamp_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ addFormatTimeFunction(SourceSystemFunctions.FORMATTIME,
QueryPlugin.Util.getString("SystemSource.Formattime_desc"),
"formatTime",
QueryPlugin.Util.getString("SystemSource.Formattime_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ addFormatDateFunction(SourceSystemFunctions.FORMATDATE,
QueryPlugin.Util.getString("SystemSource.Formatdate_desc"),
"formatDate",
QueryPlugin.Util.getString("SystemSource.Formatdate_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ addFormatTimestampFunction(SourceSystemFunctions.FORMATTIMESTAMP,
QueryPlugin.Util.getString("SystemSource.Formattimestamp_desc"),
"formatTimestamp",
QueryPlugin.Util.getString("SystemSource.Formattimestamp_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
addFormatNumberFunctions();
// parse
- addParseTimeFunction("parseTime",
QueryPlugin.Util.getString("SystemSource.Parsetime_desc"),
"parseTime",
QueryPlugin.Util.getString("SystemSource.Parsetime_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- addParseDateFunction("parseDate",
QueryPlugin.Util.getString("SystemSource.Parsedate_desc"),
"parseDate",
QueryPlugin.Util.getString("SystemSource.Parsedate_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- addParseTimestampFunction("parseTimestamp",
QueryPlugin.Util.getString("SystemSource.Parsetimestamp_desc"),
"parseTimestamp",
QueryPlugin.Util.getString("SystemSource.Parsetimestamp_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ addParseTimeFunction(SourceSystemFunctions.PARSETIME,
QueryPlugin.Util.getString("SystemSource.Parsetime_desc"),
"parseTime",
QueryPlugin.Util.getString("SystemSource.Parsetime_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ addParseDateFunction(SourceSystemFunctions.PARSEDATE,
QueryPlugin.Util.getString("SystemSource.Parsedate_desc"),
"parseDate",
QueryPlugin.Util.getString("SystemSource.Parsedate_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ addParseTimestampFunction(SourceSystemFunctions.PARSETIMESTAMP,
QueryPlugin.Util.getString("SystemSource.Parsetimestamp_desc"),
"parseTimestamp",
QueryPlugin.Util.getString("SystemSource.Parsetimestamp_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
addParseNumberFunctions();
@@ -195,21 +194,21 @@
}
private void addFormatNumberFunctions() {
- addFormatNumberFunction("formatInteger",
QueryPlugin.Util.getString("SystemSource.Formatinteger_desc"),
"formatInteger", "integer", DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Formatinteger_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- addFormatNumberFunction("formatLong",
QueryPlugin.Util.getString("SystemSource.Formatlong_desc"),
"formatLong", "long", DataTypeManager.DefaultDataTypes.LONG,
QueryPlugin.Util.getString("SystemSource.Formatlong_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- addFormatNumberFunction("formatDouble",
QueryPlugin.Util.getString("SystemSource.Formatdouble_desc"),
"formatDouble", "double", DataTypeManager.DefaultDataTypes.DOUBLE,
QueryPlugin.Util.getString("SystemSource.Formatdouble_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- addFormatNumberFunction("formatFloat",
QueryPlugin.Util.getString("SystemSource.Formatfloat_desc"),
"formatFloat", "float", DataTypeManager.DefaultDataTypes.FLOAT,
QueryPlugin.Util.getString("SystemSource.Formatfloat_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- addFormatNumberFunction("formatBigInteger",
QueryPlugin.Util.getString("SystemSource.Formatbiginteger_desc"),
"formatBigInteger", "biginteger",
DataTypeManager.DefaultDataTypes.BIG_INTEGER,
QueryPlugin.Util.getString("SystemSource.Formatbiginteger_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- addFormatNumberFunction("formatBigDecimal",
QueryPlugin.Util.getString("SystemSource.Formatbigdecimal_desc"),
"formatBigDecimal", "bigdecimal",
DataTypeManager.DefaultDataTypes.BIG_DECIMAL,
QueryPlugin.Util.getString("SystemSource.Formatbigdecimal_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ addFormatNumberFunction(SourceSystemFunctions.FORMATINTEGER,
QueryPlugin.Util.getString("SystemSource.Formatinteger_desc"),
"formatInteger", "integer", DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Formatinteger_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ addFormatNumberFunction(SourceSystemFunctions.FORMATLONG,
QueryPlugin.Util.getString("SystemSource.Formatlong_desc"),
"formatLong", "long", DataTypeManager.DefaultDataTypes.LONG,
QueryPlugin.Util.getString("SystemSource.Formatlong_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ addFormatNumberFunction(SourceSystemFunctions.FORMATDOUBLE,
QueryPlugin.Util.getString("SystemSource.Formatdouble_desc"),
"formatDouble", "double", DataTypeManager.DefaultDataTypes.DOUBLE,
QueryPlugin.Util.getString("SystemSource.Formatdouble_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ addFormatNumberFunction(SourceSystemFunctions.FORMATFLOAT,
QueryPlugin.Util.getString("SystemSource.Formatfloat_desc"),
"formatFloat", "float", DataTypeManager.DefaultDataTypes.FLOAT,
QueryPlugin.Util.getString("SystemSource.Formatfloat_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ addFormatNumberFunction(SourceSystemFunctions.FORMATBIGINTEGER,
QueryPlugin.Util.getString("SystemSource.Formatbiginteger_desc"),
"formatBigInteger", "biginteger",
DataTypeManager.DefaultDataTypes.BIG_INTEGER,
QueryPlugin.Util.getString("SystemSource.Formatbiginteger_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ addFormatNumberFunction(SourceSystemFunctions.FORMATBIGDECIMAL,
QueryPlugin.Util.getString("SystemSource.Formatbigdecimal_desc"),
"formatBigDecimal", "bigdecimal",
DataTypeManager.DefaultDataTypes.BIG_DECIMAL,
QueryPlugin.Util.getString("SystemSource.Formatbigdecimal_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
}
private void addParseNumberFunctions() {
- addParseNumberFunction("parseInteger",
QueryPlugin.Util.getString("SystemSource.Parseinteger_desc"),
"parseInteger", "integer", DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Parseinteger_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- addParseNumberFunction("parseLong",
QueryPlugin.Util.getString("SystemSource.Parselong_desc"),
"parseLong", "long", DataTypeManager.DefaultDataTypes.LONG,
QueryPlugin.Util.getString("SystemSource.Parselong_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- addParseNumberFunction("parseDouble",
QueryPlugin.Util.getString("SystemSource.Parsedouble_desc"),
"parseDouble", "double", DataTypeManager.DefaultDataTypes.DOUBLE,
QueryPlugin.Util.getString("SystemSource.Parsedouble_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- addParseNumberFunction("parseFloat",
QueryPlugin.Util.getString("SystemSource.Parsefloat_desc"),
"parseFloat", "float", DataTypeManager.DefaultDataTypes.FLOAT,
QueryPlugin.Util.getString("SystemSource.Parsefloat_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- addParseNumberFunction("parseBigInteger",
QueryPlugin.Util.getString("SystemSource.Parsebiginteger_desc"),
"parseBigInteger", "biginteger",
DataTypeManager.DefaultDataTypes.BIG_INTEGER,
QueryPlugin.Util.getString("SystemSource.Parsebiginteger_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- addParseNumberFunction("parseBigDecimal",
QueryPlugin.Util.getString("SystemSource.Parsebigdecimal_desc"),
"parseBigDecimal", "bigdecimal",
DataTypeManager.DefaultDataTypes.BIG_DECIMAL,
QueryPlugin.Util.getString("SystemSource.Parsebigdecimal_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ addParseNumberFunction(SourceSystemFunctions.PARSEINTEGER,
QueryPlugin.Util.getString("SystemSource.Parseinteger_desc"),
"parseInteger", "integer", DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Parseinteger_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ addParseNumberFunction(SourceSystemFunctions.PARSELONG,
QueryPlugin.Util.getString("SystemSource.Parselong_desc"),
"parseLong", "long", DataTypeManager.DefaultDataTypes.LONG,
QueryPlugin.Util.getString("SystemSource.Parselong_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ addParseNumberFunction(SourceSystemFunctions.PARSEDOUBLE,
QueryPlugin.Util.getString("SystemSource.Parsedouble_desc"),
"parseDouble", "double", DataTypeManager.DefaultDataTypes.DOUBLE,
QueryPlugin.Util.getString("SystemSource.Parsedouble_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ addParseNumberFunction(SourceSystemFunctions.PARSEFLOAT,
QueryPlugin.Util.getString("SystemSource.Parsefloat_desc"),
"parseFloat", "float", DataTypeManager.DefaultDataTypes.FLOAT,
QueryPlugin.Util.getString("SystemSource.Parsefloat_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ addParseNumberFunction(SourceSystemFunctions.PARSEBIGINTEGER,
QueryPlugin.Util.getString("SystemSource.Parsebiginteger_desc"),
"parseBigInteger", "biginteger",
DataTypeManager.DefaultDataTypes.BIG_INTEGER,
QueryPlugin.Util.getString("SystemSource.Parsebiginteger_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ addParseNumberFunction(SourceSystemFunctions.PARSEBIGDECIMAL,
QueryPlugin.Util.getString("SystemSource.Parsebigdecimal_desc"),
"parseBigDecimal", "bigdecimal",
DataTypeManager.DefaultDataTypes.BIG_DECIMAL,
QueryPlugin.Util.getString("SystemSource.Parsebigdecimal_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
}
private void addArithmeticFunction(String functionName, String description, String
methodName, String resultsDescription) {
@@ -241,7 +240,7 @@
private void addTypedAbsFunction(String type) {
functions.add(
- new FunctionMethod("abs",
QueryPlugin.Util.getString("SystemSource.Abs_desc"), NUMERIC, FUNCTION_CLASS,
"abs", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.ABS,
QueryPlugin.Util.getString("SystemSource.Abs_desc"), NUMERIC, FUNCTION_CLASS,
"abs", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("number", type,
QueryPlugin.Util.getString("SystemSource.Abs_arg")) }, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result", type,
QueryPlugin.Util.getString("SystemSource.Abs_result_desc")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
@@ -249,13 +248,13 @@
private void addRandFunction() {
// With Seed
- FunctionMethod rand = new FunctionMethod("rand",
QueryPlugin.Util.getString("SystemSource.Rand_desc"), NUMERIC, FUNCTION_CLASS,
"rand", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ FunctionMethod rand = new FunctionMethod(SourceSystemFunctions.RAND,
QueryPlugin.Util.getString("SystemSource.Rand_desc"), NUMERIC, FUNCTION_CLASS,
"rand", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {new
FunctionParameter("seed", DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Rand_arg")) }, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.DOUBLE,
QueryPlugin.Util.getString("SystemSource.Rand_result_desc")),
FunctionMethod.NONDETERMINISTIC ); //$NON-NLS-1$ //$NON-NLS-2$
rand.setNullDependent(true);
functions.add(rand);
// Without Seed
- functions.add( new FunctionMethod("rand",
QueryPlugin.Util.getString("SystemSource.Rand_desc"), NUMERIC, FUNCTION_CLASS,
"rand", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ functions.add( new FunctionMethod(SourceSystemFunctions.RAND,
QueryPlugin.Util.getString("SystemSource.Rand_desc"), NUMERIC, FUNCTION_CLASS,
"rand", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {},
new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.DOUBLE,
QueryPlugin.Util.getString("SystemSource.Rand_result_desc")),
FunctionMethod.NONDETERMINISTIC ) ); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -285,11 +284,11 @@
}
private void addModFunction() {
- addTypedArithmeticFunction("mod",
QueryPlugin.Util.getString("SystemSource.Mod_desc"), "mod",
QueryPlugin.Util.getString("SystemSource.Mod_result_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
- addTypedArithmeticFunction("mod",
QueryPlugin.Util.getString("SystemSource.Mod_desc"), "mod",
QueryPlugin.Util.getString("SystemSource.Mod_result_desc"),
DataTypeManager.DefaultDataTypes.LONG); //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-2$
//$NON-NLS-4$
- addTypedArithmeticFunction("mod",
QueryPlugin.Util.getString("SystemSource.Mod_desc"), "mod",
QueryPlugin.Util.getString("SystemSource.Mod_result_desc"),
DataTypeManager.DefaultDataTypes.FLOAT); //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-2$
//$NON-NLS-4$
- addTypedArithmeticFunction("mod",
QueryPlugin.Util.getString("SystemSource.Mod_desc"), "mod",
QueryPlugin.Util.getString("SystemSource.Mod_result_desc"),
DataTypeManager.DefaultDataTypes.DOUBLE); //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-2$
//$NON-NLS-4$
- addTypedArithmeticFunction("mod",
QueryPlugin.Util.getString("SystemSource.Mod_desc"), "mod",
QueryPlugin.Util.getString("SystemSource.Mod_result_desc"),
DataTypeManager.DefaultDataTypes.BIG_INTEGER); //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-2$
//$NON-NLS-4$
+ addTypedArithmeticFunction(SourceSystemFunctions.MOD,
QueryPlugin.Util.getString("SystemSource.Mod_desc"), "mod",
QueryPlugin.Util.getString("SystemSource.Mod_result_desc"),
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
+ addTypedArithmeticFunction(SourceSystemFunctions.MOD,
QueryPlugin.Util.getString("SystemSource.Mod_desc"), "mod",
QueryPlugin.Util.getString("SystemSource.Mod_result_desc"),
DataTypeManager.DefaultDataTypes.LONG); //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-2$
//$NON-NLS-4$
+ addTypedArithmeticFunction(SourceSystemFunctions.MOD,
QueryPlugin.Util.getString("SystemSource.Mod_desc"), "mod",
QueryPlugin.Util.getString("SystemSource.Mod_result_desc"),
DataTypeManager.DefaultDataTypes.FLOAT); //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-2$
//$NON-NLS-4$
+ addTypedArithmeticFunction(SourceSystemFunctions.MOD,
QueryPlugin.Util.getString("SystemSource.Mod_desc"), "mod",
QueryPlugin.Util.getString("SystemSource.Mod_result_desc"),
DataTypeManager.DefaultDataTypes.DOUBLE); //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-2$
//$NON-NLS-4$
+ addTypedArithmeticFunction(SourceSystemFunctions.MOD,
QueryPlugin.Util.getString("SystemSource.Mod_desc"), "mod",
QueryPlugin.Util.getString("SystemSource.Mod_result_desc"),
DataTypeManager.DefaultDataTypes.BIG_INTEGER); //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-2$
//$NON-NLS-4$
}
private void addPowerFunction() {
@@ -299,7 +298,7 @@
private void addTypedPowerFunction(String baseType, String powerType) {
functions.add(
- new FunctionMethod("power",
QueryPlugin.Util.getString("SystemSource.Power_desc"), NUMERIC, FUNCTION_CLASS,
"power", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.POWER,
QueryPlugin.Util.getString("SystemSource.Power_desc"), NUMERIC, FUNCTION_CLASS,
"power", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("base", baseType,
QueryPlugin.Util.getString("SystemSource.Power_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("power", powerType,
QueryPlugin.Util.getString("SystemSource.Power_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
@@ -315,7 +314,7 @@
private void addTypedRoundFunction(String roundType) {
functions.add(
- new FunctionMethod("round",
QueryPlugin.Util.getString("SystemSource.Round_desc"), NUMERIC, FUNCTION_CLASS,
"round", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.ROUND,
QueryPlugin.Util.getString("SystemSource.Round_desc"), NUMERIC, FUNCTION_CLASS,
"round", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("number", roundType,
QueryPlugin.Util.getString("SystemSource.Round_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("places",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Round_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
@@ -333,7 +332,7 @@
private void addTypedSignFunction(String type) {
functions.add(
- new FunctionMethod("sign",
QueryPlugin.Util.getString("SystemSource.Sign_desc"), NUMERIC, FUNCTION_CLASS,
"sign", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.SIGN,
QueryPlugin.Util.getString("SystemSource.Sign_desc"), NUMERIC, FUNCTION_CLASS,
"sign", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("number", type,
QueryPlugin.Util.getString("SystemSource.Sign_arg1")) }, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Sign_result_desc")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
@@ -348,7 +347,7 @@
private void addTypedSqrtFunction(String type) {
functions.add(
- new FunctionMethod("sqrt",
QueryPlugin.Util.getString("SystemSource.Sqrt_desc"), NUMERIC, FUNCTION_CLASS,
"sqrt", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.SQRT,
QueryPlugin.Util.getString("SystemSource.Sqrt_desc"), NUMERIC, FUNCTION_CLASS,
"sqrt", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("number", type,
QueryPlugin.Util.getString("SystemSource.Sqrt_arg1")) }, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.DOUBLE,
QueryPlugin.Util.getString("SystemSource.Sqrt_result_desc")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
@@ -393,21 +392,21 @@
private void addTimestampAddFunction() {
functions.add(
- new FunctionMethod("timestampAdd",
QueryPlugin.Util.getString("SystemSource.Timestampadd_d_desc"), DATETIME,
FUNCTION_CLASS, "timestampAdd", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.TIMESTAMPADD,
QueryPlugin.Util.getString("SystemSource.Timestampadd_d_desc"), DATETIME,
FUNCTION_CLASS, "timestampAdd", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("interval", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Timestampadd_d_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("count", DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Timestampadd_d_arg2")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("timestamp", DataTypeManager.DefaultDataTypes.DATE,
QueryPlugin.Util.getString("SystemSource.Timestampadd_d_arg3"))}, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result", DataTypeManager.DefaultDataTypes.DATE,
QueryPlugin.Util.getString("SystemSource.Timestampadd_d_result_desc")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
functions.add(
- new FunctionMethod("timestampAdd",
QueryPlugin.Util.getString("SystemSource.Timestampadd_t_desc"), DATETIME,
FUNCTION_CLASS, "timestampAdd", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.TIMESTAMPADD,
QueryPlugin.Util.getString("SystemSource.Timestampadd_t_desc"), DATETIME,
FUNCTION_CLASS, "timestampAdd", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("interval", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Timestampadd_t_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("count", DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Timestampadd_t_arg2")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("timestamp", DataTypeManager.DefaultDataTypes.TIME,
QueryPlugin.Util.getString("SystemSource.Timestampadd_t_arg3"))}, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result", DataTypeManager.DefaultDataTypes.TIME,
QueryPlugin.Util.getString("SystemSource.Timestampadd_t_result_desc")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
functions.add(
- new FunctionMethod("timestampAdd",
QueryPlugin.Util.getString("SystemSource.Timestampadd_ts_desc"), DATETIME,
FUNCTION_CLASS, "timestampAdd", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.TIMESTAMPADD,
QueryPlugin.Util.getString("SystemSource.Timestampadd_ts_desc"), DATETIME,
FUNCTION_CLASS, "timestampAdd", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("interval", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Timestampadd_ts_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("count", DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Timestampadd_ts_arg2")), //$NON-NLS-1$
//$NON-NLS-2$
@@ -417,14 +416,14 @@
private void addTimestampDiffFunction() {
functions.add(
- new FunctionMethod("timestampDiff",
QueryPlugin.Util.getString("SystemSource.Timestampdiff_t_desc"), DATETIME,
FUNCTION_CLASS, "timestampDiff", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.TIMESTAMPDIFF,
QueryPlugin.Util.getString("SystemSource.Timestampdiff_t_desc"), DATETIME,
FUNCTION_CLASS, "timestampDiff", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("interval",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Timestampdiff_t_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("time1",
DataTypeManager.DefaultDataTypes.TIME,
QueryPlugin.Util.getString("SystemSource.Timestampdiff_t_arg2")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("time2",
DataTypeManager.DefaultDataTypes.TIME,
QueryPlugin.Util.getString("SystemSource.Timestampdiff_t_arg3"))}, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.LONG,
QueryPlugin.Util.getString("SystemSource.Timestampdiff_t_result_desc")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
functions.add(
- new FunctionMethod("timestampDiff",
QueryPlugin.Util.getString("SystemSource.Timestampdiff_ts_desc"), DATETIME,
FUNCTION_CLASS, "timestampDiff", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.TIMESTAMPDIFF,
QueryPlugin.Util.getString("SystemSource.Timestampdiff_ts_desc"), DATETIME,
FUNCTION_CLASS, "timestampDiff", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("interval",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Timestampdiff_ts_arg1")),
//$NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter("timestamp1",
DataTypeManager.DefaultDataTypes.TIMESTAMP,
QueryPlugin.Util.getString("SystemSource.Timestampdiff_ts_arg2")), //$NON-NLS-1$
//$NON-NLS-2$
@@ -434,7 +433,7 @@
private void addTimestampCreateFunction() {
functions.add(
- new FunctionMethod("timestampCreate",
QueryPlugin.Util.getString("SystemSource.TimestampCreate_desc"), DATETIME,
FUNCTION_CLASS, "timestampCreate", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.TIMESTAMPCREATE,
QueryPlugin.Util.getString("SystemSource.TimestampCreate_desc"), DATETIME,
FUNCTION_CLASS, "timestampCreate", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("date",
DataTypeManager.DefaultDataTypes.DATE,
QueryPlugin.Util.getString("SystemSource.TimestampCreate_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("time",
DataTypeManager.DefaultDataTypes.TIME,
QueryPlugin.Util.getString("SystemSource.TimestampCreate_arg2"))}, //$NON-NLS-1$
//$NON-NLS-2$
@@ -472,7 +471,7 @@
private void addConcatFunction() {
functions.add(
- new FunctionMethod("concat",
QueryPlugin.Util.getString("SystemSource.Concat_desc"), STRING, FUNCTION_CLASS,
"concat", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.CONCAT,
QueryPlugin.Util.getString("SystemSource.Concat_desc"), STRING, FUNCTION_CLASS,
"concat", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("string1",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Concat_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("string2",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Concat_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
@@ -494,14 +493,14 @@
private void addSubstringFunction() {
functions.add(
- new FunctionMethod("substring",
QueryPlugin.Util.getString("SystemSource.Substring_desc"), STRING,
FUNCTION_CLASS, "substring", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.SUBSTRING,
QueryPlugin.Util.getString("SystemSource.Substring_desc"), STRING,
FUNCTION_CLASS, "substring", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("string",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Substring_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("index",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Substring_arg2")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("length",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Substring_arg3")) }, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Substring_result")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
functions.add(
- new FunctionMethod("substring",
QueryPlugin.Util.getString("SystemSource.Susbstring2_desc"), STRING,
FUNCTION_CLASS, "substring", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.SUBSTRING,
QueryPlugin.Util.getString("SystemSource.Susbstring2_desc"), STRING,
FUNCTION_CLASS, "substring", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("string",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Substring2_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("index",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Substring2_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
@@ -510,13 +509,13 @@
private void addLeftRightFunctions() {
functions.add(
- new FunctionMethod("left",
QueryPlugin.Util.getString("SystemSource.Left_desc"), STRING, FUNCTION_CLASS,
"left", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.LEFT,
QueryPlugin.Util.getString("SystemSource.Left_desc"), STRING, FUNCTION_CLASS,
"left", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("string",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Left_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("length",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Left_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Left2_result")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
functions.add(
- new FunctionMethod("right",
QueryPlugin.Util.getString("SystemSource.Right_desc"), STRING, FUNCTION_CLASS,
"right", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.RIGHT,
QueryPlugin.Util.getString("SystemSource.Right_desc"), STRING, FUNCTION_CLASS,
"right", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("string",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Right_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("length",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Right_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
@@ -525,14 +524,14 @@
private void addLocateFunction() {
functions.add(
- new FunctionMethod("locate",
QueryPlugin.Util.getString("SystemSource.Locate_desc"), STRING, FUNCTION_CLASS,
"locate", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.LOCATE,
QueryPlugin.Util.getString("SystemSource.Locate_desc"), STRING, FUNCTION_CLASS,
"locate", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("substring",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Locate_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("string",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Locate_arg2")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("index",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Locate_arg3")) }, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Locate_result")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
functions.add(
- new FunctionMethod("locate",
QueryPlugin.Util.getString("SystemSource.Locate2_desc"), STRING, FUNCTION_CLASS,
"locate", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.LOCATE,
QueryPlugin.Util.getString("SystemSource.Locate2_desc"), STRING, FUNCTION_CLASS,
"locate", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("substring",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Locate2_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("string",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Locate2_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
@@ -541,7 +540,7 @@
private void addReplaceFunction() {
functions.add(
- new FunctionMethod("replace",
QueryPlugin.Util.getString("SystemSource.Replace_desc"), STRING, FUNCTION_CLASS,
"replace", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.REPLACE,
QueryPlugin.Util.getString("SystemSource.Replace_desc"), STRING, FUNCTION_CLASS,
"replace", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("string",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Replace_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("substring",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Replace_arg2")), //$NON-NLS-1$
//$NON-NLS-2$
@@ -551,7 +550,7 @@
private void addRepeatFunction() {
functions.add(
- new FunctionMethod("repeat",
QueryPlugin.Util.getString("SystemSource.Repeat_desc"), STRING, FUNCTION_CLASS,
"repeat", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.REPEAT,
QueryPlugin.Util.getString("SystemSource.Repeat_desc"), STRING, FUNCTION_CLASS,
"repeat", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("string", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Repeat_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("count", DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Repeat_arg2"))}, //$NON-NLS-1$
//$NON-NLS-2$
@@ -560,7 +559,7 @@
private void addSpaceFunction() {
functions.add(
- new FunctionMethod("space",
QueryPlugin.Util.getString("SystemSource.Space_desc"), STRING, FUNCTION_CLASS,
"space", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(FunctionLibrary.SPACE,
QueryPlugin.Util.getString("SystemSource.Space_desc"), STRING,
FunctionMethod.SYNTHETIC, null, null, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("count", DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Space_arg1"))}, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Space_result")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
@@ -568,7 +567,7 @@
private void addInsertFunction() {
functions.add(
- new FunctionMethod("insert",
QueryPlugin.Util.getString("SystemSource.Insert_desc"), STRING, FUNCTION_CLASS,
"insert", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.INSERT,
QueryPlugin.Util.getString("SystemSource.Insert_desc"), STRING, FUNCTION_CLASS,
"insert", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("str1", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Insert_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("start", DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Insert_arg2")), //$NON-NLS-1$
//$NON-NLS-2$
@@ -579,36 +578,33 @@
private void addAsciiFunction() {
functions.add(
- new FunctionMethod("ascii",
QueryPlugin.Util.getString("SystemSource.Ascii_desc"), STRING, FUNCTION_CLASS,
"ascii", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.ASCII,
QueryPlugin.Util.getString("SystemSource.Ascii_desc"), STRING, FUNCTION_CLASS,
"ascii", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("string",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Ascii_arg1")) }, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Ascii_result")) ) ); //$NON-NLS-1$
//$NON-NLS-2$
functions.add(
- new FunctionMethod("ascii",
QueryPlugin.Util.getString("SystemSource.Ascii2_desc"), STRING, FUNCTION_CLASS,
"ascii", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.ASCII,
QueryPlugin.Util.getString("SystemSource.Ascii2_desc"), STRING, FUNCTION_CLASS,
"ascii", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("char",
DataTypeManager.DefaultDataTypes.CHAR,
QueryPlugin.Util.getString("SystemSource.Ascii2_arg1")) }, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Ascii2_result")) ) ); //$NON-NLS-1$
//$NON-NLS-2$
}
- private void addChrFunction() {
- functions.add(
- new FunctionMethod("chr",
QueryPlugin.Util.getString("SystemSource.Chr_desc"), STRING, FUNCTION_CLASS,
"chr", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- new FunctionParameter[] {
- new FunctionParameter("code",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Chr_arg1")) }, //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.CHAR,
QueryPlugin.Util.getString("SystemSource.Chr_result")) ) ); //$NON-NLS-1$
//$NON-NLS-2$
- }
-
private void addCharFunction() {
functions.add(
- new FunctionMethod("char",
QueryPlugin.Util.getString("SystemSource.Char_desc"), STRING, FUNCTION_CLASS,
"chr", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.CHAR,
QueryPlugin.Util.getString("SystemSource.Char_desc"), STRING, FUNCTION_CLASS,
"chr", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("code", DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Char_arg1")) }, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result", DataTypeManager.DefaultDataTypes.CHAR,
QueryPlugin.Util.getString("SystemSource.Char_result")) ) ); //$NON-NLS-1$
//$NON-NLS-2$
+ functions.add(
+ new FunctionMethod("chr",
QueryPlugin.Util.getString("SystemSource.Chr_desc"), STRING, FUNCTION_CLASS,
"chr", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionParameter[] {
+ new FunctionParameter("code",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Chr_arg1")) }, //$NON-NLS-1$
//$NON-NLS-2$
+ new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.CHAR,
QueryPlugin.Util.getString("SystemSource.Chr_result")) ) ); //$NON-NLS-1$
//$NON-NLS-2$
}
private void addInitCapFunction() {
functions.add(
- new FunctionMethod("initcap",
QueryPlugin.Util.getString("SystemSource.Initcap_desc"), STRING, FUNCTION_CLASS,
"initCap", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.INITCAP,
QueryPlugin.Util.getString("SystemSource.Initcap_desc"), STRING, FUNCTION_CLASS,
"initCap", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("string",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Initcap_arg1")) }, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Initcap_result")) ) ); //$NON-NLS-1$
//$NON-NLS-2$
@@ -616,21 +612,14 @@
private void addLpadFunction() {
functions.add(
- new FunctionMethod("lpad",
QueryPlugin.Util.getString("SystemSource.Lpad_desc"), STRING, FUNCTION_CLASS,
"lpad", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.LPAD,
QueryPlugin.Util.getString("SystemSource.Lpad_desc"), STRING, FUNCTION_CLASS,
"lpad", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("string",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Lpad_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("length",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Lpad_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Lpad_result")) ) ); //$NON-NLS-1$
//$NON-NLS-2$
functions.add(
- new FunctionMethod("lpad",
QueryPlugin.Util.getString("SystemSource.Lpad2_desc"), STRING, FUNCTION_CLASS,
"lpad", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.LPAD,
QueryPlugin.Util.getString("SystemSource.Lpad3_desc"), STRING, FUNCTION_CLASS,
"lpad", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
- new FunctionParameter("string",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Lpad2_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("length",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Lpad2_arg2")), //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("char",
DataTypeManager.DefaultDataTypes.CHAR,
QueryPlugin.Util.getString("SystemSource.Lpad2_arg3")) }, //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Lpad2_result")) ) ); //$NON-NLS-1$
//$NON-NLS-2$
- functions.add(
- new FunctionMethod("lpad",
QueryPlugin.Util.getString("SystemSource.Lpad3_desc"), STRING, FUNCTION_CLASS,
"lpad", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- new FunctionParameter[] {
new FunctionParameter("string",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Lpad3_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("length",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Lpad3_arg2")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("char",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Lpad3_arg3")) }, //$NON-NLS-1$
//$NON-NLS-2$
@@ -639,21 +628,14 @@
private void addRpadFunction() {
functions.add(
- new FunctionMethod("rpad",
QueryPlugin.Util.getString("SystemSource.Rpad1_desc"), STRING, FUNCTION_CLASS,
"rpad", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.RPAD,
QueryPlugin.Util.getString("SystemSource.Rpad1_desc"), STRING, FUNCTION_CLASS,
"rpad", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("string",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Rpad1_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("length",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Rpad1_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Rpad1_result")) ) ); //$NON-NLS-1$
//$NON-NLS-2$
functions.add(
- new FunctionMethod("rpad",
QueryPlugin.Util.getString("SystemSource.Rpad2_desc"), STRING, FUNCTION_CLASS,
"rpad", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.RPAD,
QueryPlugin.Util.getString("SystemSource.Rpad3_desc"), STRING, FUNCTION_CLASS,
"rpad", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
- new FunctionParameter("string",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Rpad2_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("length",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Rpad2_arg2")), //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("char",
DataTypeManager.DefaultDataTypes.CHAR,
QueryPlugin.Util.getString("SystemSource.Rpad2_arg3")) }, //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Rpad2_result")) ) ); //$NON-NLS-1$
//$NON-NLS-2$
- functions.add(
- new FunctionMethod("rpad",
QueryPlugin.Util.getString("SystemSource.Rpad3_desc"), STRING, FUNCTION_CLASS,
"rpad", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- new FunctionParameter[] {
new FunctionParameter("string",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Rpad3_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("length",
DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Rpad3_arg2")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("char",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Rpad3_arg3")) }, //$NON-NLS-1$
//$NON-NLS-2$
@@ -662,7 +644,7 @@
private void addTranslateFunction() {
functions.add(
- new FunctionMethod("translate",
QueryPlugin.Util.getString("SystemSource.Translate_desc"), STRING,
FUNCTION_CLASS, "translate", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod(SourceSystemFunctions.TRANSLATE,
QueryPlugin.Util.getString("SystemSource.Translate_desc"), STRING,
FUNCTION_CLASS, "translate", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("string",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Translate_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("source",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Translate_arg2")), //$NON-NLS-1$
//$NON-NLS-2$
@@ -672,7 +654,7 @@
private void addConversionFunctions() {
for (String type : DataTypeManager.getAllDataTypeNames()) {
- addTypedConversionFunction("convert", type); //$NON-NLS-1$
+ addTypedConversionFunction(SourceSystemFunctions.CONVERT, type);
//$NON-NLS-1$
addTypedConversionFunction("cast", type); //$NON-NLS-1$
}
}
@@ -725,21 +707,20 @@
}
private void addDecodeFunctions(){
-
addDecodeFunction("decodeInteger",
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$
addDecodeFunction("decodeString",
DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$
}
private void addDecodeFunction(String functionName, String resultType) {
functions.add(
- new FunctionMethod(functionName,
QueryPlugin.Util.getString("SystemSource.Decode1_desc"), MISCELLANEOUS,
FUNCTION_CLASS, functionName, //$NON-NLS-1$
+ new FunctionMethod(functionName,
QueryPlugin.Util.getString("SystemSource.Decode1_desc"), MISCELLANEOUS,
FunctionMethod.SYNTHETIC, null, null, //$NON-NLS-1$
new FunctionParameter[] {
new FunctionParameter("input",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Decode1_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("decodeString",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Decode1_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result", resultType,
QueryPlugin.Util.getString("SystemSource.Decode1_result") ) ) );
//$NON-NLS-1$ //$NON-NLS-2$
functions.add(
- new FunctionMethod(functionName,
QueryPlugin.Util.getString("SystemSource.Decode2_desc"), MISCELLANEOUS,
FUNCTION_CLASS, functionName, //$NON-NLS-1$
+ new FunctionMethod(functionName,
QueryPlugin.Util.getString("SystemSource.Decode2_desc"), MISCELLANEOUS,
FunctionMethod.SYNTHETIC, null, null, //$NON-NLS-1$
new FunctionParameter[] {
new FunctionParameter("input",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Decode2_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("decodeString",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Decode2_arg2")), //$NON-NLS-1$
//$NON-NLS-2$
@@ -790,21 +771,16 @@
new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.CommandPayload_result")), false,
FunctionMethod.COMMAND_DETERMINISTIC ) ); //$NON-NLS-1$ //$NON-NLS-2$
}
- private void addNvlFunctions() {
+ private void addIfNullFunctions() {
for (String type : DataTypeManager.getAllDataTypeNames()) {
- addNvlFunction(type);
+ addNvlFunction(type);
+ addIfNullFunction(type);
}
}
-
- private void addIfNullFunctions() {
- for (String type : DataTypeManager.getAllDataTypeNames()) {
- addIfNullFunction(type);
- }
- }
private void addNvlFunction(String valueType) {
FunctionMethod nvl =
- new FunctionMethod("nvl",
QueryPlugin.Util.getString("SystemSource.Nvl_desc"), MISCELLANEOUS,
FUNCTION_CLASS, "nvl", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod("nvl",
QueryPlugin.Util.getString("SystemSource.Nvl_desc"), MISCELLANEOUS,
FUNCTION_CLASS, "ifnull", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("value", valueType,
QueryPlugin.Util.getString("SystemSource.Nvl_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("valueIfNull", valueType,
QueryPlugin.Util.getString("SystemSource.Nvl_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
@@ -815,7 +791,7 @@
private void addIfNullFunction(String valueType) {
FunctionMethod nvl =
- new FunctionMethod("ifnull",
QueryPlugin.Util.getString("SystemSource.Ifnull_desc"), MISCELLANEOUS,
FUNCTION_CLASS, "nvl", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new FunctionMethod("ifnull",
QueryPlugin.Util.getString("SystemSource.Ifnull_desc"), MISCELLANEOUS,
FUNCTION_CLASS, "ifnull", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("value", valueType,
QueryPlugin.Util.getString("SystemSource.Ifnull_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("valueIfNull", valueType,
QueryPlugin.Util.getString("SystemSource.Ifnull_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
@@ -921,13 +897,13 @@
* @since 4.2
*/
private void addXpathFunction() {
- functions.add(new FunctionMethod("xpathValue",
QueryPlugin.Util.getString("SystemSource.xpath_description"), XML,
XML_FUNCTION_CLASS, "xpathValue", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ functions.add(new FunctionMethod(SourceSystemFunctions.XPATHVALUE,
QueryPlugin.Util.getString("SystemSource.xpath_description"), XML,
XML_FUNCTION_CLASS, "xpathValue", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("document",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.xpath_param1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("xpath",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.xpath_param2"))}, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.xpath_result")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
- functions.add(new FunctionMethod("xpathValue",
QueryPlugin.Util.getString("SystemSource.xpath_description"), XML,
XML_FUNCTION_CLASS, "xpathValue", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ functions.add(new FunctionMethod(SourceSystemFunctions.XPATHVALUE,
QueryPlugin.Util.getString("SystemSource.xpath_description"), XML,
XML_FUNCTION_CLASS, "xpathValue", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("document",
DataTypeManager.DefaultDataTypes.XML,
QueryPlugin.Util.getString("SystemSource.xpath_param1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("xpath",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.xpath_param2"))}, //$NON-NLS-1$
//$NON-NLS-2$
@@ -936,14 +912,14 @@
}
private void addTimeZoneFunctions() {
- functions.add(new FunctionMethod("modifyTimeZone",
QueryPlugin.Util.getString("SystemSource.modifyTimeZone_description"), DATETIME,
FUNCTION_CLASS, "modifyTimeZone", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ functions.add(new FunctionMethod(SourceSystemFunctions.MODIFYTIMEZONE,
QueryPlugin.Util.getString("SystemSource.modifyTimeZone_description"), DATETIME,
FUNCTION_CLASS, "modifyTimeZone", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("timestamp",
DataTypeManager.DefaultDataTypes.TIMESTAMP,
QueryPlugin.Util.getString("SystemSource.modifyTimeZone_param1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("startTimeZone",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.modifyTimeZone_param2")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("endTimeZone",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.modifyTimeZone_param3"))},
//$NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.TIMESTAMP,
QueryPlugin.Util.getString("SystemSource.modifyTimeZone_result")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
- functions.add(new FunctionMethod("modifyTimeZone",
QueryPlugin.Util.getString("SystemSource.modifyTimeZone_description"), DATETIME,
FUNCTION_CLASS, "modifyTimeZone", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ functions.add(new FunctionMethod(SourceSystemFunctions.MODIFYTIMEZONE,
QueryPlugin.Util.getString("SystemSource.modifyTimeZone_description"), DATETIME,
FUNCTION_CLASS, "modifyTimeZone", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new FunctionParameter[] {
new FunctionParameter("timestamp",
DataTypeManager.DefaultDataTypes.TIMESTAMP,
QueryPlugin.Util.getString("SystemSource.modifyTimeZone_param1")), //$NON-NLS-1$
//$NON-NLS-2$
new
FunctionParameter("endTimeZone", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.modifyTimeZone_param3"))},
//$NON-NLS-1$ //$NON-NLS-2$
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/AliasGenerator.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/AliasGenerator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/AliasGenerator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -253,7 +253,7 @@
* visit the query in definition order
*/
public void visit(Query obj) {
- if (obj.getOrderBy() != null) {
+ if (obj.getOrderBy() != null || obj.getLimit() != null) {
visitor.namingContext.aliasColumns = true;
}
visitNode(obj.getFrom());
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-16
21:35:28 UTC (rev 475)
+++ trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -53,6 +53,7 @@
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.common.types.Transform;
import com.metamatrix.common.util.TimestampWithTimezone;
+import com.metamatrix.connector.api.SourceSystemFunctions;
import com.metamatrix.core.MetaMatrixRuntimeException;
import com.metamatrix.core.util.Assertion;
import com.metamatrix.query.eval.Evaluator;
@@ -60,7 +61,6 @@
import com.metamatrix.query.function.FunctionDescriptor;
import com.metamatrix.query.function.FunctionLibrary;
import com.metamatrix.query.function.FunctionLibraryManager;
-import com.metamatrix.query.function.FunctionMethods;
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.metadata.TempMetadataAdapter;
import com.metamatrix.query.metadata.TempMetadataID;
@@ -121,7 +121,6 @@
import com.metamatrix.query.sql.proc.Statement;
import com.metamatrix.query.sql.proc.TranslateCriteria;
import com.metamatrix.query.sql.proc.WhileStatement;
-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.CaseExpression;
@@ -159,6 +158,17 @@
private final static Timestamp EXAMPLE_TIMESTAMP = Timestamp.valueOf("2001-02-03
13:04:05.01"); //$NON-NLS-1$
private final static Time EXAMPLE_TIME = Time.valueOf("13:04:05");
//$NON-NLS-1$
private final static Date EXAMPLE_DATE = Date.valueOf("2001-02-03");
//$NON-NLS-1$
+
+ private static final Map<String, String> ALIASED_FUNCTIONS = new
HashMap<String, String>();
+
+ static {
+ ALIASED_FUNCTIONS.put("lower", SourceSystemFunctions.LCASE);
+ ALIASED_FUNCTIONS.put("upper", SourceSystemFunctions.UCASE);
+ ALIASED_FUNCTIONS.put("cast", SourceSystemFunctions.CONVERT);
+ ALIASED_FUNCTIONS.put("nvl", SourceSystemFunctions.IFNULL);
+ ALIASED_FUNCTIONS.put("||", SourceSystemFunctions.CONCAT);
+ ALIASED_FUNCTIONS.put("chr", SourceSystemFunctions.CHAR);
+ }
private QueryRewriter() { }
@@ -1981,15 +1991,26 @@
return expression;
}
- /**
- * <p>Do 2 things:
- * <ol>
- * <li> If function is a type conversion of type X to type X - eliminate
it</li>
- * <li> If this is a function totally based on constants, execute it now
- * rather than many times in the processor, and return the equivalent
constant</li>
- * </ol></p>
- */
private static Expression rewriteFunction(Function function, Command procCommand,
CommandContext context, QueryMetadataInterface metadata) throws QueryValidatorException {
+ //rewrite alias functions
+ String actualName =ALIASED_FUNCTIONS.get(function.getName().toLowerCase());
+ if (actualName != null) {
+ function.setName(actualName);
+ }
+
+ //space(x) => repeat(' ', x)
+ if (function.getName().equalsIgnoreCase(FunctionLibrary.SPACE)) {
+ //change the function into timestampadd
+ Function result = new Function(SourceSystemFunctions.REPEAT,
+ new Expression[] {new Constant(" "), function.getArg(0)});
+ //resolve the function
+ FunctionDescriptor descriptor =
+
FunctionLibraryManager.getFunctionLibrary().findFunction(SourceSystemFunctions.REPEAT,
new Class[] { DataTypeManager.DefaultDataClasses.STRING,
DataTypeManager.DefaultDataClasses.INTEGER});
+ result.setFunctionDescriptor(descriptor);
+ result.setType(DataTypeManager.DefaultDataClasses.STRING);
+ return rewriteFunction(result, procCommand, context, metadata);
+ }
+
//from_unixtime(a) => timestampadd(SQL_TSI_SECOND, a, new Timestamp(0))
if (function.getName().equalsIgnoreCase(FunctionLibrary.FROM_UNIXTIME)) {
//change the function into timestampadd
@@ -2018,11 +2039,11 @@
if (function.getName().equalsIgnoreCase(FunctionLibrary.COALESCE)) {
Expression[] args = function.getArgs();
if (args.length == 2) {
- Function result = new Function(FunctionLibrary.IFNULL,
+ Function result = new Function(SourceSystemFunctions.IFNULL,
new Expression[] {function.getArg(0), function.getArg(1) });
//resolve the function
FunctionDescriptor descriptor =
-
FunctionLibraryManager.getFunctionLibrary().findFunction(FunctionLibrary.IFNULL, new
Class[] { function.getType(), function.getType() });
+
FunctionLibraryManager.getFunctionLibrary().findFunction(SourceSystemFunctions.IFNULL,
new Class[] { function.getType(), function.getType() });
result.setFunctionDescriptor(descriptor);
result.setType(function.getType());
return rewriteFunction(result, procCommand, context, metadata);
@@ -2051,18 +2072,18 @@
Function[] newArgs = new Function[args.length];
for(int i=0; i<args.length; i++) {
- newArgs[i] = new Function(FunctionLibrary.NVL, new Expression[] {args[i], new
Constant("")}); //$NON-NLS-1$
+ newArgs[i] = new Function(SourceSystemFunctions.IFNULL, new Expression[] {args[i],
new Constant("")}); //$NON-NLS-1$
newArgs[i].setType(args[i].getType());
Assertion.assertTrue(args[i].getType() ==
DataTypeManager.DefaultDataClasses.STRING);
FunctionDescriptor descriptor =
- FunctionLibraryManager.getFunctionLibrary().findFunction(FunctionLibrary.NVL,
new Class[] { args[i].getType(), DataTypeManager.DefaultDataClasses.STRING });
+
FunctionLibraryManager.getFunctionLibrary().findFunction(SourceSystemFunctions.IFNULL,
new Class[] { args[i].getType(), DataTypeManager.DefaultDataClasses.STRING });
newArgs[i].setFunctionDescriptor(descriptor);
}
- Function concat = new Function(FunctionLibrary.CONCAT, newArgs);
+ Function concat = new Function(SourceSystemFunctions.CONCAT, newArgs);
concat.setType(DataTypeManager.DefaultDataClasses.STRING);
FunctionDescriptor descriptor =
-
FunctionLibraryManager.getFunctionLibrary().findFunction(FunctionLibrary.CONCAT, new
Class[] { DataTypeManager.DefaultDataClasses.STRING,
DataTypeManager.DefaultDataClasses.STRING });
+
FunctionLibraryManager.getFunctionLibrary().findFunction(SourceSystemFunctions.CONCAT,
new Class[] { DataTypeManager.DefaultDataClasses.STRING,
DataTypeManager.DefaultDataClasses.STRING });
concat.setFunctionDescriptor(descriptor);
List when = Arrays.asList(new Criteria[] {new CompoundCriteria(CompoundCriteria.AND,
new IsNullCriteria(args[0]), new IsNullCriteria(args[1]))});
@@ -2142,16 +2163,22 @@
while (tokenizer.hasMoreTokens()) {
String resultString;
String compareString =
- FunctionMethods.convertString(tokenizer.nextToken().trim());
+ convertString(tokenizer.nextToken().trim());
if (tokenizer.hasMoreTokens()) {
- resultString =
FunctionMethods.convertString(tokenizer.nextToken().trim());
- newWhens.add(new Constant(compareString));
+ resultString = convertString(tokenizer.nextToken().trim());
+ Criteria crit;
+ if (compareString == null) {
+ crit = new IsNullCriteria((Expression) exprs[0].clone());
+ } else {
+ crit = new CompareCriteria((Expression) exprs[0].clone(),
CompareCriteria.EQ, new Constant(compareString));
+ }
+ newWhens.add(crit);
newThens.add(new Constant(resultString));
}else {
elseConst = new Constant(compareString);
}
}
- CaseExpression newCaseExpr = new CaseExpression(exprs[0], newWhens, newThens);
+ SearchedCaseExpression newCaseExpr = new SearchedCaseExpression(newWhens,
newThens);
if(elseConst != null) {
newCaseExpr.setElseExpression(elseConst);
}else {
@@ -2162,52 +2189,92 @@
return newCaseExpr;
}
+ public static String convertString(String string) {
+ /*
+ * if there are no characters in the compare string we designate that as
+ * an indication of null. ie if the decode string looks like this:
+ *
+ * "'this', 1,,'null'"
+ *
+ * Then if the value in the first argument is null then the String 'null'
is
+ * returned from the function.
+ */
+ if (string.equals("")) { //$NON-NLS-1$
+ return null;
+ }
+
+ /*
+ * we also allow the use of the keyword null in the decode string. if it
+ * wished to match on the string 'null' then the string must be qualified
by
+ * ' designators.
+ */
+ if(string.equalsIgnoreCase("null")){ //$NON-NLS-1$
+ return null;
+ }
+
+ /*
+ * Here we check to see if the String in the decode String submitted
+ * was surrounded by String literal characters. In this case we strip
+ * these literal characters from the String.
+ */
+ if ((string.startsWith("\"") &&
string.endsWith("\"")) //$NON-NLS-1$ //$NON-NLS-2$
+ || (string.startsWith("'") &&
string.endsWith("'"))) { //$NON-NLS-1$ //$NON-NLS-2$
+ if (string.length() == 2) {
+ /*
+ * This is an indication that the desired string to be compared is
+ * the "" empty string, so we return it as such.
+ */
+ string = ""; //$NON-NLS-1$
+ } else if (!string.equalsIgnoreCase("'") &&
!string.equalsIgnoreCase("\"")){ //$NON-NLS-1$ //$NON-NLS-2$
+ string = string.substring(1);
+ string = string.substring(0, string.length()-1);
+ }
+ }
+
+ return string;
+ }
+
private static Expression rewriteCaseExpression(CaseExpression expr, Command
procCommand, CommandContext context, QueryMetadataInterface metadata)
throws QueryValidatorException {
- Expression rewrittenExpr = rewriteExpression(expr.getExpression(), procCommand,
context, metadata);
- expr.setExpression(rewrittenExpr);
-
+ List<CompareCriteria> whens = new
ArrayList<CompareCriteria>(expr.getWhenCount());
+ for (Expression expression: (List<Expression>)expr.getWhen()) {
+ whens.add(new CompareCriteria((Expression)expr.getExpression().clone(),
CompareCriteria.EQ, expression));
+ }
+ SearchedCaseExpression sce = new SearchedCaseExpression(whens, expr.getThen());
+ sce.setElseExpression(expr.getElseExpression());
+ sce.setType(expr.getType());
+ return rewriteCaseExpression(sce, procCommand, context, metadata);
+ }
+
+ private static Expression rewriteCaseExpression(SearchedCaseExpression expr, Command
procCommand, CommandContext context, QueryMetadataInterface metadata)
+ throws QueryValidatorException {
int whenCount = expr.getWhenCount();
ArrayList whens = new ArrayList(whenCount);
ArrayList thens = new ArrayList(whenCount);
-
- boolean tryToSimplify =
EvaluateExpressionVisitor.isFullyEvaluatable(rewrittenExpr, true);
+
for (int i = 0; i < whenCount; i++) {
- Expression rewrittenWhen = rewriteExpression(expr.getWhenExpression(i),
procCommand, context, metadata);
- if(tryToSimplify &&
EvaluateExpressionVisitor.isFullyEvaluatable(rewrittenWhen, true)) {
- CompareCriteria crit = new CompareCriteria(rewrittenExpr,
CompareCriteria.EQ, rewrittenWhen);
+
+ // Check the when to see if this CASE can be rewritten due to an always
true/false when
+ Criteria rewrittenWhen = rewriteCriteria(expr.getWhenCriteria(i),
procCommand, context, metadata);
+ if(EvaluateExpressionVisitor.isFullyEvaluatable(rewrittenWhen, true)) {
try {
- boolean eval = Evaluator.evaluate(crit);
+ boolean eval = Evaluator.evaluate(rewrittenWhen);
if(eval) {
- // This WHEN will always match, so return the THEN expression
+ // WHEN is always true, so just return the THEN
return rewriteExpression(expr.getThenExpression(i), procCommand,
context, metadata);
}
-
- // This WHEN will never match, so remove it from the CASE
+
+ // WHEN is never true, so just skip this WHEN/THEN pair in the lists
continue;
} catch(Exception e) {
// ignore and don't simplify - shouldn't happen
- tryToSimplify = false;
- }
- } else {
- tryToSimplify = false;
- }
-
+ }
+ }
+
whens.add(rewrittenWhen);
thens.add(rewriteExpression(expr.getThenExpression(i), procCommand, context,
metadata));
}
-
- return simplifyCaseExpression(expr, procCommand,context, whenCount, whens, thens,
metadata);
- }
- private static Expression simplifyCaseExpression(AbstractCaseExpression expr,
- Command procCommand,
- CommandContext context,
- int whenCount,
- ArrayList whens,
- ArrayList thens,
- QueryMetadataInterface metadata)
throws QueryValidatorException {
-
expr.setElseExpression(rewriteExpression(expr.getElseExpression(), procCommand,
context, metadata));
Expression elseExpr = expr.getElseExpression();
@@ -2246,42 +2313,6 @@
return expr;
}
-
- private static Expression rewriteCaseExpression(SearchedCaseExpression expr, Command
procCommand, CommandContext context, QueryMetadataInterface metadata)
- throws QueryValidatorException {
- int whenCount = expr.getWhenCount();
- ArrayList whens = new ArrayList(whenCount);
- ArrayList thens = new ArrayList(whenCount);
-
- boolean tryToSimplify = true;
- for (int i = 0; i < whenCount; i++) {
-
- // Check the when to see if this CASE can be rewritten due to an always
true/false when
- Criteria rewrittenWhen = rewriteCriteria(expr.getWhenCriteria(i),
procCommand, context, metadata);
- if(tryToSimplify &&
EvaluateExpressionVisitor.isFullyEvaluatable(rewrittenWhen, true)) {
- try {
- boolean eval = Evaluator.evaluate(rewrittenWhen);
- if(eval) {
- // WHEN is always true, so just return the THEN
- return rewriteExpression(expr.getThenExpression(i), procCommand,
context, metadata);
- }
-
- // WHEN is never true, so just skip this WHEN/THEN pair in the lists
- continue;
- } catch(Exception e) {
- // ignore and don't simplify - shouldn't happen
- tryToSimplify = false;
- }
- } else {
- tryToSimplify = false;
- }
-
- whens.add(rewrittenWhen);
- thens.add(rewriteExpression(expr.getThenExpression(i), procCommand, context,
metadata));
- }
-
- return simplifyCaseExpression(expr, procCommand,context, whenCount, whens, thens,
metadata);
- }
private static Command rewriteExec(StoredProcedure storedProcedure, Command
procCommand, QueryMetadataInterface metadata, CommandContext context) throws
QueryValidatorException {
//After this method, no longer need to display named parameters
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/Function.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/Function.java 2009-02-16
21:35:28 UTC (rev 475)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/Function.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -62,6 +62,10 @@
return this.name;
}
+ public void setName(String name) {
+ this.name = name;
+ }
+
/**
* Get function arguments
* @return Get function arguments
Modified:
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -193,38 +193,18 @@
public void visit(CaseExpression obj) {
parts.add(ReservedWords.CASE);
parts.add(SPACE);
+ parts.add(registerNode(obj.getExpression()) );
+ parts.add(SPACE);
- // checking for null compare in decode string case 2969 GCSS
- for (int i =0; i < obj.getWhenCount(); i++) {
- if (ReservedWords.NULL.equalsIgnoreCase(obj.getWhenExpression(i).toString() )
) {
- parts.add(ReservedWords.WHEN);
- parts.add(SPACE);
- parts.add(registerNode(obj.getExpression()) );
- parts.add(SPACE);
- parts.add(ReservedWords.IS);
- parts.add(SPACE);
- parts.add(ReservedWords.NULL);
- parts.add(SPACE);
- parts.add(ReservedWords.THEN);
- parts.add(SPACE);
- parts.add(registerNode(obj.getThenExpression(i)));
- parts.add(SPACE);
- }
- }
-
for (int i = 0; i < obj.getWhenCount(); i++) {
- if(!ReservedWords.NULL.equalsIgnoreCase(obj.getWhenExpression(i).toString() )
) {
- parts.add(ReservedWords.WHEN);
- parts.add(SPACE);
- parts.add(registerNode(obj.getExpression()) );
- parts.add("="); //$NON-NLS-1$
- parts.add(registerNode(obj.getWhenExpression(i)) );
- parts.add(SPACE);
- parts.add(ReservedWords.THEN);
- parts.add(SPACE);
- parts.add(registerNode(obj.getThenExpression(i)));
- parts.add(SPACE);
- }
+ parts.add(ReservedWords.WHEN);
+ parts.add(SPACE);
+ parts.add(registerNode(obj.getWhenExpression(i)) );
+ parts.add(SPACE);
+ parts.add(ReservedWords.THEN);
+ parts.add(SPACE);
+ parts.add(registerNode(obj.getThenExpression(i)));
+ parts.add(SPACE);
}
if (obj.getElseExpression() != null) {
Modified: trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties 2009-02-16
21:35:28 UTC (rev 475)
+++ trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties 2009-02-19
17:59:09 UTC (rev 476)
@@ -51,9 +51,9 @@
ERR.015.001.0024 = Error occurred while taking log10 of {0}
ERR.015.001.0025 = Pad length must be > 0.
ERR.015.001.0026 = Error occurred while doing {0} mod {1}
-ERR.015.001.0027 = Pad character for lpad must be a single character.
+ERR.015.001.0027 = Pad string for lpad/rpad must have length greater than 0.
ERR.015.001.0028 = Error occurred while doing {0} ^ {1}
-ERR.015.001.0029 = Pad character for rpad must be a single character.
+ERR.015.001.0029 = Pad string for rpad must have length greater than 1.
ERR.015.001.0030 = Error occurred while taking sign({0})
ERR.015.001.0031 = Source and destination character lists must be the same length.
ERR.015.001.0032 = Error occurred while taking sqrt of {0}
Deleted:
trunk/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/language/TestCaseExpressionImpl.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/language/TestCaseExpressionImpl.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/language/TestCaseExpressionImpl.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1,152 +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.dqp.internal.datamgr.language;
-
-import com.metamatrix.query.sql.symbol.CaseExpression;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.TestCaseExpression;
-
-import junit.framework.TestCase;
-
-public class TestCaseExpressionImpl extends TestCase {
-
- /**
- * Constructor for TestCaseExpressionImpl.
- * @param name
- */
- public TestCaseExpressionImpl(String name) {
- super(name);
- }
-
- public static CaseExpression helpExample() {
- ElementSymbol x = TestElementImpl.helpExample("vm1.g1",
"e1"); //$NON-NLS-1$ //$NON-NLS-2$
- CaseExpression caseExpr = new CaseExpression(x,
TestCaseExpression.getWhenExpressions(3), TestCaseExpression.getThenExpressions(3));
- caseExpr.setElseExpression(new Constant(new Integer(9999)));
- return caseExpr;
- }
-
- public static CaseExpression helpExampleElementElse() {
- ElementSymbol x = TestElementImpl.helpExample("vm1.g1",
"e1"); //$NON-NLS-1$ //$NON-NLS-2$
- CaseExpression caseExpr = new CaseExpression(x,
TestCaseExpression.getWhenExpressions(3), TestCaseExpression.getThenExpressions(3));
- caseExpr.setElseExpression(x);
- return caseExpr;
- }
-
- public static CaseExpression helpIntExample() {
- ElementSymbol x = TestElementImpl.helpIntExample("vm1.g1",
"e1"); //$NON-NLS-1$ //$NON-NLS-2$
- CaseExpression caseExpr = new CaseExpression(x,
TestCaseExpression.getWhenExpressions(3), TestCaseExpression.getThenExpressions(3));
- caseExpr.setElseExpression(x);
- return caseExpr;
- }
-
- public static CaseExpression helpExampleNullFirst() {
- ElementSymbol x = TestElementImpl.helpExample("vm1.g1",
"e1"); //$NON-NLS-1$ //$NON-NLS-2$
- CaseExpression caseExpr = new CaseExpression(x,
TestCaseExpression.getWhenExpressions(3, 0, true),
TestCaseExpression.getThenExpressions(3));
- caseExpr.setElseExpression(new Constant(new Integer(9999)));
- return caseExpr;
- }
-
- public static CaseExpression helpExampleNullMiddle() {
- ElementSymbol x = TestElementImpl.helpExample("vm1.g1",
"e1"); //$NON-NLS-1$ //$NON-NLS-2$
- CaseExpression caseExpr = new CaseExpression(x,
TestCaseExpression.getWhenExpressions(3, 1, true),
TestCaseExpression.getThenExpressions(3));
- caseExpr.setElseExpression(new Constant(new Integer(9999)));
- return caseExpr;
- }
-
- public static CaseExpression helpExampleNullLast() {
- ElementSymbol x = TestElementImpl.helpExample("vm1.g1",
"e1"); //$NON-NLS-1$ //$NON-NLS-2$
- CaseExpression caseExpr = new CaseExpression(x,
TestCaseExpression.getWhenExpressions(3, 2, true),
TestCaseExpression.getThenExpressions(3));
- caseExpr.setElseExpression(new Constant(new Integer(9999)));
- return caseExpr;
- }
-
- public static CaseExpressionImpl example() throws Exception {
- return
(CaseExpressionImpl)TstLanguageBridgeFactory.factory.translate(helpExample());
- }
-
- public static CaseExpressionImpl exampleElementElse() throws Exception {
- return
(CaseExpressionImpl)TstLanguageBridgeFactory.factory.translate(helpExampleElementElse());
- }
-
- public static CaseExpressionImpl exampleInteger() throws Exception {
- return
(CaseExpressionImpl)TstLanguageBridgeFactory.factory.translate(helpIntExample());
- }
-
- public static CaseExpressionImpl exampleNullFirst() throws Exception {
- return
(CaseExpressionImpl)TstLanguageBridgeFactory.factory.translate(helpExampleNullFirst());
- }
-
- public static CaseExpressionImpl exampleNullMiddle() throws Exception {
- return
(CaseExpressionImpl)TstLanguageBridgeFactory.factory.translate(helpExampleNullMiddle());
- }
-
- public static CaseExpressionImpl exampleNullLast() throws Exception {
- return
(CaseExpressionImpl)TstLanguageBridgeFactory.factory.translate(helpExampleNullLast());
- }
-
- public void testGetElseExpression() throws Exception {
- assertNotNull(example().getElseExpression());
- CaseExpression expr = helpExample();
- expr.setElseExpression(null);
-
assertNull(TstLanguageBridgeFactory.factory.translate(expr).getElseExpression());
- }
-
- public void testGetExpression() throws Exception {
- assertNotNull(example().getExpression());
- }
-
- public void testGetThenExpression() throws Exception {
- assertNotNull(example().getThenExpression(0));
- assertNotNull(example().getThenExpression(1));
- assertNotNull(example().getThenExpression(2));
- }
-
- public void testGetWhenCount() throws Exception {
- assertEquals(3, example().getWhenCount());
- }
-
- public void testGetWhenExpression() throws Exception {
- assertNotNull(example().getWhenExpression(0));
- assertNotNull(example().getWhenExpression(1));
- assertNotNull(example().getWhenExpression(2));
- }
-
- public void testGetWhenExpressionNullFirst() throws Exception {
- assertNotNull(exampleNullFirst().getWhenExpression(0));
- assertNotNull(exampleNullFirst().getWhenExpression(1));
- assertNotNull(exampleNullFirst().getWhenExpression(2));
-}
- public void testGetWhenExpressionNullMiddle() throws Exception {
- assertNotNull(exampleNullMiddle().getWhenExpression(0));
- assertNotNull(exampleNullMiddle().getWhenExpression(1));
- assertNotNull(exampleNullMiddle().getWhenExpression(2));
- }
-
- public void testGetWhenExpressionNullLast() throws Exception {
- assertNotNull(exampleNullLast().getWhenExpression(0));
- assertNotNull(exampleNullLast().getWhenExpression(1));
- assertNotNull(exampleNullLast().getWhenExpression(2));
- }
-
-}
Modified:
trunk/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/language/TestElementImpl.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/language/TestElementImpl.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/language/TestElementImpl.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -28,6 +28,7 @@
import com.metamatrix.connector.language.IElement;
import com.metamatrix.connector.language.IGroup;
import com.metamatrix.connector.metadata.runtime.MetadataID;
+import com.metamatrix.connector.metadata.runtime.MetadataID.Type;
import com.metamatrix.dqp.internal.datamgr.metadata.TestMetadataFactory;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.unittest.FakeMetadataObject;
@@ -106,7 +107,7 @@
public void testSetMetadataID() throws Exception {
Object metadataID =
TstLanguageBridgeFactory.metadata.getElementID("pm1.g1.e1"); //$NON-NLS-1$
ElementImpl element = example("pm1.g1", "e1", metadataID);
//$NON-NLS-1$ //$NON-NLS-2$
- MetadataID connID =
TstLanguageBridgeFactory.metadataFactory.createMetadataID(metadataID,
MetadataID.TYPE_ELEMENT);
+ MetadataID connID =
TstLanguageBridgeFactory.metadataFactory.createMetadataID(metadataID, Type.TYPE_ELEMENT);
element.setMetadataID(connID);
assertNotNull(element.getMetadataID());
assertEquals(connID, element.getMetadataID());
Modified:
trunk/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/language/TestInsertImpl.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/language/TestInsertImpl.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/language/TestInsertImpl.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -67,7 +67,7 @@
elements.add(TestElementImpl.helpExample(groupName, "e1"));
//$NON-NLS-1$
ArrayList values = new ArrayList();
- values.add(TestCaseExpressionImpl.helpExample());
+ values.add(TestSearchedCaseExpressionImpl.helpExample());
return new Insert(group,
elements,
Modified:
trunk/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/metadata/TestMetadataFactory.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/metadata/TestMetadataFactory.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/metadata/TestMetadataFactory.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -30,8 +30,8 @@
import junit.framework.TestCase;
import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.connector.metadata.runtime.MetadataID;
import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
+import com.metamatrix.connector.metadata.runtime.MetadataID.Type;
import com.metamatrix.query.unittest.FakeMetadataFacade;
import com.metamatrix.query.unittest.FakeMetadataObject;
import com.metamatrix.query.unittest.FakeMetadataStore;
@@ -108,12 +108,12 @@
public void testCreateMetadataID(){
try{
//test create MetadataID for Group
- MetadataIDImpl gID = (MetadataIDImpl)metadataFactory.createMetadataID(pm1g1,
MetadataID.TYPE_GROUP);
+ MetadataIDImpl gID = (MetadataIDImpl)metadataFactory.createMetadataID(pm1g1,
Type.TYPE_GROUP);
assertEquals(gID.getActualMetadataID(), pm1g1);
assertEquals(((MetadataIDImpl)gID.getChildIDs().get(0)).getActualMetadataID(), pm1g1e1);
//test create MetadataID for Element
- MetadataIDImpl eID =
(MetadataIDImpl)metadataFactory.createMetadataID(pm1g1e1, MetadataID.TYPE_ELEMENT);
+ MetadataIDImpl eID =
(MetadataIDImpl)metadataFactory.createMetadataID(pm1g1e1, Type.TYPE_ELEMENT);
assertEquals(eID.getActualMetadataID(), pm1g1e1);
assertEquals(((MetadataIDImpl)eID.getParentID()).getActualMetadataID(),
pm1g1);
}catch(Exception e){
@@ -124,13 +124,13 @@
public void testRuntimeMetadata(){
try{
- RuntimeMetadata runtimeMetadata = metadataFactory.createRuntimeMetadata();
- MetadataIDImpl gID = (MetadataIDImpl)metadataFactory.createMetadataID(pm1g1,
MetadataID.TYPE_GROUP);
+ RuntimeMetadata runtimeMetadata = metadataFactory.getRuntimeMetadata();
+ MetadataIDImpl gID = (MetadataIDImpl)metadataFactory.createMetadataID(pm1g1,
Type.TYPE_GROUP);
GroupImpl group = (GroupImpl)runtimeMetadata.getObject(gID);
assertEquals(group.getNameInSource(), "g1"); //$NON-NLS-1$
assertEquals(((MetadataIDImpl)group.getMetadataID()).getActualMetadataID(),
pm1g1);
- MetadataIDImpl eID =
(MetadataIDImpl)metadataFactory.createMetadataID(pm1g1e1, MetadataID.TYPE_ELEMENT);
+ MetadataIDImpl eID =
(MetadataIDImpl)metadataFactory.createMetadataID(pm1g1e1, Type.TYPE_ELEMENT);
ElementImpl element = (ElementImpl)runtimeMetadata.getObject(eID);
assertEquals(element.getLength(), 100);
assertEquals(element.getJavaType(),
DataTypeManager.DefaultDataClasses.STRING);
@@ -145,7 +145,7 @@
public void testGetVDBResourcePaths() {
String[] expectedPaths = new String[] {"my/resource/path"};
//$NON-NLS-1$
try {
- RuntimeMetadata runtimeMetadata = metadataFactory.createRuntimeMetadata();
+ RuntimeMetadata runtimeMetadata = metadataFactory.getRuntimeMetadata();
String[] mfPaths = metadataFactory.getVDBResourcePaths();
String[] rtmdPaths = runtimeMetadata.getVDBResourcePaths();
assertEquals(expectedPaths.length, mfPaths.length);
@@ -162,7 +162,7 @@
public void testGetBinaryVDBResource() {
try {
- RuntimeMetadata runtimeMetadata = metadataFactory.createRuntimeMetadata();
+ RuntimeMetadata runtimeMetadata = metadataFactory.getRuntimeMetadata();
byte[] expectedBytes = "ResourceContents".getBytes();
//$NON-NLS-1$
byte[] mfBytes = metadataFactory.getBinaryVDBResource(null);
byte[] rtmdBytes = runtimeMetadata.getBinaryVDBResource(null);
@@ -180,7 +180,7 @@
public void testGetCharacterVDBResource() {
try {
- RuntimeMetadata runtimeMetadata = metadataFactory.createRuntimeMetadata();
+ RuntimeMetadata runtimeMetadata = metadataFactory.getRuntimeMetadata();
assertEquals("ResourceContents",
metadataFactory.getCharacterVDBResource(null)); //$NON-NLS-1$
assertEquals("ResourceContents",
runtimeMetadata.getCharacterVDBResource(null)); //$NON-NLS-1$
} catch (Exception e) {
Modified: trunk/engine/src/test/java/com/metamatrix/query/function/TestFunction.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/function/TestFunction.java 2009-02-16
21:35:28 UTC (rev 475)
+++ trunk/engine/src/test/java/com/metamatrix/query/function/TestFunction.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -112,8 +112,8 @@
assertEquals("Didn't get expected result from lpad", expected,
actual); //$NON-NLS-1$
}
- public static void helpTestLpad(String input, int length, char c, String expected)
throws FunctionExecutionException {
- String actual = (String) FunctionMethods.lpad(input, new Integer(length), new
Character(c));
+ public static void helpTestLpad(String input, int length, String pad, String
expected) throws FunctionExecutionException {
+ String actual = (String) FunctionMethods.lpad(input, new Integer(length), pad);
assertEquals("Didn't get expected result from lpad", expected,
actual); //$NON-NLS-1$
}
@@ -122,8 +122,8 @@
assertEquals("Didn't get expected result from rpad", expected,
actual); //$NON-NLS-1$
}
- public static void helpTestRpad(String input, int length, char c, String expected)
throws FunctionExecutionException {
- String actual = (String) FunctionMethods.rpad(input, new Integer(length), new
Character(c));
+ public static void helpTestRpad(String input, int length, String c, String expected)
throws FunctionExecutionException {
+ String actual = (String) FunctionMethods.rpad(input, new Integer(length), c);
assertEquals("Didn't get expected result from rpad", expected,
actual); //$NON-NLS-1$
}
@@ -519,152 +519,6 @@
helpConvert(ts, "string", "2003-08-22 22:43:53.003333333");
//$NON-NLS-1$ //$NON-NLS-2$
}
- /*
- * Test for Object decodeInteger(Object, Object)
- */
- public void testDecodeIntegerObjectObject() throws FunctionExecutionException {
- decodeIntegerTests(null);
- }
-
-
- /*
- * Test for Object decodeString(Object, Object)
- */
- public void testDecodeStringObjectObject() throws FunctionExecutionException {
- decodeStringTests(null);
- }
-
- /*
- * Test for Object decodeInteger(Object, Object, Object)
- */
- public void testDecodeIntegerObjectObjectObject() throws FunctionExecutionException
{
- decodeIntegerTests(","); //$NON-NLS-1$
-
- }
-
- /*
- * Test for Object decodeString(Object, Object, Object)
- */
- public void testDecodeStringObjectObjectObject() throws FunctionExecutionException {
- decodeStringTests(","); //$NON-NLS-1$
- }
-
- private void decodeStringTests(String delimiter) throws FunctionExecutionException {
- String decodeString = "a,1,b,2,c, 3, 8"; //$NON-NLS-1$
-
- String columnValue = "a"; //$NON-NLS-1$
- String expectedResult = "1"; //$NON-NLS-1$
- runDecodeStringTest(columnValue, decodeString, expectedResult, delimiter);
-
- columnValue = "b"; //$NON-NLS-1$
- expectedResult = "2"; //$NON-NLS-1$
- runDecodeStringTest(columnValue, decodeString, expectedResult, delimiter);
-
- columnValue = "g"; //$NON-NLS-1$
- expectedResult = "8"; //$NON-NLS-1$
- runDecodeStringTest(columnValue, decodeString, expectedResult, delimiter);
-
- decodeString = decodeString.substring(0, decodeString.length() - 3);
- columnValue = "6"; //$NON-NLS-1$
- expectedResult = "6"; //$NON-NLS-1$
- runDecodeStringTest(columnValue, decodeString, expectedResult, delimiter);
-
- decodeString = "a,1,null,2, g,5"; //$NON-NLS-1$
- columnValue = null;
- expectedResult = "2"; //$NON-NLS-1$
- runDecodeStringTest(columnValue, decodeString, expectedResult, delimiter);
-
- columnValue = "8"; //$NON-NLS-1$
- expectedResult = "8"; //$NON-NLS-1$
- runDecodeStringTest(columnValue, decodeString, expectedResult, delimiter);
-
- decodeString = "'a', 1, ' b', 2, 'c',
'3'"; //$NON-NLS-1$
- columnValue = "c"; //$NON-NLS-1$
- expectedResult = "3"; //$NON-NLS-1$
- runDecodeStringTest(columnValue, decodeString, expectedResult, delimiter);
-
- decodeString = "' ', 1, 'b', 2, 'c',
'3'"; //$NON-NLS-1$
- columnValue = " "; //$NON-NLS-1$
- expectedResult = "1"; //$NON-NLS-1$
- runDecodeStringTest(columnValue, decodeString, expectedResult, delimiter);
- }
-
- private void decodeIntegerTests(String delimiter) throws FunctionExecutionException
{
-
- String decodeString = "a,1,b,2,c, 3, 8"; //$NON-NLS-1$
-
- String columnValue = "a"; //$NON-NLS-1$
- Integer expectedResult = new Integer(1);
- runDecodeIntegerTest(columnValue, decodeString, expectedResult, delimiter);
-
- columnValue = "b"; //$NON-NLS-1$
- expectedResult = new Integer(2);
- runDecodeIntegerTest(columnValue, decodeString, expectedResult, delimiter);
-
- columnValue = "g"; //$NON-NLS-1$
- expectedResult = new Integer(8);
- runDecodeIntegerTest(columnValue, decodeString, expectedResult, delimiter);
-
- decodeString = decodeString.substring(0, decodeString.length() - 3);
- columnValue = "6"; //$NON-NLS-1$
- expectedResult = new Integer(6);
- runDecodeIntegerTest(columnValue, decodeString, expectedResult, delimiter);
-
- decodeString = "a,1,null,2, g,5"; //$NON-NLS-1$
- columnValue = null;
- expectedResult = new Integer(2);
- runDecodeIntegerTest(columnValue, decodeString, expectedResult, delimiter);
-
- columnValue = "8"; //$NON-NLS-1$
- expectedResult = new Integer(8);
- runDecodeIntegerTest(columnValue, decodeString, expectedResult, delimiter);
-
- decodeString = "'a', 1, ' b', 2, 'c',
'3'"; //$NON-NLS-1$
- columnValue = "c"; //$NON-NLS-1$
- expectedResult = new Integer(3);
- runDecodeIntegerTest(columnValue, decodeString, expectedResult, delimiter);
-
- Integer intColumnValue = new Integer(12);
- expectedResult = new Integer(12);
- runDecodeIntegerTest(intColumnValue, decodeString, expectedResult, delimiter);
-
-
- }
-
- private void runDecodeIntegerTest(Object columnValue,
- String decodeString,
- Object expectedResult,
- String delimiter) throws FunctionExecutionException
{
- Object result = null;
- if (delimiter == null) {
- result = FunctionMethods.decodeInteger(columnValue, decodeString);
- } else {
- result = FunctionMethods.decodeInteger(columnValue, decodeString,
delimiter);
- }
-
- assertEquals("Decode did not properly translate column value: " +
columnValue, //$NON-NLS-1$
- expectedResult,
- result);
-
- }
-
- private void runDecodeStringTest(Object columnValue,
- String decodeString,
- Object expectedResult,
- String delimiter) throws FunctionExecutionException
{
- Object result = null;
- if (delimiter == null) {
- result = FunctionMethods.decodeString(columnValue, decodeString);
- } else {
- result = FunctionMethods.decodeString(columnValue, decodeString, delimiter);
- }
-
- assertEquals("Decode did not properly translate column value: " +
columnValue, //$NON-NLS-1$
- expectedResult,
- result);
-
- }
-
public void testAscii1() throws FunctionExecutionException {
Integer code = (Integer) FunctionMethods.ascii(new Character(' '));
assertEquals("Didn't get expected code", 32, code.intValue());
//$NON-NLS-1$
@@ -704,17 +558,17 @@
}
public void testNvl1() {
- String ret = (String) FunctionMethods.nvl("x", "y");
//$NON-NLS-1$ //$NON-NLS-2$
+ String ret = (String) FunctionMethods.ifnull("x", "y");
//$NON-NLS-1$ //$NON-NLS-2$
assertEquals("Didn't get expected value", "x", ret);
//$NON-NLS-1$ //$NON-NLS-2$
}
public void testNvl2() {
- String ret = (String) FunctionMethods.nvl(null, "y"); //$NON-NLS-1$
+ String ret = (String) FunctionMethods.ifnull(null, "y"); //$NON-NLS-1$
assertEquals("Didn't get expected value", "y", ret);
//$NON-NLS-1$ //$NON-NLS-2$
}
public void testNvl3() {
- String ret = (String) FunctionMethods.nvl(null, null);
+ String ret = (String) FunctionMethods.ifnull(null, null);
assertEquals("Didn't get expected value", null, ret);
//$NON-NLS-1$
}
@@ -751,16 +605,20 @@
}
public void testLpad4() throws FunctionExecutionException {
- helpTestLpad("xx", 1, "xx"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTestLpad("xx", 1, "x"); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testLpad5() throws FunctionExecutionException {
- helpTestLpad("", 4, 'x', "xxxx"); //$NON-NLS-1$
//$NON-NLS-2$
+ helpTestLpad("", 4, "x", "xxxx"); //$NON-NLS-1$
//$NON-NLS-2$
}
public void testLpad6() throws FunctionExecutionException {
- helpTestLpad("10", 6, '0', "000010"); //$NON-NLS-1$
//$NON-NLS-2$
+ helpTestLpad("10", 6, "0", "000010"); //$NON-NLS-1$
//$NON-NLS-2$
}
+
+ public void testLpad7() throws FunctionExecutionException {
+ helpTestLpad("x", 4, "yq", "qyqx" ); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
public void testRpad1() throws FunctionExecutionException {
helpTestRpad("x", 4, "x "); //$NON-NLS-1$ //$NON-NLS-2$
@@ -775,15 +633,15 @@
}
public void testRpad4() throws FunctionExecutionException {
- helpTestRpad("xx", 1, "xx"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTestRpad("xx", 1, "x"); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testRpad5() throws FunctionExecutionException {
- helpTestRpad("", 4, 'x', "xxxx"); //$NON-NLS-1$
//$NON-NLS-2$
+ helpTestRpad("", 4, "x", "xxxx"); //$NON-NLS-1$
//$NON-NLS-2$
}
public void testRpad6() throws FunctionExecutionException {
- helpTestRpad("10", 6, '0', "100000"); //$NON-NLS-1$
//$NON-NLS-2$
+ helpTestRpad("10", 6, "0", "100000"); //$NON-NLS-1$
//$NON-NLS-2$
}
public void testTranslate1() throws FunctionExecutionException {
Modified:
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -123,7 +123,7 @@
private void helpFindFunction(String fname, Class[] types, FunctionDescriptor expected)
{
FunctionDescriptor actual = library.findFunction(fname, types);
- assertEquals("Function names do not match: ", expected.getName(),
actual.getName()); //$NON-NLS-1$
+ assertEquals("Function names do not match: ",
expected.getName().toLowerCase(), actual.getName().toLowerCase());
//$NON-NLS-1$
assertEquals("Arg lengths do not match: ", expected.getTypes().length,
actual.getTypes().length); //$NON-NLS-1$
}
@@ -731,24 +731,17 @@
}
public void testInvokeLpad2() {
- helpInvokeMethod("lpad", new Object[] { "x", new Integer(3),
new Character('y') }, "yyx" ); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
+ helpInvokeMethod("lpad", new Object[] { "x", new Integer(3),
"y" }, "yyx" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
-
- public void testInvokeLpad3() {
- helpInvokeMethod("lpad", new Object[] { "x", new Integer(3),
"y" }, "yyx" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
- }
-
+
public void testInvokeRpad1() {
helpInvokeMethod("rpad", new Object[] { "x", new Integer(3)
}, "x " ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
public void testInvokeRpad2() {
- helpInvokeMethod("rpad", new Object[] { "x", new Integer(3),
new Character('y') }, "xyy" ); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
+ helpInvokeMethod("rpad", new Object[] { "x", new Integer(3),
"y" }, "xyy" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- public void testInvokeRpad3() {
- helpInvokeMethod("rpad", new Object[] { "x", new Integer(3),
"y" }, "xyy" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
- }
public void testInvokeTranslate() {
helpInvokeMethod("translate", new Object[] { "ababcd",
"ad", "da" }, "dbdbca" ); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
}
@@ -1021,10 +1014,6 @@
helpInvokeMethod("repeat", new Object[] {new String("cat"), new
Integer(3)}, new String("catcatcat")); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
}
- public void testInvokeSpace() {
- helpInvokeMethod("space", new Object[] {new Integer(3)}, new String("
")); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
public void testInvokeChar() {
helpInvokeMethod("char", new Object[] {new Integer(32) }, new Character('
')); //$NON-NLS-1$
}
@@ -1207,51 +1196,7 @@
tsUtil.createTime(23, 59,
59)},
tsUtil.createTimestamp(103, 4,
15, 23, 59, 59, 0));
}
-
- /** decodeInteger */
- public void testInvokeDecode1() {
- helpInvokeMethod("decodeInteger", new Object[] {"integer",
"integer, 4", ","}, new Integer(4)); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$
- }
-
- public void testInvokeDecode2() {
- helpInvokeMethod("decodeString", new Object[] {"string",
"string, 12, integer, 4", ","}, "12");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
- public void testInvokeDecode3() {
- helpInvokeMethod("decodeString", new Object[] {"Not
Nullable", "Not Nullable, 1, Nullable, 2, Unknown, 3", ","},
"1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- helpInvokeMethod("convert", new Object[] {"1",
"integer"}, new Integer(1));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testInvokeDecode4() {
- helpInvokeMethod("decodeString", new Object[] {"Unknown",
"Not Nullable, YES, Nullable, NO, Unknown, ' '", ","}, "
"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
-
- public void testInvokeDecode5() {
- helpInvokeMethod("decodeString", new Object[] {"true",
"true, 2, false, 1"}, new String("2")); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$
- helpInvokeMethod("convert", new Object[] {"2",
"short"}, new Short((short)2)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testInvokeDecode6() {
- helpInvokeMethod("decodeString", new Object[] {"string",
"char, \', string, \""}, "\""); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- }
-
- public void testInvokeDecode7() {
- helpInvokeMethod("decodeString", new Object[] {"Searchable",
"Searchable, 3, All Except Like, 2, Like Only, 1, Unsearchable, 0"}, new
String("3")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- helpInvokeMethod("convert", new Object[] {"3",
"short"}, new Short((short)3)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testInvokeDecode8() {
- helpInvokeMethod("decodeString", new Object[] {"true",
"true, 2, false, 1"}, new String("2")); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$
- helpInvokeMethod("decodeString", new Object[] {"2", "2,
false, 1, true"}, new String("false")); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$
- helpInvokeMethod("convert", new Object[] {"false",
"boolean"}, new Boolean(false)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- helpInvokeMethod("convert", new Object[] {"true",
"boolean"}, new Boolean(true)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testInvokeDecode9() {
- helpInvokeMethod("decodeString", new Object[] {"JAVA_OBJECT",
"JAVA_OBJECT,2000 , DISTINCT, 2001, STRUCT, 2002"}, new
String("2000")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- helpInvokeMethod("convert", new Object[] {"2000",
"integer"}, new Integer(2000)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
public void testInvokeBitand() {
helpInvokeMethod("bitand", new Object[] {new Integer(0xFFF), new
Integer(0x0F0)}, new Integer(0x0F0)); //$NON-NLS-1$
}
Modified:
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinOptimization.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinOptimization.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinOptimization.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -31,6 +31,7 @@
import com.metamatrix.api.exception.query.QueryMetadataException;
import com.metamatrix.api.exception.query.QueryParserException;
import com.metamatrix.api.exception.query.QueryResolverException;
+import com.metamatrix.connector.api.SourceSystemFunctions;
import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
@@ -936,7 +937,7 @@
caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
caps.setCapabilitySupport(Capability.FUNCTION, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
- caps.setFunctionSupport("nvl", true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.IFNULL, true); //$NON-NLS-1$
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
@@ -944,7 +945,7 @@
ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata,
null, capFinder,
new String[] {
- "SELECT v_0.c_0 FROM pm1.g1 AS g_0 LEFT
OUTER JOIN (SELECT nvl(g_1.e2, 1) AS c_0 FROM pm1.g2 AS g_1) AS v_0 ON g_0.e2 =
v_0.c_0" }, //$NON-NLS-1$
+ "SELECT v_0.c_0 FROM pm1.g1 AS g_0 LEFT
OUTER JOIN (SELECT ifnull(g_1.e2, 1) AS c_0 FROM pm1.g2 AS g_1) AS v_0 ON g_0.e2 =
v_0.c_0" }, //$NON-NLS-1$
TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java 2009-02-16
21:35:28 UTC (rev 475)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -266,7 +266,7 @@
String sql = "SELECT * FROM pm1.g1 limit 50, 100";//$NON-NLS-1$
String[] expectedSql = new String[] {
- "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 LIMIT
(100 + 50)" //$NON-NLS-1$
+ "SELECT pm1.g1.e1 AS c_0, pm1.g1.e2 AS c_1, pm1.g1.e3 AS c_2, pm1.g1.e4
AS c_3 FROM pm1.g1 LIMIT (100 + 50)" //$NON-NLS-1$
};
ProcessorPlan plan = TestOptimizer.helpPlan(sql,
FakeMetadataFactory.example1Cached(),
null, capFinder, expectedSql,
TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
@@ -532,7 +532,7 @@
String sql = "SELECT * FROM pm1.g1 UNION SELECT * FROM PM1.g2 LIMIT 50,
100";//$NON-NLS-1$
String[] expectedSql = new String[] {
- "SELECT PM1.g2.e1, PM1.g2.e2, PM1.g2.e3, PM1.g2.e4 FROM PM1.g2 LIMIT
(100 + 50)", "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1
LIMIT (100 + 50)" //$NON-NLS-1$ //$NON-NLS-2$
+ "SELECT PM1.g2.e1 AS c_0, PM1.g2.e2 AS c_1, PM1.g2.e3 AS c_2, PM1.g2.e4
AS c_3 FROM PM1.g2 LIMIT (100 + 50)", "SELECT pm1.g1.e1 AS c_0, pm1.g1.e2 AS
c_1, pm1.g1.e3 AS c_2, pm1.g1.e4 AS c_3 FROM pm1.g1 LIMIT (100 + 50)" //$NON-NLS-1$
//$NON-NLS-2$
};
ProcessorPlan plan = TestOptimizer.helpPlan(sql,
FakeMetadataFactory.example1Cached(),
null, capFinder, expectedSql,
TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
@@ -598,7 +598,7 @@
String sql = "SELECT * from (SELECT pm1.g1.e1 FROM pm1.g1 LIMIT 10, 100) x
LIMIT 20, 75";//$NON-NLS-1$
String[] expectedSql = new String[] {
- "SELECT pm1.g1.e1 FROM pm1.g1 LIMIT CASE WHEN (75 + (20 + 10)) < (100
+ 10) THEN (75 + (20 + 10)) ELSE (100 + 10) END" //$NON-NLS-1$
+ "SELECT pm1.g1.e1 AS c_0 FROM pm1.g1 LIMIT CASE WHEN (75 + (20 + 10))
< (100 + 10) THEN (75 + (20 + 10)) ELSE (100 + 10) END" //$NON-NLS-1$
};
ProcessorPlan plan = TestOptimizer.helpPlan(sql,
FakeMetadataFactory.example1Cached(),
null, capFinder, expectedSql,
TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
@@ -632,7 +632,7 @@
String sql = "SELECT * from (SELECT pm1.g1.e1 FROM pm1.g1 LIMIT 10, 100) x
LIMIT 20, 75";//$NON-NLS-1$
String[] expectedSql = new String[] {
- "SELECT pm1.g1.e1 FROM pm1.g1 LIMIT (20 + 10), CASE WHEN 75 < 100
THEN 75 ELSE 100 END" //$NON-NLS-1$
+ "SELECT pm1.g1.e1 AS c_0 FROM pm1.g1 LIMIT (20 + 10), CASE WHEN 75 <
100 THEN 75 ELSE 100 END" //$NON-NLS-1$
};
ProcessorPlan plan = TestOptimizer.helpPlan(sql,
FakeMetadataFactory.example1Cached(),
null, capFinder, expectedSql,
TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -39,6 +39,7 @@
import com.metamatrix.api.exception.query.QueryResolverException;
import com.metamatrix.api.exception.query.QueryValidatorException;
import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.connector.api.SourceSystemFunctions;
import com.metamatrix.core.MetaMatrixRuntimeException;
import com.metamatrix.query.analysis.AnalysisRecord;
import com.metamatrix.query.mapping.relational.QueryNode;
@@ -2505,7 +2506,7 @@
caps.setCapabilitySupport(Capability.QUERY_WHERE_COMPARE, true);
caps.setCapabilitySupport(Capability.QUERY_WHERE_COMPARE_EQ, true);
caps.setCapabilitySupport(Capability.FUNCTION, true);
- caps.setFunctionSupport("upper", true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); //$NON-NLS-1$
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
// Add join capability to pm1
@@ -2515,7 +2516,7 @@
"SELECT e1 FROM pm1.g1 WHERE upper(e1) = 'X'",
//$NON-NLS-1$
metadata,
null, capFinder,
- new String[] {"SELECT e1 FROM pm1.g1 WHERE upper(e1) =
'X'"}, //$NON-NLS-1$
+ new String[] {"SELECT e1 FROM pm1.g1 WHERE ucase(e1) =
'X'"}, //$NON-NLS-1$
SHOULD_SUCCEED );
checkNodeTypes(plan, FULL_PUSHDOWN);
@@ -2528,8 +2529,8 @@
caps.setCapabilitySupport(Capability.QUERY_WHERE_COMPARE, true);
caps.setCapabilitySupport(Capability.QUERY_WHERE_COMPARE_EQ, true);
caps.setCapabilitySupport(Capability.FUNCTION, true);
- caps.setFunctionSupport("upper", true); //$NON-NLS-1$
- caps.setFunctionSupport("lower", true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.LCASE, true); //$NON-NLS-1$
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
// Add join capability to pm1
@@ -2539,7 +2540,7 @@
"SELECT lower(e1) FROM pm1.g1 WHERE upper(e1) = 'X'",
//$NON-NLS-1$
metadata,
null, capFinder,
- new String[] {"SELECT lower(e1) FROM pm1.g1 WHERE upper(e1) =
'X'"}, //$NON-NLS-1$
+ new String[] {"SELECT lower(e1) FROM pm1.g1 WHERE ucase(e1) =
'X'"}, //$NON-NLS-1$
SHOULD_SUCCEED );
checkNodeTypes(plan, FULL_PUSHDOWN);
@@ -2552,8 +2553,8 @@
caps.setCapabilitySupport(Capability.QUERY_WHERE_COMPARE, true);
caps.setCapabilitySupport(Capability.QUERY_WHERE_COMPARE_EQ, true);
caps.setCapabilitySupport(Capability.FUNCTION, true);
- caps.setFunctionSupport("upper", true); //$NON-NLS-1$
- caps.setFunctionSupport("lower", true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.LCASE, true); //$NON-NLS-1$
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
// Add join capability to pm1
@@ -2563,7 +2564,7 @@
"SELECT lower(e1), upper(e1), e2 FROM pm1.g1 WHERE upper(e1) =
'X'", //$NON-NLS-1$
metadata,
null, capFinder,
- new String[] {"SELECT lower(e1), upper(e1), e2 FROM pm1.g1 WHERE
upper(e1) = 'X'"}, //$NON-NLS-1$
+ new String[] {"SELECT lower(e1), upper(e1), e2 FROM pm1.g1 WHERE
ucase(e1) = 'X'"}, //$NON-NLS-1$
SHOULD_SUCCEED );
checkNodeTypes(plan, FULL_PUSHDOWN);
@@ -2576,8 +2577,8 @@
caps.setCapabilitySupport(Capability.QUERY_WHERE_COMPARE, true);
caps.setCapabilitySupport(Capability.QUERY_WHERE_COMPARE_EQ, true);
caps.setCapabilitySupport(Capability.FUNCTION, true);
- caps.setFunctionSupport("upper", true); //$NON-NLS-1$
- caps.setFunctionSupport("lower", false); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.LCASE, false); //$NON-NLS-1$
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
// Add join capability to pm1
@@ -2587,7 +2588,7 @@
"SELECT lower(e1), upper(e1) FROM pm1.g1 WHERE upper(e1) =
'X'", //$NON-NLS-1$
metadata,
null, capFinder,
- new String[] {"SELECT e1 FROM pm1.g1 WHERE upper(e1) =
'X'"}, //$NON-NLS-1$
+ new String[] {"SELECT e1 FROM pm1.g1 WHERE ucase(e1) =
'X'"}, //$NON-NLS-1$
SHOULD_SUCCEED );
checkNodeTypes(plan, new int[] {
@@ -2615,8 +2616,8 @@
caps.setCapabilitySupport(Capability.QUERY_WHERE_COMPARE, true);
caps.setCapabilitySupport(Capability.QUERY_WHERE_COMPARE_EQ, true);
caps.setCapabilitySupport(Capability.FUNCTION, true);
- caps.setFunctionSupport("upper", true); //$NON-NLS-1$
- caps.setFunctionSupport("lower", true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.LCASE, true); //$NON-NLS-1$
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
// Add join capability to pm1
@@ -2626,7 +2627,7 @@
"SELECT x FROM (SELECT lower(e1) AS x, upper(e1) AS y FROM pm1.g1 WHERE
upper(e1) = 'X') AS z", //$NON-NLS-1$
metadata,
null, capFinder,
- new String[] {"SELECT lower(e1) FROM pm1.g1 WHERE upper(e1) =
'X'"}, //$NON-NLS-1$
+ new String[] {"SELECT lcase(e1) FROM pm1.g1 WHERE ucase(e1) =
'X'"}, //$NON-NLS-1$
SHOULD_SUCCEED );
checkNodeTypes(plan, FULL_PUSHDOWN);
@@ -2639,8 +2640,8 @@
caps.setCapabilitySupport(Capability.QUERY_WHERE_COMPARE, true);
caps.setCapabilitySupport(Capability.QUERY_WHERE_COMPARE_EQ, true);
caps.setCapabilitySupport(Capability.FUNCTION, true);
- caps.setFunctionSupport("upper", true); //$NON-NLS-1$
- caps.setFunctionSupport("lower", true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.LCASE, true); //$NON-NLS-1$
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
// Add join capability to pm1
@@ -2650,7 +2651,7 @@
"SELECT y, e, x FROM (SELECT lower(e1) AS x, upper(e1) AS y, 5 as z, e1
AS e FROM pm1.g1 WHERE upper(e1) = 'X') AS w", //$NON-NLS-1$
metadata,
null, capFinder,
- new String[] {"SELECT upper(e1), e1, lower(e1) FROM pm1.g1 WHERE
upper(e1) = 'X'"}, //$NON-NLS-1$
+ new String[] {"SELECT ucase(e1), e1, lcase(e1) FROM pm1.g1 WHERE
ucase(e1) = 'X'"}, //$NON-NLS-1$
SHOULD_SUCCEED );
checkNodeTypes(plan, FULL_PUSHDOWN);
@@ -2700,8 +2701,8 @@
caps.setCapabilitySupport(Capability.QUERY_WHERE_COMPARE_EQ, true);
caps.setCapabilitySupport(Capability.FUNCTION, true);
caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
- caps.setFunctionSupport("upper", true); //$NON-NLS-1$
- caps.setFunctionSupport("lower", true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.LCASE, true); //$NON-NLS-1$
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
// Add join capability to pm1
@@ -2711,7 +2712,7 @@
"SELECT e1, lower(e1) FROM pm1.g1 WHERE upper(e1) = 'X' ORDER BY
e1", //$NON-NLS-1$
metadata,
null, capFinder,
- new String[] {"SELECT e1, lower(e1) FROM pm1.g1 WHERE upper(e1) =
'X' ORDER BY e1"}, //$NON-NLS-1$
+ new String[] {"SELECT e1, lcase(e1) FROM pm1.g1 WHERE ucase(e1) =
'X' ORDER BY e1"}, //$NON-NLS-1$
SHOULD_SUCCEED );
checkNodeTypes(plan, FULL_PUSHDOWN);
@@ -2726,8 +2727,8 @@
caps.setCapabilitySupport(Capability.QUERY_WHERE_COMPARE_EQ, true);
caps.setCapabilitySupport(Capability.FUNCTION, true);
caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
- caps.setFunctionSupport("upper", true); //$NON-NLS-1$
- caps.setFunctionSupport("lower", true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.LCASE, true); //$NON-NLS-1$
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
// Add join capability to pm1
@@ -2737,7 +2738,7 @@
"SELECT e1, lower(e1) AS x FROM pm1.g1 WHERE upper(e1) = 'X'
ORDER BY x", //$NON-NLS-1$
metadata,
null, capFinder,
- new String[] {"SELECT e1, lower(e1) AS x FROM pm1.g1 WHERE upper(e1) =
'X' ORDER BY x"}, //$NON-NLS-1$
+ new String[] {"SELECT e1, lcase(e1) AS x FROM pm1.g1 WHERE ucase(e1) =
'X' ORDER BY x"}, //$NON-NLS-1$
SHOULD_SUCCEED );
checkNodeTypes(plan, FULL_PUSHDOWN);
@@ -2752,8 +2753,8 @@
caps.setCapabilitySupport(Capability.QUERY_WHERE_COMPARE_EQ, true);
caps.setCapabilitySupport(Capability.FUNCTION, true);
caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
- caps.setFunctionSupport("upper", true); //$NON-NLS-1$
- caps.setFunctionSupport("lower", true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.LCASE, true); //$NON-NLS-1$
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
// Add join capability to pm1
@@ -2763,7 +2764,7 @@
"SELECT e1, x FROM (SELECT e1, lower(e1) AS x FROM pm1.g1 WHERE
upper(e1) = 'X') AS z ORDER BY x", //$NON-NLS-1$
metadata,
null, capFinder,
- new String[] {"SELECT e1, lower(e1) AS EXPR FROM pm1.g1 WHERE upper(e1)
= 'X' ORDER BY EXPR"}, //$NON-NLS-1$
+ new String[] {"SELECT e1, lcase(e1) AS EXPR FROM pm1.g1 WHERE ucase(e1)
= 'X' ORDER BY EXPR"}, //$NON-NLS-1$
SHOULD_SUCCEED );
checkNodeTypes(plan, FULL_PUSHDOWN);
@@ -2777,7 +2778,7 @@
caps.setCapabilitySupport(Capability.QUERY_WHERE_COMPARE_EQ, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN, true);
caps.setCapabilitySupport(Capability.FUNCTION, true);
- caps.setFunctionSupport("upper", true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); //$NON-NLS-1$
caps.setFunctionSupport("convert", true); //$NON-NLS-1$
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
@@ -2788,7 +2789,7 @@
"SELECT pm1.g1.e1, pm1.g2.e3 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e1 =
convert(pm1.g2.e2, string) AND upper(pm1.g1.e1) = 'X'", //$NON-NLS-1$
metadata,
null, capFinder,
- new String[] {"SELECT pm1.g1.e1, pm1.g2.e3 FROM pm1.g1, pm1.g2 WHERE
(pm1.g1.e1 = convert(pm1.g2.e2, string)) AND (upper(pm1.g1.e1) = 'X') AND
(upper(convert(pm1.g2.e2, string)) = 'X')"}, //$NON-NLS-1$
+ new String[] {"SELECT pm1.g1.e1, pm1.g2.e3 FROM pm1.g1, pm1.g2 WHERE
(pm1.g1.e1 = convert(pm1.g2.e2, string)) AND (ucase(pm1.g1.e1) = 'X') AND
(ucase(convert(pm1.g2.e2, string)) = 'X')"}, //$NON-NLS-1$
SHOULD_SUCCEED );
checkNodeTypes(plan, FULL_PUSHDOWN);
@@ -2802,7 +2803,7 @@
caps.setCapabilitySupport(Capability.QUERY_WHERE_COMPARE_EQ, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN, true);
caps.setCapabilitySupport(Capability.FUNCTION, true);
- caps.setFunctionSupport("upper", true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); //$NON-NLS-1$
caps.setFunctionSupport("convert", true); //$NON-NLS-1$
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
@@ -2813,7 +2814,7 @@
"SELECT pm1.g1.e1, pm1.g2.e3 FROM pm1.g1, pm1.g2, pm1.g3 WHERE pm1.g1.e1
= convert(pm1.g2.e2, string) AND pm1.g1.e1 = concat(pm1.g3.e1, 'a') AND
upper(pm1.g1.e1) = 'X'", //$NON-NLS-1$
metadata,
null, capFinder,
- new String[] {"SELECT pm1.g1.e1, pm1.g2.e3 FROM pm1.g1, pm1.g2 WHERE
(pm1.g1.e1 = convert(pm1.g2.e2, string)) AND (upper(pm1.g1.e1) = 'X') AND
(upper(convert(pm1.g2.e2, string)) = 'X')", //$NON-NLS-1$
+ new String[] {"SELECT pm1.g1.e1, pm1.g2.e3 FROM pm1.g1, pm1.g2 WHERE
(pm1.g1.e1 = convert(pm1.g2.e2, string)) AND (ucase(pm1.g1.e1) = 'X') AND
(ucase(convert(pm1.g2.e2, string)) = 'X')", //$NON-NLS-1$
"SELECT pm1.g3.e1 FROM pm1.g3"}, //$NON-NLS-1$
SHOULD_SUCCEED );
@@ -2843,7 +2844,7 @@
caps.setCapabilitySupport(Capability.QUERY_WHERE_COMPARE_EQ, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN, true);
caps.setCapabilitySupport(Capability.FUNCTION, true);
- caps.setFunctionSupport("upper", true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); //$NON-NLS-1$
caps.setFunctionSupport("convert", true); //$NON-NLS-1$
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
@@ -2854,7 +2855,7 @@
"SELECT pm1.g1.e1, pm1.g2.e3 FROM pm1.g1, pm1.g2, (SELECT e1 AS x FROM
pm1.g3) AS g WHERE pm1.g1.e1 = convert(pm1.g2.e2, string) AND pm1.g1.e1 = concat(g.x,
'a') AND upper(pm1.g1.e1) = 'X'", //$NON-NLS-1$
metadata,
null, capFinder,
- new String[] {"SELECT pm1.g1.e1, pm1.g2.e3 FROM pm1.g1, pm1.g2 WHERE
(pm1.g1.e1 = convert(pm1.g2.e2, string)) AND (upper(pm1.g1.e1) = 'X') AND
(upper(convert(pm1.g2.e2, string)) = 'X')", //$NON-NLS-1$
+ new String[] {"SELECT pm1.g1.e1, pm1.g2.e3 FROM pm1.g1, pm1.g2 WHERE
(pm1.g1.e1 = convert(pm1.g2.e2, string)) AND (ucase(pm1.g1.e1) = 'X') AND
(ucase(convert(pm1.g2.e2, string)) = 'X')", //$NON-NLS-1$
"SELECT e1 FROM pm1.g3"}, //$NON-NLS-1$
SHOULD_SUCCEED );
@@ -3508,7 +3509,7 @@
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
caps.setCapabilitySupport(Capability.FUNCTION, true);
- caps.setFunctionSupport("||", true); //$NON-NLS-1$
+ caps.setFunctionSupport(SourceSystemFunctions.CONCAT, true); //$NON-NLS-1$
caps.setFunctionSupport("convert", true); //$NON-NLS-1$
capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
@@ -7156,7 +7157,7 @@
ProcessorPlan plan = helpPlan("select * from (select v1.e1, v2.e1 as e1_1,
v1.e2, v2.e2 as e2_2 from (select * from vm1.g7 where vm1.g7.e2 = 1) v1 left outer join
(select * from vm1.g7 where vm1.g7.e2 = 1) v2 on v1.e2 = v2.e2) as v3 where v3.e2 =
1", metadata, //$NON-NLS-1$
null, capFinder,
- new String[] { "SELECT CASE WHEN g_0.e1='S' THEN 'Pay'
WHEN g_0.e1='P' THEN 'Rec' ELSE g_0.e1 END, CASE WHEN g_1.e1='S'
THEN 'Pay' WHEN g_1.e1='P' THEN 'Rec' ELSE g_1.e1 END, g_0.e2,
g_1.e2 FROM pm1.g1 AS g_0 LEFT OUTER JOIN pm1.g1 AS g_1 ON g_1.e2 = 1 WHERE g_0.e2 =
1" }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+ new String[] { "SELECT CASE WHEN g_0.e1 = 'S' THEN 'Pay'
WHEN g_0.e1 = 'P' THEN 'Rec' ELSE g_0.e1 END, CASE WHEN g_1.e1 =
'S' THEN 'Pay' WHEN g_1.e1 = 'P' THEN 'Rec' ELSE g_1.e1
END, g_0.e2, g_1.e2 FROM pm1.g1 AS g_0 LEFT OUTER JOIN pm1.g1 AS g_1 ON g_1.e2 = 1 WHERE
g_0.e2 = 1" }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
checkNodeTypes(plan, FULL_PUSHDOWN);
checkSubPlanCount(plan, 0);
Modified:
trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestAliasGenerator.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestAliasGenerator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestAliasGenerator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -62,7 +62,7 @@
public void testLongOrderByAlias() throws Exception {
String sql = "select pm1.g1.e1 || pm1.g1.e2 as
asfasdfadfasdfasdfadfasdfadsfasdfasdfasdfasdfasdfadfa, pm1.g1.e2 from pm1.g1 order by
asfasdfadfasdfasdfadfasdfadsfasdfasdfasdfasdfasdfadfa"; //$NON-NLS-1$
- String expected = "SELECT (g_0.e1 || g_0.e2) AS c_0, g_0.e2 AS c_1 FROM
pm1.g1 AS g_0 ORDER BY c_0"; //$NON-NLS-1$
+ String expected = "SELECT concat(g_0.e1, g_0.e2) AS c_0, g_0.e2 AS c_1 FROM
pm1.g1 AS g_0 ORDER BY c_0"; //$NON-NLS-1$
helpTest(sql, expected, true, FakeMetadataFactory.example1Cached());
}
@@ -112,13 +112,13 @@
public void testCorrelatedRefernce() throws Exception {
String sql = "select intnum, stringnum from (select intnum, stringnum from
bqt1.smallb) b where intnum in (select b.stringnum || b.intnum from (select intnum from
bqt1.smalla) b) "; //$NON-NLS-1$
- String expected = "SELECT v_0.c_0, v_0.c_1 FROM (SELECT g_0.intnum AS c_0,
g_0.stringnum AS c_1 FROM bqt1.smallb AS g_0) AS v_0 WHERE v_0.c_0 IN (SELECT (v_0.c_1 ||
v_1.c_0) FROM (SELECT g_1.intnum AS c_0 FROM bqt1.smalla AS g_1) AS v_1)";
//$NON-NLS-1$
+ String expected = "SELECT v_0.c_0, v_0.c_1 FROM (SELECT g_0.intnum AS c_0,
g_0.stringnum AS c_1 FROM bqt1.smallb AS g_0) AS v_0 WHERE v_0.c_0 IN (SELECT
concat(v_0.c_1, v_1.c_0) FROM (SELECT g_1.intnum AS c_0 FROM bqt1.smalla AS g_1) AS
v_1)"; //$NON-NLS-1$
helpTest(sql, expected, true, FakeMetadataFactory.exampleBQTCached());
}
public void testCorrelatedRefernce1() throws Exception {
String sql = "select intnum, stringnum from bqt1.smallb where intnum in (select
stringnum || b.intnum from (select intnum from bqt1.smalla) b) "; //$NON-NLS-1$
- String expected = "SELECT g_0.intnum, g_0.stringnum FROM bqt1.smallb AS g_0
WHERE g_0.intnum IN (SELECT (g_0.stringnum || v_0.c_0) FROM (SELECT g_1.intnum AS c_0 FROM
bqt1.smalla AS g_1) AS v_0)"; //$NON-NLS-1$
+ String expected = "SELECT g_0.intnum, g_0.stringnum FROM bqt1.smallb AS g_0
WHERE g_0.intnum IN (SELECT concat(g_0.stringnum, v_0.c_0) FROM (SELECT g_1.intnum AS c_0
FROM bqt1.smalla AS g_1) AS v_0)"; //$NON-NLS-1$
helpTest(sql, expected, true, FakeMetadataFactory.exampleBQTCached());
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/parser/TestParser.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/parser/TestParser.java 2009-02-16
21:35:28 UTC (rev 475)
+++ trunk/engine/src/test/java/com/metamatrix/query/parser/TestParser.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -6059,17 +6059,8 @@
.append(" ELSE 9999") //$NON-NLS-1$
.append(" END") //$NON-NLS-1$
.append(" FROM m.g").toString(); //$NON-NLS-1$
- String expected = new StringBuffer("SELECT y, z, ") //$NON-NLS-1$
- .append("CASE") //$NON-NLS-1$
- .append(" WHEN x='a' THEN 0") //$NON-NLS-1$
- .append(" WHEN x='b' THEN 1") //$NON-NLS-1$
- .append(" WHEN x='c' THEN 2") //$NON-NLS-1$
- .append(" WHEN x='d' THEN 3") //$NON-NLS-1$
- .append(" ELSE 9999") //$NON-NLS-1$
- .append(" END") //$NON-NLS-1$
- .append(" FROM m.g").toString(); //$NON-NLS-1$
- helpTest(query, expected, q);
+ helpTest(query, query, q);
}
public void testCaseExpression2() {
@@ -6094,15 +6085,8 @@
.append(" WHEN 'd' THEN 3") //$NON-NLS-1$
.append(" END") //$NON-NLS-1$
.append(" FROM m.g").toString(); //$NON-NLS-1$
- String expected = new StringBuffer("SELECT y, z, ") //$NON-NLS-1$
- .append("CASE") //$NON-NLS-1$
- .append(" WHEN x='a' THEN 0") //$NON-NLS-1$
- .append(" WHEN x='b' THEN 1") //$NON-NLS-1$
- .append(" WHEN x='c' THEN 2") //$NON-NLS-1$
- .append(" WHEN x='d' THEN 3") //$NON-NLS-1$
- .append(" END") //$NON-NLS-1$
- .append(" FROM m.g").toString(); //$NON-NLS-1$
- helpTest(query, expected, q);
+
+ helpTest(query, query, q);
}
public void testCaseExpression3() {
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -7940,7 +7940,7 @@
FakeDataManager dataManager = new FakeDataManager();
sampleData2(dataManager);
- ProcessorPlan plan = TestOptimizer.helpPlan(sql,
FakeMetadataFactory.example1Cached(), null, capFinder, new String[] {"SELECT
pm1.g1.e1 FROM pm1.g1 LIMIT (5 + 1)"},
TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+ ProcessorPlan plan = TestOptimizer.helpPlan(sql,
FakeMetadataFactory.example1Cached(), null, capFinder, new String[] {"SELECT
pm1.g1.e1 AS c_0 FROM pm1.g1 LIMIT (5 + 1)"},
TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
helpProcess(plan, dataManager, expected);
}
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-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1691,9 +1691,8 @@
helpTestRewriteCriteria("case 0 when 1 then 1 else 2 end = 1", "1
= 0"); //$NON-NLS-1$ //$NON-NLS-2$
}
- // First WHEN can't be rewritten, so no changes
public void testRewriteSearchedCaseExpr3() {
- helpTestRewriteCriteria("case 0 when pm1.g1.e2 then 1 else 2 end = 1",
"CASE 0 WHEN pm1.g1.e2 THEN 1 ELSE 2 END = 1"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTestRewriteCriteria("case 0 when pm1.g1.e2 then 1 else 2 end = 1",
"CASE WHEN pm1.g1.e2 = 0 THEN 1 ELSE 2 END = 1"); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testRewriteSearchedCaseExpr4() {
@@ -1704,35 +1703,35 @@
// First WHEN always false, so remove it
public void testRewriteSearchedCaseExpr5() {
- helpTestRewriteCriteria("case 0 when 1 then 1 when pm1.g1.e2 then 2 else 3
end = 1", "CASE 0 WHEN pm1.g1.e2 THEN 2 ELSE 3 END = 1"); //$NON-NLS-1$
//$NON-NLS-2$
+ helpTestRewriteCriteria("case 0 when 1 then 1 when pm1.g1.e2 then 2 else 3
end = 1", "CASE WHEN pm1.g1.e2 = 0 THEN 2 ELSE 3 END = 1"); //$NON-NLS-1$
//$NON-NLS-2$
}
public void testDefect16879_1(){
- helpTestRewriteCommand("SELECT decodestring(e1, 'a, b') FROM
pm1.g1", "SELECT CASE WHEN e1='a' THEN 'b' ELSE e1 END FROM
pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTestRewriteCommand("SELECT decodestring(e1, 'a, b') FROM
pm1.g1", "SELECT CASE WHEN e1 = 'a' THEN 'b' ELSE e1 END FROM
pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testDefect16879_2(){
- helpTestRewriteCommand("SELECT decodestring(e1, 'a, b, c, d') FROM
pm1.g1", "SELECT CASE WHEN e1='a' THEN 'b' WHEN e1='c'
THEN 'd' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTestRewriteCommand("SELECT decodestring(e1, 'a, b, c, d') FROM
pm1.g1", "SELECT CASE WHEN e1 = 'a' THEN 'b' WHEN e1 =
'c' THEN 'd' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testDefect16879_3(){
- helpTestRewriteCommand("SELECT decodeinteger(e1, 'a, b') FROM
pm1.g1", "SELECT CASE WHEN e1='a' THEN 'b' ELSE e1 END FROM
pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTestRewriteCommand("SELECT decodeinteger(e1, 'a, b') FROM
pm1.g1", "SELECT CASE WHEN e1 = 'a' THEN 'b' ELSE e1 END FROM
pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testDefect16879_4(){
- helpTestRewriteCommand("SELECT decodeinteger(e1, 'a, b, c, d') FROM
pm1.g1", "SELECT CASE WHEN e1='a' THEN 'b' WHEN e1='c'
THEN 'd' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTestRewriteCommand("SELECT decodeinteger(e1, 'a, b, c, d') FROM
pm1.g1", "SELECT CASE WHEN e1 = 'a' THEN 'b' WHEN e1 =
'c' THEN 'd' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testDefect16879_5(){
- helpTestRewriteCommand("SELECT decodeinteger(e1, 'null, b, c, d')
FROM pm1.g1", "SELECT CASE WHEN e1 IS NULL THEN 'b' WHEN e1='c'
THEN 'd' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTestRewriteCommand("SELECT decodeinteger(e1, 'null, b, c, d')
FROM pm1.g1", "SELECT CASE WHEN e1 IS NULL THEN 'b' WHEN e1 =
'c' THEN 'd' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testDefect16879_6(){
- helpTestRewriteCommand("SELECT decodeinteger(e1, 'a, b, null, d')
FROM pm1.g1", "SELECT CASE WHEN e1 IS NULL THEN 'd' WHEN e1='a'
THEN 'b' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTestRewriteCommand("SELECT decodeinteger(e1, 'a, b, null, d')
FROM pm1.g1", "SELECT CASE WHEN e1 = 'a' THEN 'b' WHEN e1 IS
NULL THEN 'd' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testDefect16879_7(){
- helpTestRewriteCommand("SELECT decodeinteger(e1, 'a, b, null, d, e')
FROM pm1.g1", "SELECT CASE WHEN e1 IS NULL THEN 'd' WHEN e1='a'
THEN 'b' ELSE 'e' END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+ 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$
}
//note that the env is now treated as deterministic, however it is really only
deterministic within a session
@@ -1770,7 +1769,7 @@
}
public void testRewriteWithReference() {
- helpTestRewriteCommand("SELECT e1 FROM pm1.g1 where parsetimestamp(e1,
'yyyy-MM-dd') != ?", "SELECT e1 FROM pm1.g1 WHERE e1 <>
formatTimestamp(?, 'yyyy-MM-dd')"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTestRewriteCommand("SELECT e1 FROM pm1.g1 where parsetimestamp(e1,
'yyyy-MM-dd') != ?", "SELECT e1 FROM pm1.g1 WHERE e1 <>
formattimestamp(?, 'yyyy-MM-dd')"); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testRewiteJoinCriteria() {
@@ -2067,15 +2066,15 @@
}
public void testRewriteConcat2_2() throws Exception {
- helpTestRewriteCriteria("concat2(pm1.g1.e1, null) = 'xyz'",
"CASE WHEN pm1.g1.e1 IS NULL THEN null ELSE CONCAT(NVL(pm1.g1.e1, ''),
'') END = 'xyz'", true); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTestRewriteCriteria("concat2(pm1.g1.e1, null) = 'xyz'",
"CASE WHEN pm1.g1.e1 IS NULL THEN null ELSE concat(ifnull(pm1.g1.e1, ''),
'') END = 'xyz'", true); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testRewriteConcat2_3() throws Exception {
- helpTestRewriteCriteria("concat2(pm1.g1.e1, convert(pm1.g1.e2, string)) =
'xyz'", "CASE WHEN (pm1.g1.e1 IS NULL) AND (convert(pm1.g1.e2, string)
IS NULL) THEN null ELSE CONCAT(NVL(pm1.g1.e1, ''), NVL(convert(pm1.g1.e2, string),
'')) END = 'xyz'", true); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTestRewriteCriteria("concat2(pm1.g1.e1, convert(pm1.g1.e2, string)) =
'xyz'", "CASE WHEN (pm1.g1.e1 IS NULL) AND (convert(pm1.g1.e2, string)
IS NULL) THEN null ELSE concat(ifnull(pm1.g1.e1, ''), ifnull(convert(pm1.g1.e2,
string), '')) END = 'xyz'", true); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testRewriteConcat2_4() throws Exception {
- helpTestRewriteCriteria("concat2('a', pm1.g1.e1) =
'xyz'", "CONCAT('a', NVL(pm1.g1.e1, '')) =
'xyz'"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTestRewriteCriteria("concat2('a', pm1.g1.e1) =
'xyz'", "concat('a', ifnull(pm1.g1.e1, '')) =
'xyz'"); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testRewiteEvaluatableAggregate() {
Modified:
trunk/engine/src/test/java/com/metamatrix/query/sql/util/TestUpdateProcedureGenerator.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/sql/util/TestUpdateProcedureGenerator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/test/java/com/metamatrix/query/sql/util/TestUpdateProcedureGenerator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -68,8 +68,12 @@
throw new RuntimeException(e);
}
}
-
+
public static FakeMetadataFacade example1() {
+ return example1(true);
+ }
+
+ public static FakeMetadataFacade example1(boolean allUpdatable) {
// Create models
FakeMetadataObject pm1 = FakeMetadataFactory.createPhysicalModel("pm1");
//$NON-NLS-1$
FakeMetadataObject vm1 = FakeMetadataFactory.createVirtualModel("vm1");
//$NON-NLS-1$
@@ -83,6 +87,9 @@
List pm1g1e = FakeMetadataFactory.createElements(pm1g1,
new String[] { "e1", "e2", "e3", "e4" },
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { DataTypeManager.DefaultDataTypes.STRING,
DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN,
DataTypeManager.DefaultDataTypes.DOUBLE });
+ if (!allUpdatable) {
+ ((FakeMetadataObject)pm1g1e.get(0)).putProperty(FakeMetadataObject.Props.UPDATE,
Boolean.FALSE);
+ }
List pm1g2e = FakeMetadataFactory.createElements(pm1g2,
new String[] { "e1", "e2", "e3", "e4" },
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
@@ -163,105 +170,8 @@
// Create the facade from the store
return new FakeMetadataFacade(store);
- }
-
- public static FakeMetadataFacade example2() {
- // Create models
- FakeMetadataObject pm1 =
FakeMetadataFactory.createPhysicalModel("pm1"); //$NON-NLS-1$
- FakeMetadataObject vm1 = FakeMetadataFactory.createVirtualModel("vm1");
//$NON-NLS-1$
-
- // Create physical groups
- FakeMetadataObject pm1g1 =
FakeMetadataFactory.createPhysicalGroup("pm1.g1", pm1); //$NON-NLS-1$
- FakeMetadataObject pm1g2 =
FakeMetadataFactory.createPhysicalGroup("pm1.g2", pm1); //$NON-NLS-1$
- FakeMetadataObject pm1g3 =
FakeMetadataFactory.createPhysicalGroup("pm1.g3", pm1); //$NON-NLS-1$
-
- // Create physical elements
- List pm1g1e = FakeMetadataFactory.createElements(pm1g1,
- new String[] { "e1", "e2", "e3", "e4"
}, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- new String[] { DataTypeManager.DefaultDataTypes.STRING,
DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN,
DataTypeManager.DefaultDataTypes.DOUBLE });
- ((FakeMetadataObject)pm1g1e.get(0)).putProperty(FakeMetadataObject.Props.UPDATE,
Boolean.FALSE);
-
- List pm1g2e = FakeMetadataFactory.createElements(pm1g2,
- new String[] { "e1", "e2", "e3", "e4"
}, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- new String[] { DataTypeManager.DefaultDataTypes.STRING,
DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN,
DataTypeManager.DefaultDataTypes.DOUBLE });
-
- List pm1g3e = FakeMetadataFactory.createElements(pm1g3,
- new String[] { "e1", "e2", "e3", "e4"
}, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- new String[] { DataTypeManager.DefaultDataTypes.STRING,
DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN,
DataTypeManager.DefaultDataTypes.DOUBLE });
- ((FakeMetadataObject)pm1g3e.get(0)).putProperty(FakeMetadataObject.Props.NULL,
Boolean.FALSE);
-
((FakeMetadataObject)pm1g3e.get(0)).putProperty(FakeMetadataObject.Props.DEFAULT_VALUE,
null);
-
- ((FakeMetadataObject)pm1g3e.get(1)).putProperty(FakeMetadataObject.Props.NULL,
Boolean.FALSE);
-
((FakeMetadataObject)pm1g3e.get(1)).putProperty(FakeMetadataObject.Props.AUTO_INCREMENT,
Boolean.TRUE);
-
((FakeMetadataObject)pm1g3e.get(1)).putProperty(FakeMetadataObject.Props.DEFAULT_VALUE,
null);
-
- ((FakeMetadataObject)pm1g3e.get(2)).putProperty(FakeMetadataObject.Props.NULL,
Boolean.FALSE);
-
((FakeMetadataObject)pm1g3e.get(2)).putProperty(FakeMetadataObject.Props.DEFAULT_VALUE,
"xyz"); //$NON-NLS-1$
-
- // Create virtual groups
- QueryNode vm1g1n1 = new QueryNode("vm1.g1", "SELECT e1 as a, e2
FROM pm1.g1 WHERE e3 > 5"); //$NON-NLS-1$ //$NON-NLS-2$
- FakeMetadataObject vm1g1 =
FakeMetadataFactory.createUpdatableVirtualGroup("vm1.g1", vm1, vm1g1n1);
//$NON-NLS-1$
- QueryNode vm1g2n1 = new QueryNode("vm1.g2", "SELECT e1, e2, e3, e4
FROM pm1.g2 WHERE e3 > 5"); //$NON-NLS-1$ //$NON-NLS-2$
- FakeMetadataObject vm1g2 =
FakeMetadataFactory.createUpdatableVirtualGroup("vm1.g2", vm1, vm1g2n1);
//$NON-NLS-1$
- QueryNode vm1g3n1 = new QueryNode("vm1.g3", "SELECT e1, e3 FROM
pm1.g3"); //$NON-NLS-1$ //$NON-NLS-2$
- FakeMetadataObject vm1g3 =
FakeMetadataFactory.createUpdatableVirtualGroup("vm1.g3", vm1, vm1g3n1);
//$NON-NLS-1$
- QueryNode vm1g4n1 = new QueryNode("vm1.g4", "SELECT e1, e2 FROM
pm1.g3"); //$NON-NLS-1$ //$NON-NLS-2$
- FakeMetadataObject vm1g4 =
FakeMetadataFactory.createUpdatableVirtualGroup("vm1.g4", vm1, vm1g4n1);
//$NON-NLS-1$
- QueryNode vm1g5n1 = new QueryNode("vm1.g5", "SELECT e2, e3 FROM
pm1.g3"); //$NON-NLS-1$ //$NON-NLS-2$
- FakeMetadataObject vm1g5 =
FakeMetadataFactory.createUpdatableVirtualGroup("vm1.g5", vm1, vm1g5n1);
//$NON-NLS-1$
-
- // Create virtual elements
- List vm1g1e = FakeMetadataFactory.createElements(vm1g1,
- new String[] { "a", "e2"}, //$NON-NLS-1$ //$NON-NLS-2$
- new String[] { DataTypeManager.DefaultDataTypes.STRING,
DataTypeManager.DefaultDataTypes.INTEGER});
- List vm1g2e = FakeMetadataFactory.createElements(vm1g2,
- new String[] { "e1", "e2","e3",
"e4"}, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- new String[] { DataTypeManager.DefaultDataTypes.STRING,
DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN,
DataTypeManager.DefaultDataTypes.DOUBLE });
- List vm1g3e = FakeMetadataFactory.createElements(vm1g3,
- new String[] { "e1", "e2"}, //$NON-NLS-1$ //$NON-NLS-2$
- new String[] { DataTypeManager.DefaultDataTypes.STRING,
DataTypeManager.DefaultDataTypes.INTEGER, });
- List vm1g4e = FakeMetadataFactory.createElements(vm1g4,
- new String[] { "e1", "e3"}, //$NON-NLS-1$ //$NON-NLS-2$
- new String[] { DataTypeManager.DefaultDataTypes.STRING,
DataTypeManager.DefaultDataTypes.BOOLEAN });
- List vm1g5e = FakeMetadataFactory.createElements(vm1g5,
- new String[] { "e2","e3"}, //$NON-NLS-1$ //$NON-NLS-2$
- new String[] { DataTypeManager.DefaultDataTypes.INTEGER,
DataTypeManager.DefaultDataTypes.BOOLEAN });
-
- // Stored queries
- FakeMetadataObject rs1 = FakeMetadataFactory.createResultSet("pm1.rs1",
pm1, new String[] { "e1", "e2" }, new String[] {
DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- FakeMetadataObject rs1p1 = FakeMetadataFactory.createParameter("ret",
1, ParameterInfo.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, rs1);
//$NON-NLS-1$
- QueryNode sq1n1 = new QueryNode("pm1.sq1", "CREATE VIRTUAL
PROCEDURE BEGIN SELECT e1, e2 FROM pm1.g1; END"); //$NON-NLS-1$ //$NON-NLS-2$
- FakeMetadataObject sq1 =
FakeMetadataFactory.createVirtualProcedure("pm1.sq1", pm1, Arrays.asList(new
FakeMetadataObject[] { rs1p1 }), sq1n1); //$NON-NLS-1$
-
- // Add all objects to the store
- FakeMetadataStore store = new FakeMetadataStore();
- store.addObject(pm1);
- store.addObject(pm1g1);
- store.addObjects(pm1g1e);
- store.addObject(pm1g2);
- store.addObjects(pm1g2e);
- store.addObject(pm1g3);
- store.addObjects(pm1g3e);
-
- store.addObject(vm1);
- store.addObject(vm1g1);
- store.addObjects(vm1g1e);
- store.addObject(vm1g2);
- store.addObjects(vm1g2e);
- store.addObject(vm1g3);
- store.addObjects(vm1g3e);
- store.addObject(vm1g4);
- store.addObjects(vm1g4e);
- store.addObject(vm1g5);
- store.addObjects(vm1g5e);
-
- store.addObject(rs1);
- store.addObject(sq1);
-
- // Create the facade from the store
- return new FakeMetadataFacade(store);
- }
-
+ }
+
//actual tests
public void testCreateInsertCommand(){
helpTest(UpdateProcedureGenerator.INSERT_PROCEDURE,
@@ -455,7 +365,7 @@
helpTest(UpdateProcedureGenerator.UPDATE_PROCEDURE,
"vm1.g1", //$NON-NLS-1$
"select e1 as a, e2 from pm1.g1 where e4 > 5",
//$NON-NLS-1$
- TestUpdateProcedureGenerator.example2(),
+ TestUpdateProcedureGenerator.example1(false),
"CREATE PROCEDURE\nBEGIN\nROWS_UPDATED = UPDATE pm1.g1 SET e2 =
INPUT.e2 WHERE TRANSLATE CRITERIA;\nEND"); //$NON-NLS-1$
}
@@ -464,7 +374,7 @@
helpTest(UpdateProcedureGenerator.INSERT_PROCEDURE,
"vm1.g1", //$NON-NLS-1$
"SELECT e1, e2 FROM pm1.g1", //$NON-NLS-1$
- TestUpdateProcedureGenerator.example2(),
+ TestUpdateProcedureGenerator.example1(false),
"CREATE PROCEDURE\nBEGIN\nROWS_UPDATED = INSERT INTO pm1.g1 (pm1.g1.e2)
VALUES (INPUT.e2);\nEND"); //$NON-NLS-1$
}
Modified:
trunk/engine/src/test/java/com/metamatrix/query/sql/visitor/TestSQLStringVisitor.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/sql/visitor/TestSQLStringVisitor.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/test/java/com/metamatrix/query/sql/visitor/TestSQLStringVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -1840,24 +1840,24 @@
public void testCaseExpression1() {
helpTest(TestCaseExpression.example(2),
- "CASE WHEN x='a' THEN 0 WHEN x='b' THEN 1 ELSE 9999
END"); //$NON-NLS-1$
+ "CASE x WHEN 'a' THEN 0 WHEN 'b' THEN 1 ELSE 9999
END"); //$NON-NLS-1$
}
public void testCaseExpression2() {
CaseExpression example = TestCaseExpression.example(2);
example.setElseExpression(null);
- helpTest(example, "CASE WHEN x='a' THEN 0 WHEN x='b' THEN 1
END"); //$NON-NLS-1$
+ helpTest(example, "CASE x WHEN 'a' THEN 0 WHEN 'b' THEN 1
END"); //$NON-NLS-1$
}
public void testCaseExpression3() {
CaseExpression example = TestCaseExpression.example(3, 0, true);
- helpTest(example, "CASE WHEN x IS NULL THEN 0 WHEN x='b' THEN 1 WHEN
x='c' THEN 2 ELSE 9999 END"); //$NON-NLS-1$
+ helpTest(example, "CASE x WHEN null THEN 0 WHEN 'b' THEN 1 WHEN
'c' THEN 2 ELSE 9999 END"); //$NON-NLS-1$
}
public void testCaseExpression4() {
CaseExpression example = TestCaseExpression.example(3, 2, true);
example.setElseExpression(null);
- helpTest(example, "CASE WHEN x IS NULL THEN 2 WHEN x='a' THEN 0 WHEN
x='b' THEN 1 END"); //$NON-NLS-1$
+ helpTest(example, "CASE x WHEN 'a' THEN 0 WHEN 'b' THEN 1
WHEN null THEN 2 END"); //$NON-NLS-1$
}
public void testSearchedCaseExpression1() {
Modified: trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -255,7 +255,7 @@
return new FakeMetadataFacade(store);
}
- public FakeMetadataFacade exampleMetadata3() {
+ public static FakeMetadataFacade exampleMetadata3() {
// Create metadata objects
FakeMetadataObject modelObj =
FakeMetadataFactory.createPhysicalModel("test"); //$NON-NLS-1$
FakeMetadataObject groupObj =
FakeMetadataFactory.createPhysicalGroup("test.group", modelObj);
//$NON-NLS-1$
@@ -266,6 +266,7 @@
elemObj1.putProperty(FakeMetadataObject.Props.NULL, Boolean.FALSE);
elemObj1.putProperty(FakeMetadataObject.Props.DEFAULT_VALUE, Boolean.FALSE);
elemObj1.putProperty(FakeMetadataObject.Props.AUTO_INCREMENT, Boolean.TRUE);
+ elemObj1.putProperty(FakeMetadataObject.Props.NAME_IN_SOURCE,
"e1:SEQUENCE=MYSEQUENCE.nextVal"); //$NON-NLS-1$
// set up validator metadata
FakeMetadataStore store = new FakeMetadataStore();
@@ -905,7 +906,7 @@
}
public void testXMLQueryRowLimitInvalidCriteria6a() {
- helpValidate("SELECT * FROM vm1.doc1 where 2 = CASE rowlimit(a2) WHEN 2 THEN
2 END", new String[] {"2 = CASE WHEN rowlimit(a2)=2 THEN 2 END"},
exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
+ helpValidate("SELECT * FROM vm1.doc1 where 2 = CASE rowlimit(a2) WHEN 2 THEN
2 END", new String[] {"2 = CASE rowlimit(a2) WHEN 2 THEN 2 END"},
exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testXMLQueryRowLimitInvalidCriteria7() {
@@ -1025,7 +1026,7 @@
}
public void testXMLQueryRowLimitExceptionInvalidCriteria6a() {
- helpValidate("SELECT * FROM vm1.doc1 where 2 = CASE rowlimitexception(a2)
WHEN 2 THEN 2 END", new String[] {"2 = CASE WHEN rowlimitexception(a2)=2 THEN 2
END"}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
+ helpValidate("SELECT * FROM vm1.doc1 where 2 = CASE rowlimitexception(a2)
WHEN 2 THEN 2 END", new String[] {"2 = CASE rowlimitexception(a2) WHEN 2 THEN 2
END"}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testXMLQueryRowLimitExceptionInvalidCriteria7() {
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-16
21:35:28 UTC (rev 475)
+++
trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -22,48 +22,45 @@
package com.metamatrix.connector.jdbc.extension;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.api.TranslationUtility;
-import com.metamatrix.connector.api.ConnectorEnvironment;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+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.util.FunctionReplacementVisitor;
+import com.metamatrix.connector.jdbc.JDBCPropertyNames;
+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;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.dqp.internal.datamgr.impl.ExecutionContextImpl;
-import com.metamatrix.dqp.internal.datamgr.impl.FakeExecutionContextImpl;
-import com.metamatrix.dqp.internal.datamgr.language.LanguageBridgeFactory;
-import com.metamatrix.dqp.internal.datamgr.language.LanguageFactoryImpl;
-import com.metamatrix.dqp.internal.datamgr.language.TestDeleteImpl;
-import com.metamatrix.dqp.internal.datamgr.language.TestInsertImpl;
-import com.metamatrix.dqp.internal.datamgr.language.TestProcedureImpl;
-import com.metamatrix.dqp.internal.datamgr.language.TestSelectImpl;
-import com.metamatrix.dqp.internal.datamgr.language.TestUpdateImpl;
-import com.metamatrix.dqp.internal.datamgr.language.TstLanguageBridgeFactory;
-import com.metamatrix.dqp.internal.datamgr.metadata.MetadataFactory;
-import com.metamatrix.dqp.internal.datamgr.metadata.RuntimeMetadataImpl;
-import com.metamatrix.metadata.runtime.VDBMetadataFactory;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.rewriter.QueryRewriter;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.From;
-import com.metamatrix.query.sql.lang.GroupBy;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.Select;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
+import com.metamatrix.core.util.UnitTestUtil;
+import com.metamatrix.dqp.internal.datamgr.impl.ExecutionContextImpl;
+import com.metamatrix.dqp.internal.datamgr.impl.FakeExecutionContextImpl;
+import com.metamatrix.dqp.internal.datamgr.language.LanguageBridgeFactory;
+import com.metamatrix.dqp.internal.datamgr.language.TestDeleteImpl;
+import com.metamatrix.dqp.internal.datamgr.language.TestInsertImpl;
+import com.metamatrix.dqp.internal.datamgr.language.TestProcedureImpl;
+import com.metamatrix.dqp.internal.datamgr.language.TestSelectImpl;
+import com.metamatrix.dqp.internal.datamgr.language.TestUpdateImpl;
+import com.metamatrix.dqp.internal.datamgr.language.TstLanguageBridgeFactory;
+import com.metamatrix.metadata.runtime.VDBMetadataFactory;
+import com.metamatrix.query.metadata.QueryMetadataInterface;
+import com.metamatrix.query.resolver.QueryResolver;
+import com.metamatrix.query.rewriter.QueryRewriter;
+import com.metamatrix.query.sql.lang.Command;
+import com.metamatrix.query.sql.lang.From;
+import com.metamatrix.query.sql.lang.GroupBy;
+import com.metamatrix.query.sql.lang.Query;
+import com.metamatrix.query.sql.lang.Select;
+import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
+import com.metamatrix.query.sql.symbol.Expression;
+import com.metamatrix.query.sql.symbol.Function;
+import com.metamatrix.query.sql.symbol.GroupSymbol;
/**
*/
@@ -95,103 +92,69 @@
return util.parseCommand(sql);
}
- public void helpTestVisitor(String vdb, String input, Map modifiers, int
expectedType, String expectedOutput) {
- helpTestVisitor(vdb, input, modifiers, expectedType, expectedOutput, false);
+ public void helpTestVisitor(String vdb, String input, Map modifiers, String
expectedOutput) {
+ helpTestVisitor(vdb, input, modifiers, expectedOutput, false);
}
- public void helpTestVisitor(String vdb, String input, Map modifiers, int
expectedType, String expectedOutput, boolean useMetadata) {
- helpTestVisitor(vdb, input, modifiers, expectedType, expectedOutput, useMetadata,
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, Map modifiers, int
expectedType, String expectedOutput, boolean useMetadata, boolean usePreparedStatement) {
+ public void helpTestVisitor(String vdb, String input, Map modifiers, String
expectedOutput, boolean useMetadata, boolean usePreparedStatement) {
// Convert from sql to objects
ICommand obj = helpTranslate(vdb, input);
try {
- helpTestVisitorWithCommand(modifiers, expectedType, expectedOutput, obj, useMetadata,
usePreparedStatement);
+ helpTestVisitorWithCommand(modifiers, expectedOutput, obj, useMetadata,
usePreparedStatement);
} catch (ConnectorException e) {
throw new RuntimeException(e);
}
}
- public static final RuntimeMetadata metadata =
TstLanguageBridgeFactory.metadataFactory.createRuntimeMetadata();
+ public static final RuntimeMetadata metadata =
TstLanguageBridgeFactory.metadataFactory.getRuntimeMetadata();
- private String getStringWithContext(ILanguageObject obj) {
+ private String getStringWithContext(ILanguageObject obj) throws ConnectorException {
Properties props = new Properties();
- props.setProperty(JDBCPropertyNames.USE_COMMENTS_SOURCE_QUERY,
"true");
-
- SQLConversionVisitor visitor = new SQLConversionVisitor();
- visitor.setRuntimeMetadata(metadata);
+ props.setProperty(JDBCPropertyNames.USE_COMMENTS_SOURCE_QUERY,
Boolean.TRUE.toString());
+ SQLTranslator trans = new SQLTranslator();
+ trans.initialize(EnvironmentUtility.createEnvironment(props, false));
+ SQLConversionVisitor visitor = new SQLConversionVisitor(trans);
visitor.setExecutionContext(context);
- visitor.setProperties(props);
visitor.append(obj);
return visitor.toString();
}
/**
- * @param modifiers
- * @param expectedType
- * @param expectedOutput
+ * @param modifiers
+ * @param expectedOutput
* @param obj
* @throws ConnectorException
* @since 4.2
*/
private void helpTestVisitorWithCommand(Map modifiers,
- int expectedType,
String expectedOutput,
- ICommand obj, boolean useMetadata, boolean
usePreparedStatement) throws ConnectorException {
+ ICommand obj,
+ boolean useMetadata, boolean
usePreparedStatement) throws ConnectorException {
// Apply function replacement
FunctionReplacementVisitor funcVisitor = new
FunctionReplacementVisitor(modifiers);
-
+ SQLTranslator trans = new SQLTranslator();
+ 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 = new SQLConversionVisitor() {
- //set the max alias lengths to test alias truncation
- protected int getMaxSelectAliasLength() {
- return 30;
- }
-
- protected int getMaxTableAliasLength() {
- return 30;
- }
- };
- if (usePreparedStatement) {
- sqlVisitor.setStmtType(TranslatedCommand.STMT_TYPE_PREPARED_STATEMENT);
- }
- sqlVisitor.setLanguageFactory(LanguageFactoryImpl.INSTANCE);
+ SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(trans);
- if (useMetadata) {
- QueryMetadataInterface metadata =
VDBMetadataFactory.getVDBMetadata(getTestVDB());
- sqlVisitor.setRuntimeMetadata(new RuntimeMetadataImpl(new
MetadataFactory(metadata)));
- }
- TranslatedCommand tc = new TranslatedCommand(new FakeExecutionContextImpl(), new
SQLTranslator() {
-
- public void initialize(ConnectorEnvironment env, RuntimeMetadata metadata) throws
ConnectorException {}
-
- public ICommand modifyCommand(ICommand command, ExecutionContext context) throws
ConnectorException {
- return command;
- }
-
- public SQLConversionVisitor getTranslationVisitor() {
- return null;
- }
-
- public Map getFunctionModifiers() {
- return null;
- }}, sqlVisitor, funcVisitor);
+ TranslatedCommand tc = new TranslatedCommand(new FakeExecutionContextImpl(),
trans, sqlVisitor, funcVisitor);
tc.translateCommand(obj);
- // 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$
- assertEquals("Did not get expected command type", expectedType,
tc.getExecutionType()); //$NON-NLS-1$
-
}
public void testSimple() {
helpTestVisitor(getTestVDB(),
"select part_name from parts", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT PARTS.PART_NAME FROM PARTS"); //$NON-NLS-1$
}
@@ -199,7 +162,6 @@
helpTestVisitor(getTestVDB(),
"select part_name as x from parts", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT PARTS.PART_NAME AS x FROM PARTS"); //$NON-NLS-1$
}
@@ -207,7 +169,6 @@
helpTestVisitor(getTestVDB(),
"select y.part_name from parts y", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT y.PART_NAME FROM PARTS AS y"); //$NON-NLS-1$
}
@@ -215,7 +176,6 @@
helpTestVisitor(getTestVDB(),
"select y.part_name AS z from parts y", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT y.PART_NAME AS z FROM PARTS AS y"); //$NON-NLS-1$
}
@@ -223,7 +183,6 @@
helpTestVisitor(getTestVDB(),
"select 'x' from parts", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT 'x' FROM PARTS"); //$NON-NLS-1$
}
@@ -231,7 +190,6 @@
helpTestVisitor(getTestVDB(),
"select 5 from parts", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT 5 FROM PARTS"); //$NON-NLS-1$
}
@@ -239,7 +197,6 @@
helpTestVisitor(getTestVDB(),
"select 5.2 from parts", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT 5.2 FROM PARTS"); //$NON-NLS-1$
}
@@ -247,7 +204,6 @@
helpTestVisitor(getTestVDB(),
"select 0.012 from parts", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT 0.012 FROM PARTS"); //$NON-NLS-1$
}
@@ -255,7 +211,6 @@
helpTestVisitor(getTestVDB(),
"select 0.00012 from parts", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT 0.00012 FROM PARTS"); //$NON-NLS-1$
}
@@ -263,7 +218,6 @@
helpTestVisitor(getTestVDB(),
"select 12345.123 from parts", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT 12345.123 FROM PARTS"); //$NON-NLS-1$
}
@@ -271,7 +225,6 @@
helpTestVisitor(getTestVDB(),
"select 1234567890.1234567 from parts", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT 1234567890.1234567 FROM PARTS"); //$NON-NLS-1$
}
@@ -279,7 +232,6 @@
helpTestVisitor(getTestVDB(),
"select {b'true'}, {b'false'} from parts",
//$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT 1, 0 FROM PARTS"); //$NON-NLS-1$
}
@@ -287,7 +239,6 @@
helpTestVisitor(getTestVDB(),
"select {d'2003-12-31'} from parts", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT {d'2003-12-31'} FROM PARTS"); //$NON-NLS-1$
}
@@ -295,7 +246,6 @@
helpTestVisitor(getTestVDB(),
"select {t'23:59:59'} from parts", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT {t'23:59:59'} FROM PARTS"); //$NON-NLS-1$
}
@@ -303,7 +253,6 @@
helpTestVisitor(getTestVDB(),
"select null from parts", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT NULL FROM PARTS"); //$NON-NLS-1$
}
@@ -311,7 +260,6 @@
helpTestVisitor(getTestVDB(),
"select {ts'2003-12-31 23:59:59.123'} from parts",
//$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT {ts'2003-12-31 23:59:59.123'} FROM PARTS");
//$NON-NLS-1$
}
@@ -319,7 +267,6 @@
helpTestVisitor(getTestVDB(),
"select p.part_name from parts p, supplier_parts s where p.part_id =
s.part_id", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT p.PART_NAME FROM PARTS AS p, SUPPLIER_PARTS AS s WHERE p.PART_ID
= s.PART_ID"); //$NON-NLS-1$
}
@@ -327,7 +274,6 @@
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(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT p.PART_NAME FROM PARTS AS p INNER JOIN SUPPLIER_PARTS AS s ON
p.PART_ID = s.PART_ID"); //$NON-NLS-1$
}
@@ -335,7 +281,6 @@
helpTestVisitor(getTestVDB(),
"select p.part_name from parts p join parts p2 on p.part_id =
p2.part_id", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT p.PART_NAME FROM PARTS AS p INNER JOIN PARTS AS p2 ON p.PART_ID
= p2.PART_ID"); //$NON-NLS-1$
}
@@ -343,7 +288,6 @@
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(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"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$
}
@@ -351,7 +295,6 @@
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(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"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$
}
@@ -359,7 +302,6 @@
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(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"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$
}
@@ -367,7 +309,6 @@
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id = 'x'",
//$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID =
'x'"); //$NON-NLS-1$
}
@@ -375,7 +316,6 @@
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id <> 'x'",
//$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID <>
'x'"); //$NON-NLS-1$
}
@@ -383,7 +323,6 @@
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id < 'x'",
//$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID <
'x'"); //$NON-NLS-1$
}
@@ -391,7 +330,6 @@
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id <= 'x'",
//$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID <=
'x'"); //$NON-NLS-1$
}
@@ -399,7 +337,6 @@
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id > 'x'",
//$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID >
'x'"); //$NON-NLS-1$
}
@@ -407,7 +344,6 @@
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id >= 'x'",
//$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID >=
'x'"); //$NON-NLS-1$
}
@@ -415,7 +351,6 @@
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id in ('x')",
//$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID =
'x'"); //$NON-NLS-1$
}
@@ -423,7 +358,6 @@
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id in ('x',
'y')", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID IN ('x',
'y')"); //$NON-NLS-1$
}
@@ -431,7 +365,6 @@
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id not in ('x',
'y')", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID NOT IN
('x', 'y')"); //$NON-NLS-1$
}
@@ -439,7 +372,6 @@
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id is null", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID IS NULL");
//$NON-NLS-1$
}
@@ -447,7 +379,6 @@
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id is not null",
//$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID IS NOT
NULL"); //$NON-NLS-1$
}
@@ -455,7 +386,6 @@
helpTestVisitor(getTestVDB(),
"insert into parts (part_id, part_name, part_color, part_weight) values
('a', null, 'c', 'd')", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_UPDATE,
"INSERT INTO PARTS (PART_ID, PART_NAME, PART_COLOR, PART_WEIGHT) VALUES
('a', NULL, 'c', 'd')"); //$NON-NLS-1$
}
@@ -463,7 +393,6 @@
helpTestVisitor(getTestVDB(),
"update parts set part_weight = null where part_color =
'b'", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_UPDATE,
"UPDATE PARTS SET PART_WEIGHT = NULL WHERE PARTS.PART_COLOR =
'b'"); //$NON-NLS-1$
}
@@ -471,7 +400,6 @@
helpTestVisitor(getTestVDB(),
"update parts set part_weight = 'a' where part_weight =
null", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_UPDATE,
"UPDATE PARTS SET PART_WEIGHT = 'a' WHERE NULL <>
NULL"); //$NON-NLS-1$
}
@@ -495,41 +423,41 @@
ICommand result = new LanguageBridgeFactory(metadata).translate(command);
- helpTestVisitorWithCommand(new HashMap(), TranslatedCommand.EXEC_TYPE_QUERY,
- "SELECT PARTS.PART_NAME FROM PARTS GROUP BY concat(PARTS.PART_ID,
'a')", //$NON-NLS-1$
- result, false, false);
+ helpTestVisitorWithCommand(new HashMap(), "SELECT PARTS.PART_NAME FROM PARTS
GROUP BY concat(PARTS.PART_ID, 'a')",
+ result, //$NON-NLS-1$
+ false, false);
}
public void testPreparedStatementCreationWithUpdate() {
helpTestVisitor(getTestVDB(),
"update parts set part_weight = 'a' where
part_weight < 5", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_UPDATE,
- "UPDATE PARTS SET PART_WEIGHT = ? WHERE PARTS.PART_WEIGHT
< ?", false, true); //$NON-NLS-1$
+ "UPDATE PARTS SET PART_WEIGHT = ? WHERE PARTS.PART_WEIGHT
< ?",
+ false, true); //$NON-NLS-1$
}
public void testPreparedStatementCreationWithInsert() {
helpTestVisitor(getTestVDB(),
"insert into parts (part_weight) values (5)",
//$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_UPDATE,
- "INSERT INTO PARTS (PART_WEIGHT) VALUES (?)", false,
true); //$NON-NLS-1$
+ "INSERT INTO PARTS (PART_WEIGHT) VALUES (?)",
+ 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(),
- TranslatedCommand.EXEC_TYPE_QUERY,
- "SELECT PARTS.PART_NAME FROM PARTS WHERE (PARTS.PART_ID NOT
IN (?, ?)) AND (PARTS.PART_WEIGHT < ?)", false, true); //$NON-NLS-1$
+ "SELECT PARTS.PART_NAME FROM PARTS WHERE (PARTS.PART_ID NOT
IN (?, ?)) AND (PARTS.PART_WEIGHT < ?)",
+ 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(),
- TranslatedCommand.EXEC_TYPE_QUERY,
- "SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_NAME
LIKE ?", false, true); //$NON-NLS-1$
+ "SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_NAME
LIKE ?",
+ false, true); //$NON-NLS-1$
}
/**
@@ -540,8 +468,8 @@
helpTestVisitor(getTestVDB(),
"select part_name from parts where 'x' =
'y'", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
- "SELECT PARTS.PART_NAME FROM PARTS WHERE 1 = ?", false,
true); //$NON-NLS-1$
+ "SELECT PARTS.PART_NAME FROM PARTS WHERE 1 = ?",
+ false, true); //$NON-NLS-1$
}
/**
@@ -552,42 +480,42 @@
helpTestVisitor(getTestVDB(),
"select part_name from parts where concat(part_name,
'x') = concat('y', part_weight)", //$NON-NLS-1$
new HashMap(),
- TranslatedCommand.EXEC_TYPE_QUERY,
- "SELECT PARTS.PART_NAME FROM PARTS WHERE
concat(PARTS.PART_NAME, 'x') = concat('y', PARTS.PART_WEIGHT)",
false, true); //$NON-NLS-1$
+ "SELECT PARTS.PART_NAME FROM PARTS WHERE
concat(PARTS.PART_NAME, 'x') = concat('y', PARTS.PART_WEIGHT)",
+ 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(),
- TranslatedCommand.EXEC_TYPE_QUERY,
- "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$
+ "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$
}
public void testVisitIDeleteWithComment() throws Exception {
- String expected = "DELETE /*metamatrix sessionid:ConnectionID,
requestid:RequestID.PartID*/ FROM g1 WHERE (100 >= 200) AND (500 < 600)";
//$NON-NLS-1$
+ String expected = "DELETE /*teiid sessionid:ConnectionID,
requestid:RequestID.PartID*/ FROM g1 WHERE (100 >= 200) AND (500 < 600)";
//$NON-NLS-1$
assertEquals(expected, getStringWithContext(TestDeleteImpl.example()));
}
public void testVisitIInsertWithComment() throws Exception {
- String expected = "INSERT /*metamatrix sessionid:ConnectionID,
requestid:RequestID.PartID*/ INTO g1 (e1, e2, e3, e4) VALUES (1, 2, 3, 4)";
//$NON-NLS-1$
+ String expected = "INSERT /*teiid sessionid:ConnectionID,
requestid:RequestID.PartID*/ INTO g1 (e1, e2, e3, e4) VALUES (1, 2, 3, 4)";
//$NON-NLS-1$
assertEquals(expected,
getStringWithContext(TestInsertImpl.example("g1"))); //$NON-NLS-1$
}
public void testVisitISelectWithComment() throws Exception {
- String expected = "SELECT /*metamatrix sessionid:ConnectionID,
requestid:RequestID.PartID*/ g1.e1, g1.e2, g1.e3, g1.e4"; //$NON-NLS-1$
+ String expected = "SELECT /*teiid sessionid:ConnectionID,
requestid:RequestID.PartID*/ g1.e1, g1.e2, g1.e3, g1.e4"; //$NON-NLS-1$
assertEquals(expected, getStringWithContext(TestSelectImpl.example(false)));
- expected = "SELECT /*metamatrix sessionid:ConnectionID,
requestid:RequestID.PartID*/ DISTINCT g1.e1, g1.e2, g1.e3, g1.e4"; //$NON-NLS-1$
+ expected = "SELECT /*teiid sessionid:ConnectionID,
requestid:RequestID.PartID*/ DISTINCT g1.e1, g1.e2, g1.e3, g1.e4"; //$NON-NLS-1$
assertEquals(expected, getStringWithContext(TestSelectImpl.example(true)));
}
public void testVisitIUpdateWithComment() throws Exception {
- String expected = "UPDATE /*metamatrix sessionid:ConnectionID,
requestid:RequestID.PartID*/ g1 SET e1 = 1, e2 = 1, e3 = 1, e4 = 1 WHERE 1 = 1";
//$NON-NLS-1$
+ String expected = "UPDATE /*teiid sessionid:ConnectionID,
requestid:RequestID.PartID*/ g1 SET e1 = 1, e2 = 1, e3 = 1, e4 = 1 WHERE 1 = 1";
//$NON-NLS-1$
assertEquals(expected, getStringWithContext(TestUpdateImpl.example()));
}
public void testVisitIProcedureWithComment() throws Exception {
- String expected = "{ /*metamatrix sessionid:ConnectionID,
requestid:RequestID.PartID*/ call sq3(?,?)}"; //$NON-NLS-1$
+ String expected = "{ /*teiid sessionid:ConnectionID,
requestid:RequestID.PartID*/ call sq3(?,?)}"; //$NON-NLS-1$
assertEquals(expected, getStringWithContext(TestProcedureImpl.example()));
}
}
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-16
21:35:28 UTC (rev 475)
+++
trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -24,7 +24,6 @@
import java.util.Map;
import java.util.Properties;
-import java.util.TimeZone;
import junit.framework.TestCase;
@@ -34,6 +33,8 @@
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.extension.SQLConversionVisitor;
import com.metamatrix.connector.jdbc.extension.TranslatedCommand;
import com.metamatrix.connector.jdbc.util.FunctionReplacementVisitor;
import com.metamatrix.connector.language.ICommand;
@@ -42,7 +43,6 @@
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.language.LanguageFactoryImpl;
import com.metamatrix.dqp.internal.datamgr.metadata.MetadataFactory;
import com.metamatrix.dqp.internal.datamgr.metadata.RuntimeMetadataImpl;
import com.metamatrix.query.metadata.QueryMetadataInterface;
@@ -61,7 +61,7 @@
OracleSQLTranslator trans = new OracleSQLTranslator();
try {
- trans.initialize(new ConnectorEnvironmentImpl(new Properties(), null, null),
null);
+ trans.initialize(new ConnectorEnvironmentImpl(new Properties(), null,
null));
} catch(ConnectorException e) {
e.printStackTrace();
}
@@ -84,59 +84,51 @@
return UnitTestUtil.getTestDataPath() + "/PartsSupplierOracle.vdb";
//$NON-NLS-1$
}
- private String getTimestampTestVDB() {
- return UnitTestUtil.getTestDataPath() + "/tstest.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, Map modifiers, String
dbmsTimeZone, int expectedType, String expectedOutput) throws ConnectorException {
- helpTestVisitor(vdb, input, modifiers, EMPTY_CONTEXT, dbmsTimeZone, expectedType,
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, Map modifiers, String
dbmsTimeZone, int expectedType, String expectedOutput, boolean correctNaming) throws
ConnectorException {
- helpTestVisitor(vdb, input, modifiers, EMPTY_CONTEXT, dbmsTimeZone, expectedType,
expectedOutput, correctNaming);
- }
-
- private void helpTestVisitor(String vdb, String input, Map modifiers,
ExecutionContext context, String dbmsTimeZone, int expectedType, String expectedOutput,
boolean correctNaming) throws ConnectorException {
+ private void helpTestVisitor(String vdb, String input, Map modifiers,
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, expectedType, expectedOutput);
+ this.helpTestVisitor(obj, util.createRuntimeMetadata(), modifiers, 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, int expectedType, String
expectedOutput) throws ConnectorException {
+ private void helpTestVisitor(QueryMetadataInterface metadata, String input, Map
modifiers, 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(new
MetadataFactory(metadata));
- this.helpTestVisitor(obj, runtimeMetadata, modifiers, context, dbmsTimeZone,
expectedType, expectedOutput);
+ this.helpTestVisitor(obj, runtimeMetadata, modifiers, context, dbmsTimeZone,
expectedOutput);
}
- private void helpTestVisitor(ICommand obj, RuntimeMetadata metadata, Map modifiers,
ExecutionContext context, String dbmsTimeZone, int expectedType, String expectedOutput)
throws ConnectorException {
+ private void helpTestVisitor(ICommand obj, RuntimeMetadata metadata, Map modifiers,
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) {
+ p.setProperty(JDBCPropertyNames.DATABASE_TIME_ZONE, dbmsTimeZone);
+ }
+ translator.initialize(EnvironmentUtility.createEnvironment(p, false));
// Convert back to SQL
- OracleSQLConversionVisitor sqlVisitor = new OracleSQLConversionVisitor();
- sqlVisitor.setFunctionModifiers(modifiers);
+ SQLConversionVisitor sqlVisitor = new SQLConversionVisitor(translator);
sqlVisitor.setExecutionContext(context);
- sqlVisitor.setRuntimeMetadata(metadata);
- if(dbmsTimeZone != null && dbmsTimeZone.trim().length() > 0) {
- sqlVisitor.setDatabaseTimeZone(TimeZone.getTimeZone(dbmsTimeZone));
- }
- sqlVisitor.setLanguageFactory(LanguageFactoryImpl.INSTANCE);
- OracleSQLTranslator translator = new OracleSQLTranslator();
- translator.initialize(EnvironmentUtility.createEnvironment(new Properties(),
false), metadata);
TranslatedCommand tc = new TranslatedCommand(context, translator, sqlVisitor,
funcVisitor);
tc.translateCommand(obj);
// Check stuff
assertEquals("Did not get correct sql", expectedOutput, tc.getSql());
//$NON-NLS-1$
- assertEquals("Did not get expected command type", expectedType,
tc.getExecutionType()); //$NON-NLS-1$
}
/**
@@ -151,19 +143,17 @@
helpTestVisitor(getTestVDB(),
input,
MODIFIERS, null,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
/** 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 ('0' || to_char(EXTRACT(MONTH FROM SmallA.DateValue))) END
ELSE to_char(EXTRACT(MONTH FROM SmallA.DateValue)) END IS NULL) OR (CASE WHEN
TO_NUMBER(TO_CHAR(SmallA.DateValue, 'DD')) < 10 THEN CASE WHEN
to_char(TO_NUMBER(TO_CHAR(SmallA.DateValue, 'DD'))) IS NULL THEN NULL ELSE
('0' || to_char(TO_NUMBER(TO_CHAR(SmallA.DateValue, 'DD')))) END ELSE
to_char(TO_NUMBER(TO_CHAR(SmallA.DateValue, 'DD'))) END IS NULL) THEN NULL ELSE
(CASE WHEN EXTRACT(MONTH FROM SmallA.DateValue) < 10 THEN CASE WHEN
to_char(EXTRACT(MONTH FROM SmallA.DateValue)) IS NULL THEN NULL ELSE ('0' ||
to_char(EXTRACT(MONTH FROM SmallA.DateValue))) END ELSE to_char(EXTRACT(MONTH FROM
SmallA.DateValue)) END || CASE WHEN TO_NUMBER(TO_CHAR(SmallA.DateValue, 'DD'))
< 10 THEN CASE WHEN to_char(TO_NUMBER(TO_CHAR(SmallA.DateValue, 'D!
D'))) IS NULL THEN NULL ELSE ('0' ||
to_char(TO_NUMBER(TO_CHAR(SmallA.DateValue, 'DD')))) END ELSE
to_char(TO_NUMBER(TO_CHAR(SmallA.DateValue, 'DD'))) END) END IS NULL) OR
(to_char(EXTRACT(YEAR FROM SmallA.DateValue)) IS NULL) THEN NULL ELSE (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 ('0' || to_char(EXTRACT(MONTH FROM
SmallA.DateValue))) END ELSE to_char(EXTRACT(MONTH FROM SmallA.DateValue)) END IS NULL) OR
(CASE WHEN TO_NUMBER(TO_CHAR(SmallA.DateValue, 'DD')) < 10 THEN CASE WHEN
to_char(TO_NUMBER(TO_CHAR(SmallA.DateValue, 'DD'))) IS NULL THEN NULL ELSE
('0' || to_char(TO_NUMBER(TO_CHAR(SmallA.DateValue, 'DD')))) END ELSE
to_char(TO_NUMBER(TO_CHAR(SmallA.DateValue, 'DD'))) END IS NULL) THEN NULL ELSE
(CASE WHEN EXTRACT(MONTH FROM SmallA.DateValue) < 10 THEN CASE WHEN
to_char(EXTRACT(MONTH FROM SmallA.DateValue)) IS NULL THEN NULL ELSE ('0' ||
to_char(EXTRACT(MONTH FROM S!
mallA.DateValue))) END ELSE to_char(EXTRACT(MONTH FROM SmallA.DateValu
e)) END || CASE WHEN TO_NUMBER(TO_CHAR(SmallA.DateValue, 'DD')) < 10 THEN CASE
WHEN to_char(TO_NUMBER(TO_CHAR(SmallA.DateValue, 'DD'))) IS NULL THEN NULL ELSE
('0' || to_char(TO_NUMBER(TO_CHAR(SmallA.DateValue, 'DD')))) END ELSE
to_char(TO_NUMBER(TO_CHAR(SmallA.DateValue, 'DD'))) END) END ||
to_char(EXTRACT(YEAR FROM SmallA.DateValue))) END, SUM(SmallA.IntKey) FROM SmallA GROUP BY
SmallA.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,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -180,7 +170,6 @@
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
input,
MODIFIERS, EMPTY_CONTEXT, null,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -192,7 +181,7 @@
input,
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
public void testLcaseFunction() throws Exception {
@@ -203,7 +192,7 @@
input,
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
public void testUcaseFunction() throws Exception {
@@ -214,7 +203,7 @@
input,
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
public void testIfnullFunction() throws Exception {
@@ -225,7 +214,7 @@
input,
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
public void testLogFunction() throws Exception {
@@ -236,7 +225,7 @@
input,
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
public void testLog10Function() throws Exception {
@@ -247,7 +236,7 @@
input,
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
public void testConvertFunctionInteger() throws Exception {
@@ -259,7 +248,7 @@
input,
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
public void testConvertFunctionChar() throws Exception {
@@ -270,7 +259,7 @@
input,
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
public void testConvertFunctionBoolean() throws Exception {
@@ -282,7 +271,7 @@
input,
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
public void testConvertFunctionDate() throws Exception {
@@ -293,7 +282,7 @@
input,
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
public void testConvertFunctionTime() throws Exception {
@@ -305,7 +294,7 @@
input,
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
public void testConvertFunctionTimestamp() throws Exception {
@@ -317,7 +306,7 @@
input,
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
public void testExtractFunctionTimestamp() throws Exception {
@@ -327,38 +316,14 @@
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
input,
MODIFIERS, EMPTY_CONTEXT, null,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
- public void testFormatFunctionTimestamp() throws Exception {
- String input = "SELECT formattimestamp(TIMESTAMPVALUE, 'YYYY-DD-MM
HH24:MI:SS.fffffffff') FROM BQT1.Smalla"; //$NON-NLS-1$
- String output = "SELECT to_char(SmallA.TimestampValue, 'YYYY-DD-MM
HH24:MI:SS.fffffffff') FROM SmallA"; //$NON-NLS-1$
-
- helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
- input,
- MODIFIERS, EMPTY_CONTEXT, null,
- TranslatedCommand.EXEC_TYPE_QUERY,
- output);
- }
-
- public void testFormatFunctionTime() throws Exception {
- String input = "SELECT formattime(TIMEVALUE, 'HH24:MI:SS') FROM
BQT1.Smalla"; //$NON-NLS-1$
- String output = "SELECT to_char(SmallA.TimeValue, 'HH24:MI:SS') FROM
SmallA"; //$NON-NLS-1$
-
- helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
- input,
- MODIFIERS, EMPTY_CONTEXT, null,
- TranslatedCommand.EXEC_TYPE_QUERY,
- output);
- }
-
public void testAliasedGroup() throws Exception {
helpTestVisitor(getTestVDB(),
"select y.part_name from parts as y", //$NON-NLS-1$
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT y.PART_NAME FROM PARTS y"); //$NON-NLS-1$
}
@@ -367,7 +332,6 @@
"select {d'2002-12-31'} FROM parts", //$NON-NLS-1$
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT {d'2002-12-31'} FROM PARTS"); //$NON-NLS-1$
}
@@ -376,7 +340,6 @@
"select {t'13:59:59'} FROM parts", //$NON-NLS-1$
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT {ts'1970-01-01 13:59:59'} FROM PARTS");
//$NON-NLS-1$
}
@@ -385,34 +348,14 @@
"select {ts'2002-12-31 13:59:59'} FROM parts",
//$NON-NLS-1$
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT {ts'2002-12-31 13:59:59.0'} FROM PARTS");
//$NON-NLS-1$
}
- public void testTimestampLiteralInCriteria() throws Exception {
- helpTestVisitor(getTimestampTestVDB(),
- "select timestampvalue FROM hugea WHERE timestampvalue =
{ts'2002-12-31 13:59:59.0'}", //$NON-NLS-1$
- MODIFIERS,
- null,
- TranslatedCommand.EXEC_TYPE_QUERY,
- "SELECT HUGEA.TIMESTAMPVALUE FROM HUGEA WHERE HUGEA.TIMESTAMPVALUE =
to_timestamp('2002-12-31 13:59:59.0','YYYY-MM-DD HH24:MI:SS.FF')");
//$NON-NLS-1$
- }
-
- public void testTimestampLiteralInCriteria2() throws Exception {
- helpTestVisitor(getTimestampTestVDB(),
- "select datevalue FROM hugea WHERE datevalue = {ts'2002-12-31
13:59:59.0'}", //$NON-NLS-1$
- MODIFIERS,
- null,
- TranslatedCommand.EXEC_TYPE_QUERY,
- "SELECT HUGEA.DATEVALUE FROM HUGEA WHERE HUGEA.DATEVALUE =
to_date('2002-12-31 13:59:59','YYYY-MM-DD HH24:MI:SS')");
//$NON-NLS-1$
- }
-
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,
- TranslatedCommand.EXEC_TYPE_QUERY,
"(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$
}
@@ -421,7 +364,6 @@
"select part_id FROM parts UNION ALL select part_name FROM
parts ORDER BY part_id", //$NON-NLS-1$
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY,
"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$
}
@@ -430,7 +372,6 @@
"select part_id as p FROM parts UNION ALL select part_name
FROM parts ORDER BY p", //$NON-NLS-1$
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY,
"SELECT PARTS.PART_ID AS p FROM PARTS UNION ALL SELECT
PARTS.PART_NAME FROM PARTS ORDER BY p"); //$NON-NLS-1$
}
@@ -441,7 +382,6 @@
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
input,
MODIFIERS, EMPTY_CONTEXT, null,
- TranslatedCommand.EXEC_TYPE_UPDATE,
output);
}
@@ -463,7 +403,7 @@
input,
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
/**
@@ -482,7 +422,7 @@
input,
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
/**
@@ -500,34 +440,10 @@
input,
MODIFIERS,
null,
- TranslatedCommand.EXEC_TYPE_QUERY, output);
+ output);
}
/**
- * Test using an Oracle sequence object to generate (via "nextVal") a value
to use
- * in an insert statement. Currently, MM does not allow column names in the value
list
- * of an Insert statement. This depends on the column being modeled with special
stuff
- * in it's "name in source" field. Case 3743
- *
- * @since 4.3
- */
- public void testInsertUsingSequence() throws Exception {
-
- String input = "INSERT INTO PARTS (PART_ID, PART_NAME, PART_COLOR,
PART_WEIGHT) VALUES ('blah', 'Toaster', 'Beige', '2
kilos')"; //$NON-NLS-1$
-
- // Column "PART_ID" is modeled with a name in source of
'PART_ID:USE_SEQUENCE=MY_SEQ.nextVal',
- // the Oracle SQL Connector will extract the sequence value and put it in the
db-specific SQL
- String output = "INSERT INTO PARTS (PART_ID, PART_NAME, PART_COLOR,
PART_WEIGHT) VALUES (MY_SEQ.nextVal, 'Toaster', 'Beige', '2
kilos')"; //$NON-NLS-1$
-
- helpTestVisitor(getTestVDB(),
- input,
- MODIFIERS,
- null,
- TranslatedCommand.EXEC_TYPE_UPDATE, output);
-
- }
-
- /**
* Case 3744. Test that an Oracle-specific db hint, delivered as a String via
command
* payload, is added to the translated SQL.
*
@@ -545,7 +461,7 @@
MODIFIERS,
context,
null,
- TranslatedCommand.EXEC_TYPE_QUERY, output, false);
+ output, false);
}
/**
@@ -559,7 +475,7 @@
FakeMetadataFacade metadata = exampleCase3845();
- helpTestVisitor(metadata, input, MODIFIERS, EMPTY_CONTEXT, null,
TranslatedCommand.EXEC_TYPE_QUERY, output);
+ helpTestVisitor(metadata, input, MODIFIERS, EMPTY_CONTEXT, null, output);
}
/** create fake BQT metadata to test this case, name in source is important */
@@ -578,61 +494,36 @@
}
public void helpTestVisitor(String vdb, String input, String expectedOutput) throws
ConnectorException {
- helpTestVisitor(vdb, input, MODIFIERS, null, TranslatedCommand.EXEC_TYPE_QUERY,
expectedOutput);
+ helpTestVisitor(vdb, input, MODIFIERS, null, expectedOutput);
}
public void testRowLimit2() throws Exception {
String input = "select intkey from bqt1.smalla limit 100";
//$NON-NLS-1$
- String output = "SELECT MM_VIEW_FOR_LIMIT.intkey FROM (SELECT
MM_VIEW_FOR_LIMIT.intkey, ROWNUM AS MM_ROWNUM FROM (SELECT SmallA.IntKey AS intkey FROM
SmallA) MM_VIEW_FOR_LIMIT) MM_VIEW_FOR_LIMIT WHERE MM_VIEW_FOR_LIMIT.MM_ROWNUM <=
100"; //$NON-NLS-1$
+ String output = "SELECT * FROM (SELECT SmallA.IntKey FROM SmallA) WHERE
ROWNUM <= 100"; //$NON-NLS-1$
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
input,
MODIFIERS, EMPTY_CONTEXT, null,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
public void testRowLimit3() throws Exception {
String input = "select intkey from bqt1.smalla limit 50, 100";
//$NON-NLS-1$
- String output = "SELECT MM_VIEW_FOR_LIMIT.intkey FROM (SELECT
MM_VIEW_FOR_LIMIT.intkey, ROWNUM AS MM_ROWNUM FROM (SELECT SmallA.IntKey AS intkey FROM
SmallA) MM_VIEW_FOR_LIMIT) MM_VIEW_FOR_LIMIT WHERE (MM_VIEW_FOR_LIMIT.MM_ROWNUM > 50)
AND (MM_VIEW_FOR_LIMIT.MM_ROWNUM <= 150)"; //$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$
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
input,
MODIFIERS, EMPTY_CONTEXT, null,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
-
- public void testRowLimit4() throws Exception {
- String input = "select intkey, null, null, null from bqt1.smalla limit 50,
100"; //$NON-NLS-1$
- String output = "SELECT MM_VIEW_FOR_LIMIT.intkey, MM_VIEW_FOR_LIMIT.expr,
MM_VIEW_FOR_LIMIT.expr0, MM_VIEW_FOR_LIMIT.expr1 FROM (SELECT MM_VIEW_FOR_LIMIT.intkey,
MM_VIEW_FOR_LIMIT.expr, MM_VIEW_FOR_LIMIT.expr0, MM_VIEW_FOR_LIMIT.expr1, ROWNUM AS
MM_ROWNUM FROM (SELECT SmallA.IntKey AS intkey, NULL AS expr, NULL AS expr0, NULL AS expr1
FROM SmallA) MM_VIEW_FOR_LIMIT) MM_VIEW_FOR_LIMIT WHERE (MM_VIEW_FOR_LIMIT.MM_ROWNUM >
50) AND (MM_VIEW_FOR_LIMIT.MM_ROWNUM <= 150)"; //$NON-NLS-1$
-
- helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
- input,
- MODIFIERS, EMPTY_CONTEXT, null,
- TranslatedCommand.EXEC_TYPE_QUERY,
- output);
- }
-
- public void testRowLimitWithOrderBy() throws Exception {
- String input = "select null, intkey as expr, null from bqt1.smalla order by
expr limit 50, 100"; //$NON-NLS-1$
- String output = "SELECT MM_VIEW_FOR_LIMIT.expr, MM_VIEW_FOR_LIMIT.expr0,
MM_VIEW_FOR_LIMIT.expr1 FROM (SELECT MM_VIEW_FOR_LIMIT.expr, MM_VIEW_FOR_LIMIT.expr0,
MM_VIEW_FOR_LIMIT.expr1, ROWNUM AS MM_ROWNUM FROM (SELECT NULL AS expr, SmallA.IntKey AS
expr0, NULL AS expr1 FROM SmallA ORDER BY expr0) MM_VIEW_FOR_LIMIT) MM_VIEW_FOR_LIMIT
WHERE (MM_VIEW_FOR_LIMIT.MM_ROWNUM > 50) AND (MM_VIEW_FOR_LIMIT.MM_ROWNUM <=
150)"; //$NON-NLS-1$
-
- helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
- input,
- MODIFIERS, EMPTY_CONTEXT, null,
- TranslatedCommand.EXEC_TYPE_QUERY,
- output);
- }
-
+
public void testLimitWithNestedInlineView() throws Exception {
String input = "select max(intkey), stringkey from (select intkey, stringkey
from bqt1.smalla order by intkey limit 100) x group by intkey"; //$NON-NLS-1$
- String output = "SELECT MAX(x.intkey), x.stringkey FROM (SELECT
MM_VIEW_FOR_LIMIT.intkey, MM_VIEW_FOR_LIMIT.stringkey FROM (SELECT
MM_VIEW_FOR_LIMIT.intkey, MM_VIEW_FOR_LIMIT.stringkey, ROWNUM AS MM_ROWNUM FROM (SELECT
SmallA.IntKey AS intkey, SmallA.StringKey AS stringkey FROM SmallA ORDER BY intkey)
MM_VIEW_FOR_LIMIT) MM_VIEW_FOR_LIMIT WHERE MM_VIEW_FOR_LIMIT.MM_ROWNUM <= 100) x GROUP
BY x.intkey"; //$NON-NLS-1$
+ String output = "SELECT MAX(x.intkey), x.stringkey FROM (SELECT * FROM
(SELECT SmallA.IntKey, SmallA.StringKey FROM SmallA ORDER BY intkey) WHERE ROWNUM <=
100) x GROUP BY x.intkey"; //$NON-NLS-1$
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
input,
MODIFIERS, EMPTY_CONTEXT, null,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
@@ -643,7 +534,6 @@
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
input,
MODIFIERS, EMPTY_CONTEXT, null,
- TranslatedCommand.EXEC_TYPE_QUERY,
output);
}
Modified:
trunk/test-integration/src/test/java/com/metamatrix/data/metadata/runtime/TestMetadataID.java
===================================================================
---
trunk/test-integration/src/test/java/com/metamatrix/data/metadata/runtime/TestMetadataID.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/test-integration/src/test/java/com/metamatrix/data/metadata/runtime/TestMetadataID.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -38,6 +38,7 @@
import com.metamatrix.connector.language.IQuery;
import com.metamatrix.connector.language.ISelectSymbol;
import com.metamatrix.connector.metadata.runtime.MetadataID;
+import com.metamatrix.connector.metadata.runtime.MetadataID.Type;
import com.metamatrix.core.util.UnitTestUtil;
/**
@@ -75,7 +76,7 @@
MetadataID groupID = getGroupID(fullGroupName, transUtil);
assertEquals(fullGroupName, groupID.getFullName());
assertEquals(shortGroupName, groupID.getName());
- assertEquals(MetadataID.TYPE_GROUP, groupID.getType());
+ assertEquals(Type.TYPE_GROUP, groupID.getType());
assertNull(groupID.getParentID());
// Check children
@@ -84,7 +85,7 @@
Iterator childIter = children.iterator();
while(childIter.hasNext()) {
MetadataID childID = (MetadataID) childIter.next();
- assertEquals(MetadataID.TYPE_ELEMENT, childID.getType());
+ assertEquals(Type.TYPE_ELEMENT, childID.getType());
assertEquals(groupID, childID.getParentID());
assertTrue(childID.getFullName().startsWith(groupID.getFullName()));
}
@@ -109,7 +110,7 @@
public void helpTestElementID(String groupName, String elementName,
TranslationUtility transUtil) throws Exception {
MetadataID elementID = getElementID(groupName, elementName, transUtil);
- assertEquals(MetadataID.TYPE_ELEMENT, elementID.getType());
+ assertEquals(Type.TYPE_ELEMENT, elementID.getType());
assertEquals(groupName + "." + elementName, elementID.getFullName());
//$NON-NLS-1$
assertEquals(elementName, elementID.getName());
assertEquals(Collections.EMPTY_LIST, elementID.getChildIDs());
@@ -145,7 +146,7 @@
public void helpTestProcedureID(String procName, String shortName, int
inputParamCount, String[] paramNames, TranslationUtility transUtil) throws Exception {
MetadataID procID = getProcedureID(procName, inputParamCount, transUtil);
- assertEquals(MetadataID.TYPE_PROCEDURE, procID.getType());
+ assertEquals(Type.TYPE_PROCEDURE, procID.getType());
assertEquals(procName, procID.getFullName()); //$NON-NLS-1$
assertNull(procID.getParentID());
assertEquals(shortName, procID.getName());
@@ -157,7 +158,7 @@
Iterator childIter = children.iterator();
while(childIter.hasNext()) {
MetadataID childID = (MetadataID) childIter.next();
- assertEquals(MetadataID.TYPE_PARAMETER, childID.getType());
+ assertEquals(Type.TYPE_PARAMETER, childID.getType());
assertEquals(procID, childID.getParentID());
assertTrue(childID.getFullName().startsWith(procID.getFullName()));
Modified:
trunk/test-integration/src/test/java/com/metamatrix/data/metadata/runtime/TestParams.java
===================================================================
---
trunk/test-integration/src/test/java/com/metamatrix/data/metadata/runtime/TestParams.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/test-integration/src/test/java/com/metamatrix/data/metadata/runtime/TestParams.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -35,6 +35,7 @@
import com.metamatrix.connector.metadata.runtime.MetadataID;
import com.metamatrix.connector.metadata.runtime.Parameter;
import com.metamatrix.connector.metadata.runtime.TypeModel;
+import com.metamatrix.connector.metadata.runtime.MetadataID.Type;
import com.metamatrix.core.util.UnitTestUtil;
@@ -103,7 +104,7 @@
assertEquals(scale, p.getScale());
assertEquals(null, param.getValue());
assertEquals(false, param.getValueSpecified());
- assertEquals(MetadataID.TYPE_PARAMETER, metadataID.getType());
+ assertEquals(Type.TYPE_PARAMETER, metadataID.getType());
//System.out.println("\n" + p.getModeledType() + "\n" +
p.getModeledBaseType() + "\n" + p.getModeledPrimitiveType());
Modified:
trunk/test-integration/src/test/java/com/metamatrix/data/metadata/runtime/TestProcedure.java
===================================================================
---
trunk/test-integration/src/test/java/com/metamatrix/data/metadata/runtime/TestProcedure.java 2009-02-16
21:35:28 UTC (rev 475)
+++
trunk/test-integration/src/test/java/com/metamatrix/data/metadata/runtime/TestProcedure.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -36,6 +36,7 @@
import com.metamatrix.connector.metadata.runtime.Parameter;
import com.metamatrix.connector.metadata.runtime.Procedure;
import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
+import com.metamatrix.connector.metadata.runtime.MetadataID.Type;
import com.metamatrix.core.util.UnitTestUtil;
/**
@@ -130,7 +131,7 @@
MetadataID elemID = (MetadataID) rsCols.get(0);
assertEquals("RSCol1", elemID.getName()); //$NON-NLS-1$
assertEquals("ConnectorMetadata.TestProc2.RSParam.RSCol1",
elemID.getFullName()); //$NON-NLS-1$
- assertEquals(MetadataID.TYPE_ELEMENT, elemID.getType());
+ assertEquals(Type.TYPE_ELEMENT, elemID.getType());
Element e1 = (Element) rmd.getObject(elemID);
assertEquals("Result set column name in source", e1.getNameInSource());
//$NON-NLS-1$
assertEquals(java.sql.Timestamp.class, e1.getJavaType());
@@ -139,7 +140,7 @@
MetadataID elemID2 = (MetadataID) rsCols.get(1);
assertEquals("RSCol2", elemID2.getName()); //$NON-NLS-1$
assertEquals("ConnectorMetadata.TestProc2.RSParam.RSCol2",
elemID2.getFullName()); //$NON-NLS-1$
- assertEquals(MetadataID.TYPE_ELEMENT, elemID2.getType());
+ assertEquals(Type.TYPE_ELEMENT, elemID2.getType());
Element e2 = (Element) rmd.getObject(elemID2);
assertEquals(null, e2.getNameInSource()); //$NON-NLS-1$
assertEquals(String.class, e2.getJavaType());
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-16
21:35:28 UTC (rev 475)
+++
trunk/test-integration/src/test/java/com/metamatrix/data/visitor/util/TestSQLStringVisitor.java 2009-02-19
17:59:09 UTC (rev 476)
@@ -34,8 +34,8 @@
import com.metamatrix.connector.language.IFunction;
import com.metamatrix.connector.language.IGroup;
import com.metamatrix.connector.language.ILanguageObject;
-import com.metamatrix.connector.metadata.runtime.MetadataID;
import com.metamatrix.connector.metadata.runtime.RuntimeMetadata;
+import com.metamatrix.connector.metadata.runtime.MetadataID.Type;
import com.metamatrix.connector.visitor.util.SQLStringVisitor;
import com.metamatrix.dqp.internal.datamgr.language.AggregateImpl;
import com.metamatrix.dqp.internal.datamgr.language.ElementImpl;
@@ -43,7 +43,6 @@
import com.metamatrix.dqp.internal.datamgr.language.GroupImpl;
import com.metamatrix.dqp.internal.datamgr.language.LiteralImpl;
import com.metamatrix.dqp.internal.datamgr.language.TestAggregateImpl;
-import com.metamatrix.dqp.internal.datamgr.language.TestCaseExpressionImpl;
import com.metamatrix.dqp.internal.datamgr.language.TestCompareCriteriaImpl;
import com.metamatrix.dqp.internal.datamgr.language.TestDeleteImpl;
import com.metamatrix.dqp.internal.datamgr.language.TestElementImpl;
@@ -66,9 +65,9 @@
import com.metamatrix.dqp.internal.datamgr.language.TestSearchedCaseExpressionImpl;
import com.metamatrix.dqp.internal.datamgr.language.TestSelectImpl;
import com.metamatrix.dqp.internal.datamgr.language.TestSelectSymbolImpl;
+import com.metamatrix.dqp.internal.datamgr.language.TestSetQueryImpl;
import com.metamatrix.dqp.internal.datamgr.language.TestSubqueryCompareCriteriaImpl;
import com.metamatrix.dqp.internal.datamgr.language.TestSubqueryInCriteriaImpl;
-import com.metamatrix.dqp.internal.datamgr.language.TestSetQueryImpl;
import com.metamatrix.dqp.internal.datamgr.language.TestUpdateImpl;
import com.metamatrix.dqp.internal.datamgr.language.TstLanguageBridgeFactory;
import com.metamatrix.dqp.internal.datamgr.metadata.MetadataFactory;
@@ -84,7 +83,7 @@
public class TestSQLStringVisitor extends TestCase {
- public static final RuntimeMetadata metadata =
TstLanguageBridgeFactory.metadataFactory.createRuntimeMetadata();
+ public static final RuntimeMetadata metadata =
TstLanguageBridgeFactory.metadataFactory.getRuntimeMetadata();
/**
@@ -96,11 +95,11 @@
}
private String getString(ILanguageObject obj) {
- return SQLStringVisitor.getSQLString(obj, metadata);
+ return SQLStringVisitor.getSQLString(obj);
}
private String getString(ILanguageObject obj, RuntimeMetadata metadata) {
- return SQLStringVisitor.getSQLString(obj, metadata);
+ return SQLStringVisitor.getSQLString(obj);
}
/** create fake BQT metadata to test this case, name in source is important */
@@ -139,54 +138,6 @@
}
/*
- * Test for void visit(ICaseExpression)
- */
- public void testVisitICaseExpression() throws Exception {
- String expected = "CASE WHEN g1.e1='a' THEN 0 WHEN g1.e1='b'
THEN 1 WHEN g1.e1='c' THEN 2 ELSE 9999 END"; //$NON-NLS-1$
- assertEquals(expected, getString(TestCaseExpressionImpl.example()));
- }
-
- /*
- * Test for void visit(ICaseExpression)
- */
- public void testVisitICaseExpressionNulFirst() throws Exception {
- String expected = "CASE WHEN g1.e1 IS NULL THEN 0 WHEN g1.e1='b'
THEN 1 WHEN g1.e1='c' THEN 2 ELSE 9999 END"; //$NON-NLS-1$
- assertEquals(expected, getString(TestCaseExpressionImpl.exampleNullFirst()));
- }
-
- /*
- * Test for void visit(ICaseExpression)
- */
- public void testVisitICaseExpressionNullMiddle() throws Exception {
- String expected = "CASE WHEN g1.e1 IS NULL THEN 1 WHEN g1.e1='a'
THEN 0 WHEN g1.e1='c' THEN 2 ELSE 9999 END"; //$NON-NLS-1$
- assertEquals(expected, getString(TestCaseExpressionImpl.exampleNullMiddle()));
- }
-
- /*
- * Test for void visit(ICaseExpression)
- */
- public void testVisitICaseExpressionNullLast() throws Exception {
- String expected = "CASE WHEN g1.e1 IS NULL THEN 2 WHEN g1.e1='a'
THEN 0 WHEN g1.e1='b' THEN 1 ELSE 9999 END"; //$NON-NLS-1$
- assertEquals(expected, getString(TestCaseExpressionImpl.exampleNullLast()));
- }
-
- /*
- * Test for void visit(ICaseExpression)
- */
- public void testVisitICaseExpressionNullElse() throws Exception {
- String expected = "CASE WHEN g1.e1='a' THEN 0 WHEN g1.e1='b'
THEN 1 WHEN g1.e1='c' THEN 2 ELSE g1.e1 END"; //$NON-NLS-1$
- assertEquals(expected, getString(TestCaseExpressionImpl.exampleElementElse() )
);
- }
-
- /*
- * Test for void visit(ICaseExpression)
- */
- public void testVisitICaseExpressionInteger() throws Exception {
- String expected = "CASE WHEN g1.e1='a' THEN 0 WHEN g1.e1='b'
THEN 1 WHEN g1.e1='c' THEN 2 ELSE g1.e1 END"; //$NON-NLS-1$
- assertEquals(expected, getString(TestCaseExpressionImpl.exampleInteger() ) );
- }
-
- /*
* Test for void visit(ICompareCriteria)
*/
public void testVisitICompareCriteria() throws Exception {
@@ -269,8 +220,8 @@
IExpression [] params = null;
params = new IExpression[2];
- IGroup g = new GroupImpl("SmallA", null,
metadataFactory.createMetadataID(facade.getStore().findObject("BQT1.SmallA",
FakeMetadataObject.GROUP), MetadataID.TYPE_GROUP)); //$NON-NLS-1$
- IElement e = new ElementImpl(g, "DoubleNum",
metadataFactory.createMetadataID(facade.getStore().findObject("DoubleNum",
FakeMetadataObject.ELEMENT), MetadataID.TYPE_ELEMENT), Double.class); //$NON-NLS-1$
//$NON-NLS-2$
+ IGroup g = new GroupImpl("SmallA", null,
metadataFactory.createMetadataID(facade.getStore().findObject("BQT1.SmallA",
FakeMetadataObject.GROUP), Type.TYPE_GROUP)); //$NON-NLS-1$
+ IElement e = new ElementImpl(g, "DoubleNum",
metadataFactory.createMetadataID(facade.getStore().findObject("DoubleNum",
FakeMetadataObject.ELEMENT), Type.TYPE_ELEMENT), Double.class); //$NON-NLS-1$
//$NON-NLS-2$
params[0] = e;
params[1] = new LiteralImpl("integer", String.class); //$NON-NLS-1$
@@ -294,19 +245,6 @@
assertEquals(expected, getString(test));
}
- public void testVisitConvertFunctionSQLServerStyle() throws Exception {
- String expected = "convert(integer, columnA)"; //$NON-NLS-1$
-
- IExpression [] params = null;
- params = new IExpression[2];
- params[0] = new LiteralImpl("integer", String.class); //$NON-NLS-1$
- params[1] = new ElementImpl(null, "columnA", null, String.class);
//$NON-NLS-1$
- IFunction test = new FunctionImpl("convert", params, Integer.class);
//$NON-NLS-1$
-
- assertEquals(expected, getString(test));
-
- }
-
/*
* Test for void visit(IGroup)
*/