Ejemplo n.º 1
0
 /** @return all the member in this team. (Use a HQL query). */
 public PageIterable<DaoMember> getMembers() {
   final Session session = SessionManager.getSessionFactory().getCurrentSession();
   final Query filter =
       session.createFilter(getTeamMembership(), "select this.member order by login");
   final Query count = session.createFilter(getTeamMembership(), "select count(*)");
   return new QueryCollection<DaoMember>(filter, count);
 }
Ejemplo n.º 2
0
  public void testCollectionFilter() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Group hb = new Group("hibernate");
    User gavin = new User("gavin");
    User max = new User("max");
    hb.getUsers().put("gavin", gavin);
    hb.getUsers().put("max", max);
    gavin.getGroups().put("hibernate", hb);
    max.getGroups().put("hibernate", hb);
    s.persist(hb);
    t.commit();
    s.close();

    s = openSession();
    t = s.beginTransaction();
    hb =
        (Group)
            s.createCriteria(Group.class)
                .setFetchMode("users", FetchMode.SELECT)
                .add(Restrictions.idEq("hibernate"))
                .uniqueResult();
    assertFalse(Hibernate.isInitialized(hb.getUsers()));
    // gavin = (User) s.createFilter( hb.getUsers(), "where index(this) = 'gavin'" ).uniqueResult();
    Long size = (Long) s.createFilter(hb.getUsers(), "select count(*)").uniqueResult();
    assertEquals(new Long(2), size);
    assertFalse(Hibernate.isInitialized(hb.getUsers()));
    s.delete(hb);
    t.commit();
    s.close();
  }
  /**
   * Creates the Hibernate query object.
   *
   * <p>If the value of the {@link
   * JRHibernateQueryExecuterFactory#PARAMETER_HIBERNATE_FILTER_COLLECTION
   * PARAMETER_HIBERNATE_FILTER_COLLECTION} is not null, then a filter query is created using the
   * value of the parameter as the collection.
   *
   * @param queryString the query string
   */
  protected synchronized void createQuery(String queryString) {
    if (log.isDebugEnabled()) {
      log.debug("HQL query: " + queryString);
    }

    Object filterCollection =
        getParameterValue(JRHibernateQueryExecuterFactory.PARAMETER_HIBERNATE_FILTER_COLLECTION);
    if (filterCollection == null) {
      query = session.createQuery(queryString);
    } else {
      query = session.createFilter(filterCollection, queryString);
    }
    query.setReadOnly(true);

    int fetchSize =
        JRProperties.getIntegerProperty(
            dataset, JRJdbcQueryExecuterFactory.PROPERTY_JDBC_FETCH_SIZE, 0);
    if (fetchSize != 0) {
      query.setFetchSize(fetchSize);
    }

    setParameters();
  }
Ejemplo n.º 4
0
 public Query createFilter(Object collection, String queryString) throws HibernateException {
   return session.createFilter(collection, queryString);
 }