in fastmodel-transform/fastmodel-transform-oceanbase/src/main/java/com/aliyun/fastmodel/transform/oceanbase/parser/OceanBaseMysqlAstBuilder.java [783:834]
public Node visitColumn_attribute(Column_attributeContext ctx) {
//not null
if (ctx.not() != null && ctx.NULLX() != null) {
return new NotNullConstraint(IdentifierUtil.sysIdentifier());
}
//comment
if (ctx.COMMENT() != null) {
TerminalNode terminalNode = ctx.STRING_VALUE();
return new Comment(StripUtils.strip(terminalNode.getText()));
}
//check
if (ctx.CHECK() != null) {
Identifier identifier = IdentifierUtil.sysIdentifier();
if (ctx.opt_constraint_name() != null) {
identifier = (Identifier)visit(ctx.opt_constraint_name());
}
BaseExpression expression = (BaseExpression)visit(ctx.expr());
Boolean enforced = null;
if (ctx.check_state() != null) {
enforced = ctx.check_state().NOT() == null && ctx.check_state().ENFORCED() != null;
}
return new CheckExpressionConstraint(identifier, expression, enforced);
}
//COLLATE
if (ctx.COLLATE() != null) {
String collateName = StripUtils.strip(ctx.collation_name().getText());
return new Property(OceanBasePropertyKey.COLLATE.getValue(), collateName);
}
//default
if (ctx.DEFAULT() != null) {
BaseExpression baseExpression = (BaseExpression)visit(ctx.now_or_signed_literal());
return new DefaultValueConstraint(IdentifierUtil.sysIdentifier(), baseExpression);
}
//unique key
if (ctx.UNIQUE() != null && ctx.KEY() != null) {
return new UniqueConstraint(IdentifierUtil.sysIdentifier(), Lists.newArrayList());
}
//primary key
if (ctx.PRIMARY() != null || ctx.KEY() != null) {
return new PrimaryConstraint(IdentifierUtil.sysIdentifier(), Lists.newArrayList());
}
//auto_increment
if (ctx.AUTO_INCREMENT() != null) {
return new Property(ExtensionPropertyKey.COLUMN_AUTO_INCREMENT.getValue(), String.valueOf(Boolean.TRUE));
}
//return null
if (ctx.NULLX() != null) {
return new NotNullConstraint(IdentifierUtil.sysIdentifier(), false);
}
return super.visitColumn_attribute(ctx);
}