Skip to content

Commit

Permalink
Implement Oracle Alter Session Statements (#1234)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
manticore-projects authored Jun 26, 2021
1 parent 3082de3 commit 3a46a29
Show file tree
Hide file tree
Showing 14 changed files with 460 additions and 1 deletion.
1 change: 1 addition & 0 deletions pmd-rules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ under the License.
<!-- for Codazy -->
<rule ref="category/java/design.xml/CyclomaticComplexity" />
<rule ref="category/java/design.xml/ExcessiveMethodLength" />
<rule ref="category/java/bestpractices.xml/SwitchStmtsShouldHaveDefault" />

<rule ref="category/java/errorprone.xml/AvoidBranchingStatementAsLastInLoop" />
<rule ref="category/java/errorprone.xml/AvoidDecimalLiteralsInBigDecimalConstructor" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package net.sf.jsqlparser.statement;

import net.sf.jsqlparser.statement.alter.Alter;
import net.sf.jsqlparser.statement.alter.AlterSession;
import net.sf.jsqlparser.statement.alter.sequence.AlterSequence;
import net.sf.jsqlparser.statement.comment.Comment;
import net.sf.jsqlparser.statement.create.index.CreateIndex;
Expand Down Expand Up @@ -102,4 +103,6 @@ public interface StatementVisitor {
void visit(CreateFunctionalStatement createFunctionalStatement);

void visit(CreateSynonym createSynonym);

void visit(AlterSession alterSession);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package net.sf.jsqlparser.statement;

import net.sf.jsqlparser.statement.alter.Alter;
import net.sf.jsqlparser.statement.alter.AlterSession;
import net.sf.jsqlparser.statement.alter.sequence.AlterSequence;
import net.sf.jsqlparser.statement.comment.Comment;
import net.sf.jsqlparser.statement.create.index.CreateIndex;
Expand Down Expand Up @@ -190,4 +191,9 @@ public void visit(CreateFunctionalStatement createFunctionalStatement) {
@Override
public void visit(CreateSynonym createSynonym) {
}

@Override
public void visit(AlterSession alterSession) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
167 changes: 167 additions & 0 deletions src/main/java/net/sf/jsqlparser/statement/alter/AlterSession.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2021 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
/*
* Copyright (C) 2021 JSQLParser.
*
* This library is free software; you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this library;
* if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/

package net.sf.jsqlparser.statement.alter;

import java.util.List;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.StatementVisitor;

/**
*
* @author are
* @@link https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_2012.htm
*/
public class AlterSession implements Statement {
private AlterSessionOperation operation;
private List<String> parameters;

public AlterSession(AlterSessionOperation operation, List<String> parameters) {
this.operation = operation;
this.parameters = parameters;
}

public AlterSessionOperation getOperation() {
return operation;
}

public void setOperation(AlterSessionOperation operation) {
this.operation = operation;
}

public List<String> getParameters() {
return parameters;
}

public void setParameters(List<String> parameters) {
this.parameters = parameters;
}

private static void appendParamaters(StringBuilder builder, List<String> parameters) {
for (String s: parameters) {
builder.append(" ").append(s);
}
}

@Override
@SuppressWarnings({"PMD.ExcessiveMethodLength", "PMD.CyclomaticComplexity"})
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ALTER SESSION ");
switch (operation) {
case ADVISE_COMMIT:
builder.append("ADVISE COMMIT");
break;
case ADVISE_ROLLBACK:
builder.append("ADVISE ROLLBACK");
break;
case ADVISE_NOTHING:
builder.append("ADVISE NOTHING");
break;
case CLOSE_DATABASE_LINK:
builder.append("CLOSE DATABASE LINK ");
appendParamaters(builder, parameters);
break;
case ENABLE_COMMIT_IN_PROCEDURE:
builder.append("ENABLE COMMIT IN PROCEDURE");
break;
case DISABLE_COMMIT_IN_PROCEDURE:
builder.append("DISABLE COMMIT IN PROCEDURE");
break;
case ENABLE_GUARD:
builder.append("ENABLE GUARD");
break;
case DISABLE_GUARD:
builder.append("DISABLE GUARD");
break;

case ENABLE_PARALLEL_DML:
builder.append("ENABLE PARALLEL DML");
appendParamaters(builder, parameters);
break;

case DISABLE_PARALLEL_DML:
builder.append("DISABLE PARALLEL DML");
appendParamaters(builder, parameters);
break;

case FORCE_PARALLEL_DML:
builder.append("FORCE PARALLEL DML");
appendParamaters(builder, parameters);
break;

case ENABLE_PARALLEL_DDL:
builder.append("ENABLE PARALLEL DDL");
appendParamaters(builder, parameters);
break;

case DISABLE_PARALLEL_DDL:
builder.append("DISABLE PARALLEL DDL");
break;

case FORCE_PARALLEL_DDL:
builder.append("FORCE PARALLEL DDL");
appendParamaters(builder, parameters);
break;

case ENABLE_PARALLEL_QUERY:
builder.append("ENABLE PARALLEL QUERY");
appendParamaters(builder, parameters);
break;

case DISABLE_PARALLEL_QUERY:
builder.append("DISABLE PARALLEL QUERY");
break;

case FORCE_PARALLEL_QUERY:
builder.append("FORCE PARALLEL QUERY");
appendParamaters(builder, parameters);
break;

case ENABLE_RESUMABLE:
builder.append("ENABLE RESUMABLE");
appendParamaters(builder, parameters);
break;

case DISABLE_RESUMABLE:
builder.append("DISABLE RESUMABLE");
break;

case SET:
builder.append("SET");
appendParamaters(builder, parameters);
break;
default:
// not going to happen

}
return builder.toString();
}

@Override
public void accept(StatementVisitor statementVisitor) {
statementVisitor.visit(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2021 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
/*
* Copyright (C) 2021 JSQLParser.
*
* This library is free software; you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this library;
* if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/

package net.sf.jsqlparser.statement.alter;

/**
*
* @author are
*/
public enum AlterSessionOperation {
ADVISE_COMMIT
, ADVISE_ROLLBACK
, ADVISE_NOTHING
, CLOSE_DATABASE_LINK
, ENABLE_COMMIT_IN_PROCEDURE
, DISABLE_COMMIT_IN_PROCEDURE
, ENABLE_GUARD
, DISABLE_GUARD
, ENABLE_PARALLEL_DML
, DISABLE_PARALLEL_DML
, FORCE_PARALLEL_DML
, ENABLE_PARALLEL_DDL
, DISABLE_PARALLEL_DDL
, FORCE_PARALLEL_DDL
, ENABLE_PARALLEL_QUERY
, DISABLE_PARALLEL_QUERY
, FORCE_PARALLEL_QUERY
, ENABLE_RESUMABLE
, DISABLE_RESUMABLE
, SET
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public String toString() {
case NO_FORCE:
sql.append("NO FORCE ");
break;
default:
// nothing
}

if (temp != TemporaryOption.NONE) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.*;
import net.sf.jsqlparser.statement.alter.Alter;
import net.sf.jsqlparser.statement.alter.AlterSession;
import net.sf.jsqlparser.statement.alter.sequence.AlterSequence;
import net.sf.jsqlparser.statement.comment.Comment;
import net.sf.jsqlparser.statement.create.index.CreateIndex;
Expand Down Expand Up @@ -987,4 +988,8 @@ private static <T> void throwUnsupported(T type){
public void visit(TimezoneExpression aThis) {
aThis.getLeftExpression().accept(this);
}

@Override
public void visit(AlterSession alterSession) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.util.deparser;

import net.sf.jsqlparser.statement.alter.AlterSession;

public class AlterSessionDeParser extends AbstractDeParser<AlterSession> {

public AlterSessionDeParser(StringBuilder buffer) {
super(buffer);
}

@Override
public void deParse(AlterSession alterSession) {
buffer.append(alterSession.toString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public void deParse(CreateView createView) {
break;
case NONE:
break;
default:
// nothing
}
if (createView.getTemporary() != TemporaryOption.NONE) {
buffer.append(createView.getTemporary().name()).append(" ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.sf.jsqlparser.statement.Statements;
import net.sf.jsqlparser.statement.UseStatement;
import net.sf.jsqlparser.statement.alter.Alter;
import net.sf.jsqlparser.statement.alter.AlterSession;
import net.sf.jsqlparser.statement.alter.sequence.AlterSequence;
import net.sf.jsqlparser.statement.comment.Comment;
import net.sf.jsqlparser.statement.create.index.CreateIndex;
Expand Down Expand Up @@ -320,4 +321,9 @@ public void visit(CreateSynonym createSynonym) {
void deParse(Statement statement) {
statement.accept(this);
}

@Override
public void visit(AlterSession alterSession) {
new AlterSessionDeParser(buffer).deParse(alterSession);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2020 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.util.validation.validator;

import net.sf.jsqlparser.statement.alter.AlterSession;

/**
* @author gitmotte
*/
public class AlterSessionValidator extends AbstractValidator<AlterSession> {
@Override
public void validate(AlterSession statement) {
//@todo: implement this method
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.sf.jsqlparser.statement.Statements;
import net.sf.jsqlparser.statement.UseStatement;
import net.sf.jsqlparser.statement.alter.Alter;
import net.sf.jsqlparser.statement.alter.AlterSession;
import net.sf.jsqlparser.statement.alter.sequence.AlterSequence;
import net.sf.jsqlparser.statement.comment.Comment;
import net.sf.jsqlparser.statement.create.function.CreateFunction;
Expand Down Expand Up @@ -254,4 +255,9 @@ public void visit(CreateSynonym createSynonym) {
getValidator(CreateSynonymValidator.class).validate(createSynonym);
}

@Override
public void visit(AlterSession alterSession) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

}
Loading

0 comments on commit 3a46a29

Please sign in to comment.