01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.commons.dbcp;
19:
20: import java.sql.Connection;
21: import java.sql.Statement;
22:
23: import javax.sql.DataSource;
24:
25: import junit.framework.Test;
26: import junit.framework.TestCase;
27: import junit.framework.TestSuite;
28:
29: import org.apache.commons.pool.KeyedObjectPoolFactory;
30: import org.apache.commons.pool.ObjectPool;
31: import org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory;
32: import org.apache.commons.pool.impl.GenericObjectPool;
33:
34: /**
35: * TestSuite for BasicDataSource with prepared statement pooling enabled
36: *
37: * @author Dirk Verbeeck
38: * @version $Revision: 479137 $ $Date: 2006-11-25 08:51:48 -0700 (Sat, 25 Nov 2006) $
39: */
40: public class TestPStmtPooling extends TestCase {
41: public TestPStmtPooling(String testName) {
42: super (testName);
43: }
44:
45: public static Test suite() {
46: return new TestSuite(TestPStmtPooling.class);
47: }
48:
49: public void testStmtPool() throws Exception {
50: new TesterDriver();
51: ConnectionFactory connFactory = new DriverManagerConnectionFactory(
52: "jdbc:apache:commons:testdriver", "u1", "p1");
53:
54: ObjectPool connPool = new GenericObjectPool();
55: KeyedObjectPoolFactory stmtPoolFactory = new GenericKeyedObjectPoolFactory(
56: null);
57:
58: PoolableConnectionFactory x = new PoolableConnectionFactory(
59: connFactory, connPool, stmtPoolFactory, null, false,
60: true);
61:
62: DataSource ds = new PoolingDataSource(connPool);
63:
64: Connection conn = ds.getConnection();
65: Statement stmt1 = conn.prepareStatement("select 1 from dual");
66: Statement ustmt1 = ((DelegatingStatement) stmt1)
67: .getInnermostDelegate();
68: stmt1.close();
69: Statement stmt2 = conn.prepareStatement("select 1 from dual");
70: Statement ustmt2 = ((DelegatingStatement) stmt2)
71: .getInnermostDelegate();
72: stmt2.close();
73: assertSame(ustmt1, ustmt2);
74: }
75: }
|