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