Identifies if an exception indicates an unsupported operation.

@param sqle the exception.
@return true if unsupported, otherwise false.
426894
public static boolean isUnsupportedException(SQLException sqle){
        if(sqle instanceof SQLFeatureNotSupportedException)
            return true;
        
        String state = sqle.getSQLState() == null ? "" : sqle.getSQLState();
        int code = sqle.getErrorCode();

        return state.startsWith("0A") || 0x0A000 == code // standard code for unsupported operation
            || state.startsWith("HYC00") // ODBC error code
            || code == -79700 && "IX000".equals(state); // Informix specific
    }
309029
public int executeUpdate(String query) throws Exception {
        int returnVal = 0;
        Statement queryStatement = null;

        try (Connection sqlConnection = getConnection()) {
            queryStatement = sqlConnection.createStatement();
            returnVal = queryStatement.executeUpdate(query);
        } catch (Exception e) {
        } finally {
            try {
                if (queryStatement != null) {
                    queryStatement.close();
                }
            } catch (Exception e) {
            }
        }

        return returnVal;
    }
20280
public boolean first() throws SQLException {
        try {
            if (dsConfig.get().beginTranForResultSetScrollingAPIs)
                getConnectionWrapper().beginTransactionIfNecessary();

            return rsetImpl.first();
        } catch (SQLException ex) {
            FFDCFilter.processException(ex, "com.ibm.ws.rsadapter.jdbc.WSJdbcResultSet.first", "411", this);
            throw WSJdbcUtil.mapException(this, ex);
        } catch (NullPointerException nullX) {
            // No FFDC code needed; we might be closed.
            throw runtimeXIfNotClosed(nullX);
        }
    }
197755
@Override
    public void isValid() throws Exception {
        if (numStmnts() >= 2) {
            if (primaryJoinableHooks.size() > 0) {
                for (String joinField:primaryJoinableHooks) {
                    if (joinField.equals("timestamp")) {// timestamp is implicitly present in the result.
                        continue;
                    }
                    for (QueryMeta query: getAllStmnts()) {
                        boolean isPresent = false;
                        if (query instanceof BaseAggQueryMeta) {// Since BaseAggQueryMeta is also a PlainDimQueryMeta we go with former first.
                            for (AggItem item:((BaseAggQueryMeta)query).aggregations) {
                                if (joinField.equals(item.fieldName) || (item.asName != null && joinField.equals(item.asName))) {
                                    isPresent = true;
                                }
                            }
                        }
                        if (query instanceof PlainDimQueryMeta) {
                            Map<String, String> dims = ((PlainDimQueryMeta)query).fetchDimensions;
                            for (Map.Entry<String, String> entry :dims.entrySet()) {
                                if (joinField.equals(entry.getKey()) || (entry.getValue() != null && joinField.equals(entry.getValue()))) {
                                    isPresent = true;
                                }
                            }
                        }
                        if (!isPresent) {
                            String error = joinField + " mentioned in the composite key should appear in all the data sources being queried and joined.";
                            throw new Exception(error);
                        }
                    }
                }
            } else {
                String error = "Need atleast one field to join on";
                throw new Exception(error);
            }
        }
    }
940422
private static boolean isJDBCClass(@SlashedClassName String name) {
        String clsName = SignatureUtils.stripSignature(name);

        return (clsName.startsWith("java.sql.") || clsName.startsWith("javax.sql.")) && !clsName.endsWith("Exception");
    }
441099
private boolean isSQLErrorTransient(SQLException sqlex) {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "isSQLErrorTransient ", new Object[] { sqlex, this });
        boolean retryBatch = false;
        int sqlErrorCode = sqlex.getErrorCode();

        if (tc.isEventEnabled()) {
            Tr.event(tc, " SQL exception:");
            Tr.event(tc, " Message: " + sqlex.getMessage());
            Tr.event(tc, " SQLSTATE: " + sqlex.getSQLState());
            Tr.event(tc, " Error code: " + sqlErrorCode);
        }

        for (int transientCode : _sqlTransientErrorCodes) {
            Tr.event(tc, "Test against stored code: " + transientCode);
            if (transientCode == sqlErrorCode) {
                Tr.event(tc, "TRANSIENT: A connection failed but could be reestablished, retry.");
                retryBatch = true;
                break;
            }
        }

        if (!retryBatch && sqlex instanceof BatchUpdateException) {
            BatchUpdateException buex = (BatchUpdateException) sqlex;
            Tr.event(tc, "BatchUpdateException: Update Counts - ");
            int[] updateCounts = buex.getUpdateCounts();
            for (int i = 0; i < updateCounts.length; i++) {
                Tr.event(tc, "   Statement " + i + ":" + updateCounts[i]);
            }
            SQLException nextex = buex.getNextException();
            while (nextex != null) {
                sqlErrorCode = nextex.getErrorCode();
                if (tc.isEventEnabled()) {
                    Tr.event(tc, " SQL exception:");
                    Tr.event(tc, " Message: " + nextex.getMessage());
                    Tr.event(tc, " SQLSTATE: " + nextex.getSQLState());

                    Tr.event(tc, " Error code: " + sqlErrorCode);
                }

                for (int transientCode : _sqlTransientErrorCodes) {
                    Tr.event(tc, "Test against stored code: " + transientCode);
                    if (transientCode == sqlErrorCode) {
                        Tr.event(tc, "TRANSIENT: A connection failed but could be reestablished, retry.");
                        retryBatch = true;
                        break;
                    }
                }

                nextex = nextex.getNextException();
            }
        }

        if (tc.isEntryEnabled())
            Tr.exit(tc, "isSQLErrorTransient", retryBatch);
        return retryBatch;
    }
