craigmcc 02/01/16 09:42:40
Modified: conf/share struts-config_1_1.dtd
src/share/org/apache/struts/action ActionServlet.java
src/share/org/apache/struts/config ConfigRuleSet.java
DataSourceConfig.java
Log:
Repair configuration of data sources so that it works with custom
javax.sql.DataSource implementations again.
Remove the <data-source> properties that we deprecated in 1.0; now, everything
about a data source is configured with <set-property> elements.
Restore ActionServlet.initDataSources() -- but deprecate it -- in case
existing apps are using this as a hook to perform their own initialization.
Revision Changes Path
1.9 +6 -49 jakarta-struts/conf/share/struts-config_1_1.dtd
Index: struts-config_1_1.dtd
===================================================================
RCS file: /home/cvs/jakarta-struts/conf/share/struts-config_1_1.dtd,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- struts-config_1_1.dtd 15 Jan 2002 20:22:20 -0000 1.8
+++ struts-config_1_1.dtd 16 Jan 2002 17:42:40 -0000 1.9
@@ -11,7 +11,7 @@
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
- $Id: struts-config_1_1.dtd,v 1.8 2002/01/15 20:22:20 craigmcc Exp $
+ $Id: struts-config_1_1.dtd,v 1.9 2002/01/16 17:42:40 craigmcc Exp $
-->
@@ -112,60 +112,17 @@
source will be stored. Default is the value specified
by string constant Action.DATA_SOURCE_KEY.
- type Fully qualified Java class name of the implementation
- class (must implement javax.sql.DataSource). Default
- value is 'org.apache.struts.util.GenericDataSource'.
-
- NOTE: The following attributes are defined by the default data source
- implementation, and only take effect for that class or subclasses of
- that class.
-
- WARNING: The use of these attributes is deprecated. You should use
- nested <set-property> elements to configure *all* properties of
- your data source implementation.
-
- autoCommit The default auto-commit state for newly created
- connections.
-
- description The description of this data source.
-
- driverClass The Java class name of the JDBC driver to be used.
- [REQUIRED]
-
- loginTimeout The maximum number of seconds to wait for a connection
- to be created or returned. Default is driver dependent.
-
- maxCount The maximum number of connections to be created.
-
- minCount The minimum number of connections to be created.
-
- password The database password to use when connecting. [REQUIRED]
-
- readOnly The default read-only state for newly created
- connections.
-
- url The JDBC URL to use when connecting. [REQUIRED]
-
- user The database username to use when connecting. [REQUIRED]
-
+ type Fully qualified Java class name of the data source
+ implementation class. This class must implement
+ "javax.sql.DataSource" and be configurable totally
+ from JavaBeans properties.
+ [org.apache.struts.util.GenericDataSource]
-->
<!ELEMENT data-source (set-property*)>
<!ATTLIST data-source id ID #IMPLIED>
<!ATTLIST data-source className %ClassName; #IMPLIED>
<!ATTLIST data-source key %AttributeName; #IMPLIED>
<!ATTLIST data-source type %ClassName; #IMPLIED>
-<!-- All of the following attributes are deprecated. Use a nested -->
-<!-- set-property element to configure data source properties. -->
-<!ATTLIST data-source autoCommit %Boolean; #IMPLIED>
-<!ATTLIST data-source description CDATA #IMPLIED>
-<!ATTLIST data-source driverClass %ClassName; #IMPLIED>
-<!ATTLIST data-source loginTimeout %Integer; #IMPLIED>
-<!ATTLIST data-source maxCount %Integer; #IMPLIED>
-<!ATTLIST data-source minCount %Integer; #IMPLIED>
-<!ATTLIST data-source password CDATA #IMPLIED>
-<!ATTLIST data-source readOnly %Boolean; #IMPLIED>
-<!ATTLIST data-source url CDATA #IMPLIED>
-<!ATTLIST data-source user CDATA #IMPLIED>
<!-- The "global-exceptions" element configures the global handling of
1.86 +30 -8
jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java
Index: ActionServlet.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -r1.85 -r1.86
--- ActionServlet.java 15 Jan 2002 18:51:26 -0000 1.85
+++ ActionServlet.java 16 Jan 2002 17:42:40 -0000 1.86
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.85
2002/01/15 18:51:26 craigmcc Exp $
- * $Revision: 1.85 $
- * $Date: 2002/01/15 18:51:26 $
+ * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.86
2002/01/16 17:42:40 craigmcc Exp $
+ * $Revision: 1.86 $
+ * $Date: 2002/01/16 17:42:40 $
*
* ====================================================================
*
@@ -81,6 +81,7 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;
+import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.collections.FastHashMap;
import org.apache.commons.digester.Digester;
@@ -265,7 +266,7 @@
*
* @author Craig R. McClanahan
* @author Ted Husted
- * @version $Revision: 1.85 $ $Date: 2002/01/15 18:51:26 $
+ * @version $Revision: 1.86 $ $Date: 2002/01/16 17:42:40 $
*/
public class ActionServlet
@@ -799,8 +800,9 @@
new ServletContextWriter(getServletContext());
DataSourceConfig dscs[] = config.findDataSourceConfigs();
if (dscs == null) {
- return;
+ dscs = new DataSourceConfig[0];
}
+
dataSources.setFast(false);
for (int i = 0; i < dscs.length; i++) {
if (debug >= 1) {
@@ -809,9 +811,9 @@
}
DataSource ds = null;
try {
- // FIXME - Support user-specified data source classes again
- ds = new GenericDataSource();
- PropertyUtils.copyProperties(ds, dscs[i]);
+ Class clazz = Class.forName(dscs[i].getType());
+ ds = (DataSource) clazz.newInstance();
+ BeanUtils.populate(ds, dscs[i].getProperties());
ds.setLogWriter(scw);
if (ds instanceof GenericDataSource) {
((GenericDataSource) ds).open();
@@ -827,6 +829,11 @@
}
dataSources.setFast(true);
+ // Call deprecated method for backwards compatibility
+ if ("".equals(config.getPrefix())) {
+ initDataSources();
+ }
+
}
@@ -896,6 +903,21 @@
configDigester.register(registrations[i], url.toString());
}
return (configDigester);
+ }
+
+
+ /**
+ * Initialize data sources for the default application. This method
+ * signature is maintained only for backwards compatibility, and will
+ * be removed in a subsequent release.
+ *
+ * @deprecated Replaced by initApplicationDataSources() that takes
+ * an ApplicationConfig argument
+ */
+ protected void initDataSources() throws javax.servlet.ServletException {
+
+ ; // Implementation has been replaced in initApplicationDataSources()
+
}
1.5 +30 -6
jakarta-struts/src/share/org/apache/struts/config/ConfigRuleSet.java
Index: ConfigRuleSet.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/ConfigRuleSet.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ConfigRuleSet.java 15 Jan 2002 20:22:20 -0000 1.4
+++ ConfigRuleSet.java 16 Jan 2002 17:42:40 -0000 1.5
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/ConfigRuleSet.java,v 1.4
2002/01/15 20:22:20 craigmcc Exp $
- * $Revision: 1.4 $
- * $Date: 2002/01/15 20:22:20 $
+ * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/ConfigRuleSet.java,v 1.5
2002/01/16 17:42:40 craigmcc Exp $
+ * $Revision: 1.5 $
+ * $Date: 2002/01/16 17:42:40 $
*
* ====================================================================
*
@@ -64,7 +64,9 @@
import org.apache.commons.digester.Digester;
+import org.apache.commons.digester.Rule;
import org.apache.commons.digester.RuleSetBase;
+import org.xml.sax.Attributes;
/**
@@ -72,7 +74,7 @@
* configuration file (<code>struts-config.xml</code>).</p>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.4 $ $Date: 2002/01/15 20:22:20 $
+ * @version $Revision: 1.5 $ $Date: 2002/01/16 17:42:40 $
* @since Struts 1.1
*/
@@ -106,9 +108,9 @@
"addDataSourceConfig",
"org.apache.struts.config.DataSourceConfig");
- digester.addSetProperty
+ digester.addRule
("struts-config/data-sources/data-source/set-property",
- "property", "value");
+ new AddDataSourcePropertyRule(digester));
digester.addObjectCreate
("struts-config/action-mappings/action",
@@ -248,3 +250,25 @@
}
}
+
+
+/**
+ * Class that calls <code>addProperty()</code> for the top object
+ * on the stack, which must be a
+ * <code>org.apache.struts.config.DataSourceConfig</code>.
+ */
+
+final class AddDataSourcePropertyRule extends Rule {
+
+ public AddDataSourcePropertyRule(Digester digester) {
+ super(digester);
+ }
+
+ public void begin(Attributes attributes) throws Exception {
+ DataSourceConfig dsc = (DataSourceConfig) digester.peek();
+ dsc.addProperty(attributes.getValue("property"),
+ attributes.getValue("value"));
+ }
+
+}
+
1.3 +37 -151
jakarta-struts/src/share/org/apache/struts/config/DataSourceConfig.java
Index: DataSourceConfig.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/DataSourceConfig.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DataSourceConfig.java 13 Jan 2002 00:25:36 -0000 1.2
+++ DataSourceConfig.java 16 Jan 2002 17:42:40 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/DataSourceConfig.java,v
1.2 2002/01/13 00:25:36 craigmcc Exp $
- * $Revision: 1.2 $
- * $Date: 2002/01/13 00:25:36 $
+ * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/DataSourceConfig.java,v
1.3 2002/01/16 17:42:40 craigmcc Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/01/16 17:42:40 $
*
* ====================================================================
*
@@ -64,6 +64,9 @@
import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
import org.apache.struts.action.Action;
@@ -77,7 +80,7 @@
* of them may be ignored by custom data source implementations.</p>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.2 $ $Date: 2002/01/13 00:25:36 $
+ * @version $Revision: 1.3 $ $Date: 2002/01/16 17:42:40 $
* @since Struts 1.1
*/
@@ -89,48 +92,6 @@
/**
- * The default auto-commit state for newly created connections.
- */
- protected boolean autoCommit = true;
-
- public boolean getAutoCommit() {
- return (this.autoCommit);
- }
-
- public void setAutoCommit(boolean autoCommit) {
- this.autoCommit = autoCommit;
- }
-
-
- /**
- * The description of this data source.
- */
- protected String description = null;
-
- public String getDescription() {
- return (this.description);
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
-
- /**
- * The fully qualified Java class name of the JDBC driver to be used.
- */
- protected String driverClass = null;
-
- public String getDriverClass() {
- return (this.driverClass);
- }
-
- public void setDriverClass(String driverClass) {
- this.driverClass = driverClass;
- }
-
-
- /**
* The servlet context attribute key under which this data source
* is stored and made available.
*/
@@ -146,140 +107,65 @@
/**
- * The maximum number of seconds to wait for a connection to be created
- * or returned, or zero for no timeout.
+ * The custom configuration properties for this data source implementation.
*/
- protected int loginTimeout = 0;
+ protected HashMap properties = new HashMap();
- public int getLoginTimeout() {
- return (this.loginTimeout);
- }
-
- public void setLoginTimeout(int loginTimeout) {
- this.loginTimeout = loginTimeout;
+ public Map getProperties() {
+ return (this.properties);
}
/**
- * The maximum number of connections to be created, or zero for no limit.
+ * The fully qualified class name of the <code>javax.sql.DataSource</code>
+ * implementation class.
*/
- protected int maxCount = 0;
+ protected String type = "org.apache.struts.util.GenericDataSource";
- public int getMaxCount() {
- return (this.maxCount);
+ public String getType() {
+ return (this.type);
}
- public void setMaxCount(int maxCount) {
- this.maxCount = maxCount;
+ public void setType(String type) {
+ this.type = type;
}
- /**
- * The minimum number of connections to be created, or zero for no limit.
- */
- protected int minCount = 0;
-
- public int getMinCount() {
- return (this.minCount);
- }
-
- public void setMinCount(int minCount) {
- this.minCount = minCount;
- }
-
-
- /**
- * The database password to use when connecting.
- */
- protected String password = null;
-
- public String getPassword() {
- return (this.password);
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
-
- /**
- * The default read-only state for newly created connections.
- */
- protected boolean readOnly = false;
-
- public boolean getReadOnly() {
- return (this.readOnly);
- }
-
- public void setReadOnly(boolean readOnly) {
- this.readOnly = readOnly;
- }
-
-
- /**
- * The JDBC URL of the database to connect to.
- */
- protected String url = null;
-
- public String getUrl() {
- return (this.url);
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
+ // --------------------------------------------------------- Public Methods
/**
- * The database username to use when connecting.
+ * Add a new custom configuration property.
+ *
+ * @param name Custom property name
+ * @param value Custom property value
*/
- protected String user = null;
+ public void addProperty(String name, String value) {
- public String getUser() {
- return (this.user);
- }
+ properties.put(name, value);
- public void setUser(String user) {
- this.user = user;
}
- // --------------------------------------------------------- Public Methods
-
/**
* Return a String representation of this object.
*/
public String toString() {
StringBuffer sb = new StringBuffer("DataSourceConfig[");
- sb.append("autoCommit=");
- sb.append(this.autoCommit);
- if (this.description != null) {
- sb.append(",description=");
- sb.append(this.description);
- }
- sb.append(",driverClass=");
- sb.append(this.driverClass);
- if (this.loginTimeout != 0) {
- sb.append(",loginTimeout=");
- sb.append(this.loginTimeout);
- }
- if (this.maxCount != 0) {
- sb.append(",maxCount=");
- sb.append(this.maxCount);
- }
- if (this.minCount != 0) {
- sb.append(",minCount=");
- sb.append(this.minCount);
+ sb.append("key=");
+ sb.append(key);
+ sb.append(",type=");
+ sb.append(type);
+ Iterator names = properties.keySet().iterator();
+ while (names.hasNext()) {
+ String name = (String) names.next();
+ String value = (String) properties.get(name);
+ sb.append(',');
+ sb.append(name);
+ sb.append('=');
+ sb.append(value);
}
- sb.append("password=");
- sb.append(this.password);
- sb.append(",readOnly=");
- sb.append(this.readOnly);
- sb.append(",url=");
- sb.append(this.url);
- sb.append(",user=");
- sb.append(this.user);
sb.append("]");
return (sb.toString());
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>