Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.swe1.kundenverwaltung.domain;
- import static javax.xml.bind.annotation.XmlAccessType.FIELD;
- import static javax.persistence.CascadeType.PERSIST;
- import static javax.persistence.CascadeType.REMOVE;
- import java.io.Serializable;
- import java.net.URI;
- import javax.persistence.Entity;
- import javax.persistence.Table;
- import javax.persistence.NamedQueries;
- import javax.persistence.NamedQuery;
- import javax.persistence.Id;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Column;
- import javax.persistence.ManyToOne;
- import javax.persistence.OneToMany;
- import javax.persistence.Transient;
- import javax.persistence.Embedded;
- import javax.persistence.FetchType;
- import javax.persistence.Version;
- import javax.validation.Valid;
- import javax.validation.constraints.Min;
- import javax.validation.constraints.NotNull;
- import javax.validation.constraints.Pattern;
- import javax.validation.constraints.Size;
- import javax.xml.bind.annotation.XmlAccessorType;
- import javax.xml.bind.annotation.XmlAttribute;
- import javax.xml.bind.annotation.XmlElement;
- import javax.xml.bind.annotation.XmlElementWrapper;
- import javax.xml.bind.annotation.XmlRootElement;
- import javax.xml.bind.annotation.XmlTransient;
- import org.hibernate.validator.constraints.Email;
- import de.swe1.anschriftverwaltung.domain.Anschrift;
- import de.swe1.bestellverwaltung.domain.Bestellung;
- import de.swe1.util.IdGroup;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * JPA Klasse Anschrift fuer Datenbank.
- */
- @Entity
- @Table(name = "kunde")
- @NamedQueries({
- @NamedQuery(name = Kunde.FIND_KUNDE,
- query = "SELECT k"
- + " FROM Kunde k LEFT JOIN FETCH k.bestellungen"),
- @NamedQuery(name = Kunde.FIND_KUNDE_BY_NACHNAME,
- query = "FROM Kunde k"
- + " WHERE k.name=:" + Kunde.PARAM_KUNDE_NACHNAME),
- @NamedQuery(name = Kunde.FIND_KUNDE_BY_ID,
- query = "FROM Kunde k"
- + " WHERE k.idKunde=:" + Kunde.PARAM_KUNDE_IDKUNDE
- ),
- @NamedQuery(name = Kunde.FIND_KUNDE_BY_VORNAMEANDNACHNAME,
- query = "FROM Kunde k"
- + " WHERE k.vorname=:" + Kunde.PARAM_KUNDE_VORNAME + " AND " + "k.name=:" + Kunde.PARAM_KUNDE_NACHNAME),
- @NamedQuery(name = "Kunde.Count",
- query = "Select Count(idKunde)as Anzahl From Kunde"),
- @NamedQuery(name = Kunde.FIND_KUNDE_BY_NACHNAMEFETCHBESTELLUNG,
- query = "SELECT DISTINCT k"
- + " FROM Kunde k LEFT JOIN FETCH k.bestellungen"
- + " WHERE k.name= :" + Kunde.PARAM_KUNDE_NACHNAME),
- @NamedQuery(name = Kunde.FIND_KUNDEN_FETCH_BESTELLUNGEN,
- query = "SELECT DISTINCT k"
- + " FROM Kunde k LEFT JOIN FETCH k.bestellungen"),
- @NamedQuery(name = Kunde.FIND_KUNDE_BY_IDKUNDEFETCHBESTELLUNG,
- query = "SELECT DISTINCT k"
- + " FROM Kunde k LEFT JOIN FETCH k.bestellungen"
- + " WHERE k.idKunde = :" + Kunde.PARAM_KUNDE_IDKUNDE),
- @NamedQuery(name = Kunde.FIND_KUNDE_BY_PLZ,
- query = "Select k"
- + " From Kunde k"
- + " Left Join Fetch k.anschrift"
- + " Where k.anschrift.plz=:" + Kunde.PARAM_KUNDE_PLZ),
- @NamedQuery(name = Kunde.FIND_KUNDE_BY_RABATT,
- query = "Select k"
- + " From Kunde k"
- + " Where k.kundenrabatt>=:" + Kunde.PARAM_KUNDE_RABATT),
- @NamedQuery(name = Kunde.FIND_KUNDE_BY_KEINEBESTELLUNG,
- query = "Select k"
- + " From Kunde k"
- + " Where k NOT IN (Select kk From Kunde kk,Bestellung b "
- + " Where kk.idKunde=b.kunde)"),
- @NamedQuery(name = Kunde.FIND_KUNDE_BY_LOGINNAME,
- query = "Select k"
- + " From Kunde k"
- + " Where k.loginname=:" + Kunde.PARAM_KUNDE_LOGINNAME),
- @NamedQuery(name = Kunde.FIND_KUNDE_BY_EMAIL,
- query = "Select k "
- + "From Kunde k "
- + "Where k.email=:" + Kunde.PARAM_KUNDE_EMAIL),
- @NamedQuery(name = Kunde.FIND_NACHNAMEN_BY_PREFIX,
- query = "SELECT DISTINCT k.name"
- + " FROM Kunde k "
- + " WHERE UPPER(k.name) LIKE UPPER(:"
- + Kunde.PARAM_KUNDE_NACHNAME_PREFIX + ")"),
- @NamedQuery(name = Kunde.FIND_KUNDEN_BY_ID_PREFIX,
- query = "SELECT k"
- + " FROM Kunde as k"
- + " WHERE CONCAT('', k.id) LIKE :" + Kunde.PARAM_KUNDE_ID_PREFIX
- + " ORDER BY k.id"),
- @NamedQuery(name = Kunde.FIND_ALL_NACHNAMEN,
- query = "SELECT DISTINCT k.name"
- + " FROM Kunde k"
- + " ORDER BY k.name")
- })
- @XmlRootElement
- @XmlAccessorType(FIELD)
- public class Kunde implements Serializable {
- /** The Constant serialVersionUID. */
- private static final long serialVersionUID = 1L;
- /** Konstante fuer die Beanvalidation. */
- private static final String NAME_PATTERN = "[A-Z\u00C4\u00D6\u00DC][a-z\u00E4\u00F6\u00FC\u00DF]+";
- /** The Constant NACHNAME_PATTERN. */
- public static final String NACHNAME_PATTERN = NAME_PATTERN + "(-" + NAME_PATTERN + ")?";
- /** The Constant GESCHLECHT_PATTERN. */
- public static final String GESCHLECHT_PATTERN = "(w|m)?";
- /** The Constant NACHNAME_LENGTH_MIN. */
- public static final int NACHNAME_LENGTH_MIN = 2;
- /** The Constant NACHNAME_LENGTH_MAX. */
- public static final int NACHNAME_LENGTH_MAX = 32;
- /** The Constant VORNAME_LENGTH_MAX. */
- public static final int VORNAME_LENGTH_MAX = 32;
- /** The Constant EMAIL_LENGTH_MAX. */
- public static final int EMAIL_LENGTH_MAX = 128;
- /** The Constant PASSWORD_LENGTH_MAX. */
- public static final int PASSWORD_LENGTH_MAX = 25;
- /** The Constant MIN_ID. */
- public static final int MIN_ID = 0;
- /** The Constant LOGINNAME_LENGTH_MAX. */
- public static final int LOGINNAME_LENGTH_MAX = 30;
- /** The Constant LOGINNAME_LENGTH_MIN. */
- public static final int LOGINNAME_LENGTH_MIN = 2;
- /** The Constant PASSWORD_LENGTH_MIN. */
- public static final int PASSWORD_LENGTH_MIN = 5;
- /** String-Konstanten fuer die @Named-Queries. */
- public static final String PREFIX = "Kunde.";
- /** The Constant FIND_KUNDE. */
- public static final String FIND_KUNDE = PREFIX + "findKunden";
- /** The Constant FIND_KUNDE_BY_NACHNAME. */
- public static final String FIND_KUNDE_BY_NACHNAME = FIND_KUNDE + ".byNachname";
- /** The Constant FIND_KUNDE_BY_ID. */
- public static final String FIND_KUNDE_BY_ID = FIND_KUNDE + ".byId";
- /** The Constant FIND_KUNDE_BY_VORNAMEANDNACHNAME. */
- public static final String FIND_KUNDE_BY_VORNAMEANDNACHNAME = FIND_KUNDE + ".byVornameUndVorname";
- /** The Constant FIND_KUNDE_BY_NACHNAMEFETCHBESTELLUNG. */
- public static final String FIND_KUNDE_BY_NACHNAMEFETCHBESTELLUNG = FIND_KUNDE + ".byNachnameFetchBestellung";
- /** The Constant FIND_KUNDE_BY_IDKUNDEFETCHBESTELLUNG. */
- public static final String FIND_KUNDE_BY_IDKUNDEFETCHBESTELLUNG = FIND_KUNDE + ".byIdFetchBestellung";
- /** The Constant FIND_KUNDEN_FETCH_BESTELLUNGEN. */
- public static final String FIND_KUNDEN_FETCH_BESTELLUNGEN = FIND_KUNDE + ".fetchBestellungen";
- /** The Constant FIND_KUNDE_BY_PLZ. */
- public static final String FIND_KUNDE_BY_PLZ = FIND_KUNDE + ".byPlz";
- /** The Constant FIND_KUNDE_BY_RABATT. */
- public static final String FIND_KUNDE_BY_RABATT = FIND_KUNDE + ".byRabatt";
- /** The Constant FIND_KUNDE_BY_KEINEBESTELLUNG. */
- public static final String FIND_KUNDE_BY_KEINEBESTELLUNG = FIND_KUNDE + ".byKeineBestellung";
- /** The Constant FIND_KUNDE_BY_LOGINNAMEANDPASSWORD. */
- public static final String FIND_KUNDE_BY_LOGINNAME = FIND_KUNDE + ".byLoginnname";
- /** The Constant FIND_KUNDE_BY_EMAIL. */
- public static final String FIND_KUNDE_BY_EMAIL = FIND_KUNDE + ".byEmail";
- public static final String FIND_NACHNAMEN_BY_PREFIX = PREFIX + "findNachnamenByPrefix";
- public static final String FIND_KUNDEN_BY_ID_PREFIX = PREFIX + "findKundenByIdPrefix";
- public static final String FIND_ALL_NACHNAMEN = PREFIX + "findAllNachnamen";
- /** Parameter fuer die @Named-Queries. */
- public static final String PARAM_KUNDE_IDKUNDE = "kundeId";
- /** The Constant PARAM_KUNDE_NACHNAME. */
- public static final String PARAM_KUNDE_NACHNAME = "kundeNachname";
- /** The Constant PARAM_KUNDE_VORNAME. */
- public static final String PARAM_KUNDE_VORNAME = "kundeVorname";
- /** The Constant PARAM_KUNDE_PLZ. */
- public static final String PARAM_KUNDE_PLZ = "kundePlz";
- /** The Constant PARAM_KUNDE_RABATT. */
- public static final String PARAM_KUNDE_RABATT = "kundeRabatt";
- /** The Constant PARAM_KUNDE_LOGINNAME. */
- public static final String PARAM_KUNDE_LOGINNAME = "kundeLoginname";
- /** The Constant PARAM_KUNDE_PASSWORD. */
- public static final String PARAM_KUNDE_PASSWORD = "kundePassword";
- /** The Constant PARAM_KUNDE_EMAIL. */
- public static final String PARAM_KUNDE_EMAIL = "kundeEmail";
- public static final String PARAM_KUNDE_ID_PREFIX = "idPrefix";
- public static final String PARAM_KUNDE_NACHNAME_PREFIX = "nachnamePrefix";
- private static final int ERSTE_VERSION = 0;
- /** The id kunde. */
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- @Column(name = "id_kunde")
- @Min(value = MIN_ID, message = "{kundenverwaltung.kunde.id.min}", groups = IdGroup.class)
- @XmlAttribute(name = "id", required = true)
- private int idKunde;
- /** The email. */
- @Column(length = EMAIL_LENGTH_MAX, nullable = false, unique = true)
- @NotNull(message = "{kundenverwaltung.kunde.email.notNull}")
- @Email(message = "{kundenverwaltung.kunde.email.pattern}")
- private String email;
- /** The firmenname. */
- private String firmenname;
- /** The geschlecht. */
- @Pattern(regexp = GESCHLECHT_PATTERN, message = "(kundenverwaltung.kunde.geschlecht.Pattern")
- private String geschlecht;
- /** The kundenrabatt. */
- @Column(nullable = false)
- private float kundenrabatt;
- /** The loginname. */
- @Column(length = LOGINNAME_LENGTH_MAX)
- @NotNull(message = "{kundenverwaltung.kunde.loginname.notNull}")
- @Size(min = LOGINNAME_LENGTH_MIN, max = LOGINNAME_LENGTH_MAX, message = "{kundenverwaltung.kunde.loginname.legth")
- private String loginname;
- /** The name. */
- @Column(length = NACHNAME_LENGTH_MAX)
- @NotNull(message = "{kundenverwaltung.kunde.nachname.notNull}")
- @Size(min = NACHNAME_LENGTH_MIN, max = NACHNAME_LENGTH_MAX, message = "{kundenverwaltung.kunde.nachname.length}")
- @Pattern(regexp = NACHNAME_PATTERN, message = "{kundenverwaltung.kunde.nachname.pattern}")
- @XmlElement(required = true)
- private String name;
- /** The password. */
- @Column(length = PASSWORD_LENGTH_MAX)
- @Size(min = PASSWORD_LENGTH_MIN, message = "(kundenverwaltung.kunde.password.length)")
- private String password;
- /** The telefonnummer. */
- private String telefonnummer;
- /** The vorname. */
- @Column(length = VORNAME_LENGTH_MAX)
- @Size(max = VORNAME_LENGTH_MAX, message = "{kundenverwaltung.kunde.vorname.length}")
- private String vorname;
- //bi-directional many-to-one association to Bestellung
- /** The bestellungen. */
- @OneToMany(mappedBy = "kunde")
- @XmlTransient
- private List<Bestellung> bestellungen;
- /** The bestellungen uris. */
- @Transient
- @XmlElementWrapper(name = "bestellungen")
- @XmlElement(name = "bestellung")
- private List<URI> bestellungenUris;
- //bi-directional many-to-one association to Anschrift
- /** The anschrift. */
- @ManyToOne(fetch = FetchType.EAGER, cascade = { PERSIST, REMOVE })
- @Embedded
- @Valid
- @NotNull(message = "{kundenverwaltung.kunde.adresse.notNull}")
- private Anschrift anschrift = new Anschrift();
- @Version
- @XmlTransient
- private int version = ERSTE_VERSION;
- /**
- * Instantiates a new kunde.
- */
- public Kunde() {
- }
- /**
- * Gets the id kunde.
- *
- * @return the id kunde
- */
- public int getIdKunde() {
- return this.idKunde;
- }
- /**
- * Sets the id kunde.
- *
- * @param idKunde the new id kunde
- */
- public void setIdKunde(int idKunde) {
- this.idKunde = idKunde;
- }
- /**
- * Gets the email.
- *
- * @return the email
- */
- public String getEmail() {
- return this.email;
- }
- /**
- * Sets the email.
- *
- * @param email the new email
- */
- public void setEmail(String email) {
- this.email = email;
- }
- /**
- * Gets the firmenname.
- *
- * @return the firmenname
- */
- public String getFirmenname() {
- return this.firmenname;
- }
- /**
- * Sets the firmenname.
- *
- * @param firmenname the new firmenname
- */
- public void setFirmenname(String firmenname) {
- this.firmenname = firmenname;
- }
- /**
- * Gets the geschlecht.
- *
- * @return the geschlecht
- */
- public String getGeschlecht() {
- return this.geschlecht;
- }
- /**
- * Sets the geschlecht.
- *
- * @param geschlecht the new geschlecht
- */
- public void setGeschlecht(String geschlecht) {
- this.geschlecht = geschlecht;
- }
- /**
- * Gets the kundenrabatt.
- *
- * @return the kundenrabatt
- */
- public float getKundenrabatt() {
- return this.kundenrabatt;
- }
- /**
- * Sets the kundenrabatt.
- *
- * @param kundenrabatt the new kundenrabatt
- */
- public void setKundenrabatt(float kundenrabatt) {
- this.kundenrabatt = kundenrabatt;
- }
- /**
- * Gets the loginname.
- *
- * @return the loginname
- */
- public String getLoginname() {
- return this.loginname;
- }
- /**
- * Sets the loginname.
- *
- * @param loginname the new loginname
- */
- public void setLoginname(String loginname) {
- this.loginname = loginname;
- }
- /**
- * Gets the name.
- *
- * @return the name
- */
- public String getName() {
- return this.name;
- }
- /**
- * Sets the name.
- *
- * @param name the new name
- */
- public void setName(String name) {
- this.name = name;
- }
- /**
- * Gets the password.
- *
- * @return the password
- */
- public String getPassword() {
- return this.password;
- }
- /**
- * Sets the password.
- *
- * @param password the new password
- */
- public void setPassword(String password) {
- this.password = password;
- }
- /**
- * Gets the telefonnummer.
- *
- * @return the telefonnummer
- */
- public String getTelefonnummer() {
- return this.telefonnummer;
- }
- /**
- * Sets the telefonnummer.
- *
- * @param telefonnummer the new telefonnummer
- */
- public void setTelefonnummer(String telefonnummer) {
- this.telefonnummer = telefonnummer;
- }
- /**
- * Gets the vorname.
- *
- * @return the vorname
- */
- public String getVorname() {
- return this.vorname;
- }
- /**
- * Sets the vorname.
- *
- * @param vorname the new vorname
- */
- public void setVorname(String vorname) {
- this.vorname = vorname;
- }
- /**
- * Gets the bestellungen.
- *
- * @return the bestellungen
- */
- public List<Bestellung> getBestellungen() {
- return this.bestellungen;
- }
- /**
- * Sets the bestellungen.
- *
- * @param bestellungs the new bestellungen
- */
- public void setBestellungen(List<Bestellung> bestellungs) {
- this.bestellungen = bestellungs;
- }
- /**
- * Adds the bestellung.
- *
- * @param bestellung the bestellung
- */
- public void addBestellung(Bestellung bestellung) {
- if (bestellungen == null) {
- bestellungen = new ArrayList<Bestellung>();
- }
- bestellungen.add(bestellung);
- }
- /**
- * Gets the anschrift.
- *
- * @return the anschrift
- */
- public Anschrift getAnschrift() {
- return this.anschrift;
- }
- /**
- * Sets the anschrift.
- *
- * @param anschrift the new anschrift
- */
- public void setAnschrift(Anschrift anschrift) {
- this.anschrift = anschrift;
- }
- /**
- * Sets the bestellungen uris.
- *
- * @param bestellungenUris the new bestellungen uris
- */
- public void setBestellungenUris(List<URI> bestellungenUris) {
- this.bestellungenUris = bestellungenUris;
- }
- /**
- * Gets the bestellungen uris.
- *
- * @return the bestellungen uris
- */
- public List<URI> getBestellungenUris() {
- return bestellungenUris;
- }
- public void setVersion(int version) {
- this.version = version;
- }
- public int getVersion() {
- return version;
- }
- /**
- * Sets the values.
- *
- * @param k the new values
- */
- public void setValues(Kunde k) {
- name = k.name;
- vorname = k.vorname;
- geschlecht = k.geschlecht;
- kundenrabatt = k.kundenrabatt;
- telefonnummer = k.telefonnummer;
- firmenname = k.firmenname;
- loginname = k.loginname;
- email = k.email;
- password = k.password;
- version = k.version;
- }
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((email == null) ? 0 : email.hashCode());
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + ((vorname == null) ? 0 : vorname.hashCode());
- return result;
- }
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- Kunde other = (Kunde) obj;
- if (email == null) {
- if (other.email != null) {
- return false;
- }
- }
- else if (!email.equals(other.email)) {
- return false;
- }
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- }
- else if (!name.equals(other.name)) {
- return false;
- }
- if (vorname == null) {
- if (other.vorname != null) {
- return false;
- }
- }
- else if (!vorname.equals(other.vorname)) {
- return false;
- }
- return true;
- }
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "Kunde [idKunde=" + idKunde + ", email=" + email
- + ", firmenname=" + firmenname + ", geschlecht=" + geschlecht
- + ", kundenrabatt=" + kundenrabatt + ", loginname=" + loginname
- + ", name=" + name + ", password=" + password
- + ", telefonnummer=" + telefonnummer + ", vorname=" + vorname
- + ", bestellungen=" + bestellungen + ", anschrift=" + anschrift
- + "]";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement