There are 2 situations in which I would recommend that you close your connection to the database. The first is when the user logs out, and the second is when the user removes the portlet from his page. Viewpoint's SQL Scratchpad portlet deals with this problem in the exact same fashion.
To handle the situation where the user logs out of Viewpoint, you should write a Java class that implements the HttpSessionListener interface. This class should close the connection to the database in the sessionDestroyed method. This class then needs to be registered in the web.xml file as a listener.
public class PortletSessionListener implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent event) {
// Do nothing
}
public void sessionDestroyed(HttpSessionEvent event) {
// Retrieve and close your connection here
}
}
<!-- Fragment to add to web.xml -->
<listener>
<listener-class>com.teradata.viewpoint.portlets.myportlet.listener.PortletSessionListener</listener-class>
</listener>
The second situation to handle is when the user removes the portlet from the page. You will want to register a custom callback function in JavaScript that will be triggered when the portlet is removed. This callback function should make a call to a URL in your portlet which can be responsible for closing the connection to the database. Adding the server side code to expose this URL is something you should already be familiar with, so I will exclude any code samples for that here. You would want to add some code similar to the following to your summary.jsp page.
<script type="text/javascript">
TDPortalManager.onPortletRemove('${context}', function() {
// Make an AJAX call here to your disconnect URL here
});
</script>
Hope that helps!
There are 2 situations in which I would recommend that you close your connection to the database. The first is when the user logs out, and the second is when the user removes the portlet from his page. Viewpoint's SQL Scratchpad portlet deals with this problem in the exact same fashion.
To handle the situation where the user logs out of Viewpoint, you should write a Java class that implements the HttpSessionListener interface. This class should close the connection to the database in the sessionDestroyed method. This class then needs to be registered in the web.xml file as a listener.
The second situation to handle is when the user removes the portlet from the page. You will want to register a custom callback function in JavaScript that will be triggered when the portlet is removed. This callback function should make a call to a URL in your portlet which can be responsible for closing the connection to the database. Adding the server side code to expose this URL is something you should already be familiar with, so I will exclude any code samples for that here. You would want to add some code similar to the following to your summary.jsp page.
Hope that helps!