mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2025-12-18 21:33:03 +00:00
do db
This commit is contained in:
65
core-database/pom.xml
Normal file
65
core-database/pom.xml
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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">
|
||||||
|
<parent>
|
||||||
|
<artifactId>lz-cow-api</artifactId>
|
||||||
|
<groupId>cn.qaiu</groupId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>core-database</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>17</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<slf4j.version>2.0.5</slf4j.version>
|
||||||
|
<commons-lang3.version>3.12.0</commons-lang3.version>
|
||||||
|
<vertx.version>4.4.1</vertx.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.qaiu</groupId>
|
||||||
|
<artifactId>core</artifactId>
|
||||||
|
<version>1.0.8</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<version>2.1.214</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zaxxer</groupId>
|
||||||
|
<artifactId>HikariCP</artifactId>
|
||||||
|
<version>5.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
<version>3.12.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.vertx</groupId>
|
||||||
|
<artifactId>vertx-codegen</artifactId>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<version>${vertx.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.vertx</groupId>
|
||||||
|
<artifactId>vertx-sql-client-templates</artifactId>
|
||||||
|
<version>${vertx.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.vertx</groupId>
|
||||||
|
<artifactId>vertx-jdbc-client</artifactId>
|
||||||
|
<version>${vertx.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package cn.qaiu;
|
||||||
|
|
||||||
|
public class StartH2DatabaseServer {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Hello world!");
|
||||||
|
}
|
||||||
|
}
|
||||||
45
core-database/src/main/java/cn/qaiu/db/ddl/Constraint.java
Normal file
45
core-database/src/main/java/cn/qaiu/db/ddl/Constraint.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package cn.qaiu.db.ddl;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 建表约束类型
|
||||||
|
*
|
||||||
|
* <br>Create date 2021/7/22 0:42
|
||||||
|
* @author <a href="https://qaiu.top">QAIU</a>
|
||||||
|
*/
|
||||||
|
@Documented
|
||||||
|
@Inherited
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.TYPE, ElementType.FIELD})
|
||||||
|
public @interface Constraint {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 非空约束
|
||||||
|
* @return false 可以为空
|
||||||
|
*/
|
||||||
|
boolean notNull() default false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 唯一键约束 TODO 待实现
|
||||||
|
* @return 唯一键约束
|
||||||
|
*/
|
||||||
|
String uniqueKey() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认值约束
|
||||||
|
* @return 默认值约束
|
||||||
|
*/
|
||||||
|
String defaultValue() default "";
|
||||||
|
/**
|
||||||
|
* 默认值是否是函数
|
||||||
|
* @return false 不是函数
|
||||||
|
*/
|
||||||
|
boolean defaultValueIsFunction() default false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否自增 只能用于int或long类型上
|
||||||
|
* @return false 不自增
|
||||||
|
*/
|
||||||
|
boolean autoIncrement() default false;
|
||||||
|
}
|
||||||
170
core-database/src/main/java/cn/qaiu/db/ddl/CreateTable.java
Normal file
170
core-database/src/main/java/cn/qaiu/db/ddl/CreateTable.java
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
package cn.qaiu.db.ddl;
|
||||||
|
|
||||||
|
import cn.qaiu.vx.core.util.ReflectionUtil;
|
||||||
|
import io.vertx.codegen.format.CamelCase;
|
||||||
|
import io.vertx.codegen.format.Case;
|
||||||
|
import io.vertx.codegen.format.LowerCamelCase;
|
||||||
|
import io.vertx.codegen.format.SnakeCase;
|
||||||
|
import io.vertx.jdbcclient.JDBCPool;
|
||||||
|
import io.vertx.sqlclient.templates.annotations.Column;
|
||||||
|
import io.vertx.sqlclient.templates.annotations.RowMapped;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建表
|
||||||
|
*
|
||||||
|
* @author <a href="https://qaiu.top">QAIU</a>
|
||||||
|
*/
|
||||||
|
public class CreateTable {
|
||||||
|
public static Map<Class<?>, String> javaProperty2SqlColumnMap = new HashMap<>();
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(CreateTable.class);
|
||||||
|
|
||||||
|
static {
|
||||||
|
javaProperty2SqlColumnMap.put(Integer.class, "INT");
|
||||||
|
javaProperty2SqlColumnMap.put(Short.class, "SMALLINT");
|
||||||
|
javaProperty2SqlColumnMap.put(Byte.class, "TINYINT");
|
||||||
|
javaProperty2SqlColumnMap.put(Long.class, "BIGINT");
|
||||||
|
javaProperty2SqlColumnMap.put(java.math.BigDecimal.class, "DECIMAL");
|
||||||
|
javaProperty2SqlColumnMap.put(Double.class, "DOUBLE");
|
||||||
|
javaProperty2SqlColumnMap.put(Float.class, "REAL");
|
||||||
|
javaProperty2SqlColumnMap.put(Boolean.class, "BOOLEAN");
|
||||||
|
javaProperty2SqlColumnMap.put(String.class, "VARCHAR");
|
||||||
|
javaProperty2SqlColumnMap.put(java.util.Date.class, "TIMESTAMP");
|
||||||
|
javaProperty2SqlColumnMap.put(java.sql.Timestamp.class, "TIMESTAMP");
|
||||||
|
javaProperty2SqlColumnMap.put(java.sql.Date.class, "DATE");
|
||||||
|
javaProperty2SqlColumnMap.put(java.sql.Time.class, "TIME");
|
||||||
|
|
||||||
|
javaProperty2SqlColumnMap.put(int.class, "INT");
|
||||||
|
javaProperty2SqlColumnMap.put(short.class, "SMALLINT");
|
||||||
|
javaProperty2SqlColumnMap.put(byte.class, "TINYINT");
|
||||||
|
javaProperty2SqlColumnMap.put(long.class, "BIGINT");
|
||||||
|
javaProperty2SqlColumnMap.put(double.class, "DOUBLE");
|
||||||
|
javaProperty2SqlColumnMap.put(float.class, "REAL");
|
||||||
|
javaProperty2SqlColumnMap.put(boolean.class, "BOOLEAN");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Case getCase(Class<?> clz) {
|
||||||
|
switch (clz.getName()) {
|
||||||
|
case "io.vertx.codegen.format.CamelCase":
|
||||||
|
return CamelCase.INSTANCE;
|
||||||
|
case "io.vertx.codegen.format.SnakeCase":
|
||||||
|
return SnakeCase.INSTANCE;
|
||||||
|
case "io.vertx.codegen.format.LowerCamelCase":
|
||||||
|
return LowerCamelCase.INSTANCE;
|
||||||
|
default:
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getCreateTableSQL(Class<?> clz) {
|
||||||
|
// 判断类上是否有次注解
|
||||||
|
String primaryKey = null; // 主键
|
||||||
|
String tableName = null; // 表名
|
||||||
|
Case caseFormat = SnakeCase.INSTANCE;
|
||||||
|
if (clz.isAnnotationPresent(RowMapped.class)) {
|
||||||
|
RowMapped annotation = clz.getAnnotation(RowMapped.class);
|
||||||
|
Class<? extends Case> formatter = annotation.formatter();
|
||||||
|
caseFormat = getCase(formatter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clz.isAnnotationPresent(Table.class)) {
|
||||||
|
// 获取类上的注解
|
||||||
|
Table annotation = clz.getAnnotation(Table.class);
|
||||||
|
// 输出注解上的类名
|
||||||
|
String tableNameAnnotation = annotation.value();
|
||||||
|
if (StringUtils.isNotEmpty(tableNameAnnotation)) {
|
||||||
|
tableName = tableNameAnnotation;
|
||||||
|
} else {
|
||||||
|
tableName = LowerCamelCase.INSTANCE.to(caseFormat, clz.getSimpleName());
|
||||||
|
}
|
||||||
|
primaryKey = annotation.keyFields();
|
||||||
|
}
|
||||||
|
Field[] fields = clz.getDeclaredFields();
|
||||||
|
String column;
|
||||||
|
int[] decimalSize = {22, 2};
|
||||||
|
int varcharSize = 255;
|
||||||
|
StringBuilder sb = new StringBuilder(50);
|
||||||
|
sb.append("CREATE TABLE IF NOT EXISTS \"").append(tableName).append("\" ( \r\n ");
|
||||||
|
boolean firstId = true;
|
||||||
|
for (Field f : fields) {
|
||||||
|
Class<?> paramType = f.getType();
|
||||||
|
String sqlType = javaProperty2SqlColumnMap.get(paramType);
|
||||||
|
if (f.getName().equals("serialVersionUID") || StringUtils.isEmpty(sqlType) || f.isAnnotationPresent(TableGenIgnore.class)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
column = LowerCamelCase.INSTANCE.to(caseFormat, f.getName());
|
||||||
|
if (f.isAnnotationPresent(Column.class)) {
|
||||||
|
Column columnAnnotation = f.getAnnotation(Column.class);
|
||||||
|
//输出注解属性
|
||||||
|
if (StringUtils.isNotBlank(columnAnnotation.name())) {
|
||||||
|
column = columnAnnotation.name();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (f.isAnnotationPresent(Length.class)) {
|
||||||
|
Length fieldAnnotation = f.getAnnotation(Length.class);
|
||||||
|
decimalSize = fieldAnnotation.decimalSize();
|
||||||
|
varcharSize = fieldAnnotation.varcharSize();
|
||||||
|
}
|
||||||
|
sb.append("\"").append(column).append("\"");
|
||||||
|
sb.append(" ").append(sqlType);
|
||||||
|
// 添加类型长度
|
||||||
|
if (sqlType.equals("DECIMAL")) {
|
||||||
|
sb.append("(").append(decimalSize[0]).append(",").append(decimalSize[1]).append(")");
|
||||||
|
}
|
||||||
|
if (sqlType.equals("VARCHAR")) {
|
||||||
|
sb.append("(").append(varcharSize).append(")");
|
||||||
|
}
|
||||||
|
if (f.isAnnotationPresent(Constraint.class)) {
|
||||||
|
Constraint constraintAnnotation = f.getAnnotation(Constraint.class);
|
||||||
|
if (constraintAnnotation.notNull()) {
|
||||||
|
//非空约束
|
||||||
|
sb.append(" NOT NULL");
|
||||||
|
}
|
||||||
|
String apostrophe = constraintAnnotation.defaultValueIsFunction() ? "" : "'";
|
||||||
|
if (StringUtils.isNotEmpty(constraintAnnotation.defaultValue())) {
|
||||||
|
//默认值约束
|
||||||
|
sb.append(" DEFAULT ").append(apostrophe).append(constraintAnnotation.defaultValue()).append(apostrophe);
|
||||||
|
}
|
||||||
|
if (constraintAnnotation.autoIncrement() && paramType.equals(Integer.class) || paramType.equals(Long.class)) {
|
||||||
|
////自增
|
||||||
|
sb.append(" AUTO_INCREMENT");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(primaryKey)) {
|
||||||
|
if (firstId) {//类型转换
|
||||||
|
sb.append(" PRIMARY KEY");
|
||||||
|
firstId = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (primaryKey.equals(column.toLowerCase())) {
|
||||||
|
sb.append(" PRIMARY KEY");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sb.append(",\n ");
|
||||||
|
}
|
||||||
|
String sql = sb.toString();
|
||||||
|
//去掉最后一个逗号
|
||||||
|
int lastIndex = sql.lastIndexOf(",");
|
||||||
|
sql = sql.substring(0, lastIndex) + sql.substring(lastIndex + 1);
|
||||||
|
return sql.substring(0, sql.length() - 1) + ");\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createTable(JDBCPool pool, String tableClassPath) {
|
||||||
|
Set<Class<?>> tableClassList = ReflectionUtil.getReflections(tableClassPath).getTypesAnnotatedWith(Table.class);
|
||||||
|
if (tableClassList.isEmpty()) LOGGER.info("Table model class not fount");
|
||||||
|
tableClassList.forEach(clazz -> {
|
||||||
|
String createTableSQL = getCreateTableSQL(clazz);
|
||||||
|
pool.query(createTableSQL).execute().onSuccess(
|
||||||
|
rs -> LOGGER.info("\n" + createTableSQL + "create table --> ok")
|
||||||
|
).onFailure(Throwable::printStackTrace);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
16
core-database/src/main/java/cn/qaiu/db/ddl/Length.java
Normal file
16
core-database/src/main/java/cn/qaiu/db/ddl/Length.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package cn.qaiu.db.ddl;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段长度属性
|
||||||
|
* @author <a href="https://qaiu.top">QAIU</a>
|
||||||
|
*/
|
||||||
|
@Documented
|
||||||
|
@Inherited
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.TYPE, ElementType.FIELD})
|
||||||
|
public @interface Length {
|
||||||
|
int[] decimalSize() default {22,2}; //bigDecimal精度
|
||||||
|
int varcharSize() default 255; //varchar大小
|
||||||
|
}
|
||||||
17
core-database/src/main/java/cn/qaiu/db/ddl/Table.java
Normal file
17
core-database/src/main/java/cn/qaiu/db/ddl/Table.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package cn.qaiu.db.ddl;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标注建表的实体类和主键字段
|
||||||
|
*
|
||||||
|
* @author <a href="https://qaiu.top">QAIU</a>
|
||||||
|
*/
|
||||||
|
@Documented
|
||||||
|
@Inherited
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.TYPE, ElementType.FIELD})//次注解作用于类和字段上
|
||||||
|
public @interface Table {
|
||||||
|
String value() default ""; //默认表名为空
|
||||||
|
String keyFields() default "id"; //默认主键为id
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package cn.qaiu.db.ddl;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 建表时忽略字段
|
||||||
|
* <br>Create date 2021/8/27 15:49
|
||||||
|
*
|
||||||
|
* @author <a href="https://qaiu.top">QAIU</a>
|
||||||
|
*/
|
||||||
|
@Documented
|
||||||
|
@Inherited
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.TYPE, ElementType.FIELD})
|
||||||
|
public @interface TableGenIgnore {
|
||||||
|
}
|
||||||
140
core-database/src/main/java/cn/qaiu/db/pool/JDBCPoolInit.java
Normal file
140
core-database/src/main/java/cn/qaiu/db/pool/JDBCPoolInit.java
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
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
|
||||||
|
*
|
||||||
|
* @author <a href="https://qaiu.top">QAIU</a>
|
||||||
|
*/
|
||||||
|
public class JDBCPoolInit {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(JDBCPoolInit.class);
|
||||||
|
private JDBCPool pool = null;
|
||||||
|
JsonObject dbConfig;
|
||||||
|
Vertx vertx = VertxHolder.getVertxInstance();
|
||||||
|
String url;
|
||||||
|
|
||||||
|
private static JDBCPoolInit instance;
|
||||||
|
|
||||||
|
public JDBCPoolInit(Builder builder) {
|
||||||
|
this.dbConfig = builder.dbConfig;
|
||||||
|
this.url = builder.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JDBCPoolInit instance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
private JsonObject dbConfig;
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
public Builder config(JsonObject dbConfig) {
|
||||||
|
this.dbConfig = dbConfig;
|
||||||
|
this.url = dbConfig.getString("jdbcUrl");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JDBCPoolInit build() {
|
||||||
|
if (JDBCPoolInit.instance == null) {
|
||||||
|
JDBCPoolInit.instance = new JDBCPoolInit(this);
|
||||||
|
}
|
||||||
|
return JDBCPoolInit.instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* init h2db<br>
|
||||||
|
* 这个方法只允许调用一次
|
||||||
|
*/
|
||||||
|
public void initPool() {
|
||||||
|
if (pool != null) {
|
||||||
|
LOGGER.error("pool 重复初始化");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 异步启动H2服务
|
||||||
|
vertx.createSharedWorkerExecutor("h2-server", 1, Long.MAX_VALUE)
|
||||||
|
.executeBlocking(this::h2serverExecute)
|
||||||
|
.onSuccess(LOGGER::info)
|
||||||
|
.onFailure(Throwable::printStackTrace);
|
||||||
|
|
||||||
|
// 初始化数据库连接
|
||||||
|
vertx.createSharedWorkerExecutor("sql-pool-init")
|
||||||
|
.executeBlocking(this::poolInitExecute)
|
||||||
|
.onSuccess(LOGGER::info)
|
||||||
|
.onFailure(Throwable::printStackTrace);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void poolInitExecute(Promise<String> promise) {
|
||||||
|
// 初始化H2db, 创建本地db文件
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 初始化连接池
|
||||||
|
pool = JDBCPool.pool(vertx, dbConfig);
|
||||||
|
CreateTable.createTable(pool, dbConfig.getString("tableClassPath"));
|
||||||
|
promise.complete("init jdbc pool success");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void h2serverExecute(Promise<String> promise) {
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取连接池
|
||||||
|
*
|
||||||
|
* @return pool
|
||||||
|
*/
|
||||||
|
public JDBCPool getPool() {
|
||||||
|
return pool;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package cn.qaiu.db.server;
|
||||||
|
|
||||||
|
import org.h2.tools.Server;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* h2db server
|
||||||
|
* <br>Create date 2021/7/23 2:44
|
||||||
|
*
|
||||||
|
* @author <a href="https://qaiu.top">QAIU</a>
|
||||||
|
*/
|
||||||
|
public class H2ServerHolder {
|
||||||
|
|
||||||
|
private static Server h2Server;
|
||||||
|
|
||||||
|
public static synchronized void init(Server server) {
|
||||||
|
Objects.requireNonNull(server, "未初始化h2Server");
|
||||||
|
h2Server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Server getH2Server() {
|
||||||
|
Objects.requireNonNull(h2Server, "等待h2Server初始化");
|
||||||
|
return h2Server;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,6 +53,12 @@
|
|||||||
<artifactId>jsoup</artifactId>
|
<artifactId>jsoup</artifactId>
|
||||||
<version>1.15.4</version>
|
<version>1.15.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.qaiu</groupId>
|
||||||
|
<artifactId>core-database</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* Red Hat licenses this file to you 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 cn.qaiu.lz.web.service;
|
||||||
|
|
||||||
|
import io.vertx.core.eventbus.DeliveryOptions;
|
||||||
|
import io.vertx.core.Vertx;
|
||||||
|
import io.vertx.core.Future;
|
||||||
|
import io.vertx.core.json.JsonObject;
|
||||||
|
import io.vertx.core.json.JsonArray;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import io.vertx.serviceproxy.ServiceException;
|
||||||
|
import io.vertx.serviceproxy.ServiceExceptionMessageCodec;
|
||||||
|
import io.vertx.serviceproxy.ProxyUtils;
|
||||||
|
|
||||||
|
import cn.qaiu.lz.common.model.UserInfo;
|
||||||
|
import cn.qaiu.vx.core.base.BaseAsyncService;
|
||||||
|
import io.vertx.core.Future;
|
||||||
|
/*
|
||||||
|
Generated Proxy code - DO NOT EDIT
|
||||||
|
@author Roger the Robot
|
||||||
|
*/
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
|
public class DbServiceVertxEBProxy implements DbService {
|
||||||
|
private Vertx _vertx;
|
||||||
|
private String _address;
|
||||||
|
private DeliveryOptions _options;
|
||||||
|
private boolean closed;
|
||||||
|
|
||||||
|
public DbServiceVertxEBProxy(Vertx vertx, String address) {
|
||||||
|
this(vertx, address, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DbServiceVertxEBProxy(Vertx vertx, String address, DeliveryOptions options) {
|
||||||
|
this._vertx = vertx;
|
||||||
|
this._address = address;
|
||||||
|
this._options = options;
|
||||||
|
try {
|
||||||
|
this._vertx.eventBus().registerDefaultCodec(ServiceException.class, new ServiceExceptionMessageCodec());
|
||||||
|
} catch (IllegalStateException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Future<JsonObject> sayOk(String data){
|
||||||
|
if (closed) return io.vertx.core.Future.failedFuture("Proxy is closed");
|
||||||
|
JsonObject _json = new JsonObject();
|
||||||
|
_json.put("data", data);
|
||||||
|
|
||||||
|
DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
|
||||||
|
_deliveryOptions.addHeader("action", "sayOk");
|
||||||
|
_deliveryOptions.getHeaders().set("action", "sayOk");
|
||||||
|
return _vertx.eventBus().<JsonObject>request(_address, _json, _deliveryOptions).map(msg -> {
|
||||||
|
return msg.body();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Future<JsonObject> sayOk2(String data, UserInfo holder){
|
||||||
|
if (closed) return io.vertx.core.Future.failedFuture("Proxy is closed");
|
||||||
|
JsonObject _json = new JsonObject();
|
||||||
|
_json.put("data", data);
|
||||||
|
_json.put("holder", holder != null ? holder.toJson() : null);
|
||||||
|
|
||||||
|
DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
|
||||||
|
_deliveryOptions.addHeader("action", "sayOk2");
|
||||||
|
_deliveryOptions.getHeaders().set("action", "sayOk2");
|
||||||
|
return _vertx.eventBus().<JsonObject>request(_address, _json, _deliveryOptions).map(msg -> {
|
||||||
|
return msg.body();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* Red Hat licenses this file to you 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 cn.qaiu.lz.web.service;
|
||||||
|
|
||||||
|
import cn.qaiu.lz.web.service.DbService;
|
||||||
|
import io.vertx.core.Vertx;
|
||||||
|
import io.vertx.core.Handler;
|
||||||
|
import io.vertx.core.AsyncResult;
|
||||||
|
import io.vertx.core.eventbus.EventBus;
|
||||||
|
import io.vertx.core.eventbus.Message;
|
||||||
|
import io.vertx.core.eventbus.MessageConsumer;
|
||||||
|
import io.vertx.core.eventbus.DeliveryOptions;
|
||||||
|
import io.vertx.core.eventbus.ReplyException;
|
||||||
|
import io.vertx.core.json.JsonObject;
|
||||||
|
import io.vertx.core.json.JsonArray;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import io.vertx.serviceproxy.ProxyHandler;
|
||||||
|
import io.vertx.serviceproxy.ServiceException;
|
||||||
|
import io.vertx.serviceproxy.ServiceExceptionMessageCodec;
|
||||||
|
import io.vertx.serviceproxy.HelperUtils;
|
||||||
|
import io.vertx.serviceproxy.ServiceBinder;
|
||||||
|
|
||||||
|
import cn.qaiu.lz.common.model.UserInfo;
|
||||||
|
import cn.qaiu.vx.core.base.BaseAsyncService;
|
||||||
|
import io.vertx.core.Future;
|
||||||
|
/*
|
||||||
|
Generated Proxy code - DO NOT EDIT
|
||||||
|
@author Roger the Robot
|
||||||
|
*/
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
|
public class DbServiceVertxProxyHandler extends ProxyHandler {
|
||||||
|
|
||||||
|
public static final long DEFAULT_CONNECTION_TIMEOUT = 5 * 60; // 5 minutes
|
||||||
|
private final Vertx vertx;
|
||||||
|
private final DbService service;
|
||||||
|
private final long timerID;
|
||||||
|
private long lastAccessed;
|
||||||
|
private final long timeoutSeconds;
|
||||||
|
private final boolean includeDebugInfo;
|
||||||
|
|
||||||
|
public DbServiceVertxProxyHandler(Vertx vertx, DbService service){
|
||||||
|
this(vertx, service, DEFAULT_CONNECTION_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DbServiceVertxProxyHandler(Vertx vertx, DbService service, long timeoutInSecond){
|
||||||
|
this(vertx, service, true, timeoutInSecond);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DbServiceVertxProxyHandler(Vertx vertx, DbService service, boolean topLevel, long timeoutInSecond){
|
||||||
|
this(vertx, service, true, timeoutInSecond, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DbServiceVertxProxyHandler(Vertx vertx, DbService service, boolean topLevel, long timeoutSeconds, boolean includeDebugInfo) {
|
||||||
|
this.vertx = vertx;
|
||||||
|
this.service = service;
|
||||||
|
this.includeDebugInfo = includeDebugInfo;
|
||||||
|
this.timeoutSeconds = timeoutSeconds;
|
||||||
|
try {
|
||||||
|
this.vertx.eventBus().registerDefaultCodec(ServiceException.class,
|
||||||
|
new ServiceExceptionMessageCodec());
|
||||||
|
} catch (IllegalStateException ex) {}
|
||||||
|
if (timeoutSeconds != -1 && !topLevel) {
|
||||||
|
long period = timeoutSeconds * 1000 / 2;
|
||||||
|
if (period > 10000) {
|
||||||
|
period = 10000;
|
||||||
|
}
|
||||||
|
this.timerID = vertx.setPeriodic(period, this::checkTimedOut);
|
||||||
|
} else {
|
||||||
|
this.timerID = -1;
|
||||||
|
}
|
||||||
|
accessed();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void checkTimedOut(long id) {
|
||||||
|
long now = System.nanoTime();
|
||||||
|
if (now - lastAccessed > timeoutSeconds * 1000000000) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
if (timerID != -1) {
|
||||||
|
vertx.cancelTimer(timerID);
|
||||||
|
}
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void accessed() {
|
||||||
|
this.lastAccessed = System.nanoTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(Message<JsonObject> msg) {
|
||||||
|
try{
|
||||||
|
JsonObject json = msg.body();
|
||||||
|
String action = msg.headers().get("action");
|
||||||
|
if (action == null) throw new IllegalStateException("action not specified");
|
||||||
|
accessed();
|
||||||
|
switch (action) {
|
||||||
|
case "sayOk": {
|
||||||
|
service.sayOk((java.lang.String)json.getValue("data")).onComplete(HelperUtils.createHandler(msg, includeDebugInfo));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "sayOk2": {
|
||||||
|
service.sayOk2((java.lang.String)json.getValue("data"),
|
||||||
|
json.getJsonObject("holder") != null ? new cn.qaiu.lz.common.model.UserInfo((JsonObject)json.getJsonObject("holder")) : null).onComplete(HelperUtils.createHandler(msg, includeDebugInfo));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: throw new IllegalStateException("Invalid action: " + action);
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
if (includeDebugInfo) msg.reply(new ServiceException(500, t.getMessage(), HelperUtils.generateDebugInfo(t)));
|
||||||
|
else msg.reply(new ServiceException(500, t.getMessage()));
|
||||||
|
throw t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* Red Hat licenses this file to you 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 cn.qaiu.lz.web.service;
|
||||||
|
|
||||||
|
import io.vertx.core.eventbus.DeliveryOptions;
|
||||||
|
import io.vertx.core.Vertx;
|
||||||
|
import io.vertx.core.Future;
|
||||||
|
import io.vertx.core.json.JsonObject;
|
||||||
|
import io.vertx.core.json.JsonArray;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import io.vertx.serviceproxy.ServiceException;
|
||||||
|
import io.vertx.serviceproxy.ServiceExceptionMessageCodec;
|
||||||
|
import io.vertx.serviceproxy.ProxyUtils;
|
||||||
|
|
||||||
|
import cn.qaiu.lz.web.model.RealUser;
|
||||||
|
import cn.qaiu.vx.core.base.BaseAsyncService;
|
||||||
|
import io.vertx.core.Future;
|
||||||
|
/*
|
||||||
|
Generated Proxy code - DO NOT EDIT
|
||||||
|
@author Roger the Robot
|
||||||
|
*/
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
|
public class UserServiceVertxEBProxy implements UserService {
|
||||||
|
private Vertx _vertx;
|
||||||
|
private String _address;
|
||||||
|
private DeliveryOptions _options;
|
||||||
|
private boolean closed;
|
||||||
|
|
||||||
|
public UserServiceVertxEBProxy(Vertx vertx, String address) {
|
||||||
|
this(vertx, address, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserServiceVertxEBProxy(Vertx vertx, String address, DeliveryOptions options) {
|
||||||
|
this._vertx = vertx;
|
||||||
|
this._address = address;
|
||||||
|
this._options = options;
|
||||||
|
try {
|
||||||
|
this._vertx.eventBus().registerDefaultCodec(ServiceException.class, new ServiceExceptionMessageCodec());
|
||||||
|
} catch (IllegalStateException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Future<String> login(RealUser user){
|
||||||
|
if (closed) return io.vertx.core.Future.failedFuture("Proxy is closed");
|
||||||
|
JsonObject _json = new JsonObject();
|
||||||
|
_json.put("user", user != null ? user.toJson() : null);
|
||||||
|
|
||||||
|
DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
|
||||||
|
_deliveryOptions.addHeader("action", "login");
|
||||||
|
_deliveryOptions.getHeaders().set("action", "login");
|
||||||
|
return _vertx.eventBus().<String>request(_address, _json, _deliveryOptions).map(msg -> {
|
||||||
|
return msg.body();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* Red Hat licenses this file to you 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 cn.qaiu.lz.web.service;
|
||||||
|
|
||||||
|
import cn.qaiu.lz.web.service.UserService;
|
||||||
|
import io.vertx.core.Vertx;
|
||||||
|
import io.vertx.core.Handler;
|
||||||
|
import io.vertx.core.AsyncResult;
|
||||||
|
import io.vertx.core.eventbus.EventBus;
|
||||||
|
import io.vertx.core.eventbus.Message;
|
||||||
|
import io.vertx.core.eventbus.MessageConsumer;
|
||||||
|
import io.vertx.core.eventbus.DeliveryOptions;
|
||||||
|
import io.vertx.core.eventbus.ReplyException;
|
||||||
|
import io.vertx.core.json.JsonObject;
|
||||||
|
import io.vertx.core.json.JsonArray;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import io.vertx.serviceproxy.ProxyHandler;
|
||||||
|
import io.vertx.serviceproxy.ServiceException;
|
||||||
|
import io.vertx.serviceproxy.ServiceExceptionMessageCodec;
|
||||||
|
import io.vertx.serviceproxy.HelperUtils;
|
||||||
|
import io.vertx.serviceproxy.ServiceBinder;
|
||||||
|
|
||||||
|
import cn.qaiu.lz.web.model.RealUser;
|
||||||
|
import cn.qaiu.vx.core.base.BaseAsyncService;
|
||||||
|
import io.vertx.core.Future;
|
||||||
|
/*
|
||||||
|
Generated Proxy code - DO NOT EDIT
|
||||||
|
@author Roger the Robot
|
||||||
|
*/
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
|
public class UserServiceVertxProxyHandler extends ProxyHandler {
|
||||||
|
|
||||||
|
public static final long DEFAULT_CONNECTION_TIMEOUT = 5 * 60; // 5 minutes
|
||||||
|
private final Vertx vertx;
|
||||||
|
private final UserService service;
|
||||||
|
private final long timerID;
|
||||||
|
private long lastAccessed;
|
||||||
|
private final long timeoutSeconds;
|
||||||
|
private final boolean includeDebugInfo;
|
||||||
|
|
||||||
|
public UserServiceVertxProxyHandler(Vertx vertx, UserService service){
|
||||||
|
this(vertx, service, DEFAULT_CONNECTION_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserServiceVertxProxyHandler(Vertx vertx, UserService service, long timeoutInSecond){
|
||||||
|
this(vertx, service, true, timeoutInSecond);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserServiceVertxProxyHandler(Vertx vertx, UserService service, boolean topLevel, long timeoutInSecond){
|
||||||
|
this(vertx, service, true, timeoutInSecond, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserServiceVertxProxyHandler(Vertx vertx, UserService service, boolean topLevel, long timeoutSeconds, boolean includeDebugInfo) {
|
||||||
|
this.vertx = vertx;
|
||||||
|
this.service = service;
|
||||||
|
this.includeDebugInfo = includeDebugInfo;
|
||||||
|
this.timeoutSeconds = timeoutSeconds;
|
||||||
|
try {
|
||||||
|
this.vertx.eventBus().registerDefaultCodec(ServiceException.class,
|
||||||
|
new ServiceExceptionMessageCodec());
|
||||||
|
} catch (IllegalStateException ex) {}
|
||||||
|
if (timeoutSeconds != -1 && !topLevel) {
|
||||||
|
long period = timeoutSeconds * 1000 / 2;
|
||||||
|
if (period > 10000) {
|
||||||
|
period = 10000;
|
||||||
|
}
|
||||||
|
this.timerID = vertx.setPeriodic(period, this::checkTimedOut);
|
||||||
|
} else {
|
||||||
|
this.timerID = -1;
|
||||||
|
}
|
||||||
|
accessed();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void checkTimedOut(long id) {
|
||||||
|
long now = System.nanoTime();
|
||||||
|
if (now - lastAccessed > timeoutSeconds * 1000000000) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
if (timerID != -1) {
|
||||||
|
vertx.cancelTimer(timerID);
|
||||||
|
}
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void accessed() {
|
||||||
|
this.lastAccessed = System.nanoTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(Message<JsonObject> msg) {
|
||||||
|
try{
|
||||||
|
JsonObject json = msg.body();
|
||||||
|
String action = msg.headers().get("action");
|
||||||
|
if (action == null) throw new IllegalStateException("action not specified");
|
||||||
|
accessed();
|
||||||
|
switch (action) {
|
||||||
|
case "login": {
|
||||||
|
service.login(json.getJsonObject("user") != null ? new cn.qaiu.lz.web.model.RealUser((JsonObject)json.getJsonObject("user")) : null).onComplete(HelperUtils.createHandler(msg, includeDebugInfo));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: throw new IllegalStateException("Invalid action: " + action);
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
if (includeDebugInfo) msg.reply(new ServiceException(500, t.getMessage(), HelperUtils.generateDebugInfo(t)));
|
||||||
|
else msg.reply(new ServiceException(500, t.getMessage()));
|
||||||
|
throw t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
package cn.qaiu.lz;
|
package cn.qaiu.lz;
|
||||||
|
|
||||||
import cn.qaiu.vx.core.Deploy;
|
import cn.qaiu.vx.core.Deploy;
|
||||||
import cn.qaiu.vx.core.util.VertxHolder;
|
|
||||||
import io.vertx.core.json.JsonObject;
|
import io.vertx.core.json.JsonObject;
|
||||||
import lombok.val;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,15 +13,16 @@ import lombok.val;
|
|||||||
public class AppMain {
|
public class AppMain {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// 注册枚举类型转换器
|
|
||||||
Deploy.instance().start(args, AppMain::exec);
|
Deploy.instance().start(args, AppMain::exec);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 初始化数据库
|
||||||
*
|
*
|
||||||
* @param jsonObject 配置
|
* @param jsonObject 配置
|
||||||
*/
|
*/
|
||||||
private static void exec(JsonObject jsonObject) {
|
private static void exec(JsonObject jsonObject) {
|
||||||
|
// JDBCPoolInit.builder().config(jsonObject.getJsonObject("dataSource")).build().initPool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package cn.qaiu.lz.web.model;
|
package cn.qaiu.lz.web.model;
|
||||||
|
|
||||||
|
import cn.qaiu.db.ddl.Table;
|
||||||
import cn.qaiu.lz.common.ToJson;
|
import cn.qaiu.lz.common.ToJson;
|
||||||
import io.vertx.codegen.annotations.DataObject;
|
import io.vertx.codegen.annotations.DataObject;
|
||||||
import io.vertx.core.json.JsonObject;
|
import io.vertx.core.json.JsonObject;
|
||||||
@@ -11,7 +12,10 @@ import lombok.NoArgsConstructor;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@DataObject
|
@DataObject
|
||||||
|
@Table("t_user")
|
||||||
public class RealUser implements ToJson {
|
public class RealUser implements ToJson {
|
||||||
|
private String id;
|
||||||
|
|
||||||
private String username;
|
private String username;
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
|||||||
@@ -35,4 +35,8 @@ https://cowtransfer.com/core/api/transfer/share/download?transferGuid=e4f41b51-b
|
|||||||
|
|
||||||
//https://download.cowcs.com/cowtransfer/cowtransfer/29188/db32e132e69f490eb4a343b398990f4b.docx?auth_key=1682111861-7b9579fbebb84aaba6bca368d083ab12-0-cbf009f3ffbcbb86191b8cdbc103abce&biz_type=1&business_code=COW_TRANSFER&channel_code=COW_CN_WEB&response-content-disposition=attachment%3B%20filename%3D05-CGB-DB-MENU-V1.02.docx%3Bfilename*%3Dutf-8%27%2705-CGB-DB-MENU-V1.02.docx&user_id=1023860921943729188&x-verify=1
|
//https://download.cowcs.com/cowtransfer/cowtransfer/29188/db32e132e69f490eb4a343b398990f4b.docx?auth_key=1682111861-7b9579fbebb84aaba6bca368d083ab12-0-cbf009f3ffbcbb86191b8cdbc103abce&biz_type=1&business_code=COW_TRANSFER&channel_code=COW_CN_WEB&response-content-disposition=attachment%3B%20filename%3D05-CGB-DB-MENU-V1.02.docx%3Bfilename*%3Dutf-8%27%2705-CGB-DB-MENU-V1.02.docx&user_id=1023860921943729188&x-verify=1
|
||||||
|
|
||||||
|
#V2 api
|
||||||
|
###
|
||||||
|
https://cowtransfer.com/core/api/dam/asset/files/download/23890683765739569/url/v2
|
||||||
|
authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJndWlkIjoiMDc1OTMwNGItMDEwZS00MGJiLTlhNDUtZTczY2Q5ODYzMDQwIiwiZXhwIjoxNjgzNzkzOTExfQ.rE9z0vhogPjUC0I92MqU8U_PKe4j_mGn7lGgPFMGt5c
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@
|
|||||||
<logger name="io.netty" level="warn"/>
|
<logger name="io.netty" level="warn"/>
|
||||||
<logger name="io.vertx" level="info"/>
|
<logger name="io.vertx" level="info"/>
|
||||||
<root level="debug">
|
<root level="debug">
|
||||||
<!-- <appender-ref ref="STDOUT"/>-->
|
<appender-ref ref="STDOUT"/>
|
||||||
<appender-ref ref="FILE"/>
|
<!-- <appender-ref ref="FILE"/>-->
|
||||||
</root>
|
</root>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
Reference in New Issue
Block a user