Reputation: 169
I am trying to put a constraint on an attribute based on another attribute. If state is enabled then name has to have a value. How can I put a constraint? Using jdk 8
@DynamoDBTable(tableName = "myTable")
public class MyTable {
private String id;
private State state;//Enabled or Disabled
private String name;//if state is enabled then name property must have a value
public MyTable() {}
public MyTable(final String id) {
this.id = id;
}
@DynamoDBHashKey
public String getId() {
return id;
}
public void setId(final String id) {
this.id = id;
}
public State getState() {
return state;
}
public void setState(final State state) {
this.state = state;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
}
Upvotes: 0
Views: 123
Reputation: 7404
This can be done only programatically:
if ("enabled".equals(myTable.getState()) {
Objects.requireNonNull(myTable.getName(), "Name is missing while state is enabled");
}
mapper.save(myTable);
Upvotes: 2