001package com.hfg.sql.jdbc; 002 003import com.hfg.setting.IntSetting; 004 005//------------------------------------------------------------------------------ 006/** 007 Settings for a JDBC-compatible connection pool. 008 <div> 009 @author J. Alex Taylor, hairyfatguy.com 010 </div> 011 */ 012//------------------------------------------------------------------------------ 013// com.hfg XML/HTML Coding Library 014// 015// This library is free software; you can redistribute it and/or 016// modify it under the terms of the GNU Lesser General Public 017// License as published by the Free Software Foundation; either 018// version 2.1 of the License, or (at your option) any later version. 019// 020// This library is distributed in the hope that it will be useful, 021// but WITHOUT ANY WARRANTY; without even the implied warranty of 022// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 023// Lesser General Public License for more details. 024// 025// You should have received a copy of the GNU Lesser General Public 026// License along with this library; if not, write to the Free Software 027// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 028// 029// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 030// jataylor@hairyfatguy.com 031//------------------------------------------------------------------------------ 032 033public class JDBCConnectionPoolSettings extends JDBCConnectionSettings 034{ 035 private static final String MAX_CONNECTIONS = "max_connections"; 036 private static final String MIN_CONNECTIONS = "min_connections"; 037 private static final String MAX_IDLE_TIME_SEC = "max_idle_time_sec"; 038 private static final String AVAILABILITY_TIMEOUT_SEC = "availability_timeout_sec"; 039 040 private static int sDefaultMaxConnections = 10; 041 private static int sDefaultMinConnections = 0; 042 private static int sDefaultMaxIdleTimeSec = 600; 043 private static int sDefaultAvailabilityTimeoutSec = 10; 044 045 046 //########################################################################### 047 // CONSTRUCTORS 048 //########################################################################### 049 050 //--------------------------------------------------------------------------- 051 public JDBCConnectionPoolSettings() 052 { 053 super(); 054 } 055 056 //--------------------------------------------------------------------------- 057 @Override 058 protected void init() 059 { 060 super.init(); 061 062 add(new IntSetting(MAX_CONNECTIONS, sDefaultMaxConnections)); 063 add(new IntSetting(MIN_CONNECTIONS, sDefaultMinConnections)); 064 add(new IntSetting(MAX_IDLE_TIME_SEC, sDefaultMaxIdleTimeSec)); 065 add(new IntSetting(AVAILABILITY_TIMEOUT_SEC, sDefaultAvailabilityTimeoutSec)); 066 } 067 068 //########################################################################### 069 // PUBLIC METHODS 070 //########################################################################### 071 072 //--------------------------------------------------------------------------- 073 public JDBCConnectionPoolSettings setMaxConnections(Integer inValue) 074 { 075 get(MAX_CONNECTIONS).setValue(inValue); 076 return this; 077 } 078 079 //--------------------------------------------------------------------------- 080 public Integer getMaxConnections() 081 { 082 return (Integer) get(MAX_CONNECTIONS).getValue(); 083 } 084 085 //--------------------------------------------------------------------------- 086 public JDBCConnectionPoolSettings setMinConnections(Integer inValue) 087 { 088 get(MIN_CONNECTIONS).setValue(inValue); 089 return this; 090 } 091 092 //--------------------------------------------------------------------------- 093 public Integer getMinConnections() 094 { 095 return (Integer) get(MIN_CONNECTIONS).getValue(); 096 } 097 098 //--------------------------------------------------------------------------- 099 /** 100 Specifies the maximum amount of time that a connection above the minimum number 101 of pool connections can sit idle before potentially being closed. 102 * @param inValue maximum idle time in seconds 103 * @return this settings object 104 */ 105 public JDBCConnectionPoolSettings setMaxIdleTimeSec(Integer inValue) 106 { 107 get(MAX_IDLE_TIME_SEC).setValue(inValue); 108 return this; 109 } 110 111 //--------------------------------------------------------------------------- 112 /** 113 Returns the maximum amount of time that a connection above the minimum number 114 of pool connections can sit idle before potentially being closed. 115 * @return maximum idle time in seconds 116 */ 117 public Integer getMaxIdleTimeSec() 118 { 119 return (Integer) get(MAX_IDLE_TIME_SEC).getValue(); 120 } 121 122 //--------------------------------------------------------------------------- 123 /** 124 Specifies the maximum amount of time to wait for a connection to become available 125 when requesting a connection from the pool. 126 * @param inValue maximum wait time in seconds 127 * @return this settings object 128 */ 129 public JDBCConnectionPoolSettings setAvailabilityTimeoutSec(Integer inValue) 130 { 131 get(AVAILABILITY_TIMEOUT_SEC).setValue(inValue); 132 return this; 133 } 134 135 //--------------------------------------------------------------------------- 136 /** 137 Returns the maximum amount of time to wait for a connection to become available 138 when requesting a connection from the pool. 139 * @return maximum wait time in seconds 140 */ 141 public Integer getAvailabilityTimeoutSec() 142 { 143 return (Integer) get(AVAILABILITY_TIMEOUT_SEC).getValue(); 144 } 145}