微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javax.persistence.EntityExistsException的实例源码

项目:sumo    文件PluginManagerDialog.java   
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());
}
项目:syndesis    文件DataManager.java   
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;
}
项目:jwala    文件WebServerCrudServiceImpl.java   
@Override
public WebServer createWebServer(final WebServer webServer,final String createdBy) {
    try {
        final JpaWebServer jpaWebServer = new JpaWebServer();

        jpaWebServer.setName(webServer.getName());
        jpaWebServer.setHost(webServer.getHost());
        jpaWebServer.setPort(webServer.getPort());
        jpaWebServer.setHttpsPort(webServer.getHttpsPort());
        jpaWebServer.setStatusPath(webServer.getStatusPath().getPath());
        jpaWebServer.setCreateBy(createdBy);
        jpaWebServer.setState(webServer.getState());
        jpaWebServer.setApacheHttpdMedia(webServer.getApacheHttpdMedia() == null ? null : new modelmapper()
                .map(webServer.getApacheHttpdMedia(),JpaMedia.class));

        return webServerFrom(create(jpaWebServer));
    } catch (final EntityExistsException eee) {
        LOGGER.error("Error creating web server {}",webServer,eee);
        throw new EntityExistsException("Web server with name already exists: " + webServer,eee);
    }

}
项目:jwala    文件WebServerCrudServiceImpl.java   
@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 {}",eee);
        throw new EntityExistsException("Web Server Name already exists",eee);
    }
}
项目:jwala    文件ApplicationCrudServiceImpl.java   
@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);
    }
}
项目:jwala    文件ApplicationCrudServiceImpl.java   
@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,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());
    }
}
项目:jwala    文件ApplicationCrudServiceImpltest.java   
@Test(expected = EntityExistsException.class)
public void testApplicationCrudServiceEEE() {
    CreateApplicationRequest request = new CreateApplicationRequest(expGroupId,textName,textContext,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);
        }
    }

}
项目:jwala    文件GroupServiceRestImpl.java   
@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));
    }
}
项目:jwala    文件GroupServiceImpl.java   
@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);
}
项目:jwala    文件GroupServiceImpl.java   
@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,e);
    }
    return groupPersistenceService.updateGroup(anUpdateGroupRequest);
}
项目:eplmp    文件FolderDAO.java   
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,pPEx);
        throw new CreationException(mLocale);
    }
}
项目:eplmp    文件PathToPathLinkDAO.java   
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,pEEEx);
            throw new PathToPathLinkAlreadyExistsException(mLocale,pathToPathLink);
        } catch (PersistenceException pPEx) {
            LOGGER.log(Level.FInesT,pPEx);
            //EntityExistsException is case sensitive
            //whereas MysqL is not thus PersistenceException Could be
            //thrown instead of EntityExistsException
            throw new CreationException(mLocale);
        }
    }
项目:eplmp    文件DocumentMasterDAO.java   
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,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,pPEx);
        throw new CreationException(mLocale);
    }
}
项目:eplmp    文件QueryDAO.java   
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,pEEEx);
        throw new QueryAlreadyExistsException(mLocale,query);
    } catch (PersistenceException pPEx) {
        LOGGER.log(Level.FInesT,pPEx);
        throw new CreationException(mLocale);
    }
}
项目:eplmp    文件OrganizationDAO.java   
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);
    }
}
项目:OpenChatAlytics    文件MentionableDAO.java   
/**
 * {@inheritDoc}
 */
