Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions src/main/java/net/sf/jsqlparser/statement/RollbackStatement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*-
* #%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;

/**
*
* @author are
*/
public class RollbackStatement implements Statement {
private boolean usingWorkKeyword=false;
private boolean usingSavepointKeyword=false;
private String savepointName=null;
private String forceDistributedTransactionIdentifier=null;

public boolean isUsingWorkKeyword() {
return usingWorkKeyword;
}

public RollbackStatement withUsingWorkKeyword(boolean usingWorkKeyword) {
this.usingWorkKeyword = usingWorkKeyword;
return this;
}

public void setUsingWorkKeyword(boolean usingWorkKeyword) {
this.usingWorkKeyword = usingWorkKeyword;
}

public boolean isUsingSavepointKeyword() {
return usingSavepointKeyword;
}

public RollbackStatement withUsingSavepointKeyword(boolean usingSavepointKeyword) {
this.usingSavepointKeyword = usingSavepointKeyword;
return this;
}

public void setUsingSavepointKeyword(boolean usingSavepointKeyword) {
this.usingSavepointKeyword = usingSavepointKeyword;
}

public String getSavepointName() {
return savepointName;
}

public RollbackStatement withSavepointName(String savepointName) {
this.savepointName = savepointName;
return this;
}

public void setSavepointName(String savepointName) {
this.savepointName = savepointName;
}

public String getForceDistributedTransactionIdentifier() {
return forceDistributedTransactionIdentifier;
}

public RollbackStatement withForceDistributedTransactionIdentifier(String forceDistributedTransactionIdentifier) {
this.forceDistributedTransactionIdentifier = forceDistributedTransactionIdentifier;
return this;
}

public void setForceDistributedTransactionIdentifier(String forceDistributedTransactionIdentifier) {
this.forceDistributedTransactionIdentifier = forceDistributedTransactionIdentifier;
}

@Override
public String toString() {
return "ROLLBACK "
+ ( usingWorkKeyword
? "WORK "
: "" )
+ (savepointName!=null && savepointName.trim().length()!=0
? "TO " + (usingSavepointKeyword
? "SAVEPOINT "
: "") + savepointName
: forceDistributedTransactionIdentifier!=null && forceDistributedTransactionIdentifier.trim().length()!=0
? "FORCE " + forceDistributedTransactionIdentifier
: ""

);
}

@Override
public void accept(StatementVisitor statementVisitor) {
statementVisitor.visit(this);
}

}
58 changes: 58 additions & 0 deletions src/main/java/net/sf/jsqlparser/statement/SavepointStatement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*-
* #%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;

import java.util.Objects;

