Skip to content

Commit 3a46a29

Browse files
Implement Oracle Alter Session Statements (#1234)
* Implement Oracle Alter Session Statements according to https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_2012.htm * Implement PMD Rule "SwitchStmtsShouldHaveDefault" * Reorganize Test Case imports
1 parent 3082de3 commit 3a46a29

File tree

14 files changed

+460
-1
lines changed

14 files changed

+460
-1
lines changed

pmd-rules.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ under the License.
7575
<!-- for Codazy -->
7676
<rule ref="category/java/design.xml/CyclomaticComplexity" />
7777
<rule ref="category/java/design.xml/ExcessiveMethodLength" />
78+
<rule ref="category/java/bestpractices.xml/SwitchStmtsShouldHaveDefault" />
7879

7980
<rule ref="category/java/errorprone.xml/AvoidBranchingStatementAsLastInLoop" />
8081
<rule ref="category/java/errorprone.xml/AvoidDecimalLiteralsInBigDecimalConstructor" />

src/main/java/net/sf/jsqlparser/statement/StatementVisitor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package net.sf.jsqlparser.statement;
1111

1212
import net.sf.jsqlparser.statement.alter.Alter;
13+
import net.sf.jsqlparser.statement.alter.AlterSession;
1314
import net.sf.jsqlparser.statement.alter.sequence.AlterSequence;
1415
import net.sf.jsqlparser.statement.comment.Comment;
1516
import net.sf.jsqlparser.statement.create.index.CreateIndex;
@@ -102,4 +103,6 @@ public interface StatementVisitor {
102103
void visit(CreateFunctionalStatement createFunctionalStatement);
103104

104105
void visit(CreateSynonym createSynonym);
106+
107+
void visit(AlterSession alterSession);
105108
}

src/main/java/net/sf/jsqlparser/statement/StatementVisitorAdapter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package net.sf.jsqlparser.statement;
1111

1212
import net.sf.jsqlparser.statement.alter.Alter;
13+
import net.sf.jsqlparser.statement.alter.AlterSession;
1314
import net.sf.jsqlparser.statement.alter.sequence.AlterSequence;
1415
import net.sf.jsqlparser.statement.comment.Comment;
1516
import net.sf.jsqlparser.statement.create.index.CreateIndex;
@@ -190,4 +191,9 @@ public void visit(CreateFunctionalStatement createFunctionalStatement) {
190191
@Override
191192
public void visit(CreateSynonym createSynonym) {
192193
}
194+
195+
@Override
196+
public void visit(AlterSession alterSession) {
197+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
198+
}
193199
}
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2021 JSQLParser
6+
* %%
7+
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
8+
* #L%
9+
*/
10+
/*
11+
* Copyright (C) 2021 JSQLParser.
12+
*
13+
* This library is free software; you can redistribute it and/or modify it under the terms of the
14+
* GNU Lesser General Public License as published by the Free Software Foundation; either version
15+
* 2.1 of the License, or (at your option) any later version.
16+
*
17+
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
18+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19+
* Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License along with this library;
22+
* if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23+
* 02110-1301 USA
24+
*/
25+
26+
package net.sf.jsqlparser.statement.alter;
27+
28+
import java.util.List;
29+
import net.sf.jsqlparser.statement.Statement;
30+
import net.sf.jsqlparser.statement.StatementVisitor;
31+
32+
/**
33+
*
34+
* @author are
35+
* @@link https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_2012.htm
36+
*/
37+
public class AlterSession implements Statement {
38+
private AlterSessionOperation operation;
39+
private List<String> parameters;
40+
41+
public AlterSession(AlterSessionOperation operation, List<String> parameters) {
42+
this.operation = operation;
43+
this.parameters = parameters;
44+
}
45+
46+
public AlterSessionOperation getOperation() {
47+
return operation;
48+
}
49+
50+
public void setOperation(AlterSessionOperation operation) {
51+
this.operation = operation;
52+
}
53+
54+
public List<String> getParameters() {
55+
return parameters;
56+
}
57+
58+
public void setParameters(List<String> parameters) {
59+
this.parameters = parameters;
60+
}
61+
62+
private static void appendParamaters(StringBuilder builder, List<String> parameters) {
63+
for (String s: parameters) {
64+
builder.append(" ").append(s);
65+
}
66+
}
67+
68+
@Override
69+
@SuppressWarnings({"PMD.ExcessiveMethodLength", "PMD.CyclomaticComplexity"})
70+
public String toString() {
71+
StringBuilder builder = new StringBuilder();
72+
builder.append("ALTER SESSION ");
73+
switch (operation) {
74+
case ADVISE_COMMIT:
75+
builder.append("ADVISE COMMIT");
76+
break;
77+
case ADVISE_ROLLBACK:
78+
builder.append("ADVISE ROLLBACK");
79+
break;
80+
case ADVISE_NOTHING:
81+
builder.append("ADVISE NOTHING");
82+
break;
83+
case CLOSE_DATABASE_LINK:
84+
builder.append("CLOSE DATABASE LINK ");
85+
appendParamaters(builder, parameters);
86+
break;
87+
case ENABLE_COMMIT_IN_PROCEDURE:
88+
builder.append("ENABLE COMMIT IN PROCEDURE");
89+
break;
90+
case DISABLE_COMMIT_IN_PROCEDURE:
91+
builder.append("DISABLE COMMIT IN PROCEDURE");
92+
break;
93+
case ENABLE_GUARD:
94+
builder.append("ENABLE GUARD");
95+
break;
96+
case DISABLE_GUARD:
97+
builder.append("DISABLE GUARD");
98+
break;
99+
100+
case ENABLE_PARALLEL_DML:
101+
builder.append("ENABLE PARALLEL DML");
102+
appendParamaters(builder, parameters);
103+
break;
104+
105+
case DISABLE_PARALLEL_DML:
106+
builder.append("DISABLE PARALLEL DML");
107+
appendParamaters(builder, parameters);
108+
break;
109+
110+
case FORCE_PARALLEL_DML:
111+
builder.append("FORCE PARALLEL DML");
112+
appendParamaters(builder, parameters);
113+
break;
114+
115+
case ENABLE_PARALLEL_DDL:
116+
builder.append("ENABLE PARALLEL DDL");
117+
appendParamaters(builder, parameters);
118+
break;
119+
120+
case DISABLE_PARALLEL_DDL:
121+
builder.append("DISABLE PARALLEL DDL");
122+
break;
123+
124+
case FORCE_PARALLEL_DDL:
125+
builder.append("FORCE PARALLEL DDL");
126+
appendParamaters(builder, parameters);
127+
break;
128+
129+
case ENABLE_PARALLEL_QUERY:
130+
builder.append("ENABLE PARALLEL QUERY");
131+
appendParamaters(builder, parameters);
132+
break;
133+
134+
case DISABLE_PARALLEL_QUERY:
135+
builder.append("DISABLE PARALLEL QUERY");
136+
break;
137+
138+
case FORCE_PARALLEL_QUERY:
139+
builder.append("FORCE PARALLEL QUERY");
140+
appendParamaters(builder, parameters);
141+
break;
142+
143+
case ENABLE_RESUMABLE:
144+
builder.append("ENABLE RESUMABLE");
145+
appendParamaters(builder, parameters);
146+
break;
147+
148+
case DISABLE_RESUMABLE:
149+
builder.append("DISABLE RESUMABLE");
150+
break;
151+
152+
case SET:
153+
builder.append("SET");
154+
appendParamaters(builder, parameters);
155+
break;
156+
default:
157+
// not going to happen
158+
159+
}
160+
return builder.toString();
161+
}
162+
163+
@Override
164+
public void accept(StatementVisitor statementVisitor) {
165+
statementVisitor.visit(this);
166+
}
167+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2021 JSQLParser
6+
* %%
7+
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
8+
* #L%
9+
*/
10+
/*
11+
* Copyright (C) 2021 JSQLParser.
12+
*
13+
* This library is free software; you can redistribute it and/or modify it under the terms of the
14+
* GNU Lesser General Public License as published by the Free Software Foundation; either version
15+
* 2.1 of the License, or (at your option) any later version.
16+
*
17+
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
18+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19+
* Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License along with this library;
22+
* if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23+
* 02110-1301 USA
24+
*/
25+
26+
package net.sf.jsqlparser.statement.alter;
27+
28+
/**
29+
*
30+
* @author are
31+
*/
32+
public enum AlterSessionOperation {
33+
ADVISE_COMMIT
34+
, ADVISE_ROLLBACK
35+
, ADVISE_NOTHING
36+
, CLOSE_DATABASE_LINK
37+
, ENABLE_COMMIT_IN_PROCEDURE
38+
, DISABLE_COMMIT_IN_PROCEDURE
39+
, ENABLE_GUARD
40+
, DISABLE_GUARD
41+
, ENABLE_PARALLEL_DML
42+
, DISABLE_PARALLEL_DML
43+
, FORCE_PARALLEL_DML
44+
, ENABLE_PARALLEL_DDL
45+
, DISABLE_PARALLEL_DDL
46+
, FORCE_PARALLEL_DDL
47+
, ENABLE_PARALLEL_QUERY
48+
, DISABLE_PARALLEL_QUERY
49+
, FORCE_PARALLEL_QUERY
50+
, ENABLE_RESUMABLE
51+
, DISABLE_RESUMABLE
52+
, SET
53+
}

src/main/java/net/sf/jsqlparser/statement/create/view/CreateView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ public String toString() {
116116
case NO_FORCE:
117117
sql.append("NO FORCE ");
118118
break;
119+
default:
120+
// nothing
119121
}
120122

121123
if (temp != TemporaryOption.NONE) {

src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import net.sf.jsqlparser.schema.Table;
6666
import net.sf.jsqlparser.statement.*;
6767
import net.sf.jsqlparser.statement.alter.Alter;
68+
import net.sf.jsqlparser.statement.alter.AlterSession;
6869
import net.sf.jsqlparser.statement.alter.sequence.AlterSequence;
6970
import net.sf.jsqlparser.statement.comment.Comment;
7071
import net.sf.jsqlparser.statement.create.index.CreateIndex;
@@ -987,4 +988,8 @@ private static <T> void throwUnsupported(T type){
987988
public void visit(TimezoneExpression aThis) {
988989
aThis.getLeftExpression().accept(this);
989990
}
991+
992+
@Override
993+
public void visit(AlterSession alterSession) {
994+
}
990995
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2019 JSQLParser
6+
* %%
7+
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
8+
* #L%
9+
*/
10+
package net.sf.jsqlparser.util.deparser;
11+
12+
import net.sf.jsqlparser.statement.alter.AlterSession;
13+
14+
public class AlterSessionDeParser extends AbstractDeParser<AlterSession> {
15+
16+
public AlterSessionDeParser(StringBuilder buffer) {
17+
super(buffer);
18+
}
19+
20+
@Override
21+
public void deParse(AlterSession alterSession) {
22+
buffer.append(alterSession.toString());
23+
}
24+
25+
}

src/main/java/net/sf/jsqlparser/util/deparser/CreateViewDeParser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public void deParse(CreateView createView) {
5050
break;
5151
case NONE:
5252
break;
53+
default:
54+
// nothing
5355
}
5456
if (createView.getTemporary() != TemporaryOption.NONE) {
5557
buffer.append(createView.getTemporary().name()).append(" ");

src/main/java/net/sf/jsqlparser/util/deparser/StatementDeParser.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import net.sf.jsqlparser.statement.Statements;
2727
import net.sf.jsqlparser.statement.UseStatement;
2828
import net.sf.jsqlparser.statement.alter.Alter;
29+
import net.sf.jsqlparser.statement.alter.AlterSession;
2930
import net.sf.jsqlparser.statement.alter.sequence.AlterSequence;
3031
import net.sf.jsqlparser.statement.comment.Comment;
3132
import net.sf.jsqlparser.statement.create.index.CreateIndex;
@@ -320,4 +321,9 @@ public void visit(CreateSynonym createSynonym) {
320321
void deParse(Statement statement) {
321322
statement.accept(this);
322323
}
324+
325+
@Override
326+
public void visit(AlterSession alterSession) {
327+
new AlterSessionDeParser(buffer).deParse(alterSession);
328+
}
323329
}

0 commit comments

Comments
 (0)