使用dfc运行DQL并取得相应sql的代码
package com.client.example;
import com.documentum.com.DfClientX;
import com.documentum.fc.client.DfClient;
import com.documentum.fc.client.DfQuery;
import com.documentum.fc.client.IDfClient;
import com.documentum.fc.client.IDfCollection;
import com.documentum.fc.client.IDfQuery;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSessionManager;
import com.documentum.fc.client.IDfTypedObject;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.DfLoginInfo;
import com.documentum.fc.common.IDfAttr;
import com.documentum.fc.common.IDfLoginInfo;
public class DFCTest {
private static final String DOCBASE = "Rep1";
private static final String USERNAME = "Administrator";
private static final String PASSWORD = "password";
/**
* @param args
*/
public static void main(String[] args) {
IDfSessionManager sessionMgr = null;
IDfSession session = null;
DfClientX clientx;
IDfClient client;
try {
clientx = new DfClientX();
System.out.println("Using DFC version : " + clientx.getDFCVersion());
client = DfClient.getLocalClient();
sessionMgr = client.newSessionManager();
// Setup login details.
IDfLoginInfo login = new DfLoginInfo();
login.setUser(USERNAME);
login.setPassword(PASSWORD) ;
login.setDomain(null);
sessionMgr.setIdentity(DOCBASE, login);
session = sessionMgr.newSession(DOCBASE);
if(session == null || !session.isConnected())
{
System.out.println("Failed conecting to Documentum");
if(session != null)
{
System.out.println("Session message: " + session.getMessage(1));
}
return;
}
System.out.println("Server version: " + session.getServerVersion());
//Now, once we're connected to the Documentum DocBase, we'll list all the cabinets:
IDfQuery query = new DfQuery();//clientx.getQuery();
query.setDQL("SELECT r_object_id, object_name, title FROM dm_cabinet");
IDfCollection queryRsult = query.execute(session,DfQuery.READ_QUERY);
while (queryRsult.next())
{
// Spin through the attributes
for (int i = 0; i < queryRsult.getAttrCount(); i++)
{
IDfTypedObject typedObj = queryRsult.getTypedObject();
IDfAttr attr = queryRsult.getAttr(i);
System.out.println("Attribute Name: " + attr.getName()
+ "Attribute Value: " + typedObj.getString(attr.getName()));
}
}
queryRsult.close();
//get sql
IDfCollection coll;
String sqlResult = "";
coll = session.apply(null, "GET_LAST_SQL", null, null, null);
if(coll.next())
{
sqlResult = coll.getString("result");
}
coll.close();
System.out.println(sqlResult);
if (session != null)
{
sessionMgr.release(session);
}
} catch (DfException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}