jackrabbit-oak-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chetan Mehrotra <chetan.mehro...@gmail.com>
Subject Re: svn commit: r1578423 - in /jackrabbit/oak/trunk/oak-core: ./ src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/
Date Tue, 18 Mar 2014 08:39:47 GMT
It would be better if we make DataSource as part of Builder itself and
remove all such logic from RDB. Or better for testing purpose or even
in normal case the RDBDocumentStore be instantiated outside and passed
in Builder. Then  main code would not have to worry about creating
DataStource and handle all possible config options that comes with
that
Chetan Mehrotra


On Mon, Mar 17, 2014 at 8:38 PM,  <reschke@apache.org> wrote:
> Author: reschke
> Date: Mon Mar 17 15:08:55 2014
> New Revision: 1578423
>
> URL: http://svn.apache.org/r1578423
> Log:
> OAK-1533 - add dbcp BasicDataSource (WIP)
>
> Added:
>     jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java
  (with props)
> Modified:
>     jackrabbit/oak/trunk/oak-core/pom.xml
>     jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java
>     jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
>
> Modified: jackrabbit/oak/trunk/oak-core/pom.xml
> URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/pom.xml?rev=1578423&r1=1578422&r2=1578423&view=diff
> ==============================================================================
> --- jackrabbit/oak/trunk/oak-core/pom.xml (original)
> +++ jackrabbit/oak/trunk/oak-core/pom.xml Mon Mar 17 15:08:55 2014
> @@ -276,6 +276,11 @@
>        <version>1.3.158</version>
>        <optional>true</optional>
>      </dependency>
> +    <dependency>
> +      <groupId>commons-dbcp</groupId>
> +      <artifactId>commons-dbcp</artifactId>
> +      <version>1.4</version>
> +    </dependency>
>
>      <!-- Logging -->
>      <dependency>
>
> Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java
> URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java?rev=1578423&r1=1578422&r2=1578423&view=diff
> ==============================================================================
> --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java
(original)
> +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java
Mon Mar 17 15:08:55 2014
> @@ -19,7 +19,6 @@ package org.apache.jackrabbit.oak.plugin
>  import java.io.Closeable;
>  import java.io.IOException;
>  import java.sql.Connection;
> -import java.sql.DriverManager;
>  import java.sql.PreparedStatement;
>  import java.sql.ResultSet;
>  import java.sql.SQLException;
> @@ -29,14 +28,14 @@ import java.util.Iterator;
>
>  import javax.sql.DataSource;
>
> -import com.google.common.collect.AbstractIterator;
> -
>  import org.apache.jackrabbit.mk.api.MicroKernelException;
> -import org.apache.jackrabbit.oak.plugins.blob.CachingBlobStore;
>  import org.apache.jackrabbit.oak.commons.StringUtils;
> +import org.apache.jackrabbit.oak.plugins.blob.CachingBlobStore;
>  import org.slf4j.Logger;
>  import org.slf4j.LoggerFactory;
>
> +import com.google.common.collect.AbstractIterator;
> +
>  public class RDBBlobStore extends CachingBlobStore implements Closeable {
>      /**
>       * Creates a {@linkplain RDBBlobStore} instance using an embedded H2
> @@ -45,8 +44,8 @@ public class RDBBlobStore extends Cachin
>      public RDBBlobStore() {
>          try {
>              String jdbcurl = "jdbc:h2:mem:oaknodes";
> -            Connection connection = DriverManager.getConnection(jdbcurl, "sa", "");
> -            initialize(connection);
> +            DataSource ds = RDBDataSourceFactory.forJdbcUrl(jdbcurl, "sa", "");
> +            initialize(ds.getConnection());
>          } catch (Exception ex) {
>              throw new MicroKernelException("initializing RDB blob store", ex);
>          }
> @@ -58,8 +57,8 @@ public class RDBBlobStore extends Cachin
>       */
>      public RDBBlobStore(String jdbcurl, String username, String password) {
>          try {
> -            Connection connection = DriverManager.getConnection(jdbcurl, username, password);
> -            initialize(connection);
> +            DataSource ds = RDBDataSourceFactory.forJdbcUrl(jdbcurl, username, password);
> +            initialize(ds.getConnection());
>          } catch (Exception ex) {
>              throw new MicroKernelException("initializing RDB blob store", ex);
>          }
>
> Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java
> URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java?rev=1578423&view=auto
> ==============================================================================
> --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java
(added)
> +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java
Mon Mar 17 15:08:55 2014
> @@ -0,0 +1,38 @@
> +/*
> + * 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.jackrabbit.oak.plugins.document.rdb;
> +
> +import java.sql.Driver;
> +import java.sql.DriverManager;
> +import java.sql.SQLException;
> +
> +import javax.sql.DataSource;
> +
> +import org.apache.commons.dbcp.BasicDataSource;
> +
> +public class RDBDataSourceFactory extends RDBMeta {
> +
> +    public static DataSource forJdbcUrl(String url, String username, String passwd)
throws SQLException {
> +        BasicDataSource bds = new BasicDataSource();
> +        Driver d = DriverManager.getDriver(url);
> +        bds.setDriverClassName(d.getClass().getName());
> +        bds.setUsername(username);
> +        bds.setPassword(passwd);
> +        bds.setUrl(url);
> +        return bds;
> +    }
> +}
>
> Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java
> ------------------------------------------------------------------------------
>     svn:eol-style = native
>
> Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
> URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java?rev=1578423&r1=1578422&r2=1578423&view=diff
> ==============================================================================
> --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
(original)
> +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
Mon Mar 17 15:08:55 2014
> @@ -17,7 +17,6 @@
>  package org.apache.jackrabbit.oak.plugins.document.rdb;
>
>  import java.sql.Connection;
> -import java.sql.DriverManager;
>  import java.sql.PreparedStatement;
>  import java.sql.ResultSet;
>  import java.sql.SQLException;
> @@ -69,8 +68,8 @@ public class RDBDocumentStore implements
>      public RDBDocumentStore(DocumentMK.Builder builder) {
>          try {
>              String jdbcurl = "jdbc:h2:mem:oaknodes";
> -            Connection connection = DriverManager.getConnection(jdbcurl, "sa", "");
> -            initialize(connection, builder);
> +            DataSource ds = RDBDataSourceFactory.forJdbcUrl(jdbcurl, "sa", "");
> +            initialize(ds.getConnection(), builder);
>          } catch (Exception ex) {
>              throw new MicroKernelException("initializing RDB document store", ex);
>          }
> @@ -94,8 +93,8 @@ public class RDBDocumentStore implements
>       */
>      public RDBDocumentStore(String jdbcurl, String username, String password, DocumentMK.Builder
builder) {
>          try {
> -            Connection connection = DriverManager.getConnection(jdbcurl, username, password);
> -            initialize(connection, builder);
> +            DataSource ds = RDBDataSourceFactory.forJdbcUrl(jdbcurl, "sa", "");
> +            initialize(ds.getConnection(), builder);
>          } catch (Exception ex) {
>              throw new MicroKernelException("initializing RDB document store", ex);
>          }
>
>

Mime
View raw message