您的位置:首页 > 其它

EMC-- DFC --Sessions and Session Managers

2014-05-27 21:47 260 查看
DFC - Documentum Foundation Classes
位于Content server和client 之间。 用来做服务端业务逻辑和客制。
BOF- Business Object Framework.
模组。 最重要的两个模组是
1. TBOs --type based objects
2. SBOs-- service based objects
3. Aspect -- similar to TBOs. enable you to attach properties and behavior on an instance-by-instace basic.

DFC的运行点
1. 运行content server的机器。 as call from a mthod.

2. 中间层系统。 as an application server

DFC除了DfClientC和 异常类及其子类(DfException),大部分类都是通过工厂方法 实例化。

如何得到一个session
1. 通过 IDfClient.newSessionMangager的方式创建一个IDfSessionManger
2. 从session manager中得到一个session. IDfSessionManger.newSession

3. session使用完成之后需要释放
4. IDfSessionManger.getSession 得到的是公用的session

clientx.getLocalClient() 这个方法会去找dfc的配置文件

IDfSessionManager.ALL_DOCBASES . 对于所有的docbases, 设置单一的身份
如果session manager有多重身份, 可以懒加载。 但是需要确认是否以及有此身份,如果有需先清空之前的身份信息,才能setIdentity否则会报错误。

package com.dev.guide.ch2;

import com.documentum.com.DfClientX;
import com.documentum.com.IDfClientX;
import com.documentum.fc.client.DfServiceException;
import com.documentum.fc.client.IDfClient;
import com.documentum.fc.client.IDfSessionManager;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.IDfLoginInfo;

public class TestSession {

	private IDfSessionManager sessionManager;

	IDfClientX clientx;

	public IDfSessionManager getSessionManager() {
		sessionManager = null;
		try {
			clientx = new DfClientX();
			IDfClient client = clientx.getLocalClient();
			sessionManager = client.newSessionManager();
		} catch (DfException e) {
			e.printStackTrace();
		}
		return sessionManager;
	}

	public IDfSessionManager getSessionManager(String userName, String password) {
		sessionManager = null;
		try {
			clientx = new DfClientX();
			IDfClient client = clientx.getLocalClient();
			sessionManager = client.newSessionManager();
			IDfLoginInfo loginInfo = clientx.getLoginInfo();
			loginInfo.setUser(userName);
			loginInfo.setPassword(password);
			sessionManager.setIdentity(IDfSessionManager.ALL_DOCBASES, loginInfo);
		} catch (DfException e) {
			e.printStackTrace();
		}
		return sessionManager;
	}

	public void addIdentity(String repository, String userName, String password) {
		try {
			IDfLoginInfo loginInfo = clientx.getLoginInfo();
			loginInfo.setUser(userName);
			loginInfo.setPassword(password);
			if (sessionManager.hasIdentity(repository)) {
				sessionManager.clearIdentity(repository);
			}
			sessionManager.setIdentity(repository, loginInfo);
		} catch (DfServiceException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		TestSession testSession = new TestSession();
		testSession.getSessionManager("dm_bof_registry", "dctmecmq");
		testSession.addIdentity("ecmq", "dm_bof_registry", "dctmecmq");

	}

}

setIdentity不会验证登录信息的正确与否, 而是到getSession或是newSession的时候验证。但是你可以调用IDfSessionManger.authenticate的方法来验证。

getSession -- 得到共享session
newSession --得到私有的session
session需及时释放,尽量不要保存使用。 释放时放在 finally的程序段里。
一些遗留的程序直接从IDfClient获取sessions, 在这种状况下,使用IDfSession.disconnet的方式释放。

当引用一个存在的session , 像session作为type object的数据成员的时候, 不能够释放session.
比如通过这种方式获取的: IDfTypedObject.getSession
同一个session不能被释放两次 ,否则会抛出异常。
session释放之后也不能再使用了。

根据现有的session,得到另外一个repository有两种方式
1. 通过session得到sessionmanger, 使用sessionmanager传入repository, 获取session. 两个session都需要释放。
2. 使用relateSession的方式。session.getRelatedSession. 这种session不需要显示释放。
早期DFC使用 setDocbaseScope方式创建子连接的方式不再推荐使用。

original 和object sessions

一般来说, 两者是一样的

事务
分为 session manager level 和 session level

IDfSessionManagerConfig
IDfSessionManager.getConfig的方式获得。
可以设置本地话, 时区,动态组,和应用程式代码设置。

使用登录门票获取session
login ticket可以使用IDfSession里的方法获取
1. 第一个使用是已经有了认证session, 需要链接进入WDK-based的程序。 使用URL方式传入, 就不需要再登录了。
2. 第二个使用是授予其他人权限。一般用在流程方法等。
获得login tickets的方法
1. getLoginTicket -- 不需要获得ticket的session是super user
2. getLoginTicketEx -- 获得ticket的session是super user,

3. getLoginTicketForUser -- 获得ticket的session是属于superuser. 当前登录的人是superuser

principal authentication support

Maintaining state in a session manager
可以使session manager维持一个repository object的状态。 通过调用IDfTypedObject的 setSessionManager.
这个方法把对象的状态从session复制到session manager, 这样的话,session 断开也不会导致对象无效。
注意:谨慎使用setSessionManager,这是一个花销很大的方法。
但是,使用setSessionManager比使用 begin/end client control 的机制防止session从session manager断开要好。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