-
Notifications
You must be signed in to change notification settings - Fork 40
Add beginReadOnly() method to transaction abstraction #2734
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package com.scalar.db.common; | ||
|
|
||
| import com.scalar.db.api.Delete; | ||
| import com.scalar.db.api.DistributedTransaction; | ||
| import com.scalar.db.api.Insert; | ||
| import com.scalar.db.api.Mutation; | ||
| import com.scalar.db.api.Put; | ||
| import com.scalar.db.api.Update; | ||
| import com.scalar.db.api.Upsert; | ||
| import com.scalar.db.common.error.CoreError; | ||
| import com.scalar.db.exception.transaction.CrudException; | ||
| import java.util.List; | ||
| import javax.annotation.concurrent.NotThreadSafe; | ||
|
|
||
| @NotThreadSafe | ||
| public class ReadOnlyDistributedTransaction extends DecoratedDistributedTransaction { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a wrapper class to enforce immutability for read-only transactions. |
||
|
|
||
| public ReadOnlyDistributedTransaction(DistributedTransaction transaction) { | ||
| super(transaction); | ||
| } | ||
|
|
||
| /** @deprecated As of release 3.13.0. Will be removed in release 5.0.0. */ | ||
| @Deprecated | ||
| @Override | ||
| public void put(Put put) throws CrudException { | ||
| throw new IllegalStateException( | ||
| CoreError.MUTATION_NOT_ALLOWED_IN_READ_ONLY_TRANSACTION.buildMessage(getId())); | ||
| } | ||
|
|
||
| /** @deprecated As of release 3.13.0. Will be removed in release 5.0.0. */ | ||
| @Deprecated | ||
| @Override | ||
| public void put(List<Put> puts) throws CrudException { | ||
| throw new IllegalStateException( | ||
| CoreError.MUTATION_NOT_ALLOWED_IN_READ_ONLY_TRANSACTION.buildMessage(getId())); | ||
| } | ||
|
|
||
| @Override | ||
| public void insert(Insert insert) throws CrudException { | ||
| throw new IllegalStateException( | ||
| CoreError.MUTATION_NOT_ALLOWED_IN_READ_ONLY_TRANSACTION.buildMessage(getId())); | ||
| } | ||
|
|
||
| @Override | ||
| public void upsert(Upsert upsert) throws CrudException { | ||
| throw new IllegalStateException( | ||
| CoreError.MUTATION_NOT_ALLOWED_IN_READ_ONLY_TRANSACTION.buildMessage(getId())); | ||
| } | ||
|
|
||
| @Override | ||
| public void update(Update update) throws CrudException { | ||
| throw new IllegalStateException( | ||
| CoreError.MUTATION_NOT_ALLOWED_IN_READ_ONLY_TRANSACTION.buildMessage(getId())); | ||
| } | ||
|
|
||
| @Override | ||
| public void delete(Delete delete) throws CrudException { | ||
| throw new IllegalStateException( | ||
| CoreError.MUTATION_NOT_ALLOWED_IN_READ_ONLY_TRANSACTION.buildMessage(getId())); | ||
| } | ||
|
|
||
| /** @deprecated As of release 3.13.0. Will be removed in release 5.0.0. */ | ||
| @Deprecated | ||
| @Override | ||
| public void delete(List<Delete> deletes) throws CrudException { | ||
| throw new IllegalStateException( | ||
| CoreError.MUTATION_NOT_ALLOWED_IN_READ_ONLY_TRANSACTION.buildMessage(getId())); | ||
| } | ||
|
|
||
| @Override | ||
| public void mutate(List<? extends Mutation> mutations) throws CrudException { | ||
| throw new IllegalStateException( | ||
| CoreError.MUTATION_NOT_ALLOWED_IN_READ_ONLY_TRANSACTION.buildMessage(getId())); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,6 +145,16 @@ public DistributedTransaction begin(String txId) { | |
| return begin(txId, config.getIsolation()); | ||
| } | ||
|
|
||
| @Override | ||
| public DistributedTransaction beginReadOnly() { | ||
| throw new UnsupportedOperationException("implement later"); | ||
brfrn169 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Override | ||
| public DistributedTransaction beginReadOnly(String txId) { | ||
| throw new UnsupportedOperationException("implement later"); | ||
| } | ||
|
Comment on lines
+148
to
+156
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will add an implementation for Consensus Commit in a separate PR after this PR is merged. |
||
|
|
||
| /** @deprecated As of release 2.4.0. Will be removed in release 4.0.0. */ | ||
| @Deprecated | ||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,6 +109,16 @@ public DistributedTransaction begin(String txId) throws TransactionException { | |
| } | ||
| } | ||
|
|
||
| @Override | ||
| public DistributedTransaction beginReadOnly() { | ||
| throw new UnsupportedOperationException("implement later"); | ||
|
||
| } | ||
|
|
||
| @Override | ||
| public DistributedTransaction beginReadOnly(String txId) { | ||
| throw new UnsupportedOperationException("implement later"); | ||
| } | ||
|
Comment on lines
+112
to
+120
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will add an implementation for JDBC transactions in a separate PR after this PR is merged. |
||
|
|
||
| /** @deprecated As of release 2.4.0. Will be removed in release 4.0.0. */ | ||
| @SuppressWarnings("InlineMeSuggester") | ||
| @Deprecated | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,20 @@ public DistributedTransaction begin(String txId) throws TransactionException { | |
| .buildMessage()); | ||
| } | ||
|
|
||
| @Override | ||
| public DistributedTransaction beginReadOnly() throws TransactionException { | ||
| throw new UnsupportedOperationException( | ||
| CoreError.SINGLE_CRUD_OPERATION_TRANSACTION_BEGINNING_TRANSACTION_NOT_ALLOWED | ||
| .buildMessage()); | ||
| } | ||
|
|
||
| @Override | ||
| public DistributedTransaction beginReadOnly(String txId) throws TransactionException { | ||
| throw new UnsupportedOperationException( | ||
| CoreError.SINGLE_CRUD_OPERATION_TRANSACTION_BEGINNING_TRANSACTION_NOT_ALLOWED | ||
| .buildMessage()); | ||
| } | ||
|
Comment on lines
+79
to
+91
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the Single Crud Operation transaction manager, just throw |
||
|
|
||
| /** @deprecated As of release 2.4.0. Will be removed in release 4.0.0. */ | ||
| @Deprecated | ||
| @Override | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added several methods for the read-only mode.