001/* 002 * JKNIV, whinstone one contract to access your database. 003 * 004 * Copyright (C) 2017, the original author or authors. 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License. 010 * 011 * This library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software Foundation, Inc., 018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 019 */ 020package net.sf.jkniv.whinstone.statement; 021 022import java.sql.ResultSet; 023import java.util.List; 024 025import net.sf.jkniv.whinstone.Param; 026import net.sf.jkniv.whinstone.Repository; 027import net.sf.jkniv.whinstone.ResultRow; 028 029/** 030 * Adapter for Statements {@link java.sql.Statement}, {@link java.sql.PreparedStatement}, 031 * {@link java.sql.CallableStatement} or {@code javax.persistence.Query} 032 * 033 * @param <T> type of object to return by {@link Repository} 034 * @param <R> The driver result of a query like {@link ResultSet} 035 * 036 * @author Alisson Gomes 037 * @since 0.6.0 038 */ 039public interface StatementAdapter<T, R> 040{ 041 /** 042 * Bind an argument to a named parameter. 043 * @param name of parameter 044 * @param value of parameter 045 * @return instance of this object 046 */ 047 StatementAdapter<T,R> bind(String name, Object value); 048 049 /** 050 * Bind an argument to a position parameter. 051 * @param value of parameter 052 * @return instance of this object 053 */ 054 StatementAdapter<T, R> bind(Param value); 055 056 /** 057 * Bind the varargs parameters to statement 058 * @param values of parameters as arbitrary number 059 * @return instance of this object 060 */ 061 StatementAdapter<T, R> bind(Param... values); 062 063 /** 064 * result row 065 * @param resultRow how to process the rows 066 * @return instance of this object 067 */ 068 StatementAdapter<T, R> with(ResultRow<T, R> resultRow); 069 070 StatementAdapter<T, R> with(AutoKey generateKey); 071 072 /** 073 * bind the keys generated 074 */ 075 void bindKey(); 076 077 List<T> rows(); 078 079 //TODO implements batch operation 080 //void batch(); 081 082 int execute(); 083 084 /** 085 * reset the internal index position parameter to zero. 086 * @return return current index position before reset 087 */ 088 int reset(); 089 090 void close(); 091 092 /** 093 * Set the number of rows that should be fetched when the statement hit the database. 094 * @param rows the number of rows to fetch 095 */ 096 void setFetchSize(int rows); 097}