package com.sequenceiq.cloudbreak.domain; import javax.persistence.Column; import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.SequenceGenerator; import com.sequenceiq.cloudbreak.common.type.ComponentType; import com.sequenceiq.cloudbreak.domain.json.Json; import com.sequenceiq.cloudbreak.domain.json.JsonToString; @Entity @NamedQueries({ @NamedQuery( name = "ClusterComponent.findComponentByClusterIdComponentTypeName", query = "SELECT cv FROM ClusterComponent cv " + "WHERE cv.cluster.id = :clusterId AND cv.componentType = :componentType AND cv.name = :name"), @NamedQuery( name = "ClusterComponent.findComponentByClusterId", query = "SELECT cv FROM ClusterComponent cv WHERE cv.cluster.id = :clusterId" ) }) public class ClusterComponent { @Id @GeneratedValue(strategy = GenerationType.AUTO, generator = "component_generator") @SequenceGenerator(name = "component_generator", sequenceName = "component_id_seq", allocationSize = 1) private Long id; @Enumerated(EnumType.STRING) private ComponentType componentType; @Column(nullable = false) private String name; @Convert(converter = JsonToString.class) @Column(columnDefinition = "TEXT") private Json attributes; @ManyToOne private Cluster cluster; public ClusterComponent() { } public ClusterComponent(ComponentType componentType, String name, Json attributes, Cluster cluster) { this.componentType = componentType; this.name = name; this.attributes = attributes; this.cluster = cluster; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public ComponentType getComponentType() { return componentType; } public void setComponentType(ComponentType componentType) { this.componentType = componentType; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Json getAttributes() { return attributes; } public void setAttributes(Json attributes) { this.attributes = attributes; } public Cluster getCluster() { return cluster; } public void setCluster(Cluster cluster) { this.cluster = cluster; } @Override public String toString() { return "Component{" + "id=" + id + ", componentType=" + componentType + ", name='" + name + '\'' + '}'; } }