| Method from org.apache.commons.dbcp.datasources.InstanceKeyObjectFactory Detail: |
public static void closeAll() throws Exception {
//Get iterator to loop over all instances of this datasource.
Iterator instanceIterator = instanceMap.entrySet().iterator();
while (instanceIterator.hasNext()) {
((InstanceKeyDataSource)
((Map.Entry) instanceIterator.next()).getValue()).close();
}
instanceMap.clear();
}
Close all pools associated with this class. |
protected static final Object deserialize(byte[] data) throws ClassNotFoundException, IOException {
ObjectInputStream in = null;
try {
in = new ObjectInputStream(new ByteArrayInputStream(data));
return in.readObject();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ex) {
}
}
}
}
used to set some properties saved within a Reference |
abstract protected InstanceKeyDataSource getNewInstance(Reference ref) throws ClassNotFoundException, IOException
Creates an instance of the subclass and sets any properties
contained in the Reference. |
public Object getObjectInstance(Object refObj,
Name name,
Context context,
Hashtable env) throws ClassNotFoundException, IOException {
// The spec says to return null if we can't create an instance
// of the reference
Object obj = null;
if (refObj instanceof Reference) {
Reference ref = (Reference) refObj;
if (isCorrectClass(ref.getClassName())) {
RefAddr ra = ref.get("instanceKey");
if (ra != null && ra.getContent() != null) {
// object was bound to jndi via Referenceable api.
obj = instanceMap.get(ra.getContent());
}
else
{
// tomcat jndi creates a Reference out of server.xml
// < ResourceParam > configuration and passes it to an
// instance of the factory given in server.xml.
String key = null;
if (name != null)
{
key = name.toString();
obj = instanceMap.get(key);
}
if (obj == null)
{
InstanceKeyDataSource ds = getNewInstance(ref);
setCommonProperties(ref, ds);
obj = ds;
if (key != null)
{
instanceMap.put(key, ds);
}
}
}
}
}
return obj;
}
implements ObjectFactory to create an instance of SharedPoolDataSource
or PerUserPoolDataSource |
abstract protected boolean isCorrectClass(String className)
|
static synchronized String registerNewInstance(InstanceKeyDataSource ds) {
int max = 0;
Iterator i = instanceMap.keySet().iterator();
while (i.hasNext()) {
Object obj = i.next();
if (obj instanceof String)
{
try {
max = Math.max(max, Integer.valueOf((String)obj).intValue());
}
catch (NumberFormatException e) {
// no sweat, ignore those keys
}
}
}
String instanceKey = String.valueOf(max + 1);
// put a placeholder here for now, so other instances will not
// take our key. we will replace with a pool when ready.
instanceMap.put(instanceKey, ds);
return instanceKey;
}
|
static void removeInstance(String key) {
instanceMap.remove(key);
}
|