Obtain a Session Using Session Manager
| October 2005 | |
|
Software Environment
| Feature | Tested on |
| Operating System | Windows 2000 Server SP4 |
| Compiler | Sun JDK 1.4.2_08 |
| Runtime | Sun JRE 1.4.2_08 |
| DFC | 5.x |
| Content Server | 5.3 |
Abstract
This code snippet demonstrates obtaining a session using a session manager and releasing it.
Snippet
/*
* Created on Oct 10, 2005
*
* EMC Documentum Developer Program 2005
*/
package com.documentum.devprog.snippets.session;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.IDfLoginInfo;
import com.documentum.fc.client.DfClient;
import com.documentum.fc.client.IDfClient;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSessionManager;
import com.documentum.com.DfClientX;
import com.documentum.com.IDfClientX;
public class ObtainingASession
{
/**
* @param args
*/
public static void main(String[] args)
{
try
{
String username="dmadmin";
String password="dmadmin";
String repoName="devprog";
obtainASession(username,password,repoName);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
/**
* Gets a session from the session manager, uses it and
* releases it back to the session manager.
* @param username
* @param password
* @param repoName
* @throws DfException
*/
private static void obtainASession(String username, String password,
String repoName) throws DfException
{
IDfSessionManager sessMgr = null;
IDfSession sess = null;
try
{
IDfClientX clientX = new DfClientX();
// create login info
IDfLoginInfo li = clientX.getLoginInfo();
li.setUser(username);
li.setPassword(password);
// create session manager and set identity
IDfClient localClient = DfClient.getLocalClient();
sessMgr = localClient.newSessionManager();
sessMgr.setIdentity(repoName, li);
// get session and use it
sess = sessMgr.getSession(repoName);
System.out.println("Session id: " + sess.getSessionId());
System.out.println("Repository Name: " + sess.getDocbaseName());
System.out.println("Database Name: " + sess.getDBMSName());
//A session needs to be released once its use is complete
//The release of the session has been put in the finally clause.
}
finally
{
if (sessMgr != null && sess != null)
{
sessMgr.release(sess);
}
}
}
}
|
Using the code
The above code snippet comes with a main method and is thus a standalone program. To use it, copy-paste the entire code into a new Java class created in your IDE. Adjust the package and class name of the pasted code according to your preference. Change the username,password, repository name and any other necessary variables. Compile and run the code. For details on setting up your IDE for DFC development, refer to the article Setting up a DFC Development Environment
Note:The above code demonstrates a specific piece of functionality and is not meant to be a complete solution
|