List of usage examples for android.database.sqlite SQLiteDatabase beginTransactionNonExclusive
public void beginTransactionNonExclusive()
From source file:Main.java
public static void beginTransactionNonExclusive(SQLiteDatabase db) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { db.beginTransactionNonExclusive(); } else {/*from ww w . j a v a 2 s . c o m*/ db.beginTransaction(); } }
From source file:org.kontalk.provider.UsersProvider.java
@TargetApi(android.os.Build.VERSION_CODES.HONEYCOMB) private void beginTransaction(SQLiteDatabase db) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) db.beginTransactionNonExclusive(); else/*from ww w .j a v a2 s . c o m*/ // this is because API < 11 doesn't have beginTransactionNonExclusive() db.execSQL("BEGIN IMMEDIATE"); }
From source file:mobisocial.musubi.service.AddressBookUpdateHandler.java
@Override public void onChange(boolean selfChange) { final DatabaseManager dbManager = new DatabaseManager(mContext); if (!dbManager.getIdentitiesManager().hasConnectedAccounts()) { Log.w(TAG, "no connected accounts, skipping friend import"); return;// ww w. j a va 2 s . co m } //a new meta contact appears (and the previous ones disappear) if the user merges //or if a new entry is added, we can detect the ones that have changed by //this condition long highestContactIdAlreadySeen = dbManager.getContactDataVersionManager().getMaxContactIdSeen(); //a new data item corresponds with a new contact, but its possible //that a users just adds a new contact method to an existing contact //and we need to detect that long highestDataIdAlreadySeen = dbManager.getContactDataVersionManager().getMaxDataIdSeen(); // BJD -- this didn't end up being faster once all import features were added. /*if (highestContactIdAlreadySeen == -1) { importFullAddressBook(mContext); return; }*/ long now = System.currentTimeMillis(); if (mLastRun + ONCE_PER_PERIOD > now) { //wake up when the period expires if (!mScheduled) { new Handler(mThread.getLooper()).postDelayed(new Runnable() { @Override public void run() { mScheduled = false; dispatchChange(false); } }, ONCE_PER_PERIOD - (now - mLastRun) + 1); } mScheduled = true; //skip this update return; } Log.i(TAG, "waking up to handle contact changes..."); boolean identityAdded = false, profileDataChanged = false; Date start = new Date(); assert (SYNC_EMAIL); String account_type_selection = getAccountSelectionString(); Cursor c = mContext.getContentResolver().query( ContactsContract.Data.CONTENT_URI, new String[] { ContactsContract.Data._ID, ContactsContract.Data.DATA_VERSION, ContactsContract.Data.CONTACT_ID }, "(" + ContactsContract.Data.DATA_VERSION + ">0 OR " + //maybe updated ContactsContract.Data.CONTACT_ID + ">? OR " + //definitely new or merged ContactsContract.Data._ID + ">? " + //definitely added a data item ") AND (" + ContactsContract.RawContacts.ACCOUNT_TYPE + "<>'" + mAccountType + "'" + ") AND (" + NAME_OR_OTHER_SELECTION + account_type_selection + ")", // All known contacts. new String[] { String.valueOf(highestContactIdAlreadySeen), String.valueOf(highestDataIdAlreadySeen) }, null); if (c == null) { Log.e(TAG, "no valid cursor", new Throwable()); mContext.getContentResolver().notifyChange(MusubiService.ADDRESS_BOOK_SCANNED, this); return; } HashMap<Pair<String, String>, MMyAccount> account_mapping = new HashMap<Pair<String, String>, MMyAccount>(); int max_changes = c.getCount(); TLongArrayList raw_data_ids = new TLongArrayList(max_changes); TLongArrayList versions = new TLongArrayList(max_changes); long new_max_data_id = highestDataIdAlreadySeen; long new_max_contact_id = highestContactIdAlreadySeen; TLongHashSet potentially_changed = new TLongHashSet(); try { //the cursor points to a list of raw contact data items that may have changed //the items will include a type specific field that we are interested in updating //it is possible that multiple data item entries mention the same identifier //so we build a list of contacts to update and then perform synchronization //by refreshing given that we know the top level contact id. if (DBG) Log.d(TAG, "Scanning " + c.getCount() + " contacts..."); while (c.moveToNext()) { if (DBG) Log.v(TAG, "check for updates of contact " + c.getLong(0)); long raw_data_id = c.getLong(0); long version = c.getLong(1); long contact_id = c.getLong(2); //if the contact was split or merged, then we get a higher contact id //so if we have a higher id, data version doesnt really matter if (contact_id <= highestContactIdAlreadySeen) { //the data associated with this contact may not be dirty //we just can't do the join against our table because thise //api is implmented over the content provider if (dbManager.getContactDataVersionManager().getVersion(raw_data_id) == version) continue; } else { new_max_contact_id = Math.max(new_max_contact_id, contact_id); } raw_data_ids.add(raw_data_id); versions.add(version); potentially_changed.add(contact_id); new_max_data_id = Math.max(new_max_data_id, raw_data_id); } if (DBG) Log.d(TAG, "Finished iterating over " + c.getCount() + " contacts for " + potentially_changed.size() + " candidates."); } finally { c.close(); } if (potentially_changed.size() == 0) { Log.w(TAG, "possible bug, woke up to update contacts, but no change was detected; there are extra wakes so it could be ok"); } final SQLiteDatabase db = dbManager.getDatabase(); Pattern emailPattern = getEmailPattern(); Pattern numberPattern = getNumberPattern(); //slice it up so we don't use too much system resource on keeping a lot of state in memory int total = potentially_changed.size(); sAddressBookTotal = total; sAddressBookPosition = 0; final TLongArrayList slice_of_changed = new TLongArrayList(BATCH_SIZE); final StringBuilder to_fetch = new StringBuilder(); final HashMap<Pair<String, String>, TLongHashSet> ids_for_account = new HashMap<Pair<String, String>, TLongHashSet>(); final TLongObjectHashMap<String> names = new TLongObjectHashMap<String>(); TLongIterator it = potentially_changed.iterator(); for (int i = 0; i < total && it.hasNext();) { sAddressBookPosition = i; if (BootstrapActivity.isBootstrapped()) { try { Thread.sleep(mSleepTime * SLEEP_SCALE); } catch (InterruptedException e) { } } slice_of_changed.clear(); ids_for_account.clear(); names.clear(); int max = i + BATCH_SIZE; for (; i < max && it.hasNext(); ++i) { slice_of_changed.add(it.next()); } if (DBG) Log.v(TAG, "looking up names "); to_fetch.setLength(0); to_fetch.append(ContactsContract.Contacts._ID + " IN "); SQLClauseHelper.appendArray(to_fetch, slice_of_changed.iterator()); //lookup the fields we care about from a user profile perspective c = mContext.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, }, to_fetch.toString(), null, null); try { while (c.moveToNext()) { long id = c.getLong(0); String name = c.getString(1); if (name == null) continue; //reject names that are just the email address or are just a number //the default for android is just to propagate this as the name //if there is no name if (emailPattern.matcher(name).matches() || numberPattern.matcher(name).matches()) continue; names.put(id, name); } } finally { c.close(); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { db.beginTransactionNonExclusive(); } else { db.beginTransaction(); } long before = SystemClock.elapsedRealtime(); SliceUpdater updater = new SliceUpdater(dbManager, slice_of_changed, ids_for_account, names, account_type_selection); long after = SystemClock.elapsedRealtime(); mSleepTime = (mSleepTime + after - before) / 2; slice_of_changed.forEach(updater); profileDataChanged |= updater.profileDataChanged; identityAdded |= updater.identityAdded; db.setTransactionSuccessful(); db.endTransaction(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { db.beginTransactionNonExclusive(); } else { db.beginTransaction(); } //add all detected members to account feed for (Entry<Pair<String, String>, TLongHashSet> e : ids_for_account.entrySet()) { Pair<String, String> k = e.getKey(); TLongHashSet v = e.getValue(); MMyAccount cached_account = account_mapping.get(k); if (cached_account == null) { cached_account = lookupOrCreateAccount(dbManager, k.getValue0(), k.getValue1()); prepareAccountWhitelistFeed(dbManager.getMyAccountManager(), dbManager.getFeedManager(), cached_account); account_mapping.put(k, cached_account); } final MMyAccount account = cached_account; v.forEach(new TLongProcedure() { @Override public boolean execute(long id) { dbManager.getFeedManager().ensureFeedMember(account.feedId_, id); db.yieldIfContendedSafely(75); return true; } }); } db.setTransactionSuccessful(); db.endTransaction(); } sAddressBookTotal = sAddressBookPosition = 0; //TODO: handle deleted //for all android data ids in our table, check if they still exist in the //contacts table, probably in batches of 100 or something. if they don't //null them out. this is annoyingly non-differential. //TODO: adding friend should update accepted feed status, however, //if a crashe happens for whatever reason, then its possible that this may need to //be run for identities which actually exist in the db. so this update code //needs to do the feed accepted status change for all users that were touched //by the profile update process //update the version ids so we can be faster on subsequent runs if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { db.beginTransactionNonExclusive(); } else { db.beginTransaction(); } int changed_data_rows = raw_data_ids.size(); for (int i = 0; i < changed_data_rows; ++i) { dbManager.getContactDataVersionManager().setVersion(raw_data_ids.get(i), versions.get(i)); } db.setTransactionSuccessful(); db.endTransaction(); dbManager.getContactDataVersionManager().setMaxDataIdSeen(new_max_data_id); dbManager.getContactDataVersionManager().setMaxContactIdSeen(new_max_contact_id); ContentResolver resolver = mContext.getContentResolver(); Date end = new Date(); double time = end.getTime() - start.getTime(); time /= 1000; Log.w(TAG, "update address book " + mChangeCount++ + " took " + time + " seconds"); if (identityAdded) { //wake up the profile push resolver.notifyChange(MusubiService.WHITELIST_APPENDED, this); } if (profileDataChanged) { //refresh the ui... resolver.notifyChange(MusubiService.PRIMARY_CONTENT_CHANGED, this); } if (identityAdded || profileDataChanged) { //update the our musubi address book as needed. String accountName = mContext.getString(R.string.account_name); String accountType = mContext.getString(R.string.account_type); Account account = new Account(accountName, accountType); ContentResolver.requestSync(account, ContactsContract.AUTHORITY, new Bundle()); } dbManager.close(); mLastRun = new Date().getTime(); resolver.notifyChange(MusubiService.ADDRESS_BOOK_SCANNED, this); }
From source file:mobile.tiis.appv2.base.BackboneApplication.java
public void updateChildVaccinationEventVaccinationAppointment(ChildCollector childCollector) { Child child = childCollector.getChildEntity(); List<VaccinationEvent> vaccinationEvents = childCollector.getVeList(); List<VaccinationAppointment> vaccinationAppointments = childCollector.getVaList(); ContentValues childCV = new ContentValues(); DatabaseHandler db = getDatabaseInstance(); SQLiteDatabase db1 = db.getWritableDatabase(); db1.beginTransactionNonExclusive(); try {/*from w ww .ja va 2 s . c o m*/ String sql0 = "INSERT OR REPLACE INTO " + SQLHandler.Tables.CHILD + " ( " + SQLHandler.SyncColumns.UPDATED + ", " + SQLHandler.ChildColumns.ID + "," + SQLHandler.ChildColumns.BARCODE_ID + "," + SQLHandler.ChildColumns.FIRSTNAME1 + "," + SQLHandler.ChildColumns.FIRSTNAME2 + "," + SQLHandler.ChildColumns.LASTNAME1 + "," + SQLHandler.ChildColumns.BIRTHDATE + "," + SQLHandler.ChildColumns.GENDER + "," + SQLHandler.ChildColumns.TEMP_ID + "," + SQLHandler.ChildColumns.HEALTH_FACILITY + "," + SQLHandler.ChildColumns.DOMICILE + "," + SQLHandler.ChildColumns.DOMICILE_ID + "," + SQLHandler.ChildColumns.HEALTH_FACILITY_ID + "," + SQLHandler.ChildColumns.STATUS_ID + "," + SQLHandler.ChildColumns.BIRTHPLACE_ID + "," + SQLHandler.ChildColumns.NOTES + "," + SQLHandler.ChildColumns.STATUS + "," + SQLHandler.ChildColumns.MOTHER_FIRSTNAME + "," + SQLHandler.ChildColumns.MOTHER_LASTNAME + "," + SQLHandler.ChildColumns.CUMULATIVE_SERIAL_NUMBER + "," + SQLHandler.ChildColumns.CHILD_REGISTRY_YEAR + "," + SQLHandler.ChildColumns.MOTHER_TT2_STS + "," + SQLHandler.ChildColumns.MOTHER_VVU_STS + "," + SQLHandler.ChildColumns.PHONE + " ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; SQLiteStatement stmt0 = db1.compileStatement(sql0); stmt0.bindString(1, "1"); stmt0.bindString(2, child.getId() == null ? "" : child.getId()); stmt0.bindString(3, child.getBarcodeID() == null ? "" : child.getBarcodeID()); stmt0.bindString(4, child.getFirstname1() == null ? "" : child.getFirstname1()); stmt0.bindString(5, child.getFirstname2() == null ? "" : child.getFirstname2()); stmt0.bindString(6, child.getLastname1() == null ? "" : child.getLastname1()); stmt0.bindString(7, child.getBirthdate() == null ? "" : child.getBirthdate()); stmt0.bindString(8, child.getGender() == null ? "" : child.getGender()); stmt0.bindString(9, child.getTempId() == null ? "" : child.getTempId()); stmt0.bindString(10, child.getHealthcenter() == null ? "" : child.getHealthcenter()); stmt0.bindString(11, child.getDomicile() == null ? "" : child.getDomicile()); stmt0.bindString(12, child.getDomicileId() == null ? "" : child.getDomicileId()); stmt0.bindString(13, child.getHealthcenterId() == null ? "" : child.getHealthcenterId()); stmt0.bindString(14, child.getStatusId() == null ? "" : child.getStatusId()); stmt0.bindString(15, child.getBirthplaceId() == null ? "" : child.getBirthplaceId()); stmt0.bindString(16, child.getNotes() == null ? "" : child.getNotes()); stmt0.bindString(17, child.getStatus() == null ? "" : child.getStatus()); stmt0.bindString(18, child.getMotherFirstname() == null ? "" : child.getMotherFirstname()); stmt0.bindString(19, child.getMotherLastname() == null ? "" : child.getMotherLastname()); stmt0.bindString(20, child.getChildCumulativeSn() == null ? "" : child.getChildCumulativeSn()); stmt0.bindString(21, child.getChildRegistryYear() == null ? "" : child.getChildRegistryYear()); stmt0.bindString(22, child.getMotherTT2Status() == null ? "" : child.getMotherTT2Status()); stmt0.bindString(23, child.getMotherHivStatus() == null ? "" : child.getMotherHivStatus()); stmt0.bindString(24, child.getPhone() == null ? "" : child.getPhone()); stmt0.execute(); stmt0.clearBindings(); String sql = "INSERT OR REPLACE INTO " + SQLHandler.Tables.VACCINATION_EVENT + " ( " + SQLHandler.SyncColumns.UPDATED + ", " + SQLHandler.VaccinationEventColumns.APPOINTMENT_ID + "," + SQLHandler.VaccinationEventColumns.CHILD_ID + "," + SQLHandler.VaccinationEventColumns.DOSE_ID + "," + SQLHandler.VaccinationEventColumns.HEALTH_FACILITY_ID + "," + SQLHandler.VaccinationEventColumns.ID + "," + SQLHandler.VaccinationEventColumns.IS_ACTIVE + "," + SQLHandler.VaccinationEventColumns.MODIFIED_BY + "," + SQLHandler.VaccinationEventColumns.MODIFIED_ON + "," + SQLHandler.VaccinationEventColumns.NONVACCINATION_REASON_ID + "," + SQLHandler.VaccinationEventColumns.SCHEDULED_DATE + "," + SQLHandler.VaccinationEventColumns.VACCINATION_DATE + "," + SQLHandler.VaccinationEventColumns.VACCINATION_STATUS + "," + SQLHandler.VaccinationEventColumns.VACCINE_LOT_ID + " ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; SQLiteStatement stmt = db1.compileStatement(sql); for (VaccinationEvent vaccinationEvent : vaccinationEvents) { stmt.bindString(1, "1"); stmt.bindString(2, vaccinationEvent.getAppointmentId()); stmt.bindString(3, vaccinationEvent.getChildId()); stmt.bindString(4, vaccinationEvent.getDoseId()); stmt.bindString(5, vaccinationEvent.getHealthFacilityId()); stmt.bindString(6, vaccinationEvent.getId()); stmt.bindString(7, vaccinationEvent.getIsActive()); stmt.bindString(8, vaccinationEvent.getModifiedBy()); stmt.bindString(9, vaccinationEvent.getModifiedOn()); stmt.bindString(10, vaccinationEvent.getNonvaccinationReasonId()); stmt.bindString(11, vaccinationEvent.getScheduledDate()); stmt.bindString(12, vaccinationEvent.getVaccinationDate()); stmt.bindString(13, vaccinationEvent.getVaccinationStatus()); stmt.bindString(14, vaccinationEvent.getVaccineLotId()); stmt.execute(); stmt.clearBindings(); } String sql1 = "INSERT OR REPLACE INTO " + SQLHandler.Tables.VACCINATION_APPOINTMENT + " ( " + SQLHandler.SyncColumns.UPDATED + ", " + SQLHandler.VaccinationAppointmentColumns.CHILD_ID + "," + SQLHandler.VaccinationAppointmentColumns.ID + "," + SQLHandler.VaccinationAppointmentColumns.IS_ACTIVE + "," + SQLHandler.VaccinationAppointmentColumns.MODIFIED_BY + "," + SQLHandler.VaccinationAppointmentColumns.MODIFIED_ON + "," + SQLHandler.VaccinationAppointmentColumns.NOTES + "," + SQLHandler.VaccinationAppointmentColumns.OUTREACH + "," + SQLHandler.VaccinationAppointmentColumns.SCHEDULED_DATE + "," + SQLHandler.VaccinationAppointmentColumns.SCHEDULED_FACILITY_ID + " ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?,?)"; SQLiteStatement stmt1 = db1.compileStatement(sql1); for (VaccinationAppointment vaccinationAppointment : vaccinationAppointments) { stmt1.bindString(1, "1"); stmt1.bindString(2, vaccinationAppointment.getChildId()); stmt1.bindString(3, vaccinationAppointment.getId()); stmt1.bindString(4, vaccinationAppointment.getIsActive()); stmt1.bindString(5, vaccinationAppointment.getModifiedBy()); stmt1.bindString(6, vaccinationAppointment.getModifiedOn()); stmt1.bindString(7, vaccinationAppointment.getNotes()); stmt1.bindString(8, vaccinationAppointment.getOutreach()); stmt1.bindString(9, vaccinationAppointment.getScheduledDate()); stmt1.bindString(10, vaccinationAppointment.getScheduledFacilityId()); stmt1.execute(); stmt1.clearBindings(); } db1.setTransactionSuccessful(); db1.endTransaction(); } catch (Exception e) { db1.endTransaction(); e.printStackTrace(); } }
From source file:mobile.tiis.appv2.base.BackboneApplication.java
/** * method used to add child, vaccination appointments and vaccination events into the database * * @param childCollector/*from w w w .j av a2s . c o m*/ */ public void addChildVaccinationEventVaccinationAppointment(ChildCollector childCollector) { Child child = childCollector.getChildEntity(); List<VaccinationEvent> vaccinationEvents = childCollector.getVeList(); List<VaccinationAppointment> vaccinationAppointments = childCollector.getVaList(); ContentValues childCV = new ContentValues(); DatabaseHandler db = getDatabaseInstance(); SQLiteDatabase db1 = db.getWritableDatabase(); db1.beginTransactionNonExclusive(); try { String sql0 = "INSERT OR REPLACE INTO " + SQLHandler.Tables.CHILD + " ( " + SQLHandler.SyncColumns.UPDATED + ", " + SQLHandler.ChildColumns.ID + "," + SQLHandler.ChildColumns.BARCODE_ID + "," + SQLHandler.ChildColumns.FIRSTNAME1 + "," + SQLHandler.ChildColumns.FIRSTNAME2 + "," + SQLHandler.ChildColumns.LASTNAME1 + "," + SQLHandler.ChildColumns.BIRTHDATE + "," + SQLHandler.ChildColumns.GENDER + "," + SQLHandler.ChildColumns.TEMP_ID + "," + SQLHandler.ChildColumns.HEALTH_FACILITY + "," + SQLHandler.ChildColumns.DOMICILE + "," + SQLHandler.ChildColumns.DOMICILE_ID + "," + SQLHandler.ChildColumns.HEALTH_FACILITY_ID + "," + SQLHandler.ChildColumns.STATUS_ID + "," + SQLHandler.ChildColumns.BIRTHPLACE_ID + "," + SQLHandler.ChildColumns.NOTES + "," + SQLHandler.ChildColumns.STATUS + "," + SQLHandler.ChildColumns.MOTHER_FIRSTNAME + "," + SQLHandler.ChildColumns.MOTHER_LASTNAME + "," + SQLHandler.ChildColumns.CUMULATIVE_SERIAL_NUMBER + "," + SQLHandler.ChildColumns.CHILD_REGISTRY_YEAR + "," + SQLHandler.ChildColumns.MOTHER_TT2_STS + "," + SQLHandler.ChildColumns.MOTHER_VVU_STS + "," + SQLHandler.ChildColumns.PHONE + " ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; SQLiteStatement stmt0 = db1.compileStatement(sql0); stmt0.bindString(1, "1"); stmt0.bindString(2, child.getId() == null ? "" : child.getId()); stmt0.bindString(3, child.getBarcodeID() == null ? "" : child.getBarcodeID()); stmt0.bindString(4, child.getFirstname1() == null ? "" : child.getFirstname1()); stmt0.bindString(5, child.getFirstname2() == null ? "" : child.getFirstname2()); stmt0.bindString(6, child.getLastname1() == null ? "" : child.getLastname1()); stmt0.bindString(7, child.getBirthdate() == null ? "" : child.getBirthdate()); stmt0.bindString(8, child.getGender() == null ? "" : child.getGender()); stmt0.bindString(9, child.getTempId() == null ? "" : child.getTempId()); stmt0.bindString(10, child.getHealthcenter() == null ? "" : child.getHealthcenter()); stmt0.bindString(11, child.getDomicile() == null ? "" : child.getDomicile()); stmt0.bindString(12, child.getDomicileId() == null ? "" : child.getDomicileId()); stmt0.bindString(13, child.getHealthcenterId() == null ? "" : child.getHealthcenterId()); stmt0.bindString(14, child.getStatusId() == null ? "" : child.getStatusId()); stmt0.bindString(15, child.getBirthplaceId() == null ? "" : child.getBirthplaceId()); stmt0.bindString(16, child.getNotes() == null ? "" : child.getNotes()); stmt0.bindString(17, child.getStatus() == null ? "" : child.getStatus()); stmt0.bindString(18, child.getMotherFirstname() == null ? "" : child.getMotherFirstname()); stmt0.bindString(19, child.getMotherLastname() == null ? "" : child.getMotherLastname()); stmt0.bindString(20, child.getChildCumulativeSn() == null ? "" : child.getChildCumulativeSn()); stmt0.bindString(21, child.getChildRegistryYear() == null ? "" : child.getChildRegistryYear()); stmt0.bindString(22, child.getMotherTT2Status() == null ? "" : child.getMotherTT2Status()); stmt0.bindString(23, child.getMotherHivStatus() == null ? "" : child.getMotherHivStatus()); stmt0.bindString(24, child.getPhone() == null ? "" : child.getPhone()); stmt0.execute(); stmt0.clearBindings(); String sql = "INSERT OR REPLACE INTO " + SQLHandler.Tables.VACCINATION_EVENT + " ( " + SQLHandler.SyncColumns.UPDATED + ", " + SQLHandler.VaccinationEventColumns.APPOINTMENT_ID + "," + SQLHandler.VaccinationEventColumns.CHILD_ID + "," + SQLHandler.VaccinationEventColumns.DOSE_ID + "," + SQLHandler.VaccinationEventColumns.HEALTH_FACILITY_ID + "," + SQLHandler.VaccinationEventColumns.ID + "," + SQLHandler.VaccinationEventColumns.IS_ACTIVE + "," + SQLHandler.VaccinationEventColumns.MODIFIED_BY + "," + SQLHandler.VaccinationEventColumns.MODIFIED_ON + "," + SQLHandler.VaccinationEventColumns.NONVACCINATION_REASON_ID + "," + SQLHandler.VaccinationEventColumns.SCHEDULED_DATE + "," + SQLHandler.VaccinationEventColumns.VACCINATION_DATE + "," + SQLHandler.VaccinationEventColumns.VACCINATION_STATUS + "," + SQLHandler.VaccinationEventColumns.VACCINE_LOT_ID + " ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; SQLiteStatement stmt = db1.compileStatement(sql); for (VaccinationEvent vaccinationEvent : vaccinationEvents) { stmt.bindString(1, "1"); stmt.bindString(2, vaccinationEvent.getAppointmentId()); stmt.bindString(3, vaccinationEvent.getChildId()); stmt.bindString(4, vaccinationEvent.getDoseId()); stmt.bindString(5, vaccinationEvent.getHealthFacilityId()); stmt.bindString(6, vaccinationEvent.getId()); stmt.bindString(7, vaccinationEvent.getIsActive()); stmt.bindString(8, vaccinationEvent.getModifiedBy()); stmt.bindString(9, vaccinationEvent.getModifiedOn()); stmt.bindString(10, vaccinationEvent.getNonvaccinationReasonId()); stmt.bindString(11, vaccinationEvent.getScheduledDate()); stmt.bindString(12, vaccinationEvent.getVaccinationDate()); stmt.bindString(13, vaccinationEvent.getVaccinationStatus()); stmt.bindString(14, vaccinationEvent.getVaccineLotId()); stmt.execute(); stmt.clearBindings(); } String sql1 = "INSERT OR REPLACE INTO " + SQLHandler.Tables.VACCINATION_APPOINTMENT + " ( " + SQLHandler.SyncColumns.UPDATED + ", " + SQLHandler.VaccinationAppointmentColumns.CHILD_ID + "," + SQLHandler.VaccinationAppointmentColumns.ID + "," + SQLHandler.VaccinationAppointmentColumns.IS_ACTIVE + "," + SQLHandler.VaccinationAppointmentColumns.MODIFIED_BY + "," + SQLHandler.VaccinationAppointmentColumns.MODIFIED_ON + "," + SQLHandler.VaccinationAppointmentColumns.NOTES + "," + SQLHandler.VaccinationAppointmentColumns.OUTREACH + "," + SQLHandler.VaccinationAppointmentColumns.SCHEDULED_DATE + "," + SQLHandler.VaccinationAppointmentColumns.SCHEDULED_FACILITY_ID + " ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?,?)"; SQLiteStatement stmt1 = db1.compileStatement(sql1); for (VaccinationAppointment vaccinationAppointment : vaccinationAppointments) { stmt1.bindString(1, "1"); stmt1.bindString(2, vaccinationAppointment.getChildId()); stmt1.bindString(3, vaccinationAppointment.getId()); stmt1.bindString(4, vaccinationAppointment.getIsActive()); stmt1.bindString(5, vaccinationAppointment.getModifiedBy()); stmt1.bindString(6, vaccinationAppointment.getModifiedOn()); stmt1.bindString(7, vaccinationAppointment.getNotes()); stmt1.bindString(8, vaccinationAppointment.getOutreach()); stmt1.bindString(9, vaccinationAppointment.getScheduledDate()); stmt1.bindString(10, vaccinationAppointment.getScheduledFacilityId()); stmt1.execute(); stmt1.clearBindings(); } db1.setTransactionSuccessful(); db1.endTransaction(); } catch (Exception e) { db1.endTransaction(); e.printStackTrace(); } }
From source file:mobile.tiis.appv2.base.BackboneApplication.java
public boolean addChildVaccinationEventVaccinationAppointment(ChildCollector2 childCollector) { Log.d("coze", "saving data to db"); boolean containsData = false; List<Child> children = childCollector.getChildList(); List<VaccinationEvent> vaccinationEvents = childCollector.getVeList(); List<VaccinationAppointment> vaccinationAppointments = childCollector.getVaList(); DatabaseHandler db = getDatabaseInstance(); SQLiteDatabase db1 = db.getWritableDatabase(); db1.beginTransactionNonExclusive(); try {/* ww w. j a va 2 s . c o m*/ if (children != null) { String sql0 = "INSERT OR REPLACE INTO " + SQLHandler.Tables.CHILD + " ( " + SQLHandler.SyncColumns.UPDATED + ", " + SQLHandler.ChildColumns.ID + "," + SQLHandler.ChildColumns.BARCODE_ID + "," + SQLHandler.ChildColumns.FIRSTNAME1 + "," + SQLHandler.ChildColumns.FIRSTNAME2 + "," + SQLHandler.ChildColumns.LASTNAME1 + "," + SQLHandler.ChildColumns.BIRTHDATE + "," + SQLHandler.ChildColumns.GENDER + "," + SQLHandler.ChildColumns.TEMP_ID + "," + SQLHandler.ChildColumns.HEALTH_FACILITY + "," + SQLHandler.ChildColumns.DOMICILE + "," + SQLHandler.ChildColumns.DOMICILE_ID + "," + SQLHandler.ChildColumns.HEALTH_FACILITY_ID + "," + SQLHandler.ChildColumns.STATUS_ID + "," + SQLHandler.ChildColumns.BIRTHPLACE_ID + "," + SQLHandler.ChildColumns.NOTES + "," + SQLHandler.ChildColumns.STATUS + "," + SQLHandler.ChildColumns.MOTHER_FIRSTNAME + "," + SQLHandler.ChildColumns.MOTHER_LASTNAME + "," + SQLHandler.ChildColumns.PHONE + "," + SQLHandler.ChildColumns.CUMULATIVE_SERIAL_NUMBER + "," + SQLHandler.ChildColumns.CHILD_REGISTRY_YEAR + "," + SQLHandler.ChildColumns.MOTHER_VVU_STS + "," + SQLHandler.ChildColumns.MOTHER_TT2_STS + "," + SQLHandler.ChildColumns.MODIFIED_ON + " ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?,?,?,?)"; SQLiteStatement stmt0 = db1.compileStatement(sql0); for (Child child : children) { containsData = true; stmt0.bindString(1, "1"); stmt0.bindString(2, child.getId() == null ? "" : child.getId()); stmt0.bindString(3, child.getBarcodeID() == null ? "" : child.getBarcodeID()); stmt0.bindString(4, child.getFirstname1() == null ? "" : child.getFirstname1()); stmt0.bindString(5, child.getFirstname2() == null ? "" : child.getFirstname2()); stmt0.bindString(6, child.getLastname1() == null ? "" : child.getLastname1()); stmt0.bindString(7, child.getBirthdate() == null ? "" : child.getBirthdate()); stmt0.bindString(8, child.getGender() == null ? "" : child.getGender()); stmt0.bindString(9, child.getTempId() == null ? "" : child.getTempId()); stmt0.bindString(10, child.getHealthcenter() == null ? "" : child.getHealthcenter()); stmt0.bindString(11, child.getDomicile() == null ? "" : child.getDomicile()); stmt0.bindString(12, child.getDomicileId() == null ? "" : child.getDomicileId()); stmt0.bindString(13, child.getHealthcenterId() == null ? "" : child.getHealthcenterId()); stmt0.bindString(14, child.getStatusId() == null ? "" : child.getStatusId()); stmt0.bindString(15, child.getBirthplaceId() == null ? "" : child.getBirthplaceId()); stmt0.bindString(16, child.getNotes() == null ? "" : child.getNotes()); stmt0.bindString(17, child.getDomicile() == null ? "" : child.getDomicile()); stmt0.bindString(18, child.getMotherFirstname() == null ? "" : child.getMotherFirstname()); stmt0.bindString(19, child.getMotherLastname() == null ? "" : child.getMotherLastname()); stmt0.bindString(20, child.getPhone() == null ? "" : child.getPhone()); stmt0.bindString(21, child.getChildCumulativeSn() == null ? "" : child.getChildCumulativeSn()); stmt0.bindString(22, child.getChildRegistryYear() == null ? "" : child.getChildRegistryYear()); stmt0.bindString(23, child.getMotherHivStatus() == null ? "" : child.getMotherHivStatus()); stmt0.bindString(24, child.getMotherTT2Status() == null ? "" : child.getMotherTT2Status()); stmt0.bindString(25, child.getModifiedOn() == null ? "" : child.getModifiedOn()); stmt0.execute(); stmt0.clearBindings(); } } if (vaccinationEvents != null) { String sql = "INSERT OR REPLACE INTO " + SQLHandler.Tables.VACCINATION_EVENT + " ( " + SQLHandler.SyncColumns.UPDATED + ", " + SQLHandler.VaccinationEventColumns.APPOINTMENT_ID + "," + SQLHandler.VaccinationEventColumns.CHILD_ID + "," + SQLHandler.VaccinationEventColumns.DOSE_ID + "," + SQLHandler.VaccinationEventColumns.HEALTH_FACILITY_ID + "," + SQLHandler.VaccinationEventColumns.ID + "," + SQLHandler.VaccinationEventColumns.IS_ACTIVE + "," + SQLHandler.VaccinationEventColumns.MODIFIED_BY + "," + SQLHandler.VaccinationEventColumns.MODIFIED_ON + "," + SQLHandler.VaccinationEventColumns.NONVACCINATION_REASON_ID + "," + SQLHandler.VaccinationEventColumns.SCHEDULED_DATE + "," + SQLHandler.VaccinationEventColumns.VACCINATION_DATE + "," + SQLHandler.VaccinationEventColumns.VACCINATION_STATUS + "," + SQLHandler.VaccinationEventColumns.VACCINE_LOT_ID + " ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; SQLiteStatement stmt = db1.compileStatement(sql); for (VaccinationEvent vaccinationEvent : vaccinationEvents) { containsData = true; stmt.bindString(1, "1"); stmt.bindString(2, vaccinationEvent.getAppointmentId()); stmt.bindString(3, vaccinationEvent.getChildId()); stmt.bindString(4, vaccinationEvent.getDoseId()); stmt.bindString(5, vaccinationEvent.getHealthFacilityId()); stmt.bindString(6, vaccinationEvent.getId()); stmt.bindString(7, vaccinationEvent.getIsActive()); stmt.bindString(8, vaccinationEvent.getModifiedBy()); stmt.bindString(9, vaccinationEvent.getModifiedOn()); stmt.bindString(10, vaccinationEvent.getNonvaccinationReasonId()); stmt.bindString(11, vaccinationEvent.getScheduledDate()); stmt.bindString(12, vaccinationEvent.getVaccinationDate()); stmt.bindString(13, vaccinationEvent.getVaccinationStatus()); stmt.bindString(14, vaccinationEvent.getVaccineLotId()); stmt.execute(); stmt.clearBindings(); } } if (vaccinationAppointments != null) { String sql1 = "INSERT OR REPLACE INTO " + SQLHandler.Tables.VACCINATION_APPOINTMENT + " ( " + SQLHandler.SyncColumns.UPDATED + ", " + SQLHandler.VaccinationAppointmentColumns.CHILD_ID + "," + SQLHandler.VaccinationAppointmentColumns.ID + "," + SQLHandler.VaccinationAppointmentColumns.IS_ACTIVE + "," + SQLHandler.VaccinationAppointmentColumns.MODIFIED_BY + "," + SQLHandler.VaccinationAppointmentColumns.MODIFIED_ON + "," + SQLHandler.VaccinationAppointmentColumns.NOTES + "," + SQLHandler.VaccinationAppointmentColumns.OUTREACH + "," + SQLHandler.VaccinationAppointmentColumns.SCHEDULED_DATE + "," + SQLHandler.VaccinationAppointmentColumns.SCHEDULED_FACILITY_ID + " ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?,?)"; SQLiteStatement stmt1 = db1.compileStatement(sql1); for (VaccinationAppointment vaccinationAppointment : vaccinationAppointments) { containsData = true; stmt1.bindString(1, "1"); stmt1.bindString(2, vaccinationAppointment.getChildId()); stmt1.bindString(3, vaccinationAppointment.getId()); stmt1.bindString(4, vaccinationAppointment.getIsActive()); stmt1.bindString(5, vaccinationAppointment.getModifiedBy()); stmt1.bindString(6, vaccinationAppointment.getModifiedOn()); stmt1.bindString(7, vaccinationAppointment.getNotes()); stmt1.bindString(8, vaccinationAppointment.getOutreach()); stmt1.bindString(9, vaccinationAppointment.getScheduledDate()); stmt1.bindString(10, vaccinationAppointment.getScheduledFacilityId()); Log.d("day20", "Out Reach for " + vaccinationAppointment.getChildId() + " is : " + vaccinationAppointment.getOutreach()); stmt1.execute(); stmt1.clearBindings(); } } db1.setTransactionSuccessful(); db1.endTransaction(); } catch (Exception e) { try { db1.endTransaction(); } catch (Exception e1) { e1.printStackTrace(); } e.printStackTrace(); } Log.d("coze", "saving data to db returning = " + containsData); return containsData; }