937640
private static boolean executesAsSimpleDirective(String line) throws Exception {

        // SHOW or LIST <blah> statement
        String subcommand = SQLParser.parseShowStatementSubcommand(line);
        if (subcommand != null) {
            if (subcommand.equals("proc") || subcommand.equals("procedures")) {
                execListProcedures();
            }
            else if (subcommand.equals("functions")) {
                execListFunctions();
            }
            else if (subcommand.equals("tables")) {
                execListTables();
            }
            else if (subcommand.equals("classes")) {
                execListClasses();
            }
            else if (subcommand.equals("config") || subcommand.equals("configuration")) {
                execListConfigurations();
            }
            else {
                String errorCase = (subcommand.equals("") || subcommand.equals(";")) ?
                        ("Incomplete SHOW command.\n") :
                        ("Invalid SHOW command completion: '" + subcommand + "'.\n");
                System.out.println(errorCase +
                        "The valid SHOW command completions are proc, procedures, tables, or classes.");
            }
            // Consider it handled here, whether or not it was a good SHOW statement.
            return true;
        }

        // HELP commands - ONLY in interactive mode, close batch and parse for execution
        // Parser returns null if it isn't a HELP command. If no arguments are specified
        // the returned string will be empty.
        String helpSubcommand = SQLParser.parseHelpStatement(line);
        if (helpSubcommand != null) {
            // Ignore the arguments for now.
            if (!helpSubcommand.isEmpty()) {
                System.out.printf("Ignoring extra HELP argument(s): %s\n", helpSubcommand);
            }
            printHelp(System.out); // Print readme to the screen
            return true;
        }

        String echoArgs = SQLParser.parseEchoStatement(line);
        if (echoArgs != null) {
            System.out.println(echoArgs);
            return true;
        }

        String echoErrorArgs = SQLParser.parseEchoErrorStatement(line);
        if (echoErrorArgs != null) {
            System.err.println(echoErrorArgs);
            return true;
        }

        // DESCRIBE table
        String describeArgs = SQLParser.parseDescribeStatement(line);
        if (describeArgs != null) {

            // Check if table exists
            String tableName = "";
            String type = "";
            VoltTable tableData = m_client.callProcedure("@SystemCatalog", "TABLES").getResults()[0];
            while (tableData.advanceRow()) {
                String t = tableData.getString(2);
                if (t.equalsIgnoreCase(describeArgs)) {
                    tableName = t;
                    type = tableData.getString(3);
                    break;
                }
            }
            if (tableName.equals("")) {
                System.err.println("Table does not exist");
                return true;
            }

            // Class to temporarily store and sort column attributes
            class Column implements Comparable {
                String name;
                String type;
                long size;
                String remarks;
                long position;
                String notNull;

                @Override
                public String toString() {return "";}

                @Override
                public int compareTo(Object obj) {
                    Column col = (Column) obj;
                    return (int)(this.position - col.position);
                }
            }

            // sort the columns as they are inserted
            SortedSet set = new TreeSet();

            // Retrieve Column attributes
            VoltTable columnData = m_client.callProcedure("@SystemCatalog", "COLUMNS").getResults()[0];
            int maxNameWidth = 10;
            while (columnData.advanceRow()) {
                if (tableName.equalsIgnoreCase(columnData.getString(2))) {

                    Column c = new Column();
                    c.name = columnData.getString(3);
                    if (c.name.length() > maxNameWidth) {
                        maxNameWidth = c.name.length();
                    }

                    c.type = columnData.getString(5);

                    c.size = columnData.getLong(6);
                    if (columnData.wasNull()) {
                        if (c.type.equals("GEOGRAPHY")) {
                            c.size = 32768;
                        }
                        if (c.type.equals("GEOGRAPHY_POINT")) {
                            c.size = 16;
                        }
                    } else if (c.type.equals("TINYINT")) {
                        c.size = 1;
                    } else if (c.type.equals("SMALLINT")) {
                        c.size = 2;
                    } else if (c.type.equals("INTEGER")) {
                        c.size = 4;
                    } else if (c.type.equals("BIGINT")) {
                        c.size = 8;
                    } else if (c.type.equals("FLOAT")) {
                        c.size = 8;
                    } else if (c.type.equals("DECIMAL")) {
                        c.size = 16;
                    } else if (c.type.equals("TIMESTAMP")) {
                        c.size = 8;
                    }

                    c.remarks = columnData.getString(11);
                    if (columnData.wasNull()) {
                        c.remarks = "";
                    }

                    c.position = columnData.getLong(16);

                    String nullableYesNo = columnData.getString(17);
                    c.notNull = "";
                    if (nullableYesNo.equals("NO")) {
                        c.notNull = "NOT NULL";
                    }

                    set.add(c);
                }
            }

            // print output
            String headerFormat = "%-" + maxNameWidth + "s|%-16s|%-11s|%-9s|%-16s\n";
            String rowFormat = "%-" + maxNameWidth + "s|%-16s|%11d|%-9s|%-16s\n";
            System.out.printf(headerFormat,"COLUMN","DATATYPE","SIZE","NULLABLE","REMARKS");
            String DASHES = new String(new char[56+maxNameWidth]).replace("\0", "-");
            System.out.println(DASHES);

            Iterator it = set.iterator();
            while (it.hasNext()) {
                Column c = (Column)it.next();
                System.out.printf(rowFormat,c.name,c.type,c.size,c.notNull,c.remarks);
            }
            System.out.println(DASHES);

            // primary key
            String primaryKey = "";
            VoltTable keyData = m_client.callProcedure("@SystemCatalog", "PRIMARYKEYS").getResults()[0];
            while (keyData.advanceRow()) {
                if (tableName.equalsIgnoreCase(keyData.getString(2))) {
                    String colName = keyData.getString(3);
                    if (!primaryKey.equals("")) {
                        primaryKey += ",";
                    }
                    primaryKey += colName;
                }
            }
            if (!primaryKey.equals("")) {
                System.out.println("Type: " + type + ", Primary Key (" + primaryKey + ")");
            } else {
                System.out.println("Type: " + type);
            }
            return true;
        }

        // It wasn't a locally-interpreted directive.
        return false;
    }
