-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreatExamples.java
More file actions
44 lines (36 loc) · 1.17 KB
/
TreatExamples.java
File metadata and controls
44 lines (36 loc) · 1.17 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
package org.javaee7.chapter04.jsf;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
/**
*
* @author Juneau
*/
@ManagedBean
public class TreatExamples implements java.io.Serializable {
@PersistenceContext(unitName = "IntroToJavaEE7PU")
private EntityManager em;
public TreatExamples() {
}
public List<Map> factoryProductListing(){
Query qry = em.createQuery("SELECT a.name, a.type, a.color " +
"FROM Factory b JOIN TREAT(b.product AS WidgetA) a");
List<Object[]> results = qry.getResultList();
List data = new ArrayList<>();
if (!results.isEmpty()) {
for (Object[] result : results) {
HashMap resultMap = new HashMap();
resultMap.put("name", result[0]);
resultMap.put("type", result[1]);
resultMap.put("color", result[2]);
data.add(resultMap);
}
}
return data;
}
}