Account.java 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import com.j256.ormlite.field.DatabaseField;
  2. import com.j256.ormlite.table.DatabaseTable;
  3. @DatabaseTable(tableName = "account")
  4. public class Account {
  5. public static final String NAME_FIELD_NAME = "name";
  6. public static final String PASSWORD_FIELD_NAME = "password";
  7. @DatabaseField(columnName = "id", generatedId = true)
  8. private int id;
  9. @DatabaseField(columnName = "name", canBeNull = false)
  10. private String name;
  11. @DatabaseField(columnName = "password")
  12. private String password;
  13. Account() {
  14. // all persisted classes must define a no-arg constructor with at least package visibility
  15. }
  16. public Account(String name) {
  17. this.name = name;
  18. }
  19. public Account(String name, String password) {
  20. this.name = name;
  21. this.password = password;
  22. }
  23. public int getId() {
  24. return id;
  25. }
  26. public String getName() {
  27. return name;
  28. }
  29. public void setName(String name) {
  30. this.name = name;
  31. }
  32. public String getPassword() {
  33. return password;
  34. }
  35. public void setPassword(String password) {
  36. this.password = password;
  37. }
  38. @Override
  39. public int hashCode() {
  40. return name.hashCode();
  41. }
  42. @Override
  43. public boolean equals(Object other) {
  44. if (other == null || other.getClass() != getClass()) {
  45. return false;
  46. }
  47. return name.equals(((Account) other).name);
  48. }
  49. }