1 24 25 package org.objectweb.cjdbc.common.sql; 26 27 import java.io.IOException ; 28 import java.sql.SQLException ; 29 30 import org.objectweb.cjdbc.common.sql.schema.DatabaseSchema; 31 import org.objectweb.cjdbc.common.stream.CJDBCInputStream; 32 import org.objectweb.cjdbc.common.stream.CJDBCOutputStream; 33 34 46 public class StoredProcedure extends AbstractRequest 47 { 48 private static final long serialVersionUID = 8425933724676827694L; 49 50 51 private transient boolean blocking = true; 52 53 private transient String procedureName = null; 54 private final boolean returnsRS; 56 57 68 public StoredProcedure(String sqlQuery, boolean escapeProcessing, 69 int timeout, String lineSeparator, boolean isRead) 70 { 71 super(sqlQuery, escapeProcessing, timeout, lineSeparator, 72 RequestType.STORED_PROCEDURE); 73 this.returnsRS = isRead; 74 } 75 76 79 public StoredProcedure(CJDBCInputStream in) throws IOException 80 { 81 super(in, RequestType.STORED_PROCEDURE); 82 this.returnsRS = in.readBoolean(); 83 if (returnsRS) 84 receiveResultSetParams(in); 85 86 } 87 88 92 public void sendToStream(CJDBCOutputStream out, boolean needSkeleton) 93 throws IOException 94 { 95 super.sendToStream(out, needSkeleton); 96 out.writeBoolean(returnsRS); 97 if (returnsRS) 98 sendResultSetParams(out); 99 } 100 101 105 public boolean needsMacroProcessing() 106 { 107 return true; 108 } 109 110 113 public boolean returnsResultSet() 114 { 115 return returnsRS; 116 } 117 118 123 public String getProcedureName() 124 { 125 if (procedureName == null) 126 try 127 { 128 parse(null, 0, true); 129 } 130 catch (SQLException e) 131 { 132 return null; 133 } 134 return procedureName; 135 } 136 137 142 public boolean mightBlock() 143 { 144 return blocking; 145 } 146 147 152 public void setBlocking(boolean blocking) 153 { 154 this.blocking = blocking; 155 } 156 157 163 public void parse(DatabaseSchema schema, int granularity, 164 boolean isCaseSensitive) throws SQLException 165 { 166 sqlQuery = sqlQuery.trim(); 167 if (sqlQuery.length() < 6) throw new SQLException ("Malformed stored procedure call '" + sqlQuery 169 + "'"); 170 171 int parenthesis = sqlQuery.indexOf('('); 172 if (parenthesis == -1) 173 procedureName = sqlQuery.substring(5); else 175 procedureName = sqlQuery.substring(5, parenthesis); procedureName = procedureName.trim(); 178 } 179 180 187 public void cloneParsing(AbstractRequest request) 188 { 189 throw new RuntimeException ( 190 "Unable to clone the parsing of a stored procedure call"); 191 } 192 193 } | Popular Tags |