openid connect repositories written, but not unit tested
parent
c6e8b12ad9
commit
685a311de1
|
@ -0,0 +1,46 @@
|
|||
package org.mitre.openid.connect.repository;
|
||||
|
||||
import org.mitre.openid.connect.model.Address;
|
||||
|
||||
/**
|
||||
* Address repository interface
|
||||
*
|
||||
* @author Michael Joseph Walsh
|
||||
*
|
||||
*/
|
||||
public interface AddressRepository {
|
||||
|
||||
/**
|
||||
* Returns the Address for the given id
|
||||
*
|
||||
* @param id
|
||||
* id the id of the Address
|
||||
* @return a valid Address if it exists, null otherwise
|
||||
*/
|
||||
public Address getById(Long id);
|
||||
|
||||
/**
|
||||
* Removes the given Address from the repository
|
||||
*
|
||||
* @param address
|
||||
* the Address object to remove
|
||||
*/
|
||||
public void remove(Address address);
|
||||
|
||||
/**
|
||||
* Removes an Address from the repository
|
||||
*
|
||||
* @param id
|
||||
* the id of the Address to remove
|
||||
*/
|
||||
public void removeById(Long id);
|
||||
|
||||
/**
|
||||
* Persists a Address
|
||||
*
|
||||
* @param address
|
||||
* the Address to be saved
|
||||
* @return
|
||||
*/
|
||||
public Address save(Address address);
|
||||
}
|
|
@ -1,19 +1,76 @@
|
|||
package org.mitre.openid.connect.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.mitre.oauth2.model.ClientDetailsEntity;
|
||||
import org.mitre.openid.connect.model.ApprovedSite;
|
||||
import org.mitre.openid.connect.model.UserInfo;
|
||||
|
||||
/**
|
||||
* ApprovedSite repository interface
|
||||
*
|
||||
* @author Michael Joseph Walsh
|
||||
*
|
||||
*/
|
||||
public interface ApprovedSiteRepository {
|
||||
|
||||
/**
|
||||
* Returns the ApprovedSite for the given id
|
||||
*
|
||||
* @param id
|
||||
* id the id of the ApprovedSite
|
||||
* @return a valid ApprovedSite if it exists, null otherwise
|
||||
*/
|
||||
public ApprovedSite getById(Long id);
|
||||
|
||||
public Collection<ApprovedSite> getAllForUser(UserInfo user);
|
||||
/**
|
||||
* Return a collection of all ApprovedSites managed by this repository
|
||||
*
|
||||
* @return the ApprovedSite collection, or null
|
||||
*/
|
||||
public Collection<ApprovedSite> getAll();
|
||||
|
||||
public Collection<ApprovedSite> getAllExpired();
|
||||
/**
|
||||
* Return a collection of UserInfo managed by this repository matching the
|
||||
* provided ClientDetailsEntity
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
public Collection<ApprovedSite> getByClientDetails(
|
||||
ClientDetailsEntity clientDetails);
|
||||
|
||||
public ApprovedSite save(ApprovedSite site);
|
||||
/**
|
||||
* Return a collection of UserInfo managed by this repository matching the
|
||||
* provided UserInfo
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
public Collection<ApprovedSite> getByUserInfo(UserInfo userInfo);
|
||||
|
||||
/**
|
||||
* Removes the given ApprovedSite from the repository
|
||||
*
|
||||
* @param aggregator
|
||||
* the ApprovedSite object to remove
|
||||
*/
|
||||
public void remove(ApprovedSite approvedSite);
|
||||
|
||||
/**
|
||||
* Removes an ApprovedSite from the repository
|
||||
*
|
||||
* @param id
|
||||
* the id of the ApprovedSite to remove
|
||||
*/
|
||||
public void removeById(Long id);
|
||||
|
||||
/**
|
||||
* Persists an ApprovedSite
|
||||
*
|
||||
* @param aggregator
|
||||
* valid ApprovedSite instance
|
||||
* @return the persisted entity
|
||||
*/
|
||||
public ApprovedSite save(ApprovedSite approvedSite);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package org.mitre.openid.connect.repository;
|
||||
|
||||
import org.mitre.openid.connect.model.Event;
|
||||
|
||||
/**
|
||||
* Event repository interface
|
||||
*
|
||||
* @author Michael Joseph Walsh
|
||||
*
|
||||
*/
|
||||
public interface EventRepository {
|
||||
|
||||
/**
|
||||
* Returns the Event for the given id
|
||||
*
|
||||
* @param id
|
||||
* id the id of the Event
|
||||
* @return a valid Event if it exists, null otherwise
|
||||
*/
|
||||
public Event getById(Long id);
|
||||
|
||||
/**
|
||||
* Removes the given Event from the repository
|
||||
*
|
||||
* @param event
|
||||
* the Event object to remove
|
||||
*/
|
||||
public void remove(Event event);
|
||||
|
||||
/**
|
||||
* Removes an Event from the repository
|
||||
*
|
||||
* @param id
|
||||
* the id of the Event to remove
|
||||
*/
|
||||
public void removeById(Long id);
|
||||
|
||||
/**
|
||||
* Persists a Event
|
||||
*
|
||||
* @param event
|
||||
* the Event to be saved
|
||||
* @return
|
||||
*/
|
||||
public Event save(Event event);
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package org.mitre.openid.connect.repository;
|
||||
|
||||
import org.mitre.openid.connect.model.IdTokenClaims;
|
||||
|
||||
public interface IdTokenClaimsRepository {
|
||||
|
||||
/**
|
||||
* Returns the IdTokenClaims for the given id
|
||||
*
|
||||
* @param id
|
||||
* id the id of the Address
|
||||
* @return a valid IdTokenClaims if it exists, null otherwise
|
||||
*/
|
||||
public IdTokenClaims getById(Long id);
|
||||
|
||||
/**
|
||||
* Removes the given IdTokenClaims from the repository
|
||||
*
|
||||
* @param address
|
||||
* the IdTokenClaims object to remove
|
||||
*/
|
||||
public void remove(IdTokenClaims idTokenClaims);
|
||||
|
||||
/**
|
||||
* Removes an IdTokenClaims from the repository
|
||||
*
|
||||
* @param id
|
||||
* the id of the IdTokenClaims to remove
|
||||
*/
|
||||
public void removeById(Long id);
|
||||
|
||||
/**
|
||||
* Persists a IdTokenClaims
|
||||
*
|
||||
* @param idTokenClaims
|
||||
* the IdTokenClaims to be saved
|
||||
* @return
|
||||
*/
|
||||
public IdTokenClaims save(IdTokenClaims idTokenClaims);
|
||||
}
|
|
@ -1,11 +1,45 @@
|
|||
package org.mitre.openid.connect.repository;
|
||||
|
||||
import org.mitre.openid.connect.model.IdTokenClaims;
|
||||
import org.mitre.openid.connect.model.IdToken;
|
||||
|
||||
/**
|
||||
* IdToken repository interface
|
||||
*
|
||||
* @author Michael Joseph Walsh
|
||||
*
|
||||
*/
|
||||
public interface IdTokenRepository {
|
||||
|
||||
public IdTokenClaims getById(Long id);
|
||||
/**
|
||||
* Returns the IdToken for the given id
|
||||
*
|
||||
* @param id
|
||||
* id the id of the IdToken
|
||||
* @return a valid IdToken if it exists, null otherwise
|
||||
*/
|
||||
public IdToken getById(Long id);
|
||||
|
||||
public IdTokenClaims save(IdTokenClaims idToken);
|
||||
/**
|
||||
* Removes the given IdToken from the repository
|
||||
*
|
||||
* @param idToken
|
||||
* the IdToken object to remove
|
||||
*/
|
||||
public void remove(IdToken idToken);
|
||||
|
||||
/**
|
||||
* Removes an IdToken from the repository
|
||||
*
|
||||
* @param id
|
||||
* the id of the IdToken to remove
|
||||
*/
|
||||
public void removeById(Long id);
|
||||
|
||||
/**
|
||||
* Persists a IdToken
|
||||
*
|
||||
* @param idToken
|
||||
* @return
|
||||
*/
|
||||
public IdToken save(IdToken idToken);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,38 @@
|
|||
package org.mitre.openid.connect.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mitre.openid.connect.model.UserInfo;
|
||||
|
||||
/**
|
||||
* UserInfo repository interface
|
||||
*
|
||||
* @author Michael Joseph Walsh
|
||||
*
|
||||
*/
|
||||
public interface UserInfoRepository {
|
||||
|
||||
public UserInfo getByUserId(String user_id);
|
||||
/**
|
||||
* Persists a UserInfo
|
||||
*
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public UserInfo save(UserInfo userInfo);
|
||||
|
||||
public UserInfo save(UserInfo user);
|
||||
/**
|
||||
* Removes the given UserInfo from the repository
|
||||
*
|
||||
* @param userInfo
|
||||
* the UserInfo object to remove
|
||||
*/
|
||||
public void remove(UserInfo userInfo);
|
||||
|
||||
/**
|
||||
* Return a collection of all UserInfos managed by this repository
|
||||
*
|
||||
* @return the UserInfo collection, or null
|
||||
*/
|
||||
public Collection<UserInfo> getAll();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,55 @@
|
|||
package org.mitre.openid.connect.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mitre.openid.connect.model.WhitelistedSite;
|
||||
|
||||
/**
|
||||
* WhitelistedSite repository interface
|
||||
*
|
||||
* @author Michael Joseph Walsh
|
||||
*
|
||||
*/
|
||||
public interface WhitelistedSiteRepository {
|
||||
|
||||
/**
|
||||
* Return a collection of all WhitelistedSite managed by this repository
|
||||
*
|
||||
* @return the WhitelistedSite collection, or null
|
||||
*/
|
||||
public Collection<WhitelistedSite> getAll();
|
||||
|
||||
/**
|
||||
* Returns the WhitelistedSite for the given id
|
||||
*
|
||||
* @param id
|
||||
* id the id of the WhitelistedSite
|
||||
* @return a valid WhitelistedSite if it exists, null otherwise
|
||||
*/
|
||||
public WhitelistedSite getById(Long id);
|
||||
|
||||
/**
|
||||
* Removes the given IdToken from the repository
|
||||
*
|
||||
* @param whitelistedSite
|
||||
* the WhitelistedSite object to remove
|
||||
*/
|
||||
public void remove(WhitelistedSite whitelistedSite);
|
||||
|
||||
/**
|
||||
* Removes an WhitelistedSite from the repository
|
||||
*
|
||||
* @param id
|
||||
* the id of the IdToken to remove
|
||||
*/
|
||||
public void removeById(Long id);
|
||||
|
||||
/**
|
||||
* Persists a WhitelistedSite
|
||||
*
|
||||
* @param whitelistedSite
|
||||
* @return
|
||||
*/
|
||||
public WhitelistedSite save(WhitelistedSite whiteListedSite);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package org.mitre.openid.connect.repository.impl;
|
||||
|
||||
import static org.mitre.util.jpa.JpaUtil.saveOrUpdate;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import org.mitre.openid.connect.model.Address;
|
||||
import org.mitre.openid.connect.repository.AddressRepository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* JPA Address repository implementation
|
||||
*
|
||||
* @author Michael Joseph Walsh
|
||||
*
|
||||
*/
|
||||
public class JpaAddressRepository implements AddressRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager manager;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Address getById(Long id) {
|
||||
return manager.find(Address.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void remove(Address address) {
|
||||
Address found = manager.find(Address.class, address.getId());
|
||||
|
||||
if (found != null) {
|
||||
manager.remove(address);
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void removeById(Long id) {
|
||||
Address found = getById(id);
|
||||
|
||||
manager.remove(found);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Address save(Address address) {
|
||||
return saveOrUpdate(address.getId(), manager, address);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package org.mitre.openid.connect.repository.impl;
|
||||
|
||||
import static org.mitre.util.jpa.JpaUtil.saveOrUpdate;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
import org.mitre.oauth2.model.ClientDetailsEntity;
|
||||
import org.mitre.openid.connect.model.ApprovedSite;
|
||||
import org.mitre.openid.connect.model.UserInfo;
|
||||
import org.mitre.openid.connect.repository.ApprovedSiteRepository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* JPA ApprovedSite repository implementation
|
||||
*
|
||||
* @author Michael Joseph Walsh
|
||||
*
|
||||
*/
|
||||
public class JpaApprovedSiteRepository implements ApprovedSiteRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager manager;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Collection<ApprovedSite> getAll() {
|
||||
TypedQuery<ApprovedSite> query = manager.createNamedQuery(
|
||||
"ApprovedSite.getAll", ApprovedSite.class);
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Collection<ApprovedSite> getByClientDetails(
|
||||
ClientDetailsEntity clientDetails) {
|
||||
|
||||
TypedQuery<ApprovedSite> query = manager.createNamedQuery(
|
||||
"ApprovedSite.getByClientDetails", ApprovedSite.class);
|
||||
query.setParameter("approvedSiteClientDetails", clientDetails);
|
||||
|
||||
List<ApprovedSite> found = query.getResultList();
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ApprovedSite getById(Long id) {
|
||||
return manager.find(ApprovedSite.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Collection<ApprovedSite> getByUserInfo(UserInfo userInfo) {
|
||||
TypedQuery<ApprovedSite> query = manager.createNamedQuery(
|
||||
"ApprovedSite.getByUserInfo", ApprovedSite.class);
|
||||
query.setParameter("approvedSiteUserInfo", userInfo);
|
||||
|
||||
List<ApprovedSite> found = query.getResultList();
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void remove(ApprovedSite approvedSite) {
|
||||
ApprovedSite found = manager.find(ApprovedSite.class,
|
||||
approvedSite.getId());
|
||||
|
||||
if (found != null) {
|
||||
manager.remove(approvedSite);
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void removeById(Long id) {
|
||||
ApprovedSite found = getById(id);
|
||||
|
||||
manager.remove(found);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ApprovedSite save(ApprovedSite approvedSite) {
|
||||
return saveOrUpdate(approvedSite.getId(), manager, approvedSite);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package org.mitre.openid.connect.repository.impl;
|
||||
|
||||
import static org.mitre.util.jpa.JpaUtil.saveOrUpdate;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import org.mitre.openid.connect.model.Event;
|
||||
import org.mitre.openid.connect.repository.EventRepository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* JPA Event repository implementation
|
||||
*
|
||||
* @author Michael Joseph Walsh
|
||||
*
|
||||
*/
|
||||
public class JpaEventRepository implements EventRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager manager;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Event getById(Long id) {
|
||||
return manager.find(Event.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void remove(Event event) {
|
||||
Event found = manager.find(Event.class, event.getId());
|
||||
|
||||
if (found != null) {
|
||||
manager.remove(event);
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void removeById(Long id) {
|
||||
Event found = getById(id);
|
||||
|
||||
manager.remove(found);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Event save(Event event) {
|
||||
return saveOrUpdate(event.getId(), manager, event);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package org.mitre.openid.connect.repository.impl;
|
||||
|
||||
import static org.mitre.util.jpa.JpaUtil.saveOrUpdate;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import org.mitre.openid.connect.model.IdTokenClaims;
|
||||
import org.mitre.openid.connect.repository.IdTokenClaimsRepository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
public class JpaIdTokenClaimsRepository implements IdTokenClaimsRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager manager;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public IdTokenClaims getById(Long id) {
|
||||
return manager.find(IdTokenClaims.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void remove(IdTokenClaims idTokenClaims) {
|
||||
IdTokenClaims found = manager.find(IdTokenClaims.class, idTokenClaims.getId());
|
||||
|
||||
if (found != null) {
|
||||
manager.remove(idTokenClaims);
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void removeById(Long id) {
|
||||
IdTokenClaims found = getById(id);
|
||||
|
||||
manager.remove(found);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public IdTokenClaims save(IdTokenClaims idTokenClaims) {
|
||||
return saveOrUpdate(idTokenClaims.getId(), manager, idTokenClaims);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package org.mitre.openid.connect.repository.impl;
|
||||
|
||||
import static org.mitre.util.jpa.JpaUtil.saveOrUpdate;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import org.mitre.openid.connect.model.IdToken;
|
||||
import org.mitre.openid.connect.repository.IdTokenRepository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
public class JpaIdTokenRepository implements IdTokenRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager manager;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public IdToken getById(Long id) {
|
||||
return manager.find(IdToken.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void remove(IdToken idToken) {
|
||||
IdToken found = manager.find(IdToken.class, idToken.getId());
|
||||
|
||||
if (found != null) {
|
||||
manager.remove(idToken);
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void removeById(Long id) {
|
||||
IdToken found = getById(id);
|
||||
|
||||
manager.remove(found);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public IdToken save(IdToken idToken) {
|
||||
return saveOrUpdate(idToken.getId(), manager, idToken);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package org.mitre.openid.connect.repository.impl;
|
||||
|
||||
import static org.mitre.util.jpa.JpaUtil.saveOrUpdate;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
import org.mitre.openid.connect.model.UserInfo;
|
||||
import org.mitre.openid.connect.repository.UserInfoRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* * JPA UserInfo repository implementation
|
||||
*
|
||||
* @author Michael Joseph Walsh
|
||||
*
|
||||
*/
|
||||
@Repository
|
||||
public class JpaUserInfoRepository implements UserInfoRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager manager;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public UserInfo save(UserInfo userInfo) {
|
||||
return saveOrUpdate(userInfo.getUserId(), manager, userInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void remove(UserInfo userInfo) {
|
||||
|
||||
UserInfo found = manager.find(UserInfo.class, userInfo.getUserId());
|
||||
|
||||
if (found != null) {
|
||||
manager.remove(userInfo);
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Collection<UserInfo> getAll() {
|
||||
|
||||
TypedQuery<UserInfo> query = manager.createNamedQuery(
|
||||
"UserInfo.getAll", UserInfo.class);
|
||||
|
||||
return query.getResultList();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package org.mitre.openid.connect.repository.impl;
|
||||
|
||||
import static org.mitre.util.jpa.JpaUtil.saveOrUpdate;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
import org.mitre.openid.connect.model.WhitelistedSite;
|
||||
import org.mitre.openid.connect.repository.WhitelistedSiteRepository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
public class JpaWhitelistedSiteRepositiory implements WhitelistedSiteRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager manager;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Collection<WhitelistedSite> getAll() {
|
||||
TypedQuery<WhitelistedSite> query = manager.createNamedQuery(
|
||||
"WhitelistedSite.getAll", WhitelistedSite.class);
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public WhitelistedSite getById(Long id) {
|
||||
return manager.find(WhitelistedSite.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void remove(WhitelistedSite whitelistedSite) {
|
||||
WhitelistedSite found = manager.find(WhitelistedSite.class,
|
||||
whitelistedSite.getId());
|
||||
|
||||
if (found != null) {
|
||||
manager.remove(whitelistedSite);
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void removeById(Long id) {
|
||||
WhitelistedSite found = getById(id);
|
||||
|
||||
manager.remove(found);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public WhitelistedSite save(WhitelistedSite whiteListedSite) {
|
||||
return saveOrUpdate(whiteListedSite.getId(), manager, whiteListedSite);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue