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.entity;
20  
21  import java.util.HashSet;
22  import java.util.Set;
23  import javax.persistence.Cacheable;
24  import javax.persistence.Entity;
25  import javax.persistence.EnumType;
26  import javax.persistence.Enumerated;
27  import javax.persistence.JoinColumn;
28  import javax.persistence.JoinTable;
29  import javax.persistence.ManyToMany;
30  import javax.persistence.Table;
31  import javax.validation.constraints.NotNull;
32  import org.apache.syncope.common.lib.types.AnyTypeKind;
33  import org.apache.syncope.core.persistence.api.entity.AnyType;
34  import org.apache.syncope.core.persistence.api.entity.AnyTypeClass;
35  import org.apache.syncope.core.persistence.jpa.validation.entity.AnyTypeCheck;
36  
37  @Entity
38  @Table(name = JPAAnyType.TABLE)
39  @AnyTypeCheck
40  @Cacheable
41  public class JPAAnyType extends AbstractProvidedKeyEntity implements AnyType {
42  
43      private static final long serialVersionUID = 2668267884059219835L;
44  
45      public static final String TABLE = "AnyType";
46  
47      @NotNull
48      @Enumerated(EnumType.STRING)
49      private AnyTypeKind kind;
50  
51      @ManyToMany
52      @JoinTable(joinColumns =
53              @JoinColumn(name = "anyType_id", referencedColumnName = "id"),
54              inverseJoinColumns =
55              @JoinColumn(name = "anyTypeClass_id", referencedColumnName = "id"))
56      private Set<JPAAnyTypeClass> classes = new HashSet<>();
57  
58      @Override
59      public AnyTypeKind getKind() {
60          return kind;
61      }
62  
63      @Override
64      public void setKind(final AnyTypeKind kind) {
65          this.kind = kind;
66      }
67  
68      @Override
69      public boolean add(final AnyTypeClass anyTypeClass) {
70          checkType(anyTypeClass, JPAAnyTypeClass.class);
71          return classes.add((JPAAnyTypeClass) anyTypeClass);
72      }
73  
74      @Override
75      public Set<? extends AnyTypeClass> getClasses() {
76          return classes;
77      }
78  }