Update to use JDatabaseQuery

Also use JModelLegacy