-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a98b1a3
commit de7c7f9
Showing
22 changed files
with
1,875 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 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
82 changes: 82 additions & 0 deletions
82
src/main/java/com/alipay/oceanbase/rpc/checkandmutate/CheckAndInsUp.java
This file contains 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,82 @@ | ||
package com.alipay.oceanbase.rpc.checkandmutate; | ||
|
||
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 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 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 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.