View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.core.persistence.jpa.dao;
20  
21  import java.util.List;
22  import javax.persistence.NoResultException;
23  import javax.persistence.TypedQuery;
24  import org.apache.syncope.core.persistence.api.dao.SAML2SP4UIIdPDAO;
25  import org.apache.syncope.core.persistence.api.entity.SAML2SP4UIIdP;
26  import org.apache.syncope.core.persistence.jpa.entity.JPASAML2SP4UIIdP;
27  import org.springframework.transaction.annotation.Transactional;
28  
29  public class JPASAML2SP4UIIdPDAO extends AbstractDAO<SAML2SP4UIIdP> implements SAML2SP4UIIdPDAO {
30  
31      @Transactional(readOnly = true)
32      @Override
33      public SAML2SP4UIIdP find(final String key) {
34          return entityManager().find(JPASAML2SP4UIIdP.class, key);
35      }
36  
37      @Transactional(readOnly = true)
38      @Override
39      public SAML2SP4UIIdP findByEntityID(final String entityID) {
40          TypedQuery<SAML2SP4UIIdP> query = entityManager().createQuery(
41                  "SELECT e FROM " + JPASAML2SP4UIIdP.class.getSimpleName()
42                  + " e WHERE e.entityID = :entityID", SAML2SP4UIIdP.class);
43          query.setParameter("entityID", entityID);
44  
45          SAML2SP4UIIdP result = null;
46          try {
47              result = query.getSingleResult();
48          } catch (NoResultException e) {
49              LOG.debug("No IdP found with entityID {}", entityID, e);
50          }
51  
52          return result;
53      }
54  
55      @Transactional(readOnly = true)
56      @Override
57      public List<SAML2SP4UIIdP> findAll() {
58          TypedQuery<SAML2SP4UIIdP> query = entityManager().createQuery(
59                  "SELECT e FROM " + JPASAML2SP4UIIdP.class.getSimpleName() + " e", SAML2SP4UIIdP.class);
60          return query.getResultList();
61      }
62  
63      @Override
64      public SAML2SP4UIIdP save(final SAML2SP4UIIdP idp) {
65          ((JPASAML2SP4UIIdP) idp).list2json();
66          return entityManager().merge(idp);
67      }
68  
69      @Override
70      public void delete(final String key) {
71          SAML2SP4UIIdP idp = find(key);
72          if (idp != null) {
73              entityManager().remove(idp);
74          }
75      }
76  }