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.dell.asm.asmcore.asmmanager.db.DeviceGroupDAO.java

License:Open Source License

/**
 * Update Device Group//from   w  w w  . j a v a 2s.  c  om
 * 
 * @return updateEntity - updated device group entity
 * 
 * @throws AsmManagerCheckedException
 */
public DeviceGroupEntity updateGroupDevice(DeviceGroupEntity updateEntity) throws AsmManagerCheckedException {

    if (updateEntity == null) {
        return null;
    }
    // Initialize locals.
    Session session = null;
    Transaction tx = null;
    DeviceGroupEntity entity = null;

    // Save the job history in the db.
    try {
        session = _dao._database.getNewSession();
        tx = session.beginTransaction();

        // Save the new DeviceGroupEntity.
        String hql = "from DeviceGroupEntity where seqId = :id";
        Query query = session.createQuery(hql);
        query.setLong("id", updateEntity.getSeqId());
        entity = (DeviceGroupEntity) query.setMaxResults(1).uniqueResult();

        if (null != entity) {

            if (null != updateEntity.getName() || !"".equals(updateEntity.getName()))
                entity.setName(updateEntity.getName());

            if (null != updateEntity.getDescription())
                entity.setDescription(updateEntity.getDescription());

            entity.setUpdatedBy(_dao.extractUserFromRequest());
            entity.setUpdatedDate(new GregorianCalendar());

            if (null != updateEntity.getDeviceInventories())
                entity.setDeviceInventories(updateEntity.getDeviceInventories());

            if (null != updateEntity.getGroupsUsers())
                entity.setGroupsUsers(updateEntity.getGroupsUsers());

            session.saveOrUpdate(entity);

            // Commit transaction and clean up.
            tx.commit();
        } else {
            throw new AsmManagerCheckedException(AsmManagerCheckedException.REASON_CODE.INVALID_REQUEST,
                    AsmManagerMessages.updateDeviceGroupError(String.valueOf(updateEntity.getSeqId())));
        }

    } catch (Exception e) {
        logger.warn("Caught exception during updating device group: " + e);
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception ex) {
            logger.warn("Unable to rollback transaction during updating device group: " + ex);
        }
        throw new AsmManagerCheckedException(AsmManagerCheckedException.REASON_CODE.INVALID_REQUEST,
                AsmManagerMessages.updateDeviceGroupError(String.valueOf(updateEntity.getSeqId())));
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex) {
            logger.warn("Unable to close session during updating device group: " + ex);
        }
    }
    return entity;
}

From source file:com.edgenius.core.dao.hibernate.CrWorkspaceDAOHibernate.java

License:Open Source License

public void updateWorkspacesQuota(final String spacename, final long size) {
    Query query = getCurrentSesssion().createQuery(UPDATE_SPACE_QUOTA);
    query.setLong(0, size);
    query.setString(1, spacename);//from  w  ww.  ja  v  a  2 s  . co  m
    query.executeUpdate();

}

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);
                }/*w w w. j  a  v a 2 s  . 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;
        }
    });
}

From source file:com.example.app.login.oneall.model.OneAllDAO.java

License:Open Source License

/**
 * Gets user token for principal./*w w  w  .ja v  a  2  s .co m*/
 *
 * @param principal the principal
 * @param provider the provider
 * @param domains the domains
 *
 * @return the user token for principal
 */
@Nullable
public String getUserTokenForPrincipal(Principal principal, String provider,
        @Nonnull AuthenticationDomainList domains) {
    final String queryString = "select cred from Principal p \n" + "inner join p.credentials cred \n"
            + "inner join p.authenticationDomains auth \n" + "where auth.id = :authId \n"
            + "and cred.openAuthType = :openAuthType \n" + "and p.id = :principalId \n"
            + "and cred.openAuthSubType = :openAuthSubType";
    return doInTransaction(session -> {
        Query query = getSession().createQuery(queryString);
        query.setParameter("openAuthType", OneAllLoginService.SERVICE_IDENTIFIER);
        query.setParameter("principalId", principal.getId());
        query.setParameter("openAuthSubType", provider);
        for (AuthenticationDomain ad : domains) {
            if (ad == null)
                continue;
            query.setLong("authId", ad.getId());
            OpenAuthCredentials creds = (OpenAuthCredentials) query.uniqueResult();
            if (creds != null)
                return creds.getOpenAuthId();
        }
        return null;
    });
}

From source file:com.exilant.eGov.src.domain.GeneralLedgerDetail.java

License:Open Source License

@Transactional
public void insert() throws SQLException {
    setId(String.valueOf(PrimaryKeyGenerator.getNextKey("GeneralLedgerDetail")));

    final String insertQuery = "INSERT INTO GeneralLedgerDetail (id, generalLedgerId, detailKeyId, detailTypeId,amount) "
            + "VALUES ( ?, ?, ?, ?, ?)";

    final Query pst = persistenceService.getSession().createSQLQuery(insertQuery);
    pst.setLong(0, Long.valueOf(id));
    pst.setLong(1, Long.valueOf(glId));
    pst.setLong(2, Long.valueOf(detailKeyId));
    pst.setLong(3, Long.valueOf(detailTypeId));
    pst.setBigDecimal(4, new BigDecimal(detailAmt));
    pst.executeUpdate();// w w w .ja  v a  2  s . com
    if (LOGGER.isInfoEnabled())
        LOGGER.info(insertQuery);
}

From source file:com.fiveamsolutions.nci.commons.audit.AuditLogRecordSearchCriteria.java

License:Open Source License

private Query helpBuildQuery(Session session, StringBuffer query, String orderByProperty) {
    if (id != null) {
        query.append(String.format(" %s.entityId = :entityId OR ", ROOT_ALIAS));
        query.append(String.format("  (ald in elements(%s.details) ", ROOT_ALIAS));
        query.append("    AND (ald.oldValue = :entityIdStr OR ald.newValue = :entityIdStr)) ");
    } else {/*  ww  w.  ja v  a2  s.c  o m*/
        query.append(String.format(" %s.transactionId in (:transactionIds) ", ROOT_ALIAS));
    }

    query.append(orderByProperty);
    Query q = session.createQuery(query.toString());

    if (id != null) {
        q.setLong("entityId", getId());
        q.setString("entityIdStr", Long.toString(getId()));
    } else {
        q.setParameterList("transactionIds", getTransactionId());
    }

    return q;
}

From source file:com.flipkart.flux.dao.StatesDAOImpl.java

License:Apache License

@Override
@Transactional/*ww  w  .ja  va 2  s .  c o m*/
public void updateStatus(Long stateId, Long stateMachineId, Status status) {
    Query query = currentSession().createQuery(
            "update State set status = :status where id = :stateId and stateMachineId = :stateMachineId");
    query.setString("status", status != null ? status.toString() : null);
    query.setLong("stateId", stateId);
    query.setLong("stateMachineId", stateMachineId);
    query.executeUpdate();
}

From source file:com.flipkart.flux.dao.StatesDAOImpl.java

License:Apache License

@Override
@Transactional// w w w.j ava2s .c  om
public void updateRollbackStatus(Long stateId, Long stateMachineId, Status rollbackStatus) {
    Query query = currentSession().createQuery(
            "update State set rollbackStatus = :rollbackStatus where id = :stateId and stateMachineId = :stateMachineId");
    query.setString("rollbackStatus", rollbackStatus != null ? rollbackStatus.toString() : null);
    query.setLong("stateId", stateId);
    query.setLong("stateMachineId", stateMachineId);
    query.executeUpdate();
}

From source file:com.flipkart.flux.dao.StatesDAOImpl.java

License:Apache License

@Override
@Transactional//from w w w .jav a2  s . c o m
public void incrementRetryCount(Long stateId, Long stateMachineId) {
    Query query = currentSession().createQuery(
            "update State set attemptedNoOfRetries = attemptedNoOfRetries + 1 where id = :stateId and stateMachineId = :stateMachineId");
    query.setLong("stateId", stateId);
    query.setLong("stateMachineId", stateMachineId);
    query.executeUpdate();
}

From source file:com.flipkart.flux.dao.StatesDAOImpl.java

License:Apache License

@Override
@Transactional/*from   w ww  . j  a  va  2 s .  c  o  m*/
@SelectDataSource(DataSourceType.READ_ONLY)
public List findErroredStates(String stateMachineName, Long fromStateMachineId, Long toStateMachineId) {
    Query query = currentSession().createQuery(
            "select state.stateMachineId, state.id, state.status from StateMachine sm join sm.states state "
                    + "where sm.id between :fromStateMachineId and :toStateMachineId and sm.name = :stateMachineName and state.status in ('errored', 'sidelined', 'cancelled')");

    query.setLong("fromStateMachineId", fromStateMachineId);
    query.setLong("toStateMachineId", toStateMachineId);
    query.setString("stateMachineName", stateMachineName);

    return query.list();
}