add getAccountJids to DatabaseBackend

This commit is contained in:
Daniel Gultsch 2017-12-11 15:56:15 +01:00
parent 37bd26c75f
commit 9a796df2a3

View file

@ -28,6 +28,7 @@ import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory; import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -745,6 +746,25 @@ public class DatabaseBackend extends SQLiteOpenHelper {
return getAccounts(db); return getAccounts(db);
} }
public Collection<Jid> getAccountJids() {
SQLiteDatabase db = this.getReadableDatabase();
final List<Jid> jids = new ArrayList<>();
final String[] columns = new String[]{Account.USERNAME, Account.SERVER};
Cursor cursor = db.query(Account.TABLENAME,columns,null,null,null,null,null);
try {
while(cursor.moveToNext()) {
jids.add(Jid.fromParts(cursor.getString(0),cursor.getString(1),null));
}
return jids;
} catch (Exception e) {
return jids;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
private List<Account> getAccounts(SQLiteDatabase db) { private List<Account> getAccounts(SQLiteDatabase db) {
List<Account> list = new ArrayList<>(); List<Account> list = new ArrayList<>();
Cursor cursor = db.query(Account.TABLENAME, null, null, null, null, Cursor cursor = db.query(Account.TABLENAME, null, null, null, null,