Skip to content

Commit

Permalink
Google Java format
Browse files Browse the repository at this point in the history
  • Loading branch information
slominskir committed Oct 2, 2024
1 parent 9725673 commit fdb0ab1
Show file tree
Hide file tree
Showing 111 changed files with 8,589 additions and 8,247 deletions.
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
* text=auto
*.sh text eol=lf
* text eol=lf
*.png binary
*.bat text eol=crlf
9 changes: 8 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'war'
id 'war'
id "com.diffplug.spotless" version "6.25.0"
}

description = "Presentation app"
Expand Down Expand Up @@ -43,4 +44,10 @@ war {
String line -> line.replaceAll("@RELEASE_DATE@", releaseDate)
}
}
}

spotless {
java {
googleJavaFormat()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@
import javax.ejb.ApplicationException;

/**
*
* @author ryans
*/
@ApplicationException(inherited = true, rollback = true)
public class WebAppException extends Exception {
private final String userMessage;
private final String userMessage;

public WebAppException(String msg) {
super(msg);
this.userMessage = msg;
}

public WebAppException(String msg, Throwable cause) {
super(msg, cause);
this.userMessage = msg;
}
public WebAppException(String msg) {
super(msg);
this.userMessage = msg;
}

public String getUserFriendlyMessage() {
return userMessage;
}
public WebAppException(String msg, Throwable cause) {
super(msg, cause);
this.userMessage = msg;
}

public String getUserFriendlyMessage() {
return userMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,61 @@
import javax.persistence.criteria.Root;

/**
*
* @author ryans
* @param <T>
*/
public abstract class AbstractFacade<T> {
private final Class<T> entityClass;
private final Class<T> entityClass;

public AbstractFacade(Class<T> entityClass) {
this.entityClass = entityClass;
}
public AbstractFacade(Class<T> entityClass) {
this.entityClass = entityClass;
}

protected abstract EntityManager getEntityManager();
protected abstract EntityManager getEntityManager();

@PermitAll
public void create(T entity) {
getEntityManager().persist(entity);
}
@PermitAll
public void create(T entity) {
getEntityManager().persist(entity);
}

@PermitAll
public T edit(T entity) {
return getEntityManager().merge(entity);
}
@PermitAll
public T edit(T entity) {
return getEntityManager().merge(entity);
}

@PermitAll
public void remove(T entity) {
getEntityManager().remove(getEntityManager().merge(entity));
}
@PermitAll
public void remove(T entity) {
getEntityManager().remove(getEntityManager().merge(entity));
}

@PermitAll
public T find(Object id) {
return getEntityManager().find(entityClass, id);
}
@PermitAll
public T find(Object id) {
return getEntityManager().find(entityClass, id);
}

@PermitAll
public List<T> findAll() {
CriteriaQuery<T> cq = getEntityManager().getCriteriaBuilder().createQuery(entityClass);
cq.select(cq.from(entityClass));
return getEntityManager().createQuery(cq).getResultList();
}
@PermitAll
public List<T> findAll() {
CriteriaQuery<T> cq = getEntityManager().getCriteriaBuilder().createQuery(entityClass);
cq.select(cq.from(entityClass));
return getEntityManager().createQuery(cq).getResultList();
}

@PermitAll
public List<T> findRange(int[] range) {
CriteriaQuery<T> cq = getEntityManager().getCriteriaBuilder().createQuery(entityClass);
cq.select(cq.from(entityClass));
TypedQuery<T> q = getEntityManager().createQuery(cq);
q.setMaxResults(range[1] - range[0]);
q.setFirstResult(range[0]);
return q.getResultList();
}
@PermitAll
public List<T> findRange(int[] range) {
CriteriaQuery<T> cq = getEntityManager().getCriteriaBuilder().createQuery(entityClass);
cq.select(cq.from(entityClass));
TypedQuery<T> q = getEntityManager().createQuery(cq);
q.setMaxResults(range[1] - range[0]);
q.setFirstResult(range[0]);
return q.getResultList();
}

@PermitAll
public int count() {
CriteriaQuery<Long> cq = getEntityManager().getCriteriaBuilder().createQuery(Long.class);
Root<T> rt = cq.from(entityClass);
cq.select(getEntityManager().getCriteriaBuilder().count(rt));
Query q = getEntityManager().createQuery(cq);
return ((Long) q.getSingleResult()).intValue();
}

@PermitAll
public int count() {
CriteriaQuery<Long> cq = getEntityManager().getCriteriaBuilder().createQuery(Long.class);
Root<T> rt = cq.from(entityClass);
cq.select(getEntityManager().getCriteriaBuilder().count(rt));
Query q = getEntityManager().createQuery(cq);
return ((Long) q.getSingleResult()).intValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@
import org.jlab.presenter.persistence.entity.AccActivityRecord;

/**
*
* @author ryans
*/
@Stateless
public class AccActivityRecordFacade extends AbstractFacade<AccActivityRecord> {
@PersistenceContext(unitName = "presenterPU")
private EntityManager em;
@PersistenceContext(unitName = "presenterPU")
private EntityManager em;

@Override
protected EntityManager getEntityManager() {
return em;
}
@Override
protected EntityManager getEntityManager() {
return em;
}

public AccActivityRecordFacade() {
super(AccActivityRecord.class);
}

public AccActivityRecordFacade() {
super(AccActivityRecord.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@
import org.jlab.presenter.persistence.entity.AccessRecord;

/**
*
* @author ryans
*/
@Stateless
public class AccessRecordFacade extends AbstractFacade<AccessRecord> {
@PersistenceContext(unitName = "presenterPU")
private EntityManager em;
@PersistenceContext(unitName = "presenterPU")
private EntityManager em;

@Override
protected EntityManager getEntityManager() {
return em;
}
@Override
protected EntityManager getEntityManager() {
return em;
}

public AccessRecordFacade() {
super(AccessRecord.class);
}

public AccessRecordFacade() {
super(AccessRecord.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@
import org.jlab.presenter.persistence.entity.BeamToHallRecord;

/**
*
* @author ryans
*/
@Stateless
public class BeamToHallRecordFacade extends AbstractFacade<BeamToHallRecord> {
@PersistenceContext(unitName = "presenterPU")
private EntityManager em;
@PersistenceContext(unitName = "presenterPU")
private EntityManager em;

@Override
protected EntityManager getEntityManager() {
return em;
}
@Override
protected EntityManager getEntityManager() {
return em;
}

public BeamToHallRecordFacade() {
super(BeamToHallRecord.class);
}

public BeamToHallRecordFacade() {
super(BeamToHallRecord.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@
import org.jlab.presenter.persistence.entity.BodySlide;

/**
*
* @author ryans
*/
@Stateless
public class BodySlideFacade extends AbstractFacade<BodySlide> {
@PersistenceContext(unitName = "presenterPU")
private EntityManager em;
@PersistenceContext(unitName = "presenterPU")
private EntityManager em;

@Override
protected EntityManager getEntityManager() {
return em;
}
@Override
protected EntityManager getEntityManager() {
return em;
}

public BodySlideFacade() {
super(BodySlide.class);
}

public BodySlideFacade() {
super(BodySlide.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@
import org.jlab.presenter.persistence.entity.BtaRecord;

/**
*
* @author ryans
*/
@Stateless
public class BtaRecordFacade extends AbstractFacade<BtaRecord> {
@PersistenceContext(unitName = "presenterPU")
private EntityManager em;
@PersistenceContext(unitName = "presenterPU")
private EntityManager em;

@Override
protected EntityManager getEntityManager() {
return em;
}
@Override
protected EntityManager getEntityManager() {
return em;
}

public BtaRecordFacade() {
super(BtaRecord.class);
}

public BtaRecordFacade() {
super(BtaRecord.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,33 @@
import org.jlab.presenter.persistence.entity.BtaShiftInfoSlide;

/**
*
* @author ryans
*/
@Stateless
public class BtaShiftInfoSlideFacade extends AbstractFacade<BtaShiftInfoSlide> {
@PersistenceContext(unitName = "presenterPU")
private EntityManager em;
@PersistenceContext(unitName = "presenterPU")
private EntityManager em;

@Override
protected EntityManager getEntityManager() {
return em;
}
@Override
protected EntityManager getEntityManager() {
return em;
}

public BtaShiftInfoSlideFacade() {
super(BtaShiftInfoSlide.class);
}
public BtaShiftInfoSlideFacade() {
super(BtaShiftInfoSlide.class);
}

@PermitAll
public int deleteBtaRecords(BigInteger slideId) {
Query q = em.createQuery("delete from BtaRecord where slideId.slideId = :slideId");
q.setParameter("slideId", slideId);
return q.executeUpdate();
}

/*Useful if cascade and ophanRemoval aren't present*/
@PermitAll
public void updateWithRecords(BtaShiftInfoSlide slide) {
deleteBtaRecords(slide.getSlideId());
edit(slide);
}

@PermitAll
public int deleteBtaRecords(BigInteger slideId) {
Query q = em.createQuery("delete from BtaRecord where slideId.slideId = :slideId");
q.setParameter("slideId", slideId);
return q.executeUpdate();
}

/*Useful if cascade and ophanRemoval aren't present*/
@PermitAll
public void updateWithRecords(BtaShiftInfoSlide slide) {
deleteBtaRecords(slide.getSlideId());
edit(slide);
}
}
Loading

0 comments on commit fdb0ab1

Please sign in to comment.