mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2025-12-15 20:03:02 +00:00
1. h2数据库文件优化, 取消h2server启动
2. 项目结构优化, pom版本统一管理 3. core的beanutils依赖升级为commons-beanutils2版本, 修复之前版本的安全风险. 4. 此版本打包部署需要替换之前所有依赖
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>netdisk-fast-download</artifactId>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<version>0.1.7</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
<dependency>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>1.0.8</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.qaiu.db.ddl;
|
||||
|
||||
import cn.qaiu.db.pool.JDBCType;
|
||||
import cn.qaiu.vx.core.util.ReflectionUtil;
|
||||
import io.vertx.codegen.format.CamelCase;
|
||||
import io.vertx.codegen.format.Case;
|
||||
@@ -65,7 +66,9 @@ public class CreateTable {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getCreateTableSQL(Class<?> clz) {
|
||||
public static String getCreateTableSQL(Class<?> clz, JDBCType type) {
|
||||
String quotationMarks = type == JDBCType.H2DB ? "\"" : "`";
|
||||
String endStr = type == JDBCType.H2DB ? ");" : ")ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
||||
// 判断类上是否有次注解
|
||||
String primaryKey = null; // 主键
|
||||
String tableName = null; // 表名
|
||||
@@ -93,7 +96,7 @@ public class CreateTable {
|
||||
int[] decimalSize = {22, 2};
|
||||
int varcharSize = 255;
|
||||
StringBuilder sb = new StringBuilder(50);
|
||||
sb.append("CREATE TABLE IF NOT EXISTS \"").append(tableName).append("\" ( \r\n ");
|
||||
sb.append("CREATE TABLE IF NOT EXISTS ").append(quotationMarks).append(tableName).append(quotationMarks).append(" ( \r\n ");
|
||||
boolean firstId = true;
|
||||
for (Field f : fields) {
|
||||
Class<?> paramType = f.getType();
|
||||
@@ -114,7 +117,7 @@ public class CreateTable {
|
||||
decimalSize = fieldAnnotation.decimalSize();
|
||||
varcharSize = fieldAnnotation.varcharSize();
|
||||
}
|
||||
sb.append("\"").append(column).append("\"");
|
||||
sb.append(quotationMarks).append(column).append(quotationMarks);
|
||||
sb.append(" ").append(sqlType);
|
||||
// 添加类型长度
|
||||
if (sqlType.equals("DECIMAL")) {
|
||||
@@ -155,17 +158,20 @@ public class CreateTable {
|
||||
//去掉最后一个逗号
|
||||
int lastIndex = sql.lastIndexOf(",");
|
||||
sql = sql.substring(0, lastIndex) + sql.substring(lastIndex + 1);
|
||||
return sql.substring(0, sql.length() - 1) + ");\r\n";
|
||||
return sql.substring(0, sql.length() - 1) + endStr;
|
||||
}
|
||||
|
||||
public static void createTable(JDBCPool pool) {
|
||||
public static void createTable(JDBCPool pool, JDBCType type) {
|
||||
Set<Class<?>> tableClassList = ReflectionUtil.getReflections().getTypesAnnotatedWith(Table.class);
|
||||
if (tableClassList.isEmpty()) LOGGER.info("Table model class not fount");
|
||||
tableClassList.forEach(clazz -> {
|
||||
String createTableSQL = getCreateTableSQL(clazz);
|
||||
String createTableSQL = getCreateTableSQL(clazz, type);
|
||||
|
||||
pool.query(createTableSQL).execute().onSuccess(
|
||||
rs -> LOGGER.info("\n" + createTableSQL + "create table --> ok")
|
||||
).onFailure(Throwable::printStackTrace);
|
||||
rs -> LOGGER.info("table auto generate:\n" + createTableSQL)
|
||||
).onFailure(e -> {
|
||||
LOGGER.error(e.getMessage() + " SQL: \n" + createTableSQL);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
package cn.qaiu.db.pool;
|
||||
|
||||
import cn.qaiu.db.ddl.CreateTable;
|
||||
import cn.qaiu.db.server.H2ServerHolder;
|
||||
import cn.qaiu.vx.core.util.VertxHolder;
|
||||
import io.vertx.core.Promise;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.jdbcclient.JDBCPool;
|
||||
import org.h2.tools.Server;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* 初始化JDBC
|
||||
* <br>Create date 2021/8/10 12:04
|
||||
@@ -28,12 +21,14 @@ public class JDBCPoolInit {
|
||||
JsonObject dbConfig;
|
||||
Vertx vertx = VertxHolder.getVertxInstance();
|
||||
String url;
|
||||
private JDBCType type;
|
||||
|
||||
private static JDBCPoolInit instance;
|
||||
|
||||
public JDBCPoolInit(Builder builder) {
|
||||
this.dbConfig = builder.dbConfig;
|
||||
this.url = builder.url;
|
||||
this.type = builder.type;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
@@ -47,10 +42,12 @@ public class JDBCPoolInit {
|
||||
public static class Builder {
|
||||
private JsonObject dbConfig;
|
||||
private String url;
|
||||
private JDBCType type;
|
||||
|
||||
public Builder config(JsonObject dbConfig) {
|
||||
this.dbConfig = dbConfig;
|
||||
this.url = dbConfig.getString("jdbcUrl");
|
||||
this.type = JDBCUtil.getJDBCType(dbConfig.getString("driverClassName"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -73,67 +70,16 @@ public class JDBCPoolInit {
|
||||
return;
|
||||
}
|
||||
|
||||
// 异步启动H2服务
|
||||
vertx.createSharedWorkerExecutor("h2-server", 1, Long.MAX_VALUE)
|
||||
.executeBlocking(this::h2serverExecute)
|
||||
.onSuccess(res->{
|
||||
LOGGER.info(res);
|
||||
// 初始化数据库连接
|
||||
vertx.createSharedWorkerExecutor("sql-pool-init")
|
||||
.executeBlocking(this::poolInitExecute)
|
||||
.onSuccess(LOGGER::info)
|
||||
.onFailure(Throwable::printStackTrace);
|
||||
// 初始化数据库连接
|
||||
vertx.createSharedWorkerExecutor("sql-pool-init")
|
||||
.executeBlocking(() -> {
|
||||
// 初始化连接池
|
||||
pool = JDBCPool.pool(vertx, dbConfig);
|
||||
CreateTable.createTable(pool, type);
|
||||
return "数据库连接初始化: URL=" + url;
|
||||
})
|
||||
.onSuccess(LOGGER::info)
|
||||
.onFailure(Throwable::printStackTrace);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void poolInitExecute(Promise<String> promise) {
|
||||
// 初始化连接池
|
||||
pool = JDBCPool.pool(vertx, dbConfig);
|
||||
CreateTable.createTable(pool);
|
||||
promise.complete("init jdbc pool success");
|
||||
|
||||
}
|
||||
|
||||
private void checkOrCreateDBFile() {
|
||||
LOGGER.info("init sql start");
|
||||
String[] path = url.split("\\./");
|
||||
path[1] = path[1].split(";")[0];
|
||||
path[1] += ".mv.db";
|
||||
File file = new File(path[1]);
|
||||
if (!file.exists()) {
|
||||
if (!file.getParentFile().exists()) {
|
||||
if (file.getParentFile().mkdirs()) {
|
||||
LOGGER.info("mkdirs -> {}", file.getParentFile().getAbsolutePath());
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (file.createNewFile()) {
|
||||
LOGGER.info("create file -> {}", file.getAbsolutePath());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(e.getMessage());
|
||||
throw new RuntimeException("file create failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void h2serverExecute(Promise<String> promise) {
|
||||
// 初始化H2db, 创建本地db文件
|
||||
checkOrCreateDBFile();
|
||||
|
||||
try {
|
||||
String url = dbConfig.getString("jdbcUrl");
|
||||
String[] portStr = url.split(":");
|
||||
String port = portStr[portStr.length - 1].split("[/\\\\]")[0];
|
||||
LOGGER.info("H2server listen port to {}", port);
|
||||
H2ServerHolder.init(Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", port).start());
|
||||
promise.complete("Start h2Server success");
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Start h2Server failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
23
core/pom.xml
23
core/pom.xml
@@ -5,28 +5,15 @@
|
||||
<parent>
|
||||
<artifactId>netdisk-fast-download</artifactId>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<version>0.1.7</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>1.0.8</version>
|
||||
<artifactId>core</artifactId>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-dependencies</artifactId>
|
||||
<version>${vertx.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<!--logback日志实现-->
|
||||
<dependency>
|
||||
@@ -73,11 +60,13 @@
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.melloware/commons-beanutils2 -->
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
<version>1.9.4</version>
|
||||
<groupId>com.melloware</groupId>
|
||||
<artifactId>commons-beanutils2</artifactId>
|
||||
<version>${commons-beanutils2.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
|
||||
@@ -3,8 +3,8 @@ package cn.qaiu.vx.core.util;
|
||||
import cn.qaiu.vx.core.annotaions.HandleSortFilter;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import org.apache.commons.beanutils.ConvertUtils;
|
||||
import org.apache.commons.beanutils.Converter;
|
||||
import org.apache.commons.beanutils2.ConvertUtils;
|
||||
import org.apache.commons.beanutils2.Converter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.qaiu.vx.core.util;
|
||||
|
||||
import io.vertx.core.MultiMap;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.apache.commons.beanutils2.BeanUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
@@ -5,12 +5,13 @@ import javassist.bytecode.AccessFlag;
|
||||
import javassist.bytecode.CodeAttribute;
|
||||
import javassist.bytecode.LocalVariableAttribute;
|
||||
import javassist.bytecode.MethodInfo;
|
||||
import org.apache.commons.beanutils.ConversionException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.scanners.*;
|
||||
import org.reflections.scanners.MemberUsageScanner;
|
||||
import org.reflections.scanners.MethodParameterNamesScanner;
|
||||
import org.reflections.scanners.Scanners;
|
||||
import org.reflections.util.ClasspathHelper;
|
||||
import org.reflections.util.ConfigurationBuilder;
|
||||
import org.reflections.util.FilterBuilder;
|
||||
@@ -185,10 +186,10 @@ public final class ReflectionUtil {
|
||||
return DateUtils.parseDate(value, fmt);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
throw new ConversionException("无法将格式化日期");
|
||||
throw new RuntimeException("无法将格式化日期");
|
||||
}
|
||||
default:
|
||||
throw new ConversionException("无法将String类型" + value + "转为[" + name + "]");
|
||||
throw new RuntimeException("无法将String类型" + value + "转为[" + name + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +201,7 @@ public final class ReflectionUtil {
|
||||
* @return Array
|
||||
*/
|
||||
public static Object conversionArray(CtClass ctClass, String value) {
|
||||
if (!isBasicTypeArray(ctClass)) throw new ConversionException("无法解析数组");
|
||||
if (!isBasicTypeArray(ctClass)) throw new RuntimeException("无法解析数组");
|
||||
String[] strArr = value.split(",");
|
||||
List<Object> obj = new ArrayList<>();
|
||||
Arrays.stream(strArr).forEach(v -> obj.add(conversion(ctClass, v, null)));
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>netdisk-fast-download</artifactId>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<version>0.1.7</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>parser</artifactId>
|
||||
|
||||
<properties>
|
||||
|
||||
33
pom.xml
33
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<artifactId>netdisk-fast-download</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>0.1.7</version>
|
||||
<version>${revision}</version>
|
||||
|
||||
<modules>
|
||||
<module>core</module>
|
||||
@@ -17,6 +17,7 @@
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<revision>0.1.7</revision>
|
||||
<java.version>17</java.version>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
@@ -30,10 +31,40 @@
|
||||
<lombok.version>1.18.12</lombok.version>
|
||||
<slf4j.version>2.0.5</slf4j.version>
|
||||
<commons-lang3.version>3.12.0</commons-lang3.version>
|
||||
<commons-beanutils2.version>2.0.0</commons-beanutils2.version>
|
||||
<jackson.version>2.14.2</jackson.version>
|
||||
<logback.version>1.4.12</logback.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-dependencies</artifactId>
|
||||
<version>${vertx.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<artifactId>core-database</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<artifactId>parser</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
||||
@@ -5,10 +5,9 @@
|
||||
<parent>
|
||||
<artifactId>netdisk-fast-download</artifactId>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<version>0.1.7</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>0.1.7</version>
|
||||
<artifactId>web-service</artifactId>
|
||||
|
||||
<properties>
|
||||
@@ -22,7 +21,14 @@
|
||||
<dependency>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>1.0.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<artifactId>core-database</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<artifactId>parser</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
@@ -47,16 +53,6 @@
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<artifactId>core-database</artifactId>
|
||||
<version>0.1.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<artifactId>parser</artifactId>
|
||||
<version>0.1.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
||||
@@ -35,7 +35,7 @@ custom:
|
||||
# 数据源配置
|
||||
dataSource:
|
||||
provider_class: io.vertx.ext.jdbc.spi.impl.HikariCPDataSourceProvider
|
||||
jdbcUrl: jdbc:h2:tcp://127.0.0.1:9095/./db/myData;MODE=MySQL;DATABASE_TO_UPPER=FALSE
|
||||
jdbcUrl: jdbc:h2:file:./db/nfdData;MODE=MySQL;DATABASE_TO_UPPER=FALSE
|
||||
driverClassName: org.h2.Driver
|
||||
username: root
|
||||
password: '123456'
|
||||
|
||||
@@ -83,14 +83,10 @@ GET http://127.0.0.1:6400/parser?url=https://share.feijipan.com/s/nMtCOXL
|
||||
### 小飞机盘 https://share.feijipan.com/s/laUshYGk
|
||||
# @no-redirect
|
||||
GET http://127.0.0.1:6400/parser?url=https://share.feijipan.com/s/laUshYGk
|
||||
### 小飞机盘
|
||||
### 小飞机盘 tIfhRqH
|
||||
GET http://127.0.0.1:6400/json/fj/tIfhRqH
|
||||
### 小飞机盘 https://share.feijipan.com/s/7jy0zlv
|
||||
GET http://127.0.0.1:6400/json/fj/7jy0zlv
|
||||
|
||||
### 小飞机盘
|
||||
# @no-redirect
|
||||
GET http://127.0.0.1:6400/fj/tIfhRqH
|
||||
### 小飞机盘 https://share.feijipan.com/s/nMtCOXL
|
||||
# @no-redirect
|
||||
GET http://127.0.0.1:6400/fj/nMtCOXL
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package cn.qaiu.web.test;
|
||||
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.apache.commons.beanutils.ConvertUtils;
|
||||
import org.apache.commons.beanutils.Converter;
|
||||
import org.apache.commons.beanutils2.BeanUtils;
|
||||
import org.apache.commons.beanutils2.ConvertUtils;
|
||||
import org.apache.commons.beanutils2.Converter;
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
Reference in New Issue
Block a user