001package com.hfg.sql.jdbc; 002 003 004import java.sql.SQLException; 005import java.sql.Statement; 006 007//------------------------------------------------------------------------------ 008/** 009 Options for a JDBC SQL statement. 010 <div> 011 @author J. Alex Taylor, hairyfatguy.com 012 </div> 013 */ 014//------------------------------------------------------------------------------ 015// com.hfg XML/HTML Coding Library 016// 017// This library is free software; you can redistribute it and/or 018// modify it under the terms of the GNU Lesser General Public 019// License as published by the Free Software Foundation; either 020// version 2.1 of the License, or (at your option) any later version. 021// 022// This library is distributed in the hope that it will be useful, 023// but WITHOUT ANY WARRANTY; without even the implied warranty of 024// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 025// Lesser General Public License for more details. 026// 027// You should have received a copy of the GNU Lesser General Public 028// License along with this library; if not, write to the Free Software 029// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 030// 031// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 032// jataylor@hairyfatguy.com 033//------------------------------------------------------------------------------ 034 035public class SQLStatementOptions 036{ 037 private Integer mMaxFieldSize; 038 private Integer mMaxRows; 039 private Boolean mEscapeProcessing; 040 private Integer mQueryTimeoutInSec; 041 private Integer mFetchDirection; 042 private Integer mFetchSize; 043 private Boolean mPoolable; 044 private Boolean mCloseOnCompletion; 045 046 //--------------------------------------------------------------------------- 047 public Integer getMaxFieldSize() 048 { 049 return mMaxFieldSize; 050 } 051 052 //--------------------------------------------------------------------------- 053 public SQLStatementOptions setMaxFieldSize(Integer inValue) 054 { 055 mMaxFieldSize = inValue; 056 return this; 057 } 058 059 060 //--------------------------------------------------------------------------- 061 public Integer getMaxRows() 062 { 063 return mMaxRows; 064 } 065 066 //--------------------------------------------------------------------------- 067 public SQLStatementOptions setMaxRows(Integer inValue) 068 { 069 mMaxRows = inValue; 070 return this; 071 } 072 073 074 //--------------------------------------------------------------------------- 075 public Boolean getEscapeProcessing() 076 { 077 return mEscapeProcessing; 078 } 079 080 //--------------------------------------------------------------------------- 081 public SQLStatementOptions setEscapeProcessing(Boolean inValue) 082 { 083 mEscapeProcessing = inValue; 084 return this; 085 } 086 087 088 //--------------------------------------------------------------------------- 089 public Integer getQueryTimeout() 090 { 091 return mQueryTimeoutInSec; 092 } 093 094 //--------------------------------------------------------------------------- 095 public SQLStatementOptions setQueryTimeout(Integer inValueInSec) 096 { 097 mQueryTimeoutInSec = inValueInSec; 098 return this; 099 } 100 101 102 //--------------------------------------------------------------------------- 103 public SQLStatementOptions setFetchDirection(Integer inValue) 104 { 105 mFetchDirection = inValue; 106 return this; 107 } 108 109 //--------------------------------------------------------------------------- 110 public Integer getFetchDirection() 111 { 112 return mFetchDirection; 113 } 114 115 116 //--------------------------------------------------------------------------- 117 public SQLStatementOptions setFetchSize(Integer inValue) 118 { 119 mFetchSize = inValue; 120 return this; 121 } 122 123 //--------------------------------------------------------------------------- 124 public Integer getFetchSize() 125 { 126 return mFetchSize; 127 } 128 129 130 //--------------------------------------------------------------------------- 131 public SQLStatementOptions setPoolable(Boolean inValue) 132 { 133 mPoolable = inValue; 134 return this; 135 } 136 137 //--------------------------------------------------------------------------- 138 public Boolean isPoolable() 139 { 140 return mPoolable; 141 } 142 143 144 //--------------------------------------------------------------------------- 145 public SQLStatementOptions closeOnCompletion() 146 { 147 mCloseOnCompletion = true; 148 return this; 149 } 150 151 //--------------------------------------------------------------------------- 152 public Boolean isCloseOnCompletion() 153 { 154 return mCloseOnCompletion; 155 } 156 157 //--------------------------------------------------------------------------- 158 public void configureStmt(Statement inStatement) 159 throws SQLException 160 { 161 if (getMaxFieldSize() != null) 162 { 163 inStatement.setMaxFieldSize(getMaxFieldSize()); 164 } 165 166 if (getMaxRows() != null) 167 { 168 inStatement.setMaxRows(getMaxRows()); 169 } 170 171 if (getEscapeProcessing() != null) 172 { 173 inStatement.setEscapeProcessing(getEscapeProcessing()); 174 } 175 176 if (getQueryTimeout() != null) 177 { 178 inStatement.setQueryTimeout(getQueryTimeout()); 179 } 180 181 if (getFetchDirection() != null) 182 { 183 inStatement.setFetchDirection(getFetchDirection()); 184 } 185 186 if (getFetchSize() != null) 187 { 188 inStatement.setFetchSize(getFetchSize()); 189 } 190 191 if (isPoolable() != null) 192 { 193 inStatement.setPoolable(isPoolable()); 194 } 195 196 if (isCloseOnCompletion() != null 197 && isCloseOnCompletion()) 198 { 199 inStatement.closeOnCompletion(); 200 } 201 } 202} 203