1 21 22 package org.opensubsystems.core.persist.db.connectionpool; 23 24 import java.sql.Connection ; 25 import java.sql.SQLException ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 29 import junit.extensions.TestSetup; 30 import junit.framework.Test; 31 import junit.framework.TestSuite; 32 33 import org.opensubsystems.core.error.OSSInternalErrorException; 34 import org.opensubsystems.core.persist.db.DatabaseTestSetup; 35 import org.opensubsystems.core.persist.db.DatabaseTestSuite; 36 37 import com.mchange.v2.c3p0.C3P0ProxyConnection; 38 import com.mchange.v2.c3p0.util.TestUtils; 39 40 48 public final class C3P0DatabaseConnectionFactoryTest 49 { 50 52 55 private C3P0DatabaseConnectionFactoryTest( 56 ) 57 { 58 } 60 61 63 69 public static Test suite( 70 ) 71 { 72 TestSuite suite = new DatabaseTestSuite("C3P0DatabaseConnectionFactoryTest"); 73 suite.addTestSuite(C3P0DatabaseConnectionFactoryTestInternal.class); 74 TestSetup wrapper = new DatabaseTestSetup(suite); 75 76 return wrapper; 77 } 78 79 84 public static class C3P0DatabaseConnectionFactoryTestInternal 85 extends PooledDatabaseConnectionFactoryImplBaseTest 86 { 87 92 public C3P0DatabaseConnectionFactoryTestInternal( 93 String strTestName 94 ) 95 { 96 super(strTestName); 97 } 98 99 102 protected void setUp( 103 ) throws Exception 104 { 105 m_connectionFactory = new C3P0DatabaseConnectionFactoryImpl(); 107 108 super.setUp(); 109 } 110 111 114 protected Object addItem( 115 Connection newConnection 116 ) throws OSSInternalErrorException 117 { 118 try 119 { 120 return new Integer (TestUtils.physicalConnectionIdentityHashCode( 121 (C3P0ProxyConnection) newConnection)); 122 } 123 catch (SQLException sqlExc) 124 { 125 throw new OSSInternalErrorException("Error occured during getting of physical " + 126 "connection identity hash code.", sqlExc); 127 } 128 } 129 130 133 protected boolean containsConnection( 134 List lstConnections, 135 Connection newConnection 136 ) throws OSSInternalErrorException 137 { 138 Integer iHashCodeFromList = null; 139 Iterator itHelp; 140 boolean bReturn = false; 141 142 itHelp = lstConnections.iterator(); 145 while (itHelp.hasNext()) 146 { 147 148 iHashCodeFromList = (Integer ) itHelp.next(); 149 try 150 { 151 bReturn = bReturn || iHashCodeFromList.intValue() 152 == TestUtils.physicalConnectionIdentityHashCode( 153 (C3P0ProxyConnection) newConnection); 154 } 155 catch (SQLException sqlExc) 156 { 157 throw new OSSInternalErrorException("Error occured during getting of physical " + 158 "connection identity hash code.", sqlExc); 159 } 160 } 161 162 return bReturn; 163 } 164 } 165 } 166 | Popular Tags |