001: //jTDS JDBC Driver for Microsoft SQL Server and Sybase
002: //Copyright (C) 2004 The jTDS Project
003: //
004: //This library is free software; you can redistribute it and/or
005: //modify it under the terms of the GNU Lesser General Public
006: //License as published by the Free Software Foundation; either
007: //version 2.1 of the License, or (at your option) any later version.
008: //
009: //This library is distributed in the hope that it will be useful,
010: //but WITHOUT ANY WARRANTY; without even the implied warranty of
011: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: //Lesser General Public License for more details.
013: //
014: //You should have received a copy of the GNU Lesser General Public
015: //License along with this library; if not, write to the Free Software
016: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: //
018: package net.sourceforge.jtds.jdbc;
019:
020: /**
021: * Stores information about a cached stored procedure or statement handle.
022: *
023: * @version $Id: ProcEntry.java,v 1.1 2005/05/25 09:24:03 alin_sinpalean Exp $
024: */
025: public class ProcEntry {
026: /** The entry references a stored procedure. */
027: public static final int PROCEDURE = 1;
028: /** The entry references a prepared statement handle. */
029: public static final int PREPARE = 2;
030: /** The entry references a prepared cursor handle. */
031: public static final int CURSOR = 3;
032: /** The entry references a failed prepare. */
033: public static final int PREP_FAILED = 4;
034:
035: /** Stored procedure name or statement handle. */
036: private String name;
037: /** Column meta data (Sybase only). */
038: private ColInfo[] colMetaData;
039: /** Parameter meta data (Sybase only). */
040: private ParamInfo[] paramMetaData;
041: /** Type of statement referenced by this entry. */
042: private int type;
043: /** Usage count for this statement. */
044: private int refCount;
045:
046: /**
047: * Retrieves the procedure or handle name.
048: *
049: * @return the statement or handle name as a <code>String</code>
050: */
051: public final String toString() {
052: return name;
053: }
054:
055: /**
056: * Sets the procedure name.
057: *
058: * @param name the procedure name
059: */
060: public void setName(String name) {
061: this .name = name;
062: }
063:
064: /**
065: * Sets the prepared statement handle.
066: *
067: * @param handle the <code>sp_prepare</code> handle value
068: */
069: public void setHandle(int handle) {
070: this .name = Integer.toString(handle);
071: }
072:
073: /**
074: * Retrieves the column meta data array.
075: *
076: * @return the column meta data as <code>ColInfo[]</code>
077: */
078: public ColInfo[] getColMetaData() {
079: return this .colMetaData;
080: }
081:
082: /**
083: * Sets the column meta data.
084: *
085: * @param colMetaData the column meta data
086: */
087: public void setColMetaData(ColInfo[] colMetaData) {
088: this .colMetaData = colMetaData;
089: }
090:
091: /**
092: * Retrieves the parameter meta data array.
093: *
094: * @return the parameter meta data as a <code>ParamInfo[]</code>
095: */
096: public ParamInfo[] getParamMetaData() {
097: return this .paramMetaData;
098: }
099:
100: /**
101: * Sets the parameter meta data.
102: *
103: * @param paramMetaData the parameter meta data array
104: */
105: public void setParamMetaData(ParamInfo[] paramMetaData) {
106: this .paramMetaData = paramMetaData;
107: }
108:
109: /**
110: * Sets the statement implementation type.
111: *
112: * @param type the type code (one of PROCEDURE,PREPARE,CURSOR)
113: */
114: public void setType(int type) {
115: this .type = type;
116: }
117:
118: /**
119: * Retrieves the statement implementation type.
120: *
121: * @return the statement type as an <code>int</code>
122: */
123: public int getType() {
124: return this .type;
125: }
126:
127: /**
128: * Retrieves the SQL to drop this statement.
129: */
130: public void appendDropSQL(StringBuffer sql) {
131: switch (type) {
132: case PROCEDURE:
133: sql.append("DROP PROC ").append(name).append('\n');
134: break;
135: case PREPARE:
136: sql.append("EXEC sp_unprepare ").append(name).append('\n');
137: break;
138: case CURSOR:
139: sql.append("EXEC sp_cursorunprepare ").append(name).append(
140: '\n');
141: break;
142: case PREP_FAILED:
143: break;
144: default:
145: throw new IllegalStateException(
146: "Invalid cached statement type " + type);
147: }
148: }
149:
150: /**
151: * Increments the usage count.
152: */
153: public void addRef() {
154: refCount++;
155: }
156:
157: /**
158: * Decrements the usage count.
159: */
160: public void release() {
161: if (refCount > 0) {
162: refCount--;
163: }
164: }
165:
166: /**
167: * Retreives the usage count.
168: *
169: * @return the usage count as an <code>int</code>
170: */
171: public int getRefCount() {
172: return refCount;
173: }
174: }
|