s_logger.debug("search {}", request);
final VersionCorrection vc = request.getVersionCorrection().withLatestFixed(now());
final HolidaySearchResult result = new HolidaySearchResult(vc);
ExternalIdSearch regionSearch = request.getRegionExternalIdSearch();
ExternalIdSearch exchangeSearch = request.getExchangeExternalIdSearch();
String currencyISO = (request.getCurrency() != null ? request.getCurrency().getCode() : null);
if ((request.getHolidayObjectIds() != null && request.getHolidayObjectIds().size() == 0) ||
ExternalIdSearch.canMatch(regionSearch) == false ||
ExternalIdSearch.canMatch(exchangeSearch) == false) {
result.setPaging(Paging.of(request.getPagingRequest(), 0));
return result;
}
final DbMapSqlParameterSource args = new DbMapSqlParameterSource()
.addTimestamp("version_as_of_instant", vc.getVersionAsOf())
.addTimestamp("corrected_to_instant", vc.getCorrectedTo())
.addValueNullIgnored("name", getDialect().sqlWildcardAdjustValue(request.getName()))
.addValueNullIgnored("hol_type", request.getType() != null ? request.getType().name() : null)
.addValueNullIgnored("currency_iso", currencyISO);
if (request.getProviderId() != null) {
args.addValue("provider_scheme", request.getProviderId().getScheme().getName());
args.addValue("provider_value", request.getProviderId().getValue());
}
if (regionSearch != null) {
if (regionSearch.getSearchType() != ExternalIdSearchType.ANY) {
throw new IllegalArgumentException("Unsupported search type: " + regionSearch.getSearchType());
}
int i = 0;
for (ExternalId idKey : regionSearch.getExternalIds()) {
args.addValue("region_scheme" + i, idKey.getScheme().getName());
args.addValue("region_value" + i, idKey.getValue());
i++;
}
args.addValue("sql_search_region_ids", sqlSelectIdKeys(request.getRegionExternalIdSearch(), "region"));
}
if (exchangeSearch != null) {
if (exchangeSearch.getSearchType() != ExternalIdSearchType.ANY) {
throw new IllegalArgumentException("Unsupported search type: " + exchangeSearch.getSearchType());
}
int i = 0;
for (ExternalId idKey : exchangeSearch.getExternalIds()) {
args.addValue("exchange_scheme" + i, idKey.getScheme().getName());
args.addValue("exchange_value" + i, idKey.getValue());
i++;
}
args.addValue("sql_search_exchange_ids", sqlSelectIdKeys(request.getExchangeExternalIdSearch(), "exchange"));