/** * Creates a data source out of the query result. * * @return the data source */ protected JRDataSource createResultDatasource() { JRDataSource resDatasource; String runType = JRProperties.getProperty( dataset, JRHibernateQueryExecuterFactory.PROPERTY_HIBERNATE_QUERY_RUN_TYPE); boolean useFieldDescriptions = JRProperties.getBooleanProperty( dataset, JRHibernateQueryExecuterFactory.PROPERTY_HIBERNATE_FIELD_MAPPING_DESCRIPTIONS, true); if (runType == null || runType.equals(JRHibernateQueryExecuterFactory.VALUE_HIBERNATE_QUERY_RUN_TYPE_LIST)) { try { int pageSize = JRProperties.getIntegerProperty( dataset, JRHibernateQueryExecuterFactory.PROPERTY_HIBERNATE_QUERY_LIST_PAGE_SIZE, 0); resDatasource = new JRHibernateListDataSource(this, useFieldDescriptions, pageSize); } catch (NumberFormatException e) { throw new JRRuntimeException( "The " + JRHibernateQueryExecuterFactory.PROPERTY_HIBERNATE_QUERY_LIST_PAGE_SIZE + " property must be numerical.", e); } } else if (runType.equals( JRHibernateQueryExecuterFactory.VALUE_HIBERNATE_QUERY_RUN_TYPE_ITERATE)) { resDatasource = new JRHibernateIterateDataSource(this, useFieldDescriptions); } else if (runType.equals( JRHibernateQueryExecuterFactory.VALUE_HIBERNATE_QUERY_RUN_TYPE_SCROLL)) { resDatasource = new JRHibernateScrollDataSource(this, useFieldDescriptions); } else { throw new JRRuntimeException( "Unknown value for the " + JRHibernateQueryExecuterFactory.PROPERTY_HIBERNATE_QUERY_RUN_TYPE + " property. Possible values are " + JRHibernateQueryExecuterFactory.VALUE_HIBERNATE_QUERY_RUN_TYPE_LIST + ", " + JRHibernateQueryExecuterFactory.VALUE_HIBERNATE_QUERY_RUN_TYPE_ITERATE + " and " + JRHibernateQueryExecuterFactory.VALUE_HIBERNATE_QUERY_RUN_TYPE_SCROLL + "."); } return resDatasource; }
/** * Creates a crosstab bucketing engine. * * @param rowBuckets the row bucket definitions * @param columnBuckets the column bucket definitions * @param measures the measure definitions * @param sorted whether the data is presorted * @param retrieveTotal totals to retrieve along with the cell values */ public BucketingService( List rowBuckets, List columnBuckets, List measures, boolean sorted, boolean[][] retrieveTotal) { this.sorted = sorted; buckets = new BucketDefinition[DIMENSIONS][]; rowBucketCount = rowBuckets.size(); buckets[DIMENSION_ROW] = new BucketDefinition[rowBucketCount]; rowBuckets.toArray(buckets[DIMENSION_ROW]); colBucketCount = columnBuckets.size(); buckets[DIMENSION_COLUMN] = new BucketDefinition[colBucketCount]; columnBuckets.toArray(buckets[DIMENSION_COLUMN]); allBuckets = new BucketDefinition[rowBucketCount + colBucketCount]; System.arraycopy(buckets[DIMENSION_ROW], 0, allBuckets, 0, rowBucketCount); System.arraycopy(buckets[DIMENSION_COLUMN], 0, allBuckets, rowBucketCount, colBucketCount); origMeasureCount = measures.size(); List measuresList = new ArrayList(measures.size() * 2); List measureIndexList = new ArrayList(measures.size() * 2); for (int i = 0; i < measures.size(); ++i) { MeasureDefinition measure = (MeasureDefinition) measures.get(i); addMeasure(measure, i, measuresList, measureIndexList); } this.measures = new MeasureDefinition[measuresList.size()]; measuresList.toArray(this.measures); this.measureIndexes = new int[measureIndexList.size()]; for (int i = 0; i < measureIndexes.length; ++i) { measureIndexes[i] = ((Integer) measureIndexList.get(i)).intValue(); } this.retrieveTotal = retrieveTotal; checkTotals(); bucketValueMap = createBucketMap(0); zeroUserMeasureValues = initUserMeasureValues(); bucketMeasureLimit = JRProperties.getIntegerProperty(PROPERTY_BUCKET_MEASURE_LIMIT, 0); }
/** * Creates the Hibernate query object. * * <p>If the value of the {@link * JRHibernateQueryExecuterFactory#PARAMETER_HIBERNATE_FILTER_COLLECTION * PARAMETER_HIBERNATE_FILTER_COLLECTION} is not null, then a filter query is created using the * value of the parameter as the collection. * * @param queryString the query string */ protected synchronized void createQuery(String queryString) { if (log.isDebugEnabled()) { log.debug("HQL query: " + queryString); } Object filterCollection = getParameterValue(JRHibernateQueryExecuterFactory.PARAMETER_HIBERNATE_FILTER_COLLECTION); if (filterCollection == null) { query = session.createQuery(queryString); } else { query = session.createFilter(filterCollection, queryString); } query.setReadOnly(true); int fetchSize = JRProperties.getIntegerProperty( dataset, JRJdbcQueryExecuterFactory.PROPERTY_JDBC_FETCH_SIZE, 0); if (fetchSize != 0) { query.setFetchSize(fetchSize); } setParameters(); }