/** * PUBLIC: * Return an expression that wraps the attribute or query key name. * This method is used to construct user-defined queries containing joins. * <p>Example: * <blockquote><pre> * builder.get("address").get("city").equal("Ottawa"); * </pre></blockquote> */ public Expression get(String attributeName) { return get(attributeName, true); }
/** * INTERNAL: */ public Expression getAllowingNull(String attributeName, Vector arguments) { /* this is meaningless for expressions in general */ return get(attributeName, arguments); }
/** * PUBLIC: * Return an expression that wraps the attribute or query key name. * This method is used to construct user-defined queries containing joins. * <p>Example: * <blockquote><pre> * builder.get("address").get("city").equal("Ottawa"); * </pre></blockquote> */ public Expression get(String attributeName) { return get(attributeName, true); }
/** * PUBLIC: * Return an expression that wraps the attribute or query key name. * This method is used to construct user-defined queries containing joins. * <p>Example: * <pre><blockquote> * builder.get("address").get("city").equal("Ottawa"); * </blockquote></pre> */ public Expression get(String attributeName) { return get(attributeName, null); }
private void resolveVirtualPath(AbstractPathExpression expression) { String path = expression.getPath(1); localExpression = localExpression.get(path); }
private void resolveVirtualPath(AbstractPathExpression expression) { String path = expression.getPath(1); localExpression = localExpression.get(path); }
/** * INTERNAL: * Used to allow object level comparisons. */ @Override public Expression buildObjectJoinExpression(Expression expression, Expression argument, AbstractSession session) { Expression attributeByAttributeComparison = null; //Enumeration mappingsEnum = getSourceToTargetKeyFields().elements(); Enumeration mappingsEnum = getReferenceDescriptor().getMappings().elements(); for (; mappingsEnum.hasMoreElements();) { DatabaseMapping mapping = (DatabaseMapping)mappingsEnum.nextElement(); String attributeName = mapping.getAttributeName(); Expression join = expression.get(attributeName).equal(argument.get(attributeName)); if (attributeByAttributeComparison == null) { attributeByAttributeComparison = join; } else { attributeByAttributeComparison = attributeByAttributeComparison.and(join); } } return attributeByAttributeComparison; }
/** * INTERNAL: * Used to allow object level comparisons. */ @Override public Expression buildObjectJoinExpression(Expression expression, Expression argument, AbstractSession session) { Expression attributeByAttributeComparison = null; //Enumeration mappingsEnum = getSourceToTargetKeyFields().elements(); Enumeration mappingsEnum = getReferenceDescriptor().getMappings().elements(); for (; mappingsEnum.hasMoreElements();) { DatabaseMapping mapping = (DatabaseMapping)mappingsEnum.nextElement(); String attributeName = mapping.getAttributeName(); Expression join = expression.get(attributeName).equal(argument.get(attributeName)); if (attributeByAttributeComparison == null) { attributeByAttributeComparison = join; } else { attributeByAttributeComparison = attributeByAttributeComparison.and(join); } } return attributeByAttributeComparison; }
/** * INTERNAL: * Used to allow object level comparisons. */ public Expression buildObjectJoinExpression(Expression expression, Expression argument, AbstractSession session) { Expression attributeByAttributeComparison = null; //Enumeration mappingsEnum = getSourceToTargetKeyFields().elements(); Enumeration mappingsEnum = getReferenceDescriptor().getMappings().elements(); for (; mappingsEnum.hasMoreElements();) { DatabaseMapping mapping = (DatabaseMapping)mappingsEnum.nextElement(); String attributeName = mapping.getAttributeName(); Expression join = expression.get(attributeName).equal(argument.get(attributeName)); if (attributeByAttributeComparison == null) { attributeByAttributeComparison = join; } else { attributeByAttributeComparison = attributeByAttributeComparison.and(join); } } return attributeByAttributeComparison; }
/** * INTERNAL: * In case Query By Example is used, this method builds and returns an expression that * corresponds to a single attribute and it's value for a directToField mapping. */ public Expression buildExpression(Object queryObject, QueryByExamplePolicy policy, Expression expressionBuilder, Map processedObjects, AbstractSession session) { String attributeName = this.getAttributeName(); Object attributeValue = this.getAttributeValueFromObject(queryObject); if (!policy.shouldIncludeInQuery(queryObject.getClass(), attributeName, attributeValue)) { //the attribute name and value pair is not to be included in the query. return null; } Expression expression = expressionBuilder.get(attributeName); if (attributeValue == null) { expression = policy.completeExpressionForNull(expression); } else { expression = policy.completeExpression(expression, attributeValue, attributeValue.getClass()); } return expression; }
/** * INTERNAL: * In case Query By Example is used, this method generates an expression from a attribute value pair. Since * this is an Aggregate mapping, a recursive call is made to the buildExpressionFromExample method of * ObjectBuilder. */ public Expression buildExpression(Object queryObject, QueryByExamplePolicy policy, Expression expressionBuilder, Map processedObjects, AbstractSession session) { String attributeName = this.getAttributeName(); Object attributeValue = this.getRealAttributeValueFromObject(queryObject, session); if (!policy.shouldIncludeInQuery(queryObject.getClass(), attributeName, attributeValue)) { //the attribute name and value pair is not to be included in the query. return null; } if (attributeValue == null) { //even though it is null, it is to be always included in the query Expression expression = expressionBuilder.get(attributeName); return policy.completeExpressionForNull(expression); } ObjectBuilder objectBuilder = getReferenceDescriptor().getObjectBuilder(); return objectBuilder.buildExpressionFromExample(attributeValue, policy, expressionBuilder.get(attributeName), processedObjects, session); }
/** * INTERNAL: * In case Query By Example is used, this method generates an expression from a attribute value pair. Since * this is an Aggregate mapping, a recursive call is made to the buildExpressionFromExample method of * ObjectBuilder. */ public Expression buildExpression(Object queryObject, QueryByExamplePolicy policy, Expression expressionBuilder, Map processedObjects, AbstractSession session) { String attributeName = this.getAttributeName(); Object attributeValue = this.getRealAttributeValueFromObject(queryObject, session); if (!policy.shouldIncludeInQuery(queryObject.getClass(), attributeName, attributeValue)) { //the attribute name and value pair is not to be included in the query. return null; } if (attributeValue == null) { //even though it is null, it is to be always included in the query Expression expression = expressionBuilder.get(attributeName); return policy.completeExpressionForNull(expression); } ObjectBuilder objectBuilder = getReferenceDescriptor().getObjectBuilder(); return objectBuilder.buildExpressionFromExample(attributeValue, policy, expressionBuilder.get(attributeName), processedObjects, session); }
/** * INTERNAL: * In case Query By Example is used, this method generates an expression from a attribute value pair. Since * this is an Aggregate mapping, a recursive call is made to the buildExpressionFromExample method of * ObjectBuilder. */ public Expression buildExpression(Object queryObject, QueryByExamplePolicy policy, Expression expressionBuilder, Map processedObjects, AbstractSession session) { String attributeName = this.getAttributeName(); Object attributeValue = this.getRealAttributeValueFromObject(queryObject, session); if (!policy.shouldIncludeInQuery(queryObject.getClass(), attributeName, attributeValue)) { //the attribute name and value pair is not to be included in the query. return null; } if (attributeValue == null) { //even though it is null, it is to be always included in the query Expression expression = expressionBuilder.get(attributeName); return policy.completeExpressionForNull(expression); } ObjectBuilder objectBuilder = getReferenceDescriptor().getObjectBuilder(); return objectBuilder.buildExpressionFromExample(attributeValue, policy, expressionBuilder.get(attributeName), processedObjects, session); }
/** * INTERNAL: * In case Query By Example is used, this method builds and returns an expression that * corresponds to a single attribute and it's value for a directToField mapping. */ @Override public Expression buildExpression(Object queryObject, QueryByExamplePolicy policy, Expression expressionBuilder, Map processedObjects, AbstractSession session) { String attributeName = this.getAttributeName(); Object attributeValue = this.getAttributeValueFromObject(queryObject); if (!policy.shouldIncludeInQuery(queryObject.getClass(), attributeName, attributeValue)) { //the attribute name and value pair is not to be included in the query. return null; } Expression expression = expressionBuilder.get(attributeName); if (attributeValue == null) { expression = policy.completeExpressionForNull(expression); } else { expression = policy.completeExpression(expression, attributeValue, attributeValue.getClass()); } return expression; }
/** * Return the path corresponding to the referenced non-collection valued * attribute. * * @param model * attribute * @return path corresponding to the referenced attribute */ public <Y> Path<Y> get(SingularAttribute<? super X, Y> att){ if (att.getPersistentAttributeType().equals(PersistentAttributeType.BASIC)){ return new PathImpl<Y>(this, this.metamodel, att.getBindableJavaType(),this.currentNode.get(att.getName()), att); }else{ Class<Y> clazz = att.getBindableJavaType(); Join join = new JoinImpl<X, Y>(this, this.metamodel.managedType(clazz), this.metamodel, clazz,this.currentNode.get(att.getName()), att); this.joins.add(join); return join; } }
/** * INTERNAL: * Rebuild myself against the base, with the values of parameters supplied by the context * expression. This is used for transforming a standalone expression (e.g. the join criteria of a mapping) * into part of some larger expression. You normally would not call this directly, instead calling twist * See the comment there for more details" */ @Override public Expression twistedForBaseAndContext(Expression newBase, Expression context, Expression oldBase) { if (oldBase == null || this.baseExpression == oldBase) { Expression twistedBase = this.baseExpression.twistedForBaseAndContext(newBase, context, oldBase); QueryKeyExpression result = (QueryKeyExpression)twistedBase.get(getName()); if (shouldUseOuterJoin) { result.doUseOuterJoin(); } if (shouldQueryToManyRelationship) { result.doQueryToManyRelationship(); } return result; } return this; }
/** * INTERNAL: * Rebuild myself against the base, with the values of parameters supplied by the context * expression. This is used for transforming a standalone expression (e.g. the join criteria of a mapping) * into part of some larger expression. You normally would not call this directly, instead calling twist * See the comment there for more details" */ public Expression twistedForBaseAndContext(Expression newBase, Expression context) { Expression twistedBase = getBaseExpression().twistedForBaseAndContext(newBase, context); QueryKeyExpression result = (QueryKeyExpression)twistedBase.get(getName()); if (shouldUseOuterJoin) { result.doUseOuterJoin(); } if (shouldQueryToManyRelationship) { result.doQueryToManyRelationship(); } return result; }
/** * INTERNAL: * Selection criteria is created to read target records (nested table) from the table. */ protected void initializeSelectionCriteria(AbstractSession session) { Expression exp1; Expression exp2; ExpressionBuilder builder = new ExpressionBuilder(); Expression queryKey = builder.getManualQueryKey(getAttributeName(), getDescriptor()); exp1 = builder.ref().equal(queryKey.get(getAttributeName()).value()); exp2 = getDescriptor().getObjectBuilder().getPrimaryKeyExpression().rebuildOn(queryKey); setSelectionCriteria(exp1.and(exp2)); }
/** * INTERNAL: * Selection criteria is created to read target records (nested table) from the table. **/ protected void initializeSelectionCriteria(AbstractSession session) { Expression exp1; Expression exp2; ExpressionBuilder builder = new ExpressionBuilder(); Expression queryKey = builder.getManualQueryKey(getAttributeName(), getDescriptor()); exp1 = builder.ref().equal(queryKey.get(getAttributeName()).value()); exp2 = getDescriptor().getObjectBuilder().getPrimaryKeyExpression().rebuildOn(queryKey); setSelectionCriteria(exp1.and(exp2)); }
/** * INTERNAL: * Selection criteria is created to read target records (nested table) from the table. */ protected void initializeSelectionCriteria(AbstractSession session) { Expression exp1; Expression exp2; ExpressionBuilder builder = new ExpressionBuilder(); Expression queryKey = builder.getManualQueryKey(getAttributeName(), getDescriptor()); exp1 = builder.ref().equal(queryKey.get(getAttributeName()).value()); exp2 = getDescriptor().getObjectBuilder().getPrimaryKeyExpression().rebuildOn(queryKey); setSelectionCriteria(exp1.and(exp2)); }