List of usage examples for org.hibernate Query setInteger
@Deprecated @SuppressWarnings("unchecked") default Query<R> setInteger(String name, int val)
From source file:com.edgenius.wiki.dao.hibernate.ActivityLogDAOHibernate.java
License:Open Source License
@SuppressWarnings("unchecked") public List<ActivityLog> getByUser(final int start, final int count, final User user) { Query query; if (user == null || user.isAnonymous()) { query = getCurrentSesssion().createQuery(GET_BY_ANONYMOUS_COUNT); } else {// ww w . j a v a 2 s . c o m query = getCurrentSesssion().createQuery(GET_BY_USER_COUNT); query.setInteger("user", user.getUid()); } if (start > 0) query.setFirstResult(start); if (count > 0) query.setMaxResults(count); return query.list(); }
From source file:com.edgenius.wiki.dao.hibernate.HistoryDAOHibernate.java
License:Open Source License
@SuppressWarnings("unchecked") public List<History> getByUuid(final String uuid, final int startVer, final int returnCount, final Date touchedDate) { Query query; if (touchedDate == null) { query = getCurrentSesssion().createQuery(GET_HISTORY_BY_UUID); query.setString(0, uuid);/*w w w . j av a 2 s . c om*/ query.setInteger(1, startVer <= 0 ? Integer.MAX_VALUE : startVer); } else { query = getCurrentSesssion().createQuery(GET_HISTORY_BY_UUID_OLDER_DATE); query.setString(0, uuid); query.setDate(1, touchedDate); query.setInteger(2, startVer <= 0 ? Integer.MAX_VALUE : startVer); } if (returnCount > 0) { query.setMaxResults(returnCount); } return query.list(); }
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); }/* www .j a va2 s . c o m*/ } 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; } }); }
From source file:com.enonic.cms.store.dao.GroupEntityDao.java
License:Open Source License
public List<GroupEntity> findBySpecification(GroupSpecification spec) { String hqlQuery = createHqlQuery(spec); Query compiled = getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery(hqlQuery); compiled.setCacheable(true);//from ww w .ja va 2 s. co m if (spec.getKey() != null) { compiled.setString("key", spec.getKey().toString()); } if (spec.getName() != null) { compiled.setString("name", spec.getName()); } if (spec.getSyncValue() != null) { compiled.setString("syncValue", spec.getSyncValue()); } if (spec.getUserStoreKey() != null) { compiled.setInteger("userStoreKey", spec.getUserStoreKey().toInt()); } if (spec.getType() != null) { compiled.setInteger("type", spec.getType().toInteger()); } return compiled.list(); }
From source file:com.enonic.cms.store.dao.SiteEntityDao.java
License:Open Source License
public List<SiteEntity> findByPublishPossible(final int contentTypeKey, final UserEntity user) { return executeListResult(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { StringBuffer hql = new StringBuffer(); SelectBuilder sites = new SelectBuilder(hql, 0); sites.addSelect("sit"); sites.addFromTable(SiteEntity.class.getName(), "sit", SelectBuilder.NO_JOIN, null); SelectBuilder mei = new SelectBuilder(3); mei.addSelect("mei.key"); mei.addFromTable(MenuItemEntity.class.getName(), "mei", SelectBuilder.NO_JOIN, null); mei.append("left outer join mei.page.template pat"); mei.addFilter("AND", "mei.site.key = sit.key"); mei.addFilter("AND", "( mei.menuItemType = 6 or pat.type = 6 )"); mei.addFilter("AND", "( mei.section = 1 )"); SelectBuilder sctf = new SelectBuilder(9); sctf.addSelect("sctf.key"); sctf.addFromTable(SectionContentTypeFilterEntity.class.getName(), "sctf", SelectBuilder.NO_JOIN, null);/*from w w w .ja va 2 s.co m*/ sctf.addFilter("AND", "sctf.contentType.key = :contentTypeKey"); sctf.addFilter("AND", "sctf.section.key = mei.key"); mei.addFilter("AND", "exists (" + sctf.toString() + ")"); if (!user.isEnterpriseAdmin()) { Collection<String> groupKeys = resolveUsersAllGroupMemberships(user); if (groupKeys.isEmpty()) { return new ArrayList<SiteEntity>(); } else { SelectBuilder mia = new SelectBuilder(6); mia.addSelect("mia.key.menuItemKey"); mia.addFromTable(MenuItemAccessEntity.class.getName(), "mia", SelectBuilder.NO_JOIN, null); mia.addFilter("AND", "mia.addAccess = 1"); mia.addFilter("AND", "mia.key.menuItemKey = mei.key"); mia.addFilter("AND", new InClauseBuilder<String>("mia.key.groupKey", groupKeys) { public void appendValue(StringBuffer sql, String value) { sql.append("'").append(value).append("'"); } }.toString()); mei.addFilter("AND", "exists (" + mia.toString() + ")"); } } sites.addFilter("AND", "exists (" + mei.toString() + ")"); Query compiled = session.createQuery(hql.toString()); compiled.setCacheable(false); compiled.setInteger("contentTypeKey", contentTypeKey); return compiled.list(); } }); }
From source file:com.enonic.cms.store.dao.UserEntityDao.java
License:Open Source License
public List<UserEntity> findBySpecification(final UserSpecification spec) { String hqlQuery = createHqlQuery(spec); Query compiled = getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery(hqlQuery); compiled.setCacheable(true);//from w ww .ja v a 2 s . c o m if (spec.getKey() != null) { compiled.setParameter("key", spec.getKey()); } if (spec.getName() != null) { compiled.setString("name", spec.getName().toLowerCase()); } if (spec.getSyncValue() != null) { compiled.setString("syncValue", spec.getSyncValue()); } if (spec.getUserStoreKey() != null) { compiled.setInteger("userStoreKey", spec.getUserStoreKey().toInt()); } if (spec.getType() != null) { compiled.setInteger("type", spec.getType().getKey()); } if (spec.getUserGroupKey() != null) { compiled.setString("userGroupKey", spec.getUserGroupKey().toString()); } if (spec.getEmail() != null) { compiled.setString("email", spec.getEmail().toLowerCase()); } return compiled.list(); }
From source file:com.enonic.cms.store.dao.UserEntityDao.java
License:Open Source License
public List<UserEntity> findByUserStoreKey(final UserStoreKey userStoreKey, final Integer index, final Integer count, final boolean includeDeleted) { return executeListResult(UserEntity.class, new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.getNamedQuery("UserEntity.findByUserStoreKey"); if (index != null) { query.setFirstResult(index); }/*w w w.ja v a 2 s . c om*/ query.setInteger("userStoreKey", userStoreKey.toInt()); query.setInteger("deleted", includeDeleted ? 1 : 0); List list = query.list(); if (count == null) { return list; } else { return list.subList(0, Math.min(count, list.size())); } } }); }
From source file:com.enonic.vertical.engine.handlers.KeyHandler.java
License:Open Source License
private int insertCurrentKey(final String tableName, final int key) { final Query query = getSession().createSQLQuery(KEY_INSERT); query.setString("table", tableName.toLowerCase()); query.setInteger("key", key); query.executeUpdate();//from www.ja va 2s.c om return key; }
From source file:com.escom.dao.ArticuloDao.java
@Override public Articulo getArticuloById(int idArticulo) throws RemoteException { Articulo articulo = null;/* w ww. j a v a 2 s . co m*/ Transaction trns = null; Session session = HibernateUtil.getSessionFactory().openSession(); try { trns = session.beginTransaction(); String queryString = "from Articulo where idarticulo= :id "; Query query = session.createQuery(queryString); query.setInteger("id", idArticulo); articulo = (Articulo) query.uniqueResult(); } catch (HibernateException e) { System.out.println(e.toString()); } finally { session.close(); } return articulo; }
From source file:com.estampate.corteI.DAO.datosGeneralesDAO.java
public Artista getArtista(int idArtista) { Artista artista = new Artista(); tx = session.beginTransaction();/*w ww. j ava 2 s .co m*/ String msg = ""; try { String hql = "from Artista a where a.idArtista = :idArtista"; Query q = session.createQuery(hql); q.setInteger("idArtista", idArtista); artista = (Artista) q.uniqueResult(); if (!tx.wasCommitted()) tx.commit(); } catch (Exception e) { msg = e.getMessage(); e.printStackTrace(); } return artista; }