当前位置: 首页 > news >正文

Nacos2.2.0多数据源适配oracle12C-修改Nacos源码

从2.2.0版本开始,可通过SPI机制注入多数据源实现插件,并在引入对应数据源实现后,便可在Nacos启动时通过读取application.properties配置文件中spring.datasource.platform配置项选择加载对应多数据源插件.本文档详细介绍一个多数据源插件如何实现以及如何使其生效。


文章目录

  • 一、Nacos官方文档
  • 二、实现步骤
    • 2.1 2.2.0版本源码下载
    • 2.2 引入Oracle驱动包
      • 2.2.1 nacos-all pom.xml
      • 2.2.2 nacos-config pom.xml
    • 2.3 nacos-config模块修改
    • 2.4 nacos-datasource-plugin模块修改(!!!重点!!!)
      • 2.4.1 DataSourceConstant类修改
      • 2.4.2 增加oracle的mapper实现类
      • 2.4.3 com.alibaba.nacos.plugin.datasource.mapper.Mapper修改
    • 2.5 nacos-console模块修改
    • 2.6 Nacos2.2.0适配Oracle12C-建表ddl语句
    • 2.7 打包
  • 总结


一、Nacos官方文档

Nacos整体介绍可看Nacos官方文档

二、实现步骤

下面,重点讲解如何通过修改源码实现Oracle适配

2.1 2.2.0版本源码下载

2.2.0版本源码下载

2.2 引入Oracle驱动包

根据适配版本选择对应驱动包

2.2.1 nacos-all pom.xml

            <dependency><groupId>com.oracle.ojdbc</groupId><artifactId>ojdbc8</artifactId><version>${ojdbc.version}</version></dependency>

2.2.2 nacos-config pom.xml

        <dependency><groupId>com.oracle.ojdbc</groupId><artifactId>ojdbc8</artifactId></dependency>

2.3 nacos-config模块修改

修改类config/src/main/java/com/alibaba/nacos/config/server/service/datasource/ExternalDataSourceProperties.java

修改后的代码如下:

/** Copyright 1999-2018 Alibaba Group Holding Ltd.** 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.alibaba.nacos.config.server.service.datasource;import com.alibaba.nacos.common.utils.Preconditions;
import com.alibaba.nacos.common.utils.StringUtils;
import com.zaxxer.hikari.HikariDataSource;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.core.env.Environment;import java.util.ArrayList;
import java.util.List;
import java.util.Objects;import static com.alibaba.nacos.common.utils.CollectionUtils.getOrDefault;/*** Properties of external DataSource.** @author Nacos*/
public class ExternalDataSourceProperties {//updateprivate String jdbcDriverName;//updateprivate String testQuery;private Integer num;private List<String> url = new ArrayList<>();private List<String> user = new ArrayList<>();private List<String> password = new ArrayList<>();public void setNum(Integer num) {this.num = num;}public void setUrl(List<String> url) {this.url = url;}public void setUser(List<String> user) {this.user = user;}public void setPassword(List<String> password) {this.password = password;}//add newpublic void setTestQuery(String testQuery) {if (StringUtils.isBlank(testQuery)) {this.testQuery = "SELECT 1";} else {this.testQuery = testQuery;}}//add newpublic void setJdbcDriverName(String jdbcDriverName) {if (StringUtils.isBlank(jdbcDriverName)) {this.jdbcDriverName = "com.mysql.cj.jdbc.Driver";} else {this.jdbcDriverName = jdbcDriverName;}}/*** Build serveral HikariDataSource.** @param environment {@link Environment}* @param callback    Callback function when constructing data source* @return List of {@link HikariDataSource}*/List<HikariDataSource> build(Environment environment, Callback<HikariDataSource> callback) {List<HikariDataSource> dataSources = new ArrayList<>();Binder.get(environment).bind("db", Bindable.ofInstance(this));Preconditions.checkArgument(Objects.nonNull(num), "db.num is null");Preconditions.checkArgument(CollectionUtils.isNotEmpty(user), "db.user or db.user.[index] is null");Preconditions.checkArgument(CollectionUtils.isNotEmpty(password), "db.password or db.password.[index] is null");for (int index = 0; index < num; index++) {int currentSize = index + 1;Preconditions.checkArgument(url.size() >= currentSize, "db.url.%s is null", index);DataSourcePoolProperties poolProperties = DataSourcePoolProperties.build(environment);if (StringUtils.isEmpty(poolProperties.getDataSource().getDriverClassName())) {poolProperties.setDriverClassName(jdbcDriverName);}poolProperties.setJdbcUrl(url.get(index).trim());poolProperties.setUsername(getOrDefault(user, index, user.get(0)).trim());poolProperties.setPassword(getOrDefault(password, index, password.get(0)).trim());HikariDataSource ds = poolProperties.getDataSource();if (StringUtils.isEmpty(ds.getConnectionTestQuery())) {ds.setConnectionTestQuery(testQuery);}dataSources.add(ds);callback.accept(ds);}Preconditions.checkArgument(CollectionUtils.isNotEmpty(dataSources), "no datasource available");return dataSources;}interface Callback<D> {/*** Perform custom logic.** @param datasource dataSource.*/void accept(D datasource);}
}

2.4 nacos-datasource-plugin模块修改(!!!重点!!!)

2.4.1 DataSourceConstant类修改

修改类:plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/constants/DataSourceConstant.java
修改后的代码如下:

/** Copyright 1999-2022 Alibaba Group Holding Ltd.** 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.alibaba.nacos.plugin.datasource.constants;/*** The data source name.** @author hyx**/public class DataSourceConstant {public static final String MYSQL = "mysql";public static final String DERBY = "derby";public static final String ORCLE = "oracle";
}

2.4.2 增加oracle的mapper实现类

先上截图,如下新增9个类:
在这里插入图片描述
在plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/目录新建oracle目录,再在oracle目录新增实现类,各个类代码如下:
1.ConfigInfoAggrMapperByOracle

