/** * * Public Function: getAllGtfsFeedUpdates() * * @return ArrayList<GtfsUpdateTracker> : All GtfsFeedUpdates */ public static synchronized ArrayList<GtfsUpdateTracker> getAllGtfsFeedUpdates(Context context) { // Create SQLFactoryAdapter instance SQLiteFactoryAdapter dbAdapter = SQLiteFactoryAdapter.getSQLiteFactoryAdapterInstance(context); // Logic to create or use the existing database try { dbAdapter.createOrUseDataBase(); } catch (Exception e) { // Log.e(TAG, "Error " + e.toString()); } // Populate SQL String sql = "SELECT FeedName " + " ,LastUpdated " + " FROM " + " GTFS_UPDATE_TRACKER; "; // Open Database dbAdapter.openDataBase(); // Log.e(TAG, "BusinessBaseGtfsUpdateTracker: getAllGtfsUpdateTrackers() database OPEN"); // Create SQLite Cursor Cursor cur = dbAdapter.selectRecordsFromDB(sql, null); // Our container objects ArrayList<GtfsUpdateTracker> curGtfsUpdateTrackerList = new ArrayList<GtfsUpdateTracker>(); GtfsUpdateTracker currentGtfsUpdateTracker = new GtfsUpdateTracker(); // If anything returned, LOOP through cursor and populate our container objects try { while (cur.moveToNext()) { // Initiate local variables String _FeedName = cur.getString(cur.getColumnIndex("FeedName")); String _LastUpdated = cur.getString(cur.getColumnIndex("LastUpdated")); // Create new instance of object currentGtfsUpdateTracker = new GtfsUpdateTracker(); currentGtfsUpdateTracker.FeedName(_FeedName); currentGtfsUpdateTracker.LastUpdated(_LastUpdated); // Add newly populated object to ArrayList curGtfsUpdateTrackerList.add(currentGtfsUpdateTracker); } } catch (Exception e) { // Log.e(TAG, "Error " + e.toString()); } finally { // House Keeping cur.close(); cur.deactivate(); dbAdapter.close(); // Log.e(TAG, "BusinessBaseGtfsUpdateTracker: getAllGtfsFeedUpdates() database CLOSED"); } return curGtfsUpdateTrackerList; }
/** * Public Function: Update(Context context) */ public static void Update(Context context, GtfsUpdateTracker curGtfsUpdateTracker) { // Create SQLFactoryAdapter instance SQLiteFactoryAdapter dbAdapter = SQLiteFactoryAdapter.getSQLiteFactoryAdapterInstance(context); // Logic to create or use the existing database try { dbAdapter.createOrUseDataBase(); } catch (Exception e) { // Log.e(TAG, "Error " + e.toString()); } try { // Open Database dbAdapter.openDataBase(); // Log.e(TAG, "BusinessBaseTrip: getAllTrips() database OPEN"); String _FeedName = ((curGtfsUpdateTracker.FeedName() == null) ? "calendar_dates" : curGtfsUpdateTracker.FeedName()); String _LastUpdated = ((curGtfsUpdateTracker.LastUpdated() == null) ? "" : curGtfsUpdateTracker.LastUpdated()); ContentValues args = new ContentValues(); // args.put("FeedName", _FeedName); args.put("LastUpdated", _LastUpdated); String whereArgs[] = new String[1]; whereArgs[0] = "" + _FeedName; dbAdapter.updateRecordsInDB("GTFS_UPDATE_TRACKER", args, "FeedName= ?", whereArgs); } catch (SQLiteException e) { // Log.d(TAG, "Update GTFS_FEED_TRACKER Update for: Calander_Dates Database Error: " + // e.toString()); } catch (Exception ex) { // Log.d(TAG, "Update GTFS_FEED_TRACKER Update for: Calander_Dates non-SQL Error: " + // ex.toString()); } finally { // House Keeping dbAdapter.close(); // Log.e(TAG, "GTFS_FEED_TRACKER Update for: Calander_Dates database CLOSED"); } }