Skip to content

Commit

Permalink
1. disable LogicalDatabaseController
Browse files Browse the repository at this point in the history
2. reverse db-browser to 1.1.3
  • Loading branch information
LuckyPickleZZ committed Jul 12, 2024
1 parent 579fc8f commit 64f7a2f
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 82 deletions.
2 changes: 1 addition & 1 deletion libs/db-browser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.oceanbase</groupId>
<artifactId>db-browser</artifactId>
<version>1.1.4</version>
<version>1.1.3</version>
<name>db-browser</name>
<url>https://github.com/oceanbase/odc/tree/main/libs/db-browser</url>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum DBObjectType {
*/
SCHEMA("SCHEMA"),
TABLE("TABLE"),
LOGICAL_TABLE("LOGICAL TABLE"),
// LOGICAL_TABLE("LOGICAL TABLE"),
COLUMN("COLUMN"),
INDEX("INDEX"),
CONSTRAINT("CONSTRAINT"),
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<alipay.sdk.version>4.20.19.ALL</alipay.sdk.version>
<bucket4j-core.version>4.10.0</bucket4j-core.version>
<springfox-swagger-ui.version>2.10.0</springfox-swagger-ui.version>
<db-browser.version>1.1.4</db-browser.version>
<db-browser.version>1.1.3</db-browser.version>
<ob-sql-parser.version>1.3.0</ob-sql-parser.version>
<pf4j.version>3.10.0</pf4j.version>
<bcpkix-jdk15on.version>1.64</bcpkix-jdk15on.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.oceanbase.odc.service.common.response.Responses;
import com.oceanbase.odc.service.common.response.SuccessResponse;
Expand All @@ -34,7 +33,6 @@
* @Date: 2024/5/7 15:07
* @Description: []
*/
@RestController
@RequestMapping("/api/v2/connect/logicaldatabase")
public class LogicalDatabaseController {
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
*/
package com.oceanbase.odc.service.connection.logicaldatabase;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.stream.Collectors;
Expand All @@ -30,16 +28,12 @@
import com.oceanbase.odc.metadb.connection.DatabaseRepository;
import com.oceanbase.odc.metadb.connection.logicaldatabase.DatabaseMappingEntity;
import com.oceanbase.odc.metadb.connection.logicaldatabase.DatabaseMappingRepository;
import com.oceanbase.odc.metadb.connection.logicaldatabase.TableMappingEntity;
import com.oceanbase.odc.metadb.connection.logicaldatabase.TableMappingRepository;
import com.oceanbase.odc.metadb.dbobject.DBObjectEntity;
import com.oceanbase.odc.metadb.dbobject.DBObjectRepository;
import com.oceanbase.odc.service.connection.database.DatabaseService;
import com.oceanbase.odc.service.connection.database.model.Database;
import com.oceanbase.odc.service.connection.logicaldatabase.core.LogicalTableFinder;
import com.oceanbase.odc.service.connection.logicaldatabase.core.model.DataNode;
import com.oceanbase.odc.service.connection.logicaldatabase.core.model.LogicalTable;
import com.oceanbase.tools.dbbrowser.model.DBObjectType;

import lombok.NonNull;

Expand Down Expand Up @@ -89,38 +83,5 @@ public void run() {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}

try {
Set<String> existedTables = dbObjectRepository.findByDatabaseIdAndType(logicalDatabase.getId(),
DBObjectType.LOGICAL_TABLE).stream().map(DBObjectEntity::getName).collect(Collectors.toSet());

logicalTables.stream().filter(table -> !existedTables.contains(table.getName())).forEach(table -> {
DBObjectEntity tableEntity = new DBObjectEntity();
tableEntity.setDatabaseId(logicalDatabase.getId());
tableEntity.setType(DBObjectType.LOGICAL_TABLE);
tableEntity.setName(table.getName());
tableEntity.setOrganizationId(logicalDatabase.getOrganizationId());
DBObjectEntity savedTableEntity = dbObjectRepository.save(tableEntity);

List<DataNode> dataNodes = table.getActualDataNodes();
List<TableMappingEntity> physicalTableEntities = new ArrayList<>();
dataNodes.stream().forEach(dataNode -> {
TableMappingEntity physicalTableEntity = new TableMappingEntity();
physicalTableEntity.setLogicalTableId(savedTableEntity.getId());
physicalTableEntity.setOrganizationId(logicalDatabase.getOrganizationId());
physicalTableEntity.setPhysicalDatabaseId(dataNode.getDatabaseId());
physicalTableEntity.setPhysicalDatabaseName(dataNode.getSchemaName());
physicalTableEntity.setPhysicalTableName(dataNode.getTableName());
physicalTableEntity.setExpression(table.getFullNameExpression());
physicalTableEntity.setConsistent(true);
physicalTableEntities.add(physicalTableEntity);
});
tableRelationRepository.batchCreate(physicalTableEntities);
});
} finally {
if (lock != null) {
lock.unlock();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@
package com.oceanbase.odc.service.connection.logicaldatabase;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import javax.validation.constraints.NotNull;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskRejectedException;
import org.springframework.stereotype.Service;
Expand All @@ -43,7 +38,6 @@
import com.oceanbase.odc.core.shared.exception.UnexpectedException;
import com.oceanbase.odc.metadb.connection.DatabaseEntity;
import com.oceanbase.odc.metadb.connection.DatabaseRepository;
import com.oceanbase.odc.metadb.connection.logicaldatabase.TableMappingEntity;
import com.oceanbase.odc.metadb.connection.logicaldatabase.TableMappingRepository;
import com.oceanbase.odc.metadb.dbobject.DBObjectEntity;
import com.oceanbase.odc.metadb.dbobject.DBObjectRepository;
Expand All @@ -56,7 +50,6 @@
import com.oceanbase.odc.service.iam.ProjectPermissionValidator;
import com.oceanbase.odc.service.iam.auth.AuthenticationFacade;
import com.oceanbase.odc.service.permission.DBResourcePermissionHelper;
import com.oceanbase.tools.dbbrowser.model.DBObjectType;
import com.oceanbase.tools.sqlparser.SyntaxErrorException;

import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -101,37 +94,7 @@ public List<DetailLogicalTableResp> list(@NotNull Long logicalDatabaseId) {
Verify.equals(DatabaseType.LOGICAL, logicalDatabase.getType(), "database type");
projectPermissionValidator.checkProjectRole(logicalDatabase.getProjectId(), ResourceRoleName.all());

List<DBObjectEntity> logicalTables =
dbObjectRepository.findByDatabaseIdAndType(logicalDatabaseId, DBObjectType.LOGICAL_TABLE);


Set<Long> logicalTableIds = logicalTables.stream().map(DBObjectEntity::getId).collect(Collectors.toSet());
if (CollectionUtils.isEmpty(logicalTableIds)) {
return Collections.emptyList();
}
Map<Long, List<TableMappingEntity>> logicalTbId2Mappings =
mappingRepository.findByLogicalTableIdIn(logicalTableIds).stream()
.collect(Collectors.groupingBy(TableMappingEntity::getLogicalTableId));


return logicalTables.stream().map(tableEntity -> {
DetailLogicalTableResp resp = new DetailLogicalTableResp();
List<TableMappingEntity> relations =
logicalTbId2Mappings.getOrDefault(tableEntity.getId(), Collections.emptyList());
resp.setId(tableEntity.getId());
resp.setName(tableEntity.getName());
resp.setExpression(relations.isEmpty() ? StringUtils.EMPTY : relations.get(0).getExpression());
resp.setPhysicalTableCount(relations.size());
List<DataNode> inconsistentPhysicalTables = new ArrayList<>();
relations.stream().filter(relation -> !relation.getConsistent()).forEach(relation -> {
DataNode dataNode = new DataNode();
dataNode.setSchemaName(relation.getPhysicalDatabaseName());
dataNode.setTableName(relation.getPhysicalTableName());
inconsistentPhysicalTables.add(dataNode);
});
resp.setInconsistentPhysicalTables(inconsistentPhysicalTables);
return resp;
}).collect(Collectors.toList());
return Collections.singletonList(new DetailLogicalTableResp());
}

@Transactional(rollbackFor = Exception.class)
Expand Down

0 comments on commit 64f7a2f

Please sign in to comment.