MicroStrategy ONE
Disconnecting Users and Database Connections
The sample code below illustrates how to disconnect a specific set of users and database connections. While it would be rare for a GUI to allow a user to delete both users and database connections with the same click, this example is included to demonstrate how flexible the MonitorManipulator is when dealing with deletion of jobs and disconnection of users and database connections. A common use case for this type of API interaction is a situation in which a user highlights a set of items and clicks the delete option.
// create a WebObjectsFactory instance
WebObjectsFactory factory = WebObjectsFactory.getInstance();
// Get the user connection source
UserConnectionSource userSource = (UserConnectionSource)
factory.getMonitorSource(EnumWebMonitorType.WebMonitorTypeUserConnection);
// Get the user connection manipulator
UserConnectionManipulator userManipulator = userSource.getManipulator();
String sessionID1 = "[First session ID]";
String sessionID2 = "[Second session ID]";
int projectID = 100; // a project ID
// Add a batch task to disconnect the project in the first session
userManipulator.addDisconnectionTask(sessionID1, projectID);
// Add another batch task to disconnect all projects associated with the second session
userManipulator.addDisconnectionTask(sessionID2);
try {
userManipulator.submit();
} catch (WebObjectsAdminException woae) {
woae.printStackTrace();
} catch (MonitorManipulationException mme) {
// We have failure in disconnecting user connection, so we display the failure
MonitorManipulationFailure[] mmf = mme.getFailures();
displayFailure(mmf);
}
// Get the DB connection source
DBConnectionSource dbSource = (DBConnectionSource) factory.getMonitorSource(EnumWebMonitorType.WebMonitorTypeDBConnection);
// Obtain the DB connection manipulator
DBConnectionManipulator dbManipulator = dbSource.getManipulator();
String dbConnectionDSSID = "[DB connection DSSID]";
int dbConnectionID = 11; // a dB connection ID
try {
// Directly disconnect the Db connection without batch operation
dbManipulator.disconnect(dbConnectionID, dbConnectionDSSID);
} catch (WebObjectsAdminException woae) {
woae.printStackTrace();
} catch (MonitorManipulationException mme) {
// We have failure in disconnecting the DB connection, so we display the failure
MonitorManipulationFailure[] mmf = mme.getFailures();
displayFailure(mmf);
}