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;
      }


  • 相关阅读:
    鼠标事件:
    各种坑记录
    Go学习笔记
    Scala学习笔记-7-代码片段
    Go学习笔记
    NIO学习笔记
    Redis常用操作
    docker & k8s 笔记
    Node常用笔记
    Maven常用笔记
  • 原文地址:https://www.cnblogs.com/chenying99/p/2677202.html
Copyright © 2011-2022 走看看