54 lines
953 B
Plaintext
54 lines
953 B
Plaintext
Including any logic other than a simple return of the field in a persistence-annotated method can result in odd behavior, including for example, the default construction of empty members which are annotated to be ``++lazy++``.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
private Double price;
|
|
|
|
@Columm(name="price")
|
|
public Double getPrice() {
|
|
if(buyer.isLoaltyMember()) { // Noncompliant
|
|
return price - getLoyaltyDiscount();
|
|
} else {
|
|
return price;
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
----
|
|
@Columm(name="price")
|
|
private Double price;
|
|
|
|
public Double getPrice() {
|
|
if(buyer.isLoaltyMember()) {
|
|
return price - getLoyaltyDiscount();
|
|
} else {
|
|
return price;
|
|
}
|
|
}
|
|
----
|
|
or
|
|
|
|
----
|
|
private Double price;
|
|
|
|
@Columm(name="price")
|
|
public Double getPrice() {
|
|
return price;
|
|
}
|
|
|
|
public Double calculatePrice() {
|
|
if(buyer.isLoaltyMember()) { // Noncompliant
|
|
return getPrice() - getLoyaltyDiscount();
|
|
} else {
|
|
return getPrice();
|
|
}
|
|
}
|
|
----
|
|
|
|
|