Exemplo n.º 1
0
 public ConfigContext(
     SearchConfiguration searchConfiguration,
     BuildContext buildContext,
     SearchMapping searchMapping) {
   this.serviceManager = buildContext.getServiceManager();
   this.luceneMatchVersion = getLuceneMatchVersion(searchConfiguration);
   this.defaultLuceneAnalyzerReference = initDefaultLuceneAnalyzerReference(searchConfiguration);
   this.jpaPresent = isPresent("javax.persistence.Id");
   this.nullToken = initNullToken(searchConfiguration);
   this.implicitProvidedId = searchConfiguration.isIdProvidedImplicit();
   this.searchMapping = searchMapping;
 }
    @Override
    protected Set<String> loadInitialShardNames(Properties properties, BuildContext buildContext) {
      ServiceManager serviceManager = buildContext.getServiceManager();
      SessionFactory sessionFactory =
          serviceManager.requestService(HibernateSessionFactoryService.class).getSessionFactory();
      Session session = sessionFactory.openSession();
      try {
        Criteria initialShardsCriteria = session.createCriteria(Animal.class);
        initialShardsCriteria.setProjection(Projections.distinct(Property.forName("type")));

        @SuppressWarnings("unchecked")
        List<String> initialTypes = initialShardsCriteria.list();
        return new HashSet<String>(initialTypes);
      } finally {
        session.close();
      }
    }