-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for
REFRESH MATERIALIZED VIEW
(#1911)
* Support REFRESH MATERIALIZED VIEW * Fix * Rename * Rename * fmt * fmt * Add test * Fix jjt * Fix jjt * Fix jjt * typo * rebase master
- Loading branch information
1 parent
085d750
commit 425c72e
Showing
20 changed files
with
483 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/main/java/net/sf/jsqlparser/statement/refresh/RefreshMaterializedViewStatement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/*- | ||
* #%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.refresh; | ||
|
||
import net.sf.jsqlparser.schema.Table; | ||
import net.sf.jsqlparser.statement.Statement; | ||
import net.sf.jsqlparser.statement.StatementVisitor; | ||
|
||
/** | ||
* REFRESH MATERIALIZED VIEW [ CONCURRENTLY ] name [ WITH [ NO ] DATA ] | ||
* <p> | ||
* https://www.postgresql.org/docs/16/sql-refreshmaterializedview.html | ||
* | ||
* @author jxnu-liguobin | ||
*/ | ||
|
||
public class RefreshMaterializedViewStatement implements Statement { | ||
|
||
private Table view; | ||
private RefreshMode refreshMode; | ||
private boolean concurrently = false; | ||
|
||
public RefreshMaterializedViewStatement() {} | ||
|
||
public RefreshMaterializedViewStatement(Table view, boolean concurrently, | ||
RefreshMode refreshMode) { | ||
this.refreshMode = refreshMode; | ||
this.concurrently = concurrently; | ||
this.view = view; | ||
} | ||
|
||
public Table getView() { | ||
return view; | ||
} | ||
|
||
public void setView(Table view) { | ||
this.view = view; | ||
} | ||
|
||
public RefreshMode getRefreshMode() { | ||
return refreshMode; | ||
} | ||
|
||
public void setRefreshMode(RefreshMode refreshMode) { | ||
this.refreshMode = refreshMode; | ||
} | ||
|
||
public boolean isConcurrently() { | ||
return concurrently; | ||
} | ||
|
||
public void setConcurrently(boolean concurrently) { | ||
this.concurrently = concurrently; | ||
} | ||
|
||
@SuppressWarnings("PMD.SwitchStmtsShouldHaveDefault") | ||
@Override | ||
public String toString() { | ||
StringBuilder builder = new StringBuilder(); | ||
builder.append("REFRESH MATERIALIZED VIEW "); | ||
if (this.refreshMode == null) { | ||
if (concurrently) { | ||
builder.append("CONCURRENTLY "); | ||
} | ||
builder.append(view); | ||
return builder.toString(); | ||
} | ||
switch (this.refreshMode) { | ||
case WITH_DATA: | ||
if (concurrently) { | ||
builder.append("CONCURRENTLY "); | ||
} | ||
builder.append(view); | ||
builder.append(" WITH DATA"); | ||
break; | ||
case WITH_NO_DATA: | ||
builder.append(view); | ||
if (!concurrently) { | ||
builder.append(" WITH NO DATA"); | ||
} | ||
break; | ||
} | ||
return builder.toString(); | ||
} | ||
|
||
@Override | ||
public void accept(StatementVisitor statementVisitor) { | ||
statementVisitor.visit(this); | ||
} | ||
|
||
public RefreshMaterializedViewStatement withTableName(Table view) { | ||
this.setView(view); | ||
return this; | ||
} | ||
|
||
public RefreshMaterializedViewStatement withConcurrently(boolean concurrently) { | ||
this.setConcurrently(concurrently); | ||
return this; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/net/sf/jsqlparser/statement/refresh/RefreshMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/*- | ||
* #%L | ||
* JSQLParser library | ||
* %% | ||
* Copyright (C) 2004 - 2022 JSQLParser | ||
* %% | ||
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0 | ||
* #L% | ||
*/ | ||
package net.sf.jsqlparser.statement.refresh; | ||
|
||
public enum RefreshMode { | ||
|
||
DEFAULT, WITH_DATA, WITH_NO_DATA; | ||
|
||
public static RefreshMode from(String type) { | ||
return Enum.valueOf(RefreshMode.class, type.toUpperCase()); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/net/sf/jsqlparser/statement/select/JoinHint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/net/sf/jsqlparser/util/deparser/RefreshMaterializedViewStatementDeParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/*- | ||
* #%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.refresh.RefreshMaterializedViewStatement; | ||
|
||
/** | ||
* @author jxnu-liguobin | ||
*/ | ||
|
||
public class RefreshMaterializedViewStatementDeParser | ||
extends AbstractDeParser<RefreshMaterializedViewStatement> { | ||
|
||
public RefreshMaterializedViewStatementDeParser(StringBuilder buffer) { | ||
super(buffer); | ||
} | ||
|
||
@SuppressWarnings("PMD.SwitchStmtsShouldHaveDefault") | ||
@Override | ||
public void deParse(RefreshMaterializedViewStatement view) { | ||
buffer.append("REFRESH MATERIALIZED VIEW "); | ||
if (view.getRefreshMode() == null) { | ||
if (view.isConcurrently()) { | ||
buffer.append("CONCURRENTLY "); | ||
} | ||
buffer.append(view.getView()); | ||
return; | ||
} | ||
switch (view.getRefreshMode()) { | ||
case WITH_DATA: | ||
if (view.isConcurrently()) { | ||
buffer.append("CONCURRENTLY "); | ||
} | ||
buffer.append(view.getView()); | ||
buffer.append(" WITH DATA"); | ||
break; | ||
case WITH_NO_DATA: | ||
buffer.append(view.getView()); | ||
if (view.isConcurrently()) { | ||
buffer.append(" WITH NO DATA"); | ||
} | ||
break; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.