List of usage examples for org.hibernate HibernateException HibernateException
public HibernateException(Throwable cause)
From source file:com.krawler.hrms.hrmsHandler.java
License:Open Source License
public static JSONObject AppraisalAssign(Session session, HttpServletRequest request) throws ServiceException, SessionExpiredException, ParseException, JSONException { JSONObject jobj = new JSONObject(); try {//from w w w .j a v a 2 s.c om Appraisalmanagement appm = null; boolean flag = true; String query = ""; String manager = ""; String hql = ""; Iterator ite = null; List tabledata = null; List list = null; String ids[] = request.getParameterValues("empids"); Date userdate = com.krawler.common.util.Timezone.toUserSystemTimezoneDate(session, request, dateFmt.format(new Date()), AuthHandler.getUserid(request)); hql = "select id from Appraisalcycle where id=? and submitenddate>=?"; tabledata = HibernateUtil.executeQuery(session, hql, new Object[] { request.getParameter("apptype"), userdate }); if (tabledata.isEmpty()) { jobj.put("message", "Appraisal cycle submission has already ended"); } else { for (int i = 0; i < ids.length; i++) { hql = "from Appraisalmanagement where employee.userID=? and appcycle.id=? "; tabledata = HibernateUtil.executeQuery(session, hql, new Object[] { ids[i], request.getParameter("apptype") }); if (tabledata.isEmpty()) {//check for appraisal cycle already initiated query = "select count(assignman.userID) from Assignmanager where assignemp.userID=? and managerstatus=1"; list = HibernateUtil.executeQuery(session, query, ids[i]); long man = (Long) list.get(0); query = "select count(reviewer.userID) from Assignreviewer where employee.userID=? and reviewerstatus=1"; list = HibernateUtil.executeQuery(session, query, ids[i]); long rv = (Long) list.get(0); if (man > 0 && rv > 0) { //at least 1 manager and reviewer are assigned query = "from Assignmanager where assignemp.userID=? and managerstatus=1"; list = HibernateUtil.executeQuery(session, query, ids[i]); ite = list.iterator(); while (ite.hasNext()) { Assignmanager assignman = (Assignmanager) ite.next(); if (assignman.getAssignman() != null) { manager = assignman.getAssignman().getUserID(); appm = new Appraisalmanagement(); User usr = (User) session.load(User.class, ids[i]); appm.setAppcycle((Appraisalcycle) session.load(Appraisalcycle.class, request.getParameter("apptype"))); appm.setEmployee(usr); appm.setManager((User) session.load(User.class, manager)); appm.setEmployeestatus(0); appm.setManagerstatus(0); appm.setEmployeedraft(0); appm.setManagerdraft(0); appm.setAppraisalstatus(request.getParameter("status")); appm.setReviewstatus(0); session.saveOrUpdate(appm); } } } else { if (rv == 0 && man == 0) { jobj.put("message", MessageSourceProxy.getMessage( "hrms.hrmshandler.msg.noappraiserandreviewerassignedforselectedappraisalcycle", null, "No appraiser and reviewer assigned for selected appraisal cycle", LocaleUtil.getCompanyLocale(AuthHandler.getCompanyid(request), 0))); return jobj; } else if (rv == 0) { jobj.put("message", MessageSourceProxy.getMessage( "hrms.hrmshandler.msg.noreviewerassignedforselectedappraisalcycle", null, "No reviewer assigned for selected appraisal cycle", LocaleUtil.getCompanyLocale(AuthHandler.getCompanyid(request), 0))); return jobj; } else { jobj.put("message", MessageSourceProxy.getMessage( "hrms.hrmshandler.msg.noappraiserassignedforselectedappraisalcycle", null, "No appraiser assigned for selected appraisal cycle", LocaleUtil.getCompanyLocale(AuthHandler.getCompanyid(request), 0))); return jobj; } } } else { jobj.put("message", MessageSourceProxy.getMessage( "hrms.hrmshandler.msg.appraisalcycleisalreadyinitiatedfortheselectedemployee", null, "Appraisal Cycle is already initiated for the selected employee", LocaleUtil.getCompanyLocale(AuthHandler.getCompanyid(request), 0))); return jobj; } //@@ProfileHandler.insertAuditLog(session, AuditAction.INITIATE_APPRAISAL, "User " + AuthHandler.getFullName(session, AuthHandler.getUserid(request)) + " has initiated appraisal of " + AuthHandler.getFullName(appm.getEmployee()) + " for the appraisal cycle " + appm.getAppcycle().getCyclename(), request); jobj.put("message", MessageSourceProxy.getMessage( "hrms.hrmshandler.msg.appraisalsuccessfullyintiatedforselectedemployee", null, "Appraisal successfully intiated for selected employee(s)", LocaleUtil.getCompanyLocale(AuthHandler.getCompanyid(request), 0))); } } } catch (HibernateException ex) { throw new HibernateException("AppraisalAssign"); } finally { } return jobj; }
From source file:com.krawler.hrms.hrmsHandler.java
License:Open Source License
public static void addAgencyFunction(Session session, HttpServletRequest request) throws ServiceException, SessionExpiredException { try {/*from w w w . ja va 2 s. c o m*/ Agency contact = null; if (StringUtil.isNullOrEmpty(request.getParameter("agencyid"))) { String id = UUID.randomUUID().toString(); contact = new Agency(); contact.setAgencyid(id); contact.setCompany((Company) session.load(Company.class, AuthHandler.getCompanyid(request))); contact.setDelflag(0); } else { contact = (Agency) session.load(Agency.class, request.getParameter("agencyid")); } contact.setAgencyname(request.getParameter("agencyname")); contact.setAgencyweb(request.getParameter("agencyweb")); contact.setReccost(request.getParameter("reccost")); contact.setConperson(request.getParameter("conperson")); contact.setApprman((User) session.load(User.class, request.getParameter("apprman"))); contact.setAgencyno(request.getParameter("agencyno")); contact.setAgencyadd(request.getParameter("agencyadd")); if (StringUtil.isNullOrEmpty(request.getParameter("agencyid"))) { session.save(contact); //@@ProfileHandler.insertAuditLog(session, AuditAction.ADD_AGENCY, "User " + AuthHandler.getFullName(session, AuthHandler.getUserid(request)) + " has added new agency " + contact.getAgencyname(),request); } else { session.update(contact); //@@ProfileHandler.insertAuditLog(session, AuditAction.EDIT_AGENCY, "User " + AuthHandler.getFullName(session, AuthHandler.getUserid(request)) + " has edited agency " + contact.getAgencyname(),request); } } catch (SessionExpiredException se) { throw new SessionExpiredException("addAgencyFunction", se.COMPANYID_NULL); } catch (HibernateException ex) { throw new HibernateException("addAgencyFunction"); } finally { } }
From source file:com.krawler.hrms.hrmsHandler.java
License:Open Source License
public static JSONObject appraisalFunction(Session session, HttpServletRequest request) throws ServiceException, ParseException, JSONException, SessionExpiredException { List tabledata = null;//from w ww . j a va2s .c o m JSONObject msgjobj = new JSONObject(); User u = null; boolean flag = true; SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); try { Appraisalmanagement appmanage = null; Appraisal app = null; if (StringUtil.isNullOrEmpty(request.getParameter("rateperformance"))) { String jsondata1 = request.getParameter("jsoncompetency"); String jsondata2 = request.getParameter("jsongoal"); String[] appids = request.getParameter("appraisalid").split(","); for (int k = 0; k < appids.length; k++) { String hql = "from Appraisalmanagement where appraisalid=?"; tabledata = HibernateUtil.executeQuery(session, hql, appids[k]); if (tabledata.isEmpty()) { appmanage = new Appraisalmanagement(); flag = true; } else { appmanage = (Appraisalmanagement) session.load(Appraisalmanagement.class, appids[k]); String appcycleid = appmanage.getAppcycle().getId(); String employeeid = appmanage.getEmployee().getUserID(); String query = "from Appraisalmanagement where appcycle.id=? and employee.userID=? and reviewstatus=2 and (not date(now()) between appcycle.submitstartdate and appcycle.submitenddate)"; List list = HibernateUtil.executeQuery(session, query, new Object[] { appcycleid, employeeid }); if (!list.isEmpty()) { flag = false; } } if (flag) { if (Boolean.parseBoolean(request.getParameter("employee"))) { appmanage.setEmployeecomment(request.getParameter("empcomment")); if (!Boolean.parseBoolean(request.getParameter("saveasDraft"))) { appmanage.setEmployeestatus(1); appmanage.setEmployeedraft(0); } else { appmanage.setEmployeedraft(1); } appmanage.setEmployeecompscore( Double.parseDouble(request.getParameter("competencyscore"))); appmanage.setEmployeegoalscore(Double.parseDouble(request.getParameter("goalscore"))); appmanage.setEmployeegapscore(Double.parseDouble(request.getParameter("compgapscore"))); appmanage.setEmployeesubmitdate((Date) fmt.parse(request.getParameter("submitdate"))); } else { appmanage.setManagercomment(request.getParameter("mancomment")); if (!Boolean.parseBoolean(request.getParameter("saveasDraft"))) { appmanage.setManagerstatus(1); appmanage.setManagerdraft(0); appmanage.setAppraisalstatus("submitted"); //@@ProfileHandler.insertAuditLog(session,AuditAction.APPRAISAL_SUBMITTED,"Appraiser " + AuthHandler.getFullName(appmanage.getManager()) + " has submitted appraisal for " + AuthHandler.getFullName(appmanage.getEmployee()) + " for the appraisal cycle " + appmanage.getAppcycle().getCyclename(), request); } else { appmanage.setAppraisalstatus("pending"); appmanage.setManagerdraft(1); } appmanage.setReviewstatus(0); if (!StringUtil.isNullOrEmpty(request.getParameter("performance"))) { appmanage.setPerformance((MasterData) session.load(MasterData.class, request.getParameter("performance"))); } appmanage.setManagercompscore( Double.parseDouble(request.getParameter("competencyscore"))); appmanage.setManagergoalscore(Double.parseDouble(request.getParameter("goalscore"))); appmanage.setManagergapscore(Double.parseDouble(request.getParameter("compgapscore"))); appmanage.setManagersubmitdate((Date) fmt.parse(request.getParameter("submitdate"))); if (Boolean.parseBoolean(request.getParameter("salarychange"))) { appmanage.setSalaryrecommend(1); if (!StringUtil.isNullOrEmpty(request.getParameter("newdesignation"))) { appmanage.setNewdesignation((MasterData) session.load(MasterData.class, request.getParameter("newdesignation"))); } else { appmanage.setNewdesignation(null); } if (!StringUtil.isNullOrEmpty(request.getParameter("newdepartment"))) { appmanage.setNewdepartment((MasterData) session.load(MasterData.class, request.getParameter("newdepartment"))); } else { appmanage.setNewdepartment(null); } if (!StringUtil.isNullOrEmpty(request.getParameter("salaryincrement"))) { appmanage.setSalaryincrement( Float.parseFloat(request.getParameter("salaryincrement"))); } else { appmanage.setSalaryincrement(0); } } else { appmanage.setSalaryrecommend(0); } } if (appmanage.getEmployeestatus() == 1 && appmanage.getManagerstatus() == 1) { appmanage.setAppraisalstatus("submitted"); appmanage.setReviewstatus(0); appmanage.setTotalscore( (appmanage.getEmployeegoalscore() + appmanage.getEmployeecompscore() + appmanage.getManagergoalscore() + appmanage.getManagercompscore()) / 4); } session.save(appmanage); String cmp = "from Appraisal where appraisal.appraisalid=? and competency!=null"; List cmplst = HibernateUtil.executeQuery(session, cmp, appids[k]); JSONArray jarr = new JSONArray("[" + jsondata1 + "]"); for (int i = 0; i < jarr.length(); i++) { JSONObject jobj = jarr.getJSONObject(i); if (cmplst.size() > 0) { app = (Appraisal) cmplst.get(i); } else { app = new Appraisal(); } if (Boolean.parseBoolean(request.getParameter("employee"))) { if (!StringUtil.isNullOrEmpty(jobj.getString("compemprate"))) { app.setCompemprating(Double.parseDouble(jobj.getString("compemprate"))); } else { app.setCompemprating(0); } app.setCompempgap(Double.parseDouble(jobj.getString("compempgap"))); app.setCompempcomment(jobj.getString("compempcomment")); } else { if (!StringUtil.isNullOrEmpty(jobj.getString("compmanrate"))) { app.setCompmanrating(Double.parseDouble(jobj.getString("compmanrate"))); } else { app.setCompmanrating(0); } app.setCompmangap(Double.parseDouble(jobj.getString("compmangap"))); app.setCompmancomment(jobj.getString("compmancomment")); } app.setAppraisal( (Appraisalmanagement) session.load(Appraisalmanagement.class, appids[k])); app.setCompetency((Managecmpt) session.load(Managecmpt.class, jobj.getString("mid"))); session.save(app); } jarr = new JSONArray("[" + jsondata2 + "]"); for (int j = 0; j < jarr.length(); j++) { JSONObject jobj = jarr.getJSONObject(j); if (StringUtil.isNullOrEmpty(jobj.getString("id"))) { app = new Appraisal(); } else { app = (Appraisal) session.load(Appraisal.class, jobj.getString("id")); } if (Boolean.parseBoolean(request.getParameter("employee"))) { if (StringUtil.equal(appids[k], jobj.getString("goalapprid"))) { if (!StringUtil.isNullOrEmpty(jobj.getString("goalemprate"))) { app.setGoalemprating(Double.parseDouble(jobj.getString("goalemprate"))); } else { app.setGoalemprating(0); } app.setGoalempcomment(jobj.getString("goalempcomment")); app.setAppraisal((Appraisalmanagement) session.load(Appraisalmanagement.class, appids[k])); app.setGoal((Finalgoalmanagement) session.load(Finalgoalmanagement.class, jobj.getString("goalid"))); session.save(app); } } else { if (!StringUtil.isNullOrEmpty(jobj.getString("goalmanrate"))) { app.setGoalmanrating(Double.parseDouble(jobj.getString("goalmanrate"))); } else { app.setGoalmanrating(0); } app.setGoalmancomment(jobj.getString("goalmancomment")); app.setAppraisal( (Appraisalmanagement) session.load(Appraisalmanagement.class, appids[k])); app.setGoal((Finalgoalmanagement) session.load(Finalgoalmanagement.class, jobj.getString("goalid"))); session.save(app); } } } else { break; } } if (Boolean.parseBoolean(request.getParameter("employee")) && !Boolean.parseBoolean(request.getParameter("saveasDraft"))) { //@@ProfileHandler.insertAuditLog(session,AuditAction.APPRAISAL_SUBMITTED,"Employee " + AuthHandler.getFullName(appmanage.getEmployee())+" has submitted appraisal for the appraisal cycle " + appmanage.getAppcycle().getCyclename(), request); } } else { String performance[] = request.getParameterValues("item_prate"); String finalid[] = request.getParameterValues("item_fid"); for (int i = 0; i < finalid.length; i++) { String query = "from Appraisalmanagement where appraisalid=?"; tabledata = HibernateUtil.executeQuery(session, query, finalid[i]); MasterData perfo = (MasterData) session.load(MasterData.class, performance[i]); if (!tabledata.isEmpty()) { appmanage = (Appraisalmanagement) tabledata.get(0); appmanage.setPerformance(perfo); appmanage.setAppraisalstatus("submitted"); appmanage.setReviewstatus(0); u = appmanage.getEmployee(); session.update(appmanage); //@@ProfileHandler.insertAuditLog(session, AuditAction.APPERAISAL_DONE, "Appraisal of " + (u != null ? AuthHandler.getFullName(u) : "") + " done by " + AuthHandler.getFullName(session, AuthHandler.getUserid(request)), request); } } } msgjobj.put("message", flag); } catch (JSONException ex) { throw ServiceException.FAILURE("appraisalFunction", ex); } catch (ParseException ex) { throw new JSONException("appraisalFunction"); // } catch (SessionExpiredException e) { // throw ServiceException.FAILURE(e.getMessage(), e); } catch (HibernateException ex) { throw new HibernateException("appraisalFunction"); } finally { } return msgjobj; }
From source file:com.krawler.spring.crm.emailMarketing.crmEmailMarketingDAOImpl.java
License:Open Source License
@Override public TargetListTargets saveTargetsForTemp(TargetList targetId, String rid, int rto, String fname, String lname, String email) { String hql = "from TargetListTargets t where t.targetlistid= ? and t.emailid=? and t.deleted=0 and t.relatedid= ?"; if (!executeQuery(hql, new Object[] { targetId, email, rid }).isEmpty()) { throw new HibernateException("Duplicate target in target list :" + email); }//from w ww .jav a 2 s . c o m TargetListTargets targetObj = new TargetListTargets(); targetObj.setFname(fname); targetObj.setLname(lname); targetObj.setEmailid(email); targetObj.setTargetlistid(targetId); targetObj.setDeleted(0); targetObj.setRelatedid(rid); targetObj.setRelatedto(rto); save(targetObj); return targetObj; }
From source file:com.l2jfree.loginserver.dao.impl.BaseRootDAOHib.java
License:Open Source License
public Session getCurrentSession() { if (__session == null) { if (getSessionFactory() == null) throw new HibernateException("Session Factory is null !"); return getSessionFactory().getCurrentSession(); } else {/* w ww. ja va2 s . c o m*/ if (__session.isOpen()) { return __session; } else { throw new HibernateException("Session is closed " + __session); } } }
From source file:com.liusoft.dlog4j.db.DataSourceConnectionProvider.java
License:Open Source License
public void close() throws HibernateException { if (dataSource != null) { try {//from w w w . j av a 2 s .com Method mClose = dataSource.getClass().getMethod("close"); mClose.invoke(dataSource); } catch (NoSuchMethodException e) { } catch (Exception e) { if (e.getCause() != null) throw new HibernateException(e.getCause()); else throw new HibernateException(e); } dataSource = null; } }
From source file:com.liusoft.dlog4j.db.DataSourceConnectionProvider.java
License:Open Source License
/** * Initialize the datasource/* www .j ava2 s . co m*/ * @param props * @throws HibernateException */ protected synchronized void initDataSource(Properties props) throws HibernateException { String dataSourceClass = null; Properties new_props = new Properties(); Iterator keys = props.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); //System.out.println(key+"="+props.getProperty(key)); if (ENCODING_KEY.equalsIgnoreCase(key)) { encoding = "true".equalsIgnoreCase(props.getProperty(key)); useProxy = true; } else if (DATASOURCE_KEY.equalsIgnoreCase(key)) { dataSourceClass = props.getProperty(key); } else if (key.startsWith(BASE_KEY)) { String value = props.getProperty(key); value = StringUtils.replace(value, "{DLOG4J}", Globals.WEBAPP_PATH); new_props.setProperty(key.substring(BASE_KEY.length()), value); } } if (dataSourceClass == null) throw new HibernateException("Property 'dscp.datasource' no defined."); try { dataSource = (DataSource) Class.forName(dataSourceClass).newInstance(); BeanUtils.populate(dataSource, new_props); } catch (Exception e) { throw new HibernateException(e); } }
From source file:com.manydesigns.portofino.database.StringBooleanType.java
License:Open Source License
protected Object parseBoolean(String value) { if (value != null) { if (value.trim().equalsIgnoreCase(trueString)) { return Boolean.TRUE; } else if (value.trim().equalsIgnoreCase(falseString)) { return Boolean.FALSE; } else {/*from www . j a v a 2s . c o m*/ throw new HibernateException("Invalid boolean value: " + value + "; possible values are " + trueString + ", " + falseString + ", null"); } } else { if (trueString == null) { return true; } else if (falseString == null) { return false; } else { return null; } } }
From source file:com.manydesigns.portofino.database.StringBooleanType.java
License:Open Source License
public void nullSafeSet(PreparedStatement statement, Object value, int index/*hb4, SessionImplementor sessionImplementor*/) throws HibernateException, SQLException { if (value == null) { if (trueString != null && falseString != null) { statement.setString(index, null); } else {//from w ww . j a v a 2s .c o m throw new HibernateException("Null is not supported as a boolean value for this type"); } } else { statement.setString(index, (Boolean) value ? trueString : falseString); } }
From source file:com.medigy.persist.model.data.EntitySeedDataPopulator.java
License:Open Source License
protected void populateCachedCustomReferenceEntities(final Class entityClass, final CachedCustomReferenceEntity[] cachedEntities, final String[] propertyList, final Object[][] data) throws HibernateException { try {/*from ww w .j a v a 2 s .co m*/ final Hashtable pdsByName = new Hashtable(); final BeanInfo beanInfo = Introspector.getBeanInfo(entityClass); final PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors(); for (int i = 0; i < descriptors.length; i++) { final PropertyDescriptor descriptor = descriptors[i]; if (descriptor.getWriteMethod() != null) pdsByName.put(descriptor.getName(), descriptor.getWriteMethod()); } Map entityMapByCache = new HashMap<CachedCustomReferenceEntity, Object>(); for (int i = 0; i < data.length; i++) { final Object entityObject = entityClass.newInstance(); for (int j = 0; j < propertyList.length; j++) { final Method setter = (Method) pdsByName.get(propertyList[j]); if (setter != null && data[i][j] != null) { if (data[i][j] instanceof CachedCustomHierarchyReferenceEntity) { setter.invoke(entityObject, new Object[] { entityMapByCache.get(data[i][j]) }); } else setter.invoke(entityObject, new Object[] { data[i][j] }); } } entityMapByCache.put(cachedEntities[i], entityObject); if (!useEjb) session.save(entityObject); else entityManager.persist(entityObject); cachedEntities[i].setEntity((CustomReferenceEntity) entityObject); } } catch (Exception e) { log.error(ExceptionUtils.getStackTrace(e)); throw new HibernateException(e); } }