package gw.rating.rtm.query uses gw.api.database.Query uses gw.api.database.Restriction uses gw.rating.rtm.domain.OrderedPersistenceElement uses java.lang.Comparable uses java.util.Map uses gw.api.system.PCLoggerCategory uses gw.rating.RateFlowLogger uses gw.rating.rtm.RateBookValidation uses java.util.List @ReadOnly class StatelessDBQuery extends AbstractStatelessQuery { construct(table: RateTable) { super(table) var msg = RateBookValidation.checkFactorRow(table.Definition) if (msg != null) { RateFlowLogger.Logger.warn(msg, table) } RateFlowLogger.Logger.debug("Using database query strategy for " +table.Definition.TableCode) } override function queryMultipleFactors(table: RateTable, inputParams: Comparable[], factorCodes: List ): Map { resetNumActiveOpsAndCheckInputParams(table, inputParams) preRelax(inputParams) var result : Map while (!this.IsFullyRelaxed) { var query = createQuery(table, inputParams) var rows = query.select().toList() .map(\ b -> OrderedPersistenceElement.wrapKeyableBean(b, table.Definition)) result = this.extractFactors(table.Definition, rows, factorCodes, inputParams) if (result == null) { relaxQuery() } else { break } } if (result == null or result.size() == 0) { PCLoggerCategory.RTM.warn("No results found for Rate Table Query [book=" + table.RateBook.DisplayName + "; table=" + table.DisplayName + "; params=" + inputParams.join(",") + "]") return {} } return result } /** * Create the query that will be used to fetch rows corresponding to the given table. If applyFilters is not null, * it is called to apply restrictions to the query. (MemoryFactorQuery is expected to pass null, because * it gets all rows in the table and then filters them in memory. DBFactorQuery will add additional * restrictions to reflect the active and relaxed matchops.) */ private function createQuery(table: RateTable, inputParams: Comparable[]) : Restriction { var query = Query.make(table.Definition.FactorRowEntity) for (op in MatchOps index i) { if (i < NumActiveOps) { op.filter(query, inputParams[i]) } else { op.relax(query) } } if (PCLoggerCategory.RTM.TraceEnabled) { query = query.withLogSQL(true) } return query.compare("RateTable", Equals, table.TableOwningFactors) } }