Package org.hibernate

Examples of org.hibernate.SQLQuery$FetchReturn


    Session ssn = getSession();
    StringBuffer sql = new StringBuffer("SELECT tag_name,COUNT(*) FROM dlog_tag");
    if(site>0)
      sql.append(" WHERE site_id=?");
    sql.append(" GROUP BY tag_name ORDER BY 2 DESC");
    SQLQuery query = ssn.createSQLQuery(sql.toString());
    if(site>0)
      query.setInteger(0, site);
    query.setMaxResults(count);
    List tags = new ArrayList();
    List results = query.list();
    for(int i=0;results!=null && i<results.size();i++){
      tags.add(((Object[])results.get(i))[0]);
    }
    return tags;
  }
View Full Code Here


        queryString.append(getBlogEntryWhereClause(ignoreDoc, year, month, day, tag));

        queryString.append(" ");
        queryString.append("order by doc2.CREATED_ON desc");

        SQLQuery query = getSession().createSQLQuery(queryString.toString());

        bindBlogEntryWhereClause(query, startDir, ignoreDoc, year, month, day, tag);

        query.setComment("Finding all blogEntry documents recursively in dir: " + startDir.getName());
        query.addEntity(WikiDocument.class);
        query.addScalar("COMMENT_COUNT", Hibernate.LONG);
        query.setFirstResult( pager.getQueryFirstResult() );
        query.setMaxResults( pager.getQueryMaxResults() );

        query.setResultTransformer(
            new ResultTransformer() {
                public Object transformTuple(Object[] result, String[] aliases) {
                    BlogEntry be = new BlogEntry();
                    be.setEntryDocument( (WikiDocument)result[0]);
                    blogEntryMap.put(be.getEntryDocument().getId(), be); // Put in map so we can attach comment count later
                    return be;
                }
                public List transformList(List list) { return list; }
            }
        );

        List<BlogEntry> result = (List<BlogEntry>)query.list();

        if (countComments && result.size() > 0) {
            // The risk here is that pager.getQueryMaxResults() is too large for the IN() operator of some DBs...
            StringBuilder commentQueryString = new StringBuilder();
            commentQueryString.append("select doc.NODE_ID as DOC_ID, count(c1.NODE_ID) as COMMENT_COUNT").append(" ");
            commentQueryString.append("from WIKI_DOCUMENT doc").append(" ");
            commentQueryString.append("left outer join WIKI_NODE c1 on doc.NODE_ID = c1.PARENT_NODE_ID").append(" ");
            commentQueryString.append("where doc.NODE_ID in (:blogEntriesIds)").append(" ");
            commentQueryString.append("group by doc.NODE_ID");

            SQLQuery commentQuery = getSession().createSQLQuery(commentQueryString.toString());
            commentQuery.setComment("Finding comment count for blog entries");
            commentQuery.addScalar("DOC_ID");
            commentQuery.addScalar("COMMENT_COUNT");
            commentQuery.setParameterList("blogEntriesIds", blogEntryMap.keySet());

            commentQuery.setResultTransformer(
              new ResultTransformer() {
                  public Object transformTuple(Object[] result, String[] aliases) {
                      BlogEntry be = blogEntryMap.get( ((BigInteger)result[0]).longValue() );
                      be.setCommentCount( ((BigInteger)result[1]).longValue() );
                      return null;
                  }
                  public List transformList(List list) { return list; }
              }
            );
            commentQuery.list();
        }

        return result;
    }
View Full Code Here

        if (projectYear || projectMonth || projectDay) queryString.append("order by").append(" ");
        if (projectYear)    queryString.append("YEAR desc");
        if (projectMonth)   queryString.append(", MONTH desc");
        if (projectDay)     queryString.append(", DAY desc");

        SQLQuery query = getSession().createSQLQuery(queryString.toString());

        bindBlogEntryWhereClause(query, startDir, ignoreDoc, limitYear, limitMonth, limitDay, tag);

        query.setComment("Finding blogEntry counts");
        query.addScalar("NUM_OF_ENTRIES", Hibernate.LONG);
        if (projectYear)    query.addScalar("YEAR", Hibernate.INTEGER);
        if (projectMonth)   query.addScalar("MONTH", Hibernate.INTEGER);
        if (projectDay)     query.addScalar("DAY", Hibernate.INTEGER);

        query.setResultTransformer(
            new ResultTransformer() {
                public Object transformTuple(Object[] result, String[] aliases) {
                    BlogEntryCount beCount = new BlogEntryCount();
                    beCount.setNumOfEntries( (Long)result[0] );
                    if (projectYear)    beCount.setYear( (Integer)result[1] );
                    if (projectMonth)   beCount.setMonth( (Integer)result[2] );
                    if (projectDay)     beCount.setDay( (Integer)result[3] );
                    return beCount;
                }
                public List transformList(List list) { return list; }
            }
        );

        return (List<BlogEntryCount>) query.list();
    }
