package com.exedio.cope.lib;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionPool
{
	private static ConnectionPool theInstance = null;

	static final ConnectionPool getInstance()
	{
		if (theInstance == null)
			theInstance = new ConnectionPool();

		return theInstance;
	}

	final Connection getConnection() throws SQLException
	{
		final Properties properties = Properties.getInstance();
		final String driver = properties.getDriver();
		final String url = properties.getUrl();
		final String user = properties.getUser();
		final String password = properties.getPassword();

		try
		{
			Class.forName(driver);
		}
		catch (ClassNotFoundException e)
		{
			throw new SystemException(e);
		}

		return DriverManager.getConnection(url, user, password);
	}

	final void putConnection(final Connection connection) throws SQLException
	{
		connection.close();
	}

}

@@ -1,8 +1,9 @@
+%0A
 package 
@@ -338,30 +338,394 @@
 %0A%09%7D%0A
-%0A%09final Connection get
+%09%0A%09private Connection%5B%5D pool = new Connection%5B10%5D;%0A%09private int size = 0;%0A%09private Object lock = new Object();%0A%0A%09final Connection getConnection() throws SQLException%0A%09%7B%0A%09%09synchronized(lock)%0A%09%09%7B%0A%09%09%09if(size%3E0)%0A%09%09%09%7B%0A%09%09%09%09//System.out.println(%22connection pool: fetch %22+(size-1));%0A%09%09%09%09return pool%5B--size%5D;%0A%09%09%09%7D%0A%09%09%09else%0A%09%09%09%7B%0A%09%09%09%09return createConnection();%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09final Connection create
 Conn
@@ -1118,16 +1118,67 @@
 );%0A%09%09%7D%0A%0A
+%09%09//System.out.println(%22connection pool: CREATE%22);%0A
 %09%09return
@@ -1310,16 +1310,293 @@
 tion%0A%09%7B%0A
+%09%09synchronized(lock)%0A%09%09%7B%0A%09%09%09if(size%3Cpool.length)%0A%09%09%09%7B%0A%09%09%09%09//System.out.println(%22connection pool: store %22+size);%0A%09%09%09%09pool%5Bsize++%5D = connection;%0A%09%09%09%09return;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09//System.out.println(%22connection pool: CLOSE %22);%0A%0A%09%09// Important to do this outside the synchronized block!%0A
 %09%09connec

introduce real connection pool