Welcome to mirror list, hosted at ThFree Co, Russian Federation.

AbstractRemoteEntity.java « interfaces « model « deck « nextcloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2f7771383fedceeef9a74835446dd667e8665380 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package it.niedermann.nextcloud.deck.model.interfaces;

import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Ignore;
import androidx.room.Index;
import androidx.room.PrimaryKey;

import java.time.Instant;

import it.niedermann.nextcloud.deck.model.Account;
import it.niedermann.nextcloud.deck.model.enums.DBStatus;

@Entity(
        indices = {
                @Index("accountId"),
                @Index("id"),
                @Index("lastModifiedLocal"),
                @Index(value = {"accountId", "id"}, unique = true)
        },
        foreignKeys = {
                @ForeignKey(
                        entity = Account.class,
                        parentColumns = "id",
                        childColumns = "accountId", onDelete = ForeignKey.CASCADE
                )
        }
)
public abstract class AbstractRemoteEntity implements IRemoteEntity {
    @PrimaryKey(autoGenerate = true)
    protected Long localId;

    protected long accountId;

    protected Long id;

    protected int status = DBStatus.UP_TO_DATE.getId();

    protected Instant lastModified;
    protected Instant lastModifiedLocal;

    protected String etag;

    public AbstractRemoteEntity() {
    }

    public AbstractRemoteEntity(AbstractRemoteEntity abstractRemoteEntity) {
        this.localId = abstractRemoteEntity.getLocalId();
        this.accountId = abstractRemoteEntity.getAccountId();
        this.id = abstractRemoteEntity.getId();
        this.status = abstractRemoteEntity.getStatus();
        this.lastModified = abstractRemoteEntity.getLastModified();
        this.lastModifiedLocal = abstractRemoteEntity.getLastModifiedLocal();
    }

    @Ignore
    @Override
    public IRemoteEntity getEntity() {
        return this;
    }

    @Override
    public Long getLocalId() {
        return localId;
    }


    @Override
    public void setLocalId(Long localId) {
        this.localId = localId;
    }


    @Override
    public long getAccountId() {
        return accountId;
    }


    @Override
    public void setAccountId(long accountId) {
        this.accountId = accountId;
    }


    @Override
    public Long getId() {
        return id;
    }


    @Override
    public void setId(Long id) {
        this.id = id;
    }


    @Override
    public int getStatus() {
        return status;
    }


    @Override
    public void setStatus(int status) {
        this.status = status;
    }

    @Override
    public Instant getLastModified() {
        return this.lastModified;
    }

    @Override
    public void setLastModified(Instant lastModified) {
        this.lastModified = lastModified;
    }

    @Override
    public Instant getLastModifiedLocal() {
        return this.lastModifiedLocal;
    }

    @Override
    public void setLastModifiedLocal(Instant lastModifiedLocal) {
        this.lastModifiedLocal = lastModifiedLocal;
    }

    @Ignore
    @Override
    public DBStatus getStatusEnum() {
        return DBStatus.findById(status);
    }


    @Ignore
    @Override
    public void setStatusEnum(DBStatus status) {
        this.status = status.getId();
    }

    @Override
    public String getEtag() {
        return etag;
    }

    @Override
    public void setEtag(String etag) {
        this.etag = etag;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        AbstractRemoteEntity that = (AbstractRemoteEntity) o;

        if (accountId != that.accountId) return false;
        if (status != that.status) return false;
        if (localId != null ? !localId.equals(that.localId) : that.localId != null) return false;
        if (id != null ? !id.equals(that.id) : that.id != null) return false;
        if (lastModified != null ? !lastModified.equals(that.lastModified) : that.lastModified != null)
            return false;
        return lastModifiedLocal != null ? lastModifiedLocal.equals(that.lastModifiedLocal) : that.lastModifiedLocal == null;
    }

    @Override
    public int hashCode() {
        int result = localId != null ? localId.hashCode() : 0;
        result = 31 * result + (int) (accountId ^ (accountId >>> 32));
        result = 31 * result + (id != null ? id.hashCode() : 0);
        result = 31 * result + status;
        result = 31 * result + (lastModified != null ? lastModified.hashCode() : 0);
        result = 31 * result + (lastModifiedLocal != null ? lastModifiedLocal.hashCode() : 0);
        return result;
    }
}