<commit_before>// Copyright 2010 Google Inc.
//
// Licensed 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 com.google.enterprise.connector.util.database;

import com.google.common.annotations.VisibleForTesting;
import com.google.enterprise.connector.spi.ConnectorType;
import com.google.enterprise.connector.spi.DatabaseResourceBundle;
import com.google.enterprise.connector.spi.LocalDatabase;
import com.google.enterprise.connector.spi.SpiConstants.DatabaseType;

import javax.sql.DataSource;

public class LocalDatabaseImpl implements LocalDatabase {
  private final JdbcDatabase database;
  private final ClassLoader classLoader;
  private final DatabaseResourceBundleManager resourceBundleManager;

  /* Automatically generate the ResourceBundle baseName,
   * based upon the ConnectorType name and an arbitary
   * prefix and suffix. This is so much easier for the
   * Connector developer than allowing them to specify
   * the baseName of their choice.  Note that the use
   * of a baseName suffix (containing an underscore) deviates
   * considerably from the typical use of ResourceBundles
   * for natural languages, while providing no benefit to
   * the developer or user.
   */
  private static final String RESOURCE_BUNDLE_PREFIX = "config.";
  private static final String RESOURCE_BUNDLE_SUFFIX = "_sql";
  @VisibleForTesting
  protected String resourceBundleBaseName;

  /**
   * Constructs a {@link LocalDatabase} implementation for Connectors
   * of type {@code connectorTypeName}.  The {@code connectorTypeName}
   * is used to select {@link DatabaseResourceBundle}s for use by the
   * Connector.
   *
   * @param jdbcDatabase backing database for this LocalDatabase
   * @param connectorTypeName the Connector's ConnectorType name.
   * @param connectorType a ConnectorType whose ClassLoader to use to locate
   *        DatabaseResourceBundles. The may be specific to Connector type.
   *        If {@code null}, the default ClassLoader will be used.
   */
  public LocalDatabaseImpl(JdbcDatabase jdbcDatabase, String connectorTypeName,
                           ConnectorType connectorType) {
    // TODO: Does this restrict resource lookup to the JAR file containing
    // the ConnectorType?  This may or may not be desireable.
    this(jdbcDatabase, connectorTypeName, (connectorType == null) ? null :
         connectorType.getClass().getClassLoader());
  }

  /**
   * Constructs a {@link LocalDatabase} implementation for Connectors
   * of type {@code connectorTypeName}.  The {@code connectorTypeName}
   * is used to select {@link DatabaseResourceBundle}s for use by the
   * Connector.
   *
   * @param jdbcDatabase backing database for this LocalDatabase
   * @param connectorTypeName the Connector's ConnectorType name.
   * @param classLoader ClassLoader to use to locate DatabaseResourceBundles.
   *        If {@code null}, the default ClassLoader will be used.
   */
  @VisibleForTesting
  public LocalDatabaseImpl(JdbcDatabase jdbcDatabase, String connectorTypeName,<commit_msg>Fix typo in comment for LocalDatabaseImpl<commit_after>// Copyright 2010 Google Inc.
//
// Licensed 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 com.google.enterprise.connector.util.database;

import com.google.common.annotations.VisibleForTesting;
import com.google.enterprise.connector.spi.ConnectorType;
import com.google.enterprise.connector.spi.DatabaseResourceBundle;
import com.google.enterprise.connector.spi.LocalDatabase;
import com.google.enterprise.connector.spi.SpiConstants.DatabaseType;

import javax.sql.DataSource;

public class LocalDatabaseImpl implements LocalDatabase {
  private final JdbcDatabase database;
  private final ClassLoader classLoader;
  private final DatabaseResourceBundleManager resourceBundleManager;

  /* Automatically generate the ResourceBundle baseName,
   * based upon the ConnectorType name and an arbitary
   * prefix and suffix. This is so much easier for the
   * Connector developer than allowing them to specify
   * the baseName of their choice.  Note that the use
   * of a baseName suffix (containing an underscore) deviates
   * considerably from the typical use of ResourceBundles
   * for natural languages, while providing no benefit to
   * the developer or user.
   */
  private static final String RESOURCE_BUNDLE_PREFIX = "config.";
  private static final String RESOURCE_BUNDLE_SUFFIX = "_sql";
  @VisibleForTesting
  protected String resourceBundleBaseName;

  /**
   * Constructs a {@link LocalDatabase} implementation for Connectors
   * of type {@code connectorTypeName}.  The {@code connectorTypeName}
   * is used to select {@link DatabaseResourceBundle}s for use by the
   * Connector.
   *
   * @param jdbcDatabase backing database for this LocalDatabase
   * @param connectorTypeName the Connector's ConnectorType name.
   * @param connectorType a ConnectorType whose ClassLoader to use to locate
   *        DatabaseResourceBundles. The may be specific to Connector type.
   *        If {@code null}, the default ClassLoader will be used.
   */
  public LocalDatabaseImpl(JdbcDatabase jdbcDatabase, String connectorTypeName,
                           ConnectorType connectorType) {
    // TODO: Does this restrict resource lookup to the JAR file containing
    // the ConnectorType?  This may or may not be desirable.
    this(jdbcDatabase, connectorTypeName, (connectorType == null) ? null :
         connectorType.getClass().getClassLoader());
  }

  /**
   * Constructs a {@link LocalDatabase} implementation for Connectors
   * of type {@code connectorTypeName}.  The {@code connectorTypeName}
   * is used to select {@link DatabaseResourceBundle}s for use by the
   * Connector.
   *
   * @param jdbcDatabase backing database for this LocalDatabase
   * @param connectorTypeName the Connector's ConnectorType name.
   * @param classLoader ClassLoader to use to locate DatabaseResourceBundles.
   *        If {@code null}, the default ClassLoader will be used.
   */
  @VisibleForTesting
  public LocalDatabaseImpl(JdbcDatabase jdbcDatabase, String connectorTypeName,
{'fraction_non_alphanumeric': 0.06818503324374027, 'fraction_numerical': 0.0022634035931532043, 'mean_word_length': 3.98589562764457, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6208406', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1761, 'n_words': 714}