sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arv...@apache.org
Subject svn commit: r1209796 - in /incubator/sqoop/branches/sqoop2: ./ core/ core/src/main/java/org/apache/sqoop/core/ core/src/main/java/org/apache/sqoop/repository/ core/src/main/java/org/apache/sqoop/utils/ repository/repository-derby/src/main/java/org/apac...
Date Sat, 03 Dec 2011 00:22:03 GMT
Author: arvind
Date: Sat Dec  3 00:22:03 2011
New Revision: 1209796

URL: http://svn.apache.org/viewvc?rev=1209796&view=rev
Log:
SQOOP-365. Formalizing repository infrastructure.

Added:
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryContext.java
  (with props)
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryHandler.java
  (with props)
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryProvider.java
  (with props)
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcTransactionIsolation.java
  (with props)
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepoConfigurationConstants.java
  (with props)
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/Repository.java
  (with props)
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java
  (with props)
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryManager.java
  (with props)
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryProvider.java
  (with props)
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/utils/
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/utils/ClassLoadingUtils.java
  (with props)
Removed:
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/Repository.java
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/RepositoryContext.java
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/RepositoryManager.java
Modified:
    incubator/sqoop/branches/sqoop2/core/pom.xml
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationConstants.java
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/CoreError.java
    incubator/sqoop/branches/sqoop2/pom.xml
    incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepository.java

Modified: incubator/sqoop/branches/sqoop2/core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/pom.xml?rev=1209796&r1=1209795&r2=1209796&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/pom.xml (original)
+++ incubator/sqoop/branches/sqoop2/core/pom.xml Sat Dec  3 00:22:03 2011
@@ -38,6 +38,10 @@ limitations under the License.
       <version>2.0.0-SNAPSHOT</version>
     </dependency>
     <dependency>
+      <groupId>commons-dbcp</groupId>
+      <artifactId>commons-dbcp</artifactId>
+    </dependency>
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <scope>test</scope>

Modified: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationConstants.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationConstants.java?rev=1209796&r1=1209795&r2=1209796&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationConstants.java
(original)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationConstants.java
Sat Dec  3 00:22:03 2011
@@ -33,13 +33,6 @@ public final class ConfigurationConstant
       + "log4j.";
 
   /**
-   * All repository related configuration is prefixed with this:
-   * <tt>org.apache.sqoop.repository.</tt>
-   */
-  public static final String PREFIX_REPO_CONFIG = PREFIX_GLOBAL_CONFIG
-      + "repository.";
-
-  /**
    * The system property that must be set for specifying the system
    * configuration directory: <tt>sqoop.config.dir</tt>.
    */
@@ -58,57 +51,6 @@ public final class ConfigurationConstant
   public static final String FILENAME_BOOTCFG_FILE =
       "sqoop_bootstrap.properties";
 
