View Javadoc
1   package at.rseiler.spbee.core.pojo;
2   
3   import at.rseiler.spbee.core.annotation.MappingConstructor;
4   import at.rseiler.spbee.core.annotation.ReturnNull;
5   import at.rseiler.spbee.core.annotation.RowMapper;
6   import at.rseiler.spbee.core.pojo.annotation.MappingConstructorData;
7   import at.rseiler.spbee.core.pojo.annotation.RowMapperData;
8   import at.rseiler.spbee.core.util.StringUtil;
9   
10  /**
11   * Represents a variable of a ResultSet.
12   *
13   * @author Reinhard Seiler {@literal <rseiler.developer@gmail.com>}
14   */
15  public class ResultSetVariable extends Variable {
16  
17      private static final long serialVersionUID = -1847032188564695473L;
18  
19      private final boolean returnNull;
20      private final RowMapperData rowMapper;
21      private final MappingConstructorData mappingConstructor;
22  
23      /**
24       * Constructs a new ResultSetVariable.
25       *
26       * @param name               the name of the variable
27       * @param qualifiedClassName the type of the variable
28       * @param rowMapper          (nullable) the RowMapper annotation of the variable
29       * @param returnNull         (nullable) the ReturnNull annotation of the variable
30       * @param mappingConstructor (nullable) the MappingConstructor annotation of the variable
31       */
32      public ResultSetVariable(String name, String qualifiedClassName, RowMapper rowMapper, ReturnNull returnNull, MappingConstructor mappingConstructor) {
33          super(name, qualifiedClassName);
34          this.rowMapper = rowMapper != null ? new RowMapperData(rowMapper) : null;
35          this.returnNull = returnNull != null;
36          this.mappingConstructor = new MappingConstructorData(mappingConstructor);
37      }
38  
39      /**
40       * Returns the qualified class name of the RowMapper.
41       *
42       * @return the qualified class name
43       */
44      public String getRowMapper() {
45          if (rowMapper != null) {
46              return rowMapper.getType();
47          }
48  
49          return StringUtil.getQualifiedMapperClassName(getTypeInfo().getGenericTypeOrType(), mappingConstructor.getName());
50      }
51  
52      /**
53       * Returns if null should be used instead of throwing an exception if an entity is expected but nothing is returned
54       * from the database.
55       *
56       * @return true if null should be used as return value
57       */
58      public boolean useNullInsteadOfAnException() {
59          return returnNull;
60      }
61  
62  }