⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drdastatement.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	 * set param  DRDAType	 *	 * @param index - starting with 1	 * @param type	 */	protected  void setParamDRDAType(int index, byte type)	{		cliParamDrdaTypes.addElement(new Byte(type));			}	/**	 * returns drda length of parameter as sent by client.	 * @param index	 * @return data length	 */	protected int getParamLen(int index)	{		return ((Integer) cliParamLens.elementAt(index -1)).intValue();	}	/**	 *  get parameter precision or DB2 max (31)	 *	 *  @param index parameter index starting with 1	 *	 *  @return  precision	 */	protected int getParamPrecision(int index) throws SQLException	{		if (ps != null && ps instanceof CallableStatement)		{			EmbedParameterSetMetaData pmeta = 	getParameterMetaData();			return Math.min(pmeta.getPrecision(index),							FdocaConstants.NUMERIC_MAX_PRECISION);		}		else 			return -1;	}		/**	 *  get parameter scale or DB2 max (31)	 *	 *  @param index parameter index starting with 1	 *	 *  @return  scale	 */	protected int getParamScale(int index) throws SQLException	{		if (ps != null && ps instanceof CallableStatement)		{			EmbedParameterSetMetaData pmeta = 	getParameterMetaData();			return Math.min(pmeta.getScale(index),FdocaConstants.NUMERIC_MAX_PRECISION);		}		else 			return -1;	}	/**	 * save parameter len sent by client	 * @param index parameter index starting with 1	 * @param value  length of data value	 *	 */	protected void  setParamLen(int index, int value)	{		cliParamLens.add(index -1, new Integer(value));	}	/**	 * get the number of parameters for this statement	 * 	 * @return number of parameters	 */	protected int getNumParams()	{		if (cliParamDrdaTypes != null)			return cliParamDrdaTypes.size();		else			return 0;	}	   	/** 	 * get the number of result set columns for the current resultSet	 * 	 * @return number of columns	 */	protected int getNumRsCols()	{		int[] rsDrdaTypes = currentDrdaRs.getRsDRDATypes();		if (rsDrdaTypes != null)			return rsDrdaTypes.length;		else 			return 0;	}	/**	 * get  resultset/out parameter DRDAType	 *	 * @param index - starting with 1	 * @return  DRDA Type of column	 */	protected int getRsDRDAType(int index)	{		return currentDrdaRs.getRsDRDAType(index);	}	/**	 * get resultset/out parameter DRDALen	 * @param index starting with 1	 * 	 * @return length of drda data	 */	 	protected int getRsLen(int index)	{		return currentDrdaRs.getRsLen(index);	}	/**	 * set resultset column data length	 * @param index starting with 1	 * @param value length	 */	protected void  setRsLen(int index, int value)	{		currentDrdaRs.setRsLen(index,value);	}	/**	 * return whether this is a procedure	 * 	 * @return true if procName is not null 	 * RESOLVE: (should we check for isCall or is this good enough)	 */ 	public  boolean isProcedure()	{		return (procName != null);	}	/**	 * @param rsNum  - result set # starting with 0 	 */	public String getResultSetCursorName(int rsNum) throws SQLException	{		ResultSet rs = getResultSet(rsNum);		return rs.getCursorName();				}	protected String toDebugString(String indent)	{		ResultSet rs = currentDrdaRs.getResultSet();				String s ="";		if (ps == null) 			s += indent + ps;		else		{			s += indent + pkgid + pkgsn ;			s += "\t" + getSQLText();		}		return s;	}	/**  For a single result set, just echo the consistency token that the client sent us.	 * For subsequent resultSets, just subtract the resultset number from	 * the consistency token and that will differentiate the result sets.	 * This seems to be what DB2 does	 * @param rsNum  - result set # starting with 0	 * 	 * @return  Consistency token for result set	 */	protected ConsistencyToken calculateResultSetPkgcnstkn(int rsNum)	{			ConsistencyToken consistToken = pkgcnstkn;		if (rsNum == 0 || pkgcnstkn == null)			return consistToken;		else		{			BigInteger consistTokenBi =				new BigInteger(consistToken.getBytes());			BigInteger rsNumBi = BigInteger.valueOf(rsNum);			consistTokenBi = consistTokenBi.subtract(rsNumBi);			consistToken = new ConsistencyToken(consistTokenBi.toByteArray());		}		return consistToken;	}	protected boolean isCallableStatement()	{		return isCall;	}	private boolean isCallableSQL(String sql)	{		java.util.StringTokenizer tokenizer = new java.util.StringTokenizer			(sql, "\t\n\r\f=? (");		 String firstToken = tokenizer.nextToken();		 if (StringUtil.SQLEqualsIgnoreCase(firstToken, 											"call")) // captures CALL...and ?=CALL...			 return true;		 return false;				 	}	private void setupCallableStatementParams(CallableStatement cs) throws SQLException	{		EmbedParameterSetMetaData pmeta = 	getParameterMetaData();		int numElems = pmeta.getParameterCount();		for ( int i = 0; i < numElems; i ++)		{			boolean outputFlag = false;						int parameterMode = pmeta.getParameterMode(i + 1);			int parameterType = pmeta.getParameterType(i + 1);			switch (parameterMode) {				case JDBC30Translation.PARAMETER_MODE_IN:					break;				case JDBC30Translation.PARAMETER_MODE_OUT:				case JDBC30Translation.PARAMETER_MODE_IN_OUT:					outputFlag = true;					break;				case JDBC30Translation.PARAMETER_MODE_UNKNOWN:					// It's only unknown if array					String objectType = pmeta.getParameterClassName(i+1);					parameterType =						getOutputParameterTypeFromClassName(objectType);					if (parameterType  != NOT_OUTPUT_PARAM)						outputFlag = true;			}			if (outputFlag)			{				if (outputTypes == null) //not initialized yet, since previously none output				{					outputTypes = new int[numElems];					for (int j = 0; j < numElems; j++)						outputTypes[j] = NOT_OUTPUT_PARAM;  //default init value				}				// save the output type so we can register when we parse				// the SQLDTA				outputTypes[i] = parameterType;			}					}	}	/** 		Given an object class  name get the paramameter type if the 		parameter mode is unknown.				Arrays except for byte arrrays are assumed to be output parameters		TINYINT output parameters are going to be broken because there		is no way to differentiate them from binary input parameters.		@param objectName Class name of object being evaluated.		indicating if this an output parameter		@return type from java.sql.Types	**/		protected static int getOutputParameterTypeFromClassName(String																	objectName)	{				if (objectName.endsWith("[]"))		{					// For byte[] we are going to assume it is input.			// For TINYINT output params you gotta use 			//  object Integer[] or use a procedure				   					if (objectName.equals("byte[]"))					{						return NOT_OUTPUT_PARAM;														//isOutParam[offset] = false;							//return java.sql.Types.VARBINARY;					}										// Known arrays are output parameters					// otherwise we pass it's a JAVA_OBJECT					if (objectName.equals("java.lang.Byte[]"))						return java.sql.Types.TINYINT;										if (objectName.equals("byte[][]"))						return java.sql.Types.VARBINARY;					if (objectName.equals("java.lang.String[]"))						return java.sql.Types.VARCHAR; 					if (objectName.equals("int[]") || 						objectName.equals("java.lang.Integer[]"))						return java.sql.Types.INTEGER;					else if (objectName.equals("long[]")							 || objectName.equals("java.lang.Long[]"))						return java.sql.Types.BIGINT;					else if (objectName.equals("java.math.BigDecimal[]"))						return java.sql.Types.NUMERIC;					else if (objectName.equals("boolean[]")  || 							 objectName.equals("java.lang.Boolean[]"))						return java.sql.Types.BIT;					else if (objectName.equals("short[]"))						return java.sql.Types.SMALLINT;					else if (objectName.equals("float[]") ||							 objectName.equals("java.lang.Float[]"))						return java.sql.Types.REAL;					else if (objectName.equals("double[]") ||							 objectName.equals("java.lang.Double[]"))						return java.sql.Types.DOUBLE;					else if (objectName.equals("java.sql.Date[]"))						return java.sql.Types.DATE;					else if (objectName.equals("java.sql.Time[]"))						return java.sql.Types.TIME;					else if (objectName.equals("java.sql.Timestamp[]"))						return java.sql.Types.TIMESTAMP;		}		// Not one of the ones we know. This must be a JAVA_OBJECT		return NOT_OUTPUT_PARAM;		//isOutParam[offset] = false;						//return java.sql.Types.JAVA_OBJECT;	}			public void registerAllOutParams() throws SQLException	{		if (isCall && (outputTypes != null))			for (int i = 1; i <= outputTypes.length; i ++)				registerOutParam(i);			}		public void registerOutParam(int paramNum) throws SQLException	{		CallableStatement cs;		if (isOutputParam(paramNum))		{			cs = (CallableStatement) ps;			cs.registerOutParameter(paramNum, getOutputParamType(paramNum));		}	}	protected boolean hasOutputParams()	{		return (outputTypes != null);	}	/**	 * is  parameter an ouput parameter	 * @param paramNum parameter number starting with 1.	 * return true if this is an output parameter.	 */	boolean isOutputParam(int paramNum)	{		if (outputTypes != null)			return (outputTypes[paramNum - 1] != NOT_OUTPUT_PARAM);		return false;			}	/** 	 * get type for output parameter. 	 *	 * @param paramNum - parameter number starting with 1	 * @return jdbcType or NOT_OUTPUT_PARAM if this is not an output parameter	 */	int getOutputParamType(int paramNum)	{		if (outputTypes != null)			return (outputTypes[ paramNum - 1 ]);		return NOT_OUTPUT_PARAM;	}	private boolean isDynamicPkgid(String pkgid)	{		char size = pkgid.charAt(3);				//  separate attribute used for holdability in 5.1.60		// this is just for checking that it is a dynamic package		char holdability = pkgid.charAt(4); 			                                    		return (pkgid.substring(0,3).equals("SYS") && (size == 'S' ||													   size == 'L')				&& (holdability == 'H' || holdability == 'N'));			}   	private  void parsePkgidToFindHoldability()	{		if (withHoldCursor != -1)			return;        		//First, check if holdability was passed as a SQL attribute "WITH HOLD" for this prepare. If yes, then withHoldCursor		//should not get overwritten by holdability from package name and that is why the check for -1		if (isDynamicPkgid(pkgid))		{       			if(pkgid.charAt(4) == 'N')				withHoldCursor = JDBC30Translation.CLOSE_CURSORS_AT_COMMIT;			else  				withHoldCursor = JDBC30Translation.HOLD_CURSORS_OVER_COMMIT;		}		else 		{            			withHoldCursor = JDBC30Translation.HOLD_CURSORS_OVER_COMMIT;				}	}	/**	 *  prepare a statement using EngineConnection.prepareStatement     *  so that server can run on jdk131 and still pass holdability.  	 *  @param sqlStmt - SQL statement text	 *  @param scrollType - scroll type	 *  @param concurType - concurrency type	 *  @param withHoldCursor - holdability	 * 	 *  @throws SQLException	 *  @return Prepared Statement	 *  @see java.sql.Connection#prepareStatement	 */	private PreparedStatement prepareStatementJDBC3(String sqlStmt, int													scrollType, int concurType,													int withHoldCursor) throws SQLException	{        EngineConnection conn = database.getConnection();        if (withHoldCursor == -1) {            // Holdability not explictly set, let the            // connection provide the default.            return conn.prepareStatement(sqlStmt,                    scrollType, concurType);        }                // Holdability explictly set.         return conn.prepareStatement(sqlStmt,                scrollType, concurType, withHoldCursor);	}		/** 	 * Get parameter metadata from EmbedPreparedStatement or 	 * BrokeredPreparedStatement. We use reflection because we don't know which	 * we have.	 * 	 * @return EmbedParameterSetMetaData for the prepared statement. 	 * Note: there is no separate BrokeredParameterSetMetaData.	 */	protected EmbedParameterSetMetaData getParameterMetaData() throws SQLException	{		if (stmtPmeta != null)			return stmtPmeta;		EmbedParameterSetMetaData pmeta = null;		Class[] getParameterMetaDataParam = {};		try {			Method sh =				getPreparedStatement().getClass().getMethod("getEmbedParameterSetMetaData", getParameterMetaDataParam);			pmeta = (EmbedParameterSetMetaData)				sh.invoke(getPreparedStatement(),null);			stmtPmeta = pmeta;		}		catch (Exception e) {			handleReflectionException(e);		}		return stmtPmeta;	}		/**	 * get more results using reflection.	 * @param current - flag to pass to Statement.getMoreResults(current)	 * @return true if there are more results.	 * @throws SQLException	 * @see java.sql.Statement#getMoreResults	 *	 */	private boolean getMoreResults(int current) throws SQLException	{               return            ((EngineStatement) getPreparedStatement()).getMoreResults(current);	}	/**	 * Use reflection to retrieve SQL Text for EmbedPreparedStatement  	 * or BrokeredPreparedStatement.	 * @return SQL text	 */	private String getSQLText() 	{	   String retVal = null;		Class[] emptyPARAM = {};		Object[] args = null;		try {			Method sh = getPreparedStatement().getClass().getMethod("getSQLText",emptyPARAM);			retVal = (String) sh.invoke(getPreparedStatement(),args);		}		catch (Exception e)		{			//  do nothing we will just return a null string		}		return retVal;	}	/** helper method to handle exceptions generated by methods invoked 	 * through  reflection.	 * @param e - exception thrown	 * @throws SQLException - actual exception that occurred	 */	private void handleReflectionException(Exception e) throws SQLException	{		if  (e instanceof InvocationTargetException) 		{			Throwable t = ((InvocationTargetException) e).getTargetException();						if (t  instanceof SQLException)			{				throw (SQLException) t;			}			else			{				t.printStackTrace();				throw Util.javaException(t);			}		}		else			// invoke can throw IllegalAccessException or 			// IllegalArgumentException, but these should not 			// occur from this code. Just in case we will throw it			throw Util.javaException(e);			}		/**	 * Delegation method to call DRDAResultSet.isRSCloseImplicit()	 * 	 * @see DRDAResultSet#isRSCloseImplicit()	 * @return implicit close boolean	 * @throws SQLException	 */	boolean isRSCloseImplicit() throws SQLException {		return currentDrdaRs.isRSCloseImplicit();	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -