/*
- * 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
package org.mxchange.addressbook.model.addressbook.entry;
import java.util.Calendar;
+import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
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
@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> {
* 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.MERGE)
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.MERGE)
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, optional = false, cascade = CascadeType.MERGE)
private Addressbook addressbookId;
@Override
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) {
+ return false;
+ } else if (getClass() != object.getClass()) {
+ return false;
+ }
+
+ final AddressbookEntry other = (AddressbookEntry) object;
+
+ if (!Objects.equals(this.getAddressbookEntryBusinessContact(), other.getAddressbookEntryBusinessContact())) {
+ return false;
+ } else if (!Objects.equals(this.getAddressbookEntryPrivateContact(), other.getAddressbookEntryPrivateContact())) {
+ return false;
+ } else if (!Objects.equals(this.getAddressbookId(), other.getAddressbookId())) {
+ return false;
+ }
+
+ return true;
+ }
+
@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.getAddressbookId());
+ return hash;
+ }
+
}