X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Forg%2Fmxchange%2Faddressbook%2Fmodel%2Faddressbook%2Fentry%2FUserAddressbookEntry.java;h=8af65ce2213502c97b7e3774613fc15cc6094ac2;hb=a5da4801e8b1a61328551a8a32a073f84c978945;hp=4e39de3a120a216d3f666a03e0d56836aec65492;hpb=cd49ae3f8c2a123eae48331de429c8a097f5688f;p=jfinancials-lib.git
diff --git a/src/org/mxchange/addressbook/model/addressbook/entry/UserAddressbookEntry.java b/src/org/mxchange/addressbook/model/addressbook/entry/UserAddressbookEntry.java
index 4e39de3..8af65ce 100644
--- a/src/org/mxchange/addressbook/model/addressbook/entry/UserAddressbookEntry.java
+++ b/src/org/mxchange/addressbook/model/addressbook/entry/UserAddressbookEntry.java
@@ -1,5 +1,5 @@
/*
- * 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
@@ -17,7 +17,7 @@
package org.mxchange.addressbook.model.addressbook.entry;
import java.util.Calendar;
-import java.util.List;
+import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
@@ -26,7 +26,8 @@ import javax.persistence.GeneratedValue;
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;
@@ -37,17 +38,20 @@ import org.mxchange.jcontacts.contact.Contact;
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
*
- * @author Roland Haeder
+ * @author Roland Haeder
*/
@Entity (name = "addressbook_entries")
@Table (name = "addressbook_entries")
-public class UserAddressbookEntry implements AddressbookEntry, Comparable {
+@NamedQueries (
+ @NamedQuery (
+ 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 {
/**
* Serial number
@@ -55,12 +59,11 @@ public class UserAddressbookEntry implements AddressbookEntry, Comparable addressbookEntryUserOriginList;
-
- /**
- * Connection to table "users" (who has added this entry)
+ * Id number
*/
- @JoinColumn (name = "entry_added_user_id", updatable = false)
- @ManyToOne (targetEntity = LoginUser.class, cascade = CascadeType.ALL)
- private List addressbookEntryUserAddedList;
+ @Id
+ @GeneratedValue (strategy = GenerationType.IDENTITY)
+ @Column (name = "entry_id", nullable = false, updatable = false)
+ private Long addressbookEntryId;
/**
* 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 "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 = "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.
+ public boolean equals (final Object object) {
+ if (null == object) {
+ return false;
+ } else if (this.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 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
@@ -150,26 +165,6 @@ public class UserAddressbookEntry implements AddressbookEntry, Comparable getAddressbookEntryUserAddedList () {
- return this.addressbookEntryUserAddedList;
- }
-
- @Override
- public void setAddressbookEntryUserAddedList (final List addressbookEntryUserAddedList) {
- this.addressbookEntryUserAddedList = addressbookEntryUserAddedList;
- }
-
- @Override
- public List getAddressbookEntryUserOriginList () {
- return this.addressbookEntryUserOriginList;
- }
-
- @Override
- public void setAddressbookEntryUserOriginList (final List addressbookEntryUserOriginList) {
- this.addressbookEntryUserOriginList = addressbookEntryUserOriginList;
- }
-
@Override
public Addressbook getAddressbookId () {
return this.addressbookId;