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.Optional;
22  import javax.persistence.Basic;
23  import javax.persistence.Entity;
24  import javax.persistence.FetchType;
25  import javax.persistence.Lob;
26  import javax.persistence.ManyToOne;
27  import javax.persistence.Table;
28  import org.apache.commons.lang3.ArrayUtils;
29  import org.apache.syncope.core.persistence.api.entity.Report;
30  import org.apache.syncope.core.persistence.api.entity.ReportExec;
31  
32  @Entity
33  @Table(name = JPAReportExec.TABLE)
34  public class JPAReportExec extends AbstractExec implements ReportExec {
35  
36      private static final long serialVersionUID = -6178274296037547769L;
37  
38      public static final String TABLE = "ReportExec";
39  
40      /**
41       * The referred report.
42       */
43      @ManyToOne(optional = false)
44      private JPAReport report;
45  
46      /**
47       * Report execution result, stored as an XML stream.
48       */
49      @Lob
50      @Basic(fetch = FetchType.LAZY)
51      private Byte[] execResult;
52  
53      @Override
54      public Report getReport() {
55          return report;
56      }
57  
58      @Override
59      public void setReport(final Report report) {
60          checkType(report, JPAReport.class);
61          this.report = (JPAReport) report;
62      }
63  
64      @Override
65      public byte[] getExecResult() {
66          return Optional.ofNullable(execResult).map(ArrayUtils::toPrimitive).orElse(null);
67      }
68  
69      @Override
70      public void setExecResult(final byte[] execResult) {
71          this.execResult = Optional.ofNullable(execResult).map(ArrayUtils::toObject).orElse(null);
72      }
73  }