Example usage for javax.persistence EntityExistsException getMessage

List of usage examples for javax.persistence EntityExistsException getMessage

Introduction

In this page you can find the example usage for javax.persistence EntityExistsException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:mx.edu.ittepic.AEEcommerce.ejbs.OperationCommerce.java

public String newUser(String username, String password, String phone, String neigborhood, String zipcode,
        String city, String country, String state, String region, String street, String email,
        String streetnumber, Part file, String cellphone, String companyid, String roleid, String gender) {
    Message m = new Message();
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();//from w ww.  ja  va  2s .co m
    try {
        Users p = new Users();

        p.setUsername(username);
        p.setPassword(password);
        p.setPhone(phone);
        p.setNeigborhood(neigborhood);
        p.setZipcode(zipcode);
        p.setCity(city);
        p.setCountry(country);
        p.setState(state);
        p.setRegion(region);
        p.setStreet(street);
        p.setEmail(email);
        p.setStreetnumber(streetnumber);

        p.setCellphone(cellphone);
        Company companyid_ = entity.find(Company.class, Integer.parseInt(companyid));
        Role roleid_ = entity.find(Role.class, Integer.parseInt(roleid));
        if (companyid_ == null) {
            m.setCode(404);
            m.setMsg("Error" + 404);
            m.setDetail("ERROR");
            return gson.toJson(m);
        } else {
            p.setCompanyid(companyid_);
        }
        if (roleid_ == null) {
            m.setCode(404);
            m.setMsg("Error" + 404);
            m.setDetail("ERROR");
            return gson.toJson(m);
        } else {
            p.setRoleid(roleid_);
        }

        p.setGender(gender.charAt(0));
        p.setApikey("");
        entity.persist(p);
        entity.flush();
        p.setApikey(DigestUtils.md5Hex(p.getUserid().toString()));
        entity.merge(p);

        PreExamenProduct insertImg = new PreExamenProduct();
        p.setPhoto(insertImg.copyIMG(file, p.getUserid(), "Usuario"));

        m.setCode(200);
        m.setMsg("Todo bien compa");
        m.setDetail("OK, El id es:" + p.getUserid().toString());
        return gson.toJson(m);
    } catch (EntityExistsException e) {
        m.setCode(404);
        m.setMsg(e.getMessage());
        m.setDetail("ERROR");
        return gson.toJson(m);
    } catch (IllegalArgumentException ex) {
        m.setCode(404);
        m.setMsg(ex.getMessage());
        m.setDetail("ERROR");
        return gson.toJson(m);
    } catch (PersistenceException exx) {
        m.setCode(404);
        m.setMsg(exx.getMessage());
        m.setDetail("ERROR");
        return gson.toJson(m);
    }
}

From source file:com.clustercontrol.performance.session.PerformanceCollectMasterControllerBean.java

/**
 * ???//  ww w . j av  a2 s .  c om
 * 
 * @param data 
 * @return ??????true
 * @throws HinemosUnknown
 */
public boolean addCollectCalcMaster(CollectorCalcMethodMstData data) throws HinemosUnknown {
    JpaTransactionManager jtm = null;

    // 
    OperateCollectCalcMaster ope = new OperateCollectCalcMaster();
    boolean ret = false;

    try {
        jtm = new JpaTransactionManager();
        jtm.begin();

        ret = ope.add(data);

        jtm.commit();
    } catch (EntityExistsException e) {
        if (jtm != null)
            jtm.rollback();
        throw new HinemosUnknown(e.getMessage(), e);
    } catch (Exception e) {
        m_log.warn("addCollectCalcMaster() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        if (jtm != null)
            jtm.rollback();
        throw new HinemosUnknown(e.getMessage(), e);
    } finally {
        if (jtm != null)
            jtm.close();
    }

    return ret;

}

From source file:com.clustercontrol.performance.session.PerformanceCollectMasterControllerBean.java

/**
 * ????// w  w  w  . ja va2s. co  m
 * 
 * @param data ?
 * @return ??????true
 * @throws HinemosUnknown
 */
public boolean addCollectCategoryMaster(CollectorCategoryMstData data) throws HinemosUnknown {
    JpaTransactionManager jtm = null;

    // ?
    OperateCollectCategoryMaster ope = new OperateCollectCategoryMaster();
    boolean ret = false;

    try {
        jtm = new JpaTransactionManager();
        jtm.begin();

        ret = ope.add(data);

        jtm.commit();
    } catch (EntityExistsException e) {
        if (jtm != null)
            jtm.rollback();
        throw new HinemosUnknown(e.getMessage(), e);
    } catch (Exception e) {
        m_log.warn("addCollectCategoryMaster() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        if (jtm != null)
            jtm.rollback();
        throw new HinemosUnknown(e.getMessage(), e);
    } finally {
        if (jtm != null)
            jtm.close();
    }

    return ret;

}

From source file:com.clustercontrol.performance.session.PerformanceCollectMasterControllerBean.java

/**
 * ?????// w w w  .  j a v a 2  s  .co  m
 * 
 * @param data ??
 * @return ??????true
 * @throws HinemosUnknown
 */
public boolean addCollectItemCalcMethodMaster(CollectorItemCalcMethodMstData data) throws HinemosUnknown {
    JpaTransactionManager jtm = null;

    // ??
    OperateCollectItemCalcMethodMaster ope = new OperateCollectItemCalcMethodMaster();
    boolean ret = false;

    try {
        jtm = new JpaTransactionManager();
        jtm.begin();

        ret = ope.add(data);

        jtm.commit();
    } catch (EntityExistsException e) {
        if (jtm != null)
            jtm.rollback();
        throw new HinemosUnknown(e.getMessage(), e);
    } catch (Exception e) {
        m_log.warn("addCollectItemCalcMethodMaster() : " + e.getClass().getSimpleName() + ", " + e.getMessage(),
                e);
        if (jtm != null)
            jtm.rollback();
        throw new HinemosUnknown(e.getMessage(), e);
    } finally {
        if (jtm != null)
            jtm.close();
    }

    return ret;
}

From source file:com.clustercontrol.performance.session.PerformanceCollectMasterControllerBean.java

/**
 * ????/*w  ww  .ja  va  2  s .c o m*/
 * 
 * @param data ?
 * @return ??????true
 * @throws HinemosUnknown
 */
public boolean addCollectItemCodeMaster(CollectorItemCodeMstData data) throws HinemosUnknown {
    JpaTransactionManager jtm = null;

    // ?
    OperateCollectItemCodeMaster ope = new OperateCollectItemCodeMaster();
    boolean ret = false;

    try {
        jtm = new JpaTransactionManager();
        jtm.begin();

        ret = ope.add(data);

        jtm.commit();
    } catch (EntityExistsException e) {
        if (jtm != null)
            jtm.rollback();
        throw new HinemosUnknown(e.getMessage(), e);
    } catch (Exception e) {
        m_log.warn("addCollectItemCodeMaster() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        if (jtm != null)
            jtm.rollback();
        throw new HinemosUnknown(e.getMessage(), e);
    } finally {
        if (jtm != null)
            jtm.close();
    }

    return ret;

}

From source file:com.clustercontrol.performance.session.PerformanceCollectMasterControllerBean.java

/**
 * ??????//from   w  ww.  j a v a 2 s . c om
 * 
 * @param data ???
 * @return ??????true
 * @throws HinemosUnknown
 */
public boolean addCollectPollingMaster(CollectorPollingMstData data) throws HinemosUnknown {
    JpaTransactionManager jtm = null;

    // ???
    OperateCollectPollingMaster ope = new OperateCollectPollingMaster();
    boolean ret = false;

    try {
        jtm = new JpaTransactionManager();
        jtm.begin();

        ret = ope.add(data);

        jtm.commit();
    } catch (EntityExistsException e) {
        if (jtm != null)
            jtm.rollback();
        throw new HinemosUnknown(e.getMessage(), e);
    } catch (Exception e) {
        m_log.warn("addCollectPollingMaster() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        if (jtm != null)
            jtm.rollback();
        throw new HinemosUnknown(e.getMessage(), e);
    } finally {
        if (jtm != null)
            jtm.close();
    }

    return ret;

}

From source file:com.clustercontrol.performance.session.PerformanceCollectMasterControllerBean.java

/**
 * ?????/*from   www .j a v  a 2s.  co m*/
 * 
 * @param data ??
 * @return ??????true
 * @throws HinemosUnknown
 */
public boolean addCollectCategoryCollectMaster(CollectorCategoryCollectMstData data) throws HinemosUnknown {
    JpaTransactionManager jtm = null;

    //??
    OperateCollectCategoryCollectMaster ope = new OperateCollectCategoryCollectMaster();
    boolean ret = false;

    try {
        jtm = new JpaTransactionManager();
        jtm.begin();

        ret = ope.add(data);

        jtm.commit();
    } catch (EntityExistsException e) {
        if (jtm != null)
            jtm.rollback();
        throw new HinemosUnknown(e.getMessage(), e);
    } catch (Exception e) {
        m_log.warn(
                "addCollectCategoryCollectMaster() : " + e.getClass().getSimpleName() + ", " + e.getMessage(),
                e);
        if (jtm != null)
            jtm.rollback();
        throw new HinemosUnknown(e.getMessage(), e);
    } finally {
        if (jtm != null)
            jtm.close();
    }

    return ret;

}

From source file:com.clustercontrol.performance.session.PerformanceCollectMasterControllerBean.java

/**
 * ???//from  www  .j a v a 2  s  .  c o m
 * 
 * @param data 
 * @return ??????true
 * @throws HinemosUnknown
 */
public boolean addCollectSubPlatformMaster(CollectorSubPlatformMstData data) throws HinemosUnknown {
    JpaTransactionManager jtm = null;

    try {
        jtm = new JpaTransactionManager();
        jtm.begin();

        // 
        new RepositoryControllerBean().addCollectorSubPlatformMst(data);

        jtm.commit();
    } catch (EntityExistsException e) {
        // ?????
        // ??????????????????????????????
        if (jtm != null)
            jtm.rollback();
        return false;
    } catch (Exception e) {
        m_log.warn("addCollectSubPlatformMaster() : " + e.getClass().getSimpleName() + ", " + e.getMessage(),
                e);
        if (jtm != null)
            jtm.rollback();
        throw new HinemosUnknown(e.getMessage(), e);
    } finally {
        if (jtm != null)
            jtm.close();
    }

    return true;

}

From source file:com.clustercontrol.performance.session.PerformanceCollectMasterControllerBean.java

/**
 * ???/*from   w w  w .ja  v a2 s .com*/
 * 
 * @param data 
 * @return ??????true
 * @throws HinemosUnknown
 */
public boolean addCollectPlatformMaster(CollectorPlatformMstData data) throws HinemosUnknown {
    JpaTransactionManager jtm = null;

    try {
        jtm = new JpaTransactionManager();
        jtm.begin();

        // 
        RepositoryControllerBean repositoryControllerBean = new RepositoryControllerBean();
        repositoryControllerBean.addCollectorPratformMst(data);

        String osParentFacilityId = FacilityTreeAttributeConstant.OS_PARENT_SCOPE;
        ScopeInfo osParentScopeInfo = repositoryControllerBean.getScope(osParentFacilityId);
        ScopeInfo scopeInfo = new ScopeInfo();
        scopeInfo.setFacilityId(data.getPlatformId());
        scopeInfo.setFacilityName(data.getPlatformName());
        scopeInfo.setDescription(data.getPlatformName());
        scopeInfo.setFacilityType(osParentScopeInfo.getFacilityType());
        scopeInfo.setIconImage(osParentScopeInfo.getIconImage());
        scopeInfo.setOwnerRoleId(osParentScopeInfo.getOwnerRoleId());
        repositoryControllerBean.addScope(osParentFacilityId, scopeInfo, data.getOrderNo());

        jtm.commit();
    } catch (EntityExistsException e) {
        // ?????
        // ??????????????????????????????
        if (jtm != null)
            jtm.rollback();
        return false;
    } catch (Exception e) {
        m_log.warn("addCollectPlatformMaster() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        if (jtm != null)
            jtm.rollback();
        throw new HinemosUnknown(e.getMessage(), e);
    } finally {
        if (jtm != null)
            jtm.close();
    }

    return true;

}

From source file:com.clustercontrol.repository.session.RepositoryControllerBean.java

/**
 * ??????TOPIC???<BR>//  www  .  j av  a2  s  .  c  o  m
 * ?????????"?"?
 * ?????
 *
 * @version 3.1.0
 * @since 1.0.0
 *
 * @param nodeInfo ??
 * @throws FacilityDuplicate
 * @throws InvalidSetting
 * @throws HinemosUnknown
 */
public void addNode(final NodeInfo nodeInfo, boolean topicSendFlg)
        throws FacilityDuplicate, InvalidSetting, HinemosUnknown {
    JpaTransactionManager jtm = new JpaTransactionManager();

    try {
        jtm.begin();

        // ??null????????????null??
        nodeInfo.setDefaultInfo();

        // ?
        RepositoryValidator.validateNodeInfo(nodeInfo);

        FacilityModifier.addNode(nodeInfo,
                (String) HinemosSessionContext.instance().getProperty(HinemosSessionContext.LOGIN_USER_ID),
                FacilitySortOrderConstant.DEFAULT_SORT_ORDER_NODE);

        jtm.addCallback(new NodeCacheUpdateCallback(nodeInfo.getFacilityId()));
        jtm.addCallback(new FacilityIdCacheInitCallback());
        jtm.addCallback(new FacilityTreeCacheRefreshCallback());
        jtm.addCallback(new RepositoryChangedNotificationCallback());
        jtm.addCallback(new NodeToMonitorCacheChangeCallback());
        jtm.addCallback(new EmptyJpaTransactionCallback() {
            @Override
            public void postCommit() {
                NodeMonitorPollerController.registNodeMonitorPoller(nodeInfo);
            }
        });

        try {
            ListenerReadWriteLock.readLock();
            for (IRepositoryListener listener : _listenerList) {
                jtm.addCallback(new RepositoryListenerCallback(listener, Type.ADD_NODE, null,
                        nodeInfo.getFacilityId()));
            }
        } finally {
            ListenerReadWriteLock.readUnlock();
        }

        jtm.commit();
    } catch (EntityExistsException e) {
        jtm.rollback();
        throw new FacilityDuplicate(e.getMessage(), e);
    } catch (InvalidSetting e) {
        jtm.rollback();
        throw e;
    } catch (FacilityNotFound e) {
        jtm.rollback();
        throw new HinemosUnknown(e.getMessage(), e);
    } catch (Exception e) {
        m_log.warn("addNode() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        jtm.rollback();
        throw new HinemosUnknown(e.getMessage(), e);
    } finally {
        jtm.close();
    }
}