當前位置: 首頁>>代碼示例>>Java>>正文


Java CrudRepository.findOne方法代碼示例

本文整理匯總了Java中org.springframework.data.repository.CrudRepository.findOne方法的典型用法代碼示例。如果您正苦於以下問題:Java CrudRepository.findOne方法的具體用法?Java CrudRepository.findOne怎麽用?Java CrudRepository.findOne使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.data.repository.CrudRepository的用法示例。


在下文中一共展示了CrudRepository.findOne方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: hasPermission

import org.springframework.data.repository.CrudRepository; //導入方法依賴的package包/類
@Override
public boolean hasPermission(@NotNull Authentication authentication,
                             @NotNull Serializable serializable,
                             @NotNull String className,
                             @NotNull Object permissions) {
    boolean result = false;
    CrudRepository<Object, Serializable> repository = repositoryFinder.find(className);
    if (repository != null) {
        Object targetDomainObject = repository.findOne(serializable);
        if (targetDomainObject instanceof CreatorAware) {
            result = hasPermission(authentication, targetDomainObject, permissions);
        } else if (targetDomainObject == null) {
            result = true;
        }
    }
    return result;
}
 
開發者ID:hmcts,項目名稱:document-management-store-app,代碼行數:18,代碼來源:PermissionEvaluatorImpl.java

示例2: shouldFindOne

import org.springframework.data.repository.CrudRepository; //導入方法依賴的package包/類
@Test
public void shouldFindOne() throws Exception {
  CrudRepository<T, UUID> repository = this.getRepository();

  T instance = this.generateInstance();

  instance = repository.save(instance);
  assertInstance(instance);

  UUID id = instance.getId();

  instance = repository.findOne(id);
  assertInstance(instance);
  Assert.assertEquals(id, instance.getId());
}
 
開發者ID:OpenLMIS,項目名稱:openlmis-stockmanagement,代碼行數:16,代碼來源:BaseCrudRepositoryIntegrationTest.java

示例3: safeGet

import org.springframework.data.repository.CrudRepository; //導入方法依賴的package包/類
private <T extends ContentEntity> T safeGet(ContentDto s, CrudRepository<? extends T, UUID> repo, T newEntity) {
    try {
        T entity = repo.findOne(s.getId());
        return entity;
    } catch (Exception e) {
        return newEntity;
    }
}
 
開發者ID:lordoftheflies,項目名稱:wonderjameeee,代碼行數:9,代碼來源:ContentManagementService.java

示例4: addACLUserGeneric

import org.springframework.data.repository.CrudRepository; //導入方法依賴的package包/類
@RequestMapping(method = RequestMethod.POST, value = "/acl/user/generic/")
public @ResponseBody HttpEntity<List<String>> addACLUserGeneric(
		@RequestBody UserACLRequestSet aclSet) {
	List<String> result = new ArrayList<String>();
	try {
		SecurityACLDAO securityACLDAO = beanFactory.getBean(
				Constants.SECURITYACL_DAO, SecurityACLDAO.class);

		logger.debug("entityList size:" + aclSet.getAclList().size());
		String entityId = null;
		for (UserACLRequest acl : aclSet.getAclList()) {
			entityId = acl.getEntityId();
			String repoName = classToRepoMap.get(acl.getEntityClassName());
			CrudRepository repo = getRepo(repoName);
			AbstractSecuredEntity securedEntity = (AbstractSecuredEntity) repo
					.findOne(Long.parseLong(entityId));
			if (securedEntity == null) {
				result.add("Entity of type " + acl.getEntityClassName()
						+ " with id " + acl.getEntityId() + " not found");
				continue;
			}
			UserEntity userEntity = userEntityRepo.findByUsername(acl
					.getUserName());
			if (userEntity == null) {
				result.add("User " + acl.getUserName() + " not found");
				continue;
			}
			boolean res = securityACLDAO.addAccessControlEntry(
					securedEntity,
					new PrincipalSid(userEntity.getUsername()),
					getPermissionFromNumber(acl.getPermission()));
			if (res) {
				// on sucess don't add msg to result list
				logger.debug("Added ACL for:" + acl.toString());
			} else {
				result.add("Failed to add ACL for:" + acl.toString());
			}
		}
	} catch (Exception e) {
		logger.warn("", e);
		result.add("Exception:" + e.getMessage());
	}
	if (result.isEmpty()) {
		result.add("Successfully added all ACLs");
		return new ResponseEntity<List<String>>(result, HttpStatus.OK);
	} else {
		return new ResponseEntity<List<String>>(result, HttpStatus.OK);
	}
}
 
開發者ID:charybr,項目名稱:spring-data-rest-acl,代碼行數:50,代碼來源:ACLController.java

示例5: removeACLUserGeneric

import org.springframework.data.repository.CrudRepository; //導入方法依賴的package包/類
@RequestMapping(method = RequestMethod.DELETE, value = "/acl/user/generic/")
public @ResponseBody HttpEntity<List<String>> removeACLUserGeneric(
		@RequestBody UserACLRequestSet aclSet) {
	List<String> result = new ArrayList<String>();
	try {
		SecurityACLDAO securityACLDAO = beanFactory.getBean(
				Constants.SECURITYACL_DAO, SecurityACLDAO.class);

		logger.debug("entityList size:" + aclSet.getAclList().size());
		String entityId = null;
		for (UserACLRequest acl : aclSet.getAclList()) {
			entityId = acl.getEntityId();
			String repoName = classToRepoMap.get(acl.getEntityClassName());
			CrudRepository repo = getRepo(repoName);
			AbstractSecuredEntity securedEntity = (AbstractSecuredEntity) repo
					.findOne(Long.parseLong(entityId));
			if (securedEntity == null) {
				result.add("Entity of type " + acl.getEntityClassName()
						+ " with id " + acl.getEntityId() + " not found");
				continue;
			}
			UserEntity userEntity = userEntityRepo.findByUsername(acl
					.getUserName());
			if (userEntity == null) {
				result.add("User " + acl.getUserName() + " not found");
				continue;
			}
			boolean res = securityACLDAO.deleteAccessControlEntry(
					securedEntity,
					new PrincipalSid(userEntity.getUsername()),
					getPermissionFromNumber(acl.getPermission()));
			if (res) {
				// on sucess don't add msg to result list
				logger.debug("Deleted ACL for:" + acl.toString());
			} else {
				result.add("Failed to add ACL for:" + acl.toString());
			}
		}
	} catch (Exception e) {
		logger.warn("", e);
		result.add("Exception:" + e.getMessage());
	}
	if (result.isEmpty()) {
		result.add("Successfully deleted all ACLs");
		return new ResponseEntity<List<String>>(result, HttpStatus.OK);
	} else {
		return new ResponseEntity<List<String>>(result, HttpStatus.OK);
	}
}
 
開發者ID:charybr,項目名稱:spring-data-rest-acl,代碼行數:50,代碼來源:ACLController.java


注:本文中的org.springframework.data.repository.CrudRepository.findOne方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。