import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
+import androidx.room.ForeignKey;
+import androidx.room.Index;
+import androidx.room.PrimaryKey;
-@Entity(tableName = "accounts", primaryKeys = {"profile", "name"})
+@Entity(tableName = "accounts",
+ indices = {@Index(name = "un_account_name", unique = true, value = {"profile_id", "name"}),
+ @Index(name = "fk_account_profile", value = "profile_id")
+ }, foreignKeys = {
+ @ForeignKey(entity = Profile.class, parentColumns = "id", childColumns = "profile_id",
+ onDelete = ForeignKey.CASCADE, onUpdate = ForeignKey.RESTRICT)
+})
public class Account {
@ColumnInfo
- int level;
+ @PrimaryKey(autoGenerate = true)
+ long id;
+ @ColumnInfo(name = "profile_id")
+ long profileId;
@ColumnInfo
- @NonNull
- private String profile;
+ int level;
@ColumnInfo
@NonNull
private String name;
@ColumnInfo(name = "amounts_expanded", defaultValue = "0")
private boolean amountsExpanded = false;
@ColumnInfo(defaultValue = "0")
- private int generation;
- @NonNull
- public String getProfile() {
- return profile;
+ private long generation;
+ public long getId() {
+ return id;
}
- public void setProfile(@NonNull String profile) {
- this.profile = profile;
+ public void setId(long id) {
+ this.id = id;
+ }
+ public long getProfileId() {
+ return profileId;
+ }
+ public void setProfileId(long profileId) {
+ this.profileId = profileId;
}
@NonNull
public String getName() {
public void setAmountsExpanded(boolean amountsExpanded) {
this.amountsExpanded = amountsExpanded;
}
- public int getGeneration() {
+ public long getGeneration() {
return generation;
}
- public void setGeneration(int generation) {
+ public void setGeneration(long generation) {
this.generation = generation;
}
+ @NonNull
+ @Override
+ public String toString() {
+ return getName();
+ }
}