Java 类org.springframework.data.repository.PagingAndSortingRepository 实例源码

项目:jkes    文件:AbstractIndexer.java   
protected void init() {
    Set<Class<?>> documentClasses = metadata.getAnnotatedDocuments();
    documentClasses.forEach(clazz -> {
        PagingAndSortingRepository repository = getRepositoryBean(clazz);
        addTask(new IndexTask() {
            @Override
            public Class<?> getDomainClass() {
                return clazz;
            }

            @Override
            public long count() {
                return repository.count();
            }

            @Override
            public Page<?> getData(Pageable pageable) {
                return repository.findAll(pageable);
            }
        });

        this.progress.put(clazz.getCanonicalName(), new IndexProgress(clazz, repository.count(), (long) 0));
    });
}
项目:crud-admin-spring-boot-starter    文件:CrudAdminController.java   
/**
 * Initialize all properties after instantiation
 */
@PostConstruct
public void postConstruct() {

    // Object Id Serializer
    if (!StringUtils.isEmpty(crudAdminProperties.getObjectidserializer())) {
        try {
            idSerializer = ((CrudAdminDefaultObjectIdSerializer) Class
                    .forName(crudAdminProperties.getObjectidserializer()).newInstance());
        } catch (Exception ex) {
            LOGGER.error("Unable to create Object Id Serializer for class  "
                    + crudAdminProperties.getObjectidserializer());
        }
    }
    if (idSerializer == null) {
        idSerializer = new CrudAdminDefaultObjectIdSerializer();
    }

    // Map of PagingAndSortingRepository
    repositoryMap = new HashMap<>();
    if (repositories != null) {
        for (PagingAndSortingRepository<?, ?> repo : repositories) {
            CrudAdminRepository repoAdmin = CrudAdminUtils.getDomainClass(repo);
            repositoryMap.put(repoAdmin.getDomainTypeNameLowerCase(), repoAdmin);
        }
    }

}
项目:crud-admin-spring-boot-starter    文件:CrudAdminUtils.java   
public static CrudAdminRepository getDomainClass(PagingAndSortingRepository<?, ?> repo) {
    try {
        Class<?>[] classes = repo.getClass().getInterfaces();
        Class<?> repoClass = classes[0];
        DefaultRepositoryMetadata metadata = new DefaultRepositoryMetadata(repoClass);
        CrudAdminRepository repoAdmin = new CrudAdminRepository(repo, metadata);
        return repoAdmin;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
项目:jkes    文件:AbstractIndexer.java   
private PagingAndSortingRepository getRepositoryBean(Class<?> entityClass) {
    String className = entityClass.getSimpleName();
    String repositoryBeanName = Character.toLowerCase(className.charAt(0)) + className.substring(1) + "Repository";
    String daoBeanName = Character.toLowerCase(className.charAt(0)) + className.substring(1) + "Dao";

    try {
        Object bean = this.contextSupport.getBean(repositoryBeanName);

        if(bean == null)
            bean = this.contextSupport.getBean(daoBeanName);

        if(bean == null) {
            RepositoryBean annotation = entityClass.getAnnotation(RepositoryBean.class);
            if(annotation != null) {
                if(StringUtils.hasText(annotation.beanName())) {
                    bean = this.contextSupport.getBean(annotation.beanName());
                    if (bean == null)
                        throw new NoAvailableRepositoryException("Couldn't find repository bean[" + annotation.beanName() + "]");

                    return (PagingAndSortingRepository) bean;
                }
                if(annotation.beanType() != void.class) {
                    bean = this.contextSupport.getBean(annotation.beanType());
                    if (bean == null)
                        throw new NoAvailableRepositoryException("Couldn't find repository bean[" + annotation.beanType() + "]");

                    return (PagingAndSortingRepository) bean;
                }
            }
        }

        if (bean == null)
            throw new NoAvailableRepositoryException(String.format("Couldn't find repository bean with name %s or %s", repositoryBeanName, daoBeanName));
        return (PagingAndSortingRepository) bean;
    } catch (InterruptedException e) {
        throw new JkesException("failed get bean: " + repositoryBeanName, e);
    }

}
项目:openlmis-template-service    文件:AuditLogInitializer.java   
/**
 * This method is part of CommandLineRunner and is called automatically by Spring.
 * @param args Main method arguments.
 */
public void run(String... args) {
  //Get all JaVers repositories.
  Map<String,Object> repositoryMap =
          applicationContext.getBeansWithAnnotation(JaversSpringDataAuditable.class);

  //For each one...
  for (Object object : repositoryMap.values()) {
    if (object instanceof PagingAndSortingRepository) {
      createSnapshots((PagingAndSortingRepository<?, ?>) object);
    } else if (object instanceof CrudRepository) {
      createSnapshots((CrudRepository<?, ?>) object);
    }
  }
}
项目:openlmis-template-service    文件:AuditLogInitializer.java   
private void createSnapshots(PagingAndSortingRepository<?, ?> repository) {
  Pageable pageable = new PageRequest(DEFAULT_PAGE_NUMBER, 2000);

  while (true) {
    Page<?> page = repository.findAll(pageable);

    if (!page.hasContent()) {
      break;
    }

    page.forEach(this::createSnapshot);

    pageable = pageable.next();
  }
}
项目:crud-admin-spring-boot-starter    文件:CrudAdminRepository.java   
public CrudAdminRepository(PagingAndSortingRepository<?, ?> repository,
        DefaultRepositoryMetadata defaultRepositoryMetadata) {
    this.repository = repository;
    this.defaultRepositoryMetadata = defaultRepositoryMetadata;
}
项目:crud-admin-spring-boot-starter    文件:CrudAdminRepository.java   
public PagingAndSortingRepository<?, ?> getRepository() {
    return repository;
}
项目:crud-admin-spring-boot-starter    文件:CrudAdminRepository.java   
@SuppressWarnings("unchecked")
public PagingAndSortingRepository<Object, Serializable> getRepositoryObjectSerializable() {
    return ((PagingAndSortingRepository<Object, Serializable>) repository);
}
项目:crud-admin-spring-boot-starter    文件:CrudAdminRepository.java   
public void setRepository(PagingAndSortingRepository<?, ?> repository) {
    this.repository = repository;
}
项目:spring-data-provider    文件:SpringDataProviderBuilder.java   
public static <T> SpringDataProviderBuilder<T, Void> forRepository(
        PagingAndSortingRepository<T, ?> repository) {
    return new SpringDataProviderBuilder<>(
            (pageable, filter) -> repository.findAll(pageable),
            filter -> repository.count());
}
项目:trippy    文件:SpringDataProviderBuilder.java   
public static <T> SpringDataProviderBuilder<T, Void> forRepository(
        PagingAndSortingRepository<T, ?> repository) {
    return new SpringDataProviderBuilder<>(
            (pageable, filter) -> repository.findAll(pageable),
            filter -> repository.count());
}
项目:bookManager    文件:GetAllPagedTransaction.java   
public GetAllPagedTransaction(Pageable page, PagingAndSortingRepository<T, ? extends Serializable> repo) {
    this.db = repo;
    this.page = page;
}
项目:openlmis-stockmanagement    文件:StockCardTemplateService.java   
private <F, T> List<T> convertAllFieldsToDto(
    PagingAndSortingRepository<F, UUID> repo, Function<F, T> converter) {
  return findAllFieldsFrom(repo)
      .map(converter)
      .collect(toList());
}
项目:openlmis-stockmanagement    文件:StockCardTemplateService.java   
private <F> Stream<F> findAllFieldsFrom(PagingAndSortingRepository<F, UUID> repo) {
  return stream(repo.findAll().spliterator(), false);
}
项目:wenku    文件:UserServiceImpl.java   
@Override
public PagingAndSortingRepository<User, String> getDao() {
    return userDao;
}
项目:wenku    文件:DocBaseInfoServiceImpl.java   
@Override
public PagingAndSortingRepository<DocBaseInfo, String> getDao() {
    return docBaseInfoDao;
}
项目:wenku    文件:VisitorServiceImpl.java   
@Override
public PagingAndSortingRepository<Visitor, String> getDao() {
    return visitorDao;
}
项目:wenku    文件:DocFileInfoServiceImpl.java   
@Override
public PagingAndSortingRepository<DocFileInfo, String> getDao() {
    return docFileInfoDao;
}
项目:spring-rest-todos    文件:JpaPersistenceCallback.java   
public JpaPersistenceCallback(PagingAndSortingRepository<T, Long> repo, Class<T> entityType) {
    this.repo = repo;
    this.entityType = entityType;
}
项目:spring-batch-support    文件:SpringDataPagingItemReader.java   
/**
 * Reader to read items in a paged manner from a {@link PagingAndSortingRepository}.
 * Implementation is stateful and writes data directly to protected properties due to ugly abstract class.
 *
 * @param repository repository to use for reading pages, must not be null.
 */
public SpringDataPagingItemReader(PagingAndSortingRepository<T, ?> repository) {
    notNull(repository, "Repository must not be null.");
    this.repository = repository;
}
项目:wenku    文件:BaseServiceImpl.java   
public abstract PagingAndSortingRepository<T, ID> getDao();