KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mchange > v2 > c3p0 > PoolConfig


1 /*
2  * Distributed as part of c3p0 v.0.9.1
3  *
4  * Copyright (C) 2005 Machinery For Change, Inc.
5  *
6  * Author: Steve Waldman <swaldman@mchange.com>
7  *
8  * This library is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License version 2.1, as
10  * published by the Free Software Foundation.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this software; see the file LICENSE. If not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */

22
23
24 package com.mchange.v2.c3p0;
25
26 import java.util.Properties JavaDoc;
27 import java.io.InputStream JavaDoc;
28 import java.io.IOException JavaDoc;
29 import com.mchange.v1.io.InputStreamUtils;
30 import com.mchange.v2.c3p0.impl.C3P0Defaults;
31 import com.mchange.v2.cfg.MultiPropertiesConfig;
32 import com.mchange.v2.log.MLevel;
33 import com.mchange.v2.log.MLog;
34 import com.mchange.v2.log.MLogger;
35
36 /**
37  * <p>Encapsulates all the configuration information required by a c3p0 pooled DataSource.</p>
38  *
39  * <p>Newly constructed PoolConfig objects are preset with default values,
40  * which you can define yourself (see below),
41  * or you can rely on c3p0's built-in defaults. Just create a PoolConfig object, and change only the
42  * properties you care about. Then pass it to the {@link com.mchange.v2.c3p0.DataSources#pooledDataSource(javax.sql.DataSource, com.mchange.v2.c3p0.PoolConfig)}
43  * method, and you're off!</p>
44  *
45  * <p>For those interested in the details, configuration properties can be specified in several ways:</p>
46  * <ol>
47  * <li>Any property can be set explicitly by calling the corresponding method on a PoolConfig object.</li>
48  * <li>Any property will default to a value defined by a System Property, using the property name shown the table below.</li>
49  * <li>Any property not set in either of the above ways will default to a value found in a user-supplied Java properties file,
50  * which may be placed in the resource path of
51  * the ClassLoader that loaded the c3p0 libraries under the name <tt>/c3p0.properties</tt>.</li>
52  * <li>Any property not set in any of the above ways will be defined according c3p0's built-in defaults.</li>
53  * </ol>
54  *
55  * <p><i>Please see c3p0's main documentation for a description of all available parameters.</i></p>
56  *
57  * @deprecated as of c3p0-0.9.1. To manipulate config programmaticall, please use ComboPooledDataSource
58  *
59  */

