Example usage for org.hibernate Query setLong

List of usage examples for org.hibernate Query setLong

Introduction

In this page you can find the example usage for org.hibernate Query setLong.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setLong(String name, long val) 

Source Link

Document

Bind a named long-valued parameter.

Usage

From source file:com.muslim.family.dao.impl.AnswerDAOImpl.java

public Answer_tbl getAnswerByQuestionIdDao(long questionId) {

    Query qry = sessionFactory.getCurrentSession()
            .createQuery("from Answer_tbl ans where ans.question.id = :questionId");
    qry.setLong("questionId", questionId);
    List<Answer_tbl> answerList = (List<Answer_tbl>) qry.list();
    Answer_tbl answer = null;/*w  w w.j a v  a2s . c  o  m*/

    if (answerList.isEmpty())
        return null;
    else
        return answerList.get(0);
}

From source file:com.netsteadfast.greenstep.base.dao.BaseDAO.java

License:Apache License

/**
 * for public QueryResult getList... doInHibernate
 * @param query       JPA-Style : from TB_ACCOUNT where account = ?0 
 * @param position   JPA-Style : "0", "1" .....
 * @param params/*from   w w w  .j a v a2s.  c om*/
 */
@SuppressWarnings("rawtypes")
private void setQueryParams(Query query, String position, Object params) {
    if (params instanceof java.lang.String) {
        query.setString(position, (java.lang.String) params);
        return;
    }
    if (params instanceof java.lang.Character) {
        query.setCharacter(position, (java.lang.Character) params);
        return;
    }
    if (params instanceof java.lang.Double) {
        query.setDouble(position, (java.lang.Double) params);
        return;
    }
    if (params instanceof java.lang.Byte) {
        query.setByte(position, (java.lang.Byte) params);
        return;
    }
    if (params instanceof java.lang.Integer) {
        query.setInteger(position, (java.lang.Integer) params);
        return;
    }
    if (params instanceof java.lang.Long) {
        query.setLong(position, (java.lang.Long) params);
        return;
    }
    if (params instanceof java.lang.Boolean) {
        query.setBoolean(position, (java.lang.Boolean) params);
        return;
    }
    if (params instanceof java.math.BigDecimal) {
        query.setBigDecimal(position, (java.math.BigDecimal) params);
        return;
    }
    if (params instanceof java.util.Date) {
        query.setDate(position, (java.util.Date) params);
        return;
    }
    if (params instanceof java.util.List) {
        List listParams = (List) params;
        this.setQueryParamsOfList(query, position, listParams);
        return;
    }
}

From source file:com.nominanuda.hibernate.AbstractHibernateStructStore.java

License:Apache License

protected void bind(Query q, String k, Object v) {
    DataType t = struct.getDataType(v);//from ww  w  .  java  2  s.c  o m
    switch (t) {
    case array:
        q.setParameterList(k, struct.toMapsAndSetLists((DataArray) v));
        break;
    case object:
        q.setEntity(k, struct.toMapsAndSetLists((DataObject) v));
        break;
    case string:
        q.setString(k, (String) v);
        break;
    case bool:
        q.setBoolean(k, (Boolean) v);
        break;
    case number:
        Double d = ((Number) v).doubleValue();
        if (Maths.isInteger(d)) {
            q.setLong(k, d.longValue());
        } else {
            q.setDouble(k, d);
        }
        break;
    default:
        throw new IllegalArgumentException(t.name());
    }
}

From source file:com.npower.dm.hibernate.management.ProfileAssignmentManagementBeanImpl.java

License:Open Source License

