org.springframework.data.jpa.repository.JpaRepository Java Examples
The following examples show how to use
org.springframework.data.jpa.repository.JpaRepository.
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 File: Mocks.java From mojito with 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 #2
Source File: InterceptorService.java From heimdall with 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 #3
Source File: JooqJpaRepositoryFactory.java From blog-examples with 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 #4
Source File: SpecificationBuilder.java From spring-repository-plus with 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 #5
Source File: SpringDataJPAProcessor.java From quarkus with 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 File: RepositoryService.java From WeBASE-Collect-Bee with 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 #7
Source File: UnitBasicQueryService.java From WeBASE-Collect-Bee with 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 #8
Source File: LdapConfigService.java From cloudbreak with Apache License 2.0 | 4 votes |
@Override public JpaRepository repository() { return ldapConfigRepository; }
Example #9
Source File: AbstractArchivistServiceTest.java From cloudbreak with Apache License 2.0 | 4 votes |
@Override public JpaRepository<Resource, Long> repository() { return repository; }
Example #10
Source File: KerberosConfigService.java From cloudbreak with Apache License 2.0 | 4 votes |
@Override public JpaRepository repository() { return kerberosConfigRepository; }
Example #11
Source File: DatabaseConfigService.java From cloudbreak with Apache License 2.0 | 4 votes |
@Override public JpaRepository repository() { return repository; }
Example #12
Source File: DatabaseServerConfigService.java From cloudbreak with Apache License 2.0 | 4 votes |
@Override public JpaRepository repository() { return repository; }
Example #13
Source File: AbstractRepository.java From pnc with Apache License 2.0 | 4 votes |
public AbstractRepository( JpaRepository<T, ID> springRepository, JpaSpecificationExecutor<T> springSpecificationsExecutor) { this.springRepository = springRepository; this.springSpecificationsExecutor = springSpecificationsExecutor; }
Example #14
Source File: WxTagsServiceImpl.java From cms with Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return tagsRepository; }
Example #15
Source File: WxAccountFansServiceImpl.java From cms with Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return fansRepository; }
Example #16
Source File: AccountServiceImpl.java From cms with Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return accountRepository; }
Example #17
Source File: SystemLogServiceImpl.java From cms with Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return systemLogRepository; }
Example #18
Source File: KeyDataServiceImpl.java From cms with Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return keyDataRepository; }
Example #19
Source File: OrderRepository.java From dog with GNU Lesser General Public License v3.0 | 4 votes |
@Override public JpaRepository<Orderdao, Integer> repository(){ return repository; }
Example #20
Source File: AdServiceImpl.java From cms with Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return adRepository; }
Example #21
Source File: ArticleServiceImpl.java From cms with Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return articleRepository; }
Example #22
Source File: WxArticleTemplateServiceImpl.java From cms with Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return articleTemplateRepository; }
Example #23
Source File: MenuServiceImpl.java From cms with Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return menuRepository; }
Example #24
Source File: VerifyCodeServiceImpl.java From cms with Apache License 2.0 | 4 votes |
@Override protected JpaRepository getRepository() { return verifyCodeRepository; }
Example #25
Source File: SpecificationBuilder.java From spring-repository-plus with 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 #26
Source File: TestBase.java From infobip-spring-data-querydsl with Apache License 2.0 | 4 votes |
@AfterEach public void clearRepositories() { repositories.forEach(JpaRepository::deleteAllInBatch); }
Example #27
Source File: UserRepository.java From dog with GNU Lesser General Public License v3.0 | 4 votes |
@Override public JpaRepository<User, String> repository() { return repository; }
Example #28
Source File: JpaUtils.java From spring-boot with 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 File: AbstractService.java From cms with Apache License 2.0 | votes |
protected abstract JpaRepository getRepository();
Example #30
Source File: AbstractArchivistService.java From cloudbreak with Apache License 2.0 | votes |
public abstract JpaRepository repository();