import java.io.Serializable;
import java.util.Calendar;
-import java.util.List;
import org.mxchange.addressbook.model.addressbook.Addressbook;
import org.mxchange.jcontacts.contact.Contact;
import org.mxchange.jcontactsbusiness.BusinessContact;
* <p>
* @return User who has added this entry
*/
- public List<User> getAddressbookEntryUserAddedList ();
+ public User getAddressbookEntryUserSharer ();
/**
* Setter for user who has added this entry to his/her addressbook
* <p>
* @param addressbookEntryUserAdded User who has added this entry
*/
- public void setAddressbookEntryUserAddedList (final List<User> addressbookEntryUserAdded);
+ public void setAddressbookEntryUserSharer (final User addressbookEntryUserAdded);
/**
* Getter for user who has initially created the address book entry
* <p>
* @return User who has created initially this address book entry
*/
- public List<User> getAddressbookEntryUserOriginList ();
+ public User getAddressbookEntryUserOwner ();
/**
* Setter for user who has initially created the address book entry
* @param addressbookEntryUserOrigin User who has created initially this
* address book entry
*/
- public void setAddressbookEntryUserOriginList (final List<User> addressbookEntryUserOrigin);
+ public void setAddressbookEntryUserOwner (final User addressbookEntryUserOrigin);
/**
* Getter for address book
package org.mxchange.addressbook.model.addressbook.entry;
import java.util.Calendar;
-import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
*/
@Entity (name = "addressbook_entries")
@Table (name = "addressbook_entries")
+@NamedQueries (
+ @NamedQuery (
+ name = "AllAddressbookEntries",
+ query = "SELECT e FROM addressbook_entries AS e WHERE e.addressbookId = :addressbook AND (e.addressbookEntryUserOwner = :owner OR e.addressbookEntryUserSharer = :sharer) ORDER BY e.addressbookEntryId ASC")
+)
public class UserAddressbookEntry implements AddressbookEntry, Comparable<AddressbookEntry> {
/**
private static final long serialVersionUID = 178_581_768_581_960L;
/**
- * Id number
+ * Connection to table "business_contacts" (commercial contacts)
*/
- @Id
- @GeneratedValue (strategy = GenerationType.IDENTITY)
- @Column (name = "entry_id", nullable = false, updatable = false)
- private Long addressbookEntryId;
+ @JoinColumn (name = "entry_business_contact_id", updatable = false)
+ @OneToOne (targetEntity = CompanyContact.class, cascade = CascadeType.ALL)
+ private BusinessContact addressbookEntryBusinessContact;
/**
* When this address book entry has been created
private Calendar addressbookEntryCreated;
/**
- * Connection to table "addressbooks"
+ * Id number
*/
- @JoinColumn (name = "addressbook_id", nullable = false, updatable = false)
- @OneToOne (targetEntity = UserAddressbook.class, optional = false, cascade = CascadeType.ALL)
- private Addressbook addressbookId;
+ @Id
+ @GeneratedValue (strategy = GenerationType.IDENTITY)
+ @Column (name = "entry_id", nullable = false, updatable = false)
+ private Long addressbookEntryId;
/**
- * Connection to table "users" (who has initially created this entry
+ * Connection to table "contacts" (private contacts)
*/
- @JoinColumn (name = "entry_origin_user_id", nullable = false, updatable = false)
- @ManyToOne (targetEntity = LoginUser.class, optional = false, cascade = CascadeType.ALL)
- private List<User> addressbookEntryUserOriginList;
+ @JoinColumn (name = "entry_private_contact_id", updatable = false)
+ @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL)
+ private Contact addressbookEntryPrivateContact;
/**
- * Connection to table "users" (who has added this entry)
+ * Connection to table "users" (who has initially created this entry
*/
- @JoinColumn (name = "entry_added_user_id", updatable = false)
- @ManyToOne (targetEntity = LoginUser.class, cascade = CascadeType.ALL)
- private List<User> addressbookEntryUserAddedList;
+ @JoinColumn (name = "entry_owner_user_id", nullable = false, updatable = false)
+ @OneToOne (targetEntity = LoginUser.class, optional = false, cascade = CascadeType.ALL)
+ private User addressbookEntryUserOwner;
/**
- * Connection to table "contacts" (private contacts)
+ * Connection to table "users" (who has added this entry)
*/
- @JoinColumn (name = "entry_private_contact_id", updatable = false)
- @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL)
- private Contact addressbookEntryPrivateContact;
+ @JoinColumn (name = "entry_sharer_user_id", updatable = false)
+ @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.ALL)
+ private User addressbookEntryUserSharer;
/**
- * Connection to table "business_contacts" (commercial contacts)
+ * Connection to table "addressbooks"
*/
- @JoinColumn (name = "entry_business_contact_id", updatable = false)
- @OneToOne (targetEntity = CompanyContact.class, cascade = CascadeType.ALL)
- private BusinessContact addressbookEntryBusinessContact;
+ @JoinColumn (name = "addressbook_id", nullable = false, updatable = false)
+ @OneToOne (targetEntity = UserAddressbook.class, optional = false, cascade = CascadeType.ALL)
+ private Addressbook addressbookId;
@Override
public int compareTo (final AddressbookEntry addressbookEntry) {
}
@Override
- public List<User> getAddressbookEntryUserAddedList () {
- return this.addressbookEntryUserAddedList;
+ public User getAddressbookEntryUserSharer () {
+ return this.addressbookEntryUserSharer;
}
@Override
- public void setAddressbookEntryUserAddedList (final List<User> addressbookEntryUserAddedList) {
- this.addressbookEntryUserAddedList = addressbookEntryUserAddedList;
+ public void setAddressbookEntryUserSharer (final User addressbookEntryUserSharer) {
+ this.addressbookEntryUserSharer = addressbookEntryUserSharer;
}
@Override
- public List<User> getAddressbookEntryUserOriginList () {
- return this.addressbookEntryUserOriginList;
+ public User getAddressbookEntryUserOwner () {
+ return this.addressbookEntryUserOwner;
}
@Override
- public void setAddressbookEntryUserOriginList (final List<User> addressbookEntryUserOriginList) {
- this.addressbookEntryUserOriginList = addressbookEntryUserOriginList;
+ public void setAddressbookEntryUserOwner (final User addressbookEntryUserOwner) {
+ this.addressbookEntryUserOwner = addressbookEntryUserOwner;
}
@Override