Database Reference
In-Depth Information
static {
columnIdentifiers.add("Proxies");
}
static Vector appColumnIdentifiers = new Vector();
static {
appColumnIdentifiers.add("Applications");
}
static Hashtable<String, Vector> appsHashtable =
new Hashtable<String, Vector>();
The last static member we declare in Listing 12-34 is a Hashtable . The appsHashTable will have a key,
the proxy user name, and a value, the Vector of applications where that proxy user is used.
A DefaultTableModel assumes that each row may have multiple columns, so it does not handle data
as a simple list, even when there is only one column. Rather, in the case where Vectors are used, it
expects each row to be a Vector of data elements, one for each column. So in the end, the data we
provide to the table model in order to build our table will be a Vector of Vectors holding a list of
potentially multi-column rows.
Now that you know where we are headed in building the data Vectors for our tables, let's look at the
code from dataInit() that builds our available proxies list. This code is shown in Listing12-35. Look
closely at the while loop where we handle the ResultSet from our query. We instantiate a new
itemVector and populate it with one element, the first column of our ResultSet . The itemVector
represents a row in our table. Then we add the itemVector to our dataVector . The dataVector represents
a list of rows for the table. The last line in Listing 12-35 is a call to the available proxies table model
setDataVector() method that will populate the table.
Listing 12-35. Build Data for Available Proxies Table
rs = stmt.executeQuery(
"SELECT DISTINCT a.app_user FROM appsec.v_application_registry a " +
"WHERE a.app_user NOT IN ('APPVER','AVADMIN','APPSEC','OJSAADM') " +
"ORDER BY a.app_user");
// dataVector must be Vector of Vectors
Vector dataVector = new Vector();
Vector itemVector ;
while (rs.next()) {
itemVector = new Vector() ;
itemVector.add(rs.getString(1)) ;
dataVector.add(itemVector) ;
}
if (rs != null)
rs.close();
availableProxiesTM.setDataVector(dataVector, columnIdentifiers) ;
In the dataInit() method we also build the data for our applications for proxy table. The contents of
this table will change to match whatever proxy user is currently selected. For each proxy user, we will
have a Vector of Vectors to use to populate the table. Those Vectors of Vectors will be held as values in
appsHashTable that we can select with the key of the proxy user name.
Listing 12-36 shows the code used to build appsHashTable. In building the data, we again skip
administrative proxies that are handled by the Admin Users screen, and we skip proxies that
are used on the apver instance. We are prepared to call dataInit() multiple times, whenever
the data may have changed, i.e., after the Save Updates button is selected. Because we may be
rebuilding the appsHashTable, we start out by removing any existing content by calling the
 
Search WWH ::




Custom Search