Merge remote-tracking branch 'origin/feature/1.6.1' into feature/1.6.1
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
"scripts": {
|
||||
"local": "webpack-dev-server --inline --progress --config build/webpack.local.conf.js",
|
||||
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
|
||||
"build:local": "cross-env NODE_ENV=dev env_config=local node build/build.js",
|
||||
"build:dev": "cross-env NODE_ENV=dev env_config=dev node build/build.js",
|
||||
"build:prod": "cross-env NODE_ENV=production env_config=prod node build/build.js",
|
||||
"build:sit": "cross-env NODE_ENV=production env_config=sit node build/build.js",
|
||||
|
||||
+7
-7
@@ -26,7 +26,7 @@ import com.google.common.collect.Lists;
|
||||
import fun.asgc.neutrino.core.annotation.PreLoad;
|
||||
import fun.asgc.neutrino.core.db.template.JdbcTemplate;
|
||||
import fun.asgc.neutrino.core.util.*;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.config.SqliteConfig;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.config.DbConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.sql.DriverManager;
|
||||
@@ -41,11 +41,11 @@ import java.util.List;
|
||||
@PreLoad("init")
|
||||
public class DBInitialize {
|
||||
private static List<String> initDataTableNameList = Lists.newArrayList("user", "license", "port_pool", "port_mapping", "job_info");
|
||||
private static SqliteConfig sqliteConfig;
|
||||
private static DbConfig dbConfig;
|
||||
private static JdbcTemplate jdbcTemplate;
|
||||
|
||||
public static void init() throws Exception {
|
||||
sqliteConfig = ConfigUtil.getYmlConfig(SqliteConfig.class);
|
||||
dbConfig = ConfigUtil.getYmlConfig(DbConfig.class);
|
||||
jdbcTemplate = getJdbcTemplate();
|
||||
initDBStructure();
|
||||
initDBData();
|
||||
@@ -116,13 +116,13 @@ public class DBInitialize {
|
||||
() -> null == jdbcTemplate,
|
||||
DBInitialize.class,
|
||||
() -> {
|
||||
Class.forName(sqliteConfig.getDriverClass());
|
||||
Class.forName(dbConfig.getDriverClass());
|
||||
//建立一个数据库名data.db的连接,如果不存在就在当前目录下创建之
|
||||
DriverManager.getConnection(sqliteConfig.getUrl());
|
||||
DriverManager.getConnection(dbConfig.getUrl());
|
||||
// 创建数据源
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
dataSource.setUrl(sqliteConfig.getUrl());
|
||||
dataSource.setDriverClassName(sqliteConfig.getDriverClass());
|
||||
dataSource.setUrl(dbConfig.getUrl());
|
||||
dataSource.setDriverClassName(dbConfig.getDriverClass());
|
||||
// 创建jdbcTemplate
|
||||
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
},
|
||||
|
||||
+9
-2
@@ -24,6 +24,7 @@ package fun.asgc.neutrino.proxy.server.base.rest.config;
|
||||
import fun.asgc.neutrino.core.annotation.Configuration;
|
||||
import fun.asgc.neutrino.core.annotation.NonIntercept;
|
||||
import fun.asgc.neutrino.core.annotation.Value;
|
||||
import fun.asgc.neutrino.proxy.server.constant.DbTypeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@@ -33,8 +34,14 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
@NonIntercept
|
||||
@Configuration(prefix = "neutrino.data.sqlite")
|
||||
public class SqliteConfig {
|
||||
@Configuration(prefix = "neutrino.data.db")
|
||||
public class DbConfig {
|
||||
/**
|
||||
* 数据库类型
|
||||
* {@link DbTypeEnum}
|
||||
*/
|
||||
@Value("type")
|
||||
private String type;
|
||||
/**
|
||||
* 连接url
|
||||
*/
|
||||
+2
-2
@@ -37,12 +37,12 @@ import javax.sql.DataSource;
|
||||
@Component
|
||||
public class RestConfiguration {
|
||||
@Autowired
|
||||
private SqliteConfig sqliteConfig;
|
||||
private DbConfig dbConfig;
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
SQLiteDataSource dataSource = new SQLiteDataSource();
|
||||
dataSource.setUrl(sqliteConfig.getUrl());
|
||||
dataSource.setUrl(dbConfig.getUrl());
|
||||
dataSource.setJournalMode("WAL");
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Copyright (c) 2022 aoshiguchen
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.constant;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 数据库类型美剧
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/11/25
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum DbTypeEnum {
|
||||
SQLITE("sqlite"),
|
||||
MYSQL("mysql");
|
||||
|
||||
private String type;
|
||||
|
||||
private static final Map<String, DbTypeEnum> cache = Stream.of(DbTypeEnum.values()).collect(Collectors.toMap(DbTypeEnum::getType, Function.identity()));
|
||||
|
||||
public static DbTypeEnum of(String type) {
|
||||
return cache.get(type);
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ neutrino:
|
||||
key-manager-password: 123456
|
||||
jks-path: classpath:/test.jks
|
||||
data:
|
||||
sqlite:
|
||||
db:
|
||||
type: sqlite
|
||||
url: jdbc:sqlite:data.db
|
||||
driver-class: org.sqlite.JDBC
|
||||
|
||||
Reference in New Issue
Block a user