org.hibernate.Query.getReturnTypes()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(190)

本文整理了Java中org.hibernate.Query.getReturnTypes方法的一些代码示例,展示了Query.getReturnTypes的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getReturnTypes方法的具体详情如下:
包路径:org.hibernate.Query
类名称:Query
方法名:getReturnTypes

Query.getReturnTypes介绍

[英]Return the Hibernate types of the query results.
[中]返回查询结果的休眠类型。

代码示例

代码示例来源:origin: hibernate/hibernate-orm

public TupleBuilderTransformer(org.hibernate.Query hqlQuery) {
  final Type[] resultTypes = hqlQuery.getReturnTypes();
  final int tupleSize = resultTypes.length;
  this.tupleElements = CollectionHelper.arrayList( tupleSize );
  final String[] aliases = hqlQuery.getReturnAliases();
  final boolean hasAliases = aliases != null && aliases.length > 0;
  this.tupleElementsByAlias = hasAliases
      ? CollectionHelper.<String, HqlTupleElementImpl>mapOfSize( tupleSize )
      : Collections.<String, HqlTupleElementImpl>emptyMap();
  for ( int i = 0; i < tupleSize; i++ ) {
    final HqlTupleElementImpl tupleElement = new HqlTupleElementImpl(
        i,
        aliases == null ? null : aliases[i],
        resultTypes[i]
    );
    tupleElements.add( tupleElement );
    if ( hasAliases ) {
      final String alias = aliases[i];
      if ( alias != null ) {
        tupleElementsByAlias.put( alias, tupleElement );
      }
    }
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testJpaTypeOperator() {
  // just checking syntax here...
  Session s = openSession();
  s.beginTransaction();
  ///////////////////////////////////////////////////////////////
  // where clause
  // control
  s.createQuery( "from Animal a where a.class = Dog" ).list();
  // test
  s.createQuery( "from Animal a where type(a) = Dog" ).list();
  ///////////////////////////////////////////////////////////////
  // select clause (at some point we should unify these)
  // control
  Query query = s.createQuery( "select a.class from Animal a where a.class = Dog" );
  query.list(); // checks syntax
  assertEquals( 1, query.getReturnTypes().length );
  assertEquals( Integer.class, query.getReturnTypes()[0].getReturnedClass() ); // always integer for joined
  // test
  query = s.createQuery( "select type(a) from Animal a where type(a) = Dog" );
  query.list(); // checks syntax
  assertEquals( 1, query.getReturnTypes().length );
  assertEquals( DiscriminatorType.class, query.getReturnTypes()[0].getClass() );
  assertEquals( Class.class, query.getReturnTypes()[0].getReturnedClass() );
  s.getTransaction().commit();
  s.close();
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
@TestForIssue( jiraKey = "HHH-1464" )
public void testQueryMetadataRetrievalWithFetching() {
  // HHH-1464 : there was a problem due to the fact they we polled
  // the shallow version of the query plan to get the metadata.
  Session s = openSession();
  Query query = s.createQuery( "from Animal a inner join fetch a.mother" );
  assertEquals( 1, query.getReturnTypes().length );
  assertNull( query.getReturnAliases() );
  s.close();
}

代码示例来源:origin: hibernate/hibernate-orm

s.clear();
Query q = s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null");
Type type = q.getReturnTypes()[0];
assertTrue( type instanceof ManyToOneType );
assertEquals( ( (ManyToOneType) type ).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo" );

代码示例来源:origin: hibernate/hibernate-orm

s.clear();
Query q = s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null");
Type type = q.getReturnTypes()[0];
assertTrue( type instanceof ManyToOneType );
assertEquals( ( (ManyToOneType) type ).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo" );

代码示例来源:origin: hibernate/hibernate-orm

s.clear();
Query q = s.createQuery("select a.zoo from Animal a where a.zoo is not null order by a.zoo.name");
Type type = q.getReturnTypes()[0];
assertTrue( type instanceof ManyToOneType );
assertEquals( ( (ManyToOneType) type ).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo" );

代码示例来源:origin: hibernate/hibernate-orm

s.clear();
Query q = s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null order by a.zoo.name");
Type type = q.getReturnTypes()[0];
assertTrue( type instanceof ManyToOneType );
assertEquals( ( (ManyToOneType) type ).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo" );

代码示例来源:origin: hibernate/hibernate-orm

qu.getReturnTypes();
qu.getNamedParameters();

代码示例来源:origin: hibernate/hibernate-orm

s.save( new Bar() );
Query query = s.createQuery("select f, f.integer from Foo f");
assertTrue( query.getReturnTypes().length==2 );
ScrollableResults iter = query.scroll();
assertTrue( iter.next() );
txn = s.beginTransaction();
query = s.createQuery("select f, f.integer from Foo f");
assertTrue( query.getReturnTypes().length==2 );
iter = query.scroll();
assertTrue( iter.next() );

代码示例来源:origin: jasperreports/jasperreports

/**
 * Returns the return types of the HQL query.
 * 
 * @return the return types of the HQL query
 */
public Type[] getReturnTypes()
{
  return query.getReturnTypes();
}

代码示例来源:origin: com.github.cafdataprocessing/corepolicy-hibernate

@Override
public Type[] getReturnTypes() {
  return query.getReturnTypes();
}

代码示例来源:origin: ezbz/projectx

@Override
public Type[] getReturnTypes() throws HibernateException {
 return query.getReturnTypes();
}

代码示例来源:origin: riotfamily/riot

public Type[] getReturnTypes() throws HibernateException {
  return query.getReturnTypes();
}

代码示例来源:origin: riotfamily/riot

@SuppressWarnings("unchecked")
public QueryResult(Query query) {
  super(query.list(), query.getReturnTypes()[0].getReturnedClass());
}

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.ejb

public TupleBuilderTransformer(org.hibernate.Query hqlQuery) {
  final Type[] resultTypes = hqlQuery.getReturnTypes();
  final int tupleSize = resultTypes.length;
  this.tupleElements = CollectionHelper.arrayList( tupleSize );
  final String[] aliases = hqlQuery.getReturnAliases();
  final boolean hasAliases = aliases != null && aliases.length > 0;
  this.tupleElementsByAlias = hasAliases
      ? CollectionHelper.<String, HqlTupleElementImpl>mapOfSize( tupleSize )
      : Collections.<String, HqlTupleElementImpl>emptyMap();
  for ( int i = 0; i < tupleSize; i++ ) {
    final HqlTupleElementImpl tupleElement = new HqlTupleElementImpl(
        i,
        aliases == null ? null : aliases[i],
        resultTypes[i]
    );
    tupleElements.add( tupleElement );
    if ( hasAliases ) {
      final String alias = aliases[i];
      if ( alias != null ) {
        tupleElementsByAlias.put( alias, tupleElement );
      }
    }
  }
}

代码示例来源:origin: org.exoplatform.core/exo.core.component.organization.jdbc

E[] entities = (E[])Array.newInstance(query.getReturnTypes()[0].getReturnedClass(), length);
Iterator<E> results = query.iterate();

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.ejb

else if ( hqlQuery.getReturnTypes().length == 1 ) {
  if ( !resultClass.isAssignableFrom( hqlQuery.getReturnTypes()[0].getReturnedClass() ) ) {
    throw new IllegalArgumentException(
        "Type specified for TypedQuery [" +
            resultClass.getName() +
            "] is incompatible with query return type [" +
            hqlQuery.getReturnTypes()[0].getReturnedClass() + "]"
    );

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.ejb

if ( namedQuery.getReturnTypes().length != 1 ) {
  throw new IllegalArgumentException( "Cannot create TypedQuery for query with more than one return" );
if ( !resultClass.isAssignableFrom( namedQuery.getReturnTypes()[0].getReturnedClass() ) ) {
  throw buildIncompatibleException( resultClass, namedQuery.getReturnTypes()[0].getReturnedClass() );

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.ejb

public <T> TypedQuery<T> createQuery(
    String jpaqlString,
    Class<T> resultClass,
    Selection selection,
    Options options) {
  try {
    org.hibernate.Query hqlQuery = getSession().createQuery( jpaqlString );
    if ( options.getValueHandlers() == null ) {
      options.getResultMetadataValidator().validate( hqlQuery.getReturnTypes() );
    }
    // determine if we need a result transformer
    List tupleElements = Tuple.class.equals( resultClass )
        ? ( ( CompoundSelectionImpl<Tuple> ) selection ).getCompoundSelectionItems()
        : null;
    if ( options.getValueHandlers() != null || tupleElements != null ) {
      hqlQuery.setResultTransformer(
          new CriteriaQueryTransformer( options.getValueHandlers(), tupleElements )
      );
    }
    return new QueryImpl<T>( hqlQuery, this, options.getNamedParameterExplicitTypes() );
  }
  catch ( HibernateException he ) {
    throw convert( he );
  }
}

相关文章