Class ProgrammaticService
To run a procedure from a user service, it is recommended to use
ServiceContext.execute(Procedure)
instead of this class,
unless input parameters have to be specified (e.g. to have
a specific behavior in triggers).
Using this class
In order to create an instance of this class, the external program must provide an authenticated session and a dataspace or snapshot:
ProgrammaticService.createForSession(Session, AdaptationHome)
In order to update the repository for import or export of data, a Procedure.execute()
method must be called in a transactional container via:
ProgrammaticService.execute(Procedure)
Code sample
public class MyBatch implements Batch
{
public void executeBatch(Repository aRepository) throws Exception {
Session session = aRepository.createSessionFromLoginPassword("xxx", "yyy");
AdaptationHome dataSpace = aRepository.lookupHome(BranchKey.forName("myBranch"));
ProgrammaticService svc = ProgrammaticService.createForSession(session, dataSpace);
// optional
svc.setSessionTrackingInfo("My Script Sample");
Procedure proc = new Procedure()
{
public void execute(ProcedureContext aContext) throws Exception
{
// ...
}
};
ProcedureResult result = svc.execute(proc);
if (result.hasErrors())
// ...
else
//...
}
}
}
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic ProgrammaticService
createForSession
(Session aSession, AdaptationHome aDataSpace) Instantiates a service that will execute within the specified session in the specified dataspace.static ProgrammaticService
createForSession
(Session aSession, AdaptationHome aDataSpace, Map<String, String> someInputParameters) Instantiates a service that will be executed in the specified dataspace, and within a session cloned fromaSession
with specific input parameters.Executes the specified procedure.Returns the current dataspace or snapshot of this service.Returns the current session of this service.void
setSessionTrackingInfo
(String aTrackingInfo) Specifies the session's tracking info.
-
Method Details
-
createForSession
Instantiates a service that will execute within the specified session in the specified dataspace. -
createForSession
public static ProgrammaticService createForSession(Session aSession, AdaptationHome aDataSpace, Map<String, String> someInputParameters) Instantiates a service that will be executed in the specified dataspace, and within a session cloned fromaSession
with specific input parameters.This is the same as
ProgrammaticService.createForSession(aSession.clone(someInputParameters), aDataSpace)
. -
execute
Executes the specified procedure. It calls in a transactional container the implementation ofProcedure.execute(ProcedureContext)
.- Returns:
- the result of the execution (particularly, whether it has thrown an exception).
-
getCurrentHome
Returns the current dataspace or snapshot of this service. -
getSession
Returns the current session of this service. -
setSessionTrackingInfo
Specifies the session's tracking info.Note: This method has a side-effect: if the underlying session is obtained through a user interface container (for instance
UISessionContext.getSession()
), this method can impact all future events of this session. In such cases, it is recommended to reset the tracking info to its previous value once the work has been done.- See Also:
-