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

License:Open Source License

@Override
public List<PhysicalmachineHB> getPhysicalMachineByRack(final Integer rackId, final String filters) {
    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();

    String namedQuery = filters == null || filters.isEmpty() ? PHYSICALMACHINE_GET_LIST_BY_RACK
            : "PHYSICALMACHINE.GET_LIST_BY_RACK_AND_ENTERPRISE";

    Query pmQuery = session.getNamedQuery(namedQuery);
    pmQuery.setInteger("idRack", rackId);
    if (filters != null && !filters.isEmpty()) {
        pmQuery.setString("filterLike", "%" + filters + "%");
    }/*from  w w w. ja v a  2  s.c  o m*/

    return pmQuery.list();
}

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

License:Open Source License

@Override
public List<RemoteServiceHB> getRemoteServicesByUrl(String uri) {
    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();

    Query pmQuery = session.getNamedQuery(REMOTE_SERVICE_GET_REMOTE_SERVICES_BY_URL);
    pmQuery.setString("uri", uri);

    return pmQuery.list();
}

From source file:com.abiquo.abiserver.persistence.dao.networking.hibernate.NetworkDAOHibernate.java

License:Open Source License

@Override
public VlanNetworkHB findVlanWithName(Integer networkId, String vlanNetworkName) throws PersistenceException {
    VlanNetworkHB namedVLAN;//from w ww.  j  a va 2s . c  o m

    try {
        Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
        Query query = session.getNamedQuery(GET_VLAN_WITH_NAME_BY_NETWORK_ID);
        query.setInteger("network_id", networkId);
        query.setString("vlan_network_name", vlanNetworkName);

        namedVLAN = (VlanNetworkHB) query.uniqueResult();

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

    return namedVLAN;
}

From source file:com.abiquo.abiserver.persistence.dao.networking.hibernate.VlanNetworkDAOHibernate.java

License:Open Source License

@Override
public IpPoolManagementHB getNextAvailableIp(final Integer vlanNetworkId, final String gateway)
        throws PersistenceException {
    try {//w ww .j a  v  a2s.c  o  m
        Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
        Query query = session.getNamedQuery(VLAN_GET_AVAILABLE_IP_MANAGEMENT);
        query.setInteger("vlanNetworkId", vlanNetworkId);
        query.setString("gateway", gateway);

        if (query.list().size() > 0) {
            return (IpPoolManagementHB) query.list().get(0);
        } else {
            return null;
        }
    } catch (HibernateException e) {
        throw new PersistenceException(e.getMessage(), e);
    }

}

From source file:com.abiquo.abiserver.persistence.dao.user.hibernate.RoleDAOHibernate.java

License:Open Source License

@Override
public RoleHB getRoleByName(final String name) {
    RoleHB requestedRol = new RoleHB();

    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
    Query userQuery = session.getNamedQuery(GET_ROLE_BY_NAME);
    userQuery.setString("name", name);
    requestedRol = (RoleHB) userQuery.uniqueResult();

    return requestedRol;
}

From source file:com.abiquo.abiserver.persistence.dao.user.hibernate.UserDAOHibernate.java

License:Open Source License

/**
 * @see com.abiquo.abiserver.persistence.dao.user.UserDAO#getUserByLoginAuth(java.lang.String,
 *      com.abiquo.server.core.enterprise.User.AuthType)
 *//*w w  w.  jav a  2 s.  co m*/
@Override
public UserHB getUserByLoginAuth(final String username, String authType) {
    UserHB requestedUser = new UserHB();

    if (authType == null) {
        authType = AuthType.ABIQUO.name();
    }
    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
    Query userQuery = session.getNamedQuery(GET_USER_BY_USER_NAME);
    userQuery.setString("username", username);
    userQuery.setString("authType", authType);
    requestedUser = (UserHB) userQuery.uniqueResult();
    return requestedUser;
}

From source file:com.abiquo.abiserver.persistence.dao.user.hibernate.UserDAOHibernate.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*ww  w.  j  av  a2  s  .c o  m*/
public List<UserHB> getUsersByUserPrivileges(final String privilege, final Integer enterprise) {
    List<UserHB> requestedUser = new ArrayList<UserHB>();

    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
    Query userQuery = session.getNamedQuery(GET_USERS_BY_PRIVILEGE);
    userQuery.setString("privilege", privilege);
    userQuery.setInteger("enterprise", enterprise);
    requestedUser = userQuery.list();

    return requestedUser;
}

From source file:com.abiquo.abiserver.persistence.dao.user.hibernate.UserDAOHibernate.java

License:Open Source License

@Override
public Object[] getCurrentUserCredentials(String user, String auth) {
    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
    Query query = session
            .createSQLQuery("select user, password from user where user = :name and authType = :auth");
    query.setString("name", user);
    query.setString("auth", auth);

    return (Object[]) query.uniqueResult();
}

From source file:com.abiquo.abiserver.persistence.dao.virtualappliance.hibernate.VirtualApplianceDAOHibernate.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
// generic Hibernate query list cast
public List<VirtualappHB> findByUsingVirtualImage(final String virtualImageId) throws PersistenceException {
    List<VirtualappHB> apps;

    try {/*from w  w  w. j  a  va  2s .  co m*/
        Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
        Query query = session.getNamedQuery(FIND_BY_USED_VIRTUAL_IMAGE);
        query.setString("usedVIId", virtualImageId);
        query.setParameter("type", NodeTypeEnum.VIRTUAL_IMAGE);

        apps = query.list();
    } catch (HibernateException e) {
        throw new PersistenceException(e.getMessage(), e);
    }

    return apps;
}

From source file:com.abiquo.abiserver.persistence.dao.virtualappliance.hibernate.VirtualMachineDAOHibernate.java

License:Open Source License

@Override
public List<VirtualmachineHB> findByNameTruncated(String name) throws PersistenceException {
    List<VirtualmachineHB> vmHB;

    try {/*from   w  w  w. ja  va2s. c  o  m*/
        Query query = getSession().createQuery(VIRTUAL_MACHINE_SEARCH_BY_NAME_TRUNCATED);
        query.setString("name", name);

        vmHB = (List<VirtualmachineHB>) query.list();
    } catch (HibernateException e) {
        throw new PersistenceException(e.getMessage(), e);
    }

    return vmHB;
}