• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DistinctRootEntityResultTransformer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testManyToManyFilterOnCriteria

import org.hibernate.transform.DistinctRootEntityResultTransformer; //导入依赖的package包/类
public void testManyToManyFilterOnCriteria() {
	TestData testData = new TestData();
	testData.prepare();

	Session session = openSession();
	session.enableFilter( "effectiveDate" ).setParameter( "asOfDate", new Date() );

	Product prod = ( Product ) session.createCriteria( Product.class )
	        .setResultTransformer( new DistinctRootEntityResultTransformer() )
	        .add( Expression.eq( "id", testData.prod1Id ) )
	        .uniqueResult();

	assertNotNull( prod );
	assertEquals( "Incorrect Product.categories count for filter", 1, prod.getCategories().size() );

	session.close();
	testData.release();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:19,代码来源:DynamicFilterTest.java


示例2: loadJobsTasks

import org.hibernate.transform.DistinctRootEntityResultTransformer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Map<Long, List<TaskData>> loadJobsTasks(Session session, List<Long> jobIds) {
    Query tasksQuery = session.getNamedQuery("loadJobsTasks")
                              .setParameterList("ids", jobIds)
                              .setReadOnly(true)
                              .setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);

    Map<Long, List<TaskData>> tasksMap = new HashMap<>(jobIds.size(), 1f);
    for (Long id : jobIds) {
        tasksMap.put(id, new ArrayList<TaskData>());
    }

    List<TaskData> tasks = tasksQuery.list();
    for (TaskData task : tasks) {
        tasksMap.get(task.getJobData().getId()).add(task);
    }

    return tasksMap;
}
 
开发者ID:ow2-proactive,项目名称:scheduling,代码行数:20,代码来源:SchedulerDBManager.java


示例3: toQuery

import org.hibernate.transform.DistinctRootEntityResultTransformer; //导入依赖的package包/类
public Query toQuery(Session session, boolean isReadOnly)
{
  org.hibernate.Query query = session.createQuery(toHql());
  for (Map.Entry<String,Object> arg : args().entrySet()) {
    if (arg.getKey().endsWith(SET_ARG_SUFFIX)) {
      // HACK: handle 'list' type parameters, used with the 'IN (?)' operator
      query.setParameterList(arg.getKey(), (Set<?>) arg.getValue());
    }
    else {
      query.setParameter(arg.getKey(), arg.getValue());
    }
  }
  if (_isDistinctRootEntities) {
    query.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);
  }
  query.setReadOnly(isReadOnly);
  return query;
}
 
开发者ID:hmsiccbl,项目名称:screensaver,代码行数:19,代码来源:HqlBuilder.java


示例4: getAllObjects

import org.hibernate.transform.DistinctRootEntityResultTransformer; //导入依赖的package包/类
/**
 * @return all objects of this Entity type
 */
@SuppressWarnings("unchecked")
protected List<EntityClass> getAllObjects() {

    List<EntityClass> objects = new ArrayList<>();
    Session session = null;
    try {
        session = sessionFactory.openSession();

        Criteria criteria = session.createCriteria(getEntityType());
        //make uniq, criteria returns many double entities, because of fetched relations
        //http://stackoverflow.com/questions/8758363/why-session-createcriteriaclasstype-list-return-more-object-than-in-list
        criteria.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);

        objects = criteria.list();

    } catch (RuntimeException re) {
        re.printStackTrace();

    } finally {
        if (session != null) {
            session.close();
        }
    }

    return objects;
}
 
开发者ID:AMOSTeam3,项目名称:amos-ss15-proj3,代码行数:30,代码来源:AbstractDefaultDao.java


示例5: testSQLQueryInterface

