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


Java Repository类代码示例

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


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

示例1: inject

import org.springframework.data.repository.Repository; //导入依赖的package包/类
@Override
public void inject(Object result, Field field) {
  try {

    String datasourceName = field.getAnnotation(RepositoryInject.class).datasource();
    EntityManagerFactory emf = provider.getProvider(datasourceName);

    if (emf == null)
      return;

    Object repository = Proxy.newProxyInstance(RepositoryInjectStrategy.class.getClassLoader(),
      new Class[]{field.getType(), Repository.class}, new RepositoryInvocationHandler(field.getType(), emf));

    field.setAccessible(true);
    field.set(result, repository);

  } catch (Exception e) {

    log.error("Failed to create repository {}", field.getType(), e);
  }
}
 
开发者ID:jspare-projects,项目名称:jspare-container,代码行数:22,代码来源:RepositoryInjectStrategy.java

示例2: setUpRepositoryProviderMock

import org.springframework.data.repository.Repository; //导入依赖的package包/类
public static Repositories setUpRepositoryProviderMock(Map<Class<?>, Repository<?, ?>> repositoriesMap)
{
	Repositories mockRepositories = Mockito.mock(Repositories.class);
	when(mockRepositories.getRepositoryFor(any())).thenAnswer(new Answer<Object>() {
		@Override
		public Object answer(InvocationOnMock invocation) throws Throwable
		{
			Class<?> entityClass = (Class<?>) invocation.getArguments()[0];
			Repository<?, ?> repository = repositoriesMap.get(entityClass);
			if (repository == null)
			{
				throw new IllegalArgumentException("Unsupported class: " + entityClass.getName());
			}
			return repository;
		}
	});
	RepositoryProvider.setRepositories(mockRepositories);
	return mockRepositories;
}
 
开发者ID:yonadev,项目名称:yona-server,代码行数:20,代码来源:JUnitUtil.java

示例3: getRepositories

import org.springframework.data.repository.Repository; //导入依赖的package包/类
@Override
protected Map<Class<?>, Repository<?, ?>> getRepositories()
{
	Map<Class<?>, Repository<?, ?>> repositoriesMap = new HashMap<>();
	repositoriesMap.put(DeviceAnonymized.class, deviceAnonymizedRepository);
	repositoriesMap.put(UserDevice.class, userDeviceRepository);
	repositoriesMap.put(Activity.class, activityRepository);
	return repositoriesMap;
}
 
开发者ID:yonadev,项目名称:yona-server,代码行数:10,代码来源:DeviceServiceTest.java

示例4: getRepositories

import org.springframework.data.repository.Repository; //导入依赖的package包/类
@Override
protected Map<Class<?>, Repository<?, ?>> getRepositories()
{
	Map<Class<?>, Repository<?, ?>> repositoriesMap = new HashMap<>();
	repositoriesMap.put(DeviceAnonymized.class, deviceAnonymizedRepository);
	repositoriesMap.put(BuddyAnonymized.class, buddyAnonymizedRepository);
	return repositoriesMap;
}
 
开发者ID:yonadev,项目名称:yona-server,代码行数:9,代码来源:AddFirstDeviceTest.java

示例5: getRepositories

import org.springframework.data.repository.Repository; //导入依赖的package包/类
@Override
protected Map<Class<?>, Repository<?, ?>> getRepositories()
{
	Map<Class<?>, Repository<?, ?>> repositoriesMap = new HashMap<>();
	repositoriesMap.put(MessageSource.class, mockMessageSourceRepository);
	return repositoriesMap;
}
 
开发者ID:yonadev,项目名称:yona-server,代码行数:8,代码来源:UserServiceTest.java

示例6: getRepositories

import org.springframework.data.repository.Repository; //导入依赖的package包/类
@Override
protected Map<Class<?>, Repository<?, ?>> getRepositories()
{
	Map<Class<?>, Repository<?, ?>> repositoriesMap = new HashMap<>();
	repositoriesMap.put(DeviceAnonymized.class, deviceAnonymizedRepository);
	repositoriesMap.put(BuddyAnonymized.class, buddyAnonymizedRepository);
	repositoriesMap.put(Message.class, mockMessageRepository);
	return repositoriesMap;
}
 
开发者ID:yonadev,项目名称:yona-server,代码行数:10,代码来源:BuddyDeviceChangeMessageDtoTest.java

示例7: setUpPerTestBase

