org.apache.deltaspike.data.api.EntityRepository Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.deltaspike.data.api;
import java.io.Serializable;
import java.util.List;
import java.util.Optional;
import javax.persistence.metamodel.SingularAttribute;
/**
* Base Repository interface. All methods are implemented by the CDI extension.
*
* @param Entity type.
* @param Primary key type.
*/
public interface EntityRepository extends EntityPersistenceRepository,
EntityCountRepository
{
/**
* Entity lookup by primary key. Convenicence method around
* {@link javax.persistence.EntityManager#find(Class, Object)}.
* @param primaryKey DB primary key.
* @return Entity identified by primary or null if it does not exist.
*/
E findBy(PK primaryKey);
/**
* Entity lookup by primary key. Convenicence method around
* {@link javax.persistence.EntityManager#find(Class, Object)}.
* @param primaryKey DB primary key.
* @return Entity identified by primary or null if it does not exist, wrapped by Optional.
*/
Optional findOptionalBy(PK primaryKey);
/**
* Lookup all existing entities of entity class {@code }.
* @return List of entities, empty if none found.
*/
List findAll();
/**
* Lookup a range of existing entities of entity class {@code } with support for pagination.
* @param start The starting position.
* @param max The maximum number of results to return
* @return List of entities, empty if none found.
*/
List findAll(int start, int max);
/**
* Query by example - for a given object and a specific set of properties.
* @param example Sample entity. Query all like.
* @param attributes Which attributes to consider for the query.
* @return List of entities matching the example, or empty if none found.
*/
List findBy(E example, SingularAttribute... attributes);
/**
* Query by example - for a given object and a specific set of properties with support for pagination.
* @param example Sample entity. Query all like.
* @param start The starting position.
* @param max The maximum number of results to return
* @param attributes Which attributes to consider for the query.
* @return List of entities matching the example, or empty if none found.
*/
List findBy(E example, int start, int max, SingularAttribute... attributes);
/**
* Query by example - for a given object and a specific set of properties using a like operator for Strings.
* @param example Sample entity. Query all like.
* @param attributes Which attributes to consider for the query.
* @return List of entities matching the example, or empty if none found.
*/
List findByLike(E example, SingularAttribute... attributes);
/**
* Query by example - for a given object and a specific set of properties
* using a like operator for Strings with support for pagination.
* @param example Sample entity. Query all like.
* @param start The starting position.
* @param max The maximum number of results to return
* @param attributes Which attributes to consider for the query.
* @return List of entities matching the example, or empty if none found.
*/
List findByLike(E example, int start, int max, SingularAttribute... attributes);
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy