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

109 lines
4.3 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);
@Query("SELECT * FROM identity" +
" WHERE account = :account" +
" AND email = :email COLLATE NOCASE")
List<EntityIdentity> getIdentities(long account, String email);
2019-09-23 10:47:05 +02:00
@Query("SELECT identity.* FROM identity" +
" JOIN account ON account.id = identity.account" +
" WHERE identity.account = :account" +
2019-12-06 14:50:15 +01:00
" AND identity.synchronize AND account.synchronize" +
" ORDER BY identity.`primary` DESC, IFNULL(identity.display, identity.name)")
2019-09-23 10:47:05 +02:00
List<EntityIdentity> getSynchronizingIdentities(long account);
@Query("SELECT COUNT(*) FROM identity WHERE synchronize")
int getSynchronizingIdentityCount();
@Query("SELECT * FROM identity WHERE id = :id")
EntityIdentity getIdentity(long id);
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);
@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-09-19 13:21:37 +02:00
@Query("UPDATE identity SET password = :password WHERE id = :id")
int setIdentityPassword(long id, String password);
2019-10-11 15:32:03 +02:00
@Query("UPDATE identity SET password = :password" +
" WHERE account = :account" +
" AND user = :user" +
" AND host LIKE :domain")
int setIdentityPassword(long account, String user, String password, String domain);
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
2019-12-05 20:23:31 +01:00
@Query("UPDATE identity SET sign_key_alias = :alias WHERE id = :id")
int setIdentitySignKeyAlias(long id, String alias);
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("DELETE FROM identity WHERE id = :id")
int deleteIdentity(long id);
2018-08-02 13:33:06 +00:00
}