You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:25:10 UTC

[sling-org-apache-sling-datasource] annotated tag org.apache.sling.datasource-1.0.0 created (now a38a658)

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a change to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git.


      at a38a658  (tag)
 tagging 322a17fa00bf8b683bb7e51bc4f5eef565027003 (commit)
      by Chetan Mehrotra
      on Thu Jan 15 11:23:11 2015 +0000

- Log -----------------------------------------------------------------
org.apache.sling.datasource-1.0.0
-----------------------------------------------------------------------

This annotated tag includes the following new commits:

     new a836938  SLING-3574 - JDBC DataSource Provider bundle
     new e0f92a3  SLING-3580 - Remove embedded Tomcat Juli jar by overriding LogFactory which delegates to Slf4j
     new 6019938  SLING-3574 - JDBC DataSource Provider bundle
     new 898ba43  SLING-3580 - Remove embedded Tomcat Juli jar by overriding LogFactory which delegates to Slf4j
     new 6958fa8  SLING-3637 - Create connection pool lazily in DataSource Provider bundle
     new d5aa6dd  SLING-3642 - Support modifying of DataSource properties at runtime without restart
     new 1d473ea  SLING-3574 - JDBC DataSource Provider bundle
     new f88c563  SLING-3574 - JDBC DataSource Provider bundle
     new 71f8e62  Update to latest parent pom 20
     new 52b427b  Update to Sling Parent POM 22 with baselining enabled
     new 814eded  SLING-4147 - Remove extensions from package name org.apache.sling.extensions.datasource.internal
     new 47452e2  SLING-3735 - support JNDI lookup in JDBC DataSource Provider
     new c45a40c  SLING-3735 - support JNDI lookup in JDBC DataSource Provider
     new 3f006c8  Preparing for release. -- Adding scm info -- Fixing formatting of initial line
     new ba2eefd  [maven-release-plugin] prepare release org.apache.sling.extensions.datasource-1.0.0
     new ce22693  [maven-release-plugin] prepare for next development iteration
     new 4d503bd  SLING-4147 - Remove extensions from package name org.apache.sling.extensions.datasource.internal
     new 3a4bf46  SLING-4147 - Remove extensions from package name org.apache.sling.extensions.datasource.internal
     new c311803  Reverting the version back to 0.0.1-SNAPSHOT so as to reattempt the release for 1.0.0. again!
     new be009e1  SLING-4147 - Remove extensions from package name org.apache.sling.extensions.datasource.internal
     new c96dfc8  [maven-release-plugin] prepare release org.apache.sling.datasource-1.0.0
     new 322a17f  [maven-release-plugin]  copy for tag org.apache.sling.datasource-1.0.0

The 22 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


-- 
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].

[sling-org-apache-sling-datasource] 02/22: SLING-3580 - Remove embedded Tomcat Juli jar by overriding LogFactory which delegates to Slf4j

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit e0f92a3a6a871fda5508edbc947d07c239d8ade0
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Tue May 20 11:43:26 2014 +0000

    SLING-3580 - Remove embedded Tomcat Juli jar by overriding LogFactory which delegates to Slf4j
    
    Adding Log and LogFactory implementations which delegates to Slf4j
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1596210 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |  15 +-
 .../java/org/apache/juli/logging/DirectJDKLog.java | 110 ----------
 src/main/java/org/apache/juli/logging/Log.java     | 236 +++++++++++++++++++++
 .../java/org/apache/juli/logging/LogFactory.java   | 114 ++++++++++
 4 files changed, 359 insertions(+), 116 deletions(-)

diff --git a/pom.xml b/pom.xml
index 21ed802..3a67c1f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -59,10 +59,12 @@
         <extensions>true</extensions>
         <configuration>
           <instructions>
+            <Export-Package>
+              !org.apache.juli.logging
+            </Export-Package>
             <Embed-Dependency>
               org.apache.sling.commons.osgi;inline=org/apache/sling/commons/osgi/PropertiesUtil.class,
               tomcat-jdbc,
-              tomcat-juli
             </Embed-Dependency>
           </instructions>
         </configuration>
@@ -131,11 +133,12 @@
       <groupId>org.apache.tomcat</groupId>
       <artifactId>tomcat-jdbc</artifactId>
       <version>7.0.53</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.tomcat</groupId>
-      <artifactId>tomcat-juli</artifactId>
-      <version>7.0.53</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.tomcat</groupId>
+          <artifactId>tomcat-juli</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
 
     <!-- OSGi test -->
