View Javadoc
1 /*** 2 * Copyright (c) 2002, Reuters America Inc. All rights reserved.<p> 3 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following 4 * conditions are met:<p> 5 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer 7 * in the documentation and/or other materials provided with the distribution. Neither the name of Reuters America Inc. nor the 8 * names of its contributors may be used to endorse or promote products derived from this software without specific prior written 9 * permission.<p> 10 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 11 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 12 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 13 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 14 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 15 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<p> 16 */ 17 18 package com.reuters.rc.db.adb; 19 20 import com.reuters.rc.db.*; 21 import com.tibco.tibrv.*; 22 23 24 /*** 25 * This class represents a request statement sent to ADB. Each instance of this class 26 * is immutable - instances can be freely shared among threads. 27 * @see AdbRequest 28 * @author Jawaid Hakim. 29 */ 30 public class AdbRequestStmt implements DbRequestStmt 31 { 32 /*** 33 * Constructor. 34 * @param sql The SQL statement to execute on the ADB. 35 */ 36 public AdbRequestStmt(String sql) 37 { 38 init(sql, DEFAULT_MAXROWS); 39 } 40 41 /*** 42 * Constructor. 43 * @param sql The SQL statement to execute on the ADB. 44 * @param maxRows Maximum number of result rows returned from request. 45 * @see #getMaxRows() 46 * @see AdbRequestBind 47 */ 48 public AdbRequestStmt(String sql, int maxRows) 49 { 50 init(sql, maxRows); 51 } 52 53 /*** 54 * Constructor. A reference to the parameter is stored so be careful about 55 * modifying the data. 56 * @param sql The SQL statement to execute on the ADB. 57 * @param bind Bind data. 58 * @see AdbRequestBind 59 */ 60 public AdbRequestStmt(String sql, DbRequestBind bind) 61 { 62 init(sql, bind, DEFAULT_MAXROWS); 63 } 64 65 /*** 66 * Constructor. 67 * @param sql The SQL statement to execute on the ADB. 68 * @param bind Bind data. 69 * @param maxRows Maximum number of result rows returned from request. 70 * @see #getMaxRows() 71 * @see AdbRequestBind 72 */ 73 public AdbRequestStmt(String sql, DbRequestBind bind, int maxRows) 74 { 75 init(sql, bind, maxRows); 76 } 77 78 /*** 79 * Constructor. A reference to the parameter is stored so be careful about 80 * modifying the data. 81 * @param sql The SQL statement to execute on the ADB. 82 * @param binds Bind data. 83 * @see AdbRequestBind 84 */ 85 public AdbRequestStmt(String sql, DbRequestBind[] binds) 86 { 87 init(sql, binds, DEFAULT_MAXROWS); 88 } 89 90 /*** 91 * Constructor. A reference to the parameter is stored so be careful about 92 * modifying the data. 93 * @param sql The SQL statement to execute on the ADB. 94 * @param binds Bind data. 95 * @param maxRows Maximum number of result rows returned from request. 96 * @see #getMaxRows() 97 * @see AdbRequestBind 98 */ 99 public AdbRequestStmt(String sql, DbRequestBind[] binds, int maxRows) 100 { 101 init(sql, binds, maxRows); 102 } 103 104 /*** 105 * Initialize. 106 * @param sql SQL statement to execute on the ADB. 107 * @param maxRows Maximum number of result rows returned from request. 108 */ 109 private void init(String sql, int maxRows) 110 { 111 sql_ = sql; 112 maxRows_ = maxRows; 113 } 114 115 /*** 116 * Initialize. 117 * @param sql SQL statement to execute on the ADB. 118 * @param bind Bind data. 119 * @param maxRows Maximum number of result rows returned from request. 120 */ 121 private void init(String sql, DbRequestBind bind, int maxRows) 122 { 123 if (bind != null) 124 { 125 AdbRequestBind[] binds = new AdbRequestBind[1]; 126 binds_[0] = bind; 127 init(sql, binds, maxRows); 128 } 129 else 130 { 131 init(sql, maxRows); 132 } 133 } 134 135 /*** 136 * Initialize. 137 * @param sql SQL statement to execute on the ADB. 138 * @param binds Bind data. 139 * @param maxRows Maximum number of result rows returned from request. 140 */ 141 private void init(String sql, DbRequestBind[] binds, int maxRows) 142 { 143 sql_ = sql; 144 binds_ = binds; 145 maxRows_ = maxRows; 146 } 147 148 /*** 149 * Get the sql statement. 150 * @return Sql statement. 151 */ 152 public final String getSql() 153 { 154 return sql_; 155 } 156 157 /*** 158 * Get the maximum number of result rows returned from request. The 159 * default maxRows is set to DEFAULT_MAXROWS which implies no constraints 160 * on the result set size. 161 * @return maxRows Maximum number of result rows returned from request. 162 * @see AdbRequest#sendRequest(TibrvTransport, String) 163 */ 164 public final int getMaxRows() 165 { 166 return maxRows_; 167 } 168 169 /*** 170 * Build request message. 171 * @return Request message. 172 * @see com.tibco.tibrv.TibrvMsg 173 */ 174 public final TibrvMsg getStmt() throws AdbBusinessException, AdbSystemException 175 { 176 try 177 { 178 String sql = getSql(); 179 if (sql == null) 180 throw new AdbBusinessException("NULL SQL"); 181 182 // Create request statement 183 TibrvMsg stmt = new TibrvMsg(); 184 185 stmt.add(ADB_SQL, sql); 186 187 if (getMaxRows() != DEFAULT_MAXROWS) 188 stmt.add(ADB_MAXROWS, getMaxRows()); 189 190 if (binds_ != null) 191 { 192 for (int i = 0; i < binds_.length; ++i) 193 stmt.add(ADB_BIND, binds_[i].getBind()); 194 } 195 return stmt; 196 } 197 catch (TibrvException ex) 198 { 199 throw new AdbSystemException(ex); 200 } 201 catch (DbBaseException ex) 202 { 203 throw new AdbSystemException(ex); 204 } 205 } 206 207 /*** 208 * No limit on number of rows returned. 209 */ 210 private static final int DEFAULT_MAXROWS = -1; 211 212 /*** 213 * Name of nested SQL statement message. 214 */ 215 private static final String ADB_STMT = "stmt"; 216 217 /*** 218 * Name of message field containing the SQL statement. 219 */ 220 private static final String ADB_SQL = "sql"; 221 222 /*** 223 * Name of message field containing the maxrows option. 224 */ 225 private static final String ADB_MAXROWS = "maxrows"; 226 227 /*** 228 * Name of message field containing the maxrows option. 229 */ 230 private static final String ADB_BIND = "bind"; 231 232 /*** 233 * SQL statement value to send with request. 234 */ 235 private String sql_; 236 237 /*** 238 * Maxrows value. 239 */ 240 private int maxRows_; 241 242 /*** 243 * Bind data. 244 */ 245 private DbRequestBind[] binds_; 246 }

This page was automatically generated by Maven