/*
$Header: /cvsroot/xorm/xorm/src/org/xorm/datastore/ConnectionInfo.java,v 1.8 2003/09/26 20:23:54 wbiggs Exp $
This file is part of XORM.
XORM is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
XORM 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with XORM; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.xorm.datastore;
import java.util.Properties;
import java.util.Iterator;
import java.util.Map;
import javax.jdo.JDOFatalUserException;
import javax.naming.InitialContext;
import org.xorm.Configurable;
import org.xorm.InterfaceManagerFactory;
/**
* This is the base class for connection information. A ConnectionInfo
* object is used to acquire a DatastoreDriver instance. The attributes
* of this class may or may not be useful to subclasses, but they reflect
* the configuration detail that is standard in JDO.
*/
public abstract class ConnectionInfo implements Configurable {
protected String connectionUserName;
protected String connectionPassword;
protected String connectionURL;
protected String connectionDriverName;
protected String connectionFactoryName;
protected String connectionFactory2Name;
protected Object connectionFactory;
protected Object connectionFactory2;
protected int minPool;
protected int maxPool;
protected int msWait;
protected Properties properties;
protected InterfaceManagerFactory factory;
public void setFactory(InterfaceManagerFactory factory) {
this.factory = factory;
}
public Properties getProperties() {
return properties;
}
public void setProperties(Properties properties) {
this.properties = properties;
// iterate through properties
Iterator i = properties.entrySet().iterator();
while (i.hasNext()) {
Map.Entry entry = (Map.Entry) i.next();
String key = (String) entry.getKey();
String value = (String) entry.getValue();
if ("javax.jdo.option.ConnectionURL".equals(key)) {
setConnectionURL(value);
} else if ("javax.jdo.option.ConnectionUserName".equals(key)) {
setConnectionUserName(value);
} else if ("javax.jdo.option.ConnectionPassword".equals(key)) {
setConnectionPassword(value);
} else if ("javax.jdo.option.ConnectionDriverName".equals(key)) {
setConnectionDriverName(value);
} else if ("javax.jdo.option.ConnectionFactoryName".equals(key)) {
setConnectionFactoryName(value);
} else if ("javax.jdo.option.ConnectionFactory2Name".equals(key)) {
setConnectionFactory2Name(value);
} else if ("javax.jdo.option.MinPool".equals(key)) {
setMinPool(Integer.parseInt(value));
} else if ("javax.jdo.option.MaxPool".equals(key)) {
setMaxPool(Integer.parseInt(value));
}
}
}
public void setConnectionUserName(String s) {
connectionUserName = s;
}
public String getConnectionUserName() {
return connectionUserName;
}
public void setConnectionPassword(String s) {
connectionPassword = s;
}
public void setConnectionURL(String s) {
connectionURL = s;
}
public String getConnectionURL() {
return connectionURL;
}
public void setConnectionDriverName(String s) {
connectionDriverName = s;
}
public String getConnectionDriverName() {
return connectionDriverName;
}
public int getMaxPool() {
return maxPool;
}
public void setMaxPool(int i) {
maxPool = i;
}
public int getMinPool() {
return minPool;
}
public void setMinPool(int i) {
minPool = i;
}
public int getMsWait() {
return msWait;
}
public void setMsWait(int i) {
msWait = i;
}
public void setConnectionFactoryName(String s) {
connectionFactoryName = s;
connectionFactory = resolveJNDI(s);
}
public String getConnectionFactoryName() {
return connectionFactoryName;
}
public void setConnectionFactory(Object o) {
connectionFactory = o;
}
public Object getConnectionFactory() {
return connectionFactory;
}
public void setConnectionFactory2Name(String s) {
connectionFactory2Name = s;
connectionFactory2 = resolveJNDI(s);
}
public String getConnectionFactory2Name() {
return connectionFactory2Name;
}
public void setConnectionFactory2(Object o) {
connectionFactory2 = o;
}
public Object getConnectionFactory2() {
return connectionFactory2;
}
public static Object resolveJNDI(String name) {
try {
InitialContext initCtx = new InitialContext();
return initCtx.lookup(name);
} catch (Exception e) {
throw new JDOFatalUserException("Cannot resolve JNDI name " + name, e);
}
}
/**
* Returns a new DatastoreDriver that interacts with the datastore
* described by this ConnectionInfo object. This method must
* be implemented by subclasses.
*/
public abstract DatastoreDriver getDriver();
public Table describeTable(String tableName) {
throw new JDOFatalUserException("No driver support for runtime metadata");
}
/** Release resources. Default implementation of this does nothing. */
public void close() { }
}