File: JndiRefConnectionPoolDataSource.java

package info (click to toggle)
c3p0 0.9.1.2-9+deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,152 kB
  • sloc: java: 29,115; xml: 791; makefile: 14; sh: 11
file content (317 lines) | stat: -rw-r--r-- 11,133 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/*
 * Distributed as part of c3p0 v.0.9.1.2
 *
 * Copyright (C) 2005 Machinery For Change, Inc.
 *
 * Author: Steve Waldman <swaldman@mchange.com>
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 2.1, as 
 * published by the Free Software Foundation.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this software; see the file LICENSE.  If not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 */


package com.mchange.v2.c3p0;

import com.mchange.v2.c3p0.impl.*;

import java.beans.PropertyVetoException;
import java.io.PrintWriter;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Hashtable;
import javax.naming.NamingException;
import javax.naming.Reference;
import javax.naming.Referenceable;
import javax.sql.ConnectionPoolDataSource;
import javax.sql.PooledConnection;
import com.mchange.v2.beans.BeansUtils;
import com.mchange.v2.log.MLevel;
import com.mchange.v2.log.MLog;
import com.mchange.v2.log.MLogger;
import com.mchange.v2.naming.JavaBeanReferenceMaker;
import com.mchange.v2.naming.JavaBeanObjectFactory;
import com.mchange.v2.naming.ReferenceMaker;

public final class JndiRefConnectionPoolDataSource extends IdentityTokenResolvable implements ConnectionPoolDataSource, Serializable, Referenceable
{
    final static MLogger logger = MLog.getLogger( JndiRefConnectionPoolDataSource.class );

    final static Collection IGNORE_PROPS = Arrays.asList( new String[] {"reference", "pooledConnection"} );

    JndiRefForwardingDataSource     jrfds;
    WrapperConnectionPoolDataSource wcpds;

    String identityToken;

    public JndiRefConnectionPoolDataSource()
    { this( true ); }

    public JndiRefConnectionPoolDataSource( boolean autoregister )
    {
	jrfds = new JndiRefForwardingDataSource();
	wcpds = new WrapperConnectionPoolDataSource();
	wcpds.setNestedDataSource( jrfds );

	if (autoregister)
	    {
		this.identityToken = C3P0ImplUtils.allocateIdentityToken( this );
		C3P0Registry.reregister( this );
	    }
    }

    public boolean isJndiLookupCaching()
    { return jrfds.isCaching();  }
    
    public void setJndiLookupCaching( boolean caching )
    { jrfds.setCaching( caching ); }
    
    public Hashtable getJndiEnv()
    { return jrfds.getJndiEnv(); }
    
    public void setJndiEnv( Hashtable jndiEnv )
    { jrfds.setJndiEnv( jndiEnv ); }
    
    public Object getJndiName()
    { return jrfds.getJndiName(); }
    
    public void setJndiName( Object jndiName ) throws PropertyVetoException
    { jrfds.setJndiName( jndiName ); }

    public int getAcquireIncrement()
    { return wcpds.getAcquireIncrement(); }
	
    public void setAcquireIncrement( int acquireIncrement )
    { wcpds.setAcquireIncrement( acquireIncrement ); }
	
    public int getAcquireRetryAttempts()
    { return wcpds.getAcquireRetryAttempts(); }
	
    public void setAcquireRetryAttempts( int ara )
    { wcpds.setAcquireRetryAttempts( ara ); }
	
    public int getAcquireRetryDelay()
    { return wcpds.getAcquireRetryDelay(); }
	
    public void setAcquireRetryDelay( int ard )
    { wcpds.setAcquireRetryDelay( ard ); }
	
    public boolean isAutoCommitOnClose()
    { return wcpds.isAutoCommitOnClose(); }

    public void setAutoCommitOnClose( boolean autoCommitOnClose )
    { wcpds.setAutoCommitOnClose( autoCommitOnClose ); }
	
    public void setAutomaticTestTable( String att )
    { wcpds.setAutomaticTestTable( att ); }
	
    public String getAutomaticTestTable()
    { return wcpds.getAutomaticTestTable(); }
	
