public List<Connection> restoreConnections(Context context) throws PersistenceException {
  String[] connectionColumns={COLUMN_HOST,COLUMN_port,COLUMN_client_ID,COLUMN_ssl,COLUMN_KEEP_ALIVE,COLUMN_CLEAN_SESSION,COLUMN_TIME_OUT,COLUMN_USER_NAME,COLUMN_PASSWORD,COLUMN_TOPIC,COLUMN_MESSAGE,COLUMN_RETAINED,COLUMN_QOS,_ID};
  String sort=COLUMN_HOST;
  SQLiteDatabase db=getReadableDatabase();
  Cursor c=db.query(TABLE_CONNECTIONS,connectionColumns,null,null,null,null,sort);
  ArrayList<Connection> list=new ArrayList<Connection>(c.getCount());
  Connection connection=null;
  for (int i=0; i < c.getCount(); i++) {
    if (!c.moveToNext()) {
      throw new PersistenceException("Failed restoring connection - count: " + c.getCount() + "loop iteration: "+ i);
    }
    Long id=c.getLong(c.getColumnIndexOrThrow(_ID));
    String host=c.getString(c.getColumnIndexOrThrow(COLUMN_HOST));
    String clientID=c.getString(c.getColumnIndexOrThrow(COLUMN_client_ID));
    int port=c.getInt(c.getColumnIndexOrThrow(COLUMN_port));
    String username=c.getString(c.getColumnIndexOrThrow(COLUMN_USER_NAME));
    String password=c.getString(c.getColumnIndexOrThrow(COLUMN_PASSWORD));
    String topic=c.getString(c.getColumnIndexOrThrow(COLUMN_TOPIC));
    String message=c.getString(c.getColumnIndexOrThrow(COLUMN_MESSAGE));
    int qos=c.getInt(c.getColumnIndexOrThrow(COLUMN_QOS));
    int keepAlive=c.getInt(c.getColumnIndexOrThrow(COLUMN_KEEP_ALIVE));
    int timeout=c.getInt(c.getColumnIndexOrThrow(COLUMN_TIME_OUT));
    boolean cleanSession=c.getInt(c.getColumnIndexOrThrow(COLUMN_CLEAN_SESSION)) == 1 ? true : false;
    boolean retained=c.getInt(c.getColumnIndexOrThrow(COLUMN_RETAINED)) == 1 ? true : false;
    boolean ssl=c.getInt(c.getColumnIndexOrThrow(COLUMN_ssl)) == 1 ? true : false;
    MqttConnectOptions opts=new MqttConnectOptions();
    opts.setCleanSession(cleanSession);
    opts.setKeepAliveInterval(keepAlive);
    opts.setConnectionTimeout(timeout);
    opts.setPassword(password != null ? password.toCharArray() : null);
    opts.setUserName(username);
    if (topic != null) {
      opts.setWill(topic,message.getBytes(),qos,retained);
    }
    connection=Connection.createConnection(clientID,host,port,context,ssl);
    connection.addConnectionOptions(opts);
    connection.assignPersistenceId(id);
    list.add(connection);
  }
  c.close();
  db.close();
  return list;
}

public List < Connection > restoreConnections ( Context context ) throws PersistenceException { String [ ] connectionColumns = { COLUMN_HOST , COLUMN_port , COLUMN_client_ID , COLUMN_ssl , COLUMN_KEEP_ALIVE , COLUMN_CLEAN_SESSION , COLUMN_TIME_OUT , COLUMN_USER_NAME , COLUMN_PASSWORD , COLUMN_TOPIC , COLUMN_MESSAGE , COLUMN_RETAINED , COLUMN_QOS , _ID } ; String sort = COLUMN_HOST ; SQLiteDatabase db = getReadableDatabase ( ) ; Cursor c = db . query ( TABLE_CONNECTIONS , connectionColumns , null , null , null , null , sort ) ; ArrayList < Connection > list = new ArrayList < Connection > ( c . getCount ( ) ) ; Connection connection = null ; for ( int i = 0 ; i < c . getCount ( ) ; i ++ ) { if ( ! c . moveToNext ( ) ) { throw new PersistenceException ( "Failed restoring connection - count: " + c . getCount ( ) + "loop iteration: " + i ) ; } Long id = c . getLong ( c . getColumnIndexOrThrow ( _ID ) ) ; String host = c . getString ( c . getColumnIndexOrThrow ( COLUMN_HOST ) ) ; String clientID = c . getString ( c . getColumnIndexOrThrow ( COLUMN_client_ID ) ) ; int port = c . getInt ( c . getColumnIndexOrThrow ( COLUMN_port ) ) ; String username = c . getString ( c . getColumnIndexOrThrow ( COLUMN_USER_NAME ) ) ; String password = c . getString ( c . getColumnIndexOrThrow ( COLUMN_PASSWORD ) ) ; String topic = c . getString ( c . getColumnIndexOrThrow ( COLUMN_TOPIC ) ) ; String message = c . getString ( c . getColumnIndexOrThrow ( COLUMN_MESSAGE ) ) ; int qos = c . getInt ( c . getColumnIndexOrThrow ( COLUMN_QOS ) ) ; int keepAlive = c . getInt ( c . getColumnIndexOrThrow ( COLUMN_KEEP_ALIVE ) ) ; int timeout = c . getInt ( c . getColumnIndexOrThrow ( COLUMN_TIME_OUT ) ) ; boolean cleanSession = c . getInt ( c . getColumnIndexOrThrow ( COLUMN_CLEAN_SESSION ) ) == 1 ? true : false ; boolean retained = c . getInt ( c . getColumnIndexOrThrow ( COLUMN_RETAINED ) ) == 1 ? true : false ; boolean ssl = c . getInt ( c . getColumnIndexOrThrow ( COLUMN_ssl ) ) == 1 ? true : false ; MqttConnectOptions opts = new MqttConnectOptions ( ) ; opts . setCleanSession ( cleanSession ) ; opts . setKeepAliveInterval ( keepAlive ) ; opts . setConnectionTimeout ( timeout ) ; opts . setPassword ( password != null ? password . toCharArray ( ) : null ) ; opts . setUserName ( username ) ; if ( topic != null ) { opts . setWill ( topic , message . getBytes ( ) , qos , retained ) ; } connection = Connection . createConnection ( clientID , host , port , context , ssl ) ; connection . addConnectionOptions ( opts ) ; connection . assignPersistenceId ( id ) ; list . add ( connection ) ; } c . close ( ) ; db . close ( ) ; return list ; }
recreates connection objects based upon information stored in the database
