-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJobsSession.java
More file actions
91 lines (77 loc) · 2.13 KB
/
JobsSession.java
File metadata and controls
91 lines (77 loc) · 2.13 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.javaee7.jpa.session;
import java.util.List;
import javax.ejb.Asynchronous;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.concurrent.Future;
import javax.ejb.AsyncResult;
import org.javaee7.entity.Jobs;
/**
*
* @author Juneau
*/
@Stateless
public class JobsSession extends AbstractFacade<Jobs> {
@PersistenceContext(unitName = "IntroToJavaEE7PU")
private EntityManager em;
private List<Jobs> jobList;
@Override
protected EntityManager getEntityManager() {
return em;
}
public JobsSession() {
super(Jobs.class);
}
/**
* Asynchronous session bean method for retrieving job database records
*/
@Asynchronous
public void retrieveJobs(){
Query qry = em.createQuery("select j from Jobs j");
List<Jobs> jobs = qry.getResultList();
for (Jobs job:jobs){
System.out.println(job.getTitle());
}
}
@Asynchronous
public Future<Boolean> obtainJobListing(){
Query qry = em.createQuery("select j from Jobs j");
List<Jobs> jobs = qry.getResultList();
if(jobs.size() > 0){
this.jobList = jobs;
return new AsyncResult<Boolean>(true);
} else {
return new AsyncResult<Boolean>(false);
}
}
/**
* @return the jobList
*/
public List<Jobs> getJobList() {
if(jobList == null || jobList.isEmpty()){
System.out.println("obtaining job listing");
obtainJobListing();
}
return jobList;
}
/**
* @return the jobList
*/
public List<Jobs> retrieveJobsSynchronously() {
Query qry = em.createQuery("select j from Jobs j");
List<Jobs> jobList = qry.getResultList();
return jobList;
}
/**
* @param jobList the jobList to set
*/
public void setJobList(List<Jobs> jobList) {
this.jobList = jobList;
}
}