List of usage examples for org.hibernate Query setLong
@Deprecated @SuppressWarnings("unchecked") default Query<R> setLong(String name, long val)
From source file:com.openkm.extension.dao.ProposedQueryDAO.java
License:Open Source License
/** * Mark proposed as accepted/*from w w w .ja va 2s . c o m*/ */ public static void markAccepted(long pqId) throws DatabaseException { log.debug("markAccepted({})", pqId); String qs = "update ProposedQueryReceived ps set ps.accepted=:accepted where ps.id=:id"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); q.setLong("id", pqId); q.setBoolean("accepted", true); q.executeUpdate(); log.debug("markAccepted: void"); } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.openkm.extension.dao.StapleGroupDAO.java
License:Open Source License
/** * Find by pk//from ww w . ja v a 2 s. co m */ public static StapleGroup findByPk(long sgId) throws DatabaseException { log.debug("findByPk({})", sgId); String qs = "from StapleGroup sg where sg.id=:id"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); q.setLong("id", sgId); StapleGroup ret = (StapleGroup) q.setMaxResults(1).uniqueResult(); log.debug("findByPk: {}", ret); return ret; } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.openkm.extension.dao.WikiPageDAO.java
License:Open Source License
/** * Find by pk// w w w .j av a 2 s .c o m */ public static WikiPage findByPk(long id) throws DatabaseException { log.debug("findByPk({})", id); String qs = "from WikiPage wp where wp.id=:id"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); q.setLong("id", id); WikiPage ret = (WikiPage) q.setMaxResults(1).uniqueResult(); log.debug("findByPk: {}", ret); return ret; } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.qcadoo.model.internal.search.SearchQueryImpl.java
License:Open Source License
@Override public void addParameters(final Query query) { for (Map.Entry<String, String> parameter : strings.entrySet()) { query.setString(parameter.getKey(), parameter.getValue()); }/*from www . j av a 2s.c o m*/ for (Map.Entry<String, Boolean> parameter : booleans.entrySet()) { query.setBoolean(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Byte> parameter : bytes.entrySet()) { query.setByte(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Short> parameter : shorts.entrySet()) { query.setShort(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Integer> parameter : integers.entrySet()) { query.setInteger(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Long> parameter : longs.entrySet()) { query.setLong(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Float> parameter : floats.entrySet()) { query.setFloat(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Double> parameter : doubles.entrySet()) { query.setDouble(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, BigDecimal> parameter : bigDecimals.entrySet()) { query.setBigDecimal(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Date> parameter : dates.entrySet()) { query.setDate(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Date> parameter : times.entrySet()) { query.setTime(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Date> parameter : timestamps.entrySet()) { query.setTimestamp(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Object> parameter : parameters.entrySet()) { query.setParameter(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Collection<? extends Object>> parametersList : parameterLists.entrySet()) { query.setParameterList(parametersList.getKey(), parametersList.getValue()); } for (Map.Entry<String, Object> parameter : entities.entrySet()) { query.setEntity(parameter.getKey(), parameter.getValue()); } }
From source file:com.redhat.rhn.domain.config.ConfigurationFactory.java
License:Open Source License
/** * Finds a ConfigRevision for a given ConfigFile and given revision id * @param cf The ConfigFile to look for. * @param revId The ConfigFile revision to look for. * @return ConfigRevision The sought for ConfigRevision. *///from ww w. j a v a 2s. co m public static ConfigRevision lookupConfigRevisionByRevId(ConfigFile cf, Long revId) { Session session = HibernateFactory.getSession(); Query q = session.getNamedQuery("ConfigRevision.findByRevisionAndConfigFile"); q.setLong("rev", revId.longValue()); q.setEntity("cf", cf); return (ConfigRevision) q.uniqueResult(); }
From source file:com.redhat.rhn.domain.errata.ErrataFactory.java
License:Open Source License
/** * Lookup ErrataFiles by errata and file type * @param errataId errata id//from w w w . j a va 2 s .c o m * @param fileType file type label * @return list of ErrataFile instances */ public static List lookupErrataFilesByErrataAndFileType(Long errataId, String fileType) { Session session = null; List retval = null; try { session = HibernateFactory.getSession(); Query q = session.getNamedQuery("PublishedErrataFile.listByErrataAndFileType"); q.setLong("errata_id", errataId.longValue()); q.setString("file_type", fileType.toUpperCase()); retval = q.list(); if (retval == null) { q = session.getNamedQuery("UnpublishedErrataFile.listByErrataAndFileType"); q.setLong("errata_id", errataId.longValue()); q.setString("file_type", fileType.toUpperCase()); retval = q.list(); } } catch (HibernateException e) { throw new HibernateRuntimeException(e.getMessage(), e); } return retval; }
From source file:com.redhat.rhn.domain.kickstart.KickstartFactory.java
License:Open Source License
/** * Lookup KickstartableTree by tree id and org id * @param treeId desired tree// w w w.ja va2 s . c o m * @param org owning org * @return KickstartableTree if found, otherwise null */ public static KickstartableTree lookupKickstartTreeByIdAndOrg(Long treeId, Org org) { Session session = null; KickstartableTree retval = null; String queryName = "KickstartableTree.findByIdAndOrg"; if (treeId != null && org != null) { session = HibernateFactory.getSession(); Query query = session.getNamedQuery(queryName); query.setLong("org_id", org.getId().longValue()); query.setLong("tree_id", treeId.longValue()); //Retrieve from cache if there retval = (KickstartableTree) query.setCacheable(true).uniqueResult(); } return retval; }
From source file:com.redhat.rhn.domain.kickstart.KickstartFactory.java
License:Open Source License
/** * Verfies that a given kickstart tree can be used based on a channel id * and org id/*from www . j av a2 s . c om*/ * @param channelId base channel * @param orgId org * @param treeId kickstart tree * @return true if it can, false otherwise */ public static boolean verifyTreeAssignment(Long channelId, Long orgId, Long treeId) { Session session = null; boolean retval = false; if (channelId != null && orgId != null && treeId != null) { session = HibernateFactory.getSession(); Query query = session.getNamedQuery("KickstartableTree.verifyTreeAssignment"); query.setLong("channel_id", channelId.longValue()); query.setLong("org_id", orgId.longValue()); query.setLong("tree_id", treeId.longValue()); Object tree = query.uniqueResult(); retval = (tree != null); } return retval; }
From source file:com.redhat.rhn.domain.rhnpackage.profile.test.ProfileTest.java
License:Open Source License
public static void testCompatibleServer() throws Exception { // create a profile // create a channel // create a server // user and org User user = UserTestUtils.findNewUser("testUser", "testOrgCompatibleServer"); Server server = ServerFactoryTest.createTestServer(user); log.debug("CreateTest channel"); Channel channel = ChannelFactoryTest.createTestChannel(user); log.debug("Created test channel"); createTestProfile(user, channel);//from w w w . j a va 2 s. c o m Session session = HibernateFactory.getSession(); // gotta make sure the Channel gets saved. session.flush(); Query qry = session.getNamedQuery("Profile.compatibleWithServer"); qry.setLong("sid", server.getId().longValue()); qry.setLong("org_id", user.getOrg().getId().longValue()); List list = qry.list(); assertNotNull("List is null", list); assertFalse("List is empty", list.isEmpty()); for (Iterator itr = list.iterator(); itr.hasNext();) { Object o = itr.next(); assertEquals("Contains non Profile objects", Profile.class, o.getClass()); } }
From source file:com.salesmanager.core.service.order.impl.dao.OrderDao.java
License:Open Source License
public SearchOrderResponse searchInvoice(SearchOrdersCriteria searchCriteria) { Criteria criteria = super.getSession().createCriteria(Order.class) .add(Restrictions.eq("merchantId", searchCriteria.getMerchantId())) .add(Restrictions.eq("channel", OrderConstants.INVOICE_CHANNEL)) .add(Restrictions.eq("orderStatus", OrderConstants.STATUSINVOICED)) .addOrder(org.hibernate.criterion.Order.desc("orderId")) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); StringBuffer q = new StringBuffer(); q.append(" select o from Order o where o.merchantId=:mId"); q.append(" and channel=:channel and orderStatus=:status"); if (searchCriteria != null) { if (!StringUtils.isBlank(searchCriteria.getCustomerName())) { q.append(" and o.customerName like %:cName%"); }/*from w ww .j a v a2s .com*/ if (searchCriteria.getOrderId() != -1) { q.append(" and o.orderId=:oId"); } if (searchCriteria.getEdate() != null || searchCriteria.getSdate() != null) { if (searchCriteria.getSdate() != null) { q.append(" and o.datePurchased > :sDate"); } else { q.append(" and o.datePurchased > :sDate"); } if (searchCriteria.getEdate() != null) { q.append(" and o.datePurchased < :eDate"); } else { q.append(" and o.datePurchased < :eDate"); } } } q.append(" order by o.orderId desc"); Query c = super.getSession().createQuery(q.toString()); c.setInteger("channel", OrderConstants.INVOICE_CHANNEL); c.setInteger("status", OrderConstants.STATUSINVOICED); c.setInteger("mId", searchCriteria.getMerchantId()); if (searchCriteria != null) { if (!StringUtils.isBlank(searchCriteria.getCustomerName())) { criteria.add(Restrictions.like("customerName", "%" + searchCriteria.getCustomerName() + "%")); c.setString("cName", "%" + searchCriteria.getCustomerName() + "%"); } if (searchCriteria.getOrderId() != -1) { criteria.add(Restrictions.eq("orderId", searchCriteria.getOrderId())); c.setLong("oId", searchCriteria.getOrderId()); } if (searchCriteria.getEdate() != null || searchCriteria.getSdate() != null) { if (searchCriteria.getSdate() != null) { criteria.add(Restrictions.ge("datePurchased", searchCriteria.getSdate())); c.setDate("sDate", searchCriteria.getSdate()); } else { criteria.add(Restrictions.ge("datePurchased", DateUtils.addDays(new Date(), -1))); c.setDate("sDate", DateUtils.addDays(new Date(), -1)); } if (searchCriteria.getEdate() != null) { criteria.add(Restrictions.le("datePurchased", searchCriteria.getEdate())); c.setDate("eDate", searchCriteria.getEdate()); } else { criteria.add(Restrictions.ge("datePurchased", DateUtils.addDays(new Date(), +1))); c.setDate("eDate", DateUtils.addDays(new Date(), +1)); } } } criteria.setProjection(Projections.rowCount()); Integer count = (Integer) criteria.uniqueResult(); criteria.setProjection(null); int max = searchCriteria.getQuantity(); List list = null; if (max != -1 && count > 0) { list = c.setMaxResults(searchCriteria.getUpperLimit(count)) .setFirstResult(searchCriteria.getLowerLimit()).list(); } else { list = c.list(); } SearchOrderResponse response = new SearchOrderResponse(); response.setCount(count); response.setOrders(list); return response; }