result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_STATEDOCUMENT,
finderArgs, this);
}
if (result instanceof LFTincanLrsState) {
LFTincanLrsState lfTincanLrsState = (LFTincanLrsState) result;
if (!Validator.equals(activityId, lfTincanLrsState.getActivityId()) ||
!Validator.equals(stateId, lfTincanLrsState.getStateId()) ||
!Validator.equals(agentId, lfTincanLrsState.getAgentId()) ||
!Validator.equals(registration,
lfTincanLrsState.getRegistration())) {
result = null;
}
}
if (result == null) {
StringBundler query = new StringBundler(6);
query.append(_SQL_SELECT_LFTINCANLRSSTATE_WHERE);
boolean bindActivityId = false;
if (activityId == null) {
query.append(_FINDER_COLUMN_STATEDOCUMENT_ACTIVITYID_1);
} else if (activityId.equals(StringPool.BLANK)) {
query.append(_FINDER_COLUMN_STATEDOCUMENT_ACTIVITYID_3);
} else {
bindActivityId = true;
if (activityId.equals(StringPool.BLANK)) {
query.append(_FINDER_COLUMN_STATEDOCUMENT_ACTIVITYID_3);
} else {
query.append(_FINDER_COLUMN_STATEDOCUMENT_ACTIVITYID_2);
}
}
boolean bindStateId = false;
if (stateId == null) {
query.append(_FINDER_COLUMN_STATEDOCUMENT_STATEID_1);
} else if (stateId.equals(StringPool.BLANK)) {
query.append(_FINDER_COLUMN_STATEDOCUMENT_STATEID_3);
} else {
bindStateId = true;
if (stateId.equals(StringPool.BLANK)) {
query.append(_FINDER_COLUMN_STATEDOCUMENT_STATEID_3);
} else {
query.append(_FINDER_COLUMN_STATEDOCUMENT_STATEID_2);
}
}
if (agentId == null) {
query.append(_FINDER_COLUMN_STATEDOCUMENT_AGENTID_NULL_2);
} else {
query.append(_FINDER_COLUMN_STATEDOCUMENT_AGENTID_2);
}
boolean bindRegistration = false;
if (registration == null) {
query.append(_FINDER_COLUMN_STATEDOCUMENT_REGISTRATION_1);
} else if (registration.equals(StringPool.BLANK)) {
query.append(_FINDER_COLUMN_STATEDOCUMENT_REGISTRATION_3);
} else {
bindRegistration = true;
if (registration.equals(StringPool.BLANK)) {
query.append(_FINDER_COLUMN_STATEDOCUMENT_REGISTRATION_3);
} else {
query.append(_FINDER_COLUMN_STATEDOCUMENT_REGISTRATION_2);
}
}
String sql = query.toString();
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
QueryPos qPos = QueryPos.getInstance(q);
if (bindActivityId) {
if (activityId != null) {
qPos.add(activityId);
}
}
if (bindStateId) {
if (stateId != null) {
qPos.add(stateId);
}
}
if (agentId != null) {
qPos.add(agentId.intValue());
}
if (bindRegistration) {
if (registration != null) {
qPos.add(registration);
}
}
List<LFTincanLrsState> list = q.list();
if (list.isEmpty()) {
FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_STATEDOCUMENT,
finderArgs, list);
} else {
if ((list.size() > 1) && _log.isWarnEnabled()) {
_log.warn(
"LFTincanLrsStatePersistenceImpl.fetchByStateDocument(String, String, Integer, String, boolean) with parameters (" +
StringUtil.merge(finderArgs) +
") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
}
LFTincanLrsState lfTincanLrsState = list.get(0);
result = lfTincanLrsState;
cacheResult(lfTincanLrsState);
if ((lfTincanLrsState.getActivityId() == null) ||
!lfTincanLrsState.getActivityId().equals(activityId) ||
(lfTincanLrsState.getStateId() == null) ||
!lfTincanLrsState.getStateId().equals(stateId) ||
(lfTincanLrsState.getAgentId() != agentId) ||
(lfTincanLrsState.getRegistration() == null) ||
!lfTincanLrsState.getRegistration()
.equals(registration)) {
FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_STATEDOCUMENT,
finderArgs, lfTincanLrsState);
}
}