本文整理汇总了Java中javax.persistence.EntityNotFoundException类的典型用法代码示例。如果您正苦于以下问题:Java EntityNotFoundException类的具体用法?Java EntityNotFoundException怎么用?Java EntityNotFoundException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EntityNotFoundException类属于javax.persistence包,在下文中一共展示了EntityNotFoundException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteCategories
import javax.persistence.EntityNotFoundException; //导入依赖的package包/类
/**
* @param toBeDeleted
* @throws OperationNotPermittedException
* @throws ObjectNotFoundException
*/
private void deleteCategories(List<VOCategory> toBeDeleted)
throws OperationNotPermittedException, ObjectNotFoundException {
final Organization currentOrg = dm.getCurrentUser().getOrganization();
final Query marketplaceQuery = dm
.createNamedQuery("Marketplace.findByBusinessKey");
for (VOCategory voCategory : toBeDeleted) {
final Category category = dm.getReference(Category.class,
voCategory.getKey());
try {
marketplaceQuery.setParameter("marketplaceId", category
.getMarketplace().getMarketplaceId());
} catch (EntityNotFoundException e) {
throw new ObjectNotFoundException(ClassEnum.MARKETPLACE,
voCategory.getMarketplaceId());
}
final Marketplace marketplace = (Marketplace) marketplaceQuery
.getSingleResult();
PermissionCheck.owns(marketplace, currentOrg, logger, null);
List<PlatformUser> usersToBeNotified = collectUsersToBeNotified(category);
prefetchRequiredObject(category);
dm.remove(category);
sendNotification(category, usersToBeNotified);
}
}
示例2: update
import javax.persistence.EntityNotFoundException; //导入依赖的package包/类
public <T extends WithId<T>> void update(T entity) {
Optional<String> id = entity.getId();
if (!id.isPresent()) {
throw new EntityNotFoundException("Setting the id on the entity is required for updates");
}
String idVal = id.get();
Kind kind = entity.getKind();
T previous = this.<T, T>doWithDataAccessObject(kind.getModelClass(), d -> d.update(entity));
Map<String, T> cache = caches.getCache(kind.getModelName());
if (!cache.containsKey(idVal) && previous==null) {
throw new EntityNotFoundException("Can not find " + kind + " with id " + idVal);
}
cache.put(idVal, entity);
broadcast("updated", kind.getModelName(), idVal);
//TODO 1. properly merge the data ? + add data validation in the REST Resource
}
示例3: delete
import javax.persistence.EntityNotFoundException; //导入依赖的package包/类
public <T extends WithId<T>> boolean delete(Class<T> model, String id) {
if (id == null || id.equals("")) {
throw new EntityNotFoundException("Setting the id on the entity is required for updates");
}
Kind kind = Kind.from(model);
Map<String, WithId<T>> cache = caches.getCache(kind.getModelName());
// Remove it out of the cache
WithId<T> entity = cache.remove(id);
boolean deletedInCache = entity != null;
// And out of the DAO
boolean deletedFromDAO = Boolean.TRUE.equals(doWithDataAccessObject(model, d -> d.delete(id)));
// Return true if the entity was found in any of the two.
if ( deletedInCache || deletedFromDAO ) {
broadcast("deleted", kind.getModelName(), id);
return true;
}
return false;
}
示例4: get
import javax.persistence.EntityNotFoundException; //导入依赖的package包/类
@Override
public Integration get(String id) {
Integration integration = Getter.super.get(id);
if (Status.Deleted.equals(integration.getCurrentStatus().get()) ||
Status.Deleted.equals(integration.getDesiredStatus().get())) {
//Not sure if we need to do that for both current and desired status,
//but If we don't do include the desired state, IntegrationITCase is not going to pass anytime soon. Why?
//Cause that test, is using NoopHandlerProvider, so that means no controllers.
throw new EntityNotFoundException(String.format("Integration %s has been deleted", integration.getId()));
}
//fudging the timesUsed for now
Optional<Status> currentStatus = integration.getCurrentStatus();
if (currentStatus.isPresent() && currentStatus.get() == Integration.Status.Activated) {
return new Integration.Builder()
.createFrom(integration)
.timesUsed(BigInteger.valueOf(new Date().getTime()/1000000))
.build();
}
return integration;
}
示例5: withGeneratorAndTemplate
import javax.persistence.EntityNotFoundException; //导入依赖的package包/类
final <T> T withGeneratorAndTemplate(final String templateId,
final BiFunction<ConnectorGenerator, ConnectorTemplate, T> callback) {
final ConnectorTemplate connectorTemplate = getDataManager().fetch(ConnectorTemplate.class, templateId);
if (connectorTemplate == null) {
throw new EntityNotFoundException("Connector template: " + templateId);
}
final ConnectorGenerator connectorGenerator = context.getBean(templateId, ConnectorGenerator.class);
if (connectorGenerator == null) {
throw new EntityNotFoundException(
"Unable to find connector generator for connector template with id: " + templateId);
}
return callback.apply(connectorGenerator, connectorTemplate);
}
示例6: load
import javax.persistence.EntityNotFoundException; //导入依赖的package包/类
@Override
public final Object load() {
final Serializable entityId = resolveNaturalId( this.naturalIdParameters );
if ( entityId == null ) {
return null;
}
try {
return this.getIdentifierLoadAccess().load( entityId );
}
catch (EntityNotFoundException enf) {
// OK
}
catch (ObjectNotFoundException nf) {
// OK
}
return null;
}
示例7: RequestDetailPage
import javax.persistence.EntityNotFoundException; //导入依赖的package包/类
public RequestDetailPage(PageParameters params) {
super(params);
if (getProject().getDefaultBranch() == null)
throw new RestartResponseException(NoBranchesPage.class, paramsOf(getProject()));
requestModel = new LoadableDetachableModel<PullRequest>() {
@Override
protected PullRequest load() {
Long requestNumber = params.get(PARAM_REQUEST).toLong();
PullRequest request = GitPlex.getInstance(PullRequestManager.class).find(getProject(), requestNumber);
if (request == null)
throw new EntityNotFoundException("Unable to find request #" + requestNumber + " in project " + getProject());
return request;
}
};
reviewUpdateId = requestModel.getObject().getLatestUpdate().getId();
}
示例8: changePassword
import javax.persistence.EntityNotFoundException; //导入依赖的package包/类
/**
* Handles the actual act of changing the user's password.
*
* @param newPassword The password, which should be already validated.
*/
private void changePassword(String newPassword) {
// Ensure that we have an employee to change the password for
if(this.employeeId == null) {
throw new IllegalStateException("Must initialize employeeId");
}
EmployeeService employeeService = new EmployeeService();
Employee employee = employeeService.getEmployeeById(this.employeeId);
try {
employee.setPassword(newPassword);
employeeService.updateEmployee(employee);
} catch (EntityNotFoundException e) {
// TODO
}
}
示例9: authenticate
import javax.persistence.EntityNotFoundException; //导入依赖的package包/类
/**
* Performs authentication on the provided employee.
*
* @param employeeId The id number of the employee to authenticate.
*
* @param plaintextPassword The plaintext password of the employee.
*
* @return The appropriate authenticationResult enum type.
*/
public AuthenticationResult authenticate(Long employeeId, String plaintextPassword) {
Employee employee = getEmployeeById(employeeId);
String hashed; // The encrypted (hashed) password of the employee.
try {
hashed = employee.getHashedPassword();
} catch (EntityNotFoundException e) {
return AuthenticationResult.FAILURE;
}
boolean passwordCorrect = BCrypt.checkpw(plaintextPassword, hashed);
if(passwordCorrect) {
return AuthenticationResult.SUCCESS;
} else {
return AuthenticationResult.FAILURE;
}
}
示例10: update
import javax.persistence.EntityNotFoundException; //导入依赖的package包/类
/**
* Update a named token with a new generated one.
*
* @param name
* Token to update.
* @return the new generated token.
*/
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Path("{name:[\\w\\-\\.]+}")
public String update(@PathParam("name") final String name) throws GeneralSecurityException {
final SystemApiToken entity = repository.findByUserAndName(securityHelper.getLogin(), name);
if (entity == null) {
// No token with given name
throw new EntityNotFoundException();
}
// Token has been found, update it
final String token = newToken(entity);
repository.saveAndFlush(entity);
return token;
}
示例11: getAllEventItems
import javax.persistence.EntityNotFoundException; //导入依赖的package包/类
@Override
public List<RvepEventItem> getAllEventItems(String eventProfileId, String email) {
// get user id
RvepUser user = this.rvepUserProfileDAO.findByEmail(email).getRvepUser();
// get event
RvepEvent event = rvepEventProfileDAO
.findById(Integer.valueOf(eventProfileId).intValue())
.getRvepEvent();
// get user event roles
List<RvepUserEventRole> rvepUserEventRoles = this.rvepUserEventRoleDAO
.findByRvepUserIdAndRvepEventId(user.getId(), event.getId());
// check if user has roles for the event
if (rvepUserEventRoles.size() > 0) {
return this.rvepEventItemDAO.findByRvepEventId(event.getId());
}
// no access found, throw exception
throw new EntityNotFoundException();
}
示例12: getHomeMunicipalityName
import javax.persistence.EntityNotFoundException; //导入依赖的package包/类
@Nonnull
public LocalisedString getHomeMunicipalityName() {
if (this.homeMunicipality != null) {
if (!Hibernate.isInitialized(this.homeMunicipality)) {
try {
// Referenced row might not exist
return this.homeMunicipality.getNameLocalisation();
} catch (UnresolvableObjectException | EntityNotFoundException o) {
this.homeMunicipality = null;
}
} else {
return this.homeMunicipality.getNameLocalisation();
}
}
return LocalisedString.EMPTY;
}
示例13: putComicBook
import javax.persistence.EntityNotFoundException; //导入依赖的package包/类
@RequestMapping(value = {"/{id}"},
consumes = {"application/json"},
produces = {"application/json; charset=UTF-8"},
method = RequestMethod.PUT)
@ResponseBody
public Object putComicBook(@PathVariable("id") Long id, @RequestBody ComicBookWebDTO dto, HttpServletResponse httpResponse) throws ExecutionException, InterruptedException {
ComicBookEntity entity = service.findById(id);
if (entity != null) {
converter.updateEntity(entity, dto);
try {
ComicBookEntity result = service.update(entity);
httpResponse.setDateHeader(HttpHeaders.LAST_MODIFIED, result.getUpdated().getTime());
return converter.convertEntity(result);
} catch (EntityNotFoundException e) {
LOGGER.warn("Can't modify the resource: " + entity, e);
httpResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
return null;
}
} else {
httpResponse.setStatus(HttpStatus.NOT_FOUND.value());
return null;
}
}
示例14: deleteComicBook
import javax.persistence.EntityNotFoundException; //导入依赖的package包/类
@RequestMapping(value = {"/{id}"}, method = RequestMethod.DELETE)
@ResponseBody
public Object deleteComicBook(@PathVariable(value = "id") Long id, HttpServletResponse httpResponse) {
ComicBookEntity entity = service.findById(id);
if (entity != null) {
try {
service.delete(id);
} catch (EntityNotFoundException e) {
LOGGER.warn("Can't delete the resource: " + entity, e);
httpResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
}
httpResponse.setStatus(HttpStatus.NO_CONTENT.value());
} else {
httpResponse.setStatus(HttpStatus.NOT_FOUND.value());
}
return null;
}
示例15: create
import javax.persistence.EntityNotFoundException; //导入依赖的package包/类
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes("application/json")
@Path("/{connector-template-id}")
public Connector create(@NotNull @PathParam("connector-template-id") final String connectorTemplateId, final Connector template) {
final ConnectorTemplate connectorTemplate = getDataManager().fetch(ConnectorTemplate.class, connectorTemplateId);
if (connectorTemplate == null) {
throw new EntityNotFoundException("Connector template: " + connectorTemplateId);
}
final ConnectorGenerator connectorGenerator = applicationContext.getBean(connectorTemplateId, ConnectorGenerator.class);
final Connector connector = connectorGenerator.generate(connectorTemplate, template);
return getDataManager().create(connector);
}