Query to store information from the jbpm to a db
vanz Oct 4, 2010 11:44 AMI have a TodoDoc.java document where I manage the process and from which I get 3 information to store in the db.
I also have a Workflow.java document that is the entity I have to put the 3 information.
I have a process definition. When I switch from one task to the next one I have to store in the database some information (like logged user, task description and name of the task). I have to put these information inside the entity (Workflow.java)
The task description should be put in the idDocumento of the entity, the user and the name of the task inside the idStato.
How can I create a query that would let me save these information inside the DB?
todoDoc.java
@Name("todoDoc") public class TodoDoc { private String description; private String nomeDoc = new String(); EntityManager entityManager; @In Credentials credentials; public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } @CreateProcess(definition = "todo") public void createTodo() { nomeDoc = description; } @CreateProcess(definition = "todo2") public void createTodo2() { nomeDoc = description; } @StartTask @EndTask public void conferma() { this.idprocesso(); System.out.println("Nome Documento: "+TaskInstance.instance().getDescription()); System.out.println("Stato Documento: "+TaskInstance.instance().getName()); System.out.println("User: "+credentials.getUsername()); // String query="INSERT INTO Workflow (documento_fk,statoDocumento_fk) VALUES (?,?)"; // entityManager.createQuery(query).executeUpdate(); // String query="INSERT INTO Workflow (documento_fk,statoDocumento_fk) VALUES("+TaskInstance.instance().getDescription()+","+TaskInstance.instance().getName()+")"; // entityManager.createQuery(query); } @StartTask @EndTask(transition = "rifiuta") public void rifiuta() { idprocesso(); } public void idprocesso() { if ("redazione".equals(TaskInstance.instance().getName())) { ProcessInstance.instance().getContextInstance().createVariable( "Var", TaskInstance.instance().getDescription().toString()); } nomeDoc = ProcessInstance.instance().getContextInstance().getVariable( "Var").toString(); } public String getNomeDoc() { return nomeDoc; } public void setNomeDoc(String nomeDoc) { this.nomeDoc = nomeDoc; } public EntityManager getEntityManager() { return entityManager; } public void setEntityManager(EntityManager entityManager) { this.entityManager = entityManager; } }
Workflow.java
@Entity public class Workflow implements Serializable { private Long id; private String name; private Documento documento; private StatoDocumento statoDocumento; private User user; @Id @GeneratedValue public Long getId() { return id; } public void setId(Long id) { this.id = id; } @Length(max = 20) public String getName() { return name; } public void setName(String name) { this.name = name; } @ManyToOne @JoinColumn(name="documento_fk") public Documento getDocumento() { return documento; } public void setDocumento(Documento documento) { this.documento = documento; } @ManyToOne @JoinColumn(name="statoDocumento_fk") public StatoDocumento getStatoDocumento() { return statoDocumento; } public void setStatoDocumento(StatoDocumento statoDocumento) { this.statoDocumento = statoDocumento; } @ManyToOne @JoinColumn(name="user_fk") public User getUser() { return user; } public void setUser(User user) { this.user = user; } }