/** * INTERNAL: * Compute a consistent hash-code for the expression. * This is used to allow dynamic expression's SQL to be cached. */ @Override public int hashCode() { if (!isExpressionQuery()) { return super.hashCode(); } int hashCode = 32; if (this.referenceClass != null) { hashCode = hashCode + this.referenceClass.hashCode(); } Expression selectionCriteria = getSelectionCriteria(); if (selectionCriteria != null) { hashCode = hashCode + selectionCriteria.hashCode(); } return hashCode; }
/** * INTERNAL: * Compute a consistent hash-code for the expression. * This is used to allow dynamic expression's SQL to be cached. */ public int hashCode() { if (!isExpressionQuery()) { return super.hashCode(); } int hashCode = 32; if (getReferenceClass() != null) { hashCode = hashCode + getReferenceClass().hashCode(); } if (getSelectionCriteria() != null) { hashCode = hashCode + getSelectionCriteria().hashCode(); } return hashCode; }
/** * INTERNAL: * Compute a consistent hash-code for the expression. * This is used to allow dynamic expression's SQL to be cached. */ @Override public int hashCode() { if (!isExpressionQuery()) { return super.hashCode(); } int hashCode = 32; if (this.referenceClass != null) { hashCode = hashCode + this.referenceClass.hashCode(); } Expression selectionCriteria = getSelectionCriteria(); if (selectionCriteria != null) { hashCode = hashCode + selectionCriteria.hashCode(); } return hashCode; }
/** * INTERNAL: * Clone the query, including its selection criteria. * <p> * Normally selection criteria are not cloned here as they are cloned * later on during prepare. */ public Object deepClone() { ObjectLevelReadQuery clone = (ObjectLevelReadQuery)clone(); if (getSelectionCriteria() != null) { clone.setSelectionCriteria((Expression)getSelectionCriteria().clone()); } else if (defaultBuilder != null) { clone.defaultBuilder = (ExpressionBuilder)defaultBuilder.clone(); } return clone; }
/** * INTERNAL: * Clone the query, including its selection criteria. * <p> * Normally selection criteria are not cloned here as they are cloned * later on during prepare. */ @Override public Object deepClone() { ObjectLevelReadQuery clone = (ObjectLevelReadQuery)clone(); if (getSelectionCriteria() != null) { clone.setSelectionCriteria((Expression)getSelectionCriteria().clone()); } if (defaultBuilder != null) { clone.defaultBuilder = (ExpressionBuilder)defaultBuilder.clone(); } return clone; }
/** * INTERNAL: * Clone the query, including its selection criteria. * <p> * Normally selection criteria are not cloned here as they are cloned * later on during prepare. */ @Override public Object deepClone() { ObjectLevelReadQuery clone = (ObjectLevelReadQuery)clone(); if (getSelectionCriteria() != null) { clone.setSelectionCriteria((Expression)getSelectionCriteria().clone()); } if (defaultBuilder != null) { clone.defaultBuilder = (ExpressionBuilder)defaultBuilder.clone(); } return clone; }
/** * INTERNAL: * Called only if both * shouldExtendPessimisticLockScope and shouldExtendPessimisticLockScopeInSourceQuery are true. * Adds fields to be locked to the where clause of the source query. * Note that the sourceQuery must be ObjectLevelReadQuery so that it has ExpressionBuilder. * * This method must be implemented in subclasses that allow * setting shouldExtendPessimisticLockScopeInSourceQuery to true. */ public void extendPessimisticLockScopeInSourceQuery(ObjectLevelReadQuery sourceQuery) { Expression exp = sourceQuery.getSelectionCriteria(); exp = this.mechanism.joinRelationTableField(exp, sourceQuery.getExpressionBuilder()); sourceQuery.setSelectionCriteria(exp); }
/** * INTERNAL: * Called only if both * shouldExtendPessimisticLockScope and shouldExtendPessimisticLockScopeInSourceQuery are true. * Adds fields to be locked to the where clause of the source query. * Note that the sourceQuery must be ObjectLevelReadQuery so that it has ExpressionBuilder. * * This method must be implemented in subclasses that allow * setting shouldExtendPessimisticLockScopeInSourceQuery to true. */ @Override public void extendPessimisticLockScopeInSourceQuery(ObjectLevelReadQuery sourceQuery) { Expression exp = sourceQuery.getSelectionCriteria(); exp = this.mechanism.joinRelationTableField(exp, sourceQuery.getExpressionBuilder()); sourceQuery.setSelectionCriteria(exp); }
/** * INTERNAL: * Called only if both * shouldExtendPessimisticLockScope and shouldExtendPessimisticLockScopeInSourceQuery are true. * Adds fields to be locked to the where clause of the source query. * Note that the sourceQuery must be ObjectLevelReadQuery so that it has ExpressionBuilder. * * This method must be implemented in subclasses that allow * setting shouldExtendPessimisticLockScopeInSourceQuery to true. */ @Override public void extendPessimisticLockScopeInSourceQuery(ObjectLevelReadQuery sourceQuery) { Expression exp = sourceQuery.getSelectionCriteria(); exp = this.mechanism.joinRelationTableField(exp, sourceQuery.getExpressionBuilder()); sourceQuery.setSelectionCriteria(exp); }
/** * INTERNAL: * Called only if both * shouldExtendPessimisticLockScope and shouldExtendPessimisticLockScopeInSourceQuery are true. * Adds fields to be locked to the where clause of the source query. * Note that the sourceQuery must be ObjectLevelReadQuery so that it has ExpressionBuilder. * * This method must be implemented in subclasses that allow * setting shouldExtendPessimisticLockScopeInSourceQuery to true. */ @Override public void extendPessimisticLockScopeInSourceQuery(ObjectLevelReadQuery sourceQuery) { Expression exp = sourceQuery.getSelectionCriteria(); if(this.mechanism == null) { ExpressionBuilder builder = sourceQuery.getExpressionBuilder(); Iterator<Map.Entry<DatabaseField, DatabaseField>> it = this.getSourceToTargetKeyFields().entrySet().iterator(); Map.Entry<DatabaseField, DatabaseField> entry = it.next(); exp = builder.getField(entry.getKey()).equal(builder.get(this.getAttributeName()).getField(entry.getValue())).and(exp); } else { exp = this.mechanism.joinRelationTableField(exp, sourceQuery.getExpressionBuilder()); } sourceQuery.setSelectionCriteria(exp); }
&& ((getSelectionCriteria() == query.getSelectionCriteria()) || ((getSelectionCriteria() != null) && getSelectionCriteria().equals(query.getSelectionCriteria())));
/** * INTERNAL: * Called only if both * shouldExtendPessimisticLockScope and shouldExtendPessimisticLockScopeInSourceQuery are true. * Adds fields to be locked to the where clause of the source query. * Note that the sourceQuery must be ObjectLevelReadQuery so that it has ExpressionBuilder. * * This method must be implemented in subclasses that allow * setting shouldExtendPessimisticLockScopeInSourceQuery to true. */ public void extendPessimisticLockScopeInSourceQuery(ObjectLevelReadQuery sourceQuery) { Expression exp = sourceQuery.getSelectionCriteria(); if(this.mechanism == null) { ExpressionBuilder builder = sourceQuery.getExpressionBuilder(); Iterator<Map.Entry<DatabaseField, DatabaseField>> it = this.getSourceToTargetKeyFields().entrySet().iterator(); Map.Entry<DatabaseField, DatabaseField> entry = it.next(); exp = builder.getField(entry.getKey()).equal(builder.get(this.getAttributeName()).getField(entry.getValue())).and(exp); } else { exp = this.mechanism.joinRelationTableField(exp, sourceQuery.getExpressionBuilder()); } sourceQuery.setSelectionCriteria(exp); }
/** * INTERNAL: * Called only if both * shouldExtendPessimisticLockScope and shouldExtendPessimisticLockScopeInSourceQuery are true. * Adds fields to be locked to the where clause of the source query. * Note that the sourceQuery must be ObjectLevelReadQuery so that it has ExpressionBuilder. * * This method must be implemented in subclasses that allow * setting shouldExtendPessimisticLockScopeInSourceQuery to true. */ @Override public void extendPessimisticLockScopeInSourceQuery(ObjectLevelReadQuery sourceQuery) { Expression exp = sourceQuery.getSelectionCriteria(); if(this.mechanism == null) { ExpressionBuilder builder = sourceQuery.getExpressionBuilder(); Iterator<Map.Entry<DatabaseField, DatabaseField>> it = this.getSourceToTargetKeyFields().entrySet().iterator(); Map.Entry<DatabaseField, DatabaseField> entry = it.next(); exp = builder.getField(entry.getKey()).equal(builder.get(this.getAttributeName()).getField(entry.getValue())).and(exp); } else { exp = this.mechanism.joinRelationTableField(exp, sourceQuery.getExpressionBuilder()); } sourceQuery.setSelectionCriteria(exp); }
return false; Expression selectionCriteria = getSelectionCriteria(); Expression otherSelectionCriteria = query.getSelectionCriteria(); return ((selectionCriteria == otherSelectionCriteria) || ((selectionCriteria != null) && selectionCriteria.equals(otherSelectionCriteria)));
setQueryMechanism(new QueryByExampleMechanism(this, getSelectionCriteria())); ((QueryByExampleMechanism)getQueryMechanism()).setExampleObject(newExampleObject); setIsPrepared(false);
setQueryMechanism(new QueryByExampleMechanism(this, getSelectionCriteria())); ((QueryByExampleMechanism)getQueryMechanism()).setExampleObject(newExampleObject); setIsPrepared(false);
setQueryMechanism(new QueryByExampleMechanism(this, getSelectionCriteria())); ((QueryByExampleMechanism)getQueryMechanism()).setExampleObject(newExampleObject); setIsPrepared(false);
/** * PUBLIC: * The QueryByExamplePolicy, is a useful to customize the query when Query By Example is used. * The policy will control what attributes should, or should not be included in the query. * When dealing with nulls, using special operations (notEqual, lessThan, like, etc.) * for comparison, or choosing to include certain attributes at all times, it is useful to modify * the policy accordingly. * <p>Once a query is executed you must make an explicit call to setQueryByExamplePolicy * when changing the policy, so the query will know to prepare itself again. * <p>There is a caution to setting both a selection criteria and an example object: * If you set the policy after execution you must also reset the selection criteria. * (This is because after execution the original criteria and Query By Example criteria are fused together, * and the former cannot be easily recovered). */ public void setQueryByExamplePolicy(QueryByExamplePolicy queryByExamplePolicy) { if (!getQueryMechanism().isQueryByExampleMechanism()) { setQueryMechanism(new QueryByExampleMechanism(this, getSelectionCriteria())); ((QueryByExampleMechanism)getQueryMechanism()).setQueryByExamplePolicy(queryByExamplePolicy); setIsPrepared(false); } else { ((QueryByExampleMechanism)getQueryMechanism()).setQueryByExamplePolicy(queryByExamplePolicy); // Must allow the query to be prepared again. if (isPrepared() || (!shouldPrepare() && ((QueryByExampleMechanism)getQueryMechanism()).isParsed())) { ((QueryByExampleMechanism)getQueryMechanism()).setIsParsed(false); setSelectionCriteria(null); // setIsPrepared(false) triggered by previous. } } setIsPrePrepared(false); }
/** * PUBLIC: * The QueryByExamplePolicy, is a useful to customize the query when Query By Example is used. * The policy will control what attributes should, or should not be included in the query. * When dealing with nulls, using special operations (notEqual, lessThan, like, etc.) * for comparison, or choosing to include certain attributes at all times, it is useful to modify * the policy accordingly. * <p>Once a query is executed you must make an explicit call to setQueryByExamplePolicy * when changing the policy, so the query will know to prepare itself again. * <p>There is a caution to setting both a selection criteria and an example object: * If you set the policy after execution you must also reset the selection criteria. * (This is because after execution the original criteria and Query By Example criteria are fused together, * and the former cannot be easily recovered). */ public void setQueryByExamplePolicy(QueryByExamplePolicy queryByExamplePolicy) { if (!getQueryMechanism().isQueryByExampleMechanism()) { setQueryMechanism(new QueryByExampleMechanism(this, getSelectionCriteria())); ((QueryByExampleMechanism)getQueryMechanism()).setQueryByExamplePolicy(queryByExamplePolicy); setIsPrepared(false); } else { ((QueryByExampleMechanism)getQueryMechanism()).setQueryByExamplePolicy(queryByExamplePolicy); // Must allow the query to be prepared again. if (isPrepared() || (!shouldPrepare() && ((QueryByExampleMechanism)getQueryMechanism()).isParsed())) { ((QueryByExampleMechanism)getQueryMechanism()).setIsParsed(false); setSelectionCriteria(null); // setIsPrepared(false) triggered by previous. } } setIsPrePrepared(false); }
/** * PUBLIC: * The QueryByExamplePolicy, is a useful to customize the query when Query By Example is used. * The policy will control what attributes should, or should not be included in the query. * When dealing with nulls, using special operations (notEqual, lessThan, like, etc.) * for comparison, or choosing to include certain attributes at all times, it is useful to modify * the policy accordingly. * <p>Once a query is executed you must make an explicit call to setQueryByExamplePolicy * when changing the policy, so the query will know to prepare itself again. * <p>There is a caution to setting both a selection criteria and an example object: * If you set the policy after execution you must also reset the selection criteria. * (This is because after execution the original criteria and Query By Example criteria are fused together, * and the former cannot be easily recovered). */ public void setQueryByExamplePolicy(QueryByExamplePolicy queryByExamplePolicy) { if (!getQueryMechanism().isQueryByExampleMechanism()) { setQueryMechanism(new QueryByExampleMechanism(this, getSelectionCriteria())); ((QueryByExampleMechanism)getQueryMechanism()).setQueryByExamplePolicy(queryByExamplePolicy); setIsPrepared(false); } else { ((QueryByExampleMechanism)getQueryMechanism()).setQueryByExamplePolicy(queryByExamplePolicy); // Must allow the query to be prepared again. if (isPrepared() || (!shouldPrepare() && ((QueryByExampleMechanism)getQueryMechanism()).isParsed())) { ((QueryByExampleMechanism)getQueryMechanism()).setIsParsed(false); setSelectionCriteria(null); // setIsPrepared(false) triggered by previous. } } setIsPrePrepared(false); }