|
34 | 34 | import com.tencent.tcvectordb.model.param.entity.SearchRes;
|
35 | 35 | import com.tencent.tcvectordb.model.param.enums.DataBaseTypeEnum;
|
36 | 36 | import com.tencent.tcvectordb.model.param.enums.ReadConsistencyEnum;
|
| 37 | +import com.tencent.tcvectordb.model.param.user.*; |
37 | 38 | import com.tencent.tcvectordb.service.HttpStub;
|
38 | 39 | import com.tencent.tcvectordb.service.Stub;
|
39 | 40 | import com.tencent.tcvectordb.service.param.*;
|
@@ -244,6 +245,71 @@ public Collection createCollectionIfNotExists(String databaseName, CreateCollect
|
244 | 245 | return param;
|
245 | 246 | }
|
246 | 247 |
|
| 248 | + /** |
| 249 | + * list collection of database |
| 250 | + * @param databaseName: database's name |
| 251 | + * @return List<Collection>: the list of collection |
| 252 | + * @throws VectorDBException |
| 253 | + */ |
| 254 | + public List<Collection> listCollections(String databaseName) throws VectorDBException { |
| 255 | + List<Collection> collections = stub.listCollections(databaseName); |
| 256 | + collections.forEach(c -> { |
| 257 | + c.setStub(stub); |
| 258 | + c.setReadConsistency(readConsistency); |
| 259 | + }); |
| 260 | + return collections; |
| 261 | + } |
| 262 | + |
| 263 | + /** |
| 264 | + * truncate collection |
| 265 | + * @param collectionName |
| 266 | + * @return |
| 267 | + */ |
| 268 | + public AffectRes truncateCollections(String databaseName, String collectionName) { |
| 269 | + return stub.truncateCollection(databaseName, collectionName, DataBaseTypeEnum.BASE_DB); |
| 270 | + } |
| 271 | + |
| 272 | + /** |
| 273 | + * describe collection |
| 274 | + * @param collectionName |
| 275 | + * @return Collection if collection exist |
| 276 | + * @throws VectorDBException |
| 277 | + */ |
| 278 | + public Collection describeCollection(String databaseName, String collectionName) throws VectorDBException { |
| 279 | + Collection collection = stub.describeCollection(databaseName, collectionName); |
| 280 | + collection.setStub(stub); |
| 281 | + collection.setReadConsistency(readConsistency); |
| 282 | + return collection; |
| 283 | + } |
| 284 | + |
| 285 | + /** |
| 286 | + * drop collection |
| 287 | + * @param collectionName |
| 288 | + * @throws VectorDBException |
| 289 | + */ |
| 290 | + public void dropCollection(String databaseName, String collectionName) throws VectorDBException { |
| 291 | + stub.dropCollection(databaseName, collectionName); |
| 292 | + } |
| 293 | + |
| 294 | + /** |
| 295 | + * set alias for collection |
| 296 | + * @param collectionName |
| 297 | + * @param aliasName |
| 298 | + * @return |
| 299 | + */ |
| 300 | + public AffectRes setAlias(String databaseName, String collectionName, String aliasName) { |
| 301 | + return stub.setAlias(databaseName, collectionName, aliasName); |
| 302 | + } |
| 303 | + |
| 304 | + /** |
| 305 | + * delete alias of collection |
| 306 | + * @param aliasName |
| 307 | + * @return |
| 308 | + */ |
| 309 | + public AffectRes deleteAlias(String databaseName, String aliasName) { |
| 310 | + return stub.deleteAlias(databaseName, aliasName); |
| 311 | + } |
| 312 | + |
247 | 313 | /**
|
248 | 314 | * upsert document
|
249 | 315 | * @param database: database name
|
@@ -297,6 +363,7 @@ public AffectRes upsert(String database, String collection, InsertParam param) t
|
297 | 363 | * filter(Filter): filter rows before return result
|
298 | 364 | * document_ids(List): filter rows by id list
|
299 | 365 | * output_fields(List): return columns by column name list
|
| 366 | + * sort(OrderRule): sort rows by OrderRule{fieldName, direction} before return result |
300 | 367 | * @return List<Document>
|
301 | 368 | * @throws VectorDBException
|
302 | 369 | */
|
@@ -458,6 +525,14 @@ public BaseRes AddIndex(String database, String collection, AddIndexParam addInd
|
458 | 525 | new AddIndexParamInner(database, collection, addIndexParam));
|
459 | 526 | }
|
460 | 527 |
|
| 528 | + /** |
| 529 | + * rebuild index |
| 530 | + * @param rebuildIndexParam: rebuild index param |
| 531 | + * @return BaseRes |
| 532 | + */ |
| 533 | + public BaseRes rebuildIndex(String database, String collection, RebuildIndexParam rebuildIndexParam) { |
| 534 | + return this.stub.rebuildIndex(new RebuildIndexParamInner(database, collection, rebuildIndexParam)); |
| 535 | + } |
461 | 536 |
|
462 | 537 | /**
|
463 | 538 | * Used to add a scalar field index to an existing collection
|
@@ -513,4 +588,127 @@ public BaseRes modifyVectorIndex(String database, String collection, ModifyVecto
|
513 | 588 | new ModifyIndexParamInner(database, collection, modifyVectorIndexParam), false);
|
514 | 589 | }
|
515 | 590 |
|
| 591 | + /** |
| 592 | + * create user |
| 593 | + * @param username: user name to create |
| 594 | + * @param password: The password of user. |
| 595 | + * @return BaseRes.class: {code: 0, msg: "operation success"} |
| 596 | + * @throws VectorDBException |
| 597 | + */ |
| 598 | + public BaseRes createUser(String username, String password) throws VectorDBException { |
| 599 | + return this.stub.createUser( |
| 600 | + new UserCreateParam(username, password)); |
| 601 | + } |
| 602 | + |
| 603 | + |
| 604 | + /** |
| 605 | + * grant user to database |
| 606 | + * @param param: UserGrantParam.class: |
| 607 | + * user (str): The user to grant permission. |
| 608 | + * privileges (str): The privileges to grant. For example: |
| 609 | + * { |
| 610 | + * "resource": "db0.*", |
| 611 | + * "actions": ["read"] |
| 612 | + * } |
| 613 | + * for example: |
| 614 | + * UserGrantParam.newBuilder() |
| 615 | + * .withUser(user_test) |
| 616 | + * .withPrivileges(Arrays.asList( |
| 617 | + * PrivilegeParam.newBuilder().withResource("java-sdk-test-user-permission.*").withActions(Arrays.asList("read")).build(), |
| 618 | + * PrivilegeParam.newBuilder().withResource("java-sdk-test-user-permission.*").withActions(Arrays.asList("readWrite")).build())) |
| 619 | + * .build() |
| 620 | + * @return BaseRes.class: {code: 0, msg: "operation success"} |
| 621 | + * @throws VectorDBException |
| 622 | + */ |
| 623 | + public BaseRes grantToUser(UserGrantParam param) throws VectorDBException { |
| 624 | + return this.stub.grantToUser(param); |
| 625 | + } |
| 626 | + |
| 627 | + |
| 628 | + /** |
| 629 | + * revoke user from database |
| 630 | + * @param param: UserRevokeParam.class: |
| 631 | + * user (str): The user to grant permission. |
| 632 | + * privileges (str): The privileges to grant. For example: |
| 633 | + * { |
| 634 | + * "resource": "db0.*", |
| 635 | + * "actions": ["read"] |
| 636 | + * } |
| 637 | + * for example: |
| 638 | + * UserRevokeParam.newBuilder() |
| 639 | + * .withUser(user_test) |
| 640 | + * .withPrivileges(Arrays.asList( |
| 641 | + * PrivilegeParam.newBuilder().withResource("java-sdk-test-user-permission.*").withActions(Arrays.asList("read")).build(), |
| 642 | + * PrivilegeParam.newBuilder().withResource("java-sdk-test-user-permission.*").withActions(Arrays.asList("readWrite")).build())) |
| 643 | + * .build() |
| 644 | + * @return BaseRes.class: {code: 0, msg: "operation success"} |
| 645 | + * @throws VectorDBException |
| 646 | + */ |
| 647 | + public BaseRes revokeFromUser(UserRevokeParam param) throws VectorDBException { |
| 648 | + return this.stub.revokeFromUser(param); |
| 649 | + } |
| 650 | + |
| 651 | + |
| 652 | + /** |
| 653 | + * describe user |
| 654 | + * @param user: user name to describe |
| 655 | + * @return UserDescribeRes.class: |
| 656 | + * { |
| 657 | + * "user": "test_user", |
| 658 | + * "createTime": "2024-10-01 00:00:00", |
| 659 | + * "privileges": [ |
| 660 | + * { |
| 661 | + * "resource": "db0.*", |
| 662 | + * "actions": ["read"] |
| 663 | + * } |
| 664 | + * ] |
| 665 | + * } |
| 666 | + * @throws VectorDBException |
| 667 | + */ |
| 668 | + public UserDescribeRes describeUser(String user) throws VectorDBException { |
| 669 | + return this.stub.describeUser(new UserDescribeParam(user)); |
| 670 | + } |
| 671 | + |
| 672 | + /** |
| 673 | + * list user |
| 674 | + * @return UserListRes.class: |
| 675 | + * { |
| 676 | + * "users": [ |
| 677 | + * "user": "test_user", |
| 678 | + * "createTime": "2024-10-01 00:00:00", |
| 679 | + * "privileges": [ |
| 680 | + * { |
| 681 | + * "resource": "db0.*", |
| 682 | + * "actions": ["read"] |
| 683 | + * } |
| 684 | + * ] |
| 685 | + * ] |
| 686 | + * } |
| 687 | + * @throws VectorDBException |
| 688 | + */ |
| 689 | + public UserListRes listUser() throws VectorDBException { |
| 690 | + return this.stub.listUser(); |
| 691 | + } |
| 692 | + |
| 693 | + /** |
| 694 | + * drop user |
| 695 | + * @param user: user name to drop |
| 696 | + * @return baseRes.class: {code: 0, msg: "operation success"} |
| 697 | + * @throws VectorDBException |
| 698 | + */ |
| 699 | + public BaseRes dropUser(String user) throws VectorDBException { |
| 700 | + return this.stub.dropUser(new UserDropParam(user)); |
| 701 | + } |
| 702 | + |
| 703 | + /** |
| 704 | + * change user password |
| 705 | + * @param user: user name to change password |
| 706 | + * @param password: <PASSWORD> |
| 707 | + * @return baseRes.class: {code: 0, msg: "operation success"} |
| 708 | + * @throws VectorDBException |
| 709 | + */ |
| 710 | + public BaseRes changePassword(String user, String password) throws VectorDBException { |
| 711 | + return this.stub.changeUserPassword(UserChangePasswordParam.newBuilder().withUser(user).withPassword(password).build()); |
| 712 | + } |
| 713 | + |
516 | 714 | }
|
0 commit comments