public DatabaseMapping getMapping() { if (!hasMapping) { return null; } if (mapping == null) { mapping = super.getMapping(); if (mapping == null) { hasMapping = false; } } return mapping; }
@Override public DatabaseMapping getMapping() { if (!hasMapping) { return null; } if (mapping == null) { mapping = super.getMapping(); if (mapping == null) { hasMapping = false; } } return mapping; }
@Override public DatabaseMapping getMapping() { if (!hasMapping) { return null; } if (mapping == null) { mapping = super.getMapping(); if (mapping == null) { hasMapping = false; } } return mapping; }
/** * Iterate through a list of expressions searching for the given attribute name. * Return true if it is found, false otherwise. Only use if the query was preprepared so that join expressions * were processed. */ protected boolean isMappingInJoinedExpressionList(DatabaseMapping attributeMapping, List joinedExpressionList) { for (Iterator joinEnum = joinedExpressionList.iterator(); joinEnum.hasNext();) { List aggregateMappings = new ArrayList(); ObjectExpression expression = ((ObjectExpression)joinEnum.next()).getFirstNonAggregateExpressionAfterExpressionBuilder(aggregateMappings); if (attributeMapping.isAggregateObjectMapping() && aggregateMappings.contains(attributeMapping)) { return true; } else if (attributeMapping.equals(expression.getMapping())) {//expression may not have been processed yet return true; } } return false; }
/** * Iterate through a list of expressions searching for the given attribute name. * Return true if it is found, false otherwise. Only use if the query was preprepared so that join expressions * were processed. */ protected boolean isMappingInJoinedExpressionList(DatabaseMapping attributeMapping, List joinedExpressionList) { for (Iterator joinEnum = joinedExpressionList.iterator(); joinEnum.hasNext();) { List aggregateMappings = new ArrayList(); ObjectExpression expression = ((ObjectExpression)joinEnum.next()).getFirstNonAggregateExpressionAfterExpressionBuilder(aggregateMappings); if (attributeMapping.isAggregateObjectMapping() && aggregateMappings.contains(attributeMapping)) { return true; } else if (attributeMapping.equals(expression.getMapping())) {//expression may not have been processed yet return true; } } return false; }
public ClassDescriptor getDescriptor() { if (isAttribute()) { return null; } if (descriptor == null) { // Look first for query keys, then mappings. Ultimately we should have query keys // for everything and can dispense with the mapping part. ForeignReferenceQueryKey queryKey = (ForeignReferenceQueryKey)getQueryKeyOrNull(); if (queryKey != null) { descriptor = getSession().getDescriptor(queryKey.getReferenceClass()); return descriptor; } if (getMapping() == null) { throw QueryException.invalidQueryKeyInExpression(this); } // We assume this is either a foreign reference or an aggregate mapping descriptor = getMapping().getReferenceDescriptor(); if (getMapping().isVariableOneToOneMapping()) { throw QueryException.cannotQueryAcrossAVariableOneToOneMapping(getMapping(), descriptor); } } return descriptor; }
@Override public ClassDescriptor getDescriptor() { if (isAttribute()) { return null; } if (descriptor == null) { // Look first for query keys, then mappings. Ultimately we should have query keys // for everything and can dispense with the mapping part. ForeignReferenceQueryKey queryKey = (ForeignReferenceQueryKey)getQueryKeyOrNull(); if (queryKey != null) { descriptor = convertToCastDescriptor(getSession().getDescriptor(queryKey.getReferenceClass()), getSession()); return descriptor; } if (getMapping() == null) { throw QueryException.invalidQueryKeyInExpression(this); } // We assume this is either a foreign reference or an aggregate mapping descriptor = getMapping().getReferenceDescriptor(); if (getMapping().isVariableOneToOneMapping()) { throw QueryException.cannotQueryAcrossAVariableOneToOneMapping(getMapping(), descriptor); } descriptor = convertToCastDescriptor(descriptor, getSession()); } return descriptor; }
/** * INTERNAL: * Parses an expression to return the first non-AggregateObjectMapping expression after the base ExpressionBuilder. * This is used by joining and batch fetch to get the list of mappings that really need to be processed (non-aggregates). * @param aggregateMappingsEncountered - collection of aggregateObjectMapping expressions encountered in the returned expression * between the first expression and the ExpressionBuilder * @return first non-AggregateObjectMapping expression after the base ExpressionBuilder from the fullExpression */ public ObjectExpression getFirstNonAggregateExpressionAfterExpressionBuilder(List aggregateMappingsEncountered) { boolean done = false; ObjectExpression baseExpression = this; ObjectExpression prevExpression = this; while (!baseExpression.getBaseExpression().isExpressionBuilder() && !done) { baseExpression = (ObjectExpression)baseExpression.getBaseExpression(); while (!baseExpression.isExpressionBuilder() && baseExpression.getMapping().isAggregateObjectMapping()) { aggregateMappingsEncountered.add(baseExpression.getMapping()); baseExpression = (ObjectExpression)baseExpression.getBaseExpression(); } if (baseExpression.isExpressionBuilder()) { done = true; //use the one closest to the expression builder that wasn't an aggregate baseExpression = prevExpression; } else { prevExpression = baseExpression; } } return baseExpression; }
/** * INTERNAL: * Iterate through a list of joined expressions and add the fields they represent to a list * of fields. */ protected void addSelectionFieldsForJoinedExpressions(List fields, List joinedExpressions) { for (int index = 0; index < joinedExpressions.size(); index++) { ObjectExpression objectExpression = (ObjectExpression)joinedExpressions.get(index); // Expression may not have been initialized. ExpressionBuilder builder = objectExpression.getBuilder(); builder.setSession(getSession().getRootSession(null)); builder.setQueryClass(getReferenceClass()); ClassDescriptor descriptor = objectExpression.getMapping().getReferenceDescriptor(); fields.addAll(descriptor.getAllFields()); } }
/** * INTERNAL: * Parses an expression to return the first non-AggregateObjectMapping expression after the base ExpressionBuilder. * This is used by joining and batch fetch to get the list of mappings that really need to be processed (non-aggregates). * @param aggregateMappingsEncountered - collection of aggregateObjectMapping expressions encountered in the returned expression * between the first expression and the ExpressionBuilder * @return first non-AggregateObjectMapping expression after the base ExpressionBuilder from the fullExpression */ public ObjectExpression getFirstNonAggregateExpressionAfterExpressionBuilder(List aggregateMappingsEncountered) { boolean done = false; ObjectExpression baseExpression = this; ObjectExpression prevExpression = this; while (!baseExpression.getBaseExpression().isExpressionBuilder() && !done) { baseExpression = (ObjectExpression)baseExpression.getBaseExpression(); while (!baseExpression.isExpressionBuilder() && baseExpression.getMapping().isAggregateObjectMapping()) { aggregateMappingsEncountered.add(baseExpression.getMapping()); baseExpression = (ObjectExpression)baseExpression.getBaseExpression(); } if (baseExpression.isExpressionBuilder()) { done = true; //use the one closest to the expression builder that wasn't an aggregate baseExpression = prevExpression; } else { prevExpression = baseExpression; } } return baseExpression; }
@Override public ClassDescriptor getDescriptor() { if (isAttribute()) { return null; } if (descriptor == null) { // Look first for query keys, then mappings. Ultimately we should have query keys // for everything and can dispense with the mapping part. ForeignReferenceQueryKey queryKey = (ForeignReferenceQueryKey)getQueryKeyOrNull(); if (queryKey != null) { descriptor = convertToCastDescriptor(getSession().getDescriptor(queryKey.getReferenceClass()), getSession()); return descriptor; } if (getMapping() == null) { throw QueryException.invalidQueryKeyInExpression(this); } // We assume this is either a foreign reference or an aggregate mapping descriptor = getMapping().getReferenceDescriptor(); if (getMapping().isVariableOneToOneMapping()) { throw QueryException.cannotQueryAcrossAVariableOneToOneMapping(getMapping(), descriptor); } descriptor = convertToCastDescriptor(descriptor, getSession()); } return descriptor; }
/** * INTERNAL: * Return if the represents an object comparison. */ protected boolean isObjectComparison() { if (isObjectComparisonExpression == null) { // PERF: direct-access. if ((!this.firstChild.isObjectExpression()) || ((ObjectExpression)this.firstChild).isAttribute()) { isObjectComparisonExpression = Boolean.FALSE; } else { DatabaseMapping mapping = ((ObjectExpression)this.firstChild).getMapping(); if ((mapping != null) && (mapping.isDirectCollectionMapping()) && !(this.firstChild.isMapEntryExpression())) { isObjectComparisonExpression = Boolean.FALSE; } else { isObjectComparisonExpression = Boolean.valueOf(this.secondChild.isObjectExpression() || (this.secondChild.isValueExpression() || (this.secondChild.isFunctionExpression() && ((FunctionExpression)this.secondChild).operator.isAnyOrAll()))); } } } return isObjectComparisonExpression.booleanValue(); }
DatabaseMapping mapping = objectExpression.getMapping(); if ((mapping != null) && mapping.isForeignReferenceMapping()) {
DatabaseMapping mapping = ((ObjectExpression) queryKey).getMapping(); if (mapping != null) { if (mapping.isCollectionMapping() && queryKey.isMapEntryExpression() && !((MapEntryExpression)queryKey).shouldReturnMapEntry()){
/** * INTERNAL: Not to be confused with the public getField(String) * This returns a collection of all fields associated with this object. Really * only applies to query keys representing an object or to expression builders. */ public Vector getFields() { if (getDescriptor() == null) { DatabaseMapping mapping = getMapping(); if (mapping != null) { return mapping.getSelectFields(); } return new NonSynchronizedVector(0); } if (descriptor.hasInheritance() && descriptor.getInheritancePolicy().shouldReadSubclasses() && (!descriptor.getInheritancePolicy().hasMultipleTableChild()) || shouldUseOuterJoinForMultitableInheritance()) { // return all fields because we can. return descriptor.getAllFields(); } else { return descriptor.getFields(); } }
return null; DatabaseMapping mapping = expression.getMapping(); Object attributeValue = mapping.getRealAttributeValueFromObject(baseValue, session); if (attributeValue != null) {
/** * INTERNAL: */ @Override public List<DatabaseField> getSelectionFields(ReadQuery query) { if (getDescriptor() == null) { DatabaseMapping mapping = getMapping(); if (mapping != null) { return mapping.getSelectFields(); } return new ArrayList<DatabaseField>(0); } if (descriptor.hasInheritance() && descriptor.getInheritancePolicy().shouldReadSubclasses() && (!descriptor.getInheritancePolicy().hasMultipleTableChild()) || shouldUseOuterJoinForMultitableInheritance()) { // return all fields because we can. if (query != null && query.isObjectLevelReadQuery()) { return descriptor.getAllSelectionFields((ObjectLevelReadQuery)query); } else { return descriptor.getAllSelectionFields(); } } else { if (query != null && query.isObjectLevelReadQuery()) { return descriptor.getSelectionFields((ObjectLevelReadQuery)query); } else { return descriptor.getSelectionFields(); } } }
/** * INTERNAL: */ @Override public List<DatabaseField> getSelectionFields(ReadQuery query) { if (getDescriptor() == null) { DatabaseMapping mapping = getMapping(); if (mapping != null) { return mapping.getSelectFields(); } return new ArrayList<DatabaseField>(0); } if (descriptor.hasInheritance() && descriptor.getInheritancePolicy().shouldReadSubclasses() && (!descriptor.getInheritancePolicy().hasMultipleTableChild()) || shouldUseOuterJoinForMultitableInheritance()) { // return all fields because we can. if (query != null && query.isObjectLevelReadQuery()) { return descriptor.getAllSelectionFields((ObjectLevelReadQuery)query); } else { return descriptor.getAllSelectionFields(); } } else { if (query != null && query.isObjectLevelReadQuery()) { return descriptor.getSelectionFields((ObjectLevelReadQuery)query); } else { return descriptor.getSelectionFields(); } } }
/** * INTERNAL: Not to be confused with the public getField(String) * This returns a collection of all fields associated with this object. Really * only applies to query keys representing an object or to expression builders. */ @Override public Vector getFields() { if (getDescriptor() == null) { DatabaseMapping mapping = getMapping(); if (mapping != null) { return mapping.getSelectFields(); } return new NonSynchronizedVector(0); } if (descriptor.hasInheritance() && descriptor.getInheritancePolicy().shouldReadSubclasses() && (!descriptor.getInheritancePolicy().hasMultipleTableChild()) || shouldUseOuterJoinForMultitableInheritance()) { // return all fields because we can. return descriptor.getAllFields(); } else { return descriptor.getFields(); } }
/** * INTERNAL: Not to be confused with the public getField(String) * This returns a collection of all fields associated with this object. Really * only applies to query keys representing an object or to expression builders. */ @Override public Vector getFields() { if (getDescriptor() == null) { DatabaseMapping mapping = getMapping(); if (mapping != null) { return mapping.getSelectFields(); } return new NonSynchronizedVector(0); } if (descriptor.hasInheritance() && descriptor.getInheritancePolicy().shouldReadSubclasses() && (!descriptor.getInheritancePolicy().hasMultipleTableChild()) || shouldUseOuterJoinForMultitableInheritance()) { // return all fields because we can. return descriptor.getAllFields(); } else { return descriptor.getFields(); } }