[JBoss jBPM] - Re: Can I get to the parent process, given a sub-process?
by avbentem
GraphElement#getParentChain is documented to return "this graph element plus all the parents ordered by age". However, this does not seem to work when using sub-processes: the parents of the parent process-state(s) are not returned.
To me, the "ordered by age" in the documentation suggests that getParents/getParentChain return runtime information, knowing about how a specific process got invoked, and thus also returning that information... So, maybe either the documentation can be enhanced to make clear that any super process is not taken into account. Or, if we'd expect the super process(es) to be included as well, then the current implementation has a bug.
Any ideas on this?
For example:
// NOTE: not thoroughly tested
| public String getElementHistory(GraphElement element) {
| StringBuffer s = new StringBuffer();
| List<GraphElement> parentChain = element.getParentChain();
| if (parentChain != null) {
| for (GraphElement parent : parentChain) {
| if (s.length() != 0) {
| s.append(" -> ");
| }
| s.append(parent.getName());
| s.append(" [" + parent.getClass().getSimpleName() + "]");
| }
| }
| return s.toString();
| }
This prints
task1 [TaskNode] -> my-sub-process [ProcessDefinition]
...when invoked using
log.info(getElementHistory(taskInstance.getToken().getNode()));
...from a task-start event in the example posted earlier in this thread:
<process-definition xmlns="" name="my-sub-process">
| :
| <task-node name="task1">
| <task name="task1">
| <event type="task-start">
| <action name="taskStart" expression="#{...}" />
| </event>
| ...
| </task>
| :
Above, it doesn't matter whether my-sub-process is started stand-alone, or by some parent process: the code does not iterate into the parent process.
Of course, one could use getSuperProcessToken to iterate into the parent process, using the processInstance rather than a token from the taskInstance. Like:
// NOTE: not thoroughly tested
| public String getProcessHistory(ProcessInstance instance) {
| StringBuffer s = new StringBuffer();
|
| Token superToken = instance.getSuperProcessToken();
| if (superToken != null) {
| ProcessInstance superInstance = superToken.getProcessInstance();
| s.append(getHistory(superInstance));
| }
|
| List<GraphElement> parentChain =
| instance.getProcessDefinition().getParentChain();
| if (parentChain != null) {
| for (GraphElement parent : parentChain) {
| if (s.length() != 0) {
| s.append(" -> ");
| }
| s.append(parent.getName());
| }
| }
| return s.toString();
| }
For the example posted earlier, when passing the processInstance, this would print:
my-process -> my-sub-process
It's a bit harder to get the detailed node information though...
Arjan.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4039904#4039904
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4039904
19 years
[EJB 3.0] - Re: Problem with composite Primary key which is also a forei
by imranpariyani
I think i dint explain my problem that well ... will do it again
CREATE TABLE `parent` (
`id` int(11) NOT NULL auto_increment,
`sitename` varchar(40) NOT NULL,
PRIMARY KEY (`id`))
CREATE TABLE `child` (
`parent_id` int(11) NOT NULL,
`language` enum('EN,'DE','FR') NOT NULL default 'EN',
PRIMARY KEY (`parent_id`,`language`),
CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8
so as you see the parent_id in the child is a part of composite primary key and also a forigen key ..
so the childPk has the fileds parentId and language ...
and the child class must have the same exact properties as the childPk class and these properties are annotated with multiple @Id annotations..
everything works fine .. like update delete insert .. there is only a prob when i try to insert a new parent .. with the child collection initialized ..
If i first insert the parent with the child collection null and the insert the child collection after assigning the parent object which was inserted then it works fine .. but not if i insert new parent with child objects ... it throws this error of foreign key violation because it tries to insert the child with the foreign key parent id as 0
Regards,
Imran
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4039900#4039900
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4039900
19 years