Skip to content

Instantly share code, notes, and snippets.

@debop
Created May 2, 2013 15:02
Show Gist options
  • Select an option

  • Save debop/5502836 to your computer and use it in GitHub Desktop.

Select an option

Save debop/5502836 to your computer and use it in GitHub Desktop.
Overlap Criteria
/** 지정한 범위 값이 두 속성 값 구간과 겹치는지를 알아보기 위한 질의어 */
public static Criterion getIsOverlapCriterion(String loPropertyName,
String hiPropertyName,
Object lo,
Object hi,
boolean includeLo,
boolean includeHi) {
if (lo == null && hi == null)
throw new IllegalArgumentException("lo, hi 모두 null 값이면 질의어를 만들 수 없습니다.");
if (log.isDebugEnabled())
log.debug(String.format("build getIsOverlapCriterion... loPropertyName=[%s], hiPropertyName=[%s]" +
" lo=[%s], hi=[%s], includeLo=[%s], includeHi=[%s]",
loPropertyName, hiPropertyName, lo, hi, includeLo, includeHi));
if (lo != null && hi != null) {
return Restrictions
.disjunction()
.add(getIsInRangeCriterion(loPropertyName, hiPropertyName, lo, includeLo, includeHi))
.add(getIsInRangeCriterion(loPropertyName, hiPropertyName, hi, includeLo, includeHi))
.add(getIsBetweenCriterion(loPropertyName, lo, hi, includeLo, includeHi))
.add(getIsBetweenCriterion(hiPropertyName, lo, hi, includeLo, includeHi));
}
if (lo != null) {
return Restrictions
.disjunction()
.add(getIsInRangeCriterion(loPropertyName, hiPropertyName, lo, includeLo, includeHi))
.add((includeLo) ? ge(loPropertyName, lo)
: gt(loPropertyName, lo))
.add((includeLo) ? ge(hiPropertyName, lo)
: gt(hiPropertyName, lo));
} else {
return Restrictions
.disjunction()
.add(getIsInRangeCriterion(loPropertyName, hiPropertyName, hi, includeLo, includeHi))
.add((includeLo) ? le(loPropertyName, hi)
: lt(loPropertyName, hi))
.add((includeLo) ? le(hiPropertyName, hi)
: lt(hiPropertyName, hi));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment