Search in sources :

Example 1 with ReferentialAction

use of net.sf.jsqlparser.statement.ReferentialAction in project JSqlParser by JSQLParser.

the class AlterTest method assertReferentialActionOnConstraint.

private void assertReferentialActionOnConstraint(Alter parsed, Action onUpdate, Action onDelete) {
    AlterExpression alterExpression = parsed.getAlterExpressions().get(0);
    ForeignKeyIndex index = (ForeignKeyIndex) alterExpression.getIndex();
    // remove line if deprecated methods are removed.
    index.setOnDeleteReferenceOption(index.getOnDeleteReferenceOption());
    if (onDelete != null) {
        assertEquals(new ReferentialAction(Type.DELETE, onDelete), index.getReferentialAction(Type.DELETE));
    } else {
        assertNull(index.getReferentialAction(Type.DELETE));
    }
    // remove line if deprecated methods are removed.
    index.setOnUpdateReferenceOption(index.getOnUpdateReferenceOption());
    if (onUpdate != null) {
        assertEquals(new ReferentialAction(Type.UPDATE, onUpdate), index.getReferentialAction(Type.UPDATE));
    } else {
        assertNull(index.getReferentialAction(Type.UPDATE));
    }
}
Also used : ReferentialAction(net.sf.jsqlparser.statement.ReferentialAction) ForeignKeyIndex(net.sf.jsqlparser.statement.create.table.ForeignKeyIndex)

Example 2 with ReferentialAction

use of net.sf.jsqlparser.statement.ReferentialAction in project JSqlParser by JSQLParser.

the class AlterTest method assertReferentialAction.

private void assertReferentialAction(Alter parsed, Action onUpdate, Action onDelete) {
    AlterExpression alterExpression = parsed.getAlterExpressions().get(0);
    if (onDelete != null) {
        ReferentialAction actual = alterExpression.getReferentialAction(Type.DELETE);
        assertEquals(new ReferentialAction(Type.DELETE, onDelete), actual);
        // remove line if deprecated methods are removed.
        if (Action.CASCADE.equals(actual.getAction())) {
            alterExpression.setOnDeleteCascade(alterExpression.isOnDeleteCascade());
        }
        if (Action.RESTRICT.equals(actual.getAction())) {
            alterExpression.setOnDeleteRestrict(alterExpression.isOnDeleteRestrict());
        }
        if (Action.SET_NULL.equals(actual.getAction())) {
            alterExpression.setOnDeleteSetNull(alterExpression.isOnDeleteSetNull());
        }
    } else {
        assertNull(alterExpression.getReferentialAction(Type.DELETE));
    }
    if (onUpdate != null) {
        // remove line if deprecated methods are removed.
        assertEquals(new ReferentialAction(Type.UPDATE, onUpdate), alterExpression.getReferentialAction(Type.UPDATE));
    } else {
        assertNull(alterExpression.getReferentialAction(Type.UPDATE));
    }
}
Also used : ReferentialAction(net.sf.jsqlparser.statement.ReferentialAction)

Aggregations

ReferentialAction (net.sf.jsqlparser.statement.ReferentialAction)2 ForeignKeyIndex (net.sf.jsqlparser.statement.create.table.ForeignKeyIndex)1