/*
 * JPA entity template
 *
 *
 * Takatuka - Template fuer JPA2 Entitaeten (inklusive Bean Validation)
 *
 * Moeglichkeiten und Einschraenkungen:
 * - Beziehungen werden abgebildet
 * -- es gibt keine 1:1 Beziehungen
 * -- N:M Beziehungen sind immer bidirektional
 * - Vererbung wird nicht unterstuetzt
 * - Support für CustomData
 */
package de.ivu.elect.business.gebietsbaum.entity;

@javax.persistence.NamedQueries(
 {



       @javax.persistence.NamedQuery(
     name="GEBIET_POLYGON_POINT.UK",
     query="SELECT o FROM GebietPolygonPoint o WHERE "

                         + "o"
                +".position"
              +" = ?1"

             +" AND "         + "o"
                +".gebiet"
                +".nummer"
              +" = ?2"

             +" AND "         + "o"
                +".gebiet"
                +".gebietsart"
                +".name"
              +" = ?3"

             +" AND "         + "o"
                +".gebiet"
                +".gebietsart"
                +".mandant"
                +".nummer"
              +" = ?4"

             +" AND "         + "o"
                +".gebiet"
                +".wahl"
                +".wahlart"
                +".name"
              +" = ?5"

             +" AND "         + "o"
                +".gebiet"
                +".wahl"
                +".wahlart"
                +".mandant"
                +".nummer"
              +" = ?6"

             +" AND "         + "o"
                +".gebiet"
                +".wahl"
                +".wahltermin"
                +".nummer"
              +" = ?7"

             +" AND "         + "o"
                +".gebiet"
                +".wahl"
                +".wahltermin"
                +".wahldatum"
              +" = ?8"

             +" AND "         + "o"
                +".gebiet"
                +".wahl"
                +".wahltermin"
                +".mandant"
                +".nummer"
              +" = ?9"

             +" AND "         + "o"
                +".gebiet"
                +".wahltermin"
                +".nummer"
              +" = ?10"

             +" AND "         + "o"
                +".gebiet"
                +".wahltermin"
                +".wahldatum"
              +" = ?11"

             +" AND "         + "o"
                +".gebiet"
                +".wahltermin"
                +".mandant"
                +".nummer"
              +" = ?12"

     ,
   hints = {
              @javax.persistence.QueryHint(name = "org.hibernate.cacheable", value = "true"),
             @javax.persistence.QueryHint(name = "org.hibernate.flushMode", value = "commit")
   }


   )
   
     ,   @javax.persistence.NamedQuery(
     name="GEBIET_POLYGON_POINT.GebietOrderByPosition",
     query="SELECT o FROM GebietPolygonPoint o WHERE o.gebiet = ?1 ORDER BY o.position",
     hints = {@javax.persistence.QueryHint(name = "org.hibernate.cacheable", value = "true"),
                            @javax.persistence.QueryHint(name = "org.hibernate.flushMode", value = "commit")
             }
   )

        
         ,   @javax.persistence.NamedQuery(
     name="GEBIET_POLYGON_POINT.Wahl",
     query="SELECT o FROM GebietPolygonPoint o WHERE o.gebiet.wahl = ?1",
     hints = {@javax.persistence.QueryHint(name = "org.hibernate.cacheable", value = "true"),
                            @javax.persistence.QueryHint(name = "org.hibernate.flushMode", value = "commit")
             }
   )

        
         ,   @javax.persistence.NamedQuery(
     name="GEBIET_POLYGON_POINT.Wahltermin",
     query="SELECT o FROM GebietPolygonPoint o WHERE o.gebiet.wahltermin = ?1",
     hints = {@javax.persistence.QueryHint(name = "org.hibernate.cacheable", value = "false"),
                            @javax.persistence.QueryHint(name = "org.hibernate.flushMode", value = "commit")
             }
   )

        
     }
)
@javax.enterprise.inject.Vetoed
@javax.persistence.Entity
@javax.persistence.Table(name = "GEBIET_POLYGON_POINT")
// @javax.persistence.IdClass(GebietPolygonPointPK.class)
    @javax.persistence.EntityListeners(de.ivu.elect.jee.protokollierung.ProtokollEntityListener.class)
    @javax.persistence.Cacheable

public
 class GebietPolygonPoint
extends AbstractGebietPolygonPoint
  {

  private static final long serialVersionUID = 0L;


  /**
   * default constructor
   */
  public GebietPolygonPoint() {
    super();
  }

    /**
     * @param original
     *
     * @deprecated Sollte nur mit Bedacht genutzt werden, da hier auch die Beziehungen kopiert werden. Deswegen markiert
     *             als Deprecated.
     */
    @Deprecated
    public GebietPolygonPoint(GebietPolygonPoint original){
      original.copyEntity(this);
    }

  /**
   * PRIMARY KEY
   */
  @javax.persistence.Id
  @javax.persistence.Column(name = "gebiet_polygon_point_id")
    @javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.TABLE, generator = "GebietPolygonPoint")
    @javax.persistence.TableGenerator(name = "GebietPolygonPoint", table = "SEQUENCES", pkColumnName = "sequence_name", pkColumnValue = "GebietPolygonPoint", valueColumnName = "next_val", allocationSize = 1000, initialValue = 0)
    protected java.lang.Long id;

  @Override
  public java.lang.Long getId() {
    return id;
  }

  public void setId(java.lang.Long id) {
    this.id = id;
  }

  @javax.persistence.Transient
  private transient GebietPolygonPointPK pkCache;

  @Override
  public GebietPolygonPointPK getPk() {
    if (pkCache==null || pkCache.getId() != id ) {
      pkCache = new GebietPolygonPointPK(getId());
    }

    return pkCache;
  }

  public static <E extends GebietPolygonPoint> java.util.Map<GebietPolygonPointPK, E> mappeNachPk(java.util.Collection<E> entities){
    java.util.Map<GebietPolygonPointPK, E> result = new java.util.HashMap<>();

    for (E entity : entities) {
      result.put(entity.getPk(), entity);
    }

    return result;
  }

  public static <E extends GebietPolygonPoint> java.util.Map<Long, E> mappeNachId(java.util.Collection<E> entities){
    java.util.Map<Long, E> result = new java.util.HashMap<>();

    for (E entity : entities) {
      result.put(entity.getId(), entity);
    }

    return result;
  }



  /**
   * Indikator, ob sich ein Attribut oder eine UNIDIREKTIONALE n:1-Beziehungen geaendert hat
   */
  @javax.persistence.Transient
  protected boolean attributeChanged = false;

  public void setAttributeChanged() {
    attributeChanged = true;
  }

  public boolean isAttributeChanged() {
    return attributeChanged;
  }

  /**
   * Hilfsvariable fuer das Aktualisieren von Beziehungen
   */
  @javax.persistence.Transient
  protected boolean updateRelationship = false;


  public void resetAttributeChanged() {
        hasChangedGebietPolygonPointArt = false;
          hasChangedLatitude = false;
          hasChangedLongitude = false;
          hasChangedPosition = false;
  
      hasChangedGebiet = false;
  


    attributeChanged = false;
  }


  /**
   * ATTRIBUTE
   */

    
    @javax.persistence.Enumerated(javax.persistence.EnumType.STRING)
      @javax.persistence.Column(name = "GEBIET_POLYGON_POINT_ART", nullable = GebietPolygonPointConstants.GEBIET_POLYGON_POINT_ART_NULLABLE)
    
  protected de.ivu.elect.business.gebietsbaum.entity.GebietPolygonPointArt gebietPolygonPointArt =  null;

  @javax.persistence.Transient
  protected boolean hasChangedGebietPolygonPointArt = false;

  public boolean hasChangedGebietPolygonPointArt(){
    return hasChangedGebietPolygonPointArt;
  }
  
  /**
   * 
   *
   * getter for GEBIET_POLYGON_POINT.GEBIET_POLYGON_POINT_ART
   */
    @Override   public  de.ivu.elect.business.gebietsbaum.entity.GebietPolygonPointArt getGebietPolygonPointArt() {
        return gebietPolygonPointArt;
      }

  /**
   * 
   *
   * setter for GEBIET_POLYGON_POINT.GEBIET_POLYGON_POINT_ART
   *
   * @param gebietPolygonPointArt
   */
  @Override   public void setGebietPolygonPointArt( de.ivu.elect.business.gebietsbaum.entity.GebietPolygonPointArt gebietPolygonPointArt) {

       resetTkCache();
                  de.ivu.elect.business.gebietsbaum.entity.GebietPolygonPointArt gebietPolygonPointArtInternal = gebietPolygonPointArt;
       
       
      boolean thisAttributChanged =
      !de.ivu.elect.jee.entity.EntityUtil.compareObjects(this.gebietPolygonPointArt
      , gebietPolygonPointArtInternal);

      attributeChanged |= thisAttributChanged;

      hasChangedGebietPolygonPointArt |= thisAttributChanged;

      if (thisAttributChanged) {
      markDirty("gebietPolygonPointArt");
      }


      

       this.gebietPolygonPointArt = gebietPolygonPointArtInternal;

         }

        
        @javax.persistence.Column(name = "LATITUDE", nullable = GebietPolygonPointConstants.LATITUDE_NULLABLE)
    
  protected java.lang.Double latitude =  null;

  @javax.persistence.Transient
  protected boolean hasChangedLatitude = false;

  public boolean hasChangedLatitude(){
    return hasChangedLatitude;
  }
  
  /**
   * 
   *
   * getter for GEBIET_POLYGON_POINT.LATITUDE
   */
    @Override   public  java.lang.Double getLatitude() {
        return latitude;
      }

  /**
   * 
   *
   * setter for GEBIET_POLYGON_POINT.LATITUDE
   *
   * @param latitude
   */
  @Override   public void setLatitude( java.lang.Double latitude) {

       resetTkCache();
                  java.lang.Double latitudeInternal = latitude;
       
       
      boolean thisAttributChanged =
      !de.ivu.elect.jee.entity.EntityUtil.compareObjects(this.latitude
      , latitudeInternal);

      attributeChanged |= thisAttributChanged;

      hasChangedLatitude |= thisAttributChanged;

      if (thisAttributChanged) {
      markDirty("latitude");
      }


      

       this.latitude = latitudeInternal;

         }

        
        @javax.persistence.Column(name = "LONGITUDE", nullable = GebietPolygonPointConstants.LONGITUDE_NULLABLE)
    
  protected java.lang.Double longitude =  null;

  @javax.persistence.Transient
  protected boolean hasChangedLongitude = false;

  public boolean hasChangedLongitude(){
    return hasChangedLongitude;
  }
  
  /**
   * 
   *
   * getter for GEBIET_POLYGON_POINT.LONGITUDE
   */
    @Override   public  java.lang.Double getLongitude() {
        return longitude;
      }

  /**
   * 
   *
   * setter for GEBIET_POLYGON_POINT.LONGITUDE
   *
   * @param longitude
   */
  @Override   public void setLongitude( java.lang.Double longitude) {

       resetTkCache();
                  java.lang.Double longitudeInternal = longitude;
       
       
      boolean thisAttributChanged =
      !de.ivu.elect.jee.entity.EntityUtil.compareObjects(this.longitude
      , longitudeInternal);

      attributeChanged |= thisAttributChanged;

      hasChangedLongitude |= thisAttributChanged;

      if (thisAttributChanged) {
      markDirty("longitude");
      }


      

       this.longitude = longitudeInternal;

         }

        
      @javax.persistence.Column(name = "POSITION", nullable = GebietPolygonPointConstants.POSITION_NULLABLE, precision=GebietPolygonPointConstants.POSITION_PRECISION, scale=GebietPolygonPointConstants.POSITION_SCALE)
            
  protected java.lang.Long position =  null;

  @javax.persistence.Transient
  protected boolean hasChangedPosition = false;

  public boolean hasChangedPosition(){
    return hasChangedPosition;
  }
  
  /**
   * 
   *
   * getter for GEBIET_POLYGON_POINT.POSITION
   */
    @Override   public  java.lang.Long getPosition() {
        return position;
      }

  /**
   * 
   *
   * setter for GEBIET_POLYGON_POINT.POSITION
   *
   * @param position
   */
  @Override   public void setPosition( java.lang.Long position) {

       resetTkCache();
                  java.lang.Long positionInternal = position;
       
       
      boolean thisAttributChanged =
      !de.ivu.elect.jee.entity.EntityUtil.compareObjects(this.position
      , positionInternal);

      attributeChanged |= thisAttributChanged;

      hasChangedPosition |= thisAttributChanged;

      if (thisAttributChanged) {
      markDirty("position");
      }


      

       this.position = positionInternal;

         }

    
/**
 * Beziehungen N:1 unidirektional
 */
  /**
   * Beziehung (unidirektional) zu Gebiet
   */
  @javax.persistence.ManyToOne(fetch =  javax.persistence.FetchType.LAZY , optional=false, cascade = {javax.persistence.CascadeType.PERSIST})
  @javax.persistence.JoinColumns(@javax.persistence.JoinColumn(name = "GEBIET_ID", referencedColumnName="GEBIET_ID"))
  protected de.ivu.elect.business.gebietsbaum.entity.Gebiet gebiet;

  /**
   * 
   */
  @Override
  public void setGebiet( de.ivu.elect.business.gebietsbaum.entity.Gebiet gebiet){
    resetTkCache();
    
    boolean thisAttributChanged =
    !de.ivu.elect.jee.entity.EntityUtil.compareObjects(this.gebiet
    , gebiet);

    attributeChanged |= thisAttributChanged;

    hasChangedGebiet |= thisAttributChanged;

    if (thisAttributChanged) {
    markDirty("gebiet");
    }

    this.gebiet = gebiet;
      }

  /**
   * 
   */
    @Override
  public de.ivu.elect.business.gebietsbaum.entity.Gebiet getGebiet(){
    return this.gebiet;
  }

  @javax.persistence.Transient
  protected boolean hasChangedGebiet = false;

  public boolean hasChangedGebiet(){
    return hasChangedGebiet;
  }


/**
 * Beziehungen N:1 bidirektional
 */

  /**
   * Beziehungen 1:N unidirektional (nicht unterstuetzt)
   */

  /**
   * Beziehungen 1:N bidirektional
   */

  /**
   * Beziehungen N:M bidirektional nicht selbstreferenzierend
   */


  /**
   * Beziehungen N:M bidirektional selbstreferenzierend
   */
  

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("GebietPolygonPoint:");
    sb.append(getId());
    sb.append(" (TK: ");
    try {
      sb.append(getTk());
    } catch (Exception e) {
      sb.append(e.getMessage());
    }
    sb.append(")");
    return sb.toString();
}



  /**
   * Kopiert alle Attribute (ausser PK und Version) und UNIDIREKTIONALE n:1-Beziehungen in uebergebene Entitaet.
   *
   * @param other
   *
   * @deprecated Sollte nur mit Bedacht genutzt werden, da hier auch die Beziehungen kopiert werden. Deswegen markiert
   *             als Deprecated.
   */
  @Deprecated
  protected void copyEntity(GebietPolygonPoint other){
                             other.gebietPolygonPointArt = this.gebietPolygonPointArt;
                                other.latitude = this.latitude;
                                other.longitude = this.longitude;
                                other.position = this.position;
           
  other.setGebiet(this.getGebiet());
    if (this.transientContext != null && !this.transientContext.isEmpty()) {
      other.getTransientContext().putAll(this.transientContext);
    }
  }



    @Override
    public void copyEntityAttributesToOtherEntity(de.ivu.elect.jee.entity.Entity other) {
      if (other==null){
        return;
      }
      if (other.isInstanceOf(GebietPolygonPoint.class)){
        copyEntityAttributesUsingSetter((GebietPolygonPoint) other.castTo(GebietPolygonPoint.class).getEntity());
      } else {
        throw new IllegalArgumentException("Keine Instanz von GebietPolygonPoint: " + other);
      }
    }

  /**
  * Kopiert alle Attribute (ausser PK und Version)  in uebergebene Entitaet.
  *
  */
  public void copyEntityAttributesUsingSetter(GebietPolygonPoint other){
               other.setGebietPolygonPointArt(this.gebietPolygonPointArt);
                  other.setLatitude(this.latitude);
                  other.setLongitude(this.longitude);
                  other.setPosition(this.position);
           if (this.transientContext != null && !this.transientContext.isEmpty()) {
      other.getTransientContext().putAll(this.transientContext);
    }
  }


  /**
   * Kopiert alle veränderten Attribute (ausser PK, CustomData, wenn vorhanden und Version) in uebergebene Entitaet.
   *
   */
  public void copyChangedEntityAttributesUsingSetter(GebietPolygonPoint other){
                       if (hasChangedGebietPolygonPointArt) {
        other.setGebietPolygonPointArt(this.gebietPolygonPointArt);
      }
                             if (hasChangedLatitude) {
        other.setLatitude(this.latitude);
      }
                             if (hasChangedLongitude) {
        other.setLongitude(this.longitude);
      }
                             if (hasChangedPosition) {
        other.setPosition(this.position);
      }
             }





    @javax.persistence.Transient
    private transient GebietPolygonPointTK tkCache;

    protected void resetTkCache() {
        tkCache = null;
    }

    public GebietPolygonPointTK getGebietPolygonPointTK(){
    if (tkCache==null) {
    tkCache = new GebietPolygonPointTK(

getPosition()
,   (getGebiet() == null) ? null : getGebiet().getGebietTK()


  );}
  return tkCache;
}
    @Override
    public de.ivu.elect.jee.entity.tk.EntityTK getTk() {
       return getGebietPolygonPointTK();
    }

  @Override
  public GebietPolygonPointUK getUk(){
    return getGebietPolygonPointUK();
  }

  @Override
  public Class< ? > getEntityClass() {
    return GebietPolygonPoint.class;
  }

