/*
 * 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.ambari.server.orm.entities;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 * Entity representing a KerberosPrincipal stored on a host.
 */
@Entity
@IdClass(KerberosPrincipalHostEntityPK.class)
@Table(name = "kerberos_principal_host")
@NamedQueries({
    @NamedQuery(name = "KerberosPrincipalHostEntityFindAll",
        query = "SELECT kph FROM KerberosPrincipalHostEntity kph"),
    @NamedQuery(name = "KerberosPrincipalHostEntityFindByPrincipal",
        query = "SELECT kph FROM KerberosPrincipalHostEntity kph WHERE kph.principalName=:principalName"),
    @NamedQuery(name = "KerberosPrincipalHostEntityFindByHost",
        query = "SELECT kph FROM KerberosPrincipalHostEntity kph WHERE kph.hostName=:hostName")
})
public class KerberosPrincipalHostEntity {

  @Id
  @Column(name = "principal_name", insertable = true, updatable = false, nullable = false)
  private String principalName;

  @Id
  @Column(name = "host_name", insertable = true, updatable = false, nullable = false)
  private String hostName;

  @ManyToOne
  @JoinColumn(name = "principal_name", referencedColumnName = "principal_name", nullable = false, insertable = false, updatable = false)
  private KerberosPrincipalEntity principalEntity;

  @ManyToOne
  @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false, insertable = false, updatable = false)
  private HostEntity hostEntity;

  /**
   * Constucts an empty KerberosPrincipalHostEntity
   */
  public KerberosPrincipalHostEntity() {
  }

  /**
   * Constructs a new KerberosPrincipalHostEntity
   *
   * @param principalName a String indicating this KerberosPrincipalHostEntity's principal name
   * @param hostName      a String indicating the KerberosPrincipalHostEntity's host name
   */
  public KerberosPrincipalHostEntity(String principalName, String hostName) {
    setPrincipalName(principalName);
    setHostName(hostName);
  }

  /**
   * Gets the principal name for this KerberosPrincipalHostEntity
   *
   * @return a String indicating this KerberosPrincipalHostEntity's principal name
   */
  public String getPrincipalName() {
    return principalName;
  }

  /**
   * Sets the principal name for this KerberosPrincipalHostEntity
   *
   * @param principalName a String indicating this KerberosPrincipalHostEntity's principal name
   */
  public void setPrincipalName(String principalName) {
    this.principalName = principalName;
  }

  /**
   * Gets the host name for this KerberosHostHostEntity
   *
   * @return a String indicating this KerberosHostHostEntity's host name
   */
  public String getHostName() {
    return hostName;
  }

  /**
   * Sets the host name for this KerberosHostHostEntity
   *
   * @param hostName a String indicating this KerberosHostHostEntity's host name
   */
  public void setHostName(String hostName) {
    this.hostName = hostName;
  }

  /**
   * Gets the related HostEntity
   *
   * @return the related HostEntity
   */
  public HostEntity getHostEntity() {
    return hostEntity;
  }

  /**
   * Sets the related HostEntity
   *
   * @param hostEntity the related HostEntity
   */
  public void setHostEntity(HostEntity hostEntity) {
    this.hostEntity = hostEntity;
  }

  /**
   * Gets the related KerberosPrincipalEntity
   *
   * @return the related KerberosPrincipalEntity
   */
  public KerberosPrincipalEntity getPrincipalEntity() {
    return principalEntity;
  }

  /**
   * Sets the related KerberosPrincipalEntity
   *
   * @param principalEntity the related KerberosPrincipalEntity
   */
  public void setPrincipalEntity(KerberosPrincipalEntity principalEntity) {
    this.principalEntity = principalEntity;
  }
}
