addChildVisitor(JpaColumn.class, new ColumnVisitor());
}
@Override
public boolean onStartNode(ProjectPath path) {
JpaBasic jpaBasic = (JpaBasic) path.getObject();
if (jpaBasic.getColumn() == null) {
JpaColumn column = new JpaColumn(AnnotationPrototypes.getColumn());
column.setName(jpaBasic.getName());
column.setNullable(jpaBasic.isOptional());
jpaBasic.setColumn(column);
}
JpaAbstractEntity entity = (JpaAbstractEntity) path
.firstInstanceOf(JpaAbstractEntity.class);
// process temporal type defaults
if (jpaBasic.getTemporal() == null && jpaBasic.getEnumerated() == null) {
JpaClassDescriptor descriptor = entity.getClassDescriptor();
JpaPropertyDescriptor property = descriptor.getProperty(jpaBasic
.getName());
// sanity check
if (property == null) {
throw new IllegalStateException("No class property found for name: "
+ jpaBasic.getName());
}
if (java.sql.Date.class.isAssignableFrom(property.getType())) {
jpaBasic.setTemporal(TemporalType.DATE);
}
else if (Time.class.isAssignableFrom(property.getType())) {
jpaBasic.setTemporal(TemporalType.TIME);
}
else if (Timestamp.class.isAssignableFrom(property.getType())) {
jpaBasic.setTemporal(TemporalType.TIMESTAMP);
}
else if (Date.class.isAssignableFrom(property.getType())) {
jpaBasic.setTemporal(TemporalType.TIMESTAMP);
}
else if (property.getType().isEnum()) {
jpaBasic.setEnumerated(EnumType.ORDINAL);
}
}
return true;
}