teiid SVN: r1194 - trunk/build/kit-runtime/examples/portfolio/PortfolioModel.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2009-07-27 16:27:21 -0400 (Mon, 27 Jul 2009)
New Revision: 1194
Modified:
trunk/build/kit-runtime/examples/portfolio/PortfolioModel/Portfolio.vdb
Log:
TEIID-684: adding the classpath for the deby connector
Modified: trunk/build/kit-runtime/examples/portfolio/PortfolioModel/Portfolio.vdb
===================================================================
--- trunk/build/kit-runtime/examples/portfolio/PortfolioModel/Portfolio.vdb 2009-07-27 18:50:49 UTC (rev 1193)
+++ trunk/build/kit-runtime/examples/portfolio/PortfolioModel/Portfolio.vdb 2009-07-27 20:27:21 UTC (rev 1194)
@@ -108,34 +108,40 @@
i�p�h|%�m�~%+0��yz�jU�,��[υm��xJW/-~^��h���w���gi�
-
-sl$
-G^����5�����v2.�]H-M�%��f��{�"�LH�:o�z��a��ܹz�v1y��Y�����������3j2����kx?w�b�?���s�w�~��/؟�-nP�G�Q��Ç���!����&�����Β�|A_<�B2O�I7�������D�9�p��P�'�~�$�x#g�&� w΄z ��fo���5�Z�p���w�H�|�/�A4Ķ=��{��ۛ�͝n�d�;�^��՚n�z-cט�l̦l�UN�0��W
-=8��߲b�۷�r���`p4P /FO��j���,I��a���d5�\�)��z�1��p�*G�x��c�:tj13=��̐��uf(Wr/�����A|�Iԑ��S2�~'A�G�ꄊ�T��X1���+ؠO�ݭ�^_����-5r�j��9[�I��ȵ����J��DGxQ�Ըfd��>�ԝ+n�� 5���vm}
-����(��Z3PDȝ��9|��m��Ss�]�upx���З�����T��k�\���]3~� -�Ɗ
-��S@�G�v����n���Iww�����mono@�^�x$��&�
-�\6y��ܢY�@$�_�|0i>WZ
-�@'pgĈ�a0�\r��5�pv����7�p�R$D�߁C�(���<gz\�V��# j@f$�����;^�I�S���R+C͞|x�`�!!<y)�Ȕ?��{�P�!/�CBH�\b�'
-��%�K���z@ʙ���1�N��3�R�[�-$~���x�ҔD���xVJ�
-����9������/ �`��
-#IW8n��L)�Ya������tDΟ����h�[3�x�=\�%���1��������Y;�ؤ��m4<�1f�^�!���4�Ӄ�S�(�������sD��Or�)��c
-$V؉���{�����YGI�a�:^�$�'�:�jʌ�k�Y��-�� 8�
-x�Y'BѬ�H�+��N�=��b��LNԁXRZ���2�p9�r}������p�ܐ�Nj��F�{X��Sf�i>_�KV�ҵ��-<�����G��$V�GǞ���j�z� @ �Q�4��k��c��'*t<8���q�|�$R�|�zا0���W����*�@��E�[�-�%�z�ullw��۱�\=٣����(�ӳ$�ZRu:G��x��c\v�
-�c���븞$Dy��N�`�-����b��q�ڏ�6ڤ/q���E��6Ǹ�ua�>�+���S�Kc~g�,q̨�Ki.�kQ
-�!8*�"�o"T��c#5zH��ҩ�1�
-2I���$It���h=F��g��=ru��P/�eRAA�ý�>��[J�W���tW�o���`�r�!̦r
-`0�Cz�nq���0���&
-d�Ik�e��1/=L2�ȴX�ɾT������`��� �*�GkX.&*E�Cp��ݐ�F�ί����{z˝��ka�ҵ���tm��U��'F��Oe74T��:���*̌��.��^Fg8�T�� ��0�w�.~O��*�;R��|"�=V�
-�ۀ?�+ `H
-Kde�I,��R�BQ寸o略5
+��
+LKpb٪ś�Z:6����/�ܦ?�#7��ä�X꺬��
+w���8�����p9�����$�pb��݆��|!�=��Vt�D�0���QP$FB�,���l�C��G�olW�bs��
+
+��(���!���22R�%�R���@
+:�1`7�[L�aT6谕]��{9�a��`�@U�_�����ݏ���c���$�
+�$P�~2b30˥/Q��&����nt]���I]�qD�2)�A>�I+Mc�|�Ff���.ƗI��ӯ��n�<����m�[�>����;�5��o���<�*o�`���rf��A�;'E�e����G�ZR�"1�@��B����*�/�4���
+���+�
+�I�71�R��i7<��[D0�p��!�<R|�����s�9o�n��þjM��y�p���R�G�[h2�8h�Rg �Tl�R8ƶQs�1��by�$Oɠ��.\�D.l���:�^���NI�}0��]��t�<�0=t�g5�<��}*Z��VZ��=3�/�#��Nd�t���:�N�:�*J����@���,�<v�%���P؆���=����#! �!�c�;���S�+��W��Q�d<�8����7��'gg��x�_-R����
+�����������r~q^:�9�d|1�[��0���Ҁ�NS8��"ռ)��(�A�e�5���>��l�~0�[4�[�n�n��q�-��A�Tz�B�Z�g�
+-^��k��tV�PJ4�(R�J-��c���.2��
+n@.�K�ck��w�Nm�����G���^F>H��} �Ғ��92P��ß,����3'}�U�c[�+HQ�~T �˨.¬� h\���F��&� �<r3��%��1.�|]����s1�T��X��Y%K1���ԗ˵(�^��%�
+�y�7��f�H�R����u�8@��lB�q�*��+�L�8>CAb]9>�0������i�y�X_�!#�s�a�TGP�p�&Op����/��[/�!ض\x��,����Z�v��fʩ|N3Q^��O��
+�s�/��_ُ���%Y�~w�A��l������b�@��wH�o�MB��9��>C��t���-�t�A����s���q2W�f�f)2$z*fp4��i��ma���
+�������W�z}]g}��u���X�7V��K�j�*.u^Wq����U\�*.u���K]ť����Vq���uH��uH��m����u�����~����+�|+�G���iiLQ��^U
+�5�X$
+
+��[qO�0�+
+k
���t;������y�J&"��I �
�,�f�^�Z���x�glS��y
@@ -193,7 +199,6 @@
��E����͛�,���O��6�C�vdz]t�2�0r`&�wשS����'iDi�G��$���1�_�I,"�&��:L�ղ(V�TOV���q
-
-
\ No newline at end of file
+
+
\ No newline at end of file
16 years, 5 months
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
===================================================================
--- 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$
+ }
}
16 years, 5 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/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;
16 years, 5 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 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$
16 years, 5 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: 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>
16 years, 5 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/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
16 years, 5 months