org.apache.mailreaderjpa.User Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.mailreaderjpa;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Version;
/**
* JPA entity class for the MAILREADER_USERS
table.
*/
@Entity(name="mailreader_users")
@NamedQueries({
@NamedQuery(name="User.findAll", query="SELECT u FROM mailreader_users u"),
@NamedQuery(name="User.findByUsername", query="SELECT u FROM mailreader_users u WHERE u.username = :username")
})
public class User implements Serializable {
@Id
@Column(name="user_id")
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
/** Creates a new instance of User */
public User() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String toString() {
return "org.apache.mailreaderjpa.User[id=" + id
+ ",fromAddress='" + getFromAddress()
+ "',fullName='" + getFullName()
+ "',password='" + getPassword()
+ "',replyToAddress='" + getReplyToAddress()
+ "',username='" + getUsername()
+ "',lastUpdate='" + getLastUpdate()
+ "']";
}
public int hashCode() {
if (getId() != null) {
return getId().intValue();
} else {
return super.hashCode();
}
}
public boolean equals(Object obj) {
if ((obj instanceof User)
&& (getId() != null)) {
return getId().equals(((User) obj).getId());
} else {
return false;
}
}
@Column(name="from_address")
private String fromAddress;
@Column(name="full_name")
private String fullName;
@Column(nullable=false)
private String password;
@Column(name="reply_to_address")
private String replyToAddress;
@OneToMany(mappedBy="user",cascade=CascadeType.ALL)
private List subscriptions;
@Column(nullable=false, unique=true)
private String username;
@Column(name="last_update")
@Version()
private Timestamp lastUpdate;
public String getFromAddress() {
return fromAddress;
}
public void setFromAddress(String fromAddress) {
this.fromAddress = fromAddress;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getReplyToAddress() {
return replyToAddress;
}
public void setReplyToAddress(String replyToAddress) {
this.replyToAddress = replyToAddress;
}
public List getSubscriptions() {
return subscriptions;
}
public void setSubscriptions(List subscriptions) {
this.subscriptions = subscriptions;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Timestamp getLastUpdate() {
return lastUpdate;
}
public void setLastUpdate(Timestamp lastUpdate) {
this.lastUpdate = lastUpdate;
}
public void addSubscription(Subscription subscription) {
List subscriptions = getSubscriptions();
if (!subscriptions.contains(subscription)) {
subscription.setUser(this);
subscriptions.add(subscription);
}
}
public void removeSubscription(Subscription subscription) {
List subscriptions = getSubscriptions();
if (subscriptions.contains(subscription)) {
subscriptions.remove(subscription);
// Commment out following line because it seems to cause
// an update of the USER_ID column setting it to null, which
// would violate the database integrity constraints
// subscription.setUser(null);
}
}
}