Index: src/main/java/org/modeshape/sequencer/ddl/StandardDdlParser.java =================================================================== --- src/main/java/org/modeshape/sequencer/ddl/StandardDdlParser.java (revision 2498) +++ src/main/java/org/modeshape/sequencer/ddl/StandardDdlParser.java (working copy) @@ -1548,7 +1548,12 @@ constraintNode.setProperty(CONSTRAINT_TYPE, PRIMARY_KEY); // CONSUME COLUMNS - parseColumnNameList(tokens, constraintNode, TYPE_COLUMN_REFERENCE); + boolean columnsAdded = parseColumnNameList(tokens, constraintNode, TYPE_COLUMN_REFERENCE); + + if (!columnsAdded) { + // add the current column as the PK reference + nodeFactory().node(colName, constraintNode, TYPE_COLUMN_REFERENCE); + } parseConstraintAttributes(tokens, constraintNode); } else if (tokens.matches("REFERENCES")) { Index: src/test/java/org/modeshape/sequencer/ddl/StandardDdlParserTest.java =================================================================== --- src/test/java/org/modeshape/sequencer/ddl/StandardDdlParserTest.java (revision 2498) +++ src/test/java/org/modeshape/sequencer/ddl/StandardDdlParserTest.java (working copy) @@ -43,6 +43,7 @@ import static org.modeshape.sequencer.ddl.StandardDdlLexicon.TYPE_ADD_TABLE_CONSTRAINT_DEFINITION; import static org.modeshape.sequencer.ddl.StandardDdlLexicon.TYPE_ALTER_TABLE_STATEMENT; import static org.modeshape.sequencer.ddl.StandardDdlLexicon.TYPE_COLUMN_DEFINITION; +import static org.modeshape.sequencer.ddl.StandardDdlLexicon.TYPE_COLUMN_REFERENCE; import static org.modeshape.sequencer.ddl.StandardDdlLexicon.TYPE_CREATE_SCHEMA_STATEMENT; import static org.modeshape.sequencer.ddl.StandardDdlLexicon.TYPE_CREATE_TABLE_STATEMENT; import static org.modeshape.sequencer.ddl.StandardDdlLexicon.TYPE_CREATE_VIEW_STATEMENT; @@ -63,6 +64,7 @@ import org.junit.Test; import org.modeshape.common.FixFor; import org.modeshape.graph.JcrLexicon; +import org.modeshape.graph.property.Property; import org.modeshape.sequencer.ddl.node.AstNode; public class StandardDdlParserTest extends DdlParserTestHelper { @@ -809,6 +811,42 @@ AstNode columnRef = prim_key.getChildren().get(0); assertEquals("REALMUID", columnRef.getName().getString()); } + + @Test + public void shouldParseCreateTableWithPrimaryKeyColumnConstraint() { + printTest("shouldWork()"); + String PK_COL = "customerfamilyhistoryid"; + String content = "CREATE TABLE CustomerFamilyHistory ("; + content += PK_COL + " numeric(10) CONSTRAINT customerfamilyhistoryid_pk PRIMARY KEY, firstname varchar(50) NOT NULL, lastname varchar(50) NOT NULL, age numeric(3), sibling varchar(20), customerid numeric(7) NOT NULL);"; + DdlTokenStream tokens = getTokens(content); + AstNode result = parser.parseCreateTableStatement(tokens, rootNode); + + // test to make sure there is a table node + assertEquals(1, rootNode.getChildCount()); // TABLE + AstNode tableNode = rootNode.getChild(0); + + // test to make sure all columns and primary key constraint are children of the table node + assertEquals(7, tableNode.getChildCount()); // 6 Columns + 1 Constraint + + // find constraint + boolean foundConstraint = false; + for (AstNode kid : tableNode.getChildren()) { + Property value = (Property)kid.getProperty(CONSTRAINT_TYPE); + + if (value != null) { + assertFalse(foundConstraint); // make sure no other constraint found + foundConstraint = true; + + assertEquals(value.getFirstValue(), PRIMARY_KEY); // test for primary key + + // make sure a child node pointing to the column is found + assertEquals(1, kid.getChildCount()); + AstNode child = kid.getChild(0); + assertTrue(hasMixinType(child.getProperty(JcrLexicon.MIXIN_TYPES), TYPE_COLUMN_REFERENCE)); + assertEquals(PK_COL, child.getName().getString()); + } + } + } @Test public void shouldParseCreateTableWithInlineUniqueConstraintWithColumns() {