Skip to content

Commit 49a3518

Browse files
committed
Add SET CONSTRAINTS statement.
1 parent 75b7edf commit 49a3518

11 files changed

Lines changed: 229 additions & 5 deletions

File tree

‎src/main/java/com/foundationdb/sql/parser/NodeFactoryImpl.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ protected String nodeName(int nodeType) throws StandardException {
187187
case NodeTypes.TABLE_NAME:
188188
return NodeNames.TABLE_NAME_NAME;
189189

190+
case NodeTypes.TABLE_NAME_LIST:
191+
return NodeNames.TABLE_NAME_LIST_NAME;
192+
190193
case NodeTypes.GROUP_BY_COLUMN:
191194
return NodeNames.GROUP_BY_COLUMN_NAME;
192195

@@ -668,6 +671,9 @@ protected String nodeName(int nodeType) throws StandardException {
668671
case NodeTypes.STORAGE_FORMAT_NODE:
669672
return NodeNames.STORAGE_FORMAT_NODE_NAME;
670673

674+
case NodeTypes.SET_CONSTRAINTS_NODE:
675+
return NodeNames.SET_CONSTRAINTS_NODE_NAME;
676+
671677
default:
672678
throw new StandardException("Not implemented");
673679
}

‎src/main/java/com/foundationdb/sql/parser/NodeNames.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ public interface NodeNames
319319

320320
static final String SET_CONFIGURATION_NODE_NAME = "com.foundationdb.sql.parser.SetConfigurationNode";
321321

322+
static final String SET_CONSTRAINTS_NODE_NAME = "com.foundationdb.sql.parser.SetConstraintsNode";
323+
322324
static final String SET_ROLE_NODE_NAME = "com.foundationdb.sql.parser.SetRoleNode";
323325

324326
static final String SET_SCHEMA_NODE_NAME = "com.foundationdb.sql.parser.SetSchemaNode";
@@ -355,6 +357,8 @@ public interface NodeNames
355357

356358
static final String TABLE_NAME_NAME = "com.foundationdb.sql.parser.TableName";
357359

360+
static final String TABLE_NAME_LIST_NAME = "com.foundationdb.sql.parser.TableNameList";
361+
358362
static final String TABLE_PRIVILEGES_NAME = "com.foundationdb.sql.parser.TablePrivilegesNode";
359363

360364
static final String TERNARY_OPERATOR_NODE_NAME = "com.foundationdb.sql.parser.TernaryOperatorNode";

‎src/main/java/com/foundationdb/sql/parser/NodeTypes.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,9 @@ public interface NodeTypes
223223
public static final int FULL_OUTER_JOIN_NODE = 173;
224224
public static final int SHOW_CONFIGURATION_NODE = 174;
225225
public static final int STORAGE_FORMAT_NODE = 175;
226-
// 176 - 182 available
226+
public static final int TABLE_NAME_LIST = 176;
227+
public static final int SET_CONSTRAINTS_NODE = 177;
228+
// 178 - 182 available
227229
public static final int ALTER_SERVER_NODE = 183;
228230
public static final int TIMESTAMP_ADD_FN_NODE = 184;
229231
public static final int TIMESTAMP_DIFF_FN_NODE = 185;
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/**
2+
* Copyright 2011-2013 FoundationDB, LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.foundationdb.sql.parser;
18+
19+
import com.foundationdb.sql.StandardException;
20+
21+
/**
22+
* A SET CONSTRAINTS statement.
23+
*/
24+
25+
public class SetConstraintsNode extends StatementNode
26+
{
27+
private boolean all;
28+
private TableNameList constraints;
29+
private boolean deferred;
30+
31+
/**
32+
* Initializer for SetTransactionIsolationNode
33+
*
34+
* @param all whether to affect all constraints
35+
* @param constraints list of constraints to affect
36+
* @param deferred <code>true</code> to defer
37+
*/
38+
public void init(Object all,
39+
Object constraints,
40+
Object deferred) {
41+
this.all = (Boolean)all;
42+
this.constraints = (TableNameList)constraints;
43+
this.deferred = (Boolean)deferred;
44+
}
45+
46+
public boolean isAll() {
47+
return all;
48+
}
49+
50+
public TableNameList getConstraints() {
51+
return constraints;
52+
}
53+
54+
public boolean isDeferred() {
55+
return deferred;
56+
}
57+
58+
/**
59+
* Fill this node with a deep copy of the given node.
60+
*/
61+
public void copyFrom(QueryTreeNode node) throws StandardException {
62+
super.copyFrom(node);
63+
64+
SetConstraintsNode other = (SetConstraintsNode)node;
65+
this.all = other.all;
66+
this.constraints = (TableNameList)getNodeFactory().copyNode(other.constraints,
67+
getParserContext());
68+
this.deferred = other.deferred;
69+
}
70+
71+
/**
72+
* Convert this object to a String. See comments in QueryTreeNode.java
73+
* for how this should be done for tree printing.
74+
*
75+
* @return This object as a String
76+
*/
77+
78+
public String toString() {
79+
return "all: " + all + "\n" +
80+
super.toString();
81+
}
82+
83+
/**
84+
* Prints the sub-nodes of this object. See QueryTreeNode.java for
85+
* how tree printing is supposed to work.
86+
*
87+
* @param depth The depth of this node in the tree
88+
*/
89+
90+
public void printSubNodes(int depth) {
91+
super.printSubNodes(depth);
92+
93+
if (constraints != null) {
94+
printLabel(depth, "constraints: ");
95+
constraints.treePrint(depth + 1);
96+
}
97+
}
98+
99+
/**
100+
* Accept the visitor for all visitable children of this node.
101+
*
102+
* @param v the visitor
103+
*
104+
* @exception StandardException on error
105+
*/
106+
void acceptChildren(Visitor v) throws StandardException {
107+
super.acceptChildren(v);
108+
109+
if (constraints != null) {
110+
constraints = (TableNameList)constraints.accept(v);
111+
}
112+
}
113+
114+
public String statementToString() {
115+
return "SET CONSTRAINTS";
116+
}
117+
118+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright 2011-2013 FoundationDB, LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.foundationdb.sql.parser;
18+
19+
/**
20+
* List of TableName
21+
*
22+
*/
23+
public class TableNameList extends QueryTreeNodeList<TableName>
24+
{
25+
}

‎src/main/java/com/foundationdb/sql/unparser/NodeToString.java‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@ public String toString(QueryTreeNode node) throws StandardException {
4848
return setTransactionIsolationNode((SetTransactionIsolationNode)node);
4949
case NodeTypes.SET_TRANSACTION_ACCESS_NODE:
5050
return setTransactionAccessNode((SetTransactionAccessNode)node);
51+
case NodeTypes.SET_CONSTRAINTS_NODE:
52+
return setConstraintsNode((SetConstraintsNode)node);
5153
case NodeTypes.SET_CONFIGURATION_NODE:
5254
return setConfigurationNode((SetConfigurationNode)node);
5355
case NodeTypes.SHOW_CONFIGURATION_NODE:
5456
return showConfigurationNode((ShowConfigurationNode)node);
5557
case NodeTypes.TABLE_ELEMENT_LIST:
5658
return tableElementList((TableElementList)node);
59+
case NodeTypes.TABLE_NAME_LIST:
60+
return tableNameList((TableNameList)node);
5761
case NodeTypes.COLUMN_DEFINITION_NODE:
5862
return columnDefinitionNode((ColumnDefinitionNode)node);
5963
case NodeTypes.CONSTRAINT_DEFINITION_NODE:
@@ -372,6 +376,10 @@ protected String tableElementList(TableElementList node) throws StandardExceptio
372376
return nodeList(node);
373377
}
374378

379+
protected String tableNameList(TableNameList node) throws StandardException {
380+
return nodeList(node);
381+
}
382+
375383
protected String columnDefinitionNode(ColumnDefinitionNode node)
376384
throws StandardException {
377385
return node.getColumnName() + " " + node.getType();
@@ -1332,6 +1340,26 @@ protected String setTransactionAccessNode(SetTransactionAccessNode node)
13321340
return node.statementToString() + " " + node.getAccessMode().getSyntax();
13331341
}
13341342

1343+
protected String setConstraintsNode(SetConstraintsNode node)
1344+
throws StandardException {
1345+
StringBuilder str = new StringBuilder(node.statementToString());
1346+
str.append(" ");
1347+
if (node.isAll()) {
1348+
str.append("ALL");
1349+
}
1350+
else {
1351+
str.append(toString(node.getConstraints()));
1352+
}
1353+
str.append(" ");
1354+
if (node.isDeferred()) {
1355+
str.append("DEFERRED");
1356+
}
1357+
else {
1358+
str.append("IMMEDIATE");
1359+
}
1360+
return str.toString();
1361+
}
1362+
13351363
protected String setConfigurationNode(SetConfigurationNode node)
13361364
throws StandardException {
13371365
return node.statementToString() + " = '" + node.getValue() + "'";

‎src/main/javacc/SQLGrammar.jj‎

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3313,6 +3313,8 @@ spsSetStatement() throws StandardException :
33133313
statementNode = setRoleStatement()
33143314
|
33153315
statementNode = setTransactionStatement()
3316+
|
3317+
statementNode = setConstraintsStatement()
33163318
|
33173319
statementNode = setConfigurationStatement()
33183320
)
@@ -4919,16 +4921,22 @@ intervalNonSecond() throws StandardException :
49194921

49204922

49214923

4922-
void
4923-
qualifiedNameList(List<TableName> list) throws StandardException :
4924-
{}
4924+
TableNameList
4925+
qualifiedNameList() throws StandardException :
4926+
{
4927+
TableNameList list = (TableNameList)
4928+
nodeFactory.getNode(NodeTypes.TABLE_NAME_LIST, parserContext);
4929+
}
49254930
{
49264931
qualifiedNameElement(list)
49274932
( <COMMA> qualifiedNameElement(list) )*
4933+
{
4934+
return list;
4935+
}
49284936
}
49294937

49304938
void
4931-
qualifiedNameElement(List<TableName> list) throws StandardException :
4939+
qualifiedNameElement(TableNameList list) throws StandardException :
49324940
{
49334941
TableName qualifiedName = null;
49344942
}
@@ -12639,6 +12647,35 @@ transactionAccessMode() throws StandardException :
1263912647
)
1264012648
}
1264112649

12650+
StatementNode
12651+
setConstraintsStatement() throws StandardException :
12652+
{
12653+
boolean all = false;
12654+
TableNameList constraints = null;
12655+
boolean deferred;
12656+
}
12657+
{
12658+
<CONSTRAINTS>
12659+
(
12660+
<ALL>
12661+
{
12662+
all = true;
12663+
}
12664+
|
12665+
constraints = qualifiedNameList()
12666+
)
12667+
(
12668+
<DEFERRED> { deferred = true; }
12669+
|
12670+
<IMMEDIATE> { deferred = false; }
12671+
)
12672+
{
12673+
return (StatementNode)nodeFactory.getNode(NodeTypes.SET_CONSTRAINTS_NODE,
12674+
all, constraints, deferred,
12675+
parserContext);
12676+
}
12677+
}
12678+
1264212679
StatementNode
1264312680
setConfigurationStatement() throws StandardException :
1264412681
{
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SET CONSTRAINTS ALL DEFERRED
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SET CONSTRAINTS ALL DEFERRED
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SET CONSTRAINTS foo, x.bar IMMEDIATE

0 commit comments

Comments
 (0)