Example usage for org.hibernate Query setString

List of usage examples for org.hibernate Query setString

Introduction

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

Prototype

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

Source Link

Document

Bind a named String-valued parameter.

Usage

From source file:cn.effine.dao.OauthAccessTokenDaoImpl.java

@Override
public boolean deloAccessToken(String id) {
    String hql = "delete OauthAccessToken u where u.id = ?";
    Query query = sessionFactory.getCurrentSession().createQuery(hql);
    query.setString(0, id);
    return (query.executeUpdate() > 0);
}

From source file:cn.effine.dao.OauthAccessTokenDaoImpl.java

@Override
public OauthAccessToken getoAccessToken(String id) {
    String hql = "from OauthAccessToken u where u.id=?";
    Query query = sessionFactory.getCurrentSession().createQuery(hql);
    query.setString(0, id);
    return (OauthAccessToken) query.uniqueResult();
}

From source file:cn.trymore.core.dao.impl.DAOGenericImpl.java

License:Open Source License

public int execUpdateByHQL(final String hql, final Object[] params) throws DAOException {
    Query query = getSession().createQuery(hql);

    if (params != null) {
        for (int i = 0, len = params.length; i < len; i++) {
            query.setString(i, params[i].toString());
        }/*from w  w  w .j  a  v  a 2  s.c o m*/
    }

    return query.executeUpdate();

}

From source file:com.abiquo.abiserver.abicloudws.InfrastructureWS.java

License:Open Source License

@Override
public BasicResult forceRefreshVirtualMachineState(final VirtualMachine virtualMachine) {
    logger.info("Forcing refresh of the virtual machine state: {}", virtualMachine.getId());
    BasicResult result = new BasicResult();
    VirtualappHB virtualappHBPojo = null;
    Session session = null;/*from  w w  w . java  2  s .co  m*/
    Transaction transaction = null;
    try {
        session = HibernateUtil.getSession();
        transaction = session.beginTransaction();
        Query query = session.createSQLQuery(IDVIRTUALAPP_SQL_BY_VM);
        query.setString("id", virtualMachine.getId().toString());
        Integer virtualApplianceId = (Integer) query.uniqueResult();
        virtualappHBPojo = (VirtualappHB) session.get("VirtualappExtendedHB", virtualApplianceId);
        VirtualAppliance vapp = virtualappHBPojo.toPojo();
        String virtualSystemMonitorAddress = RemoteServiceUtils.getVirtualSystemMonitorFromVA(vapp);
        // EventingSupport.subscribePullEventToVM(virtualMachine, virtualSystemMonitorAddress);
    } catch (PersistenceException e) {
        logger.trace("An error occurred when retrieving the VirtualSystemMonitor", e.getStackTrace()[0]);
    } catch (RemoteServiceException e) {
        logger.trace("An error occurred when contacting the VirtualSystemMonitor", e.getStackTrace()[0]);
    }

    result.setSuccess(true);
    return result;
}

From source file:com.abiquo.abiserver.business.authentication.AuthenticationManagerDB.java

License:Open Source License

/**
 * gets a user from DB given the credentials.
 * /* www  .  j a  v  a  2  s .c  o  m*/
 * @param login The user credentials.
 * @param session The Hibernate session.
 * @return The user.
 */
private UserHB getUser(final Login login, final Session session) {
    // Checking if a user exists for the given credentials (remeber to check that the user
    String customQuery = "SELECT * FROM user WHERE user= :user AND password= :password";

    Query query = session.createSQLQuery(customQuery).addEntity(UserHB.class);
    query.setString("user", login.getUser());
    query.setString("password", login.getPassword());
    return (UserHB) query.uniqueResult();
}

From source file:com.abiquo.abiserver.business.authentication.AuthenticationManagerDB.java

License:Open Source License

/**
 * Gets the user from DB using the authentication Token information.
 * //from   w  w  w .jav  a 2  s .c o  m
 * @param login The object with the token information.
 * @param session The Hibernate session.
 * @return The user.
 */
private UserHB getUserUsingToken(final Login login, final Session session) throws Exception {
    // Get token data
    String[] token = TokenUtils.getTokenFields(login.getAuthToken());
    String tokenUser = TokenUtils.getTokenUser(token);
    long tokenExpiration = TokenUtils.getTokenExpiration(token);
    String tokenSignature = TokenUtils.getTokenSignature(token);

    // Check token expiration
    if (TokenUtils.isTokenExpired(tokenExpiration)) {
        throw new Exception("Authentication token has expired.");
    }

    // Get the token user from db
    String customQuery = "SELECT * FROM user WHERE user= :user";
    Query query = session.createSQLQuery(customQuery).addEntity(UserHB.class);
    query.setString("user", tokenUser);
    UserHB userHB = (UserHB) query.uniqueResult();

    if (userHB != null) {
        // Validate credentials with the token
        String signature = TokenUtils.makeTokenSignature(tokenExpiration, userHB.getUser(),
                userHB.getPassword());

        if (!signature.equals(tokenSignature)) {
            return null;
        }
    }

    return userHB;
}

From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.DataCenterDAOHibernate.java

License:Open Source License

@Override
public DatacenterHB findByName(final String name) throws PersistenceException {
    DatacenterHB datacenter;/*w  w w . ja va2  s.  c  o  m*/

    try {
        final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
        final Query query = session.getNamedQuery(GET_DATACENTER_BY_NAME);
        query.setString("name", name);
        datacenter = (DatacenterHB) query.uniqueResult();
    } catch (final NonUniqueResultException e) {
        // No datacenter found
        return null;
    } catch (final HibernateException he) {
        throw new PersistenceException(he.getMessage(), he);
    }

    return datacenter;
}

From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.DataCenterDAOHibernate.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from www . j av a 2  s . co m
public ArrayList<RackHB> getRacks(final Integer datacenterId, final String filters) {
    final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
    final Query query = session.getNamedQuery(GET_RACKS_BY_DATACENTER);
    query.setInteger("idDatacenter", datacenterId);
    query.setString("filterLike", filters == null || filters.isEmpty() ? "%" : "%" + filters + "%");

    return (ArrayList<RackHB>) query.list();
}

From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.HyperVisorDAOHibernate.java

License:Open Source License

@Override
public List<HypervisorType> getHypervisorsTypeByDataCenter(DatacenterHB datacenter)
        throws PersistenceException {
    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();

    try {//from  w w  w . ja  v a2s.co  m
        Query query = session.getNamedQuery(GET_HYPERTECH_FROM_DATACENTER);
        query.setString("idDataCenter", String.valueOf(datacenter.getIdDataCenter()));

        return query.list();

    } catch (HibernateException e) {
        throw new PersistenceException(e.getMessage(), e);
    }
}

From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.PhysicalMachineDAOHibernate.java

License:Open Source License

@Override
public PhysicalmachineHB findByIp(final String hypervisorIp, final Integer idDataCenter) {
    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();

    Query pmQuery = session.getNamedQuery(PHYSICALMACHINE_GET_FROM_IP);
    pmQuery.setString("ipPhysicalMachine", hypervisorIp);
    pmQuery.setInteger("idDataCenter", idDataCenter);

    PhysicalmachineHB pm = (PhysicalmachineHB) pmQuery.uniqueResult();

    return pm;// w w w.j av a  2s  . c om
}