/** Copyright 1999-2022 Alibaba Group Holding Ltd.** 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.alibaba.nacos.plugin.datasource.impl.oracle;import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoAggrMapper;import java.util.List;/*** The mysql implementation of ConfigInfoAggrMapper.** @author hyx**/public class ConfigInfoAggrMapperByOracle extends AbstractMapper implements ConfigInfoAggrMapper {@Overridepublic String batchRemoveAggr(List<String> datumList) {final StringBuilder datumString = new StringBuilder();for (String datum : datumList) {datumString.append('\'').append(datum).append("',");}datumString.deleteCharAt(datumString.length() - 1);return "DELETE FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND datum_id IN ("+ datumString + ")";}@Overridepublic String aggrConfigInfoCount(int size, boolean isIn) {StringBuilder sql = new StringBuilder("SELECT count(*) FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND datum_id");if (isIn) {sql.append(" IN (");} else {sql.append(" NOT IN (");}for (int i = 0; i < size; i++) {if (i > 0) {sql.append(", ");}sql.append('?');}sql.append(')');return sql.toString();}@Overridepublic String findConfigInfoAggrIsOrdered() {return "SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM "+ "config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY datum_id";}@Overridepublic String findConfigInfoAggrByPageFetchRows(int startRow, int pageSize) {return "SELECT * FROM (SELECT data_id,group_id,tenant_id,datum_id,app_name,content, ROWNUM as rnum"+ " FROM config_info_aggr WHERE data_id= ? AND "+ "group_id= ? AND tenant_id= ? ORDER BY datum_id) WHERE  rnum >= " + startRow + " and " + pageSize + " >= rnum";}@Overridepublic String findAllAggrGroupByDistinct() {return "SELECT DISTINCT data_id, group_id, tenant_id FROM config_info_aggr";}@Overridepublic String getTableName() {return TableConstant.CONFIG_INFO_AGGR;}@Overridepublic String getDataSource() {return DataSourceConstant.ORCLE;}
}

2.ConfigInfoBetaMapperByOracle

/** Copyright 1999-2022 Alibaba Group Holding Ltd.** 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.alibaba.nacos.plugin.datasource.impl.oracle;import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoBetaMapper;/*** The mysql implementation of ConfigInfoBetaMapper.** @author hyx**/public class ConfigInfoBetaMapperByOracle extends AbstractMapper implements ConfigInfoBetaMapper {@Overridepublic String updateConfigInfo4BetaCas() {return "UPDATE config_info_beta SET content = ?,md5 = ?,beta_ips = ?,src_ip = ?,src_user = ?,gmt_modified = ?,app_name = ? "+ "WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND (md5 = ? or md5 is null or md5 = '')";}@Overridepublic String findAllConfigInfoBetaForDumpAllFetchRows(int startRow, int pageSize) {return " SELECT * FROM (SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,beta_ips,encrypted_data_key "+ " FROM ( SELECT * FROM (SELECT id, ROWNUM as rnum FROM config_info_beta  ORDER BY id) "+ "WHERE  rnum >= " + startRow + " and " + pageSize + " >= rnum" + " )"+ "  g, config_info_beta t WHERE g.id = t.id ";}@Overridepublic String getTableName() {return TableConstant.CONFIG_INFO_BETA;}@Overridepublic String getDataSource() {return DataSourceConstant.ORCLE;}
}

3.ConfigInfoMapperByOracle

/** Copyright 1999-2022 Alibaba Group Holding Ltd.** 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.alibaba.nacos.plugin.datasource.impl.oracle;import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoMapper;import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;/*** The mysql implementation of ConfigInfoMapper.** @author hyx**/public class ConfigInfoMapperByOracle extends AbstractMapper implements ConfigInfoMapper {private static final String DATA_ID = "dataId";private static final String GROUP = "group";private static final String APP_NAME = "appName";private static final String CONTENT = "content";private static final String TENANT = "tenant";@Overridepublic String findConfigMaxId() {return "SELECT MAX(id) FROM config_info";}@Overridepublic String findAllDataIdAndGroup() {return "SELECT DISTINCT data_id, group_id FROM config_info";}@Overridepublic String findConfigInfoByAppCountRows() {return "SELECT count(*) FROM config_info WHERE tenant_id LIKE ? AND app_name= ?";}@Overridepublic String findConfigInfoByAppFetchRows(int startRow, int pageSize) {return "SELECT * FROM (SELECT id,data_id,group_id,tenant_id,app_name,content, ROWNUM as rnum FROM config_info"+ " WHERE tenant_id LIKE ? AND app_name= ?)" + " WHERE  rnum >= " + startRow + " and " + pageSize + " >= rnum";}@Overridepublic String configInfoLikeTenantCount() {return "SELECT count(*) FROM config_info WHERE tenant_id LIKE ?";}@Overridepublic String getTenantIdList(int startRow, int pageSize) {return "SELECT * FROM (SELECT tenant_id, ROWNUM as rnum FROM config_info WHERE tenant_id != '' GROUP BY tenant_id)"+ " WHERE  rnum >= " + startRow + " and " + pageSize + " >= rnum";}@Overridepublic String getGroupIdList(int startRow, int pageSize) {return "SELECT * FROM (SELECT group_id, ROWNUM as rnum FROM config_info WHERE tenant_id ='' GROUP BY group_id) "+ " WHERE  rnum >= " + startRow + " and " + pageSize + " >= rnum";}@Overridepublic String findAllConfigKey(int startRow, int pageSize) {return " SELECT data_id,group_id,app_name  FROM ( "+ " SELECT * FROM (SELECT id, ROWNUM as rnum FROM config_info WHERE tenant_id LIKE ? ORDER BY id)"+ " WHERE  rnum >= " + startRow + " and " + pageSize + " >= rnum"+ " )" + " g, config_info t WHERE g.id = t.id  ";}@Overridepublic String findAllConfigInfoBaseFetchRows(int startRow, int pageSize) {return "SELECT t.id,data_id,group_id,content,md5"+ " FROM (SELECT * FROM ( SELECT id, ROWNUM as rnum FROM config_info ORDER BY id)"+ " WHERE  rnum >= " + startRow + " and " + pageSize + " >= rnum) "+ " g, config_info t  WHERE g.id = t.id ";}@Overridepublic String findAllConfigInfoFragment(int startRow, int pageSize) {return "SELECT * FROM (SELECT id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,type,encrypted_data_key "+ "FROM config_info WHERE id > ? ORDER BY id ASC) " + " WHERE  rnum >= " + startRow + " and " + pageSize + " >= rnum) ";}@Overridepublic String findChangeConfig() {return "SELECT data_id, group_id, tenant_id, app_name, content, gmt_modified,encrypted_data_key "+ "FROM config_info WHERE gmt_modified >= ? AND gmt_modified <= ?";}@Overridepublic String findChangeConfigCountRows(Map<String, String> params, final Timestamp startTime,final Timestamp endTime) {final String tenant = params.get(TENANT);final String dataId = params.get(DATA_ID);final String group = params.get(GROUP);final String appName = params.get(APP_NAME);final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;final String sqlCountRows = "SELECT count(*) FROM config_info WHERE ";String where = " 1=1 ";if (!StringUtils.isBlank(dataId)) {where += " AND data_id LIKE ? ";}if (!StringUtils.isBlank(group)) {where += " AND group_id LIKE ? ";}if (!StringUtils.isBlank(tenantTmp)) {where += " AND tenant_id = ? ";}if (!StringUtils.isBlank(appName)) {where += " AND app_name = ? ";}if (startTime != null) {where += " AND gmt_modified >=? ";}if (endTime != null) {where += " AND gmt_modified <=? ";}return sqlCountRows + where;}@Overridepublic String findChangeConfigFetchRows(Map<String, String> params, final Timestamp startTime,final Timestamp endTime, int startRow, int pageSize, long lastMaxId) {final String tenant = params.get(TENANT);final String dataId = params.get(DATA_ID);final String group = params.get(GROUP);final String appName = params.get(APP_NAME);final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;final String sqlFetchRows = "SELECT * FROM (SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_modified"+ ", ROWNUM as rnum FROM config_info WHERE ";String where = " 1=1 ";if (!StringUtils.isBlank(dataId)) {where += " AND data_id LIKE ? ";}if (!StringUtils.isBlank(group)) {where += " AND group_id LIKE ? ";}if (!StringUtils.isBlank(tenantTmp)) {where += " AND tenant_id = ? ";}if (!StringUtils.isBlank(appName)) {where += " AND app_name = ? ";}if (startTime != null) {where += " AND gmt_modified >=? ";}if (endTime != null) {where += " AND gmt_modified <=? ";}return sqlFetchRows + where + " AND id > " + lastMaxId + " ORDER BY id ASC)" + " WHERE  rnum >= " + 0 + " and " + pageSize + " >= rnum";}@Overridepublic String listGroupKeyMd5ByPageFetchRows(int startRow, int pageSize) {return "SELECT t.id,data_id,group_id,tenant_id,app_name,md5,type,gmt_modified,encrypted_data_key FROM "+ "(SELECT * FROM ( SELECT id, ROWNUM as rnum FROM config_info ORDER BY id) "+ " WHERE  rnum >= " + startRow + " and " + pageSize + " >= rnum "+ " ) g, config_info t WHERE g.id = t.id";}@Overridepublic String findAllConfigInfo4Export(List<Long> ids, Map<String, String> params) {String tenant = params.get("tenant");String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;String sql ="SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_create,gmt_modified,src_user,src_ip,"+ "c_desc,c_use,effect,c_schema,encrypted_data_key FROM config_info";StringBuilder where = new StringBuilder(" WHERE ");List<Object> paramList = new ArrayList<>();if (!CollectionUtils.isEmpty(ids)) {where.append(" id IN (");for (int i = 0; i < ids.size(); i++) {if (i != 0) {where.append(", ");}where.append('?');paramList.add(ids.get(i));}where.append(") ");} else {where.append(" tenant_id= ? ");paramList.add(tenantTmp);if (!StringUtils.isBlank(params.get(DATA_ID))) {where.append(" AND data_id LIKE ? ");}if (StringUtils.isNotBlank(params.get(GROUP))) {where.append(" AND group_id= ? ");}if (StringUtils.isNotBlank(params.get(APP_NAME))) {where.append(" AND app_name= ? ");}}return sql + where;}@Overridepublic String findConfigInfoBaseLikeCountRows(Map<String, String> params) {final String sqlCountRows = "SELECT count(*) FROM config_info WHERE ";String where = " 1=1 AND tenant_id='' ";if (!StringUtils.isBlank(params.get(DATA_ID))) {where += " AND data_id LIKE ? ";}if (!StringUtils.isBlank(params.get(GROUP))) {where += " AND group_id LIKE ";}if (!StringUtils.isBlank(params.get(CONTENT))) {where += " AND content LIKE ? ";}return sqlCountRows + where;}@Overridepublic String findConfigInfoBaseLikeFetchRows(Map<String, String> params, int startRow, int pageSize) {final String sqlFetchRows = "SELECT * FROM (SELECT id,data_id,group_id,tenant_id,content, ROWNUM as rnum FROM config_info WHERE ";String where = " 1=1 AND tenant_id='' ";if (!StringUtils.isBlank(params.get(DATA_ID))) {where += " AND data_id LIKE ? ";}if (!StringUtils.isBlank(params.get(GROUP))) {where += " AND group_id LIKE ";}if (!StringUtils.isBlank(params.get(CONTENT))) {where += " AND content LIKE ? ";}return sqlFetchRows + where + ") " + " WHERE  rnum >= " + startRow + " and " + pageSize + " >= rnum ";}@Overridepublic String findConfigInfo4PageCountRows(Map<String, String> params) {final String appName = params.get(APP_NAME);final String dataId = params.get(DATA_ID);final String group = params.get(GROUP);final String sqlCount = "SELECT count(*) FROM config_info";StringBuilder where = new StringBuilder(" WHERE ");where.append(" tenant_id=? ");if (StringUtils.isNotBlank(dataId)) {where.append(" AND data_id=? ");}if (StringUtils.isNotBlank(group)) {where.append(" AND group_id=? ");}if (StringUtils.isNotBlank(appName)) {where.append(" AND app_name=? ");}return sqlCount + where;}@Overridepublic String findConfigInfo4PageFetchRows(Map<String, String> params, int startRow, int pageSize) {final String appName = params.get(APP_NAME);final String dataId = params.get(DATA_ID);final String group = params.get(GROUP);final String sql = "SELECT * FROM (SELECT id,data_id,group_id,tenant_id,app_name,content,type,encrypted_data_key,"+ " ROWNUM as rnum FROM config_info";StringBuilder where = new StringBuilder(" WHERE ");where.append(" tenant_id=? ");if (StringUtils.isNotBlank(dataId)) {where.append(" AND data_id=? ");}if (StringUtils.isNotBlank(group)) {where.append(" AND group_id=? ");}if (StringUtils.isNotBlank(appName)) {where.append(" AND app_name=? ");}return sql + where + ")  " + " WHERE  rnum >= " + startRow + " and " + pageSize + " >= rnum ";}@Overridepublic String findConfigInfoBaseByGroupFetchRows(int startRow, int pageSize) {return "SELECT * FROM (SELECT id,data_id,group_id,content, ROWNUM as rnum FROM config_info WHERE group_id=? AND tenant_id=?" + ")  "+ " WHERE  rnum >= " + startRow + " and " + pageSize + " >= rnum ";}@Overridepublic String findConfigInfoLike4PageCountRows(Map<String, String> params) {String dataId = params.get(DATA_ID);String group = params.get(GROUP);final String appName = params.get(APP_NAME);final String content = params.get(CONTENT);final String sqlCountRows = "SELECT count(*) FROM config_info";StringBuilder where = new StringBuilder(" WHERE ");where.append(" tenant_id LIKE ? ");if (!StringUtils.isBlank(dataId)) {where.append(" AND data_id LIKE ? ");}if (!StringUtils.isBlank(group)) {where.append(" AND group_id LIKE ? ");}if (!StringUtils.isBlank(appName)) {where.append(" AND app_name = ? ");}if (!StringUtils.isBlank(content)) {where.append(" AND content LIKE ? ");}return sqlCountRows + where;}@Overridepublic String findConfigInfoLike4PageFetchRows(Map<String, String> params, int startRow, int pageSize) {String dataId = params.get(DATA_ID);String group = params.get(GROUP);final String appName = params.get(APP_NAME);final String content = params.get(CONTENT);final String sqlFetchRows = "SELECT * FROM (SELECT id,data_id,group_id,tenant_id,app_name,content,encrypted_data_key,"+ " ROWNUM as rnum FROM config_info";StringBuilder where = new StringBuilder(" WHERE ");where.append(" tenant_id LIKE ? ");if (!StringUtils.isBlank(dataId)) {where.append(" AND data_id LIKE ? ");}if (!StringUtils.isBlank(group)) {where.append(" AND group_id LIKE ? ");}if (!StringUtils.isBlank(appName)) {where.append(" AND app_name = ? ");}if (!StringUtils.isBlank(content)) {where.append(" AND content LIKE ? ");}return sqlFetchRows + where + " ) " + " WHERE  rnum >= " + startRow + " and " + pageSize + " >= rnum ";}@Overridepublic String findAllConfigInfoFetchRows(int startRow, int pageSize) {return "SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5 "+ " FROM (SELECT * FROM (  SELECT id, ROWNUM as rnum FROM config_info WHERE tenant_id LIKE ? ORDER BY id)"+ " WHERE  rnum >= " + startRow + " and " + pageSize + " >= rnum)"+ " g, config_info t  WHERE g.id = t.id ";}@Overridepublic String findConfigInfosByIds(int idSize) {StringBuilder sql = new StringBuilder("SELECT ID,data_id,group_id,tenant_id,app_name,content,md5 FROM config_info WHERE ");sql.append("id IN (");for (int i = 0; i < idSize; i++) {if (i != 0) {sql.append(", ");}sql.append('?');}sql.append(") ");return sql.toString();}@Overridepublic String removeConfigInfoByIdsAtomic(int size) {StringBuilder sql = new StringBuilder("DELETE FROM config_info WHERE ");sql.append("id IN (");for (int i = 0; i < size; i++) {if (i != 0) {sql.append(", ");}sql.append('?');}sql.append(") ");return sql.toString();}@Overridepublic String getTableName() {return TableConstant.CONFIG_INFO;}@Overridepublic String getDataSource() {return DataSourceConstant.ORCLE;}@Overridepublic String updateConfigInfoAtomicCas() {return "UPDATE config_info SET "+ "content=?, md5 = ?, src_ip=?,src_user=?,gmt_modified=?, app_name=?,c_desc=?,c_use=?,effect=?,type=?,c_schema=? "+ "WHERE data_id=? AND group_id=? AND tenant_id=? AND (md5=? OR md5 IS NULL OR md5='')";}
}

