Skip to content
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
42 changes: 42 additions & 0 deletions src/main/java/com/alipay/oceanbase/rpc/ObTableClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ private <T> T execute(String tableName, TableExecuteCallback<T> callback) throws
*/
private <T> T execute(String tableName, TableExecuteCallback<T> callback, ObServerRoute route)
throws Exception {
if (tableName == null || tableName.isEmpty()) {
throw new IllegalArgumentException("table name is null");
}
boolean needRefreshTableEntry = false;
int tryTimes = 0;
long startExecute = System.currentTimeMillis();
Expand Down Expand Up @@ -670,6 +673,9 @@ private <T> T executeMutation(String tableName, MutationExecuteCallback<T> callb
*/
private <T> T executeMutation(String tableName, MutationExecuteCallback<T> callback,
ObServerRoute route) throws Exception {
if (tableName == null || tableName.isEmpty()) {
throw new IllegalArgumentException("table name is null");
}
boolean needRefreshTableEntry = false;
int tryTimes = 0;
long startExecute = System.currentTimeMillis();
Expand Down Expand Up @@ -1050,6 +1056,9 @@ public TableEntry getOrRefreshTableEntry(final String tableName, final boolean r
final boolean waitForRefresh, boolean fetchAll)
throws Exception {

if (tableName == null || tableName.isEmpty()) {
throw new IllegalArgumentException("table name is null");
}
TableEntry tableEntry = tableLocations.get(tableName);
// attempt the cached data and try best to avoid lock
if (tableEntry != null) {
Expand Down Expand Up @@ -1713,6 +1722,9 @@ public TableBatchOps batch(String tableName) {
@Override
public Map<String, Object> get(final String tableName, final Object[] rowKey,
final String[] columns) throws Exception {
if (tableName == null || tableName.isEmpty()) {
throw new IllegalArgumentException("table name is null");
}
final long startTime = System.currentTimeMillis();
final ObReadConsistency obReadConsistency = this.getReadConsistency();
return execute(tableName, new TableExecuteCallback<Map<String, Object>>(rowKey) {
Expand Down Expand Up @@ -1752,6 +1764,9 @@ public Update update(String tableName) {
@Override
public long update(final String tableName, final Object[] rowKey, final String[] columns,
final Object[] values) throws Exception {
if (tableName == null || tableName.isEmpty()) {
throw new IllegalArgumentException("table name is null");
}
final long start = System.currentTimeMillis();
return execute(tableName, new TableExecuteCallback<Long>(rowKey) {
/**
Expand Down Expand Up @@ -1831,6 +1846,9 @@ public Delete delete(String tableName) {
*/
@Override
public long delete(final String tableName, final Object[] rowKey) throws Exception {
if (tableName == null || tableName.isEmpty()) {
throw new IllegalArgumentException("table name is null");
}
final long start = System.currentTimeMillis();
return execute(tableName, new TableExecuteCallback<Long>(rowKey) {

Expand Down Expand Up @@ -1909,6 +1927,9 @@ public Insert insert(String tableName) {
@Override
public long insert(final String tableName, final Object[] rowKey, final String[] columns,
final Object[] values) throws Exception {
if (tableName == null || tableName.isEmpty()) {
throw new IllegalArgumentException("table name is null");
}
final long start = System.currentTimeMillis();
return execute(tableName, new TableExecuteCallback<Long>(rowKey) {
/**
Expand Down Expand Up @@ -1989,6 +2010,9 @@ public Replace replace(String tableName) {
@Override
public long replace(final String tableName, final Object[] rowKey, final String[] columns,
final Object[] values) throws Exception {
if (tableName == null || tableName.isEmpty()) {
throw new IllegalArgumentException("table name is null");
}
final long start = System.currentTimeMillis();
return execute(tableName, new TableExecuteCallback<Long>(rowKey) {
/**
Expand Down Expand Up @@ -2069,6 +2093,9 @@ public InsertOrUpdate insertOrUpdate(String tableName) {
@Override
public long insertOrUpdate(final String tableName, final Object[] rowKey,
final String[] columns, final Object[] values) throws Exception {
if (tableName == null || tableName.isEmpty()) {
throw new IllegalArgumentException("table name is null");
}
final long start = System.currentTimeMillis();
return execute(tableName, new TableExecuteCallback<Long>(rowKey) {
/**
Expand Down Expand Up @@ -2169,6 +2196,9 @@ public Increment increment(String tableName) {
public Map<String, Object> increment(final String tableName, final Object[] rowKey,
final String[] columns, final Object[] values,
final boolean withResult) throws Exception {
if (tableName == null || tableName.isEmpty()) {
throw new IllegalArgumentException("table name is null");
}
final long start = System.currentTimeMillis();
return execute(tableName, new TableExecuteCallback<Map<String, Object>>(rowKey) {
/**
Expand Down Expand Up @@ -2256,6 +2286,9 @@ public Append append(String tableName) {
public Map<String, Object> append(final String tableName, final Object[] rowKey,
final String[] columns, final Object[] values,
final boolean withResult) throws Exception {
if (tableName == null || tableName.isEmpty()) {
throw new IllegalArgumentException("table name is null");
}
final long start = System.currentTimeMillis();
return execute(tableName, new TableExecuteCallback<Map<String, Object>>(rowKey) {
@Override
Expand Down Expand Up @@ -2491,6 +2524,9 @@ ObTableQueryAndMutateRequest obTableQueryAndMutate(final ObTableOperation operat
final boolean withResult) throws Exception {
ObTableQuery obTableQuery = tableQuery.getObTableQuery();
String tableName = tableQuery.getTableName();
if (tableName == null || tableName.isEmpty()) {
throw new IllegalArgumentException("table name is null");
}

ObTableBatchOperation operations = new ObTableBatchOperation();

Expand Down Expand Up @@ -2518,6 +2554,9 @@ ObTableQueryAndMutateRequest obTableQueryAndMutate(final ObTableOperation operat
* @throws Exception if fail
*/
public ObPayload execute(final ObTableAbstractOperationRequest request) throws Exception {
if (request.getTableName() == null || request.getTableName().isEmpty()) {
throw new IllegalArgumentException("table name is null");
}
if (request instanceof ObTableOperationRequest) {
ObTableBatchOperation batchOperation = new ObTableBatchOperation();
batchOperation.addTableOperation(((ObTableOperationRequest) request)
Expand Down Expand Up @@ -2947,6 +2986,9 @@ public void addRowKeyElement(String tableName, String[] columns) {
throw new IllegalArgumentException("add row key element error table " + tableName
+ " column " + Arrays.toString(columns));
}
if (tableName == null || tableName.length() == 0) {
throw new IllegalArgumentException("table name is null");
}
Map<String, Integer> rowKeyElement = new HashMap<String, Integer>();
for (int i = 0; i < columns.length; i++) {
rowKeyElement.put(columns[i], i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public boolean isCheckExists() {
}

public MutationResult execute() throws Exception {
if (null == tableName) {
if (null == tableName || tableName.isEmpty()) {
throw new ObTableException("table name is null");
} else if (null == client) {
throw new ObTableException("client is null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public Append removeRowkeyFromMutateColval() {
* execute
*/
public MutationResult execute() throws Exception {
if (null == getTableName()) {
if (null == getTableName() || getTableName().isEmpty()) {
throw new ObTableException("table name is null");
} else if (null == getClient()) {
throw new ObTableException("client is null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public BatchOperationResult execute() throws Exception {
}

public BatchOperationResult executeWithNormalBatchOp() throws Exception {
if (tableName == null || tableName.isEmpty()) {
throw new IllegalArgumentException("table name is null");
}
TableBatchOps batchOps = client.batch(tableName);
boolean hasSetRowkeyElement = false;

Expand Down Expand Up @@ -191,6 +194,9 @@ public BatchOperationResult executeWithNormalBatchOp() throws Exception {
}

public BatchOperationResult executeWithLSBatchOp() throws Exception {
if (tableName == null || tableName.isEmpty()) {
throw new IllegalArgumentException("table name is null");
}
ObTableClientLSBatchOpsImpl batchOps;
if (client instanceof ObTableClient) {
batchOps = new ObTableClientLSBatchOpsImpl(tableName, (ObTableClient) client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ObTableOperationType getOperationType() {
* execute
*/
public MutationResult execute() throws Exception {
if (null == getTableName()) {
if (null == getTableName() || getTableName().isEmpty()) {
throw new ObTableException("table name is null");
} else if (null == getClient()) {
throw new ObTableException("client is null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public Increment removeRowkeyFromMutateColval() {
* execute
*/
public MutationResult execute() throws Exception {
if (null == getTableName()) {
if (null == getTableName() || getTableName().isEmpty()) {
throw new ObTableException("table name is null");
} else if (null == getClient()) {
throw new ObTableException("client is null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public Insert removeRowkeyFromMutateColval() {
* execute
*/
public MutationResult execute() throws Exception {
if (null == getTableName()) {
if (null == getTableName() || getTableName().isEmpty()) {
throw new ObTableException("table name is null");
} else if (null == getClient()) {
throw new ObTableException("client is null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public InsertOrUpdate removeRowkeyFromMutateColval() {
* execute
*/
public MutationResult execute() throws Exception {
if (null == getTableName()) {
if (null == getTableName() || getTableName().isEmpty()) {
throw new ObTableException("table name is null");
} else if (null == getClient()) {
throw new ObTableException("client is null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public Replace removeRowkeyFromMutateColval() {
* execute
*/
public MutationResult execute() throws Exception {
if (null == getTableName()) {
if (null == getTableName() || getTableName().isEmpty()) {
throw new ObTableException("table name is null");
} else if (null == getClient()) {
throw new ObTableException("client is null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public Update removeRowkeyFromMutateColval() {
* execute
*/
public MutationResult execute() throws Exception {
if (null == getTableName()) {
if (null == getTableName() || getTableName().isEmpty()) {
throw new ObTableException("table name is null");
} else if (null == getClient()) {
throw new ObTableException("client is null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ public void partitionExecute(ObTableOperationResult[] results,
*/
public ObTableBatchOperationResult executeInternal() throws Exception {

if (tableName == null || tableName.isEmpty()) {
throw new IllegalArgumentException("table name is null");
}
long start = System.currentTimeMillis();
List<ObTableOperation> operations = batchOperation.getTableOperations();
final ObTableOperationResult[] obTableOperationResults = new ObTableOperationResult[operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ public void partitionExecute(ObTableSingleOpResult[] results,
*/
public ObTableTabletOpResult executeInternal() throws Exception {

if (tableName == null || tableName.isEmpty()) {
throw new IllegalArgumentException("table name is null");
}
long start = System.currentTimeMillis();
final ObTableSingleOpResult[] obTableOperationResults = new ObTableSingleOpResult[batchOperation
.size()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public ObTableClientQueryStreamResult executeInternal() throws Exception {
throw new ObTableException("table client is null");
} else if (tableQuery.getLimit() < 0 && tableQuery.getOffset() > 0) {
throw new ObTableException("offset can not be use without limit");
} else if (tableName == null || tableName.isEmpty()) {
throw new IllegalArgumentException("table name is null");
}
final long startTime = System.currentTimeMillis();
// partitionObTables -> Map<logicId, Pair<logicId, param>>
Expand Down
38 changes: 38 additions & 0 deletions src/test/java/com/alipay/oceanbase/rpc/ObTableClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2489,4 +2489,42 @@ PRIMARY KEY (`c1`)
client.delete("test_timestamp_table", new Object[] { "key_0" });
}
}

@Test
public void testQueryWithEmptyTable() throws Exception {
// test query with empty table name.
try {
client.insert("", new Object[]{0L}, new String[]{"c2", "c3"},
new Object[]{new byte[]{1}, "row1"});
} catch (IllegalArgumentException e) {
Assert.assertEquals("table name is null",
((IllegalArgumentException) e).getMessage());
}
try {
TableQuery tableQuery = client.query("");
tableQuery.addScanRange(new Object[]{0L}, new Object[]{250L});
tableQuery.select("c1", "c2");
QueryResultSet result = tableQuery.execute();
} catch (IllegalArgumentException e) {
Assert.assertEquals("table name is null",
((IllegalArgumentException) e).getMessage());
}
// test insertOrUpdate
final ObTableClient client1 = ObTableClientTestUtil.newTestClient();
try {
client1.setMetadataRefreshInterval(100);
client1.setServerAddressCachingTimeout(8000);
client1.init();
long lastTime = getMaxAccessTime(client1);
Thread.sleep(10000);
// test_query_filter_mutate
client1.insertOrUpdate("", "foo", new String[] { "c2" },
new String[] { "bar" });
long nowTime = getMaxAccessTime(client1);
Assert.assertTrue(nowTime - lastTime > 8000);
} catch (IllegalArgumentException e) {
Assert.assertEquals("table name is null",
((IllegalArgumentException) e).getMessage());
}
}
}