View Full Code Here

    OgmSession session = openSession();
    Transaction transaction = session.beginTransaction();

    try {
      String nativeQuery = "MATCH ( n:" + TABLE_NAME + " { name:{name}, author:'Oscar Wilde' } ) RETURN n";
      SQLQuery query = session.createNativeQuery( nativeQuery ).addEntity( OscarWildePoem.class );
      query.setParameter( "name", "Portia" );

      OscarWildePoem uniqueResult = (OscarWildePoem) query.uniqueResult();
      assertThat( uniqueResult ).isEqualTo( portia );
      transaction.commit();
    }
    finally {
      session.clear();
View Full Code Here

  private <T> TypedQuery<T> createNamedNativeQuery(NamedSQLQueryDefinition sqlDefinition, Class<T> resultType) {
    if ( resultType != null ) {
      resultClassChecking( resultType, sqlDefinition );
    }
    String sqlQueryString = sqlDefinition.getQueryString();
    SQLQuery noSqlQuery = ( (Session) getDelegate() ).createSQLQuery( sqlQueryString );

    if ( sqlDefinition.getQueryReturns() != null ) {
      if ( sqlDefinition.getQueryReturns().length == 1 ) {
        NativeSQLQueryRootReturn rootReturn = (NativeSQLQueryRootReturn) sqlDefinition.getQueryReturns()[0];
        noSqlQuery.addEntity( "alias1", rootReturn.getReturnEntityName(), LockMode.READ );
      }
    }
    else if ( sqlDefinition.getResultSetRef() != null ) {
      SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) factory.getSessionFactory();
      ResultSetMappingDefinition resultSetMapping = sessionFactory.getResultSetMapping( sqlDefinition.getResultSetRef() );

      if ( resultSetMapping == null ) {
        throw new HibernateException( "Result set mapping '" + sqlDefinition.getResultSetRef() + "' referenced by query '" + sqlDefinition.getName() + "' does not exist." );
      }

      for (NativeSQLQueryReturn queryReturn : resultSetMapping.getQueryReturns() ) {
        if ( queryReturn instanceof NativeSQLQueryScalarReturn ) {
          noSqlQuery.addScalar( ( (NativeSQLQueryScalarReturn) queryReturn ).getColumnAlias() );
        }
        else if ( queryReturn instanceof NativeSQLQueryRootReturn ) {
          noSqlQuery.addEntity( ( (NativeSQLQueryRootReturn) queryReturn ).getReturnEntityName() );
        }
      }
    }

    return new OgmJpaQuery<T>( noSqlQuery, hibernateEm );
View Full Code Here

    return buildQueryFromName( name, resultClass );
  }

  @Override
  public Query createNativeQuery(String sqlString) {
    SQLQuery q = ( (Session) getDelegate() ).createSQLQuery( sqlString );
    return new OgmJpaQuery( q, hibernateEm );
  }
View Full Code Here

    return new OgmJpaQuery( q, hibernateEm );
  }

  @Override
  public Query createNativeQuery(String sqlString, Class resultClass) {
    SQLQuery q = ( (Session) getDelegate() ).createSQLQuery( sqlString );
    q.addEntity( "alias1", resultClass.getName(), LockMode.READ );
    return new OgmJpaQuery( q, hibernateEm );
  }
View Full Code Here

    return new OgmJpaQuery( q, hibernateEm );
  }

  @Override
  public Query createNativeQuery(String sqlString, String resultSetMapping) {
    SQLQuery q = ( (Session) getDelegate() ).createSQLQuery( sqlString );
    q.setResultSetMapping( resultSetMapping );
    return new OgmJpaQuery( q, hibernateEm );
  }
View Full Code Here

  @Override
  public Query createNativeQuery(String sqlString) {
    checkOpen();
    try {
      SQLQuery q = internalGetSession().createSQLQuery( sqlString );
      return new QueryImpl( q, this );
    }
    catch ( HibernateException he ) {
      throw convert( he );
    }
View Full Code Here

  @Override
  public Query createNativeQuery(String sqlString, Class resultClass) {
    checkOpen();
    try {
      SQLQuery q = internalGetSession().createSQLQuery( sqlString );
      q.addEntity( "alias1", resultClass.getName(), LockMode.READ );
      return new QueryImpl( q, this );
    }
    catch ( HibernateException he ) {
      throw convert( he );
    }
View Full Code Here

TOP

Related Classes of org.hibernate.SQLQuery$FetchReturn

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.