/*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2022 Free Software Foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.mxchange.jaddressbook.model.addressbook.status.AddressbokStatus;
+import org.mxchange.jcoreutils.comparable.Comparables;
import org.mxchange.jusercore.model.user.LoginUser;
import org.mxchange.jusercore.model.user.User;
/**
- * A POJO for user addressbooks
+ * A POJO for user address books
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
@Table (name = "addressbooks")
@NamedQueries (
{
+ @NamedQuery (name = "AllAddressbooks", query = "SELECT a FROM addressbooks AS a ORDER BY a.addressbookId ASC"),
@NamedQuery (name = "AllUsersAddressbooks", query = "SELECT a FROM addressbooks AS a WHERE a.addressbookUser = :param ORDER BY a.addressbookId ASC"),
- @NamedQuery (name = "SearchUserAddressbookName", query = "SELECT a FROM addressbooks AS a WHERE a.addressbookUser = :user AND LOWER(a.addressbookName) LIKE LOWER(:name)"),
+ @NamedQuery (name = "SearchUserAddressbookName", query = "SELECT a FROM addressbooks AS a WHERE a.addressbookUser = :user AND LOWER(a.addressbookName) LIKE LOWER(:name)")
}
)
@SuppressWarnings ("PersistenceUnitPresent")
*/
@Basic (optional = false)
@Temporal (value = TemporalType.TIMESTAMP)
- @Column (name = "addressbook_created", nullable = false, updatable = false)
+ @Column (name = "addressbook_created", updatable = false, nullable = false)
private Date addressbookCreated;
/**
private String addressbookName;
/**
- * Adress book status
+ * Address book status
*/
@Basic (optional = false)
@Enumerated (EnumType.STRING)
@Column (name = "addressbook_status", nullable = false, length = 10)
private AddressbokStatus addressbookStatus;
+ /**
+ * When this address book has been created
+ */
+ @Temporal (value = TemporalType.TIMESTAMP)
+ @Column (name = "addressbook_updated", insertable = false, nullable = false)
+ private Date addressbookUpdated;
+
/**
* Connection to "users" table
*/
* @param addressbookUser User instance
*/
public UserAddressbook (final String addressbookName, final User addressbookUser) {
- // Call default constructor
+ // Invoke default constructor
this();
// Set name and user instance
* Default constructor
*/
public UserAddressbook () {
- // Set status to UNLOCKED
- this.addressbookStatus = AddressbokStatus.UNLOCKED;
+ }
+
+ @Override
+ public int compareTo (final Addressbook addressbook) {
+ // Check parameter and return 0 if equal
+ if (null == addressbook) {
+ // Should not happen
+ throw new NullPointerException("addressbook is null"); //NOI18N
+ } else if (addressbook.equals(this)) {
+ // Same object, below "expensive" code can be safely skipped
+ return 0;
+ }
+
+ // All comparators
+ final int comparators[] = {
+ // First name ...
+ this.getAddressbookName().compareToIgnoreCase(addressbook.getAddressbookName()),
+ // ... status
+ this.getAddressbookStatus().compareTo(addressbook.getAddressbookStatus()),
+ // .. then user
+ this.getAddressbookUser().compareTo(addressbook.getAddressbookUser())
+ };
+
+ // Check all values
+ final int comparison = Comparables.checkAll(comparators);
+
+ // Return value
+ return comparison;
}
@Override
return false;
}
- final Addressbook other = (Addressbook) object;
+ final Addressbook addressbook = (Addressbook) object;
- if (!Objects.equals(this.getAddressbookName(), other.getAddressbookName())) {
+ if (!Objects.equals(this.getAddressbookId(), addressbook.getAddressbookId())) {
return false;
- } else if (!Objects.equals(this.getAddressbookUser(), other.getAddressbookUser())) {
+ } else if (!Objects.equals(this.getAddressbookLastLocked(), addressbook.getAddressbookLastLocked())) {
+ return false;
+ } else if (!Objects.equals(this.getAddressbookLastLockedReason(), addressbook.getAddressbookLastLockedReason())) {
+ return false;
+ } else if (!Objects.equals(this.getAddressbookName(), addressbook.getAddressbookName())) {
+ return false;
+ } else if (!Objects.equals(this.getAddressbookStatus(), addressbook.getAddressbookStatus())) {
+ return false;
+ } else if (!Objects.equals(this.getAddressbookUser(), addressbook.getAddressbookUser())) {
return false;
}
}
@Override
- public int hashCode () {
- int hash = 7;
- hash = 59 * hash + Objects.hashCode(this.getAddressbookName());
- hash = 59 * hash + Objects.hashCode(this.getAddressbookUser());
- return hash;
- }
-
- @Override
+ @SuppressWarnings ("ReturnOfDateField")
public Date getAddressbookCreated () {
return this.addressbookCreated;
}
@Override
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
public void setAddressbookCreated (final Date addressbookCreated) {
this.addressbookCreated = addressbookCreated;
}
}
@Override
+ @SuppressWarnings ("ReturnOfDateField")
public Date getAddressbookLastLocked () {
return this.addressbookLastLocked;
}
@Override
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
public void setAddressbookLastLocked (final Date addressbookLastLocked) {
this.addressbookLastLocked = addressbookLastLocked;
}
this.addressbookStatus = addressbookStatus;
}
+ @Override
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getAddressbookUpdated () {
+ return this.addressbookUpdated;
+ }
+
+ @Override
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setAddressbookUpdated (final Date addressbookUpdated) {
+ this.addressbookUpdated = addressbookUpdated;
+ }
+
@Override
public User getAddressbookUser () {
return this.addressbookUser;
this.addressbookUser = addressbookUser;
}
+ @Override
+ public int hashCode () {
+ int hash = 7;
+
+ hash = 59 * hash + Objects.hashCode(this.getAddressbookId());
+ hash = 59 * hash + Objects.hashCode(this.getAddressbookLastLocked());
+ hash = 59 * hash + Objects.hashCode(this.getAddressbookLastLockedReason());
+ hash = 59 * hash + Objects.hashCode(this.getAddressbookName());
+ hash = 59 * hash + Objects.hashCode(this.getAddressbookStatus());
+ hash = 59 * hash + Objects.hashCode(this.getAddressbookUser());
+
+ return hash;
+ }
+
}