private void useDelegatedPrivilege(Connection dConn, Connection gConn, String tableName) { int num = SQLTest.random.nextInt(SQLTest.numOfWorkers) + 1; String grantees = getGrantees(num); ArrayList<SQLException> exceptionList = new ArrayList<SQLException>(); StringBuffer sql = new StringBuffer(); int whichPriv = SQLTest.random.nextInt(tablePriv.length); sql.append("grant " + tablePriv[whichPriv] + " on " + tableName + " to " + grantees); Log.getLogWriter().info("security statement is " + sql.toString()); try { Statement stmt = dConn.createStatement(); stmt.execute(sql.toString()); // execute authorization dConn.commit(); stmt.close(); } catch (SQLException se) { SQLHelper.handleDerbySQLException(se, exceptionList); } try { Statement stmt = gConn.createStatement(); stmt.execute(sql.toString()); // execute authorization gConn.commit(); stmt.close(); } catch (SQLException se) { SQLHelper.handleGFGFXDException(se, exceptionList); } SQLHelper.handleMissedSQLException(exceptionList); }
public void doDDLOp(Connection dConn, Connection gConn) { boolean success = false; int maxNumOfTries = 1; ArrayList<SQLException> exList = new ArrayList<SQLException>(); String tableName = tableNames[SQLTest.random.nextInt(tableNames.length)]; String routineName = (hasRoutine) ? getRoutineNames(dConn, gConn) : null; StringBuffer aStr = new StringBuffer(); // grant or revoke String act = action[SQLTest.random.nextInt(action.length)]; aStr.append(act); // rest of the authorization stmt if (routineName == null) aStr.append(getAuthForTables(tableName, act)); else aStr.append( SQLTest.random.nextBoolean() ? getAuthForTables(tableName, act) : getAuthForRoutines(routineName, act)); if (dConn != null) { try { success = applySecurityToDerby(dConn, aStr.toString(), exList); // insert to derby table int count = 0; while (!success) { if (count >= maxNumOfTries) { Log.getLogWriter() .info("Could not get the lock to finish grant/revoke stmt, abort this operation"); return; } exList.clear(); success = applySecurityToDerby( dConn, aStr.toString(), exList); // retry insert to derby table count++; } applySecurityToGFE(gConn, aStr.toString(), exList); // insert to gfe table SQLHelper.handleMissedSQLException(exList); gConn.commit(); dConn.commit(); } catch (SQLException se) { SQLHelper.printSQLException(se); throw new TestException("execute security statement fails " + TestHelper.getStackTrace(se)); } // for verification } else { try { applySecurityToGFE(gConn, aStr.toString()); // insert to gfe table gConn.commit(); } catch (SQLException se) { SQLHelper.printSQLException(se); throw new TestException("execute security statement fails " + TestHelper.getStackTrace(se)); } } // no verification }
public static void turnOnAuthorization(Connection dConn, Connection gConn) { String sql = "CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY( " + "'derby.database.sqlAuthorization', 'true')"; ArrayList<SQLException> exList = new ArrayList<SQLException>(); if (dConn != null) { turnOnDerbyAuthorization(dConn, sql, exList); turnOnGFEAuthorization(gConn, sql, exList); SQLHelper.handleMissedSQLException(exList); } else turnOnGFEAuthorization(gConn, sql); }
public void assignSelectToMe(Connection dConn, Connection gConn, int tid) { boolean success = false; int maxNumOfTries = 1; ArrayList<SQLException> exList = new ArrayList<SQLException>(); // for load test String sql = "grant select on trade.buyorders to thr_" + tid; if (dConn != null) { try { success = applySecurityToDerby(dConn, sql, exList); // insert to derby table int count = 0; while (!success) { if (count >= maxNumOfTries) { Log.getLogWriter() .info("Could not get the lock to finish grant/revoke stmt, abort this operation"); return; } exList.clear(); success = applySecurityToDerby(dConn, sql, exList); // retry insert to derby table count++; } applySecurityToGFE(gConn, sql, exList); // insert to gfe table SQLHelper.handleMissedSQLException(exList); gConn.commit(); dConn.commit(); } catch (SQLException se) { SQLHelper.printSQLException(se); throw new TestException("execute security statement fails " + TestHelper.getStackTrace(se)); } // for verification } else { try { applySecurityToGFE(gConn, sql); // insert to gfe table gConn.commit(); } catch (SQLException se) { SQLHelper.printSQLException(se); throw new TestException("execute security statement fails " + TestHelper.getStackTrace(se)); } } // no verification }