-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f514f29
commit 554190a
Showing
15 changed files
with
431 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/org/jlab/jam/business/session/FacilityFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.jlab.jam.business.session; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.annotation.security.PermitAll; | ||
import javax.ejb.Stateless; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceContext; | ||
import javax.persistence.TypedQuery; | ||
import javax.persistence.criteria.*; | ||
import org.jlab.jam.persistence.entity.Facility; | ||
|
||
/** | ||
* @author ryans | ||
*/ | ||
@Stateless | ||
public class FacilityFacade extends AbstractFacade<Facility> { | ||
@PersistenceContext(unitName = "jamPU") | ||
private EntityManager em; | ||
|
||
@Override | ||
protected EntityManager getEntityManager() { | ||
return em; | ||
} | ||
|
||
public FacilityFacade() { | ||
super(Facility.class); | ||
} | ||
|
||
@PermitAll | ||
public Facility findByPath(String pathInfo) { | ||
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); | ||
CriteriaQuery<Facility> cq = cb.createQuery(Facility.class); | ||
Root<Facility> root = cq.from(Facility.class); | ||
|
||
List<Predicate> filters = new ArrayList<>(); | ||
|
||
filters.add(cb.equal(root.get("path"), pathInfo)); | ||
|
||
if (!filters.isEmpty()) { | ||
cq.where(cb.and(filters.toArray(new Predicate[] {}))); | ||
} | ||
|
||
cq.select(root); | ||
TypedQuery<Facility> q = getEntityManager().createQuery(cq).setFirstResult(0).setMaxResults(2); | ||
List<Facility> recordList = q.getResultList(); | ||
|
||
Facility facility = null; | ||
|
||
if (recordList.size() > 1) { | ||
throw new RuntimeException("Duplicate facility paths configured"); | ||
} | ||
|
||
if (recordList.size() > 0) { | ||
facility = recordList.get(0); | ||
} | ||
|
||
return facility; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.