Author: rareddy
Date: 2009-04-22 14:21:28 -0400 (Wed, 22 Apr 2009)
New Revision: 825
Modified:
branches/6.0.x/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java
branches/6.0.x/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCConnector.java
Log:
TEIID-505: pulling changes from trunk for consistency for the branch
Modified:
branches/6.0.x/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java
===================================================================
---
branches/6.0.x/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java 2009-04-22
17:54:23 UTC (rev 824)
+++
branches/6.0.x/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java 2009-04-22
18:21:28 UTC (rev 825)
@@ -254,13 +254,13 @@
}
final String url = connectionProps.getProperty(JDBCPropertyNames.URL);
- if (url == null || url.trim().length() == 0) {
- throw new
ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.Missing_JDBC_database_name_3"));
//$NON-NLS-1$
- }
if (temp instanceof Driver) {
final Driver driver = (Driver)temp;
// check URL if there is one
+ if (url == null || url.trim().length() == 0) {
+ throw new
ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.Missing_JDBC_database_name_3"));
//$NON-NLS-1$
+ }
validateURL(driver, url);
this.ds =
(DataSource)Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new
Class[] {DataSource.class}, new InvocationHandler() {
@Override
@@ -289,7 +289,6 @@
}
});
} else {
- parseURL(url, connectionProps);
if (temp instanceof DataSource) {
this.ds = (DataSource)temp;
PropertiesUtils.setBeanProperties(this.ds, connectionProps, null);
@@ -325,57 +324,6 @@
}
}
- /**
- * Parse URL for DataSource connection properties and add to connectionProps.
- * @param url
- * @param connectionProps
- * @throws ConnectorException
- */
- static void parseURL(final String url, final Properties connectionProps) throws
ConnectorException {
- // Will be: [jdbc:mmx:dbType://aHost:aPort], [DatabaseName=aDataBase],
[CollectionID=aCollectionID], ...
- final String[] urlParts = url.split(";"); //$NON-NLS-1$
-
- // Will be: [jdbc:mmx:dbType:], [aHost:aPort]
- final String[] protoHost = urlParts[0].split("//"); //$NON-NLS-1$
-
- // Will be: [aHost], [aPort]
- final String[] hostPort = protoHost[1].split(":"); //$NON-NLS-1$
- connectionProps.setProperty(XAJDBCPropertyNames.SERVER_NAME, hostPort[0]);
- connectionProps.setProperty(XAJDBCPropertyNames.PORT_NUMBER, hostPort[1]);
-
- // For "databaseName", "SID", and all optional props
- //
(<propName1>=<propValue1>;<propName2>=<propValue2>;...)
- for ( int i = 1; i < urlParts.length; i++ ) {
- final String nameVal = urlParts[i];
- // Will be: [propName], [propVal]
- final String[] aProp = nameVal.split("="); //$NON-NLS-1$
- if ( aProp.length > 1) {
- // Set optional prop names lower case so that we can find
- // set method names for them when we introspect the DataSource
- connectionProps.setProperty(aProp[0].toLowerCase(), aProp[1]);
- }
- }
-
- String serverName =
connectionProps.getProperty(XAJDBCPropertyNames.SERVER_NAME);
- String serverPort =
connectionProps.getProperty(XAJDBCPropertyNames.PORT_NUMBER);
- if ( serverName == null || serverName.trim().length() == 0 ) {
- throw new
ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.MissingProp",
//$NON-NLS-1$
- XAJDBCPropertyNames.SERVER_NAME));
- }
- if ( serverPort == null || serverPort.trim().length() == 0 ) {
- throw new
ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.MissingProp",
//$NON-NLS-1$
- XAJDBCPropertyNames.PORT_NUMBER));
- }
-
- // Unique resource name for this connector
- final StringBuffer dataSourceResourceName = new
StringBuffer(connectionProps.getProperty(XAJDBCPropertyNames.DATASOURCE_NAME,
"XADS")); //$NON-NLS-1$
- dataSourceResourceName.append('_');
- dataSourceResourceName.append(serverName);
- dataSourceResourceName.append('_');
-
dataSourceResourceName.append(connectionProps.getProperty(ConnectorPropertyNames.CONNECTOR_ID));
- connectionProps.setProperty( XAJDBCPropertyNames.DATASOURCE_NAME,
dataSourceResourceName.toString());
- }
-
public int getDefaultTransactionIsolationLevel() {
return this.transIsoLevel;
}
Modified:
branches/6.0.x/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCConnector.java
===================================================================
---
branches/6.0.x/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCConnector.java 2009-04-22
17:54:23 UTC (rev 824)
+++
branches/6.0.x/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCConnector.java 2009-04-22
18:21:28 UTC (rev 825)
@@ -60,18 +60,4 @@
public void test3() throws Exception {
helpTestMaxIn(1, 1);
}
-
- @Test
- public void testParseUrl() throws ConnectorException {
- String urlWithEmptyProp =
"jdbc:mmx:db2://aHost:aPort;DatabaseName=DB2_DataBase;CollectionID=aCollectionID;PackageName=aPackageName;BogusProp=aBogusProp;UnEmptyProp=;";
//$NON-NLS-1$
- Properties props = new Properties();
- JDBCConnector.parseURL(urlWithEmptyProp, props);
-
- assertEquals("aPort", props.getProperty(XAJDBCPropertyNames.PORT_NUMBER));
//$NON-NLS-1$
- assertEquals("aHost", props.getProperty(XAJDBCPropertyNames.SERVER_NAME));
//$NON-NLS-1$
- assertEquals("XADS_aHost_null",
props.getProperty(XAJDBCPropertyNames.DATASOURCE_NAME)); //$NON-NLS-1$
- assertEquals("aBogusProp", props.getProperty("bogusprop"));
//$NON-NLS-1$ //$NON-NLS-2$
- assertNull(props.getProperty("unemptyprop")); //$NON-NLS-1$
- }
-
}
Show replies by date