DatabaseFile.java

/*
 * Copyright 2022 Global Crop Diversity Trust
 *
 * 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 org.genesys.filerepository.model;

import lombok.Getter;
import lombok.Setter;
import org.genesys.blocks.model.AuditedVersionedModel;
import org.genesys.filerepository.service.impl.DatabaseStorageServiceImpl;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 * {@code DatabaseFile} is used by {@link DatabaseStorageServiceImpl} to keeps bytes in the database.
 */
@Entity
@Table(name = "database_file", 
	indexes = {@Index (columnList = "path", unique = true)},
	uniqueConstraints = { @UniqueConstraint(columnNames = { "path" }) })
@Getter
@Setter
public class DatabaseFile extends AuditedVersionedModel {

	private static final long serialVersionUID = -4035237121994619715L;

	/** Virtual path in the database repository. */
	@Column(length = 250, nullable = false)
	private String path;

	/** Data bytes. */
	@Column(nullable = false)
	private byte[] data;

	@Override
	public boolean canEqual(Object other) {
		return other instanceof DatabaseFile;
	}
}