Mercury-IM/persistence-room/src/main/java/org/mercury_im/messenger/persistence/room/dao/AccountDao.java

50 lines
1.6 KiB
Java

package org.mercury_im.messenger.persistence.room.dao;
import androidx.annotation.WorkerThread;
import androidx.room.Dao;
import androidx.room.Query;
import androidx.room.TypeConverters;
import org.jxmpp.jid.EntityBareJid;
import org.mercury_im.messenger.persistence.room.model.RoomAccountModel;
import org.mercury_im.messenger.persistence.room.type_converter.EntityBareJidConverter;
import java.util.List;
import io.reactivex.Completable;
import io.reactivex.Maybe;
import io.reactivex.Observable;
@Dao
@TypeConverters(EntityBareJidConverter.class)
@WorkerThread
public interface AccountDao extends BaseDao<RoomAccountModel> {
/**
* Return an {@link Observable} wrapping a {@link List} which contains all
* {@link RoomAccountModel Accounts} which are currently stored in the database.
*
* @return live updating account list
*/
@Query("select * from accounts")
Observable<List<RoomAccountModel>> getAllAccounts();
/**
* Return the {@link RoomAccountModel Account} which is identified by the given id.
*
* @param id id of the account
* @return account or null
*/
@Query("select * from accounts where pk_account_id = :id")
Maybe<RoomAccountModel> getAccountById(long id);
@Query("select * from accounts where jid = :jid")
Maybe<RoomAccountModel> getAccountByJid(EntityBareJid jid);
@Query("update accounts set state = :state where pk_account_id = :accountId")
Completable updateConnectionState(long accountId, String state);
@Query("DELETE FROM accounts WHERE pk_account_id = :accountId")
Completable deleteAccount(long accountId);
}