List of usage examples for javax.persistence EntityExistsException getMessage
public String getMessage()
From source file:com.telefonica.euro_iaas.commons.dao.AbstractBaseDao.java
/** * {@inheritDoc}// w w w . j ava2s . c o m */ public T create(T entity) throws AlreadyExistsEntityException { try { entityManager.persist(entity); entityManager.flush(); return entity; } catch (EntityExistsException e) { throw new AlreadyExistsEntityException(entity, e); } catch (PersistenceException e) { throw new DaoRuntimeException(e.getMessage(), e); } }
From source file:com.clustercontrol.repository.factory.FacilityModifier.java
/** ?<BR> * * @param CollectorPlatformMstData /*w w w . ja v a 2s . c o m*/ * @throws CollectorPlatformMstData * @throws EntityExistsException */ public static void addCollectorPratformMst(CollectorPlatformMstData data) throws EntityExistsException { JpaTransactionManager jtm = new JpaTransactionManager(); try { // ? CollectorPlatformMstEntity entity = new CollectorPlatformMstEntity(data.getPlatformId()); // ?? jtm.checkEntityExists(CollectorPlatformMstEntity.class, entity.getPlatformId()); entity.setOrderNo(data.getOrderNo().intValue()); entity.setPlatformName(data.getPlatformName()); } catch (EntityExistsException e) { m_log.info("addCollectorPratformMst() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); throw e; } }
From source file:com.clustercontrol.repository.factory.FacilityModifier.java
/** ?<BR> * * @param addCollectorSubPratformMst /*from w w w .jav a 2s . co m*/ * @throws addCollectorSubPratformMst * @throws EntityExistsException */ public static void addCollectorSubPratformMst(CollectorSubPlatformMstData data) throws EntityExistsException { JpaTransactionManager jtm = new JpaTransactionManager(); try { // ? CollectorSubPlatformMstEntity entity = new CollectorSubPlatformMstEntity(data.getSubPlatformId()); // ?? jtm.checkEntityExists(CollectorSubPlatformMstEntity.class, entity.getSubPlatformId()); entity.setSubPlatformName(data.getSubPlatformName()); entity.setType(data.getType()); entity.setOrderNo(data.getOrderNo()); } catch (EntityExistsException e) { m_log.info("addCollectorSubPratformMst() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); throw e; } }
From source file:com.clustercontrol.calendar.factory.ModifyCalendar.java
/** * /* w w w . j a v a2 s . c o m*/ * * @param info * @param userName * @return * @throws HinemosUnknown * @throws CalendarDuplicate * @throws CalendarNotFound */ public void addCalendar(CalendarInfo info, String userName) throws HinemosUnknown, CalendarDuplicate, CalendarNotFound { JpaTransactionManager jtm = new JpaTransactionManager(); HinemosEntityManager em = jtm.getEntityManager(); //? try { //?? Long now = HinemosTime.currentTimeMillis(); // ?? jtm.checkEntityExists(CalendarInfo.class, info.getCalendarId()); info.setRegDate(now); info.setRegUser(userName); info.setUpdateDate(now); info.setUpdateUser(userName); em.persist(info); // for (int i = 0; i < info.getCalendarDetailList().size(); i++) { CalendarDetailInfo calDetailInfoEntity = info.getCalendarDetailList().get(i); calDetailInfoEntity.setCalendarId(info.getCalendarId()); calDetailInfoEntity.setOrderNo(i + 1); em.persist(calDetailInfoEntity); calDetailInfoEntity.relateToCalInfoEntity(info); } } catch (EntityExistsException e) { m_log.info("addCalendar() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); throw new CalendarDuplicate(e.getMessage(), e); } catch (Exception e) { m_log.warn("addCalendar() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); throw new HinemosUnknown(e.getMessage(), e); } }
From source file:com.clustercontrol.monitor.run.factory.ModifyMonitor.java
/** * ?????????/*from w w w. j ava2 s.com*/ * * @param info * @param user ?? * @return ???????</code> true </code> * @throws MonitorNotFound * @throws MonitorDuplicate * @throws TriggerSchedulerException * @throws HinemosUnknown * @throws InvalidRole * * @see #addMonitorInfo(String) */ public boolean add(MonitorInfo info, String user) throws MonitorNotFound, MonitorDuplicate, TriggerSchedulerException, HinemosUnknown, InvalidRole { m_monitorInfo = info; boolean result = false; try { // result = addMonitorInfo(user); } catch (EntityExistsException e) { throw new MonitorDuplicate(e.getMessage(), e); } catch (MonitorNotFound e) { throw e; } catch (TriggerSchedulerException e) { throw e; } catch (HinemosUnknown e) { throw e; } catch (InvalidRole e) { throw e; } return result; }
From source file:com.clustercontrol.monitor.run.factory.ModifyMonitor.java
/** * ????// ww w. ja va 2 s . c om * <p> * <ol> * <li>?????????</li> * <li>??????????????{@link #addJudgementInfo()}</li> * <li>????????????????{@link #addCheckInfo()}</li> * <li>Quartz????/???</li> * </ol> * * @param user ?? * @return ???????</code> true </code> * @throws MonitorNotFound * @throws TriggerSchedulerException * @throws EntityExistsException * @throws HinemosUnknown * @throws InvalidRole * * @see com.clustercontrol.monitor.run.ejb.entity.MonitorInfoBean * @see #addJudgementInfo() * @see #addCheckInfo() * @see com.clustercontrol.monitor.run.factory.ModifySchedule#addSchedule(MonitorInfo, String, Calendar) */ protected boolean addMonitorInfo(String user) throws MonitorNotFound, TriggerSchedulerException, EntityExistsException, HinemosUnknown, InvalidRole { long now = HinemosTime.currentTimeMillis(); JpaTransactionManager jtm = new JpaTransactionManager(); try { // ?? jtm.checkEntityExists(MonitorInfo.class, m_monitorInfo.getMonitorId()); m_monitorInfo.setDelayTime(getDelayTime()); m_monitorInfo.setNotifyGroupId(NotifyGroupIdGenerator.generate(m_monitorInfo)); m_monitorInfo.setRegDate(now); m_monitorInfo.setRegUser(user); m_monitorInfo.setTriggerType(getTriggerType().name()); m_monitorInfo.setUpdateDate(now); m_monitorInfo.setUpdateUser(user); jtm.getEntityManager().persist(m_monitorInfo); // ? String notifyGroupId = NotifyGroupIdGenerator.generate(m_monitorInfo); m_monitorInfo.setNotifyGroupId(notifyGroupId); if (m_monitorInfo.getNotifyRelationList() != null && m_monitorInfo.getNotifyRelationList().size() > 0) { for (NotifyRelationInfo notifyRelationInfo : m_monitorInfo.getNotifyRelationList()) { notifyRelationInfo.setNotifyGroupId(notifyGroupId); } // new ModifyNotifyRelation().add(m_monitorInfo.getNotifyRelationList()); } // if (addJudgementInfo()) { // ?? if (addCheckInfo()) { // Quartz?(runInterval = 0 -> ???) if (m_monitorInfo.getRunInterval() > 0) { ModifySchedule quartz = new ModifySchedule(); quartz.updateSchedule(m_monitorInfo.getMonitorId()); } return true; } } return false; } catch (EntityExistsException e) { m_log.info("addMonitorInfo() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); throw e; } catch (MonitorNotFound e) { throw e; } catch (HinemosUnknown e) { throw e; } catch (InvalidRole e) { throw e; } }
From source file:com.clustercontrol.jobmanagement.factory.ModifyJobKick.java
/** * DB??????/*w ww. j a va 2s . c om*/ * ???????<BR> * * @param info * @param user ID * @param jobkickType * @throws HinemosUnknown * @throws JobKickDuplicate * * @see com.clustercontrol.jobmanagement.bean.QuartzConstant * @see com.clustercontrol.jobmanagement.bean.JobTriggerInfo * @see com.clustercontrol.jobmanagement.util.QuartzUtil#getQuartzManager() */ public void addJobKick(final JobKick info, String loginUser, Integer jobkickType) throws HinemosUnknown, JobKickDuplicate { m_log.debug("addJobKick() : id=" + info.getId() + ", jobId=" + info.getJobId() + ", jobkickType=" + jobkickType); JpaTransactionManager jtm = new JpaTransactionManager(); // long now = HinemosTime.currentTimeMillis(); // DB?? try { // ID??? String id = info.getId(); jtm.checkEntityExists(JobKickEntity.class, id); // JobKickEntity jobKickEntity = new JobKickEntity(info.getId()); jobKickEntity.setJobkickName(info.getName()); jobKickEntity.setJobkickType(jobkickType); jobKickEntity.setJobunitId(info.getJobunitId()); jobKickEntity.setJobId(info.getJobId()); // if (info.getJobRuntimeParamList() != null && info.getJobRuntimeParamList().size() > 0) { for (JobRuntimeParam jobRuntimeParam : info.getJobRuntimeParamList()) { JobRuntimeParamEntity jobRuntimeParamEntity = new JobRuntimeParamEntity(jobKickEntity, jobRuntimeParam.getParamId()); jobRuntimeParamEntity.setParamType(jobRuntimeParam.getParamType()); jobRuntimeParamEntity.setDefaultValue(jobRuntimeParam.getValue()); jobRuntimeParamEntity.setDescription(jobRuntimeParam.getDescription()); jobRuntimeParamEntity.setRequiredFlg(jobRuntimeParam.getRequiredFlg()); // if (jobRuntimeParam.getJobRuntimeParamDetailList() != null && jobRuntimeParam.getJobRuntimeParamDetailList().size() > 0) { int detailIdx = 0; for (JobRuntimeParamDetail jobRuntimeParamDetail : jobRuntimeParam .getJobRuntimeParamDetailList()) { JobRuntimeParamDetailEntity jobRuntimeParamDetailEntity = new JobRuntimeParamDetailEntity( jobRuntimeParamEntity, detailIdx); jobRuntimeParamDetailEntity.setParamValue(jobRuntimeParamDetail.getParamValue()); jobRuntimeParamDetailEntity.setDescription(jobRuntimeParamDetail.getDescription()); detailIdx++; } } } } if (jobkickType == JobKickConstant.TYPE_SCHEDULE) { // if (!(info instanceof JobSchedule)) { throw new HinemosUnknown("type error : " + info.getClass() + "!=JobSchedule"); } JobSchedule jobSchedule = (JobSchedule) info; if (!"".equals(jobSchedule.getCalendarId())) { jobKickEntity.setCalendarId(jobSchedule.getCalendarId()); } jobKickEntity.setValidFlg(info.isValid()); jobKickEntity.setScheduleType(jobSchedule.getScheduleType()); jobKickEntity.setWeek(jobSchedule.getWeek()); jobKickEntity.setHour(jobSchedule.getHour()); jobKickEntity.setMinute(jobSchedule.getMinute()); jobKickEntity.setFromXMinutes(jobSchedule.getFromXminutes()); jobKickEntity.setEveryXMinutes(jobSchedule.getEveryXminutes()); } else if (jobkickType == JobKickConstant.TYPE_FILECHECK) { // ? if (!(info instanceof JobFileCheck)) { throw new HinemosUnknown("type error : " + info.getClass() + "!=JobFileCheck"); } JobFileCheck jobFileCheck = (JobFileCheck) info; if (!"".equals(jobFileCheck.getCalendarId())) { jobKickEntity.setCalendarId(jobFileCheck.getCalendarId()); } jobKickEntity.setValidFlg(info.isValid()); jobKickEntity.setFacilityId(jobFileCheck.getFacilityId()); jobKickEntity.setFileName(jobFileCheck.getFileName()); jobKickEntity.setDirectory(jobFileCheck.getDirectory()); jobKickEntity.setEventType(jobFileCheck.getEventType()); jobKickEntity.setModifyType(jobFileCheck.getModifyType()); } else if (jobkickType == JobKickConstant.TYPE_MANUAL) { jobKickEntity.setCalendarId(null); jobKickEntity.setValidFlg(true); } jobKickEntity.setOwnerRoleId(info.getOwnerRoleId()); jobKickEntity.setRegDate(now); jobKickEntity.setUpdateDate(now); jobKickEntity.setRegUser(loginUser); jobKickEntity.setUpdateUser(loginUser); } catch (EntityExistsException e) { m_log.info("addJobKick() JobKickEntity.create() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); throw new JobKickDuplicate(e.getMessage(), e); } catch (Exception e) { m_log.warn( "addJobKick() JobKickEntity.create() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); throw new HinemosUnknown(e.getMessage(), e); } if (jobkickType == JobKickConstant.TYPE_SCHEDULE) { // ????? JobTriggerInfo triggerInfo = new JobTriggerInfo(); triggerInfo.setTrigger_type(JobTriggerTypeConstant.TYPE_SCHEDULE); triggerInfo.setTrigger_info(info.getName() + "(" + info.getId() + ")"); //JobDetail???? Serializable[] jdArgs = new Serializable[QuartzConstant.ARGS_NUM]; @SuppressWarnings("unchecked") Class<? extends Serializable>[] jdArgsType = new Class[QuartzConstant.ARGS_NUM]; //ID jdArgs[QuartzConstant.INDEX_JOBUNIT_ID] = info.getJobunitId(); jdArgsType[QuartzConstant.INDEX_JOBUNIT_ID] = String.class; //ID jdArgs[QuartzConstant.INDEX_JOB_ID] = info.getJobId(); jdArgsType[QuartzConstant.INDEX_JOB_ID] = String.class; //ID jdArgs[QuartzConstant.INDEX_CALENDAR_ID] = info.getCalendarId(); jdArgsType[QuartzConstant.INDEX_CALENDAR_ID] = String.class; // jdArgs[QuartzConstant.INDEX_TRIGGER_TYPE] = triggerInfo.getTrigger_type(); jdArgsType[QuartzConstant.INDEX_TRIGGER_TYPE] = Integer.class; // jdArgs[QuartzConstant.INDEX_TRIGGER_INFO] = triggerInfo.getTrigger_info(); jdArgsType[QuartzConstant.INDEX_TRIGGER_INFO] = String.class; //?? jdArgs[QuartzConstant.INDEX_TRIGGER_FILENAME] = triggerInfo.getFilename(); jdArgsType[QuartzConstant.INDEX_TRIGGER_FILENAME] = String.class; //?? jdArgs[QuartzConstant.INDEX_TRIGGER_DIRECTORY] = triggerInfo.getDirectory(); jdArgsType[QuartzConstant.INDEX_TRIGGER_DIRECTORY] = String.class; //???? jdArgs[QuartzConstant.INDEX_TRIGGER_JOB_WAIT_TIME] = triggerInfo.getJobWaitTime(); jdArgsType[QuartzConstant.INDEX_TRIGGER_JOB_WAIT_TIME] = Boolean.class; //????? jdArgs[QuartzConstant.INDEX_TRIGGER_JOB_WAIT_MINUTE] = triggerInfo.getJobWaitTime(); jdArgsType[QuartzConstant.INDEX_TRIGGER_JOB_WAIT_MINUTE] = Boolean.class; //???? jdArgs[QuartzConstant.INDEX_TRIGGER_JOB_COMMAND] = triggerInfo.getJobCommand(); jdArgsType[QuartzConstant.INDEX_TRIGGER_JOB_COMMAND] = Boolean.class; //???? jdArgs[QuartzConstant.INDEX_TRIGGER_JOB_COMMAND_TEXT] = triggerInfo.getJobCommandText(); jdArgsType[QuartzConstant.INDEX_TRIGGER_JOB_COMMAND_TEXT] = String.class; //ID jdArgs[QuartzConstant.INDEX_TRIGGER_JOBKICK_ID] = info.getId(); jdArgsType[QuartzConstant.INDEX_TRIGGER_JOBKICK_ID] = String.class; //Cron?? String cronString = QuartzUtil.getCronString(((JobSchedule) info).getScheduleType(), ((JobSchedule) info).getWeek(), ((JobSchedule) info).getHour(), ((JobSchedule) info).getMinute(), ((JobSchedule) info).getFromXminutes(), ((JobSchedule) info).getEveryXminutes()); m_log.trace("CronString =" + cronString); // try { if (info.isValid().booleanValue()) { SchedulerPlugin.scheduleCronJob(SchedulerType.DBMS, info.getId(), QuartzConstant.GROUP_NAME, HinemosTime.currentTimeMillis() + 15 * 1000, cronString, true, JobControllerBean.class.getName(), QuartzConstant.METHOD_NAME, jdArgsType, jdArgs); } else { SchedulerPlugin.deleteJob(SchedulerType.DBMS, info.getId(), QuartzConstant.GROUP_NAME); } } catch (HinemosUnknown e) { m_log.error(e); } } }
From source file:com.clustercontrol.plugin.factory.ModifyDbmsScheduler.java
/** * @param jobDetail//from w w w . j av a2s . com * @param trigger * @return * @throws EntityExistsException * @throws InvalidClassException */ public void addDbmsScheduler(JobDetail jobDetail, Trigger trigger) throws EntityExistsException, InvalidClassException { JpaTransactionManager jtm = null; try { jtm = new JpaTransactionManager(); jtm.begin(); // ?? jtm.checkEntityExists(DbmsSchedulerEntity.class, new DbmsSchedulerEntityPK(jobDetail.getName(), jobDetail.getGroup())); DbmsSchedulerEntity entity = new DbmsSchedulerEntity(jobDetail.getName(), jobDetail.getGroup()); setEntityInfo(entity, jobDetail, trigger); HinemosEntityManager em = jtm.getEntityManager(); em.persist(entity); jtm.commit(); } catch (EntityExistsException e) { m_log.error("DbmsSchedulerEntity entity is already exists. (name = " + jobDetail.getName() + ", group = " + jobDetail.getGroup() + ")"); if (jtm != null) jtm.rollback(); throw e; } catch (DatabaseException e) { m_log.error("addDbmsScheduler() DatabaseException: (name = " + jobDetail.getName() + ", group = " + jobDetail.getGroup() + ")"); if (jtm != null) jtm.rollback(); throw e; } catch (Exception e) { m_log.error("modifyDbmsScheduler() Exception. (name = " + jobDetail.getName() + ", group = " + jobDetail.getGroup() + ")"); m_log.error("modifyDbmsScheduler(): " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw e; } finally { if (jtm != null) jtm.close(); } }
From source file:mx.edu.ittepic.AEEcommerce.ejbs.OperationCommerce.java
public String newCategory(String categoryname) { Message m = new Message(); GsonBuilder builder = new GsonBuilder(); Gson gson = builder.create();/*from w ww . j a v a 2 s . co m*/ try { Category p = new Category(); p.setCategoryname(categoryname); entity.persist(p); entity.flush(); m.setCode(200); m.setMsg("Todo bien compa"); m.setDetail("OK, El id es:" + p.getCategoryid().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:mx.edu.ittepic.AEEcommerce.ejbs.OperationCommerce.java
public String newCompany(String CompanyName, String neighborhood, String zipcode, String city, String country, String state, String region, String street, String streetnumber, String phone, String rfc, String logo) {/*from w w w .j av a 2 s . c o m*/ Message m = new Message(); GsonBuilder builder = new GsonBuilder(); Gson gson = builder.create(); try { Company p = new Company(); p.setCompanyname(CompanyName); p.setNeighborhood(neighborhood); p.setZipcode(zipcode); p.setCity(city); p.setCountry(country); p.setState(state); p.setRegion(region); p.setStreet(street); p.setStreetnumber(streetnumber); p.setPhone(phone); p.setRfc(rfc); p.setLogo(logo); entity.persist(p); entity.flush(); m.setCode(200); m.setMsg("Todo bien compa"); m.setDetail("OK, El id es:" + p.getCompanyid().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); } }