Example usage for org.hibernate Query setBoolean

List of usage examples for org.hibernate Query setBoolean

Introduction

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

Prototype

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

Source Link

Document

Bind a named boolean-valued parameter.

Usage

From source file:com.ikon.dao.TwitterAccountDAO.java

License:Open Source License

/**
 * Find all twitter accounts// w  w w. ja v a  2s  . c o m
 */
@SuppressWarnings("unchecked")
public static List<TwitterAccount> findAll(boolean filterByActive) throws DatabaseException {
    log.debug("findAll()");
    String qs = "from TwitterAccount ta " + (filterByActive ? "where ta.active=:active" : "")
            + " order by ta.id";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);

        if (filterByActive) {
            q.setBoolean("active", true);
        }

        List<TwitterAccount> ret = q.list();
        log.debug("findAll: {}", ret);
        return ret;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.netsteadfast.greenstep.base.dao.BaseDAO.java

License:Apache License

/**
 * for public QueryResult getList... doInHibernate
 * @param query       JPA-Style : from TB_ACCOUNT where account = ?0 
 * @param position   JPA-Style : "0", "1" .....
 * @param params/*from  ww  w.  ja v  a 2s  . com*/
 */
@SuppressWarnings("rawtypes")
private void setQueryParams(Query query, String position, Object params) {
    if (params instanceof java.lang.String) {
        query.setString(position, (java.lang.String) params);
        return;
    }
    if (params instanceof java.lang.Character) {
        query.setCharacter(position, (java.lang.Character) params);
        return;
    }
    if (params instanceof java.lang.Double) {
        query.setDouble(position, (java.lang.Double) params);
        return;
    }
    if (params instanceof java.lang.Byte) {
        query.setByte(position, (java.lang.Byte) params);
        return;
    }
    if (params instanceof java.lang.Integer) {
        query.setInteger(position, (java.lang.Integer) params);
        return;
    }
    if (params instanceof java.lang.Long) {
        query.setLong(position, (java.lang.Long) params);
        return;
    }
    if (params instanceof java.lang.Boolean) {
        query.setBoolean(position, (java.lang.Boolean) params);
        return;
    }
    if (params instanceof java.math.BigDecimal) {
        query.setBigDecimal(position, (java.math.BigDecimal) params);
        return;
    }
    if (params instanceof java.util.Date) {
        query.setDate(position, (java.util.Date) params);
        return;
    }
    if (params instanceof java.util.List) {
        List listParams = (List) params;
        this.setQueryParamsOfList(query, position, listParams);
        return;
    }
}

From source file:com.nominanuda.hibernate.AbstractHibernateStructStore.java

License:Apache License

protected void bind(Query q, String k, Object v) {
    DataType t = struct.getDataType(v);/*from  www  .j a  v a  2  s  . co m*/
    switch (t) {
    case array:
        q.setParameterList(k, struct.toMapsAndSetLists((DataArray) v));
        break;
    case object:
        q.setEntity(k, struct.toMapsAndSetLists((DataObject) v));
        break;
    case string:
        q.setString(k, (String) v);
        break;
    case bool:
        q.setBoolean(k, (Boolean) v);
        break;
    case number:
        Double d = ((Number) v).doubleValue();
        if (Maths.isInteger(d)) {
            q.setLong(k, d.longValue());
        } else {
            q.setDouble(k, d);
        }
        break;
    default:
        throw new IllegalArgumentException(t.name());
    }
}

From source file:com.obird.OUMS.dao.imp.RoleDaoImp.java

@SuppressWarnings("unchecked")
@Override/*from  ww  w .j a  v a2  s. c om*/
public List<Role> getAllNonAdminRoles() {
    return getHibernateTemplate().execute(new HibernateCallback<List<Role>>() {
        @Override
        public List<Role> doInHibernate(Session sn) throws HibernateException {
            Query query = sn.createQuery(
                    "select r from Role r where r.name <> :superAdminRole AND r.name <> :adminRole and r.deleted= :deleted");
            query.setBoolean("deleted", false);
            query.setString("superAdminRole", "SUPER_ADMIN");
            query.setString("adminRole", "ADMIN");
            List<Role> users = query.list();
            //return result 
            return users;
        }
    });
}

