package de.terrestris.shogun2.model.layer;

import javax.persistence.Entity;
import javax.persistence.Table;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import de.terrestris.shogun2.model.SecuredPersistentObject;
import de.terrestris.shogun2.model.layer.appearance.LayerAppearance;
import de.terrestris.shogun2.model.layer.source.LayerDataSource;

/**
 *
 * Representation of a layer which consists a corresponding data source
 * and an appearance
 *
 * @author Andre Henn
 * @author terrestris GmbH & Co. KG
 *
 */
@Entity
@Table
public abstract class AbstractLayer extends SecuredPersistentObject {

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	/**
	 *
	 */
	private String name;
	private String type;

	/**
	 *
	 */
	public AbstractLayer() {
		super();
	}

	/**
	 * @param name Layer name
	 * @param type Layer type
	 * @param source The data source of the layer
	 * @param appearance The appearance configuration of the layer
	 */
	public AbstractLayer(String name, String type, LayerDataSource source, LayerAppearance appearance) {
		super();
		this.name = name;
		this.type = type;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}


	/**
	 * @see java.lang.Object#hashCode()
	 *
	 *      According to
	 *      http://stackoverflow.com/questions/27581/overriding-equals
	 *      -and-hashcode-in-java it is recommended only to use getter-methods
	 *      when using ORM like Hibernate
	 */
	@Override
	public int hashCode() {
		// two randomly chosen prime numbers
		return new HashCodeBuilder(29, 13).
				appendSuper(super.hashCode()).
				append(getName()).
				append(getType()).
				toHashCode();
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 *
	 *      According to
	 *      http://stackoverflow.com/questions/27581/overriding-equals
	 *      -and-hashcode-in-java it is recommended only to use getter-methods
	 *      when using ORM like Hibernate
	 */
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof AbstractLayer))
			return false;
		AbstractLayer other = (AbstractLayer) obj;

		return new EqualsBuilder().
				appendSuper(super.equals(other)).
				append(getName(), other.getName()).
				append(getType(), other.getType()).
				isEquals();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.DEFAULT_STYLE);
	}

}

@@ -66,41 +66,255 @@
 nce.
-Entity;%0Aimport javax.persistence.
+AssociationOverride;%0Aimport javax.persistence.AssociationOverrides;%0Aimport javax.persistence.Entity;%0Aimport javax.persistence.Inheritance;%0Aimport javax.persistence.InheritanceType;%0Aimport javax.persistence.JoinColumn;%0Aimport javax.persistence.Join
 Tabl
@@ -855,18 +855,42 @@
 hor 
-Andre Henn
+Kai Volland%0A * @author Nils B%C3%BChner
 %0A * 
@@ -938,21 +938,424 @@
 Entity%0A@
-Table
+Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)%0A@AssociationOverrides(%7B%0A%09@AssociationOverride(%0A%09%09%09name=%22userPermissions%22,%0A%09%09%09joinTable=@JoinTable(name=%22ABSTR_LAYERS_USERPERMISSIONS%22,%0A%09%09%09joinColumns = @JoinColumn(name = %22LAYER_ID%22))),%0A%0A%09@AssociationOverride(%0A%09%09%09name=%22groupPermissions%22,%0A%09%09%09joinTable=@JoinTable(name=%22ABSTR_LAYERS_GROUPPERMISSIONS%22,%0A%09%09%09joinColumns = @JoinColumn(name = %22LAYER_ID%22)))%0A%7D)
 %0Apublic 

Fix hibernate annotations