/** * Process trace action - pass trace data back to the callback * * @param data */ private void traceAction(Bundle data) { if (traceCallback != null) { String severity = data.getString(MqttServiceConstants.CALLBACK_TRACE_SEVERITY); String message = data.getString(MqttServiceConstants.CALLBACK_ERROR_MESSAGE); String tag = data.getString(MqttServiceConstants.CALLBACK_TRACE_TAG); if (MqttServiceConstants.TRACE_DEBUG.equals(severity)) traceCallback.traceDebug(tag, message); else if (MqttServiceConstants.TRACE_ERROR.equals(severity)) traceCallback.traceError(tag, message); else { Exception e = (Exception) data.getSerializable(MqttServiceConstants.CALLBACK_EXCEPTION); traceCallback.traceException(tag, message, e); } } }
/** * When the database is (re)created, create our table * * @param database */ @Override public void onCreate(SQLiteDatabase database) { String createArrivedTableStatement = "CREATE TABLE " + ARRIVED_MESSAGE_TABLE_NAME + "(" + MqttServiceConstants.MESSAGE_ID + " TEXT PRIMARY KEY, " + MqttServiceConstants.CLIENT_HANDLE + " TEXT, " + MqttServiceConstants.DESTINATION_NAME + " TEXT, " + MqttServiceConstants.PAYLOAD + " BLOB, " + MqttServiceConstants.QOS + " INTEGER, " + MqttServiceConstants.RETAINED + " TEXT, " + MqttServiceConstants.DUPLICATE + " TEXT, " + MTIMESTAMP + " INTEGER" + ");"; traceHandler.traceDebug(TAG, "onCreate {" + createArrivedTableStatement + "}"); try { database.execSQL(createArrivedTableStatement); traceHandler.traceDebug(TAG, "created the table"); } catch (SQLException e) { traceHandler.traceException(TAG, "onCreate", e); throw e; } }
/** * Delete all messages (optionally for a specific client) * * @param clientHandle * identifier for the client.<br> * If null, all messages are deleted */ @Override public void clearArrivedMessages(String clientHandle) { db = mqttDb.getWritableDatabase(); String[] selectionArgs = new String[1]; selectionArgs[0] = clientHandle; int rows = 0; if (clientHandle == null) { traceHandler.traceDebug(TAG, "clearArrivedMessages: clearing the table"); rows = db.delete(ARRIVED_MESSAGE_TABLE_NAME, null, null); } else { traceHandler.traceDebug(TAG, "clearArrivedMessages: clearing the table of " + clientHandle + " messages"); rows = db.delete(ARRIVED_MESSAGE_TABLE_NAME, MqttServiceConstants.CLIENT_HANDLE + "=?", selectionArgs); } traceHandler.traceDebug(TAG, "clearArrivedMessages: rows affected = " + rows); }
/** * To upgrade the database, drop and recreate our table * * @param db * the database * @param oldVersion * ignored * @param newVersion * ignored */ @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { traceHandler.traceDebug(TAG, "onUpgrade"); try { db.execSQL("DROP TABLE IF EXISTS " + ARRIVED_MESSAGE_TABLE_NAME); } catch (SQLException e) { traceHandler.traceException(TAG, "onUpgrade", e); throw e; } onCreate(db); traceHandler.traceDebug(TAG, "onUpgrade complete"); } }
/** * Constructor - create a DatabaseMessageStore to store arrived MQTT message * * @param service * our parent MqttService * @param context * a context to use for android calls */ public DatabaseMessageStore(MqttService service, Context context) { this.traceHandler = service; // Open message database mqttDb = new MQTTDatabaseHelper(traceHandler, context); // Android documentation suggests that this perhaps // could/should be done in another thread, but as the // database is only one table, I doubt it matters... traceHandler.traceDebug(TAG, "DatabaseMessageStore<init> complete"); }
traceHandler.traceDebug(TAG, "discardArrived{" + clientHandle + "}, {" + id + "}"); int rows; selectionArgs); } catch (SQLException e) { traceHandler.traceException(TAG, "discardArrived", e); throw e; traceHandler.traceError(TAG, "discardArrived - Error deleting message {" + id + "} from database: Rows affected = " + rows); .traceDebug( TAG, "discardArrived - Message deleted successfully. - messages in db for this clientHandle "
traceHandler.traceDebug(TAG, "storeArrived{" + clientHandle + "}, {" + message.toString() + "}"); db.insertOrThrow(ARRIVED_MESSAGE_TABLE_NAME, null, values); } catch (SQLException e) { traceHandler.traceException(TAG, "onUpgrade", e); throw e; .traceDebug( TAG, "storeArrived: inserted message with id of {"
/** * Delete all messages (optionally for a specific client) * * @param clientHandle * identifier for the client.<br> * If null, all messages are deleted */ @Override public void clearArrivedMessages(String clientHandle) { db = mqttDb.getWritableDatabase(); String[] selectionArgs = new String[1]; selectionArgs[0] = clientHandle; int rows = 0; if (clientHandle == null) { traceHandler.traceDebug(TAG, "clearArrivedMessages: clearing the table"); rows = db.delete(ARRIVED_MESSAGE_TABLE_NAME, null, null); } else { traceHandler.traceDebug(TAG, "clearArrivedMessages: clearing the table of " + clientHandle + " messages"); rows = db.delete(ARRIVED_MESSAGE_TABLE_NAME, MqttServiceConstants.CLIENT_HANDLE + "=?", selectionArgs); } traceHandler.traceDebug(TAG, "clearArrivedMessages: rows affected = " + rows); }
/** * Process trace action - pass trace data back to the callback * * @param data */ private void traceAction(Bundle data) { if (traceCallback != null) { String severity = data.getString(MqttServiceConstants.CALLBACK_TRACE_SEVERITY); String message = data.getString(MqttServiceConstants.CALLBACK_ERROR_MESSAGE); String tag = data.getString(MqttServiceConstants.CALLBACK_TRACE_TAG); if (MqttServiceConstants.TRACE_DEBUG.equals(severity)) traceCallback.traceDebug(tag, message); else if (MqttServiceConstants.TRACE_ERROR.equals(severity)) traceCallback.traceError(tag, message); else { Exception e = (Exception) data.getSerializable(MqttServiceConstants.CALLBACK_EXCEPTION); traceCallback.traceException(tag, message, e); } } }
/** * When the database is (re)created, create our table * * @param database */ @Override public void onCreate(SQLiteDatabase database) { String createArrivedTableStatement = "CREATE TABLE " + ARRIVED_MESSAGE_TABLE_NAME + "(" + MqttServiceConstants.MESSAGE_ID + " TEXT PRIMARY KEY, " + MqttServiceConstants.CLIENT_HANDLE + " TEXT, " + MqttServiceConstants.DESTINATION_NAME + " TEXT, " + MqttServiceConstants.PAYLOAD + " BLOB, " + MqttServiceConstants.QOS + " INTEGER, " + MqttServiceConstants.RETAINED + " TEXT, " + MqttServiceConstants.DUPLICATE + " TEXT, " + MTIMESTAMP + " INTEGER" + ");"; traceHandler.traceDebug(TAG, "onCreate {" + createArrivedTableStatement + "}"); try { database.execSQL(createArrivedTableStatement); traceHandler.traceDebug(TAG, "created the table"); } catch (SQLException e) { traceHandler.traceException(TAG, "onCreate", e); throw e; } }
/** * Delete all messages (optionally for a specific client) * * @param clientHandle * identifier for the client.<br> * If null, all messages are deleted */ @Override public void clearArrivedMessages(String clientHandle) { db = mqttDb.getWritableDatabase(); String[] selectionArgs = new String[1]; selectionArgs[0] = clientHandle; int rows = 0; if (clientHandle == null) { traceHandler.traceDebug(TAG, "clearArrivedMessages: clearing the table"); rows = db.delete(ARRIVED_MESSAGE_TABLE_NAME, null, null); } else { traceHandler.traceDebug(TAG, "clearArrivedMessages: clearing the table of " + clientHandle + " messages"); rows = db.delete(ARRIVED_MESSAGE_TABLE_NAME, MqttServiceConstants.CLIENT_HANDLE + "=?", selectionArgs); } traceHandler.traceDebug(TAG, "clearArrivedMessages: rows affected = " + rows); }
/** * Process trace action - pass trace data back to the callback * * @param data */ private void traceAction(Bundle data) { if (traceCallback != null) { String severity = data.getString(MqttServiceConstants.CALLBACK_TRACE_SEVERITY); String message = data.getString(MqttServiceConstants.CALLBACK_ERROR_MESSAGE); String tag = data.getString(MqttServiceConstants.CALLBACK_TRACE_TAG); if (MqttServiceConstants.TRACE_DEBUG.equals(severity)) traceCallback.traceDebug(tag, message); else if (MqttServiceConstants.TRACE_ERROR.equals(severity)) traceCallback.traceError(tag, message); else { Exception e = (Exception) data.getSerializable(MqttServiceConstants.CALLBACK_EXCEPTION); traceCallback.traceException(tag, message, e); } } }
/** * When the database is (re)created, create our table * * @param database */ @Override public void onCreate(SQLiteDatabase database) { String createArrivedTableStatement = "CREATE TABLE " + ARRIVED_MESSAGE_TABLE_NAME + "(" + MqttServiceConstants.MESSAGE_ID + " TEXT PRIMARY KEY, " + MqttServiceConstants.CLIENT_HANDLE + " TEXT, " + MqttServiceConstants.DESTINATION_NAME + " TEXT, " + MqttServiceConstants.PAYLOAD + " BLOB, " + MqttServiceConstants.QOS + " INTEGER, " + MqttServiceConstants.RETAINED + " TEXT, " + MqttServiceConstants.DUPLICATE + " TEXT, " + MTIMESTAMP + " INTEGER" + ");"; traceHandler.traceDebug(TAG, "onCreate {" + createArrivedTableStatement + "}"); try { database.execSQL(createArrivedTableStatement); traceHandler.traceDebug(TAG, "created the table"); } catch (SQLException e) { traceHandler.traceException(TAG, "onCreate", e); throw e; } }
/** * Constructor - create a DatabaseMessageStore to store arrived MQTT message * * @param service * our parent MqttService * @param context * a context to use for android calls */ public DatabaseMessageStore(MqttService service, Context context) { this.traceHandler = service; // Open message database mqttDb = new MQTTDatabaseHelper(traceHandler, context); // Android documentation suggests that this perhaps // could/should be done in another thread, but as the // database is only one table, I doubt it matters... traceHandler.traceDebug(TAG, "DatabaseMessageStore<init> complete"); }
traceHandler.traceDebug(TAG, "discardArrived{" + clientHandle + "}, {" + id + "}"); int rows; selectionArgs); } catch (SQLException e) { traceHandler.traceException(TAG, "discardArrived", e); throw e; traceHandler.traceError(TAG, "discardArrived - Error deleting message {" + id + "} from database: Rows affected = " + rows); .traceDebug( TAG, "discardArrived - Message deleted successfully. - messages in db for this clientHandle "
/** * To upgrade the database, drop and recreate our table * * @param db * the database * @param oldVersion * ignored * @param newVersion * ignored */ @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { traceHandler.traceDebug(TAG, "onUpgrade"); try { db.execSQL("DROP TABLE IF EXISTS " + ARRIVED_MESSAGE_TABLE_NAME); } catch (SQLException e) { traceHandler.traceException(TAG, "onUpgrade", e); throw e; } onCreate(db); traceHandler.traceDebug(TAG, "onUpgrade complete"); } }
/** * Constructor - create a DatabaseMessageStore to store arrived MQTT message * * @param service * our parent MqttService * @param context * a context to use for android calls */ public DatabaseMessageStore(MqttService service, Context context) { this.traceHandler = service; // Open message database mqttDb = new MQTTDatabaseHelper(traceHandler, context); // Android documentation suggests that this perhaps // could/should be done in another thread, but as the // database is only one table, I doubt it matters... traceHandler.traceDebug(TAG, "DatabaseMessageStore<init> complete"); }
traceHandler.traceDebug(TAG, "discardArrived{" + clientHandle + "}, {" + id + "}"); int rows; selectionArgs); } catch (SQLException e) { traceHandler.traceException(TAG, "discardArrived", e); throw e; traceHandler.traceError(TAG, "discardArrived - Error deleting message {" + id + "} from database: Rows affected = " + rows); .traceDebug( TAG, "discardArrived - Message deleted successfully. - messages in db for this clientHandle "
/** * To upgrade the database, drop and recreate our table * * @param db * the database * @param oldVersion * ignored * @param newVersion * ignored */ @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { traceHandler.traceDebug(TAG, "onUpgrade"); try { db.execSQL("DROP TABLE IF EXISTS " + ARRIVED_MESSAGE_TABLE_NAME); } catch (SQLException e) { traceHandler.traceException(TAG, "onUpgrade", e); throw e; } onCreate(db); traceHandler.traceDebug(TAG, "onUpgrade complete"); } }
traceHandler.traceDebug(TAG, "storeArrived{" + clientHandle + "}, {" + message.toString() + "}"); db.insertOrThrow(ARRIVED_MESSAGE_TABLE_NAME, null, values); } catch (SQLException e) { traceHandler.traceException(TAG, "onUpgrade", e); throw e; .traceDebug( TAG, "storeArrived: inserted message with id of {"