From source file:com.obird.OUMS.dao.imp.UserDaoImp.java

@SuppressWarnings("unchecked")
@Override/*  w  w  w .java  2s . c o m*/
public List<User> getAllUsers() {
    return getHibernateTemplate().execute(new HibernateCallback<List<User>>() {
        @Override
        public List<User> doInHibernate(Session sn) throws HibernateException {
            Query query = sn.createQuery("from User u where u.deleted =:deleted");
            query.setBoolean("deleted", false);
            return query.list();
        }
    });
}

From source file:com.ocare.obook.dao.impl.ExamineTypeDaoImpl.java

/**
 *
 * @return//from ww w  .  j  a va  2 s  .  c o m
 */
@SuppressWarnings("unchecked")
@Override
public List<ExamineType> getAllExamineTypes() {
    return getHibernateTemplate().execute(new HibernateCallback<List<ExamineType>>() {
        @Override
        public List<ExamineType> doInHibernate(Session sn) throws HibernateException {
            Query query = sn.createQuery("from ExamineType where isDeleted=:deleted ");
            query.setBoolean("deleted", false);
            return (List<ExamineType>) query.list();
        }
    });
}

From source file:com.ocare.obook.dao.impl.ExamineTypeDaoImpl.java

@Override
public ExamineType getDefaultExamineType() {
    return getHibernateTemplate().execute(new HibernateCallback<ExamineType>() {
        @Override/*w w  w  . j  a  v  a2 s.  co m*/
        public ExamineType doInHibernate(Session sn) throws HibernateException {
            Query query = sn.createQuery("from ExamineType where defaultOne=:default");
            query.setBoolean("default", true);
            return (ExamineType) query.uniqueResult();
        }
    });
}

From source file:com.ocare.obook.dao.impl.ExamineTypeDaoImpl.java

@SuppressWarnings("unchecked")
@Override// ww  w  .j a va2s .c  om
public List<ExamineType> getExamineTypesWithPattern(final String pattern) {
    return getHibernateTemplate().execute(new HibernateCallback<List<ExamineType>>() {
        @Override
        public List<ExamineType> doInHibernate(Session sn) throws HibernateException {
            Query query = sn.createQuery(
                    "from ExamineType e where e.isDeleted=:deleted AND (e.nameEn LIKE :nameEn OR e.nameAr LIKE :nameAr)");
            query.setString("nameAr", "%" + pattern + "%");
            query.setString("nameEn", "%" + pattern + "%");
            query.setBoolean("deleted", false);
            return (List<ExamineType>) query.list();
        }
    });
}

From source file:com.ocare.obook.dao.impl.InsuranceCompanyDaoImpl.java

@SuppressWarnings("unchecked")
@Override//  ww w.ja  v  a2s. com
public List<InsuranceCompany> getAllInsuranceCompanys() {
    return getHibernateTemplate().execute(new HibernateCallback<List<InsuranceCompany>>() {
        @Override
        public List<InsuranceCompany> doInHibernate(Session sn) throws HibernateException {
            Query query = sn.createQuery("from InsuranceCompany where isDeleted = :deleted");
            query.setBoolean("deleted", false);
            return (List<InsuranceCompany>) query.list();
        }
    });
}

From source file:com.ocare.obook.dao.impl.InsuranceCompanyDaoImpl.java

@SuppressWarnings("unchecked")
@Override//from  www.j  av  a2s  . c  o  m
public List<InsuranceCompany> getInsurranceCompaniesWithPattern(final String pattern) {
    return getHibernateTemplate().execute(new HibernateCallback<List<InsuranceCompany>>() {
        @Override
        public List<InsuranceCompany> doInHibernate(Session sn) throws HibernateException {
            Query query = sn.createQuery(
                    "from InsuranceCompany i where i.isDeleted = :deleted AND (i.nameEn LIKE :nameEn OR i.nameAr LIKE :nameAr)");
            query.setString("nameAr", "%" + pattern + "%");
            query.setString("nameEn", "%" + pattern + "%");
            query.setBoolean("deleted", false);
            return (List<InsuranceCompany>) query.list();
        }
    });
}