-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(object-search): persistence and service layer implementation (#2155
) * add persistence layer impl * add service layer empty impl * add service impl * fix unit tests and refine codes * modify migrate script version number * rename classes and table * fix ut
- Loading branch information
1 parent
2d6cd47
commit f4e5e31
Showing
28 changed files
with
1,559 additions
and
20 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
...egration-test/src/test/java/com/oceanbase/odc/metadb/dbobject/DBColumnRepositoryTest.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,75 @@ | ||
/* | ||
* Copyright (c) 2023 OceanBase. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.oceanbase.odc.metadb.dbobject; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import com.oceanbase.odc.ServiceTestEnv; | ||
import com.oceanbase.odc.test.tool.TestRandom; | ||
|
||
/** | ||
* @author gaoda.xy | ||
* @date 2024/3/27 19:11 | ||
*/ | ||
public class DBColumnRepositoryTest extends ServiceTestEnv { | ||
|
||
@Autowired | ||
private DBColumnRepository dbColumnRepository; | ||
|
||
@Before | ||
public void setUp() { | ||
dbColumnRepository.deleteAll(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
dbColumnRepository.deleteAll(); | ||
} | ||
|
||
@Test | ||
public void test_findAll() { | ||
List<DBColumnEntity> entities = Arrays.asList( | ||
TestRandom.nextObject(DBColumnEntity.class), | ||
TestRandom.nextObject(DBColumnEntity.class), | ||
TestRandom.nextObject(DBColumnEntity.class)); | ||
dbColumnRepository.saveAll(entities); | ||
Assert.assertEquals(entities.size(), dbColumnRepository.findAll().size()); | ||
} | ||
|
||
@Test | ||
public void test_findTop1000ByDatabaseIdInAndNameLike() { | ||
DBColumnEntity entity1 = TestRandom.nextObject(DBColumnEntity.class); | ||
entity1.setDatabaseId(1L); | ||
entity1.setName("database_for_test_1"); | ||
DBColumnEntity entity2 = TestRandom.nextObject(DBColumnEntity.class); | ||
entity2.setDatabaseId(2L); | ||
entity2.setName("database_for_test_2"); | ||
dbColumnRepository.saveAll(Arrays.asList(entity1, entity2)); | ||
List<DBColumnEntity> entities = | ||
dbColumnRepository.findTop1000ByDatabaseIdInAndNameLike(Arrays.asList(1L, 2L, 3L), "%test_1"); | ||
Assert.assertEquals(1, entities.size()); | ||
entities = dbColumnRepository.findTop1000ByDatabaseIdInAndNameLike(Arrays.asList(1L, 2L, 3L), "%test%"); | ||
Assert.assertEquals(2, entities.size()); | ||
} | ||
|
||
} |
93 changes: 93 additions & 0 deletions
93
...egration-test/src/test/java/com/oceanbase/odc/metadb/dbobject/DBObjectRepositoryTest.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,93 @@ | ||
/* | ||
* Copyright (c) 2023 OceanBase. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.oceanbase.odc.metadb.dbobject; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import com.oceanbase.odc.ServiceTestEnv; | ||
import com.oceanbase.odc.test.tool.TestRandom; | ||
import com.oceanbase.tools.dbbrowser.model.DBObjectType; | ||
|
||
/** | ||
* @author gaoda.xy | ||
* @date 2024/3/27 19:15 | ||
*/ | ||
public class DBObjectRepositoryTest extends ServiceTestEnv { | ||
|
||
@Autowired | ||
private DBObjectRepository dbObjectRepository; | ||
|
||
@Before | ||
public void setUp() { | ||
dbObjectRepository.deleteAll(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
dbObjectRepository.deleteAll(); | ||
} | ||
|
||
@Test | ||
public void test_findAll() { | ||
List<DBObjectEntity> entities = Arrays.asList( | ||
TestRandom.nextObject(DBObjectEntity.class), | ||
TestRandom.nextObject(DBObjectEntity.class), | ||
TestRandom.nextObject(DBObjectEntity.class)); | ||
dbObjectRepository.saveAll(entities); | ||
Assert.assertEquals(entities.size(), dbObjectRepository.findAll().size()); | ||
} | ||
|
||
@Test | ||
public void test_findTop1000ByDatabaseIdInAndNameLike() { | ||
DBObjectEntity entity1 = TestRandom.nextObject(DBObjectEntity.class); | ||
entity1.setDatabaseId(1L); | ||
entity1.setName("object_for_test_1"); | ||
DBObjectEntity entity2 = TestRandom.nextObject(DBObjectEntity.class); | ||
entity2.setDatabaseId(2L); | ||
entity2.setName("object_for_test_2"); | ||
dbObjectRepository.saveAll(Arrays.asList(entity1, entity2)); | ||
dbObjectRepository.flush(); | ||
List<DBObjectEntity> entities = | ||
dbObjectRepository.findTop1000ByDatabaseIdInAndNameLike(Arrays.asList(1L, 2L), "%test%"); | ||
Assert.assertEquals(2, entities.size()); | ||
} | ||
|
||
@Test | ||
public void test_findTop1000ByDatabaseIdInAndTypeAndNameLike() { | ||
DBObjectEntity entity1 = TestRandom.nextObject(DBObjectEntity.class); | ||
entity1.setDatabaseId(1L); | ||
entity1.setType(DBObjectType.TABLE); | ||
entity1.setName("table_for_test_1"); | ||
DBObjectEntity entity2 = TestRandom.nextObject(DBObjectEntity.class); | ||
entity2.setDatabaseId(1L); | ||
entity2.setType(DBObjectType.VIEW); | ||
entity2.setName("view_for_test_1"); | ||
dbObjectRepository.saveAll(Arrays.asList(entity1, entity2)); | ||
List<DBObjectEntity> entities = dbObjectRepository.findTop1000ByDatabaseIdInAndTypeInAndNameLike( | ||
Arrays.asList(1L, 2L), Collections.singletonList(DBObjectType.VIEW.name()), "%test%"); | ||
Assert.assertEquals(1, entities.size()); | ||
Assert.assertEquals("view_for_test_1", entities.get(0).getName()); | ||
} | ||
|
||
} |
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.