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

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

/*
 * 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 java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 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;
            }
        }
    }

    public  T find(Serializable id, Class type);

    public  List findAll(Class type);

    /**
     * 
     * @param 
     * @param first
     * @param pageSize
     * @param sort
     * @param params
     * @param type
     * @return 
     */
    public  List findDynamic(Integer first, Integer pageSize, Map sort, List params, Class type);

    public int countDynamic(List params, Class type);

    public  List find(String namedQuery, List params, Integer first, Integer max, Class type);

    public  List findNative(String namedNativeQuery, List params, Integer first, Integer max, Class type);

    /**
     * Use in conjunction with {@link #find(java.lang.String, java.util.List, java.lang.Integer, java.lang.Integer, java.lang.Class) } or
     * {@link #findNative(java.lang.String, java.util.List, java.lang.Integer, java.lang.Integer, java.lang.Class) }.
     * @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