-
Notifications
You must be signed in to change notification settings - Fork 160
/
JpaStepStatusDAO.java
60 lines (46 loc) · 2.14 KB
/
JpaStepStatusDAO.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*******************************************************************************
* Copyright (c) 2019 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.job.engine.jbatch.persistence.jpa;
import com.ibm.jbatch.container.status.StepStatus;
import org.eclipse.kapua.commons.jpa.EntityManager;
import javax.persistence.TypedQuery;
import java.util.List;
public class JpaStepStatusDAO {
private JpaStepStatusDAO() {
}
public static JpaStepStatus create(EntityManager em, long stepExecutionId) {
JpaStepStatus jpaStepStatus = new JpaStepStatus();
jpaStepStatus.setStepExecutionId(stepExecutionId);
jpaStepStatus.setObj(new StepStatus(stepExecutionId));
em.persist(jpaStepStatus);
em.flush();
em.refresh(jpaStepStatus);
return jpaStepStatus;
}
public static void update(EntityManager em, long stepExecutionId, StepStatus stepStatus) {
JpaStepStatus jpaStepStatus = find(em, stepExecutionId);
jpaStepStatus.setObj(stepStatus);
em.merge(jpaStepStatus);
em.flush();
em.refresh(jpaStepStatus);
}
public static JpaStepStatus find(EntityManager em, long jobInstanceId) {
return em.find(JpaStepStatus.class, jobInstanceId);
}
public static JpaStepStatus getStepStatusByJobInstance(EntityManager em, long jobInstanceId, String stepName) {
TypedQuery<JpaStepStatus> selectQuery = em.createNamedQuery("StepStatus.findByJobInstanceIdStepName", JpaStepStatus.class);
selectQuery.setParameter("jobInstanceId", jobInstanceId);
selectQuery.setParameter("stepName", stepName);
List<JpaStepStatus> queryResult = selectQuery.getResultList();
return queryResult.isEmpty() ? null : queryResult.get(0);
}
}