模块整改

This commit is contained in:
lyd
2022-09-23 17:11:09 +08:00
parent 9adb01e9c3
commit 67ff316bdf
190 changed files with 630 additions and 898 deletions

View File

@@ -6,11 +6,11 @@ import com.alibaba.fastjson.JSONObject;
import jxl.Sheet;
import jxl.Workbook;
import lombok.extern.slf4j.Slf4j;
import org.nl.utils.SpringContextHolder;
import org.nl.wql.core.bean.*;
import org.nl.wql.core.db.DBConnBean;
import org.nl.wql.core.engine.WQLEngine;
import org.nl.wql.core.engine.object.WO;
import org.nl.wql.util.SpringContextHolder;
import org.nl.wql.util.WqlUtil;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternResolver;

View File

@@ -1,17 +1,17 @@
package org.nl.wql.core.bean;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.beanutils.BasicDynaBean;
import org.apache.commons.beanutils.DynaProperty;
import org.nl.exception.WDKException;
import org.nl.wql.exception.WDKException;
import org.nl.wql.util.WqlUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
public class WQLData {

View File

@@ -5,11 +5,11 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BasicDynaBean;
import org.nl.exception.WDKException;
import org.nl.wql.WQLCore;
import org.nl.wql.core.content.BaseContext;
import org.nl.wql.core.engine.WQLFun;
import org.nl.wql.core.engine.object.WO;
import org.nl.wql.exception.WDKException;
import org.nl.wql.util.WqlUtil;
import java.io.Serializable;

View File

@@ -1,14 +1,12 @@
package org.nl.wql.core.db;
import java.sql.Connection;
import javax.sql.DataSource;
import lombok.extern.slf4j.Slf4j;
import org.nl.utils.SpringContextHolder;
import org.nl.wql.WQLCore;
import org.nl.wql.util.SpringContextHolder;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.nl.wql.WQLCore;
import javax.sql.DataSource;
import java.sql.Connection;
@Slf4j
public class DBConnection {

View File

@@ -1,8 +1,8 @@
package org.nl.wql.core.db;
import lombok.extern.slf4j.Slf4j;
import org.nl.utils.SpringContextHolder;
import org.nl.wql.WQLCore;
import org.nl.wql.util.SpringContextHolder;
import org.springframework.jdbc.datasource.DataSourceUtils;
import javax.naming.Context;

View File

@@ -16,8 +16,6 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.nl.exception.WDKException;
import org.nl.utils.SpringContextHolder;
import org.nl.wql.WQLCore;
import org.nl.wql.core.DataType;
import org.nl.wql.core.bean.ErrorBean;
@@ -28,6 +26,8 @@ import org.nl.wql.core.content.HttpContext;
import org.nl.wql.core.db.DBConnBean;
import org.nl.wql.core.db.DBConnection;
import org.nl.wql.core.engine.Syntax;
import org.nl.wql.exception.WDKException;
import org.nl.wql.util.SpringContextHolder;
import org.nl.wql.util.WqlUtil;
import javax.servlet.http.HttpServletRequest;
@@ -35,7 +35,10 @@ import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@Slf4j
public class WO implements Serializable, Cloneable {

View File

@@ -0,0 +1,54 @@
package org.nl.wql.exception;
public class WDKException extends RuntimeException {
private static final long serialVersionUID = 9059634125483898385L;
private String code;
private String desc;
private String message = "";
public WDKException() {
}
public WDKException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause);
this.message = message;
}
public WDKException(String message, Throwable cause) {
super(message, cause);
this.message = message;
}
public WDKException(String message) {
super(message);
this.message = message;
}
public WDKException(Throwable cause) {
super(cause);
}
public String getCode() {
return this.code;
}
public void setCode(String code) {
this.code = code;
}
public String getDesc() {
return this.desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright 2019-2020 the original author or authors.
*
* 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 org.nl.wql.util;
/**
* @author: liaojinlong
* @date: 2020/6/9 17:02
* @since: 1.0
* @see {@link SpringContextHolder}
* 针对某些初始化方法在SpringContextHolder 初始化前时,<br>
* 可提交一个 提交回调任务。<br>
* 在SpringContextHolder 初始化后,进行回调使用
*/
public interface CallBack {
/**
* 回调执行方法
*/
void executor();
/**
* 本回调任务名称
* @return /
*/
default String getCallBackName() {
return Thread.currentThread().getId() + ":" + this.getClass().getName();
}
}

View File

@@ -0,0 +1,156 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* 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 org.nl.wql.util;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.env.Environment;
import java.util.ArrayList;
import java.util.List;
/**
* @author Jie
* @date 2019-01-07
*/
@Slf4j
public class SpringContextHolder implements ApplicationContextAware, DisposableBean {
private static ApplicationContext applicationContext = null;
//数据库连接的bean名字
public static String dataSourceBeanName="dataSource";
private static final List<CallBack> CALL_BACKS = new ArrayList<>();
private static boolean addCallback = true;
/**
* 针对 某些初始化方法在SpringContextHolder 未初始化时 提交回调方法。
* 在SpringContextHolder 初始化后,进行回调使用
*
* @param callBack 回调函数
*/
public synchronized static void addCallBacks(CallBack callBack) {
if (addCallback) {
SpringContextHolder.CALL_BACKS.add(callBack);
} else {
log.warn("CallBack{} 已无法添加!立即执行", callBack.getCallBackName());
callBack.executor();
}
}
public static ApplicationContext getApplicationContext() {
try {
} catch (Exception e) {
e.printStackTrace();
}
return applicationContext;
}
/**
* 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
*/
@SuppressWarnings("unchecked")
public static <T> T getBean(String name) {
assertContextInjected();
return (T) applicationContext.getBean(name);
}
/**
* 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
*/
public static <T> T getBean(Class<T> requiredType) {
assertContextInjected();
return applicationContext.getBean(requiredType);
}
/**
* 获取SpringBoot 配置信息
*
* @param property 属性key
* @param defaultValue 默认值
* @param requiredType 返回类型
* @return /
*/
public static <T> T getProperties(String property, T defaultValue, Class<T> requiredType) {
T result = defaultValue;
try {
result = getBean(Environment.class).getProperty(property, requiredType);
} catch (Exception ignored) {}
return result;
}
/**
* 获取SpringBoot 配置信息
*
* @param property 属性key
* @return /
*/
public static String getProperties(String property) {
return getProperties(property, null, String.class);
}
/**
* 获取SpringBoot 配置信息
*
* @param property 属性key
* @param requiredType 返回类型
* @return /
*/
public static <T> T getProperties(String property, Class<T> requiredType) {
return getProperties(property, null, requiredType);
}
/**
* 检查ApplicationContext不为空.
*/
private static void assertContextInjected() {
if (applicationContext == null) {
throw new IllegalStateException("applicaitonContext属性未注入, 请在applicationContext" +
".xml中定义SpringContextHolder或在SpringBoot启动类中注册SpringContextHolder.");
}
}
/**
* 清除SpringContextHolder中的ApplicationContext为Null.
*/
private static void clearHolder() {
log.debug("清除SpringContextHolder中的ApplicationContext:"
+ applicationContext);
applicationContext = null;
}
@Override
public void destroy() {
SpringContextHolder.clearHolder();
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
if (SpringContextHolder.applicationContext != null) {
log.warn("SpringContextHolder中的ApplicationContext被覆盖, 原有ApplicationContext为:" + SpringContextHolder.applicationContext);
}
SpringContextHolder.applicationContext = applicationContext;
if (addCallback) {
for (CallBack callBack : SpringContextHolder.CALL_BACKS) {
callBack.executor();
}
CALL_BACKS.clear();
}
SpringContextHolder.addCallback = false;
}
}