Java Code Examples for org.springframework.data.jpa.repository.JpaRepository
The following examples show how to use
org.springframework.data.jpa.repository.JpaRepository.
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: heimdall Author: getheimdall File: InterceptorService.java License: Apache License 2.0 | 6 votes |
private List<Long> ignoredValidate(List<Long> ignoredList, JpaRepository<?, Long> repository) { List<Long> invalids = new ArrayList<>(); if (ignoredList != null && !ignoredList.isEmpty()) { for (Long ignored : ignoredList) { Object o = repository.findOne(ignored); if (o == null) { invalids.add(ignored); } } } return invalids; }
Example #2
Source Project: mojito Author: box File: Mocks.java License: Apache License 2.0 | 6 votes |
/** * Creates a simple mock for a {@link JpaRepository} that mocks the * {@link JpaRepository#getOne(java.io.Serializable)} to return a base * entity that only has its id set. * * @param <U> type of repository * @param <T> type of repository entity * @param repositoryClass class of repository to be created * @param entityClass class of the entity to be created and returned by that mock * @param id the id that will be set on the created entity * @return */ static public <U extends JpaRepository<T, Long>, T extends BaseEntity> U getJpaRepositoryMockForGetOne(Class<U> repositoryClass, Class<T> entityClass, Long id) { try { T baseEntity = entityClass.newInstance(); baseEntity.setId(id); U mock = mock(repositoryClass); when(mock.getOne(id)).thenReturn(baseEntity); return mock; } catch (IllegalAccessException | InstantiationException e) { throw new RuntimeException("Can't create mock for repository", e); } }
Example #3
Source Project: WeBASE-Collect-Bee Author: WeBankFinTech File: UnitBasicQueryService.java License: Apache License 2.0 | 5 votes |
/** * Page query by unit type. * * @param req * @param unitType * @return */ public <T> CommonResponse find(UnitQueryPageReq<String> req, String unitType) { String repositoryName = StringUtils.uncapitalize(req.getUnitName() + unitType); if (repositoryService.getRepository(repositoryName).isPresent()) { JpaRepository j = repositoryService.getRepository(repositoryName).get(); Page<T> page = j.findAll(req.convert()); CommonPageRes<T> ret = new CommonPageRes<>(req); ret.setResult(page.getContent()).setTotalCount(page.getTotalElements()).setPageNo(req.getPageNo()) .setPageSize(req.getPageSize()); return ResponseUtils.data(ret); } else { return ResponseUtils.paramError("The unit name is invalid: " + req.getUnitName()); } }
Example #4
Source Project: WeBASE-Collect-Bee Author: WeBankFinTech File: RepositoryService.java License: Apache License 2.0 | 5 votes |
public Optional<JpaRepository> getRepository(String name) { for (String k : repositories.keySet()) { if (name.equalsIgnoreCase(k)) { return Optional.of(repositories.get(k)); } } return Optional.empty(); }
Example #5
Source Project: quarkus Author: quarkusio File: SpringDataJPAProcessor.java License: Apache License 2.0 | 5 votes |
@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 #6
Source Project: spring-repository-plus Author: ZhongjunTian File: SpecificationBuilder.java License: Apache License 2.0 | 5 votes |
public static <T, R extends JpaRepository<T, ?> & JpaSpecificationExecutor> SpecificationBuilder<T> selectFrom(R repository) { SpecificationBuilder<T> builder = new SpecificationBuilder<>(); builder.repository = repository; builder.specification = new SpecificationImpl(); return builder; }
Example #7
Source Project: blog-examples Author: mscharhag File: JooqJpaRepositoryFactory.java License: Apache License 2.0 | 5 votes |
protected <T, ID extends Serializable> JpaRepository<?, ?> getTargetRepository( RepositoryMetadata metadata, EntityManager entityManager) { Class<?> repositoryInterface = metadata.getRepositoryInterface(); JpaEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType()); SimpleJpaRepository<?, ?> repo; if (JooqQueryExecutor.class.isAssignableFrom(repositoryInterface)) { repo = new JooqJpaRepository(entityInformation, entityManager, jooq); } else { repo = new SimpleJpaRepository(entityInformation, entityManager); } repo.setLockMetadataProvider(LockModeRepositoryPostProcessor.INSTANCE.getLockMetadataProvider()); return repo; }
Example #8
Source Project: dog Author: sunpengChina File: OrderRepository.java License: GNU Lesser General Public License v3.0 | 4 votes |
@Override public JpaRepository<Orderdao, Integer> repository(){ return repository; }
Example #9
Source Project: dog Author: sunpengChina File: UserRepository.java License: GNU Lesser General Public License v3.0 | 4 votes |
@Override public JpaRepository<User, String> repository() { return repository; }
Example #10
Source Project: infobip-spring-data-querydsl Author: infobip File: TestBase.java License: Apache License 2.0 | 4 votes |
@AfterEach public void clearRepositories() { repositories.forEach(JpaRepository::deleteAllInBatch); }
Example #11
Source Project: spring-repository-plus Author: ZhongjunTian File: SpecificationBuilder.java License: Apache License 2.0 | 4 votes |
public static <T, R extends JpaRepository<T, ?> & JpaSpecificationExecutor> SpecificationBuilder<T> selectDistinctFrom(R repository) { SpecificationBuilder<T> builder = selectFrom(repository); builder.distinct(); return builder; }
Example #12
Source Project: cms Author: myxzjie File: VerifyCodeServiceImpl.java License: Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return verifyCodeRepository; }
Example #13
Source Project: cms Author: myxzjie File: MenuServiceImpl.java License: Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return menuRepository; }
Example #14
Source Project: cms Author: myxzjie File: WxArticleTemplateServiceImpl.java License: Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return articleTemplateRepository; }
Example #15
Source Project: cms Author: myxzjie File: ArticleServiceImpl.java License: Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return articleRepository; }
Example #16
Source Project: cms Author: myxzjie File: AdServiceImpl.java License: Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return adRepository; }
Example #17
Source Project: cms Author: myxzjie File: WxTagsServiceImpl.java License: Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return tagsRepository; }
Example #18
Source Project: cms Author: myxzjie File: KeyDataServiceImpl.java License: Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return keyDataRepository; }
Example #19
Source Project: cms Author: myxzjie File: SystemLogServiceImpl.java License: Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return systemLogRepository; }
Example #20
Source Project: cms Author: myxzjie File: AccountServiceImpl.java License: Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return accountRepository; }
Example #21
Source Project: cms Author: myxzjie File: WxAccountFansServiceImpl.java License: Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return fansRepository; }
Example #22
Source Project: pnc Author: project-ncl File: AbstractRepository.java License: Apache License 2.0 | 4 votes |
public AbstractRepository( JpaRepository<T, ID> springRepository, JpaSpecificationExecutor<T> springSpecificationsExecutor) { this.springRepository = springRepository; this.springSpecificationsExecutor = springSpecificationsExecutor; }
Example #23
Source Project: cloudbreak Author: hortonworks File: DatabaseServerConfigService.java License: Apache License 2.0 | 4 votes |
@Override public JpaRepository repository() { return repository; }
Example #24
Source Project: cloudbreak Author: hortonworks File: DatabaseConfigService.java License: Apache License 2.0 | 4 votes |
@Override public JpaRepository repository() { return repository; }
Example #25
Source Project: cloudbreak Author: hortonworks File: KerberosConfigService.java License: Apache License 2.0 | 4 votes |
@Override public JpaRepository repository() { return kerberosConfigRepository; }
Example #26
Source Project: cloudbreak Author: hortonworks File: LdapConfigService.java License: Apache License 2.0 | 4 votes |
@Override public JpaRepository repository() { return ldapConfigRepository; }
Example #27
Source Project: cloudbreak Author: hortonworks File: AbstractArchivistServiceTest.java License: Apache License 2.0 | 4 votes |
@Override public JpaRepository<Resource, Long> repository() { return repository; }
Example #28
Source Project: spring-boot Author: h819 File: JpaUtils.java License: Apache License 2.0 | 3 votes |
/** * 无查询条件,进行分页查询。 * findAll() 方法,会进行两次查询,先做 count 查询,之后是具体查询,所以 Page 中包含了总数和具体查询结果集 * <p> * 仅是 repository 类型不同,没有和上一个方法合并 * * @param repository 查询器,必须是 extends JpaRepository<???, Long>, JpaSpecificationExecutor 类型的写法。 * @param currentPageNo 当前页,起始页为 1 * @param pageSize 页面可显示行数 * @param sort * @return */ public static Page getPage(JpaRepository repository, int currentPageNo, int pageSize, Sort sort) { //jpa 中起始页为 0,但传递过来的参数 currentPageNo 不能小于1 Assert.isTrue(currentPageNo >= 1, "currentPageNo 需要 >= 1 "); currentPageNo = currentPageNo - 1; return repository.findAll(new PageRequest(currentPageNo, pageSize, sort)); }
Example #29
Source Project: dog Author: sunpengChina File: DogJpaRepository.java License: GNU Lesser General Public License v3.0 | votes |
public abstract JpaRepository<T,ID> repository();
Example #30
Source Project: cms Author: myxzjie File: AbstractService.java License: Apache License 2.0 | votes |
protected abstract JpaRepository getRepository();