diff --git a/src/main/java/com/alipay/oceanbase/rpc/ObTableClient.java b/src/main/java/com/alipay/oceanbase/rpc/ObTableClient.java index 4826b262..c1643b71 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/ObTableClient.java +++ b/src/main/java/com/alipay/oceanbase/rpc/ObTableClient.java @@ -518,6 +518,9 @@ private T execute(String tableName, TableExecuteCallback callback) throws */ private T execute(String tableName, TableExecuteCallback 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(); @@ -670,6 +673,9 @@ private T executeMutation(String tableName, MutationExecuteCallback callb */ private T executeMutation(String tableName, MutationExecuteCallback 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(); @@ -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) { @@ -1713,6 +1722,9 @@ public TableBatchOps batch(String tableName) { @Override public Map 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>(rowKey) { @@ -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(rowKey) { /** @@ -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(rowKey) { @@ -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(rowKey) { /** @@ -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(rowKey) { /** @@ -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(rowKey) { /** @@ -2169,6 +2196,9 @@ public Increment increment(String tableName) { public Map 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>(rowKey) { /** @@ -2256,6 +2286,9 @@ public Append append(String tableName) { public Map 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>(rowKey) { @Override @@ -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(); @@ -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) @@ -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 rowKeyElement = new HashMap(); for (int i = 0; i < columns.length; i++) { rowKeyElement.put(columns[i], i); diff --git a/src/main/java/com/alipay/oceanbase/rpc/checkandmutate/CheckAndInsUp.java b/src/main/java/com/alipay/oceanbase/rpc/checkandmutate/CheckAndInsUp.java index 1a89c75e..3568a462 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/checkandmutate/CheckAndInsUp.java +++ b/src/main/java/com/alipay/oceanbase/rpc/checkandmutate/CheckAndInsUp.java @@ -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"); diff --git a/src/main/java/com/alipay/oceanbase/rpc/mutation/Append.java b/src/main/java/com/alipay/oceanbase/rpc/mutation/Append.java index 0d879d55..4549c9a0 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/mutation/Append.java +++ b/src/main/java/com/alipay/oceanbase/rpc/mutation/Append.java @@ -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"); diff --git a/src/main/java/com/alipay/oceanbase/rpc/mutation/BatchOperation.java b/src/main/java/com/alipay/oceanbase/rpc/mutation/BatchOperation.java index 48092e30..4055f140 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/mutation/BatchOperation.java +++ b/src/main/java/com/alipay/oceanbase/rpc/mutation/BatchOperation.java @@ -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; @@ -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); diff --git a/src/main/java/com/alipay/oceanbase/rpc/mutation/Delete.java b/src/main/java/com/alipay/oceanbase/rpc/mutation/Delete.java index d8dd7180..e0eb352a 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/mutation/Delete.java +++ b/src/main/java/com/alipay/oceanbase/rpc/mutation/Delete.java @@ -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"); diff --git a/src/main/java/com/alipay/oceanbase/rpc/mutation/Increment.java b/src/main/java/com/alipay/oceanbase/rpc/mutation/Increment.java index 6a6bd3d0..8ffc5c8e 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/mutation/Increment.java +++ b/src/main/java/com/alipay/oceanbase/rpc/mutation/Increment.java @@ -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"); diff --git a/src/main/java/com/alipay/oceanbase/rpc/mutation/Insert.java b/src/main/java/com/alipay/oceanbase/rpc/mutation/Insert.java index 2d6b516f..c23b6241 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/mutation/Insert.java +++ b/src/main/java/com/alipay/oceanbase/rpc/mutation/Insert.java @@ -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"); diff --git a/src/main/java/com/alipay/oceanbase/rpc/mutation/InsertOrUpdate.java b/src/main/java/com/alipay/oceanbase/rpc/mutation/InsertOrUpdate.java index ae8e9a0b..b60fbf2b 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/mutation/InsertOrUpdate.java +++ b/src/main/java/com/alipay/oceanbase/rpc/mutation/InsertOrUpdate.java @@ -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"); diff --git a/src/main/java/com/alipay/oceanbase/rpc/mutation/Replace.java b/src/main/java/com/alipay/oceanbase/rpc/mutation/Replace.java index 1a89d954..0e0eaf7a 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/mutation/Replace.java +++ b/src/main/java/com/alipay/oceanbase/rpc/mutation/Replace.java @@ -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"); diff --git a/src/main/java/com/alipay/oceanbase/rpc/mutation/Update.java b/src/main/java/com/alipay/oceanbase/rpc/mutation/Update.java index 2f028548..37e45a47 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/mutation/Update.java +++ b/src/main/java/com/alipay/oceanbase/rpc/mutation/Update.java @@ -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"); diff --git a/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientBatchOpsImpl.java b/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientBatchOpsImpl.java index ab08cda6..6b06ea30 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientBatchOpsImpl.java +++ b/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientBatchOpsImpl.java @@ -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 operations = batchOperation.getTableOperations(); final ObTableOperationResult[] obTableOperationResults = new ObTableOperationResult[operations diff --git a/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientLSBatchOpsImpl.java b/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientLSBatchOpsImpl.java index 0d886662..f857c0c0 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientLSBatchOpsImpl.java +++ b/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientLSBatchOpsImpl.java @@ -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()]; diff --git a/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientQueryImpl.java b/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientQueryImpl.java index 21455cab..abe87c4b 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientQueryImpl.java +++ b/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientQueryImpl.java @@ -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> diff --git a/src/test/java/com/alipay/oceanbase/rpc/ObTableClientTest.java b/src/test/java/com/alipay/oceanbase/rpc/ObTableClientTest.java index a480b54e..5597a4aa 100644 --- a/src/test/java/com/alipay/oceanbase/rpc/ObTableClientTest.java +++ b/src/test/java/com/alipay/oceanbase/rpc/ObTableClientTest.java @@ -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()); + } + } }