Docbase methods can be run in a number of ways:
EXECUTE do_method
apply
Apart from the above mechanisms, you can also call and run methods by making DFC calls, as we will see in this example.
Create a Java file and save it as RunningMethodThroughDFC.java
.
Declare constants, storing the name of the method and its associated job and the method arguments as shown in the code below.
We will be running the Data Dictionary Publisher method via DFC code in this example. This administration tool provided by Documentum publishes the Content Server data dictionary information to client applications. Recall our earlier discussion of the Data Dictionary in Chapter 3.
import com.documentum.fc.client.*; import com.documentum.fc.common.*; import java.io.IOException; public class RunningMethodThroughDFC{ static final String methodName = "dm_DataDictionaryPublisher"; static final String jobName = "dm_DataDictionaryPublisher"; static final String methodArguments = "-docbase_name dev_doc.dev_doc -user_name documentum -method_trace_level 5"; //Main method public static void main(String args[]){
Note that the method arguments for the Data Dictionary tool shown are docbase_name
(dev_doc.dev_doc
, i.e. <server>.<Docbase name>), user_name
(documentum, i.e. Docbase user used to run the method), and method_trace_level
(5, i.e. tracing level for the method execution).
Establish a Docbase session first and then follow the code snippet shown below:
IDfQuery q = null; IDfCollection coll = null; String methodCmd = null; String methResult = null; String methObjectId = null; // Fetching method reference q = new DfQuery(); q.setDQL("select r_object_id from dm_method where object_name='" + methodName + "'"); coll = q.execute(session, DfQuery.DF_READ_QUERY); while (coll.next()) { methObjectId = coll.getId("r_object_id").toString(); } coll.close(); System.out.println("Object ID of the method: " + methObjectId ); // Fetching associated job reference IDfQuery qry = null; IDfCollection colln = null; String jobObjectId = null; qry = new DfQuery(); qry.setDQL("select r_object_id from dm_job where object_name='" + jobName + "'"); colln = qry.execute(session, DfQuery.DF_READ_QUERY); while (colln.next()) { jobObjectId = colln.getId("r_object_id").toString(); } colln.close(); methodCmd="DO_METHOD,METHOD,S," + methodName + ",TIME_OUT,I,200,SAVE_RESULTS,B,T,ARGUMENTS,S," + methodArguments + " -job_id " + jobObjectId; //Obtaining handle to the method IDfId sysObjID = new DfId(methObjectId); IDfSysObject sysObject = (IDfSysObject)session.getObject(sysObjID); // Executing the method methResult = sysObject.apiGet("apply", methodCmd); System.out.println("Result of executing the method: " + methResult ); sysObject.save(); System.out.println("method executed successfully!!"); }catch(Exception e){ System.out.println("main::Exception is " + e.getMessage()); } finally { sMgr.release( session ); } } }
The anatomy of the DFC code is discussed below:
q = new DfQuery();
This gets a reference to an IDfQuery
object to run DQL queries against the Docbase.
q.setDQL("select r_object_id from dm_method where object_name='" + methodName + "'");
This calls the setDQL()
method of IDfQuery
object, passing it the DQL query to be executed as a parameter. Ensure that the DQL query is correct in terms of its syntax.
coll = q.execute(session, DfQuery.DF_READ_QUERY);
This calls the execute()
method of the IDfQuery
object, passing it the Docbase session and the type of query to be executed. In our case, since we need to simply retrieve an object reference from Docbase (in other words a read-only select query), we specify the query type as DfQuery.DF_READ_QUERY
.
while (coll.next()) {
Executing the DQL query returns a collection result (IDfCollection
object).
Iterate through the collection by calling the next()
method until it returns false
.
It is good practice to close the collection to conserve system resources.
methObjectId = coll.getId("r_object_id").toString();
We call the method getId()
of IDfTypedObject
object to get the object ID (r_object_id
) of the retrieved Data Dictionary Publisher method.
IDfQuery qry = null; IDfCollection colln = null; String jobObjectId = null; qry = new DfQuery(); qry.setDQL("select r_object_id from dm_job where object_name='" + jobName + "'"); colln = qry.execute(session, DfQuery.DF_READ_QUERY); while (colln.next()) { jobObjectId = colln.getId("r_object_id").toString(); } colln.close();
In the above lines we obtain the object ID of the associated Data Dictionary Publisher job.
methodCmd="DO_METHOD,METHOD,S," + methodName + ",TIME_OUT,I,200,SAVE_RESULTS,B,T,ARGUMENTS,S," + methodArguments + " -job_id " + jobObjectId;
We define the method execution command arguments as follows:
DO_METHOD
is used to execute Docbase scripts and methods.METHOD
signifies that a method needs to be executed.S
indicates that the data type for method name is string
.TIME_OUT
signifies the time-out length in seconds for method execution.I
indicates that the data type for time out is integer
.200
indicates the time-out period in seconds for the method.SAVE_RESULTS
indicates if you want the execution results to be saved in a document in Docbase.B
indicates a Boolean data type (true or false) for the SAVE_RESULTS
option.T
stands for option true, asking for the results to be saved in a document.ARGUMENTS
signifies the command-line arguments for the method execution.S
indicates that the data type for method arguments is string
.job_id
argument captures the object ID of the associated Data Dictionary Publisher job.The following statement calls the apiGet()
method of IDfPersistentObject
object to execute the apply
server API call, passing it the arguments we had constructed for methodCmd
.
methResult = sysObject.apiGet("apply", methodCmd)
A result object is returned as the result of executing the method.
When you compile and execute the RunningMethodThroughDFC.java
code, the Data Dictionary Publisher method is executed. If you selected the checkbox against Trace Launch field in the method (refer to figure 23.3), you can see the trace for the method execution in the Docbase server logs when the above DFC code is run.
Note that the Data Dictionary Publisher method can be seen in Documentum Administrator by browsing to Administration | Job Management | Methods.
18.223.172.191