Projekt

Obecné

Profil

Stáhnout (3.04 KB) Statistiky
| Větev: | Revize:
1
package vldc.aswi.domain.parameter;
2

    
3
import lombok.Data;
4
import lombok.EqualsAndHashCode;
5
import lombok.NoArgsConstructor;
6
import vldc.aswi.domain.*;
7
import vldc.aswi.validators.operator.value.OperatorValueConstraint;
8

    
9
import javax.persistence.*;
10
import java.util.List;
11

    
12
/**
13
 * Domain entity representing ParameterInConfiguration in application.
14
 */
15
@Entity(name = "Parametr_konfigurace")
16
@Data
17
@EqualsAndHashCode(callSuper = true)
18
@NoArgsConstructor
19
@OperatorValueConstraint
20
public class ParameterInConfiguration extends EntityParent {
21

    
22
    /** Specific configuration in which is this parameterConfiguration presented. */
23
    @ManyToOne(fetch = FetchType.LAZY)
24
    @JoinColumn(name = "konfigurace_id")
25
    private Configuration configuration;
26

    
27
    /** Specific parameter of configuration, which is used as template. */
28
    @ManyToOne(fetch=FetchType.EAGER)
29
    @JoinColumn(name = "parametr_id")
30
    private Parameter parameter;
31

    
32
    /** Value of used operator. */
33
    @Column(name = "hodnota_operatoru")
34
    private String operatorValue;
35

    
36
    /** Specific location in which this parameterConfiguration will be used. */
37
    @ManyToOne(fetch=FetchType.LAZY)
38
    @JoinColumn(name = "umisteni_id")
39
    private Location location;
40

    
41
    /** User-defined name of this parameterConfiguration. */
42
    @Column(name = "nazev_sloupce")
43
    private String columnName;
44

    
45
    /** Specific operator which will be aplied onto data. */
46
    @ManyToOne(fetch=FetchType.LAZY)
47
    @JoinColumn(name = "operator_id")
48
    private Operator operator;
49

    
50
    /**
51
     * Creating new table with M:N relationship between ParameterInConfiguration and Function.
52
     * On every ParameterInConfiguration can be applied 0 - every function.
53
     */
54
    @ManyToMany(cascade = CascadeType.PERSIST)
55
    @JoinTable(
56
            name = "Parametr_konfigurace_ma_Funkce",
57
            joinColumns = @JoinColumn(name = "parametr_konfigurace_id"),
58
            inverseJoinColumns = @JoinColumn(name = "funkce_id")
59
    )
60
    private List<Function> functions;
61

    
62
    /**
63
     * Constructor.
64
     * @param operatorValue - Value of used operator.
65
     * @param columnName - User-defined name of this parameterConfiguration.
66
     */
67
    public ParameterInConfiguration(String operatorValue, String columnName) {
68
        this.setOperatorValue(operatorValue);
69
        this.setColumnName(columnName);
70
    }
71

    
72
    /**
73
     * Equal method for comparing two objects.
74
     * @param obj - Comparing object.
75
     * @return true if objects are same.
76
     */
77
    @Override
78
    public boolean equals(Object obj) {
79
        return super.equals(obj);
80
    }
81

    
82
    /**
83
     * Overriding toString method to prevent StackOverflowError.
84
     * @return Object with zero parameters.
85
     */
86
    @Override
87
    public String toString() {
88
        return "ParameterInConfiguration[]";
89
    }
90

    
91
    /**
92
     * Remove function from parameter in 'Parametr_Konfigurace_ma_Funkce' table.
93
     * @param function - Function to be removed.
94
     */
95
    public void removeFunction(Function function) {
96
        functions.remove(function);
97
        function.getParametersInConfigurations().remove(this);
98
    }
99
}
(2-2/4)