All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.s24.search.solr.analysis.jdbc.JdbcReaderFactory Maven / Gradle / Ivy

There is a newer version: 2.3.10
Show newest version
package com.s24.search.solr.analysis.jdbc;

import java.util.Map;

import javax.sql.DataSource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Preconditions;

/**
 * Factory to create {@link JdbcReader}s from a Solr params.
 */
@SuppressWarnings("unused") // API
public class JdbcReaderFactory {
   /**
    * Logger.
    */
   private static final Logger log = LoggerFactory.getLogger(JdbcReaderFactory.class);

   /**
    * Create the {@link JdbcReader} from configuration.
    *
    * Set synonyms file to a fixed name.
    * This is needed because our patched resource loader should load the synonyms exactly once.
    *
    * @param config
    *           Configuration.
    * @param originalParamName
    *           Default synonym file name.
    * @return JdbcReader.
    */
   public static JdbcReader createFromSolrParams(Map config, String originalParamName) {
      Preconditions.checkNotNull(config);

      // Set a fixed synonyms "file".
      // This "file" will be loaded from the database by the JdbcResourceLoader.
      if (originalParamName != null) {
         config.put(originalParamName, JdbcResourceLoader.DATABASE);
      }

      DataSource dataSource = JdbcDataSourceFactory.getDataSource(config);
      String sql = config.remove(JdbcReaderFactoryParams.SQL);
      String ignoreString = config.remove(JdbcReaderFactoryParams.IGNORE);
      boolean ignore = !"false".equals(ignoreString);

      return new SimpleJdbcReader(dataSource, sql, ignore);
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy