org.opencastproject.series.impl.persistence.SeriesEntity Maven / Gradle / Ivy
/**
* Licensed to The Apereo Foundation under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
*
* The Apereo Foundation licenses this file to you under the Educational
* Community 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://opensource.org/licenses/ecl2.txt
*
* 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.opencastproject.series.impl.persistence;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
import javax.persistence.Access;
import javax.persistence.AccessType;
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.IdClass;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.MapKeyColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
/**
* Enitity object for storing series in persistence storage. Series ID is stored as primary key, DUBLIN_CORE field is
* used to store serialized Dublin core and ACCESS_CONTROL field is used to store information about access control
* rules.
*
*/
@Entity(name = "SeriesEntity")
@IdClass(SeriesEntityId.class)
@Access(AccessType.FIELD)
@Table(name = "oc_series",
indexes = {
@Index(name = "IX_oc_series_modified_date", columnList = ("modified_date")),
}
)
@NamedQueries({
@NamedQuery(
name = "Series.findAll",
query = "select s from SeriesEntity s where s.deletionDate is null"
),
@NamedQuery(
name = "Series.getCount",
query = "select COUNT(s) from SeriesEntity s where s.deletionDate is null"
),
@NamedQuery(
name = "seriesById",
query = "select s from SeriesEntity as s where s.seriesId=:seriesId and s.organization=:organization"
),
@NamedQuery(
name = "Series.getAllModifiedSince",
query = "select s from SeriesEntity as s "
+ "where s.modifiedDate >= :since and s.organization=:organization "
+ "order by s.modifiedDate asc"
),
@NamedQuery(
name = "Series.getAllModifiedInRange",
query = "select s from SeriesEntity as s "
+ "where s.modifiedDate >= :from and s.modifiedDate < :to and s.organization=:organization "
+ "order by s.modifiedDate asc"
),
})
public class SeriesEntity {
/** Series ID, primary key */
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", length = 128)
protected String seriesId;
/** Series ID, primary key */
@Id
@Column(name = "organization", length = 128)
protected String organization;
/** Serialized Dublin core */
@Lob
@Column(name = "dublin_core", length = 65535)
protected String dublinCoreXML;
/** Serialized access control */
@Lob
@Column(name = "access_control", length = 65535)
protected String accessControl;
@Column(name = "modified_date", nullable = false)
@Temporal(TemporalType.TIMESTAMP)
protected Date modifiedDate = new Date();
@Column(name = "deletion_date")
@Temporal(TemporalType.TIMESTAMP)
protected Date deletionDate = null;
@Lob
@ElementCollection(targetClass = String.class)
@MapKeyColumn(name = "name", nullable = false)
@Column(name = "value", length = 65535)
@CollectionTable(name = "oc_series_property", uniqueConstraints = {
@UniqueConstraint(name = "UNQ_series_properties", columnNames = {"series", "organization", "name"})
}, joinColumns = {
@JoinColumn(name = "series", referencedColumnName = "id", nullable = false),
@JoinColumn(name = "organization", referencedColumnName = "organization", nullable = false) })
protected Map properties;
@ElementCollection
@MapKeyColumn(name = "type", length = 128, nullable = false)
@Column(name = "data")
@CollectionTable(name = "oc_series_elements", uniqueConstraints = {
@UniqueConstraint(name = "UNQ_series_elements", columnNames = {"series", "organization", "type"})
}, joinColumns = {
@JoinColumn(name = "series", referencedColumnName = "id", nullable = false),
@JoinColumn(name = "organization", referencedColumnName = "organization", nullable = false) })
protected Map elements;
/**
* Default constructor without any import.
*/
public SeriesEntity() {
}
/**
* Returns series ID.
*
* @return series ID
*/
public String getSeriesId() {
return seriesId;
}
/**
* Sets series ID. ID length limit is 128 characters.
*
* @param seriesId
*/
public void setSeriesId(String seriesId) {
if (seriesId == null) {
throw new IllegalArgumentException("Series id can't be null");
}
if (seriesId.length() > 128) {
throw new IllegalArgumentException("Series id can't be longer than 128 characters");
}
this.seriesId = seriesId;
}
/**
* Returns serialized Dublin core.
*
* @return serialized Dublin core
*/
public String getDublinCoreXML() {
return dublinCoreXML;
}
/**
* Sets serialized Dublin core.
*
* @param dublinCoreXML
* serialized Dublin core
*/
public void setSeries(String dublinCoreXML) {
this.dublinCoreXML = dublinCoreXML;
}
/**
* Returns serialized access control
*
* @return serialized access control
*/
public String getAccessControl() {
return accessControl;
}
/**
* Sets serialized access control.
*
* @param accessControl
* serialized access control
*/
public void setAccessControl(String accessControl) {
this.accessControl = accessControl;
}
/**
* @return the organization
*/
public String getOrganization() {
return organization;
}
/**
* @param organization
* the organization to set
*/
public void setOrganization(String organization) {
this.organization = organization;
}
public Date getModifiedDate() {
return this.modifiedDate;
}
public void setModifiedDate(Date date) {
this.modifiedDate = date;
}
public Date getDeletionDate() {
return this.deletionDate;
}
public void setDeletionDate(Date date) {
this.deletionDate = date;
}
public boolean isDeleted() {
return this.deletionDate != null;
}
public Map getProperties() {
return new TreeMap(properties);
}
public void setProperties(Map properties) {
this.properties = properties;
}
public Map getElements() {
return Collections.unmodifiableMap(elements);
}
public void addElement(String type, byte[] data) {
elements.put(type, data);
}
public void removeElement(String type) {
elements.remove(type);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy