/*
 *   Copyright (c) 2007 Mike Heath.  All rights reserved.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */
package org.safehaus.adbcj.mysql;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Properties;
import java.util.concurrent.ExecutorService;

import org.safehaus.adbcj.ConnectionManager;
import org.safehaus.adbcj.ConnectionManagerFactory;
import org.safehaus.adbcj.ConnectionManagerProvider;
import org.safehaus.adbcj.DbException;

public class MysqlConnectionManagerFactory implements ConnectionManagerFactory {

	public static final String PROTOCOL = "mysql";
	public static final int DEFAULT_PORT = 3306;
	
	static void register() {
		ConnectionManagerProvider.registerConnectionManagerFactory(PROTOCOL, new MysqlConnectionManagerFactory());
	}
	
	
	private MysqlConnectionManagerFactory() {
	}
	
	public ConnectionManager createConnectionManager(String url, String username, String password, ExecutorService executorService, Properties properties) throws DbException {
		String host;
		int port;
		String database;
		/*
		 * Parse URL
		 */
		try {
			URI uri = new URI(url);
			// Throw away the 'adbcj' protocol part of the URL
			uri = new URI(uri.getSchemeSpecificPart());

			host = uri.getHost();
			port = uri.getPort();
			if (port < 0) {
				port = DEFAULT_PORT;
			}
			database = uri.getPath().substring(1);
		} catch (URISyntaxException e) {
			throw new DbException(e);
		}
		
		return new MysqlConnectionManager(host, port, username, password, database, executorService, properties);
	}

}

@@ -1541,57 +1541,21 @@
 %7B%0A%09%09
-S
 tr
-ing host;%0A%09%09int port;%0A%09%09String database;%0A
+y %7B%0A%09
 %09%09/*%0A
+%09
 %09%09 *
@@ -1571,20 +1571,13 @@
 L%0A%09%09
+%09
  */%0A
-%09%09try %7B%0A
 %09%09%09U
@@ -1704,16 +1704,23 @@
 ));%0A%0A%09%09%09
+String 
 host = u
@@ -1736,16 +1736,20 @@
 t();%0A%09%09%09
+int 
 port = u
@@ -1814,24 +1814,29 @@
 %09%09%09%7D%0A%09%09%09
-database
+String schema
  = uri.g
@@ -1862,79 +1862,10 @@
 1);%0A
-%09%09%7D catch (URISyntaxException e) %7B%0A%09%09%09throw new DbException(e);%0A%09%09%7D%0A%09%09
 %0A
+%09
 %09%09re
@@ -1932,16 +1932,14 @@
 rd, 
-database
+schema
 , ex
@@ -1966,14 +1966,82 @@
 rties);%0A
+%09%09%7D catch (URISyntaxException e) %7B%0A%09%09%09throw new DbException(e);%0A%09%09%7D%0A
 %09%7D%0A%0A%7D%0A

Cleaned up the connection logic.