-/*
- * 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jusercore.model.user;
-
-import java.util.Calendar;
-import java.util.Objects;
-import javax.persistence.Basic;
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.Index;
-import javax.persistence.JoinColumn;
-import javax.persistence.Lob;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
-import javax.persistence.OneToOne;
-import javax.persistence.Table;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
-import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jcontacts.contact.UserContact;
-import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
-import org.mxchange.jusercore.model.user.status.UserAccountStatus;
-
-/**
- * A generic user entity class
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-@Entity (name = "users")
-@Table (
- name = "users",
- indexes = {
- @Index (
- name = "confirmation_key",
- unique = true,
- columnList = "user_confirm_key"
- ),
- @Index (
- name = "user_name",
- unique = true,
- columnList = "user_name"
- )
- }
-)
-@NamedQueries (
- {
- @NamedQuery (name = "AllUserNames", query = "SELECT DISTINCT u.userName FROM users AS u ORDER BY u.userId ASC"),
- @NamedQuery (name = "AllEmailAddresses", query = "SELECT DISTINCT c.contactEmailAddress FROM contacts AS c INNER JOIN users AS u ON u.userContact = c ORDER BY c.contactId ASC"),
- @NamedQuery (name = "SearchUserName", query = "SELECT u FROM users AS u WHERE LOWER(u.userName) LIKE LOWER(:param)"),
- @NamedQuery (name = "SearchUserId", query = "SELECT u FROM users AS u WHERE u.userId = :id"),
- @NamedQuery (name = "SearchEmailAddress", query = "SELECT u FROM users AS u INNER JOIN contacts AS c ON u.userContact = c WHERE LOWER(c.contactEmailAddress) LIKE LOWER(:param)"),
- @NamedQuery (name = "SearchAllUsersExcept", query = "SELECT u FROM users AS u WHERE u != :user ORDER BY u.userId ASC"),
- @NamedQuery (name = "AllUsers", query = "SELECT u FROM users AS u ORDER BY u.userId ASC"),
- @NamedQuery (name = "AllPublicUsers", query = "SELECT u FROM users AS u WHERE u.userAccountStatus = :status AND u.userProfileMode = :mode ORDER BY u.userId ASC"),
- @NamedQuery (name = "AllMemberPublicUsers", query = "SELECT u FROM users AS u WHERE u.userAccountStatus = :status AND u.userProfileMode IN (:public, :members) ORDER BY u.userId ASC")
- }
-)
-@SuppressWarnings ("PersistenceUnitPresent")
-public class LoginUser implements User {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 4_328_454_581_751L;
-
- /**
- * Account status
- */
- @Basic (optional = false)
- @Column (name = "user_account_status", nullable = false)
- @Enumerated (value = EnumType.STRING)
- private UserAccountStatus userAccountStatus;
-
- /**
- * Confirmation key
- */
- @Column (name = "user_confirm_key", length = 50)
- private String userConfirmKey;
-
- /**
- * Id number from "contacts" table
- */
- @JoinColumn (name = "user_contact_id", referencedColumnName = "contact_id", nullable = false, updatable = false, unique = true)
- @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL, optional = false)
- private Contact userContact;
-
- /**
- * "created" timestamp
- */
- @Basic (optional = false)
- @Temporal (TemporalType.TIMESTAMP)
- @Column (name = "user_created", nullable = false)
- private Calendar userCreated;
-
- /**
- * Encrypted password
- */
- @Basic (optional = false)
- @Column (name = "user_encrypted_password", nullable = false)
- private String userEncryptedPassword;
-
- /**
- * User id
- */
- @Id
- @Column (name = "user_id", nullable = false, length = 20, updatable = false)
- @GeneratedValue (strategy = GenerationType.IDENTITY)
- private Long userId;
-
- /**
- * Last "locked" timestamp
- */
- @Temporal (TemporalType.TIMESTAMP)
- @Column (name = "user_last_locked_timestamp")
- private Calendar userLastLocked;
-
- /**
- * Last locked reason
- */
- @Lob
- @Column (name = "user_last_locked_reason")
- private String userLastLockedReason;
-
- /**
- * User name
- */
- @Basic (optional = false)
- @Column (name = "user_name", nullable = false, length = 20)
- private String userName;
-
- /**
- * Profile mode of this user
- */
- @Basic (optional = false)
- @Enumerated (EnumType.STRING)
- @Column (name = "user_profile_mode", nullable = false)
- private ProfileMode userProfileMode;
-
- /**
- * When this user has been updated
- */
- @Temporal (TemporalType.TIMESTAMP)
- @Column (name = "user_updated")
- private Calendar userUpdated;
-
- /**
- * Default constructor
- */
- public LoginUser () {
- // Default is invisible
- this.userProfileMode = ProfileMode.INVISIBLE;
- }
-
- @Override
- public void copyAll (final User user) {
- // Is contact set?
- if (user.getUserContact() instanceof Contact) {
- // Copy also contact data
- this.getUserContact().copyAll(user.getUserContact());
- }
-
- // Copy other data
- this.setUserConfirmKey(user.getUserConfirmKey());
- this.setUserName(user.getUserName());
- this.setUserEncryptedPassword(user.getUserEncryptedPassword());
- this.setUserAccountStatus(user.getUserAccountStatus());
- this.setUserCreated(user.getUserCreated());
- this.setUserLastLocked(user.getUserLastLocked());
- this.setUserUpdated(user.getUserUpdated());
- this.setUserProfileMode(user.getUserProfileMode());
- }
-
- @Override
- public boolean equals (final Object object) {
- if (null == object) {
- return false;
- } else if (this.getClass() != object.getClass()) {
- return false;
- }
-
- final User other = (User) object;
-
- return ((Objects.equals(this.getUserName(), other.getUserName())) &&
- (Objects.equals(this.getUserId(), other.getUserId())));
- }
-
- @Override
- public UserAccountStatus getUserAccountStatus () {
- return this.userAccountStatus;
- }
-
- @Override
- public void setUserAccountStatus (final UserAccountStatus userAccountStatus) {
- this.userAccountStatus = userAccountStatus;
- }
-
- @Override
- public String getUserConfirmKey () {
- return this.userConfirmKey;
- }
-
- @Override
- public void setUserConfirmKey (final String userConfirmKey) {
- this.userConfirmKey = userConfirmKey;
- }
-
- @Override
- public Contact getUserContact () {
- return this.userContact;
- }
-
- @Override
- public void setUserContact (final Contact userContact) {
- this.userContact = userContact;
- }
-
- @Override
- @SuppressWarnings ("ReturnOfDateField")
- public Calendar getUserCreated () {
- return this.userCreated;
- }
-
- @Override
- @SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setUserCreated (final Calendar userCreated) {
- this.userCreated = userCreated;
- }
-
- @Override
- public String getUserEncryptedPassword () {
- return this.userEncryptedPassword;
- }
-
- @Override
- public void setUserEncryptedPassword (final String userEncryptedPassword) {
- this.userEncryptedPassword = userEncryptedPassword;
- }
-
- @Override
- public Long getUserId () {
- return this.userId;
- }
-
- @Override
- public void setUserId (final Long userId) {
- this.userId = userId;
- }
-
- @Override
- @SuppressWarnings ("ReturnOfDateField")
- public Calendar getUserLastLocked () {
- return this.userLastLocked;
- }
-
- @Override
- @SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setUserLastLocked (final Calendar userLastLocked) {
- this.userLastLocked = userLastLocked;
- }
-
- @Override
- public String getUserLastLockedReason () {
- return this.userLastLockedReason;
- }
-
- @Override
- public void setUserLastLockedReason (final String userLastLockedReason) {
- this.userLastLockedReason = userLastLockedReason;
- }
-
- @Override
- public String getUserName () {
- return this.userName;
- }
-
- @Override
- public void setUserName (final String userName) {
- this.userName = userName;
- }
-
- @Override
- public ProfileMode getUserProfileMode () {
- return this.userProfileMode;
- }
-
- @Override
- public void setUserProfileMode (final ProfileMode userProfileMode) {
- this.userProfileMode = userProfileMode;
- }
-
- @Override
- @SuppressWarnings ("ReturnOfDateField")
- public Calendar getUserUpdated () {
- return this.userUpdated;
- }
-
- @Override
- @SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setUserUpdated (final Calendar userUpdated) {
- this.userUpdated = userUpdated;
- }
-
- @Override
- public int hashCode () {
- int hash = 5;
- hash = 83 * hash + Objects.hashCode(this.getUserName());
- hash = 83 * hash + Objects.hashCode(this.getUserId());
- return hash;
- }
-
-}
+/*\r
+ * Copyright (C) 2016 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.jusercore.model.user;\r
+\r
+import java.util.Calendar;\r
+import java.util.Objects;\r
+import javax.persistence.Basic;\r
+import javax.persistence.CascadeType;\r
+import javax.persistence.Column;\r
+import javax.persistence.Entity;\r
+import javax.persistence.EnumType;\r
+import javax.persistence.Enumerated;\r
+import javax.persistence.GeneratedValue;\r
+import javax.persistence.GenerationType;\r
+import javax.persistence.Id;\r
+import javax.persistence.Index;\r
+import javax.persistence.JoinColumn;\r
+import javax.persistence.Lob;\r
+import javax.persistence.NamedQueries;\r
+import javax.persistence.NamedQuery;\r
+import javax.persistence.OneToOne;\r
+import javax.persistence.Table;\r
+import javax.persistence.Temporal;\r
+import javax.persistence.TemporalType;\r
+import org.mxchange.jcontacts.contact.Contact;\r
+import org.mxchange.jcontacts.contact.UserContact;\r
+import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;\r
+import org.mxchange.jusercore.model.user.status.UserAccountStatus;\r
+\r
+/**\r
+ * A generic user entity class\r
+ * <p>\r
+ * @author Roland Haeder<roland@mxchange.org>\r
+ */\r
+@Entity (name = "users")\r
+@Table (\r
+ name = "users",\r
+ indexes = {\r
+ @Index (\r
+ name = "confirmation_key",\r
+ unique = true,\r
+ columnList = "user_confirm_key"\r
+ ),\r
+ @Index (\r
+ name = "user_name",\r
+ unique = true,\r
+ columnList = "user_name"\r
+ )\r
+ }\r
+)\r
+@NamedQueries (\r
+ {\r
+ @NamedQuery (name = "AllUserNames", query = "SELECT DISTINCT u.userName FROM users AS u ORDER BY u.userId ASC"),\r
+ @NamedQuery (name = "AllEmailAddresses", query = "SELECT DISTINCT c.contactEmailAddress FROM contacts AS c INNER JOIN users AS u ON u.userContact = c ORDER BY c.contactId ASC"),\r
+ @NamedQuery (name = "SearchUserByName", query = "SELECT u FROM users AS u WHERE LOWER(u.userName) LIKE LOWER(:param)"),\r
+ @NamedQuery (name = "SearchUserById", query = "SELECT u FROM users AS u WHERE u.userId = :id"),\r
+ @NamedQuery (name = "SearchUserByEmailAddress", query = "SELECT u FROM users AS u INNER JOIN contacts AS c ON u.userContact = c WHERE LOWER(c.contactEmailAddress) LIKE LOWER(:param)"),\r
+ @NamedQuery (name = "SearchAllUsersExcept", query = "SELECT u FROM users AS u WHERE u != :user ORDER BY u.userId ASC"),\r
+ @NamedQuery (name = "AllUsers", query = "SELECT u FROM users AS u ORDER BY u.userId ASC"),\r
+ @NamedQuery (name = "AllPublicUsers", query = "SELECT u FROM users AS u WHERE u.userAccountStatus = :status AND u.userProfileMode = :mode ORDER BY u.userId ASC"),\r
+ @NamedQuery (name = "AllMemberPublicUsers", query = "SELECT u FROM users AS u WHERE u.userAccountStatus = :status AND u.userProfileMode IN (:public, :members) ORDER BY u.userId ASC")\r
+ }\r
+)\r
+@SuppressWarnings ("PersistenceUnitPresent")\r
+public class LoginUser implements User {\r
+\r
+ /**\r
+ * Serial number\r
+ */\r
+ private static final long serialVersionUID = 4_328_454_581_751L;\r
+\r
+ /**\r
+ * Account status\r
+ */\r
+ @Basic (optional = false)\r
+ @Column (name = "user_account_status", nullable = false)\r
+ @Enumerated (value = EnumType.STRING)\r
+ private UserAccountStatus userAccountStatus;\r
+\r
+ /**\r
+ * Confirmation key\r
+ */\r
+ @Column (name = "user_confirm_key", length = 50)\r
+ private String userConfirmKey;\r
+\r
+ /**\r
+ * Id number from "contacts" table\r
+ */\r
+ @JoinColumn (name = "user_contact_id", referencedColumnName = "contact_id", nullable = false, updatable = false, unique = true)\r
+ @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL, optional = false)\r
+ private Contact userContact;\r
+\r
+ /**\r
+ * "created" timestamp\r
+ */\r
+ @Basic (optional = false)\r
+ @Temporal (TemporalType.TIMESTAMP)\r
+ @Column (name = "user_created", nullable = false)\r
+ private Calendar userCreated;\r
+\r
+ /**\r
+ * Encrypted password\r
+ */\r
+ @Basic (optional = false)\r
+ @Column (name = "user_encrypted_password", nullable = false)\r
+ private String userEncryptedPassword;\r
+\r
+ /**\r
+ * User id\r
+ */\r
+ @Id\r
+ @Column (name = "user_id", nullable = false, length = 20, updatable = false)\r
+ @GeneratedValue (strategy = GenerationType.IDENTITY)\r
+ private Long userId;\r
+\r
+ /**\r
+ * Last "locked" timestamp\r
+ */\r
+ @Temporal (TemporalType.TIMESTAMP)\r
+ @Column (name = "user_last_locked_timestamp")\r
+ private Calendar userLastLocked;\r
+\r
+ /**\r
+ * Last locked reason\r
+ */\r
+ @Lob\r
+ @Column (name = "user_last_locked_reason")\r
+ private String userLastLockedReason;\r
+\r
+ /**\r
+ * User name\r
+ */\r
+ @Basic (optional = false)\r
+ @Column (name = "user_name", nullable = false, length = 20)\r
+ private String userName;\r
+\r
+ /**\r
+ * Profile mode of this user\r
+ */\r
+ @Basic (optional = false)\r
+ @Enumerated (EnumType.STRING)\r
+ @Column (name = "user_profile_mode", nullable = false)\r
+ private ProfileMode userProfileMode;\r
+\r
+ /**\r
+ * When this user has been updated\r
+ */\r
+ @Temporal (TemporalType.TIMESTAMP)\r
+ @Column (name = "user_updated")\r
+ private Calendar userUpdated;\r
+\r
+ /**\r
+ * Default constructor\r
+ */\r
+ public LoginUser () {\r
+ // Default is invisible\r
+ this.userProfileMode = ProfileMode.INVISIBLE;\r
+ }\r
+\r
+ @Override\r
+ public void copyAll (final User user) {\r
+ // Is contact set?\r
+ if (user.getUserContact() instanceof Contact) {\r
+ // Copy also contact data\r
+ this.getUserContact().copyAll(user.getUserContact());\r
+ }\r
+\r
+ // Copy other data\r
+ this.setUserConfirmKey(user.getUserConfirmKey());\r
+ this.setUserName(user.getUserName());\r
+ this.setUserEncryptedPassword(user.getUserEncryptedPassword());\r
+ this.setUserAccountStatus(user.getUserAccountStatus());\r
+ this.setUserCreated(user.getUserCreated());\r
+ this.setUserLastLocked(user.getUserLastLocked());\r
+ this.setUserUpdated(user.getUserUpdated());\r
+ this.setUserProfileMode(user.getUserProfileMode());\r
+ }\r
+\r
+ @Override\r
+ public boolean equals (final Object object) {\r
+ if (null == object) {\r
+ return false;\r
+ } else if (this.getClass() != object.getClass()) {\r
+ return false;\r
+ }\r
+\r
+ final User other = (User) object;\r
+\r
+ return ((Objects.equals(this.getUserName(), other.getUserName())) &&\r
+ (Objects.equals(this.getUserId(), other.getUserId())));\r
+ }\r
+\r
+ @Override\r
+ public UserAccountStatus getUserAccountStatus () {\r
+ return this.userAccountStatus;\r
+ }\r
+\r
+ @Override\r
+ public void setUserAccountStatus (final UserAccountStatus userAccountStatus) {\r
+ this.userAccountStatus = userAccountStatus;\r
+ }\r
+\r
+ @Override\r
+ public String getUserConfirmKey () {\r
+ return this.userConfirmKey;\r
+ }\r
+\r
+ @Override\r
+ public void setUserConfirmKey (final String userConfirmKey) {\r
+ this.userConfirmKey = userConfirmKey;\r
+ }\r
+\r
+ @Override\r
+ public Contact getUserContact () {\r
+ return this.userContact;\r
+ }\r
+\r
+ @Override\r
+ public void setUserContact (final Contact userContact) {\r
+ this.userContact = userContact;\r
+ }\r
+\r
+ @Override\r
+ @SuppressWarnings ("ReturnOfDateField")\r
+ public Calendar getUserCreated () {\r
+ return this.userCreated;\r
+ }\r
+\r
+ @Override\r
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")\r
+ public void setUserCreated (final Calendar userCreated) {\r
+ this.userCreated = userCreated;\r
+ }\r
+\r
+ @Override\r
+ public String getUserEncryptedPassword () {\r
+ return this.userEncryptedPassword;\r
+ }\r
+\r
+ @Override\r
+ public void setUserEncryptedPassword (final String userEncryptedPassword) {\r
+ this.userEncryptedPassword = userEncryptedPassword;\r
+ }\r
+\r
+ @Override\r
+ public Long getUserId () {\r
+ return this.userId;\r
+ }\r
+\r
+ @Override\r
+ public void setUserId (final Long userId) {\r
+ this.userId = userId;\r
+ }\r
+\r
+ @Override\r
+ @SuppressWarnings ("ReturnOfDateField")\r
+ public Calendar getUserLastLocked () {\r
+ return this.userLastLocked;\r
+ }\r
+\r
+ @Override\r
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")\r
+ public void setUserLastLocked (final Calendar userLastLocked) {\r
+ this.userLastLocked = userLastLocked;\r
+ }\r
+\r
+ @Override\r
+ public String getUserLastLockedReason () {\r
+ return this.userLastLockedReason;\r
+ }\r
+\r
+ @Override\r
+ public void setUserLastLockedReason (final String userLastLockedReason) {\r
+ this.userLastLockedReason = userLastLockedReason;\r
+ }\r
+\r
+ @Override\r
+ public String getUserName () {\r
+ return this.userName;\r
+ }\r
+\r
+ @Override\r
+ public void setUserName (final String userName) {\r
+ this.userName = userName;\r
+ }\r
+\r
+ @Override\r
+ public ProfileMode getUserProfileMode () {\r
+ return this.userProfileMode;\r
+ }\r
+\r
+ @Override\r
+ public void setUserProfileMode (final ProfileMode userProfileMode) {\r
+ this.userProfileMode = userProfileMode;\r
+ }\r
+\r
+ @Override\r
+ @SuppressWarnings ("ReturnOfDateField")\r
+ public Calendar getUserUpdated () {\r
+ return this.userUpdated;\r
+ }\r
+\r
+ @Override\r
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")\r
+ public void setUserUpdated (final Calendar userUpdated) {\r
+ this.userUpdated = userUpdated;\r
+ }\r
+\r
+ @Override\r
+ public int hashCode () {\r
+ int hash = 5;\r
+ hash = 83 * hash + Objects.hashCode(this.getUserName());\r
+ hash = 83 * hash + Objects.hashCode(this.getUserId());\r
+ return hash;\r
+ }\r
+\r
+}\r