60 public final class PoolConfig
61 {
62     final static MLogger logger;
63
64     public final static String JavaDoc INITIAL_POOL_SIZE = "c3p0.initialPoolSize";
65     public final static String JavaDoc MIN_POOL_SIZE = "c3p0.minPoolSize";
66     public final static String JavaDoc MAX_POOL_SIZE = "c3p0.maxPoolSize";
67     public final static String JavaDoc IDLE_CONNECTION_TEST_PERIOD = "c3p0.idleConnectionTestPeriod";
68     public final static String JavaDoc MAX_IDLE_TIME = "c3p0.maxIdleTime";
69     public final static String JavaDoc PROPERTY_CYCLE = "c3p0.propertyCycle";
70     public final static String JavaDoc MAX_STATEMENTS = "c3p0.maxStatements";
71     public final static String JavaDoc MAX_STATEMENTS_PER_CONNECTION = "c3p0.maxStatementsPerConnection";
72     public final static String JavaDoc CHECKOUT_TIMEOUT = "c3p0.checkoutTimeout";
73     public final static String JavaDoc ACQUIRE_INCREMENT = "c3p0.acquireIncrement";
74     public final static String JavaDoc ACQUIRE_RETRY_ATTEMPTS = "c3p0.acquireRetryAttempts";
75     public final static String JavaDoc ACQUIRE_RETRY_DELAY = "c3p0.acquireRetryDelay";
76     public final static String JavaDoc BREAK_AFTER_ACQUIRE_FAILURE = "c3p0.breakAfterAcquireFailure";
77     public final static String JavaDoc USES_TRADITIONAL_REFLECTIVE_PROXIES = "c3p0.usesTraditionalReflectiveProxies";
78     public final static String JavaDoc TEST_CONNECTION_ON_CHECKOUT = "c3p0.testConnectionOnCheckout";
79     public final static String JavaDoc TEST_CONNECTION_ON_CHECKIN = "c3p0.testConnectionOnCheckin";
80     public final static String JavaDoc CONNECTION_TESTER_CLASS_NAME = "c3p0.connectionTesterClassName";
81     public final static String JavaDoc AUTOMATIC_TEST_TABLE = "c3p0.automaticTestTable";
82     public final static String JavaDoc AUTO_COMMIT_ON_CLOSE = "c3p0.autoCommitOnClose";
83     public final static String JavaDoc FORCE_IGNORE_UNRESOLVED_TRANSACTIONS = "c3p0.forceIgnoreUnresolvedTransactions";
84     public final static String JavaDoc NUM_HELPER_THREADS = "c3p0.numHelperThreads";
85     public final static String JavaDoc PREFERRED_TEST_QUERY = "c3p0.preferredTestQuery";
86     public final static String JavaDoc FACTORY_CLASS_LOCATION = "c3p0.factoryClassLocation";
87     
88     public final static String JavaDoc DEFAULT_CONFIG_RSRC_PATH = "/c3p0.properties";
89     
90     final static PoolConfig DEFAULTS;
91
92     static
93     {
94     logger = MLog.getLogger( PoolConfig.class );
95
96     Properties JavaDoc rsrcProps = findResourceProperties();
97     PoolConfig rsrcDefaults = extractConfig( rsrcProps, null );
98
99     Properties JavaDoc sysProps;
100     try
101         { sysProps = System.getProperties(); }
102     catch ( SecurityException JavaDoc e )
103         {
104         if (logger.isLoggable(MLevel.WARNING))
105             logger.log(MLevel.WARNING,
106                    "Read of system Properties blocked -- ignoring any c3p0 configuration via System properties! " +
107                    "(But any configuration via a c3p0.properties file is still okay!)",
108                    e);
109         sysProps = new Properties JavaDoc(); //TODO -- an alternative approach to getting c3p0-specific sysprops if allowed
110
}
111     DEFAULTS = extractConfig( sysProps, rsrcDefaults );
112     }
113
114     public static int defaultNumHelperThreads()
115     { return DEFAULTS.getNumHelperThreads(); }
116
117     public static String JavaDoc defaultPreferredTestQuery()
118     { return DEFAULTS.getPreferredTestQuery(); }
119
120     public static String JavaDoc defaultFactoryClassLocation()
121     { return DEFAULTS.getFactoryClassLocation(); }
122
123     public static int defaultMaxStatements()
124     { return DEFAULTS.getMaxStatements(); }
125
126     public static int defaultMaxStatementsPerConnection()
127     { return DEFAULTS.getMaxStatementsPerConnection(); }
128
129     public static int defaultInitialPoolSize()
130     { return DEFAULTS.getInitialPoolSize(); }
131
132     public static int defaultMinPoolSize()
133     { return DEFAULTS.getMinPoolSize(); }
134
135     public static int defaultMaxPoolSize()
136     { return DEFAULTS.getMaxPoolSize(); }
137
138     public static int defaultIdleConnectionTestPeriod()
139     { return DEFAULTS.getIdleConnectionTestPeriod(); }
140
141     public static int defaultMaxIdleTime()
142     { return DEFAULTS.getMaxIdleTime(); }
143
144     public static int defaultPropertyCycle()
145     { return DEFAULTS.getPropertyCycle(); }
146
147     public static int defaultCheckoutTimeout()
148     { return DEFAULTS.getCheckoutTimeout(); }
149
150     public static int defaultAcquireIncrement()
151     { return DEFAULTS.getAcquireIncrement(); }
152
153     public static int defaultAcquireRetryAttempts()
154     { return DEFAULTS.getAcquireRetryAttempts(); }
155
156     public static int defaultAcquireRetryDelay()
157     { return DEFAULTS.getAcquireRetryDelay(); }
158
159     public static boolean defaultBreakAfterAcquireFailure()
160     { return DEFAULTS.isBreakAfterAcquireFailure(); }
161
162     public static String JavaDoc defaultConnectionTesterClassName()
163     { return DEFAULTS.getConnectionTesterClassName(); }
164
165     public static String JavaDoc defaultAutomaticTestTable()
166     { return DEFAULTS.getAutomaticTestTable(); }
167
168     public static boolean defaultTestConnectionOnCheckout()
169     { return DEFAULTS.isTestConnectionOnCheckout(); }
170
171     public static boolean defaultTestConnectionOnCheckin()
172     { return DEFAULTS.isTestConnectionOnCheckin(); }
173
174     public static boolean defaultAutoCommitOnClose()
175     { return DEFAULTS.isAutoCommitOnClose(); }
176
177     public static boolean defaultForceIgnoreUnresolvedTransactions()
178     { return DEFAULTS.isAutoCommitOnClose(); }
179
180     public static boolean defaultUsesTraditionalReflectiveProxies()
181     { return DEFAULTS.isUsesTraditionalReflectiveProxies(); }
182
183
184     int maxStatements;
185     int maxStatementsPerConnection;
186     int initialPoolSize;
187     int minPoolSize;
188     int maxPoolSize;
189     int idleConnectionTestPeriod;
190     int maxIdleTime;
191     int propertyCycle;
192     int checkoutTimeout;
193     int acquireIncrement;
194     int acquireRetryAttempts;
195     int acquireRetryDelay;
196     boolean breakAfterAcquireFailure;
197     boolean testConnectionOnCheckout;
198     boolean testConnectionOnCheckin;
199     boolean autoCommitOnClose;
200     boolean forceIgnoreUnresolvedTransactions;
201     boolean usesTraditionalReflectiveProxies;
202     String JavaDoc connectionTesterClassName;
203     String JavaDoc automaticTestTable;
204     int numHelperThreads;
205     String JavaDoc preferredTestQuery;
206     String JavaDoc factoryClassLocation;
207
208     private PoolConfig( Properties JavaDoc props, boolean init ) throws NumberFormatException JavaDoc
209     {
210     if (init)
211         extractConfig( this, props, DEFAULTS );
212     }
213
214     public PoolConfig( Properties JavaDoc props ) throws NumberFormatException JavaDoc
215     { this( props, true ); }
216
217     public PoolConfig() throws NumberFormatException JavaDoc
218     { this( null, true ); }
219
220     public int getNumHelperThreads()
221     { return numHelperThreads; }
222
223     public String JavaDoc getPreferredTestQuery()
224     { return preferredTestQuery; }
225
226     public String JavaDoc getFactoryClassLocation()
227     { return factoryClassLocation; }
228
229     public int getMaxStatements()
230     { return maxStatements; }
231     
232     public int getMaxStatementsPerConnection()
233     { return maxStatementsPerConnection; }
234     
235     public int getInitialPoolSize()
236     { return initialPoolSize; }
237     
238     public int getMinPoolSize()
239     { return minPoolSize; }
240     
241     public int getMaxPoolSize()
242     { return maxPoolSize; }
243     
244     public int getIdleConnectionTestPeriod()
245     { return idleConnectionTestPeriod; }
246     
247     public int getMaxIdleTime()
248     { return maxIdleTime; }
249     
250     public int getPropertyCycle()
251     { return propertyCycle; }
252     
253     public int getAcquireIncrement()
254     { return acquireIncrement; }
255     
256     public int getCheckoutTimeout()
257     { return checkoutTimeout; }
258     
259     public int getAcquireRetryAttempts()
260     { return acquireRetryAttempts; }
261     
262     public int getAcquireRetryDelay()
263     { return acquireRetryDelay; }
264     
265     public boolean isBreakAfterAcquireFailure()
266     { return this.breakAfterAcquireFailure; }
267
268     public boolean isUsesTraditionalReflectiveProxies()
269     { return this.usesTraditionalReflectiveProxies; }
270
271     public String JavaDoc getConnectionTesterClassName()
272     { return connectionTesterClassName; }
273     
274     public String JavaDoc getAutomaticTestTable()
275     { return automaticTestTable; }
276     
277     /**
278      * @deprecated use isTestConnectionOnCheckout
279      */

280     public boolean getTestConnectionOnCheckout()
281     { return testConnectionOnCheckout; }
282
283     public boolean isTestConnectionOnCheckout()
284     { return this.getTestConnectionOnCheckout(); }
285
286     public boolean isTestConnectionOnCheckin()
287     { return testConnectionOnCheckin; }
288
289     public boolean isAutoCommitOnClose()
290     { return this.autoCommitOnClose; }
291
292     public boolean isForceIgnoreUnresolvedTransactions()
293     { return this.forceIgnoreUnresolvedTransactions; }
294     
295     public void setNumHelperThreads( int numHelperThreads )
296     { this.numHelperThreads = numHelperThreads; }
297
298     public void setPreferredTestQuery( String JavaDoc preferredTestQuery )
299     { this.preferredTestQuery = preferredTestQuery; }
300
301     public void setFactoryClassLocation( String JavaDoc factoryClassLocation )
302     { this.factoryClassLocation = factoryClassLocation; }
303
304     public void setMaxStatements( int maxStatements )
305     { this.maxStatements = maxStatements; }
306     
307     public void setMaxStatementsPerConnection( int maxStatementsPerConnection )
308     { this.maxStatementsPerConnection = maxStatementsPerConnection; }
309     
310     public void setInitialPoolSize( int initialPoolSize )
311     { this.initialPoolSize = initialPoolSize; }
312     
313     public void setMinPoolSize( int minPoolSize )
314     { this.minPoolSize = minPoolSize; }
315     
316     public void setMaxPoolSize( int maxPoolSize )
317     { this.maxPoolSize = maxPoolSize; }
318     
319     public void setIdleConnectionTestPeriod( int idleConnectionTestPeriod )
320     { this.idleConnectionTestPeriod = idleConnectionTestPeriod; }
321     
322     public void setMaxIdleTime( int maxIdleTime )
323     { this.maxIdleTime = maxIdleTime; }
324     
325     public void setPropertyCycle( int propertyCycle )
326     { this.propertyCycle = propertyCycle; }
327     
328     public void setCheckoutTimeout( int checkoutTimeout )
329     { this.checkoutTimeout = checkoutTimeout; }
330     
331     public void setAcquireIncrement( int acquireIncrement )
332     { this.acquireIncrement = acquireIncrement; }
333     
334     public void setAcquireRetryAttempts( int acquireRetryAttempts )
335     { this.acquireRetryAttempts = acquireRetryAttempts; }
336     
337     public void setAcquireRetryDelay( int acquireRetryDelay )
338     { this.acquireRetryDelay = acquireRetryDelay; }
339     
340     public void setConnectionTesterClassName( String JavaDoc connectionTesterClassName )
341     { this.connectionTesterClassName = connectionTesterClassName; }
342     
343     public void setAutomaticTestTable( String JavaDoc automaticTestTable )
344     { this.automaticTestTable = automaticTestTable; }
345     
346     public void setBreakAfterAcquireFailure( boolean breakAfterAcquireFailure )
347     { this.breakAfterAcquireFailure = breakAfterAcquireFailure; }
348     
349     public void setUsesTraditionalReflectiveProxies( boolean usesTraditionalReflectiveProxies )
350     { this.usesTraditionalReflectiveProxies = usesTraditionalReflectiveProxies; }
351     
352     public void setTestConnectionOnCheckout( boolean testConnectionOnCheckout )
353     { this.testConnectionOnCheckout = testConnectionOnCheckout; }
354     
355     public void setTestConnectionOnCheckin( boolean testConnectionOnCheckin )
356     { this.testConnectionOnCheckin = testConnectionOnCheckin; }
357     
358     public void setAutoCommitOnClose( boolean autoCommitOnClose )
359     { this.autoCommitOnClose = autoCommitOnClose; }
360
361     public void setForceIgnoreUnresolvedTransactions( boolean forceIgnoreUnresolvedTransactions )
362     { this.forceIgnoreUnresolvedTransactions = forceIgnoreUnresolvedTransactions; }
363
364     private static PoolConfig extractConfig(Properties JavaDoc props, PoolConfig defaults) throws NumberFormatException JavaDoc
365     {
366     PoolConfig pcfg = new PoolConfig(null, false);
367     extractConfig( pcfg, props, defaults );
368     return pcfg;
369     }
370
371     private static void extractConfig(PoolConfig pcfg, Properties JavaDoc props, PoolConfig defaults) throws NumberFormatException JavaDoc
372     {
373     String JavaDoc maxStatementsStr = null;
374     String JavaDoc maxStatementsPerConnectionStr = null;
375     String JavaDoc initialPoolSizeStr = null;
376     String JavaDoc minPoolSizeStr = null;
377     String JavaDoc maxPoolSizeStr = null;
378     String JavaDoc idleConnectionTestPeriodStr = null;
379     String JavaDoc maxIdleTimeStr = null;
380     String JavaDoc propertyCycleStr = null;
381     String JavaDoc checkoutTimeoutStr = null;
382     String JavaDoc acquireIncrementStr = null;
383     String JavaDoc acquireRetryAttemptsStr = null;
384     String JavaDoc acquireRetryDelayStr = null;
385     String JavaDoc breakAfterAcquireFailureStr = null;
386     String JavaDoc usesTraditionalReflectiveProxiesStr = null;
387     String JavaDoc testConnectionOnCheckoutStr = null;
388     String JavaDoc testConnectionOnCheckinStr = null;
389     String JavaDoc autoCommitOnCloseStr = null;
390     String JavaDoc forceIgnoreUnresolvedTransactionsStr = null;
391     String JavaDoc connectionTesterClassName = null;
392     String JavaDoc automaticTestTable = null;
393     String JavaDoc numHelperThreadsStr = null;
394     String JavaDoc preferredTestQuery = null;
395     String JavaDoc factoryClassLocation = null;
396
397     if ( props != null )
398         {
399         maxStatementsStr = props.getProperty(MAX_STATEMENTS);
400         maxStatementsPerConnectionStr = props.getProperty(MAX_STATEMENTS_PER_CONNECTION);
401         initialPoolSizeStr = props.getProperty(INITIAL_POOL_SIZE);
402         minPoolSizeStr = props.getProperty(MIN_POOL_SIZE);
403         maxPoolSizeStr = props.getProperty(MAX_POOL_SIZE);
404         idleConnectionTestPeriodStr = props.getProperty(IDLE_CONNECTION_TEST_PERIOD);
405         maxIdleTimeStr = props.getProperty(MAX_IDLE_TIME);
406         propertyCycleStr = props.getProperty(PROPERTY_CYCLE);
407         checkoutTimeoutStr = props.getProperty(CHECKOUT_TIMEOUT);
408         acquireIncrementStr = props.getProperty(ACQUIRE_INCREMENT);
409         acquireRetryAttemptsStr = props.getProperty(ACQUIRE_RETRY_ATTEMPTS);
410         acquireRetryDelayStr = props.getProperty(ACQUIRE_RETRY_DELAY);
411         breakAfterAcquireFailureStr = props.getProperty(BREAK_AFTER_ACQUIRE_FAILURE);
412         usesTraditionalReflectiveProxiesStr = props.getProperty(USES_TRADITIONAL_REFLECTIVE_PROXIES);
413         testConnectionOnCheckoutStr = props.getProperty(TEST_CONNECTION_ON_CHECKOUT);
414         testConnectionOnCheckinStr = props.getProperty(TEST_CONNECTION_ON_CHECKIN);
415         autoCommitOnCloseStr = props.getProperty(AUTO_COMMIT_ON_CLOSE);
416         forceIgnoreUnresolvedTransactionsStr = props.getProperty(FORCE_IGNORE_UNRESOLVED_TRANSACTIONS);
417         connectionTesterClassName = props.getProperty(CONNECTION_TESTER_CLASS_NAME);
418         automaticTestTable = props.getProperty(AUTOMATIC_TEST_TABLE);
419         numHelperThreadsStr = props.getProperty(NUM_HELPER_THREADS);
420         preferredTestQuery = props.getProperty(PREFERRED_TEST_QUERY);
421         factoryClassLocation = props.getProperty(FACTORY_CLASS_LOCATION);
422         }
423
424     // maxStatements
425
if ( maxStatementsStr != null )
426         pcfg.setMaxStatements( Integer.parseInt( maxStatementsStr.trim() ) );
427     else if (defaults != null)
428         pcfg.setMaxStatements( defaults.getMaxStatements() );
429     else
430         pcfg.setMaxStatements( C3P0Defaults.maxStatements() );
431
432     // maxStatementsPerConnection
433
if ( maxStatementsPerConnectionStr != null )
434         pcfg.setMaxStatementsPerConnection( Integer.parseInt( maxStatementsPerConnectionStr.trim() ) );
435     else if (defaults != null)
436         pcfg.setMaxStatementsPerConnection( defaults.getMaxStatementsPerConnection() );
437     else
438         pcfg.setMaxStatementsPerConnection( C3P0Defaults.maxStatementsPerConnection() );
439
440     // initialPoolSize
441
if ( initialPoolSizeStr != null )
442         pcfg.setInitialPoolSize( Integer.parseInt( initialPoolSizeStr.trim() ) );
443     else if (defaults != null)
444         pcfg.setInitialPoolSize( defaults.getInitialPoolSize() );
445     else
446         pcfg.setInitialPoolSize( C3P0Defaults.initialPoolSize() );
447
448     // minPoolSize
449
if ( minPoolSizeStr != null )
450         pcfg.setMinPoolSize( Integer.parseInt( minPoolSizeStr.trim() ) );
451     else if (defaults != null)
452         pcfg.setMinPoolSize( defaults.getMinPoolSize() );
453     else
454         pcfg.setMinPoolSize( C3P0Defaults.minPoolSize() );
455
456     // maxPoolSize
457
if ( maxPoolSizeStr != null )
458         pcfg.setMaxPoolSize( Integer.parseInt( maxPoolSizeStr.trim() ) );
459     else if (defaults != null)
460         pcfg.setMaxPoolSize( defaults.getMaxPoolSize() );
461     else
462         pcfg.setMaxPoolSize( C3P0Defaults.maxPoolSize() );
463
464     // maxIdleTime
465
if ( idleConnectionTestPeriodStr != null )
466         pcfg.setIdleConnectionTestPeriod( Integer.parseInt( idleConnectionTestPeriodStr.trim() ) );
467     else if (defaults != null)
468         pcfg.setIdleConnectionTestPeriod( defaults.getIdleConnectionTestPeriod() );
469     else
470         pcfg.setIdleConnectionTestPeriod( C3P0Defaults.idleConnectionTestPeriod() );
471
472     // maxIdleTime
473
if ( maxIdleTimeStr != null )
474         pcfg.setMaxIdleTime( Integer.parseInt( maxIdleTimeStr.trim() ) );
475     else if (defaults != null)
476         pcfg.setMaxIdleTime( defaults.getMaxIdleTime() );
477     else
478         pcfg.setMaxIdleTime( C3P0Defaults.maxIdleTime() );
479
480     // propertyCycle
481
if ( propertyCycleStr != null )
482         pcfg.setPropertyCycle( Integer.parseInt( propertyCycleStr.trim() ) );
483     else if (defaults != null)
484         pcfg.setPropertyCycle( defaults.getPropertyCycle() );
485     else
486         pcfg.setPropertyCycle( C3P0Defaults.propertyCycle() );
487
488     // checkoutTimeout
489
if ( checkoutTimeoutStr != null )
490         pcfg.setCheckoutTimeout( Integer.parseInt( checkoutTimeoutStr.trim() ) );
491     else if (defaults != null)
492         pcfg.setCheckoutTimeout( defaults.getCheckoutTimeout() );
493     else
494         pcfg.setCheckoutTimeout( C3P0Defaults.checkoutTimeout() );
495
496     // acquireIncrement
497
if ( acquireIncrementStr != null )
498         pcfg.setAcquireIncrement( Integer.parseInt( acquireIncrementStr.trim() ) );
499     else if (defaults != null)
500         pcfg.setAcquireIncrement( defaults.getAcquireIncrement() );
501     else
502         pcfg.setAcquireIncrement( C3P0Defaults.acquireIncrement() );
503
504     // acquireRetryAttempts
505
if ( acquireRetryAttemptsStr != null )
506         pcfg.setAcquireRetryAttempts( Integer.parseInt( acquireRetryAttemptsStr.trim() ) );
507     else if (defaults != null)
508         pcfg.setAcquireRetryAttempts( defaults.getAcquireRetryAttempts() );
509     else
510         pcfg.setAcquireRetryAttempts( C3P0Defaults.acquireRetryAttempts() );
511
512     // acquireRetryDelay
513
if ( acquireRetryDelayStr != null )
514         pcfg.setAcquireRetryDelay( Integer.parseInt( acquireRetryDelayStr.trim() ) );
515     else if (defaults != null)
516         pcfg.setAcquireRetryDelay( defaults.getAcquireRetryDelay() );
517     else
518         pcfg.setAcquireRetryDelay( C3P0Defaults.acquireRetryDelay() );
519
520     // breakAfterAcquireFailure
521
if ( breakAfterAcquireFailureStr != null )
522         pcfg.setBreakAfterAcquireFailure( Boolean.valueOf(breakAfterAcquireFailureStr.trim()).booleanValue() );
523     else if (defaults != null)
524         pcfg.setBreakAfterAcquireFailure( defaults.isBreakAfterAcquireFailure() );
525     else
526         pcfg.setBreakAfterAcquireFailure( C3P0Defaults.breakAfterAcquireFailure() );
527
528     // usesTraditionalReflectiveProxies
529
if ( usesTraditionalReflectiveProxiesStr != null )
530         pcfg.setUsesTraditionalReflectiveProxies( Boolean.valueOf(usesTraditionalReflectiveProxiesStr.trim()).booleanValue() );
531     else if (defaults != null)
532         pcfg.setUsesTraditionalReflectiveProxies( defaults.isUsesTraditionalReflectiveProxies() );
533     else
534         pcfg.setUsesTraditionalReflectiveProxies( C3P0Defaults.usesTraditionalReflectiveProxies() );
535
536     // testConnectionOnCheckout
537
if ( testConnectionOnCheckoutStr != null )
538         pcfg.setTestConnectionOnCheckout( Boolean.valueOf(testConnectionOnCheckoutStr.trim()).booleanValue() );
539     else if (defaults != null)
540         pcfg.setTestConnectionOnCheckout( defaults.isTestConnectionOnCheckout() );
541     else
542         pcfg.setTestConnectionOnCheckout( C3P0Defaults.testConnectionOnCheckout() );
543
544     // testConnectionOnCheckin
545
if ( testConnectionOnCheckinStr != null )
546         pcfg.setTestConnectionOnCheckin( Boolean.valueOf(testConnectionOnCheckinStr.trim()).booleanValue() );
547     else if (defaults != null)
548         pcfg.setTestConnectionOnCheckin( defaults.isTestConnectionOnCheckin() );
549     else
550         pcfg.setTestConnectionOnCheckin( C3P0Defaults.testConnectionOnCheckin() );
551
552     // autoCommitOnClose
553
if ( autoCommitOnCloseStr != null )
554         pcfg.setAutoCommitOnClose( Boolean.valueOf(autoCommitOnCloseStr.trim()).booleanValue() );
555     else if (defaults != null)
556         pcfg.setAutoCommitOnClose( defaults.isAutoCommitOnClose() );
557     else
558         pcfg.setAutoCommitOnClose( C3P0Defaults.autoCommitOnClose() );
559
560     // forceIgnoreUnresolvedTransactions
561
if ( forceIgnoreUnresolvedTransactionsStr != null )
562         pcfg.setForceIgnoreUnresolvedTransactions( Boolean.valueOf( forceIgnoreUnresolvedTransactionsStr.trim() ).booleanValue() );
563     else if (defaults != null)
564         pcfg.setForceIgnoreUnresolvedTransactions( defaults.isForceIgnoreUnresolvedTransactions() );
565     else
566         pcfg.setForceIgnoreUnresolvedTransactions( C3P0Defaults.forceIgnoreUnresolvedTransactions() );
567
568     // connectionTesterClassName
569
if ( connectionTesterClassName != null )
570         pcfg.setConnectionTesterClassName( connectionTesterClassName.trim() );
571     else if (defaults != null)
572         pcfg.setConnectionTesterClassName( defaults.getConnectionTesterClassName() );
573     else
574         pcfg.setConnectionTesterClassName( C3P0Defaults.connectionTesterClassName() );
575
576     // automaticTestTable
577
if ( automaticTestTable != null )
578         pcfg.setAutomaticTestTable( automaticTestTable.trim() );
579     else if (defaults != null)
580         pcfg.setAutomaticTestTable( defaults.getAutomaticTestTable() );
581     else
582         pcfg.setAutomaticTestTable( C3P0Defaults.automaticTestTable() );
583
584     // numHelperThreads
585
if ( numHelperThreadsStr != null )
586         pcfg.setNumHelperThreads( Integer.parseInt( numHelperThreadsStr.trim() ) );
587     else if (defaults != null)
588         pcfg.setNumHelperThreads( defaults.getNumHelperThreads() );
589     else
590         pcfg.setNumHelperThreads( C3P0Defaults.numHelperThreads() );
591
592     // preferredTestQuery
593
if ( preferredTestQuery != null )
594         pcfg.setPreferredTestQuery( preferredTestQuery.trim() );
595     else if (defaults != null)
596         pcfg.setPreferredTestQuery( defaults.getPreferredTestQuery() );
597     else
598         pcfg.setPreferredTestQuery( C3P0Defaults.preferredTestQuery() );
599
600     // factoryClassLocation
601
if ( factoryClassLocation != null )
602         pcfg.setFactoryClassLocation( factoryClassLocation.trim() );
603     else if (defaults != null)
604         pcfg.setFactoryClassLocation( defaults.getFactoryClassLocation() );
605     else
606         pcfg.setFactoryClassLocation( C3P0Defaults.factoryClassLocation() );
607     }
608
609     private static Properties JavaDoc findResourceProperties()
610     { return MultiPropertiesConfig.readVmConfig().getPropertiesByResourcePath(DEFAULT_CONFIG_RSRC_PATH); }
611
612     private static Properties JavaDoc origFindResourceProperties()
613     {
614     Properties JavaDoc props = new Properties JavaDoc();
615
616     InputStream JavaDoc is = null;
617     try
618         {
619         is = PoolConfig.class.getResourceAsStream(DEFAULT_CONFIG_RSRC_PATH);
620         if ( is != null )
621             props.load( is );
622         }
623     catch (IOException JavaDoc e)
624         {
625         //e.printStackTrace();
626
if ( logger.isLoggable( MLevel.WARNING ) )
627             logger.log( MLevel.WARNING, "An IOException occurred while trying to read Pool properties!", e );
628         props = new Properties JavaDoc();
629         }
630     finally
631         { InputStreamUtils.attemptClose( is ); }
632
633     return props;
634     }
635 }
636
Popular Tags