Database Reference
In-Depth Information
the corresponding check box on the Admin Users screen. Before we got to this point, in the
userComboBox_actionPerformed()
method, we called the
blankAll()
method, which had deselected all of
the check boxes. So at the end of this procedure, the only check boxes that are selected are those
representing proxy privileges that are granted to the selected user.
Listing 12-31.
Query to get Administrative Proxy Grants for the Selected User
rs = stmt.executeQuery("SELECT INSTANCE, proxy, client " +
"FROM ojsaadm.instance_proxy_users ");
while (rs.next()) {
if (rs.getString(3).equalsIgnoreCase(userID)) {
if (rs.getString(2).equalsIgnoreCase("OJSAADM"))
ojsaadmCheckBox.setSelected(true);
if (rs.getString(2).equalsIgnoreCase("APPUSR"))
appusrCheckBox.setSelected(true);
if (rs.getString(2).equalsIgnoreCase("AVADMIN"))
avadminCheckBox.setSelected(true);
}
}
Save Updates to the Administrative Privileges
When the application user has selected a user and made changes to the administrative privilege check
boxes that are selected, he will need to save the changes. He does this by selecting the Save Updates
button. When that button is selected, the
saveButton_actionPerformed()
method is called. Once again,
the selected
userID
is pulled from the selected item in the
userComboBox
. A delayed thread is created with
the code in Listing 12-32 in its
run()
method.
This method is extensive because we are independently calling procedures to grant or revoke each
privilege represented by the check boxes on the Admin Users screen. We could have combined several of
these calls into a dynamic loop, but we wouldn't have saved much code, and the clarity would have been
diminished. The first step we take is to try to create the user on both the
orcl
and
apver
instances. The
user may already exist, but this is an easy enough step and assures the user both exists and has the
privileges needed to run our applications. We call three Oracle procedures to create the user—two
operate on the
orcl
instance (
sys.usr_role_adm_pkg.p_create_user_once
and
p_create_user_many
), and
one operates across a database link to the
apver
instance
(
ojsaadm.apver_usr_adm_pkg.p_create_apver_user
). Each of these procedure calls has the identical
syntax, so I'll only show the full syntax once. Some of the procedure calls take one parameter, the user
ID; some take two parameters, the user ID and the proxy user.
Listing 12-32.
Saving Updates to Administrative Privileges, Abbreviated
stmt = (OracleCallableStatement)conn.prepareCall(
"CALL sys.usr_role_adm_pkg.p_create_user_once(?)");
stmt.setString(1, userID);
stmt.executeUpdate();
if (stmt != null) stmt.close();
stmt = (OracleCallableStatement)conn.prepareCall(
"CALL sys.usr_role_adm_pkg.
p_create_user_many
(?)");
...