protected synchronized String getProcedureName(Connection dConn, Connection gConn) {
    /// avoid #42569
    ResultSet rs = null;

    try {
      rs = gConn.getMetaData().getProcedures(null, null, null);
      List procNames = ResultSetHelper.asList(rs, false);
      Log.getLogWriter().info("procedure names are " + ResultSetHelper.listToString(procNames));
      rs.close();
    } catch (SQLException se) {
      SQLHelper.handleSQLException(se);
    }

    try {
      rs = gConn.getMetaData().getFunctions(null, null, null);
    } catch (SQLException se) {
      SQLHelper.handleSQLException(se);
    }
    List funcNames = ResultSetHelper.asList(rs, false);
    Log.getLogWriter().info("function names are " + ResultSetHelper.listToString(funcNames));

    if (procedureNames == null) {
      ArrayList<String> procs = new ArrayList<String>();
      procs.addAll(ProcedureDDLStmt.modifyProcNameList);
      procs.addAll(ProcedureDDLStmt.nonModifyProcNameList);
      procedureNames = new ArrayList<String>(procs);
    }

    return procedureNames.get(SQLTest.random.nextInt(procedureNames.size()));
  }
 public static void HydraTask_populateMusicDB() {
   if (musicHelper == null) {
     musicHelper = new MusicHelper();
   }
   try {
     if (hasDerbyServer) {
       Connection dConn = musicHelper.getDiscConnection();
       MusicPopulator.addToTables(
           dConn,
           MusicPrms.getNumGeneratedArtists(),
           MusicPrms.getNumGeneratedAlbums(),
           MusicPrms.getNumGeneratedCopyrightOwners(),
           MusicPrms.getNumGeneratedSongs(),
           MusicPrms.getNumGeneratedGenres(),
           MusicPrms.getNumGeneratedTags(),
           MusicPrms.getNumGeneratedTracks());
       dConn.close();
     }
     Connection gConn = musicHelper.getGFEConnection();
     MusicPopulator.addToTables(
         gConn,
         MusicPrms.getNumGeneratedArtists(),
         MusicPrms.getNumGeneratedAlbums(),
         MusicPrms.getNumGeneratedCopyrightOwners(),
         MusicPrms.getNumGeneratedSongs(),
         MusicPrms.getNumGeneratedGenres(),
         MusicPrms.getNumGeneratedTags(),
         MusicPrms.getNumGeneratedTracks());
     gConn.close();
   } catch (SQLException sqle) {
     SQLHelper.handleSQLException(sqle);
   }
 }
 public void provideAllPrivToAll(Connection dConn, Connection gConn) {
   ArrayList<SQLException> exList = new ArrayList<SQLException>();
   for (int i = 0; i < tableNames.length; i++) {
     StringBuffer sql = new StringBuffer();
     sql.append("grant all privileges on " + tableNames[i] + " to " + getAllGrantees());
     Log.getLogWriter().info("security statement is " + sql.toString());
     if (dConn != null) {
       try {
         Statement stmt = dConn.createStatement();
         stmt.execute(sql.toString()); // execute authorization
         dConn.commit();
         stmt.close();
       } catch (SQLException se) {
         SQLHelper.handleDerbySQLException(se, exList);
       }
       try {
         Statement stmt = gConn.createStatement();
         stmt.execute(sql.toString()); // execute authorization
         gConn.commit();
         stmt.close();
       } catch (SQLException se) {
         SQLHelper.handleGFGFXDException(se, exList);
       }
     } else {
       try {
         Statement stmt = gConn.createStatement();
         stmt.execute(sql.toString()); // execute authorization
         gConn.commit();
         stmt.close();
       } catch (SQLException se) {
         SQLHelper.handleSQLException(se);
       }
     }
   }
 }
 protected void applySecurityToGFE(Connection gConn, String sql) {
   Log.getLogWriter().info("execute authorization statement in GFE");
   Log.getLogWriter().info("security statement is: " + sql);
   try {
     Statement stmt = gConn.createStatement();
     stmt.execute(sql); // execute authorization
   } catch (SQLException se) {
     if (se.getSQLState().equals("42506") && SQLTest.testSecurity)
       Log.getLogWriter()
           .info("Got the expected exception for authorization," + " continuing tests");
     else if (se.getSQLState().equals("42509") && SQLTest.testSecurity)
       Log.getLogWriter()
           .info(
               "Got the expected grant or revoke operation "
                   + "is not allowed exception for authorization,"
                   + " continuing tests");
     else if (se.getSQLState().equals("42Y03") && hasRoutine)
       Log.getLogWriter()
           .info(
               "Got the expected not recognized as "
                   + "a function or procedure exception for authorization,"
                   + " continuing tests");
     else SQLHelper.handleSQLException(se);
   }
 }
 protected Statement initialValue() {
   Statement s = null;
   try {
     s = dConn.get().createStatement();
   } catch (SQLException se) {
     SQLHelper.handleSQLException(se);
   }
   return s;
 }
 protected PreparedStatement initialValue() {
   PreparedStatement stmt = null;
   try {
     stmt = dConn.get().prepareStatement(delete);
   } catch (SQLException se) {
     SQLHelper.handleSQLException(se);
   }
   return stmt;
 }
 public static void turnOnGFEAuthorization(Connection conn, String sql) {
   Log.getLogWriter().info("turn on authorization statement in GFE");
   try {
     Statement stmt = conn.createStatement();
     stmt.executeUpdate(sql);
     conn.commit();
   } catch (SQLException se) {
     SQLHelper.handleSQLException(se);
   }
 }
 protected Connection initialValue() {
   Connection dConn = null;
   try {
     dConn = ClientDiscDBManager.getConnection();
     // may need to use url to get the correct db connection
   } catch (SQLException se) {
     SQLHelper.handleSQLException(se);
   }
   return dConn;
 }
 public static Connection getDefaultConnection() {
   Connection conn = null;
   try {
     conn = DriverManager.getConnection("jdbc:default:connection");
     // Log.getLogWriter().info("Connection in - getDefaultConnection " +
     // conn.getMetaData().getDriverName());
   } catch (SQLException se) {
     SQLHelper.handleSQLException(se);
   }
   return conn;
 }
 protected static Connection getDefaultConnection() {
   Connection conn = null;
   try {
     conn = DriverManager.getConnection("jdbc:default:connection");
   } catch (SQLException se) {
     // TODO, add Asif's work around for ticket #41642
     // and use jdbc:default:gemfirexd:connection
     SQLHelper.handleSQLException(se);
   }
   return conn;
 }
 private void revokeDelegatedPrivilege(Connection gConn, String tableName) {
   int num = SQLTest.random.nextInt(SQLTest.numOfWorkers) + 1;
   String grantees = getGrantees(num);
   int whichPriv = SQLTest.random.nextInt(tablePriv.length);
   StringBuffer sql = new StringBuffer();
   sql.append("revoke " + tablePriv[whichPriv] + " on " + tableName + " from " + grantees);
   Log.getLogWriter().info("security statement is " + sql.toString());
   try {
     Statement stmt = gConn.createStatement();
     stmt.execute(sql.toString()); // execute authorization
     gConn.commit();
     stmt.close();
   } catch (SQLException se) {
     SQLHelper.handleSQLException(se);
   }
 }
  protected List<Struct> getKeysForQuery(String sql, boolean[] success) {
    Connection noneTxConn = (Connection) SQLDistTxTest.gfxdNoneTxConn.get();

    try {
      Log.getLogWriter().info("executing the following query: " + sql);
      ResultSet noneTxGfxdRS = noneTxConn.createStatement().executeQuery(sql);
      List<Struct> noneTxGfxdList = ResultSetHelper.asList(noneTxGfxdRS, false);
      if (noneTxGfxdList == null && isHATest) {
        Log.getLogWriter().info("Testing HA and did not get GFXD result set");
        success[0] = false;
      } else {
        success[0] = true;
      }
      return noneTxGfxdList;
    } catch (SQLException se) {
      SQLHelper.handleSQLException(se);
    }

    return null; // should not hit this as SQLHelper.handleSQLException(se) throws TestException.
  }
 private void delegateGrantOption(Connection gConn, String tableName) {
   int num = SQLTest.random.nextInt(SQLTest.numOfWorkers) + 1;
   String grantees = getGrantees(num);
   StringBuffer sql = new StringBuffer();
   int whichPriv = SQLTest.random.nextInt(tablePriv.length);
   sql.append(
       "grant " + tablePriv[whichPriv] + " on " + tableName + " to " + grantees + withGrantOption);
   Log.getLogWriter().info("security statement is " + sql.toString());
   try {
     Statement stmt = gConn.createStatement();
     stmt.execute(sql.toString()); // execute authorization
     gConn.commit();
     stmt.close();
   } catch (SQLException se) {
     if (se.getSQLState().equals("42X01")) {
       Log.getLogWriter()
           .info(
               "Got expected exception as WITH GRANT OPTION "
                   + "is not supported yet, continuing test");
     } else {
       SQLHelper.handleSQLException(se);
     }
   }
 }