teiid SVN: r1193 - in trunk: common-core/src/main/java/com/metamatrix/common/util and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-07-27 14:50:49 -0400 (Mon, 27 Jul 2009)
New Revision: 1193
Modified:
trunk/build/kit-runtime/deploy.properties
trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java
trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java
Log:
TEIID-740 update to numeric getters to check for ws and empty strings
Modified: trunk/build/kit-runtime/deploy.properties
===========================================================…
[View More]========
--- trunk/build/kit-runtime/deploy.properties 2009-07-27 03:24:44 UTC (rev 1192)
+++ trunk/build/kit-runtime/deploy.properties 2009-07-27 18:50:49 UTC (rev 1193)
@@ -123,8 +123,8 @@
server.portNumber=31000
server.bindAddress=localhost
server.maxSocketThreads=15
-server.inputBufferSize=0
-server.outputBufferSize=0
+server.inputBufferSize=0
+server.outputBufferSize=0
# SSL Settings
ssl.enabled=false
Modified: trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java 2009-07-27 03:24:44 UTC (rev 1192)
+++ trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java 2009-07-27 18:50:49 UTC (rev 1193)
@@ -42,7 +42,6 @@
import java.util.Properties;
import com.metamatrix.common.properties.UnmodifiableProperties;
-import com.metamatrix.common.protocol.URLHelper;
import com.metamatrix.core.CorePlugin;
import com.metamatrix.core.MetaMatrixRuntimeException;
import com.metamatrix.core.util.ArgCheck;
@@ -346,63 +345,83 @@
}
public static int getIntProperty(Properties props, String propName, int defaultValue) throws InvalidPropertyException {
- int val = defaultValue;
String stringVal = props.getProperty(propName);
- if(stringVal != null && stringVal.trim().length() > 0) {
- try {
- val = Integer.parseInt(stringVal);
- } catch(NumberFormatException e) {
- throw new InvalidPropertyException(propName, stringVal, Integer.class, e);
- }
+ if(stringVal == null) {
+ return defaultValue;
}
- return val;
+ stringVal = stringVal.trim();
+ if (stringVal.length() == 0) {
+ return defaultValue;
+ }
+ try {
+ return Integer.parseInt(stringVal);
+ } catch(NumberFormatException e) {
+ throw new InvalidPropertyException(propName, stringVal, Integer.class, e);
+ }
}
public static long getLongProperty(Properties props, String propName, long defaultValue) {
- long val = defaultValue;
String stringVal = props.getProperty(propName);
- if(stringVal != null && stringVal.trim().length() > 0) {
- try {
- val = Long.parseLong(props.getProperty(propName));
- } catch(NumberFormatException e) {
- throw new InvalidPropertyException(propName, stringVal, Integer.class, e);
- }
+ if(stringVal == null) {
+ return defaultValue;
}
- return val;
+ stringVal = stringVal.trim();
+ if (stringVal.length() == 0) {
+ return defaultValue;
+ }
+ try {
+ return Long.parseLong(stringVal);
+ } catch(NumberFormatException e) {
+ throw new InvalidPropertyException(propName, stringVal, Long.class, e);
+ }
}
public static float getFloatProperty(Properties props, String propName, float defaultValue) {
- float val = defaultValue;
- if(props.containsKey(propName)) {
- try {
- Float f = new Float(props.getProperty(propName));
- val = f.floatValue();
- } catch(NumberFormatException e) {
- // ignore
- }
+ String stringVal = props.getProperty(propName);
+ if(stringVal == null) {
+ return defaultValue;
}
- return val;
+ stringVal = stringVal.trim();
+ if (stringVal.length() == 0) {
+ return defaultValue;
+ }
+ try {
+ return Float.parseFloat(stringVal);
+ } catch(NumberFormatException e) {
+ throw new InvalidPropertyException(propName, stringVal, Float.class, e);
+ }
}
public static double getDoubleProperty(Properties props, String propName, double defaultValue) {
- double val = defaultValue;
- if(props.containsKey(propName)) {
- try {
- Double d = new Double(props.getProperty(propName));
- val = d.doubleValue();
- } catch(NumberFormatException e) {
- // ignore
- }
+ String stringVal = props.getProperty(propName);
+ if(stringVal == null) {
+ return defaultValue;
}
- return val;
+ stringVal = stringVal.trim();
+ if (stringVal.length() == 0) {
+ return defaultValue;
+ }
+ try {
+ return Double.parseDouble(stringVal);
+ } catch(NumberFormatException e) {
+ throw new InvalidPropertyException(propName, stringVal, Double.class, e);
+ }
}
public static boolean getBooleanProperty(Properties props, String propName, boolean defaultValue) {
- boolean val = defaultValue;
- if(props.containsKey(propName)) {
- val = Boolean.valueOf(props.getProperty(propName)).booleanValue();
+ String stringVal = props.getProperty(propName);
+ if(stringVal == null) {
+ return defaultValue;
}
- return val;
+ stringVal = stringVal.trim();
+ if (stringVal.length() == 0) {
+ return defaultValue;
+ }
+ try {
+ return Boolean.valueOf(stringVal);
+ } catch(NumberFormatException e) {
+ throw new InvalidPropertyException(propName, stringVal, Float.class, e);
+ }
}
/**
Modified: trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java 2009-07-27 03:24:44 UTC (rev 1192)
+++ trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java 2009-07-27 18:50:49 UTC (rev 1193)
@@ -646,29 +646,29 @@
public void testOverrideProperties() {
Properties p = new Properties();
- p.setProperty("foo", "bar");
- p.setProperty("foo1", "bar1");
- p.setProperty("foo2", "bar2");
+ p.setProperty("foo", "bar"); //$NON-NLS-1$ //$NON-NLS-2$
+ p.setProperty("foo1", "bar1"); //$NON-NLS-1$ //$NON-NLS-2$
+ p.setProperty("foo2", "bar2"); //$NON-NLS-1$ //$NON-NLS-2$
Properties p1 = new Properties(p);
- p1.setProperty("foo", "x");
+ p1.setProperty("foo", "x"); //$NON-NLS-1$ //$NON-NLS-2$
PropertiesUtils.setOverrideProperies(p1, p);
- assertEquals("bar", p1.getProperty("foo"));
+ assertEquals("bar", p1.getProperty("foo")); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals(1, p1.size());
}
public void testGetInvalidInt() {
Properties p = new Properties();
- p.setProperty("x", "y");
+ p.setProperty("x", "y"); //$NON-NLS-1$ //$NON-NLS-2$
try {
- PropertiesUtils.getIntProperty(p, "x", 1);
- fail("expected exception");
+ PropertiesUtils.getIntProperty(p, "x", 1); //$NON-NLS-1$
+ fail("expected exception"); //$NON-NLS-1$
} catch (InvalidPropertyException e) {
- assertEquals("Property 'x' with value 'y' is not a valid Integer.", e.getMessage());
+ assertEquals("Property 'x' with value 'y' is not a valid Integer.", e.getMessage()); //$NON-NLS-1$
}
}
@@ -707,25 +707,31 @@
public void testSetBeanProperties() {
Bean bean = new Bean();
Properties p = new Properties();
- p.setProperty("prop", "0");
- p.setProperty("prop1", "1");
- p.setProperty("prop2", "2");
- p.setProperty("prop3", "3");
+ p.setProperty("prop", "0"); //$NON-NLS-1$//$NON-NLS-2$
+ p.setProperty("prop1", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ p.setProperty("prop2", "2"); //$NON-NLS-1$ //$NON-NLS-2$
+ p.setProperty("prop3", "3"); //$NON-NLS-1$ //$NON-NLS-2$
PropertiesUtils.setBeanProperties(bean, p, null);
assertEquals(0, bean.getProp());
- assertEquals("1", bean.getProp1());
+ assertEquals("1", bean.getProp1()); //$NON-NLS-1$
assertEquals(2d, bean.getProp2());
- assertEquals(Arrays.asList("3"), bean.getProp3());
+ assertEquals(Arrays.asList("3"), bean.getProp3()); //$NON-NLS-1$
- p.setProperty("prop", "?");
+ p.setProperty("prop", "?"); //$NON-NLS-1$ //$NON-NLS-2$
try {
PropertiesUtils.setBeanProperties(bean, p, null);
- fail("expected exception");
+ fail("expected exception"); //$NON-NLS-1$
} catch (InvalidPropertyException e) {
}
}
+
+ public void testGetInt() {
+ Properties p = new Properties();
+ p.setProperty("prop", "0 "); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(PropertiesUtils.getIntProperty(p, "prop", -1), 0); //$NON-NLS-1$
+ }
}
[View Less]
15 years, 8 months
teiid SVN: r1192 - in trunk: connectors/connector-text/src/main/resources and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-07-26 23:24:44 -0400 (Sun, 26 Jul 2009)
New Revision: 1192
Modified:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyCapabilities.java
trunk/connectors/connector-text/src/main/resources/connector-text.xml
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java
Log:
TEIID-739 minor update to derby and adding immutable=true to the text connector.
Modified: trunk/connectors/…
[View More]connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyCapabilities.java 2009-07-27 03:23:43 UTC (rev 1191)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyCapabilities.java 2009-07-27 03:24:44 UTC (rev 1192)
@@ -37,9 +37,9 @@
@Test public void testFunctionSupport() {
DerbyCapabilities derbyCapabilities = new DerbyCapabilities();
- assertEquals(32, derbyCapabilities.getSupportedFunctions().size());
+ assertEquals(27, derbyCapabilities.getSupportedFunctions().size());
derbyCapabilities.setVersion(DerbyCapabilities.TEN_4);
- assertEquals(48, derbyCapabilities.getSupportedFunctions().size());
+ assertEquals(43, derbyCapabilities.getSupportedFunctions().size());
}
}
Modified: trunk/connectors/connector-text/src/main/resources/connector-text.xml
===================================================================
--- trunk/connectors/connector-text/src/main/resources/connector-text.xml 2009-07-27 03:23:43 UTC (rev 1191)
+++ trunk/connectors/connector-text/src/main/resources/connector-text.xml 2009-07-27 03:24:44 UTC (rev 1192)
@@ -7,5 +7,6 @@
<PropertyDefinition Name="EnforceColumnCount" DisplayName="Enforce Column Count" ShortDescription="This forces the number of columns in text file to match what was modeled" DefaultValue="false" PropertyType="Boolean" />
<PropertyDefinition Name="DateResultFormatsDelimiter" DisplayName="Date Result Formats Delimiter" ShortDescription="" IsExpert="true" />
<PropertyDefinition Name="DateResultFormats" DisplayName="Date Result Formats" ShortDescription="" IsExpert="true" />
+ <PropertyDefinition Name="Immutable" DisplayName="Is Immutable" ShortDescription="True if the source never changes." DefaultValue="true" IsRequired="true" PropertyType="Boolean" IsExpert="true" />
</ComponentType>
\ No newline at end of file
Modified: trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java
===================================================================
--- trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java 2009-07-27 03:23:43 UTC (rev 1191)
+++ trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java 2009-07-27 03:24:44 UTC (rev 1192)
@@ -54,8 +54,6 @@
import com.metamatrix.common.log.LogManager;
import com.metamatrix.common.protocol.URLHelper;
import com.metamatrix.common.util.PropertiesUtils;
-import com.metamatrix.common.util.crypto.CryptoException;
-import com.metamatrix.common.util.crypto.CryptoUtil;
import com.metamatrix.common.vdb.api.ModelInfo;
import com.metamatrix.common.vdb.api.VDBArchive;
import com.metamatrix.common.vdb.api.VDBDefn;
[View Less]
15 years, 8 months
teiid SVN: r1191 - in trunk: client-jdbc/src/main/java/org/teiid/jdbc and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-07-26 23:23:43 -0400 (Sun, 26 Jul 2009)
New Revision: 1191
Modified:
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDataSource.java
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDriver.java
trunk/client-jdbc/src/main/java/org/teiid/jdbc/EmbeddedProfile.java
trunk/client-jdbc/src/main/java/org/teiid/jdbc/TeiidDriver.java
trunk/runtime/src/test/java/com/metamatrix/jdbc/TestEmbeddedDriver.java
Log:
TEIID-701 changing legacy …
[View More]driver/datasource to just be extensions of the replacements
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDataSource.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDataSource.java 2009-07-27 03:18:45 UTC (rev 1190)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDataSource.java 2009-07-27 03:23:43 UTC (rev 1191)
@@ -22,107 +22,24 @@
package com.metamatrix.jdbc;
-import java.net.URL;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.Properties;
+import org.teiid.jdbc.TeiidDataSource;
-import com.metamatrix.common.api.MMURL;
-import com.metamatrix.common.protocol.URLHelper;
-
/**
* @since 4.3
*/
-public class EmbeddedDataSource extends BaseDataSource {
+public class EmbeddedDataSource extends TeiidDataSource {
- //*************************** EmbeddedDataSource Specific Properties
- /**
- * configFile -
- * The path and file name to which embedded DQP configuration info will be read. This property is <i>optional</i>; if none is
- * specified, then embedded DQP access cannot be used.
- */
- private String bootstrapFile;
-
- // string constant for the embedded configuration file property
- public static final String DQP_BOOTSTRAP_FILE = "bootstrapFile"; //$NON-NLS-1$
-
- public static final String SHUTDOWN = MMURL.CONNECTION.SHUTDOWN;
-
- // The driver used to connect
- private final transient EmbeddedDriver driver = new EmbeddedDriver();
-
- /**
- * Constructor for EmbeddedDataSource.
- */
public EmbeddedDataSource() {
}
- protected Properties buildProperties(final String userName,
- final String password) {
- Properties props = super.buildProperties(userName, password);
-
- if (this.getBootstrapFile().equals(EmbeddedDriver.getDefaultConnectionURL())) {
- props.put("vdb.definition", getDatabaseName() +".vdb"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- props.put(DQP_BOOTSTRAP_FILE, this.bootstrapFile);
- return props;
- }
-
- protected void validateProperties(final String userName,
- final String password) throws java.sql.SQLException {
- super.validateProperties(userName, password);
-
- // we do not have bootstrap file, make sure we have a default one.
- if (getBootstrapFile() == null && getDatabaseName() != null) {
- setBootstrapFile(EmbeddedDriver.getDefaultConnectionURL());
- }
-
- String reason = reasonWhyInvalidConfigFile(this.bootstrapFile);
- if (reason != null) {
- throw new SQLException(reason);
- }
- }
-
/**
- * Return the reason why the supplied config file may be invalid, or null if it is considered valid.
- *
- * @param configFile
- * a possible value for the property
- * @return the reason why the property is invalid, or null if it is considered valid
- * @see #setBootstrapFile(String)
- */
- public static String reasonWhyInvalidConfigFile(final String configFile) {
- if(configFile == null) {
- return getResourceMessage("EmbeddedDataSource.The_configFile_property_is_null"); //$NON-NLS-1$
- }
-
- try {
- URL url = URLHelper.buildURL(configFile);
- url.openStream();
- } catch (Exception e) {
- return getResourceMessage("EmbeddedDataSource.The_configFile_does_not_exist_or_cant_be_read"); //$NON-NLS-1$
- }
- return null;
- }
-
- /**
- * @see com.metamatrix.jdbc.BaseDataSource#getConnection(java.lang.String, java.lang.String)
- * @since 4.3
- */
- public Connection getConnection(String userName, String password) throws SQLException {
- validateProperties(userName, password);
- final Properties props = buildProperties(userName, password);
- return this.driver.createConnection(props);
- }
-
- /**
* Returns the path and file name from which embedded DQP configuration information will be read.
*
* @return the name of the config file for this data source; may be null
*/
public String getBootstrapFile() {
- return bootstrapFile;
+ return getEmbeddedBootstrapFile();
}
/**
@@ -132,7 +49,7 @@
* The name of the config file name to set
*/
public void setBootstrapFile(final String configFile) {
- this.bootstrapFile = configFile;
+ setEmbeddedBootstrapFile(configFile);
}
}
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDriver.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDriver.java 2009-07-27 03:18:45 UTC (rev 1190)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDriver.java 2009-07-27 03:23:43 UTC (rev 1191)
@@ -22,41 +22,15 @@
package com.metamatrix.jdbc;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.sql.Connection;
import java.sql.DriverManager;
-import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.teiid.jdbc.TeiidDriver;
-import com.metamatrix.common.classloader.PostDelegatingClassLoader;
-import com.metamatrix.common.comm.api.ServerConnection;
-import com.metamatrix.common.comm.api.ServerConnectionFactory;
-import com.metamatrix.common.comm.exception.CommunicationException;
-import com.metamatrix.common.comm.exception.ConnectionException;
-import com.metamatrix.common.protocol.MMURLConnection;
-import com.metamatrix.common.protocol.MetaMatrixURLStreamHandlerFactory;
-import com.metamatrix.common.protocol.URLHelper;
-import com.metamatrix.common.util.ApplicationInfo;
-import com.metamatrix.common.util.PropertiesUtils;
-import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
-import com.metamatrix.jdbc.util.MMJDBCURL;
-
/**
* <p> The java.sql.DriverManager class uses this class to connect to MetaMatrix.
* The Driver Manager maintains a pool of MMDriver objects, which it could use
@@ -64,7 +38,7 @@
* </p>
*/
-public final class EmbeddedDriver extends BaseDriver {
+public final class EmbeddedDriver extends TeiidDriver {
/**
* Match URL like
* - jdbc:metamatrix:BQT@c:/foo.properties;version=1..
@@ -83,7 +57,6 @@
private static Logger logger = Logger.getLogger("org.teiid.jdbc"); //$NON-NLS-1$
- private static EmbeddedTransport currentTransport = null;
static Pattern urlPattern = Pattern.compile(URL_PATTERN);
static Pattern basePattern = Pattern.compile(BASE_PATTERN);
@@ -97,168 +70,8 @@
logger.log(Level.SEVERE, logMsg);
}
}
-
- /**
- * This method tries to make a metamatrix connection to the given URL. This class
- * will return a null if this is not the right driver to connect to the given URL.
- * @param The URL used to establish a connection.
- * @return Connection object created
- * @throws SQLException if it is unable to establish a connection to the MetaMatrix server.
- */
- public Connection connect(String url, Properties info)
- throws SQLException {
- Connection conn = null;
- // create a properties obj if it is null
- if (info == null) {
- info = new Properties();
- } else {
- info = PropertiesUtils.clone(info);
- }
- if (!acceptsURL(url)) {
- return null;
- }
- // parse the URL to add it's properties to properties object
- parseURL(url, info);
- conn = createConnection(info);
- // logging
- String logMsg = JDBCPlugin.Util.getString("JDBCDriver.Connection_sucess"); //$NON-NLS-1$
- logger.fine(logMsg);
-
- return conn;
-
- }
-
- Connection createConnection(Properties info) throws SQLException{
-
- // first validate the properties as this may called from the EmbeddedDataSource
- // and make sure we have all the properties we need.
- validateProperties(info);
-
- URL dqpURL;
- try {
- dqpURL = URLHelper.buildURL(info.getProperty(EmbeddedDataSource.DQP_BOOTSTRAP_FILE));
- } catch (MalformedURLException e) {
- throw MMSQLException.create(e);
- }
-
- // now create the connection
- EmbeddedTransport transport = getDQPTransport(dqpURL, info);
-
- Connection conn = transport.createConnection(dqpURL, info);
-
- return conn;
- }
-
/**
- * Get the DQP transport or build the transport if one not available from the
- * DQP URL supplied. DQP transport contains all the details about DQP.
- * @param dqpURL - URL to the DQP.properties file
- * @return EmbeddedTransport
- * @throws SQLException
- * @since 4.4
- */
- private synchronized static EmbeddedTransport getDQPTransport(URL dqpURL, Properties info) throws SQLException {
- EmbeddedTransport transport = currentTransport;
- if (transport == null || !currentTransport.getURL().equals(dqpURL)) {
- // shutdown any previous instance; we do encourage single instance in a given VM
- shutdown();
- try {
- transport = new EmbeddedTransport(dqpURL, info);
- } catch (SQLException e) {
- logger.log(Level.SEVERE, "Could not start the embedded engine", e); //$NON-NLS-1$
- throw e;
- }
- }
- currentTransport = transport;
- return transport;
- }
-
- /**
- * This method parses the URL and adds properties to the the properties object. These include required and any optional
- * properties specified in the URL.
- * Expected URL format --
- * jdbc:metamatrix:local:VDB@<pathToConfigFile>logFile=<logFile.log>; logLevel=<logLevel>;txnAutoWrap=<?>;credentials=mycredentials;
- *
- * @param The URL needed to be parsed.
- * @param The properties object which is to be updated with properties in the URL.
- * @throws SQLException if the URL is not in the expected format.
- */
- protected void parseURL(String url, Properties info) throws SQLException {
- if (url == null || url.trim().length() == 0) {
- String logMsg = BaseDataSource.getResourceMessage("EmbeddedDriver.URL_must_be_specified"); //$NON-NLS-1$
- throw new SQLException(logMsg);
- }
-
- try {
- MMJDBCURL jdbcURL = new MMJDBCURL(url);
-
- // Set the VDB Name
- info.setProperty(BaseDataSource.VDB_NAME, jdbcURL.getVDBName());
-
- // Need to resolve the URL fully, if we are using the default URL like
- // jdbc:metamatrix:<vdbName>.., where as this fully qualifies to
- // jdbc:metamatrix:<vdbName>@classpath:<vdbName>/mm.properties;...
- String connectionURL = jdbcURL.getConnectionURL();
- if (connectionURL == null) {
- connectionURL = getDefaultConnectionURL();
- info.setProperty("vdb.definition", jdbcURL.getVDBName()+".vdb"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- info.setProperty(EmbeddedDataSource.DQP_BOOTSTRAP_FILE, connectionURL);
-
- Properties optionalParams = jdbcURL.getProperties();
- MMJDBCURL.normalizeProperties(info);
-
- Enumeration keys = optionalParams.keys();
- while (keys.hasMoreElements()) {
- String propName = (String)keys.nextElement();
- // Don't let the URL properties override the passed-in Properties object.
- if (!info.containsKey(propName)) {
- info.setProperty(propName, optionalParams.getProperty(propName));
- }
- }
- // add the property only if it is new because they could have
- // already been specified either through url or otherwise.
- if(! info.containsKey(BaseDataSource.VDB_VERSION) && jdbcURL.getVDBVersion() != null) {
- info.setProperty(BaseDataSource.VDB_VERSION, jdbcURL.getVDBVersion());
- }
- if(!info.containsKey(BaseDataSource.APP_NAME)) {
- info.setProperty(BaseDataSource.APP_NAME, BaseDataSource.DEFAULT_APP_NAME);
- }
- } catch (Exception e) {
- throw new SQLException(e);
- }
- }
-
- /**
- * Create the default connection URL, if one is not supplied
- * @param jdbcURL
- * @return default connection URL
- */
- static String getDefaultConnectionURL() {
- return "classpath:/deploy.properties"; //$NON-NLS-1$
- }
-
- /**
- * validate some required properties
- * @param info the connection properties to be validated
- * @throws SQLException
- * @since 4.3
- */
- void validateProperties(Properties info) throws SQLException {
-
- // VDB Name has to be there
- String value = null;
- value = info.getProperty(BaseDataSource.VDB_NAME);
- if (value == null || value.trim().length() == 0) {
- String logMsg = BaseDataSource.getResourceMessage("MMDataSource.Virtual_database_name_must_be_specified"); //$NON-NLS-1$
- throw new SQLException(logMsg);
- }
-
- }
-
-
- /**
* Returns true if the driver thinks that it can open a connection to the given URL. Typically drivers will return true if
* they understand the subprotocol specified in the URL and false if they don't. Expected URL format is
* jdbc:metamatrix:VDB@pathToPropertyFile;version=1;logFile=<logFile.log>;logLevel=<logLevel>;txnAutoWrap=<?>
@@ -283,227 +96,4 @@
return matched;
}
- @Override
- protected List<DriverPropertyInfo> getAdditionalPropertyInfo(String url,
- Properties info) {
- return Collections.emptyList();
- }
-
- /**
- * Get's the driver's major version number. Initially this should be 1.
- * @return major version number of the driver.
- */
- public int getMajorVersion() {
- return ApplicationInfo.getInstance().getMajorReleaseVersion();
- }
-
- /**
- * Get's the driver's minor version number. Initially this should be 0.
- * @return major version number of the driver.
- */
- public int getMinorVersion() {
- return ApplicationInfo.getInstance().getMinorReleaseVersion();
- }
-
- /**
- * Get's the name of the driver.
- * @return name of the driver
- */
- public String getDriverName() {
- return DRIVER_NAME;
- }
-
- /**
- * Shutdown the DQP instance which has been started using the given URL
- * @param dqpURL
- */
- public static synchronized void shutdown() {
- if (currentTransport != null) {
- currentTransport.shutdown();
- currentTransport = null;
- }
- }
-
- /**
- * inner class to hold DQP tansportMap object
- * @since 4.3
- */
- static class EmbeddedTransport {
- private ServerConnectionFactory connectionFactory;
- private ClassLoader classLoader;
- private URL url;
- Properties props;
-
- public EmbeddedTransport(URL dqpURL, Properties info) throws SQLException {
-
- this.url = dqpURL;
-
- //Load the properties from dqp.properties file
- props = loadDQPProperties(dqpURL);
- props.putAll(info);
-
- props = PropertiesUtils.resolveNestedProperties(props);
-
- // a non-delegating class loader will be created from where all third party dependent jars can be loaded
- ArrayList<URL> runtimeClasspathList = new ArrayList<URL>();
- String libLocation = props.getProperty(DQPEmbeddedProperties.DQP_LIBDIR, "./lib/"); //$NON-NLS-1$
- if (!libLocation.endsWith("/")) { //$NON-NLS-1$
- libLocation = libLocation + "/"; //$NON-NLS-1$
- }
-
- // find jars in the "lib" directory; patches is reverse alpaha and not case sensitive so small letters then capitals
- if (!EmbeddedDriver.getDefaultConnectionURL().equals(dqpURL.toString())) {
- runtimeClasspathList.addAll(libClassPath(dqpURL, libLocation+"patches/", MMURLConnection.REVERSEALPHA)); //$NON-NLS-1$
- runtimeClasspathList.addAll(libClassPath(dqpURL, libLocation, MMURLConnection.DATE));
-
- try {
- String configLocation = props.getProperty(DQPEmbeddedProperties.DQP_DEPLOYDIR, "./deploy/"); //$NON-NLS-1$
- if (!configLocation.endsWith("/")) { //$NON-NLS-1$
- configLocation = configLocation + "/"; //$NON-NLS-1$
- }
- runtimeClasspathList.add(URLHelper.buildURL(dqpURL, configLocation));
- } catch(IOException e) {
- // ignore..
- }
- }
-
- URL[] dqpClassPath = runtimeClasspathList.toArray(new URL[runtimeClasspathList.size()]);
- this.classLoader = new PostDelegatingClassLoader(dqpClassPath, this.getClass().getClassLoader(), new MetaMatrixURLStreamHandlerFactory());
-
- String logMsg = BaseDataSource.getResourceMessage("EmbeddedDriver.use_classpath"); //$NON-NLS-1$
- logger.log(Level.FINER, logMsg + " " + Arrays.toString(dqpClassPath)); //$NON-NLS-1$
-
- // Now using this class loader create the connection factory to the dqp.
- ClassLoader current = Thread.currentThread().getContextClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(this.classLoader);
- String className = "com.metamatrix.jdbc.EmbeddedConnectionFactoryImpl"; //$NON-NLS-1$
- Class<?> clazz = this.classLoader.loadClass(className);
- this.connectionFactory = (ServerConnectionFactory)clazz.newInstance();
- } catch (Exception e) {
- throw MMSQLException.create(e, "Could not load the embedded server, please ensure that your classpath is set correctly."); //$NON-NLS-1$
- } finally {
- Thread.currentThread().setContextClassLoader(current);
- }
- }
-
- URL getURL() {
- return this.url;
- }
-
- /**
- * Note that this only works when embedded loaded with "mmfile" protocol in the URL.
- * @param dqpURL
- * @return
- */
- private List<URL> libClassPath (URL dqpURL, String directory, String sortStyle) {
- ObjectInputStream in = null;
- ArrayList<URL> urlList = new ArrayList<URL>();
- try {
- urlList.add(URLHelper.buildURL(dqpURL, directory));
- dqpURL = URLHelper.buildURL(dqpURL, directory+"?action=list&filter=.jar&sort="+sortStyle); //$NON-NLS-1$
- in = new ObjectInputStream(dqpURL.openStream());
- String[] urls = (String[])in.readObject();
- for (int i = 0; i < urls.length; i++) {
- urlList.add(URLHelper.buildURL(urls[i]));
- }
- } catch(IOException e) {
- //ignore, treat as if lib does not exist
- } catch(ClassNotFoundException e) {
- //ignore, treat as if lib does not exist
- } finally {
- if (in != null) {
- try{in.close();}catch(IOException e) {}
- }
- }
- return urlList;
- }
-
- /**
- * Load DQP Properties from the URL supplied.
- * @param dqpURL - URL to the "dqp.properties" object
- * @return Properties loaded
- * @throws SQLException
- */
- Properties loadDQPProperties(URL dqpURL) throws SQLException {
- InputStream in = null;
- try{
- in = dqpURL.openStream();
- Properties props = new Properties();
- props.load(in);
-
- String logMsg = BaseDataSource.getResourceMessage("EmbeddedDriver.use_properties"); //$NON-NLS-1$
- logger.log(Level.FINER, logMsg + props);
- return props;
- }catch(IOException e) {
- String logMsg = BaseDataSource.getResourceMessage("EmbeddedTransport.invalid_dqpproperties_path", new Object[] {dqpURL}); //$NON-NLS-1$
- throw MMSQLException.create(e, logMsg);
- }finally {
- if (in != null) {
- try{in.close();}catch(IOException e) {}
- }
- }
- }
-
- /**
- * Shutdown the current transport
- */
- void shutdown() {
- this.connectionFactory.shutdown(false);
- }
-
- /**
- * Create a connection to the DQP defined by this transport object based on
- * properties supplied
- * @param info
- * @return Connection
- */
- Connection createConnection(URL url, Properties info) throws SQLException {
- ClassLoader current = null;
- try {
- current = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(classLoader);
- try {
- info.setProperty(DQPEmbeddedProperties.BOOTURL, url.toExternalForm());
- info.setProperty(DQPEmbeddedProperties.TEIID_HOME, getHomeDirectory(url));
- ServerConnection conn = connectionFactory.createConnection(info);
- return new MMConnection(conn, info, url.toExternalForm());
- } catch (CommunicationException e) {
- throw MMSQLException.create(e);
- } catch (ConnectionException e) {
- throw MMSQLException.create(e);
- }
- } finally {
- Thread.currentThread().setContextClassLoader(current);
- }
- }
-
- String getHomeDirectory(URL url) throws SQLException {
- try {
- // check the system wide
- String teiidHome = System.getProperty(DQPEmbeddedProperties.TEIID_HOME);
-
- // then check the deploy.properties
- if (teiidHome == null) {
- teiidHome = this.props.getProperty(DQPEmbeddedProperties.TEIID_HOME);
- }
-
- if (teiidHome == null) {
- if (getDefaultConnectionURL().equals(url.toString())) {
- teiidHome = System.getProperty("user.dir")+"/teiid"; //$NON-NLS-1$ //$NON-NLS-2$
- }
- else {
- URL installDirectory = URLHelper.buildURL(url, "."); //$NON-NLS-1$
- teiidHome = installDirectory.getPath();
- }
- }
- File f = new File(teiidHome);
- return f.getCanonicalPath();
- } catch(IOException e) {
- throw MMSQLException.create(e);
- }
- }
-
- }
-
}
Modified: trunk/client-jdbc/src/main/java/org/teiid/jdbc/EmbeddedProfile.java
===================================================================
--- trunk/client-jdbc/src/main/java/org/teiid/jdbc/EmbeddedProfile.java 2009-07-27 03:18:45 UTC (rev 1190)
+++ trunk/client-jdbc/src/main/java/org/teiid/jdbc/EmbeddedProfile.java 2009-07-27 03:23:43 UTC (rev 1191)
@@ -45,6 +45,7 @@
import org.teiid.adminapi.Admin;
import org.teiid.adminapi.AdminException;
+import com.metamatrix.common.api.MMURL;
import com.metamatrix.common.classloader.PostDelegatingClassLoader;
import com.metamatrix.common.comm.api.ServerConnection;
import com.metamatrix.common.comm.api.ServerConnectionFactory;
@@ -56,7 +57,6 @@
import com.metamatrix.common.util.PropertiesUtils;
import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
import com.metamatrix.jdbc.BaseDataSource;
-import com.metamatrix.jdbc.EmbeddedDataSource;
import com.metamatrix.jdbc.JDBCPlugin;
import com.metamatrix.jdbc.MMConnection;
import com.metamatrix.jdbc.MMSQLException;
@@ -105,7 +105,7 @@
// parse the URL to add it's properties to properties object
parseURL(url, info);
MMConnection conn = createConnection(info);
- boolean shutdown = Boolean.parseBoolean(info.getProperty(EmbeddedDataSource.SHUTDOWN, "false")); //$NON-NLS-1$
+ boolean shutdown = Boolean.parseBoolean(info.getProperty(MMURL.CONNECTION.SHUTDOWN, "false")); //$NON-NLS-1$
if (shutdown) {
Admin admin = conn.getAdminAPI();
try {
Modified: trunk/client-jdbc/src/main/java/org/teiid/jdbc/TeiidDriver.java
===================================================================
--- trunk/client-jdbc/src/main/java/org/teiid/jdbc/TeiidDriver.java 2009-07-27 03:18:45 UTC (rev 1190)
+++ trunk/client-jdbc/src/main/java/org/teiid/jdbc/TeiidDriver.java 2009-07-27 03:23:43 UTC (rev 1191)
@@ -50,7 +50,7 @@
* Look at {@link MMJDBCURL} KNOWN_PROPERTIES for list of known properties allowed.
*/
-public final class TeiidDriver implements Driver {
+public class TeiidDriver implements Driver {
private static Logger logger = Logger.getLogger("org.teiid.jdbc"); //$NON-NLS-1$
static final String DRIVER_NAME = "Teiid JDBC Driver"; //$NON-NLS-1$
Modified: trunk/runtime/src/test/java/com/metamatrix/jdbc/TestEmbeddedDriver.java
===================================================================
--- trunk/runtime/src/test/java/com/metamatrix/jdbc/TestEmbeddedDriver.java 2009-07-27 03:18:45 UTC (rev 1190)
+++ trunk/runtime/src/test/java/com/metamatrix/jdbc/TestEmbeddedDriver.java 2009-07-27 03:23:43 UTC (rev 1191)
@@ -24,10 +24,7 @@
import java.sql.DriverManager;
import java.sql.SQLException;
-import java.util.Properties;
-import com.metamatrix.jdbc.api.ExecutionProperties;
-
import junit.framework.TestCase;
@@ -81,70 +78,6 @@
assertTrue(driver.acceptsURL("jdbc:metamatrix:BQT;version=1;logFile=foo.txt")); //$NON-NLS-1$
}
- public void testParseURL() throws SQLException{
- Properties p = new Properties();
- driver.parseURL("jdbc:metamatrix:BQT@c:\\metamatrix\\dqp\\dqp.properties", p); //$NON-NLS-1$
- assertTrue(p.getProperty(BaseDataSource.VDB_NAME).equals("BQT")); //$NON-NLS-1$
- assertEquals("c:\\metamatrix\\dqp\\dqp.properties", p.getProperty(EmbeddedDataSource.DQP_BOOTSTRAP_FILE)); //$NON-NLS-1$
- assertEquals(3, p.size());
- }
-
- public void testParseURL2() throws SQLException {
- Properties p = new Properties();
- driver.parseURL("jdbc:metamatrix:BQT@\\metamatrix\\dqp\\dqp.properties;version=3", p); //$NON-NLS-1$
- assertTrue(p.getProperty(BaseDataSource.VDB_NAME).equals("BQT")); //$NON-NLS-1$
- assertEquals("\\metamatrix\\dqp\\dqp.properties", p.getProperty(EmbeddedDataSource.DQP_BOOTSTRAP_FILE)); //$NON-NLS-1$
- assertTrue(p.getProperty(BaseDataSource.VDB_VERSION).equals("3")); //$NON-NLS-1$
- assertTrue(p.getProperty(BaseDataSource.VERSION).equals("3")); //$NON-NLS-1$
- assertEquals(5, p.size());
- }
-
- public void testParseURL3() throws SQLException{
- Properties p = new Properties();
- driver.parseURL("jdbc:metamatrix:BQT@/metamatrix/dqp/dqp.properties;version=4;txnAutoWrap=ON;partialResultsMode=YES;", p); //$NON-NLS-1$
- assertTrue(p.getProperty(BaseDataSource.VDB_NAME).equals("BQT")); //$NON-NLS-1$
- assertTrue(p.getProperty(BaseDataSource.VDB_VERSION).equals("4")); //$NON-NLS-1$
- assertTrue(p.getProperty(BaseDataSource.VERSION).equals("4")); //$NON-NLS-1$
- assertTrue(p.getProperty(ExecutionProperties.PROP_TXN_AUTO_WRAP).equals("ON")); //$NON-NLS-1$
- assertTrue(p.getProperty(ExecutionProperties.PROP_PARTIAL_RESULTS_MODE).equals("YES")); //$NON-NLS-1$
- assertEquals(7, p.size());
- }
-
- public void testParseURL4() throws SQLException{
- Properties p = new Properties();
- driver.parseURL("jdbc:metamatrix:BQT@testdata/dqp/dqp.properties;partialResultsMode=true", p); //$NON-NLS-1$
- assertTrue(p.getProperty(BaseDataSource.VDB_NAME).equals("BQT")); //$NON-NLS-1$
- assertEquals("testdata/dqp/dqp.properties", p.getProperty(EmbeddedDataSource.DQP_BOOTSTRAP_FILE)); //$NON-NLS-1$
- assertTrue(p.getProperty(ExecutionProperties.PROP_PARTIAL_RESULTS_MODE).equals("true")); //$NON-NLS-1$
- assertEquals(4, p.size());
- }
-
- public void testParseURL5() throws SQLException{
- Properties p = new Properties();
- driver.parseURL("jdbc:metamatrix:BQT", p); //$NON-NLS-1$
- assertTrue(p.getProperty(BaseDataSource.VDB_NAME).equals("BQT")); //$NON-NLS-1$
- assertTrue(p.get(EmbeddedDataSource.DQP_BOOTSTRAP_FILE).equals("classpath:/deploy.properties")); //$NON-NLS-1$
- }
-
- public void testParseURL55() throws SQLException{
- Properties p = new Properties();
- driver.parseURL("jdbc:metamatrix:BQT;", p); //$NON-NLS-1$
- assertTrue(p.getProperty(BaseDataSource.VDB_NAME).equals("BQT")); //$NON-NLS-1$
- assertTrue(p.get(EmbeddedDataSource.DQP_BOOTSTRAP_FILE).equals("classpath:/deploy.properties")); //$NON-NLS-1$
- }
-
- public void testParseURL6() throws SQLException{
- Properties p = new Properties();
- driver.parseURL("jdbc:metamatrix:BQT;partialResultsMode=true;version=1", p); //$NON-NLS-1$
- assertTrue(p.getProperty(BaseDataSource.VDB_NAME).equals("BQT")); //$NON-NLS-1$
- assertTrue(p.get(EmbeddedDataSource.DQP_BOOTSTRAP_FILE).equals("classpath:/deploy.properties")); //$NON-NLS-1$
- assertTrue(p.getProperty(ExecutionProperties.PROP_PARTIAL_RESULTS_MODE).equals("true")); //$NON-NLS-1$
- assertTrue(p.getProperty(BaseDataSource.VDB_VERSION).equals("1")); //$NON-NLS-1$
- assertTrue(p.getProperty("vdb.definition").equals("BQT.vdb")); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals(7, p.size());
-
- }
-
public void test() throws Exception {
try {
Class.forName("com.metamatrix.jdbc.EmbeddedDriver"); //$NON-NLS-1$
[View Less]
15 years, 8 months
teiid SVN: r1190 - in trunk/build/kit-runtime/examples: vdbless-portfolio and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-07-26 23:18:45 -0400 (Sun, 26 Jul 2009)
New Revision: 1190
Modified:
trunk/build/kit-runtime/examples/simpleclient/JDBCClient.class
trunk/build/kit-runtime/examples/simpleclient/JDBCClient.java
trunk/build/kit-runtime/examples/vdbless-portfolio/vdbless.def
Log:
correcting the example
Modified: trunk/build/kit-runtime/examples/simpleclient/JDBCClient.class
===================================================================
(Binary files differ)
Modified: …
[View More]trunk/build/kit-runtime/examples/simpleclient/JDBCClient.java
===================================================================
--- trunk/build/kit-runtime/examples/simpleclient/JDBCClient.java 2009-07-26 16:53:56 UTC (rev 1189)
+++ trunk/build/kit-runtime/examples/simpleclient/JDBCClient.java 2009-07-27 03:18:45 UTC (rev 1190)
@@ -56,7 +56,7 @@
ds.setDatabaseName(vdb);
ds.setUser("admin");
ds.setPassword("teiid");
- ds.setEmbeddedBootstrapFile("../.../deploy.properties");
+ ds.setEmbeddedBootstrapFile("../../deploy.properties");
/* Alternatively server mode would be
* ds.setServerName("localhost");
* ds.setPortNumber(31000);
Modified: trunk/build/kit-runtime/examples/vdbless-portfolio/vdbless.def
===================================================================
--- trunk/build/kit-runtime/examples/vdbless-portfolio/vdbless.def 2009-07-26 16:53:56 UTC (rev 1189)
+++ trunk/build/kit-runtime/examples/vdbless-portfolio/vdbless.def 2009-07-27 03:18:45 UTC (rev 1190)
@@ -61,7 +61,7 @@
<Property Name="DescriptorFile">${teiid.home}/examples/portfolio/marketdata-def.txt</Property>
</Properties>
</Connector>
- <Connector Name="Derby Connector" ComponentType="Apache Derby Embedded Connector">
+ <Connector Name="Derby Connector" ComponentType="Apache Derby Network Connector">
<Properties>
<Property Name="URL">jdbc:derby://localhost:1527/teiid/accounts</Property>
<Property Name="ConnectorClassPath">extensionjar:derbyclient.jar</Property>
[View Less]
15 years, 8 months
teiid SVN: r1189 - in trunk/connectors/connector-jdbc/src: main/java/org/teiid/connector/jdbc/derby and 9 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-07-26 12:53:56 -0400 (Sun, 26 Jul 2009)
New Revision: 1189
Added:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/MODFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyCapabilities.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestMODFunctionModifier.java
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/…
[View More]connector/jdbc/db2/DB2Capabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2ConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbySQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ConcatFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerCapabilities.java
trunk/connectors/connector-jdbc/src/main/resources/connector-jdbc.xml
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2SqlTranslator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLeftOrRightFunctionModifier.java
Log:
TEIID-710 TEIID-486 TEIID-739 consolidating db2 and derby connector code, also adding Larry's fix for selected null literals and mod function handling
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2Capabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2Capabilities.java 2009-07-25 20:58:40 UTC (rev 1188)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2Capabilities.java 2009-07-26 16:53:56 UTC (rev 1189)
@@ -40,8 +40,8 @@
/**
* @see com.metamatrix.data.ConnectorCapabilities#getSupportedFunctions()
*/
- public List getSupportedFunctions() {
- List supportedFunctions = new ArrayList();
+ public List<String> getSupportedFunctions() {
+ List<String> supportedFunctions = new ArrayList<String>();
supportedFunctions.addAll(super.getSupportedFunctions());
supportedFunctions.add("ABS"); //$NON-NLS-1$
supportedFunctions.add("ACOS"); //$NON-NLS-1$
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2ConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2ConvertModifier.java 2009-07-25 20:58:40 UTC (rev 1188)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2ConvertModifier.java 2009-07-26 16:53:56 UTC (rev 1189)
@@ -29,14 +29,17 @@
import org.teiid.connector.api.TypeFacility;
import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
import org.teiid.connector.jdbc.translator.DropFunctionModifier;
-import org.teiid.connector.jdbc.translator.FunctionModifier;
-import org.teiid.connector.language.*;
+import org.teiid.connector.language.ICompareCriteria;
+import org.teiid.connector.language.IExpression;
+import org.teiid.connector.language.IFunction;
+import org.teiid.connector.language.ILanguageFactory;
+import org.teiid.connector.language.ILiteral;
import org.teiid.connector.language.ICompareCriteria.Operator;
/**
*/
-public class DB2ConvertModifier extends BasicFunctionModifier implements FunctionModifier {
+public class DB2ConvertModifier extends BasicFunctionModifier {
private static DropFunctionModifier DROP_MODIFIER = new DropFunctionModifier();
@@ -227,7 +230,7 @@
return null;
}
- private IExpression convertToReal(IExpression expression, Class sourceType) {
+ protected IExpression convertToReal(IExpression expression, Class sourceType) {
if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING) ||
sourceType.equals(TypeFacility.RUNTIME_TYPES.DOUBLE) ||
@@ -243,7 +246,7 @@
return null;
}
- private IExpression convertToDouble(IExpression expression, Class sourceType) {
+ protected IExpression convertToDouble(IExpression expression, Class sourceType) {
if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)){
@@ -257,7 +260,7 @@
return null;
}
- private IExpression convertToBigDecimal(IExpression expression, Class sourceType) {
+ protected IExpression convertToBigDecimal(IExpression expression, Class sourceType) {
if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)){
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java 2009-07-25 20:58:40 UTC (rev 1188)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java 2009-07-26 16:53:56 UTC (rev 1189)
@@ -22,6 +22,7 @@
package org.teiid.connector.jdbc.db2;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -31,13 +32,18 @@
import org.teiid.connector.api.ExecutionContext;
import org.teiid.connector.api.SourceSystemFunctions;
import org.teiid.connector.api.TypeFacility;
+import org.teiid.connector.api.TypeFacility.RUNTIME_TYPES;
import org.teiid.connector.jdbc.translator.AliasModifier;
+import org.teiid.connector.jdbc.translator.MODFunctionModifier;
import org.teiid.connector.jdbc.translator.Translator;
import org.teiid.connector.language.ICommand;
+import org.teiid.connector.language.IExpression;
import org.teiid.connector.language.IJoin;
import org.teiid.connector.language.ILimit;
import org.teiid.connector.language.ILiteral;
import org.teiid.connector.language.IQuery;
+import org.teiid.connector.language.ISelect;
+import org.teiid.connector.language.ISelectSymbol;
import org.teiid.connector.language.ICompareCriteria.Operator;
import org.teiid.connector.language.IJoin.JoinType;
import org.teiid.connector.visitor.framework.HierarchyVisitor;
@@ -55,6 +61,12 @@
registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new AliasModifier("day")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("coalesce")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new AliasModifier("substr")); //$NON-NLS-1$
+
+ List<Class<?>> supportedModTypes = new ArrayList<Class<?>>(3);
+ supportedModTypes.add(RUNTIME_TYPES.SHORT);
+ supportedModTypes.add(RUNTIME_TYPES.INTEGER);
+ supportedModTypes.add(RUNTIME_TYPES.LONG);
+ registerFunctionModifier(SourceSystemFunctions.MOD, new MODFunctionModifier(getLanguageFactory(), "MOD", supportedModTypes)); //$NON-NLS-1$
}
@SuppressWarnings("unchecked")
@@ -79,6 +91,16 @@
};
command.acceptVisitor(hierarchyVisitor);
+
+ ISelect select = ((IQuery)command).getSelect();
+ for (ISelectSymbol selectSymbol : select.getSelectSymbols()) {
+ if (selectSymbol.getExpression() instanceof ILiteral) {
+ ILiteral literal = (ILiteral)selectSymbol.getExpression();
+ if (literal.getValue() == null) {
+ selectSymbol.setExpression(createCastToExprType(literal));
+ }
+ }
+ }
}
return command;
}
@@ -92,5 +114,67 @@
public Class<? extends ConnectorCapabilities> getDefaultCapabilities() {
return DB2Capabilities.class;
}
-
+
+ /**
+ * Create and return an expression to cast <code>expr</code> to <code>expr</code>'s
+ * type.
+ * <p>
+ * If a compatible type is not found, <code>expr</code> is returned unmodified.
+ * <p>
+ * <em>WARNING</em>: This method currently returns the smallest type associated with
+ * the run-time type. So, all <code>String</code> expressions, regardless of
+ * their value's length are returned as CHAR.
+ * <p>
+ * For example, if <code>expr</code> is "e1" of type <code>String</code> the
+ * returned expression would be "CAST(expr AS CHAR)".
+ *
+ * @param expr
+ * @return
+ */
+ private IExpression createCastToExprType(IExpression expr) {
+ String typeName = null;
+ if ( RUNTIME_TYPES.STRING.equals(expr.getType()) ) {
+ typeName = "CHAR"; //$NON-NLS-1$
+ } else if ( RUNTIME_TYPES.BOOLEAN.equals(expr.getType()) ) {
+ typeName = "SMALLINT"; //$NON-NLS-1$
+ } else if ( RUNTIME_TYPES.BYTE.equals(expr.getType()) ) {
+ typeName = "SMALLINT"; //$NON-NLS-1$
+ } else if ( RUNTIME_TYPES.SHORT.equals(expr.getType()) ) {
+ typeName = "SMALLINT"; //$NON-NLS-1$
+ } else if ( RUNTIME_TYPES.CHAR.equals(expr.getType()) ) {
+ typeName = "CHAR"; //$NON-NLS-1$
+ } else if ( RUNTIME_TYPES.INTEGER.equals(expr.getType()) ) {
+ typeName = "INTEGER"; //$NON-NLS-1$
+ } else if ( RUNTIME_TYPES.LONG.equals(expr.getType()) ) {
+ typeName = "BIGINT"; //$NON-NLS-1$
+ } else if ( RUNTIME_TYPES.BIG_INTEGER.equals(expr.getType()) ) {
+ typeName = "BIGINT"; //$NON-NLS-1$
+ } else if ( RUNTIME_TYPES.FLOAT.equals(expr.getType()) ) {
+ typeName = "REAL"; //$NON-NLS-1$
+ } else if ( RUNTIME_TYPES.DOUBLE.equals(expr.getType()) ) {
+ typeName = "DOUBLE"; //$NON-NLS-1$
+ } else if ( RUNTIME_TYPES.BIG_DECIMAL.equals(expr.getType()) ) {
+ typeName = "DECIMAL"; //$NON-NLS-1$
+ } else if ( RUNTIME_TYPES.DATE.equals(expr.getType()) ) {
+ typeName = "DATE"; //$NON-NLS-1$
+ } else if ( RUNTIME_TYPES.TIME.equals(expr.getType()) ) {
+ typeName = "TIME"; //$NON-NLS-1$
+ } else if ( RUNTIME_TYPES.TIMESTAMP.equals(expr.getType()) ) {
+ typeName = "TIMESTAMP"; //$NON-NLS-1$
+ } else if ( RUNTIME_TYPES.OBJECT.equals(expr.getType()) ) {
+ typeName = "BLOB"; //$NON-NLS-1$
+ } else if ( RUNTIME_TYPES.BLOB.equals(expr.getType()) ) {
+ typeName = "BLOB"; //$NON-NLS-1$
+ } else if ( RUNTIME_TYPES.CLOB.equals(expr.getType()) ) {
+ typeName = "CLOB"; //$NON-NLS-1$
+ } else if ( RUNTIME_TYPES.XML.equals(expr.getType()) ) {
+ typeName = "CLOB"; //$NON-NLS-1$
+ }
+ if ( typeName != null ) {
+ return getLanguageFactory().createFunction("CAST", Arrays.asList(expr, getLanguageFactory().createLiteral(typeName, String.class)), expr.getType()); //$NON-NLS-1$
+ }
+ return expr;
+ }
+
+
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyCapabilities.java 2009-07-25 20:58:40 UTC (rev 1188)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyCapabilities.java 2009-07-26 16:53:56 UTC (rev 1189)
@@ -32,51 +32,64 @@
/**
* @since 5.0
*/
-public class DerbyCapabilities extends JDBCCapabilities {
+public class DerbyCapabilities extends JDBCCapabilities {
+
+ public static final String TEN_1 = "10.1"; //$NON-NLS-1$
+ public static final String TEN_2 = "10.2"; //$NON-NLS-1$
+ public static final String TEN_4 = "10.4"; //$NON-NLS-1$
+ public static final String TEN_5 = "10.5"; //$NON-NLS-1$
+
+ private String version = TEN_1;
- public List getSupportedFunctions() {
- List supportedFunctions = new ArrayList();
+ public List<String> getSupportedFunctions() {
+ List<String> supportedFunctions = new ArrayList<String>();
supportedFunctions.addAll(super.getSupportedFunctions());
- supportedFunctions.add("ABS"); //$NON-NLS-1$
- //supportedFunctions.add("ACOS"); //$NON-NLS-1$
- //supportedFunctions.add("ASIN"); //$NON-NLS-1$
- //supportedFunctions.add("ATAN"); //$NON-NLS-1$
- //supportedFunctions.add("ATAN2"); //$NON-NLS-1$
+ supportedFunctions.add("ABS"); //$NON-NLS-1$
+ if (version.compareTo(TEN_2) >= 0) {
+ supportedFunctions.add("ACOS"); //$NON-NLS-1$
+ supportedFunctions.add("ASIN"); //$NON-NLS-1$
+ supportedFunctions.add("ATAN"); //$NON-NLS-1$
+ }
+ if (version.compareTo(TEN_4) >= 0) {
+ supportedFunctions.add("ATAN2"); //$NON-NLS-1$
+ }
// These are executed within the server and never pushed down
//supportedFunctions.add("BITAND"); //$NON-NLS-1$
//supportedFunctions.add("BITNOT"); //$NON-NLS-1$
//supportedFunctions.add("BITOR"); //$NON-NLS-1$
- //supportedFunctions.add("BITXOR"); //$NON-NLS-1$
- //supportedFunctions.add("CEILING"); //$NON-NLS-1$
- //supportedFunctions.add("COS"); //$NON-NLS-1$
- //supportedFunctions.add("COT"); //$NON-NLS-1$
- //supportedFunctions.add("DEGREES"); //$NON-NLS-1$
- //supportedFunctions.add("EXP"); //$NON-NLS-1$
- //supportedFunctions.add("FLOOR"); //$NON-NLS-1$
- //supportedFunctions.add("LOG"); //$NON-NLS-1$
- //supportedFunctions.add("LOG10"); //$NON-NLS-1$
- supportedFunctions.add("MOD"); //$NON-NLS-1$
- //supportedFunctions.add("PI"); //$NON-NLS-1$
- //supportedFunctions.add("POWER"); //$NON-NLS-1$
- //supportedFunctions.add("RADIANS"); //$NON-NLS-1$
- //supportedFunctions.add("ROUND"); //$NON-NLS-1$
- //supportedFunctions.add("SIGN"); //$NON-NLS-1$
- //supportedFunctions.add("SIN"); //$NON-NLS-1$
+ //supportedFunctions.add("BITXOR"); //$NON-NLS-1$
+ if (version.compareTo(TEN_2) >= 0) {
+ supportedFunctions.add("CEILING"); //$NON-NLS-1$
+ supportedFunctions.add("COS"); //$NON-NLS-1$
+ supportedFunctions.add("COT"); //$NON-NLS-1$
+ supportedFunctions.add("DEGREES"); //$NON-NLS-1$
+ supportedFunctions.add("EXP"); //$NON-NLS-1$
+ supportedFunctions.add("FLOOR"); //$NON-NLS-1$
+ supportedFunctions.add("LOG"); //$NON-NLS-1$
+ supportedFunctions.add("LOG10"); //$NON-NLS-1$
+ }
+ supportedFunctions.add("MOD"); //$NON-NLS-1$
+ if (version.compareTo(TEN_2) >= 0) {
+ supportedFunctions.add("PI"); //$NON-NLS-1$
+ //supportedFunctions.add("POWER"); //$NON-NLS-1$
+ supportedFunctions.add("RADIANS"); //$NON-NLS-1$
+ //supportedFunctions.add("ROUND"); //$NON-NLS-1$
+ supportedFunctions.add("SIGN"); //$NON-NLS-1$
+ supportedFunctions.add("SIN"); //$NON-NLS-1$
+ }
supportedFunctions.add("SQRT"); //$NON-NLS-1$
//supportedFunctions.add("TAN"); //$NON-NLS-1$
//supportedFunctions.add("ASCII"); //$NON-NLS-1$
//supportedFunctions.add("CHR"); //$NON-NLS-1$
//supportedFunctions.add("CHAR"); //$NON-NLS-1$
- supportedFunctions.add("||"); //$NON-NLS-1$
supportedFunctions.add("CONCAT"); //$NON-NLS-1$
//supportedFunctions.add("INSERT"); //$NON-NLS-1$
supportedFunctions.add("LCASE"); //$NON-NLS-1$
- //supportedFunctions.add("LEFT"); //$NON-NLS-1$
+ supportedFunctions.add("LEFT"); //$NON-NLS-1$
supportedFunctions.add("LENGTH"); //$NON-NLS-1$
supportedFunctions.add("LOCATE"); //$NON-NLS-1$
- supportedFunctions.add("LOWER"); //$NON-NLS-1$
//supportedFunctions.add("LPAD"); //$NON-NLS-1$
supportedFunctions.add("LTRIM"); //$NON-NLS-1$
//supportedFunctions.add("REPEAT"); //$NON-NLS-1$
@@ -86,7 +99,6 @@
supportedFunctions.add("RTRIM"); //$NON-NLS-1$
supportedFunctions.add("SUBSTRING"); //$NON-NLS-1$
supportedFunctions.add("UCASE"); //$NON-NLS-1$
- supportedFunctions.add("UPPER"); //$NON-NLS-1$
// These are executed within the server and never pushed down
//supportedFunctions.add("CURDATE"); //$NON-NLS-1$
@@ -117,13 +129,15 @@
//supportedFunctions.add("WEEK"); //$NON-NLS-1$
supportedFunctions.add("YEAR"); //$NON-NLS-1$
- supportedFunctions.add("CAST"); //$NON-NLS-1$
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;
- }
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
/**
* Derby supports only SearchedCaseExpression, not CaseExpression.
@@ -152,11 +166,6 @@
return true;
}
- @Override
- public boolean supportsSetQueryOrderBy() {
- return false;
- }
-
/**
* @see org.teiid.connector.basic.BasicConnectorCapabilities#supportsExcept()
*/
@@ -171,6 +180,11 @@
@Override
public boolean supportsIntersect() {
return true;
+ }
+
+ @Override
+ public boolean supportsRowLimit() {
+ return this.version.compareTo(TEN_5) >= 0;
}
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyConvertModifier.java 2009-07-25 20:58:40 UTC (rev 1188)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyConvertModifier.java 2009-07-26 16:53:56 UTC (rev 1189)
@@ -22,213 +22,29 @@
package org.teiid.connector.jdbc.derby;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
import org.teiid.connector.api.TypeFacility;
-import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
-import org.teiid.connector.jdbc.translator.DropFunctionModifier;
-import org.teiid.connector.jdbc.translator.FunctionModifier;
-import org.teiid.connector.language.*;
-import org.teiid.connector.language.ICompareCriteria.Operator;
+import org.teiid.connector.jdbc.db2.DB2ConvertModifier;
+import org.teiid.connector.language.IExpression;
+import org.teiid.connector.language.IFunction;
+import org.teiid.connector.language.ILanguageFactory;
/**
*/
-public class DerbyConvertModifier extends BasicFunctionModifier implements FunctionModifier {
+public class DerbyConvertModifier extends DB2ConvertModifier {
- private static DropFunctionModifier DROP_MODIFIER = new DropFunctionModifier();
-
private ILanguageFactory langFactory;
public DerbyConvertModifier(ILanguageFactory langFactory) {
+ super(langFactory);
this.langFactory = langFactory;
}
-
- public IExpression modify(IFunction function) {
- List<IExpression> args = function.getParameters();
- Class sourceType = args.get(0).getType();
- String targetTypeString = getTargetType(args.get(1));
- Class targetType = TypeFacility.getDataTypeClass(targetTypeString);
- IExpression returnExpr = null;
-
- if(targetType != null) {
-
- // targetType is always lower-case due to getTargetType implementation
- if(targetType.equals(TypeFacility.RUNTIME_TYPES.STRING)) {
- returnExpr = convertToString(args.get(0), sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.TIMESTAMP)) {
- returnExpr = convertToTimestamp(args.get(0), sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.DATE)) {
- returnExpr = convertToDate(args.get(0), sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.TIME)) {
- returnExpr = convertToTime(args.get(0), sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN) ||
- targetType.equals(TypeFacility.RUNTIME_TYPES.BYTE) ||
- targetType.equals(TypeFacility.RUNTIME_TYPES.SHORT)) {
- returnExpr = convertToSmallInt(args.get(0), sourceType, targetType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.INTEGER)) {
- returnExpr = convertToInteger(args.get(0), sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.LONG) ||
- targetType.equals(TypeFacility.RUNTIME_TYPES.BIG_INTEGER)) {
- returnExpr = convertToBigInt(args.get(0), sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.FLOAT)) {
- returnExpr = convertToFloat(args.get(0), sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.DOUBLE)) {
- returnExpr = convertToDouble(args.get(0), sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL)) {
- returnExpr = convertToBigDecimal(args.get(0), sourceType);
-
- } else if(targetType.equals(TypeFacility.RUNTIME_TYPES.CHAR)) {
- returnExpr = convertToChar(args.get(0), sourceType);
- }
-
- if(returnExpr != null) {
- return returnExpr;
- }
- }
-
- // Last resort - just drop the convert and let the db figure it out
- return DROP_MODIFIER.modify(function);
- }
-
- /**
- * @param expression
- * @return
- * @since 4.2
- */
- private String getTargetType(IExpression expression) {
- if(expression != null && expression instanceof ILiteral) {
- String target = (String) ((ILiteral)expression).getValue();
- return target.toLowerCase();
- }
-
- return null;
- }
-
- /**
- * @param expression
- * @param sourceType
- * @return
- * @since 4.2
- */
- private IExpression convertToString(IExpression expression,
- Class sourceType) {
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN)) {
- // BEFORE: convert(booleanExpression, string)
- // AFTER: CASE WHEN booleanExpression = 0 THEN 'false' ELSE 'true' END
-
- ILiteral literalZero = this.langFactory.createLiteral(new Integer(0), TypeFacility.RUNTIME_TYPES.INTEGER);
- ICompareCriteria when = this.langFactory.createCompareCriteria(Operator.EQ, expression, literalZero);
- List whens = new ArrayList(1);
- whens.add(when);
-
- ILiteral literalFalse = this.langFactory.createLiteral("false", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
- List thens = new ArrayList(1);
- thens.add(literalFalse);
-
- ILiteral literalTrue = this.langFactory.createLiteral("true", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
-
- return this.langFactory.createSearchedCaseExpression(whens, thens, literalTrue, TypeFacility.RUNTIME_TYPES.STRING);
-
- } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.CHAR)) {
- // Drop convert entirely for char
- return null;
-
- } else {
- // BEFORE: convert(EXPR, string)
- // AFTER: char(EXPR)
- return wrapNewFunction(expression, "char", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
- }
- }
-
- private IExpression convertToChar(IExpression expression,
- Class sourceType) {
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)) {
- ILiteral literalOne = this.langFactory.createLiteral(new Integer(1), TypeFacility.RUNTIME_TYPES.INTEGER);
- return this.langFactory.createFunction("char", Arrays.asList( expression, literalOne ), TypeFacility.RUNTIME_TYPES.CHAR); //$NON-NLS-1$
- }
+ @Override
+ protected IExpression convertToReal(IExpression expression, Class sourceType) {
- return null;
- }
-
- private IExpression convertToSmallInt(IExpression expression,
- Class sourceType, Class targetType) {
-
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING) && targetType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN)) {
- // BEFORE: convert(stringExpression, boolean)
- // AFTER: CASE WHEN stringExpression = 'true' THEN 1 ELSE 0 END
- ILiteral literalTrue = this.langFactory.createLiteral("true", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
- ICompareCriteria when = this.langFactory.createCompareCriteria(Operator.EQ, expression, literalTrue);
- List whens = new ArrayList(1);
- whens.add(when);
-
- ILiteral literalOne = this.langFactory.createLiteral(new Integer(1), TypeFacility.RUNTIME_TYPES.INTEGER);
- List thens = new ArrayList(1);
- thens.add(literalOne);
-
- ILiteral literalZero = this.langFactory.createLiteral(new Integer(0), TypeFacility.RUNTIME_TYPES.INTEGER);
-
- return this.langFactory.createSearchedCaseExpression(whens, thens, literalZero, TypeFacility.RUNTIME_TYPES.STRING);
-
- } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.BYTE) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.SHORT)){
-
- // Just drop these
- return null;
- }
-
- // BEFORE: convert(expression, [boolean,byte,short])
- // AFTER: smallint(expression)
- return wrapNewFunction(expression, "smallint", targetType); //$NON-NLS-1$
- }
-
- private IExpression convertToInteger(IExpression expression, Class sourceType) {
-
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.BOOLEAN) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.BYTE) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.SHORT)){
-
- // Just drop these
- return null;
- }
-
- // BEFORE: convert(expression, integer)
- // AFTER: integer(expression)
- return wrapNewFunction(expression, "integer", TypeFacility.RUNTIME_TYPES.INTEGER); //$NON-NLS-1$
- }
-
- private IExpression convertToBigInt(IExpression expression, Class sourceType) {
-
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.FLOAT) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.DOUBLE) ||
- sourceType.equals(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL)){
-
- // BEFORE: convert(expression, [long, biginteger])
- // AFTER: bigint(expression)
- return wrapNewFunction(expression, "bigint", TypeFacility.RUNTIME_TYPES.LONG); //$NON-NLS-1$
-
- }
-
- // Just drop anything else
- return null;
- }
-
- private IExpression convertToFloat(IExpression expression, Class sourceType) {
-
if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)){
// BEFORE: convert(string_expr, float)
@@ -257,7 +73,8 @@
return null;
}
- private IExpression convertToDouble(IExpression expression, Class sourceType) {
+ @Override
+ protected IExpression convertToDouble(IExpression expression, Class sourceType) {
if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)){
// BEFORE: convert(string_expr, double)
@@ -275,7 +92,8 @@
return null;
}
- private IExpression convertToBigDecimal(IExpression expression, Class sourceType) {
+ @Override
+ protected IExpression convertToBigDecimal(IExpression expression, Class sourceType) {
if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)){
// BEFORE: convert(string_expr, bigdecimal)
@@ -288,66 +106,5 @@
// Just drop anything else
return null;
}
-
- /**
- * @param expression
- * @param sourceType
- * @return
- * @since 4.2
- */
- private IExpression convertToDate(IExpression expression,
- Class sourceType) {
-
- // BEFORE: convert(EXPR, date)
- // AFTER: date(EXPR)
- return wrapNewFunction(expression, "date", TypeFacility.RUNTIME_TYPES.DATE); //$NON-NLS-1$
- }
-
- private IExpression convertToTime(IExpression expression,
- Class sourceType) {
-
- // BEFORE: convert(EXPR, time)
- // AFTER: time(EXPR)
- return wrapNewFunction(expression, "time", TypeFacility.RUNTIME_TYPES.DATE); //$NON-NLS-1$
- }
-
- private IExpression convertToTimestamp(IExpression expression,
- Class sourceType) {
-
- if(sourceType.equals(TypeFacility.RUNTIME_TYPES.STRING)) {
- // BEFORE: convert(EXPR, timestamp)
- // AFTER: timestamp(expr)
- return wrapNewFunction(expression, "timestamp", TypeFacility.RUNTIME_TYPES.TIMESTAMP); //$NON-NLS-1$
-
- } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.DATE)) {
- // BEFORE: convert(EXPR, timestamp)
- // AFTER: timestamp(EXPR, '00:00:00')
- ILiteral timeString = this.langFactory.createLiteral("00:00:00", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
- return this.langFactory.createFunction("timestamp", Arrays.asList(expression, timeString), TypeFacility.RUNTIME_TYPES.TIMESTAMP); //$NON-NLS-1$
-
- } else if(sourceType.equals(TypeFacility.RUNTIME_TYPES.TIME)) {
- // BEFORE: convert(EXPR, timestamp)
- // AFTER: timestamp(EXPR, '1970-01-01', EXPR)
- ILiteral dateString = this.langFactory.createLiteral("1970-01-01", TypeFacility.RUNTIME_TYPES.STRING); //$NON-NLS-1$
- return this.langFactory.createFunction("timestamp", Arrays.asList(dateString, expression), TypeFacility.RUNTIME_TYPES.TIMESTAMP); //$NON-NLS-1$
- }
-
- return null;
- }
- /**
- * @param expression
- * @param functionName
- * @param outputType
- * @return
- * @since 4.2
- */
- private IFunction wrapNewFunction(IExpression expression,
- String functionName,
- Class outputType) {
- return langFactory.createFunction(functionName,
- Arrays.asList( expression ),
- outputType);
- }
-
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbySQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbySQLTranslator.java 2009-07-25 20:58:40 UTC (rev 1188)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbySQLTranslator.java 2009-07-26 16:53:56 UTC (rev 1189)
@@ -26,28 +26,30 @@
import org.teiid.connector.api.ConnectorEnvironment;
import org.teiid.connector.api.ConnectorException;
import org.teiid.connector.api.SourceSystemFunctions;
-import org.teiid.connector.jdbc.translator.AliasModifier;
+import org.teiid.connector.jdbc.db2.DB2SQLTranslator;
+import org.teiid.connector.jdbc.oracle.LeftOrRightFunctionModifier;
import org.teiid.connector.jdbc.translator.EscapeSyntaxModifier;
-import org.teiid.connector.jdbc.translator.Translator;
/**
* @since 4.3
*/
-public class DerbySQLTranslator extends Translator {
+public class DerbySQLTranslator extends DB2SQLTranslator {
+
+ public static final String DATABASE_VERSION = "DatabaseVersion"; //$NON-NLS-1$
@Override
public void initialize(ConnectorEnvironment env) throws ConnectorException {
super.initialize(env);
- registerFunctionModifier(SourceSystemFunctions.CONCAT, new EscapeSyntaxModifier());
- registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new AliasModifier("substr")); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new AliasModifier("day")); //$NON-NLS-1$
+ //additional derby functions
registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new EscapeSyntaxModifier());
- registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.LEFT, new LeftOrRightFunctionModifier(getLanguageFactory()));
+
+ //overrides of db2 functions
+ registerFunctionModifier(SourceSystemFunctions.CONCAT, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.CONVERT, new DerbyConvertModifier(getLanguageFactory()));
- registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("coalesce")); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.COALESCE, new AliasModifier("coalesce")); //$NON-NLS-1$
}
@Override
@@ -63,6 +65,16 @@
@Override
public Class<? extends ConnectorCapabilities> getDefaultCapabilities() {
return DerbyCapabilities.class;
+ }
+
+ @Override
+ public ConnectorCapabilities getConnectorCapabilities()
+ throws ConnectorException {
+ ConnectorCapabilities capabilities = super.getConnectorCapabilities();
+ if (capabilities instanceof DerbyCapabilities) {
+ ((DerbyCapabilities)capabilities).setVersion(getEnvironment().getProperties().getProperty(DATABASE_VERSION, DerbyCapabilities.TEN_1));
+ }
+ return capabilities;
}
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ConcatFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ConcatFunctionModifier.java 2009-07-25 20:58:40 UTC (rev 1188)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ConcatFunctionModifier.java 2009-07-26 16:53:56 UTC (rev 1189)
@@ -40,7 +40,6 @@
/**
* This Function modifier used to support ANSI concat on Oracle 9i.
- * TODO: this is no longer necessary on Oracle 10g and later.
* <code>
* CONCAT(a, b) ==> CASE WHEN (a is NULL OR b is NULL) THEN NULL ELSE CONCAT(a, b)
* </code>
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java 2009-07-25 20:58:40 UTC (rev 1188)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java 2009-07-26 16:53:56 UTC (rev 1189)
@@ -35,8 +35,8 @@
public class PostgreSQLCapabilities extends JDBCCapabilities {
- public List getSupportedFunctions() {
- List supportedFunctions = new ArrayList();
+ public List<String> getSupportedFunctions() {
+ List<String> supportedFunctions = new ArrayList<String>();
supportedFunctions.addAll(super.getSupportedFunctions());
supportedFunctions.add("ABS"); //$NON-NLS-1$
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java 2009-07-25 20:58:40 UTC (rev 1188)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java 2009-07-26 16:53:56 UTC (rev 1189)
@@ -37,6 +37,7 @@
import org.teiid.connector.jdbc.oracle.LeftOrRightFunctionModifier;
import org.teiid.connector.jdbc.oracle.MonthOrDayNameFunctionModifier;
import org.teiid.connector.jdbc.translator.AliasModifier;
+import org.teiid.connector.jdbc.translator.EscapeSyntaxModifier;
import org.teiid.connector.jdbc.translator.ExtractFunctionModifier;
import org.teiid.connector.jdbc.translator.Translator;
import org.teiid.connector.language.IAggregate;
@@ -86,8 +87,8 @@
registerFunctionModifier(SourceSystemFunctions.YEAR, new ExtractFunctionModifier());
//specific to 8.2 client or later
- //registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new EscapeSyntaxModifier());
- //registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("coalesce")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.CONVERT, new PostgreSQLConvertModifier(getLanguageFactory()));
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerCapabilities.java 2009-07-25 20:58:40 UTC (rev 1188)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerCapabilities.java 2009-07-26 16:53:56 UTC (rev 1189)
@@ -39,8 +39,8 @@
/**
* @see com.metamatrix.data.ConnectorCapabilities#getSupportedFunctions()
*/
- public List getSupportedFunctions() {
- List supportedFunctions = new ArrayList();
+ public List<String> getSupportedFunctions() {
+ List<String> supportedFunctions = new ArrayList<String>();
supportedFunctions.addAll(super.getSupportedFunctions());
supportedFunctions.add("ABS"); //$NON-NLS-1$
supportedFunctions.add("ACOS"); //$NON-NLS-1$
Added: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/MODFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/MODFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/MODFunctionModifier.java 2009-07-26 16:53:56 UTC (rev 1189)
@@ -0,0 +1,185 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.translator;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.connector.api.TypeFacility.RUNTIME_TYPES;
+import org.teiid.connector.language.IExpression;
+import org.teiid.connector.language.IFunction;
+import org.teiid.connector.language.ILanguageFactory;
+
+/**
+ * A modifier class that can be used to translate the scalar function
+ * <code>mod(x, y)</code> to a function or expression that can be used at the
+ * data source.
+ * <p>
+ * If the default implementation is used, a function name of MOD will be used
+ * for the alias name and the expression will be unmodified if the data type
+ * of the <code>x</code> parameter is one of {@link RUNTIME_TYPES#BYTE},
+ * {@link RUNTIME_TYPES#SHORT}, {@link RUNTIME_TYPES#INTEGER}, or
+ * {@link RUNTIME_TYPES#LONG}. If the data type is not one of these types, the
+ * expression will be modified to return: <code>(x - (TRUNC((x / y), 0) * y))</code>
+ *
+ * @since 6.2
+ */
+public class MODFunctionModifier extends AliasModifier {
+
+ private static List<Class<?>> DEFAULT_TYPELIST = new ArrayList<Class<?>>(4);
+ static {
+ DEFAULT_TYPELIST.add(RUNTIME_TYPES.BYTE);
+ DEFAULT_TYPELIST.add(RUNTIME_TYPES.SHORT);
+ DEFAULT_TYPELIST.add(RUNTIME_TYPES.INTEGER);
+ DEFAULT_TYPELIST.add(RUNTIME_TYPES.LONG);
+ }
+ private static String DEFAULT_FUNCTIONNAME = "MOD"; //$NON-NLS-1$
+
+ private ILanguageFactory langFactory;
+ private List<Class<?>> supTypeList;
+
+ /**
+ * Constructs a {@link AliasModifier} object that can be used to translate
+ * the use of the scalar function MOD() to a source specific scalar function
+ * or expression.
+ * <p>
+ * This constructor invokes {@link #MODFunctionModifier(ILanguageFactory, String, List)}
+ * passing it <code>langFactory</code>, {@link #DEFAULT_FUNCTIONNAME}, and
+ * {@link #DEFAULT_TYPELIST}.
+ *
+ * @param langFactory the language factory associated with translation
+ */
+ public MODFunctionModifier(ILanguageFactory langFactory) {
+ this(langFactory, DEFAULT_FUNCTIONNAME, DEFAULT_TYPELIST);
+ }
+
+ /**
+ * Constructs a {@link AliasModifier} object that can be used to translate
+ * the use of the scalar function MOD() to a source specific scalar function
+ * or expression.
+ * <p>
+ * <code>functionName</code> is used to construct the parent {@link AliasModifier}
+ * and should represent the default function name or alias used by the data
+ * source.
+ * <p>
+ * <code>supportedTypeList</code> should contain a list of <code>Class</code>
+ * objects that represent the data types that the data source can support
+ * with its implementation of the MOD() scalar function.
+ *
+ * @param langFactory the language factory associated with translation
+ * @param functionName the function name or alias that should be used
+ * instead of MOD
+ * @param supportedTypeList a list of type classes that is supported by the
+ * data source's MOD function
+ */
+ public MODFunctionModifier(ILanguageFactory langFactory, String functionName, List<Class<?>>supportedTypeList) {
+ super(functionName);
+ this.langFactory = langFactory;
+ if ( supportedTypeList != null ) {
+ this.supTypeList = supportedTypeList;
+ } else {
+ this.supTypeList = MODFunctionModifier.DEFAULT_TYPELIST;
+ }
+ }
+
+ /**
+ * Returns a version of <code>function</code> suitable for executing at the
+ * data source.
+ * <p>
+ * If the data type of the parameters in <code>function</code> is in the
+ * list of supported data types, this method simply returns <code>super.modify(function)</code>.
+ * <p>
+ * If the data type of the parameters in <code>function</code are not in the
+ * list of supported data types, this method will return an expression that
+ * is valid at the data source and will yield the same result as the original
+ * MOD() scalar function. To build the expression, a call is make to
+ * {@link #getQuotientExpression(IExpression)} and its result is multiplied
+ * by the second parameter of <code>function</code> and that result is then
+ * subtracted from the first parameter of <code>function</code>.
+ * <p>
+ * For example:
+ * <code>mod(x, y) ---> (x - (getQuotientExpression((x / y)) * y))</code>
+ *
+ * @param function the MOD function that may need to be modified
+ * @see org.teiid.connector.jdbc.translator.AliasModifier#modify(org.teiid.connector.language.IFunction)
+ */
+ @Override
+ public IExpression modify(IFunction function) {
+ List<IExpression> expressions = function.getParameters();
+ IExpression dividend = expressions.get(0);
+ IExpression divisor = expressions.get(1);
+
+ // Check to see if parameters are supported by source MOD function
+ if (this.supTypeList.contains(dividend.getType())) {
+ return super.modify(function);
+ }
+
+ /*
+ * Parameters are not supported by source MOD function so modify
+ * MOD(<dividend>, <divisor>) --> (<dividend> - (<func_getQuotient((<dividend> / <divisor>))> * <divisor>))
+ */
+ // --> (<dividend> / <divisor>)
+ IFunction divide = langFactory.createFunction("/", Arrays.asList(dividend, divisor), dividend.getType()); //$NON-NLS-1$
+ // --> <func_getQuotient(<divide>)> -- i.e. TRUNC(<divide>, 0)
+ IFunction quotient = (IFunction) this.getQuotientExpression(divide);
+ // --> (<quotient> * <divisor>)
+ List<IExpression> multiplyArgs = Arrays.asList(quotient, divisor);
+ IFunction multiply = langFactory.createFunction("*", multiplyArgs, divisor.getType()); //$NON-NLS-1$
+ // --> (<dividend> - <multiply>)
+ List<IExpression> minusArgs = Arrays.asList(dividend, multiply);
+ return langFactory.createFunction("-", minusArgs, dividend.getType()); //$NON-NLS-1$
+ }
+
+ /**
+ * Return an expression that will result in the quotient of </code>division</code>.
+ * Quotient should always be represented as an integer (no remainder).
+ * <p>
+ * <code>division</code> will represent simple division that may result in a
+ * fraction. <code>division</code> should be returned within a helper
+ * function or expression that will result in an integer return value (no
+ * decimal or fraction).
+ * <p>
+ * If this method is not overriden, the result will be:
+ * <p>
+ * <ul>TRUNC(<code>division</code>, 0)</ul>
+ * <p>
+ * For the default TRUNC() function to work, the source must support it.
+ * TRUNC was used instead of FLOOR because FLOOR rounds to the nearest
+ * integer toward negative infinity. This would result in incorrect values
+ * when performing MOD on negative float, double, etc. values.
+ *
+ * @param division an expression representing simple division
+ * @return an expression that will extract the quotient from the
+ * <code>division</code> expression
+ */
+ protected IExpression getQuotientExpression(IExpression division) {
+ // --> TRUNC(<division>, 0)
+ return langFactory.createFunction("TRUNC", Arrays.asList(division, langFactory.createLiteral(0, RUNTIME_TYPES.SHORT)), division.getType()); //$NON-NLS-1$
+ }
+
+ protected ILanguageFactory getLanguageFactory() {
+ return this.langFactory;
+ }
+
+}
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/MODFunctionModifier.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/connectors/connector-jdbc/src/main/resources/connector-jdbc.xml
===================================================================
--- trunk/connectors/connector-jdbc/src/main/resources/connector-jdbc.xml 2009-07-25 20:58:40 UTC (rev 1188)
+++ trunk/connectors/connector-jdbc/src/main/resources/connector-jdbc.xml 2009-07-26 16:53:56 UTC (rev 1189)
@@ -99,11 +99,13 @@
<PropertyDefinition Name="ConnectionSource" DisplayName="Connection Source Class" ShortDescription="Driver, DataSource, or XADataSource class name" DefaultValue="org.apache.derby.jdbc.EmbeddedDriver" IsRequired="true" />
<PropertyDefinition Name="URL" DisplayName="JDBC URL" ShortDescription="" DefaultValue="jdbc:derby:<databaseName>" IsRequired="true" PropertyType="String" IsMasked="false" />
<PropertyDefinition Name="ExtensionTranslationClass" DisplayName="Extension SQL Translation Class" ShortDescription="" DefaultValue="org.teiid.connector.jdbc.derby.DerbySQLTranslator" PropertyType="String" IsExpert="true" IsMasked="false" />
+ <PropertyDefinition Name="DatabaseVersion" DisplayName="Database Version" ShortDescription="Derby Version i.e. 10.3" DefaultValue="10.1" PropertyType="String" />
</ComponentType>
<ComponentType Name="Apache Derby Network Connector" ComponentTypeCode="2" Deployable="true" Deprecated="false" Monitorable="false" SuperComponentType="JDBC Connector" ParentComponentType="Connectors" LastChangedBy="ConfigurationStartup" CreatedBy="ConfigurationStartup">
<PropertyDefinition Name="ConnectionSource" DisplayName="Connection Source Class" ShortDescription="Driver, DataSource, or XADataSource class name" DefaultValue="org.apache.derby.jdbc.ClientDriver" IsRequired="true" />
<PropertyDefinition Name="URL" DisplayName="JDBC URL" ShortDescription="" DefaultValue="jdbc:derby://localhost:1527/<path/to/db>" IsRequired="true" PropertyType="String" IsMasked="false" />
<PropertyDefinition Name="ExtensionTranslationClass" DisplayName="Extension SQL Translation Class" ShortDescription="" DefaultValue="org.teiid.connector.jdbc.derby.DerbySQLTranslator" PropertyType="String" IsExpert="true" IsMasked="false" />
+ <PropertyDefinition Name="DatabaseVersion" DisplayName="Database Version" ShortDescription="Derby Version i.e. 10.3" DefaultValue="10.1" PropertyType="String" />
</ComponentType>
<ComponentType Name="Teiid 6 JDBC Connector" ComponentTypeCode="2" Deployable="true" Deprecated="false" Monitorable="false" SuperComponentType="JDBC Connector" ParentComponentType="Connectors" LastChangedBy="ConfigurationStartup" CreatedBy="ConfigurationStartup">
<PropertyDefinition Name="ConnectionSource" DisplayName="Connection Source Class" ShortDescription="Driver, DataSource, or XADataSource class name" DefaultValue="com.metamatrix.jdbc.MMDriver" IsRequired="true" />
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2SqlTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2SqlTranslator.java 2009-07-25 20:58:40 UTC (rev 1188)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/db2/TestDB2SqlTranslator.java 2009-07-26 16:53:56 UTC (rev 1189)
@@ -58,7 +58,7 @@
// Convert from sql to objects
ICommand obj = util.parseCommand(input);
- ExecutionContext context = EnvironmentUtility.createSecurityContext("user");
+ ExecutionContext context = EnvironmentUtility.createSecurityContext("user"); //$NON-NLS-1$
TranslatedCommand tc = new TranslatedCommand(context, TRANSLATOR);
tc.translateCommand(obj);
@@ -106,5 +106,16 @@
input,
output);
}
+
+ @Test
+ public void testSelectNullLiteral() throws Exception {
+ String input = "select null + 1 as x, null || 'a' from BQT1.Smalla"; //$NON-NLS-1$
+ String output = "SELECT CAST(NULL AS INTEGER) AS x, CAST(NULL AS CHAR) FROM SmallA"; //$NON-NLS-1$
+
+ helpTestVisitor(FakeTranslationFactory.getInstance().getBQTTranslationUtility(),
+ input,
+ output);
+ }
+
}
Added: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyCapabilities.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyCapabilities.java 2009-07-26 16:53:56 UTC (rev 1189)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.derby;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class TestDerbyCapabilities {
+
+ @Test public void testLimitSupport() {
+ DerbyCapabilities derbyCapabilities = new DerbyCapabilities();
+ assertFalse(derbyCapabilities.supportsRowLimit());
+ derbyCapabilities.setVersion(DerbyCapabilities.TEN_5);
+ assertTrue(derbyCapabilities.supportsRowLimit());
+ }
+
+ @Test public void testFunctionSupport() {
+ DerbyCapabilities derbyCapabilities = new DerbyCapabilities();
+ assertEquals(32, derbyCapabilities.getSupportedFunctions().size());
+ derbyCapabilities.setVersion(DerbyCapabilities.TEN_4);
+ assertEquals(48, derbyCapabilities.getSupportedFunctions().size());
+ }
+
+}
Property changes on: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyCapabilities.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLeftOrRightFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLeftOrRightFunctionModifier.java 2009-07-25 20:58:40 UTC (rev 1188)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestLeftOrRightFunctionModifier.java 2009-07-26 16:53:56 UTC (rev 1189)
@@ -25,16 +25,14 @@
import java.util.Arrays;
import java.util.Properties;
-import org.teiid.connector.jdbc.oracle.LeftOrRightFunctionModifier;
-import org.teiid.connector.jdbc.oracle.OracleSQLTranslator;
+import junit.framework.TestCase;
+
import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
import org.teiid.connector.language.IExpression;
import org.teiid.connector.language.IFunction;
import org.teiid.connector.language.ILanguageFactory;
import org.teiid.connector.language.ILiteral;
-import junit.framework.TestCase;
-
import com.metamatrix.cdk.CommandBuilder;
import com.metamatrix.cdk.api.EnvironmentUtility;
Added: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestMODFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestMODFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestMODFunctionModifier.java 2009-07-26 16:53:56 UTC (rev 1189)
@@ -0,0 +1,1253 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.translator;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.teiid.connector.api.ConnectorEnvironment;
+import org.teiid.connector.api.ConnectorException;
+import org.teiid.connector.api.SourceSystemFunctions;
+import org.teiid.connector.language.IExpression;
+import org.teiid.connector.language.IFunction;
+import org.teiid.connector.language.ILanguageFactory;
+
+import com.metamatrix.cdk.CommandBuilder;
+import com.metamatrix.cdk.api.EnvironmentUtility;
+
+/**
+ * Test <code>ModFunctionModifier</code> by invoking its methods with varying
+ * parameters to validate it performs as designed and expected.
+ */
+public class TestMODFunctionModifier extends TestCase {
+
+ private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
+
+ /**
+ * Constructor for TestModFunctionModifier.
+ * @param name
+ */
+ public TestMODFunctionModifier(String name) {
+ super(name);
+ }
+
+
+ /**
+ * Create an expression containing a MOD function using <code>args</code>
+ * and pass it to the <code>Translator</code>'s MOD function modifier and
+ * compare the resulting expression to <code>expectedStr</code>.
+ *
+ * @param args An array of <code>IExpression</code>'s to use as the
+ * arguments to the MOD() function
+ * @param expectedStr A string representing the modified expression
+ * @return On success, the modified expression.
+ * @throws Exception
+ */
+ public IExpression helpTestMod(IExpression[] args, String expectedStr) throws Exception {
+ return this.helpTestMod(null, null, args, expectedStr);
+ }
+
+ /**
+ * Create an expression containing a MOD function using a function name of
+ * <code>modFunctionName</code> which supports types of <code>supportedTypes</code>
+ * and uses the arguments <code>args</code> and pass it to the
+ * <code>Translator</code>'s MOD function modifier and compare the resulting
+ * expression to <code>expectedStr</code>.
+ *
+ * @param modFunctionName the name to use for the function modifier
+ * @param supportedTypes a list of types that the mod function should support
+ * @param args an array of <code>IExpression</code>'s to use as the
+ * arguments to the MOD() function
+ * @param expectedStr A string representing the modified expression
+ * @return On success, the modified expression.
+ * @throws Exception
+ */
+ public IExpression helpTestMod(final String modFunctionName, final List<Class<?>> supportedTypes, IExpression[] args, String expectedStr) throws Exception {
+ IExpression param1 = null;
+ IExpression param2 = null;
+
+ if (args.length < 2) {
+ param2 = LANG_FACTORY.createLiteral(null, Short.class);
+ if (args.length < 1) {
+ param1 = LANG_FACTORY.createLiteral(null, Short.class);
+ } else {
+ param1 = args[0];
+ }
+ } else {
+ param1 = args[0];
+ param2 = args[1];
+ }
+
+ if ( !param1.getType().equals(param2.getType()) ) {
+ if (param2.getType().equals(BigDecimal.class)) {
+ param1.setType(param2.getType());
+ } else if (param1.getType().equals(BigDecimal.class)) {
+ param2.setType(param1.getType());
+ } else if (param2.getType().equals(BigInteger.class)) {
+ param1.setType(param2.getType());
+ } else if (param1.getType().equals(BigInteger.class)) {
+ param2.setType(param1.getType());
+ } else if (param2.getType().equals(Float.class)) {
+ param1.setType(param2.getType());
+ } else if (param1.getType().equals(Float.class)) {
+ param2.setType(param1.getType());
+ } else if (param2.getType().equals(Long.class)) {
+ param1.setType(param2.getType());
+ } else if (param1.getType().equals(Long.class)) {
+ param2.setType(param1.getType());
+ } else if (param2.getType().equals(Integer.class)) {
+ param1.setType(param2.getType());
+ } else if (param1.getType().equals(Integer.class)) {
+ param2.setType(param1.getType());
+ } else if (param2.getType().equals(Short.class)) {
+ param1.setType(param2.getType());
+ } else if (param1.getType().equals(Short.class)) {
+ param2.setType(param1.getType());
+ } else {
+ throw new IllegalArgumentException("Parameters must be of numeric types"); //$NON-NLS-1$
+ }
+ }
+
+ IFunction func = LANG_FACTORY.createFunction(modFunctionName,
+ Arrays.asList(param1, param2), param1.getType());
+
+ Translator trans = new Translator() {
+ @Override
+ public void initialize(ConnectorEnvironment env)
+ throws ConnectorException {
+ super.initialize(env);
+ if (modFunctionName == null) {
+ registerFunctionModifier(SourceSystemFunctions.MOD, new MODFunctionModifier(getLanguageFactory()));
+ } else {
+ registerFunctionModifier(SourceSystemFunctions.MOD, new MODFunctionModifier(getLanguageFactory(), modFunctionName, supportedTypes));
+ }
+ }
+ };
+
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
+
+ IExpression expr = trans.getFunctionModifiers().get(SourceSystemFunctions.MOD).modify(func);
+
+ SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
+ sqlVisitor.append(expr);
+
+ assertEquals("Modified function does not match", expectedStr, sqlVisitor.toString()); //$NON-NLS-1$
+
+ return expr;
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link Short} constants for both parameters returns MOD(x,y).
+ * {@link MODFunctionModifier} will be constructed without specifying a
+ * function name or a supported type list.
+ *
+ * @throws Exception
+ */
+ public void testTwoShortConst() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Short((short) 10), Short.class),
+ LANG_FACTORY.createLiteral(new Short((short) 6), Short.class)
+ };
+ // default / default
+ helpTestMod(args, "MOD(10, 6)"); //$NON-NLS-1$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link Short} constants for both parameters returns MOD(x,y).
+ * {@link MODFunctionModifier} will be constructed with a function name of
+ * "MOD" but without a supported type list.
+ *
+ * @throws Exception
+ */
+ public void testTwoShortConst2() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Short((short) 10), Short.class),
+ LANG_FACTORY.createLiteral(new Short((short) 6), Short.class)
+ };
+ // mod / default
+ helpTestMod("MOD", null, args, "MOD(10, 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link Short} constants for both parameters returns MOD(x,y).
+ * {@link MODFunctionModifier} will be constructed with a function name of
+ * "MOD" and a supported type list which contains {@link Short}.
+ *
+ * @throws Exception
+ */
+ public void testTwoShortConst3() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Short((short) 10), Short.class),
+ LANG_FACTORY.createLiteral(new Short((short) 6), Short.class)
+ };
+ // mod / Short
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Short.class);
+ helpTestMod("MOD", typeList, args, "MOD(10, 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link Short} constants for both parameters returns
+ * (x - (TRUNC((x / y), 0) * y)). {@link MODFunctionModifier} will be
+ * constructed with a function name of "MOD" and a supported type list which
+ * does not contains {@link Short}.
+ *
+ * @throws Exception
+ */
+ public void testTwoShortConst4() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Short((short) 10), Short.class),
+ LANG_FACTORY.createLiteral(new Short((short) 6), Short.class)
+ };
+ // mod / Integer
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Integer.class);
+ helpTestMod("MOD", typeList, args, "(10 - (TRUNC((10 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * x % y using {@link Short} constants for both parameters returns (x % y).
+ * {@link MODFunctionModifier} will be constructed with a function name of
+ * "%" and no supported type list.
+ *
+ * @throws Exception
+ */
+ public void testTwoShortConst5() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Short((short) 10), Short.class),
+ LANG_FACTORY.createLiteral(new Short((short) 6), Short.class)
+ };
+ // % / default
+ helpTestMod("%", null, args, "(10 % 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * x % y using {@link Short} constants for both parameters returns (x % y).
+ * {@link MODFunctionModifier} will be constructed with a function name of
+ * "%" and a supported type list which contains {@link Short}.
+ *
+ * @throws Exception
+ */
+ public void testTwoShortConst6() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Short((short) 10), Short.class),
+ LANG_FACTORY.createLiteral(new Short((short) 6), Short.class)
+ };
+ // % / Short
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Short.class);
+ helpTestMod("%", typeList, args, "(10 % 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * x % y using {@link Short} constants for both parameters returns
+ * (10 - (TRUNC((10 / 6), 0) * 6)). {@link MODFunctionModifier} will be
+ * constructed with a function name of "%" and a supported type list does not
+ * contain {@link Short}.
+ *
+ * @throws Exception
+ */
+ public void testTwoShortConst7() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Short((short) 10), Short.class),
+ LANG_FACTORY.createLiteral(new Short((short) 6), Short.class)
+ };
+ // % / Integer
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Integer.class);
+ helpTestMod("%", typeList, args, "(10 - (TRUNC((10 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link Integer} constants for both parameters returns
+ * MOD(x,y). {@link MODFunctionModifier} will be constructed without
+ * specifying a function name or a supported type list.
+ *
+ * @throws Exception
+ */
+ public void testTwoIntConst() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Integer(10), Integer.class),
+ LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
+ };
+ // default / default
+ helpTestMod(args, "MOD(10, 6)"); //$NON-NLS-1$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link Integer} constants for both parameters returns
+ * MOD(x,y). {@link MODFunctionModifier} will be constructed with a
+ * function name of "MOD" but without a supported type list.
+ *
+ * @throws Exception
+ */
+ public void testTwoIntConst2() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Integer(10), Integer.class),
+ LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
+ };
+ // mod / default
+ helpTestMod("MOD", null, args, "MOD(10, 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link Integer} constants for both parameters returns
+ * MOD(x,y). {@link MODFunctionModifier} will be constructed with a
+ * function name of "MOD" and a supported type list which contains {@link Integer}.
+ *
+ * @throws Exception
+ */
+ public void testTwoIntConst3() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Integer(10), Integer.class),
+ LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
+ };
+ // mod / Short
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Integer.class);
+ helpTestMod("MOD", typeList, args, "MOD(10, 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link Integer} constants for both parameters returns
+ * (x - (TRUNC((x / y), 0) * y)). {@link MODFunctionModifier} will be
+ * constructed with a function name of "MOD" and a supported type list which
+ * does not contain {@link Integer}.
+ *
+ * @throws Exception
+ */
+ public void testTwoIntConst4() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Integer(10), Integer.class),
+ LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
+ };
+ // mod / Integer
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Short.class);
+ helpTestMod("MOD", typeList, args, "(10 - (TRUNC((10 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * x % y using {@link Integer} constants for both parameters returns (x % y).
+ * {@link MODFunctionModifier} will be constructed with a function name of
+ * "%" and no supported type list.
+ *
+ * @throws Exception
+ */
+ public void testTwoIntConst5() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Integer(10), Integer.class),
+ LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
+ };
+ // % / default
+ helpTestMod("%", null, args, "(10 % 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * x % y using {@link Integer} constants for both parameters returns (x % y).
+ * {@link MODFunctionModifier} will be constructed with a function name of
+ * "%" and a supported type list which contains {@link Integer}.
+ *
+ * @throws Exception
+ */
+ public void testTwoIntConst6() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Integer(10), Integer.class),
+ LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
+ };
+ // % / Short
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Integer.class);
+ helpTestMod("%", typeList, args, "(10 % 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * x % y using {@link Integer} constants for both parameters returns
+ * (10 - (TRUNC((10 / 6), 0) * 6)). {@link MODFunctionModifier} will be
+ * constructed with a function name of "%" and a supported type list that
+ * does not contain {@link Integer}.
+ *
+ * @throws Exception
+ */
+ public void testTwoIntConst7() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Integer(10), Integer.class),
+ LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
+ };
+ // % / Integer
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Short.class);
+ helpTestMod("%", typeList, args, "(10 - (TRUNC((10 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link Long} constants for both parameters returns
+ * MOD(x,y). {@link MODFunctionModifier} will be constructed without
+ * specifying a function name or a supported type list.
+ *
+ * @throws Exception
+ */
+ public void testTwoLongConst() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Long(10), Long.class),
+ LANG_FACTORY.createLiteral(new Long(6), Long.class)
+ };
+ // default / default
+ helpTestMod(args, "MOD(10, 6)"); //$NON-NLS-1$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link Long} constants for both parameters returns
+ * MOD(x,y). {@link MODFunctionModifier} will be constructed with a
+ * function name of "MOD" but without a supported type list.
+ *
+ * @throws Exception
+ */
+ public void testTwoLongConst2() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Long(10), Long.class),
+ LANG_FACTORY.createLiteral(new Long(6), Long.class)
+ };
+ // mod / default
+ helpTestMod("MOD", null, args, "MOD(10, 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link Long} constants for both parameters returns
+ * MOD(x,y). {@link MODFunctionModifier} will be constructed with a
+ * function name of "MOD" and a supported type list which contains {@link Long}.
+ *
+ * @throws Exception
+ */
+ public void testTwoLongConst3() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Long(10), Long.class),
+ LANG_FACTORY.createLiteral(new Long(6), Long.class)
+ };
+ // mod / Long
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Long.class);
+ helpTestMod("MOD", typeList, args, "MOD(10, 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link Long} constants for both parameters returns
+ * (x - (TRUNC((x / y), 0) * y)). {@link MODFunctionModifier} will be
+ * constructed with a function name of "MOD" and a supported type list which
+ * does not contain {@link Long}.
+ *
+ * @throws Exception
+ */
+ public void testTwoLongConst4() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Long(10), Long.class),
+ LANG_FACTORY.createLiteral(new Long(6), Long.class)
+ };
+ // mod / Short
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Short.class);
+ helpTestMod("MOD", typeList, args, "(10 - (TRUNC((10 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * x % y using {@link Long} constants for both parameters returns (x % y).
+ * {@link MODFunctionModifier} will be constructed with a function name of
+ * "%" and no supported type list.
+ *
+ * @throws Exception
+ */
+ public void testTwoLongConst5() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Long(10), Long.class),
+ LANG_FACTORY.createLiteral(new Long(6), Long.class)
+ };
+ // % / default
+ helpTestMod("%", null, args, "(10 % 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * x % y using {@link Long} constants for both parameters returns (x % y).
+ * {@link MODFunctionModifier} will be constructed with a function name of
+ * "%" and a supported type list which contains {@link Long}.
+ *
+ * @throws Exception
+ */
+ public void testTwoLongConst6() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Long(10), Long.class),
+ LANG_FACTORY.createLiteral(new Long(6), Long.class)
+ };
+ // % / Long
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Long.class);
+ helpTestMod("%", typeList, args, "(10 % 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * x % y using {@link Long} constants for both parameters returns
+ * (10 - (TRUNC((10 / 6), 0) * 6)). {@link MODFunctionModifier} will be
+ * constructed with a function name of "%" and a supported type list that
+ * does not contain {@link Long}.
+ *
+ * @throws Exception
+ */
+ public void testTwoLongConst7() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Long(10), Long.class),
+ LANG_FACTORY.createLiteral(new Long(6), Long.class)
+ };
+ // % / Short
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Short.class);
+ helpTestMod("%", typeList, args, "(10 - (TRUNC((10 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link Float} constants for both parameters returns
+ * (x - (TRUNC((x / y), 0) * y)). {@link MODFunctionModifier} will be
+ * constructed without specifying a function name or a supported type list.
+ *
+ * @throws Exception
+ */
+ public void testTwoFloatConst() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Float(10), Float.class),
+ LANG_FACTORY.createLiteral(new Float(6), Float.class)
+ };
+ // default / default
+ helpTestMod(args, "(10.0 - (TRUNC((10.0 / 6.0), 0) * 6.0))"); //$NON-NLS-1$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link Float} constants for both parameters returns
+ * (x - (TRUNC((x / y), 0) * y)). {@link MODFunctionModifier} will be
+ * constructed with a function name of "MOD" but without a supported type
+ * list.
+ *
+ * @throws Exception
+ */
+ public void testTwoFloatConst2() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Float(10), Float.class),
+ LANG_FACTORY.createLiteral(new Float(6), Float.class)
+ };
+ // mod / default
+ helpTestMod("MOD", null, args, "(10.0 - (TRUNC((10.0 / 6.0), 0) * 6.0))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link Float} constants for both parameters returns
+ * MOD(x,y). {@link MODFunctionModifier} will be constructed with a
+ * function name of "MOD" and a supported type list which contains {@link Float}.
+ *
+ * @throws Exception
+ */
+ public void testTwoFloatConst3() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Float(10), Float.class),
+ LANG_FACTORY.createLiteral(new Float(6), Float.class)
+ };
+ // mod / Float
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Float.class);
+ helpTestMod("MOD", typeList, args, "MOD(10.0, 6.0)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link Float} constants for both parameters returns
+ * (x - (TRUNC((x / y), 0) * y)). {@link MODFunctionModifier} will be
+ * constructed with a function name of "MOD" and a supported type list which
+ * does not contain {@link Float}.
+ *
+ * @throws Exception
+ */
+ public void testTwoFloatConst4() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Float(10), Float.class),
+ LANG_FACTORY.createLiteral(new Float(6), Float.class)
+ };
+ // mod / Short
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Short.class);
+ helpTestMod("MOD", typeList, args, "(10.0 - (TRUNC((10.0 / 6.0), 0) * 6.0))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * x % y using {@link Float} constants for both parameters returns
+ * (x - (TRUNC((x / y), 0) * x)). {@link MODFunctionModifier} will be
+ * constructed with a function name of "%" and no supported type list.
+ *
+ * @throws Exception
+ */
+ public void testTwoFloatConst5() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Float(10), Float.class),
+ LANG_FACTORY.createLiteral(new Float(6), Float.class)
+ };
+ // % / default
+ helpTestMod("%", null, args, "(10.0 - (TRUNC((10.0 / 6.0), 0) * 6.0))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * x % y using {@link Float} constants for both parameters returns (x % y).
+ * {@link MODFunctionModifier} will be constructed with a function name of
+ * "%" and a supported type list which contains {@link Float}.
+ *
+ * @throws Exception
+ */
+ public void testTwoFloatConst6() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Float(10), Float.class),
+ LANG_FACTORY.createLiteral(new Float(6), Float.class)
+ };
+ // % / Float
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Float.class);
+ helpTestMod("%", typeList, args, "(10.0 % 6.0)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * x % y using {@link Float} constants for both parameters returns
+ * (x - (TRUNC((x / y), 0) * x)). {@link MODFunctionModifier} will be
+ * constructed with a function name of "%" and a supported type list that
+ * does not contain {@link Float}.
+ *
+ * @throws Exception
+ */
+ public void testTwoFloatConst7() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Float(10), Float.class),
+ LANG_FACTORY.createLiteral(new Float(6), Float.class)
+ };
+ // % / Short
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Short.class);
+ helpTestMod("%", typeList, args, "(10.0 - (TRUNC((10.0 / 6.0), 0) * 6.0))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link BigInteger} constants for both parameters returns
+ * (x - (TRUNC((x / y), 0) * y)). {@link MODFunctionModifier} will be
+ * constructed without specifying a function name or a supported type list.
+ *
+ * @throws Exception
+ */
+ public void testTwoBigIntConst() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new BigInteger("10"), BigInteger.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigInteger("6"), BigInteger.class) //$NON-NLS-1$
+ };
+ // default / default
+ helpTestMod(args, "(10 - (TRUNC((10 / 6), 0) * 6))"); //$NON-NLS-1$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link BigInteger} constants for both parameters returns
+ * (x - (TRUNC((x / y), 0) * y)). {@link MODFunctionModifier} will be
+ * constructed with a function name of "MOD" but without a supported type
+ * list.
+ *
+ * @throws Exception
+ */
+ public void testTwoBigIntConst2() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new BigInteger("10"), BigInteger.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigInteger("6"), BigInteger.class) //$NON-NLS-1$
+ };
+ // mod / default
+ helpTestMod("MOD", null, args, "(10 - (TRUNC((10 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link BigInteger} constants for both parameters returns
+ * MOD(x,y). {@link MODFunctionModifier} will be constructed with a
+ * function name of "MOD" and a supported type list which contains {@link BigInteger}.
+ *
+ * @throws Exception
+ */
+ public void testTwoBigIntConst3() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new BigInteger("10"), BigInteger.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigInteger("6"), BigInteger.class) //$NON-NLS-1$
+ };
+ // mod / BigInteger
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(BigInteger.class);
+ helpTestMod("MOD", typeList, args, "MOD(10, 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link BigInteger} constants for both parameters returns
+ * (x - (TRUNC((x / y), 0) * y)). {@link MODFunctionModifier} will be
+ * constructed with a function name of "MOD" and a supported type list which
+ * does not contain {@link BigInteger}.
+ *
+ * @throws Exception
+ */
+ public void testTwoBigIntConst4() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new BigInteger("10"), BigInteger.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigInteger("6"), BigInteger.class) //$NON-NLS-1$
+ };
+ // mod / Short
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Short.class);
+ helpTestMod("MOD", typeList, args, "(10 - (TRUNC((10 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * x % y using {@link BigInteger} constants for both parameters returns
+ * (x - (TRUNC((x / y), 0) * x)). {@link MODFunctionModifier} will be
+ * constructed with a function name of "%" and no supported type list.
+ *
+ * @throws Exception
+ */
+ public void testTwoBigIntConst5() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new BigInteger("10"), BigInteger.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigInteger("6"), BigInteger.class) //$NON-NLS-1$
+ };
+ // % / default
+ helpTestMod("%", null, args, "(10 - (TRUNC((10 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * x % y using {@link BigInteger} constants for both parameters returns
+ * (x % y). {@link MODFunctionModifier} will be constructed with a function
+ * name of "%" and a supported type list which contains {@link BigInteger}.
+ *
+ * @throws Exception
+ */
+ public void testTwoBigIntConst6() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new BigInteger("10"), BigInteger.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigInteger("6"), BigInteger.class) //$NON-NLS-1$
+ };
+ // % / BigInteger
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(BigInteger.class);
+ helpTestMod("%", typeList, args, "(10 % 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * x % y using {@link BigInteger} constants for both parameters returns
+ * (x - (TRUNC((x / y), 0) * x)). {@link MODFunctionModifier} will be
+ * constructed with a function name of "%" and a supported type list that
+ * does not contain {@link BigInteger}.
+ *
+ * @throws Exception
+ */
+ public void testTwoBigIntConst7() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new BigInteger("10"), BigInteger.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigInteger("6"), BigInteger.class) //$NON-NLS-1$
+ };
+ // % / Short
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Short.class);
+ helpTestMod("%", typeList, args, "(10 - (TRUNC((10 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link BigDecimal} constants for both parameters returns
+ * (x - (TRUNC((x / y), 0) * y)). {@link MODFunctionModifier} will be
+ * constructed without specifying a function name or a supported type list.
+ *
+ * @throws Exception
+ */
+ public void testTwoBigDecConst() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new BigDecimal("10"), BigDecimal.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigDecimal("6"), BigDecimal.class) //$NON-NLS-1$
+ };
+ // default / default
+ helpTestMod(args, "(10 - (TRUNC((10 / 6), 0) * 6))"); //$NON-NLS-1$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link BigDecimal} constants for both parameters returns
+ * (x - (TRUNC((x / y), 0) * y)). {@link MODFunctionModifier} will be
+ * constructed with a function name of "MOD" but without a supported type
+ * list.
+ *
+ * @throws Exception
+ */
+ public void testTwoBigDecConst2() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new BigDecimal("10"), BigDecimal.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigDecimal("6"), BigDecimal.class) //$NON-NLS-1$
+ };
+ // mod / default
+ helpTestMod("MOD", null, args, "(10 - (TRUNC((10 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link BigDecimal} constants for both parameters returns
+ * MOD(x,y). {@link MODFunctionModifier} will be constructed with a
+ * function name of "MOD" and a supported type list which contains {@link BigDecimal}.
+ *
+ * @throws Exception
+ */
+ public void testTwoBigDecConst3() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new BigDecimal("10"), BigDecimal.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigDecimal("6"), BigDecimal.class) //$NON-NLS-1$
+ };
+ // mod / BigDecimal
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(BigDecimal.class);
+ helpTestMod("MOD", typeList, args, "MOD(10, 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,y) using {@link BigDecimal} constants for both parameters returns
+ * (x - (TRUNC((x / y), 0) * y)). {@link MODFunctionModifier} will be
+ * constructed with a function name of "MOD" and a supported type list which
+ * does not contain {@link BigDecimal}.
+ *
+ * @throws Exception
+ */
+ public void testTwoBigDecConst4() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new BigDecimal("10"), BigDecimal.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigDecimal("6"), BigDecimal.class) //$NON-NLS-1$
+ };
+ // mod / Short
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Short.class);
+ helpTestMod("MOD", typeList, args, "(10 - (TRUNC((10 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * x % y using {@link BigDecimal} constants for both parameters returns
+ * (x - (TRUNC((x / y), 0) * x)). {@link MODFunctionModifier} will be
+ * constructed with a function name of "%" and no supported type list.
+ *
+ * @throws Exception
+ */
+ public void testTwoBigDecConst5() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new BigDecimal("10"), BigDecimal.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigDecimal("6"), BigDecimal.class) //$NON-NLS-1$
+ };
+ // % / default
+ helpTestMod("%", null, args, "(10 - (TRUNC((10 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * x % y using {@link BigDecimal} constants for both parameters returns
+ * (x % y). {@link MODFunctionModifier} will be constructed with a function
+ * name of "%" and a supported type list which contains {@link BigDecimal}.
+ *
+ * @throws Exception
+ */
+ public void testTwoBigDecConst6() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new BigDecimal("10"), BigDecimal.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigDecimal("6"), BigDecimal.class) //$NON-NLS-1$
+ };
+ // % / BigDecimal
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(BigDecimal.class);
+ helpTestMod("%", typeList, args, "(10 % 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * x % y using {@link BigDecimal} constants for both parameters returns
+ * (x - (TRUNC((x / y), 0) * x)). {@link MODFunctionModifier} will be
+ * constructed with a function name of "%" and a supported type list that
+ * does not contain {@link BigDecimal}.
+ *
+ * @throws Exception
+ */
+ public void testTwoBigDecConst7() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new BigDecimal("10"), BigDecimal.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigDecimal("6"), BigDecimal.class) //$NON-NLS-1$
+ };
+ // % / Short
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Short.class);
+ helpTestMod("%", typeList, args, "(10 - (TRUNC((10 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(e1,y) using a {@link Integer} element and a {@link Integer} constant
+ * for parameters returns MOD(e1,y). {@link MODFunctionModifier} will be
+ * constructed without specifying a function name or a supported type list.
+ *
+ * @throws Exception
+ */
+ public void testOneIntElemOneIntConst() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createElement("e1", null, null, Integer.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
+ };
+ // default / default
+ helpTestMod(args, "MOD(e1, 6)"); //$NON-NLS-1$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(e1,y) using a {@link Integer} element and a {@link Integer} constant
+ * for parameters returns MOD(e1,y). {@link MODFunctionModifier} will be
+ * constructed with a function name of "MOD" but without a supported type
+ * list.
+ *
+ * @throws Exception
+ */
+ public void testOneIntElemOneIntConst2() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createElement("e1", null, null, Integer.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
+ };
+ // mod / default
+ helpTestMod("MOD", null, args, "MOD(e1, 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(e1,y) using a {@link Integer} element and a {@link Integer} constant
+ * for parameters returns MOD(e1,y). {@link MODFunctionModifier} will be
+ * constructed with a function name of "MOD" and a supported type list which
+ * contains {@link Integer}.
+ *
+ * @throws Exception
+ */
+ public void testOneIntElemOneIntConst3() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createElement("e1", null, null, Integer.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
+ };
+ // mod / Integer
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Integer.class);
+ helpTestMod("MOD", typeList, args, "MOD(e1, 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(e1,y) using a {@link Integer} element and a {@link Integer} constant
+ * for parameters returns (e1 - (TRUNC((e1 / y), 0) * y)).
+ * {@link MODFunctionModifier} will be constructed with a function name of
+ * "MOD" and a supported type list which does not contain {@link Integer}.
+ *
+ * @throws Exception
+ */
+ public void testOneIntElemOneIntConst4() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createElement("e1", null, null, Integer.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
+ };
+ // mod / Short
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Short.class);
+ helpTestMod("MOD", typeList, args, "(e1 - (TRUNC((e1 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * e1 % y using a {@link Integer} element and a {@link Integer} constant for
+ * parameters returns (e1 % y). {@link MODFunctionModifier} will be
+ * constructed with a function name of "%" and no supported type list.
+ *
+ * @throws Exception
+ */
+ public void testOneIntElemOneIntConst5() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createElement("e1", null, null, Integer.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
+ };
+ // % / default
+ helpTestMod("%", null, args, "(e1 % 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * e1 % y using a {@link Integer} element and a {@link Integer} constant for
+ * parameters returns (e1 % y). {@link MODFunctionModifier} will be
+ * constructed with a function name of "%" and a supported type list which
+ * contains {@link Integer}.
+ *
+ * @throws Exception
+ */
+ public void testOneIntElemOneIntConst6() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createElement("e1", null, null, Integer.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
+ };
+ // % / Integer
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Integer.class);
+ helpTestMod("%", typeList, args, "(e1 % 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * e1 % y using a {@link Integer} element and a {@link Integer} constant for
+ * parameters returns (e1 - (TRUNC((e1 / y), 0) * y)).
+ * {@link MODFunctionModifier} will be constructed with a function name of
+ * "%" and a supported type list that does not contain {@link Integer}.
+ *
+ * @throws Exception
+ */
+ public void testOneIntElemOneIntConst7() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createElement("e1", null, null, Integer.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
+ };
+ // % / Short
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Short.class);
+ helpTestMod("%", typeList, args, "(e1 - (TRUNC((e1 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(e1,y) using a {@link BigDecimal} element and a {@link BigDecimal}
+ * constant for parameters returns (e1 - (TRUNC((e1 / y), 0) * y)).
+ * {@link MODFunctionModifier} will be constructed without specifying a
+ * function name or a supported type list.
+ *
+ * @throws Exception
+ */
+ public void testOneBigDecElemOneBigDecConst() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createElement("e1", null, null, BigDecimal.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigDecimal(6), BigDecimal.class)
+ };
+ // default / default
+ helpTestMod(args, "(e1 - (TRUNC((e1 / 6), 0) * 6))"); //$NON-NLS-1$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(e1,y) using a {@link BigDecimal} element and a {@link BigDecimal}
+ * constant for parameters returns (e1 - (TRUNC((e1 / y), 0) * y)).
+ * {@link MODFunctionModifier} will be constructed with a function name of
+ * "MOD" but without a supported type list.
+ *
+ * @throws Exception
+ */
+ public void testOneBigDecElemOneBigDecConst2() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createElement("e1", null, null, BigDecimal.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigDecimal(6), BigDecimal.class)
+ };
+ // mod / default
+ helpTestMod("MOD", null, args, "(e1 - (TRUNC((e1 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(e1,y) using a {@link BigDecimal} element and a {@link BigDecimal}
+ * constant for parameters returns MOD(e1,y). {@link MODFunctionModifier}
+ * will be constructed with a function name of "MOD" and a supported type
+ * list which contains {@link BigDecimal}.
+ *
+ * @throws Exception
+ */
+ public void testOneBigDecElemOneBigDecConst3() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createElement("e1", null, null, BigDecimal.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigDecimal(6), BigDecimal.class)
+ };
+ // mod / Integer
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(BigDecimal.class);
+ helpTestMod("MOD", typeList, args, "MOD(e1, 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(e1,y) using a {@link BigDecimal} element and a {@link BigDecimal}
+ * constant for parameters returns (e1 - (TRUNC((e1 / y), 0) * y)).
+ * {@link MODFunctionModifier} will be constructed with a function name of
+ * "MOD" and a supported type list which does not contain {@link BigDecimal}.
+ *
+ * @throws Exception
+ */
+ public void testOneBigDecElemOneBigDecConst4() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createElement("e1", null, null, BigDecimal.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigDecimal(6), BigDecimal.class)
+ };
+ // mod / Short
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Short.class);
+ helpTestMod("MOD", typeList, args, "(e1 - (TRUNC((e1 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * e1 % y using a {@link BigDecimal} element and a {@link BigDecimal}
+ * constant for parameters returns (e1 % y). {@link MODFunctionModifier}
+ * will be constructed with a function name of "%" and no supported type
+ * list.
+ *
+ * @throws Exception
+ */
+ public void testOneBigDecElemOneBigDecConst5() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createElement("e1", null, null, BigDecimal.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigDecimal(6), BigDecimal.class)
+ };
+ // % / default
+ helpTestMod("%", null, args, "(e1 - (TRUNC((e1 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * e1 % y using a {@link BigDecimal} element and a {@link BigDecimal}
+ * constant for parameters returns (e1 % y). {@link MODFunctionModifier}
+ * will be constructed with a function name of "%" and a supported type list
+ * which contains {@link BigDecimal}.
+ *
+ * @throws Exception
+ */
+ public void testOneBigDecElemOneBigDecConst6() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createElement("e1", null, null, BigDecimal.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigDecimal(6), BigDecimal.class)
+ };
+ // % / BigDecimal
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(BigDecimal.class);
+ helpTestMod("%", typeList, args, "(e1 % 6)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * e1 % y using a {@link BigDecimal} element and a {@link BigDecimal}
+ * constant for parameters returns (e1 - (TRUNC((e1 / y), 0) * y)).
+ * {@link MODFunctionModifier} will be constructed with a function name of
+ * "%" and a supported type list that does not contain {@link BigDecimal}.
+ *
+ * @throws Exception
+ */
+ public void testOneBigDecElemOneBigDecConst7() throws Exception {
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createElement("e1", null, null, BigDecimal.class), //$NON-NLS-1$
+ LANG_FACTORY.createLiteral(new BigDecimal(6), BigDecimal.class)
+ };
+ // % / Short
+ List<Class<?>> typeList = new ArrayList<Class<?>>(1);
+ typeList.add(Short.class);
+ helpTestMod("%", typeList, args, "(e1 - (TRUNC((e1 / 6), 0) * 6))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test {@link MODFunctionModifier#modify(IFunction)} to validate a call to
+ * MOD(x,e1) using a {@link Float} literal and a {@link Float} element for
+ * parameters returns (x - (floor((x / e1)) * e1)). {@link MODFunctionModifier}
+ * will be constructed with a function name of "MOD" and no supported type
+ * list. The test explicitly overrides
+ * {@link MODFunctionModifier#getQuotientExpression(IExpression)} to produce
+ * output that uses the floor(z) function.
+ *
+ * @throws Exception
+ */
+ public void testOverrideGetQuotient() throws Exception {
+ final Class<?> dataType = Float.class;
+ final String modFunctionName = "MOD"; //$NON-NLS-1$
+ final String expectedStr = "(1000.23 - (floor((1000.23 / e1)) * e1))"; //$NON-NLS-1$
+
+ IExpression[] args = new IExpression[] {
+ LANG_FACTORY.createLiteral(new Float(1000.23), dataType),
+ LANG_FACTORY.createElement("e1", null, null, dataType), //$NON-NLS-1$
+ };
+ IFunction func = LANG_FACTORY.createFunction(modFunctionName, args, dataType);
+
+ final Translator trans = new Translator() {
+ @Override
+ public void initialize(ConnectorEnvironment env)
+ throws ConnectorException {
+ super.initialize(env);
+ registerFunctionModifier(SourceSystemFunctions.MOD, new MODFunctionModifier(getLanguageFactory(), modFunctionName, null) {
+ @Override
+ protected IExpression getQuotientExpression(
+ IExpression division) {
+ return getLanguageFactory().createFunction("floor", Arrays.asList(division), division.getType()); //$NON-NLS-1$
+ }
+
+ });
+ }
+ };
+
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
+
+ IExpression expr = trans.getFunctionModifiers().get(SourceSystemFunctions.MOD).modify(func);
+ SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
+ sqlVisitor.append(expr);
+ assertEquals("Modified function does not match", expectedStr, sqlVisitor.toString()); //$NON-NLS-1$
+ }
+}
Property changes on: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestMODFunctionModifier.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
[View Less]
15 years, 8 months
teiid SVN: r1188 - in trunk: connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle and 11 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-07-25 16:58:40 -0400 (Sat, 25 Jul 2009)
New Revision: 1188
Added:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ExtractFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestExtractFunctionModifier.java
Removed:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/…
[View More]oracle/ExtractFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/DatePartFunctionModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/ModifiedDatePartFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestExtractFunctionModifier.java
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseConvertModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseConvertModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java
trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java
Log:
TEIID-739 TEIID-360 updates to jdbc connector translators and capabilities. also changing the sybase/sql server time literal back to using the year 1900
Modified: trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java
===================================================================
--- trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java 2009-07-25 02:40:46 UTC (rev 1187)
+++ trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -85,7 +85,7 @@
public class SQLStringVisitor extends AbstractLanguageVisitor implements SQLReservedWords {
private Set<String> infixFunctions = new HashSet<String>(Arrays.asList("%", "+", "-", "*", "+", "/", "||", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
- "&", "|", "^")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "&", "|", "^", "#")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
private static final String ESCAPED_QUOTE = "''"; //$NON-NLS-1$
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ExtractFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ExtractFunctionModifier.java 2009-07-25 02:40:46 UTC (rev 1187)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ExtractFunctionModifier.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -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 org.teiid.connector.jdbc.oracle;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
-import org.teiid.connector.language.IExpression;
-import org.teiid.connector.language.IFunction;
-
-
-/**
- * Convert the YEAR/MONTH/DAY etc. function into an equivalent Oracle function.
- * Format: EXTRACT(YEAR from Element) or EXTRACT(YEAR from DATE '2004-03-03')
- */
-public class ExtractFunctionModifier extends BasicFunctionModifier {
- public static final String SPACE = " "; //$NON-NLS-1$
-
- private String target;
-
- public ExtractFunctionModifier(String target) {
- this.target = target;
- }
-
- public List<?> translate(IFunction function) {
- List<IExpression> args = function.getParameters();
-
- List<Object> objs = new ArrayList<Object>();
- objs.add("EXTRACT("); //$NON-NLS-1$
- objs.add(target);
- objs.add(SPACE);
- objs.add("FROM"); //$NON-NLS-1$
- objs.add(SPACE);
- objs.add(args.get(0));
- objs.add(")"); //$NON-NLS-1$
- return objs;
- }
-}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java 2009-07-25 02:40:46 UTC (rev 1187)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -40,6 +40,7 @@
import org.teiid.connector.api.SourceSystemFunctions;
import org.teiid.connector.jdbc.JDBCPlugin;
import org.teiid.connector.jdbc.translator.AliasModifier;
+import org.teiid.connector.jdbc.translator.ExtractFunctionModifier;
import org.teiid.connector.jdbc.translator.Translator;
import org.teiid.connector.language.ICommand;
import org.teiid.connector.language.IElement;
@@ -72,12 +73,12 @@
registerFunctionModifier(SourceSystemFunctions.CEILING, new AliasModifier("ceil")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.LOG10, new Log10FunctionModifier(getLanguageFactory()));
registerFunctionModifier(SourceSystemFunctions.CONVERT, new OracleConvertModifier(getLanguageFactory(), getEnvironment().getLogger()));
- registerFunctionModifier(SourceSystemFunctions.HOUR, new ExtractFunctionModifier("HOUR"));//$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.YEAR, new ExtractFunctionModifier("YEAR"));//$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.MINUTE, new ExtractFunctionModifier("MINUTE"));//$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.SECOND, new ExtractFunctionModifier("SECOND"));//$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.MONTH, new ExtractFunctionModifier("MONTH"));//$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new ExtractFunctionModifier("DAY"));//$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.HOUR, new ExtractFunctionModifier());
+ registerFunctionModifier(SourceSystemFunctions.YEAR, new ExtractFunctionModifier());
+ registerFunctionModifier(SourceSystemFunctions.MINUTE, new ExtractFunctionModifier());
+ registerFunctionModifier(SourceSystemFunctions.SECOND, new ExtractFunctionModifier());
+ registerFunctionModifier(SourceSystemFunctions.MONTH, new ExtractFunctionModifier());
+ registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new ExtractFunctionModifier());
registerFunctionModifier(SourceSystemFunctions.MONTHNAME, new MonthOrDayNameFunctionModifier(getLanguageFactory(), "Month"));//$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.DAYNAME, new MonthOrDayNameFunctionModifier(getLanguageFactory(), "Day"));//$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.WEEK, new DayWeekQuarterFunctionModifier(getLanguageFactory(), "WW"));//$NON-NLS-1$
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/DatePartFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/DatePartFunctionModifier.java 2009-07-25 02:40:46 UTC (rev 1187)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/DatePartFunctionModifier.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -1,52 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.connector.jdbc.postgresql;
-
-import java.util.Arrays;
-
-import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
-import org.teiid.connector.language.IExpression;
-import org.teiid.connector.language.IFunction;
-import org.teiid.connector.language.ILanguageFactory;
-
-
-
-/**
- * @since 4.3
- */
-class DatePartFunctionModifier extends BasicFunctionModifier {
-
- protected ILanguageFactory factory;
- private String part;
-
- DatePartFunctionModifier(ILanguageFactory langFactory, String partName) {
- this.factory = langFactory;
- this.part = partName;
- }
-
- public IExpression modify(IFunction function) {
- return factory.createFunction("date_part", //$NON-NLS-1$
- Arrays.asList(factory.createLiteral(part, String.class), function.getParameters().get(0)),
- Integer.class);
- }
-}
Deleted: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/ModifiedDatePartFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/ModifiedDatePartFunctionModifier.java 2009-07-25 02:40:46 UTC (rev 1187)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/ModifiedDatePartFunctionModifier.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -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 org.teiid.connector.jdbc.postgresql;
-
-import java.util.Arrays;
-
-import org.teiid.connector.language.IExpression;
-import org.teiid.connector.language.IFunction;
-import org.teiid.connector.language.ILanguageFactory;
-
-
-
-/**
- * @since 4.3
- */
-class ModifiedDatePartFunctionModifier extends DatePartFunctionModifier {
-
- private String modifier;
- private Object arg;
-
- ModifiedDatePartFunctionModifier(ILanguageFactory factory, String partName, String modifierFunctionName, Object modifierArgument) {
- super(factory, partName);
- this.modifier = modifierFunctionName;
- this.arg = modifierArgument;
- }
-
- public IExpression modify(IFunction function) {
- IExpression expr = super.modify(function);
- return factory.createFunction(modifier,
- Arrays.asList(expr, factory.createLiteral(arg, arg.getClass())),
- arg.getClass());
- }
-
-
-}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java 2009-07-25 02:40:46 UTC (rev 1187)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -22,8 +22,8 @@
package org.teiid.connector.jdbc.postgresql;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.ArrayList;
+import java.util.List;
import org.teiid.connector.jdbc.JDBCCapabilities;
@@ -44,11 +44,10 @@
supportedFunctions.add("ASIN"); //$NON-NLS-1$
supportedFunctions.add("ATAN"); //$NON-NLS-1$
supportedFunctions.add("ATAN2"); //$NON-NLS-1$
- // These are executed within the server and never pushed down
-// supportedFunctions.add("BITAND"); //$NON-NLS-1$
-// supportedFunctions.add("BITNOT"); //$NON-NLS-1$
-// supportedFunctions.add("BITOR"); //$NON-NLS-1$
-// supportedFunctions.add("BITXOR"); //$NON-NLS-1$
+ supportedFunctions.add("BITAND"); //$NON-NLS-1$
+ supportedFunctions.add("BITNOT"); //$NON-NLS-1$
+ supportedFunctions.add("BITOR"); //$NON-NLS-1$
+ supportedFunctions.add("BITXOR"); //$NON-NLS-1$
supportedFunctions.add("CEILING"); //$NON-NLS-1$
supportedFunctions.add("COS"); //$NON-NLS-1$
supportedFunctions.add("COT"); //$NON-NLS-1$
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java 2009-07-25 02:40:46 UTC (rev 1187)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -37,6 +37,7 @@
import org.teiid.connector.jdbc.oracle.LeftOrRightFunctionModifier;
import org.teiid.connector.jdbc.oracle.MonthOrDayNameFunctionModifier;
import org.teiid.connector.jdbc.translator.AliasModifier;
+import org.teiid.connector.jdbc.translator.ExtractFunctionModifier;
import org.teiid.connector.jdbc.translator.Translator;
import org.teiid.connector.language.IAggregate;
import org.teiid.connector.language.ICommand;
@@ -46,16 +47,22 @@
-/**
+/**
+ * Translator class for PostgreSQL. Updated to expect a 8.0+ jdbc client
* @since 4.3
*/
public class PostgreSQLTranslator extends Translator {
public void initialize(ConnectorEnvironment env) throws ConnectorException {
-
+ //TODO: all of the functions (except for convert) can be handled through just the escape syntax
super.initialize(env);
registerFunctionModifier(SourceSystemFunctions.LOG, new AliasModifier("ln")); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.LOG10, new AliasModifier("log")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.LOG10, new AliasModifier("log")); //$NON-NLS-1$
+
+ registerFunctionModifier(SourceSystemFunctions.BITAND, new AliasModifier("&")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.BITNOT, new AliasModifier("~")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.BITOR, new AliasModifier("|")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.BITXOR, new AliasModifier("#")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.CHAR, new AliasModifier("chr")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.CONCAT, new AliasModifier("||")); //$NON-NLS-1$
@@ -66,20 +73,24 @@
registerFunctionModifier(SourceSystemFunctions.UCASE, new AliasModifier("upper")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.DAYNAME, new MonthOrDayNameFunctionModifier(getLanguageFactory(), "Day"));//$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new ModifiedDatePartFunctionModifier(getLanguageFactory(), "dow", "+", new Integer(1)));//$NON-NLS-1$ //$NON-NLS-2$
- registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new DatePartFunctionModifier(getLanguageFactory(), "day"));//$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new DatePartFunctionModifier(getLanguageFactory(), "doy"));//$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.HOUR, new DatePartFunctionModifier(getLanguageFactory(), "hour"));//$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.MINUTE, new DatePartFunctionModifier(getLanguageFactory(), "minute"));//$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.MONTH, new DatePartFunctionModifier(getLanguageFactory(), "month"));//$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new ExtractFunctionModifier());
+ registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new ExtractFunctionModifier());
+ registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new ExtractFunctionModifier());
+ registerFunctionModifier(SourceSystemFunctions.HOUR, new ExtractFunctionModifier());
+ registerFunctionModifier(SourceSystemFunctions.MINUTE, new ExtractFunctionModifier());
+ registerFunctionModifier(SourceSystemFunctions.MONTH, new ExtractFunctionModifier());
registerFunctionModifier(SourceSystemFunctions.MONTHNAME, new MonthOrDayNameFunctionModifier(getLanguageFactory(), "Month"));//$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.QUARTER, new DatePartFunctionModifier(getLanguageFactory(), "quarter"));//$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.SECOND, new DatePartFunctionModifier(getLanguageFactory(), "second"));//$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.WEEK, new DatePartFunctionModifier(getLanguageFactory(), "week"));//$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.YEAR, new DatePartFunctionModifier(getLanguageFactory(), "year"));//$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.QUARTER, new ExtractFunctionModifier());
+ registerFunctionModifier(SourceSystemFunctions.SECOND, new ExtractFunctionModifier());
+ registerFunctionModifier(SourceSystemFunctions.WEEK, new ExtractFunctionModifier());
+ registerFunctionModifier(SourceSystemFunctions.YEAR, new ExtractFunctionModifier());
+
+ //specific to 8.2 client or later
+ //registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new EscapeSyntaxModifier());
+ //registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("coalesce")); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.CONVERT, new PostgreSQLConvertModifier(getLanguageFactory()));
+ registerFunctionModifier(SourceSystemFunctions.CONVERT, new PostgreSQLConvertModifier(getLanguageFactory()));
}
@Override
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerCapabilities.java 2009-07-25 02:40:46 UTC (rev 1187)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerCapabilities.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -88,20 +88,20 @@
supportedFunctions.add("UPPER"); //$NON-NLS-1$
//supportedFunctons.add("CURDATE"); //$NON-NLS-1$
//supportedFunctons.add("CURTIME"); //$NON-NLS-1$
- //supportedFunctons.add("DAYNAME"); //$NON-NLS-1$
+ supportedFunctions.add("DAYNAME"); //$NON-NLS-1$
supportedFunctions.add("DAYOFMONTH"); //$NON-NLS-1$
- //supportedFunctons.add("DAYOFWEEK"); //$NON-NLS-1$
- //supportedFunctons.add("DAYOFYEAR"); //$NON-NLS-1$
- //supportedFunctons.add("HOUR"); //$NON-NLS-1$
- //supportedFunctons.add("MINUTE"); //$NON-NLS-1$
+ supportedFunctions.add("DAYOFWEEK"); //$NON-NLS-1$
+ supportedFunctions.add("DAYOFYEAR"); //$NON-NLS-1$
+ supportedFunctions.add("HOUR"); //$NON-NLS-1$
+ supportedFunctions.add("MINUTE"); //$NON-NLS-1$
supportedFunctions.add("MONTH"); //$NON-NLS-1$
- //supportedFunctons.add("MONTHNAME"); //$NON-NLS-1$
- //supportedFunctons.add("NOW"); //$NON-NLS-1$
- //supportedFunctons.add("QUARTER"); //$NON-NLS-1$
- //supportedFunctons.add("SECOND"); //$NON-NLS-1$
- //supportedFunctons.add("TIMESTAMPADD"); //$NON-NLS-1$
- //supportedFunctons.add("TIMESTAMPDIFF"); //$NON-NLS-1$
- //supportedFunctons.add("WEEK"); //$NON-NLS-1$
+ supportedFunctions.add("MONTHNAME"); //$NON-NLS-1$
+ //supportedFunctions.add("NOW"); //$NON-NLS-1$
+ supportedFunctions.add("QUARTER"); //$NON-NLS-1$
+ supportedFunctions.add("SECOND"); //$NON-NLS-1$
+ supportedFunctions.add("TIMESTAMPADD"); //$NON-NLS-1$
+ supportedFunctions.add("TIMESTAMPDIFF"); //$NON-NLS-1$
+ supportedFunctions.add("WEEK"); //$NON-NLS-1$
supportedFunctions.add("YEAR"); //$NON-NLS-1$
supportedFunctions.add("CAST"); //$NON-NLS-1$
supportedFunctions.add("CONVERT"); //$NON-NLS-1$
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerSQLTranslator.java 2009-07-25 02:40:46 UTC (rev 1187)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerSQLTranslator.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -30,9 +30,10 @@
import org.teiid.connector.api.SourceSystemFunctions;
import org.teiid.connector.jdbc.sybase.SybaseSQLTranslator;
import org.teiid.connector.jdbc.translator.AliasModifier;
+import org.teiid.connector.jdbc.translator.EscapeSyntaxModifier;
-
-/**
+/**
+ * Updated to assume the use of the DataDirect, 2005 driver, or later.
*/
public class SqlServerSQLTranslator extends SybaseSQLTranslator {
@@ -40,7 +41,18 @@
super.initialize(env);
//TEIID-31 remove mod modifier for SQL Server 2008
registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new AliasModifier("day")); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.REPEAT, new AliasModifier("replicate")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.REPEAT, new AliasModifier("replicate")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.DAYNAME, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.MONTHNAME, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.HOUR, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.MINUTE, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.QUARTER, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.SECOND, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.WEEK, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new EscapeSyntaxModifier());
}
@Override
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseConvertModifier.java 2009-07-25 02:40:46 UTC (rev 1187)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseConvertModifier.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -28,7 +28,6 @@
import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
import org.teiid.connector.jdbc.translator.DropFunctionModifier;
-import org.teiid.connector.jdbc.translator.FunctionModifier;
import org.teiid.connector.language.IExpression;
import org.teiid.connector.language.IFunction;
import org.teiid.connector.language.ILanguageFactory;
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseSQLTranslator.java 2009-07-25 02:40:46 UTC (rev 1187)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sybase/SybaseSQLTranslator.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -75,6 +75,11 @@
}
@Override
+ public String getDefaultTimeYMD() {
+ return "1900-01-01"; //$NON-NLS-1$
+ }
+
+ @Override
public List<?> translateCommand(ICommand command, ExecutionContext context) {
if (!(command instanceof IQueryCommand)) {
return null;
Copied: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ExtractFunctionModifier.java (from rev 1179, trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ExtractFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ExtractFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ExtractFunctionModifier.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.translator;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.teiid.connector.api.SourceSystemFunctions;
+import org.teiid.connector.language.IExpression;
+import org.teiid.connector.language.IFunction;
+import org.teiid.connector.visitor.util.SQLReservedWords;
+
+
+/**
+ * Convert the YEAR/MONTH/DAY etc. function into an equivalent Extract function.
+ * Format: EXTRACT(YEAR from Element) or EXTRACT(YEAR from DATE '2004-03-03')
+ */
+public class ExtractFunctionModifier extends BasicFunctionModifier {
+ public static final String YEAR = "YEAR"; //$NON-NLS-1$
+ public static final String QUARTER = "QUARTER"; //$NON-NLS-1$
+ public static final String MONTH = "MONTH"; //$NON-NLS-1$
+ public static final String DAYOFYEAR = "DOY"; //$NON-NLS-1$
+ public static final String DAY = "DAY"; //$NON-NLS-1$
+ public static final String WEEK = "WEEK"; //$NON-NLS-1$
+ public static final String DAYOFWEEK = "DOW"; //$NON-NLS-1$
+ public static final String HOUR = "HOUR"; //$NON-NLS-1$
+ public static final String MINUTE = "MINUTE"; //$NON-NLS-1$
+ public static final String SECOND = "SECOND"; //$NON-NLS-1$
+ public static final String MILLISECONDS = "MILLISECONDS"; //$NON-NLS-1$
+
+ private static Map<String, String> FUNCTION_PART_MAP = new HashMap<String, String>();
+
+ static {
+ FUNCTION_PART_MAP.put(SourceSystemFunctions.WEEK, WEEK);
+ FUNCTION_PART_MAP.put(SourceSystemFunctions.DAYOFWEEK, DAYOFWEEK);
+ FUNCTION_PART_MAP.put(SourceSystemFunctions.DAYOFYEAR, DAYOFYEAR);
+ FUNCTION_PART_MAP.put(SourceSystemFunctions.YEAR, YEAR);
+ FUNCTION_PART_MAP.put(SourceSystemFunctions.QUARTER, QUARTER);
+ FUNCTION_PART_MAP.put(SourceSystemFunctions.MONTH, MONTH);
+ FUNCTION_PART_MAP.put(SourceSystemFunctions.DAYOFMONTH, DAY);
+ FUNCTION_PART_MAP.put(SourceSystemFunctions.HOUR, HOUR);
+ FUNCTION_PART_MAP.put(SourceSystemFunctions.MINUTE, MINUTE);
+ FUNCTION_PART_MAP.put(SourceSystemFunctions.SECOND, SECOND);
+ }
+
+ public ExtractFunctionModifier() {
+ }
+
+ public List<?> translate(IFunction function) {
+ List<IExpression> args = function.getParameters();
+ List<Object> objs = new ArrayList<Object>();
+ objs.add("EXTRACT("); //$NON-NLS-1$
+ objs.add(FUNCTION_PART_MAP.get(function.getName().toLowerCase()));
+ objs.add(SQLReservedWords.SPACE);
+ objs.add(SQLReservedWords.FROM);
+ objs.add(SQLReservedWords.SPACE);
+ objs.add(args.get(0));
+ objs.add(SQLReservedWords.RPAREN);
+ if (function.getName().toLowerCase().equals(SourceSystemFunctions.DAYOFWEEK)) {
+ objs.add(0, SQLReservedWords.LPAREN);
+ objs.add(" + 1)"); //$NON-NLS-1$
+ }
+ return objs;
+ }
+}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java 2009-07-25 02:40:46 UTC (rev 1187)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -263,7 +263,7 @@
*/
public String translateLiteralTime(Time timeValue) {
if (!hasTimeType()) {
- return "{ts'1970-01-01 " + formatDateValue(timeValue) + "'}"; //$NON-NLS-1$ //$NON-NLS-2$
+ return "{ts'"+ getDefaultTimeYMD()+ " " + formatDateValue(timeValue) + "'}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
return "{t'" + formatDateValue(timeValue) + "'}"; //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -350,6 +350,10 @@
return true;
}
+ public String getDefaultTimeYMD() {
+ return "1970-01-01"; //$NON-NLS-1$
+ }
+
/**
* Returns the name for a given {@link ISetQuery.Operation}
* @param operation
Deleted: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestExtractFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestExtractFunctionModifier.java 2009-07-25 02:40:46 UTC (rev 1187)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestExtractFunctionModifier.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -1,118 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.connector.jdbc.oracle;
-
-import java.sql.Timestamp;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Properties;
-
-import org.teiid.connector.api.TypeFacility;
-import org.teiid.connector.jdbc.oracle.ExtractFunctionModifier;
-import org.teiid.connector.jdbc.oracle.OracleSQLTranslator;
-import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
-import org.teiid.connector.language.IElement;
-import org.teiid.connector.language.IExpression;
-import org.teiid.connector.language.IFunction;
-import org.teiid.connector.language.IGroup;
-import org.teiid.connector.language.ILanguageFactory;
-import org.teiid.connector.language.ILiteral;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.CommandBuilder;
-import com.metamatrix.cdk.api.EnvironmentUtility;
-import com.metamatrix.query.unittest.TimestampUtil;
-
-/**
- */
-public class TestExtractFunctionModifier extends TestCase {
-
- private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
-
- /**
- * Constructor for TestMonthFunctionModifier.
- * @param name
- */
- public TestExtractFunctionModifier(String name) {
- super(name);
- }
-
- public IExpression helpTestMod(IExpression c, String expectedStr, String target) throws Exception {
- IFunction func = LANG_FACTORY.createFunction(target,
- Arrays.asList(c),
- Integer.class);
-
- ExtractFunctionModifier mod = new ExtractFunctionModifier (target);
- IExpression expr = mod.modify(func);
- List<?> parts = mod.translate(func);
- assertEquals(7, parts.size());
- assertFalse(parts.get(5) instanceof String);
- OracleSQLTranslator trans = new OracleSQLTranslator();
- trans.registerFunctionModifier("extract", mod);
- trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
-
- SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
-
- sqlVisitor.append(expr);
- assertEquals(expectedStr, sqlVisitor.toString());
- return expr;
- }
- public void test1() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
- helpTestMod(arg1, "EXTRACT(MONTH FROM {d'2004-01-21'})" , "month"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void test2() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 17, 5, 0, 0), Timestamp.class);
- helpTestMod(arg1, "EXTRACT(MONTH FROM {ts'2004-01-21 17:05:00.0'})", "month"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void test3() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
- helpTestMod(arg1, "EXTRACT(YEAR FROM {d'2004-01-21'})", "year"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void test4() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 17, 5, 0, 0), Timestamp.class);
- helpTestMod(arg1, "EXTRACT(YEAR FROM {ts'2004-01-21 17:05:00.0'})", "year"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void test5() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
- helpTestMod(arg1, "EXTRACT(DAY FROM {d'2004-01-21'})", "dayofmonth"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void test6() throws Exception {
- ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 17, 5, 0, 0), Timestamp.class);
- helpTestMod(arg1, "EXTRACT(DAY FROM {ts'2004-01-21 17:05:00.0'})", "dayofmonth"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void test11() throws Exception {
- IGroup group = LANG_FACTORY.createGroup(null, "group", null); //$NON-NLS-1$
- IElement elem = LANG_FACTORY.createElement("col", group, null, TypeFacility.RUNTIME_TYPES.DATE); //$NON-NLS-1$
- helpTestMod(elem, "EXTRACT(DAY FROM col)", "dayofmonth"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-}
-
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java 2009-07-25 02:40:46 UTC (rev 1187)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -289,7 +289,7 @@
public void testDayOfWeek() throws Exception {
String input = "SELECT dayofweek(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
- String output = "SELECT (date_part('dow', to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) + 1) FROM PARTS"; //$NON-NLS-1$
+ String output = "SELECT (EXTRACT(DOW FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) + 1) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
@@ -298,7 +298,7 @@
}
public void testDayOfMonth() throws Exception {
String input = "SELECT dayofmonth(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
- String output = "SELECT date_part('day', to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
+ String output = "SELECT EXTRACT(DAY FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
@@ -307,7 +307,7 @@
}
public void testDayOfYear() throws Exception {
String input = "SELECT dayofyear(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
- String output = "SELECT date_part('doy', to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
+ String output = "SELECT EXTRACT(DOY FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
@@ -316,7 +316,7 @@
}
public void testHour() throws Exception {
String input = "SELECT hour(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
- String output = "SELECT date_part('hour', to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
+ String output = "SELECT EXTRACT(HOUR FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
@@ -325,7 +325,7 @@
}
public void testMinute() throws Exception {
String input = "SELECT minute(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
- String output = "SELECT date_part('minute', to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
+ String output = "SELECT EXTRACT(MINUTE FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
@@ -334,7 +334,7 @@
}
public void testMonth() throws Exception {
String input = "SELECT month(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
- String output = "SELECT date_part('month', to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
+ String output = "SELECT EXTRACT(MONTH FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
@@ -343,7 +343,7 @@
}
public void testQuarter() throws Exception {
String input = "SELECT quarter(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
- String output = "SELECT date_part('quarter', to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
+ String output = "SELECT EXTRACT(QUARTER FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
@@ -352,7 +352,7 @@
}
public void testSecond() throws Exception {
String input = "SELECT second(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
- String output = "SELECT date_part('second', to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
+ String output = "SELECT EXTRACT(SECOND FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
@@ -361,7 +361,7 @@
}
public void testWeek() throws Exception {
String input = "SELECT week(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
- String output = "SELECT date_part('week', to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
+ String output = "SELECT EXTRACT(WEEK FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
@@ -370,7 +370,7 @@
}
public void testYear() throws Exception {
String input = "SELECT year(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
- String output = "SELECT date_part('year', to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
+ String output = "SELECT EXTRACT(YEAR FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
@@ -448,6 +448,17 @@
input,
MODIFIERS,
output);
- }
+ }
+
+ public void testBitFunctions() throws Exception {
+ String input = "select bitand(intkey, intnum), bitnot(intkey), bitor(intnum, intkey), bitxor(intnum, intkey) from bqt1.smalla"; //$NON-NLS-1$
+ String output = "SELECT (SmallA.IntKey & SmallA.IntNum), ~(SmallA.IntKey), (SmallA.IntNum | SmallA.IntKey), (SmallA.IntNum # SmallA.IntKey) FROM SmallA"; //$NON-NLS-1$
+
+ helpTestVisitor(getTestBQTVDB(),
+ input,
+ MODIFIERS,
+ output);
+ }
+
}
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2009-07-25 02:40:46 UTC (rev 1187)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -113,5 +113,15 @@
input,
output);
}
+
+ @Test
+ public void testDateFunctions() throws Exception {
+ String input = "select dayName(timestampValue), dayOfWeek(timestampValue), quarter(timestampValue) from bqt1.smalla"; //$NON-NLS-1$
+ String output = "SELECT {fn dayName(SmallA.TimestampValue)}, {fn dayOfWeek(SmallA.TimestampValue)}, {fn quarter(SmallA.TimestampValue)} FROM SmallA"; //$NON-NLS-1$
+
+ helpTestVisitor(getBQTVDB(),
+ input,
+ output);
+ }
}
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseConvertModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseConvertModifier.java 2009-07-25 02:40:46 UTC (rev 1187)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseConvertModifier.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -171,7 +171,7 @@
LANG_FACTORY.createLiteral("timestamp", String.class)}, //$NON-NLS-1$
java.sql.Timestamp.class);
- helpGetString1(func, "convert(datetime, {ts'1970-01-01 12:02:03'})"); //$NON-NLS-1$
+ helpGetString1(func, "convert(datetime, {ts'1900-01-01 12:02:03'})"); //$NON-NLS-1$
}
public void testDateToTimestamp() throws Exception {
@@ -236,7 +236,7 @@
LANG_FACTORY.createLiteral("string", String.class)}, //$NON-NLS-1$
String.class);
- helpGetString1(func, "convert(varchar, {ts'1970-01-01 03:10:01'}, 108)"); //$NON-NLS-1$
+ helpGetString1(func, "convert(varchar, {ts'1900-01-01 03:10:01'}, 108)"); //$NON-NLS-1$
}
public void testBigDecimalToString() throws Exception {
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java 2009-07-25 02:40:46 UTC (rev 1187)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -190,7 +190,7 @@
public void testTimeLiteral() {
helpTestVisitor(getTestVDB(),
"select {t'13:59:59'} FROM parts", //$NON-NLS-1$
- "SELECT {ts'1970-01-01 13:59:59'} FROM PARTS"); //$NON-NLS-1$
+ "SELECT {ts'1900-01-01 13:59:59'} FROM PARTS"); //$NON-NLS-1$
}
@Test
Copied: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestExtractFunctionModifier.java (from rev 1179, trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestExtractFunctionModifier.java)
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestExtractFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestExtractFunctionModifier.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.translator;
+
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.teiid.connector.api.SourceSystemFunctions;
+import org.teiid.connector.api.TypeFacility;
+import org.teiid.connector.language.IElement;
+import org.teiid.connector.language.IExpression;
+import org.teiid.connector.language.IFunction;
+import org.teiid.connector.language.IGroup;
+import org.teiid.connector.language.ILanguageFactory;
+import org.teiid.connector.language.ILiteral;
+
+import com.metamatrix.cdk.CommandBuilder;
+import com.metamatrix.cdk.api.EnvironmentUtility;
+import com.metamatrix.query.unittest.TimestampUtil;
+
+/**
+ */
+public class TestExtractFunctionModifier extends TestCase {
+
+ private static final ILanguageFactory LANG_FACTORY = CommandBuilder.getLanuageFactory();
+
+ /**
+ * Constructor for TestMonthFunctionModifier.
+ * @param name
+ */
+ public TestExtractFunctionModifier(String name) {
+ super(name);
+ }
+
+ public IExpression helpTestMod(IExpression c, String expectedStr, String target) throws Exception {
+ IFunction func = LANG_FACTORY.createFunction(target,
+ Arrays.asList(c),
+ Integer.class);
+
+ ExtractFunctionModifier mod = new ExtractFunctionModifier ();
+ IExpression expr = mod.modify(func);
+ Translator trans = new Translator();
+ trans.registerFunctionModifier(target, mod);
+ trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
+
+ SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
+
+ sqlVisitor.append(expr);
+ assertEquals(expectedStr, sqlVisitor.toString());
+ return expr;
+ }
+ public void test1() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
+ helpTestMod(arg1, "EXTRACT(MONTH FROM {d'2004-01-21'})" , "month"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void test2() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 17, 5, 0, 0), Timestamp.class);
+ helpTestMod(arg1, "EXTRACT(MONTH FROM {ts'2004-01-21 17:05:00.0'})", "month"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void test3() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
+ helpTestMod(arg1, "EXTRACT(YEAR FROM {d'2004-01-21'})", "year"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void test4() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 17, 5, 0, 0), Timestamp.class);
+ helpTestMod(arg1, "EXTRACT(YEAR FROM {ts'2004-01-21 17:05:00.0'})", "year"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void test5() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
+ helpTestMod(arg1, "EXTRACT(DAY FROM {d'2004-01-21'})", "dayofmonth"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void test6() throws Exception {
+ ILiteral arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 17, 5, 0, 0), Timestamp.class);
+ helpTestMod(arg1, "EXTRACT(DAY FROM {ts'2004-01-21 17:05:00.0'})", "dayofmonth"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void test11() throws Exception {
+ IGroup group = LANG_FACTORY.createGroup(null, "group", null); //$NON-NLS-1$
+ IElement elem = LANG_FACTORY.createElement("col", group, null, TypeFacility.RUNTIME_TYPES.DATE); //$NON-NLS-1$
+ helpTestMod(elem, "EXTRACT(DAY FROM col)", "dayofmonth"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void test12() 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(DOW FROM col) + 1)", SourceSystemFunctions.DAYOFWEEK); //$NON-NLS-1$
+ }
+
+}
+
Modified: trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java
===================================================================
--- trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java 2009-07-25 02:40:46 UTC (rev 1187)
+++ trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java 2009-07-25 20:58:40 UTC (rev 1188)
@@ -22,20 +22,19 @@
package com.metamatrix.connector.jdbc.oracle;
+import static org.junit.Assert.*;
+
import java.util.Properties;
-import junit.framework.TestCase;
-
+import org.junit.Test;
import org.teiid.connector.api.ConnectorException;
import org.teiid.connector.api.ExecutionContext;
import org.teiid.connector.jdbc.JDBCPropertyNames;
import org.teiid.connector.jdbc.oracle.OracleSQLTranslator;
import org.teiid.connector.jdbc.translator.TranslatedCommand;
import org.teiid.connector.language.ICommand;
-import org.teiid.connector.metadata.runtime.RuntimeMetadata;
import org.teiid.dqp.internal.datamgr.impl.ExecutionContextImpl;
import org.teiid.dqp.internal.datamgr.impl.FakeExecutionContextImpl;
-import org.teiid.dqp.internal.datamgr.metadata.RuntimeMetadataImpl;
import com.metamatrix.cdk.CommandBuilder;
import com.metamatrix.cdk.api.EnvironmentUtility;
@@ -47,20 +46,10 @@
import com.metamatrix.query.unittest.FakeMetadataFactory;
import com.metamatrix.query.unittest.FakeMetadataObject;
import com.metamatrix.query.unittest.FakeMetadataStore;
-
-/**
- */
-public class TestOracleSQLConversionVisitor extends TestCase {
+
+public class TestOracleSQLConversionVisitor {
private static ExecutionContext EMPTY_CONTEXT = new FakeExecutionContextImpl();
- /**
- * Constructor for TestOracleSQLConversionVisitor.
- * @param name
- */
- public TestOracleSQLConversionVisitor(String name) {
- super(name);
- }
-
private String getTestVDB() {
return UnitTestUtil.getTestDataPath() + "/PartsSupplierOracle.vdb"; //$NON-NLS-1$
}
@@ -77,7 +66,7 @@
// Convert from sql to objects
TranslationUtility util = new TranslationUtility(vdb);
ICommand obj = util.parseCommand(input, correctNaming, true);
- this.helpTestVisitor(obj, util.createRuntimeMetadata(), context, dbmsTimeZone, expectedOutput);
+ this.helpTestVisitor(obj, context, dbmsTimeZone, expectedOutput);
}
/** Helper method takes a QueryMetadataInterface impl instead of a VDB filename
@@ -87,11 +76,10 @@
// Convert from sql to objects
CommandBuilder commandBuilder = new CommandBuilder(metadata);
ICommand obj = commandBuilder.getCommand(input);
- RuntimeMetadata runtimeMetadata = new RuntimeMetadataImpl(metadata);
- this.helpTestVisitor(obj, runtimeMetadata, context, dbmsTimeZone, expectedOutput);
+ this.helpTestVisitor(obj, context, dbmsTimeZone, expectedOutput);
}
- private void helpTestVisitor(ICommand obj, RuntimeMetadata metadata, ExecutionContext context, String dbmsTimeZone, String expectedOutput) throws ConnectorException {
+ private void helpTestVisitor(ICommand obj, ExecutionContext context, String dbmsTimeZone, String expectedOutput) throws ConnectorException {
// Apply function replacement
@@ -124,7 +112,7 @@
}
/** defect 21775 */
- public void testDateStuff() throws Exception {
+ @Test public void testDateStuff() throws Exception {
String input = "SELECT ((CASE WHEN month(datevalue) < 10 THEN ('0' || convert(month(datevalue), string)) ELSE convert(month(datevalue), string) END || CASE WHEN dayofmonth(datevalue) < 10 THEN ('0' || convert(dayofmonth(datevalue), string)) ELSE convert(dayofmonth(datevalue), string) END) || convert(year(datevalue), string)), SUM(intkey) FROM bqt1.SMALLA GROUP BY datevalue"; //$NON-NLS-1$
String output = "SELECT CASE WHEN (CASE WHEN (CASE WHEN EXTRACT(MONTH FROM SmallA.DateValue) < 10 THEN CASE WHEN to_char(EXTRACT(MONTH FROM SmallA.DateValue)) IS NULL THEN NULL ELSE concat('0', to_char(EXTRACT(MONTH FROM SmallA.DateValue))) END ELSE to_char(EXTRACT(MONTH FROM SmallA.DateValue)) END IS NULL) OR (CASE WHEN EXTRACT(DAY FROM SmallA.DateValue) < 10 THEN CASE WHEN to_char(EXTRACT(DAY FROM SmallA.DateValue)) IS NULL THEN NULL ELSE concat('0', to_char(EXTRACT(DAY FROM SmallA.DateValue))) END ELSE to_char(EXTRACT(DAY FROM SmallA.DateValue)) END IS NULL) THEN NULL ELSE concat(CASE WHEN EXTRACT(MONTH FROM SmallA.DateValue) < 10 THEN CASE WHEN to_char(EXTRACT(MONTH FROM SmallA.DateValue)) IS NULL THEN NULL ELSE concat('0', to_char(EXTRACT(MONTH FROM SmallA.DateValue))) END ELSE to_char(EXTRACT(MONTH FROM SmallA.DateValue)) END, CASE WHEN EXTRACT(DAY FROM SmallA.DateValue) < 10 THEN CASE WHEN to_char(EXTRACT(DAY FROM SmallA.DateValue)) IS NULL THEN NULL ELSE con!
cat('0', to_char(EXTRACT(DAY FROM SmallA.DateValue))) END ELSE to_char(EXTRACT(DAY FROM SmallA.DateValue)) END) END IS NULL) OR (to_char(EXTRACT(YEAR FROM SmallA.DateValue)) IS NULL) THEN NULL ELSE concat(CASE WHEN (CASE WHEN EXTRACT(MONTH FROM SmallA.DateValue) < 10 THEN CASE WHEN to_char(EXTRACT(MONTH FROM SmallA.DateValue)) IS NULL THEN NULL ELSE concat('0', to_char(EXTRACT(MONTH FROM SmallA.DateValue))) END ELSE to_char(EXTRACT(MONTH FROM SmallA.DateValue)) END IS NULL) OR (CASE WHEN EXTRACT(DAY FROM SmallA.DateValue) < 10 THEN CASE WHEN to_char(EXTRACT(DAY FROM SmallA.DateValue)) IS NULL THEN NULL ELSE concat('0', to_char(EXTRACT(DAY FROM SmallA.DateValue))) END ELSE to_char(EXTRACT(DAY FROM SmallA.DateValue)) END IS NULL) THEN NULL ELSE concat(CASE WHEN EXTRACT(MONTH FROM SmallA.DateValue) < 10 THEN CASE WHEN to_char(EXTRACT(MONTH FROM SmallA.DateValue)) IS NULL THEN NULL ELSE concat('0', to_char(EXTRACT(MONTH FROM SmallA.DateValue))) END ELSE to_char(EXTRACT(MONTH FR!
OM SmallA.DateValue)) END, CASE WHEN EXTRACT(DAY FROM SmallA.D!
ateValue
) < 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$
@@ -148,7 +136,7 @@
EMPTY_CONTEXT, null, output);
}
- public void testCharFunction() throws Exception {
+ @Test public void testCharFunction() throws Exception {
String input = "SELECT char(CONVERT(PART_ID, INTEGER)) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT chr(to_number(PARTS.PART_ID)) FROM PARTS"; //$NON-NLS-1$
@@ -158,7 +146,7 @@
output);
}
- public void testLcaseFunction() throws Exception {
+ @Test 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$
@@ -168,7 +156,7 @@
output);
}
- public void testUcaseFunction() throws Exception {
+ @Test 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$
@@ -178,7 +166,7 @@
output);
}
- public void testIfnullFunction() throws Exception {
+ @Test public void testIfnullFunction() throws Exception {
String input = "SELECT ifnull(PART_NAME, 'x') FROM PARTS"; //$NON-NLS-1$
String output = "SELECT nvl(PARTS.PART_NAME, 'x') FROM PARTS"; //$NON-NLS-1$
@@ -188,7 +176,7 @@
output);
}
- public void testLogFunction() throws Exception {
+ @Test public void testLogFunction() throws Exception {
String input = "SELECT log(CONVERT(PART_ID, INTEGER)) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT ln(to_number(PARTS.PART_ID)) FROM PARTS"; //$NON-NLS-1$
@@ -198,7 +186,7 @@
output);
}
- public void testLog10Function() throws Exception {
+ @Test public void testLog10Function() throws Exception {
String input = "SELECT log10(CONVERT(PART_ID, INTEGER)) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT log(10, to_number(PARTS.PART_ID)) FROM PARTS"; //$NON-NLS-1$
@@ -208,7 +196,7 @@
output);
}
- public void testConvertFunctionInteger() throws Exception {
+ @Test public void testConvertFunctionInteger() throws Exception {
String input = "SELECT convert(PARTS.PART_ID, integer) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT to_number(PARTS.PART_ID) FROM PARTS"; //$NON-NLS-1$
@@ -219,7 +207,7 @@
output);
}
- public void testConvertFunctionChar() throws Exception {
+ @Test public void testConvertFunctionChar() throws Exception {
String input = "SELECT convert(PARTS.PART_ID, char) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT PARTS.PART_ID FROM PARTS"; //$NON-NLS-1$
@@ -229,7 +217,7 @@
output);
}
- public void testConvertFunctionBoolean() throws Exception {
+ @Test public void testConvertFunctionBoolean() throws Exception {
String input = "SELECT convert(PARTS.PART_ID, boolean) FROM PARTS"; //$NON-NLS-1$
//String output = "SELECT PARTS.PART_ID FROM PARTS"; //$NON-NLS-1$
String output = "SELECT decode(PARTS.PART_ID, 'true', 1, 'false', 0) FROM PARTS"; //$NON-NLS-1$
@@ -240,7 +228,7 @@
output);
}
- public void testConvertFunctionDate() throws Exception {
+ @Test public void testConvertFunctionDate() throws Exception {
String input = "SELECT convert(PARTS.PART_ID, date) FROM PARTS"; //$NON-NLS-1$
//String output = "SELECT PARTS.PART_ID FROM PARTS"; //$NON-NLS-1$
String output = "SELECT to_date(PARTS.PART_ID, 'YYYY-MM-DD') FROM PARTS"; //$NON-NLS-1$
@@ -250,7 +238,7 @@
output);
}
- public void testConvertFunctionTime() throws Exception {
+ @Test public void testConvertFunctionTime() throws Exception {
String input = "SELECT convert(PARTS.PART_ID, time) FROM PARTS"; //$NON-NLS-1$
//String output = "SELECT PARTS.PART_ID FROM PARTS"; //$NON-NLS-1$
String output = "SELECT to_date(('1970-01-01 ' || to_char(PARTS.PART_ID, 'HH24:MI:SS')), 'YYYY-MM-DD HH24:MI:SS') FROM PARTS"; //$NON-NLS-1$
@@ -261,7 +249,7 @@
output);
}
- public void testConvertFunctionTimestamp() throws Exception {
+ @Test public void testConvertFunctionTimestamp() throws Exception {
String input = "SELECT convert(PARTS.PART_ID, timestamp) FROM PARTS"; //$NON-NLS-1$
//String output = "SELECT PARTS.PART_ID FROM PARTS"; //$NON-NLS-1$
String output = "SELECT to_timestamp(PARTS.PART_ID, 'YYYY-MM-DD HH24:MI:SS.FF') FROM PARTS"; //$NON-NLS-1$
@@ -272,7 +260,7 @@
output);
}
- public void testExtractFunctionTimestamp() throws Exception {
+ @Test public void testExtractFunctionTimestamp() throws Exception {
String input = "SELECT month(TIMESTAMPVALUE) FROM BQT1.Smalla"; //$NON-NLS-1$
String output = "SELECT EXTRACT(MONTH FROM SmallA.TimestampValue) FROM SmallA"; //$NON-NLS-1$
@@ -281,58 +269,58 @@
EMPTY_CONTEXT, null, output);
}
- public void testAliasedGroup() throws Exception {
+ @Test public void testAliasedGroup() throws Exception {
helpTestVisitor(getTestVDB(),
"select y.part_name from parts as y", //$NON-NLS-1$
null,
"SELECT y.PART_NAME FROM PARTS y"); //$NON-NLS-1$
}
- public void testDateLiteral() throws Exception {
+ @Test public void testDateLiteral() throws Exception {
helpTestVisitor(getTestVDB(),
"select {d'2002-12-31'} FROM parts", //$NON-NLS-1$
null,
"SELECT {d'2002-12-31'} FROM PARTS"); //$NON-NLS-1$
}
- public void testTimeLiteral() throws Exception {
+ @Test public void testTimeLiteral() throws Exception {
helpTestVisitor(getTestVDB(),
"select {t'13:59:59'} FROM parts", //$NON-NLS-1$
null,
"SELECT {ts'1970-01-01 13:59:59'} FROM PARTS"); //$NON-NLS-1$
}
- public void testTimestampLiteral() throws Exception {
+ @Test public void testTimestampLiteral() throws Exception {
helpTestVisitor(getTestVDB(),
"select {ts'2002-12-31 13:59:59'} FROM parts", //$NON-NLS-1$
null,
"SELECT {ts'2002-12-31 13:59:59.0'} FROM PARTS"); //$NON-NLS-1$
}
- public void testUnionOrderByWithThreeBranches() throws Exception {
+ @Test 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$
null,
- "(SELECT g_2.PART_ID AS c_0 FROM PARTS g_2 UNION ALL SELECT g_1.PART_NAME AS c_0 FROM PARTS g_1) UNION ALL SELECT g_0.PART_ID AS c_0 FROM PARTS g_0 ORDER BY c_0",
- true); //$NON-NLS-1$
+ "(SELECT g_2.PART_ID AS c_0 FROM PARTS g_2 UNION ALL SELECT g_1.PART_NAME AS c_0 FROM PARTS g_1) UNION ALL SELECT g_0.PART_ID AS c_0 FROM PARTS g_0 ORDER BY c_0", //$NON-NLS-1$
+ true);
}
- public void testUnionOrderBy() throws Exception {
+ @Test public void testUnionOrderBy() throws Exception {
helpTestVisitor(getTestVDB(),
"select part_id FROM parts UNION ALL select part_name FROM parts ORDER BY part_id", //$NON-NLS-1$
null,
- "SELECT g_1.PART_ID AS c_0 FROM PARTS g_1 UNION ALL SELECT g_0.PART_NAME AS c_0 FROM PARTS g_0 ORDER BY c_0",
- true); //$NON-NLS-1$
+ "SELECT g_1.PART_ID AS c_0 FROM PARTS g_1 UNION ALL SELECT g_0.PART_NAME AS c_0 FROM PARTS g_0 ORDER BY c_0", //$NON-NLS-1$
+ true);
}
- public void testUnionOrderBy2() throws Exception {
+ @Test public void testUnionOrderBy2() throws Exception {
helpTestVisitor(getTestVDB(),
"select part_id as p FROM parts UNION ALL select part_name FROM parts ORDER BY p", //$NON-NLS-1$
null,
"SELECT PARTS.PART_ID AS p FROM PARTS UNION ALL SELECT PARTS.PART_NAME FROM PARTS ORDER BY p"); //$NON-NLS-1$
}
- public void testUpdateWithFunction() throws Exception {
+ @Test public void testUpdateWithFunction() throws Exception {
String input = "UPDATE bqt1.smalla SET intkey = intkey + 1"; //$NON-NLS-1$
String output = "UPDATE SmallA SET IntKey = (SmallA.IntKey + 1)"; //$NON-NLS-1$
@@ -351,7 +339,7 @@
*
* @since 4.3
*/
- public void testDUAL() throws Exception {
+ @Test public void testDUAL() throws Exception {
String input = "SELECT something FROM DUAL"; //$NON-NLS-1$
String output = "SELECT something FROM DUAL"; //$NON-NLS-1$
@@ -369,7 +357,7 @@
*
* @since 4.3
*/
- public void testROWNUM() throws Exception {
+ @Test public void testROWNUM() throws Exception {
String input = "SELECT part_name, rownum FROM parts"; //$NON-NLS-1$
String output = "SELECT PARTS.PART_NAME, ROWNUM FROM PARTS"; //$NON-NLS-1$
@@ -386,7 +374,7 @@
*
* @since 4.3
*/
- public void testROWNUM2() throws Exception {
+ @Test public void testROWNUM2() throws Exception {
String input = "SELECT part_name FROM parts where rownum < 100"; //$NON-NLS-1$
String output = "SELECT PARTS.PART_NAME FROM PARTS WHERE ROWNUM < 100"; //$NON-NLS-1$
@@ -402,7 +390,7 @@
*
* @since 4.3
*/
- public void testOracleCommentPayload() throws Exception {
+ @Test public void testOracleCommentPayload() throws Exception {
String input = "SELECT part_name, rownum FROM parts"; //$NON-NLS-1$
String output = "SELECT /*+ ALL_ROWS */ PARTS.PART_NAME, ROWNUM FROM PARTS"; //$NON-NLS-1$
@@ -421,7 +409,7 @@
* reproducing this case relies on the name in source for the table being different from
* the name
*/
- public void testCase3845() throws Exception {
+ @Test public void testCase3845() throws Exception {
String input = "SELECT (DoubleNum * 1.0) FROM BQT1.Smalla"; //$NON-NLS-1$
String output = "SELECT (SmallishA.DoubleNum * 1.0) FROM SmallishA"; //$NON-NLS-1$
@@ -450,7 +438,7 @@
helpTestVisitor(vdb, input, null, expectedOutput);
}
- public void testRowLimit2() throws Exception {
+ @Test public void testRowLimit2() throws Exception {
String input = "select intkey from bqt1.smalla limit 100"; //$NON-NLS-1$
String output = "SELECT * FROM (SELECT SmallA.IntKey FROM SmallA) WHERE ROWNUM <= 100"; //$NON-NLS-1$
@@ -459,7 +447,7 @@
EMPTY_CONTEXT, null, output);
}
- public void testRowLimit3() throws Exception {
+ @Test public void testRowLimit3() throws Exception {
String input = "select intkey from bqt1.smalla limit 50, 100"; //$NON-NLS-1$
String output = "SELECT * FROM (SELECT VIEW_FOR_LIMIT.*, ROWNUM ROWNUM_ FROM (SELECT SmallA.IntKey FROM SmallA) VIEW_FOR_LIMIT WHERE ROWNUM <= 150) WHERE ROWNUM_ > 50"; //$NON-NLS-1$
@@ -468,7 +456,7 @@
EMPTY_CONTEXT, null, output);
}
- public void testLimitWithNestedInlineView() throws Exception {
+ @Test 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 * FROM (SELECT SmallA.IntKey, SmallA.StringKey FROM SmallA ORDER BY intkey) WHERE ROWNUM <= 100) x GROUP BY x.intkey"; //$NON-NLS-1$
@@ -477,7 +465,7 @@
EMPTY_CONTEXT, null, output);
}
- public void testExceptAsMinus() throws Exception {
+ @Test public void testExceptAsMinus() throws Exception {
String input = "select intkey, intnum from bqt1.smalla except select intnum, intkey from bqt1.smallb"; //$NON-NLS-1$
String output = "SELECT SmallA.IntKey, SmallA.IntNum FROM SmallA MINUS SELECT SmallB.IntNum, SmallB.IntKey FROM SmallB"; //$NON-NLS-1$
@@ -486,27 +474,27 @@
EMPTY_CONTEXT, null, output);
}
- public void testConcat2_useLiteral() throws Exception {
+ @Test public void testConcat2_useLiteral() throws Exception {
String sql = "select concat2(stringnum,'_xx') from BQT1.Smalla"; //$NON-NLS-1$
String expected = "SELECT concat(nvl(SmallA.StringNum, ''), '_xx') FROM SmallA"; //$NON-NLS-1$
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(), sql, EMPTY_CONTEXT, null, expected);
}
- public void testConcat2() throws Exception {
+ @Test public void testConcat2() throws Exception {
String sql = "select concat2(stringnum, stringnum) from BQT1.Smalla"; //$NON-NLS-1$
- String expected = "SELECT CASE WHEN SmallA.StringNum IS NULL THEN NULL ELSE concat(nvl(SmallA.StringNum, ''), nvl(SmallA.StringNum, '')) END FROM SmallA";
+ String expected = "SELECT CASE WHEN SmallA.StringNum IS NULL THEN NULL ELSE concat(nvl(SmallA.StringNum, ''), nvl(SmallA.StringNum, '')) END FROM SmallA"; //$NON-NLS-1$
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(), sql, EMPTY_CONTEXT, null, expected);
}
- public void testConcat() throws Exception {
+ @Test public void testConcat() throws Exception {
String sql = "select concat(stringnum, stringkey) from BQT1.Smalla"; //$NON-NLS-1$
- String expected = "SELECT CASE WHEN (SmallA.StringNum IS NULL) OR (SmallA.StringKey IS NULL) THEN NULL ELSE concat(SmallA.StringNum, SmallA.StringKey) END FROM SmallA";
+ String expected = "SELECT CASE WHEN (SmallA.StringNum IS NULL) OR (SmallA.StringKey IS NULL) THEN NULL ELSE concat(SmallA.StringNum, SmallA.StringKey) END FROM SmallA"; //$NON-NLS-1$
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(), sql, EMPTY_CONTEXT, null, expected);
}
- public void testConcat_withLiteral() throws Exception {
+ @Test public void testConcat_withLiteral() throws Exception {
String sql = "select stringnum || '1' from BQT1.Smalla"; //$NON-NLS-1$
- String expected = "SELECT CASE WHEN SmallA.StringNum IS NULL THEN NULL ELSE concat(SmallA.StringNum, '1') END FROM SmallA";
+ String expected = "SELECT CASE WHEN SmallA.StringNum IS NULL THEN NULL ELSE concat(SmallA.StringNum, '1') END FROM SmallA"; //$NON-NLS-1$
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(), sql, EMPTY_CONTEXT, null, expected);
}
[View Less]
15 years, 8 months