726903
public boolean isUniqueConstraintError(SQLException e) {
        if (isConstraintError(e)) {
            String sqlstate = e.getSQLState();
            return SQLSTATE_UNIQUE_CONSTRAINT_VIOLATION.equals(sqlstate);
        }
        return false;
    }
1276191
public static void assertTrueOrUnknownParamInJQLException(boolean expression, SQLiteModelMethod method,
			String paramName) {
		if (!expression) {
			throw (new UnknownParamUsedInJQLException(method, paramName));
		}
	}
917175
private boolean isApplicationError(Throwable rootEx, String pkgRoot) {
        
        if (rootEx != null) {
            StackTraceElement[] stackTrace = rootEx.getStackTrace();
            if (stackTrace != null && stackTrace.length > 0) {
                StackTraceElement rootThrower = stackTrace[0];
                String className = rootThrower.getClassName();
                if (className != null && !!!className.startsWith(pkgRoot)) {
                    return true;
                }
            }
        }
        
        return false;
    }
761489
public static boolean hasJoinOperation(String selectQuery) {
    if (selectQuery == null || selectQuery.length() == 0) {
      return false;
    }

    SqlParser sqlParser = SqlParser.create(selectQuery);
    try {

      SqlNode all = sqlParser.parseQuery();
      SqlSelect query;
      if (all instanceof SqlSelect) {
        query = (SqlSelect) all;
      } else if (all instanceof SqlOrderBy) {
        query = (SqlSelect) ((SqlOrderBy) all).query;
      } else {
        throw new UnsupportedOperationException("The select query is type of " + all.getClass() + " which is not supported here");
      }
      return query.getFrom().getKind() == SqlKind.JOIN;
    } catch (SqlParseException e) {
      return false;
    }
  }
