Example usage for org.hibernate Query getQueryString

List of usage examples for org.hibernate Query getQueryString

Introduction

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

Prototype

String getQueryString();

Source Link

Document

Get the query string.

Usage

From source file:com.abiquo.server.core.cloud.VirtualMachineDAO.java

License:Open Source License

public List<VirtualMachine> findVirtualMachinesByVirtualAppliance(final Integer vappId, Integer startwith,
        Integer limit, final String filter, final OrderByEnum orderby, final boolean asc) {
    // List<VirtualMachine> vmList = null;

    // TypedQuery<VirtualMachine> query =
    // getEntityManager().createNamedQuery("VIRTUAL_MACHINE.BY_VAPP", VirtualMachine.class);
    // query.setParameter("vapp_id", vappId);
    // vmList = query.getResultList();
    String orderBy = defineOrderBy(orderby.getColumnHQL(), asc);
    Query query = getSession().getNamedQuery("VIRTUAL_MACHINE.BY_VAPP");

    String req = query.getQueryString() + orderBy;
    // Add order filter to the query
    Query queryWithOrder = getSession().createQuery(req);
    queryWithOrder.setInteger("vapp_id", vappId);
    queryWithOrder.setString("filterLike", filter.isEmpty() ? "%" : "%" + filter + "%");

    Integer size = queryWithOrder.list().size();

    // Limit 0 means no size filter
    if (limit == 0) {
        limit = size;//w  ww .ja  v  a2s . c  o  m
        startwith = 0;
    }

    queryWithOrder.setFirstResult(startwith);
    queryWithOrder.setMaxResults(limit);

    PagedList<VirtualMachine> vmList = new PagedList<VirtualMachine>(queryWithOrder.list());
    vmList.setTotalResults(size);
    vmList.setPageSize(limit > size ? size : limit);
    vmList.setCurrentElement(startwith);

    return vmList;
}

From source file:com.abiquo.server.core.infrastructure.storage.VolumeManagementDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<VolumeManagement> getVolumesByPool(final StoragePool sp, final FilterOptions filters) {
    // Check if the orderBy element is actually one of the available ones
    VolumeManagement.OrderByEnum orderByEnum = VolumeManagement.OrderByEnum
            .valueOf(filters.getOrderBy().toUpperCase());

    String orderBy = defineOrderBy(orderByEnum.getColumnHQL(), filters.getAsc());

    Query query = getSession().getNamedQuery(VolumeManagement.VOLUMES_BY_POOL);

    String req = query.getQueryString() + orderBy;
    // Add order filter to the query
    Query queryWithOrder = getSession().createQuery(req);
    queryWithOrder.setString("poolId", sp.getId());
    queryWithOrder.setString("filterLike",
            filters.getFilter().isEmpty() ? "%" : "%" + filters.getFilter() + "%");

    Integer size = queryWithOrder.list().size();

    queryWithOrder.setFirstResult(filters.getStartwith());
    queryWithOrder.setMaxResults(filters.getLimit());

    PagedList<VolumeManagement> volumesList = new PagedList<VolumeManagement>(queryWithOrder.list());
    volumesList.setTotalResults(size);//w  w  w . ja v a2s . co  m
    volumesList.setPageSize(filters.getLimit() > size ? size : filters.getLimit());
    volumesList.setCurrentElement(filters.getStartwith());

    return volumesList;
}

From source file:com.abiquo.server.core.infrastructure.storage.VolumeManagementDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<VolumeManagement> getVolumesByVirtualDatacenter(final VirtualDatacenter vdc,
        final FilterOptions filters) {
    // Check if the orderBy element is actually one of the available ones
    VolumeManagement.OrderByEnum orderByEnum = VolumeManagement.OrderByEnum
            .valueOf(filters.getOrderBy().toUpperCase());

    String orderBy = defineOrderBy(orderByEnum.getColumnHQL(), filters.getAsc());

    Query query = getSession().getNamedQuery(VolumeManagement.VOLUMES_BY_VDC);

    String req = query.getQueryString() + orderBy;
    // Add order filter to the query
    Query queryWithOrder = getSession().createQuery(req);
    queryWithOrder.setInteger("vdcId", vdc.getId());
    queryWithOrder.setString("filterLike",
            filters.getFilter().isEmpty() ? "%" : "%" + filters.getFilter() + "%");

    Integer size = queryWithOrder.list().size();

    queryWithOrder.setFirstResult(filters.getStartwith());
    queryWithOrder.setMaxResults(filters.getLimit());

    PagedList<VolumeManagement> volumesList = new PagedList<VolumeManagement>(queryWithOrder.list());
    volumesList.setTotalResults(size);/*from   w w w.  j av a 2  s .c om*/
    volumesList.setPageSize(filters.getLimit() > size ? size : filters.getLimit());
    volumesList.setCurrentElement(filters.getStartwith());

    return volumesList;
}

From source file:com.abiquo.server.core.infrastructure.storage.VolumeManagementDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<VolumeManagement> getAvailableVolumes(final VirtualDatacenter vdc, final FilterOptions filters) {
    // Check if the orderBy element is actually one of the available ones
    VolumeManagement.OrderByEnum orderByEnum = VolumeManagement.OrderByEnum
            .valueOf(filters.getOrderBy().toUpperCase());

    String orderBy = defineOrderBy(orderByEnum.getColumnHQL(), filters.getAsc());

    Query query = getSession().getNamedQuery(VolumeManagement.VOLUMES_AVAILABLES);

    String req = query.getQueryString() + orderBy;
    // Add order filter to the query
    Query queryWithOrder = getSession().createQuery(req);
    queryWithOrder.setInteger("vdcId", vdc.getId());
    queryWithOrder.setString("filterLike",
            filters.getFilter().isEmpty() ? "%" : "%" + filters.getFilter() + "%");

    Integer size = queryWithOrder.list().size();

    // Limit 0 means no size filter
    if (filters.getLimit() == 0) {
        filters.setLimit(size);/* w w  w .  j a  va 2  s.  co m*/
        filters.setStartwith(0);
    }

    queryWithOrder.setFirstResult(filters.getStartwith());
    queryWithOrder.setMaxResults(filters.getLimit());

    PagedList<VolumeManagement> volumesList = new PagedList<VolumeManagement>(queryWithOrder.list());
    volumesList.setTotalResults(size);
    volumesList.setPageSize(filters.getLimit() > size ? size : filters.getLimit());
    volumesList.setCurrentElement(filters.getStartwith());

    return volumesList;
}