-  /**
-   * Class name of the repository implementation specified by:
-   * <tt>org.apache.sqoop.repository.provider</tt>
-   */
-  public static final String SYSCFG_REPO_PROVIDER = PREFIX_REPO_CONFIG
-      + "provider";
-
-  /**
-   * Indicates if the repository should create the schema objects as necessary,
-   * specified as a boolean value for the key:
-   * <tt>org.apache.sqoop.repository.create.schema</tt>
-   */
-  public static final String SYSCFG_REPO_CREATE_SCHEMA = PREFIX_REPO_CONFIG
-      + "create.schema";
-
-  /**
-   * JDBC connection URL specified by:
-   * <tt>org.apache.sqoop.repository.jdbc.url</tt>
-   */
-  public static final String SYSCFG_REPO_JDBC_URL = PREFIX_REPO_CONFIG
-      + "jdbc.url";
-
-  /**
-   * JDBC driver to be used, specified by:
-   * <tt>org.apache.sqoop.repository.jdbc.driver</tt>
-   */
-  public static final String SYSCFG_REPO_JDBC_DRIVER = PREFIX_REPO_CONFIG
-      + "jdbc.driver";
-
-  /**
-   * JDBC connection user name, specified by:
-   * <tt>org.apache.sqoop.repository.jdbc.user</tt>
-   */
-  public static final String SYSCFG_REPO_JDBC_USER = PREFIX_REPO_CONFIG
-      + "jdbc.user";
-
-  /**
-   * JDBC connection password, specified by:
-   * <tt>org.apache.sqoop.repository.jdbc.password</tt>
-   */
-  public static final String SYSCFG_REPO_JDBC_PASSWORD = PREFIX_REPO_CONFIG
-      + "jdbc.password";
-
-  /**
-   * Prefix that is used to provide any JDBC specific properties for the
-   * system. Configuration keys which start with this prefix will be stripped
-   * of the prefix and used as regular properties for JDBC connection
-   * initialization.
-   */
-  public static final String PREFIX_SYSCFG_REPO_JDBC_PROPERTIES =
-      PREFIX_REPO_CONFIG + "jdbc.properties.";
 
   private ConfigurationConstants() {
     // Disable explicit object creation

Modified: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/CoreError.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/CoreError.java?rev=1209796&r1=1209795&r2=1209796&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/CoreError.java
(original)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/CoreError.java
Sat Dec  3 00:22:03 2011
@@ -47,13 +47,7 @@ public enum CoreError implements ErrorCo
   CORE_0006("Properties configuration provider unable to load config file"),
 
   /** The configuration system has not been initialized correctly. */
-  CORE_0007("System not initialized"),
-
-  /** The system was unable to find or load the repository provider. */
-  CORE_0008("Invalid repository provider specified"),
-
-  /** An invalid JDBC connection URL was specified. */
-  CORE_0009("Invalid JDBC connection URL specified");
+  CORE_0007("System not initialized");
 
   private final String message;
 

Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryContext.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryContext.java?rev=1209796&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryContext.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryContext.java
Sat Dec  3 00:22:03 2011
@@ -0,0 +1,191 @@
+/**
+ * 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.sqoop.repository;
+
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+import org.apache.sqoop.core.ConfigurationConstants;
+import org.apache.sqoop.core.Context;
+import org.apache.sqoop.core.CoreError;
+import org.apache.sqoop.core.SqoopException;
+
+
+public final class JdbcRepositoryContext {
+
+  private static final Logger LOG =
+      Logger.getLogger(JdbcRepositoryContext.class);
+
+  private final Context context;
+  private final String handlerClassName;
+  private final boolean createSchema;
+  private final String connectionUrl;
+  private final String driverClassName;
+  private final Properties connectionProperties;
+  private final JdbcTransactionIsolation transactionIsolation;
+  private final int maxConnections;
+
+
+  public JdbcRepositoryContext(Context context) {
+    this.context = context;
+
+    handlerClassName = context.getString(
+        RepoConfigurationConstants.SYSCFG_REPO_JDBC_HANDLER);
+
+    if (handlerClassName == null || handlerClassName.trim().length() == 0) {
+      throw new SqoopException(RepositoryError.JDBCREPO_0001,
+          RepoConfigurationConstants.SYSCFG_REPO_JDBC_HANDLER);
+    }
+
+    createSchema = context.getBoolean(
+        RepoConfigurationConstants.SYSCFG_REPO_JDBC_CREATE_SCHEMA);
+
+    connectionUrl = context.getString(
+        RepoConfigurationConstants.SYSCFG_REPO_JDBC_URL);
+
+    driverClassName = context.getString(
+        RepoConfigurationConstants.SYSCFG_REPO_JDBC_DRIVER);
+
+    String jdbcUserName = context.getString(
+        RepoConfigurationConstants.SYSCFG_REPO_JDBC_USER);
+
+    String jdbcPassword = context.getString(
+        RepoConfigurationConstants.SYSCFG_REPO_JDBC_PASSWORD);
+
+    connectionProperties = new Properties();
+
+    Map<String, String> params = context.getNestedProperties(
+        RepoConfigurationConstants.PREFIX_SYSCFG_REPO_JDBC_PROPERTIES);
+    for (String key : params.keySet()) {
+      connectionProperties.setProperty(key, params.get(key));
+    }
+
+    if (jdbcUserName != null) {
+      Object oldUser = connectionProperties.put("user", jdbcUserName);
+      if (oldUser != null) {
+        LOG.warn("Overriding user (" + oldUser
+            + ") with explicitly specified user (" + jdbcUserName + ")");
+      }
+    }
+
+    if (jdbcPassword != null) {
+      Object oldPassword = connectionProperties.put("password", jdbcPassword);
+      if (oldPassword != null) {
+        LOG.warn("Overriding password from jdbc connection properties with "
+            + "explicitly specified password.");
+      }
+    }
+
+    String txIsolation = context.getString(
+        RepoConfigurationConstants.SYSCFG_REPO_JDBC_TX_ISOLATION);
+
+    try {
+      transactionIsolation = JdbcTransactionIsolation.getByName(txIsolation);
+    } catch (IllegalArgumentException ex) {
+      throw new SqoopException(RepositoryError.JDBCREPO_0004,
+          txIsolation, ex);
+    }
+
+    String maxConnStr = context.getString(
+        RepoConfigurationConstants.SYSCFG_REPO_JDBC_MAX_CONN);
+
+    if (maxConnStr == null || maxConnStr.trim().length() == 0) {
+      throw new SqoopException(RepositoryError.JDBCREPO_0005,
+          RepoConfigurationConstants.SYSCFG_REPO_JDBC_MAX_CONN);
+    }
+
+    int maxConnInt = 0;
+    try {
+      maxConnInt = Integer.parseInt(maxConnStr);
+    } catch (NumberFormatException ex) {
+      throw new SqoopException(RepositoryError.JDBCREPO_0005, maxConnStr);
+    }
+
+    if (maxConnInt <= 0) {
+      throw new SqoopException(RepositoryError.JDBCREPO_0005, maxConnStr);
+    }
+
+    maxConnections = maxConnInt;
+
+    if (LOG.isInfoEnabled()) {
+      StringBuilder sb = new StringBuilder("[repo-ctx] ");
+      sb.append("handler=").append(handlerClassName).append(", ");
+      sb.append("create-schema=").append(createSchema).append(", ");
+      sb.append("conn-url=").append(connectionUrl).append(", ");
+      sb.append("driver=").append(driverClassName).append(", ");
+      sb.append("user=").append(jdbcUserName).append(", ");
+      sb.append("password=").append("*****").append(", ");
+      sb.append("jdbc-props={");
+      boolean first = true;
+      for (String key : params.keySet()) {
+        if (first) {
+          first = false;
+        } else {
+          sb.append(", ");
+        }
+        sb.append(key).append("=");
+        if (key.equalsIgnoreCase("password")) {
+          sb.append("*****");
+        } else {
+          sb.append(params.get(key));
+        }
+      }
+      sb.append("}").append(", ");
+      sb.append("tx-isolation=").append(transactionIsolation).append(", ");
+      sb.append("max-conn=").append(maxConnections);
+
+      LOG.info(sb.toString());
+    }
+  }
+
+  public String getHandlerClassName() {
+    return handlerClassName;
+  }
+
+  public String getConnectionUrl() {
+    return connectionUrl;
+  }
+
+  public String getDriverClass() {
+    return driverClassName;
+  }
+
+  public boolean shouldCreateSchema() {
+    return createSchema;
+  }
+
+  public JdbcTransactionIsolation getTransactionIsolation() {
+    return transactionIsolation;
+  }
+
+  public int getMaximumConnections() {
+    return maxConnections;
+  }
+
+  public Properties getConnectionProperties() {
+    Properties props = new Properties();
+    props.putAll(connectionProperties);
+
+    return props;
+  }
+
+  public Context getContext() {
+    return context;
+  }
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryHandler.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryHandler.java?rev=1209796&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryHandler.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryHandler.java
Sat Dec  3 00:22:03 2011
@@ -0,0 +1,29 @@
+/**
+ * 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.sqoop.repository;
+
+import javax.sql.DataSource;
+
+public interface JdbcRepositoryHandler {
+
+  public void initialize(DataSource dataSource,
+      JdbcRepositoryContext repoContext);
+
+  public Repository getRepository();
+
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryProvider.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryProvider.java?rev=1209796&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryProvider.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryProvider.java
Sat Dec  3 00:22:03 2011
@@ -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.sqoop.repository;
+
+import java.util.Properties;
+
+import javax.sql.DataSource;
+
+import org.apache.commons.dbcp.ConnectionFactory;
+import org.apache.commons.dbcp.DriverManagerConnectionFactory;
+import org.apache.commons.dbcp.PoolableConnectionFactory;
+import org.apache.commons.dbcp.PoolingDataSource;
+import org.apache.commons.pool.KeyedObjectPoolFactory;
+import org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory;
+import org.apache.commons.pool.impl.GenericObjectPool;
+import org.apache.log4j.Logger;
+import org.apache.sqoop.core.Context;
+import org.apache.sqoop.core.SqoopConfiguration;
+import org.apache.sqoop.core.SqoopException;
+import org.apache.sqoop.utils.ClassLoadingUtils;
+
+
+public class JdbcRepositoryProvider implements RepositoryProvider {
+
+  private static final Logger LOG =
+      Logger.getLogger(JdbcRepositoryProvider.class);
+
+  private JdbcRepositoryContext repoContext;
+
+  private JdbcRepositoryHandler handler;
+  private GenericObjectPool connectionPool;
+  private KeyedObjectPoolFactory statementPool;
+  private DataSource dataSource;
+
+  public JdbcRepositoryProvider() {
+    // Default constructor
+  }
+
+  @Override
+  public synchronized void initialize(Context context) {
+    repoContext = new JdbcRepositoryContext(SqoopConfiguration.getContext());
+
+    String jdbcHandlerClassName = repoContext.getHandlerClassName();
+
+    Class<?> handlerClass = ClassLoadingUtils.loadClass(jdbcHandlerClassName);
+
+    if (handlerClass == null) {
+      throw new SqoopException(RepositoryError.JDBCREPO_0001,
+          jdbcHandlerClassName);
+    }
+
+    try {
+      handler = (JdbcRepositoryHandler) handlerClass.newInstance();
+    } catch (Exception ex) {
+      throw new SqoopException(RepositoryError.JDBCREPO_0001,
+          jdbcHandlerClassName, ex);
+    }
+
+    String connectUrl = repoContext.getConnectionUrl();
+    if (connectUrl == null || connectUrl.trim().length() == 0) {
+      throw new SqoopException(RepositoryError.JDBCREPO_0002);
+    }
+
+    String jdbcDriverClassName = repoContext.getDriverClass();
+    if (jdbcDriverClassName == null || jdbcDriverClassName.trim().length() == 0)
+    {
+      throw new SqoopException(RepositoryError.JDBCREPO_0003);
+    }
+
+    // Initialize a datasource
+    if (ClassLoadingUtils.loadClass(jdbcDriverClassName) == null) {
+      throw new SqoopException(RepositoryError.JDBCREPO_0003,
+          jdbcDriverClassName);
+    }
+
+    Properties jdbcProps = repoContext.getConnectionProperties();
+
+    ConnectionFactory connFactory =
+        new DriverManagerConnectionFactory(connectUrl, jdbcProps);
+
+    connectionPool = new GenericObjectPool();
+    connectionPool.setMaxActive(repoContext.getMaximumConnections());
+
+    statementPool = new GenericKeyedObjectPoolFactory(null);
+
+    // creating the factor automatically wires the connection pool
+    new PoolableConnectionFactory(connFactory, connectionPool, statementPool,
+        /* FIXME validation query */null, false, false,
+        repoContext.getTransactionIsolation().getCode());
+
+    dataSource = new PoolingDataSource(connectionPool);
+
+    handler.initialize(dataSource, repoContext);
+
+    LOG.info("JdbcRepository initialized.");
+  }
+
+  @Override
+  public synchronized Repository getRepository() {
+    return handler.getRepository();
+  }
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcTransactionIsolation.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcTransactionIsolation.java?rev=1209796&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcTransactionIsolation.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcTransactionIsolation.java
Sat Dec  3 00:22:03 2011
@@ -0,0 +1,52 @@
+/**
+ * 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.sqoop.repository;
+
+import java.sql.Connection;
+
+public enum JdbcTransactionIsolation {
+
+  READ_UNCOMMITTED("READ_UNCOMMITTED", Connection.TRANSACTION_READ_UNCOMMITTED),
+  READ_COMMITTED("READ_COMMITTED", Connection.TRANSACTION_READ_COMMITTED),
+  REPEATABLE_READ("REPEATABLE_READ", Connection.TRANSACTION_REPEATABLE_READ),
+  SERIALIZABLE("SERIALIZABLE", Connection.TRANSACTION_SERIALIZABLE);
+
+  private final String name;
+  private final int code;
+
+  private JdbcTransactionIsolation(String name, int code) {
+    this.name = name;
+    this.code = code;
+  }
+
+  public int getCode() {
+    return code;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public String toString() {
+    return getName();
+  }
+
+  public static JdbcTransactionIsolation getByName(String name) {
+    return valueOf(name.trim().toUpperCase());
+  }
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcTransactionIsolation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepoConfigurationConstants.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepoConfigurationConstants.java?rev=1209796&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepoConfigurationConstants.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepoConfigurationConstants.java
Sat Dec  3 00:22:03 2011
@@ -0,0 +1,113 @@
+/**
+ * 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.sqoop.repository;
+
+import org.apache.sqoop.core.ConfigurationConstants;
+
+public final class RepoConfigurationConstants {
+
+  /**
+   * All repository related configuration is prefixed with this:
+   * <tt>org.apache.sqoop.repository.</tt>
+   */
+  public static final String PREFIX_REPO_CONFIG =
+      ConfigurationConstants.PREFIX_GLOBAL_CONFIG + "repository.";
+
+  /**
+   * Class name of the repository implementation specified by:
+   * <tt>org.apache.sqoop.repository.provider</tt>
+   */
+  public static final String SYSCFG_REPO_PROVIDER = PREFIX_REPO_CONFIG
+      + "provider";
+
+  /**
+   * Class name for the JDBC repository handler specified by:
+   * <tt>org.apache.sqoop.repository.jdbc.handler</tt>.
+   */
+  public static final String SYSCFG_REPO_JDBC_HANDLER = PREFIX_REPO_CONFIG
+      + "jdbc.handler";
+
+  /**
+   * Indicates if the repository should create the schema objects as necessary,
+   * specified as a boolean value for the key:
+   * <tt>org.apache.sqoop.repository.jdbc.create.schema</tt>
+   */
+  public static final String SYSCFG_REPO_JDBC_CREATE_SCHEMA =
+      PREFIX_REPO_CONFIG + "jdbc.create.schema";
+
+  /**
+   * JDBC connection URL specified by:
+   * <tt>org.apache.sqoop.repository.jdbc.url</tt>
+   */
+  public static final String SYSCFG_REPO_JDBC_URL = PREFIX_REPO_CONFIG
+      + "jdbc.url";
+
+  /**
+   * JDBC driver to be used, specified by:
+   * <tt>org.apache.sqoop.repository.jdbc.driver</tt>
+   */
+  public static final String SYSCFG_REPO_JDBC_DRIVER = PREFIX_REPO_CONFIG
+      + "jdbc.driver";
+
+  /**
+   * JDBC connection user name, specified by:
+   * <tt>org.apache.sqoop.repository.jdbc.user</tt>
+   */
+  public static final String SYSCFG_REPO_JDBC_USER = PREFIX_REPO_CONFIG
+      + "jdbc.user";
+
+  /**
+   * JDBC connection password, specified by:
+   * <tt>org.apache.sqoop.repository.jdbc.password</tt>
+   */
+  public static final String SYSCFG_REPO_JDBC_PASSWORD = PREFIX_REPO_CONFIG
+      + "jdbc.password";
+
+  /**
+   * JDBC Transaction Isolation, specified by:
+   * <tt>org.apache.sqoop.repository.jdbc.transaction.isolation</tt>. The valid
+   * values include: <tt>READ_UNCOMMITTED</tt>, <tt>READ_COMMITTED</tt>,
+   * <tt>REPEATABLE_READ</tt> and <tt>SERIALIZABLE</tt>.
+   */
+  public static final String SYSCFG_REPO_JDBC_TX_ISOLATION = PREFIX_REPO_CONFIG
+      + "jdbc.transaction.isolation";
+
+  /**
+   * JDBC connection pool maximum connections, specified by:
+   * <tt>org.apache.sqoop.repository.jdbc.maximum.connections</tt>
+   */
+  public static final String SYSCFG_REPO_JDBC_MAX_CONN = PREFIX_REPO_CONFIG
+      + "jdbc.maximum.connections";
+
+  /**
+   * Prefix that is used to provide any JDBC specific properties for the
+   * system. Configuration keys which start with this prefix will be stripped
+   * of the prefix and used as regular properties for JDBC connection
+   * initialization. The prefix value is
+   * <tt>org.apache.sqoop.repository.jdbc.properties.</tt> A property such as
+   * <tt>foo</tt> with value <tt>bar</tt> will be set as:
+   * <tt>org.apache.sqoop.repository.jdbc.properties.foo = bar </tt>
+   */
+  public static final String PREFIX_SYSCFG_REPO_JDBC_PROPERTIES =
+      PREFIX_REPO_CONFIG + "jdbc.properties.";
+
+
+  private RepoConfigurationConstants() {
+    // Disable explicit object creation
+  }
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepoConfigurationConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/Repository.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/Repository.java?rev=1209796&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/Repository.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/Repository.java
Sat Dec  3 00:22:03 2011
@@ -0,0 +1,30 @@
+/**
+ * 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.sqoop.repository;
+
+import org.apache.sqoop.core.Context;
+
+/**
+ * Defines the contract of a Repository used by Sqoop. A Repository allows
+ * Sqoop to store metadata, statistics and other state relevant to Sqoop
+ * Jobs in the system.
+ */
+public interface Repository {
+
+
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/Repository.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java?rev=1209796&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java
Sat Dec  3 00:22:03 2011
@@ -0,0 +1,67 @@
+/**
+ * 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.sqoop.repository;
+
+import org.apache.sqoop.core.ErrorCode;
+
+public enum RepositoryError implements ErrorCode {
+
+  // General Repository Errors: Prefix REPO
+
+  /** An unknown error has occurred. */
+  REPO_0000("An unknown error has occurred"),
+
+  /** The system was unable to find or load the repository provider. */
+  REPO_0001("Invalid repository provider specified"),
+
+
+
+  // JDBC Repository Errors: Prefix JDBCREP
+
+  /** An unknown error has occurred. */
+  JDBCREPO_0000("An unknown error has occurred"),
+
+  /** The system was unable to find or load the JDBC repository handler. */
+  JDBCREPO_0001("Invalid JDBC Repository Handler specified"),
+
+  /** An invalid JDBC connection URL was specified. */
+  JDBCREPO_0002("Invalid JDBC connection URL specified"),
+
+  /** An invalid JDBC driver class name was specified. */
+  JDBCREPO_0003("Invalid JDBC driver class specified"),
+
+  /** An invalid JDBC transaction isolation level was specified. */
+  JDBCREPO_0004("Invalid JDBC transaction isolation level specified"),
+
+  /** The value specified for maximum connection pool connections is invalid.*/
+  JDBCREPO_0005("Invalid maximum connections specified for connection pool");
+
+  private final String message;
+
+  private RepositoryError(String message) {
+    this.message = message;
+  }
+
+  public String getCode() {
+    return name();
+  }
+
+  public String getMessage() {
+    return message;
+  }
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryManager.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryManager.java?rev=1209796&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryManager.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryManager.java
Sat Dec  3 00:22:03 2011
@@ -0,0 +1,73 @@
+/**
+ * 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.sqoop.repository;
+
+import org.apache.log4j.Logger;
+import org.apache.sqoop.core.ConfigurationConstants;
+import org.apache.sqoop.core.Context;
+import org.apache.sqoop.core.CoreError;
+import org.apache.sqoop.core.SqoopConfiguration;
+import org.apache.sqoop.core.SqoopException;
+import org.apache.sqoop.utils.ClassLoadingUtils;
+
+public final class RepositoryManager {
+
+  private static final Logger LOG = Logger.getLogger(RepositoryManager.class);
+
+  private static RepositoryProvider provider;
+
+  public synchronized static void initialize() {
+    Context context = SqoopConfiguration.getContext();
+
+    String repoProviderClassName = context.getString(
+        RepoConfigurationConstants.SYSCFG_REPO_PROVIDER);
+
+    if (repoProviderClassName == null
+        || repoProviderClassName.trim().length() == 0) {
+      throw new SqoopException(RepositoryError.REPO_0001,
+          RepoConfigurationConstants.SYSCFG_REPO_PROVIDER);
+    }
+
+    if (LOG.isTraceEnabled()) {
+      LOG.trace("Repository provider: " + repoProviderClassName);
+    }
+
+    Class<?> repoProviderClass =
+        ClassLoadingUtils.loadClass(repoProviderClassName);
+
+    if (repoProviderClass == null) {
+      throw new SqoopException(RepositoryError.REPO_0001,
+          repoProviderClassName);
+    }
+
+    try {
+      provider = (RepositoryProvider) repoProviderClass.newInstance();
+    } catch (Exception ex) {
+      throw new SqoopException(RepositoryError.REPO_0001,
+          repoProviderClassName, ex);
+    }
+
+    provider.initialize(context);
+
+    LOG.info("Repository initialized: OK");
+  }
+
+  public synchronized Repository getRepository() {
+    return provider.getRepository();
+  }
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryProvider.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryProvider.java?rev=1209796&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryProvider.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryProvider.java
Sat Dec  3 00:22:03 2011
@@ -0,0 +1,28 @@
+/**
+ * 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.sqoop.repository;
+
+import org.apache.sqoop.core.Context;
+
+public interface RepositoryProvider {
+
+  public void initialize(Context context);
+
+  public Repository getRepository();
+
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/utils/ClassLoadingUtils.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/utils/ClassLoadingUtils.java?rev=1209796&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/utils/ClassLoadingUtils.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/utils/ClassLoadingUtils.java
Sat Dec  3 00:22:03 2011
@@ -0,0 +1,52 @@
+/**
+ * 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.sqoop.utils;
+
+import org.apache.log4j.Logger;
+
+public final class ClassLoadingUtils {
+
+  private static final Logger LOG = Logger.getLogger(ClassLoadingUtils.class);
+
+  public static Class<?> loadClass(String className) {
+    Class<?> klass = null;
+    try {
+      klass = Class.forName(className);
+    } catch (ClassNotFoundException ex) {
+      LOG.debug("Exception while loading class: " + className, ex);
+    }
+
+    if (klass == null) {
+      // Try the context class loader if one exists
+      ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+      if (ctxLoader != null) {
+        try {
+          klass = ctxLoader.loadClass(className);
+        } catch (ClassNotFoundException ex) {
+          LOG.debug("Exception while load class: " + className, ex);
+        }
+      }
+    }
+
+    return klass;
+  }
+
+  private ClassLoadingUtils() {
+    // Disable explicit object creation
+  }
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/utils/ClassLoadingUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/sqoop/branches/sqoop2/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/pom.xml?rev=1209796&r1=1209795&r2=1209796&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/pom.xml (original)
+++ incubator/sqoop/branches/sqoop2/pom.xml Sat Dec  3 00:22:03 2011
@@ -113,6 +113,16 @@ limitations under the License.
         <version>2.5</version>
       </dependency>
       <dependency>
+        <groupId>commons-dbcp</groupId>
+        <artifactId>commons-dbcp</artifactId>
+        <version>1.4</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.derby</groupId>
+        <artifactId>derby</artifactId>
+        <version>10.8.1.2</version>
+      </dependency>
+      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>4.9</version>

Modified: incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepository.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepository.java?rev=1209796&r1=1209795&r2=1209796&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepository.java
(original)
+++ incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepository.java
Sat Dec  3 00:22:03 2011
@@ -17,14 +17,26 @@
  */
 package org.apache.sqoop.repository.derby;
 
-import org.apache.sqoop.core.Repository;
-import org.apache.sqoop.core.RepositoryContext;
+import javax.sql.DataSource;
 
-public class DerbyRepository implements Repository {
+import org.apache.sqoop.repository.JdbcRepositoryContext;
+import org.apache.sqoop.repository.JdbcRepositoryHandler;
+import org.apache.sqoop.repository.Repository;
+
+public class DerbyRepository implements JdbcRepositoryHandler {
+
+  @Override
+  public void initialize(DataSource dataSource,
+      JdbcRepositoryContext repoContext) {
+    // TODO Auto-generated method stub
+
+  }
 
   @Override
-  public void initialize(RepositoryContext context) {
-    // FIXME
+  public Repository getRepository() {
+    // TODO Auto-generated method stub
+    return null;
   }
 
+
 }



Mime
View raw message