* the prnter
*/
protected void printIncrementVersionMethod(final Printer printer) {
printer.println("@Override");
printer.println("protected void incrementVersion(Object model) {");
final AttributeMetaDesc attr =
modelMetaDesc.getVersionAttributeMetaDesc();
if (attr != null) {
printer.println(" %1$s m = (%1$s) model;", modelMetaDesc
.getModelClassName());
DataType dataType = attr.getDataType();
dataType.accept(
new SimpleDataTypeVisitor<Void, Void, RuntimeException>() {
@Override
protected Void defaultAction(DataType type, Void p)
throws RuntimeException {
printer
.println(
" throw new IllegalStateException(\"The version property of the model(%1$s) is not defined.\");",
modelMetaDesc.getModelClassName());
return null;
}
@Override
public Void visitPrimitiveLongType(PrimitiveLongType type,
Void p) throws RuntimeException {
printer.println(" m.%1$s(m.%2$s() + 1L);", attr
.getWriteMethodName(), attr.getReadMethodName());
return null;
}
@Override
public Void visitLongType(LongType type, Void p)
throws RuntimeException {
printer
.println(
" long version = m.%1$s() != null ? m.%1$s().longValue() : 0L;",
attr.getReadMethodName());
printer.println(
" m.%1$s(Long.valueOf(version + 1L));",
attr.getWriteMethodName());
return null;
}
},
null);