From source file:com.abiquo.server.core.infrastructure.storage.VolumeManagementDAO.java

License:Open Source License

public List<VolumeManagement> getVolumesByVirtualMachine(final VirtualMachine vm, final FilterOptions filters) {
    if (filters != null) {
        // Check if the orderBy element is actually one of the available ones
        VolumeManagement.OrderByEnum orderByEnum = VolumeManagement.OrderByEnum
                .valueOf(filters.getOrderBy().toUpperCase());

        String orderBy = defineOrderBy(orderByEnum.getColumnHQL(), filters.getAsc());

        Query query = getSession().getNamedQuery(VolumeManagement.VOLUMES_ATTACHED_TO_VM);

        String req = query.getQueryString() + orderBy;
        // Add order filter to the query
        Query queryWithOrder = getSession().createQuery(req);
        queryWithOrder.setInteger("vmId", vm.getId());
        queryWithOrder.setParameter("state", VolumeState.ATTACHED);
        queryWithOrder.setString("filterLike",
                filters.getFilter().isEmpty() ? "%" : "%" + filters.getFilter() + "%");

        Integer size = queryWithOrder.list().size();

        queryWithOrder.setFirstResult(filters.getStartwith());
        queryWithOrder.setMaxResults(filters.getLimit());

        PagedList<VolumeManagement> volumesList = new PagedList<VolumeManagement>(queryWithOrder.list());
        volumesList.setTotalResults(size);
        volumesList.setPageSize(filters.getLimit() > size ? size : filters.getLimit());
        volumesList.setCurrentElement(filters.getStartwith());

        return volumesList;
    } else {//from   w w w. j  a  v a 2 s . c  o  m
        Criteria criteria = createCriteria(sameVirtualMachine(vm), sameState(VolumeState.ATTACHED));
        return getResultList(criteria);
    }
}

From source file:com.blazebit.persistence.integration.hibernate.Hibernate43Access.java

License:Apache License

@Override
public String expandParameterLists(SessionImplementor session, org.hibernate.Query hibernateQuery,
        Map<String, TypedValue> namedParamsCopy) {
    String query = hibernateQuery.getQueryString();
    ParameterMetadata parameterMetadata = getParameterMetadata(hibernateQuery);
    Iterator<Map.Entry<String, TypedValue>> iter = getNamedParamLists(hibernateQuery).entrySet().iterator();
    while (iter.hasNext()) {
        Map.Entry<String, TypedValue> me = iter.next();
        query = expandParameterList(session, parameterMetadata, query, (String) me.getKey(),
                (TypedValue) me.getValue(), namedParamsCopy);
    }//from  w w w. j a  va  2  s  .  com
    return query;
}

From source file:com.blazebit.persistence.integration.hibernate.Hibernate52Access.java

License:Apache License

@Override
public String expandParameterLists(SessionImplementor session, org.hibernate.Query hibernateQuery,
        Map<String, TypedValue> namedParamsCopy) {
    QueryParameterBindingsImpl queryParameterBindings = hibernateQuery.unwrap(QueryParameterBindingsImpl.class);
    SharedSessionContractImplementor producer = (SharedSessionContractImplementor) ((QueryImplementor<?>) hibernateQuery)
            .getProducer();//from   ww w  . j a v a 2s  . co m
    String query = hibernateQuery.getQueryString();

    query = queryParameterBindings.expandListValuedParameters(query, producer);
    return query;
}

From source file:com.blazebit.persistence.integration.hibernate.Hibernate53Access.java

License:Apache License

@Override
public String expandParameterLists(SessionImplementor session, org.hibernate.Query hibernateQuery,
        Map<String, TypedValue> namedParamsCopy) {
    QueryParameterBindingsImpl queryParameterBindings = hibernateQuery.unwrap(QueryParameterBindingsImpl.class);
    SharedSessionContractImplementor producer = (SharedSessionContractImplementor) ((QueryImplementor<?>) hibernateQuery)
            .getProducer();//w  ww. jav a2  s  .  c o m
    String query = hibernateQuery.getQueryString();

    // NOTE: In Hibernate 5.3.0.CR1 this is call causes a side effect which is why this is essentially unusable for us
    query = queryParameterBindings.expandListValuedParameters(query, producer);
    return query;
}

From source file:com.creative.dao.repository.GenericBatchDaoImpl.java

License:Apache License

@Override
public int executeUpdate(Query query) {
    Session session = sessionFactory.getCurrentSession();
    session.setCacheMode(CacheMode.IGNORE);
    session.setFlushMode(FlushMode.MANUAL);
    int rows = query.executeUpdate();
    session.flush();//from   w  ww .  j a v a 2s  .c o m

    logger.info("Updated rows  " + rows + " for " + query.getQueryString());
    return rows;
}

From source file:com.creative.dao.repository.GenericDaoImpl.java

License:Apache License

@Override
public <T> T findUniqueObject(Query query, Class<T> clazz) throws IncorrectResultException {
    return getUniqueObject((List<T>) query.list(), query.getQueryString());
}