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
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,12 @@ public DocStoreTransactionManager(TransactionManagerOptions options) {

@Override
public SpiTransaction createTransaction(boolean explicit, int isolationLevel) {
return createTransaction(explicit, null);
return new DocStoreOnlyTransaction(explicit, this);
}

@Override
public SpiTransaction createReadOnlyTransaction(Object tenantId, boolean useMaster) {
return new DocStoreOnlyTransaction(false, this);
}

@Override
protected SpiTransaction createTransaction(boolean explicit, Connection c) {
return new DocStoreOnlyTransaction(explicit, this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.ebeaninternal.server.transaction;

import org.jspecify.annotations.Nullable;

import java.sql.Connection;

/**
* Ebean transaction used for AutoCommit true connections.
*/
final class JdbcAutoCommitTransaction extends JdbcTransaction {

JdbcAutoCommitTransaction(boolean explicit, Connection connection, @Nullable TransactionManager manager) {
super(true, explicit, connection, manager);
}

@Override
void performRollback() {
long offset = profileOffset();
if (profileStream != null) {
profileStream.addEvent(EVT_ROLLBACK, offset);
}
}

@Override
void performCommit() {
long offset = profileOffset();
if (profileStream != null) {
profileStream.addEvent(EVT_COMMIT, offset);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,17 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
*/
private final boolean skipCacheAfterWrite;
DocStoreTransaction docStoreTxn;
private ProfileStream profileStream;
protected ProfileStream profileStream;
private ProfileLocation profileLocation;
private final Instant startTime = Instant.now();
private final long startNanos;
private boolean autoPersistUpdates;

JdbcTransaction(boolean explicit, Connection connection, TransactionManager manager) {
this(false, explicit, connection, manager);
}

JdbcTransaction(boolean autoCommit, boolean explicit, Connection connection, TransactionManager manager) {
try {
this.active = true;
this.explicit = explicit;
Expand Down Expand Up @@ -125,7 +129,9 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
this.onQueryOnlyCommit = true;
}

checkAutoCommit(connection);
if (!autoCommit) {
checkAutoCommit(connection);
}

} catch (Exception e) {
throw new PersistenceException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@
abstract class TransactionFactory {

final TransactionManager manager;
private final boolean autoCommitMode;

TransactionFactory(TransactionManager manager) {
this.manager = manager;
this.autoCommitMode = manager.isAutoCommitMode();
}

/**
* Return a new transaction.
*/
SpiTransaction createTransaction(boolean explicit, Connection connection) {
return autoCommitMode ? new JdbcAutoCommitTransaction(explicit, connection, manager) : new JdbcTransaction(explicit, connection, manager);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final SpiTransaction createTransaction(boolean explicit, int isolationLev
Connection connection = null;
try {
connection = dataSource.getConnection();
SpiTransaction t = manager.createTransaction(explicit, connection);
SpiTransaction t = createTransaction(explicit, connection);
return setIsolationLevel(t, isolationLevel);
} catch (PersistenceException ex) {
JdbcClose.close(connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final SpiTransaction createTransaction(boolean explicit, int isolationLev
try {
Object tenantId = tenantProvider.currentId();
connection = dataSourceSupplier.connection(tenantId);
SpiTransaction transaction = manager.createTransaction(explicit, connection);
SpiTransaction transaction = createTransaction(explicit, connection);
transaction.setTenantId(tenantId);
return setIsolationLevel(transaction, isolationLevel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import io.ebean.ProfileLocation;
import io.ebean.TxScope;
import io.ebean.annotation.PersistBatch;
import io.ebean.annotation.Platform;
import io.ebean.annotation.TxType;
import io.ebean.cache.ServerCacheNotification;
import io.ebean.cache.ServerCacheNotify;
import io.ebean.config.CurrentTenantProvider;
import io.ebean.config.dbplatform.DatabasePlatform;
import io.ebean.datasource.DataSourcePool;
import io.ebean.event.changelog.ChangeLogListener;
import io.ebean.event.changelog.ChangeLogPrepare;
import io.ebean.event.changelog.ChangeSet;
Expand Down Expand Up @@ -106,6 +106,7 @@ public class TransactionManager implements SpiTransactionManager {
private final ServerCacheNotify cacheNotify;
private final boolean supportsSavepointId;
private final ConcurrentHashMap<String, ProfileLocation> profileLocations = new ConcurrentHashMap<>();
private final boolean autoCommitMode;

/**
* Create the TransactionManager
Expand All @@ -115,6 +116,7 @@ public TransactionManager(TransactionManagerOptions options) {
this.logManager = options.logManager;
this.databasePlatform = options.config.getDatabasePlatform();
this.supportsSavepointId = databasePlatform.supportsSavepointId();
this.autoCommitMode = databasePlatform.platform() == Platform.CLICKHOUSE;
this.skipCacheAfterWrite = options.config.isSkipCacheAfterWrite();
this.notifyL2CacheInForeground = options.notifyL2CacheInForeground;
this.autoPersistUpdates = options.config.isAutoPersistUpdates();
Expand Down Expand Up @@ -206,6 +208,10 @@ public final void shutdown(boolean shutdownDataSource, boolean deregisterDriver)
}
}

final boolean isAutoCommitMode() {
return autoCommitMode;
}

/**
* Return true if the DB platform supports SavepointId().
*/
Expand Down Expand Up @@ -298,13 +304,6 @@ public SpiTransaction createReadOnlyTransaction(Object tenantId, boolean useMast
return transactionFactory.createReadOnlyTransaction(tenantId, useMaster);
}

/**
* Create a new transaction.
*/
SpiTransaction createTransaction(boolean explicit, Connection c) {
return new JdbcTransaction(explicit, c, this);
}

/**
* Process a local rolled back transaction.
*/
Expand Down