Be an enterpreneur and invest about one hour of your time to watch David Hansson give a talk at Stanford.
15° Salone del Risparmio, ci vediamo?
4 days ago
...or how to be heavyweight and agile at the same time
Object obj = new Object();As behind the curtains the expression is
all you have to do is change the type and note how the IDE at the same time changes the name of the variable setting the first letter in lowercase, e.g. if you hit newo TAB MyObject the result will be
${TYPE default="Object"} ${OBJ newVarName default="obj"} = new ${TYPE}(${cursor});
MyObject myObject = new MyObject();Neat and clean :-)
And, just like that... it's gone!
The observation of bilingual speakers indicate that these [behaviors and signals] are semi-independent systems which must be examined in context. The significant aspect of this is that as a bilingual speaker changes languages he also changes kinesic systems.
/** Creates a new transient ${Type} */
public ${Type} new${Type}(){
${Type} ${instance} = newTransientInstance(${Type}.class);
return ${instance};
}
/** The name of the icon that represents the object */
public String iconName(){
return "${iconName}";
}
/** A description of the object */Note the use of the reserved ${cursor} property that positions the cursor where you are supposed to add your custom code.
public String title(){
TitleBuffer buf = new TitleBuffer();
// TODO add properties
${cursor}
return buf.toString();
}
/** Validation for property ${property} */Last but not least
public String validate${Property}(${Type} ${value}){
if ((${value} == null)) {
return null;
}
// TODO implement imperative rule
${cursor}
return null;
}
/** Find all ${TypePlural} */
@Exploration
public List<${Type}> findAll${TypePlural}(){
return allInstances(${Type}.class);
}
It takes real skill to ensure the correct separation of concerns between these layers, if indeed you can get an agreement to what these concerns really are. Even with the best intentions, it's all too easy for custom-written layers to blur the boundaries and put (for example) validation in the user interface layer when it should belong to the domain layer. At the other extreme, it's quite possible for custom layers to distort or completely subvert the underlying domain model.
@TestI run the test and got a green bar for free. You may notice that in the comparison there are a couple of different variables: these are the names of the Enums, and I was quite pleased with the fact that Dozer had silently mapped them just as I expected.
public void testPojoToPersistenceEntity() {
System.out.println("testPojoToPersistenceEntity");
MyPojo pojo = new MyPojo(
propOne,
propTwo,
propThree,
propFour);
MyPersistentClass persistent = mapper.map(pojo, MyPersistentClass.class);
assertNotNull(persistent);
assertEquals(propOne, persistent.getPropOne());
assertEquals(propTwoTxt, persistent.getPropTwo());
assertEquals(propThreeTxt, persistent.getPropThree());
assertEquals(propFour, persistent.getPropFour());
}
@TestStill smiling I hit the CTRL+F6 combination and... WTF? red bar?
public void testPersistenceEntityToExistingPojo() {
System.out.println("testPersistenceEntityToExistingPojo");
MyPersistentClass persistent = new MyPersistentClass(
propOne,
propTwoTxt,
propThreeTxt,
propFour);
persistent.setPropFive(propFive);
persistent.setPropSix(propSix);
MyPojo pojo = new MyPojo(
propOne,
propTwo,
propThree,
propFour);
assertEquals(0d, pojo.getPropFive(), 0.01d);
assertEquals(0d, pojo.getPropSix(), 0.01d);
mapper.map(persistent, pojo);
assertEquals(propFive, pojo.getPropFive(), 0.01d);
assertEquals(propSix, pojo.getPropSix(), 0.01d);
}
org.dozer.MappingException: Illegal object type for the method 'setPropTwo'.Hmmm... weird... but not too much after all, I had been too optimistic.
Expected types:
my.package.MyEnum
Actual types:
java.lang.String
<mapping>Not exactly what I had in mind, because it doesn't let me create a new instance of a POJO, but for now it will suffice.
<class-a>my.model.package.MyPersistentClass</class-a>
<class-b>my.package.MyPojo</class-b>
<field-exclude type="one-way">
<a>propTwo</a>
<b>propTwo</b>
</field-exclude>
<field-exclude type="one-way">
<a>propThree</a>
<b>propThree</b>
</field-exclude>
</mapping>