import org.hibernate.transform.DistinctRootEntityResultTransformer; //导入依赖的package包/类
public void testSQLQueryInterface() {
	Session s = openSession();
	Transaction t = s.beginTransaction();
	Organization ifa = new Organization("IFA");
	Organization jboss = new Organization("JBoss");
	Person gavin = new Person("Gavin");
	Employment emp = new Employment(gavin, jboss, "AU");

	s.persist(ifa);
	s.persist(jboss);
	s.persist(gavin);
	s.persist(emp);

	List l = s.createSQLQuery( getOrgEmpRegionSQL() )
			.addEntity("org", Organization.class)
			.addJoin("emp", "org.employments")
			.addScalar("regionCode", Hibernate.STRING)
			.list();
	assertEquals( 2, l.size() );

	l = s.createSQLQuery( getOrgEmpPersonSQL() )
			.addEntity("org", Organization.class)
			.addJoin("emp", "org.employments")
			.addJoin("pers", "emp.employee")
			.list();
	assertEquals( l.size(), 1 );

	t.commit();
	s.close();

	s = openSession();
	t = s.beginTransaction();

	l = s.createSQLQuery( "select {org.*}, {emp.*} " +
		       "from ORGANIZATION org " +
		       "     left outer join EMPLOYMENT emp on org.ORGID = emp.EMPLOYER, ORGANIZATION org2" )
	.addEntity("org", Organization.class)
	.addJoin("emp", "org.employments")
	.setResultTransformer(new DistinctRootEntityResultTransformer())
	.list();
	assertEquals( l.size(), 2 );

	t.commit();
	s.close();

	s = openSession();
	t = s.beginTransaction();

	s.delete(emp);
	s.delete(gavin);
	s.delete(ifa);
	s.delete(jboss);

	t.commit();
	s.close();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:57,代码来源:NativeSQLQueriesTest.java


示例6: testResultTransformerScalarQueries

import org.hibernate.transform.DistinctRootEntityResultTransformer; //导入依赖的package包/类
public void testResultTransformerScalarQueries() throws Exception {

		createTestBaseData();

		String query = "select an.description as description, an.bodyWeight as bodyWeight from Animal an order by bodyWeight desc";

		Session session = openSession();

		List results = session.createQuery( query )
		.setResultTransformer(Transformers.aliasToBean(Animal.class)).list();
		assertEquals( "Incorrect result size", results.size(), 2 );
		assertTrue( "Incorrect return type", results.get(0) instanceof Animal );
		Animal firstAnimal = (Animal) results.get(0);
		Animal secondAnimal = (Animal) results.get(1);
		assertEquals("Mammal #1", firstAnimal.getDescription());
		assertEquals("Mammal #2", secondAnimal.getDescription());
		assertFalse(session.contains(firstAnimal));
		session.close();

		session = openSession();

		Iterator iter = session.createQuery( query )
	     .setResultTransformer(Transformers.aliasToBean(Animal.class)).iterate();
		assertTrue( "Incorrect result size", iter.hasNext() );
		assertTrue( "Incorrect return type", iter.next() instanceof Animal );

		session.close();

		session = openSession();

		ScrollableResults sr = session.createQuery( query )
	     .setResultTransformer(Transformers.aliasToBean(Animal.class)).scroll();
		assertTrue( "Incorrect result size", sr.next() );
		assertTrue( "Incorrect return type", sr.get(0) instanceof Animal );
		assertFalse(session.contains(sr.get(0)));
		sr.close();

		session.close();

		session = openSession();

		results = session.createQuery( "select a from Animal a, Animal b order by a.id" )
				.setResultTransformer(new DistinctRootEntityResultTransformer())
				.list();
		assertEquals( "Incorrect result size", 2, results.size());
		assertTrue( "Incorrect return type", results.get(0) instanceof Animal );
		firstAnimal = (Animal) results.get(0);
		secondAnimal = (Animal) results.get(1);
		assertEquals("Mammal #1", firstAnimal.getDescription());
		assertEquals("Mammal #2", secondAnimal.getDescription());

		session.close();

		destroyTestBaseData();
	}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:56,代码来源:ASTParserLoadingTest.java


示例7: getData

import org.hibernate.transform.DistinctRootEntityResultTransformer; //导入依赖的package包/类
/**
 * Executes a query that is built using full text search, core column filters, and extension column filters. The filters
 * and sorting to be applied are provided via the criteria parameter, and the code uses introspection to determine which
 * fields are core and which are extensions (assuming it is a table that with extensions). The querying is extremely
 * flexible and dynamic, which means it is also not optimized ... use with care on large data sets!
 *
 * @param criteria
 *            Provides the detail filter and sorting information
 * @param entityClass
 *            The class of the data to be returned
 * @return List of result objects of type entityClass
 */
@Transactional
public QueryResult<T> getData(Criteria criteria, Class<?> entityClass) {
	TableInfo tableInfo = TableInfo.create(entityClass);
	QueryResult<T> result = new QueryResult<>();
	Session session = ((HibernateEntityManager) em).getSession();

	StringBuilder sql = new StringBuilder();
	if (StringUtils.isNotBlank(tableInfo.getExtTableName())) {
		sql.append("SELECT {filtered.*}, {extended.*} ");
		sql.append(", filtered." + tableInfo.getPkColumn() + " INDX FROM (");
	}

	String baseSql = generateFilterQuery(criteria, tableInfo, result, true, true);
	result.setExectutedSql(baseSql);
	sql.append(baseSql);

	if (criteria.isPagingActive()) {
		sql.append(" LIMIT " + criteria.getFirstResults());
		sql.append(", " + criteria.getPageSize());
	}
	if (StringUtils.isNotBlank(tableInfo.getExtTableName())) {
		sql.append(") filtered ");
		sql.append(" left join " + tableInfo.getExtTableName() + " extended on (filtered." + tableInfo.getPkColumn()
				+ " = extended." + tableInfo.getPkColumn() + ") ");
	}

	SQLQuery query = session.createSQLQuery(sql.toString());
	if (StringUtils.isNotBlank(tableInfo.getExtTableName())) {
		query.addScalar("INDX"); // this scalar has to be here to workaround a hibernate bug.
		query.addEntity("filtered", tableInfo.getEntityClass());
		query.addJoin("extended", "filtered." + tableInfo.getExtFieldName());
		query.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);
	} else if (StringUtils.isNotBlank(tableInfo.getTableName())) {
		query.addEntity("main", tableInfo.getEntityClass());
	} else if (Map.class.isAssignableFrom(entityClass)) {
		query.setResultTransformer(AliasToEntityStringMapResultTransformer.INSTANCE);
	} else {
		query.setResultTransformer(new IgnoringCaseAliasToBeanResultTransformer(tableInfo.getEntityClass()));
	}

	for (String key : criteria.getParameters().keys()) {
		result.queryParameters.put(key, criteria.getParameters().get(key));
	}

	query.setProperties(result.queryParameters);
	List<T> rows = query.list();

	result.setRows(rows);
	if (!criteria.isPagingActive()) {
		result.setTotalRowCount(rows.size());
	} else {
		StringBuilder countSql = new StringBuilder();
		countSql.append("select count(*) cnt from (");
		countSql.append(generateFilterQuery(criteria, tableInfo, result, false, false));
		countSql.append(") c");
		SQLQuery countQuery = session.createSQLQuery(countSql.toString());
		countQuery.addScalar("cnt", StandardBasicTypes.INTEGER); // this scalar has to be here to workaround a hibernate
		// bug.
		countQuery.setProperties(result.queryParameters);
		Integer count = (Integer) countQuery.uniqueResult();
		result.setTotalRowCount(count);

	}

	return result;
}
 
