com.teradata.benchto.service.model.Environment Maven / Gradle / Ivy
/*
* Licensed 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 com.teradata.benchto.service.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.Type;
import javax.persistence.Cacheable;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.MapKeyColumn;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.time.ZonedDateTime;
import java.util.Map;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.collect.Maps.newHashMap;
import static javax.persistence.FetchType.EAGER;
import static org.hibernate.annotations.CacheConcurrencyStrategy.TRANSACTIONAL;
@Entity
@Cacheable
@Table(name = "environments", uniqueConstraints = @UniqueConstraint(columnNames = {"name"}))
public class Environment
implements Serializable
{
public static final String DEFAULT_ENVIRONMENT_NAME = "name";
@Id
@SequenceGenerator(name = "environments_id_seq",
sequenceName = "environments_id_seq",
allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = "environments_id_seq")
@Column(name = "id")
@JsonIgnore
private long id;
@Size(min = 1, max = 64)
@Column(name = "name")
private String name;
@JsonIgnore
@Column(name = "version")
@Version
private Long version;
@Cache(usage = TRANSACTIONAL)
@BatchSize(size = 10)
@ElementCollection(fetch = EAGER)
@MapKeyColumn(name = "name")
@Column(name = "value")
@CollectionTable(name = "environment_attributes", joinColumns = @JoinColumn(name = "environment_id"))
private Map attributes = newHashMap();
@Column(name = "started")
@Type(type = "org.jadira.usertype.dateandtime.threeten.PersistentZonedDateTime")
private ZonedDateTime started;
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 Long getVersion()
{
return version;
}
public void setVersion(Long version)
{
this.version = version;
}
public Map getAttributes()
{
return attributes;
}
public void setAttributes(Map attributes)
{
this.attributes = attributes;
}
public ZonedDateTime getStarted()
{
return started;
}
public void setStarted(ZonedDateTime started)
{
this.started = started;
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Environment that = (Environment) o;
return Objects.equals(name, that.name);
}
@Override
public int hashCode()
{
return Objects.hash(name);
}
@Override
public String toString()
{
return toStringHelper(this)
.add("id", id)
.add("name", name)
.add("version", version)
.add("attributes", attributes)
.add("started", started)
.toString();
}
}