Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some refactoring for JdbcTransaction #213

Merged
merged 1 commit into from
Jun 5, 2021
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 @@ -37,18 +37,21 @@
public class JdbcTransaction implements DistributedTransaction {
private static final Logger LOGGER = LoggerFactory.getLogger(JdbcTransaction.class);

private final String txId;
private final JdbcService jdbcService;
private final Connection connection;
private final RdbEngine rdbEngine;
private Optional<String> namespace;
private Optional<String> tableName;

JdbcTransaction(
String txId,
JdbcService jdbcService,
Connection connection,
RdbEngine rdbEngine,
Optional<String> namespace,
Optional<String> tableName) {
this.txId = txId;
this.jdbcService = jdbcService;
this.connection = connection;
this.rdbEngine = rdbEngine;
Expand All @@ -58,7 +61,7 @@ public class JdbcTransaction implements DistributedTransaction {

@Override
public String getId() {
throw new UnsupportedOperationException("doesn't support this operation");
return txId;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.scalar.db.storage.jdbc.query.QueryBuilder;
import java.sql.SQLException;
import java.util.Optional;
import java.util.UUID;
import javax.annotation.concurrent.ThreadSafe;
import org.apache.commons.dbcp2.BasicDataSource;
import org.slf4j.Logger;
Expand Down Expand Up @@ -81,19 +82,20 @@ public Optional<String> getTable() {

@Override
public JdbcTransaction start() throws TransactionException {
String txId = UUID.randomUUID().toString();
return start(txId);
}

@Override
public JdbcTransaction start(String txId) throws TransactionException {
try {
return new JdbcTransaction(
jdbcService, dataSource.getConnection(), rdbEngine, namespace, tableName);
txId, jdbcService, dataSource.getConnection(), rdbEngine, namespace, tableName);
} catch (SQLException e) {
throw new TransactionException("failed to start the transaction", e);
}
}

@Override
public JdbcTransaction start(String txId) throws TransactionException {
throw new UnsupportedOperationException("doesn't support starting transaction with txId");
}

@Deprecated
@Override
public JdbcTransaction start(Isolation isolation) throws TransactionException {
Expand All @@ -103,7 +105,7 @@ public JdbcTransaction start(Isolation isolation) throws TransactionException {
@Deprecated
@Override
public JdbcTransaction start(String txId, Isolation isolation) throws TransactionException {
throw new UnsupportedOperationException("doesn't support starting transaction with txId");
return start(txId);
}

@Deprecated
Expand All @@ -123,19 +125,19 @@ public JdbcTransaction start(SerializableStrategy strategy) throws TransactionEx
@Override
public JdbcTransaction start(String txId, SerializableStrategy strategy)
throws TransactionException {
throw new UnsupportedOperationException("doesn't support starting transaction with txId");
return start(txId);
}

@Deprecated
@Override
public JdbcTransaction start(String txId, Isolation isolation, SerializableStrategy strategy)
throws TransactionException {
throw new UnsupportedOperationException("doesn't support starting transaction with txId");
return start(txId);
}

@Override
public TransactionState getState(String txId) {
throw new UnsupportedOperationException("doesn't support this operation");
return TransactionState.UNKNOWN; // always returns UNKNOWN
}

@Override
Expand Down