@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; } }
@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; } }
protected List executeLoad( SessionImplementor session, QueryParameters queryParameters, LoadQueryDetails loadQueryDetails, boolean returnProxies, ResultTransformer forcedResultTransformer) throws SQLException { final List<AfterLoadAction> afterLoadActions = new ArrayList<AfterLoadAction>(); return executeLoad( session, queryParameters, loadQueryDetails, returnProxies, forcedResultTransformer, afterLoadActions ); }
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); }
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; } }
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; } }
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; } }
/** * Transform to bean. See bug * http://opensource.atlassian.com/projects/hibernate/browse/HHH-2463 * * @param aliasList * the alias list * @param resultList * the result list * * @return the list of GisFeatureDistance */ //TODO tests zip test public static List<GisFeatureDistance> transformToGisFeatureDistance(String aliasList[], List<?> resultList, Map<Long, Set<String>> featureIdToZipCodesMap,Class clazz) { List<GisFeatureDistance> results = new ArrayList<GisFeatureDistance>(); if (aliasList != null && !resultList.isEmpty()) { ResultTransformer tr = new AliasToBeanResultTransformer(GisFeatureDistance.class); Iterator<?> it = resultList.iterator(); Object[] obj; GisFeatureDistance gisFeatureDistance; while (it.hasNext()) { obj = (Object[]) it.next(); gisFeatureDistance = (GisFeatureDistance) tr.transformTuple(obj, aliasList); int indexInList = results.indexOf(gisFeatureDistance); if (indexInList == -1) { gisFeatureDistanceFactory.updateFields(gisFeatureDistance,clazz); results.add(gisFeatureDistance); if (featureIdToZipCodesMap != null){ gisFeatureDistance.setZipCodes(featureIdToZipCodesMap.get(gisFeatureDistance.getId())); } } } } return results; }
private static ResultTransformer getAlarmDefResultTransformer() { return new ResultTransformer() { private static final long serialVersionUID = -3052468375925339521L; @Override public Object transformTuple(final Object[] tuple, final String[] aliases) { for (int i = 0, length = aliases.length; i < length; i++) { aliases[i] = aliases[i].toUpperCase(); } return AliasToEntityMapResultTransformer .INSTANCE .transformTuple(tuple, aliases); } @Override public List transformList(final List collection) { return AliasToEntityMapResultTransformer .INSTANCE .transformList(collection); } }; }
public PageResponse<Code> searchType(PageRequest request) { Query query = super.createQuery("FROM WizardCode WHERE typeId = '0'"); query.setResultTransformer(new ResultTransformer() { private static final long serialVersionUID = 1L; @Override public Object transformTuple(Object[] tuple, String[] aliases) { WizardCode wizardCode = (WizardCode) tuple[0]; Code code = new Code(); code.setPkId(wizardCode.getPkId()); code.setNewId(wizardCode.getPkId()); code.setTypeId(wizardCode.getTypeId()); code.setContent(wizardCode.getContent()); return code; } @Override @SuppressWarnings("rawtypes") public List transformList(List collection) { return collection; } }); return super.pageQuery(query, request); }
private static final SQLQuery bindTransformer(SQLQuery q, NativeQuery<?> query) { String[] retvals = newArray(String.class, map(Transformers.<String>left(), query.retvals)); final OptionResultTransformer resultTransformer = new OptionResultTransformer(query.retvals); if (query instanceof NativeQuery.NativeQuerySingleEntity || query instanceof NativeQuery.NativeQueryT1 || query instanceof NativeQuery.NativeQueryVoid) { q.setResultTransformer(resultTransformer); } else { final TupleResultTransformer tupleResultTransformer = new TupleResultTransformer(retvals); q.setResultTransformer(new ResultTransformer() { @Override public Object transformTuple(Object[] tuple, String[] aliases) { Object[] ret = (Object[]) resultTransformer.transformTuple(tuple, aliases); return tupleResultTransformer.transformTuple(ret, aliases); } @SuppressWarnings("rawtypes") @Override public List transformList(List collection) { return collection; } }); } return q; }
@Override protected Object getResultColumnOrRow( Object[] row, ResultTransformer transformer, ResultSet rs, SessionImplementor session) throws SQLException, HibernateException { return row[row.length-1]; }
@Override protected Object getResultColumnOrRow(Object[] row, ResultTransformer transformer, ResultSet rs, SessionImplementor session) throws SQLException, HibernateException { return resolveResultTransformer( transformer ).transformTuple( getResultRow( row, rs, session), getResultRowAliases() ); }
static private HolderInstantiator getHolderInstantiator(ResultTransformer resultTransformer, String[] queryReturnAliases) { if ( resultTransformer == null ) { return HolderInstantiator.NOOP_INSTANTIATOR; } else { return new HolderInstantiator(resultTransformer, queryReturnAliases); } }
@Override protected Object getResultColumnOrRow( Object[] row, ResultTransformer transformer, ResultSet rs, SessionImplementor session) throws SQLException, HibernateException { return rowProcessor.buildResultRow( row, rs, transformer != null, session ); }
public List doQueryAndInitializeNonLazyCollections( final SessionImplementor session, final QueryParameters queryParameters, final boolean returnProxies, final ResultTransformer forcedResultTransformer) throws HibernateException, SQLException { final PersistenceContext persistenceContext = session.getPersistenceContext(); boolean defaultReadOnlyOrig = persistenceContext.isDefaultReadOnly(); if ( queryParameters.isReadOnlyInitialized() ) { // The read-only/modifiable mode for the query was explicitly set. // Temporarily set the default read-only/modifiable setting to the query's setting. persistenceContext.setDefaultReadOnly( queryParameters.isReadOnly() ); } else { // The read-only/modifiable setting for the query was not initialized. // Use the default read-only/modifiable from the persistence context instead. queryParameters.setReadOnly( persistenceContext.isDefaultReadOnly() ); } persistenceContext.beforeLoad(); List result; try { try { result = doQuery( session, queryParameters, returnProxies, forcedResultTransformer ); } finally { persistenceContext.afterLoad(); } persistenceContext.initializeNonLazyCollections(); } finally { // Restore the original default persistenceContext.setDefaultReadOnly( defaultReadOnlyOrig ); } return result; }
private List doQuery( final SessionImplementor session, final QueryParameters queryParameters, final boolean returnProxies, final ResultTransformer forcedResultTransformer) throws SQLException, HibernateException { final RowSelection selection = queryParameters.getRowSelection(); final int maxRows = LimitHelper.hasMaxRows( selection ) ? selection.getMaxRows() : Integer.MAX_VALUE; final List<AfterLoadAction> afterLoadActions = new ArrayList<AfterLoadAction>(); final SqlStatementWrapper wrapper = executeQueryStatement( queryParameters, false, afterLoadActions, session ); final ResultSet rs = wrapper.getResultSet(); final Statement st = wrapper.getStatement(); // would be great to move all this below here into another method that could also be used // from the new scrolling stuff. // // Would need to change the way the max-row stuff is handled (i.e. behind an interface) so // that I could do the control breaking at the means to know when to stop try { return processResultSet( rs, queryParameters, session, returnProxies, forcedResultTransformer, maxRows, afterLoadActions ); } finally { session.getTransactionCoordinator().getJdbcCoordinator().release( st ); } }
/** * 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, SessionImplementor session) throws SQLException, HibernateException { return row; }
private List doList(final SessionImplementor 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.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().getStatisticsImplementor().queryExecuted( getQueryIdentifier(), result.size(), milliseconds ); } return result; }
@Override protected ResultTransformer resolveResultTransformer(ResultTransformer resultTransformer) { final ResultTransformer implicitResultTransformer = aggregatedSelectExpression == null ? null : aggregatedSelectExpression.getResultTransformer(); return HolderInstantiator.resolveResultTransformer( implicitResultTransformer, resultTransformer ); }
@Override protected Object getResultColumnOrRow(Object[] row, ResultTransformer transformer, ResultSet rs, SessionImplementor session) throws SQLException, HibernateException { Object[] resultRow = getResultRow( row, rs, session ); boolean hasTransform = hasSelectNew() || transformer!=null; return ( ! hasTransform && resultRow.length == 1 ? resultRow[ 0 ] : resultRow ); }
private HolderInstantiator buildHolderInstantiator(ResultTransformer queryLocalResultTransformer) { final ResultTransformer implicitResultTransformer = aggregatedSelectExpression == null ? null : aggregatedSelectExpression.getResultTransformer(); return HolderInstantiator.getHolderInstantiator( implicitResultTransformer, queryLocalResultTransformer, queryReturnAliases ); }
public QueryParameters( final Type[] positionalParameterTypes, final Object[] positionalParameterValues, 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 boolean isLookupByNaturalKey, final ResultTransformer transformer) { this( positionalParameterTypes, positionalParameterValues, null, lockOptions, rowSelection, isReadOnlyInitialized, readOnly, cacheable, cacheRegion, comment, queryHints, null, transformer ); isNaturalKeyLookup = isLookupByNaturalKey; }
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; }
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; }
@Override public ResultTransformer getResultTransformer() { if ( constructor != null ) { return new AliasToBeanConstructorResultTransformer( constructor ); } else if ( isMap ) { return Transformers.ALIAS_TO_ENTITY_MAP; } else if ( isList ) { return Transformers.TO_LIST; } throw new QueryException( "Unable to determine proper dynamic-instantiation tranformer to use." ); }
public static ResultTransformer createSelectNewTransformer(Constructor constructor, boolean returnMaps, boolean returnLists) { if ( constructor != null ) { return new AliasToBeanConstructorResultTransformer(constructor); } else if ( returnMaps ) { return Transformers.ALIAS_TO_ENTITY_MAP; } else if ( returnLists ) { return Transformers.TO_LIST; } else { return null; } }
public HolderInstantiator( ResultTransformer transformer, String[] queryReturnAliases ) { this.transformer = transformer; this.queryReturnAliases = queryReturnAliases; }
@Override protected ResultTransformer resolveResultTransformer(ResultTransformer resultTransformer) { return HolderInstantiator.resolveClassicResultTransformer( holderConstructor, resultTransformer ); }
@Override protected Object getResultColumnOrRow(Object[] row, ResultTransformer transformer, ResultSet rs, SessionImplementor session) throws SQLException, HibernateException { Object[] resultRow = getResultRow( row, rs, session ); return ( holderClass == null && resultRow.length == 1 ? resultRow[ 0 ] : resultRow ); }
@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; }
@Override public ResultTransformer getResultTransformer() { return new BasicTransformerAdapter() { @Override public Object transformTuple(Object[] tuple, String[] aliases) { return new GetObjectResult((String) tuple[0], (byte[]) tuple[1], tuple.length > 2 ? (Short) tuple[2] : null, tuple.length > 3 ? (Short) tuple[3] : null, tuple.length > 4 ? (Short) tuple[4] : null, tuple.length > 5 ? (Short) tuple[5] : null, tuple.length > 6 ? (Short) tuple[6] : null, tuple.length > 7 ? (Short) tuple[7] : null); } }; }
@Override public ResultTransformer getResultTransformer() { return new BasicTransformerAdapter() { @Override public Object transformTuple(Object[] tuple, String[] aliases) { return new GetContainerableResult((String) tuple[0], (byte[]) tuple[2]); } }; }
@Override public ResultTransformer getResultTransformer() { return new BasicTransformerAdapter() { @Override public Object transformTuple(Object[] tuple, String[] aliases) { return new GetCertificationWorkItemResult((String) tuple[0], (Integer) tuple[1], (Integer) tuple[2]); } }; }
@Override protected List<ColumnInfoDTO> getColumnsInfoFromTable(String table) { String query = "SELECT OWNER, COLUMN_NAME, DATA_TYPE, CHAR_LENGTH, DATA_PRECISION, TABLE_NAME, DATA_LENGTH, NULLABLE " + " FROM SYS.ALL_TAB_COLS " + " WHERE TABLE_NAME = :nome_tabela"; SQLQuery querySQL = getSession().createSQLQuery(query); querySQL.setParameter("nome_tabela", table); querySQL.setResultTransformer(new ResultTransformer() { @Override public Object transformTuple(Object[] obj, String[] arg1) { ColumnInfoDTO column = new ColumnInfoDTO(); int i=0; column.setSchema((String) obj[i]); column.setColumnName((String) obj[++i]); column.setDataType((String) obj[++i]); column.setCharLength((BigDecimal) obj[++i]); column.setDataPrecision((BigDecimal) obj[++i]); column.setTableName((String) obj[++i]); column.setDataLength((BigDecimal) obj[++i]); column.setNullable("Y".equals((String) obj[++i])); column.setFoundDataBase(true); return column; } @Override public List transformList(List list) { return list; } }); return querySQL.list(); }
@Override protected SequenceInfoDTO getSequenceInfoDTO(String sequenceName) { String query = "SELECT " + " seq.SEQUENCE_NAME, seq.LAST_NUMBER, seq.MIN_VALUE, seq.MAX_VALUE, seq.INCREMENT_BY " + " FROM SYS.ALL_SEQUENCES seq " + " WHERE seq.SEQUENCE_NAME = :sequence_name"; SQLQuery querySQL = getSession().createSQLQuery(query); querySQL.setParameter("sequence_name", sequenceName); querySQL.setResultTransformer(new ResultTransformer() { @Override public Object transformTuple(Object[] arg0, String[] arg1) { SequenceInfoDTO info = new SequenceInfoDTO(); int i=0; info.setSequenceName((String) arg0[i]); info.setCurrentValue((BigDecimal) arg0[++i]); info.setMinValue((BigDecimal) arg0[++i]); info.setMaxValue((BigDecimal) arg0[++i]); info.setIncrement((BigDecimal) arg0[++i]); info.setFound(true); return info; } @Override public List transformList(List list) { return list; } }); return (SequenceInfoDTO) querySQL.uniqueResult(); }
protected Object getResultColumnOrRow( Object[] row, ResultTransformer transformer, ResultSet rs, SessionImplementor session) throws SQLException, HibernateException { return row[row.length-1]; }
static private HolderInstantiator getHolderInstantiator(ResultTransformer resultTransformer, String[] queryReturnAliases) { if ( resultTransformer != null ) { return HolderInstantiator.NOOP_INSTANTIATOR; } else { return new HolderInstantiator(resultTransformer, queryReturnAliases); } }
protected Object getResultColumnOrRow( Object[] row, ResultTransformer transformer, ResultSet rs, SessionImplementor session) throws SQLException, HibernateException { return rowProcessor.buildResultRow( row, rs, transformer != null, session ); }
protected Object getResultColumnOrRow(Object[] row, ResultTransformer transformer, ResultSet rs, SessionImplementor session) throws SQLException, HibernateException { row = toResultRow( row ); boolean hasTransform = hasSelectNew() || transformer!=null; if ( hasScalars ) { String[][] scalarColumns = scalarColumnNames; int queryCols = queryReturnTypes.length; if ( !hasTransform && queryCols == 1 ) { return queryReturnTypes[0].nullSafeGet( rs, scalarColumns[0], session, null ); } else { row = new Object[queryCols]; for ( int i = 0; i < queryCols; i++ ) { row[i] = queryReturnTypes[i].nullSafeGet( rs, scalarColumns[i], session, null ); } return row; } } else if ( !hasTransform ) { return row.length == 1 ? row[0] : row; } else { return row; } }