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.abiquo.abiserver.persistence.dao.infrastructure.hibernate.PhysicalMachineDAOHibernate.java

License:Open Source License

@Override
public List<PhysicalmachineHB> getByRackAndVirtualDatacenter(final Integer idRack,
        final Integer idVirtualDatacenter, final Long hdRequiredOnDatastore, final EnterpriseHB enterprise) {

    // "(pm.ram - pm.ramUsed) >= " + vimage.getRamRequired() +
    // " and (pm.cpu - pm.cpuUsed) >= " + vimage.getCpuRequired();
    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
    Query pmQuery = session.getNamedQuery(FIRST_PASS_QUERY);

    pmQuery.setInteger("idVirtualDataCenter", idVirtualDatacenter);
    pmQuery.setInteger("idRack", idRack);
    pmQuery.setLong("hdRequiredOnRepository", hdRequiredOnDatastore);
    pmQuery.setParameter("enterprise", enterprise);

    return pmQuery.list();
}

From source file:com.abiquo.server.core.infrastructure.MachineDAO.java

License:Open Source License

public List<Machine> findCandidateMachines(final Integer idRack, final Integer idVirtualDatacenter,
        final Long hdRequiredOnDatastore, final Enterprise enterprise) {

    List<Machine> machines;

    if (enterprise.getIsReservationRestricted()) {
        machines = findFirstCandidateMachinesReservedRestricted(idRack, idVirtualDatacenter,
                hdRequiredOnDatastore, enterprise);
    } else {//from w  ww  .j ava2  s  .com
        machines = findFirstCandidateMachines(idRack, idVirtualDatacenter, hdRequiredOnDatastore, enterprise);
    }

    // StringBuilder sbcandidates = new StringBuilder();
    List<Integer> candidatesids = new LinkedList<Integer>();
    for (Machine m : machines) {
        candidatesids.add(m.getId());
    }

    // with datastore
    Query datastoreQuery = getSession().createQuery(QUERY_CANDIDATE_DATASTORE);
    datastoreQuery.setLong("hdRequiredOnRepository", hdRequiredOnDatastore);
    datastoreQuery.setParameterList("candidates", candidatesids);

    List<Integer> includedIds = datastoreQuery.list();

    if (includedIds.size() == 0) {
        throw new PersistenceException(String.format(
                "There isn't any machine with the required datastore capacity [%d]", hdRequiredOnDatastore));
    }

    // execute the enterprise exclusion rule
    Query excludedQuery = getSession().createQuery(QUERY_CANDIDATE_NO_ENTERPRISE_EXCLUDED);
    excludedQuery.setParameter("enterpriseId", enterprise.getId());
    List<Integer> excludedMachineIds = excludedQuery.list();

    List<Machine> notExcludedMachines = new LinkedList<Machine>();

    for (Machine m : machines) {
        Integer machineId = m.getId();

        if (!excludedMachineIds.contains(machineId) && includedIds.contains(machineId)) {
            notExcludedMachines.add(m);
        }
    }

    if (notExcludedMachines.size() == 0) {
        throw new PersistenceException("All the candiate machines are excluded by other enterprsies "
                + "with virtual machines deployed on it. Please check the enterprise affinity rules.");
    }

    return notExcludedMachines;
}

From source file:com.all.mobile.web.persistence.WidgetDao.java

License:Apache License

@SuppressWarnings("unchecked")
public List<MobileTrack> getPlaylist(final Long playlistId) {
    return hibernate.executeFind(new HibernateCallback<List<MobileTrack>>() {
        @Override/*from  ww  w  .  j  av a  2 s .c  o m*/
        public List<MobileTrack> doInHibernate(Session session) throws HibernateException, SQLException {
            Query query = session.createQuery("from WidgetContent w where w.widgetId=:playlistId");
            query.setLong("playlistId", playlistId);
            WidgetContent widgetContent = (WidgetContent) query.uniqueResult();
            return widgetContent.getPlaylist();
        }
    });
}

From source file:com.anite.zebra.hivemind.om.state.ZebraProcessInstance.java

License:Apache License

/**
 * returns a recursive list of processes that are children of this process
 * //from  www  . ja va 2  s. c  om
 * @return list of processes that are children of this process
 * @throws PersistenceException
 *             persistence exception
 * @throws HibernateException
 *             hibernate exception
 */
@Transient
public List<ZebraProcessInstance> getRunningChildProcesses() {

    List<ZebraProcessInstance> results = new ArrayList<ZebraProcessInstance>();

    String querySQL = "select api from ZebraProcessInstance api where api.parentProcessInstance.processInstanceId =:guid";
    querySQL += " and api.state=:state";

    Session s = RegistryHelper.getInstance().getSession();
    Query q = s.createQuery(querySQL);
    q.setCacheable(true);
    q.setLong("state", IProcessInstance.STATE_RUNNING);

    // Recursive Process children
    recursivelyQueryChildProcesses(results, q);
    return results;
}

From source file:com.anite.zebra.hivemind.om.state.ZebraProcessInstance.java

License:Apache License

