Commit 397875d4 authored by Maxym Borodenko's avatar Maxym Borodenko
Browse files

WIP: RepositoryGalleryImage entity for repository_gallery_image

parent 5381c257
/*
* Copyright 2020 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 javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MapsId;
import javax.persistence.Table;
@Entity
@Table(name = "repository_gallery_image")
public class RepositoryGalleryImage {
@EmbeddedId
private RepositoryGalleryImageKey id;
@ManyToOne
@MapsId("galleryId")
@JoinColumn(name = "galleryId")
private ImageGallery imageGallery;
@ManyToOne
@MapsId("imageId")
@JoinColumn(name = "imageId")
private RepositoryImage repositoryImage;
private int position;
public RepositoryGalleryImageKey getId() {
return id;
}
public void setId(RepositoryGalleryImageKey id) {
this.id = id;
}
public ImageGallery getImageGallery() {
return imageGallery;
}
public void setImageGallery(ImageGallery imageGallery) {
this.imageGallery = imageGallery;
}
public RepositoryImage getRepositoryImage() {
return repositoryImage;
}
public void setRepositoryImage(RepositoryImage repositoryImage) {
this.repositoryImage = repositoryImage;
}
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
}
/*
* Copyright 2020 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 javax.persistence.Column;
import javax.persistence.Embeddable;
import java.io.Serializable;
import java.util.Objects;
@Embeddable
public class RepositoryGalleryImageKey implements Serializable {
@Column(name = "galleryId")
private Long galleryId;
@Column(name = "imageId")
private Long imageId;
public Long getGalleryId() {
return galleryId;
}
public void setGalleryId(Long galleryId) {
this.galleryId = galleryId;
}
public Long getImageId() {
return imageId;
}
public void setImageId(Long imageId) {
this.imageId = imageId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof RepositoryGalleryImageKey)) return false;
RepositoryGalleryImageKey that = (RepositoryGalleryImageKey) o;
if (!Objects.equals(galleryId, that.galleryId)) return false;
return Objects.equals(imageId, that.imageId);
}
@Override
public int hashCode() {
int result = galleryId != null ? galleryId.hashCode() : 0;
result = 31 * result + (imageId != null ? imageId.hashCode() : 0);
return result;
}
}
/*
* Copyright 2020 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.persistence;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryGalleryImage;
import org.genesys.filerepository.model.RepositoryGalleryImageKey;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import java.util.List;
/**
* The Interface RepositoryGalleryImagePersistence.
*/
public interface RepositoryGalleryImagePersistence extends JpaRepository<RepositoryGalleryImage, Long>, QuerydslPredicateExecutor<RepositoryGalleryImage> {
@Query("select IGI.id from RepositoryGalleryImage IGI where IGI.imageGallery = :gallery")
List<RepositoryGalleryImageKey> listIdsByImageGallery(@Param("gallery") ImageGallery gallery);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment