📄 utilmain.java
字号:
{ String errorCode; String sqlState = null; SQLException fatalException = null; if (Boolean.getBoolean("ij.showErrorCode")) { errorCode = langUtil.getTextMessage("IJ_Erro0", langUtil.getNumberAsString(e.getErrorCode())); } else { errorCode = ""; } for (; e!=null; e=e.getNextException()) { /* ** If we are to throw errors, then throw the exceptions ** that aren't in the ignoreErrors list. If ** the ignoreErrors list is null we don't throw ** any errors. */ if (ignoreErrors != null) { sqlState = e.getSQLState(); if ((sqlState != null) && (ignoreErrors.get(sqlState) != null)) { continue; } else { fatalException = e; } } String st1 = JDBCDisplayUtil.mapNull(e.getSQLState(),langUtil.getTextMessage("IJ_NoSqls")); String st2 = JDBCDisplayUtil.mapNull(e.getMessage(),langUtil.getTextMessage("IJ_NoMess")); out.println(langUtil.getTextMessage("IJ_Erro012", st1, st2, errorCode)); JDBCDisplayUtil.doTrace(out, e); } if (fatalException != null) { throw new ijFatalException(fatalException); } } /** * stack trace dumper */ private void doTrace(Throwable t) { if (util.getSystemProperty("ij.exceptionTrace") != null) { t.printStackTrace(out); } out.flush(); } void newInput(String fileName) { FileInputStream newFile = null; try { newFile = new FileInputStream(fileName); } catch (FileNotFoundException e) { throw ijException.fileNotFound(); } if (newFile == null) return; // if the file was opened, move to use it for input. oldGrabbers.push(commandGrabber[currCE]); commandGrabber[currCE] = new StatementFinder(langUtil.getNewInput(new BufferedInputStream(newFile, BUFFEREDFILESIZE))); fileInput = true; } void newResourceInput(String resourceName) { InputStream is = util.getResourceAsStream(resourceName); if (is==null) throw ijException.resourceNotFound(); oldGrabbers.push(commandGrabber[currCE]); commandGrabber[currCE] = new StatementFinder(langUtil.getNewEncodedInput(new BufferedInputStream(is, BUFFEREDFILESIZE), "UTF8")); fileInput = true; } /** * REMIND: eventually this might be part of StatementFinder, * used at each carriage return to show that it is still "live" * when it is reading multi-line input. */ static void doPrompt(boolean newStatement, LocalizedOutput out, String tag) { if (newStatement) { out.print("ij"+(tag==null?"":tag)+"> "); } else { out.print("> "); } out.flush(); } void setMtUse(boolean b) { mtUse = b; } // JDBC 2.0 support /** * Return the right utilMain to use. (JDBC 1.1 or 2.0) * */ public utilMain getUtilMain() { return this; } /** * Connections by default create ResultSet objects with holdability true. This method can be used * to change the holdability of the connection by passing one of ResultSet.HOLD_CURSORS_OVER_COMMIT * or ResultSet.CLOSE_CURSORS_AT_COMMIT. We implement this using reflection in jdk13 and lower * * @param conn The connection. * @param holdType The new holdability for the Connection object. * * @return The connection object with holdability set to passed value. */ public Connection setHoldability(Connection conn, int holdType) throws SQLException { //Prior to db2 compatibility work, the default holdability for connections was close cursors over commit and all the tests //were written based on that assumption //Later, as part of db2 compatibility, we changed the default holdability for connection to hold cursors over commit. //But in order for the existing tests to work fine, the tests needed a way to set the holdability to close cursors for connections //Since there is no direct jdbc api in jdk13 and lower to do that, we are using reflection to set the holdability to close cursors try { //for jdks prior to jdk14, need to use reflection to set holdability to false. Method sh = conn.getClass().getMethod("setHoldability", CONN_PARAM); sh.invoke(conn, CONN_ARG); } catch( Exception e) { throw PublicAPI.wrapStandardException( StandardException.plainWrapException( e)); } return conn; } /** * Retrieves the current holdability of ResultSet objects created using this * Connection object. We implement this using reflection in jdk13 and lower * * @return The holdability, one of ResultSet.HOLD_CURSORS_OVER_COMMIT * or ResultSet.CLOSE_CURSORS_AT_COMMIT * */ public int getHoldability(Connection conn) throws SQLException { //this method is used to make sure we are not trying to create a statement with holdability different than the connection holdability //This is because jdk13 and lower does not have support for that. //The holdability of connection and statement can differ if connection holdability is set to close cursor on commit using reflection //and statement is getting created with holdability true //Another instance of holdability of connection and statement not being same is when connection holdability is hold cursor //over commit and statement is being created with holdability false int defaultHoldability = JDBC30Translation.HOLD_CURSORS_OVER_COMMIT; try { Method sh = conn.getClass().getMethod("getHoldability", null); defaultHoldability = ((Integer)sh.invoke(conn, null)).intValue(); } catch( Exception e) { throw PublicAPI.wrapStandardException( StandardException.plainWrapException( e)); } return defaultHoldability; } /** * Create the right kind of statement (scrolling or not) * off of the specified connection. * * @param conn The connection. * @param scrollType The scroll type of the cursor. * * @return The statement. */ public Statement createStatement(Connection conn, int scrollType, int holdType) throws SQLException { //following if is used to make sure we are not trying to create a statement with holdability different that the connection //holdability. This is because jdk13 and lower does not have support for that. //The holdability of connection and statement can differ if connection holdability is set to close cursor on commit using reflection //and statement is getting created with holdability true //Another instance of holdability of connection and statement not being same is when connection holdability is hold cursor //over commit and statement is being created with holdability false if (holdType != getHoldability(conn)) { throw ijException.holdCursorsNotSupported(); } Statement stmt; try { stmt = conn.createStatement(scrollType, JDBC20Translation.CONCUR_READ_ONLY); } catch(AbstractMethodError ame) { //because weblogic 4.5 doesn't yet implement jdbc 2.0 interfaces, need to go back //to jdbc 1.x functionality stmt = conn.createStatement(); } return stmt; } /** * Position on the specified row of the specified ResultSet. * * @param rs The specified ResultSet. * @param row The row # to move to. * (Negative means from the end of the result set.) * * @return NULL. * * @exception SQLException thrown on error. * (absolute() not supported pre-JDBC2.0) */ public ijResult absolute(ResultSet rs, int row) throws SQLException { boolean forwardOnly; try { // absolute is only allowed on scroll cursors forwardOnly = (rs.getStatement().getResultSetType() == JDBC20Translation.TYPE_FORWARD_ONLY); } catch (AbstractMethodError ame) { //because weblogic 4.5 doesn't yet implement jdbc 2.0 interfaces, need to go back //to jdbc 1.x functionality forwardOnly = true; } if (forwardOnly) { throw ijException.forwardOnlyCursor("ABSOLUTE"); } // 0 is an *VALID* value for row return new ijRowResult(rs, rs.absolute(row)); } /** * Move the cursor position by the specified amount. * * @param rs The specified ResultSet. * @param row The # of rows to move. * (Negative means toward the beginning of the result set.) * * @return NULL. * * @exception SQLException thrown on error. * (relative() not supported pre-JDBC2.0) */ public ijResult relative(ResultSet rs, int row) throws SQLException { boolean forwardOnly; try { forwardOnly = (rs.getStatement().getResultSetType() == JDBC20Translation.TYPE_FORWARD_ONLY); } catch (AbstractMethodError ame) { //because weblogic 4.5 doesn't yet implement jdbc 2.0 interfaces, need to go back //to jdbc 1.x functionality forwardOnly = true; } // relative is only allowed on scroll cursors if (forwardOnly) { throw ijException.forwardOnlyCursor("RELATIVE"); } return new ijRowResult(rs, rs.relative(row)); } /** * Position before the first row of the specified ResultSet * and return NULL to the user. * * @param rs The specified ResultSet. * * @return NULL. * * @exception SQLException thrown on error. * (beforeFirst() not supported pre-JDBC2.0) */ public ijResult beforeFirst(ResultSet rs) throws SQLException { boolean forwardOnly; try { forwardOnly = (rs.getStatement().getResultSetType() == JDBC20Translation.TYPE_FORWARD_ONLY); } catch (AbstractMethodError ame) { //because weblogic 4.5 doesn't yet implement jdbc 2.0 interfaces, need to go back //to jdbc 1.x functionality forwardOnly = true; } // before first is only allowed on scroll cursors if (forwardOnly) { throw ijException.forwardOnlyCursor("BEFORE FIRST"); } rs.beforeFirst(); return new ijRowResult(rs, false); } /** * Position on the first row of the specified ResultSet * and return that row to the user. * * @param rs The specified ResultSet. * * @return The first row of the ResultSet. * * @exception SQLException thrown on error. * (first() not supported pre-JDBC2.0) */ public ijResult first(ResultSet rs) throws SQLException { boolean forwardOnly; try { forwardOnly = (rs.getStatement().getResultSetType() == JDBC20Translation.TYPE_FORWARD_ONLY); } catch (AbstractMethodError ame) { //because weblogic 4.5 doesn't yet implement jdbc 2.0 interfaces, need to go back //to jdbc 1.x functionality forwardOnly = true; } // first is only allowed on scroll cursors if (forwardOnly) { throw ijException.forwardOnlyCursor("FIRST"); } return new ijRowResult(rs, rs.first()); } /** * Position after the last row of the specified ResultSet * and return NULL to the user. * * @param rs The specified ResultSet. * * @return NULL. * * @exception SQLException thrown on error. * (afterLast() not supported pre-JDBC2.0) */ public ijResult afterLast(ResultSet rs) throws SQLException { boolean forwardOnly; try { forwardOnly = (rs.getStatement().getResultSetType() == JDBC20Translation.TYPE_FORWARD_ONLY); } catch (AbstractMethodError ame) { //because weblogic 4.5 doesn't yet implement jdbc 2.0 interfaces, need to go back //to jdbc 1.x functionality forwardOnly = true; } // after last is only allowed on scroll cursors if (forwardOnly) { throw ijException.forwardOnlyCursor("AFTER LAST"); } rs.afterLast(); return new ijRowResult(rs, false); } /** * Position on the last row of the specified ResultSet * and return that row to the user. * * @param rs The specified ResultSet. * * @return The last row of the ResultSet. * * @exception SQLException thrown on error. * (last() not supported pre-JDBC2.0) */ public ijResult last(ResultSet rs) throws SQLException { boolean forwardOnly; try { forwardOnly = (rs.getStatement().getResultSetType() == JDBC20Translation.TYPE_FORWARD_ONLY); } catch (AbstractMethodError ame) { //because weblogic 4.5 doesn't yet implement jdbc 2.0 interfaces, need to go back //to jdbc 1.x functionality forwardOnly = true; } // last is only allowed on scroll cursors if (forwardOnly) { throw ijException.forwardOnlyCursor("LAST"); } return new ijRowResult(rs, rs.last()); } /** * Position on the previous row of the specified ResultSet * and return that row to the user. * * @param rs The specified ResultSet. * * @return The previous row of the ResultSet. * * @exception SQLException thrown on error. * (previous() not supported pre-JDBC2.0) */ public ijResult previous(ResultSet rs) throws SQLException { boolean forwardOnly; try { forwardOnly = (rs.getStatement().getResultSetType() == JDBC20Translation.TYPE_FORWARD_ONLY); } catch (AbstractMethodError ame) { //because weblogic 4.5 doesn't yet implement jdbc 2.0 interfaces, need to go back //to jdbc 1.x functionality forwardOnly = true; } // first is only allowed on scroll cursors if (forwardOnly) { throw ijException.forwardOnlyCursor("PREVIOUS"); } return new ijRowResult(rs, rs.previous()); } /** * Get the current row number * * @param rs The specified ResultSet. * * @return The current row number * * @exception SQLException thrown on error. * (getRow() not supported pre-JDBC2.0) */ public int getCurrentRowNumber(ResultSet rs) throws SQLException { boolean forwardOnly; try { forwardOnly = (rs.getStatement().getResultSetType() == JDBC20Translation.TYPE_FORWARD_ONLY); } catch (AbstractMethodError ame) { //because weblogic 4.5 doesn't yet implement jdbc 2.0 interfaces, need to go back //to jdbc 1.x functionality forwardOnly = true; } // getCurrentRow is only allowed on scroll cursors if (forwardOnly) { throw ijException.forwardOnlyCursor("GETCURRENTROWNUMBER"); } return rs.getRow(); } public Properties getConnAttributeDefaults () { return connAttributeDefaults; } public final Object run() { return getClass().getResourceAsStream(ProductGenusNames.TOOLS_INFO); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -