Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ and missing syntax gets added on demand — [open an issue](https://github.com/J
| **MySQL table maintenance** | `ANALYZE` · `CHECK` · `CHECKSUM` · `OPTIMIZE` · `REPAIR TABLE` |
| **PostgreSQL maintenance** | `VACUUM` · `ANALYZE` · `CLUSTER` · `CHECKPOINT` |
| **MySQL locks** | `LOCK TABLES` · `UNLOCK TABLES` · `LOCK INSTANCE FOR BACKUP` · `UNLOCK INSTANCE` |
| **MySQL resource groups** | `CREATE`/`ALTER`/`DROP RESOURCE GROUP` · `SET RESOURCE GROUP` |
| **PostgreSQL session statements** | `DISCARD` · `LISTEN` · `UNLISTEN` · `SHOW`/`RESET TIME ZONE`/`TRANSACTION ISOLATION LEVEL`/`SESSION AUTHORIZATION` · `COPY` options from before 9.0 |
| **MySQL account management** | `CREATE`/`ALTER`/`RENAME USER` · `CREATE ROLE` · `SET ROLE` · `SET DEFAULT ROLE` · `SET PASSWORD` |
| **Tablespaces** | MySQL and PostgreSQL `CREATE TABLESPACE` · `ALTER TABLESPACE` |
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/net/sf/jsqlparser/parser/feature/Feature.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
import net.sf.jsqlparser.statement.merge.Merge;
import net.sf.jsqlparser.statement.refresh.RefreshMaterializedViewStatement;
import net.sf.jsqlparser.statement.reindex.Reindex;
import net.sf.jsqlparser.statement.resourcegroup.AlterResourceGroup;
import net.sf.jsqlparser.statement.resourcegroup.CreateResourceGroup;
import net.sf.jsqlparser.statement.resourcegroup.SetResourceGroup;
import net.sf.jsqlparser.statement.role.ReassignOwned;
import net.sf.jsqlparser.statement.select.Fetch;
import net.sf.jsqlparser.statement.select.First;
Expand Down Expand Up @@ -796,6 +799,24 @@ public enum Feature {
* @see BackupLockStatement
*/
backupLock,
/**
* MySQL "CREATE RESOURCE GROUP" statement is allowed
*
* @see CreateResourceGroup
*/
createResourceGroup,
/**
* MySQL "ALTER RESOURCE GROUP" statement is allowed
*
* @see AlterResourceGroup
*/
alterResourceGroup,
/**
* MySQL "SET RESOURCE GROUP" statement is allowed
*
* @see SetResourceGroup
*/
setResourceGroup,
/**
* SQL "COMMENT ON" statement is allowed
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@
import net.sf.jsqlparser.statement.oracle.OracleNullStatement;
import net.sf.jsqlparser.statement.refresh.RefreshMaterializedViewStatement;
import net.sf.jsqlparser.statement.reindex.Reindex;
import net.sf.jsqlparser.statement.resourcegroup.AlterResourceGroup;
import net.sf.jsqlparser.statement.resourcegroup.CreateResourceGroup;
import net.sf.jsqlparser.statement.resourcegroup.SetResourceGroup;
import net.sf.jsqlparser.statement.securitylabel.SecurityLabel;
import net.sf.jsqlparser.statement.role.AlterRole;
import net.sf.jsqlparser.statement.role.CreateRole;
Expand Down Expand Up @@ -928,6 +931,21 @@ public <S> Void visit(XaStatement statement, S context) {
: transactionOnly();
}

@Override
public <S> Void visit(CreateResourceGroup statement, S context) {
return schemaOnly();
}

@Override
public <S> Void visit(AlterResourceGroup statement, S context) {
return schemaOnly();
}

@Override
public <S> Void visit(SetResourceGroup statement, S context) {
return sessionOnly();
}

@Override
public <S> Void visit(Commit commit, S context) {
return transactionOnly();
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/net/sf/jsqlparser/statement/StatementVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
import net.sf.jsqlparser.statement.merge.Merge;
import net.sf.jsqlparser.statement.refresh.RefreshMaterializedViewStatement;
import net.sf.jsqlparser.statement.reindex.Reindex;
import net.sf.jsqlparser.statement.resourcegroup.AlterResourceGroup;
import net.sf.jsqlparser.statement.resourcegroup.CreateResourceGroup;
import net.sf.jsqlparser.statement.resourcegroup.SetResourceGroup;
import net.sf.jsqlparser.statement.securitylabel.SecurityLabel;
import net.sf.jsqlparser.statement.select.Select;
import net.sf.jsqlparser.statement.show.ShowCreateStatement;
Expand Down Expand Up @@ -197,6 +200,30 @@ default void visit(XaStatement statement) {
visit(statement, null);
}

default <S> T visit(CreateResourceGroup statement, S context) {
return null;
}

default void visit(CreateResourceGroup statement) {
visit(statement, null);
}

default <S> T visit(AlterResourceGroup statement, S context) {
return null;
}

default void visit(AlterResourceGroup statement) {
visit(statement, null);
}

default <S> T visit(SetResourceGroup statement, S context) {
return null;
}

default void visit(SetResourceGroup statement) {
visit(statement, null);
}

<S> T visit(Commit commit, S context);

default void visit(Commit commit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@
import net.sf.jsqlparser.statement.merge.MergeOperationVisitorAdapter;
import net.sf.jsqlparser.statement.refresh.RefreshMaterializedViewStatement;
import net.sf.jsqlparser.statement.reindex.Reindex;
import net.sf.jsqlparser.statement.resourcegroup.AlterResourceGroup;
import net.sf.jsqlparser.statement.resourcegroup.CreateResourceGroup;
import net.sf.jsqlparser.statement.resourcegroup.SetResourceGroup;
import net.sf.jsqlparser.statement.securitylabel.SecurityLabel;
import net.sf.jsqlparser.statement.select.FromItem;
import net.sf.jsqlparser.statement.select.FromItemVisitor;
Expand Down Expand Up @@ -262,6 +265,21 @@ public <S> T visit(XaStatement statement, S context) {
return null;
}

@Override
public <S> T visit(CreateResourceGroup statement, S context) {
return null;
}

@Override
public <S> T visit(AlterResourceGroup statement, S context) {
return null;
}

@Override
public <S> T visit(SetResourceGroup statement, S context) {
return null;
}

@Override
public <S> T visit(Commit commit, S context) {

Expand Down
10 changes: 7 additions & 3 deletions src/main/java/net/sf/jsqlparser/statement/drop/Drop.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
public class Drop extends ASTNodeAccessImpl implements Statement {

public enum ObjectType {
DATABASE, EVENT, FUNCTION, INDEX, PROCEDURE, SCHEMA, SEQUENCE, SERVER, TABLE, TABLESPACE, TRIGGER, VIEW, FOREIGN_TABLE, FOREIGN_DATA_WRAPPER, AGGREGATE, DOMAIN, EVENT_TRIGGER, GROUP, OWNED, ROLE, ROUTINE, RULE, TYPE, USER, SYNONYM, ACCESS_METHOD, LANGUAGE, OPERATOR_CLASS, OPERATOR_FAMILY, TEXT_SEARCH_CONFIGURATION, TEXT_SEARCH_DICTIONARY, TEXT_SEARCH_PARSER, TEXT_SEARCH_TEMPLATE, CAST, OPERATOR, TRANSFORM, OTHER;
DATABASE, EVENT, FUNCTION, INDEX, PROCEDURE, SCHEMA, SEQUENCE, SERVER, TABLE, TABLESPACE, TRIGGER, VIEW, FOREIGN_TABLE, FOREIGN_DATA_WRAPPER, AGGREGATE, DOMAIN, EVENT_TRIGGER, GROUP, OWNED, ROLE, ROUTINE, RULE, TYPE, USER, SYNONYM, ACCESS_METHOD, LANGUAGE, OPERATOR_CLASS, OPERATOR_FAMILY, TEXT_SEARCH_CONFIGURATION, TEXT_SEARCH_DICTIONARY, TEXT_SEARCH_PARSER, TEXT_SEARCH_TEMPLATE, CAST, OPERATOR, TRANSFORM, RESOURCE_GROUP, OTHER;

/** Targets are {@link RoutineReference}s, each with an optional argument signature. */
public boolean hasRoutineTargets() {
Expand Down Expand Up @@ -432,7 +432,10 @@ public Drop withUndo(boolean undo) {
return this;
}

/** PostgreSQL DROP DATABASE ... WITH (FORCE), or Oracle DROP SYNONYM ... FORCE. */
/**
* PostgreSQL DROP DATABASE ... WITH (FORCE), or Oracle DROP SYNONYM ... FORCE and MySQL DROP
* RESOURCE GROUP ... FORCE.
*/
public boolean isForce() {
return force;
}
Expand Down Expand Up @@ -634,7 +637,8 @@ public StringBuilder appendTo(StringBuilder builder, Consumer<Table> tablePrinte
builder.append(" USING ").append(accessMethod);
}
if (force) {
builder.append(objectType == ObjectType.SYNONYM ? " FORCE" : " WITH (FORCE)");
builder.append(objectType == ObjectType.SYNONYM
|| objectType == ObjectType.RESOURCE_GROUP ? " FORCE" : " WITH (FORCE)");
}
if (engine != null) {
builder.append(engineUseEquals ? " ENGINE = " : " ENGINE ").append(engine);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2026 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement.resourcegroup;

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

/**
* MySQL {@code ALTER RESOURCE GROUP group_name [VCPU [=] vcpu_spec [, vcpu_spec] ...]
* [THREAD_PRIORITY [=] N] [ENABLE | DISABLE] [FORCE]}. MySQL's grammar takes FORCE without DISABLE
* too.
*
* @see <a href="https://dev.mysql.com/doc/refman/8.4/en/alter-resource-group.html">MySQL ALTER
* RESOURCE GROUP Statement</a>
*/
public class AlterResourceGroup extends ResourceGroupDefinition {
private boolean force;

public AlterResourceGroup() {
// the parser fills the statement in
}

public AlterResourceGroup(String name) {
super(name);
}

/** Whether FORCE is written: the group is changed although threads are assigned to it. */
public boolean isForce() {
return force;
}

public void setForce(boolean force) {
this.force = force;
}

public AlterResourceGroup withForce(boolean force) {
setForce(force);
return this;
}

public AlterResourceGroup withVcpus(List<VcpuRange> vcpus) {
setVcpus(vcpus);
return this;
}

public AlterResourceGroup addVcpuRanges(Collection<? extends VcpuRange> vcpus) {
addVcpus(vcpus);
return this;
}

public AlterResourceGroup withThreadPriority(Integer threadPriority) {
setThreadPriority(threadPriority);
return this;
}

public AlterResourceGroup withState(State state) {
setState(state);
return this;
}

@Override
public StringBuilder appendTo(StringBuilder builder) {
appendOptionsTo(builder.append("ALTER RESOURCE GROUP ").append(getName()));
return force ? builder.append(" FORCE") : builder;
}

@Override
public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) {
return statementVisitor.visit(this, context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2026 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement.resourcegroup;

import java.util.Collection;
import java.util.List;
import java.util.Objects;
import net.sf.jsqlparser.statement.StatementVisitor;

/**
* MySQL {@code CREATE RESOURCE GROUP group_name TYPE [=] {SYSTEM | USER} [VCPU [=] vcpu_spec [,
* vcpu_spec] ...] [THREAD_PRIORITY [=] N] [ENABLE | DISABLE]}.
*
* @see <a href="https://dev.mysql.com/doc/refman/8.4/en/create-resource-group.html">MySQL CREATE
* RESOURCE GROUP Statement</a>
*/
public class CreateResourceGroup extends ResourceGroupDefinition {
/** Whether the group takes system threads or user threads. */
public enum Type {
SYSTEM, USER
}

private Type type;
private OptionAssignment typeAssignment = OptionAssignment.EQUALS;

public CreateResourceGroup() {
// the parser fills the statement in
}

public CreateResourceGroup(String name, Type type) {
super(name);
setType(type);
}

public Type getType() {
return type;
}

public final void setType(Type type) {
this.type = Objects.requireNonNull(type, "type");
}

public OptionAssignment getTypeAssignment() {
return typeAssignment;
}

public void setTypeAssignment(OptionAssignment typeAssignment) {
this.typeAssignment = Objects.requireNonNull(typeAssignment, "typeAssignment");
}

public CreateResourceGroup withTypeAssignment(OptionAssignment typeAssignment) {
setTypeAssignment(typeAssignment);
return this;
}

public CreateResourceGroup withVcpus(List<VcpuRange> vcpus) {
setVcpus(vcpus);
return this;
}

public CreateResourceGroup addVcpuRanges(Collection<? extends VcpuRange> vcpus) {
addVcpus(vcpus);
return this;
}

public CreateResourceGroup withThreadPriority(Integer threadPriority) {
setThreadPriority(threadPriority);
return this;
}

public CreateResourceGroup withState(State state) {
setState(state);
return this;
}

@Override
public StringBuilder appendTo(StringBuilder builder) {
builder.append("CREATE RESOURCE GROUP ").append(getName()).append(' ');
typeAssignment.appendTo(builder, "TYPE").append(type);
return appendOptionsTo(builder);
}

@Override
public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) {
return statementVisitor.visit(this, context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2026 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement.resourcegroup;

/**
* How a MySQL resource group option is joined to its value: {@code TYPE USER}, {@code TYPE = USER}
* or {@code TYPE := USER}. MySQL reads the three alike.
*/
public enum OptionAssignment {
NONE(""), EQUALS("="), COLON_EQUALS(":=");

private final String symbol;

OptionAssignment(String symbol) {
this.symbol = symbol;
}

/** The symbol as written, empty for {@link #NONE}. */
public String getSymbol() {
return symbol;
}

/** Appends the option name, the symbol if there is one, and a space before the value. */
StringBuilder appendTo(StringBuilder builder, String option) {
builder.append(option).append(' ');
return this == NONE ? builder : builder.append(symbol).append(' ');
}
}
Loading
Loading