[jOOQ/jOOQ#7106] Add support for procedural transaction statements - WIP

This includes:
- START TRANSACTION
- COMMIT
- RELEASE SAVEPOINT
- ROLLBACK [ TO SAVEPOINT ]
- SAVEPOINT

Implementations:
- H2
- HSQLDB (not passing tests yet)
- PostgreSQL
This commit is contained in:
Lukas Eder 2023-01-03 17:08:05 +01:00
parent 68de5bfa35
commit e38ceeafdc
11 changed files with 1356 additions and 3 deletions

View File

@ -11240,6 +11240,167 @@ public interface DSLContext extends Scope {
/**
* The <code>START TRANSACTION</code> statement.
* <p>
* Start a transaction
*
* @see DSL#startTransaction()
*/
@NotNull @CheckReturnValue
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
Query startTransaction();
/**
* The <code>SAVEPOINT</code> statement.
* <p>
* Specify a savepoint
*
* @see DSL#savepoint(String)
*/
@NotNull @CheckReturnValue
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
Query savepoint(@Stringly.Name String name);
/**
* The <code>SAVEPOINT</code> statement.
* <p>
* Specify a savepoint
*
* @see DSL#savepoint(Name)
*/
@NotNull @CheckReturnValue
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
Query savepoint(Name name);
/**
* The <code>RELEASE SAVEPOINT</code> statement.
* <p>
* Release a savepoint
*
* @see DSL#releaseSavepoint(String)
*/
@NotNull @CheckReturnValue
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
Query releaseSavepoint(@Stringly.Name String name);
/**
* The <code>RELEASE SAVEPOINT</code> statement.
* <p>
* Release a savepoint
*
* @see DSL#releaseSavepoint(Name)
*/
@NotNull @CheckReturnValue
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
Query releaseSavepoint(Name name);
/**
* The <code>COMMIT</code> statement.
* <p>
* Commit a transaction
*
* @see DSL#commit()
*/
@NotNull @CheckReturnValue
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
Query commit();
/**
* The <code>ROLLBACK</code> statement.
* <p>
* Rollback a transaction
*
* @see DSL#rollback()
*/
@NotNull @CheckReturnValue
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
RollbackToSavepointStep rollback();
/**
* Create a new DSL <code>CREATE VIEW</code> statement.
*

View File

@ -0,0 +1,86 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: https://www.jooq.org/legal/licensing
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq;
import static org.jooq.SQLDialect.*;
import static org.jooq.impl.DSL.*;
import java.util.*;
import org.jooq.impl.DSL;
import org.jetbrains.annotations.*;
/**
* A step in the construction of the <code>ROLLBACK</code> statement.
* <p>
* <h3>Referencing <code>XYZ*Step</code> types directly from client code</h3>
* <p>
* It is usually not recommended to reference any <code>XYZ*Step</code> types
* directly from client code, or assign them to local variables. When writing
* dynamic SQL, creating a statement's components dynamically, and passing them
* to the DSL API statically is usually a better choice. See the manual's
* section about dynamic SQL for details: <a href=
* "https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql">https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql</a>.
* <p>
* Drawbacks of referencing the <code>XYZ*Step</code> types directly:
* <ul>
* <li>They're operating on mutable implementations (as of jOOQ 3.x)</li>
* <li>They're less composable and not easy to get right when dynamic SQL gets
* complex</li>
* <li>They're less readable</li>
* <li>They might have binary incompatible changes between minor releases</li>
* </ul>
*/
@SuppressWarnings({ "unused" })
public interface RollbackToSavepointStep extends Query {
/**
* Add the <code>TO SAVEPOINT</code> clause to the <code>ROLLBACK</code> statement.
*/
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
@NotNull @CheckReturnValue
Query toSavepoint(@Stringly.Name String toSavepoint);
/**
* Add the <code>TO SAVEPOINT</code> clause to the <code>ROLLBACK</code> statement.
*/
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
@NotNull @CheckReturnValue
Query toSavepoint(Name toSavepoint);
}

View File

@ -0,0 +1,87 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: https://www.jooq.org/legal/licensing
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq.impl;
import static org.jooq.impl.DSL.*;
import static org.jooq.impl.Internal.*;
import static org.jooq.impl.Keywords.*;
import static org.jooq.impl.Names.*;
import static org.jooq.impl.SQLDataType.*;
import static org.jooq.impl.Tools.*;
import static org.jooq.impl.Tools.BooleanDataKey.*;
import static org.jooq.impl.Tools.ExtendedDataKey.*;
import static org.jooq.impl.Tools.SimpleDataKey.*;
import static org.jooq.SQLDialect.*;
import org.jooq.*;
import org.jooq.Function1;
import org.jooq.Record;
import org.jooq.conf.*;
import org.jooq.impl.*;
import org.jooq.impl.QOM.*;
import org.jooq.tools.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
/**
* The <code>COMMIT</code> statement.
*/
@SuppressWarnings({ "unused" })
final class Commit
extends
AbstractRowCountQuery
implements
QOM.Commit
{
Commit(Configuration configuration) {
super(configuration);
}
// -------------------------------------------------------------------------
// XXX: QueryPart API
// -------------------------------------------------------------------------
@Override
public final void accept(Context<?> ctx) {
ctx.visit(K_COMMIT);
}
}

View File

@ -10272,6 +10272,251 @@ public class DSL {
/**
* The <code>START TRANSACTION</code> statement.
* <p>
* Start a transaction
* <p>
* Unlike statement construction methods in the {@link DSLContext} API, this
* creates an unattached, and thus not directly renderable or executable
* statement. It can be used as a subquery or nested in procedural logic.
*
* @see DSLContext#startTransaction()
*/
@NotNull @CheckReturnValue
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
public static org.jooq.Query startTransaction() {
return dsl().startTransaction();
}
/**
* The <code>SAVEPOINT</code> statement.
* <p>
* Specify a savepoint
* <p>
* Unlike statement construction methods in the {@link DSLContext} API, this
* creates an unattached, and thus not directly renderable or executable
* statement. It can be used as a subquery or nested in procedural logic.
*
* @see DSLContext#savepoint(String)
*/
@NotNull @CheckReturnValue
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
public static org.jooq.Query savepoint(@Stringly.Name String name) {
return dsl().savepoint(name);
}
/**
* The <code>SAVEPOINT</code> statement.
* <p>
* Specify a savepoint
* <p>
* Unlike statement construction methods in the {@link DSLContext} API, this
* creates an unattached, and thus not directly renderable or executable
* statement. It can be used as a subquery or nested in procedural logic.
*
* @see DSLContext#savepoint(Name)
*/
@NotNull @CheckReturnValue
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
public static org.jooq.Query savepoint(Name name) {
return dsl().savepoint(name);
}
/**
* The <code>RELEASE SAVEPOINT</code> statement.
* <p>
* Release a savepoint
* <p>
* Unlike statement construction methods in the {@link DSLContext} API, this
* creates an unattached, and thus not directly renderable or executable
* statement. It can be used as a subquery or nested in procedural logic.
*
* @see DSLContext#releaseSavepoint(String)
*/
@NotNull @CheckReturnValue
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
public static org.jooq.Query releaseSavepoint(@Stringly.Name String name) {
return dsl().releaseSavepoint(name);
}
/**
* The <code>RELEASE SAVEPOINT</code> statement.
* <p>
* Release a savepoint
* <p>
* Unlike statement construction methods in the {@link DSLContext} API, this
* creates an unattached, and thus not directly renderable or executable
* statement. It can be used as a subquery or nested in procedural logic.
*
* @see DSLContext#releaseSavepoint(Name)
*/
@NotNull @CheckReturnValue
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
public static org.jooq.Query releaseSavepoint(Name name) {
return dsl().releaseSavepoint(name);
}
/**
* The <code>COMMIT</code> statement.
* <p>
* Commit a transaction
* <p>
* Unlike statement construction methods in the {@link DSLContext} API, this
* creates an unattached, and thus not directly renderable or executable
* statement. It can be used as a subquery or nested in procedural logic.
*
* @see DSLContext#commit()
*/
@NotNull @CheckReturnValue
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
public static org.jooq.Query commit() {
return dsl().commit();
}
/**
* The <code>ROLLBACK</code> statement.
* <p>
* Rollback a transaction
* <p>
* Unlike statement construction methods in the {@link DSLContext} API, this
* creates an unattached, and thus not directly renderable or executable
* statement. It can be used as a subquery or nested in procedural logic.
*
* @see DSLContext#rollback()
*/
@NotNull @CheckReturnValue
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
public static org.jooq.RollbackToSavepointStep rollback() {
return dsl().rollback();
}
/**
* Create a new DSL <code>CREATE VIEW</code> statement.
*

View File

@ -100,7 +100,6 @@ import org.jooq.BatchedRunnable;
import org.jooq.BindContext;
import org.jooq.Block;
import org.jooq.Catalog;
import org.jooq.Commit;
import org.jooq.Commits;
import org.jooq.CommonTableExpression;
import org.jooq.Condition;
@ -408,7 +407,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
}
@Override
public Commit commit(String id) {
public org.jooq.Commit commit(String id) {
return new CommitImpl(configuration, id, null, emptyList(), emptyList());
}
@ -418,7 +417,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
}
@Override
public Migration migrateTo(Commit to) {
public Migration migrateTo(org.jooq.Commit to) {
return new MigrationImpl(configuration, to);
}
@ -3964,6 +3963,83 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
@Override
public org.jooq.Query startTransaction() {
return new StartTransaction(configuration());
}
@Override
public org.jooq.Query savepoint(@Stringly.Name String name) {
return new Savepoint(configuration(), DSL.name(name));
}
@Override
public org.jooq.Query savepoint(Name name) {
return new Savepoint(configuration(), name);
}
@Override
public org.jooq.Query releaseSavepoint(@Stringly.Name String name) {
return new ReleaseSavepoint(configuration(), DSL.name(name));
}
@Override
public org.jooq.Query releaseSavepoint(Name name) {
return new ReleaseSavepoint(configuration(), name);
}
@Override
public org.jooq.Query commit() {
return new Commit(configuration());
}
@Override
public org.jooq.RollbackToSavepointStep rollback() {
return new Rollback(configuration());
}
@Override
public Queries ddl(Catalog catalog) {
return ddl(catalog, new DDLExportConfiguration());

View File

@ -96,6 +96,7 @@ final class Keywords {
static final Keyword K_COLUMN = keyword("column");
static final Keyword K_COLUMNS = keyword("columns");
static final Keyword K_COMMENT = keyword("comment");
static final Keyword K_COMMIT = keyword("commit");
static final Keyword K_CONNECT_BY = keyword("connect by");
static final Keyword K_CONSTRAINT = keyword("constraint");
static final Keyword K_CONSTRAINTS = keyword("constraints");
@ -331,6 +332,7 @@ final class Keywords {
static final Keyword K_RAISE = keyword("raise");
static final Keyword K_RAISERROR = keyword("raiserror");
static final Keyword K_RAW = keyword("raw");
static final Keyword K_READ = keyword("read");
static final Keyword K_READPAST = keyword("readpast");
static final Keyword K_READS = keyword("reads");
static final Keyword K_RECORD = keyword("record");
@ -339,6 +341,7 @@ final class Keywords {
static final Keyword K_REFERENCES = keyword("references");
static final Keyword K_REFERENCING = keyword("referencing");
static final Keyword K_REGEXP = keyword("regexp");
static final Keyword K_RELEASE = keyword("release");
static final Keyword K_REMOVE = keyword("remove");
static final Keyword K_RENAME = keyword("rename");
static final Keyword K_RENAME_COLUMN = keyword("rename column");
@ -359,6 +362,7 @@ final class Keywords {
static final Keyword K_RETURNS = keyword("returns");
static final Keyword K_REVERSE = keyword("reverse");
static final Keyword K_REVOKE = keyword("revoke");
static final Keyword K_ROLLBACK = keyword("rollback");
static final Keyword K_ROOT = keyword("root");
static final Keyword K_ROW = keyword("row");
static final Keyword K_ROWCOUNT = keyword("rowcount");
@ -367,6 +371,7 @@ final class Keywords {
static final Keyword K_ROWS_FROM = keyword("rows from");
static final Keyword K_ROWS_ONLY = keyword("rows only");
static final Keyword K_ROWS_WITH_TIES = keyword("rows with ties");
static final Keyword K_SAVEPOINT = keyword("savepoint");
static final Keyword K_SCHEMA = keyword("schema");
static final Keyword K_SCN = keyword("scn");
static final Keyword K_SEARCH_PATH = keyword("search_path");
@ -389,6 +394,7 @@ final class Keywords {
static final Keyword K_SQL = keyword("sql");
static final Keyword K_SQLSTATE = keyword("sqlstate");
static final Keyword K_SQL_ERROR_CODE = keyword("sql_error_code");
static final Keyword K_START = keyword("start");
static final Keyword K_START_AT = keyword("start at");
static final Keyword K_START_WITH = keyword("start with");
static final Keyword K_STATEMENT = keyword("statement");
@ -410,6 +416,7 @@ final class Keywords {
static final Keyword K_TO = keyword("to");
static final Keyword K_TOP = keyword("top");
static final Keyword K_TRAILING = keyword("trailing");
static final Keyword K_TRANSACTION = keyword("transaction");
static final Keyword K_TRIGGER = keyword("trigger");
static final Keyword K_TRIM = keyword("trim");
static final Keyword K_TRUE = keyword("true");
@ -451,6 +458,7 @@ final class Keywords {
static final Keyword K_WITH_READ_ONLY = keyword("with read only");
static final Keyword K_WITH_ROLLUP = keyword("with rollup");
static final Keyword K_WITH_TIES = keyword("with ties");
static final Keyword K_WRITE = keyword("write");
static final Keyword K_XML = keyword("xml");
static final Keyword K_XMLEXISTS = keyword("xmlexists");
static final Keyword K_XMLTABLE = keyword("xmltable");

View File

@ -2619,6 +2619,159 @@ public final class QOM {
/**
* The <code>START TRANSACTION</code> statement.
* <p>
* Start a transaction
*/
public /*sealed*/ interface StartTransaction
extends
UEmpty,
org.jooq.Query
//permits
// StartTransaction
{}
/**
* The <code>SAVEPOINT</code> statement.
* <p>
* Specify a savepoint
*/
public /*sealed*/ interface Savepoint
extends
org.jooq.Query
//permits
// Savepoint
{
@NotNull Name $name();
@CheckReturnValue
@NotNull Savepoint $name(Name name);
}
/**
* The <code>RELEASE SAVEPOINT</code> statement.
* <p>
* Release a savepoint
*/
public /*sealed*/ interface ReleaseSavepoint
extends
org.jooq.Query
//permits
// ReleaseSavepoint
{
@NotNull Name $name();
@CheckReturnValue
@NotNull ReleaseSavepoint $name(Name name);
}
/**
* The <code>COMMIT</code> statement.
* <p>
* Commit a transaction
*/
public /*sealed*/ interface Commit
extends
UEmpty,
org.jooq.Query
//permits
// Commit
{}
/**
* The <code>ROLLBACK</code> statement.
* <p>
* Rollback a transaction
*/
public /*sealed*/ interface Rollback
extends
RowCountQuery
//permits
// Rollback
{
@Nullable Name $toSavepoint();
@CheckReturnValue
@NotNull Rollback $toSavepoint(Name toSavepoint);
}
/**
* The <code>AND</code> operator.
*/

View File

@ -0,0 +1,133 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: https://www.jooq.org/legal/licensing
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq.impl;
import static org.jooq.impl.DSL.*;
import static org.jooq.impl.Internal.*;
import static org.jooq.impl.Keywords.*;
import static org.jooq.impl.Names.*;
import static org.jooq.impl.SQLDataType.*;
import static org.jooq.impl.Tools.*;
import static org.jooq.impl.Tools.BooleanDataKey.*;
import static org.jooq.impl.Tools.ExtendedDataKey.*;
import static org.jooq.impl.Tools.SimpleDataKey.*;
import static org.jooq.SQLDialect.*;
import org.jooq.*;
import org.jooq.Function1;
import org.jooq.Record;
import org.jooq.conf.*;
import org.jooq.impl.*;
import org.jooq.impl.QOM.*;
import org.jooq.tools.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
/**
* The <code>RELEASE SAVEPOINT</code> statement.
*/
@SuppressWarnings({ "unused" })
final class ReleaseSavepoint
extends
AbstractRowCountQuery
implements
QOM.ReleaseSavepoint
{
final Name name;
ReleaseSavepoint(
Configuration configuration,
Name name
) {
super(configuration);
this.name = name;
}
// -------------------------------------------------------------------------
// XXX: QueryPart API
// -------------------------------------------------------------------------
@Override
public final void accept(Context<?> ctx) {
ctx.visit(K_RELEASE).sql(' ').visit(K_SAVEPOINT).sql(' ').visit(name);
}
// -------------------------------------------------------------------------
// XXX: Query Object Model
// -------------------------------------------------------------------------
@Override
public final Name $name() {
return name;
}
@Override
public final QOM.ReleaseSavepoint $name(Name newValue) {
return $constructor().apply(newValue);
}
public final Function1<? super Name, ? extends QOM.ReleaseSavepoint> $constructor() {
return (a1) -> new ReleaseSavepoint(configuration(), a1);
}
}

View File

@ -0,0 +1,161 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: https://www.jooq.org/legal/licensing
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq.impl;
import static org.jooq.impl.DSL.*;
import static org.jooq.impl.Internal.*;
import static org.jooq.impl.Keywords.*;
import static org.jooq.impl.Names.*;
import static org.jooq.impl.SQLDataType.*;
import static org.jooq.impl.Tools.*;
import static org.jooq.impl.Tools.BooleanDataKey.*;
import static org.jooq.impl.Tools.ExtendedDataKey.*;
import static org.jooq.impl.Tools.SimpleDataKey.*;
import static org.jooq.SQLDialect.*;
import org.jooq.*;
import org.jooq.Function1;
import org.jooq.Record;
import org.jooq.conf.*;
import org.jooq.impl.*;
import org.jooq.impl.QOM.*;
import org.jooq.tools.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
/**
* The <code>ROLLBACK</code> statement.
*/
@SuppressWarnings({ "hiding", "unused" })
final class Rollback
extends
AbstractRowCountQuery
implements
QOM.Rollback,
RollbackToSavepointStep
{
Name toSavepoint;
Rollback(
Configuration configuration
) {
this(
configuration,
null
);
}
Rollback(
Configuration configuration,
Name toSavepoint
) {
super(configuration);
this.toSavepoint = toSavepoint;
}
// -------------------------------------------------------------------------
// XXX: DSL API
// -------------------------------------------------------------------------
@Override
public final Rollback toSavepoint(String toSavepoint) {
return toSavepoint(DSL.name(toSavepoint));
}
@Override
public final Rollback toSavepoint(Name toSavepoint) {
this.toSavepoint = toSavepoint;
return this;
}
// -------------------------------------------------------------------------
// XXX: QueryPart API
// -------------------------------------------------------------------------
@Override
public final void accept(Context<?> ctx) {
ctx.visit(K_ROLLBACK);
if (toSavepoint != null)
ctx.sql(' ').visit(K_TO).sql(' ').visit(K_SAVEPOINT).sql(' ').visit(toSavepoint);
}
// -------------------------------------------------------------------------
// XXX: Query Object Model
// -------------------------------------------------------------------------
@Override
public final Name $toSavepoint() {
return toSavepoint;
}
@Override
public final QOM.Rollback $toSavepoint(Name newValue) {
return $constructor().apply(newValue);
}
public final Function1<? super Name, ? extends QOM.Rollback> $constructor() {
return (a1) -> new Rollback(configuration(), a1);
}
}

View File

@ -0,0 +1,133 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: https://www.jooq.org/legal/licensing
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq.impl;
import static org.jooq.impl.DSL.*;
import static org.jooq.impl.Internal.*;
import static org.jooq.impl.Keywords.*;
import static org.jooq.impl.Names.*;
import static org.jooq.impl.SQLDataType.*;
import static org.jooq.impl.Tools.*;
import static org.jooq.impl.Tools.BooleanDataKey.*;
import static org.jooq.impl.Tools.ExtendedDataKey.*;
import static org.jooq.impl.Tools.SimpleDataKey.*;
import static org.jooq.SQLDialect.*;
import org.jooq.*;
import org.jooq.Function1;
import org.jooq.Record;
import org.jooq.conf.*;
import org.jooq.impl.*;
import org.jooq.impl.QOM.*;
import org.jooq.tools.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
/**
* The <code>SAVEPOINT</code> statement.
*/
@SuppressWarnings({ "unused" })
final class Savepoint
extends
AbstractRowCountQuery
implements
QOM.Savepoint
{
final Name name;
Savepoint(
Configuration configuration,
Name name
) {
super(configuration);
this.name = name;
}
// -------------------------------------------------------------------------
// XXX: QueryPart API
// -------------------------------------------------------------------------
@Override
public final void accept(Context<?> ctx) {
ctx.visit(K_SAVEPOINT).sql(' ').visit(name);
}
// -------------------------------------------------------------------------
// XXX: Query Object Model
// -------------------------------------------------------------------------
@Override
public final Name $name() {
return name;
}
@Override
public final QOM.Savepoint $name(Name newValue) {
return $constructor().apply(newValue);
}
public final Function1<? super Name, ? extends QOM.Savepoint> $constructor() {
return (a1) -> new Savepoint(configuration(), a1);
}
}

View File

@ -0,0 +1,110 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: https://www.jooq.org/legal/licensing
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq.impl;
import static org.jooq.impl.DSL.*;
import static org.jooq.impl.Internal.*;
import static org.jooq.impl.Keywords.*;
import static org.jooq.impl.Names.*;
import static org.jooq.impl.SQLDataType.*;
import static org.jooq.impl.Tools.*;
import static org.jooq.impl.Tools.BooleanDataKey.*;
import static org.jooq.impl.Tools.ExtendedDataKey.*;
import static org.jooq.impl.Tools.SimpleDataKey.*;
import static org.jooq.SQLDialect.*;
import org.jooq.*;
import org.jooq.Function1;
import org.jooq.Record;
import org.jooq.conf.*;
import org.jooq.impl.*;
import org.jooq.impl.QOM.*;
import org.jooq.tools.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
/**
* The <code>START TRANSACTION</code> statement.
*/
@SuppressWarnings({ "unused" })
final class StartTransaction
extends
AbstractRowCountQuery
implements
QOM.StartTransaction
{
StartTransaction(Configuration configuration) {
super(configuration);
}
// -------------------------------------------------------------------------
// XXX: QueryPart API
// -------------------------------------------------------------------------
@Override
public final void accept(Context<?> ctx) {
switch (ctx.family()) {
case POSTGRES:
case YUGABYTEDB: {
// [#7106] PostgreSQL blocks can't start new transactions
if (ctx.data(DATA_BLOCK_NESTING) == null)
ctx.visit(K_START).sql(' ').visit(K_TRANSACTION);
break;
}
case H2: {
ctx.visit(K_BEGIN).sql(' ').visit(K_TRANSACTION);
break;
}
case HSQLDB: {
ctx.visit(K_START).sql(' ').visit(K_TRANSACTION).sql(' ').visit(K_READ).sql(' ').visit(K_WRITE);
break;
}
default:
ctx.visit(K_START).sql(' ').visit(K_TRANSACTION);
break;
}
}
}