当前位置: 首页>>代码示例>>Java>>正文


Java JpaRepository类代码示例

本文整理汇总了Java中org.springframework.data.jpa.repository.JpaRepository的典型用法代码示例。如果您正苦于以下问题:Java JpaRepository类的具体用法?Java JpaRepository怎么用?Java JpaRepository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JpaRepository类属于org.springframework.data.jpa.repository包,在下文中一共展示了JpaRepository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseBaseEntity

import org.springframework.data.jpa.repository.JpaRepository; //导入依赖的package包/类
/**
 * Updates a BaseEntity in the database
 *
 * @param value     data to edit
 * @param fieldType type of baseentity
 * @return edited base entity
 * @throws JSONException the exception
 */
private BaseEntity parseBaseEntity(final JSONObject value, final Class fieldType) throws JSONException {
    final JpaRepository repository = getFieldRepository(fieldType);
    Optional<BaseEntity> entity = Optional.empty();

    if (value.has("id") && (!value.isNull("id"))) {
        final String id = value.get("id").toString();
        entity = Optional.ofNullable((BaseEntity) repository.findOne(id));
    }

    if (!entity.isPresent()) {
        try {
            entity = Optional.ofNullable((BaseEntity) Class.forName(fieldType.getName()).newInstance());
        } catch (InstantiationException | ClassNotFoundException | IllegalAccessException e1) {
            logger.info("[FormParse] [parseBaseEntity] Failure To Create Class Instance", e1);
        }
    }
    entity.ifPresent(e -> {
        final ParameterMapParser parser = new ParameterMapParser(value);
        parser.loopData((key, data) -> writeToEntity(e, key, data));
        repository.saveAndFlush(e);
    });

    return entity.orElseGet(null);
}
 
开发者ID:mhaddon,项目名称:Sound.je,代码行数:33,代码来源:FormParse.java

示例2: getJpaRepositoryMockForGetOne

import org.springframework.data.jpa.repository.JpaRepository; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:box,项目名称:mojito,代码行数:28,代码来源:Mocks.java

示例3: scanForJpaRepositories

import org.springframework.data.jpa.repository.JpaRepository; //导入依赖的package包/类
private Map<Class<?>, Set<Class<?>>> scanForJpaRepositories(final String basePackage) {
    final Map<Class<?>, Set<Class<?>>> jpaRepositories = new HashMap<Class<?>, Set<Class<?>>>();
    final ClassPathScanner scanner = new ClassPathScanner().withInterfacesOnly();
    scanner.addIncludeFilter(new AssignableTypeFilter(JpaRepository.class));

    final Set<BeanDefinition> candidateComponents = scanner.findCandidateComponents(basePackage);
    for (final BeanDefinition bd : candidateComponents) {
        final String beanClassName = bd.getBeanClassName();
        final Class<?> repositoryClass = Reflections.classForName(beanClassName);
        if (!IDao.class.isAssignableFrom(repositoryClass)) {
            final Class<?>[] typeArguments = Reflections.resolveTypeArguments(repositoryClass, JpaRepository.class);
            Assertions.assertThat(typeArguments.length).isEqualTo(2);
            final Class<?> entity = typeArguments[0];
            Set<Class<?>> set = jpaRepositories.get(entity);
            if (set == null) {
                set = new HashSet<Class<?>>();
                jpaRepositories.put(entity, set);
            }
            Assertions.assertThat(set.add(repositoryClass)).isTrue();
        }
    }
    return jpaRepositories;
}
 
开发者ID:subes,项目名称:invesdwin-context-persistence,代码行数:24,代码来源:JpaRepositoryScanContextLocation.java

示例4: parseCSVDatabaseIndexes

import org.springframework.data.jpa.repository.JpaRepository; //导入依赖的package包/类
/**
 * Parses a comma separated value of database indexes.
 * Retrieves all the items from the database and adds them to an array to save them to the object
 *
 * @param value           CSV of indexes
 * @param repositoryClass repository of entities
 * @return array of entities
 */
private Collection<BaseEntity> parseCSVDatabaseIndexes(final String value, final Class repositoryClass) {
    final Set<BaseEntity> elements = new HashSet<>();
    final JpaRepository repository = getFieldRepository(repositoryClass);
    Arrays.stream(value.split(","))
            .distinct()
            .filter(Objects::nonNull)
            .filter(UUIDConverter::isUUID)
            .forEach(id -> elements.add((BaseEntity) repository.getOne(id)));
    return elements;
}
 
开发者ID:mhaddon,项目名称:Sound.je,代码行数:19,代码来源:FormParse.java

示例5: beforeMethod

