Author: shawkins
Date: 2010-02-01 13:02:43 -0500 (Mon, 01 Feb 2010)
New Revision: 1794
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java
Log:
TEIID-880 fix for NPE getting the metadataobject
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerSQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerSQLTranslator.java 2010-01-30
20:24:58 UTC (rev 1793)
+++
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/sqlserver/SqlServerSQLTranslator.java 2010-02-01
18:02:43 UTC (rev 1794)
@@ -65,7 +65,7 @@
if (obj instanceof IElement) {
IElement elem = (IElement)obj;
try {
- if (TypeFacility.RUNTIME_TYPES.STRING.equals(elem.getType()) &&
"uniqueidentifier".equalsIgnoreCase(elem.getMetadataObject().getNativeType())) {
//$NON-NLS-1$
+ if (TypeFacility.RUNTIME_TYPES.STRING.equals(elem.getType()) &&
elem.getMetadataObject() != null &&
"uniqueidentifier".equalsIgnoreCase(elem.getMetadataObject().getNativeType())) {
//$NON-NLS-1$
return Arrays.asList("cast(", elem, " as char(36))");
//$NON-NLS-1$ //$NON-NLS-2$
}
} catch (ConnectorException e) {
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java 2010-01-30
20:24:58 UTC (rev 1793)
+++
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java 2010-02-01
18:02:43 UTC (rev 1794)
@@ -216,7 +216,7 @@
} else if (obj instanceof IElement) {
IElement elem = (IElement)obj;
try {
- if (trimChar && elem.getType() == TypeFacility.RUNTIME_TYPES.STRING
+ if (trimChar && elem.getType() == TypeFacility.RUNTIME_TYPES.STRING
&& elem.getMetadataObject() != null
&&
("char".equalsIgnoreCase(elem.getMetadataObject().getNativeType()) ||
"nchar".equalsIgnoreCase(elem.getMetadataObject().getNativeType()))) {
//$NON-NLS-1$ //$NON-NLS-2$
return
Arrays.asList(getLanguageFactory().createFunction(SourceSystemFunctions.RTRIM, new
IExpression[] {elem}, TypeFacility.RUNTIME_TYPES.STRING));
}
Modified:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2010-01-30
20:24:58 UTC (rev 1793)
+++
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2010-02-01
18:02:43 UTC (rev 1794)
@@ -158,6 +158,9 @@
TranslationUtility tu = new TranslationUtility(metadata);
ICommand command = tu.parseCommand("select max(x) from bar");
//$NON-NLS-1$
TranslationHelper.helpTestVisitor("SELECT MAX(cast(bar.x as char(36))) FROM
bar", trans, command); //$NON-NLS-1$
+
+ command = tu.parseCommand("select * from (select max(x) from bar) x");
//$NON-NLS-1$
+ TranslationHelper.helpTestVisitor("SELECT x.MAX FROM (SELECT MAX(cast(bar.x
as char(36))) FROM bar) x", trans, command); //$NON-NLS-1$
}
}