Bytte till "Imp" istället för "Impl" på de som hette det i paketet. Skrev om EventDaoJPAImp till SciProevents. Skapade Alla Project-relaterade klasser
git-svn-id: svn://svn.dsv.su.se/scipro/scipro/trunk@42 73ecded7-942e-4092-bab0-0e58ef0ee984
This commit is contained in:
parent
c2d8d9ef48
commit
f4f3d919c3
@ -21,7 +21,7 @@ import se.su.dsv.scipro.data.dataobjects.DomainObject;
|
|||||||
*
|
*
|
||||||
* @param <T>
|
* @param <T>
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractDaoJPAImpl<T extends DomainObject> extends JpaDaoSupport implements Dao<T> {
|
public abstract class AbstractDaoJPAImp<T extends DomainObject> extends JpaDaoSupport implements Dao<T> {
|
||||||
|
|
||||||
protected Class<T> domainClass;
|
protected Class<T> domainClass;
|
||||||
protected String domainClassString;
|
protected String domainClassString;
|
||||||
@ -35,7 +35,7 @@ public abstract class AbstractDaoJPAImpl<T extends DomainObject> extends JpaDaoS
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public AbstractDaoJPAImpl(Class<T> domainClass) {
|
public AbstractDaoJPAImp(Class<T> domainClass) {
|
||||||
this.domainClass = domainClass;
|
this.domainClass = domainClass;
|
||||||
domainClassString = domainClass.getCanonicalName();
|
domainClassString = domainClass.getCanonicalName();
|
||||||
}
|
}
|
@ -1,14 +1,5 @@
|
|||||||
package se.su.dsv.scipro.data.dao.jpa;
|
package se.su.dsv.scipro.data.dao.jpa;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.PersistenceException;
|
|
||||||
import javax.persistence.TypedQuery;
|
|
||||||
|
|
||||||
import org.springframework.orm.jpa.JpaCallback;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import se.su.dsv.scipro.data.dao.interfaces.EventDao;
|
import se.su.dsv.scipro.data.dao.interfaces.EventDao;
|
||||||
import se.su.dsv.scipro.data.dataobjects.Event;
|
import se.su.dsv.scipro.data.dataobjects.Event;
|
||||||
|
|
||||||
@ -16,31 +7,10 @@ import se.su.dsv.scipro.data.dataobjects.Event;
|
|||||||
* @author Richard Wilkinson - richard.wilkinson@jweekend.com
|
* @author Richard Wilkinson - richard.wilkinson@jweekend.com
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class EventDaoJPAImp extends AbstractDaoJPAImpl<Event> implements EventDao {
|
public class EventDaoJPAImp extends LazyDeleteAbstractDaoJPAImp<Event> implements EventDao {
|
||||||
|
|
||||||
public EventDaoJPAImp() {
|
public EventDaoJPAImp() {
|
||||||
super(Event.class);
|
super(Event.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public List<Event> findAll() {
|
|
||||||
return getJpaTemplate().execute(new JpaCallback<List<Event>>() {
|
|
||||||
public List<Event> doInJpa(EntityManager em) throws PersistenceException {
|
|
||||||
TypedQuery<Event> query = em.createQuery("select e from Event e", Event.class);
|
|
||||||
return query.getResultList();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public int countAll() {
|
|
||||||
return getJpaTemplate().execute(new JpaCallback<Integer>() {
|
|
||||||
|
|
||||||
public Integer doInJpa(EntityManager em) throws PersistenceException {
|
|
||||||
TypedQuery<Long> query = em.createQuery("select count (e) from Event e", Long.class);
|
|
||||||
return (query.getSingleResult()).intValue();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,9 @@ import se.su.dsv.scipro.data.dataobjects.DomainObject;
|
|||||||
*
|
*
|
||||||
* @param <T>
|
* @param <T>
|
||||||
*/
|
*/
|
||||||
public abstract class LazyDeleteAbstractDaoJPAImpl<T extends DomainObject & LazyDeletable> extends AbstractDaoJPAImpl<T> implements LazyDeleteDao<T> {
|
public abstract class LazyDeleteAbstractDaoJPAImp<T extends DomainObject & LazyDeletable> extends AbstractDaoJPAImp<T> implements LazyDeleteDao<T> {
|
||||||
|
|
||||||
public LazyDeleteAbstractDaoJPAImpl(Class<T> domainClass) {
|
public LazyDeleteAbstractDaoJPAImp(Class<T> domainClass) {
|
||||||
super(domainClass);
|
super(domainClass);
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,164 @@
|
|||||||
|
package se.su.dsv.scipro.data.dao.jpa;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.NoResultException;
|
||||||
|
import javax.persistence.PersistenceException;
|
||||||
|
import javax.persistence.TypedQuery;
|
||||||
|
|
||||||
|
import org.springframework.orm.jpa.JpaCallback;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||||
|
import se.su.dsv.scipro.data.dataobjects.Project;
|
||||||
|
import se.su.dsv.scipro.data.dataobjects.User;
|
||||||
|
import se.su.dsv.scipro.data.enums.ProjectStatus;
|
||||||
|
import se.su.dsv.scipro.data.enums.ProjectTeamMemberRoles;
|
||||||
|
|
||||||
|
public class ProjectDaoJPAImp extends AbstractDaoJPAImp<Project> implements ProjectDao {
|
||||||
|
|
||||||
|
public ProjectDaoJPAImp() {
|
||||||
|
super(Project.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public List<Project> getProjectsByParticipant(final User user, final ProjectStatus projectStatus) {
|
||||||
|
return getJpaTemplate().execute(new JpaCallback<List<Project>>() {
|
||||||
|
public List<Project> doInJpa(EntityManager em)
|
||||||
|
throws PersistenceException {
|
||||||
|
String q = "select p " +
|
||||||
|
"from Project p, User u " +
|
||||||
|
"join p.projectParticipants participant " +
|
||||||
|
"join u.roles role " +
|
||||||
|
"where participant = role " +
|
||||||
|
"and u = :user ";
|
||||||
|
|
||||||
|
if(projectStatus != null){
|
||||||
|
q += "and p.projectStatus = :status ";
|
||||||
|
}
|
||||||
|
|
||||||
|
q += "order by p.title asc";
|
||||||
|
|
||||||
|
TypedQuery<Project> query = em.createQuery(q, Project.class);
|
||||||
|
query.setParameter("user", user);
|
||||||
|
|
||||||
|
if(projectStatus != null){
|
||||||
|
query.setParameter("status", projectStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return query.getResultList();
|
||||||
|
} catch (NoResultException e) {
|
||||||
|
return new ArrayList<Project>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public int countProjectsByParticipant(final User user, final ProjectStatus projectStatus) {
|
||||||
|
return getJpaTemplate().execute(new JpaCallback<Integer>() {
|
||||||
|
public Integer doInJpa(EntityManager em)
|
||||||
|
throws PersistenceException {
|
||||||
|
String q = "select count(p) " +
|
||||||
|
"from Project p, User u " +
|
||||||
|
"join p.projectParticipants participant " +
|
||||||
|
"join u.roles role " +
|
||||||
|
"where participant = role " +
|
||||||
|
"and u = :user ";
|
||||||
|
|
||||||
|
if(projectStatus != null){
|
||||||
|
q += "and p.projectStatus = :status ";
|
||||||
|
}
|
||||||
|
|
||||||
|
TypedQuery<Long> query = em.createQuery(q, Long.class);
|
||||||
|
query.setParameter("user", user);
|
||||||
|
|
||||||
|
if(projectStatus != null){
|
||||||
|
query.setParameter("status", projectStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (query.getSingleResult()).intValue();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public List<Project> getProjectsByHeadSupervisor(final User user, final ProjectStatus projectStatus) {
|
||||||
|
return getJpaTemplate().execute(new JpaCallback<List<Project>>() {
|
||||||
|
public List<Project> doInJpa(EntityManager em)
|
||||||
|
throws PersistenceException {
|
||||||
|
String q = "select p " +
|
||||||
|
"from Project p, User u " +
|
||||||
|
"join u.roles role " +
|
||||||
|
"where u = :user " +
|
||||||
|
"and p.headSupervisor = role ";
|
||||||
|
|
||||||
|
if(projectStatus != null){
|
||||||
|
q += "and p.projectStatus = :status ";
|
||||||
|
}
|
||||||
|
|
||||||
|
q += "order by p.title asc";
|
||||||
|
|
||||||
|
TypedQuery<Project> query = em.createQuery(q, Project.class);
|
||||||
|
query.setParameter("user", user);
|
||||||
|
|
||||||
|
if(projectStatus != null){
|
||||||
|
query.setParameter("status", projectStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return query.getResultList();
|
||||||
|
} catch (NoResultException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new ArrayList<Project>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public List<Project> getProjectsByProjectTeamMember(final User user, final ProjectStatus projectStatus, final ProjectTeamMemberRoles teamRole) {
|
||||||
|
return getJpaTemplate().execute(new JpaCallback<List<Project>>() {
|
||||||
|
public List<Project> doInJpa(EntityManager em)
|
||||||
|
throws PersistenceException {
|
||||||
|
String q = "select p " +
|
||||||
|
"from Project p, User u " +
|
||||||
|
"join u.roles role " +
|
||||||
|
"join p.projectFollowers pf " +
|
||||||
|
"where u = :user " +
|
||||||
|
"and pf.follower = role ";
|
||||||
|
|
||||||
|
if(projectStatus != null){
|
||||||
|
q += "and p.projectStatus = :status ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(teamRole != null){
|
||||||
|
q += "and pf.projectRole = :teamRole ";
|
||||||
|
}
|
||||||
|
|
||||||
|
q += "order by p.title asc";
|
||||||
|
|
||||||
|
TypedQuery<Project> query = em.createQuery(q, Project.class);
|
||||||
|
query.setParameter("user", user);
|
||||||
|
|
||||||
|
if(projectStatus != null){
|
||||||
|
query.setParameter("status", projectStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(teamRole != null){
|
||||||
|
query.setParameter("teamRole", teamRole);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return query.getResultList();
|
||||||
|
} catch (NoResultException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new ArrayList<Project>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package se.su.dsv.scipro.data.dao.jpa;
|
||||||
|
|
||||||
|
import se.su.dsv.scipro.data.dao.interfaces.ProjectFollowerDao;
|
||||||
|
import se.su.dsv.scipro.data.dataobjects.ProjectFollower;
|
||||||
|
|
||||||
|
public class ProjectFollowerDaoJPAImp extends AbstractDaoJPAImp<ProjectFollower> implements ProjectFollowerDao {
|
||||||
|
|
||||||
|
public ProjectFollowerDaoJPAImp() {
|
||||||
|
super(ProjectFollower.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,110 @@
|
|||||||
|
package se.su.dsv.scipro.data.dao.jpa;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.NoResultException;
|
||||||
|
import javax.persistence.PersistenceException;
|
||||||
|
import javax.persistence.TypedQuery;
|
||||||
|
|
||||||
|
import org.springframework.orm.jpa.JpaCallback;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import se.su.dsv.scipro.data.dao.interfaces.ProjectScheduleDao;
|
||||||
|
import se.su.dsv.scipro.data.dataobjects.Event;
|
||||||
|
import se.su.dsv.scipro.data.dataobjects.ProjectSchedule;
|
||||||
|
|
||||||
|
public class ProjectScheduleDaoJPAImp extends AbstractDaoJPAImp<ProjectSchedule>
|
||||||
|
implements ProjectScheduleDao {
|
||||||
|
|
||||||
|
private static final int ALL_EVENTS = 0;
|
||||||
|
private static final int OLD_EVENTS = 1;
|
||||||
|
private static final int UPCOMING_EVENTS = 2;
|
||||||
|
private static final int UPCOMING_AND_NOT_DONE_EVENTS = 3;
|
||||||
|
|
||||||
|
public ProjectScheduleDaoJPAImp() {
|
||||||
|
super(ProjectSchedule.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public List<Event> getEventsByProjectSchedule(final ProjectSchedule ps, final int eventCode, final Boolean eventIsDone) {
|
||||||
|
return getJpaTemplate().execute(new JpaCallback<List<Event>>() {
|
||||||
|
public List<Event> doInJpa(EntityManager em) throws PersistenceException {
|
||||||
|
|
||||||
|
String q = "Select e " +
|
||||||
|
"from Event e " +
|
||||||
|
"where e.projectSchedule = :ps " +
|
||||||
|
"and e.deleted = false ";
|
||||||
|
|
||||||
|
switch(eventCode){
|
||||||
|
case OLD_EVENTS:
|
||||||
|
q += "and e.dueDate < now() ";
|
||||||
|
break;
|
||||||
|
case UPCOMING_AND_NOT_DONE_EVENTS:
|
||||||
|
q += "and (e.dueDate > now() or e.done = false) ";
|
||||||
|
break;
|
||||||
|
case UPCOMING_EVENTS:
|
||||||
|
q += "and e.dueDate > now() ";
|
||||||
|
break;
|
||||||
|
case ALL_EVENTS:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(eventIsDone != null){
|
||||||
|
q += String.format("and e.done = %s ", eventIsDone);
|
||||||
|
}
|
||||||
|
|
||||||
|
q += "order by e.dueDate asc";
|
||||||
|
|
||||||
|
System.out.println(q);
|
||||||
|
|
||||||
|
TypedQuery<Event> query = em.createQuery(q, Event.class);
|
||||||
|
query.setParameter("ps", ps);
|
||||||
|
|
||||||
|
try {
|
||||||
|
return query.getResultList();
|
||||||
|
} catch (NoResultException e){
|
||||||
|
return new ArrayList<Event>(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Event> getUpcomingEventsByProjectSchedule(final ProjectSchedule ps, boolean includeOldNotDoneEvents) {
|
||||||
|
if(includeOldNotDoneEvents)
|
||||||
|
return getEventsByProjectSchedule(ps, UPCOMING_AND_NOT_DONE_EVENTS, null);
|
||||||
|
else
|
||||||
|
return getEventsByProjectSchedule(ps, UPCOMING_EVENTS, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Event> getAllEventsByProjectSchedule(final ProjectSchedule ps) {
|
||||||
|
return getEventsByProjectSchedule(ps, ALL_EVENTS, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Event> getOldEventsByProjectSchedule(final ProjectSchedule ps, final Boolean done) {
|
||||||
|
return getEventsByProjectSchedule(ps, OLD_EVENTS, done);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public int countOverDueEvents(final ProjectSchedule ps) {
|
||||||
|
return getJpaTemplate().execute(new JpaCallback<Integer>() {
|
||||||
|
public Integer doInJpa(EntityManager em) throws PersistenceException {
|
||||||
|
|
||||||
|
String q = "select count(e) " +
|
||||||
|
"from Event e " +
|
||||||
|
"where e.projectSchedule = :ps " +
|
||||||
|
"and e.done = false " +
|
||||||
|
"and e.dueDate < now() " +
|
||||||
|
"and e.deleted = false ";
|
||||||
|
|
||||||
|
TypedQuery<Long> query = em.createQuery(q, Long.class);
|
||||||
|
query.setParameter("ps", ps);
|
||||||
|
|
||||||
|
return (query.getSingleResult()).intValue();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -13,7 +13,7 @@ import se.su.dsv.scipro.data.dataobjects.Role;
|
|||||||
import se.su.dsv.scipro.data.dataobjects.User;
|
import se.su.dsv.scipro.data.dataobjects.User;
|
||||||
|
|
||||||
|
|
||||||
public class RoleDaoJPAImp extends LazyDeleteAbstractDaoJPAImpl<Role> implements
|
public class RoleDaoJPAImp extends LazyDeleteAbstractDaoJPAImp<Role> implements
|
||||||
RoleDao {
|
RoleDao {
|
||||||
|
|
||||||
public RoleDaoJPAImp() {
|
public RoleDaoJPAImp() {
|
||||||
|
@ -12,7 +12,7 @@ import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
|||||||
import se.su.dsv.scipro.data.dataobjects.User;
|
import se.su.dsv.scipro.data.dataobjects.User;
|
||||||
|
|
||||||
|
|
||||||
public class UserDaoJPAImp extends LazyDeleteAbstractDaoJPAImpl<User> implements
|
public class UserDaoJPAImp extends LazyDeleteAbstractDaoJPAImp<User> implements
|
||||||
UserDao {
|
UserDao {
|
||||||
|
|
||||||
public UserDaoJPAImp() {
|
public UserDaoJPAImp() {
|
||||||
|
@ -15,7 +15,7 @@ import se.su.dsv.scipro.data.dao.interfaces.UsernameDao;
|
|||||||
import se.su.dsv.scipro.data.dataobjects.User;
|
import se.su.dsv.scipro.data.dataobjects.User;
|
||||||
import se.su.dsv.scipro.data.dataobjects.Username;
|
import se.su.dsv.scipro.data.dataobjects.Username;
|
||||||
|
|
||||||
public class UserNameDaoJPAImp extends AbstractDaoJPAImpl<Username> implements UsernameDao{
|
public class UserNameDaoJPAImp extends AbstractDaoJPAImp<Username> implements UsernameDao{
|
||||||
|
|
||||||
public UserNameDaoJPAImp() {
|
public UserNameDaoJPAImp() {
|
||||||
super(Username.class);
|
super(Username.class);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user