zoukankan      html  css  js  c++  java
  • solr dataimport 数据导入源码分析(七)

    solr dataimport 数据导入源码分析(五) 提到了contextimpl类调用DataImporter对象获取数据源 

     contextimpl.java

     private DataSource ds;
      

    private DataImporter dataImporter;

       

    @Override

      public DataSource getDataSource() {

        if (ds != nullreturn ds;

        if(entity == nullreturn  null;

        if (entity.dataSrc == null) {

          entity.dataSrc = dataImporter.getDataSourceInstance(entity, entity.dataSource, this);

        }

        if (entity.dataSrc != null && docBuilder != null && docBuilder.verboseDebug &&

                 Context.FULL_DUMP.equals(currentProcess())) {

          //debug is not yet implemented properly for deltas

          entity.dataSrc = docBuilder.getDebugLogger().wrapDs(entity.dataSrc);

        }

        return entity.dataSrc;

      }

    我们跟踪源码,在DataImporter.java里面调用了jdbcDataSource对象方法

    参考solr dataimport 数据导入源码分析(二) DataImporter.java 源码

    DataImporter.java  

     DataSource getDataSourceInstance(DataConfig.Entity key, String name, Context ctx) {

        Properties p = dataSourceProps.get(name);
        if (p == null)
          p = config.dataSources.get(name);
        if (p == null)
          p = dataSourceProps.get(null);// for default data source
        if (p == null)
          p = config.dataSources.get(null);
        if (p == null)  
          throw new DataImportHandlerException(SEVERE,
                  "No dataSource :" + name + " available for entity :"
                          + key.name);
        String type = p.getProperty(TYPE);
        DataSource dataSrc = null;
        if (type == null) {
          dataSrc = new JdbcDataSource();
        } else {
          try {
            dataSrc = (DataSource) DocBuilder.loadClass(type, getCore()).newInstance();
          } catch (Exception e) {
            wrapAndThrow(SEVERE, e, "Invalid type for data source: " + type);
          }
        }
        try {
          Properties copyProps = new Properties();
          copyProps.putAll(p);
          Map<String, Object> map = ctx.getRequestParameters();
          if (map.containsKey("rows")) {
            int rows = Integer.parseInt((String) map.get("rows"));
            if (map.containsKey("start")) {
              rows += Integer.parseInt((String) map.get("start"));
            }
            copyProps.setProperty("maxRows", String.valueOf(rows));
          }
          dataSrc.init(ctx, copyProps);
        } catch (Exception e) {
          wrapAndThrow(SEVERE, e, "Failed to initialize DataSource: " + key.dataSource);
        }
        return dataSrc;
      }


  • 相关阅读:
    【转载】分析商品日均销量(DMS)对促销商品选择的意义
    日志备份和差异备份还原中的常见问题示例(转自&邹建)
    SQL Server 2000中的完整备份、差异备份操作
    数据库差异备份与增量备份的不同之处
    差异备份和还原操作方法(转)
    SQL备份(全)
    Microsoft SQL2000 错误代码 (@@error)
    图解SQL的inner join(join)、left join、right join、full outer join、union、union all的区别
    arm-none-linux-gnueabi-gcc command not found
    关于ST-Link的internal command error问题的解决方法
  • 原文地址:https://www.cnblogs.com/chenying99/p/2677202.html
Copyright © 2011-2022 走看看