001/******************************************************************************* 002 * Copyright 2018 The MIT Internet Trust Consortium 003 * 004 * Portions copyright 2011-2013 The MITRE Corporation 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 *******************************************************************************/ 018/** 019 * 020 */ 021package org.mitre.openid.connect.repository.impl; 022 023import static org.mitre.util.jpa.JpaUtil.saveOrUpdate; 024 025import java.util.Collection; 026 027import javax.persistence.EntityManager; 028import javax.persistence.PersistenceContext; 029import javax.persistence.TypedQuery; 030 031import org.mitre.openid.connect.model.BlacklistedSite; 032import org.mitre.openid.connect.repository.BlacklistedSiteRepository; 033import org.springframework.stereotype.Repository; 034import org.springframework.transaction.annotation.Transactional; 035 036/** 037 * @author jricher 038 * 039 */ 040@Repository 041public class JpaBlacklistedSiteRepository implements BlacklistedSiteRepository { 042 043 @PersistenceContext(unitName="defaultPersistenceUnit") 044 private EntityManager manager; 045 046 /* (non-Javadoc) 047 * @see org.mitre.openid.connect.repository.BlacklistedSiteRepository#getAll() 048 */ 049 @Override 050 @Transactional(value="defaultTransactionManager") 051 public Collection<BlacklistedSite> getAll() { 052 TypedQuery<BlacklistedSite> query = manager.createNamedQuery(BlacklistedSite.QUERY_ALL, BlacklistedSite.class); 053 return query.getResultList(); 054 } 055 056 /* (non-Javadoc) 057 * @see org.mitre.openid.connect.repository.BlacklistedSiteRepository#getById(java.lang.Long) 058 */ 059 @Override 060 @Transactional(value="defaultTransactionManager") 061 public BlacklistedSite getById(Long id) { 062 return manager.find(BlacklistedSite.class, id); 063 } 064 065 /* (non-Javadoc) 066 * @see org.mitre.openid.connect.repository.BlacklistedSiteRepository#remove(org.mitre.openid.connect.model.BlacklistedSite) 067 */ 068 @Override 069 @Transactional(value="defaultTransactionManager") 070 public void remove(BlacklistedSite blacklistedSite) { 071 BlacklistedSite found = manager.find(BlacklistedSite.class, blacklistedSite.getId()); 072 073 if (found != null) { 074 manager.remove(found); 075 } else { 076 throw new IllegalArgumentException(); 077 } 078 079 } 080 081 /* (non-Javadoc) 082 * @see org.mitre.openid.connect.repository.BlacklistedSiteRepository#save(org.mitre.openid.connect.model.BlacklistedSite) 083 */ 084 @Override 085 @Transactional(value="defaultTransactionManager") 086 public BlacklistedSite save(BlacklistedSite blacklistedSite) { 087 return saveOrUpdate(blacklistedSite.getId(), manager, blacklistedSite); 088 } 089 090 /* (non-Javadoc) 091 * @see org.mitre.openid.connect.repository.BlacklistedSiteRepository#update(org.mitre.openid.connect.model.BlacklistedSite, org.mitre.openid.connect.model.BlacklistedSite) 092 */ 093 @Override 094 @Transactional(value="defaultTransactionManager") 095 public BlacklistedSite update(BlacklistedSite oldBlacklistedSite, BlacklistedSite blacklistedSite) { 096 097 blacklistedSite.setId(oldBlacklistedSite.getId()); 098 return saveOrUpdate(oldBlacklistedSite.getId(), manager, blacklistedSite); 099 100 } 101 102}