本文整理匯總了Java中javax.persistence.EntityExistsException類的典型用法代碼示例。如果您正苦於以下問題:Java EntityExistsException類的具體用法?Java EntityExistsException怎麽用?Java EntityExistsException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
EntityExistsException類屬於javax.persistence包,在下文中一共展示了EntityExistsException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: mapEJBExceptions
import javax.persistence.EntityExistsException; //導入依賴的package包/類
@Test(expected = ConcurrentModificationException.class)
public void mapEJBExceptions() throws Exception {
mapper.mapEJBExceptions(new InvocationContextStub() {
public Object proceed() throws Exception {
throw new EJBException(new EntityExistsException());
}
});
}
示例2: newPluginButtonActionPerformed
import javax.persistence.EntityExistsException; //導入依賴的package包/類
private void newPluginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newPluginButtonActionPerformed
PluginEditor dialog = new PluginEditor(new javax.swing.JFrame(), true);
dialog.setVisible(true);
while (dialog.isVisible()) {
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
logger.error(ex.getMessage(),ex);
}
}
if(dialog.getPlugin()==null) return;
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
try {
em.persist(dialog.getPlugin());
} catch (EntityExistsException e) {
javax.swing.JOptionPane.showMessageDialog(this, "The plugin is already registered!", "Warning", JOptionPane.WARNING_MESSAGE);
em.getTransaction().rollback();
em.close();
return;
}
em.getTransaction().commit();
em.close();
inactivemodel.addElement(dialog.getPlugin());
}
示例3: create
import javax.persistence.EntityExistsException; //導入依賴的package包/類
public <T extends WithId<T>> T create(final T entity) {
Kind kind = entity.getKind();
Map<String, T> cache = caches.getCache(kind.getModelName());
Optional<String> id = entity.getId();
String idVal;
final T entityToCreate;
if (!id.isPresent()) {
idVal = KeyGenerator.createKey();
entityToCreate = entity.withId(idVal);
} else {
idVal = id.get();
if (cache.containsKey(idVal)) {
throw new EntityExistsException("There already exists a "
+ kind + " with id " + idVal);
}
entityToCreate = entity;
}
this.<T, T>doWithDataAccessObject(kind.getModelClass(), d -> d.create(entityToCreate));
cache.put(idVal, entityToCreate);
broadcast("created", kind.getModelName(), idVal);
return entityToCreate;
}
示例4: updateWebServer
import javax.persistence.EntityExistsException; //導入依賴的package包/類
@Override
public WebServer updateWebServer(final WebServer webServer, final String createdBy) {
try {
final JpaWebServer jpaWebServer = findById(webServer.getId().getId());
jpaWebServer.setName(webServer.getName());
jpaWebServer.setHost(webServer.getHost());
jpaWebServer.setPort(webServer.getPort());
jpaWebServer.setHttpsPort(webServer.getHttpsPort());
jpaWebServer.setStatusPath(webServer.getStatusPath().getPath());
jpaWebServer.setCreateBy(createdBy);
return webServerFrom(update(jpaWebServer));
} catch (final EntityExistsException eee) {
LOGGER.error("Error updating web server {}", webServer, eee);
throw new EntityExistsException("Web Server Name already exists", eee);
}
}
示例5: createApplication
import javax.persistence.EntityExistsException; //導入依賴的package包/類
@Override
public JpaApplication createApplication(CreateApplicationRequest createApplicationRequest, JpaGroup jpaGroup) {
final JpaApplication jpaApp = new JpaApplication();
jpaApp.setName(createApplicationRequest.getName());
jpaApp.setGroup(jpaGroup);
jpaApp.setWebAppContext(createApplicationRequest.getWebAppContext());
jpaApp.setSecure(createApplicationRequest.isSecure());
jpaApp.setLoadBalanceAcrossServers(createApplicationRequest.isLoadBalanceAcrossServers());
jpaApp.setUnpackWar(createApplicationRequest.isUnpackWar());
try {
return create(jpaApp);
} catch (final EntityExistsException eee) {
LOGGER.error("Error creating app with request {} in group {}", createApplicationRequest, jpaGroup, eee);
throw new EntityExistsException("App already exists: " + createApplicationRequest, eee);
}
}
示例6: updateApplication
import javax.persistence.EntityExistsException; //導入依賴的package包/類
@Override
public JpaApplication updateApplication(UpdateApplicationRequest updateApplicationRequest, JpaApplication jpaApp, JpaGroup jpaGroup) {
final Identifier<Application> appId = updateApplicationRequest.getId();
if (jpaApp != null) {
jpaApp.setName(updateApplicationRequest.getNewName());
jpaApp.setWebAppContext(updateApplicationRequest.getNewWebAppContext());
jpaApp.setGroup(jpaGroup);
jpaApp.setSecure(updateApplicationRequest.isNewSecure());
jpaApp.setLoadBalanceAcrossServers(updateApplicationRequest.isNewLoadBalanceAcrossServers());
jpaApp.setUnpackWar(updateApplicationRequest.isUnpackWar());
try {
return update(jpaApp);
} catch (EntityExistsException eee) {
LOGGER.error("Error updating application {} in group {}", jpaApp, jpaGroup, eee);
throw new EntityExistsException("App already exists: " + updateApplicationRequest, eee);
}
} else {
LOGGER.error("Application cannot be found {} attempting to update application", updateApplicationRequest);
throw new BadRequestException(FaultType.INVALID_APPLICATION_NAME,
"Application cannot be found: " + appId.getId());
}
}
示例7: testApplicationCrudServiceEEE
import javax.persistence.EntityExistsException; //導入依賴的package包/類
@Test(expected = EntityExistsException.class)
public void testApplicationCrudServiceEEE() {
CreateApplicationRequest request = new CreateApplicationRequest(expGroupId, textName, textContext, true, true, false);
JpaApplication created = applicationCrudService.createApplication(request, jpaGroup);
assertNotNull(created);
try {
JpaApplication duplicate = applicationCrudService.createApplication(request, jpaGroup);
fail(duplicate.toString());
} catch (BadRequestException e) {
assertEquals(FaultType.DUPLICATE_APPLICATION, e.getMessageResponseStatus());
throw e;
} finally {
try {
applicationCrudService.removeApplication(Identifier.<Application>id(created.getId())
);
} catch (Exception x) {
LOGGER.trace("Test tearDown", x);
}
}
}
示例8: updateGroup
import javax.persistence.EntityExistsException; //導入依賴的package包/類
@Override
public Response updateGroup(final JsonUpdateGroup anUpdatedGroup,
final AuthenticatedUser aUser) {
LOGGER.info("Update Group requested: {} by user {}", anUpdatedGroup, aUser.getUser().getId());
try {
// TODO: Refactor adhoc conversion to process group name instead of Id.
final Group group = groupService.getGroup(anUpdatedGroup.getId());
final JsonUpdateGroup updatedGroup = new JsonUpdateGroup(group.getId().getId().toString(),
anUpdatedGroup.getName());
return ResponseBuilder.ok(groupService.updateGroup(updatedGroup.toUpdateGroupCommand(),
aUser.getUser()));
} catch (EntityExistsException eee) {
LOGGER.error("Group Name already exists: {}", anUpdatedGroup.getName(), eee);
return ResponseBuilder.notOk(Response.Status.INTERNAL_SERVER_ERROR, new FaultCodeException(
FaultType.DUPLICATE_GROUP_NAME, eee.getMessage(), eee));
}
}
示例9: createGroup
import javax.persistence.EntityExistsException; //導入依賴的package包/類
@Override
@Transactional
public Group createGroup(final CreateGroupRequest createGroupRequest,
final User aCreatingUser) {
createGroupRequest.validate();
try {
groupPersistenceService.getGroup(createGroupRequest.getGroupName());
String message = MessageFormat.format("Group Name already exists: {0} ", createGroupRequest.getGroupName());
LOGGER.error(message);
throw new EntityExistsException(message);
} catch (NotFoundException e) {
LOGGER.debug("No group name conflict, ignoring not found exception for creating group ", e);
}
return groupPersistenceService.createGroup(createGroupRequest);
}
示例10: updateGroup
import javax.persistence.EntityExistsException; //導入依賴的package包/類
@Override
@Transactional
public Group updateGroup(final UpdateGroupRequest anUpdateGroupRequest,
final User anUpdatingUser) {
anUpdateGroupRequest.validate();
Group orginalGroup = getGroup(anUpdateGroupRequest.getId());
try {
if (!orginalGroup.getName().equalsIgnoreCase(anUpdateGroupRequest.getNewName()) && null != groupPersistenceService.getGroup(anUpdateGroupRequest.getNewName())) {
String message = MessageFormat.format("Group Name already exists: {0}", anUpdateGroupRequest.getNewName());
LOGGER.error(message);
throw new EntityExistsException(message);
}
} catch (NotFoundException e) {
LOGGER.debug("No group name conflict, ignoring not found exception for creating group ", e);
}
return groupPersistenceService.updateGroup(anUpdateGroupRequest);
}
示例11: createFolder
import javax.persistence.EntityExistsException; //導入依賴的package包/類
public void createFolder(Folder pFolder) throws FolderAlreadyExistsException, CreationException{
try{
//the EntityExistsException is thrown only when flush occurs
em.persist(pFolder);
em.flush();
}catch(EntityExistsException pEEEx){
LOGGER.log(Level.FINEST,null,pEEEx);
throw new FolderAlreadyExistsException(mLocale, pFolder);
}catch(PersistenceException pPEx){
//EntityExistsException is case sensitive
//whereas MySQL is not thus PersistenceException could be
//thrown instead of EntityExistsException
LOGGER.log(Level.FINEST,null,pPEx);
throw new CreationException(mLocale);
}
}
示例12: createPathToPathLink
import javax.persistence.EntityExistsException; //導入依賴的package包/類
public void createPathToPathLink(PathToPathLink pathToPathLink) throws CreationException, PathToPathLinkAlreadyExistsException {
try {
//the EntityExistsException is thrown only when flush occurs
em.persist(pathToPathLink);
em.flush();
} catch (EntityExistsException pEEEx) {
LOGGER.log(Level.FINEST,null,pEEEx);
throw new PathToPathLinkAlreadyExistsException(mLocale, pathToPathLink);
} catch (PersistenceException pPEx) {
LOGGER.log(Level.FINEST,null,pPEx);
//EntityExistsException is case sensitive
//whereas MySQL is not thus PersistenceException could be
//thrown instead of EntityExistsException
throw new CreationException(mLocale);
}
}
示例13: createDocM
import javax.persistence.EntityExistsException; //導入依賴的package包/類
public void createDocM(DocumentMaster pDocumentMaster) throws DocumentMasterAlreadyExistsException, CreationException {
try {
//the EntityExistsException is thrown only when flush occurs
em.persist(pDocumentMaster);
em.flush();
} catch (EntityExistsException pEEEx) {
LOGGER.log(Level.FINER,null,pEEEx);
throw new DocumentMasterAlreadyExistsException(mLocale, pDocumentMaster);
} catch (PersistenceException pPEx) {
//EntityExistsException is case sensitive
//whereas MySQL is not thus PersistenceException could be
//thrown instead of EntityExistsException
LOGGER.log(Level.FINER,null,pPEx);
throw new CreationException(mLocale);
}
}
示例14: createQuery
import javax.persistence.EntityExistsException; //導入依賴的package包/類
public void createQuery(Query query) throws CreationException, QueryAlreadyExistsException {
try {
QueryRule queryRule = query.getQueryRule();
if(queryRule != null){
persistQueryRules(queryRule);
}
QueryRule pathDataQueryRule = query.getPathDataQueryRule();
if (pathDataQueryRule != null) {
persistQueryRules(pathDataQueryRule);
}
em.persist(query);
em.flush();
persistContexts(query, query.getContexts());
} catch (EntityExistsException pEEEx) {
LOGGER.log(Level.FINEST, null, pEEEx);
throw new QueryAlreadyExistsException(mLocale, query);
} catch (PersistenceException pPEx) {
LOGGER.log(Level.FINEST, null, pPEx);
throw new CreationException(mLocale);
}
}
示例15: createOrganization
import javax.persistence.EntityExistsException; //導入依賴的package包/類
public void createOrganization(Organization pOrganization) throws OrganizationAlreadyExistsException, CreationException {
try {
//the EntityExistsException is thrown only when flush occurs
if (pOrganization.getName().trim().equals(""))
throw new CreationException(mLocale);
em.persist(pOrganization);
em.flush();
} catch (EntityExistsException pEEEx) {
throw new OrganizationAlreadyExistsException(mLocale, pOrganization);
} catch (PersistenceException pPEx) {
//EntityExistsException is case sensitive
//whereas MySQL is not thus PersistenceException could be
//thrown instead of EntityExistsException
throw new CreationException(mLocale);
}
}