4.ConfigInfoTagMapperByOracle

/** Copyright 1999-2022 Alibaba Group Holding Ltd.** 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.alibaba.nacos.plugin.datasource.impl.oracle;import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoTagMapper;/*** The mysql implementation of ConfigInfoTagMapper.** @author hyx**/public class ConfigInfoTagMapperByOracle extends AbstractMapper implements ConfigInfoTagMapper {@Overridepublic String updateConfigInfo4TagCas() {return "UPDATE config_info_tag SET content = ?, md5 = ?, src_ip = ?,src_user = ?,gmt_modified = ?,app_name = ? "+ "WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND tag_id = ? AND (md5 = ? OR md5 IS NULL OR md5 = '')";}@Overridepublic String findAllConfigInfoTagForDumpAllFetchRows(int startRow, int pageSize) {return " SELECT t.id,data_id,group_id,tenant_id,tag_id,app_name,content,md5,gmt_modified "+ " FROM ( SELECT * FROM ( SELECT id, ROWNUM as rnum FROM config_info_tag  ORDER BY id) "+ " WHERE  rnum >= " + startRow + " and " + pageSize + " >= rnum ) "+ "g, config_info_tag t  WHERE g.id = t.id  ";}@Overridepublic String getTableName() {return TableConstant.CONFIG_INFO_TAG;}@Overridepublic String getDataSource() {return DataSourceConstant.ORCLE;}
}

5.ConfigTagsRelationMapperByOracle

