Files
FairEmail/app/src/main/java/eu/faircode/email/DaoIdentity.java

97 lines
3.7 KiB
Java
Raw Normal View History

2018-08-02 13:33:06 +00:00
package eu.faircode.email;
/*
2018-08-14 05:53:24 +00:00
This file is part of FairEmail.
2018-08-02 13:33:06 +00:00
2018-08-14 05:53:24 +00:00
FairEmail is free software: you can redistribute it and/or modify
2018-08-02 13:33:06 +00:00
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
2018-10-29 10:46:49 +00:00
FairEmail is distributed in the hope that it will be useful,
2018-08-02 13:33:06 +00:00
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
2018-10-29 10:46:49 +00:00
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2018-08-02 13:33:06 +00:00
2018-12-31 08:04:33 +00:00
Copyright 2018-2019 by Marcel Bokhorst (M66B)
2018-08-02 13:33:06 +00:00
*/
2018-08-08 06:55:47 +00:00
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;
import java.util.List;
2018-08-02 13:33:06 +00:00
@Dao
public interface DaoIdentity {
2018-08-08 10:22:12 +00:00
@Query("SELECT identity.*, account.name AS accountName FROM identity" +
" JOIN account ON account.id = identity.account" +
" WHERE NOT :synchronize OR account.synchronize")
LiveData<List<TupleIdentityEx>> liveIdentities(boolean synchronize);
2018-08-02 13:33:06 +00:00
@Query("SELECT identity.*, account.name AS accountName FROM identity" +
" JOIN account ON account.id = identity.account" +
2019-06-28 11:00:55 +02:00
" JOIN folder ON folder.account = identity.account AND folder.type = '" + EntityFolder.DRAFTS + "'" +
2019-02-17 12:57:29 +00:00
" WHERE (:account IS NULL OR identity.account = :account)" +
2019-02-10 17:39:27 +00:00
" AND identity.synchronize" +
2019-04-25 09:21:09 +02:00
" AND account.synchronize" +
" ORDER BY account.`order`, account.`primary` DESC, account.name COLLATE NOCASE" +
", identity.`primary` DESC, identity.display COLLATE NOCASE, identity.name COLLATE NOCASE, identity.email COLLATE NOCASE")
2019-02-10 17:39:27 +00:00
List<TupleIdentityEx> getComposableIdentities(Long account);
2019-06-27 10:09:24 +02:00
@Query("SELECT * FROM identity" +
" WHERE account = :account" +
" ORDER BY name COLLATE NOCASE")
2018-09-14 11:33:22 +00:00
List<EntityIdentity> getIdentities(long account);
2018-08-02 13:33:06 +00:00
@Query("SELECT * FROM identity WHERE id = :id")
EntityIdentity getIdentity(long id);
@Query("SELECT * FROM identity" +
" WHERE account = :account AND email = :email COLLATE NOCASE" +
" ORDER BY CASE WHEN synchronize THEN 0 ELSE 1 END" +
" LIMIT 1")
2018-11-10 16:47:11 +00:00
EntityIdentity getIdentity(long account, String email);
@Query("SELECT COUNT(*) FROM identity WHERE synchronize")
int getSynchronizingIdentityCount();
2018-08-12 08:16:41 +00:00
@Insert
2018-08-02 13:33:06 +00:00
long insertIdentity(EntityIdentity identity);
@Update
void updateIdentity(EntityIdentity identity);
2019-09-18 16:34:07 +02:00
@Query("UPDATE identity SET password = :password WHERE password = :old")
int updateIdentityPassword(String old, String password);
@Query("UPDATE identity SET synchronize = :synchronize WHERE id = :id")
int setIdentitySynchronize(long id, boolean synchronize);
2018-08-15 11:26:59 +00:00
@Query("UPDATE identity SET state = :state WHERE id = :id")
int setIdentityState(long id, String state);
2019-01-25 18:13:00 +00:00
@Query("UPDATE identity SET last_connected = :last_connected WHERE id = :id")
int setIdentityConnected(long id, long last_connected);
2019-07-18 17:38:51 +02:00
@Query("UPDATE identity SET sign_key = :sign_key WHERE id = :id")
2019-07-18 17:45:00 +02:00
int setIdentitySignKey(long id, Long sign_key);
2018-08-27 16:19:56 +00:00
2018-08-15 11:26:59 +00:00
@Query("UPDATE identity SET error = :error WHERE id = :id")
int setIdentityError(long id, String error);
2018-12-27 17:01:07 +00:00
@Query("UPDATE identity SET `primary` = 0 WHERE account = :account")
void resetPrimary(long account);
2018-08-07 19:35:21 +00:00
@Query("UPDATE identity SET tbd = 1 WHERE id = :id")
int setIdentityTbd(long id);
@Query("DELETE FROM identity WHERE tbd = 1")
int deleteIdentitiesTbd();
2018-08-02 13:33:06 +00:00
}