List of usage examples for android.content ContentValues get
public Object get(String key)
From source file:org.opendatakit.services.instance.provider.InstanceProvider.java
@Override public synchronized int update(@NonNull Uri uri, ContentValues cv, String where, String[] whereArgs) { possiblyWaitForContentProviderDebugger(); List<String> segments = uri.getPathSegments(); if (segments.size() != 3) { throw new SQLException("Unknown URI (does not specify instance!) " + uri); }//from w ww . j ava2s. com String appName = segments.get(0); ODKFileUtils.verifyExternalStorageAvailability(); ODKFileUtils.assertDirectoryStructure(appName); String tableId = segments.get(1); // _ID in UPLOADS_TABLE_NAME String instanceId = segments.get(2); DbHandle dbHandleName = OdkConnectionFactorySingleton.getOdkConnectionFactoryInterface() .generateInternalUseDbHandle(); OdkConnectionInterface db = null; int count = 0; try { // +1 referenceCount if db is returned (non-null) db = OdkConnectionFactorySingleton.getOdkConnectionFactoryInterface().getConnection(appName, dbHandleName); db.beginTransactionNonExclusive(); boolean success = false; try { success = ODKDatabaseImplUtils.get().hasTableId(db, tableId); } catch (Exception e) { WebLogger.getLogger(appName).printStackTrace(e); throw new SQLException("Unknown URI (exception testing for tableId) " + uri); } if (!success) { throw new SQLException("Unknown URI (missing data table for tableId) " + uri); } internalUpdate(db, uri, appName, tableId); // run the query to get all the ids... List<IdStruct> idStructs = new ArrayList<IdStruct>(); Cursor ref = null; try { // use this provider's query interface to get the set of ids that // match (if any) ref = internalQuery(db, uri, appName, tableId, instanceId, null, where, whereArgs, null); ref.moveToFirst(); if (ref.getCount() != 0) { do { String iId = CursorUtils.getIndexAsString(ref, ref.getColumnIndex(InstanceColumns._ID)); String iIdDataTable = CursorUtils.getIndexAsString(ref, ref.getColumnIndex(InstanceColumns.DATA_INSTANCE_ID)); idStructs.add(new IdStruct(iId, iIdDataTable)); } while (ref.moveToNext()); } } finally { if (ref != null) { ref.close(); } } // update the values string... if (cv.containsKey(InstanceColumns.XML_PUBLISH_STATUS)) { Date xmlPublishDate = new Date(); cv.put(InstanceColumns.XML_PUBLISH_TIMESTAMP, TableConstants.nanoSecondsFromMillis(xmlPublishDate.getTime())); String xmlPublishStatus = cv.getAsString(InstanceColumns.XML_PUBLISH_STATUS); if (!cv.containsKey(InstanceColumns.DISPLAY_SUBTEXT)) { String text = getDisplaySubtext(xmlPublishStatus, xmlPublishDate); cv.put(InstanceColumns.DISPLAY_SUBTEXT, text); } } Map<String, Object> values = new HashMap<String, Object>(); for (String key : cv.keySet()) { values.put(key, cv.get(key)); } Object[] args = new String[1]; for (IdStruct idStruct : idStructs) { args[0] = idStruct.idUploadsTable; count += db.update(DatabaseConstants.UPLOADS_TABLE_NAME, values, InstanceColumns._ID + "=?", args); } db.setTransactionSuccessful(); } finally { if (db != null) { try { if (db.inTransaction()) { db.endTransaction(); } } finally { try { db.releaseReference(); } finally { // this closes the connection OdkConnectionFactorySingleton.getOdkConnectionFactoryInterface().removeConnection(appName, dbHandleName); } } } } getContext().getContentResolver().notifyChange(uri, null); return count; }
From source file:watch.oms.omswatch.actioncenter.helpers.WatchTransDBParser.java
private void processJsonData(String servertableName, JSONObject tableJSON) { Iterator tableIterator;/* w w w . ja v a 2 s . c o m*/ ContentValues contentvalues = new ContentValues(); String colName; String primaryKeyVal; Double timeStamp; Set cols = new HashSet<String>(); cols = sp.getStringSet(servertableName, cols); String colVal; try { //adding root attribute to table if it is there in table if (rootAttribute != null) { for (String rootKey : rootAttribute.keySet()) { if (cols != null && cols.contains(rootKey)) { contentvalues.put(rootKey, rootAttribute.get(rootKey)); } else { Log.d(TAG, "skipping server column:" + rootKey); } } } tableIterator = tableJSON.keys(); while (tableIterator.hasNext()) { colName = (String) tableIterator.next(); if (colName.equalsIgnoreCase(OMSDatabaseConstants.UNIQUE_ROW_ID)) { primaryKeyVal = tableJSON.getString(colName); contentvalues.put(colName, primaryKeyVal); } else if (colName.equalsIgnoreCase(OMSDatabaseConstants.MODIFIED_DATE)) { timeStamp = tableJSON.getDouble(colName); contentvalues.put(colName, timeStamp); } else { if (cols != null && cols.contains(colName)) { colVal = tableJSON.getString(colName); contentvalues.put(colName, colVal.trim()); } else { Log.d(TAG, "skipping server column:" + colName); } } } } catch (JSONException je) { Log.e(TAG, "Error:" + je.getMessage()); } // This changes are for Oasis Project. # Start //Oasis Tables only // if(servertableName.equalsIgnoreCase("BillToDetails") // ||servertableName.equalsIgnoreCase("OrdSearchCriteriaList") // ||servertableName.equalsIgnoreCase("OrderDetails") // ||servertableName.equalsIgnoreCase("OrderSearch") // ||servertableName.equalsIgnoreCase("OrderTitles") // ||servertableName.equalsIgnoreCase("Orders") // ||servertableName.equalsIgnoreCase("DeliveryInfo") // ||servertableName.equalsIgnoreCase("ShipmentDetails") // ||servertableName.equalsIgnoreCase("AccountShipToDetail")) // contentvalues.put("isdelete", 0); // This changes are for Oasis Project. # End if (OMSConstants.tableKeyMap.size() > 0 && OMSConstants.tableKeyMap.containsKey(servertableName)) { String serverPrimaryKeyVal = contentvalues.get(OMSConstants.tableKeyMap.get(servertableName)) .toString(); Log.d(TAG, "serverPrimaryKey:" + servertableName + "." + OMSConstants.tableKeyMap.get(servertableName) + "[" + serverPrimaryKeyVal + "]"); if (serverPrimaryKeyVal != null) { contentvalues.put(OMSDatabaseConstants.UNIQUE_ROW_ID, serverPrimaryKeyVal); } } //Log.d(TAG, "contentvalues:"+contentvalues); int insertedRowId = configDBParserHelper.insertOrUpdateTransDB(servertableName, contentvalues); Log.d(TAG, "Inserted into " + servertableName + " insert value : " + insertedRowId); }
From source file:org.opendatakit.services.forms.provider.FormsProvider.java
@Override public synchronized int update(@NonNull Uri uri, ContentValues values, String where, String[] whereArgs) { possiblyWaitForContentProviderDebugger(); List<String> segments = uri.getPathSegments(); PatchedFilter pf = extractUriFeatures(uri, segments, where, whereArgs); WebLoggerIf logger = WebLogger.getLogger(pf.appName); /*/*ww w.ja v a2 s.c o m*/ * First, find out what records match this query. Replicate the * ContentValues if there are multiple tableIds/formIds involved * and the contentValues do not have formId and tableId specified. * * Otherwise, it is an error to specify the tableId or formId in * the ContentValues and have those not match the where results. * */ String contentTableId = (values != null && values.containsKey(FormsColumns.TABLE_ID)) ? values.getAsString(FormsColumns.TABLE_ID) : null; String contentFormId = (values != null && values.containsKey(FormsColumns.FORM_ID)) ? values.getAsString(FormsColumns.FORM_ID) : null; HashMap<FormSpec, HashMap<String, Object>> matchedValues = new HashMap<FormSpec, HashMap<String, Object>>(); DbHandle dbHandleName = OdkConnectionFactorySingleton.getOdkConnectionFactoryInterface() .generateInternalUseDbHandle(); OdkConnectionInterface db = null; try { // +1 referenceCount if db is returned (non-null) db = OdkConnectionFactorySingleton.getOdkConnectionFactoryInterface().getConnection(pf.appName, dbHandleName); db.beginTransactionNonExclusive(); Cursor c = null; try { c = db.query(DatabaseConstants.FORMS_TABLE_NAME, null, pf.whereId, pf.whereIdArgs, null, null, null, null); if (c == null) { throw new SQLException( "FAILED Update of " + uri + " -- query for existing row did not return a cursor"); } if (c.moveToFirst()) { int idxId = c.getColumnIndex(FormsColumns._ID); int idxTableId = c.getColumnIndex(FormsColumns.TABLE_ID); int idxFormId = c.getColumnIndex(FormsColumns.FORM_ID); Integer idValue = null; String tableIdValue = null; String formIdValue = null; do { idValue = CursorUtils.getIndexAsType(c, Integer.class, idxId); tableIdValue = CursorUtils.getIndexAsString(c, idxTableId); formIdValue = CursorUtils.getIndexAsString(c, idxFormId); if (contentTableId != null && !contentTableId.equals(tableIdValue)) { throw new SQLException("Modification of tableId for an existing form is prohibited"); } if (contentFormId != null && !contentFormId.equals(formIdValue)) { throw new SQLException("Modification of formId for an existing form is prohibited"); } HashMap<String, Object> cv = new HashMap<String, Object>(); if (values != null) { for (String key : values.keySet()) { cv.put(key, values.get(key)); } } cv.put(FormsColumns.TABLE_ID, tableIdValue); cv.put(FormsColumns.FORM_ID, formIdValue); for (int idx = 0; idx < c.getColumnCount(); ++idx) { String colName = c.getColumnName(idx); if (colName.equals(FormsColumns._ID)) { // don't insert the PK continue; } if (c.isNull(idx)) { cv.put(colName, null); } else { // everything else, we control... Class<?> dataType = CursorUtils.getIndexDataType(c, idx); if (dataType == String.class) { cv.put(colName, CursorUtils.getIndexAsString(c, idx)); } else if (dataType == Long.class) { cv.put(colName, CursorUtils.getIndexAsType(c, Long.class, idx)); } else if (dataType == Double.class) { cv.put(colName, CursorUtils.getIndexAsType(c, Double.class, idx)); } } } FormSpec formSpec = patchUpValues(pf.appName, cv); formSpec._id = idValue.toString(); formSpec.success = false; matchedValues.put(formSpec, cv); } while (c.moveToNext()); } else { // no match on where clause... return 0; } } finally { if (c != null && !c.isClosed()) { c.close(); } } // go through the entries and update the database with these patched-up values... for (Entry<FormSpec, HashMap<String, Object>> e : matchedValues.entrySet()) { FormSpec fs = e.getKey(); HashMap<String, Object> cv = e.getValue(); if (db.update(DatabaseConstants.FORMS_TABLE_NAME, cv, FormsColumns._ID + "=?", new String[] { fs._id }) > 0) { fs.success = true; } } db.setTransactionSuccessful(); } catch (Exception e) { logger.w(t, "FAILED Update of " + uri + " -- query for existing row failed: " + e.toString()); if (e instanceof SQLException) { throw (SQLException) e; } else { throw new SQLException( "FAILED Update of " + uri + " -- query for existing row failed: " + e.toString()); } } finally { if (db != null) { try { if (db.inTransaction()) { db.endTransaction(); } } finally { try { db.releaseReference(); } finally { // this closes the connection OdkConnectionFactorySingleton.getOdkConnectionFactoryInterface() .removeConnection(pf.appName, dbHandleName); } } } } int failureCount = 0; for (FormSpec fs : matchedValues.keySet()) { if (fs.success) { Uri formUri = Uri .withAppendedPath( Uri.withAppendedPath(Uri.withAppendedPath( Uri.parse("content://" + getFormsAuthority()), pf.appName), fs.tableId), fs.formId); getContext().getContentResolver().notifyChange(formUri, null); Uri idUri = Uri.withAppendedPath( Uri.withAppendedPath(Uri.parse("content://" + getFormsAuthority()), pf.appName), fs._id); getContext().getContentResolver().notifyChange(idUri, null); } else { ++failureCount; } } getContext().getContentResolver().notifyChange(uri, null); int count = matchedValues.size(); if (failureCount != 0) { throw new SQLiteException( "Unable to update all forms (" + (count - failureCount) + " of " + count + " updated)"); } return count; }
From source file:org.restcomm.app.qoslib.Services.LibPhoneStateListener.java
public void processNewMMCSignal(SignalEx signal) { ContentValues values = null; // if in a service outage, store a null signal // (I've seen cases where phone was out of service yet it was still returning a signal level) try {//from w w w . j a v a2 s .c o m if (mPhoneState.getLastServiceState() == ServiceState.STATE_OUT_OF_SERVICE) signal = null; // avoid storing repeating identical signals if (mPhoneState.lastKnownMMCSignal != null && mPhoneState.lastKnownMMCSignal.getSignalStrength() != null && signal != null && signal.getSignalStrength() != null) if (mPhoneState.lastKnownMMCSignal.getSignalStrength().toString().equals( signal.getSignalStrength().toString()) && tmlastSig + 3000 > System.currentTimeMillis()) return; tmlastSig = System.currentTimeMillis(); Integer dbmValue = 0; boolean isLTE = false; if (signal == null) dbmValue = -256; else if (signal.getSignalStrength() == null) dbmValue = 0; //store the last known signal if (signal != null && signal.getSignalStrength() != null) { prevMMCSignal = mPhoneState.lastKnownMMCSignal; // used for looking at signal just before a call ended mPhoneState.lastKnownMMCSignal = signal; } else if (signal == null) mPhoneState.lastKnownMMCSignal = null; //push the new signal level into the sqlite database long stagedEventId = owner.getEventManager().getStagedEventId(); int serviceState = mPhoneState.getLastServiceState(); int wifiSignal = -1; WifiManager wifiManager = (WifiManager) owner.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiinfo = wifiManager.getConnectionInfo(); if (wifiinfo != null && wifiinfo.getBSSID() != null) wifiSignal = wifiManager.getConnectionInfo().getRssi(); //if (signal != null) // disabled because we do want the no-signal to be written to the signals table { values = ContentValuesGenerator.generateFromSignal(signal, telephonyManager.getPhoneType(), telephonyManager.getNetworkType(), serviceState, telephonyManager.getDataState(), stagedEventId, wifiSignal, mPhoneState.mServicemode); Integer valSignal = (Integer) values.get("signal"); if (mPhoneState.getNetworkType() == PhoneState.NETWORK_NEWTYPE_LTE) // && phoneStateListener.previousNetworkState == TelephonyManager.DATA_CONNECTED) valSignal = (Integer) values.get("lteRsrp"); if (valSignal != null && dbmValue != null && valSignal > -130 && valSignal < -30) // && (dbmValue <= -120 || dbmValue >= -1)) dbmValue = valSignal; if ((dbmValue > -120 || mPhoneState.getNetworkType() == PhoneState.NETWORK_NEWTYPE_LTE) && dbmValue < -40) this.validSignal = true; if (this.validSignal) // make sure phone has at least one valid signal before recording owner.getDBProvider(owner).insert(TablesEnum.SIGNAL_STRENGTHS.getContentUri(), values); } //update the signal strength percentometer, chart, and look for low/high signal event if (dbmValue != null) { if (dbmValue < -120) // might be -256 if no service, but want to display as -120 on livestatus chart dbmValue = -120; owner.getIntentDispatcher().updateSignalStrength(dbmValue, mPhoneState.getNetworkType(), owner.bWifiConnected, wifiSignal); // Store signal in a sharedPreference for tools such as Indoor/Transit sample mapper, which dont have reference to service if (isLTE == true) // improve the value of the signal for LTE, so that Indoor samples don't look redder in LTE PreferenceManager.getDefaultSharedPreferences(owner).edit() .putInt(PreferenceKeys.Miscellaneous.SIGNAL_STRENGTH, (dbmValue + 15)).commit(); else PreferenceManager.getDefaultSharedPreferences(owner).edit() .putInt(PreferenceKeys.Miscellaneous.SIGNAL_STRENGTH, dbmValue).commit(); } } catch (Exception e) { LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "processNewMMCSignal", "exception", e); LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "processNewMMCSignal", "values: " + values); } catch (Error err) { LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "processNewMMCSignal", "error" + err.getMessage()); } }
From source file:com.zns.comicdroid.activity.Edit.java
private void UpdateComics() { final ContentValues values = new ContentValues(); final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(this); String title = mEtTitle.getText().toString().trim(); if (title.toLowerCase(Locale.ENGLISH).startsWith("the ")) { title = title.substring(4) + ", The"; }/*from ww w .ja v a2s . c om*/ if (mComics != null && mComics.size() > 1) { if (!isEmpty(mEtTitle)) values.put("Title", title); if (!isEmpty(mEtSubtitle)) values.put("SubTitle", mEtSubtitle.getText().toString()); if (!isEmpty(mEtAuthor)) values.put("Author", mEtAuthor.getText().toString()); if (!isEmpty(mEtIllustrator)) values.put("Illustrator", mEtIllustrator.getText().toString()); if (!isEmpty(mEtPublisher)) values.put("Publisher", mEtPublisher.getText().toString()); if (mSpGroup.getSelectedItemPosition() > 0) { Group g = (Group) mSpGroup.getSelectedItem(); values.put("GroupId", g.getId()); } } else { //Strings values.put("Title", title); values.put("SubTitle", mEtSubtitle.getText().toString()); values.put("Author", mEtAuthor.getText().toString()); values.put("Illustrator", mEtIllustrator.getText().toString()); values.put("Publisher", mEtPublisher.getText().toString()); values.put("Issues", mEtIssues.getText().toString()); //Integers if (!isEmpty(mEtIssue)) { if (isValidInt(mEtIssue.getText().toString())) { values.put("Issue", Integer.parseInt(mEtIssue.getText().toString())); } else { Toast.makeText(this, R.string.edit_issueerror, Toast.LENGTH_LONG).show(); return; } } else { values.putNull("Issue"); } if (!isEmpty(mEtPageCount)) { if (isValidInt(mEtPageCount.getText().toString())) { values.put("PageCount", Integer.parseInt(mEtPageCount.getText().toString())); } else { Toast.makeText(this, R.string.edit_pagecounterror, Toast.LENGTH_LONG).show(); return; } } else { values.putNull("PageCount"); } //Dates try { if (!isEmpty(mEtPublished)) { values.put("PublishDate", getDBHelper().GetDateStamp(mEtPublished.getText().toString(), dateFormat)); } else { values.putNull("PublishDate"); } if (!isEmpty(mEtAdded)) { values.put("AddedDate", getDBHelper().GetDateStamp(mEtAdded.getText().toString(), dateFormat)); } else { values.putNull("AddedDate"); } } catch (ParseException e) { Toast.makeText(this, getString(R.string.edit_dateerror) + " " + dateFormat.format(new Date()), Toast.LENGTH_LONG).show(); return; } //Image if (mNewImage != null) { values.put("ImageUrl", ""); values.put("Image", new File(mNewImage).getName()); } //Group if (mSpGroup.getSelectedItemPosition() > 0) { Group g = (Group) mSpGroup.getSelectedItem(); values.put("GroupId", g.getId()); } else { values.putNull("GroupId"); } } if (mComics != null) { //UPDATE StringBuilder sbWhere = new StringBuilder("_id IN ("); String[] ids = new String[mComics.size()]; int i = 0; for (Comic c : mComics) { sbWhere.append("?,"); ids[i] = Integer.toString(c.getId()); i++; } sbWhere.setLength(sbWhere.length() - 1); sbWhere.append(")"); getDBHelper().update("tblBooks", values, sbWhere.toString(), ids); } else { //INSERT if (!values.containsKey("AddedDate") || values.get("AddedDate") == null) { values.remove("AddedDate"); values.put("AddedDate", (int) (System.currentTimeMillis() / 1000L)); } long id = getDBHelper().insert("tblBooks", values); Comic comic = getDBHelper().getComic((int) id); if (comic != null) { mComics = new ArrayList<Comic>(); mComics.add(comic); } } //Backup BackupManager m = new BackupManager(this); m.dataChanged(); setResult(RESULT_OK); Toast.makeText(this, getResources().getString(R.string.edit_done), Toast.LENGTH_LONG).show(); }
From source file:org.opendatakit.services.database.utlities.ODKDatabaseImplUtils.java
/** * Insert a row into a local only table// ww w . ja v a 2 s . c om * * @param db * @param tableId * @param rowValues * @throws ActionNotAuthorizedException */ public void insertLocalOnlyRow(OdkConnectionInterface db, String tableId, ContentValues rowValues) throws IllegalArgumentException { if (rowValues == null || rowValues.size() <= 0) { throw new IllegalArgumentException(t + ": No values to add into table " + tableId); } HashMap<String, Object> cvDataTableVal = new HashMap<String, Object>(); for (String key : rowValues.keySet()) { cvDataTableVal.put(key, rowValues.get(key)); } boolean dbWithinTransaction = db.inTransaction(); try { if (!dbWithinTransaction) { db.beginTransactionNonExclusive(); } db.insertOrThrow(tableId, null, cvDataTableVal); if (!dbWithinTransaction) { db.setTransactionSuccessful(); } } finally { if (!dbWithinTransaction) { db.endTransaction(); } } }
From source file:org.opendatakit.services.database.utlities.ODKDatabaseImplUtils.java
/** * Update a row in a local only table//from w ww . j av a2s . c o m * * @param db * @param tableId * @param rowValues * @param whereClause * @param bindArgs * @throws ActionNotAuthorizedException */ public void updateLocalOnlyRow(OdkConnectionInterface db, String tableId, ContentValues rowValues, String whereClause, Object[] bindArgs) throws IllegalArgumentException { if (rowValues == null || rowValues.size() <= 0) { throw new IllegalArgumentException(t + ": No values to add into table " + tableId); } HashMap<String, Object> cvDataTableVal = new HashMap<String, Object>(); for (String key : rowValues.keySet()) { cvDataTableVal.put(key, rowValues.get(key)); } boolean dbWithinTransaction = db.inTransaction(); try { if (!dbWithinTransaction) { db.beginTransactionNonExclusive(); } db.update(tableId, cvDataTableVal, whereClause, bindArgs); if (!dbWithinTransaction) { db.setTransactionSuccessful(); } } finally { if (!dbWithinTransaction) { db.endTransaction(); } } }
From source file:org.opendatakit.services.database.utlities.ODKDatabaseImplUtils.java
/** * Insert the given rowId with the values in the cvValues. If certain metadata * values are not specified in the cvValues, then suitable default values may * be supplied for them.//from w w w.j a va2 s .c om * <p/> * If a row with this rowId and certain matching metadata fields is present, * then an exception is thrown. * * @param db * @param tableId * @param orderedColumns * @param cvValues * @param rowId * @param activeUser * @param rolesList * @param locale */ public void insertRowWithId(OdkConnectionInterface db, String tableId, OrderedColumns orderedColumns, ContentValues cvValues, String rowId, String activeUser, String rolesList, String locale) throws ActionNotAuthorizedException { if (cvValues == null || cvValues.size() <= 0) { throw new IllegalArgumentException(t + ": No values to add into table " + tableId); } HashMap<String, Object> cvDataTableVal = new HashMap<String, Object>(); cvDataTableVal.put(DataTableColumns.ID, rowId); for (String key : cvValues.keySet()) { cvDataTableVal.put(key, cvValues.get(key)); } upsertDataIntoExistingTable(db, tableId, orderedColumns, cvDataTableVal, false, false, activeUser, rolesList, locale, false); }
From source file:org.opendatakit.services.database.utilities.ODKDatabaseImplUtils.java
/** * Insert a row into a local only table/*from www. j a v a 2s . c om*/ * * @param db * @param tableId * @param rowValues * @throws ActionNotAuthorizedException */ public void insertLocalOnlyRow(OdkConnectionInterface db, String tableId, ContentValues rowValues) throws IllegalArgumentException { if (rowValues == null || rowValues.size() <= 0) { throw new IllegalArgumentException(t + ": No values to add into table " + tableId); } HashMap<String, Object> cvDataTableVal = new HashMap<String, Object>(); for (String key : rowValues.keySet()) { cvDataTableVal.put(key, rowValues.get(key)); } boolean dbWithinTransaction = db.inTransaction(); try { if (!dbWithinTransaction) { db.beginTransactionNonExclusive(); } if (!tableId.startsWith("L_")) { tableId = "L_" + tableId; } db.insertOrThrow(tableId, null, cvDataTableVal); if (!dbWithinTransaction) { db.setTransactionSuccessful(); } } finally { if (!dbWithinTransaction) { db.endTransaction(); } } }
From source file:org.opendatakit.services.database.utilities.ODKDatabaseImplUtils.java
/** * Update a row in a local only table/*from ww w . j a v a2 s .c o m*/ * * @param db * @param tableId * @param rowValues * @param whereClause * @param bindArgs * @throws ActionNotAuthorizedException */ public void updateLocalOnlyRow(OdkConnectionInterface db, String tableId, ContentValues rowValues, String whereClause, Object[] bindArgs) throws IllegalArgumentException { if (rowValues == null || rowValues.size() <= 0) { throw new IllegalArgumentException(t + ": No values to add into table " + tableId); } HashMap<String, Object> cvDataTableVal = new HashMap<String, Object>(); for (String key : rowValues.keySet()) { cvDataTableVal.put(key, rowValues.get(key)); } boolean dbWithinTransaction = db.inTransaction(); try { if (!dbWithinTransaction) { db.beginTransactionNonExclusive(); } if (!tableId.startsWith("L_")) { tableId = "L_" + tableId; } db.update(tableId, cvDataTableVal, whereClause, bindArgs); if (!dbWithinTransaction) { db.setTransactionSuccessful(); } } finally { if (!dbWithinTransaction) { db.endTransaction(); } } }