/** Copyright 1999-2022 Alibaba Group Holding Ltd.** 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.alibaba.nacos.plugin.datasource.impl.oracle;import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigTagsRelationMapper;import java.util.Map;/*** The mysql implementation of ConfigTagsRelationMapper.** @author hyx**/public class ConfigTagsRelationMapperByOracle extends AbstractMapper implements ConfigTagsRelationMapper {@Overridepublic String findConfigInfo4PageCountRows(final Map<String, String> params, final int tagSize) {final String appName = params.get("appName");final String dataId = params.get("dataId");final String group = params.get("group");StringBuilder where = new StringBuilder(" WHERE ");final String sqlCount = "SELECT count(*) FROM config_info  a LEFT JOIN config_tags_relation b ON a.id=b.id";where.append(" a.tenant_id=? ");if (StringUtils.isNotBlank(dataId)) {where.append(" AND a.data_id=? ");}if (StringUtils.isNotBlank(group)) {where.append(" AND a.group_id=? ");}if (StringUtils.isNotBlank(appName)) {where.append(" AND a.app_name=? ");}where.append(" AND b.tag_name IN (");for (int i = 0; i < tagSize; i++) {if (i != 0) {where.append(", ");}where.append('?');}where.append(") ");return sqlCount + where;}@Overridepublic String findConfigInfo4PageFetchRows(Map<String, String> params, int tagSize, int startRow, int pageSize) {final String appName = params.get("appName");final String dataId = params.get("dataId");final String group = params.get("group");StringBuilder where = new StringBuilder(" WHERE ");final String sql ="SELECT * FROM (SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content, ROWNUM as rnum FROM config_info  a LEFT JOIN "+ "config_tags_relation b ON a.id=b.id";where.append(" a.tenant_id=? ");if (StringUtils.isNotBlank(dataId)) {where.append(" AND a.data_id=? ");}if (StringUtils.isNotBlank(group)) {where.append(" AND a.group_id=? ");}if (StringUtils.isNotBlank(appName)) {where.append(" AND a.app_name=? ");}where.append(" AND b.tag_name IN (");for (int i = 0; i < tagSize; i++) {if (i != 0) {where.append(", ");}where.append('?');}where.append(") ");return sql + where + ")" + " WHERE  rnum >= " + startRow + " and " + pageSize + " >= rnum ";}@Overridepublic String findConfigInfoLike4PageCountRows(final Map<String, String> params, int tagSize) {final String appName = params.get("appName");final String content = params.get("content");final String dataId = params.get("dataId");final String group = params.get("group");StringBuilder where = new StringBuilder(" WHERE ");final String sqlCountRows = "SELECT count(*) FROM config_info  a LEFT JOIN config_tags_relation b ON a.id=b.id ";where.append(" a.tenant_id LIKE ? ");if (!StringUtils.isBlank(dataId)) {where.append(" AND a.data_id LIKE ? ");}if (!StringUtils.isBlank(group)) {where.append(" AND a.group_id LIKE ? ");}if (!StringUtils.isBlank(appName)) {where.append(" AND a.app_name = ? ");}if (!StringUtils.isBlank(content)) {where.append(" AND a.content LIKE ? ");}where.append(" AND b.tag_name IN (");for (int i = 0; i < tagSize; i++) {if (i != 0) {where.append(", ");}where.append('?');}where.append(") ");return sqlCountRows + where;}@Overridepublic String findConfigInfoLike4PageFetchRows(final Map<String, String> params, int tagSize, int startRow,int pageSize) {final String appName = params.get("appName");final String content = params.get("content");final String dataId = params.get("dataId");final String group = params.get("group");StringBuilder where = new StringBuilder(" WHERE ");final String sqlFetchRows = "SELECT * FROM (SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content, ROWNUM as rnum "+ "FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id ";where.append(" a.tenant_id LIKE ? ");if (!StringUtils.isBlank(dataId)) {where.append(" AND a.data_id LIKE ? ");}if (!StringUtils.isBlank(group)) {where.append(" AND a.group_id LIKE ? ");}if (!StringUtils.isBlank(appName)) {where.append(" AND a.app_name = ? ");}if (!StringUtils.isBlank(content)) {where.append(" AND a.content LIKE ? ");}where.append(" AND b.tag_name IN (");for (int i = 0; i < tagSize; i++) {if (i != 0) {where.append(", ");}where.append('?');}where.append(") ");return sqlFetchRows + where + ") " + " WHERE  rnum >= " + startRow + " and " + pageSize + " >= rnum ";}@Overridepublic String getTableName() {return TableConstant.CONFIG_TAGS_RELATION;}@Overridepublic String getDataSource() {return DataSourceConstant.ORCLE;}
}

6.GroupCapacityMapperByOracle

/** Copyright 1999-2022 Alibaba Group Holding Ltd.** 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.alibaba.nacos.plugin.datasource.impl.oracle;import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.GroupCapacityMapper;/*** The derby implementation of {@link GroupCapacityMapper}.** @author lixiaoshuang*/
public class GroupCapacityMapperByOracle extends AbstractMapper implements GroupCapacityMapper {@Overridepublic String getTableName() {return TableConstant.GROUP_CAPACITY;}@Overridepublic String getDataSource() {return DataSourceConstant.ORCLE;}@Overridepublic String insertIntoSelect() {return "INSERT INTO group_capacity (group_id, quota, `usage`, `max_size`, max_aggr_count, max_aggr_size,gmt_create,"+ " gmt_modified) SELECT ?, ?, count(*), ?, ?, ?, ?, ? FROM config_info";}@Overridepublic String insertIntoSelectByWhere() {return "INSERT INTO group_capacity (group_id, quota,`usage`, `max_size`, max_aggr_count, max_aggr_size, gmt_create,"+ " gmt_modified) SELECT ?, ?, count(*), ?, ?, ?, ?, ? FROM config_info WHERE group_id=? AND tenant_id = ''";}@Overridepublic String incrementUsageByWhereQuotaEqualZero() {return "UPDATE group_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE group_id = ? AND `usage` < ? AND quota = 0";}@Overridepublic String incrementUsageByWhereQuotaNotEqualZero() {return "UPDATE group_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE group_id = ? AND `usage` < quota AND quota != 0";}@Overridepublic String incrementUsageByWhere() {return "UPDATE group_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE group_id = ?";}@Overridepublic String decrementUsageByWhere() {return "UPDATE group_capacity SET `usage` = `usage` - 1, gmt_modified = ? WHERE group_id = ? AND `usage` > 0";}@Overridepublic String updateUsage() {return "UPDATE group_capacity SET `usage` = (SELECT count(*) FROM config_info), gmt_modified = ? WHERE group_id = ?";}@Overridepublic String updateUsageByWhere() {return "UPDATE group_capacity SET `usage` = (SELECT count(*) FROM config_info WHERE group_id=? AND tenant_id = ''),"+ " gmt_modified = ? WHERE group_id= ?";}@Overridepublic String selectGroupInfoBySize() {return "SELECT id, group_id FROM group_capacity WHERE id > ? LIMIT ?";}
}

7.HistoryConfigInfoMapperByOracle

/** Copyright 1999-2022 Alibaba Group Holding Ltd.** 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.alibaba.nacos.plugin.datasource.impl.oracle;import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.HistoryConfigInfoMapper;/*** The mysql implementation of HistoryConfigInfoMapper.** @author hyx**/public class HistoryConfigInfoMapperByOracle extends AbstractMapper implements HistoryConfigInfoMapper {@Overridepublic String removeConfigHistory() {return "DELETE FROM his_config_info WHERE gmt_modified < ? LIMIT ?";}@Overridepublic String findConfigHistoryCountByTime() {return "SELECT count(*) FROM his_config_info WHERE gmt_modified < ?";}@Overridepublic String findDeletedConfig() {return "SELECT DISTINCT data_id, group_id, tenant_id FROM his_config_info WHERE op_type = 'D' AND gmt_modified >= ? AND gmt_modified <= ?";}@Overridepublic String findConfigHistoryFetchRows() {return "SELECT nid,data_id,group_id,tenant_id,app_name,src_ip,src_user,op_type,gmt_create,gmt_modified FROM his_config_info "+ "WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY nid DESC";}@Overridepublic String detailPreviousConfigHistory() {return "SELECT nid,data_id,group_id,tenant_id,app_name,content,md5,src_user,src_ip,op_type,gmt_create,gmt_modified "+ "FROM his_config_info WHERE nid = (SELECT max(nid) FROM his_config_info WHERE id = ?) ";}@Overridepublic String getTableName() {return TableConstant.HIS_CONFIG_INFO;}@Overridepublic String getDataSource() {return DataSourceConstant.ORCLE;}
}

