From 1f8add441383e17daae8b99ca86ebb242e16a67f Mon Sep 17 00:00:00 2001
From: Peter Hormanns <peter.hormanns@hostsharing.net>
Date: Wed, 18 Jul 2012 10:53:46 +0200
Subject: [PATCH] DomainOptions Model

---
 hsarback/src/de/hsadmin/mods/dom/DomainOption.java |   88 ++++++++++++++++++++++++++++++++++++++++++++
 hsarback/src/de/hsadmin/mods/dom/Domain.java       |   14 +++++++
 hsarback/conf/META-INF/persistence.xml             |    1 
 3 files changed, 103 insertions(+), 0 deletions(-)

diff --git a/hsarback/conf/META-INF/persistence.xml b/hsarback/conf/META-INF/persistence.xml
index 8651105..6efa7fe 100644
--- a/hsarback/conf/META-INF/persistence.xml
+++ b/hsarback/conf/META-INF/persistence.xml
@@ -17,6 +17,7 @@
 		<class>de.hsadmin.mods.pac.INetAddress</class>
 		<class>de.hsadmin.mods.user.UnixUser</class> 
 		<class>de.hsadmin.mods.dom.Domain</class> 
+		<class>de.hsadmin.mods.dom.DomainOption</class> 
 		<class>de.hsadmin.mods.email.EMailAddress</class> 
 		<class>de.hsadmin.mods.email.EMailAlias</class> 
 		<class>de.hsadmin.mods.db.DatabaseUser</class> 
diff --git a/hsarback/src/de/hsadmin/mods/dom/Domain.java b/hsarback/src/de/hsadmin/mods/dom/Domain.java
index 451a5bb..f9ff399 100644
--- a/hsarback/src/de/hsadmin/mods/dom/Domain.java
+++ b/hsarback/src/de/hsadmin/mods/dom/Domain.java
@@ -4,13 +4,16 @@
 import static javax.persistence.GenerationType.SEQUENCE;
 
 import java.util.Date;
+import java.util.Set;
 
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.EntityManager;
+import javax.persistence.FetchType;
 import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
+import javax.persistence.ManyToMany;
 import javax.persistence.ManyToOne;
 import javax.persistence.SequenceGenerator;
 import javax.persistence.Table;
@@ -64,6 +67,9 @@
 	@Column(name = "domain_dns_master", columnDefinition = "character varying(64)")
 	private String dnsMaster;
 
+	@ManyToMany(fetch=FetchType.EAGER, mappedBy="domains")
+	private Set<DomainOption> domainOptions;
+	
 	public Domain() {
 	}
 
@@ -207,6 +213,14 @@
 			"obj.user=:loginUser";
 	}
 
+	public Set<DomainOption> getDomainOptions() {
+		return domainOptions;
+	}
+
+	public void setDomainOptions(Set<DomainOption> domainOptions) {
+		this.domainOptions = domainOptions;
+	}
+
 	public static enum Status {
 		NONE(""), 
 		ERROR("error"), 
diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainOption.java b/hsarback/src/de/hsadmin/mods/dom/DomainOption.java
new file mode 100644
index 0000000..55db527
--- /dev/null
+++ b/hsarback/src/de/hsadmin/mods/dom/DomainOption.java
@@ -0,0 +1,88 @@
+package de.hsadmin.mods.dom;
+
+import static javax.persistence.GenerationType.SEQUENCE;
+
+import java.util.Set;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EntityManager;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+
+import de.hsadmin.core.model.AbstractEntity;
+import de.hsadmin.core.model.FieldValidation;
+import de.hsadmin.mods.user.UnixUser;
+
+@Table(name="domain_option")
+@Entity(name="DomainOption")
+@SequenceGenerator(name = "DomainOptionSeqGen", sequenceName = "domain_option_id_seq")
+public class DomainOption extends AbstractEntity {
+
+	@Id
+	@Column(name = "domain_option_id", columnDefinition = "integer")
+	@GeneratedValue(strategy = SEQUENCE, generator = "DomainOptionSeqGen")
+	private long id;
+
+	@FieldValidation("[a-z0-9]+")
+	@Column(name = "domain_option_name", columnDefinition = "character varying(256)", nullable = false)
+	private String name;
+
+	@ManyToMany(fetch=FetchType.LAZY)
+	@JoinTable(name="domain__domain_option",
+		joinColumns={@JoinColumn(name="domain_option_id", referencedColumnName="domain_option_id")},
+		inverseJoinColumns={@JoinColumn(name="domain_id", referencedColumnName="domain_id")})
+	private Set<Domain> domains;
+
+	@Override
+	public long id() {
+		return getId();
+	}
+
+	@Override
+	public String createStringKey() {
+		return name;
+	}
+
+	@Override
+	public boolean isNew() {
+		return false;
+	}
+
+	@Override
+	public UnixUser owningUser(EntityManager em) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public long getId() {
+		return id;
+	}
+
+	public void setId(long id) {
+		this.id = id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public Set<Domain> getDomains() {
+		return domains;
+	}
+
+	public void setDomains(Set<Domain> domains) {
+		this.domains = domains;
+	}
+
+}

--
Gitblit v1.9.1