Author: jolee
Date: 2012-10-31 17:31:09 -0400 (Wed, 31 Oct 2012)
New Revision: 4525
Modified:
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java
branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java
Log:
TEIID-669: Support "pass though" SQL commands to sources - fix
Modified:
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java
===================================================================
---
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java 2012-10-31
21:06:10 UTC (rev 4524)
+++
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java 2012-10-31
21:31:09 UTC (rev 4525)
@@ -414,6 +414,9 @@
if (obj.getMetadataObject() != null) {
String nativeQuery = obj.getMetadataObject().getProperty(TEIID_NATIVE_QUERY, false);
if (nativeQuery != null) {
+ if (obj.getCorrelationName() == null) {
+ throw new IllegalArgumentException("alias needed. When native query is being
used, then alias name must be defined for table in the query.");
+ }
buffer.append(Tokens.LPAREN).append(nativeQuery).append(Tokens.RPAREN);
if (obj.getCorrelationName() == null) {
buffer.append(Tokens.SPACE);
@@ -421,6 +424,7 @@
buffer.append(AS).append(Tokens.SPACE);
}
}
+ return;
}
}
super.appendBaseName(obj);
Modified:
branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java
===================================================================
---
branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java 2012-10-31
21:06:10 UTC (rev 4524)
+++
branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java 2012-10-31
21:31:09 UTC (rev 4525)
@@ -896,7 +896,7 @@
Mockito.verify(cs, Mockito.times(1)).getObject(1);
}
- @Test public void testNativeQuery() throws Exception {
+ @Test (expected=IllegalArgumentException.class)public void
testNativeQueryWithNoCorrelationName() throws Exception {
String input = "SELECT (DoubleNum * 1.0) FROM x"; //$NON-NLS-1$
String output = "SELECT (x.DoubleNum * 1.0) FROM (select c from d) x";
//$NON-NLS-1$
@@ -905,6 +905,14 @@
helpTestVisitor(metadata, input, EMPTY_CONTEXT, null, output);
}
+ @Test public void testNativeQuery() throws Exception {
+ String input = "SELECT (DoubleNum * 1.0) FROM x as y"; //$NON-NLS-1$
+ String output = "SELECT (y.DoubleNum * 1.0) FROM (select c from d) y";
//$NON-NLS-1$
+
+ QueryMetadataInterface metadata = getOracleSpecificMetadata();
+ helpTestVisitor(metadata, input, EMPTY_CONTEXT, null, output);
+ }
+
@Test public void testNativeQueryProc() throws Exception {
String input = "call proc(2)"; //$NON-NLS-1$
String output = "select x from y where z = ?"; //$NON-NLS-1$
Show replies by date