List of usage examples for android.database.sqlite SQLiteConstraintException printStackTrace
public void printStackTrace()
From source file:com.appdynamics.demo.gasp.service.RestaurantSyncService.java
@Override public void onCompleted(String results) { Log.i(TAG, "Response from " + mGaspRestaurantsUri.toString() + " :" + results + '\n'); if (results != null) { try {/* w ww .j ava 2 s .c om*/ Gson gson = new Gson(); Type type = new TypeToken<List<Restaurant>>() { }.getType(); List<Restaurant> restaurants = gson.fromJson(results, type); // Check how many records already in local SQLite database long localRecords = checkLastId(); RestaurantDataAdapter restaurantsDB = new RestaurantDataAdapter(getApplicationContext()); restaurantsDB.open(); ListIterator<Restaurant> iterator = restaurants.listIterator(); int index = 0; while (iterator.hasNext()) { try { Restaurant restaurant = iterator.next(); if (restaurant.getId() > localRecords) { restaurantsDB.insert(restaurant); index = restaurant.getId(); } } catch (SQLiteConstraintException e) { e.printStackTrace(); } } restaurantsDB.close(); String resultTxt = "Sync: Found " + localRecords + ", Loaded " + index + " restaurants from " + mGaspRestaurantsUri; Log.i(TAG, resultTxt + '\n'); // Notify LocationsActivity that Gasp restaurant data has been synced LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(LocationsActivity.SYNC_COMPLETED)); } catch (Exception e) { e.printStackTrace(); } } }