/** * INTERNAL: * Method used to abstract addToConstructorItem behavour from the public addItem methods */ private void addItem(ReportItem item){ if (this.addToConstructorItem && (getItems().size() > 0) && (getItems().get(getItems().size() - 1).isConstructorItem())) { ((ConstructorReportItem)getItems().get(getItems().size() - 1)).addItem(item); } else { getItems().add(item); } //Bug2804042 Must un-prepare if prepared as the SQL may change. setIsPrepared(false); }
/** * INTERNAL: * Method used to abstract addToConstructorItem behavour from the public addItem methods */ private void addItem(ReportItem item){ if (this.addToConstructorItem && (getItems().size() > 0) && (getItems().get(getItems().size() - 1).isConstructorItem())) { ((ConstructorReportItem)getItems().get(getItems().size() - 1)).addItem(item); } else { getItems().add(item); } //Bug2804042 Must un-prepare if prepared as the SQL may change. setIsPrepared(false); }
/** * INTERNAL: * Method used to abstract addToConstructorItem behavour from the public addItem methods */ private void addItem(ReportItem item){ if (this.addToConstructorItem && (getItems().size() > 0) && (getItems().get(getItems().size() - 1).isConstructorItem())) { ((ConstructorReportItem)getItems().get(getItems().size() - 1)).addItem(item); } else { getItems().add(item); } //Bug2804042 Must un-prepare if prepared as the SQL may change. setIsPrepared(false); }
/** * INTERNAL: * Prepare a report query with a count defined on an object attribute. * Added to fix bug 3268040, addCount(objectAttribute) not supported. */ protected void prepareObjectAttributeCount(Map clonedExpressions) { prepareObjectAttributeCount(getItems(), clonedExpressions); }
/** * INTERNAL: * Prepare a report query with a count defined on an object attribute. * Added to fix bug 3268040, addCount(objectAttribute) not supported. */ protected void prepareObjectAttributeCount(Map clonedExpressions) { prepareObjectAttributeCount(getItems(), clonedExpressions); }
/** * INTERNAL: * Prepare a report query with a count defined on an object attribute. * Added to fix bug 3268040, addCount(objectAttribute) not supported. */ protected void prepareObjectAttributeCount(Map clonedExpressions) { prepareObjectAttributeCount(getItems(), clonedExpressions); }
/** * INTERNAL: * Lazily initialize and return the names of the items requested for use in each result object. */ public List<String> getNames() { if (this.names == null) { this.names = new ArrayList<String>(); for (ReportItem item : getItems()) { this.names.add(item.getName()); } } return this.names; }
/** * INTERNAL: * Lazily initialize and return the names of the items requested for use in each result object. */ public List<String> getNames() { if (this.names == null) { this.names = new ArrayList<String>(); for (ReportItem item : getItems()) { this.names.add(item.getName()); } } return this.names; }
/** * INTERNAL: * Lazily initialize and return the names of the items requested for use in each result object. */ public List<String> getNames() { if (this.names == null) { this.names = new ArrayList<String>(); for (ReportItem item : getItems()) { this.names.add(item.getName()); } } return this.names; }
/** * PUBLIC: Call a constructor for the given class with the results of this query. * @param constructorClass */ public ConstructorReportItem beginAddingConstructorArguments(Class constructorClass){ ConstructorReportItem citem = new ConstructorReportItem(constructorClass.getName()); citem.setResultType(constructorClass); //add directly to avoid addToConstructorItem behavior getItems().add(citem); //Bug2804042 Must un-prepare if prepared as the SQL may change. setIsPrepared(false); this.addToConstructorItem=true; return citem; } /**
/** * PUBLIC: Call a constructor for the given class with the results of this query. * @param constructorClass */ public ConstructorReportItem beginAddingConstructorArguments(Class constructorClass){ ConstructorReportItem citem = new ConstructorReportItem(constructorClass.getName()); citem.setResultType(constructorClass); //add directly to avoid addToConstructorItem behavior getItems().add(citem); //Bug2804042 Must un-prepare if prepared as the SQL may change. setIsPrepared(false); this.addToConstructorItem=true; return citem; } /**
/** * PUBLIC: Call a constructor for the given class with the results of this query. * @param constructorClass */ public ConstructorReportItem beginAddingConstructorArguments(Class constructorClass){ ConstructorReportItem citem = new ConstructorReportItem(constructorClass.getName()); citem.setResultType(constructorClass); //add directly to avoid addToConstructorItem behavior getItems().add(citem); //Bug2804042 Must un-prepare if prepared as the SQL may change. setIsPrepared(false); this.addToConstructorItem=true; return citem; } /**
/** * INTERNAL: * return a collection of expressions if PK's are used. */ public Vector getQueryExpressions() { Vector fieldExpressions = NonSynchronizedVector.newInstance(getItems().size()); // For bug 3115576 and an EXISTS subquery only need to return a single field. if (shouldRetrieveFirstPrimaryKey()) { if (!getDescriptor().getPrimaryKeyFields().isEmpty()) { fieldExpressions.addElement(getDescriptor().getPrimaryKeyFields().get(0)); } } if (shouldRetrievePrimaryKeys()) { fieldExpressions.addAll(getDescriptor().getPrimaryKeyFields()); } return fieldExpressions; }
/** * INTERNAL: * return a collection of expressions if PK's are used. */ public Vector getQueryExpressions() { Vector fieldExpressions = NonSynchronizedVector.newInstance(getItems().size()); if (shouldSelectValue1()) { Expression one = new ConstantExpression(new Integer(1), new ExpressionBuilder()); this.addItem("one", one); this.dontUseDistinct(); fieldExpressions.addElement(one); } else // For bug 3115576 and an EXISTS subquery only need to return a single field. if (shouldRetrieveFirstPrimaryKey()) { if (!getDescriptor().getPrimaryKeyFields().isEmpty()) { fieldExpressions.addElement(getDescriptor().getPrimaryKeyFields().get(0)); } } if (shouldRetrievePrimaryKeys()) { fieldExpressions.addAll(getDescriptor().getPrimaryKeyFields()); } return fieldExpressions; }
/** * Prepare the report items. * Indexes of results need to be calculated. */ protected void prepareReportQueryItems(){ //calculate indexes after normalize to insure expressions are set up correctly //take into account any field expressions added to the ReportQuery ReportQuery query = (ReportQuery)getQuery(); int itemOffset = query.getQueryExpressions().size(); for (Iterator items = query.getItems().iterator(); items.hasNext();) { ReportItem item = (ReportItem) items.next(); item.setResultIndex(itemOffset); if (item.getAttributeExpression() != null) { if (item.hasJoining()){ itemOffset = item.getJoinedAttributeManager().computeJoiningMappingIndexes(true, getSession(), itemOffset); } else { if (item.getDescriptor() != null) { itemOffset += item.getDescriptor().getAllSelectionFields(query).size(); } else { ++itemOffset; //only a single attribute can be selected } } } } }
/** * INTERNAL: * return a collection of expressions if PK's are used. */ public Vector getQueryExpressions() { Vector fieldExpressions = NonSynchronizedVector.newInstance(getItems().size()); if (shouldSelectValue1()) { Expression one = new ConstantExpression(Integer.valueOf(1), new ExpressionBuilder()); this.addItem("one", one); this.dontUseDistinct(); fieldExpressions.addElement(one); } else // For bug 3115576 and an EXISTS subquery only need to return a single field. if (shouldRetrieveFirstPrimaryKey()) { if (!getDescriptor().getPrimaryKeyFields().isEmpty()) { fieldExpressions.addElement(getDescriptor().getPrimaryKeyFields().get(0)); } } if (shouldRetrievePrimaryKeys()) { fieldExpressions.addAll(getDescriptor().getPrimaryKeyFields()); } return fieldExpressions; }
/** * Prepare the report items. * Indexes of results need to be calculated. */ protected void prepareReportQueryItems(){ //calculate indexes after normalize to insure expressions are set up correctly int itemOffset = 0; for (Iterator items = ((ReportQuery)getQuery()).getItems().iterator(); items.hasNext();) { ReportItem item = (ReportItem) items.next(); item.setResultIndex(itemOffset); if (item.getAttributeExpression() != null) { if (item.hasJoining()){ itemOffset = item.getJoinedAttributeManager().computeJoiningMappingIndexes(true, getSession(), itemOffset); } else { if (item.getDescriptor() != null) { itemOffset += item.getDescriptor().getAllFields().size(); } else { ++itemOffset; //only a single attribute can be selected } } } } }
protected void integrateRoot(RootImpl root) { if (this.roots.isEmpty()) { TypeImpl type = ((MetamodelImpl)this.metamodel).getType(this.queryType); if ((type != null && type.getPersistenceType() == PersistenceType.ENTITY) || queryType.equals(ClassConstants.OBJECT)) { // this is the first root, set return type and selection and query type if (this.selection == null) { this.selection = root; this.subQuery.getItems().clear(); this.subQuery.addAttribute("", new ConstantExpression(1, root.getCurrentNode().getBuilder())); this.queryResult = ResultType.ENTITY; } } this.subQuery.setReferenceClass(root.getJavaType()); this.subQuery.setExpressionBuilder(root.getCurrentNode().getBuilder()); this.queryType = root.getJavaType(); this.currentNode.setBaseExpression(((CommonAbstractCriteriaImpl)this.parent).getBaseExpression()); } super.integrateRoot(root); }
/** * INTERNAL: * Normalize the expression into a printable structure. * Any joins must be added to form a new root. */ @Override public Expression normalize(ExpressionNormalizer normalizer) { if (this.subSelect != null) { // Each item that is a function must have an alias defined for it. for (ReportItem item : this.subSelect.getSubQuery().getItems()) { if (!item.getAttributeExpression().isQueryKeyExpression()) { item.setAttributeExpression(item.getAttributeExpression().as(item.getName())); } } // Need to force the sub-slect to normalize instead of deferring. this.subSelect.normalizeSubSelect(normalizer, normalizer.getClonedExpressions()); } return super.normalize(normalizer); }
/** * INTERNAL: * Normalize the expression into a printable structure. * Any joins must be added to form a new root. */ @Override public Expression normalize(ExpressionNormalizer normalizer) { if (this.subSelect != null) { // Each item that is a function must have an alias defined for it. for (ReportItem item : this.subSelect.getSubQuery().getItems()) { if (!item.getAttributeExpression().isQueryKeyExpression()) { item.setAttributeExpression(item.getAttributeExpression().as(item.getName())); } } // Need to force the sub-slect to normalize instead of deferring. this.subSelect.normalizeSubSelect(normalizer, normalizer.getClonedExpressions()); } return super.normalize(normalizer); }