import org.springframework.data.repository.Repository; //导入依赖的package包/类
@Before
public final void setUpPerTestBase()
{
	MockitoAnnotations.initMocks(this);

	Map<Class<?>, Repository<?, ?>> repositoriesMap = new HashMap<>();
	repositoriesMap.put(User.class, userRepository);
	repositoriesMap.put(UserAnonymized.class, userAnonymizedRepository);
	repositoriesMap.putAll(getRepositories());
	Set<CrudRepository<?, ?>> crudRepositories = filterForCrudRepositories(repositoriesMap.values());
	crudRepositories.forEach(CrudRepository::deleteAll);
	crudRepositories.stream().filter(this::isMock).forEach(r -> JUnitUtil.setUpRepositoryMock(r));
	JUnitUtil.setUpRepositoryProviderMock(repositoriesMap);
}
 
开发者ID:yonadev,项目名称:yona-server,代码行数:15,代码来源:BaseSpringIntegrationTest.java

示例8: generateCustomImplementation

import org.springframework.data.repository.Repository; //导入依赖的package包/类
private Object generateCustomImplementation() {
    EntityManagerFactory emf = context.getBean(entityManagerFactoryRef, EntityManagerFactory.class);
    for (Class<?> clz : repositoryInterface.getInterfaces()) {
        if (Repository.class.isAssignableFrom(clz)) {
            continue;
        } else if (clz.getAnnotation(RepositoryDefinition.class) != null) {
            continue;
        }
        String implementation=clz.getName() + StringUtils.trimToEmpty(repositoryImplementationPostfix);
        ClassEx implClz = ClassEx.forName(implementation);
        if (implClz == null) {
            log.error("Lack of implementation class: " + clz.getName());
            throw new IllegalArgumentException("Lack of implementation class: " + implementation);
        }
        try {
            Object obj = implClz.newInstance();
            for (FieldEx field : implClz.getDeclaredFields()) {
                if (field.getAnnotation(PersistenceContext.class) != null) {
                    field.set(obj, QueryUtils.getEntityManager((JefEntityManagerFactory) emf));
                }
            }
            if (obj instanceof ApplicationContextAware) {
                ((ApplicationContextAware) obj).setApplicationContext(context);
            }
            if (obj instanceof InitializingBean) {
                ((InitializingBean) obj).afterPropertiesSet();
            }
            return obj;
        } catch (Exception ex) {
            log.error("", ex);
            return null;
        }
    }
    return null;
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:36,代码来源:GqRepositoryFactoryBean.java

示例9: mapEntityToRepository

import org.springframework.data.repository.Repository; //导入依赖的package包/类
/**
 * @param entityToRepositoryMapping
 * @param bfName
 * @param bf
 * @throws ClassNotFoundException
 */
private void mapEntityToRepository(Map<Class<?>, String> entityToRepositoryMapping,
		String bfName, BeanDefinition bf) throws ClassNotFoundException {

	// Determine the Entity Class associated with the Repo
	//
	String value = (String)bf.getPropertyValues().getPropertyValue("repositoryInterface").getValue();
	Class<?> repoInterface = Class.forName(value);
	Class<?> entityType = null;
	for(Type type : repoInterface.getGenericInterfaces()) {
		if (type instanceof ParameterizedType) {
			ParameterizedType parmType = (ParameterizedType)type;
			if (Repository.class.isAssignableFrom((Class<?>)parmType.getRawType()) &&
			    parmType.getActualTypeArguments() != null &&
			    parmType.getActualTypeArguments().length > 0) {
				entityType = (Class<?>)parmType.getActualTypeArguments()[0];
				break;
			}
		}
	}

	if (entityType == null) {
		throw new RuntimeException("Unable to determine Entity type for class " + repoInterface.getName());
	}

	// Map Entity to the RepositoryFactoryBeanSupport bean
	//
	logger.debug("Mapped \"{}\" to repo \"{}\", beanId=\"{}\"", entityType.getName(), value, bfName);

	entityToRepositoryMapping.put(entityType, bfName);
}
 
开发者ID:statefulj,项目名称:statefulj,代码行数:37,代码来源:StatefulFactory.java

示例10: setUp

import org.springframework.data.repository.Repository; //导入依赖的package包/类
@Before
public void setUp()
{
	Map<Class<?>, Repository<?, ?>> repositoriesMap = new HashMap<>();
	repositoriesMap.put(DayActivity.class, mockDayActivityRepository);
	JUnitUtil.setUpRepositoryProviderMock(repositoriesMap);

	// created 2 weeks ago
	gamblingGoal = BudgetGoal.createNoGoInstance(TimeUtil.utcNow().minusWeeks(2),
			ActivityCategory.createInstance(UUID.randomUUID(), usString("gambling"), false,
					new HashSet<>(Arrays.asList("poker", "lotto")), Collections.emptySet(), usString("Descr")));
	newsGoal = BudgetGoal.createNoGoInstance(TimeUtil.utcNow(),
			ActivityCategory.createInstance(UUID.randomUUID(), usString("news"), false,
					new HashSet<>(Arrays.asList("refdag", "bbc")), Collections.emptySet(), usString("Descr")));
	gamingGoal = BudgetGoal.createNoGoInstance(TimeUtil.utcNow(), ActivityCategory.createInstance(UUID.randomUUID(),
			usString("gaming"), false, new HashSet<>(Arrays.asList("games")), Collections.emptySet(), usString("Descr")));
	socialGoal = TimeZoneGoal.createInstance(TimeUtil.utcNow(),
			ActivityCategory.createInstance(UUID.randomUUID(), usString("social"), false,
					new HashSet<>(Arrays.asList("social")), Collections.emptySet(), usString("Descr")),
			Collections.emptyList());
	shoppingGoal = BudgetGoal.createInstance(TimeUtil.utcNow(), ActivityCategory.createInstance(UUID.randomUUID(),
			usString("shopping"), false, new HashSet<>(Arrays.asList("webshop")), Collections.emptySet(), usString("Descr")),
			1);

	goalMap.put("gambling", gamblingGoal);
	goalMap.put("news", newsGoal);
	goalMap.put("gaming", gamingGoal);
	goalMap.put("social", socialGoal);
	goalMap.put("shopping", shoppingGoal);

	when(mockYonaProperties.getAnalysisService()).thenReturn(new AnalysisServiceProperties());

	// Set up UserAnonymized instance.
	MessageDestination anonMessageDestinationEntity = MessageDestination
			.createInstance(PublicKeyUtil.generateKeyPair().getPublic());
	Set<Goal> goals = new HashSet<>(Arrays.asList(gamblingGoal, gamingGoal, socialGoal, shoppingGoal));
	deviceAnonEntity = DeviceAnonymized.createInstance(0, OperatingSystem.ANDROID, "Unknown");
	userAnonEntity = UserAnonymized.createInstance(anonMessageDestinationEntity, goals);
	userAnonEntity.addDeviceAnonymized(deviceAnonEntity);
	UserAnonymizedDto userAnon = UserAnonymizedDto.createInstance(userAnonEntity);
	userAnonZone = userAnon.getTimeZone();
	userAnonId = userAnon.getId();

	userId = UUID.randomUUID();

	// Stub the UserService to return our user anonymized ID.
	when(mockUserService.getUserAnonymizedId(userId)).thenReturn(userAnonId);

	// Stub the UserAnonymizedService to return our user.
	when(mockUserAnonymizedService.getUserAnonymized(userAnonId)).thenReturn(userAnon);
	when(mockUserAnonymizedService.getUserAnonymizedEntity(userAnonId)).thenReturn(userAnonEntity);

	// Stub the GoalService to return our goals.
	when(mockGoalService.getGoalEntityForUserAnonymizedId(userAnonId, gamblingGoal.getId())).thenReturn(gamblingGoal);
	when(mockGoalService.getGoalEntityForUserAnonymizedId(userAnonId, newsGoal.getId())).thenReturn(newsGoal);
	when(mockGoalService.getGoalEntityForUserAnonymizedId(userAnonId, gamingGoal.getId())).thenReturn(gamingGoal);
	when(mockGoalService.getGoalEntityForUserAnonymizedId(userAnonId, socialGoal.getId())).thenReturn(socialGoal);
	when(mockGoalService.getGoalEntityForUserAnonymizedId(userAnonId, shoppingGoal.getId())).thenReturn(shoppingGoal);
}
 
开发者ID:yonadev,项目名称:yona-server,代码行数:60,代码来源:ActivityServiceTest.java

示例11: filterForCrudRepositories

import org.springframework.data.repository.Repository; //导入依赖的package包/类
private Set<CrudRepository<?, ?>> filterForCrudRepositories(Collection<Repository<?, ?>> values)
{
	return values.stream().filter(r -> r instanceof CrudRepository).map(r -> (CrudRepository<?, ?>) r)
			.collect(Collectors.toSet());
}
 
开发者ID:yonadev,项目名称:yona-server,代码行数:6,代码来源:BaseSpringIntegrationTest.java

示例12: setUp

import org.springframework.data.repository.Repository; //导入依赖的package包/类
@Before
public void setUp() {
	this.factoryBean = new KeyValueRepositoryFactoryBean<Repository<Object, Object>, Object, Object>(
			SampleRepository.class);
}
 
开发者ID:spring-projects,项目名称:spring-data-keyvalue,代码行数:6,代码来源:KeyValueRepositoryFactoryBeanUnitTests.java

示例13: getRepositories

import org.springframework.data.repository.Repository; //导入依赖的package包/类
protected abstract Map<Class<?>, Repository<?, ?>> getRepositories(); 
开发者ID:yonadev,项目名称:yona-server,代码行数:2,代码来源:BaseSpringIntegrationTest.java


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