From: Roland Haeder Date: Tue, 22 Sep 2015 14:05:47 +0000 (+0200) Subject: JPA started X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0662fc422ad5b313da3dbb8418cd1d5d422fd53c;p=jcore.git JPA started Signed-off-by:Roland Häder --- diff --git a/lib/jpa20-persistence/javax.persistence-2.1.0-doc.zip b/lib/jpa20-persistence/javax.persistence-2.1.0-doc.zip new file mode 100644 index 0000000..fd55e6e Binary files /dev/null and b/lib/jpa20-persistence/javax.persistence-2.1.0-doc.zip differ diff --git a/lib/jpa20-persistence/javax.persistence_2.1.0.v201304241213.jar b/lib/jpa20-persistence/javax.persistence_2.1.0.v201304241213.jar new file mode 100644 index 0000000..841d2e1 Binary files /dev/null and b/lib/jpa20-persistence/javax.persistence_2.1.0.v201304241213.jar differ diff --git a/lib/nblibraries.properties b/lib/nblibraries.properties index 6d0afb5..7ee5412 100644 --- a/lib/nblibraries.properties +++ b/lib/nblibraries.properties @@ -2,3 +2,9 @@ libs.CopyLibs.classpath=\ ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar libs.CopyLibs.displayName=CopyLibs Task libs.CopyLibs.prop-version=2.0 +libs.jpa20-persistence.classpath=\ + ${base}/jpa20-persistence/javax.persistence_2.1.0.v201304241213.jar +libs.jpa20-persistence.displayName=Persistence (JPA 2.1) +libs.jpa20-persistence.javadoc=\ + ${base}/jpa20-persistence/javax.persistence-2.1.0-doc.zip +libs.jpa20-persistence.prop-maven-dependencies=org.eclipse.persistence:javax.persistence:2.1.0:jar diff --git a/nbproject/project.properties b/nbproject/project.properties index a99007e..06346c9 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -38,7 +38,8 @@ jar.compress=false jar.index=${jnlp.enabled} javac.classpath=\ ${file.reference.log4j-api-2.3.jar}:\ - ${file.reference.log4j-core-2.3.jar} + ${file.reference.log4j-core-2.3.jar}:\ + ${libs.jpa20-persistence.classpath} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=true diff --git a/src/org/mxchange/jcore/model/contact/BaseContact.java b/src/org/mxchange/jcore/model/contact/BaseContact.java index 0fb4d49..b41332e 100644 --- a/src/org/mxchange/jcore/model/contact/BaseContact.java +++ b/src/org/mxchange/jcore/model/contact/BaseContact.java @@ -17,7 +17,19 @@ package org.mxchange.jcore.model.contact; import java.sql.Timestamp; +import java.util.Date; import java.util.Objects; +import javax.annotation.PostConstruct; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; import org.mxchange.jcore.client.Client; import org.mxchange.jcore.model.contact.gender.Gender; @@ -27,105 +39,135 @@ import org.mxchange.jcore.model.contact.gender.Gender; * @author Roland Haeder * @version 0.0 */ -public class BaseContact implements Contact, Comparable { +@Entity (name = "contact") +@Table (name = "contacts") +public abstract class BaseContact implements Contact, Comparable { + /** * Serial number */ private static final long serialVersionUID = 58_744_284_981_863L; - /** - * When the contact has been created - */ - private Timestamp created; - - /** - * Id number - */ - private Long id; - /** * Birth day */ - private String birthday; + @Column + @Temporal (TemporalType.DATE) + private Date birthday; /** * Cellphone number */ + @Column (name = "cellphone_number", length = 100) private String cellphoneNumber; /** * City */ + @Column (nullable = false, length = 100) private String city; /** * Optional comments */ + @Lob + @Column private String comment; /** * Company name */ + @Column (name = "company_name", nullable = false) private String companyName; /** * Country code */ + @Column (name = "country_code", length = 2, nullable = false) private String countryCode; + /** + * When the contact has been created + */ + @Basic(optional = false) + @Temporal (TemporalType.TIMESTAMP) + @Column(nullable = false) + private Timestamp created; + /** * Email address */ + @Column (name = "email_address", length = 100, nullable = false) private String emailAddress; /** * Family name */ + @Basic (optional = false) + @Column (name = "family_name", length = 100, nullable = false) private String familyName; /** * Fax number */ + @Column (name = "fax_number", length = 100) private String faxNumber; /** * First name */ + @Basic (optional = false) + @Column (name = "first_name", length = 100, nullable = false) private String firstName; /** * Gender instance */ + @Basic (optional = false) + @Column (nullable = false) private Gender gender; /** * House number */ + @Column (name = "house_number", length = 5, nullable = false) private Long houseNumber; + /** + * Id number + */ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + /** * Flag whether this contact is user's own data */ - private boolean ownContact; + @Column (name = "own_contact", nullable = false) + private Boolean ownContact; /** * Phone number */ + @Column (name = "phone_number", length = 100) private String phoneNumber; /** * Street */ + @Column (nullable = false) private String street; /** * When the contact has been updated */ + @Temporal (TemporalType.TIMESTAMP) private Timestamp updated; /** * ZIP code */ + @Column (name = "zip_code", nullable = false, length = 6) private Long zipCode; /** @@ -133,16 +175,39 @@ public class BaseContact implements Contact, Comparable { * and provide proper constructors. */ protected BaseContact () { - // Fake gender - this.gender = Gender.UNKNOWN; + } + + /** + * Compares two contacts with each other + * + * @param contact Contact comparator + * @return Comparison value + */ + @Override + public int compareTo (final Contact contact) { + // contact should not be null + if (null == contact) { + throw new NullPointerException("contact is null"); //NOI18N + } + + // Is the id the same? + if (Objects.equals(this.getId(), contact.getId())) { + // Same id, means same contact + return 0; + } else if (this.getId() > contact.getId()) { + // This id is larger than compared to + return -1; + } + + // The other id is larger + return 1; } /** * Check if contacts are same or throw an exception * * @param object Other possible contact class - * @return Whether both contacts are same - * TODO Needs a lot improvements + * @return Whether both contacts are same TODO Needs a lot improvements */ @Override public boolean equals (final Object object) { @@ -164,310 +229,167 @@ public class BaseContact implements Contact, Comparable { && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase()))); } - /** - * Birth day - * - * @return the birthday - */ @Override - public String getBirthday () { + public Date getBirthday () { return this.birthday; } - /** - * Birth day - * - * @param birthday the birthday to set - */ @Override - public void setBirthday (final String birthday) { + public void setBirthday (final Date birthday) { this.birthday = birthday; } - /** - * Cellphone number - * - * @return the cellphoneNumber - */ @Override public String getCellphoneNumber () { return this.cellphoneNumber; } - /** - * Cellphone number - * - * @param cellphoneNumber the cellphoneNumber to set - */ @Override public void setCellphoneNumber (final String cellphoneNumber) { this.cellphoneNumber = cellphoneNumber; } - /** - * City - * - * @return the city - */ @Override public String getCity () { return this.city; } - /** - * City - * - * @param city the city to set - */ @Override public void setCity (final String city) { this.city = city; } - /** - * Comments - * - * @return the comment - */ @Override public String getComment () { return this.comment; } - /** - * Comments - * - * @param comment the comment to set - */ @Override public void setComment (final String comment) { this.comment = comment; } - /** - * Company name - * - * @return the companyName - */ @Override public String getCompanyName () { return this.companyName; } - /** - * Company name - * - * @param companyName the companyName to set - */ @Override public void setCompanyName (final String companyName) { this.companyName = companyName; } @Override - public Timestamp getCreated () { - return this.created; - } - - @Override - public void setCreated (final Timestamp created) { - this.created = created; - } - - /** - * Id number - * @return the id - */ - @Override - public Long getId () { - return this.id; + public String getCountryCode () { + return this.countryCode; } - /** - * Id number - * @param id the id to set - */ @Override - public void setId (final Long id) { - this.id = id; + public void setCountryCode (final String countryCode) { + this.countryCode = countryCode; } - /** - * Country code - * - * @return the countryCode - */ @Override - public String getCountryCode () { - return this.countryCode; + public Timestamp getCreated () { + return this.created; } - /** - * Country code - * - * @param countryCode the countryCode to set - */ @Override - public void setCountryCode (final String countryCode) { - this.countryCode = countryCode; + public void setCreated (final Timestamp created) { + this.created = created; } - /** - * Email address - * - * @return the emailAddress - */ @Override public String getEmailAddress () { return this.emailAddress; } - /** - * Email address - * - * @param emailAddress the emailAddress to set - */ @Override public void setEmailAddress (final String emailAddress) { this.emailAddress = emailAddress; } - /** - * Family name - * - * @return the familyName - */ @Override public String getFamilyName () { //* NOISY-DEBUG: */ this.getLogger().trace("CALLED!"); return this.familyName; } - /** - * Family name - * - * @param familyName the familyName to set - */ @Override public void setFamilyName (final String familyName) { this.familyName = familyName; } - /** - * Fax number - * - * @return the faxNumber - */ @Override public String getFaxNumber () { return this.faxNumber; } - /** - * Fax number - * - * @param faxNumber the faxNumber to set - */ @Override public void setFaxNumber (final String faxNumber) { this.faxNumber = faxNumber; } - /** - * First name - * - * @return the firstName - */ @Override public String getFirstName () { return this.firstName; } - /** - * First name - * - * @param firstName the firstName to set - */ @Override public void setFirstName (final String firstName) { this.firstName = firstName; } - /** - * Gender of the contact - * - * @return the gender - */ @Override public Gender getGender () { return this.gender; } - /** - * Gender of the contact - * - * @param gender the gender to set - */ @Override public void setGender (final Gender gender) { this.gender = gender; } - /** - * House number - * - * @return the houseNumber - */ @Override public Long getHouseNumber () { return this.houseNumber; } - /** - * House number - * - * @param houseNumber the houseNumber to set - */ @Override public void setHouseNumber (final Long houseNumber) { this.houseNumber = houseNumber; } - /** - * Phone number - * - * @return the phoneNumber - */ + @Override + public Long getId () { + return this.id; + } + + @Override + public void setId (final Long id) { + this.id = id; + } + + @Override + public void setOwnContact (final Boolean ownContact) { + this.ownContact = ownContact; + } + @Override public String getPhoneNumber () { return this.phoneNumber; } - /** - * Phone number - * - * @param phoneNumber the phoneNumber to set - */ @Override public void setPhoneNumber (final String phoneNumber) { this.phoneNumber = phoneNumber; } - /** - * Street - * - * @return the street - */ @Override public String getStreet () { return this.street; } - /** - * Street - * - * @param street the street to set - */ @Override public void setStreet (final String street) { this.street = street; @@ -483,21 +405,11 @@ public class BaseContact implements Contact, Comparable { this.updated = updated; } - /** - * ZIP code - * - * @return the zipCode - */ @Override public Long getZipCode () { return this.zipCode; } - /** - * ZIP code - * - * @param zipCode the zipCode to set - */ @Override public void setZipCode (final Long zipCode) { this.zipCode = zipCode; @@ -515,22 +427,24 @@ public class BaseContact implements Contact, Comparable { return hash; } - /** - * Checks whether the contact is user's own data - * - * @return Own data? - */ + @PostConstruct + public void init () { + // Fake gender + this.gender = Gender.UNKNOWN; + } + @Override - public boolean isOwnContact () { + public Boolean isOwnContact () { return this.ownContact; } /** - * Shows this contact to the user + * Shows this contact to the user. * * @param client Client instance to use - * TODO: Maybe needs to be moved to other class + * @deprecated Should not be called here */ + @Deprecated public void show (final Client client) { // The client must be set if (null == client) { @@ -547,35 +461,4 @@ public class BaseContact implements Contact, Comparable { // Display other data "box" client.displayOtherDataBox(this); } - - @Override - public void setOwnContact (final Boolean ownContact) { - this.ownContact = ownContact; - } - - /** - * Compares two contacts with each other - * - * @param contact Contact comparator - * @return Comparison value - */ - @Override - public int compareTo (final Contact contact) { - // contact should not be null - if (null == contact) { - throw new NullPointerException("contact is null"); //NOI18N - } - - // Is the id the same? - if (Objects.equals(this.getId(), contact.getId())) { - // Same id, means same contact - return 0; - } else if (this.getId() > contact.getId()) { - // This id is larger than compared to - return -1; - } - - // The other id is larger - return 1; - } } diff --git a/src/org/mxchange/jcore/model/contact/Contact.java b/src/org/mxchange/jcore/model/contact/Contact.java index 33fbe37..8cbc93d 100644 --- a/src/org/mxchange/jcore/model/contact/Contact.java +++ b/src/org/mxchange/jcore/model/contact/Contact.java @@ -18,6 +18,7 @@ package org.mxchange.jcore.model.contact; import java.io.Serializable; import java.sql.Timestamp; +import java.util.Date; import org.mxchange.jcore.model.contact.gender.Gender; /** @@ -225,14 +226,14 @@ public interface Contact extends Serializable { * * @return the birthday */ - public String getBirthday (); + public Date getBirthday (); /** * Birth day * * @param birthday the birthday to set */ - public void setBirthday (final String birthday); + public void setBirthday (final Date birthday); /** * Comments @@ -253,7 +254,7 @@ public interface Contact extends Serializable { * * @return Own data? */ - public boolean isOwnContact (); + public Boolean isOwnContact (); /** * Setter for own contact