    public void setBreakAfterAcquireFailure( boolean baaf )
    { wcpds.setBreakAfterAcquireFailure( baaf ); }
	
    public boolean isBreakAfterAcquireFailure()
    { return wcpds.isBreakAfterAcquireFailure(); }

    public void setCheckoutTimeout( int ct )
    { wcpds.setCheckoutTimeout( ct ); }

    public int getCheckoutTimeout()
    { return wcpds.getCheckoutTimeout(); }
	
    public String getConnectionTesterClassName()
    { return wcpds.getConnectionTesterClassName(); }
	
    public void setConnectionTesterClassName( String connectionTesterClassName ) throws PropertyVetoException
    { wcpds.setConnectionTesterClassName( connectionTesterClassName ); }
	
    public boolean isForceIgnoreUnresolvedTransactions()
    { return wcpds.isForceIgnoreUnresolvedTransactions(); }
	
    public void setForceIgnoreUnresolvedTransactions( boolean forceIgnoreUnresolvedTransactions )
    { wcpds.setForceIgnoreUnresolvedTransactions( forceIgnoreUnresolvedTransactions ); }
	
    public String getIdentityToken()
    { return identityToken; }
	
    public void setIdentityToken(String identityToken)
    { this.identityToken = identityToken; }
	
    public void setIdleConnectionTestPeriod( int idleConnectionTestPeriod )
    { wcpds.setIdleConnectionTestPeriod( idleConnectionTestPeriod ); }
    
    public int getIdleConnectionTestPeriod()
    { return wcpds.getIdleConnectionTestPeriod(); }
	
    public int getInitialPoolSize()
    { return wcpds.getInitialPoolSize(); }
	
    public void setInitialPoolSize( int initialPoolSize )
    { wcpds.setInitialPoolSize( initialPoolSize ); }

    public int getMaxIdleTime()
    { return wcpds.getMaxIdleTime(); }
	
    public void setMaxIdleTime( int maxIdleTime )
    { wcpds.setMaxIdleTime( maxIdleTime ); }
	
    public int getMaxPoolSize()
    { return wcpds.getMaxPoolSize(); }
	
    public void setMaxPoolSize( int maxPoolSize )
    { wcpds.setMaxPoolSize( maxPoolSize ); }
	
    public int getMaxStatements()
    { return wcpds.getMaxStatements(); }
	
    public void setMaxStatements( int maxStatements )
    { wcpds.setMaxStatements( maxStatements ); }
	
    public int getMaxStatementsPerConnection()
    { return wcpds.getMaxStatementsPerConnection(); }
	
    public void setMaxStatementsPerConnection( int mspc )
    { wcpds.setMaxStatementsPerConnection( mspc ); }
	
    public int getMinPoolSize()
    { return wcpds.getMinPoolSize(); }
	
    public void setMinPoolSize( int minPoolSize )
    { wcpds.setMinPoolSize( minPoolSize ); }
	
    public String getPreferredTestQuery()
    { return wcpds.getPreferredTestQuery(); }
	
    public void setPreferredTestQuery( String ptq )
    { wcpds.setPreferredTestQuery( ptq ); }
	
    public int getPropertyCycle()
    { return wcpds.getPropertyCycle(); }
	
    public void setPropertyCycle( int propertyCycle )
    { wcpds.setPropertyCycle( propertyCycle ); }
	
    public boolean isTestConnectionOnCheckin()
    { return wcpds.isTestConnectionOnCheckin(); }
	
    public void setTestConnectionOnCheckin( boolean testConnectionOnCheckin )
    { wcpds.setTestConnectionOnCheckin( testConnectionOnCheckin ); }
	
    public boolean isTestConnectionOnCheckout()
    { return wcpds.isTestConnectionOnCheckout(); }
	
    public void setTestConnectionOnCheckout( boolean testConnectionOnCheckout )
    { wcpds.setTestConnectionOnCheckout( testConnectionOnCheckout ); }
	
    public boolean isUsesTraditionalReflectiveProxies()
    { return wcpds.isUsesTraditionalReflectiveProxies(); }
	
