Java 类org.springframework.data.jpa.repository.JpaRepository 实例源码

项目:Sound.je    文件:FormParse.java   
/**
 * 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);
}
项目:mojito    文件:Mocks.java   
/**
 * 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);
    }
}
项目:invesdwin-context-persistence    文件:JpaRepositoryScanContextLocation.java   
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;
}
项目:Sound.je    文件:FormParse.java   
/**
 * 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;
}
项目:spring-repository-plus    文件:SpecificationBuilder.java   
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;
}
项目:limbr    文件:EntityEditorPresenterTest.java   
@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);
}
项目:g2    文件:DefaultRepositoryFactory.java   
@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
}
项目:infobip-spring-data-jpa-querydsl    文件:TestBase.java   
@After
public void clearRepositories() throws Exception {

    repositories.forEach(JpaRepository::deleteAllInBatch);
}
项目:gamesboard    文件:BaseServiceImpl.java   
public void setDao(final JpaRepository<T, String> repository) {
    this.repository = repository;
}
项目:spring-repository-plus    文件:SpecificationBuilder.java   
public static <ENTITY, REPO extends JpaRepository<ENTITY, ?> & JpaSpecificationExecutor>
SpecificationBuilder<ENTITY> selectDistinctFrom(REPO repository) {
    SpecificationBuilder<ENTITY> builder = selectFrom(repository);
    builder.distinct();
    return builder;
}
项目:data-migration    文件:MagicService.java   
public MagicService(JpaRepository<T, String> jpaRepository) {
    this.jpaRepository = jpaRepository;
}
项目:oma-riista-web    文件:HuntingClubGroupCrudFeature.java   
@Override
protected JpaRepository<HuntingClubGroup, Long> getRepository() {
    return huntingClubGroupRepository;
}
项目:oma-riista-web    文件:HuntingClubCrudFeature.java   
@Override
protected JpaRepository<HuntingClub, Long> getRepository() {
    return huntingClubRepository;
}
项目:oma-riista-web    文件:HuntingClubAreaCrudFeature.java   
@Override
protected JpaRepository<HuntingClubArea, Long> getRepository() {
    return huntingClubAreaRepository;
}
项目:oma-riista-web    文件:GroupHuntingDayCrudFeature.java   
@Override
protected JpaRepository<GroupHuntingDay, Long> getRepository() {
    return huntingDayRepository;
}
项目:oma-riista-web    文件:GroupMemberCrudFeature.java   
@Override
protected JpaRepository<Occupation, Long> getRepository() {
    return occupationRepository;
}
项目:oma-riista-web    文件:HuntingClubMemberCrudFeature.java   
@Override
protected JpaRepository<Occupation, Long> getRepository() {
    return occupationRepository;
}
项目:oma-riista-web    文件:BasicClubHuntingSummaryCrudFeature.java   
@Override
protected JpaRepository<BasicClubHuntingSummary, Long> getRepository() {
    return basicClubHuntingSummaryRepository;
}
项目:oma-riista-web    文件:MooseHuntingSummaryCrudFeature.java   
@Override
protected JpaRepository<MooseHuntingSummary, Long> getRepository() {
    return mooseHuntingSummaryRepository;
}
项目:oma-riista-web    文件:MooseHarvestReportCrudFeature.java   
@Override
protected JpaRepository<MooseHarvestReport, Long> getRepository() {
    return mooseHarvestReportRepository;
}
项目:oma-riista-web    文件:UserCrudFeature.java   
@Override
protected JpaRepository<SystemUser, Long> getRepository() {
    return userRepository;
}
项目:oma-riista-web    文件:HarvestPermitAreaFeature.java   
@Override
protected JpaRepository<HarvestPermitArea, Long> getRepository() {
    return harvestPermitAreaRepository;
}
项目:oma-riista-web    文件:HarvestPermitCrudFeature.java   
@Override
protected JpaRepository<HarvestPermit, Long> getRepository() {
    return harvestPermitRepository;
}
项目:oma-riista-web    文件:HarvestReportCrudFeature.java   
@Override
protected JpaRepository<HarvestReport, Long> getRepository() {
    return harvestReportRepository;
}
项目:oma-riista-web    文件:RiistanhoitoyhdistysCrudFeature.java   
@Override
protected JpaRepository<Riistanhoitoyhdistys, Long> getRepository() {
    return riistanhoitoyhdistysRepository;
}
项目:oma-riista-web    文件:OccupationCrudFeature.java   
@Override
protected JpaRepository<Occupation, Long> getRepository() {
    return occupationRepository;
}
项目:oma-riista-web    文件:JHTTrainingCrudFeature.java   
@Override
protected JpaRepository<JHTTraining, Long> getRepository() {
    return jhtTrainingRepository;
}
项目:oma-riista-web    文件:OccupationNominationCrudFeature.java   
@Override
protected JpaRepository<OccupationNomination, Long> getRepository() {
    return occupationNominationRepository;
}
项目:oma-riista-web    文件:VenueCrudFeature.java   
@Override
protected JpaRepository<Venue, Long> getRepository() {
    return venueRepository;
}
项目:oma-riista-web    文件:CalendarEventCrudFeature.java   
@Override
protected JpaRepository<CalendarEvent, Long> getRepository() {
    return calendarEventRepository;
}
项目:oma-riista-web    文件:OrganisationCrudFeature.java   
@Override
protected JpaRepository<Organisation, Long> getRepository() {
    return organisationRepository;
}
项目:springJpaKata    文件:GenericController.java   
public GenericController(JpaRepository<T, Long> repo){
    this.repo = repo;
}
项目:limbr    文件:EntityEditorPresenter.java   
@Autowired
public EntityEditorPresenter(JpaRepository<T, Long> repository, EntityUtil entityUtil) {
    this.repository = repository;
    this.entityUtil = entityUtil;
}
项目:limbr    文件:RoleEditorPresenter.java   
@Autowired
public RoleEditorPresenter(JpaRepository<Role, Long> repository, EntityUtil entityUtil) {
    super(repository, entityUtil);
}
项目:limbr    文件:UserEditorPresenter.java   
@Autowired
public UserEditorPresenter(JpaRepository<User, Long> repository, EntityUtil entityUtil) {
    super(repository, entityUtil);
}
项目:limbr    文件:ProjectEditorPresenter.java   
@Autowired
public ProjectEditorPresenter(JpaRepository<Project, Long> repository, EntityUtil entityUtil) {
    super(repository, entityUtil);
}
项目:limbr    文件:EntityEditorPresenterTest.java   
public TestPresenter(JpaRepository<TestBean, Long> repository, EntityUtil entityUtil) {
    super(repository, entityUtil);
}
项目:fjorum    文件:UserServiceImpl.java   
@Override
protected JpaRepository<User, Long> getRepository() {
    return userRepository;
}
项目:fjorum    文件:ReplyServiceImpl.java   
@Override
protected JpaRepository<Reply, Long> getRepository() {
    return replyRepository;
}
项目:fjorum    文件:TopicServiceImpl.java   
@Override
protected JpaRepository<Topic, Long> getRepository() {
    return topicRepository;
}