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

win.doyto.query.service.QueryService Maven / Gradle / Ivy

There is a newer version: 0.2.2.1-RELEASE
Show newest version
package win.doyto.query.service;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * QueryService
 *
 * @author f0rb
 */
public interface QueryService {

    List query(Q query);

    long count(Q query);

    default E get(Q query) {
        return CollectionUtil.first(query(query));
    }

    default  List query(Q query, Function transfer) {
        return query(query).stream().map(transfer).collect(Collectors.toList());
    }

    default  PageList page(Q query, Function transfer) {
        return new PageList<>(query(query, transfer), count(query));
    }

     List queryColumns(Q query, Class clazz, String... columns);

     List queryColumn(Q query, Class clazz, String column);

    default  V getColumns(Q query, Class clazz, String... columns) {
        return CollectionUtil.first(queryColumns(query, clazz, columns));
    }

    default  V getColumn(Q query, Class clazz, String column) {
        return CollectionUtil.first(queryColumns(query, clazz, column));
    }

}