private long addCache(TablePageQueryParam param, TableCacheVersionDO versionDO) {
        LambdaQueryWrapper<TableCacheVersionDO> queryWrapper = new LambdaQueryWrapper<>();
        String key = getTableKey(param.getDataSourceId(), param.getDatabaseName(), param.getSchemaName());
        queryWrapper.eq(TableCacheVersionDO::getKey, key);
        long total = 0;
        long version = getLock(param.getDataSourceId(), param.getDatabaseName(), param.getSchemaName(), versionDO);
        if (version == -1) {
            int n = 0;
            while (n < 100) {
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                }
                versionDO = getVersionMapper().selectOne(queryWrapper);
                if (versionDO != null && "1".equals(versionDO.getStatus())) {
                    version = versionDO.getVersion();
                    total = versionDO.getTableCount();
                    break;
                }
                n++;
            }
        } else {
            total = addDBCache(param.getDataSourceId(), param.getDatabaseName(), param.getSchemaName(), version);
            TableCacheVersionDO versionDO1 = new TableCacheVersionDO();
            versionDO1.setStatus("1");
            versionDO1.setTableCount(total);
            getVersionMapper().update(versionDO1, queryWrapper);
        }
        return total;
    }
@author moji
@version DataSourceCoreServiceImpl.java, v 0.1 September 23, 2022 15:51 moji Exp $
@date 2022/09/23
chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/TableServiceImpl.java