import org.springframework.data.jpa.repository.JpaRepository; //导入依赖的package包/类
@BeforeMethod
@SuppressWarnings({"unchecked"})
public void beforeMethod() {
    repository = mock(JpaRepository.class);

    presenter = new TestPresenter(repository, new EntityUtil());

    ApplicationContext applicationContext = mock(ApplicationContext.class);
    testView = mock(TestView.class);
    when(applicationContext.getBean(TestView.class)).thenReturn(testView);

    presenter.setApplicationContext(applicationContext);
}
 
开发者ID:limbr-management,项目名称:limbr,代码行数:14,代码来源:EntityEditorPresenterTest.java

示例6: getTargetRepository

import org.springframework.data.jpa.repository.JpaRepository; //导入依赖的package包/类
@Override
protected <T, ID extends Serializable> JpaRepository<?, ?> getTargetRepository(
		RepositoryMetadata metadata, EntityManager entityManager) {

	JpaEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata
			.getDomainType());
	return new GenericRepositoryImpl(entityInformation, entityManager); // custom
																		// implementation
}
 
开发者ID:pengqiuyuan,项目名称:g2,代码行数:10,代码来源:DefaultRepositoryFactory.java

示例7: clearRepositories

import org.springframework.data.jpa.repository.JpaRepository; //导入依赖的package包/类
@After
public void clearRepositories() throws Exception {

    repositories.forEach(JpaRepository::deleteAllInBatch);
}
 
开发者ID:infobip,项目名称:infobip-spring-data-jpa-querydsl,代码行数:6,代码来源:TestBase.java

示例8: setDao

import org.springframework.data.jpa.repository.JpaRepository; //导入依赖的package包/类
public void setDao(final JpaRepository<T, String> repository) {
	this.repository = repository;
}
 
开发者ID:eduyayo,项目名称:gamesboard,代码行数:4,代码来源:BaseServiceImpl.java

示例9: selectFrom

import org.springframework.data.jpa.repository.JpaRepository; //导入依赖的package包/类
public static <ENTITY, REPO extends JpaRepository<ENTITY, ?> & JpaSpecificationExecutor>
SpecificationBuilder<ENTITY> selectFrom(REPO repository) {
    SpecificationBuilder<ENTITY> builder = new SpecificationBuilder<>();
    builder.repository = repository;
    builder.specification = new SpecificationImpl();
    return builder;
}
 
开发者ID:ZhongjunTian,项目名称:spring-repository-plus,代码行数:8,代码来源:SpecificationBuilder.java

示例10: selectDistinctFrom

import org.springframework.data.jpa.repository.JpaRepository; //导入依赖的package包/类
public static <ENTITY, REPO extends JpaRepository<ENTITY, ?> & JpaSpecificationExecutor>
SpecificationBuilder<ENTITY> selectDistinctFrom(REPO repository) {
    SpecificationBuilder<ENTITY> builder = selectFrom(repository);
    builder.distinct();
    return builder;
}
 
开发者ID:ZhongjunTian,项目名称:spring-repository-plus,代码行数:7,代码来源:SpecificationBuilder.java

示例11: MagicService

import org.springframework.data.jpa.repository.JpaRepository; //导入依赖的package包/类
public MagicService(JpaRepository<T, String> jpaRepository) {
    this.jpaRepository = jpaRepository;
}
 
开发者ID:finefuture,项目名称:data-migration,代码行数:4,代码来源:MagicService.java

示例12: getRepository

import org.springframework.data.jpa.repository.JpaRepository; //导入依赖的package包/类
@Override
protected JpaRepository<HuntingClubGroup, Long> getRepository() {
    return huntingClubGroupRepository;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:5,代码来源:HuntingClubGroupCrudFeature.java

示例13: getRepository

import org.springframework.data.jpa.repository.JpaRepository; //导入依赖的package包/类
@Override
protected JpaRepository<HuntingClub, Long> getRepository() {
    return huntingClubRepository;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:5,代码来源:HuntingClubCrudFeature.java

示例14: getRepository

import org.springframework.data.jpa.repository.JpaRepository; //导入依赖的package包/类
@Override
protected JpaRepository<HuntingClubArea, Long> getRepository() {
    return huntingClubAreaRepository;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:5,代码来源:HuntingClubAreaCrudFeature.java

示例15: getRepository

import org.springframework.data.jpa.repository.JpaRepository; //导入依赖的package包/类
@Override
protected JpaRepository<GroupHuntingDay, Long> getRepository() {
    return huntingDayRepository;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:5,代码来源:GroupHuntingDayCrudFeature.java


注:本文中的org.springframework.data.jpa.repository.JpaRepository类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。