All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fryske_akademy.ejb.CrudReadService Maven / Gradle / Ivy

The newest version!
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.fryske_akademy.ejb;

/*-
 * #%L
 * ejbCrudApi
 * %%
 * Copyright (C) 2018 Fryske Akademy
 * %%
 * 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.
 * #L%
 */
import org.fryske_akademy.jpa.Param;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

/**
 * Generic interface for read operations on entities.
 *
 * @see SORTORDER
 * @see Param
 * @author eduard
 */
public interface CrudReadService extends Serializable {

    public enum SORTORDER implements Serializable {
        DESC, ASC, NONE;

        public static Map order(String key, SORTORDER order) {
            return new Builder().add(key, order).build();
        }

        public static class Builder {

            private final Map sort = new HashMap<>(2);

            public Builder add(String key, SORTORDER o) {
                sort.put(key, o);
                return this;
            }

            public Map build() {
                return sort;
            }
        }
    }

    /**
     * Return a default page size when no max is given, negative value means no limit
     *
     * @return
     */
    public int getDefaultPageSize();

    public  T find(Serializable id, Class type);

    public  List findAll(Class type);

    public  Stream streamAll(Class type);

    /**
     * 
     * @param 
     * @param first defaults to 0
     * @param max defaults to {@link #getDefaultPageSize() }
     * @param sort
     * @param params
     * @param type
     * @return 
     */
    public  List findDynamic(Integer first, Integer max, Map sort, List params, Class type);

    /**
     * 
     * @param 
     * @param first defaults to 0
     * @param max defaults to {@link #getDefaultPageSize() }
     * @param sort
     * @param params
     * @param type
     * @return 
     */
    public  Stream streamDynamic(Integer first, Integer max, Map sort, List params, Class type);

    /**
     * Call this using the same parameters as in findDynamic to get to know the total number of results
     * @param params
     * @param type
     * @return 
     */
    public int countDynamic(List params, Class type);

    /**
     * 
     * @param 
     * @param namedQuery
     * @param params
     * @param first defaults to 0
     * @param max defaults to {@link #getDefaultPageSize() }
     * @param type
     * @return 
     */
    public  List find(String namedQuery, List params, Integer first, Integer max, Class type);

    /**
     * 
     * @param 
     * @param namedQuery
     * @param params
     * @param first defaults to 0
     * @param max defaults to {@link #getDefaultPageSize() }
     * @param type
     * @return 
     */
    public  Stream stream(String namedQuery, List params, Integer first, Integer max, Class type);

    /**
     * 
     * @param 
     * @param namedNativeQuery
     * @param params
     * @param first defaults to 0
     * @param max defaults to {@link #getDefaultPageSize() }
     * @param type
     * @return 
     */
    public  List findNative(String namedNativeQuery, List params, Integer first, Integer max, Class type);

    /**
     * 
     * @param 
     * @param namedNativeQuery
     * @param params
     * @param first defaults to 0
     * @param max defaults to {@link #getDefaultPageSize() }
     * @param type
     * @return 
     */
    public  Stream streamNative(String namedNativeQuery, List params, Integer first, Integer max, Class type);

    /**
     * Call this using the same parameters as in {@link #find(java.lang.String, java.util.List, java.lang.Integer, java.lang.Integer, java.lang.Class) }
     * to get to know the total number of results
     *
     * @param namedQuery
     * @param params
     * @return
     */
    public int count(String namedQuery, List params);

    /**
     * return one result or null, multiple results throws an exception
     *
     * @param 
     * @param namedQuery
     * @param params
     * @param type
     * @return
     */
    public  T findOne(String namedQuery, List params, Class type);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy