In our integration test for the Spring Roo control object, we encountered the problem of using AspectJ interface style interfaces, which not only present methods with a default implementation, but also add attributes annotated using the JSR 303 validation rule. The problem is that the Spring Roo DataOnDemand logic does not see these fields and therefore does not take them into account in the getNewTransientObject () method.
For example, the following (simplified) interface adds a key field to each object that implements the Keyed interface:
import javax.persistence.Column; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; public interface Keyed { public String getKey(); public void setKey(String key); static aspect Impl { @NotNull @Column(name = "key", unique = true) @Size(min = 8, max = 12) private String Keyed.key; public void Keyed.setKey(String key) { this.key = key; } public String Keyed.getKey() { return this.key; } } }
This is actually a problem for us. What we did was insert the getNewTransientObject () method from the AspectJ ITD (.aj) file created by Spring Roo, and then make sure the attribute is set to an acceptable value. In our DataOnDemand.java file for the test class, we have the following snippet.
public KeyedExampleA getNewTransientKeyedExampleA(int index) { KeyedExampleA obj = new KeyedExampleA(); setDescription(obj, index); setListPrice(obj, index); setName(obj, index);
What is inconvenient for me because of the above is that we do not create the setKey (obj, index) method in the DataOnDemand.java file and use the same style as Spring Roo generated for the getNewTransientKeyedObject (int) method.
Should we worry about creating the setKey (obj, index) method for such a trivial case, or do we just need to go with what we do obj.setKey (value) inside the getNewTransientObject () method?
From a look at Spring .aj-created .oo files, I donโt see that it matters a lot because there is nothing that calls setField (obj, index), not the getNewTransientObject () method. And since Spring Roo does not figure out that we have mixed attributes entered, this will probably never take care in the future.
source share