class JpaColumnVisitor extends BaseTreeVisitor {
@Override
public boolean onStartNode(ProjectPath path) {
JpaColumn jpaColumn = (JpaColumn) path.getObject();
JpaAttribute attribute = (JpaAttribute) path.getObjectParent();
DbAttribute dbAttribute = new DbAttribute(jpaColumn.getName());
if (attribute instanceof JpaBasic) {
JpaBasic basic = (JpaBasic) attribute;
dbAttribute.setType(basic.getDefaultJdbcType());
}
else if (attribute instanceof JpaVersion) {
JpaVersion version = (JpaVersion) attribute;
dbAttribute.setType(version.getDefaultJdbcType());
}
dbAttribute.setMandatory(!jpaColumn.isNullable());
dbAttribute.setMaxLength(jpaColumn.getLength());
// DbAttribute "no scale" means -1, not 0 like in JPA.
if (jpaColumn.getScale() > 0) {
dbAttribute.setScale(jpaColumn.getScale());
}
// DbAttribute "no precision" means -1, not 0 like in JPA.
if (jpaColumn.getPrecision() > 0) {
dbAttribute.setAttributePrecision(jpaColumn.getPrecision());
}
if (jpaColumn.getTable() == null) {
throw new JpaProviderException("No default table defined for JpaColumn "
+ jpaColumn.getName());
}
DbEntity entity = ((DataMap) targetPath.firstInstanceOf(DataMap.class))
.getDbEntity(jpaColumn.getTable());
if (entity == null) {
throw new JpaProviderException("No DbEntity defined for table "
+ jpaColumn.getTable());
}
entity.addAttribute(dbAttribute);
return false;