    public void setUsesTraditionalReflectiveProxies( boolean utrp )
    { wcpds.setUsesTraditionalReflectiveProxies( utrp ); }
	
    public String getFactoryClassLocation()
    { return jrfds.getFactoryClassLocation(); }

    public void setFactoryClassLocation( String factoryClassLocation )
    { 
	jrfds.setFactoryClassLocation( factoryClassLocation );
	wcpds.setFactoryClassLocation( factoryClassLocation );
    }

    final static JavaBeanReferenceMaker referenceMaker = new JavaBeanReferenceMaker();
    
    static
    {
	referenceMaker.setFactoryClassName( C3P0JavaBeanObjectFactory.class.getName() );
	referenceMaker.addReferenceProperty("acquireIncrement");
	referenceMaker.addReferenceProperty("acquireRetryAttempts");
	referenceMaker.addReferenceProperty("acquireRetryDelay");
	referenceMaker.addReferenceProperty("autoCommitOnClose");
	referenceMaker.addReferenceProperty("automaticTestTable");
	referenceMaker.addReferenceProperty("checkoutTimeout");
	referenceMaker.addReferenceProperty("connectionTesterClassName");
	referenceMaker.addReferenceProperty("factoryClassLocation");
	referenceMaker.addReferenceProperty("forceIgnoreUnresolvedTransactions");
	referenceMaker.addReferenceProperty("idleConnectionTestPeriod");
	referenceMaker.addReferenceProperty("identityToken");
	referenceMaker.addReferenceProperty("initialPoolSize");
	referenceMaker.addReferenceProperty("jndiEnv");
	referenceMaker.addReferenceProperty("jndiLookupCaching");
	referenceMaker.addReferenceProperty("jndiName");
	referenceMaker.addReferenceProperty("maxIdleTime");
	referenceMaker.addReferenceProperty("maxPoolSize");
	referenceMaker.addReferenceProperty("maxStatements");
	referenceMaker.addReferenceProperty("maxStatementsPerConnection");
	referenceMaker.addReferenceProperty("minPoolSize");
	referenceMaker.addReferenceProperty("preferredTestQuery");
	referenceMaker.addReferenceProperty("propertyCycle");
	referenceMaker.addReferenceProperty("testConnectionOnCheckin");
	referenceMaker.addReferenceProperty("testConnectionOnCheckout");
	referenceMaker.addReferenceProperty("usesTraditionalReflectiveProxies");
    }
    
    public Reference getReference() throws NamingException
    { return referenceMaker.createReference( this ); }

    //implementation of javax.sql.ConnectionPoolDataSource
    public PooledConnection getPooledConnection()
	throws SQLException
    { return wcpds.getPooledConnection(); } 
 
    public PooledConnection getPooledConnection(String user, String password)
	throws SQLException
    { return wcpds.getPooledConnection( user, password ); } 
 
    public PrintWriter getLogWriter()
	throws SQLException
    { return wcpds.getLogWriter(); }

    public void setLogWriter(PrintWriter out)
	throws SQLException
    { wcpds.setLogWriter( out ); }

    public void setLoginTimeout(int seconds)
	throws SQLException
    { wcpds.setLoginTimeout( seconds ); }

    public int getLoginTimeout()
	throws SQLException
    { return wcpds.getLoginTimeout(); }

    public String toString()
    {
	StringBuffer sb = new StringBuffer(512);
	sb.append( super.toString() );
	sb.append(" [");
	try { BeansUtils.appendPropNamesAndValues( sb, this, IGNORE_PROPS ); }
	catch (Exception e)
	    {
		//e.printStackTrace();
		if ( Debug.DEBUG && logger.isLoggable( MLevel.FINE ) )
		    logger.log( MLevel.FINE, "An exception occurred while extracting property names and values for toString()", e);
		sb.append( e.toString() ); 
	    }
	sb.append("]");
	return sb.toString();
    }
    
    // JDBC 4.1

    public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException {
        return wcpds.getParentLogger();
    }
}