List of usage examples for org.hibernate Query setString
@Deprecated @SuppressWarnings("unchecked") default Query<R> setString(String name, String val)
From source file:com.edgenius.wiki.dao.hibernate.SpaceDAOHibernate.java
License:Open Source License
public int getSpaceCount(final String filter) { String filterWith = ""; if (!StringUtils.isBlank(filter)) { filterWith = " where s.name like :filter or s.unixName like :filter or s.description like :filter "; }/* w w w . j a v a2 s . c o m*/ Query query = getCurrentSesssion().createQuery(GET_SPACES_COUNT + filterWith); if (!StringUtils.isBlank(filter)) { query.setString("filter", "%" + filter.trim() + "%"); } List list = query.list(); if (list != null && list.size() > 0) { return (int) ((Long) list.get(0)).longValue(); } return 0; }
From source file:com.edgenius.wiki.dao.hibernate.SpaceDAOHibernate.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Space> getSpaces(final int start, final int returnSize, final String sortBy, final String filter, final boolean sortByDesc) { String orderBy = ""; String filterWith = ""; if (!StringUtils.isBlank(filter)) { filterWith = "where s.name like :filter or s.unixName like :filter or s.description like :filter "; }//from w w w . j ava 2s.c o m if (!StringUtils.isBlank(sortBy)) { StringBuffer orderSb = new StringBuffer(" order by "); String[] sortStr = sortBy.split("\\|"); String seq = (sortByDesc ? " desc" : " asc"); for (String str : sortStr) { int sort = NumberUtils.toInt(str, -1); if (sort == -1) continue; if (sort == Space.SORT_BY_PAGE_SCORE) orderSb.append("s.score ").append(seq).append(","); else if (sort == Space.SORT_BY_CREATEON) orderSb.append("s.createdDate ").append(seq).append(","); else if (sort == Space.SORT_BY_CREATEBY) orderSb.append("s.creator ").append(seq).append(","); else if (sort == Space.SORT_BY_SPACE_TITLE) orderSb.append("s.name ").append(seq).append(","); else if (sort == Space.SORT_BY_SPACEKEY) orderSb.append("s.unixName ").append(seq).append(","); } if (orderSb.length() > 0) { orderBy = orderSb.toString(); if (orderBy.endsWith(",")) { //remove last "," orderBy = orderBy.substring(0, orderBy.length() - 1); } } } else { //default order orderBy = " order by s.score desc, s.createdDate desc"; } Query query = getCurrentSesssion().createQuery(GET_SPACES + filterWith + orderBy); if (!StringUtils.isBlank(filter)) { query.setString("filter", "%" + filter.trim() + "%"); } query.setFirstResult(start); if (returnSize > 0) query.setMaxResults(returnSize); return query.list(); }
From source file:com.edgenius.wiki.dao.hibernate.SpaceDAOHibernate.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Space> getUserCreatedSpaces(final String username, final int limit) { Query query = getCurrentSesssion().createQuery(GET_USER_AUTHORED_SPACES); query.setString("name", username); if (limit > 0) query.setMaxResults(limit);/* www .j a v a2 s . c o m*/ return query.list(); }
From source file:com.edgenius.wiki.ext.calendar.dao.hibernate.CalendarEventDAOHibernate.java
License:Open Source License
@SuppressWarnings("unchecked") public List<CalendarEvent> getEvents(final String calName, final String pageUuid, final Date start, final Date end) { Query query = getCurrentSesssion().createQuery(GET_CALENDAR); query.setString("name", calName); query.setString("pageUuid", pageUuid); query.setDate("start", start); query.setDate("end", end); return query.list(); }
From source file:com.elearing.impl.UserDaoImpl.java
@Override public boolean update(User obj) { Session ses = HibernateUtil.getSessionFactory().openSession(); ses.beginTransaction();/*from ww w .j a v a 2 s. c om*/ String hql = "Update User set firstName= :fn , lastName= :ln , userEmail= :email , userPhone= :ph where userName= :un"; Query qr = ses.createQuery(hql); qr.setString("fn", obj.getFirstName()); qr.setString("ln", obj.getLastName()); qr.setString("email", obj.getUserEmail()); qr.setString("ph", obj.getUserPhone()); qr.setString("un", obj.getUserName()); qr.executeUpdate(); ses.getTransaction().commit(); ses.clear(); ses.close(); return true; //To change body of generated methods, choose Tools | Templates. }
From source file:com.elearing.impl.UserDaoImpl.java
public User getUserObject(String name, String pass) { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction();/*ww w. jav a 2s .c o m*/ Query query = session.createQuery("from User where userName =:ur and userPass =:pass"); query.setString("ur", name); query.setString("pass", pass); User user = (User) query.list().get(0); return user; }
From source file:com.elearing.impl.UserDaoImpl.java
public boolean getObjectByName(String name) { Session sessi = HibernateUtil.getSessionFactory().openSession(); sessi.beginTransaction();/* w w w .ja v a 2 s .c om*/ Query query = sessi.createQuery("from User where userName =:ur"); query.setString("ur", name); List list = query.list(); if (list.size() > 0) { return true; } else { return false; } }
From source file:com.elearing.impl.UserDaoImpl.java
public boolean getUserObjectOnNameAndPass(String name, String pass) { Session ss = HibernateUtil.getSessionFactory().openSession(); ss.beginTransaction();/* w w w.j a va 2s . c om*/ Query query = ss.createQuery("from User where userName =:ur and userPass =:pass"); query.setString("ur", name); query.setString("pass", pass); List list = query.list(); if (list.size() > 0) { return true; } else { return false; } }
From source file:com.elearing.impl.UserRoleDaoImpl.java
public UserRole getRole(String s) { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction();//ww w.j a va2 s . c o m Query query = session.createQuery("from UserRole where roleName =:name"); query.setString("name", s); UserRole userRole = (UserRole) query.list().get(0); session.clear(); session.close(); return userRole; }
From source file:com.enonic.cms.store.dao.ContentIndexEntityDao.java
License:Open Source License
public List<ContentKey> findContentKeysByQuery(final String hqlQuery, final Map<String, Object> parameters, final boolean cacheable) { return executeListResult(ContentKey.class, new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query compiled = session.createQuery(hqlQuery); compiled.setCacheable(cacheable); for (String key : parameters.keySet()) { Object value = parameters.get(key); if (value instanceof Date) { compiled.setTimestamp(key, (Date) value); } else if (value instanceof String) { compiled.setString(key, (String) value); } else if (value instanceof Boolean) { compiled.setBoolean(key, (Boolean) value); } else if (value instanceof Long) { compiled.setLong(key, (Long) value); } else if (value instanceof Integer) { compiled.setInteger(key, (Integer) value); } else if (value instanceof Byte) { compiled.setByte(key, (Byte) value); } else if (value instanceof byte[]) { compiled.setBinary(key, (byte[]) value); } else if (value instanceof Float) { compiled.setFloat(key, (Float) value); } else if (value instanceof Double) { compiled.setDouble(key, (Double) value); } else if (value instanceof BigDecimal) { compiled.setBigDecimal(key, (BigDecimal) value); } else if (value instanceof Short) { compiled.setShort(key, (Short) value); } else if (value instanceof BigInteger) { compiled.setBigInteger(key, (BigInteger) value); } else if (value instanceof Character) { compiled.setCharacter(key, (Character) value); } else { compiled.setParameter(key, value); }//from w ww. ja v a 2s . com } final List result = compiled.list(); LinkedHashSet<ContentKey> distinctContentKeySet = new LinkedHashSet<ContentKey>(result.size()); for (Object value : result) { if (value instanceof ContentKey) { distinctContentKeySet.add((ContentKey) value); } else { Object[] valueList = (Object[]) value; distinctContentKeySet.add(((ContentKey) valueList[0])); } } List<ContentKey> distinctContentKeyList = new ArrayList<ContentKey>(distinctContentKeySet.size()); distinctContentKeyList.addAll(distinctContentKeySet); return distinctContentKeyList; } }); }