001/* 002 * Copyright (c) 2006-2012 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Florent Guillaume 011 * Julien Carsique 012 */ 013package org.nuxeo.runtime.jtajca; 014 015import org.apache.commons.logging.LogFactory; 016import org.nuxeo.common.xmap.annotation.XNode; 017import org.nuxeo.common.xmap.annotation.XObject; 018 019/** 020 * Descriptor of the pool configuration, used by NuxeoContainer when creating a pool directly instead of the previous 021 * way that was using a JNDI factory (NuxeoConnectionManagerFactory). 022 * 023 * @since 5.6 024 */ 025@XObject("pool") 026public class NuxeoConnectionManagerConfiguration { 027 028 public static final int DEFAULT_MAX_POOL_SIZE = 20; 029 030 public static final int DEFAULT_MIN_POOL_SIZE = 0; 031 032 public static final int DEFAULT_BLOCKING_TIMEOUT_MILLIS = 100; 033 034 public static final int DEFAULT_IDLE_TIMEOUT_MINUTES = 0; // no timeout 035 036 @XNode("@name") 037 private String name = "NuxeoConnectionManager"; 038 039 // transaction 040 @XNode("@xaMode") 041 private Boolean xaMode; 042 043 @XNode("@useTransactionCaching") 044 private Boolean useTransactionCaching; 045 046 @XNode("@useThreadCaching") 047 private Boolean useThreadCaching; 048 049 // pool 050 051 @XNode("@matchOne") 052 private Boolean matchOne; // unused by Geronimo? 053 054 @XNode("@matchAll") 055 private Boolean matchAll; 056 057 @XNode("@selectOneNoMatch") 058 private Boolean selectOneNoMatch; 059 060 @XNode("@maxPoolSize") 061 private Integer maxPoolSize; 062 063 @XNode("@minPoolSize") 064 private Integer minPoolSize; 065 066 @XNode("@blockingTimeoutMillis") 067 private Integer blockingTimeoutMillis; 068 069 @XNode("@idleTimeoutMinutes") 070 private Integer idleTimeoutMinutes; 071 072 public NuxeoConnectionManagerConfiguration() { 073 } 074 075 /** Copy constructor. */ 076 public NuxeoConnectionManagerConfiguration(NuxeoConnectionManagerConfiguration other) { 077 name = other.name; 078 useTransactionCaching = other.useTransactionCaching; 079 useThreadCaching = other.useThreadCaching; 080 matchOne = other.matchOne; 081 matchAll = other.matchAll; 082 selectOneNoMatch = other.selectOneNoMatch; 083 maxPoolSize = other.maxPoolSize; 084 minPoolSize = other.minPoolSize; 085 blockingTimeoutMillis = other.blockingTimeoutMillis; 086 idleTimeoutMinutes = other.idleTimeoutMinutes; 087 } 088 089 public void merge(NuxeoConnectionManagerConfiguration other) { 090 if (other.name != null) { 091 name = other.name; 092 } 093 if (other.xaMode) { 094 xaMode = other.xaMode; 095 } 096 if (other.useTransactionCaching != null) { 097 useTransactionCaching = other.useTransactionCaching; 098 } 099 if (other.useThreadCaching != null) { 100 useThreadCaching = other.useThreadCaching; 101 } 102 if (other.matchOne != null) { 103 matchOne = other.matchOne; 104 } 105 if (other.matchAll != null) { 106 matchAll = other.matchAll; 107 } 108 if (other.selectOneNoMatch != null) { 109 selectOneNoMatch = other.selectOneNoMatch; 110 } 111 if (other.maxPoolSize != null) { 112 maxPoolSize = other.maxPoolSize; 113 } 114 if (other.minPoolSize != null) { 115 minPoolSize = other.minPoolSize; 116 } 117 if (other.blockingTimeoutMillis != null) { 118 blockingTimeoutMillis = other.blockingTimeoutMillis; 119 } 120 if (other.idleTimeoutMinutes != null) { 121 idleTimeoutMinutes = other.idleTimeoutMinutes; 122 } 123 } 124 125 /** False if the boolean is null or FALSE, true otherwise. */ 126 private static boolean defaultFalse(Boolean bool) { 127 return Boolean.TRUE.equals(bool); 128 } 129 130 /** True if the boolean is null or TRUE, false otherwise. */ 131 private static boolean defaultTrue(Boolean bool) { 132 return !Boolean.FALSE.equals(bool); 133 } 134 135 private static int defaultInt(Integer value, int def) { 136 return value == null ? def : value.intValue(); 137 } 138 139 public String getName() { 140 return name; 141 } 142 143 public boolean getXAMode() { 144 return defaultTrue(xaMode); 145 } 146 147 public boolean getUseTransactionCaching() { 148 return defaultTrue(useTransactionCaching); 149 } 150 151 public boolean getUseThreadCaching() { 152 return defaultTrue(useThreadCaching); 153 } 154 155 public boolean getMatchOne() { 156 return defaultTrue(matchOne); 157 } 158 159 public boolean getMatchAll() { 160 return defaultTrue(matchAll); 161 } 162 163 public boolean getSelectOneNoMatch() { 164 return defaultFalse(selectOneNoMatch); 165 } 166 167 public int getMaxPoolSize() { 168 return defaultInt(maxPoolSize, DEFAULT_MAX_POOL_SIZE); 169 } 170 171 public int getMinPoolSize() { 172 return defaultInt(minPoolSize, DEFAULT_MIN_POOL_SIZE); 173 } 174 175 public int getBlockingTimeoutMillis() { 176 return defaultInt(blockingTimeoutMillis, DEFAULT_BLOCKING_TIMEOUT_MILLIS); 177 } 178 179 public int getIdleTimeoutMinutes() { 180 return defaultInt(idleTimeoutMinutes, DEFAULT_IDLE_TIMEOUT_MINUTES); 181 } 182 183 public void setName(String name) { 184 this.name = name; 185 } 186 187 public void setXAMode(boolean xaMode) { 188 this.xaMode = Boolean.valueOf(xaMode); 189 } 190 191 public void setUseTransactionCaching(boolean useTransactionCaching) { 192 this.useTransactionCaching = Boolean.valueOf(useTransactionCaching); 193 } 194 195 public void setUseThreadCaching(boolean useThreadCaching) { 196 this.useThreadCaching = Boolean.valueOf(useThreadCaching); 197 } 198 199 public void setMatchOne(boolean matchOne) { 200 this.matchOne = Boolean.valueOf(matchOne); 201 } 202 203 public void setMatchAll(boolean matchAll) { 204 this.matchAll = Boolean.valueOf(matchAll); 205 } 206 207 public void setSelectOneNoMatch(boolean selectOneNoMatch) { 208 this.selectOneNoMatch = Boolean.valueOf(selectOneNoMatch); 209 } 210 211 public void setMaxPoolSize(int maxPoolSize) { 212 this.maxPoolSize = Integer.valueOf(maxPoolSize); 213 } 214 215 public void setMinPoolSize(int minPoolSize) { 216 this.minPoolSize = Integer.valueOf(minPoolSize); 217 } 218 219 public void setBlockingTimeoutMillis(int blockingTimeoutMillis) { 220 this.blockingTimeoutMillis = Integer.valueOf(blockingTimeoutMillis); 221 } 222 223 public void setIdleTimeoutMinutes(int idleTimeoutMinutes) { 224 this.idleTimeoutMinutes = Integer.valueOf(idleTimeoutMinutes); 225 } 226 227 @XNode("@maxActive") 228 public void setMaxActive(int num) { 229 maxPoolSize = num; 230 LogFactory.getLog(NuxeoConnectionManagerConfiguration.class).warn( 231 "maxActive deprecated dbcp pool attribute usage, should use maxPoolSize geronimo pool attribute instead"); 232 } 233 234 @XNode("@maxIdle") 235 public void setMaxIdle(int num) { 236 minPoolSize = num; 237 LogFactory.getLog(NuxeoConnectionManagerConfiguration.class).warn( 238 "maxIdle deprecated dbcp pool attribute usage, should use minPoolSize geronimo pool attribute instead"); 239 } 240 241 @XNode("@maxWait") 242 public void setMaxWait(int num) { 243 blockingTimeoutMillis = num; 244 LogFactory.getLog(NuxeoConnectionManagerConfiguration.class).warn( 245 "maxWait deprecated dbcp pool attribute usage, should use blockingTimeoutMillis geronimo pool attribute instead"); 246 247 } 248}