Refactor relations - Pyosch/powertac-server GitHub Wiki

up

When we drop Hibernate, we need to accomodate the need to locate instances of various types. If we look through the server code, we can discover database queries as calls of the form findByXx(), FindAllByXx(), and withCriteria(). Many of these queries are finding instances by id for the purpose of refreshing an object in a new session/transaction, to avoid stale object problems. In virtually all cases, we can simply drop these.

Other cases indicate a need for either direct object relationships, or some sort of lookup scheme.

Instances of findByXx()

We will omit cases that appear in test code:

  • AbstractCustomer has several instances of findByTariffAndCustomer() -- these can replaced by Customer keeping a list or hashtable of its Tariffs.
  • The various initialization services look up their respective PluginConfig instances by roleName. This could be replaced with a hashtable.
  • AuctionService looks up Orderbooks by timeslot and product. The product abstraction should be dropped (YAGNI), and Orderbooks could be stored in an array indexed by timeslot sequence number. The server knows the number of timeslots ahead of time.
  • CompetitionControlService looks up Timeslots by sequence number, could be an array index.
  • CompetitionControlService looks up Roles by authority. Not sure what this means.
  • The singleton Competition instance is looked up various ways. This is completely unnecessary.
  • DistributionUtility looks up Orderbooks by timeslot.
  • DefaultBroker and Genco look up own MarketPositions by timeslot. Could be an array.
  • BrokerLookupService finds brokers by username.
  • ApiController looks up brokers by LoginRequest. Not sure what this is for.
  • Tariff looks up superseded Tariff by specId.
  • Timeslot looks up timeslots by serial number and by start instant.
  • TariffMarketService looks up TariffSubscriptions by Tariff and Customer.
  • TariffMarketService looks up Tariffs by specId.
  • AccountingService looks up MarketPositions by broker and timeslot.
  • WeatherService looks up WeatherReport by timeslot.
  • AuctionService looks up all the enabled Timeslots. Do we need to keep non-enabled timeslots around?
  • CompetitionControlService looks up all the non-wholesale Brokers.
  • Customers look up all their TariffSubscriptions.
  • DistributionUtility looks up all the wholesale Brokers.
  • DefaultBroker looks up its TariffTransactions for the current timeslot.
  • Timeslot looks up all the enabled timeslots.
  • TariffMarketService looks up the subscriptions for a given Tariff.
  • TariffMarketService looks up all the PENDING Tariffs.
  • TariffMarketService looks up all the TariffSubscriptions for a given Customer.