public void update(ProfileAssignment assignment) throws DMException {
    if (assignment == null) {
        throw new NullPointerException("Could not add a null ProfileAssignmentEntity into database.");
    }// ww  w .j a  v a2  s .  c o  m
    Session session = this.getHibernateSession();
    try {
        ProfileConfig profile = assignment.getProfileConfig();

        ProfileTemplate template = profile.getProfileTemplate();
        Device device = assignment.getDevice();
        Model model = device.getModel();

        ProfileMapping mapping = model.getProfileMap(template);
        if (mapping == null) {
            // TODO uncomments the following line, make sure the device had a ProfileMapping for this template.
            //throw new DMException("Could not assign the profile to this device, no ProfileMapping defined for this device.");
        }

        long id = assignment.getID();
        if (id == 0) {
            // is new!
            // Automaticly caculate assignIndex

            Query query = session.createQuery("select max(assignmentIndex) from ProfileAssignmentEntity "
                    + " where DEVICE_ID=? and PROFILE_ID=?");
            query.setLong(0, device.getID());
            query.setLong(1, profile.getID());

            Long assignmentIndex = (Long) query.uniqueResult();
            if (assignmentIndex == null) {
                assignment.setAssignmentIndex(1L);
            } else {
                assignment.setAssignmentIndex(assignmentIndex.longValue() + 1);
            }
        }

        // TODO checking this assignment before update(), make sure every attributes has been filled value and match the policy defined by ProfileTemplate
        session.saveOrUpdate(assignment);
    } catch (HibernateException e) {
        throw new DMException(e);
    } finally {
    }
}

From source file:com.onlinemart.dao.impl.SalesDAOImpl.java

@Override
public List<Sales> findSalesByOrderID(Long id) {
    Query query = getSession().createQuery("from Sales s where s.orderID=:oid");
    query.setLong("oid", id);

    return query.list();
}

From source file:com.opengamma.masterdb.batch.DbBatchWriter.java

License:Open Source License

public RiskRun getRiskRunById(final Long id) {
    return getHibernateTemplate().execute(new HibernateCallback<RiskRun>() {
        @Override//www.j a  v  a  2 s.co m
        public RiskRun doInHibernate(Session session) throws HibernateException, SQLException {
            Query query = session.getNamedQuery("RiskRun.one.byId");
            query.setLong("id", id);
            return (RiskRun) query.uniqueResult();
        }
    });
}

From source file:com.opengamma.masterdb.security.hibernate.HibernateSecurityMasterSession.java

License:Open Source License

@Override
public SecurityBean getSecurityBean(final ManageableSecurity base, SecurityBeanOperation<?, ?> beanOperation) {
    String beanType = beanOperation.getBeanClass().getSimpleName();
    Query query = getSession().getNamedQuery(beanType + ".one.bySecurityId");
    query.setLong("securityId", extractRowId(base.getUniqueId()));
    return (SecurityBean) query.uniqueResult();
}

From source file:com.openkm.extension.dao.ForumDAO.java

License:Open Source License

/**
 * Find by pk//from w w  w . j  av  a 2 s  . c om
 */
public static Forum findByPk(long id) throws DatabaseException {
    log.debug("findByPk({})");
    String qs = "from Forum frm where frm.id=:id";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setLong("id", id);
        Forum ret = (Forum) 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.MessageDAO.java

License:Open Source License

/**
 * Mark message as seen//  ww w .  ja va  2  s.  c o m
 */
public static void markSeen(long msgId) throws DatabaseException {
    log.debug("markSeen({})", msgId);
    String qs = "update MessageReceived msg set msg.seenDate=:seenDate where msg.id=:id";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setLong("id", msgId);
        q.setCalendar("seenDate", Calendar.getInstance());
        q.executeUpdate();
        log.debug("markSeen: void");
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.openkm.extension.dao.ProposedQueryDAO.java

License:Open Source License

/**
 * Mark proposed as seen/*from  www. ja va2 s.c om*/
 */
public static void markSeen(long pqId) throws DatabaseException {
    log.debug("markSeen({})", pqId);
    String qs = "update ProposedQueryReceived pq set pq.seenDate=:seenDate where pq.id=:id";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setLong("id", pqId);
        q.setCalendar("seenDate", Calendar.getInstance());
        q.executeUpdate();
        log.debug("markSeen: void");
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}