开发者ID:SmarterApp,项目名称:TechnologyReadinessTool,代码行数:79,代码来源:CriteriaQuery.java


示例8: testFetchMode

import org.hibernate.transform.DistinctRootEntityResultTransformer; //导入依赖的package包/类
@Test
public void testFetchMode(){

	JazzDetachedCriteria criteria = JazzDetachedCriteria.forClass(QuestionnaireVO.class);
	
	//criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
	
	ResultTransformer rt = DistinctRootEntityResultTransformer.INSTANCE;
	criteria.setResultTransformer(rt);
	
	criteria.add(Restrictions.eq("PK", 1l));

	criteria.enableFetchProfile("questinario_com_questoes");
	criteria.enableFetchProfile("questao_com_alternativas");
	
	List<QuestionnaireVO> questinnaires = hibernateTemplate.findByCriteria(criteria);
	
	
	//criteria.disableFetchProfile("questinario_com_questoes");
	//questinnaires = hibernateTemplate.findByCriteria(criteria);
	
	for (QuestionnaireVO questionnaireVO : questinnaires) {
		
		System.out.println("\t "+questionnaireVO.getDescription());
		
		Collection<QuestionVO> questions = questionnaireVO.getQuestions();
		for (QuestionVO questionVO : questions) {
			
			System.out.println("\t\t "+questionVO.getDescription());
			Set<AbstractCriterionVO> criterions = questionVO.getCriterionVOs();
			
			for (AbstractCriterionVO alternativeVO : criterions) {
				String x = alternativeVO==null?"":alternativeVO.getDescription();
				
				System.out.println("\t\t\t "+alternativeVO+" "+x);
				
			}
			
		}
		
		System.out.println(questionnaireVO);
	}		
	
}
 
开发者ID:darciopacifico,项目名称:omr,代码行数:45,代码来源:JazzFetchAndQueryTests.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FastInfosetFeature类代码示例发布时间:2022-05-23
下一篇:
Java ColorDescriptor类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap