private final ISqlJetTypeDef type;
private final List<ISqlJetColumnConstraint> constraints;
public SqlJetColumnDef(CommonTree ast) throws SqlJetException {
name = ast.getText();
CommonTree constraintsNode = (CommonTree) ast.getChild(0);
assert "constraints".equalsIgnoreCase(constraintsNode.getText());
List<ISqlJetColumnConstraint> constraints = new ArrayList<ISqlJetColumnConstraint>();
for (int i = 0; i < constraintsNode.getChildCount(); i++) {
CommonTree constraintRootNode = (CommonTree) constraintsNode.getChild(i);
assert "column_constraint".equalsIgnoreCase(constraintRootNode.getText());
CommonTree constraintNode = (CommonTree) constraintRootNode.getChild(0);
String constraintType = constraintNode.getText();
String constraintName = constraintRootNode.getChildCount() > 1 ? constraintRootNode.getChild(1).getText()
: null;
if ("primary".equalsIgnoreCase(constraintType)) {
constraints.add(new SqlJetColumnPrimaryKey(this, constraintName, constraintNode));
} else if ("not_null".equalsIgnoreCase(constraintType)) {
constraints.add(new SqlJetColumnNotNull(this, constraintName, constraintNode));
} else if ("unique".equalsIgnoreCase(constraintType)) {
constraints.add(new SqlJetColumnUnique(this, constraintName, constraintNode));
} else if ("check".equalsIgnoreCase(constraintType)) {
constraints.add(new SqlJetColumnCheck(this, constraintName, constraintNode));
} else if ("default".equalsIgnoreCase(constraintType)) {
constraints.add(new SqlJetColumnDefault(this, constraintName, constraintNode));
} else if ("collate".equalsIgnoreCase(constraintType)) {
constraints.add(new SqlJetColumnCollate(this, constraintName, constraintNode));
} else if ("references".equalsIgnoreCase(constraintType)) {
constraints.add(new SqlJetColumnForeignKey(constraintName, constraintNode));
} else if ("is_null".equalsIgnoreCase(constraintType)) {
constraints.add(new SqlJetColumnNull(this, constraintName, constraintNode));
} else {
assert false;
}
}
this.constraints = Collections.unmodifiableList(constraints);
if (ast.getChildCount() > 1) {
CommonTree typeNode = (CommonTree) ast.getChild(1);
assert "type".equalsIgnoreCase(typeNode.getText());
type = new SqlJetTypeDef(typeNode);
} else {
type = null;
}
}