diff --git a/src/main/java/org/apache/juli/logging/DirectJDKLog.java b/src/main/java/org/apache/juli/logging/DirectJDKLog.java
deleted file mode 100644
index f49ac08..0000000
--- a/src/main/java/org/apache/juli/logging/DirectJDKLog.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.juli.logging;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Overriding the DirectJDKLog impl to delegate the logging to Slf4j
- */
-@SuppressWarnings("UnusedDeclaration")
-class DirectJDKLog implements Log {
-    private final Logger logger;
-
-    public DirectJDKLog(String name) {
-        this.logger = LoggerFactory.getLogger(name);
-    }
-
-    static Log getInstance(String name) {
-        return new DirectJDKLog( name );
-    }
-
-    public boolean isDebugEnabled() {
-        return logger.isDebugEnabled();
-    }
-
-    public boolean isErrorEnabled() {
-        return logger.isErrorEnabled();
-    }
-
-    public boolean isFatalEnabled() {
-        return logger.isErrorEnabled();
-    }
-
-    public boolean isInfoEnabled() {
-        return logger.isInfoEnabled();
-    }
-
-    public boolean isTraceEnabled() {
-        return logger.isTraceEnabled();
-    }
-
-    public boolean isWarnEnabled() {
-        return logger.isWarnEnabled();
-    }
-
-    public void trace(Object message) {
-        logger.trace(String.valueOf(message));
-    }
-
-    public void trace(Object message, Throwable t) {
-        logger.trace(String.valueOf(message), t);
-    }
-
-    public void debug(Object message) {
-        logger.debug(String.valueOf(message));
-    }
-
-    public void debug(Object message, Throwable t) {
-        logger.debug(String.valueOf(message), t);
-    }
-
-    public void info(Object message) {
-        logger.info(String.valueOf(message));
-    }
-
-    public void info(Object message, Throwable t) {
-        logger.info(String.valueOf(message), t);
-    }
-
-    public void warn(Object message) {
-        logger.warn(String.valueOf(message));
-    }
-
-    public void warn(Object message, Throwable t) {
-        logger.warn(String.valueOf(message), t);
-    }
-
-    public void error(Object message) {
-        logger.error(String.valueOf(message));
-    }
-
-    public void error(Object message, Throwable t) {
-        logger.error(String.valueOf(message), t);
-    }
-
-    public void fatal(Object message) {
-        logger.error(String.valueOf(message));
-    }
-
-    public void fatal(Object message, Throwable t) {
-        logger.error(String.valueOf(message), t);
-    }
-}
diff --git a/src/main/java/org/apache/juli/logging/Log.java b/src/main/java/org/apache/juli/logging/Log.java
new file mode 100644
index 0000000..daf5226
--- /dev/null
+++ b/src/main/java/org/apache/juli/logging/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */ 
+
+
+package org.apache.juli.logging;
+
+/**
+ * <p>A simple logging interface abstracting logging APIs.  In order to be
+ * instantiated successfully by {@link LogFactory}, classes that implement
+ * this interface must have a constructor that takes a single String
+ * parameter representing the "name" of this Log.</p>
+ *
+ * <p> The six logging levels used by <code>Log</code> are (in order):
+ * <ol>
+ * <li>trace (the least serious)</li>
+ * <li>debug</li>
+ * <li>info</li>
+ * <li>warn</li>
+ * <li>error</li>
+ * <li>fatal (the most serious)</li>
+ * </ol>
+ * The mapping of these log levels to the concepts used by the underlying
+ * logging system is implementation dependent.
+ * The implementation should ensure, though, that this ordering behaves
+ * as expected.</p>
+ *
+ * <p>Performance is often a logging concern.
+ * By examining the appropriate property,
+ * a component can avoid expensive operations (producing information
+ * to be logged).</p>
+ *
+ * <p> For example,
+ * <code><pre>
+ *    if (log.isDebugEnabled()) {
+ *        ... do something expensive ...
+ *        log.debug(theResult);
+ *    }
+ * </pre></code>
+ * </p>
+ *
+ * <p>Configuration of the underlying logging system will generally be done
+ * external to the Logging APIs, through whatever mechanism is supported by
+ * that system.</p>
+ *
+ * @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
+ * @author Rod Waldhoff
+ */
+@SuppressWarnings("UnusedDeclaration")
+public interface Log {
+
+
+    // ----------------------------------------------------- Logging Properties
+
+
+    /**
+     * <p> Is debug logging currently enabled? </p>
+     *
+     * <p> Call this method to prevent having to perform expensive operations
+     * (for example, <code>String</code> concatenation)
+     * when the log level is more than debug. </p>
+     */
+    public boolean isDebugEnabled();
+
+
+    /**
+     * <p> Is error logging currently enabled? </p>
+     *
+     * <p> Call this method to prevent having to perform expensive operations
+     * (for example, <code>String</code> concatenation)
+     * when the log level is more than error. </p>
+     */
+    public boolean isErrorEnabled();
+
+
+    /**
+     * <p> Is fatal logging currently enabled? </p>
+     *
+     * <p> Call this method to prevent having to perform expensive operations
+     * (for example, <code>String</code> concatenation)
+     * when the log level is more than fatal. </p>
+     */
+    public boolean isFatalEnabled();
+
+
+    /**
+     * <p> Is info logging currently enabled? </p>
+     *
+     * <p> Call this method to prevent having to perform expensive operations
+     * (for example, <code>String</code> concatenation)
+     * when the log level is more than info. </p>
+     */
+    public boolean isInfoEnabled();
+
+
+    /**
+     * <p> Is trace logging currently enabled? </p>
+     *
+     * <p> Call this method to prevent having to perform expensive operations
+     * (for example, <code>String</code> concatenation)
+     * when the log level is more than trace. </p>
+     */
+    public boolean isTraceEnabled();
+
+
+    /**
+     * <p> Is warn logging currently enabled? </p>
+     *
+     * <p> Call this method to prevent having to perform expensive operations
+     * (for example, <code>String</code> concatenation)
+     * when the log level is more than warn. </p>
+     */
+    public boolean isWarnEnabled();
+
+
+    // -------------------------------------------------------- Logging Methods
+
+
+    /**
+     * <p> Log a message with trace log level. </p>
+     *
+     * @param message log this message
+     */
+    public void trace(Object message);
+
+
+    /**
+     * <p> Log an error with trace log level. </p>
+     *
+     * @param message log this message
+     * @param t log this cause
+     */
+    public void trace(Object message, Throwable t);
+
+
+    /**
+     * <p> Log a message with debug log level. </p>
+     *
+     * @param message log this message
+     */
+    public void debug(Object message);
+
+
+    /**
+     * <p> Log an error with debug log level. </p>
+     *
+     * @param message log this message
+     * @param t log this cause
+     */
+    public void debug(Object message, Throwable t);
+
+
+    /**
+     * <p> Log a message with info log level. </p>
+     *
+     * @param message log this message
+     */
+    public void info(Object message);
+
+
+    /**
+     * <p> Log an error with info log level. </p>
+     *
+     * @param message log this message
+     * @param t log this cause
+     */
+    public void info(Object message, Throwable t);
+
+
+    /**
+     * <p> Log a message with warn log level. </p>
+     *
+     * @param message log this message
+     */
+    public void warn(Object message);
+
+
+    /**
+     * <p> Log an error with warn log level. </p>
+     *
+     * @param message log this message
+     * @param t log this cause
+     */
+    public void warn(Object message, Throwable t);
+
+
+    /**
+     * <p> Log a message with error log level. </p>
+     *
+     * @param message log this message
+     */
+    public void error(Object message);
+
+
+    /**
+     * <p> Log an error with error log level. </p>
+     *
+     * @param message log this message
+     * @param t log this cause
+     */
+    public void error(Object message, Throwable t);
+
+
+    /**
+     * <p> Log a message with fatal log level. </p>
+     *
+     * @param message log this message
+     */
+    public void fatal(Object message);
+
+
+    /**
+     * <p> Log an error with fatal log level. </p>
+     *
+     * @param message log this message
+     * @param t log this cause
+     */
+    public void fatal(Object message, Throwable t);
+
+
+}
diff --git a/src/main/java/org/apache/juli/logging/LogFactory.java b/src/main/java/org/apache/juli/logging/LogFactory.java
new file mode 100644
index 0000000..c93908c
--- /dev/null
+++ b/src/main/java/org/apache/juli/logging/LogFactory.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.juli.logging;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LogFactory {
+
+    public static Log getLog(String name){
+        return new Slf4jLog(name);
+    }
+
+    public static Log getLog(Class<?> clazz){
+        return getLog(clazz.getName());
+    }
+
+    private static class Slf4jLog implements Log {
+        private final Logger logger;
+
+        public Slf4jLog(String name) {
+            this.logger = LoggerFactory.getLogger(name);
+        }
+
+        public boolean isDebugEnabled() {
+            return logger.isDebugEnabled();
+        }
+
+        public boolean isErrorEnabled() {
+            return logger.isErrorEnabled();
+        }
+
+        public boolean isFatalEnabled() {
+            return logger.isErrorEnabled();
+        }
+
+        public boolean isInfoEnabled() {
+            return logger.isInfoEnabled();
+        }
+
+        public boolean isTraceEnabled() {
+            return logger.isTraceEnabled();
+        }
+
+        public boolean isWarnEnabled() {
+            return logger.isWarnEnabled();
+        }
+
+        public void trace(Object message) {
+            logger.trace(String.valueOf(message));
+        }
+
+        public void trace(Object message, Throwable t) {
+            logger.trace(String.valueOf(message), t);
+        }
+
+        public void debug(Object message) {
+            logger.debug(String.valueOf(message));
+        }
+
+        public void debug(Object message, Throwable t) {
+            logger.debug(String.valueOf(message), t);
+        }
+
+        public void info(Object message) {
+            logger.info(String.valueOf(message));
+        }
+
+        public void info(Object message, Throwable t) {
+            logger.info(String.valueOf(message), t);
+        }
+
+        public void warn(Object message) {
+            logger.warn(String.valueOf(message));
+        }
+
+        public void warn(Object message, Throwable t) {
+            logger.warn(String.valueOf(message), t);
+        }
+
+        public void error(Object message) {
+            logger.error(String.valueOf(message));
+        }
+
+        public void error(Object message, Throwable t) {
+            logger.error(String.valueOf(message), t);
+        }
+
+        public void fatal(Object message) {
+            logger.error(String.valueOf(message));
+        }
+
+        public void fatal(Object message, Throwable t) {
+            logger.error(String.valueOf(message), t);
+        }
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 16/22: [maven-release-plugin] prepare for next development iteration

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit ce22693210d2bafbd242e2687a506ab2ec83ce86
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 15 07:26:45 2015 +0000

    [maven-release-plugin] prepare for next development iteration
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1651956 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index d27a123..ddd8fa7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
 
   <artifactId>org.apache.sling.extensions.datasource</artifactId>
   <packaging>bundle</packaging>
-  <version>1.0.0</version>
+  <version>1.0.1-SNAPSHOT</version>
 
   <name>Apache Sling DataSource Provider</name>
   <description>
@@ -51,9 +51,9 @@
   </properties>
 
   <scm>
-    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.extensions.datasource-1.0.0</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.extensions.datasource-1.0.0</developerConnection>
-    <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.extensions.datasource-1.0.0</url>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource</developerConnection>
+    <url>http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/datasource</url>
   </scm>
 
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 09/22: Update to latest parent pom 20

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit 71f8e62b236dd32b2216f3aab9d5c1608c3a133a
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Sep 2 14:49:28 2014 +0000

    Update to latest parent pom 20
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1622027 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 721d31e..766911f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@
   <parent>
     <groupId>org.apache.sling</groupId>
     <artifactId>sling</artifactId>
-    <version>18</version>
+    <version>20</version>
   </parent>
 
   <artifactId>org.apache.sling.extensions.datasource</artifactId>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 20/22: SLING-4147 - Remove extensions from package name org.apache.sling.extensions.datasource.internal

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit be009e1abbec1965c33f25ba56ab9246f2b2b179
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 15 11:19:51 2015 +0000

    SLING-4147 - Remove extensions from package name org.apache.sling.extensions.datasource.internal
    
    -- Dropping the coverage profile as parent pom has explicit support for that
    -- Reverting the version to 0.0.1-SNAPSHOT so at to attempt release again
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1652062 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 34 ----------------------------------
 1 file changed, 34 deletions(-)

diff --git a/pom.xml b/pom.xml
index 1ea501f..944710c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -250,39 +250,5 @@
         </plugins>
       </build>
     </profile>
-    <profile>
-      <id>coverage</id>
-      <build>
-        <plugins>
-          <plugin>
-            <groupId>org.jacoco</groupId>
-            <artifactId>jacoco-maven-plugin</artifactId>
-            <executions>
-              <!-- Default to setup argLine required by surefire -->
-              <execution>
-                <id>prepare-agent-surefire</id>
-                <phase>test-compile</phase>
-                <goals>
-                  <goal>prepare-agent</goal>
-                </goals>
-                <configuration>
-                  <propertyName>coverage.command</propertyName>
-                  <includes>
-                    <include>org.apache.sling.datasource.internal.*</include>
-                  </includes>
-                </configuration>
-              </execution>
-              <execution>
-                <id>report</id>
-                <phase>post-integration-test</phase>
-                <goals>
-                  <goal>report</goal>
-                </goals>
-              </execution>
-            </executions>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
   </profiles>
 </project>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 07/22: SLING-3574 - JDBC DataSource Provider bundle

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit 1d473ea74e92e01130411a9debf332e6af83291b
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Wed Jun 4 14:02:30 2014 +0000

    SLING-3574 - JDBC DataSource Provider bundle
    
    Updating docs
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1600216 13f79535-47bb-0310-9956-ffa450edef68
---
 README.md | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 381e79f..42f9f2d 100644
--- a/README.md
+++ b/README.md
@@ -4,9 +4,10 @@ Apache Sling DataSource Provider
 This bundle enables creating and configuring JDBC DataSource in OSGi environment based on 
 OSGi configuration. It uses [Tomcat JDBC Pool][1] as the JDBC Connection Pool provider.
 
-1. Supports configuring the DataSource based on OSGi config wihich rich metatype
+1. Supports configuring the DataSource based on OSGi config with rich metatype
 2. Supports deploying of JDBC Driver as independent bundles and not as fragment
 3. Exposes the DataSource stats as JMX MBean 
+4. Supports updating of DataSource connection pool properties at runtime without restart
 
 Driver Loading
 --------------
@@ -37,6 +38,10 @@ Configuration
 If Felix WebConsole is used then you can configure it via Configuration UI at
 http://localhost:8080/system/console/configMgr/org.apache.sling.extensions.datasource.DataSourceFactory
 
+![Web Console Config](http://sling.apache.org/documentation/development/sling-datasource-config.png)
+
+Using the config ui above one can directly configure most of the properties as explained in [Tomcat Docs][1]
+
 Usage
 -----
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 15/22: [maven-release-plugin] prepare release org.apache.sling.extensions.datasource-1.0.0

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit ba2eefdfa123a6c0cac78da23c2215c31ca76ce9
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 15 07:26:38 2015 +0000

    [maven-release-plugin] prepare release org.apache.sling.extensions.datasource-1.0.0
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1651954 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 489b4d6..d27a123 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
 
   <artifactId>org.apache.sling.extensions.datasource</artifactId>
   <packaging>bundle</packaging>
-  <version>0.0.1-SNAPSHOT</version>
+  <version>1.0.0</version>
 
   <name>Apache Sling DataSource Provider</name>
   <description>
@@ -51,9 +51,9 @@
   </properties>
 
   <scm>
-    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource</developerConnection>
-    <url>http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/datasource</url>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.extensions.datasource-1.0.0</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.extensions.datasource-1.0.0</developerConnection>
+    <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.extensions.datasource-1.0.0</url>
   </scm>
 
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 03/22: SLING-3574 - JDBC DataSource Provider bundle

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit 6019938eca5f6e25b8a8359bc36a8d8e3b48fffc
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Tue May 20 11:43:50 2014 +0000

    SLING-3574 - JDBC DataSource Provider bundle
    
    Adding assertions for service properties
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1596211 13f79535-47bb-0310-9956-ffa450edef68
---
 .../java/org/apache/sling/extensions/datasource/DataSourceIT.java   | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/test/java/org/apache/sling/extensions/datasource/DataSourceIT.java b/src/test/java/org/apache/sling/extensions/datasource/DataSourceIT.java
index 08720e2..e75e962 100644
--- a/src/test/java/org/apache/sling/extensions/datasource/DataSourceIT.java
+++ b/src/test/java/org/apache/sling/extensions/datasource/DataSourceIT.java
@@ -56,6 +56,10 @@ public class DataSourceIT extends DataSourceTestBase{
         Dictionary<String, Object> p = new Hashtable<String, Object>();
         p.put("url","jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
         p.put("datasource.name","test");
+        p.put("datasource.svc.properties",new String[]{
+                "initialSize=5",
+                "testOnBorrow=true",
+        });
         p.put("maxActive",70);
         config.update(p);
 
@@ -72,6 +76,8 @@ public class DataSourceIT extends DataSourceTestBase{
 
         //Cannot access directly so access via reflection
         assertEquals("70", getProperty(ds, "poolProperties.maxActive"));
+        assertEquals("5", getProperty(ds, "poolProperties.initialSize"));
+        assertEquals("true", getProperty(ds, "poolProperties.testOnBorrow"));
     }
 
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 19/22: Reverting the version back to 0.0.1-SNAPSHOT so as to reattempt the release for 1.0.0. again!

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit c311803f54af83c7ca32447e94e59228e7a7e5ed
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 15 11:19:43 2015 +0000

    Reverting the version back to 0.0.1-SNAPSHOT so as to reattempt the release for 1.0.0. again!
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1652061 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index f078ce3..1ea501f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
 
   <artifactId>org.apache.sling.datasource</artifactId>
   <packaging>bundle</packaging>
-  <version>1.0.1-SNAPSHOT</version>
+  <version>0.0.1-SNAPSHOT</version>
 
   <name>Apache Sling DataSource Provider</name>
   <description>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 13/22: SLING-3735 - support JNDI lookup in JDBC DataSource Provider

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit c45a40ce185d4d048250c0116ad2c64565f9917a
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Mon Nov 10 07:35:34 2014 +0000

    SLING-3735 - support JNDI lookup in JDBC DataSource Provider
    
    Update the help doc
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1637804 13f79535-47bb-0310-9956-ffa450edef68
---
 .../org/apache/sling/datasource/internal/JNDIDataSourceFactory.java    | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/datasource/internal/JNDIDataSourceFactory.java b/src/main/java/org/apache/sling/datasource/internal/JNDIDataSourceFactory.java
index 07108ec..925b548 100644
--- a/src/main/java/org/apache/sling/datasource/internal/JNDIDataSourceFactory.java
+++ b/src/main/java/org/apache/sling/datasource/internal/JNDIDataSourceFactory.java
@@ -71,7 +71,8 @@ public class JNDIDataSourceFactory {
     @Property(
             label = "JNDI Properties",
             description = "Set the environment for the JNDI InitialContext i.e. properties passed on to InitialContext " +
-                    "for performing the JNDI instance lookup",
+                    "for performing the JNDI instance lookup. Each row form a map entry where each row format be propertyName=property " +
+                    "e.g. java.naming.factory.initial=exampleFactory",
             value = {},
             cardinality = 1024)
     static final String PROP_JNDI_PROPS = "jndi.properties";

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 12/22: SLING-3735 - support JNDI lookup in JDBC DataSource Provider

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit 47452e2a08bccdf052aa92e38ae49108cb07ab62
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Mon Nov 10 07:05:08 2014 +0000

    SLING-3735 - support JNDI lookup in JDBC DataSource Provider
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1637799 13f79535-47bb-0310-9956-ffa450edef68
---
 README.md                                          |  70 +++++----
 .../datasource/internal/DataSourceFactory.java     |   6 +-
 .../datasource/internal/JNDIDataSourceFactory.java | 160 +++++++++++++++++++++
 .../OSGI-INF/metatype/metatype.properties          |   2 +-
 4 files changed, 207 insertions(+), 31 deletions(-)

diff --git a/README.md b/README.md
index f987e4d..0da8c3e 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,11 @@
-Apache Sling DataSource Provider
-================================
+# Apache Sling DataSource Provider
+
+DataSource provider bundle supports two type of DataSource
+
+1. Pooled Connection DataSource
+2. JNDI DataSource
+
+## Pooled Connection DataSource Provider
 
 This bundle enables creating and configuring JDBC DataSource in OSGi environment based on 
 OSGi configuration. It uses [Tomcat JDBC Pool][1] as the JDBC Connection Pool provider.
@@ -9,8 +15,7 @@ OSGi configuration. It uses [Tomcat JDBC Pool][1] as the JDBC Connection Pool pr
 3. Exposes the DataSource stats as JMX MBean 
 4. Supports updating of DataSource connection pool properties at runtime without restart
 
-Driver Loading
---------------
+### Driver Loading
 
 Loading of JDBC driver is tricky on OSGi env. Mostly one has to attach the Driver bundle as a
 fragment bundle to the code which creates the JDBC Connection. 
@@ -28,8 +33,7 @@ bundle to Driver class supported by it. With this feature there is no need to wr
 bundle as fragment to DataSource provider bundle
 
 
-Configuration
--------------
+### Configuration
 
 1. Install the current bundle
 2. Install the JDBC Driver bundle
@@ -42,26 +46,7 @@ http://localhost:8080/system/console/configMgr/org.apache.sling.datasource.DataS
 
 Using the config ui above one can directly configure most of the properties as explained in [Tomcat Docs][1]
 
-Usage
------
-
-Once the required configuration is done the `DataSource` would be registered as part of the OSGi Service Registry
-The service is registered with service property `datasource.name` whose value is the name of datasource provided in 
-OSGi config. 
-
-Following snippet demonstrates accessing the DataSource named `foo` via DS annotation
-
-    import javax.sql.DataSource;
-    import org.apache.felix.scr.annotations.Reference;
-    
-    public class DSExample {
-        
-        @Reference(target = "(&(objectclass=javax.sql.DataSource)(datasource.name=foo))")
-        private DataSource dataSource;
-    }
-
-Convert Driver jars to Bundle
------------------------------
+### Convert Driver jars to Bundle
 
 Most of the JDBC driver jars have the required OSGi headers and can be directly deployed to OSGi container
 as bundles. However some of the drivers e.g. Postgres are not having such headers and hence need to be 
@@ -85,6 +70,37 @@ In the steps above we
 2. Create a bnd file with required instructions. 
 3. Execute the bnd command
 4. Resulting bundle is present in `org.postgresql-9.3.1101.jar`
- 
+
+## JNDI DataSource
+
+While running in Application Server the DataSource instance might be managed by app server and registered with
+JNDI. To enable lookup of DataSource instance from JNDI you can configure `JNDIDataSourceFactory`
+
+1. Configure the DataSource from OSGi config for PID `org.apache.sling.datasource.JNDIDataSourceFactory`
+2. Provide the JNDI name to lookup from and other details
+
+If Felix WebConsole is used then you can configure it via Configuration UI at
+http://localhost:8080/system/console/configMgr/org.apache.sling.datasource.JNDIDataSourceFactory
+
+Once configured `JNDIDataSourceFactory` would lookup the DataSource instance and register it with OSGi
+ServiceRegistry
+
+## Usage
+
+Once the required configuration is done the `DataSource` would be registered as part of the OSGi Service Registry
+The service is registered with service property `datasource.name` whose value is the name of datasource provided in
+OSGi config.
+
+Following snippet demonstrates accessing the DataSource named `foo` via DS annotation
+
+    import javax.sql.DataSource;
+    import org.apache.felix.scr.annotations.Reference;
+
+    public class DSExample {
+
+        @Reference(target = "(&(objectclass=javax.sql.DataSource)(datasource.name=foo))")
+        private DataSource dataSource;
+    }
+
 [1]: http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html
 [2]: http://www.aqute.biz/Bnd/Wrapping
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/datasource/internal/DataSourceFactory.java b/src/main/java/org/apache/sling/datasource/internal/DataSourceFactory.java
index 436ebf3..23f0553 100644
--- a/src/main/java/org/apache/sling/datasource/internal/DataSourceFactory.java
+++ b/src/main/java/org/apache/sling/datasource/internal/DataSourceFactory.java
@@ -321,11 +321,11 @@ public class DataSourceFactory {
 
     //~----------------------------------------< Config Handling >
 
-    private static String getDataSourceName(Map<String, ?> config) {
+    static String getDataSourceName(Map<String, ?> config) {
         return PropertiesUtil.toString(config.get(PROP_DATASOURCE_NAME), null);
     }
 
-    private static String getSvcPropName(Map<String, ?> config) {
+    static String getSvcPropName(Map<String, ?> config) {
         return PropertiesUtil.toString(config.get(PROP_DS_SVC_PROP_NAME), PROP_DATASOURCE_NAME);
     }
 
@@ -343,7 +343,7 @@ public class DataSourceFactory {
         }
     }
 
-    private static void checkArgument(boolean expression,
+    static void checkArgument(boolean expression,
                                       String errorMessageTemplate,
                                       Object... errorMessageArgs) {
         if (!expression) {
diff --git a/src/main/java/org/apache/sling/datasource/internal/JNDIDataSourceFactory.java b/src/main/java/org/apache/sling/datasource/internal/JNDIDataSourceFactory.java
new file mode 100644
index 0000000..07108ec
--- /dev/null
+++ b/src/main/java/org/apache/sling/datasource/internal/JNDIDataSourceFactory.java
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.datasource.internal;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.sling.datasource.internal.DataSourceFactory.checkArgument;
+
+@Component(
+        name = JNDIDataSourceFactory.NAME,
+        label = "Apache Sling JNDI DataSource",
+        description = "Registers a DataSource instance with OSGi ServiceRegistry which is looked up " +
+                "from the JNDI",
+        metatype = true,
+        configurationFactory = true,
+        policy = ConfigurationPolicy.REQUIRE
+)
+public class JNDIDataSourceFactory {
+    public static final String NAME = "org.apache.sling.datasource.JNDIDataSourceFactory";
+
+    @Property
+    static final String PROP_DATASOURCE_NAME = "datasource.name";
+
+    @Property(value = PROP_DATASOURCE_NAME)
+    static final String PROP_DS_SVC_PROP_NAME = "datasource.svc.prop.name";
+
+    @Property(
+            label = "JNDI Name (*)",
+            description = "JNDI location name used to perform DataSource instance lookup"
+    )
+    static final String PROP_DS_JNDI_NAME = "datasource.jndi.name";
+
+    @Property(
+            label = "JNDI Properties",
+            description = "Set the environment for the JNDI InitialContext i.e. properties passed on to InitialContext " +
+                    "for performing the JNDI instance lookup",
+            value = {},
+            cardinality = 1024)
+    static final String PROP_JNDI_PROPS = "jndi.properties";
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private ServiceRegistration dsRegistration;
+
+
+    @Activate
+    protected void activate(BundleContext bundleContext, Map<String, ?> config) throws Exception {
+        String name = DataSourceFactory.getDataSourceName(config);
+        String jndiName = PropertiesUtil.toString(config.get(PROP_DS_JNDI_NAME), null);
+
+        checkArgument(name != null, "DataSource name must be specified via [%s] property", PROP_DATASOURCE_NAME);
+        checkArgument(jndiName != null, "DataSource JNDI name must be specified via [%s] property", PROP_DS_JNDI_NAME);
+
+        DataSource dataSource = lookupDataSource(jndiName, config);
+        String svcPropName = DataSourceFactory.getSvcPropName(config);
+
+        Dictionary<String, Object> svcProps = new Hashtable<String, Object>();
+        svcProps.put(svcPropName, name);
+        svcProps.put(Constants.SERVICE_VENDOR, "Apache Software Foundation");
+        svcProps.put(Constants.SERVICE_DESCRIPTION, "DataSource service looked up from " + jndiName);
+        dsRegistration = bundleContext.registerService(javax.sql.DataSource.class, dataSource, svcProps);
+
+        log.info("Registered DataSource [{}] looked up from JNDI at [{}]", name, jndiName);
+    }
+
+    @Deactivate
+    protected void deactivate() {
+        if (dsRegistration != null) {
+            dsRegistration.unregister();
+            dsRegistration = null;
+        }
+    }
+
+    private DataSource lookupDataSource(String jndiName, Map<String, ?> config) throws NamingException {
+        Properties jndiProps = createJndiEnv(config);
+        Context context = null;
+        try {
+            log.debug("Looking up DataSource [{}] with InitialContext env [{}]", jndiName, jndiProps);
+
+            context = new InitialContext(jndiProps);
+            Object lookup = context.lookup(jndiName);
+            if (lookup == null) {
+                throw new NameNotFoundException("JNDI object with [" + jndiName + "] not found");
+            }
+
+            if (!DataSource.class.isInstance(lookup)) {
+                throw new IllegalStateException("JNDI object of type " + lookup.getClass() +
+                        "is not an instance of javax.sql.DataSource");
+            }
+
+            return (DataSource) lookup;
+        } finally {
+            if (context != null) {
+                context.close();
+            }
+        }
+    }
+
+    private Properties createJndiEnv(Map<String, ?> config) {
+        Properties props = new Properties();
+
+        //Copy the other properties first
+        Map<String, String> otherProps = PropertiesUtil.toMap(config.get(PROP_JNDI_PROPS), new String[0]);
+        for (Map.Entry<String, String> e : otherProps.entrySet()) {
+            set(e.getKey(), e.getValue(), props);
+        }
+
+        return props;
+    }
+
+    //~----------------------------------------< Config Handling >
+
+    private static void set(String name, String value, Properties props) {
+        if (value != null) {
+            value = value.trim();
+        }
+
+        if (value != null && !value.isEmpty()) {
+            props.setProperty(name, value);
+        }
+    }
+}
diff --git a/src/main/resources/OSGI-INF/metatype/metatype.properties b/src/main/resources/OSGI-INF/metatype/metatype.properties
index 0984696..f2acb93 100644
--- a/src/main/resources/OSGI-INF/metatype/metatype.properties
+++ b/src/main/resources/OSGI-INF/metatype/metatype.properties
@@ -130,7 +130,7 @@ logValidationErrors.name=Log Validation Error
 logValidationErrors.description=Set this to true to log errors during the validation phase to the log file
 
 datasource.svc.prop.name.name=DataSource Service Property Name
-datasource.svc.prop.name.name.description=Name of the service property which would store the DataSource Name while\
+datasource.svc.prop.name.description=Name of the service property which would store the DataSource Name while\
   registering the DataSource instance as OSGi service
 
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 14/22: Preparing for release. -- Adding scm info -- Fixing formatting of initial line

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit 3f006c86789c2fccf8dd0e25fdde3359c4127859
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 15 07:19:16 2015 +0000

    Preparing for release.
    -- Adding scm info
    -- Fixing formatting of initial line
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1651953 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 9970105..489b4d6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -18,8 +18,8 @@
  * from Adobe Systems Incorporated.
  **************************************************************************/
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
 
   <modelVersion>4.0.0</modelVersion>
 
@@ -50,6 +50,12 @@
     </bundle.file.name>
   </properties>
 
+  <scm>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource</developerConnection>
+    <url>http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/datasource</url>
+  </scm>
+
 
   <build>
     <plugins>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 05/22: SLING-3637 - Create connection pool lazily in DataSource Provider bundle

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit 6958fa8905c2da4b4829cb37e64417abe32e118b
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Wed Jun 4 13:24:14 2014 +0000

    SLING-3637 - Create connection pool lazily in DataSource Provider bundle
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1600198 13f79535-47bb-0310-9956-ffa450edef68
---
 .../datasource/internal/DataSourceFactory.java     | 65 ++++++++++++++--------
 .../datasource/internal/DriverDataSource.java      | 25 ++++++---
 2 files changed, 58 insertions(+), 32 deletions(-)

diff --git a/src/main/java/org/apache/sling/extensions/datasource/internal/DataSourceFactory.java b/src/main/java/org/apache/sling/extensions/datasource/internal/DataSourceFactory.java
index f653fcc..43b5815 100644
--- a/src/main/java/org/apache/sling/extensions/datasource/internal/DataSourceFactory.java
+++ b/src/main/java/org/apache/sling/extensions/datasource/internal/DataSourceFactory.java
@@ -19,6 +19,7 @@
 package org.apache.sling.extensions.datasource.internal;
 
 import java.lang.management.ManagementFactory;
+import java.sql.SQLException;
 import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.Map;
@@ -26,7 +27,6 @@ import java.util.Properties;
 
 import javax.management.InstanceNotFoundException;
 import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 import javax.sql.DataSource;
 
@@ -115,10 +115,7 @@ public class DataSourceFactory {
         }
 
         dataSource = createDataSource(props, bundleContext);
-
         registerDataSource(bundleContext);
-        registerJmx();
-
         log.info("Created DataSource [{}] with properties {}", name, getDataSourceDetails());
     }
 
@@ -139,20 +136,15 @@ public class DataSourceFactory {
     private DataSource createDataSource(Properties props, BundleContext bundleContext) throws Exception {
         PoolConfiguration poolProperties = org.apache.tomcat.jdbc.pool.DataSourceFactory.parsePoolProperties(props);
 
-        DriverDataSource driverDataSource = new DriverDataSource(poolProperties, driverRegistry, bundleContext);
+        DriverDataSource driverDataSource = new DriverDataSource(poolProperties, driverRegistry,
+                bundleContext, this);
 
         //Specify the DataSource such that connection creation logic is handled
         //by us where we take care of OSGi env
         poolProperties.setDataSource(driverDataSource);
 
-        org.apache.tomcat.jdbc.pool.DataSource dataSource =
-                new org.apache.tomcat.jdbc.pool.DataSource(poolProperties);
-        //initialise the pool itself
-        ConnectionPool pool = dataSource.createPool();
-        driverDataSource.setJmxPool(pool.getJmxPool());
-
         // Return the configured DataSource instance
-        return dataSource;
+        return new LazyJmxRegisteringDataSource(poolProperties);
     }
 
     private void registerDataSource(BundleContext bundleContext) {
@@ -163,12 +155,9 @@ public class DataSourceFactory {
         dsRegistration = bundleContext.registerService(DataSource.class, dataSource, svcProps);
     }
 
-    private void registerJmx() throws MalformedObjectNameException {
-        if(dataSource instanceof DataSourceProxy){
-            org.apache.tomcat.jdbc.pool.jmx.ConnectionPool pool =
-                    ((DataSourceProxy) dataSource).getPool().getJmxPool();
-
-            if(pool == null){
+    void registerJmx(ConnectionPool pool) throws SQLException {
+            org.apache.tomcat.jdbc.pool.jmx.ConnectionPool jmxPool = pool.getJmxPool();
+            if (jmxPool == null) {
                 //jmx not enabled
                 return;
             }
@@ -176,16 +165,19 @@ public class DataSourceFactory {
             table.put("type", "ConnectionPool");
             table.put("class", DataSource.class.getName());
             table.put("name", ObjectName.quote(name));
-            jmxName = new ObjectName("org.apache.sling", table);
 
             try {
+                jmxName = new ObjectName("org.apache.sling", table);
                 MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
-                mbs.registerMBean(pool, jmxName);
-            }catch(Exception e){
+                mbs.registerMBean(jmxPool, jmxName);
+            } catch (Exception e) {
                 log.warn("Error occurred while registering the JMX Bean for " +
-                        "connection pool with name {}",jmxName, e);
+                        "connection pool with name {}", jmxName, e);
             }
-        }
+    }
+
+    ConnectionPool getPool() {
+        return ((DataSourceProxy) dataSource).getPool();
     }
 
     private void unregisterJmx(){
@@ -219,6 +211,33 @@ public class DataSourceFactory {
         }
     }
 
+    private class LazyJmxRegisteringDataSource extends org.apache.tomcat.jdbc.pool.DataSource {
+        private volatile boolean initialized;
+
+        public LazyJmxRegisteringDataSource(PoolConfiguration poolProperties) {
+            super(poolProperties);
+        }
+
+        @Override
+        public ConnectionPool createPool() throws SQLException {
+            ConnectionPool pool = super.createPool();
+            registerJmxLazily(pool);
+            return pool;
+        }
+
+        private void registerJmxLazily(ConnectionPool pool) throws SQLException {
+            if(!initialized){
+                synchronized (this){
+                    if(initialized){
+                        return;
+                    }
+                    DataSourceFactory.this.registerJmx(pool);
+                    initialized = true;
+                }
+            }
+        }
+    }
+
     /**
      * Dummy impl to enable access to protected fields
      */
diff --git a/src/main/java/org/apache/sling/extensions/datasource/internal/DriverDataSource.java b/src/main/java/org/apache/sling/extensions/datasource/internal/DriverDataSource.java
index e2e0b32..58f7ccb 100644
--- a/src/main/java/org/apache/sling/extensions/datasource/internal/DriverDataSource.java
+++ b/src/main/java/org/apache/sling/extensions/datasource/internal/DriverDataSource.java
@@ -51,14 +51,16 @@ class DriverDataSource implements DataSource {
     private final DriverRegistry driverRegistry;
     private final BundleContext bundleContext;
     private final org.slf4j.Logger log = LoggerFactory.getLogger(getClass());
-    private org.apache.tomcat.jdbc.pool.jmx.ConnectionPool jmxPool;
     private Driver driver;
+    private final DataSourceFactory dataSourceFactory;
 
     public DriverDataSource(PoolConfiguration poolProperties, DriverRegistry driverRegistry,
-                            BundleContext bundleContext) {
+                            BundleContext bundleContext,
+                            DataSourceFactory dataSourceFactory) {
         this.poolProperties = poolProperties;
         this.driverRegistry = driverRegistry;
         this.bundleContext = bundleContext;
+        this.dataSourceFactory = dataSourceFactory;
     }
 
     public Connection getConnection() throws SQLException {
@@ -85,8 +87,9 @@ class DriverDataSource implements DataSource {
             if (log.isDebugEnabled()) {
                 log.debug("Unable to connect to database.", x);
             }
-            //Based on logic in org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver()
-            if (jmxPool!=null) {
+            //Based on logic in org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver()\
+            org.apache.tomcat.jdbc.pool.jmx.ConnectionPool jmxPool = getJmxPool();
+            if (jmxPool !=null) {
                 jmxPool.notify(org.apache.tomcat.jdbc.pool.jmx.ConnectionPool.NOTIFY_CONNECT,
                         ConnectionPool.getStackTrace(x));
             }
@@ -105,10 +108,6 @@ class DriverDataSource implements DataSource {
         return connection;
     }
 
-    public void setJmxPool(org.apache.tomcat.jdbc.pool.jmx.ConnectionPool jmxPool) {
-        this.jmxPool = jmxPool;
-    }
-
     //~-------------------------------------< DataSource >
 
     public PrintWriter getLogWriter() throws SQLException {
@@ -127,6 +126,7 @@ class DriverDataSource implements DataSource {
         return 0;
     }
 
+    @SuppressWarnings("UnusedDeclaration") //Part of JDK 7
     public Logger getParentLogger() throws SQLFeatureNotSupportedException {
         throw new SQLFeatureNotSupportedException();
     }
@@ -139,6 +139,13 @@ class DriverDataSource implements DataSource {
         return false;
     }
 
+    private org.apache.tomcat.jdbc.pool.jmx.ConnectionPool getJmxPool() {
+        if(dataSourceFactory.getPool() != null){
+            return dataSourceFactory.getPool().getJmxPool();
+        }
+        return null;
+    }
+
     private Driver getDriver() throws SQLException {
         if (driver != null) {
             return driver;
@@ -151,7 +158,7 @@ class DriverDataSource implements DataSource {
             driver = findMatchingDriver(drivers);
         }
 
-        if(driver == null){
+        if(driver == null && poolProperties.getDriverClassName() != null){
             log.debug("Looking for driver for [{}] via provided className [{}]",
                     url, poolProperties.getDriverClassName());
             driver = loadDriverClass();

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 11/22: SLING-4147 - Remove extensions from package name org.apache.sling.extensions.datasource.internal

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit 814eded7cdad7e124c4979fa0cb2e8a2a263712d
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Mon Nov 10 05:21:50 2014 +0000

    SLING-4147 - Remove extensions from package name org.apache.sling.extensions.datasource.internal
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1637789 13f79535-47bb-0310-9956-ffa450edef68
---
 README.md                                                             | 4 ++--
 .../sling/{extensions => }/datasource/internal/DataSourceFactory.java | 4 ++--
 .../sling/{extensions => }/datasource/internal/DriverDataSource.java  | 2 +-
 .../sling/{extensions => }/datasource/internal/DriverRegistry.java    | 2 +-
 .../java/org/apache/sling/extensions/datasource/DataSourceIT.java     | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/README.md b/README.md
index fa7ed6e..f987e4d 100644
--- a/README.md
+++ b/README.md
@@ -33,10 +33,10 @@ Configuration
 
 1. Install the current bundle
 2. Install the JDBC Driver bundle
-3. Configure the DataSource from OSGi config for PID `org.apache.sling.extensions.datasource.DataSourceFactory`
+3. Configure the DataSource from OSGi config for PID `org.apache.sling.datasource.DataSourceFactory`
 
 If Felix WebConsole is used then you can configure it via Configuration UI at
-http://localhost:8080/system/console/configMgr/org.apache.sling.extensions.datasource.DataSourceFactory
+http://localhost:8080/system/console/configMgr/org.apache.sling.datasource.DataSourceFactory
 
 ![Web Console Config](http://sling.apache.org/documentation/development/sling-datasource-config.png)
 
diff --git a/src/main/java/org/apache/sling/extensions/datasource/internal/DataSourceFactory.java b/src/main/java/org/apache/sling/datasource/internal/DataSourceFactory.java
similarity index 98%
rename from src/main/java/org/apache/sling/extensions/datasource/internal/DataSourceFactory.java
rename to src/main/java/org/apache/sling/datasource/internal/DataSourceFactory.java
index eb56710..436ebf3 100644
--- a/src/main/java/org/apache/sling/extensions/datasource/internal/DataSourceFactory.java
+++ b/src/main/java/org/apache/sling/datasource/internal/DataSourceFactory.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.extensions.datasource.internal;
+package org.apache.sling.datasource.internal;
 
 import java.lang.management.ManagementFactory;
 import java.sql.SQLException;
@@ -61,7 +61,7 @@ import org.slf4j.LoggerFactory;
         policy = ConfigurationPolicy.REQUIRE
 )
 public class DataSourceFactory {
-    public static final String NAME = "org.apache.sling.extensions.datasource.DataSourceFactory";
+    public static final String NAME = "org.apache.sling.datasource.DataSourceFactory";
 
     @Property
     static final String PROP_DATASOURCE_NAME = "datasource.name";
diff --git a/src/main/java/org/apache/sling/extensions/datasource/internal/DriverDataSource.java b/src/main/java/org/apache/sling/datasource/internal/DriverDataSource.java
similarity index 99%
rename from src/main/java/org/apache/sling/extensions/datasource/internal/DriverDataSource.java
rename to src/main/java/org/apache/sling/datasource/internal/DriverDataSource.java
index 58f7ccb..f8bcdd0 100644
--- a/src/main/java/org/apache/sling/extensions/datasource/internal/DriverDataSource.java
+++ b/src/main/java/org/apache/sling/datasource/internal/DriverDataSource.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.extensions.datasource.internal;
+package org.apache.sling.datasource.internal;
 
 
 import java.io.PrintWriter;
diff --git a/src/main/java/org/apache/sling/extensions/datasource/internal/DriverRegistry.java b/src/main/java/org/apache/sling/datasource/internal/DriverRegistry.java
similarity index 99%
rename from src/main/java/org/apache/sling/extensions/datasource/internal/DriverRegistry.java
rename to src/main/java/org/apache/sling/datasource/internal/DriverRegistry.java
index 732433e..ceebf72 100644
--- a/src/main/java/org/apache/sling/extensions/datasource/internal/DriverRegistry.java
+++ b/src/main/java/org/apache/sling/datasource/internal/DriverRegistry.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.extensions.datasource.internal;
+package org.apache.sling.datasource.internal;
 
 import java.io.BufferedReader;
 import java.io.IOException;
diff --git a/src/test/java/org/apache/sling/extensions/datasource/DataSourceIT.java b/src/test/java/org/apache/sling/extensions/datasource/DataSourceIT.java
index a830a5c..73fd3f2 100644
--- a/src/test/java/org/apache/sling/extensions/datasource/DataSourceIT.java
+++ b/src/test/java/org/apache/sling/extensions/datasource/DataSourceIT.java
@@ -47,7 +47,7 @@ public class DataSourceIT extends DataSourceTestBase{
     }
 
 
-    String PID = "org.apache.sling.extensions.datasource.DataSourceFactory";
+    String PID = "org.apache.sling.datasource.DataSourceFactory";
 
     @Inject
     ConfigurationAdmin ca;

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 21/22: [maven-release-plugin] prepare release org.apache.sling.datasource-1.0.0

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit c96dfc8428775128c404f64df7655230e7393094
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 15 11:23:07 2015 +0000

    [maven-release-plugin] prepare release org.apache.sling.datasource-1.0.0
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1652065 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 944710c..2ecf59d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
 
   <artifactId>org.apache.sling.datasource</artifactId>
   <packaging>bundle</packaging>
-  <version>0.0.1-SNAPSHOT</version>
+  <version>1.0.0</version>
 
   <name>Apache Sling DataSource Provider</name>
   <description>
@@ -51,9 +51,9 @@
   </properties>
 
   <scm>
-    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource</developerConnection>
-    <url>http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/datasource</url>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.datasource-1.0.0</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.datasource-1.0.0</developerConnection>
+    <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.datasource-1.0.0</url>
   </scm>
 
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 01/22: SLING-3574 - JDBC DataSource Provider bundle

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit a836938dd7303864fe0e41841949062286f26ba1
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Tue May 20 10:28:07 2014 +0000

    SLING-3574 - JDBC DataSource Provider bundle
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1596184 13f79535-47bb-0310-9956-ffa450edef68
---
 README.md                                          |  59 +++++
 pom.xml                                            | 279 +++++++++++++++++++++
 .../java/org/apache/juli/logging/DirectJDKLog.java | 110 ++++++++
 .../datasource/internal/DataSourceFactory.java     | 230 +++++++++++++++++
 .../datasource/internal/DriverDataSource.java      | 204 +++++++++++++++
 .../datasource/internal/DriverRegistry.java        | 175 +++++++++++++
 .../OSGI-INF/metatype/metatype.properties          |  47 ++++
 .../sling/extensions/datasource/DataSourceIT.java  |  77 ++++++
 .../extensions/datasource/DataSourceTestBase.java  | 117 +++++++++
 9 files changed, 1298 insertions(+)

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..381e79f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,59 @@
+Apache Sling DataSource Provider
+================================
+
+This bundle enables creating and configuring JDBC DataSource in OSGi environment based on 
+OSGi configuration. It uses [Tomcat JDBC Pool][1] as the JDBC Connection Pool provider.
+
+1. Supports configuring the DataSource based on OSGi config wihich rich metatype
+2. Supports deploying of JDBC Driver as independent bundles and not as fragment
+3. Exposes the DataSource stats as JMX MBean 
+
+Driver Loading
+--------------
+
+Loading of JDBC driver is tricky on OSGi env. Mostly one has to attach the Driver bundle as a
+fragment bundle to the code which creates the JDBC Connection. 
+
+With JDBC 4 onwards the Driver class can be loaded via Java SE Service Provider mechanism (SPM)
+JDBC 4.0 drivers must include the file META-INF/services/java.sql.Driver. This file contains 
+the name of the JDBC driver's implementation of java.sql.Driver. For example, to load the JDBC 
+driver to connect to a Apache Derby database, the META-INF/services/java.sql.Driver file would 
+contain the following entry:
+
+    org.apache.derby.jdbc.EmbeddedDriver
+    
+Sling DataSource Provider bundles maintains a `DriverRegistry` which contains mapping of Driver
+bundle to Driver class supported by it. With this feature there is no need to wrap the Driver
+bundle as fragment to DataSource provider bundle
+
+
+Configuration
+-------------
+
+1. Install the current bundle
+2. Install the JDBC Driver bundle
+3. Configure the DataSource from OSGi config for PID `org.apache.sling.extensions.datasource.DataSourceFactory`
+
+If Felix WebConsole is used then you can configure it via Configuration UI at
+http://localhost:8080/system/console/configMgr/org.apache.sling.extensions.datasource.DataSourceFactory
+
+Usage
+-----
+
+Once the required configuration is done the `DataSource` would be registered as part of the OSGi Service Registry
+The service is registered with service property `datasource.name` whose value is the name of datasource provided in 
+OSGi config. 
+
+Following snippet demonstrates accessing the DataSource named `foo` via DS annotation
+
+    import javax.sql.DataSource;
+    import org.apache.felix.scr.annotations.Reference;
+    
+    public class DSExample {
+        
+        @Reference(target = "(&(objectclass=javax.sql.DataSource)(datasource.name=foo))")
+        private DataSource dataSource;
+    }
+
+ 
+[1]: http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..21ed802
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,279 @@
+<?xml version="1.0"?>
+<!--
+/*************************************************************************
+ *
+ * ADOBE CONFIDENTIAL
+ * __________________
+ *
+ *  Copyright 2012 Adobe Systems Incorporated
+ *  All Rights Reserved.
+ *
+ * NOTICE:  All information contained herein is, and remains
+ * the property of Adobe Systems Incorporated and its suppliers,
+ * if any.  The intellectual and technical concepts contained
+ * herein are proprietary to Adobe Systems Incorporated and its
+ * suppliers and are protected by trade secret or copyright law.
+ * Dissemination of this information or reproduction of this material
+ * is strictly forbidden unless prior written permission is obtained
+ * from Adobe Systems Incorporated.
+ **************************************************************************/
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.sling</groupId>
+    <artifactId>sling</artifactId>
+    <version>18</version>
+  </parent>
+
+  <artifactId>org.apache.sling.extensions.datasource</artifactId>
+  <packaging>bundle</packaging>
+  <version>0.0.1-SNAPSHOT</version>
+
+  <name>Apache Sling DataSource Provider</name>
+  <description>
+    Enables creation of DataSource based on OSGi configuration
+  </description>
+
+  <properties>
+    <sling.java.version>6</sling.java.version>
+    <pax.exam.version>3.4.0</pax.exam.version>
+    <pax.url.version>1.6.0</pax.url.version>
+    <bundle.build.name>
+      ${basedir}/target
+    </bundle.build.name>
+    <bundle.file.name>
+      ${bundle.build.name}/${project.build.finalName}.jar
+    </bundle.file.name>
+  </properties>
+
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Embed-Dependency>
+              org.apache.sling.commons.osgi;inline=org/apache/sling/commons/osgi/PropertiesUtil.class,
+              tomcat-jdbc,
+              tomcat-juli
+            </Embed-Dependency>
+          </instructions>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-scr-plugin</artifactId>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.servicemix.tooling</groupId>
+        <artifactId>depends-maven-plugin</artifactId>
+        <version>1.2</version>
+        <executions>
+          <execution>
+            <id>generate-depends-file</id>
+            <goals>
+              <goal>generate-depends-file</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <artifactId>maven-failsafe-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>integration-test</goal>
+              <goal>verify</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <systemPropertyVariables>
+            <project.bundle.file>${bundle.file.name}</project.bundle.file>
+            <coverage.command>${coverage.command}</coverage.command>
+          </systemPropertyVariables>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <version>4.3.1</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.compendium</artifactId>
+      <version>4.3.1</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.commons.osgi</artifactId>
+      <version>2.2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>tomcat-jdbc</artifactId>
+      <version>7.0.53</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>tomcat-juli</artifactId>
+      <version>7.0.53</version>
+    </dependency>
+
+    <!-- OSGi test -->
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.framework</artifactId>
+      <version>4.4.0</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-container-forked</artifactId>
+      <version>${pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-junit4</artifactId>
+      <version>${pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-link-mvn</artifactId>
+      <version>${pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.url</groupId>
+      <artifactId>pax-url-aether</artifactId>
+      <version>${pax.url.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.url</groupId>
+      <artifactId>pax-url-reference</artifactId>
+      <version>${pax.url.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.url</groupId>
+      <artifactId>pax-url-wrap</artifactId>
+      <version>${pax.url.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.configadmin</artifactId>
+      <version>1.8.0</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.scr</artifactId>
+      <version>1.8.2</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.h2database</groupId>
+      <artifactId>h2</artifactId>
+      <version>1.4.178</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <version>1.5.2</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-beanutils</groupId>
+      <artifactId>commons-beanutils-core</artifactId>
+      <version>1.8.3</version>
+    </dependency>
+  </dependencies>
+
+  <profiles>
+    <!--
+        copy the package such that IDEs may easily use it without
+        setting the system property
+    -->
+    <profile>
+      <id>ide</id>
+      <build>
+        <plugins>
+          <plugin>
+            <artifactId>maven-antrun-plugin</artifactId>
+            <executions>
+              <execution>
+                <id>bundle-file-create</id>
+                <phase>package</phase>
+                <goals>
+                  <goal>run</goal>
+                </goals>
+                <configuration>
+                  <target>
+                    <copy file="${project.build.directory}/${project.build.finalName}.jar" tofile="${project.build.directory}/bundle.jar" />
+                  </target>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+    <profile>
+      <id>coverage</id>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.jacoco</groupId>
+            <artifactId>jacoco-maven-plugin</artifactId>
+            <executions>
+              <!-- Default to setup argLine required by surefire -->
+              <execution>
+                <id>prepare-agent-surefire</id>
+                <phase>test-compile</phase>
+                <goals>
+                  <goal>prepare-agent</goal>
+                </goals>
+                <configuration>
+                  <propertyName>coverage.command</propertyName>
+                  <includes>
+                    <include>org.apache.sling.extensions.datasource.internal.*</include>
+                  </includes>
+                </configuration>
+              </execution>
+              <execution>
+                <id>report</id>
+                <phase>post-integration-test</phase>
+                <goals>
+                  <goal>report</goal>
+                </goals>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+</project>
diff --git a/src/main/java/org/apache/juli/logging/DirectJDKLog.java b/src/main/java/org/apache/juli/logging/DirectJDKLog.java
new file mode 100644
index 0000000..f49ac08
--- /dev/null
+++ b/src/main/java/org/apache/juli/logging/DirectJDKLog.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.juli.logging;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Overriding the DirectJDKLog impl to delegate the logging to Slf4j
+ */
+@SuppressWarnings("UnusedDeclaration")
+class DirectJDKLog implements Log {
+    private final Logger logger;
+
+    public DirectJDKLog(String name) {
+        this.logger = LoggerFactory.getLogger(name);
+    }
+
+    static Log getInstance(String name) {
+        return new DirectJDKLog( name );
+    }
+
+    public boolean isDebugEnabled() {
+        return logger.isDebugEnabled();
+    }
+
+    public boolean isErrorEnabled() {
+        return logger.isErrorEnabled();
+    }
+
+    public boolean isFatalEnabled() {
+        return logger.isErrorEnabled();
+    }
+
+    public boolean isInfoEnabled() {
+        return logger.isInfoEnabled();
+    }
+
+    public boolean isTraceEnabled() {
+        return logger.isTraceEnabled();
+    }
+
+    public boolean isWarnEnabled() {
+        return logger.isWarnEnabled();
+    }
+
+    public void trace(Object message) {
+        logger.trace(String.valueOf(message));
+    }
+
+    public void trace(Object message, Throwable t) {
+        logger.trace(String.valueOf(message), t);
+    }
+
+    public void debug(Object message) {
+        logger.debug(String.valueOf(message));
+    }
+
+    public void debug(Object message, Throwable t) {
+        logger.debug(String.valueOf(message), t);
+    }
+
+    public void info(Object message) {
+        logger.info(String.valueOf(message));
+    }
+
+    public void info(Object message, Throwable t) {
+        logger.info(String.valueOf(message), t);
+    }
+
+    public void warn(Object message) {
+        logger.warn(String.valueOf(message));
+    }
+
+    public void warn(Object message, Throwable t) {
+        logger.warn(String.valueOf(message), t);
+    }
+
+    public void error(Object message) {
+        logger.error(String.valueOf(message));
+    }
+
+    public void error(Object message, Throwable t) {
+        logger.error(String.valueOf(message), t);
+    }
+
+    public void fatal(Object message) {
+        logger.error(String.valueOf(message));
+    }
+
+    public void fatal(Object message, Throwable t) {
+        logger.error(String.valueOf(message), t);
+    }
+}
diff --git a/src/main/java/org/apache/sling/extensions/datasource/internal/DataSourceFactory.java b/src/main/java/org/apache/sling/extensions/datasource/internal/DataSourceFactory.java
new file mode 100644
index 0000000..f653fcc
--- /dev/null
+++ b/src/main/java/org/apache/sling/extensions/datasource/internal/DataSourceFactory.java
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.extensions.datasource.internal;
+
+import java.lang.management.ManagementFactory;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.sql.DataSource;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.apache.tomcat.jdbc.pool.ConnectionPool;
+import org.apache.tomcat.jdbc.pool.DataSourceProxy;
+import org.apache.tomcat.jdbc.pool.PoolConfiguration;
+import org.apache.tomcat.jdbc.pool.PoolProperties;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(
+        name = DataSourceFactory.NAME,
+        label = "%datasource.component.name",
+        description = "%datasource.component.description",
+        metatype = true,
+        configurationFactory = true,
+        policy = ConfigurationPolicy.REQUIRE
+)
+public class DataSourceFactory {
+    public static final String NAME = "org.apache.sling.extensions.datasource.DataSourceFactory";
+
+    @Property
+    static final String PROP_DATASOURCE_NAME = "datasource.name";
+
+    @Property
+    static final String PROP_DRIVERCLASSNAME = "driverClassName";
+
+    @Property
+    static final String PROP_URL = "url";
+
+    @Property
+    static final String PROP_USERNAME = "username";
+
+    @Property(passwordValue = "")
+    static final String PROP_PASSWORD = "password";
+
+    @Property(intValue = PoolProperties.DEFAULT_MAX_ACTIVE)
+    static final String PROP_MAXACTIVE = "maxActive";
+
+    @Property(value = {}, cardinality = 1024)
+    static final String PROP_DATASOURCE_SVC_PROPS = "datasource.svc.properties";
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Reference
+    private DriverRegistry driverRegistry;
+
+    private String name;
+
+    private ObjectName jmxName;
+
+    private ServiceRegistration dsRegistration;
+
+    private DataSource dataSource;
+
+    @Activate
+    protected void activate(BundleContext bundleContext, Map<String,?> config) throws Exception {
+        Properties props = new Properties();
+        name = PropertiesUtil.toString(config.get(PROP_DATASOURCE_NAME), null);
+
+        checkArgument(name != null, "DataSource name must be specified via [%s] property", PROP_DATASOURCE_NAME);
+
+        //Copy the other properties first
+        Map<String,String> otherProps = PropertiesUtil.toMap(config.get(PROP_DATASOURCE_SVC_PROPS), new String[0]);
+        for(Map.Entry<String, String> e : otherProps.entrySet()){
+            props.setProperty(e.getKey(), e.getValue());
+        }
+
+        props.setProperty(org.apache.tomcat.jdbc.pool.DataSourceFactory.OBJECT_NAME, name);
+
+        for(String propName : DummyDataSourceFactory.getPropertyNames()){
+            String value = PropertiesUtil.toString(config.get(propName), null);
+            if(value != null){
+                props.setProperty(propName, value);
+            }
+        }
+
+        dataSource = createDataSource(props, bundleContext);
+
+        registerDataSource(bundleContext);
+        registerJmx();
+
+        log.info("Created DataSource [{}] with properties {}", name, getDataSourceDetails());
+    }
+
+    @Deactivate
+    protected void deactivate(){
+        if(dsRegistration != null){
+            dsRegistration.unregister();
+        }
+
+        unregisterJmx();
+
+        if(dataSource instanceof DataSourceProxy){
+            ((DataSourceProxy) dataSource).close();
+        }
+
+    }
+
+    private DataSource createDataSource(Properties props, BundleContext bundleContext) throws Exception {
+        PoolConfiguration poolProperties = org.apache.tomcat.jdbc.pool.DataSourceFactory.parsePoolProperties(props);
+
+        DriverDataSource driverDataSource = new DriverDataSource(poolProperties, driverRegistry, bundleContext);
+
+        //Specify the DataSource such that connection creation logic is handled
+        //by us where we take care of OSGi env
+        poolProperties.setDataSource(driverDataSource);
+
+        org.apache.tomcat.jdbc.pool.DataSource dataSource =
+                new org.apache.tomcat.jdbc.pool.DataSource(poolProperties);
+        //initialise the pool itself
+        ConnectionPool pool = dataSource.createPool();
+        driverDataSource.setJmxPool(pool.getJmxPool());
+
+        // Return the configured DataSource instance
+        return dataSource;
+    }
+
+    private void registerDataSource(BundleContext bundleContext) {
+        Dictionary<String,Object> svcProps = new Hashtable<String, Object>();
+        svcProps.put(PROP_DATASOURCE_NAME, name);
+        svcProps.put(Constants.SERVICE_VENDOR, "Apache Software Foundation");
+        svcProps.put(Constants.SERVICE_DESCRIPTION, "DataSource service based on Tomcat JDBC");
+        dsRegistration = bundleContext.registerService(DataSource.class, dataSource, svcProps);
+    }
+
+    private void registerJmx() throws MalformedObjectNameException {
+        if(dataSource instanceof DataSourceProxy){
+            org.apache.tomcat.jdbc.pool.jmx.ConnectionPool pool =
+                    ((DataSourceProxy) dataSource).getPool().getJmxPool();
+
+            if(pool == null){
+                //jmx not enabled
+                return;
+            }
+            Hashtable<String, String> table = new Hashtable<String, String>();
+            table.put("type", "ConnectionPool");
+            table.put("class", DataSource.class.getName());
+            table.put("name", ObjectName.quote(name));
+            jmxName = new ObjectName("org.apache.sling", table);
+
+            try {
+                MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+                mbs.registerMBean(pool, jmxName);
+            }catch(Exception e){
+                log.warn("Error occurred while registering the JMX Bean for " +
+                        "connection pool with name {}",jmxName, e);
+            }
+        }
+    }
+
+    private void unregisterJmx(){
+        try {
+            if(jmxName != null) {
+                MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+                mbs.unregisterMBean(jmxName);
+            }
+        } catch (InstanceNotFoundException ignore) {
+            // NOOP
+        } catch (Exception e) {
+            log.error("Unable to unregister JDBC pool with JMX",e);
+        }
+    }
+
+    private String getDataSourceDetails() {
+        if(dataSource instanceof DataSourceProxy){
+            return ((DataSourceProxy) dataSource).getPoolProperties().toString();
+        }
+        return "<UNKNOWN>";
+    }
+
+
+
+    public static void checkArgument(boolean expression,
+                                     String errorMessageTemplate,
+                                     Object... errorMessageArgs) {
+        if (!expression) {
+            throw new IllegalArgumentException(
+                    String.format(errorMessageTemplate, errorMessageArgs));
+        }
+    }
+
+    /**
+     * Dummy impl to enable access to protected fields
+     */
+    private static class DummyDataSourceFactory extends org.apache.tomcat.jdbc.pool.DataSourceFactory {
+        static String[] getPropertyNames(){
+            return ALL_PROPERTIES;
+        }
+    }
+}
diff --git a/src/main/java/org/apache/sling/extensions/datasource/internal/DriverDataSource.java b/src/main/java/org/apache/sling/extensions/datasource/internal/DriverDataSource.java
new file mode 100644
index 0000000..e2e0b32
--- /dev/null
+++ b/src/main/java/org/apache/sling/extensions/datasource/internal/DriverDataSource.java
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.extensions.datasource.internal;
+
+
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+import javax.sql.DataSource;
+
+import org.apache.tomcat.jdbc.pool.ConnectionPool;
+import org.apache.tomcat.jdbc.pool.PoolConfiguration;
+import org.apache.tomcat.jdbc.pool.PoolUtilities;
+import org.osgi.framework.BundleContext;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DataSource implementation which only implements the Connection creation part. Tomcat
+ * JDBC currently does not support specifying the Drive instance directly. While running
+ * in OSGi env DriverRegistry maintains a list of seen driver instances.
+ *
+ * DriverDataSource make use of the DriverRegistry to lookup right Driver instance. This avoid
+ * the requirement of having the Driver OSGi bundle attaches as fragments to our bundle
+ */
+class DriverDataSource implements DataSource {
+    private final PoolConfiguration poolProperties;
+    private final DriverRegistry driverRegistry;
+    private final BundleContext bundleContext;
+    private final org.slf4j.Logger log = LoggerFactory.getLogger(getClass());
+    private org.apache.tomcat.jdbc.pool.jmx.ConnectionPool jmxPool;
+    private Driver driver;
+
+    public DriverDataSource(PoolConfiguration poolProperties, DriverRegistry driverRegistry,
+                            BundleContext bundleContext) {
+        this.poolProperties = poolProperties;
+        this.driverRegistry = driverRegistry;
+        this.bundleContext = bundleContext;
+    }
+
+    public Connection getConnection() throws SQLException {
+        return getConnection(null, null);
+    }
+
+    public Connection getConnection(String usr, String pwd) throws SQLException {
+        Properties properties = PoolUtilities.clone(poolProperties.getDbProperties());
+        if(usr == null){
+            usr = poolProperties.getUsername();
+        }
+        if(pwd == null){
+            pwd= poolProperties.getPassword();
+        }
+
+        if (usr != null) properties.setProperty(PoolUtilities.PROP_USER, usr);
+        if (pwd != null) properties.setProperty(PoolUtilities.PROP_PASSWORD, pwd);
+
+        String driverURL = poolProperties.getUrl();
+        Connection connection;
+        try {
+            connection = getDriver().connect(driverURL, properties);
+        } catch (Exception x) {
+            if (log.isDebugEnabled()) {
+                log.debug("Unable to connect to database.", x);
+            }
+            //Based on logic in org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver()
+            if (jmxPool!=null) {
+                jmxPool.notify(org.apache.tomcat.jdbc.pool.jmx.ConnectionPool.NOTIFY_CONNECT,
+                        ConnectionPool.getStackTrace(x));
+            }
+            if (x instanceof SQLException) {
+                throw (SQLException)x;
+            } else {
+                SQLException ex = new SQLException(x.getMessage());
+                ex.initCause(x);
+                throw ex;
+            }
+        }
+        if (connection==null) {
+            throw new SQLException("Driver:"+driver+" returned null for URL:"+driverURL);
+        }
+
+        return connection;
+    }
+
+    public void setJmxPool(org.apache.tomcat.jdbc.pool.jmx.ConnectionPool jmxPool) {
+        this.jmxPool = jmxPool;
+    }
+
+    //~-------------------------------------< DataSource >
+
+    public PrintWriter getLogWriter() throws SQLException {
+        throw new SQLFeatureNotSupportedException();
+    }
+
+    public void setLogWriter(PrintWriter out) throws SQLException {
+
+    }
+
+    public void setLoginTimeout(int seconds) throws SQLException {
+
+    }
+
+    public int getLoginTimeout() throws SQLException {
+        return 0;
+    }
+
+    public Logger getParentLogger() throws SQLFeatureNotSupportedException {
+        throw new SQLFeatureNotSupportedException();
+    }
+
+    public <T> T unwrap(Class<T> iface) throws SQLException {
+        return null;
+    }
+
+    public boolean isWrapperFor(Class<?> iface) throws SQLException {
+        return false;
+    }
+
+    private Driver getDriver() throws SQLException {
+        if (driver != null) {
+            return driver;
+        }
+        final String url = poolProperties.getUrl();
+
+        Collection<Driver> drivers = driverRegistry.getDrivers();
+        if(!drivers.isEmpty()) {
+            log.debug("Looking for driver for [{}] against registered drivers", url);
+            driver = findMatchingDriver(drivers);
+        }
+
+        if(driver == null){
+            log.debug("Looking for driver for [{}] via provided className [{}]",
+                    url, poolProperties.getDriverClassName());
+            driver = loadDriverClass();
+        }
+
+        if(driver == null){
+            //This one is redundant as DriverManager would filter out drivers
+            //whose classes are not visible from our bundle classloader which
+            //means that this list would be empty in most cases
+            log.debug("Looking for driver from DriverManager");
+            driver = findMatchingDriver(Collections.list(DriverManager.getDrivers()));
+        }
+
+        if(driver == null){
+            String msg = String.format("Not able to find any matching driver for url [%s] " +
+                    "and driverClassName [%s]",url,poolProperties.getDriverClassName());
+            throw new SQLException(msg);
+        }
+
+        return driver;
+    }
+
+    private Driver loadDriverClass() throws SQLException {
+        try {
+              log.debug("Instantiating driver using class: {} [url={}]",
+                      poolProperties.getDriverClassName(),poolProperties.getUrl());
+                return (Driver) bundleContext.getBundle()
+                        .loadClass(poolProperties.getDriverClassName()).newInstance();
+        } catch (java.lang.Exception cn) {
+            log.debug("Unable to instantiate JDBC driver.", cn);
+            SQLException ex = new SQLException(cn.getMessage());
+            ex.initCause(cn);
+            throw ex;
+        }
+    }
+
+    private Driver findMatchingDriver(Collection<Driver> drivers) {
+        final String url = poolProperties.getUrl();
+        for (Driver driver : drivers) {
+            try {
+                if (driver.acceptsURL(url)) {
+                    return driver;
+                }
+            } catch (SQLException e) {
+                log.debug("Error occurred while matching driver against url {}", url, e);
+            }
+        }
+        return null;
+    }
+}
diff --git a/src/main/java/org/apache/sling/extensions/datasource/internal/DriverRegistry.java b/src/main/java/org/apache/sling/extensions/datasource/internal/DriverRegistry.java
new file mode 100644
index 0000000..732433e
--- /dev/null
+++ b/src/main/java/org/apache/sling/extensions/datasource/internal/DriverRegistry.java
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.extensions.datasource.internal;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.sql.Driver;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Service;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.util.tracker.BundleTracker;
+import org.osgi.util.tracker.BundleTrackerCustomizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component
+@Service(value = DriverRegistry.class)
+public class DriverRegistry {
+    private static final String DRIVER_SERVICE = "META-INF/services/"
+            + Driver.class.getName();
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private BundleTracker<Collection<DriverInfo>> bundleTracker;
+
+    private ConcurrentMap<DriverInfo, Driver> driverInfos = new ConcurrentHashMap<DriverInfo, Driver>();
+
+    public Collection<Driver> getDrivers() {
+        return driverInfos.values();
+    }
+
+    @Activate
+    protected void activate(BundleContext bundleContext) {
+        bundleTracker = new BundleTracker<Collection<DriverInfo>>(bundleContext,
+                Bundle.ACTIVE, new DriverBundleTracker());
+        bundleTracker.open();
+    }
+
+    @Deactivate
+    protected void deactivate() {
+        if (bundleTracker != null) {
+            bundleTracker.close();
+        }
+    }
+
+    private void registerDrivers(Collection<DriverInfo> drivers) {
+        for (DriverInfo di : drivers) {
+            driverInfos.put(di, di.driver);
+            log.info("Registering {}", di);
+        }
+    }
+
+    private void deregisterDrivers(Collection<DriverInfo> drivers) {
+        for (DriverInfo di : drivers) {
+            driverInfos.remove(di);
+            log.info("Deregistering {}", di);
+        }
+    }
+
+    private Collection<DriverInfo> createDrivers(final Bundle bundle) {
+        URL url = bundle.getEntry(DRIVER_SERVICE);
+        InputStream ins = null;
+        final List<DriverInfo> extensions = new ArrayList<DriverInfo>();
+        try {
+            ins = url.openStream();
+            BufferedReader reader = new BufferedReader(new InputStreamReader(ins));
+            String line;
+            while ((line = reader.readLine()) != null) {
+                if (!line.startsWith("#") && line.trim().length() > 0) {
+                    try {
+                        Class<?> clazz = bundle.loadClass(line);
+                        extensions.add(new DriverInfo(bundle, (Driver) clazz.newInstance()));
+                    } catch (Throwable t) {
+                        log.warn("Cannot register java.sql.Driver [{}] from bundle [{}]",
+                                new Object[]{line, bundle, t});
+                    }
+                }
+            }
+        } catch (IOException ioe) {
+            // ignore
+        } finally {
+            if (ins != null) {
+                try {
+                    ins.close();
+                } catch (IOException ignore) {
+                }
+            }
+        }
+
+        return extensions;
+    }
+
+    private class DriverBundleTracker implements BundleTrackerCustomizer<Collection<DriverInfo>> {
+        public Collection<DriverInfo> addingBundle(Bundle bundle, BundleEvent event) {
+            if (bundle.getEntry(DRIVER_SERVICE) != null) {
+                Collection<DriverInfo> drivers = createDrivers(bundle);
+                registerDrivers(drivers);
+                return drivers;
+            }
+            return null;
+        }
+
+        public void modifiedBundle(Bundle bundle, BundleEvent event, Collection<DriverInfo> object) {
+
+        }
+
+        public void removedBundle(Bundle bundle, BundleEvent event, Collection<DriverInfo> drivers) {
+            deregisterDrivers(drivers);
+        }
+    }
+
+    private static class DriverInfo {
+        final Driver driver;
+        final Bundle bundle;
+
+        DriverInfo(Bundle bundle, Driver driver) {
+            this.driver = driver;
+            this.bundle = bundle;
+        }
+
+        @SuppressWarnings("RedundantIfStatement")
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) return true;
+            if (o == null || getClass() != o.getClass()) return false;
+
+            DriverInfo that = (DriverInfo) o;
+
+            if (!(bundle == that.bundle)) return false;
+            if (!(driver == that.driver)) return false;
+
+            return true;
+        }
+
+        @Override
+        public int hashCode() {
+            int result = driver.hashCode();
+            result = 31 * result + bundle.hashCode();
+            return result;
+        }
+
+        public String toString() {
+            return String.format("java.sql.Driver [%s] from bundle [%s]", driver.getClass().getName(), bundle);
+        }
+    }
+}
diff --git a/src/main/resources/OSGI-INF/metatype/metatype.properties b/src/main/resources/OSGI-INF/metatype/metatype.properties
new file mode 100644
index 0000000..e0e9e5c
--- /dev/null
+++ b/src/main/resources/OSGI-INF/metatype/metatype.properties
@@ -0,0 +1,47 @@
+#
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+#
+
+# suppress inspection "UnusedProperty" for whole file
+
+datasource.component.name = Apache Sling JDBC DataSource
+datasource.component.description = Creates a DataSource services based on configuration provided
+
+datasource.name.name = Datasource name(*)
+datasource.name.description = Name of this data source (required)
+
+datasource.svc.properties.name = Additional Properties
+datasource.svc.properties.description = Properties that are added additionally to the underlying DataSource \
+  provider(name=value pairs). Refer to http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#Common_Attributes \
+  for various property names and details.
+
+url.name=JDBC connection URI
+url.description=URI of the JDBC connection to use e.g. jdbc:mysql://localhost:3306/mysql
+
+driverClassName.name=JDBC driver class
+driverClassName.description=Java class name of the JDBC driver to use
+
+username.name=Username
+username.description=The connection username to be passed to our JDBC driver to establish a connection
+
+password.name=Password
+password.description=The connection password to be passed to our JDBC driver to establish a connection.
+
+maxActive.name=Max Active Connections
+maxActive.description=The maximum number of active connections that can be allocated from this pool at \
+  the same time. The default value is 100
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/extensions/datasource/DataSourceIT.java b/src/test/java/org/apache/sling/extensions/datasource/DataSourceIT.java
new file mode 100644
index 0000000..08720e2
--- /dev/null
+++ b/src/test/java/org/apache/sling/extensions/datasource/DataSourceIT.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.extensions.datasource;
+
+import java.sql.Connection;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.inject.Inject;
+import javax.sql.DataSource;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.Filter;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+import static org.apache.commons.beanutils.BeanUtils.getProperty;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(PaxExam.class)
+public class DataSourceIT extends DataSourceTestBase{
+
+    static {
+        //paxRunnerVmOption = DEBUG_VM_OPTION;
+    }
+
+
+    String PID = "org.apache.sling.extensions.datasource.DataSourceFactory";
+
+    @Inject
+    ConfigurationAdmin ca;
+
+    @Test
+    public void testDataSourceAsService() throws Exception{
+        Configuration config = ca.createFactoryConfiguration(PID, null);
+        Dictionary<String, Object> p = new Hashtable<String, Object>();
+        p.put("url","jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
+        p.put("datasource.name","test");
+        p.put("maxActive",70);
+        config.update(p);
+
+        Filter filter = context.createFilter("(&(objectclass=javax.sql.DataSource)(datasource.name=test))");
+        ServiceTracker<DataSource, DataSource> st =
+                new ServiceTracker<DataSource, DataSource>(context, filter, null);
+        st.open();
+
+        DataSource ds = st.waitForService(10000);
+        assertNotNull(ds);
+
+        Connection conn = ds.getConnection();
+        assertNotNull(conn);
+
+        //Cannot access directly so access via reflection
+        assertEquals("70", getProperty(ds, "poolProperties.maxActive"));
+    }
+
+}
diff --git a/src/test/java/org/apache/sling/extensions/datasource/DataSourceTestBase.java b/src/test/java/org/apache/sling/extensions/datasource/DataSourceTestBase.java
new file mode 100644
index 0000000..7415017
--- /dev/null
+++ b/src/test/java/org/apache/sling/extensions/datasource/DataSourceTestBase.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.extensions.datasource;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+import javax.inject.Inject;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.osgi.framework.BundleContext;
+
+import static org.ops4j.pax.exam.CoreOptions.cleanCaches;
+import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.keepCaches;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemPackage;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import static org.ops4j.pax.exam.CoreOptions.systemTimeout;
+import static org.ops4j.pax.exam.CoreOptions.workingDirectory;
+import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
+import static org.ops4j.pax.exam.util.PathUtils.getBaseDir;
+
+public abstract class DataSourceTestBase {
+    @Inject
+    protected BundleContext context;
+
+    // the name of the system property providing the bundle file to be installed
+    // and tested
+    protected static final String BUNDLE_JAR_SYS_PROP = "project.bundle.file";
+
+    // the default bundle jar file name
+    protected static final String BUNDLE_JAR_DEFAULT = "target/bundle.jar";
+
+    // the name of the system property which captures the jococo coverage agent command
+    //if specified then agent would be specified otherwise ignored
+    protected static final String COVERAGE_COMMAND = "coverage.command";
+
+    // the JVM option to set to enable remote debugging
+    @SuppressWarnings("UnusedDeclaration")
+    protected static final String DEBUG_VM_OPTION = "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=31313";
+
+    // the actual JVM option set, extensions may implement a static
+    // initializer overwriting this value to have the configuration()
+    // method include it when starting the OSGi framework JVM
+    protected static String paxRunnerVmOption = null;
+
+    @Configuration
+    public Option[] config() throws IOException {
+        final String bundleFileName = System.getProperty(BUNDLE_JAR_SYS_PROP, BUNDLE_JAR_DEFAULT);
+        final File bundleFile = new File(bundleFileName);
+        if (!bundleFile.canRead()) {
+            throw new IllegalArgumentException("Cannot read from bundle file " + bundleFileName + " specified in the "
+                    + BUNDLE_JAR_SYS_PROP + " system property. Try building the project first " +
+                    "with 'mvn clean install -Pide -DskipTests'");
+        }
+        return options(
+                // the current project (the bundle under test)
+                CoreOptions.bundle(bundleFile.toURI().toString()),
+                mavenBundle("com.h2database", "h2").versionAsInProject(),
+                wrappedBundle(mavenBundle("commons-beanutils", "commons-beanutils-core").versionAsInProject()),
+                mavenBundle("org.slf4j", "slf4j-simple").versionAsInProject().noStart(),
+                mavenBundle("org.apache.felix", "org.apache.felix.scr").versionAsInProject(),
+                mavenBundle("org.apache.felix", "org.apache.felix.configadmin").versionAsInProject(),
+                junitBundles(),
+                systemProperty("pax.exam.osgi.unresolved.fail").value("fail"),
+                systemPackage("com.sun.tools.attach"),
+                cleanCaches(),
+                addCodeCoverageOption(),
+                addDebugOptions()
+        );
+    }
+
+    private static Option addCodeCoverageOption() {
+        String coverageCommand = System.getProperty(COVERAGE_COMMAND);
+        if (coverageCommand != null) {
+            return CoreOptions.vmOption(coverageCommand);
+        }
+        return null;
+    }
+
+    private static Option addDebugOptions() throws IOException {
+        if (paxRunnerVmOption != null) {
+            String workDir = FilenameUtils.concat(getBaseDir(), "target/pax");
+            File workDirFile = new File(workDir);
+            if (workDirFile.exists()) {
+                FileUtils.deleteDirectory(workDirFile);
+            }
+            return composite(CoreOptions.vmOption(paxRunnerVmOption), keepCaches(),
+                    systemTimeout(TimeUnit.MINUTES.toMillis(10)), workingDirectory(workDir));
+        }
+        return null;
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 18/22: SLING-4147 - Remove extensions from package name org.apache.sling.extensions.datasource.internal

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit 3a4bf46d6e6111ca7df9b5b8b8b2b86526f7d527
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 15 11:07:20 2015 +0000

    SLING-4147 - Remove extensions from package name org.apache.sling.extensions.datasource.internal
    
    Remove leftover empty directories
    
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1652052 13f79535-47bb-0310-9956-ffa450edef68

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 22/22: [maven-release-plugin] copy for tag org.apache.sling.datasource-1.0.0

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit 322a17fa00bf8b683bb7e51bc4f5eef565027003
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 15 11:23:11 2015 +0000

    [maven-release-plugin]  copy for tag org.apache.sling.datasource-1.0.0
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.datasource-1.0.0@1652066 13f79535-47bb-0310-9956-ffa450edef68

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 08/22: SLING-3574 - JDBC DataSource Provider bundle

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit f88c56384735153affed32833c05aac12ab61a41
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Mon Jun 16 06:14:03 2014 +0000

    SLING-3574 - JDBC DataSource Provider bundle
    
    Adding docs around wrapping driver jars
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1602803 13f79535-47bb-0310-9956-ffa450edef68
---
 README.md | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 42f9f2d..fa7ed6e 100644
--- a/README.md
+++ b/README.md
@@ -60,5 +60,31 @@ Following snippet demonstrates accessing the DataSource named `foo` via DS annot
         private DataSource dataSource;
     }
 
+Convert Driver jars to Bundle
+-----------------------------
+
+Most of the JDBC driver jars have the required OSGi headers and can be directly deployed to OSGi container
+as bundles. However some of the drivers e.g. Postgres are not having such headers and hence need to be 
+converted to OSGi bundles. For them we can use the [Bnd Wrap][2] command.
+
+For example to convert the Postgres driver jar follow the steps below
+
+    $ wget https://github.com/bndtools/bnd/releases/download/2.3.0.REL/biz.aQute.bnd-2.3.0.jar -O bnd.jar
+    $ wget http://jdbc.postgresql.org/download/postgresql-9.3-1101.jdbc41.jar
+    $ cat > bnd.bnd <<EOT
+    Bundle-Version: 9.3.1101
+    Bundle-SymbolicName: org.postgresql
+    Export-Package: org.postgresql
+    Include-Resource: @postgresql-9.3-1101.jdbc41.jar
+    EOT
+    $ java -jar bnd.jar bnd.bnd
+    
+In the steps above we
+
+1. Download the bnd jar and postgres driver jar
+2. Create a bnd file with required instructions. 
+3. Execute the bnd command
+4. Resulting bundle is present in `org.postgresql-9.3.1101.jar`
  
-[1]: http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html
\ No newline at end of file
+[1]: http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html
+[2]: http://www.aqute.biz/Bnd/Wrapping
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 10/22: Update to Sling Parent POM 22 with baselining enabled

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit 52b427b79d98b23e8ed4b157f8526cbcd48f2798
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Oct 1 06:52:29 2014 +0000

    Update to Sling Parent POM 22 with baselining enabled
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1628620 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 766911f..9970105 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@
   <parent>
     <groupId>org.apache.sling</groupId>
     <artifactId>sling</artifactId>
-    <version>20</version>
+    <version>22</version>
   </parent>
 
   <artifactId>org.apache.sling.extensions.datasource</artifactId>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 17/22: SLING-4147 - Remove extensions from package name org.apache.sling.extensions.datasource.internal

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit 4d503bd7b2cf35c3cfd132d3c7b659cc10ef17be
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 15 10:58:40 2015 +0000

    SLING-4147 - Remove extensions from package name org.apache.sling.extensions.datasource.internal
    
    -- Fixing the artifactId to not have extension
    -- Fix test class package name and jacoco config to not have extensions
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1652046 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                                               | 4 ++--
 .../org/apache/sling/{extensions => }/datasource/DataSourceIT.java    | 2 +-
 .../apache/sling/{extensions => }/datasource/DataSourceTestBase.java  | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index ddd8fa7..f078ce3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@
     <version>22</version>
   </parent>
 
-  <artifactId>org.apache.sling.extensions.datasource</artifactId>
+  <artifactId>org.apache.sling.datasource</artifactId>
   <packaging>bundle</packaging>
   <version>1.0.1-SNAPSHOT</version>
 
@@ -268,7 +268,7 @@
                 <configuration>
                   <propertyName>coverage.command</propertyName>
                   <includes>
-                    <include>org.apache.sling.extensions.datasource.internal.*</include>
+                    <include>org.apache.sling.datasource.internal.*</include>
                   </includes>
                 </configuration>
               </execution>
diff --git a/src/test/java/org/apache/sling/extensions/datasource/DataSourceIT.java b/src/test/java/org/apache/sling/datasource/DataSourceIT.java
similarity index 98%
rename from src/test/java/org/apache/sling/extensions/datasource/DataSourceIT.java
rename to src/test/java/org/apache/sling/datasource/DataSourceIT.java
index 73fd3f2..9a771f5 100644
--- a/src/test/java/org/apache/sling/extensions/datasource/DataSourceIT.java
+++ b/src/test/java/org/apache/sling/datasource/DataSourceIT.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.extensions.datasource;
+package org.apache.sling.datasource;
 
 import java.sql.Connection;
 import java.util.Dictionary;
diff --git a/src/test/java/org/apache/sling/extensions/datasource/DataSourceTestBase.java b/src/test/java/org/apache/sling/datasource/DataSourceTestBase.java
similarity index 99%
rename from src/test/java/org/apache/sling/extensions/datasource/DataSourceTestBase.java
rename to src/test/java/org/apache/sling/datasource/DataSourceTestBase.java
index 7415017..b7b7899 100644
--- a/src/test/java/org/apache/sling/extensions/datasource/DataSourceTestBase.java
+++ b/src/test/java/org/apache/sling/datasource/DataSourceTestBase.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.extensions.datasource;
+package org.apache.sling.datasource;
 
 import java.io.File;
 import java.io.IOException;

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 06/22: SLING-3642 - Support modifying of DataSource properties at runtime without restart

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit d5aa6ddbbf7394a6f471ec54bdf34dd3a9b4f524
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Wed Jun 4 13:24:57 2014 +0000

    SLING-3642 - Support modifying of DataSource properties at runtime without restart
    
    -- Added support to refresh connectionPool associated with DataSource with new config
    -- Made the metatype more richer
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1600199 13f79535-47bb-0310-9956-ffa450edef68
---
 .../datasource/internal/DataSourceFactory.java     | 287 ++++++++++++++++-----
 .../OSGI-INF/metatype/metatype.properties          |  95 ++++++-
 .../sling/extensions/datasource/DataSourceIT.java  |  21 +-
 3 files changed, 327 insertions(+), 76 deletions(-)

diff --git a/src/main/java/org/apache/sling/extensions/datasource/internal/DataSourceFactory.java b/src/main/java/org/apache/sling/extensions/datasource/internal/DataSourceFactory.java
index 43b5815..eb56710 100644
--- a/src/main/java/org/apache/sling/extensions/datasource/internal/DataSourceFactory.java
+++ b/src/main/java/org/apache/sling/extensions/datasource/internal/DataSourceFactory.java
@@ -20,25 +20,30 @@ package org.apache.sling.extensions.datasource.internal;
 
 import java.lang.management.ManagementFactory;
 import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.Dictionary;
+import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
 
 import javax.management.InstanceNotFoundException;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
-import javax.sql.DataSource;
 
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.ConfigurationPolicy;
 import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Modified;
 import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.PropertyOption;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.tomcat.jdbc.pool.ConnectionPool;
-import org.apache.tomcat.jdbc.pool.DataSourceProxy;
+import org.apache.tomcat.jdbc.pool.DataSource;
 import org.apache.tomcat.jdbc.pool.PoolConfiguration;
 import org.apache.tomcat.jdbc.pool.PoolProperties;
 import org.osgi.framework.BundleContext;
@@ -61,6 +66,9 @@ public class DataSourceFactory {
     @Property
     static final String PROP_DATASOURCE_NAME = "datasource.name";
 
+    @Property(value = PROP_DATASOURCE_NAME)
+    static final String PROP_DS_SVC_PROP_NAME = "datasource.svc.prop.name";
+
     @Property
     static final String PROP_DRIVERCLASSNAME = "driverClassName";
 
@@ -73,12 +81,103 @@ public class DataSourceFactory {
     @Property(passwordValue = "")
     static final String PROP_PASSWORD = "password";
 
+    /**
+     * Value indicating default value should be used. if the value is set to
+     * this value then that value would be treated as null
+     */
+    static final String DEFAULT_VAL = "default";
+
+    @Property(value = DEFAULT_VAL, options = {
+            @PropertyOption(name = "Default", value = DEFAULT_VAL),
+            @PropertyOption(name = "true", value = "true"),
+            @PropertyOption(name = "false", value = "false")})
+    static final String PROP_DEFAULTAUTOCOMMIT = "defaultAutoCommit";
+
+    @Property(value = DEFAULT_VAL, options = {
+            @PropertyOption(name = "Default", value = DEFAULT_VAL),
+            @PropertyOption(name = "true", value = "true"),
+            @PropertyOption(name = "false", value = "false")})
+    static final String PROP_DEFAULTREADONLY = "defaultReadOnly";
+
+    @Property(value = DEFAULT_VAL, options = {
+            @PropertyOption(name = "Default", value = DEFAULT_VAL),
+            @PropertyOption(name = "NONE", value = "NONE"),
+            @PropertyOption(name = "READ_COMMITTED", value = "READ_COMMITTED"),
+            @PropertyOption(name = "READ_UNCOMMITTED", value = "READ_UNCOMMITTED"),
+            @PropertyOption(name = "REPEATABLE_READ", value = "REPEATABLE_READ"),
+            @PropertyOption(name = "SERIALIZABLE", value = "SERIALIZABLE")})
+    static final String PROP_DEFAULTTRANSACTIONISOLATION = "defaultTransactionIsolation";
+
+    @Property
+    static final String PROP_DEFAULTCATALOG = "defaultCatalog";
+
     @Property(intValue = PoolProperties.DEFAULT_MAX_ACTIVE)
     static final String PROP_MAXACTIVE = "maxActive";
 
+    @Property(intValue = PoolProperties.DEFAULT_MAX_ACTIVE)
+    static final String PROP_MAXIDLE = "maxIdle"; //defaults to maxActive
+
+    @Property(intValue = 10)
+    static final String PROP_MINIDLE = "minIdle"; //defaults to initialSize
+
+    @Property(intValue = 10)
+    static final String PROP_INITIALSIZE = "initialSize";
+
+    @Property(intValue = 30000)
+    static final String PROP_MAXWAIT = "maxWait";
+
+    @Property(intValue = 0)
+    static final String PROP_MAXAGE = "maxAge";
+
+    @Property(boolValue = false)
+    static final String PROP_TESTONBORROW = "testOnBorrow";
+
+    @Property(boolValue = false)
+    static final String PROP_TESTONRETURN = "testOnReturn";
+
+    @Property(boolValue = false)
+    static final String PROP_TESTWHILEIDLE = "testWhileIdle";
+
+    @Property
+    static final String PROP_VALIDATIONQUERY = "validationQuery";
+
+    @Property(intValue = -1)
+    static final String PROP_VALIDATIONQUERY_TIMEOUT = "validationQueryTimeout";
+
+    @Property(intValue = 5000)
+    protected static final String PROP_TIMEBETWEENEVICTIONRUNSMILLIS = "timeBetweenEvictionRunsMillis";
+
+    @Property(intValue = 60000)
+    protected static final String PROP_MINEVICTABLEIDLETIMEMILLIS = "minEvictableIdleTimeMillis";
+
+    @Property
+    protected static final String PROP_CONNECTIONPROPERTIES = "connectionProperties";
+
+    @Property
+    protected static final String PROP_INITSQL = "initSQL";
+
+    @Property(value = "StatementCache;SlowQueryReport(threshold=10000);ConnectionState")
+    protected static final String PROP_INTERCEPTORS = "jdbcInterceptors";
+
+    @Property(intValue = 30000)
+    protected static final String PROP_VALIDATIONINTERVAL = "validationInterval";
+
+    @Property(boolValue = true)
+    protected static final String PROP_LOGVALIDATIONERRORS = "logValidationErrors";
+
     @Property(value = {}, cardinality = 1024)
     static final String PROP_DATASOURCE_SVC_PROPS = "datasource.svc.properties";
 
+    /**
+     * Property names where we need to treat value 'default' as null
+     */
+    private static final Set<String> PROPS_WITH_DFEAULT =
+            Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(
+                    PROP_DEFAULTAUTOCOMMIT,
+                    PROP_DEFAULTREADONLY,
+                    PROP_DEFAULTTRANSACTIONISOLATION
+            )));
+
     private final Logger log = LoggerFactory.getLogger(getClass());
 
     @Reference
@@ -86,125 +185,167 @@ public class DataSourceFactory {
 
     private String name;
 
+    private String svcPropName;
+
     private ObjectName jmxName;
 
     private ServiceRegistration dsRegistration;
 
     private DataSource dataSource;
 
+    private BundleContext bundleContext;
+
     @Activate
-    protected void activate(BundleContext bundleContext, Map<String,?> config) throws Exception {
-        Properties props = new Properties();
-        name = PropertiesUtil.toString(config.get(PROP_DATASOURCE_NAME), null);
+    protected void activate(BundleContext bundleContext, Map<String, ?> config) throws Exception {
+        this.bundleContext = bundleContext;
+        name = getDataSourceName(config);
 
         checkArgument(name != null, "DataSource name must be specified via [%s] property", PROP_DATASOURCE_NAME);
+        dataSource = new LazyJmxRegisteringDataSource(createPoolConfig(config));
 
-        //Copy the other properties first
-        Map<String,String> otherProps = PropertiesUtil.toMap(config.get(PROP_DATASOURCE_SVC_PROPS), new String[0]);
-        for(Map.Entry<String, String> e : otherProps.entrySet()){
-            props.setProperty(e.getKey(), e.getValue());
-        }
+        svcPropName = getSvcPropName(config);
+        registerDataSource(svcPropName);
 
-        props.setProperty(org.apache.tomcat.jdbc.pool.DataSourceFactory.OBJECT_NAME, name);
+        log.info("Created DataSource [{}] with properties {}", name, dataSource.getPoolProperties().toString());
+    }
 
-        for(String propName : DummyDataSourceFactory.getPropertyNames()){
-            String value = PropertiesUtil.toString(config.get(propName), null);
-            if(value != null){
-                props.setProperty(propName, value);
-            }
+    @Modified
+    protected void modified(Map<String, ?> config) throws Exception {
+        String name = getDataSourceName(config);
+        String svcPropName = getSvcPropName(config);
+
+        if (!this.name.equals(name) || !this.svcPropName.equals(svcPropName)) {
+            log.info("Change in datasource name/service property name detected. DataSource would be recreated");
+            deactivate();
+            activate(bundleContext, config);
+            return;
         }
 
-        dataSource = createDataSource(props, bundleContext);
-        registerDataSource(bundleContext);
-        log.info("Created DataSource [{}] with properties {}", name, getDataSourceDetails());
+        //Other modifications can be applied at runtime itself
+        //Tomcat Connection Pool is decoupled from DataSource so can be closed and reset
+        dataSource.setPoolProperties(createPoolConfig(config));
+        closeConnectionPool();
+        dataSource.createPool();
+        log.info("Updated DataSource [{}] with properties {}", name, dataSource.getPoolProperties().toString());
     }
 
     @Deactivate
-    protected void deactivate(){
-        if(dsRegistration != null){
+    protected void deactivate() {
+        if (dsRegistration != null) {
             dsRegistration.unregister();
+            dsRegistration = null;
         }
 
+        closeConnectionPool();
+        dataSource = null;
+    }
+
+    private void closeConnectionPool() {
         unregisterJmx();
+        dataSource.close();
+    }
 
-        if(dataSource instanceof DataSourceProxy){
-            ((DataSourceProxy) dataSource).close();
-        }
+    private PoolConfiguration createPoolConfig(Map<String, ?> config) {
+        Properties props = new Properties();
 
-    }
+        //Copy the other properties first
+        Map<String, String> otherProps = PropertiesUtil.toMap(config.get(PROP_DATASOURCE_SVC_PROPS), new String[0]);
+        for (Map.Entry<String, String> e : otherProps.entrySet()) {
+            set(e.getKey(), e.getValue(), props);
+        }
 
-    private DataSource createDataSource(Properties props, BundleContext bundleContext) throws Exception {
-        PoolConfiguration poolProperties = org.apache.tomcat.jdbc.pool.DataSourceFactory.parsePoolProperties(props);
+        props.setProperty(org.apache.tomcat.jdbc.pool.DataSourceFactory.OBJECT_NAME, name);
 
-        DriverDataSource driverDataSource = new DriverDataSource(poolProperties, driverRegistry,
-                bundleContext, this);
+        for (String propName : DummyDataSourceFactory.getPropertyNames()) {
+            String value = PropertiesUtil.toString(config.get(propName), null);
+            set(propName, value, props);
+        }
 
         //Specify the DataSource such that connection creation logic is handled
         //by us where we take care of OSGi env
-        poolProperties.setDataSource(driverDataSource);
+        PoolConfiguration poolProperties = org.apache.tomcat.jdbc.pool.DataSourceFactory.parsePoolProperties(props);
+        poolProperties.setDataSource(createDriverDataSource(poolProperties));
+
+        return poolProperties;
+    }
 
-        // Return the configured DataSource instance
-        return new LazyJmxRegisteringDataSource(poolProperties);
+    private DriverDataSource createDriverDataSource(PoolConfiguration poolProperties) {
+        return new DriverDataSource(poolProperties, driverRegistry, bundleContext, this);
     }
 
-    private void registerDataSource(BundleContext bundleContext) {
-        Dictionary<String,Object> svcProps = new Hashtable<String, Object>();
-        svcProps.put(PROP_DATASOURCE_NAME, name);
+    private void registerDataSource(String svcPropName) {
+        Dictionary<String, Object> svcProps = new Hashtable<String, Object>();
+        svcProps.put(svcPropName, name);
         svcProps.put(Constants.SERVICE_VENDOR, "Apache Software Foundation");
         svcProps.put(Constants.SERVICE_DESCRIPTION, "DataSource service based on Tomcat JDBC");
-        dsRegistration = bundleContext.registerService(DataSource.class, dataSource, svcProps);
+        dsRegistration = bundleContext.registerService(javax.sql.DataSource.class, dataSource, svcProps);
     }
 
-    void registerJmx(ConnectionPool pool) throws SQLException {
-            org.apache.tomcat.jdbc.pool.jmx.ConnectionPool jmxPool = pool.getJmxPool();
-            if (jmxPool == null) {
-                //jmx not enabled
-                return;
-            }
-            Hashtable<String, String> table = new Hashtable<String, String>();
-            table.put("type", "ConnectionPool");
-            table.put("class", DataSource.class.getName());
-            table.put("name", ObjectName.quote(name));
+    private void registerJmx(ConnectionPool pool) throws SQLException {
+        org.apache.tomcat.jdbc.pool.jmx.ConnectionPool jmxPool = pool.getJmxPool();
+        if (jmxPool == null) {
+            //jmx not enabled
+            return;
+        }
+        Hashtable<String, String> table = new Hashtable<String, String>();
+        table.put("type", "ConnectionPool");
+        table.put("class", javax.sql.DataSource.class.getName());
+        table.put("name", ObjectName.quote(name));
 
-            try {
-                jmxName = new ObjectName("org.apache.sling", table);
-                MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
-                mbs.registerMBean(jmxPool, jmxName);
-            } catch (Exception e) {
-                log.warn("Error occurred while registering the JMX Bean for " +
-                        "connection pool with name {}", jmxName, e);
-            }
+        try {
+            jmxName = new ObjectName("org.apache.sling", table);
+            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+            mbs.registerMBean(jmxPool, jmxName);
+        } catch (Exception e) {
+            log.warn("Error occurred while registering the JMX Bean for " +
+                    "connection pool with name {}", jmxName, e);
+        }
     }
 
     ConnectionPool getPool() {
-        return ((DataSourceProxy) dataSource).getPool();
+        return dataSource.getPool();
     }
 
-    private void unregisterJmx(){
+    private void unregisterJmx() {
         try {
-            if(jmxName != null) {
+            if (jmxName != null) {
                 MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
                 mbs.unregisterMBean(jmxName);
             }
         } catch (InstanceNotFoundException ignore) {
             // NOOP
         } catch (Exception e) {
-            log.error("Unable to unregister JDBC pool with JMX",e);
+            log.error("Unable to unregister JDBC pool with JMX", e);
         }
     }
 
-    private String getDataSourceDetails() {
-        if(dataSource instanceof DataSourceProxy){
-            return ((DataSourceProxy) dataSource).getPoolProperties().toString();
-        }
-        return "<UNKNOWN>";
+    //~----------------------------------------< Config Handling >
+
+    private static String getDataSourceName(Map<String, ?> config) {
+        return PropertiesUtil.toString(config.get(PROP_DATASOURCE_NAME), null);
+    }
+
+    private static String getSvcPropName(Map<String, ?> config) {
+        return PropertiesUtil.toString(config.get(PROP_DS_SVC_PROP_NAME), PROP_DATASOURCE_NAME);
     }
 
+    private static void set(String name, String value, Properties props) {
+        if (PROPS_WITH_DFEAULT.contains(name) && DEFAULT_VAL.equals(value)) {
+            value = null;
+        }
 
+        if (value != null) {
+            value = value.trim();
+        }
 
-    public static void checkArgument(boolean expression,
-                                     String errorMessageTemplate,
-                                     Object... errorMessageArgs) {
+        if (value != null && !value.isEmpty()) {
+            props.setProperty(name, value);
+        }
+    }
+
+    private static void checkArgument(boolean expression,
+                                      String errorMessageTemplate,
+                                      Object... errorMessageArgs) {
         if (!expression) {
             throw new IllegalArgumentException(
                     String.format(errorMessageTemplate, errorMessageArgs));
@@ -225,10 +366,16 @@ public class DataSourceFactory {
             return pool;
         }
 
+        @Override
+        public void close() {
+            initialized = false;
+            super.close();
+        }
+
         private void registerJmxLazily(ConnectionPool pool) throws SQLException {
-            if(!initialized){
-                synchronized (this){
-                    if(initialized){
+            if (!initialized) {
+                synchronized (this) {
+                    if (initialized) {
                         return;
                     }
                     DataSourceFactory.this.registerJmx(pool);
@@ -242,7 +389,7 @@ public class DataSourceFactory {
      * Dummy impl to enable access to protected fields
      */
     private static class DummyDataSourceFactory extends org.apache.tomcat.jdbc.pool.DataSourceFactory {
-        static String[] getPropertyNames(){
+        static String[] getPropertyNames() {
             return ALL_PROPERTIES;
         }
     }
diff --git a/src/main/resources/OSGI-INF/metatype/metatype.properties b/src/main/resources/OSGI-INF/metatype/metatype.properties
index e0e9e5c..0984696 100644
--- a/src/main/resources/OSGI-INF/metatype/metatype.properties
+++ b/src/main/resources/OSGI-INF/metatype/metatype.properties
@@ -19,8 +19,9 @@
 
 # suppress inspection "UnusedProperty" for whole file
 
-datasource.component.name = Apache Sling JDBC DataSource
-datasource.component.description = Creates a DataSource services based on configuration provided
+datasource.component.name = Apache Sling Connection Pooled DataSource
+datasource.component.description = Creates a DataSource services based on configuration provided. For more details \
+  on the various properties refer to http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#Common_Attributes
 
 datasource.name.name = Datasource name(*)
 datasource.name.description = Name of this data source (required)
@@ -42,6 +43,94 @@ username.description=The connection username to be passed to our JDBC driver to
 password.name=Password
 password.description=The connection password to be passed to our JDBC driver to establish a connection.
 
+defaultAutoCommit.name=Auto Commit
+defaultAutoCommit.description=The default auto-commit state of connections created by this pool. (If 'default' \
+  then the setAutoCommit method will not be called.)
+
+defaultReadOnly.name=Readonly
+defaultReadOnly.description=The default read-only state of connections created by this pool.
+
+defaultTransactionIsolation.name=Transaction Isolation
+defaultTransactionIsolation.description=The default TransactionIsolation state of connections created by this \
+  pool. If 'default', the method will not be called and it defaults to the JDBC driver.
+
+defaultCatalog.name=Catalog Name
+defaultCatalog.description=The default catalog of connections created by this pool.
+
 maxActive.name=Max Active Connections
 maxActive.description=The maximum number of active connections that can be allocated from this pool at \
-  the same time. The default value is 100
\ No newline at end of file
+  the same time. The default value is 100
+
+maxIdle.name=Max Idle Connections
+maxIdle.description=The maximum number of connections that should be kept in the pool at all times. Idle \
+  connections are checked periodically (if enabled) and connections that been idle for longer than \
+  minEvictableIdleTimeMillis will be released. (also see testWhileIdle)
+
+minIdle.name=Min Idle Connections
+minIdle.description=The minimum number of established connections that should be kept in the pool at all times. \
+  The connection pool can shrink below this number if validation queries fail. Default value is derived from\
+   initialSize:10 (also see testWhileIdle)
+
+initialSize.name=Initial Size
+initialSize.description=The initial number of connections that are created when the pool is started. \
+  Default value is 10
+
+maxWait.name=Max Wait
+maxWait.description=The maximum number of milliseconds that the pool will wait (when there are no available\
+   connections) for a connection to be returned before throwing an exception. Default value is 30000 (30 seconds)
+
+maxAge.name=Max Age
+maxAge.description=Time in milliseconds to keep this connection.
+
+validationQuery.name=Validation Query
+validationQuery.description=The SQL query that will be used to validate connections from this pool before \
+  returning them to the caller. If specified, this query does not have to return any data, it just can't \
+  throw a SQLException. The default value is null. Example values are SELECT 1(mysql), select 1 from \
+  dual(oracle), SELECT 1(MS Sql Server)
+
+validationQueryTimeout.name=Validation Query timeout
+validationQueryTimeout.description=The timeout in seconds before a connection validation queries fail. A value \
+  less than or equal to zero will disable this feature. The default value is -1.
+
+testOnBorrow.name=Test on Borrow
+testOnBorrow.description=The indication of whether objects will be validated before being borrowed from the pool.
+
+testOnReturn.name=Test on Return
+testOnReturn.description=The indication of whether objects will be validated before being returned to the pool.
+
+testWhileIdle.name=Test while Idle
+testWhileIdle.description=The indication of whether objects will be validated by the idle object evictor (if any).
+
+timeBetweenEvictionRunsMillis.name=Eviction Run Interval
+timeBetweenEvictionRunsMillis.description=The number of milliseconds to sleep between runs of the idle connection\
+   validation/cleaner thread.
+
+minEvictableIdleTimeMillis.name=Eviction Idle Time
+minEvictableIdleTimeMillis.description=The minimum amount of time an object may sit idle in the pool before it \
+  is eligible for eviction.
+
+connectionProperties.name=Connection Properties
+connectionProperties.description=The connection properties that will be sent to our JDBC driver when establishing \
+  new connections. Format of the string must be [propertyName=property;]* NOTE - The "user" and "password" properties\
+   will be passed explicitly, so they do not need to be included here.
+
+initSQL.name=Init Sql
+initSQL.description=A custom query to be run when a connection is first created
+
+jdbcInterceptors.name=JDBC Interceptors
+jdbcInterceptors.description= A semicolon separated list of classnames of JDBCInterceptor. See \
+  http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#Configuring_JDBC_interceptors for more details
+
+validationInterval.name=Validation Interval
+validationInterval.description=avoid excess validation, only run validation at most at this frequency - time in \
+  milliseconds. If a connection is due for validation, but has been validated previously within this interval, \
+  it will not be validated again.
+
+logValidationErrors.name=Log Validation Error
+logValidationErrors.description=Set this to true to log errors during the validation phase to the log file
+
+datasource.svc.prop.name.name=DataSource Service Property Name
+datasource.svc.prop.name.name.description=Name of the service property which would store the DataSource Name while\
+  registering the DataSource instance as OSGi service
+
+
diff --git a/src/test/java/org/apache/sling/extensions/datasource/DataSourceIT.java b/src/test/java/org/apache/sling/extensions/datasource/DataSourceIT.java
index e75e962..a830a5c 100644
--- a/src/test/java/org/apache/sling/extensions/datasource/DataSourceIT.java
+++ b/src/test/java/org/apache/sling/extensions/datasource/DataSourceIT.java
@@ -21,6 +21,7 @@ package org.apache.sling.extensions.datasource;
 import java.sql.Connection;
 import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.concurrent.TimeUnit;
 
 import javax.inject.Inject;
 import javax.sql.DataSource;
@@ -36,6 +37,7 @@ import org.osgi.util.tracker.ServiceTracker;
 import static org.apache.commons.beanutils.BeanUtils.getProperty;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 @RunWith(PaxExam.class)
 public class DataSourceIT extends DataSourceTestBase{
@@ -50,15 +52,18 @@ public class DataSourceIT extends DataSourceTestBase{
     @Inject
     ConfigurationAdmin ca;
 
+    @SuppressWarnings("unchecked")
     @Test
     public void testDataSourceAsService() throws Exception{
         Configuration config = ca.createFactoryConfiguration(PID, null);
         Dictionary<String, Object> p = new Hashtable<String, Object>();
         p.put("url","jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
         p.put("datasource.name","test");
+        p.put("initialSize","5");
+        p.put("defaultAutoCommit","default");
+        p.put("defaultReadOnly","false");
         p.put("datasource.svc.properties",new String[]{
-                "initialSize=5",
-                "testOnBorrow=true",
+                "initSQL=SELECT 1",
         });
         p.put("maxActive",70);
         config.update(p);
@@ -77,7 +82,17 @@ public class DataSourceIT extends DataSourceTestBase{
         //Cannot access directly so access via reflection
         assertEquals("70", getProperty(ds, "poolProperties.maxActive"));
         assertEquals("5", getProperty(ds, "poolProperties.initialSize"));
-        assertEquals("true", getProperty(ds, "poolProperties.testOnBorrow"));
+        assertEquals("SELECT 1", getProperty(ds, "poolProperties.initSQL"));
+        assertEquals("false", getProperty(ds, "poolProperties.defaultReadOnly"));
+        assertNull(getProperty(ds, "poolProperties.defaultAutoCommit"));
+
+        config = ca.listConfigurations("(datasource.name=test)")[0];
+        Dictionary dic = config.getProperties();
+        dic.put("defaultReadOnly", Boolean.TRUE);
+        config.update(dic);
+
+        TimeUnit.MILLISECONDS.sleep(100);
+        assertEquals("true", getProperty(ds, "poolProperties.defaultReadOnly"));
     }
 
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-datasource] 04/22: SLING-3580 - Remove embedded Tomcat Juli jar by overriding LogFactory which delegates to Slf4j

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.datasource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-datasource.git

commit 898ba43e794466d128f29573ece1c8d300e5e6f0
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Tue May 20 11:44:03 2014 +0000

    SLING-3580 - Remove embedded Tomcat Juli jar by overriding LogFactory which delegates to Slf4j
    
    Also inlined the tomcat-jdbc jar
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/datasource@1596213 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 3a67c1f..721d31e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -64,7 +64,7 @@
             </Export-Package>
             <Embed-Dependency>
               org.apache.sling.commons.osgi;inline=org/apache/sling/commons/osgi/PropertiesUtil.class,
-              tomcat-jdbc,
+              tomcat-jdbc;inline=true,
             </Embed-Dependency>
           </instructions>
         </configuration>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.