当前位置: 首页>>代码示例>>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;未经允许,请勿转载。