@SuppressWarnings("unchecked")
@Transient//from ww w.j a va 2  s  .c o m
public List<ZebraProcessInstance> getRunningRelatedProcesses() {
    List<ZebraProcessInstance> results = new ArrayList<ZebraProcessInstance>();

    if (this.getRelatedKey() != null) {

        String querySQL = "select api from ZebraProcessInstance api where api.relatedClass =:relatedClass";
        querySQL += " and api.relatedKey = :relatedKey";
        querySQL += " and api.state=:state";

        Session s = RegistryHelper.getInstance().getSession();
        Query q = s.createQuery(querySQL);
        q.setCacheable(true);
        q.setParameter("relatedClass", this.getRelatedClass());
        q.setLong("relatedKey", this.getRelatedKey().longValue());
        q.setLong("state", IProcessInstance.STATE_RUNNING);
        results = q.list();
    }
    return results;
}

From source file:com.anite.zebra.hivemind.om.state.ZebraProcessInstance.java

License:Apache License

/**
 * Returns a list of all related processes that are complete
 * // w ww.  j a v  a2  s .c  o  m
 * @return list of processes that are children of this process
 * @throws PersistenceException
 *             persistence exception
 * @throws HibernateException
 *             hibernate exception
 */
@SuppressWarnings("unchecked")
@Transient
public List<ZebraProcessInstance> getCompleteRelatedProcesses() {
    List<ZebraProcessInstance> results = new ArrayList<ZebraProcessInstance>();
    if (this.getRelatedKey() != null) {

        String querySQL = "select api from ZebraProcessInstance api where api.relatedClass =:relatedClass";
        querySQL += " and api.relatedKey = :relatedKey";
        querySQL += " and api.state=:state";

        Session s = RegistryHelper.getInstance().getSession();
        Query q = s.createQuery(querySQL);
        q.setCacheable(true);
        q.setParameter("relatedClass", this.getRelatedClass());
        q.setParameter("relatedKey", this.getRelatedKey());
        q.setLong("state", IProcessInstance.STATE_COMPLETE);

        results = q.list();
    }
    return results;
}

From source file:com.anite.zebra.hivemind.om.state.ZebraProcessInstance.java

License:Apache License

/**
 * Get all child processes not running (e.g. complete and killed)
 * /*www.ja va  2 s .  com*/
 * @return
 * @throws PersistenceException
 * @throws HibernateException
 */
@Transient
public List<ZebraProcessInstance> getNotRunningChildProcesses() throws HibernateException {
    List<ZebraProcessInstance> results = new ArrayList<ZebraProcessInstance>();

    String querySQL = "select api from ZebraProcessInstance api where api.parentProcessInstance.processInstanceId =:guid";
    querySQL += " and api.state!=:state";

    Session s = RegistryHelper.getInstance().getSession();
    Query q = s.createQuery(querySQL);
    q.setLong("state", IProcessInstance.STATE_RUNNING);
    q.setCacheable(true);

    recursivelyQueryChildProcesses(results, q);
    return results;
}

From source file:com.anite.zebra.hivemind.om.state.ZebraProcessInstance.java

License:Apache License

/**
 * @param results/*from w  ww . java  2  s  . c o  m*/
 * @param q
 * @throws HibernateException
 */
@Transient
private void recursivelyQueryChildProcesses(List<ZebraProcessInstance> results, Query q)
        throws HibernateException {
    // Recursive Process children
    Stack<ZebraProcessInstance> checkList = new Stack<ZebraProcessInstance>();
    checkList.push(this);
    while (!checkList.isEmpty()) {
        ZebraProcessInstance processInstance = checkList.pop();
        q.setLong("guid", processInstance.getProcessInstanceId().longValue());
        for (Iterator it = q.iterate(); it.hasNext();) {
            ZebraProcessInstance childProcess = (ZebraProcessInstance) it.next();
            results.add(childProcess);
            checkList.push(childProcess);
        }
    }
}

From source file:com.appeligo.alerts.KeywordAlert.java

License:Apache License

@SuppressWarnings("unchecked")
public static KeywordAlert getByNormalizedQuery(User user, String query) {
    Permissions.checkUser(user);/*from  w  w w.  java2s .com*/
    Session session = getSession();
    Query hqlQuery = session.getNamedQuery("KeywordAlert.getByNormalizedQuery");
    hqlQuery.setLong("userId", user.getUserId());
    hqlQuery.setString("normalizedQuery", query);
    List<KeywordAlert> programAlerts = hqlQuery.list();
    if (programAlerts.size() > 0) {
        return programAlerts.get(0);
    } else {
        return null;
    }
}

From source file:com.appeligo.alerts.KeywordMatch.java

License:Apache License

public static KeywordMatch getKeywordMatch(long keywordAlertId, String programId) {
    Session session = getSession();/* ww  w  .j a  va 2 s. c om*/
    Query query = session.getNamedQuery("KeywordMatch.getKeywordMatch");
    query.setLong("keywordAlertId", keywordAlertId);
    query.setString("programId", programId);
    return (KeywordMatch) query.uniqueResult();
}