001/* 002 * Copyright 2020 Global Biodiversity Information Facility (GBIF) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.gbif.api.service.common; 017 018import org.gbif.api.model.common.paging.Pageable; 019import org.gbif.api.model.common.paging.PagingResponse; 020 021import javax.annotation.Nullable; 022 023/** 024 * A generic CRUD service interface for any writable entity. 025 * 026 * @param <T> The complete entity class 027 * @param <W> The writable entity class, can be the same as T 028 * @param <K> The primary key class of the entity 029 */ 030public interface CrudService<T, W, K> { 031 032 /** 033 * Persists a new entity. 034 * 035 * @param entity to create. 036 * 037 * @return The persisted entity. 038 */ 039 K create(W entity); 040 041 /** 042 * Deletes the entity. 043 * 044 * @param key The entity key to delete. 045 */ 046 void delete(K key); 047 048 /** 049 * Get an entity by its unique key. 050 * 051 * @return the entity or null if not existing. 052 */ 053 @Nullable 054 T get(K key); 055 056 /** 057 * Lists all entity. 058 * 059 * @param page to enable paging. 060 * 061 * @return The pagable list of entities. 062 */ 063 PagingResponse<T> list(@Nullable Pageable page); 064 065 /** 066 * Updates the entity. 067 * 068 * @param entity to update 069 */ 070 void update(W entity); 071 072}