@Override
public void persistValue(T value) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    EntityTransaction transaction = entityManager.getTransaction();
    transaction.begin();
    try {
        entityManager.persist(value);
        transaction.commit();
    } catch (PersistenceException e) {
        if (isEntityAlreadyExists(value)) {
            closeEntityManager(entityManager);
            throw new EntityExistsException(e.getCause());
        }
        LOG.error("Cannot store {}. {}",value,e.getMessage());
    }

    if (transaction.isActive() && transaction.getRollbackOnly()) {
        transaction.rollback();
    }

    closeEntityManager(entityManager);
}
项目:cosmic    文件Xcpserverdiscoverer.java   
void setClusterGuid(final ClusterVO cluster,final String guid) {
    cluster.setGuid(guid);
    try {
        _clusterDao.update(cluster.getId(),cluster);
    } catch (final EntityExistsException e) {
        final QueryBuilder<ClusterVO> sc = QueryBuilder.create(ClusterVO.class);
        sc.and(sc.entity().getGuid(),Op.EQ,guid);
        final List<ClusterVO> clusters = sc.list();
        final ClusterVO clu = clusters.get(0);
        final List<HostVO> clusterHosts = _resourceMgr.listAllHostsInCluster(clu.getId());
        if (clusterHosts == null || clusterHosts.size() == 0) {
            clu.setGuid(null);
            _clusterDao.update(clu.getId(),clu);
            _clusterDao.update(cluster.getId(),cluster);
            return;
        }
        throw e;
    }
}
项目:syndesis-rest    文件DataManager.java   
public <T extends WithId<T>> T create(final T entity) {
    Kind kind = entity.getKind();
    Cache<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.keySet().contains(idVal)) {
            throw new EntityExistsException("There already exists a "
                + kind + " with id " + idVal);
        }
        entityToCreate = entity;
    }

    this.<T,idVal);
    return entityToCreate;
}
项目:java-persistence    文件DdbIndex.java   
@Override
public void putItemOrThrow(T item) {
    try {
        Expected[] expected;
        if ( null == _rkName ) {
            expected = new Expected[]{
                new Expected(_hkName).notExist()
            };
        } else {
            expected = new Expected[]{
                new Expected(_hkName).notExist(),new Expected(_rkName).notExist()
            };
        }
        maybeBackoff(false,() ->
                     _putItem.putItem(_encryption.encrypt(toItem(item)),expected));
    } catch ( ConditionalCheckFailedException ex ) {
        throw new EntityExistsException(ex);
    }
}
项目:europa    文件NewPipeline.java   
public Object get(AjaxRequest ajaxRequest,EuropaRequestContext requestContext)
{
    _permissionCheck.check(ajaxRequest.getoperation(),requestContext);

    String domain = requestContext.getownerDomain();
    String name = ajaxRequest.getParam("name",true);
    Matcher m = pipelineNamePattern.matcher(name);
    if(!m.matches())
        throw(new AjaxClientException("The Pipeline Name is invalid. It must match regex [a-zA-Z0-9_.-]",AjaxErrors.Codes.BadPipelineName,400));
    Pipeline pipeline = Pipeline.builder()
                                .domain(domain)
                                .name(name)
                                .build();
    try {
        _db.createPipeline(pipeline);
    } catch(EntityExistsException rbe) {
        throw(new AjaxClientException("A Pipeline with that name already exists.",AjaxErrors.Codes.PipelineAlreadyExists,400));
    }
    return pipeline;
}
项目:keystone4j    文件AssignmentJpadriver.java   
@Override
public void addRoletoUserAndProject(String userid,String projectid,String roleid) {
    RoleAssignment roleAssignment = new RoleAssignment();
    roleAssignment.setType(AssignmentType.USER_PROJECT);
    roleAssignment.setActorId(userid);
    roleAssignment.setTargetId(projectid);
    roleAssignment.setRoleId(roleid);
    roleAssignment.setInherited(false);

    try {
        roleAssignmentDao.persist(roleAssignment);
    } catch (EntityExistsException e) {
        String msg = messageformat.format(USER_ALREADY_HAS_ROLE,userid,roleid,projectid);
        logger.error(msg,e);
        throw Exceptions.ConflictException.getInstance(null,ROLE_GRANT,msg); // replace
        // KeyError
    }

}
项目:spring-data-fundamentals    文件GreetingServiceTest.java   
@Test
public void testCreateWithId() {

    Exception exception = null;

    Greeting entity = new Greeting();
    entity.setId(Long.MAX_VALUE);
    entity.setText("test");

    try {
        service.create(entity);
    } catch (EntityExistsException e) {
        exception = e;
    }

    Assert.assertNotNull("failure - expected exception",exception);
    Assert.assertTrue("failure - expected EntityExistsException",exception instanceof EntityExistsException);

}
项目:skeleton-ws-spring-boot    文件GreetingServiceBean.java   
@CachePut(value = Application.CACHE_GREETINGS,key = "#result.id")
@Transactional
@Override
public Greeting create(final Greeting greeting) {
    logger.info("> create");

    counterService.increment("method.invoked.greetingServiceBean.create");

    // Ensure the entity object to be created does NOT exist in the
    // repository. Prevent the default behavior of save() which will update
    // an existing entity if the entity matching the supplied id exists.
    if (greeting.getId() != null) {
        logger.error("Attempted to create a Greeting,but id attribute was not null.");
        logger.info("< create");
        throw new EntityExistsException(
                "Cannot create new Greeting with supplied id.  The id attribute must be null to create an entity.");
    }

    final Greeting savedGreeting = greetingRepository.save(greeting);

    logger.info("< create");
    return savedGreeting;
}
项目:skeleton-ws-spring-boot    文件GreetingServiceTest.java   
@Test
public void testCreateGreetingWithId() {

    Exception exception = null;

    final Greeting greeting = new Greeting();
    greeting.setId(Long.MAX_VALUE);
    greeting.setText(VALUE_TEXT);

    try {
        greetingService.create(greeting);
    } catch (EntityExistsException eee) {
        exception = eee;
    }

    Assert.assertNotNull("failure - expected exception",exception instanceof EntityExistsException);

}
项目:spring-boot-fundamentals    文件GreetingServiceTest.java   
@Test
public void testCreateWithId() {

    Exception exception = null;

    Greeting entity = new Greeting();
    entity.setId(Long.MAX_VALUE);
    entity.setText("test");

    try {
        service.create(entity);
    } catch (EntityExistsException e) {
        exception = e;
    }

    Assert.assertNotNull("failure - expected exception",exception instanceof EntityExistsException);

}
项目:low-latency-high-throughput    文件VehicleControllerConcurentHashMapImpl.java   
@Override
    public void add(Vehicle vehicle) throws EntityExistsException {
        if (getByPlateNumber(vehicle.getNumber()).isPresent())
            throw new EntityExistsException("The vehicle with plate number " + vehicle.getNumber() + " already exists in DB." );
        vehicle.setId(getNextId());
        vehicles.put(vehicle.getId(),vehicle);
        String number = vehicle.getNumber();
        if(LOG.isEnabledFor(Level.TRACE)){
            Optional<Vehicle> vehicleOrNull = getByPlateNumber(number);
            LOG.trace("Vehicle [{}] has GPS number : {}",number,vehicleOrNull.isPresent() ?  vehicleOrNull.get().getGpsNumber(): "none");
        }
//      LOG.trace("Vehicle [{}] has GPS number : {}",//          getByPlateNumber(number).isPresent() ? getByPlateNumber(number).get().getGpsNumber(): "none");

    }
项目:spring-security-fundamentals    文件GreetingServiceTest.java   
@Test
public void testCreateWithId() {

    Exception exception = null;

    Greeting entity = new Greeting();
    entity.setId(Long.MAX_VALUE);
    entity.setText("test");

    try {
        service.create(entity);
    } catch (EntityExistsException e) {
        exception = e;
    }

    Assert.assertNotNull("failure - expected exception",exception instanceof EntityExistsException);

}
项目:syncope    文件ReportTest.java   
@Test
public void saveWithExistingName() {
    assertThrows(EntityExistsException.class,() -> {
        Report report = reportDAO.find("0062ea9c-924d-4ecf-9961-4492a8cc6d1b");
        assertNotNull(report);

        String name = report.getName();

        report = entityFactory.newEntity(Report.class);
        report.setName(name);
        report.setActive(true);
        report.setTemplate(reportTemplateDAO.find("sample"));

        reportDAO.save(report);
        reportDAO.flush();
    });
}
项目:syncope    文件PlainSchemaTest.java   
@Test
public void checkIdUniqueness() {
    assertNotNull(derSchemaDAO.find("cn"));

    PlainSchema schema = entityFactory.newEntity(PlainSchema.class);
    schema.setKey("cn");
    schema.setType(AttrSchemaType.String);
    plainSchemaDAO.save(schema);

    try {
        plainSchemaDAO.flush();
        fail("This should not happen");
    } catch (Exception e) {
        assertTrue(e instanceof EntityExistsException);
    }
}
项目:cloudstack    文件Xcpserverdiscoverer.java   
void setClusterGuid(ClusterVO cluster,String guid) {
    cluster.setGuid(guid);
    try {
        _clusterDao.update(cluster.getId(),cluster);
    } catch (EntityExistsException e) {
        QueryBuilder<ClusterVO> sc = QueryBuilder.create(ClusterVO.class);
        sc.and(sc.entity().getGuid(),guid);
        List<ClusterVO> clusters = sc.list();
        ClusterVO clu = clusters.get(0);
        List<HostVO> clusterHosts = _resourceMgr.listAllHostsInCluster(clu.getId());
        if (clusterHosts == null || clusterHosts.size() == 0) {
            clu.setGuid(null);
            _clusterDao.update(clu.getId(),cluster);
            return;
        }
        throw e;
    }
}
项目:cloudstack    文件OvsTunnelManagerImpl.java   
@DB
protected OvsTunnelInterfaceVO createInterfaceRecord(String ip,String netmask,String mac,long hostId,String label) {
    OvsTunnelInterfaceVO ti = null;
    try {
        ti = new OvsTunnelInterfaceVO(ip,netmask,mac,hostId,label);
        // Todo: Is locking really necessary here?
        OvsTunnelInterfaceVO lock = _tunnelInterfaceDao
                .acquireInLockTable(Long.valueOf(1));
        if (lock == null) {
            s_logger.warn("Cannot lock table ovs_tunnel_account");
            return null;
        }
        _tunnelInterfaceDao.persist(ti);
        _tunnelInterfaceDao.releaseFromlockTable(lock.getId());
    } catch (EntityExistsException e) {
        s_logger.debug("A record for the interface for network " + label
                + " on host id " + hostId + " already exists");
    }
    return ti;
}
项目:cloudstack    文件OvsTunnelManagerImpl.java   
@DB
protected OvsTunnelNetworkVO createTunnelRecord(long from,long to,long networkId,int key) {
    OvsTunnelNetworkVO ta = null;
    try {
        ta = new OvsTunnelNetworkVO(from,to,key,networkId);
        OvsTunnelNetworkVO lock = _tunnelNetworkDao.acquireInLockTable(Long.valueOf(1));
        if (lock == null) {
            s_logger.warn("Cannot lock table ovs_tunnel_account");
            return null;
        }
        _tunnelNetworkDao.persist(ta);
        _tunnelNetworkDao.releaseFromlockTable(lock.getId());
    } catch (EntityExistsException e) {
        s_logger.debug("A record for the tunnel from " + from + " to " + to + " already exists");
    }
    return ta;
}
项目:cloudstack    文件CiscoVnmcElement.java   
@Override
public CiscoAsa1000vDevice addCiscoAsa1000vResource(AddCiscoAsa1000vResourceCmd cmd) {
    Long physicalNetworkId = cmd.getPhysicalNetworkId();
    CiscoAsa1000vDevice ciscoAsa1000vResource = null;

    PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
    }

    ciscoAsa1000vResource = new CiscoAsa1000vDeviceVO(physicalNetworkId,cmd.getManagementIp().trim(),cmd.getInPortProfile(),cmd.getClusterId());
    try {
        _ciscoAsa1000vDao.persist((CiscoAsa1000vDeviceVO)ciscoAsa1000vResource);
    } catch (EntityExistsException e) {
        throw new InvalidParameterValueException("An ASA 1000v appliance already exists with same configuration");
    }

    return ciscoAsa1000vResource;
}
项目:cloudstack    文件DeleteServicePackageOfferingCmd.java   
@Override
public void execute() throws ServerApiException,ConcurrentOperationException,EntityExistsException {
    SuccessResponse response = new SuccessResponse();
    try {
        boolean result = _netsclarLbService.deleteServicePackageOffering(this);

        if (response != null && result) {
            response.setdisplayText("Deleted Successfully");
            response.setSuccess(result);
            response.setResponseName(getCommandName());
            this.setResponSEObject(response);
        }
    } catch (CloudRuntimeException runtimeExcp) {
        response.setdisplayText(runtimeExcp.getMessage());
        response.setSuccess(false);
        response.setResponseName(getCommandName());
        this.setResponSEObject(response);
        return;
    } catch (Exception e) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,"Failed to delete Service Package due to internal error.");
    }
}
项目:cloudstack    文件DeletenetscalerControlCenterCmd.java   
@Override
public void execute() throws ServerApiException,EntityExistsException {
    SuccessResponse response = new SuccessResponse();
    try {
        boolean result = _netsclarLbService.deletenetscalerControlCenter(this);
        if (response != null && result) {
            response.setdisplayText("netscaler Control Center Deleted Successfully");
            response.setSuccess(result);
            response.setResponseName(getCommandName());
            setResponSEObject(response);
        }
    } catch (CloudRuntimeException runtimeExcp) {
        response.setdisplayText(runtimeExcp.getMessage());
        response.setSuccess(false);
        response.setResponseName(getCommandName());
        setResponSEObject(response);
        return;
    } catch (Exception e) {
        e.printstacktrace();
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,e.getMessage());
    }
}
项目:geoPingProject    文件StopWatchStateEndpoint.java   
/**
 * This inserts a new entity into App Engine datastore. If the entity already
 * exists in the datastore,an exception is thrown.
 * It uses HTTP POST method.
 *
 * @param stopWatchState the entity to be inserted.
 * @return The inserted entity.
 */
@ApiMethod(name = "insertStopWatchState")
public StopWatchState insertStopWatchState(StopWatchState stopWatchState) {
    EntityManager mgr = getEntityManager();
    try {
        if (containsstopWatchState(stopWatchState)) {
            throw new EntityExistsException("Object already exists");
        }
        mgr.persist(stopWatchState);
        // Send to GCM
        Sender sender = new Sender(API_KEY);

    } finally {
        mgr.close();
    }
    return stopWatchState;
}
项目:homePi    文件DeviceManagementService.java   
/**
 * The create inserts a new row if none is present and then returns the result populated with what data the request provided. 
 * @param piSerialId
 * @param ipAddress
 * @return
 * @throws HomePiAppException
 */
public PiProfile createPiProfile(String piSerialId,String ipAddress,String userName) throws HomePiAppException {
    if(StringUtil.isNullOrEmpty(piSerialId)){
        throw new HomePiAppException(Status.BAD_REQUEST,"Invalid Pi Serial ID.");
    }
    try{
        PiProfile piProfile = new PiProfile();
        piProfile.setPiSerialId(piSerialId);
        piProfile.setCreateTime(new DateTime());
        piProfile.setIpAddress(ipAddress);
        piProfile.setName("PI-"+piSerialId); //sets default name
        piProfile.setUserId(getUid(userName));

        piProfileDao.save(piProfile);

        //Add apiKey to the entry.
        piProfileDao.updateUUID(piProfile);

        return piProfileDao.findOne(piProfile.getPiId());
    } catch(EntityExistsException eee){
        throw new HomePiAppException(Status.BAD_REQUEST,piSerialId + ": This PI has already been registered");
    } catch(Exception e){
        throw new HomePiAppException(Status.BAD_REQUEST,e);
    }
}
项目:oscm    文件ExceptionMapperTest.java   
@Test(expected = ConcurrentModificationException.class)
public void mapEJBExceptions() throws Exception {
    mapper.mapEJBExceptions(new InvocationContextStub() {
        public Object proceed() throws Exception {
            throw new EJBException(new EntityExistsException());
        }
    });
}
项目:oscm    文件ExceptionMapper.java   
private boolean canMapToConcurrentModificationException(
        PersistenceException pe) {
    if (pe instanceof EntityExistsException
            || pe instanceof OptimisticLockException) {
        return true;
    }
    return false;
}
项目:jwala    文件GroupCrudServiceImpl.java   
@Override
public JpaGroup createGroup(CreateGroupRequest createGroupRequest) {
    final JpaGroup jpaGroup = new JpaGroup();
    jpaGroup.setName(createGroupRequest.getGroupName());

    try {
        return create(jpaGroup);
    } catch (final EntityExistsException eee) {
        LOGGER.error("Error creating group {}",createGroupRequest,eee);
        throw new EntityExistsException("Group Name already exists: " + createGroupRequest,eee);
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。