当前位置: 首页>>代码示例>>Java>>正文


Java HibernateQuery类代码示例

本文整理汇总了Java中com.mysema.query.jpa.hibernate.HibernateQuery的典型用法代码示例。如果您正苦于以下问题:Java HibernateQuery类的具体用法?Java HibernateQuery怎么用?Java HibernateQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HibernateQuery类属于com.mysema.query.jpa.hibernate包,在下文中一共展示了HibernateQuery类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findAll

import com.mysema.query.jpa.hibernate.HibernateQuery; //导入依赖的package包/类
@Override
public Page<T> findAll(final Predicate predicate, final Pageable pageable, final Sort... sorts) {
	
	return hibernateTemplate.executeWithNativeSession(new HibernateCallback<Page<T>>() {
		public Page<T> doInHibernate(Session session) throws HibernateException, SQLException {
			
			HibernateQuery query = new HibernateQuery(session).from(metamodel);
			applyWhere(query, predicate);
			applySorting(query, sorts);
			applyPagination(query, pageable);
			List<T> content = query.list(metamodel);
			
			
			HibernateQuery countQuery = new HibernateQuery(session).from(metamodel);
			applyWhere(countQuery, predicate);
			long total = countQuery.count();

			return new Pagination<T>(content, pageable, total);
		}
	});
}
 
开发者ID:u2ware,项目名称:springfield,代码行数:22,代码来源:HibernateQueryDslExecutor.java

示例2: groupingTest

import com.mysema.query.jpa.hibernate.HibernateQuery; //导入依赖的package包/类
@Test
@Transactional( readOnly = true )
public void groupingTest() {
    HibernateQuery query = new HibernateQuery(getCurrentSession());
    QEmployee employee = QEmployee.employee;
    QCompany company = QCompany.company;

    List<Tuple> loaded =
            query.from(employee)
                    .groupBy(employee.company.code, employee.empGrade.code)
                    .list(employee.company.code.as("CompanyCode"),
                          employee.empGrade.code.as("GradeCode"),
                          employee.countDistinct().as("RowCount"));

    log.info("Group by = [{}]", loaded);
}
 
开发者ID:debop,项目名称:debop4j,代码行数:17,代码来源:QuerydslSampleTest.java

示例3: getHibernateQuery

import com.mysema.query.jpa.hibernate.HibernateQuery; //导入依赖的package包/类
@Test
@Transactional( readOnly = true )
@SuppressWarnings( "unchecked" )
public void getHibernateQuery() {
    HibernateQuery query = new HibernateQuery(getCurrentSession());
    QEmployee employee = QEmployee.employee;
    org.hibernate.Query hibernateQuery =
            query.from(employee)
                    .where(employee.name.like("Smith%"))
                    .createQuery(employee);

    List<Employee> emps = hibernateQuery.list();

    for (Employee emp : emps)
        log.info("Employee=[{}]", emp);
}
 
开发者ID:debop,项目名称:debop4j,代码行数:17,代码来源:QuerydslSampleTest.java

示例4: count

import com.mysema.query.jpa.hibernate.HibernateQuery; //导入依赖的package包/类
@Override
public long count(final Predicate predicate) {
	return hibernateTemplate.executeWithNativeSession(new HibernateCallback<Long>() {
		public Long doInHibernate(Session session) throws HibernateException, SQLException {
			HibernateQuery query = new HibernateQuery(session).from(metamodel);
			applyWhere(query, predicate);
			return query.count();
		}
	});
}
 
开发者ID:u2ware,项目名称:springfield,代码行数:11,代码来源:HibernateQueryDslExecutor.java

示例5: getCompany

import com.mysema.query.jpa.hibernate.HibernateQuery; //导入依赖的package包/类
/**
         * Gets company.
         *
         * @return the company
         */
        public static Company getCompany() {
            HibernateQuery query = new HibernateQuery(UnitOfWorks.getCurrentSession());
            QCompany company = QCompany.company;
            return query
                    .from(company)
                    .where(company.code.eq(getCompanyCode()))
                    .singleResult(company);
//            return (Company) UnitOfWorks.getCurrentSession()
//                    .createCriteria(Company.class)
//                    .add(Restrictions.eq("code", getCompanyCode()))
//                    .uniqueResult();
        }
 
开发者ID:debop,项目名称:debop4j,代码行数:18,代码来源:AccessContext.java

示例6: getDepartment

import com.mysema.query.jpa.hibernate.HibernateQuery; //导入依赖的package包/类
/**
         * Gets department.
         *
         * @return the department
         */
        public static Department getDepartment() {
            HibernateQuery query = new HibernateQuery(UnitOfWorks.getCurrentSession());
            QDepartment department = QDepartment.department;

            return query.from(department)
                    .where(department.code.eq(getDepartmentCode()))
                    .singleResult(department);

//            return (Department) UnitOfWorks.getCurrentSession()
//                    .createCriteria(Department.class)
//                    .add(Restrictions.eq("code", getDepartmentCode()))
//                    .uniqueResult();
        }
 
开发者ID:debop,项目名称:debop4j,代码行数:19,代码来源:AccessContext.java

示例7: getUser

import com.mysema.query.jpa.hibernate.HibernateQuery; //导入依赖的package包/类
/**
         * Gets user.
         *
         * @return the user
         */
        public static User getUser() {
            HibernateQuery query = new HibernateQuery(UnitOfWorks.getCurrentSession());
            QUser user = QUser.user;

            return query.from(user)
                    .where(user.username.eq(getUsername()))
                    .singleResult(user);

//            return (User) UnitOfWorks.getCurrentSession()
//                    .createCriteria(User.class)
//                    .add(Restrictions.eq("username", getUsername()))
//                    .uniqueResult();
        }
 
开发者ID:debop,项目名称:debop4j,代码行数:19,代码来源:AccessContext.java

示例8: simpleWhere

import com.mysema.query.jpa.hibernate.HibernateQuery; //导入依赖的package包/类
@Test
@Transactional( readOnly = true )
public void simpleWhere() {
    HibernateQuery query = new HibernateQuery(getCurrentSession());
    QEmployee employee = QEmployee.employee;
    Employee loaded = query.from(employee)
            .where(employee.name.eq("Smith"))
            .uniqueResult(employee);

    log.info("Employee=[{}]", loaded);
}
 
开发者ID:debop,项目名称:debop4j,代码行数:12,代码来源:QuerydslSampleTest.java

示例9: joinWhere

import com.mysema.query.jpa.hibernate.HibernateQuery; //导入依赖的package包/类
@Test
@Transactional( readOnly = true )
public void joinWhere() {
    HibernateQuery query = new HibernateQuery(getCurrentSession());
    QEmployee employee = QEmployee.employee;
    QCompany company = QCompany.company;
    Employee loaded = query.from(employee)
            .innerJoin(employee.company, company)
            .where(employee.name.eq("Smith").and(company.code.eq("KTH")))
            .uniqueResult(employee);

    log.info("Employee=[{}]", loaded);
}
 
开发者ID:debop,项目名称:debop4j,代码行数:14,代码来源:QuerydslSampleTest.java

示例10: subQueriesTest

import com.mysema.query.jpa.hibernate.HibernateQuery; //导入依赖的package包/类
@Test
@Transactional( readOnly = true )
public void subQueriesTest() {
    QDepartment department = QDepartment.department;
    QDepartmentMember member = QDepartmentMember.departmentMember;
    QDepartment d = new QDepartment("d");

    HibernateQuery query = new HibernateQuery(getCurrentSession());

    QEmployee employee = QEmployee.employee;
    QEmployee e = new QEmployee("e");

    query.from(employee)
            .where(employee.age.gt(new HibernateSubQuery().from(e).unique(e.age.avg())))
            .list(employee);

    // 직원이 가장 많은 부서 (이것은 차라리 subquery 보다 이 방식이 낫다)
    List<Long> results = query.from(member).groupBy(member.department).list(member.count());

    if (results != null && results.size() > 0) {
        Long max = (Long) results.get(0);
        List<Department> bigDepartment =
                query.from(department)
                        .where(department.members.size().eq(max.intValue()))
                        .list(department);
    }
}
 
开发者ID:debop,项目名称:debop4j,代码行数:28,代码来源:QuerydslSampleTest.java

示例11: transformTest

import com.mysema.query.jpa.hibernate.HibernateQuery; //导入依赖的package包/类
@Test
@Transactional( readOnly = true )
public void transformTest() {
    QCompany company = QCompany.company;
    QEmployee employee = QEmployee.employee;
    HibernateQuery query = new HibernateQuery(getCurrentSession());

    Map<Long, List<Employee>> results =
            query.from(company)
                    .innerJoin(company.employees, employee)
                    .transform(groupBy(company.id).as(list(employee)));

}
 
开发者ID:debop,项目名称:debop4j,代码行数:14,代码来源:QuerydslSampleTest.java

示例12: queryCompany

import com.mysema.query.jpa.hibernate.HibernateQuery; //导入依赖的package包/类
@Test
@Transactional( readOnly = true )
public void queryCompany() {
    QCompany qCompany = QCompany.company;

    HibernateQuery query = new HibernateQuery(getCurrentSession());
    List<Company> loaded = query.from(qCompany)
            .where(qCompany.active.isTrue().and(qCompany.name.isNotEmpty()).and(qCompany.code.in("KTH", "KT")))
            .list(qCompany);

    log.debug("company={}", StringTool.listToString(loaded));
}
 
开发者ID:debop,项目名称:debop4j,代码行数:13,代码来源:QuerydslTest.java

示例13: createQuery

import com.mysema.query.jpa.hibernate.HibernateQuery; //导入依赖的package包/类
private HibernateQuery createQuery() {
    return new HibernateQuery(sessionFactory.getCurrentSession());
}
 
开发者ID:KevinWorkman,项目名称:StaticVoidGames,代码行数:4,代码来源:NotificationsJpaDao.java


注:本文中的com.mysema.query.jpa.hibernate.HibernateQuery类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。