teiid SVN: r3296 - in branches/7.4.x/client/src: test/java/org/teiid/jdbc and 1 other directory.
by teiid-commits@lists.jboss.org
Author: van.halbert
Date: 2011-07-01 15:17:03 -0400 (Fri, 01 Jul 2011)
New Revision: 3296
Modified:
branches/7.4.x/client/src/main/java/org/teiid/jdbc/BaseDataSource.java
branches/7.4.x/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java
branches/7.4.x/client/src/main/java/org/teiid/jdbc/ExecutionProperties.java
branches/7.4.x/client/src/main/java/org/teiid/jdbc/PreparedStatementImpl.java
branches/7.4.x/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java
branches/7.4.x/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java
branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java
branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java
branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestStatement.java
branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestTeiidDataSource.java
branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java
Log:
Added backward compatibility support so that pre JDBC 4, when using an 'Alias', it will still be returned via the ResultSetMetadata.getColumnName. In JDBC 4, you will need to call ResultSetMetadata.getColumnLabel. To enable backward support, add the property: useJDBC4ColumnNameAndLabelSemantics=false to the url connection string.
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/BaseDataSource.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/BaseDataSource.java 2011-06-29 18:45:44 UTC (rev 3295)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/BaseDataSource.java 2011-07-01 19:17:03 UTC (rev 3296)
@@ -147,6 +147,8 @@
private int queryTimeout;
+ private boolean useJDBC4ColumnNameAndLabelSemantics = true;
+
/**
* Reference to the logWriter, which is transient and is therefore not serialized with the DataSource.
*/
@@ -247,6 +249,10 @@
props.setProperty(ExecutionProperties.DISABLE_LOCAL_TRANSACTIONS, this.getDisableLocalTxn());
}
+ if (!this.getUseJDBC4ColumnNameAndLabelSemantics()) {
+ props.setProperty(ExecutionProperties.JDBC4COLUMNNAMEANDLABELSEMANTICS, "false");
+ }
+
if (this.additionalProperties != null) {
JDBCURL.parseConnectionProperties(this.additionalProperties, props);
}
@@ -652,7 +658,16 @@
public void setAutoCommitTxn(String transactionAutoWrap) {
this.transactionAutoWrap = transactionAutoWrap;
}
+
+
+ public boolean getUseJDBC4ColumnNameAndLabelSemantics() {
+ return useJDBC4ColumnNameAndLabelSemantics;
+ }
+ public void setUseJDBC4ColumnNameAndLabelSemantics(boolean useJDBC4ColumnNameAndLabelSemantics) {
+ this.useJDBC4ColumnNameAndLabelSemantics = useJDBC4ColumnNameAndLabelSemantics;
+ }
+
// --------------------------------------------------------------------------------------------
// V A L I D A T I O N M E T H O D S
// --------------------------------------------------------------------------------------------
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java 2011-06-29 18:45:44 UTC (rev 3295)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java 2011-07-01 19:17:03 UTC (rev 3296)
@@ -1586,7 +1586,7 @@
metadataList[16] = StatementImpl.getColumnMetadata(CoreConstants.SYSTEM_MODEL + "." + DATA_TYPES, JDBCColumnNames.TYPE_INFO.SQL_DATETIME_SUB, JDBCSQLTypeInfo.INTEGER, ResultsMetadataConstants.NULL_TYPES.NULLABLE, ResultsMetadataConstants.SEARCH_TYPES.SEARCHABLE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE, driverConnection);//$NON-NLS-1$
metadataList[17] = StatementImpl.getColumnMetadata(CoreConstants.SYSTEM_MODEL + "." + DATA_TYPES, JDBCColumnNames.TYPE_INFO.NUM_PREC_RADIX, JDBCSQLTypeInfo.INTEGER, ResultsMetadataConstants.NULL_TYPES.NULLABLE, ResultsMetadataConstants.SEARCH_TYPES.SEARCHABLE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, driverConnection);//$NON-NLS-1$
- ResultSetMetaData rmetadata = new ResultSetMetaDataImpl(new MetadataProvider(metadataList));
+ ResultSetMetaData rmetadata = new ResultSetMetaDataImpl(new MetadataProvider(metadataList), null);
logger.fine(JDBCPlugin.Util.getString("MMDatabaseMetadata.getTypes_success")); //$NON-NLS-1$
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/ExecutionProperties.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/ExecutionProperties.java 2011-06-29 18:45:44 UTC (rev 3295)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/ExecutionProperties.java 2011-07-01 19:17:03 UTC (rev 3296)
@@ -104,5 +104,19 @@
public static final String QUERYTIMEOUT = "QUERYTIMEOUT"; //$NON-NLS-1$
+ /**
+ * TEIID-1651
+ * A change was made in JDBC4 so that when an 'Alias' is used it will
+ * now be returned as the label. Prior to this, it was returned as
+ * the name. Setting this property to <code>false</code> will enable
+ * backwards compatibility when JDBC3 and older support is still required.
+ *
+ * Default is <code>true</code>
+ * @since 7.4.1
+ */
+
+ public static final String JDBC4COLUMNNAMEANDLABELSEMANTICS = "useJDBC4ColumnNameAndLabelSemantics"; //$NON-NLS-1$
+
+
}
\ No newline at end of file
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/PreparedStatementImpl.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/PreparedStatementImpl.java 2011-06-29 18:45:44 UTC (rev 3295)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/PreparedStatementImpl.java 2011-07-01 19:17:03 UTC (rev 3296)
@@ -259,7 +259,7 @@
return null;
}
MetadataProvider provider = new MetadataProvider(getMetadataResults().getColumnMetadata());
- metadata = new ResultSetMetaDataImpl(provider);
+ metadata = new ResultSetMetaDataImpl(provider, this.getExecutionProperty(ExecutionProperties.JDBC4COLUMNNAMEANDLABELSEMANTICS));
}
}
@@ -653,7 +653,7 @@
public ParameterMetaData getParameterMetaData() throws SQLException {
if (parameterMetaData == null) {
//TODO: some of the base implementation of ResultSetMetadata could be on the MetadataProvider
- this.parameterMetaData = new ParameterMetaDataImpl(new ResultSetMetaDataImpl(new MetadataProvider(getMetadataResults().getParameterMetadata())));
+ this.parameterMetaData = new ParameterMetaDataImpl(new ResultSetMetaDataImpl(new MetadataProvider(getMetadataResults().getParameterMetadata()), this.getExecutionProperty(ExecutionProperties.JDBC4COLUMNNAMEANDLABELSEMANTICS)));
}
return parameterMetaData;
}
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java 2011-06-29 18:45:44 UTC (rev 3295)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java 2011-07-01 19:17:03 UTC (rev 3296)
@@ -133,12 +133,11 @@
this.batchResults = new BatchResults(this, getCurrentBatch(resultsMsg), this.cursorType == ResultSet.TYPE_FORWARD_ONLY ? 1 : BatchResults.DEFAULT_SAVED_BATCHES);
accumulateWarnings(resultsMsg);
this.serverTimeZone = statement.getServerTimeZone();
-
if (metadata == null) {
MetadataProvider provider = new DeferredMetadataProvider(resultsMsg.getColumnNames(),
resultsMsg.getDataTypes(), statement,
statement.getCurrentRequestID());
- rmetadata = new ResultSetMetaDataImpl(provider);
+ rmetadata = new ResultSetMetaDataImpl(provider, this.statement.getExecutionProperty(ExecutionProperties.JDBC4COLUMNNAMEANDLABELSEMANTICS));
} else {
rmetadata = metadata;
}
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java 2011-06-29 18:45:44 UTC (rev 3295)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java 2011-07-01 19:17:03 UTC (rev 3296)
@@ -34,10 +34,13 @@
public class ResultSetMetaDataImpl extends WrapperImpl implements ResultSetMetaData {
private MetadataProvider provider;
+
+ private boolean useJDBC4ColumnNameAndLabelSemantics = false;
- public ResultSetMetaDataImpl(MetadataProvider provider) {
+ public ResultSetMetaDataImpl(MetadataProvider provider, String supportBackwardsCompatibility) {
this.provider = provider;
- }
+ this.useJDBC4ColumnNameAndLabelSemantics = (supportBackwardsCompatibility != null && supportBackwardsCompatibility.equalsIgnoreCase("false") ? false : true);
+ }
/**
* Adjust from 1-based to internal 0-based representation
@@ -105,6 +108,13 @@
}
public String getColumnName(int index) throws SQLException {
+
+ if (!useJDBC4ColumnNameAndLabelSemantics) {
+ String result = provider.getStringValue(adjustColumn(index), ResultsMetadataConstants.ELEMENT_LABEL);
+ if (result != null) {
+ return result;
+ }
+ }
return provider.getStringValue(adjustColumn(index), ResultsMetadataConstants.ELEMENT_NAME);
}
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java 2011-06-29 18:45:44 UTC (rev 3295)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java 2011-07-01 19:17:03 UTC (rev 3296)
@@ -1158,7 +1158,7 @@
}
ResultSetImpl createResultSet(List records, Map[] columnMetadata) throws SQLException {
- ResultSetMetaData rsmd = new ResultSetMetaDataImpl(new MetadataProvider(columnMetadata));
+ ResultSetMetaData rsmd = new ResultSetMetaDataImpl(new MetadataProvider(columnMetadata), this.getExecutionProperty(ExecutionProperties.JDBC4COLUMNNAMEANDLABELSEMANTICS));
return createResultSet(records, rsmd);
}
Modified: branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java
===================================================================
--- branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java 2011-06-29 18:45:44 UTC (rev 3295)
+++ branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java 2011-07-01 19:17:03 UTC (rev 3296)
@@ -733,7 +733,7 @@
}
ResultsMessage msg = exampleResultsMsg4(1, batchLength, fetchSize, batchLength == totalLength);
- return new ResultSetImpl(msg, statement, new ResultSetMetaDataImpl(new MetadataProvider(DeferredMetadataProvider.loadPartialMetadata(msg.getColumnNames(), msg.getDataTypes()))), 0);
+ return new ResultSetImpl(msg, statement, new ResultSetMetaDataImpl(new MetadataProvider(DeferredMetadataProvider.loadPartialMetadata(msg.getColumnNames(), msg.getDataTypes())), null), 0);
}
// /////////////////////Helper Method///////////////////
Modified: branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestStatement.java
===================================================================
--- branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestStatement.java 2011-06-29 18:45:44 UTC (rev 3295)
+++ branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestStatement.java 2011-07-01 19:17:03 UTC (rev 3296)
@@ -145,4 +145,15 @@
assertEquals(2, statement.getQueryTimeout());
}
+ @Test public void testUseJDBC4ColumnNameAndLabelSemantics() throws Exception {
+ ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
+ Properties p = new Properties();
+ p.setProperty(ExecutionProperties.JDBC4COLUMNNAMEANDLABELSEMANTICS, "false");
+
+ Mockito.stub(conn.getExecutionProperties()).toReturn(p);
+ StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
+ assertEquals(Boolean.FALSE.toString(), statement.getExecutionProperty(ExecutionProperties.JDBC4COLUMNNAMEANDLABELSEMANTICS));
+
+ }
+
}
Modified: branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestTeiidDataSource.java
===================================================================
--- branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestTeiidDataSource.java 2011-06-29 18:45:44 UTC (rev 3295)
+++ branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestTeiidDataSource.java 2011-07-01 19:17:03 UTC (rev 3296)
@@ -75,6 +75,7 @@
dataSource.setPartialResultsMode(STD_PARTIAL_MODE);
dataSource.setSecure(true);
dataSource.setAlternateServers(STD_ALTERNATE_SERVERS);
+ dataSource.setUseJDBC4ColumnNameAndLabelSemantics(true);
}
// =========================================================================
@@ -141,6 +142,19 @@
final int fetchSize, final boolean showPlan,
final boolean secure, final String expectedURL) {
+
+ helpTestBuildingURL2(vdbName, vdbVersion, serverName, portNumber, alternateServers,
+ txnAutoWrap, partialMode, fetchSize, showPlan, secure, true, expectedURL);
+ }
+
+ public void helpTestBuildingURL2( final String vdbName, final String vdbVersion,
+ final String serverName, final int portNumber,
+ final String alternateServers,
+ final String txnAutoWrap, final String partialMode,
+ final int fetchSize, final boolean showPlan,
+ final boolean secure, final boolean useJDBC4Semantics,
+ final String expectedURL ) {
+
final TeiidDataSource ds = new TeiidDataSource();
ds.setServerName(serverName);
ds.setDatabaseVersion(vdbVersion);
@@ -154,6 +168,7 @@
}
ds.setSecure(secure);
ds.setAlternateServers(alternateServers);
+ ds.setUseJDBC4ColumnNameAndLabelSemantics(useJDBC4Semantics);
String url;
try {
@@ -184,6 +199,7 @@
ds.setTransactionAutoWrap(txnAutoWrap);
ds.setPartialResultsMode(partialMode);
ds.setAlternateServers(alternateServers);
+ ds.setUseJDBC4ColumnNameAndLabelSemantics(true);
return ds.getConnection();
@@ -627,6 +643,21 @@
"jdbc:teiid:vdbName@mm://hostName:7001,hostName:7002,hostName2:7001,hostName2:7002;ApplicationName=JDBC;SHOWPLAN=ON;partialResultsMode=false;autoCommitTxn=DETECT;VirtualDatabaseName=vdbName"); //$NON-NLS-1$
}
+ /**
+ * Test turning off using JDBC4 semantics
+ */
+ public void testBuildURL8() {
+ final String serverName = "hostName"; //$NON-NLS-1$
+ final String vdbName = "vdbName"; //$NON-NLS-1$
+ final String vdbVersion = "1.2.3"; //$NON-NLS-1$
+ final int portNumber = 7001;
+ final String transactionAutoWrap = null;
+ final String partialMode = "true"; //$NON-NLS-1$
+ final boolean secure = false;
+ helpTestBuildingURL2(vdbName,vdbVersion,serverName,portNumber,null,transactionAutoWrap, partialMode, 500, false, secure, false,
+ "jdbc:teiid:vdbName@mm://hostname:7001;fetchSize=500;ApplicationName=JDBC;VirtualDatabaseVersion=1.2.3;partialResultsMode=true;useJDBC4ColumnNameAndLabelSemantics=false;VirtualDatabaseName=vdbName"); //$NON-NLS-1$
+ }
+
public void testBuildURL_AdditionalProperties() throws TeiidSQLException {
final TeiidDataSource ds = new TeiidDataSource();
ds.setAdditionalProperties("foo=bar;a=b"); //$NON-NLS-1$
Modified: branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java
===================================================================
--- branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java 2011-06-29 18:45:44 UTC (rev 3295)
+++ branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java 2011-07-01 19:17:03 UTC (rev 3296)
@@ -89,7 +89,10 @@
assertTrue(!drv.acceptsURL("jdbc:teiid:@localhost:1234;logLevel=2;logFile=D:\\metamatrix\\work\\DQP\\log\\jdbcLogFile.log")); //$NON-NLS-1$
assertTrue(!drv.acceptsURL("jdbc:teiid:@localhost:1234;logLevel=2;logFile=D:\\metamatrix\\work\\DQP\\log\\jdbcLogFile.log;autoCommitTxn=OFF;paritalResultsMode=true")); //$NON-NLS-1$
assertTrue(!drv.acceptsURL("jdbc:teiid:@localhost:1234;stickyConnections=false;socketsPerVM=4")); //$NON-NLS-1$
- assertTrue(drv.acceptsURL("jdbc:teiid:vdb@mm://my_host.mydomain.com:53535,127.0.0.1:1234")); //$NON-NLS-1$
+ assertTrue(drv.acceptsURL("jdbc:teiid:vdb@mm://my_host.mydomain.com:53535,127.0.0.1:1234")); //$NON-NLS-1$
+
+ assertTrue(drv.acceptsURL("jdbc:teiid:vdb@mm://localhost:1234;version=x;useJDBC4ColumnNameAndLabelSemantics=false")); //$NON-NLS-1$
+
}
/** Invalid format of urls*/
13 years, 5 months