-
Notifications
You must be signed in to change notification settings - Fork 3
Backport to branch(3) : Add ClientService and CLI for Table Store #235
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...e-store/src/main/java/com/scalar/dl/tablestore/client/model/StatementExecutionResult.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.scalar.dl.tablestore.client.model; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.scalar.dl.ledger.model.ContractExecutionResult; | ||
import com.scalar.dl.ledger.proof.AssetProof; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import javax.annotation.concurrent.Immutable; | ||
|
||
/** | ||
* The result of statement execution. It contains the result of the statement execution along with a | ||
* list of {@link AssetProof}s from Ledger and Auditor. | ||
*/ | ||
@Immutable | ||
// non-final for mocking | ||
public class StatementExecutionResult { | ||
private final String result; | ||
private final ImmutableList<AssetProof> ledgerProofs; | ||
private final ImmutableList<AssetProof> auditorProofs; | ||
|
||
/** | ||
* Constructs a {@code StatementExecutionResult} using the specified {@code | ||
* ContractExecutionResult} | ||
* | ||
* @param contractExecutionResult a {@code ContractExecutionResult} | ||
*/ | ||
public StatementExecutionResult(ContractExecutionResult contractExecutionResult) { | ||
this.result = contractExecutionResult.getContractResult().orElse(null); | ||
this.ledgerProofs = ImmutableList.copyOf(contractExecutionResult.getLedgerProofs()); | ||
this.auditorProofs = ImmutableList.copyOf(contractExecutionResult.getAuditorProofs()); | ||
} | ||
|
||
/** | ||
* Returns the result of statement execution. | ||
* | ||
* @return the result of statement execution | ||
*/ | ||
public Optional<String> getResult() { | ||
return Optional.ofNullable(result); | ||
} | ||
|
||
/** | ||
* Returns the list of {@link AssetProof}s from Ledger. | ||
* | ||
* @return the list of {@link AssetProof}s from Ledger | ||
*/ | ||
public List<AssetProof> getLedgerProofs() { | ||
return ledgerProofs; | ||
} | ||
|
||
/** | ||
* Returns the list of {@link AssetProof}s from Auditor. | ||
* | ||
* @return the list of {@link AssetProof}s from Auditor | ||
*/ | ||
public List<AssetProof> getAuditorProofs() { | ||
return auditorProofs; | ||
} | ||
|
||
/** | ||
* Returns a hash code value for the object. | ||
* | ||
* @return a hash code value for this object. | ||
*/ | ||
@Override | ||
public int hashCode() { | ||
return Objects.hash(result, ledgerProofs, auditorProofs); | ||
} | ||
|
||
/** | ||
* Indicates whether some other object is "equal to" this object. The other object is considered | ||
* equal if it is the same instance or if: | ||
* | ||
* <ul> | ||
* <li>it is also an {@code StatementExecutionResult} and | ||
* <li>both instances have the same result and proofs. | ||
* </ul> | ||
* | ||
* @param o an object to be tested for equality | ||
* @return {@code true} if the other object is "equal to" this object otherwise {@code false} | ||
*/ | ||
@Override | ||
public boolean equals(Object o) { | ||
if (o == this) { | ||
return true; | ||
} | ||
if (!(o instanceof StatementExecutionResult)) { | ||
return false; | ||
} | ||
StatementExecutionResult other = (StatementExecutionResult) o; | ||
return Objects.equals(this.result, other.result) | ||
&& this.ledgerProofs.equals(other.ledgerProofs) | ||
&& this.auditorProofs.equals(other.auditorProofs); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For better consistency and error handling, it's preferable to throw a
ClientException
here instead of a genericRuntimeException
. The rest of the client code, including thefileToBytes
method in this same class, usesClientException
for expected error conditions. This allows callers to handle specific errors more gracefully rather than catching a broadRuntimeException
.