/**
*
* @author are
*/
public class SavepointStatement implements Statement {
private String savepointName;

public String getSavepointName() {
return savepointName;
}

public void setSavepointName(String savepointName) {
this.savepointName = Objects.requireNonNull(savepointName, "The Savepoint Name must not be NULL.");
}

public SavepointStatement(String savepointName) {
this.savepointName = Objects.requireNonNull(savepointName, "The Savepoint Name must not be NULL.");
}

@Override
public String toString() {
return "SAVEPOINT " + savepointName;
}

@Override
public void accept(StatementVisitor statementVisitor) {
statementVisitor.visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
import net.sf.jsqlparser.statement.values.ValuesStatement;

public interface StatementVisitor {

void visit(SavepointStatement savepointStatement);

void visit(RollbackStatement rollbackStatement);

void visit(Comment comment);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,17 @@ public void visit(CreateFunctionalStatement createFunctionalStatement) {
public void visit(CreateSynonym createSynonym) {
}

@Override
public void visit(SavepointStatement savepointStatement) {
//@todo: do something usefull here
}

@Override
public void visit(RollbackStatement rollbackStatement) {
//@todo: do something usefull here
}
@Override
public void visit(AlterSession alterSession) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
//@todo: do something usefull here
}
}
10 changes: 10 additions & 0 deletions src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,17 @@ public void visit(TimezoneExpression aThis) {
aThis.getLeftExpression().accept(this);
}

@Override
public void visit(SavepointStatement savepointStatement) {
}

@Override
public void visit(RollbackStatement rollbackStatement) {

}

@Override
public void visit(AlterSession alterSession) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import net.sf.jsqlparser.statement.DeclareStatement;
import net.sf.jsqlparser.statement.DescribeStatement;
import net.sf.jsqlparser.statement.ExplainStatement;
import net.sf.jsqlparser.statement.RollbackStatement;
import net.sf.jsqlparser.statement.SavepointStatement;
import net.sf.jsqlparser.statement.ResetStatement;
import net.sf.jsqlparser.statement.SetStatement;
import net.sf.jsqlparser.statement.ShowColumnsStatement;
Expand Down Expand Up @@ -216,6 +218,16 @@ public void visit(Merge merge) {
buffer.append(merge.toString());
}

@Override
public void visit(SavepointStatement savepointStatement) {
buffer.append(savepointStatement.toString());
}

@Override
public void visit(RollbackStatement rollbackStatement) {
buffer.append(rollbackStatement.toString());
}

@Override
public void visit(Commit commit) {
buffer.append(commit.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import net.sf.jsqlparser.statement.DeclareStatement;
import net.sf.jsqlparser.statement.DescribeStatement;
import net.sf.jsqlparser.statement.ExplainStatement;
import net.sf.jsqlparser.statement.RollbackStatement;
import net.sf.jsqlparser.statement.SavepointStatement;
import net.sf.jsqlparser.statement.ResetStatement;
import net.sf.jsqlparser.statement.SetStatement;
import net.sf.jsqlparser.statement.ShowColumnsStatement;
Expand Down Expand Up @@ -262,8 +264,17 @@ public void visit(CreateSynonym createSynonym) {
}

@Override
public void visit(SavepointStatement savepointStatement) {
//@todo: write something usefull here
}

@Override
public void visit(RollbackStatement rollbackStatement) {
//@todo: write something usefull here
}

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

}
42 changes: 42 additions & 0 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
| <K_ROLLBACK:"ROLLBACK">
| <K_ROW: "ROW">
| <K_ROWS: "ROWS">
| <K_SAVEPOINT: "SAVEPOINT">
| <K_SCHEMA: "SCHEMA">
| <K_SELECT: ("SELECT" | "SEL")>
| <K_SEMI : "SEMI">
Expand Down Expand Up @@ -381,6 +382,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
| <K_WITH:"WITH">
| <K_WITHIN:"WITHIN">
| <K_WITHOUT:"WITHOUT">
| <K_WORK:"WORK">
| <K_XML:"XML">
| <K_XOR:"XOR">
| <K_XMLSERIALIZE:"XMLSERIALIZE">
Expand Down Expand Up @@ -551,6 +553,10 @@ Statement SingleStatement() :
|
stm = Use()
|
stm = SavepointStatement()
|
stm = RollbackStatement()
|
stm = Commit()
|
stm = Comment()
Expand Down Expand Up @@ -5238,6 +5244,42 @@ Wait Wait():
}
}

SavepointStatement SavepointStatement():
{
SavepointStatement savepointStatement;
}
{
<K_SAVEPOINT> token=<S_IDENTIFIER> { savepointStatement = new SavepointStatement(token.image); }
{
return savepointStatement;
}
}

RollbackStatement RollbackStatement():
{
RollbackStatement rollbackStatement;
boolean usingWorkKeyword=false;
boolean usingSavepointKeyword=false;
String savepointName=null;
String forceDistributedTransactionIdentifier=null;
}
{
<K_ROLLBACK> { rollbackStatement = new RollbackStatement(); }
[ <K_WORK> { rollbackStatement.setUsingWorkKeyword(true); } ]
[ (
<K_TO> [ <K_SAVEPOINT> { rollbackStatement.setUsingSavepointKeyword(true); }]
token=<S_IDENTIFIER> { rollbackStatement.setSavepointName(token.image); }
)
|
(
<K_FORCE> token=<S_CHAR_LITERAL> { rollbackStatement.setForceDistributedTransactionIdentifier(token.image); }
) ]

{
return rollbackStatement;
}
}

Commit Commit():
{
Commit commit=new Commit();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*-
* #%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.statement;

import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed;

import org.junit.Test;

public class SavepointRollbackCommitTest {
@Test
public void testSavepoint() throws Exception {
assertSqlCanBeParsedAndDeparsed("SAVEPOINT banda_sal", true);
}

@Test
public void testRollback() throws Exception {
assertSqlCanBeParsedAndDeparsed("ROLLBACK", true);
assertSqlCanBeParsedAndDeparsed("ROLLBACK WORK", true);
assertSqlCanBeParsedAndDeparsed("ROLLBACK TO banda_sal", true);
assertSqlCanBeParsedAndDeparsed("ROLLBACK TO SAVEPOINT banda_sal", true);
assertSqlCanBeParsedAndDeparsed("ROLLBACK WORK TO banda_sal", true);
assertSqlCanBeParsedAndDeparsed("ROLLBACK WORK TO SAVEPOINT banda_sal", true);
assertSqlCanBeParsedAndDeparsed("ROLLBACK FORCE '25.32.87'", true);
assertSqlCanBeParsedAndDeparsed("ROLLBACK WORK FORCE '25.32.87'", true);
}


@Test
public void testCommit() throws Exception {
assertSqlCanBeParsedAndDeparsed("COMMIT");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,8 @@ public void testInsertKeyWordIntervalIssue682() throws JSQLParserException {
}

@Test
@Ignore
public void testWithAtFront() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("WITH foo AS ( SELECT attr FROM bar ) INSERT INTO lalelu (attr) SELECT attr FROM foo");
assertSqlCanBeParsedAndDeparsed("WITH foo AS ( SELECT attr FROM bar ) INSERT INTO lalelu (attr) SELECT attr FROM foo", true);
}

@Test
Expand Down
Loading