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.commands; 021 022import net.sf.jkniv.exception.HandleableException; 023 024/** 025 * Command to be executed in database like 026 * {@code Select}, {@code Update}, {@code Delete}, 027 * {@code Insert}, {@code Stored Procedure}... 028 * 029 * @author Alisson Gomes 030 * @since 0.6.0 031 */ 032public interface Command 033{ 034 /** 035 * Configure the handler exception for the command 036 * @param handlerException rules to handler the all exceptions 037 * @return a reference to this object. 038 */ 039 Command with(HandleableException handlerException); 040 041 /** 042 * Configure the life-cycle of command 043 * @param commandHandler the life-cycle of command handler 044 * @return a reference to this object. 045 */ 046 Command with(CommandHandler commandHandler); 047 048 /** 049 * The statement to run this command 050 * @param <T> Type responsible to execute the statement into database. 051 * For example: {@code Statement} for JDBC or Cassandra, {@code EntityManager} for JPA, 052 * {@code bucket} for Couchbase etc 053 * @param stmt a statement implementation to run the command. 054 * @return a reference to this object. 055 */ 056 <T> Command with(T stmt); 057 058 /** 059 * Execute the database statement could be a {@code Command} or a {@code Query} 060 * @param <T> Generic type of return, example: rows affected by a command or list of objects. 061 * @return the result of the statement execution 062 */ 063 <T> T execute(); 064}