Example usage for org.hibernate.criterion ProjectionList getProjection

List of usage examples for org.hibernate.criterion ProjectionList getProjection

Introduction

In this page you can find the example usage for org.hibernate.criterion ProjectionList getProjection.

Prototype

@SuppressWarnings("UnusedDeclaration")
public Projection getProjection(int i) 

Source Link

Document

Access a wrapped projection by index

Usage

From source file:com.amalto.core.storage.hibernate.StandardQueryHandler.java

License:Open Source License

private ProjectionList optimizeProjectionList(ComplexTypeMetadata mainType, ProjectionList oldProjectionList) {
    ProjectionList newProjectionList = null;
    RDBMSDataSource dataSource = (RDBMSDataSource) storage.getDataSource();
    if (dataSource.getDialectName() != RDBMSDataSource.DataSourceDialect.ORACLE_10G) {
        newProjectionList = oldProjectionList;
        for (FieldMetadata keyField : mainType.getKeyFields()) {
            newProjectionList.add(Projections.groupProperty(keyField.getName()));
        }/*from  w ww .j  ava  2  s . c  om*/
    } else { // ORACLE need to GROUP BY all selected fields
        newProjectionList = Projections.projectionList();
        Set<String> groupBys = new LinkedHashSet<String>();// GROUP BY fields
        ProjectionList extraProjectionList = Projections.projectionList();
        for (int i = 0; i < oldProjectionList.getLength(); i++) {
            String propertyName = null;
            Projection oldProjection = oldProjectionList.getProjection(i);
            if (oldProjection instanceof SQLProjection) { // Group Size
                newProjectionList.add(oldProjection);
            } else if (oldProjection instanceof PropertyProjection) {// normal fields
                propertyName = ((PropertyProjection) oldProjection).getPropertyName();
                newProjectionList.add(Projections.groupProperty(propertyName));
            } else if (oldProjection instanceof AggregateProjection) {// Max, Min
                propertyName = ((AggregateProjection) oldProjection).getPropertyName();
                newProjectionList.add(oldProjection);
                extraProjectionList.add(Projections.groupProperty(propertyName));
            }
            if (propertyName != null) {
                groupBys.add(propertyName);
            }
        }
        // Add key fields to GROUP BY
        for (FieldMetadata keyField : mainType.getKeyFields()) {
            String keyFieldName = mainType.getName() + '.' + keyField.getName();
            if (!groupBys.contains(keyFieldName)) {
                extraProjectionList.add(Projections.groupProperty(keyFieldName));
            }
        }
        for (int i = 0; i < extraProjectionList.getLength(); i++) {
            newProjectionList.add(extraProjectionList.getProjection(i));
        }
    }
    return newProjectionList;
}

From source file:com.jaspersoft.jasperserver.api.search.SearchCriteria.java

License:Open Source License

private Projection addProjectionToList(ProjectionList projectionList, Projection newProjection) {
    if (newProjection instanceof ProjectionList) {
        ProjectionList newProjectionList = ((ProjectionList) newProjection);

        for (int i = 0; i < newProjectionList.getLength(); i++) {
            projectionList.add(newProjectionList.getProjection(i));
        }/*from  w w  w. j  a va 2s.  co  m*/
    } else {
        projectionList.add(newProjection);
    }

    return projectionList;
}