public GebietPolygonPointUK getGebietPolygonPointUK(){

   return  new GebietPolygonPointUK(

getPosition()
,     getGebiet()==null?null:getGebiet().getGebietUK()


  );
}

  @javax.persistence.Transient
  private transient GebietPolygonPointProperties properties;

  public GebietPolygonPointProperties getProperties(){
    if (properties == null) {
      properties = new GebietPolygonPointProperties(this);
    }
    return properties;
  }

  /**
   * @deprecated getProperties() verwenden.
   */
  @Deprecated
  public GebietPolygonPointProperties getGebietPolygonPointProperties(){
    return getProperties();
  }

  @Override
  public String getEntityTechnicalName() {
    return GebietPolygonPointConstants.MESSAGE_KEY_ENTITY_EINZAHL;
  }

  @Override
  public boolean isAenderungenProtokollieren(){
    
    return false;
  }


    @Override
   public void setProtokollierteAttributeMitWerten(java.util.Map<String, de.ivu.elect.jee.protokollierung.AttributWertVorher> werteVorher) {
                                         }

  @Override
  public java.util.Map<String, de.ivu.elect.jee.protokollierung.VorherNachherWert> getProtokollierteAttributeMitWerten() {
    java.util.Map<String,de.ivu.elect.jee.protokollierung.VorherNachherWert> result;
        result = createEmptyProtokollierteAttributeMitWertenMap();
                                                                                            return result;
  }

  @Override
  public void resetProtokollierteAttribute() {
                                                                               }

  @Override
  public  java.util.List<de.ivu.elect.jee.entity.EntityFachlichAbhaengigNode> getFachlichAbhaengigeEntitaeten(){
            java.util.List<de.ivu.elect.jee.entity.EntityFachlichAbhaengigNode> result = new java.util.ArrayList<>();
                    return result;
  }

        
            protected String getInitialDiscriminator() {
              return "GEBIET_POLYGON_POINT";
            }

            @Override
            public boolean isInstanceOf(Class<?> clazz) {
            return clazz.isInstance(this);
            }


            @Override
            public <E> de.ivu.elect.jee.entity.EntityContainer<E> castTo(Class<E> clazz) {
                return new de.ivu.elect.jee.entity.EntityContainer<>((E)this); // EntityContainer ist notwendig, da sonst von Hibernate die Entität wieder durch ihren Proxy ersetzt wird...
            }

  public boolean isPersistent() {
    return getId() != null;
  }


   private static final String BASE_CLASS_NAME = "GebietPolygonPoint";
   @Override
   public String getBaseClassName() {
     return BASE_CLASS_NAME;
   }


    @Override
    public boolean equals(Object obj) {
    if (obj == null) {
    return false;
    }

    if (this==obj) {
    return true;
    }


    if (id != null) {
      try {
        return id.longValue() == ((de.ivu.elect.jee.entity.Entity) obj).getId().longValue() && BASE_CLASS_NAME.equals(((de.ivu.elect.jee.entity.Entity) obj).getBaseClassName());
      } catch (Exception ignored) {
        // do nothing
        return false;
      }
    }
   return super.equals(obj);
    }

  @javax.persistence.Transient
  private transient boolean hashCodeBerechnet = false;

  @javax.persistence.Transient
  private transient int hashCode = 0;


  @Deprecated // nur in Unit-Tests verwenden(!)
  public void resetHashCode() {
    hashCodeBerechnet = false;
    hashCode = 0;
  }

  @Override
    public int hashCode() {
      if (hashCodeBerechnet) {
      return hashCode;
    }

    if (id == null) {
      hashCode = super.hashCode();
    } else {
      hashCode = id.hashCode();
    }

    hashCodeBerechnet = true;

    return hashCode;

    }


                            @javax.persistence.Transient
                private transient java.util.Set
            <String> dirtyProperties = null;

                protected void markDirty(String property) {
            
          }

          public java.util.Set
      <String> getDirtyProperties() {
          if (dirtyProperties==null){
          dirtyProperties = new java.util.HashSet<>();
          }
          return dirtyProperties;
          }

          public void clearDirtyProperties(){
          dirtyProperties = null;
          }
          public boolean isHibernateDirty() {
            return dirtyProperties!=null;
          }

      
                public void resetValidation() {
        
    validationResult = null;
        }

        @javax.persistence.Transient
        private transient java.util.Set<de.ivu.elect.jee.entity.EntityConstraintViolation> validationResult;

                    public java.util.Set<de.ivu.elect.jee.entity.EntityConstraintViolation> validateEntity() {
            if (validationResult==null) {
               validationResult  = new java.util.HashSet<>();
                                                                   de.ivu.elect.jee.entity.EntityConstraintCheck.checkNotNull(gebietPolygonPointArt, this, GebietPolygonPointConstants.MESSAGE_KEY_GEBIET_POLYGON_POINT_ART_EINZAHL, validationResult);
                                                                                           de.ivu.elect.jee.entity.EntityConstraintCheck.checkNotNull(latitude, this, GebietPolygonPointConstants.MESSAGE_KEY_LATITUDE_EINZAHL, validationResult);
                                                                          de.ivu.elect.jee.entity.EntityConstraintCheck.checkValueRange(GebietPolygonPointConstants.LATITUDE_MAX_VALUE, GebietPolygonPointConstants.LATITUDE_MIN_VALUE, latitude, this, GebietPolygonPointConstants.MESSAGE_KEY_LATITUDE_EINZAHL, validationResult);
                                                           de.ivu.elect.jee.entity.EntityConstraintCheck.checkNotNull(longitude, this, GebietPolygonPointConstants.MESSAGE_KEY_LONGITUDE_EINZAHL, validationResult);
                                                                          de.ivu.elect.jee.entity.EntityConstraintCheck.checkValueRange(GebietPolygonPointConstants.LONGITUDE_MAX_VALUE, GebietPolygonPointConstants.LONGITUDE_MIN_VALUE, longitude, this, GebietPolygonPointConstants.MESSAGE_KEY_LONGITUDE_EINZAHL, validationResult);
                                                           de.ivu.elect.jee.entity.EntityConstraintCheck.checkNotNull(position, this, GebietPolygonPointConstants.MESSAGE_KEY_POSITION_EINZAHL, validationResult);
                                                                          de.ivu.elect.jee.entity.EntityConstraintCheck.checkValueRange(GebietPolygonPointConstants.POSITION_MAX_VALUE, GebietPolygonPointConstants.POSITION_MIN_VALUE, position, this, GebietPolygonPointConstants.MESSAGE_KEY_POSITION_EINZAHL, validationResult);
                                    }
             return validationResult;
        }

            
        @javax.persistence.Transient
        protected transient java.util.Map<String, Object> transientContext;

        @Override
        public java.util.Map<String, Object> getTransientContext() {
          if (transientContext == null) {
             transientContext = new java.util.HashMap<>();
          }
        return transientContext;

        }
                              }
