當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。