Java Code Examples for org.springframework.data.repository.PagingAndSortingRepository

The following examples show how to use org.springframework.data.repository.PagingAndSortingRepository. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: jkes   Source File: AbstractIndexer.java    License: Apache License 2.0 6 votes vote down vote up
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));
    });
}
 
Example 2
/**
 *  更新对象的收藏数量
 * @param objType
 * @param objId
 */
public void updateFavoriteCount(int objType, long objId) {

    PagingAndSortingRepository dao = findDao(objType);

    // 找到对应的对象
    // 对象必须实现了可收藏,否则报错,可以把报错完善一下
    Favoritable bizObj = (Favoritable) dao.findOne(objId);

    // 更新收藏数量字段
    // FIXME 也可以在DAO上做,会少一些SQL
    int count = favoriteDao.countByObjTypeAndObjId(objType, objId);
    bizObj.setFavoriteCount(count);

    dao.save(bizObj);

    log.info("update  obj [type:{}, id:{}] favorite count[{}] success.", objType, objId, count);
}
 
Example 3
Source Project: quarkus   Source File: SpringDataJPAProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@BuildStep
void contributeClassesToIndex(BuildProducer<AdditionalIndexedClassesBuildItem> additionalIndexedClasses) {
    // index the Spring Data repository interfaces that extend Repository because we need to pull the generic types from it
    additionalIndexedClasses.produce(new AdditionalIndexedClassesBuildItem(
            Repository.class.getName(),
            CrudRepository.class.getName(),
            PagingAndSortingRepository.class.getName(),
            JpaRepository.class.getName(),
            QueryByExampleExecutor.class.getName()));
}
 
Example 4
Source Project: jkes   Source File: AbstractIndexer.java    License: Apache License 2.0 5 votes vote down vote up
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);
    }

}
 
Example 5
PagingAndSortingRepository<? extends BaseEntity, Long> findDao(int objType) {
    if (objType == ObjType.BLOG) {
        return blogDao;
    }

    throw new IllegalArgumentException("object type error: " + objType);
}
 
Example 6
Source Project: seckill   Source File: SecKillCommandConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
SecKillEventRepository secKillEventRepository(
    PagingAndSortingRepository<EventEntity, Integer> repository) {
  return new SecKillEventRepositoryImpl(repository);
}
 
Example 7
Source Project: seckill   Source File: SecKillEventRepositoryImpl.java    License: Apache License 2.0 4 votes vote down vote up
public SecKillEventRepositoryImpl(PagingAndSortingRepository<EventEntity, Integer> repository) {
  this.repository = repository;
}
 
Example 8
public static <T> SpringDataProviderBuilder<T, Void> forRepository(
        PagingAndSortingRepository<T, ?> repository) {
    return new SpringDataProviderBuilder<>(
            (pageable, filter) -> repository.findAll(pageable),
            filter -> repository.count());
}
 
Example 9
Source Project: wenku   Source File: UserServiceImpl.java    License: MIT License 4 votes vote down vote up
@Override
public PagingAndSortingRepository<User, String> getDao() {
    return userDao;
}
 
Example 10
Source Project: wenku   Source File: DocBaseInfoServiceImpl.java    License: MIT License 4 votes vote down vote up
@Override
public PagingAndSortingRepository<DocBaseInfo, String> getDao() {
    return docBaseInfoDao;
}
 
Example 11
Source Project: wenku   Source File: VisitorServiceImpl.java    License: MIT License 4 votes vote down vote up
@Override
public PagingAndSortingRepository<Visitor, String> getDao() {
    return visitorDao;
}
 
Example 12
Source Project: wenku   Source File: DocFileInfoServiceImpl.java    License: MIT License 4 votes vote down vote up
@Override
public PagingAndSortingRepository<DocFileInfo, String> getDao() {
    return docFileInfoDao;
}
 
Example 13
Source Project: tutorials   Source File: FooService.java    License: MIT License 4 votes vote down vote up
@Override
protected PagingAndSortingRepository<Foo, Long> getDao() {
    return dao;
}
 
Example 14
Source Project: tutorials   Source File: FooService.java    License: MIT License 4 votes vote down vote up
@Override
protected PagingAndSortingRepository<Foo, Long> getDao() {
    return dao;
}
 
Example 15
Source Project: tutorials   Source File: FooService.java    License: MIT License 4 votes vote down vote up
@Override
protected PagingAndSortingRepository<Foo, Long> getDao() {
    return dao;
}
 
Example 16
Source Project: tutorials   Source File: FooService.java    License: MIT License 4 votes vote down vote up
@Override
protected PagingAndSortingRepository<Foo, Long> getDao() {
    return dao;
}
 
Example 17
Source Project: wenku   Source File: BaseServiceImpl.java    License: MIT License votes vote down vote up
public abstract PagingAndSortingRepository<T, ID> getDao(); 
Example 18
Source Project: tutorials   Source File: AbstractService.java    License: MIT License votes vote down vote up
protected abstract PagingAndSortingRepository<T, Long> getDao(); 
Example 19
Source Project: tutorials   Source File: AbstractService.java    License: MIT License votes vote down vote up
protected abstract PagingAndSortingRepository<T, Long> getDao(); 
Example 20
Source Project: tutorials   Source File: AbstractService.java    License: MIT License votes vote down vote up
protected abstract PagingAndSortingRepository<T, Long> getDao(); 
Example 21
Source Project: tutorials   Source File: AbstractService.java    License: MIT License votes vote down vote up
protected abstract PagingAndSortingRepository<T, Long> getDao();