Author: kkolinko
Date: Thu Jan 20 20:54:23 2011
New Revision: 1061506
URL: http://svn.apache.org/viewvc?rev=1061506&view=rev
Log:
https://issues.apache.org/bugzilla/show_bug.cgi?id=49543
Add the ability to specify a data source link, to use a shared datasource with
per application credentials.
(fhanik)
Backported documentation update from r1055989 as well.
Added:
tomcat/tc6.0.x/trunk/java/org/apache/naming/factory/DataSourceLinkFactory.java
- copied, changed from r1061505,
tomcat/trunk/java/org/apache/naming/factory/DataSourceLinkFactory.java
Modified:
tomcat/tc6.0.x/trunk/STATUS.txt
tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java
tomcat/tc6.0.x/trunk/java/org/apache/catalina/deploy/ContextResourceLink.java
tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
tomcat/tc6.0.x/trunk/webapps/docs/config/context.xml
Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=1061506&r1=1061505&r2=1061506&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Thu Jan 20 20:54:23 2011
@@ -108,11 +108,6 @@ PATCHES PROPOSED TO BACKPORT:
sufficient
-1:
-* Add helper class to allow a shared data source with different credentials
- http://people.apache.org/~fhanik/dslink.patch
- +1: fhanik, funkman, kkolinko
- -1:
-
* Fix very large memory leak in NIO connector
Additional patch (not important):
http://svn.apache.org/viewvc?rev=1061397&view=rev
Modified:
tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java?rev=1061506&r1=1061505&r2=1061506&view=diff
==============================================================================
---
tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java
(original)
+++
tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java
Thu Jan 20 20:54:23 2011
@@ -1062,7 +1062,18 @@ public class NamingContextListener
// Create a reference to the resource.
Reference ref = new ResourceLinkRef
- (resourceLink.getType(), resourceLink.getGlobal());
+ (resourceLink.getType(), resourceLink.getGlobal(),
+ resourceLink.getFactory(),null);
+ Iterator i = resourceLink.listProperties();
+ while (i.hasNext()) {
+ String key = i.next().toString();
+ Object val = resourceLink.getProperty(key);
+ if (val!=null) {
+ StringRefAddr refAddr = new StringRefAddr(key, val.toString());
+ ref.add(refAddr);
+ }
+ }
+
javax.naming.Context ctx =
"UserTransaction".equals(resourceLink.getName())
? compCtx : envCtx;
Modified:
tomcat/tc6.0.x/trunk/java/org/apache/catalina/deploy/ContextResourceLink.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/deploy/ContextResourceLink.java?rev=1061506&r1=1061505&r2=1061506&view=diff
==============================================================================
---
tomcat/tc6.0.x/trunk/java/org/apache/catalina/deploy/ContextResourceLink.java
(original)
+++
tomcat/tc6.0.x/trunk/java/org/apache/catalina/deploy/ContextResourceLink.java
Thu Jan 20 20:54:23 2011
@@ -49,7 +49,16 @@ public class ContextResourceLink extends
this.global = global;
}
+ private String factory = null;
+ public String getFactory() {
+ return factory;
+ }
+
+ public void setFactory(String factory) {
+ this.factory = factory;
+ }
+
// --------------------------------------------------------- Public Methods
Copied:
tomcat/tc6.0.x/trunk/java/org/apache/naming/factory/DataSourceLinkFactory.java
(from r1061505,
tomcat/trunk/java/org/apache/naming/factory/DataSourceLinkFactory.java)
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/naming/factory/DataSourceLinkFactory.java?p2=tomcat/tc6.0.x/trunk/java/org/apache/naming/factory/DataSourceLinkFactory.java&p1=tomcat/trunk/java/org/apache/naming/factory/DataSourceLinkFactory.java&r1=1061505&r2=1061506&rev=1061506&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/naming/factory/DataSourceLinkFactory.java
(original)
+++
tomcat/tc6.0.x/trunk/java/org/apache/naming/factory/DataSourceLinkFactory.java
Thu Jan 20 20:54:23 2011
@@ -54,7 +54,7 @@ public class DataSourceLinkFactory exten
* @param obj The reference object describing the DataSource
*/
@Override
- public Object getObjectInstance(Object obj, Name name, Context nameCtx,
Hashtable<?,?> environment)
+ public Object getObjectInstance(Object obj, Name name, Context nameCtx,
Hashtable environment)
throws NamingException {
Object result = super.getObjectInstance(obj, name, nameCtx,
environment);
// Can we process this request?
@@ -102,7 +102,7 @@ public class DataSourceLinkFactory exten
getConnection = ds.getClass().getMethod("getConnection",
String.class, String.class);
}
- @Override
+
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
if ("getConnection".equals(method.getName()) && (args==null ||
args.length==0)) {
Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=1061506&r1=1061505&r2=1061506&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Thu Jan 20 20:54:23 2011
@@ -46,6 +46,10 @@
<section name="Tomcat 6.0.31 (jfclere)">
<subsection name="Catalina">
<changelog>
+ <fix>
+ <bug>49543</bug>: Allow Tomcat to use shared data sources with per
+ application credentials. (fhanik)
+ </fix>
<add>
<bug>50205</bug>: Add the deployIgnorePaths attribute to the Host
element. Based on a patch by Jim Riggs. (markt/kkolinko)
@@ -458,7 +462,7 @@
</add>
<add>
Configure the Host Manager web application to use the new CSRF
- protection. To take advantge of this protection, the
<code>admin</code> role
+ protection. To take advantage of this protection, the
<code>admin</code> role
must be removed from all users and the new <code>admin-gui</code> and
<code>admin-script</code> roles used instead. (markt)
</add>
Modified: tomcat/tc6.0.x/trunk/webapps/docs/config/context.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/config/context.xml?rev=1061506&r1=1061505&r2=1061506&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/config/context.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/config/context.xml Thu Jan 20 20:54:23
2011
@@ -869,8 +869,72 @@
application when it performs a lookup for this resource link.</p>
</attribute>
+ <attribute name="factory" required="false">
+ <p>The fully qualified Java class name for the class creating these
objects.
+ This class should implement the
<code>javax.naming.spi.ObjectFactory</code> interface.</p>
+ </attribute>
</attributes>
+ <p>When the attribute
<code>factory="org.apache.naming.factory.DataSourceLinkFactory"</code>
the resource link can be used with
+ two additional attributes to allow a shared data source to be used with
different credentials.
+ When these two additional attributes are used in combination with the
<code>javax.sql.DataSource</code>
+ type, different contexts can share a global data source with different
credentials.
+ Under the hood, what happens is that a call to <a
href="http://download.oracle.com/javase/6/docs/api/javax/sql/DataSource.html#getConnection()"><code>getConnection()</code></a>
+ is simply translated to a call <a
href="http://download.oracle.com/javase/6/docs/api/javax/sql/DataSource.html#getConnection(java.lang.String,%20java.lang.String)">
+ <code>getConnection(username, password)</code></a> on the global data
source. This is an easy way to get code to be transparent to what schemas are
being used,
+ yet be able to control connections (or pools) in the global
configuration.
+ </p>
+ <attributes>
+
+ <attribute name="username" required="false">
+ <p><code>username</code> value for the <code>getConnection(username,
password)</code>
+ call on the linked global DataSource.
+ </p>
+ </attribute>
+
+ <attribute name="password" required="false">
+ <p><code>password</code> value for the <code>getConnection(username,
password)</code>
+ call on the linked global DataSource.
+ </p>
+ </attribute>
+
+ </attributes>
+ <p>Shared Data Source Example</p>
+<source>
+<GlobalNamingResources ...>
+ ...
+ <Resource name="sharedDataSource"
+ global="sharedDataSource"
+ type="javax.sql.DataSource"
+ username="bar"
+ password="barpass"
+
+ ...
+ ...
+</GlobalNamingResources>
+
+<Context path="/foo"...>
+ ...
+ <ResourceLink
+ name="appDataSource"
+ global="sharedDataSource"
+ type="javax.sql.DataSource"
+ factory="org.apache.naming.factory.DataSourceLinkFactory"
+ username="foo"
+ password="foopass"
+ ...
+</Context>
+<Context path="/bar"...>
+ ...
+ <ResourceLink
+ name="appDataSource"
+ global="sharedDataSource"
+ type="javax.sql.DataSource"
+ ...
+</Context>
+</source>
+ <p>When a request for <code>getConnection()</code> is made in the
<code>/foo</code> context, the request is translated into
+ <code>getConnection("foo","foopass")</code>, while
a request in the <code>/bar</code> gets passed straight through.</p>
</subsection>
<subsection name="Transaction">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]