org.hibernate.transform.ResultTransformer Java Examples
The following examples show how to use
org.hibernate.transform.ResultTransformer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultJpaRepository.java From ueboot with BSD 3-Clause "New" or "Revised" License | 6 votes |
public <S> Page<S> find(String queryString, String queryCount, NamedParams params, Pageable pageable, ResultTransformer transformer) { Assert.hasText(queryString, "Query must has text!"); Assert.hasText(queryCount, "Query count must has text!"); Assert.notNull(params, "QueryParams must not be null!"); Assert.notNull(pageable, "PageRequest must not be null!"); Assert.notNull(transformer, "Transformer must not be null!"); Query query = em.createQuery(queryString); setQueryParams(query, params); query.setMaxResults(pageable.getPageSize()); query.setFirstResult((int) pageable.getOffset()); List<S> resultList = query.unwrap(QueryImpl.class).setResultTransformer(transformer).list(); Query countQuery = em.createQuery(queryCount); setQueryParams(countQuery, params); Long total = (Long) countQuery.getSingleResult(); Page<S> page = new PageImpl(resultList, pageable, total); return page; }
Example #2
Source File: ReactiveAbstractEntityLoader.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 6 votes |
@Override public List<Object> getRowsFromResultSet( ResultSet rs, QueryParameters queryParameters, SharedSessionContractImplementor session, boolean returnProxies, ResultTransformer forcedResultTransformer, int maxRows, List<Object> hydratedObjects, List<EntityKey[]> subselectResultKeys) throws SQLException { return super.getRowsFromResultSet( rs, queryParameters, session, returnProxies, forcedResultTransformer, maxRows, hydratedObjects, subselectResultKeys ); }
Example #3
Source File: QueryLoader.java From lams with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override protected List getResultList(List results, ResultTransformer resultTransformer) throws QueryException { // meant to handle dynamic instantiation queries... HolderInstantiator holderInstantiator = buildHolderInstantiator( resultTransformer ); if ( holderInstantiator.isRequired() ) { for ( int i = 0; i < results.size(); i++ ) { Object[] row = (Object[]) results.get( i ); Object result = holderInstantiator.instantiate( row ); results.set( i, result ); } if ( !hasSelectNew() && resultTransformer != null ) { return resultTransformer.transformList( results ); } else { return results; } } else { return results; } }
Example #4
Source File: CachingReactiveLoader.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 6 votes |
default CompletionStage<List<Object>> doReactiveList( final String sql, final String queryIdentifier, final SessionImplementor session, final QueryParameters queryParameters, final ResultTransformer forcedResultTransformer) throws HibernateException { final StatisticsImplementor statistics = session.getSessionFactory().getStatistics(); final boolean stats = statistics.isStatisticsEnabled(); final long startTime = stats ? System.nanoTime() : 0; return doReactiveQueryAndInitializeNonLazyCollections( sql, session, queryParameters, true, forcedResultTransformer ) .handle( (list, err) -> { CompletionStages.logSqlException( err, () -> "could not execute query", sql ); if ( err ==null && stats ) { final long endTime = System.nanoTime(); final long milliseconds = TimeUnit.MILLISECONDS.convert( endTime - startTime, TimeUnit.NANOSECONDS ); statistics.queryExecuted( queryIdentifier, list.size(), milliseconds ); } return CompletionStages.returnOrRethrow(err, list ); } ); }
Example #5
Source File: ReactiveCustomLoader.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 6 votes |
@Override public List<Object> getRowsFromResultSet( ResultSet rs, QueryParameters queryParameters, SharedSessionContractImplementor session, boolean returnProxies, ResultTransformer forcedResultTransformer, int maxRows, List<Object> hydratedObjects, List<EntityKey[]> subselectResultKeys) throws SQLException { return super.getRowsFromResultSet( rs, queryParameters, session, returnProxies, forcedResultTransformer, maxRows, hydratedObjects, subselectResultKeys); }
Example #6
Source File: CachingReactiveLoader.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 6 votes |
default List<?> transform(QueryParameters queryParameters, QueryKey key, List<Object> result, ResultTransformer resolvedTransformer) { if (resolvedTransformer == null) { return result; } else { CacheableResultTransformer transformer = key.getResultTransformer(); if ( areResultSetRowsTransformedImmediately() ) { return transformer.retransformResults( result, getResultRowAliases(), queryParameters.getResultTransformer(), includeInResultRow() ); } else { return transformer.untransformToTuples(result); } } }
Example #7
Source File: CriteriaLoader.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
protected Object getResultColumnOrRow(Object[] row, ResultTransformer transformer, ResultSet rs, SessionImplementor session) throws SQLException, HibernateException { final Object[] result; final String[] aliases; if ( translator.hasProjection() ) { Type[] types = translator.getProjectedTypes(); result = new Object[types.length]; String[] columnAliases = translator.getProjectedColumnAliases(); for ( int i=0; i<result.length; i++ ) { result[i] = types[i].nullSafeGet(rs, columnAliases[i], session, null); } aliases = translator.getProjectedAliases(); } else { result = row; aliases = userAliases; } return translator.getRootCriteria().getResultTransformer() .transformTuple(result, aliases); }
Example #8
Source File: ReactiveCollectionLoader.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 6 votes |
@Override public List<Object> getRowsFromResultSet( ResultSet rs, QueryParameters queryParameters, SharedSessionContractImplementor session, boolean returnProxies, ResultTransformer forcedResultTransformer, int maxRows, List<Object> hydratedObjects, List<EntityKey[]> subselectResultKeys) throws SQLException { return super.getRowsFromResultSet( rs, queryParameters, session, returnProxies, forcedResultTransformer, maxRows, hydratedObjects, subselectResultKeys); }
Example #9
Source File: DataBaseConfig.java From framework with Apache License 2.0 | 6 votes |
/** * Description: <br> * * @author 王伟<br> * @taskId <br> * @param dbType * @return <br> */ @Bean public AutoProxyBeanFactory registAutoProxyBeanFactory(final @Value("${master.db.type}") String dbType) { AutoProxyBeanFactory beanFactory = new AutoProxyBeanFactory(); // dao的配置 DaoConfig dataConfig = new DaoConfig(); dataConfig.setCache(true); dataConfig.setDbType(dbType); dataConfig.setBaseDaoType(BaseHibernateDao.class); dataConfig.setCallBackType(ResultTransformer.class); beanFactory.setConfig(dataConfig); beanFactory.setInterceptors("springDaoHandler"); beanFactory.setPackagesToScan(TransactionManagerHolder.getBasePackage()); return beanFactory; }
Example #10
Source File: CustomLoader.java From lams with GNU General Public License v2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") protected List getResultList(List results, ResultTransformer resultTransformer) throws QueryException { // meant to handle dynamic instantiation queries...(Copy from QueryLoader) HolderInstantiator holderInstantiator = HolderInstantiator.getHolderInstantiator( null, resultTransformer, getReturnAliasesForTransformer() ); if ( holderInstantiator.isRequired() ) { for ( int i = 0; i < results.size(); i++ ) { Object[] row = (Object[]) results.get( i ); Object result = holderInstantiator.instantiate( row ); results.set( i, result ); } return resultTransformer.transformList( results ); } else { return results; } }
Example #11
Source File: CustomLoader.java From lams with GNU General Public License v2.0 | 6 votes |
public ScrollableResultsImplementor scroll(final QueryParameters queryParameters, final SharedSessionContractImplementor session) throws HibernateException { ResultTransformer resultTransformer = queryParameters.getResultTransformer(); HolderInstantiator holderInstantiator = ( resultTransformer == null ) ? HolderInstantiator.NOOP_INSTANTIATOR : new HolderInstantiator( resultTransformer, this::getReturnAliasesForTransformer ); return scroll( queryParameters, resultTypes, holderInstantiator, session ); }
Example #12
Source File: QueryTranslatorImpl.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
protected Object getResultColumnOrRow(Object[] row, ResultTransformer transformer, ResultSet rs, SessionImplementor session) throws SQLException, HibernateException { row = toResultRow( row ); if ( hasScalars ) { String[][] scalarColumns = getColumnNames(); int queryCols = returnTypes.length; if ( holderClass == null && queryCols == 1 ) { return returnTypes[0].nullSafeGet( rs, scalarColumns[0], session, null ); } else { row = new Object[queryCols]; for ( int i = 0; i < queryCols; i++ ) row[i] = returnTypes[i].nullSafeGet( rs, scalarColumns[i], session, null ); return row; } } else if ( holderClass == null ) { return row.length == 1 ? row[0] : row; } else { return row; } }
Example #13
Source File: CustomLoader.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
protected List getResultList(List results, ResultTransformer resultTransformer) throws QueryException { // meant to handle dynamic instantiation queries...(Copy from QueryLoader) HolderInstantiator holderInstantiator = HolderInstantiator.getHolderInstantiator( null, resultTransformer, getReturnAliasesForTransformer() ); if ( holderInstantiator.isRequired() ) { for ( int i = 0; i < results.size(); i++ ) { Object[] row = ( Object[] ) results.get( i ); Object result = holderInstantiator.instantiate(row); results.set( i, result ); } return resultTransformer.transformList(results); } else { return results; } }
Example #14
Source File: QueryLoader.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
protected List getResultList(List results, ResultTransformer resultTransformer) throws QueryException { // meant to handle dynamic instantiation queries... HolderInstantiator holderInstantiator = HolderInstantiator.getHolderInstantiator(selectNewTransformer, resultTransformer, queryReturnAliases); if ( holderInstantiator.isRequired() ) { for ( int i = 0; i < results.size(); i++ ) { Object[] row = ( Object[] ) results.get( i ); Object result = holderInstantiator.instantiate(row); results.set( i, result ); } if(!hasSelectNew() && resultTransformer!=null) { return resultTransformer.transformList(results); } else { return results; } } else { return results; } }
Example #15
Source File: TopBaseService.java From ZTuoExchange_framework with MIT License | 6 votes |
/** * 原生sql 多表关联分页查询 映射Map 或者 Class * @param countSql * @param sql * @param pageModel * @param result 映射的对象 (Map 或者 Class) * @return */ public Page createNativePageQuery(StringBuilder countSql , StringBuilder sql , PageModel pageModel,ResultTransformer result){ Query query1 = entityManager.createNativeQuery(countSql.toString()); long count =((BigInteger) query1.getSingleResult()).longValue() ; if(pageModel.getProperty()!=null && pageModel.getProperty().size()>0 && pageModel.getDirection().size() == pageModel.getProperty().size()){ sql.append(" order by") ; for(int i = 0 ; i < pageModel.getProperty().size() ; i++){ sql.append(" "+pageModel.getProperty().get(i)+" "+pageModel.getDirection().get(i)+" "); if(i < pageModel.getProperty().size()-1){ sql.append(","); } } } sql.append(" limit "+pageModel.getPageSize()*(pageModel.getPageNo()-1)+" , "+pageModel.getPageSize()); javax.persistence.Query query2 = entityManager.createNativeQuery(sql.toString()); query2.unwrap(SQLQuery.class).setResultTransformer(result); List list = query2.getResultList() ; return new PageImpl<>(list,pageModel.getPageable(),count); }
Example #16
Source File: DefaultJpaRepository.java From ueboot with BSD 3-Clause "New" or "Revised" License | 6 votes |
public List findBySql(StringQuery stringQuery, ResultTransformer transformer) { Assert.notNull(stringQuery, "StringQuery must not be null!"); String sql = stringQuery.getQuery(); NamedParams params = stringQuery.getParams(); Assert.notNull(params, "NamedParams must not be null!"); Query query = em.createNativeQuery(sql); setQueryParams(query, params); NativeQuery sqlQuery = query.unwrap(NativeQuery.class); stringQuery.getScalars().forEach((s, type) -> { sqlQuery.addScalar(s, type); }); return sqlQuery.setResultTransformer(transformer).list(); }
Example #17
Source File: TopBaseService.java From ZTuoExchange_framework with MIT License | 6 votes |
/** * 原生sql 多表关联分页查询 映射Map 或者 Class * @param countSql * @param sql * @param pageModel * @param result 映射的对象 (Map 或者 Class) * @return */ public Page createNativePageQuery(StringBuilder countSql , StringBuilder sql , PageModel pageModel,ResultTransformer result){ Query query1 = entityManager.createNativeQuery(countSql.toString()); long count =((BigInteger) query1.getSingleResult()).longValue() ; if(pageModel.getProperty()!=null && pageModel.getProperty().size()>0 && pageModel.getDirection().size() == pageModel.getProperty().size()){ sql.append(" order by") ; for(int i = 0 ; i < pageModel.getProperty().size() ; i++){ sql.append(" "+pageModel.getProperty().get(i)+" "+pageModel.getDirection().get(i)+" "); if(i < pageModel.getProperty().size()-1){ sql.append(","); } } } sql.append(" limit "+pageModel.getPageSize()*(pageModel.getPageNo()-1)+" , "+pageModel.getPageSize()); javax.persistence.Query query2 = entityManager.createNativeQuery(sql.toString()); query2.unwrap(SQLQuery.class).setResultTransformer(result); List list = query2.getResultList() ; return new PageImpl<>(list,pageModel.getPageable(),count); }
Example #18
Source File: CustomLoader.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
protected Object getResultColumnOrRow( Object[] row, ResultTransformer transformer, ResultSet rs, SessionImplementor session) throws SQLException, HibernateException { return rowProcessor.buildResultRow( row, rs, transformer != null, session ); }
Example #19
Source File: QueryLoader.java From lams with GNU General Public License v2.0 | 5 votes |
private HolderInstantiator buildHolderInstantiator(ResultTransformer queryLocalResultTransformer) { final ResultTransformer implicitResultTransformer = aggregatedSelectExpression == null ? null : aggregatedSelectExpression.getResultTransformer(); return HolderInstantiator.getHolderInstantiator( implicitResultTransformer, queryLocalResultTransformer, queryReturnAliases ); }
Example #20
Source File: Loader.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Get the actual object that is returned in the user-visible result list. * This empty implementation merely returns its first argument. This is * overridden by some subclasses. */ protected Object getResultColumnOrRow( Object[] row, ResultTransformer transformer, ResultSet rs, SharedSessionContractImplementor session) throws SQLException, HibernateException { return row; }
Example #21
Source File: Loader.java From lams with GNU General Public License v2.0 | 5 votes |
private List doList( final SharedSessionContractImplementor session, final QueryParameters queryParameters, final ResultTransformer forcedResultTransformer) throws HibernateException { final boolean stats = getFactory().getStatistics().isStatisticsEnabled(); long startTime = 0; if ( stats ) { startTime = System.nanoTime(); } List result; try { result = doQueryAndInitializeNonLazyCollections( session, queryParameters, true, forcedResultTransformer ); } catch (SQLException sqle) { throw factory.getJdbcServices().getSqlExceptionHelper().convert( sqle, "could not execute query", getSQLString() ); } if ( stats ) { final long endTime = System.nanoTime(); final long milliseconds = TimeUnit.MILLISECONDS.convert( endTime - startTime, TimeUnit.NANOSECONDS ); getFactory().getStatistics().queryExecuted( getQueryIdentifier(), result.size(), milliseconds ); } return result; }
Example #22
Source File: QueryTranslatorImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override protected Object getResultColumnOrRow( Object[] row, ResultTransformer transformer, ResultSet rs, SharedSessionContractImplementor session) throws SQLException, HibernateException { Object[] resultRow = getResultRow( row, rs, session ); return ( holderClass == null && resultRow.length == 1 ? resultRow[0] : resultRow ); }
Example #23
Source File: AbstractHibernateCriteriaBuilder.java From gorm-hibernate5 with Apache License 2.0 | 5 votes |
/** * Sets the resultTransformer. * @param transformer The result transformer to use. */ public void resultTransformer(ResultTransformer transformer) { if (criteria == null) { throwRuntimeException(new IllegalArgumentException("Call to [resultTransformer] not supported here")); } resultTransformer = transformer; }
Example #24
Source File: CollectionElementLoader.java From lams with GNU General Public License v2.0 | 5 votes |
@Override protected Object getResultColumnOrRow( Object[] row, ResultTransformer transformer, ResultSet rs, SharedSessionContractImplementor session) throws SQLException, HibernateException { return row[row.length - 1]; }
Example #25
Source File: QueryTranslatorImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override protected List getResultList(List results, ResultTransformer resultTransformer) throws QueryException { if ( holderClass != null ) { for ( int i = 0; i < results.size(); i++ ) { Object[] row = (Object[]) results.get( i ); try { results.set( i, holderConstructor.newInstance( row ) ); } catch (Exception e) { throw new QueryException( "could not instantiate: " + holderClass, e ); } } } return results; }
Example #26
Source File: QueryParameters.java From lams with GNU General Public License v2.0 | 5 votes |
public QueryParameters( final Type[] positionalParameterTypes, final Object[] positionalParameterValues, final Map<String,TypedValue> namedParameters, final LockOptions lockOptions, final RowSelection rowSelection, final boolean isReadOnlyInitialized, final boolean readOnly, final boolean cacheable, final String cacheRegion, //final boolean forceCacheRefresh, final String comment, final List<String> queryHints, final Serializable[] collectionKeys, ResultTransformer transformer) { this.positionalParameterTypes = positionalParameterTypes; this.positionalParameterValues = positionalParameterValues; this.namedParameters = namedParameters; this.lockOptions = lockOptions; this.rowSelection = rowSelection; this.cacheable = cacheable; this.cacheRegion = cacheRegion; //this.forceCacheRefresh = forceCacheRefresh; this.comment = comment; this.queryHints = queryHints; this.collectionKeys = collectionKeys; this.isReadOnlyInitialized = isReadOnlyInitialized; this.readOnly = readOnly; this.resultTransformer = transformer; }
Example #27
Source File: QueryParameters.java From lams with GNU General Public License v2.0 | 5 votes |
public QueryParameters( final Type[] positionalParameterTypes, final Object[] positionalParameterValues, final Map<String,TypedValue> namedParameters, final LockOptions lockOptions, final RowSelection rowSelection, final boolean isReadOnlyInitialized, final boolean readOnly, final boolean cacheable, final String cacheRegion, //final boolean forceCacheRefresh, final String comment, final List<String> queryHints, final Serializable[] collectionKeys, final Object optionalObject, final String optionalEntityName, final Serializable optionalId, final ResultTransformer transformer) { this( positionalParameterTypes, positionalParameterValues, namedParameters, lockOptions, rowSelection, isReadOnlyInitialized, readOnly, cacheable, cacheRegion, comment, queryHints, collectionKeys, transformer ); this.optionalEntityName = optionalEntityName; this.optionalId = optionalId; this.optionalObject = optionalObject; }
Example #28
Source File: CollectionElementLoader.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
protected Object getResultColumnOrRow( Object[] row, ResultTransformer transformer, ResultSet rs, SessionImplementor session) throws SQLException, HibernateException { return row[row.length-1]; }
Example #29
Source File: ReactiveAbstractEntityLoader.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 5 votes |
@Override public List<Object> processResultSet(ResultSet resultSet, QueryParameters queryParameters, SharedSessionContractImplementor session, boolean returnProxies, ResultTransformer forcedResultTransformer, int maxRows, List<AfterLoadAction> afterLoadActions) throws SQLException { throw new UnsupportedOperationException( "use #reactiveProcessResultSet instead." ); }
Example #30
Source File: QueryTranslatorImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override protected ResultTransformer resolveResultTransformer(ResultTransformer resultTransformer) { return HolderInstantiator.resolveClassicResultTransformer( holderConstructor, resultTransformer ); }