List of usage examples for org.hibernate SQLQuery list
List<R> list();
From source file:com.isdemu.dao.impl.TB_Ubicacion_PersonaDaoImpl.java
@Override public List getAll() { System.out.println("ingresa al getAllInvPer"); Session session = null;/* w w w.jav a 2 s. co m*/ session = sessionFactory.getCurrentSession(); SQLQuery query = session.createSQLQuery( "select distinct p.ID_PERSONA, p.NOMBRE_PERSONA from [ActivosFijosISDEMU].[dbo].[TB_UBICACION_PERSONA] u\n" + " inner join [ActivosFijosISDEMU].[dbo].[TBC_PERSONA] p on u.ID_PERSONA=p.ID_PERSONA"); List mov = query.list(); return mov; }
From source file:com.iwancool.dsm.dao.impl.AbstractBaseGenericORMDaoImpl.java
License:Open Source License
@Override public List<Object[]> findBySql(String sql) { SQLQuery q = this.getCurrentSession().createSQLQuery(sql); return q.list(); }
From source file:com.iwancool.dsm.dao.impl.AbstractBaseGenericORMDaoImpl.java
License:Open Source License
@Override public List<Object[]> findBySql(String sql, Map<String, Object> params) { SQLQuery q = this.getCurrentSession().createSQLQuery(sql); if (params != null && !params.isEmpty()) { for (String key : params.keySet()) { q.setParameter(key, params.get(key)); }//w w w .j a v a 2 s. c o m } return q.list(); }
From source file:com.krawler.customFieldMaster.fieldManager.java
License:Open Source License
public ArrayList getFieldData(Session session, String module, String moduleRecId) { ArrayList returnList = new ArrayList(); String query1 = "show tables "; SQLQuery sql1 = session.createSQLQuery(query1); ArrayList l = new ArrayList(); l = (ArrayList) sql1.list(); if (!l.contains(module + "cstm")) { query1 = "CREATE TABLE `" + module + "cstm`(`modulerecid` varchar(36) NOT NULL,`fieldparamid` int(11) NOT NULL, `fieldvalue` varchar(255) NOT NULL, `fieldname` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; sql1 = session.createSQLQuery(query1); sql1.executeUpdate();//from w ww . j a v a 2 s .com } // String query = "SELECT `fieldname`,`fieldvalue`,`fieldtype` FROM " + module + "cstm where modulerecid = ?"; String query = "SELECT cm.fieldname,cm.fieldvalue,cm.fieldparamid, fp.fieldtype FROM " + module + "cstm as cm inner join fieldparams as fp on cm.fieldparamid = fp.id where modulerecid = ?"; SQLQuery sql = session.createSQLQuery(query); sql.setParameter(0, moduleRecId); returnList = (ArrayList) sql.list(); return returnList; }
From source file:com.krawler.customFieldMaster.fieldManager.java
License:Open Source License
public ArrayList getFieldName(Session session, String module, String moduleRecId) { ArrayList returnList = new ArrayList(); String query = "SELECT distinct `fieldname` FROM " + module + "cstm "; SQLQuery sql = session.createSQLQuery(query); returnList = (ArrayList) sql.list(); return returnList; }
From source file:com.krawler.customFieldMaster.fieldManager.java
License:Open Source License
public ArrayList getOnlyFieldName(Session session, HttpServletRequest request, String moduleId) throws SessionExpiredException, ServiceException { ArrayList returnList = new ArrayList(); try {/*ww w .j ava 2s . c o m*/ String companyid = AuthHandler.getCompanyid(request); String query = "SELECT distinct `fieldname` FROM fieldparams where moduleid=? and companyid = ?"; SQLQuery sql = session.createSQLQuery(query); sql.setParameter(0, moduleId); sql.setParameter(1, companyid); returnList = (ArrayList) sql.list(); } catch (Exception e) { throw ServiceException.FAILURE("fieldManager.getOnlyFieldName", e); } return returnList; }
From source file:com.krawler.customFieldMaster.fieldManager.java
License:Open Source License
public String customComboValue(Session session, String df) { String status = ""; if (df != null) { ArrayList returnList = new ArrayList(); String query = "SELECT `name` FROM fieldComboData where id = ?"; SQLQuery sql = session.createSQLQuery(query); sql.setParameter(0, df);/*from www . jav a 2 s . c o m*/ returnList = (ArrayList) sql.list(); Object[] item1 = returnList.toArray(); status = item1[0].toString(); } return status; }
From source file:com.krawler.customFieldMaster.fieldManager.java
License:Open Source License
public boolean storeCustomFields(JSONArray jarray, String modulename, boolean isNew, String modulerecid) { Session session = null;/*from w ww.j a va2s .c o m*/ Transaction tx = null; try { session = HibernateUtil.getCurrentSession(); tx = session.beginTransaction(); for (int i = 0; i < jarray.length(); i++) { try { JSONObject jobj = jarray.getJSONObject(i); Iterator ittr = jobj.keys(); String fieldid = ""; String fieldName = ""; String fieldValue = ""; while (ittr.hasNext()) { Object obj = ittr.next(); if (obj.toString().equals("filedid")) { fieldid = jobj.getString("filedid"); } else { fieldName = obj.toString(); } } String query1 = "show tables "; SQLQuery sql1 = session.createSQLQuery(query1); ArrayList l = new ArrayList(); l = (ArrayList) sql1.list(); if (!l.contains(modulename + "cstm")) { query1 = "CREATE TABLE `" + modulename + "cstm`(`modulerecid` varchar(36) NOT NULL,`fieldparamid` int(11) NOT NULL, `fieldvalue` varchar(255) NOT NULL, `fieldname` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; sql1 = session.createSQLQuery(query1); sql1.executeUpdate(); } fieldValue = jobj.getString(fieldName); String query = "SELECT modulerecid FROM " + modulename + "cstm where modulerecid = ? and fieldparamid = ?"; SQLQuery sql = session.createSQLQuery(query); sql.setParameter(0, modulerecid); sql.setParameter(1, fieldid); ArrayList list = (ArrayList) sql.list(); boolean recExists = false; if (list.size() > 0) { recExists = true; } if ((isNew || !recExists) && (!fieldValue.equals("undefined"))) { query = "insert into " + modulename + "cstm values(?,?,?,?)"; } else { query = "update " + modulename + "cstm set fieldvalue=? where modulerecid=? and fieldparamid = ?"; } sql = session.createSQLQuery(query); if ((isNew || !recExists) && (!fieldValue.equals("undefined"))) { sql.setParameter(0, modulerecid); sql.setParameter(1, fieldid); sql.setParameter(2, fieldValue); sql.setParameter(3, fieldName); } else { sql.setParameter(0, fieldValue); sql.setParameter(1, modulerecid); sql.setParameter(2, fieldid); } sql.executeUpdate(); } catch (Exception ex) { Logger.getLogger(fieldManager.class.getName()).log(Level.SEVERE, null, ex); } } } catch (Exception e) { if (tx != null) tx.rollback(); Logger.getLogger(fieldManager.class.getName()).log(Level.SEVERE, null, e); } finally { HibernateUtil.closeSession(session); } return true; }
From source file:com.krawler.customFieldMaster.fieldManager.java
License:Open Source License
public boolean storeCustomFields(JSONArray jarray, String modulename, boolean isNew, String modulerecid, ArrayList ll) {// w ww. ja v a 2s .c om Session session = null; Transaction tx = null; try { session = HibernateUtil.getCurrentSession(); tx = session.beginTransaction(); for (int i = 0; i < jarray.length(); i++) { try { JSONObject jobj = jarray.getJSONObject(i); Iterator ittr = jobj.keys(); String fieldid = ""; String fieldName = ""; String fieldValue = ""; while (ittr.hasNext()) { Object obj = ittr.next(); if (obj.toString().equals("filedid")) { fieldid = jobj.getString("filedid"); } else { fieldName = obj.toString(); } } String query1 = "show tables "; SQLQuery sql1 = session.createSQLQuery(query1); ArrayList l = new ArrayList(); l = (ArrayList) sql1.list(); if (!l.contains(modulename + "cstm")) { query1 = "CREATE TABLE `" + modulename + "cstm`(`modulerecid` varchar(36) NOT NULL,`fieldparamid` int(11) NOT NULL, `fieldvalue` varchar(255) NOT NULL, `fieldname` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; sql1 = session.createSQLQuery(query1); sql1.executeUpdate(); } fieldValue = jobj.getString(fieldName); String query = "SELECT modulerecid FROM " + modulename + "cstm where modulerecid = ? and fieldparamid = ?"; SQLQuery sql = session.createSQLQuery(query); sql.setParameter(0, modulerecid); sql.setParameter(1, fieldid); ArrayList list = (ArrayList) sql.list(); boolean recExists = false; if (list.size() > 0) { recExists = true; } for (int j = 0; j < ll.size(); j++) { Object[] temp = (Object[]) ll.get(j); if ((isNew || !recExists) && (temp[0].toString().equals(fieldName))) { query = "insert into " + modulename + "cstm values(?,?,?,?)"; sql = session.createSQLQuery(query); sql.setParameter(0, modulerecid); sql.setParameter(1, fieldid); sql.setParameter(2, fieldValue); sql.setParameter(3, fieldName); sql.executeUpdate(); } } } catch (Exception ex) { Logger.getLogger(fieldManager.class.getName()).log(Level.SEVERE, null, ex); } } } catch (Exception e) { if (tx != null) tx.rollback(); Logger.getLogger(fieldManager.class.getName()).log(Level.SEVERE, null, e); } finally { HibernateUtil.closeSession(session); } return true; }
From source file:com.krawler.customFieldMaster.fieldManager.java
License:Open Source License
public String createNewField(String fieldlabel, int isessential, int maxlength, int validationtype, int fieldtype, int moduleid, String customregex, String companyid, String combodata, String formulae, String iseditable, HttpServletRequest request) { int result = 0; String msg = ""; Session session = null;/*w w w . java 2s.co m*/ try { String query = "insert into fieldparams(moduleid,fieldname,fieldlabel,isessential,maxlength,validationtype,fieldtype,customregex,companyid,iseditable) values(?,?,?,?,?,?,?,?,?,?)"; session = HibernateUtil.getCurrentSession(); Transaction tx = session.beginTransaction(); SQLQuery sql = session.createSQLQuery(query); sql.setParameter(0, moduleid); sql.setParameter(1, fieldlabel.replaceAll(" ", "_")); sql.setParameter(2, fieldlabel); sql.setParameter(3, isessential); sql.setParameter(4, maxlength); sql.setParameter(5, validationtype); sql.setParameter(6, fieldtype); sql.setParameter(7, StringUtil.checkForNull(customregex)); sql.setParameter(8, companyid); sql.setParameter(9, iseditable); result = sql.executeUpdate(); tx.commit(); if (!StringUtil.isNullOrEmpty(combodata)) { String[] combovalues = combodata.split(";"); query = "SELECT max(id) as fieldid from fieldparams"; SQLQuery sql1 = session.createSQLQuery(query); int fieldid = 0; ArrayList list = (ArrayList) sql1.list(); if (list.size() > 0) { fieldid = Integer.parseInt(list.get(0).toString()); } for (int cnt = 0; cnt < combovalues.length; cnt++) { if (!StringUtil.isNullOrEmpty(combovalues[cnt])) { tx = session.beginTransaction(); query = "insert into fieldComboData(name,fieldid) values(?,?)"; SQLQuery sql2 = session.createSQLQuery(query); sql2.setParameter(0, combovalues[cnt]); sql2.setParameter(1, fieldid); sql2.executeUpdate(); tx.commit(); } } } if (!StringUtil.isNullOrEmpty(formulae)) { tx = session.beginTransaction(); setCustomColumnFormulae(session, request); tx.commit(); } } catch (ConstraintViolationException e) { msg = messageSource.getMessage("hrms.commonlib.new.custom.column.created", null, RequestContextUtils.getLocale(request)); } catch (Exception e) { msg = messageSource.getMessage("hrms.commonlib.new.custom.column.cannot.created", null, RequestContextUtils.getLocale(request)); } finally { HibernateUtil.closeSession(session); } if (result == 1) { msg = messageSource.getMessage("hrms.commonlib.new.custom.column.created", null, RequestContextUtils.getLocale(request)); return msg; } else { if (StringUtil.isNullOrEmpty(msg)) { msg = messageSource.getMessage("hrms.commonlib.new.custom.column.cannot.created", null, RequestContextUtils.getLocale(request)); } return msg; } }