90280
boolean connect() throws SQLException {
    try {
      if (driver != null && driver.length() != 0) {
        Class.forName(driver);
      }
    } catch (ClassNotFoundException cnfe) {
      return sqlLine.error(cnfe);
    }

    boolean foundDriver = false;
    Driver theDriver = null;
    try {
      theDriver = DriverManager.getDriver(url);
      foundDriver = theDriver != null;
    } catch (Exception e) {
      // ignore
    }

    if (!foundDriver) {
      sqlLine.output(sqlLine.loc("autoloading-known-drivers", url));
      sqlLine.registerKnownDrivers();
      theDriver = DriverManager.getDriver(url);
    }

    try {
      close();
    } catch (Exception e) {
      return sqlLine.error(e);
    }

    // Avoid using DriverManager.getConnection(). It is a synchronized
    // method and thus holds the lock while making the connection.
    // Deadlock can occur if the driver's connection processing uses any
    // synchronized DriverManager methods.  One such example is the
    // RMI-JDBC driver, whose RJDriverServer.connect() method uses
    // DriverManager.getDriver(). Because RJDriverServer.connect runs in
    // a different thread (RMI) than the getConnection() caller (here),
    // this sequence will hang every time.
/*
          connection = DriverManager.getConnection (url, username, password);
*/
    // Instead, we use the driver instance to make the connection

    connection = theDriver.connect(url, info);
    meta = (DatabaseMetaData) Proxy.newProxyInstance(
        DatabaseMetaData.class.getClassLoader(),
        new Class[] {DatabaseMetaData.class},
        new DatabaseMetaDataHandler(connection.getMetaData()));
    try {
      sqlLine.debug(
          sqlLine.loc("connected",
              meta.getDatabaseProductName(),
              meta.getDatabaseProductVersion()));
    } catch (Exception e) {
      sqlLine.handleException(e);
    }

    try {
      sqlLine.debug(
          sqlLine.loc("driver",
              meta.getDriverName(),
              meta.getDriverVersion()));
    } catch (Exception e) {
      sqlLine.handleException(e);
    }

    try {
      connection.setAutoCommit(sqlLine.getOpts().getAutoCommit());
      sqlLine.autocommitStatus(connection);
    } catch (Exception e) {
      sqlLine.handleException(e);
    }

    try {
      // nothing is done off of this command beyond the handle so no
      // need to use the callback.
      sqlLine.getCommands().isolation("isolation: " + sqlLine.getOpts()
          .getIsolation(),
          new DispatchCallback());
      initSyntaxRule();
    } catch (Exception e) {
      sqlLine.handleException(e);
    }

    sqlLine.showWarnings();

    return true;
  }
905896
@Override
    public SQLException attempt() {
        try {
            Connection con = this.connectionSpec.getOrCreate();
            con.setReadOnly(true);
            try {
                Statement stmt = con.createStatement(
                        ResultSet.TYPE_FORWARD_ONLY,
                        ResultSet.CONCUR_READ_ONLY);
                stmt.setFetchSize(AbstractSQLGenerator.FETCH_SIZE);
                if (this.queryTimeout != null) {
                    stmt.setQueryTimeout(this.queryTimeout);
                }
                try {
                    SQLExecutor.executeSQL(con, stmt, this.query,
                            this.resultProcessor);
                    stmt.close();
                    stmt = null;
                } finally {
                    if (stmt != null) {
                        try {
                            stmt.close();
                        } catch (SQLException e) {
                        }
                    }
                }
                con.close();
                con = null;
            } finally {
                if (con != null) {
                    try {
                        con.close();
                    } catch (SQLException e) {
                    }
                }
            }
            return null;
        } catch (SQLException ex) {
            return ex;
        }
    }
192256
private static boolean mySqlErrorCodeMatches(Exception e, int errorCode)
    {
        return Throwables.getCausalChain(e).stream()
                .filter(SQLException.class::isInstance)
                .map(SQLException.class::cast)
                .filter(t -> t.getErrorCode() == errorCode)
                .map(Throwable::getStackTrace)
                .anyMatch(isMySQLException());
    }
187554
public static void assertTrueOrUnknownClassInJQLException(boolean expression, SQLiteModelMethod method,
			String className) {
		if (!expression) {
			throw (new UnknownClassInJQLException(method, className));
		}
	}
313809
public boolean isConnectionError(SQLException ex) {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();

        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(this, tc, "isConnectionError", ex);

        // Maintain a set in order to check for cycles
        Set<Throwable> chain = new HashSet<Throwable>();

        boolean stale = super.isConnectionError(ex);
        for (Throwable t = ex; t != null && !stale && chain.add(t); t = t.getCause()) {
            SQLException sqlX = t instanceof SQLException ? (SQLException) t : null;
            if (isTraceOn && tc.isDebugEnabled())
                Tr.debug(this, tc, "checking " + t,
                         sqlX == null ? null : sqlX.getSQLState(),
                         sqlX == null ? null : sqlX.getErrorCode());
            if (sqlX != null)
                stale |= isDataDirectExp(ex)
                         ? staleDDErrorCodes.contains(sqlX.getErrorCode()) || staleDDSQLStates.contains(sqlX.getSQLState())
                         : staleMSErrorCodes.contains(sqlX.getErrorCode());
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(this, tc, "isConnectionError", stale);

        return stale;
    }
1047542
public static boolean isSqlStateRollbackException(SQLException se) {
        String sqlState = se.getSQLState();
        return sqlState != null && sqlState.startsWith("40");
    }