8.TenantCapacityMapperByOracle

/** Copyright 1999-2022 Alibaba Group Holding Ltd.** 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.alibaba.nacos.plugin.datasource.impl.oracle;import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.TenantCapacityMapper;/*** The mysql implementation of TenantCapacityMapper.** @author hyx**/public class TenantCapacityMapperByOracle extends AbstractMapper implements TenantCapacityMapper {@Overridepublic String getTableName() {return TableConstant.TENANT_CAPACITY;}@Overridepublic String getDataSource() {return DataSourceConstant.ORCLE;}@Overridepublic String incrementUsageWithDefaultQuotaLimit() {return "UPDATE tenant_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE tenant_id = ? AND `usage` <"+ " ? AND quota = 0";}@Overridepublic String incrementUsageWithQuotaLimit() {return "UPDATE tenant_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE tenant_id = ? AND `usage` < "+ "quota AND quota != 0";}@Overridepublic String incrementUsage() {return "UPDATE tenant_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE tenant_id = ?";}@Overridepublic String decrementUsage() {return "UPDATE tenant_capacity SET `usage` = `usage` - 1, gmt_modified = ? WHERE tenant_id = ? AND `usage` > 0";}@Overridepublic String correctUsage() {return "UPDATE tenant_capacity SET `usage` = (SELECT count(*) FROM config_info WHERE tenant_id = ?), "+ "gmt_modified = ? WHERE tenant_id = ?";}@Overridepublic String getCapacityList4CorrectUsage() {return "SELECT id, tenant_id FROM tenant_capacity WHERE id>? LIMIT ?";}@Overridepublic String insertTenantCapacity() {return "INSERT INTO tenant_capacity (tenant_id, quota, `usage`, `max_size`, max_aggr_count, max_aggr_size, "+ "gmt_create, gmt_modified) SELECT ?, ?, count(*), ?, ?, ?, ?, ? FROM config_info WHERE tenant_id=?;";}
}

9.TenantInfoMapperByOracle

/** Copyright 1999-2022 Alibaba Group Holding Ltd.** 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.alibaba.nacos.plugin.datasource.impl.oracle;import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.TenantInfoMapper;/*** The mysql implementation of TenantInfoMapper.** @author hyx**/public class TenantInfoMapperByOracle extends AbstractMapper implements TenantInfoMapper {@Overridepublic String getTableName() {return TableConstant.TENANT_INFO;}@Overridepublic String getDataSource() {return DataSourceConstant.ORCLE;}
}

2.4.3 com.alibaba.nacos.plugin.datasource.mapper.Mapper修改

修改类:plugin/datasource/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.mapper.Mapper

#
# Copyright 1999-2022 Alibaba Group Holding Ltd.
#
# 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.
#com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoAggrMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoBetaMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoTagMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigTagsRelationMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.HistoryConfigInfoMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.TenantInfoMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.TenantCapacityMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.GroupCapacityMapperByMysqlcom.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoAggrMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoBetaMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoTagMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoTagsRelationMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.HistoryConfigInfoMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.TenantInfoMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.TenantCapacityMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.GroupCapacityMapperByDerbycom.alibaba.nacos.plugin.datasource.impl.oracle.ConfigInfoAggrMapperByOracle
com.alibaba.nacos.plugin.datasource.impl.oracle.ConfigInfoBetaMapperByOracle
com.alibaba.nacos.plugin.datasource.impl.oracle.ConfigInfoMapperByOracle
com.alibaba.nacos.plugin.datasource.impl.oracle.ConfigInfoTagMapperByOracle
com.alibaba.nacos.plugin.datasource.impl.oracle.ConfigTagsRelationMapperByOracle
com.alibaba.nacos.plugin.datasource.impl.oracle.HistoryConfigInfoMapperByOracle
com.alibaba.nacos.plugin.datasource.impl.oracle.TenantInfoMapperByOracle
com.alibaba.nacos.plugin.datasource.impl.oracle.TenantCapacityMapperByOracle
com.alibaba.nacos.plugin.datasource.impl.oracle.GroupCapacityMapperByOracle

2.5 nacos-console模块修改

修改配置文件:console/src/main/resources/application.properties
只修改一部分,数据源连接信息,截图如下:
在这里插入图片描述

nacos.plugin.datasource.log.enabled=true
spring.sql.init.platform=oracle
### Count of DB:
db.num=1### Connect URL of DB:
db.url.0=jdbc:oracle:thin:@192.168.10.2:1521/xe
db.user.0=nacos220
db.password.0=123456
db.jdbcDriverName=oracle.jdbc.OracleDriver
db.testQuery=select 1 from dual

2.6 Nacos2.2.0适配Oracle12C-建表ddl语句

Nacos2.2.0适配Oracle12C-建表ddl语句

2.7 打包

在nacos-all目录下执行mvn命令
mvn -Prelease-nacos -Dmaven.test.skip=true -Dpmd.skip=true -Drat.skip=true -Dcheckstyle.skip=true clean install -U
最后在distributioni目录下的target就会出现压缩文件了,这样就相当于从nacos官网直接下载的压缩包,具体nacos配置可以自行完成。
在这里插入图片描述


总结

以上就是Nacos2.2.0多数据源适配oracle12C-修改Nacos源码的步骤


曾经淋过雨,希望大家都有伞!

相关文章:

Nacos2.2.0多数据源适配oracle12C-修改Nacos源码

从2.2.0版本开始,可通过SPI机制注入多数据源实现插件,并在引入对应数据源实现后,便可在Nacos启动时通过读取application.properties配置文件中spring.datasource.platform配置项选择加载对应多数据源插件.本文档详细介绍一个多数据源插件如何实现以及如何使其生效。 文章目录一…...

第十四届蓝桥杯三月真题刷题训练——第 5 天

目录 题目1&#xff1a;数的分解 题目描述 运行限制 代码&#xff1a; 题目2&#xff1a;猜生日 题目描述 运行限制 代码&#xff1a; 题目3&#xff1a;成绩分析 题目描述 输入描述 输出描述 输入输出样例 运行限制 代码&#xff1a; 题目4&#xff1a;最大和…...

大数据框架之Hive:第3章 DDL(Data Definition Language)数据定义

第3章 DDL&#xff08;Data Definition Language&#xff09;数据定义 3.1 数据库&#xff08;database&#xff09; 3.1.1 创建数据库 1&#xff09;语法 CREATE DATABASE [IF NOT EXISTS] database_name [COMMENT database_comment] [LOCATION hdfs_path] [WITH DBPROPER…...

概率论小课堂:统计学是大数据方法的基础

文章目录 引言I 统计学1.1 统计学的内容1.2 统计学的目的II 用好数据的五个步骤2.1 设立研究目标2.2 设计实验,选取数据。2.3 根据实验方案进行统计和实验,分析方差。2.4 通过分析进一步了解数据,提出新假说。2.5 使用研究结果III 数据没用好的原因3.1 霍桑效应3.2 数据的稀…...

监控集群概念讲解

监控概述 1、监控的重要性 监控是运维日常的重要工作之一&#xff1b; 监控是有多重要&#xff1f; 监控可以帮助运维监控服务器的状态&#xff1b;要及时解决&#xff1b; 如果淘宝、腾讯宕机了1个小时&#xff1f; 损失是无法估量的&#xff1b; 服务器是否故障、宕不…...

如何通过DAS连接GaussDB

文章目录1 实验介绍2 实验目的3 配置DAS服务4 SQL使用入门1 实验介绍 本实验主要描述如何通过华为云数据管理服务 (Data Admin Service&#xff0c;简称DAS) 来连接华为云GaussDB数据库实例&#xff0c;DAS是一款专业的简化数据库管理工具&#xff0c;提供优质的可视化操作界面…...

支持在局域网使用的项目管理系统有哪些?5款软件对比

一、选择私有部署的原因以及该方案的优点有很多可能的原因导致人们更倾向于使用私有部署的企业管理软件&#xff0c;其中一些原因可能包括&#xff1a;1.数据安全性要求&#xff1a;一些企业管理软件包含敏感的商业数据和隐私信息&#xff0c;为了保护这些信息不被未经授权的第…...

Linux CentOS7 MySQL 5.7安装

准备工作 //创建目录 mkdir /opt/mysql //跳转目录 cd /opt/mysql下载MySQL 请耐心等待&#xff0c;也可以在Windows下载以后上传到 /opt/mysql目录 wget http://dev.mysql.com/get/mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar解压 tar -xvf mysql-5.7.26-1.el7.x86_64.rpm-b…...

Kubernetes学习(四)控制器

ReplicaSet ReplicaSet的目的是维护一组在任何时候都处于运行状态的Pod副本的稳定集合。因此&#xff0c;它通常用来保证给定数量的、完全相同的Pod的可用性。 ReplicaSet的工作原理 ReplicaSet是通过一组字段来定义的&#xff0c;包括一个用来识别可获得的pod的集合的选择符…...

vue组件间通信的几个方法

一&#xff0c;props属性传递数据 适用场景&#xff1a;父组件传递数据给子组件 子组件设置props属性&#xff0c;定义接收父组件传递过来的参数 父组件在使用子组件标签中通过字面量来传递值 Children.vue props:{ // 字符串形式 name:String // 接收的类型参数 // 对象…...

商品价格区间设置与排序--课后程序(Python程序开发案例教程-黑马程序员编著-第4章-课后作业)

实例2&#xff1a;商品价格区间设置与排序 在网上购物时&#xff0c;面对琳琅满目的商品&#xff0c;我们应该如何快速选择适合自己的商品呢&#xff1f;为了能够让用户快速地定位到适合自己的商品&#xff0c;每个电商购物平台都提供价格排序与设置价格区间功能。假设现在某平…...

mybatis中sqlSession的使用

文章目录sqlsession的使用依赖jdbc.propertiesmysql-config.xml配置逆向工程创建sqlSessionsqlsession的使用 在最开始我们使用jdbcUtil的方式进行硬编码&#xff0c;sql字符串写的很难受&#xff0c;使用mybatis可以解决这个问题&#xff0c;它提供了数据库与实体类的关系映射…...

TPOT(Tree-based Pipeline Optimization Tool) API简介

文章目录TPOT简介TPOT APIClassification接口形式&#xff1a;Parameters&#xff1a;Attributes:Functions&#xff1a;Regression接口形式Parameters:&#xff08;只列与分类任务有差异的参数&#xff09;TPOT简介 TPOT是一个Python自动机器学习&#xff08;AML&#xff09;…...

Java 19和IntelliJ IDEA,如何和谐共生?

Java仍然是目前比较流行的编程语言&#xff0c;它更短的发布节奏让开发者每六个月左右就可以试用新的语言或平台功能&#xff0c;IntelliJ IDEA帮助我们更流畅地发现和使用这些新功能。IntelliJ IDEA v2022.3正式版下载(Q技术交流&#xff1a;786598704&#xff09;在本文中&am…...

js循环判断的方法

js循环判断的方法if语句if else语句if else if else if......三元表达式switchswitch语句和if语句的区别for循环while循环do while循环for inforEachfor of性能问题if语句 条件满足就执行&#xff0c;不满足就不执行 if(条件){语句}if else语句 条件满足&#xff0c;执行语句…...

git快速入门(1)

1 git的下载与安装1&#xff09;下载git安装包下载路径&#xff1a;https://git-scm.com/我的操作系统是window&#xff0c;64位的&#xff0c;我下载的Git-2.33.0-64-bit.exe&#xff0c;从官网下载或者从网址下载链接&#xff1a;链接地址&#xff1a;https://pan.baidu.com/…...

韩国绿芯1~16通道触摸芯片型号推荐

随着技术的发展&#xff0c;触摸感应技术正日益受到更多关注和应用&#xff0c;目前实现触摸感应的方式主要有两种&#xff0c;一种是电阻式&#xff0c;另一种是电容式。电容式触摸具有感应灵敏、功耗低、寿命长等特点&#xff0c;因此逐步取代电阻式触摸&#xff0c;成为当前…...

Go语言设计与实现 -- http服务器编程

Go http服务器编程 初始 http 是典型的 C/S 架构&#xff0c;客户端向服务端发送请求&#xff08;request&#xff09;&#xff0c;服务端做出应答&#xff08;response&#xff09;。 golang 的标准库 net/http 提供了 http 编程有关的接口&#xff0c;封装了内部TCP连接和…...

MySQL-视图

视图是什么&#xff1f; 一张虚表&#xff0c;和真实的表一样。视图包含一系列带有名称的行和列数据。视图是从一个或多个表中导出来的&#xff0c;我们可以通过insert&#xff0c;update&#xff0c;delete来操作视图。当通过视图看到的数据被修改时&#xff0c;相应的原表的数…...

都工作3年了,怎么能不懂双亲委派呢?(带你手把手断点源码)

&#x1f497;推荐阅读文章&#x1f497; &#x1f338;JavaSE系列&#x1f338;&#x1f449;1️⃣《JavaSE系列教程》&#x1f33a;MySQL系列&#x1f33a;&#x1f449;2️⃣《MySQL系列教程》&#x1f340;JavaWeb系列&#x1f340;&#x1f449;3️⃣《JavaWeb系列教程》…...

Hive 运行环境搭建

文章目录Hive 运行环境搭建一、Hive 安装部署1、安装hive2、MySQL 安装3、Hive 元数据配置到 Mysql1) 拷贝驱动2) 配置Metastore 到 MySQL3) 再次启动Hive4) 使用元数据服务的方式访问Hive二、使用Dbaver连接HiveHive 运行环境搭建 HIve 下载地址&#xff1a;http://archive.a…...

SAP ABAP 深度解析Smartform打印特殊符号等功能

ABAP 开发人员可以在 Smartform 输出上显示 SAP 图标或 SAP 符号。例如,需要在 SAP Smart Forms 文档上显示复选框形状的输出。SAP Smartform 文档上可以轻松显示空复选框、标记复选框以及 SAP 图标等特殊符号。 在 SAP Smartform 文档中添加一个新的文本节点。 1. 单击“更…...

React17+React Hook+TS4 最佳实践仿 Jira 企业级项目笔记

前言 个人笔记,记录个人过程,如有不对,敬请指出React17React HookTS4 最佳实践仿 Jira 企业级项目项目完成到第十章,剩下后面就没有看了,说的不是特别好 github地址:https://github.com/superBiuBiuMan/React-jira husky方便我们管理git hooks的工具 REST-API风格 https://zh…...

35- tensorboard的使用 (PyTorch系列) (深度学习)

知识要点 FashionMNIST数据集: 十种产品的分类. # T-shirt/top, Trouser, Pullover, Dress, Coat,Sandal, Shirt, Sneaker, Bag, Ankle Boot.writer SummaryWriter(run/fashion_mnist_experiment_1) # 网站显示一 tensorboard的使用 在网站显示pytorch的架构:1.1 …...

ChatGPT在工业领域的用法

在工业数字化时代&#xff0c;我们需要怎么样的ChatGPT&#xff1f; 近日&#xff0c;ChatGPT热度高居不下&#xff0c;强大的人机交互能力令人咋舌&#xff0c;在国内更是掀起一股讨论热潮。一时间&#xff0c;这场由ChatGPT引起的科技飓风&#xff0c;使得全球最顶尖科技力量…...

使用Chakra-UI封装简书的登录页面组件(React)

要求&#xff1a;使用chakra ui和react 框架将简书的登录页面的表单封装成独立的可重用的组件使用到的API&#xff1a;注册API请求方式&#xff1a;POST 请求地址&#xff1a;https://conduit.productionready.io/api/users请求数据: {"user":{ "username&quo…...

Three.js初试——基础概念(二)

前言 姊妹篇&#xff1a;Three.js初试——基础概念 介绍了 Three.js 的一些核心要素概念&#xff0c;这篇文章会讲一下它的关键要素概念。 之前我们了解到展示一个3D图像&#xff0c;必须要有场景、相机、渲染器这些核心要素&#xff0c;仅仅这些还不够&#xff0c;我们还需要…...

Qt音视频开发21-mpv内核万能属性机制

一、前言 搞过vlc内核后又顺带搞了搞mpv内核&#xff0c;mpv相比vlc&#xff0c;在文件数量、sdk开发便捷性方面绝对占优势的&#xff0c;单文件&#xff08;可能是静态编译&#xff09;&#xff0c;不像vlc带了一堆插件&#xff0c;通过各种属性来set和get值&#xff0c;后面…...

C语言学生随机抽号演讲计分系统

6.学生随机抽号演讲计分系统&#xff08;★★★★) 设计一款用于课程大作业检查或比赛计分的软件&#xff0c;基本功能: (1)设置本课程的学生总数 (2)根据本次参与的学生总数&#xff0c;随机抽取一个还未汇报演讲的学生的学号。 (3)每个学生汇报演讲完毕&#xff0c;输入该学生…...

Spring Boot 3.0系列【12】核心特性篇之任务调度

有道无术,术尚可求,有术无道,止于术。 本系列Spring Boot版本3.0.3 源码地址:https://gitee.com/pearl-organization/study-spring-boot3 文章目录 前言Spring Scheduler1. 单线程任务2. 自动配置3. 多线程异步任务Quartz1. 简介2. 核心组件2.1 Job(任务)2.2 Trigger(…...

html5设计网页代码/深圳网站优化网站

经典知识库&#xff1a;MGR原理介绍与案例分享-9月2日20:00MySQL推出MGR之前&#xff0c;传统复制分为两种&#xff1a;异步复制、半同步复制 &#xff1b;随着应用对数据库的高可用要求越来越高&#xff0c;MySQL MGR应运而生。MySQL MGR作为一种全新的高可用、高扩展架构的解…...

网站的ci设计怎么做/沈阳网站建设公司

20145308 20145302 《信息安全系统设计基础》实验二 固件设计 北京电子科技学院&#xff08;BESTI&#xff09; 实 验 报 告 课程&#xff1a; 深入理解计算机系统 班级&#xff1a; 1453 姓名&#xff1a; &#xff08;按贡献程度大小排名&#xff09;刘昊阳 张薇 学号&#x…...

手机端网站需要多少钱/google seo整站优化

游戏中的数学&#xff0c;数学中的游戏手持锥顶球&#xff0c;围坐赛棋楼。三人分同组&#xff0c;出手需轮流。两人赛一次&#xff0c;全员不重丢。棋手若干个&#xff0c;重奖授鳌头。五七人能否&#xff1f;构造明理由。通俗地讲就是如下所述的构造论证问题。把m名棋手分n组…...

网站制作外包公司/抖音seo排名

译者 | HelloGitHub-小鱼干、鸭鸭来源 | HelloGitHub(ID&#xff1a;GitHub520)头图 | CSDN 下载自东方IC虽然本质上 API 就是拿来用的&#xff0c;但即便某个 API 的使用者全是内部人员&#xff0c;它还是可能会出现安全问题。为了解决 API 安全问题&#xff0c;在本文我们收集…...

个人网站icp备案教程/文案写作软件app

终于可以从百度云上BOS读取数据到本地了转载于:https://www.cnblogs.com/geili/p/10235390.html...

广州网络营销选择/赣州seo顾问

Linux Kernel snd_seq_write()函数本地缓冲区溢出漏洞(CVE-2018-7566)发布日期&#xff1a;2018-03-27更新日期&#xff1a;2018-04-11受影响系统&#xff1a;Linux kernel 4.15描述&#xff1a;BUGTRAQ ID: 103605CVE(CAN) ID: CVE-2018-7566Linux Kernel是Linux操作系统的内…...