/*
- * Copyright (C) 2015 Roland Haeder
+ * Copyright (C) 2016 Roland Haeder
*
* 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 org.mxchange.jcontacts.contact.UserContact;
import org.mxchange.jcontactsbusiness.BusinessContact;
import org.mxchange.jcontactsbusiness.CompanyContact;
-import org.mxchange.jusercore.model.user.LoginUser;
-import org.mxchange.jusercore.model.user.User;
/**
* A POJO for address book entries
* <p>
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
*/
@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")
+ name = "SearchUsersAddressbookEntries",
+ query = "SELECT e FROM addressbook_entries AS e INNER JOIN addressbooks AS a ON e.addressbookId = a WHERE e.addressbookId = :addressbook AND a.addressbookUser = :owner ORDER BY e.addressbookEntryId ASC")
)
-public class UserAddressbookEntry implements AddressbookEntry, Comparable<AddressbookEntry> {
+public class UserAddressbookEntry implements AddressbookEntry {
/**
* Serial number
* Connection to table "business_contacts" (commercial contacts)
*/
@JoinColumn (name = "entry_business_contact_id", updatable = false)
- @OneToOne (targetEntity = CompanyContact.class, cascade = CascadeType.ALL)
+ @OneToOne (targetEntity = CompanyContact.class, cascade = CascadeType.REFRESH)
private BusinessContact addressbookEntryBusinessContact;
/**
* Connection to table "contacts" (private contacts)
*/
@JoinColumn (name = "entry_private_contact_id", updatable = false)
- @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL)
+ @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.REFRESH)
private Contact addressbookEntryPrivateContact;
- /**
- * Connection to table "users" (who has initially created this entry
- */
- @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 "users" (who has added this entry)
- */
- @JoinColumn (name = "entry_sharer_user_id", updatable = false)
- @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.ALL)
- private User addressbookEntryUserSharer;
-
/**
* Connection to table "addressbooks"
*/
- @JoinColumn (name = "addressbook_id", nullable = false, updatable = false)
- @OneToOne (targetEntity = UserAddressbook.class, optional = false, cascade = CascadeType.ALL)
+ @JoinColumn (name = "entry_addressbook_id", nullable = false, updatable = false)
+ @OneToOne (targetEntity = UserAddressbook.class, cascade = CascadeType.REFRESH, optional = false)
private Addressbook addressbookId;
- @Override
- public int compareTo (final AddressbookEntry addressbookEntry) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
-
@Override
public boolean equals (final Object object) {
- if (object == null) {
+ if (null == object) {
return false;
- } else if (getClass() != object.getClass()) {
+ } else if (this.getClass() != object.getClass()) {
return false;
}
return false;
} else if (!Objects.equals(this.getAddressbookEntryPrivateContact(), other.getAddressbookEntryPrivateContact())) {
return false;
- } else if (!Objects.equals(this.getAddressbookEntryUserOwner(), other.getAddressbookEntryUserOwner())) {
- return false;
- } else if (!Objects.equals(this.getAddressbookEntryUserSharer(), other.getAddressbookEntryUserSharer())) {
- return false;
} else if (!Objects.equals(this.getAddressbookId(), other.getAddressbookId())) {
return false;
}
return true;
}
+ @Override
+ public int hashCode () {
+ int hash = 3;
+ hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryBusinessContact());
+ hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryPrivateContact());
+ hash = 19 * hash + Objects.hashCode(this.getAddressbookId());
+ return hash;
+ }
+
@Override
public BusinessContact getAddressbookEntryBusinessContact () {
return this.addressbookEntryBusinessContact;
this.addressbookEntryPrivateContact = addressbookEntryPrivateContact;
}
- @Override
- public User getAddressbookEntryUserSharer () {
- return this.addressbookEntryUserSharer;
- }
-
- @Override
- public void setAddressbookEntryUserSharer (final User addressbookEntryUserSharer) {
- this.addressbookEntryUserSharer = addressbookEntryUserSharer;
- }
-
- @Override
- public User getAddressbookEntryUserOwner () {
- return this.addressbookEntryUserOwner;
- }
-
- @Override
- public void setAddressbookEntryUserOwner (final User addressbookEntryUserOwner) {
- this.addressbookEntryUserOwner = addressbookEntryUserOwner;
- }
-
@Override
public Addressbook getAddressbookId () {
return this.addressbookId;
this.addressbookId = addressbookId;
}
- @Override
- public int hashCode () {
- int hash = 3;
- hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryBusinessContact());
- hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryPrivateContact());
- hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryUserOwner());
- hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryUserSharer());
- hash = 19 * hash + Objects.hashCode(this.getAddressbookId());
- return hash;
- }
-
}