-
Notifications
You must be signed in to change notification settings - Fork 26
[Feat] support checkAndInsUp #64
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
100 changes: 100 additions & 0 deletions
100
src/main/java/com/alipay/oceanbase/rpc/checkandmutate/CheckAndInsUp.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,100 @@ | ||
| /*- | ||
| * #%L | ||
| * OBKV Table Client Framework | ||
| * %% | ||
| * Copyright (C) 2024 OceanBase | ||
| * %% | ||
| * OBKV Table Client Framework is licensed under Mulan PSL v2. | ||
| * You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
| * You may obtain a copy of Mulan PSL v2 at: | ||
| * http://license.coscl.org.cn/MulanPSL2 | ||
| * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, | ||
| * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, | ||
| * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | ||
| * See the Mulan PSL v2 for more details. | ||
| * #L% | ||
| */ | ||
|
|
||
| package com.alipay.oceanbase.rpc.checkandmutate; | ||
IHEII marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import com.alipay.oceanbase.rpc.ObTableClient; | ||
| import com.alipay.oceanbase.rpc.exception.ObTableException; | ||
| import com.alipay.oceanbase.rpc.filter.ObTableFilter; | ||
| import com.alipay.oceanbase.rpc.mutation.InsertOrUpdate; | ||
| import com.alipay.oceanbase.rpc.mutation.result.MutationResult; | ||
| import com.alipay.oceanbase.rpc.protocol.payload.impl.ObRowKey; | ||
| import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.ObTableOperation; | ||
| import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.ObTableOperationType; | ||
| import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.query.ObNewRange; | ||
| import com.alipay.oceanbase.rpc.table.api.Table; | ||
| import com.alipay.oceanbase.rpc.table.api.TableQuery; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class CheckAndInsUp { | ||
| private Table client; | ||
| private String tableName; | ||
| private ObTableFilter filter; | ||
| private InsertOrUpdate insUp; | ||
| boolean checkExists = true; | ||
|
|
||
| public CheckAndInsUp(ObTableFilter filter, InsertOrUpdate insUp, boolean check_exists) | ||
| throws IllegalArgumentException { | ||
| this.filter = filter; | ||
| this.insUp = insUp; | ||
| this.checkExists = check_exists; | ||
| this.tableName = null; | ||
| this.client = null; | ||
| } | ||
|
|
||
| public CheckAndInsUp(Table client, String tableName, ObTableFilter filter, | ||
| InsertOrUpdate insUp, boolean check_exists) | ||
| throws IllegalArgumentException { | ||
| this.client = client; | ||
| this.tableName = tableName; | ||
| this.filter = filter; | ||
| this.insUp = insUp; | ||
| this.checkExists = check_exists; | ||
| } | ||
|
|
||
| public Object[] getRowKey() { | ||
| return insUp.getRowKey(); | ||
| } | ||
|
|
||
| public ObTableFilter getFilter() { | ||
| return filter; | ||
| } | ||
|
|
||
| public InsertOrUpdate getInsUp() { | ||
| return insUp; | ||
| } | ||
|
|
||
| public boolean isCheckExists() { | ||
| return checkExists; | ||
| } | ||
|
|
||
| public MutationResult execute() throws Exception { | ||
| if (null == tableName) { | ||
| throw new ObTableException("table name is null"); | ||
| } else if (null == client) { | ||
| throw new ObTableException("client is null"); | ||
| } else if (!(client instanceof ObTableClient)) { | ||
| throw new ObTableException("the client must be table clinet"); | ||
| } | ||
|
|
||
| TableQuery query = client.query(tableName); | ||
| query.setFilter(filter); | ||
| Object[] rowKey = getRowKey(); | ||
| List<ObNewRange> ranges = new ArrayList<>(); | ||
| ObNewRange range = new ObNewRange(); | ||
| range.setStartKey(ObRowKey.getInstance(insUp.getRowKey())); | ||
| range.setEndKey(ObRowKey.getInstance(insUp.getRowKey())); | ||
| ranges.add(range); | ||
| query.getObTableQuery().setKeyRanges(ranges); | ||
| ObTableOperation operation = ObTableOperation.getInstance(ObTableOperationType.INSERT_OR_UPDATE, | ||
| insUp.getRowKey(), insUp.getColumns(), insUp.getValues()); | ||
|
|
||
| return new MutationResult(((ObTableClient)client).mutationWithFilter(query, rowKey, ranges, operation, false, true, checkExists)); | ||
| } | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.