Commit ee88dbc8 authored by yanzg's avatar yanzg

SQL层级处理的支持

parent 168d95a5
package com.yanzuoguang.util.base;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.StringHelper;
......@@ -184,7 +183,7 @@ public class ObjectHelper {
try {
setByType(vType, target, field, value);
} catch (Exception ex) {
throw new CodeException(ex);
throw new RuntimeException(ex);
}
}
}
......@@ -240,7 +239,7 @@ public class ObjectHelper {
writeWithFromClass(to, from);
return (T) to;
} catch (Exception e) {
throw new CodeException("对象" + cls.getName() + "不能复制", e);
throw new RuntimeException("对象" + cls.getName() + "不能复制", e);
}
}
......
package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.exception.CodeException;
/**
* 通信格式转换
......@@ -543,7 +542,7 @@ public class ByteHelper {
*/
public static byte toBCD(int from) {
if (from >= BCD_MAX_FLAG) {
throw new CodeException("整形转换成字节的PCD码必须小于100");
throw new RuntimeException("整形转换成字节的PCD码必须小于100");
}
byte bt = (byte) ((from / BYTE_TEN_UNIT * BYTE_HEX_UNIT) + from % BYTE_TEN_UNIT);
return bt;
......
package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.exception.ExceptionHelper;
import java.sql.Timestamp;
......@@ -549,7 +548,7 @@ public class DateHelper {
long mill = toMill - fromMill;
return mill;
} catch (ParseException ex) {
throw new CodeException(ex);
throw new RuntimeException(ex);
}
}
......@@ -754,7 +753,7 @@ public class DateHelper {
Date dt = format.parse(from);
return format.format(dt);
} catch (ParseException e) {
throw new CodeException(e);
throw new RuntimeException(e);
}
}
......
package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.exception.CodeException;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.io.*;
/**
* 登录相关函数
......@@ -39,7 +33,7 @@ public class FileHelper {
if (file.isDirectory()) {
return StringHelper.EMPTY;
} else {
throw new CodeException("文件" + file.getName() + "已存在文件,不能创建目录");
throw new RuntimeException("文件" + file.getName() + "已存在文件,不能创建目录");
}
}
file.mkdirs();
......@@ -65,10 +59,10 @@ public class FileHelper {
try {
InputStream inputStream = new FileInputStream(file);
return readFile(inputStream, encoding);
} catch (CodeException e) {
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new CodeException(e);
throw new RuntimeException(e);
}
}
......@@ -99,10 +93,10 @@ public class FileHelper {
} finally {
inputStream.close();//关闭输入流
}
} catch (CodeException e) {
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new CodeException(e);
throw new RuntimeException(e);
}
return sb.toString();
}
......@@ -122,11 +116,11 @@ public class FileHelper {
if (parentFile != null) {
if (!parentFile.exists()) {
if (!parentFile.mkdirs()) {
throw new CodeException("创建文件夹失败");
throw new RuntimeException("创建文件夹失败");
}
}
if (!parentFile.exists()) {
throw new CodeException("创建文件夹失败");
throw new RuntimeException("创建文件夹失败");
}
}
// 文件不存在则创建
......@@ -138,10 +132,10 @@ public class FileHelper {
raf.seek(file.length());
raf.write(content.getBytes(encoding));
raf.close();
} catch (CodeException e) {
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new CodeException(e);
throw new RuntimeException(e);
}
}
......@@ -157,17 +151,17 @@ public class FileHelper {
// 删除文件
if (file.exists()) {
if (!file.delete()) {
throw new CodeException("文件删除失败");
throw new RuntimeException("文件删除失败");
}
}
if (file.exists()) {
throw new CodeException("文件删除失败");
throw new RuntimeException("文件删除失败");
}
writeFileAppend(file, content, encoding);
} catch (CodeException e) {
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new CodeException(e);
throw new RuntimeException(e);
}
}
......
package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.log.Log;
import com.yanzuoguang.util.thread.ProcessData;
import com.yanzuoguang.util.thread.RunProcess;
......@@ -10,7 +8,6 @@ import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
/**
* HTTP请求工具类
......@@ -31,7 +28,7 @@ public class HttpHelper {
java.net.HttpURLConnection httpConn = getConn(url);
return post(httpConn, jsonString);
} catch (Exception ex) {
throw new CodeException(ex);
throw new RuntimeException(ex);
}
}
......@@ -49,7 +46,7 @@ public class HttpHelper {
httpConn.setRequestProperty("Content-Type", "application/json");
return post(httpConn, jsonString);
} catch (Exception ex) {
throw new CodeException(ex);
throw new RuntimeException(ex);
}
}
......
package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.thread.ThreadHelper;
/**
* 重复执行工具类
*
* @author 颜佐光
*/
public class RunHelper {
......@@ -50,7 +50,7 @@ public class RunHelper {
}
}
if (ex != null) {
throw new CodeException(tag + ex.getMessage(), ex);
throw new RuntimeException(tag + ex.getMessage(), ex);
}
}
}
package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.exception.ExceptionHelper;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -910,7 +912,7 @@ public class StringHelper {
*/
public static String getNewMD5Id(Date date, Object... froms) {
if (date == null) {
throw new CodeException("生成时间搓 MD5 ID 时,时间不能为空");
throw new RuntimeException("生成时间搓 MD5 ID 时,时间不能为空");
}
String tag = getNewIdTag(date.getTime());
String id = md51(getId(froms));
......
package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.contants.SystemContants;
import com.yanzuoguang.util.exception.CodeException;
import java.net.*;
import java.util.*;
......@@ -33,7 +32,7 @@ public class UrlHelper {
}
return sb.toString();
} catch (Exception ex) {
throw new CodeException(ex);
throw new RuntimeException(ex);
}
}
......@@ -48,7 +47,7 @@ public class UrlHelper {
try {
return URLDecoder.decode(from, encoding);
} catch (Exception ex) {
throw new CodeException(ex);
throw new RuntimeException(ex);
}
}
......
package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.exception.CodeException;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
......@@ -39,10 +38,10 @@ public class ZipHelper {
*/
public static void zipDirectory(File dirFile, File zipFile, boolean isDir) throws IOException {
if (dirFile == null) {
throw new CodeException("压缩时文件夹对象不能为空。");
throw new RuntimeException("压缩时文件夹对象不能为空。");
}
if (!dirFile.isDirectory()) {
throw new CodeException("[" + dirFile.getName() + "]不是一个文件夹,或者不存在。");
throw new RuntimeException("[" + dirFile.getName() + "]不是一个文件夹,或者不存在。");
}
if (zipFile == null) {
zipFile = new File(dirFile.getAbsolutePath() + ".zip");
......@@ -158,7 +157,7 @@ public class ZipHelper {
if (flag) {
tempFile.renameTo(zipTo);
} else {
throw new CodeException("删除文件失败");
throw new RuntimeException("删除文件失败");
}
}
}
......@@ -216,7 +215,7 @@ public class ZipHelper {
*/
private static void zipFile(String sourcePath, File file, ZipOutputStream zipOutStream, BufferedOutputStream bufferOutStream) throws IOException {
if (!file.exists()) {
throw new CodeException("文件" + file.getAbsolutePath() + "不存在");
throw new RuntimeException("文件" + file.getAbsolutePath() + "不存在");
}
// 创建压缩文件实体
ZipEntry entry = new ZipEntry(sourcePath + file.getName());
......
package com.yanzuoguang.util.thread;
import com.yanzuoguang.util.exception.CodeException;
/**
* 根据指定的线程数量, 执行多个Runnable对象
*
* @author 颜佐光
*/
public class RunnableList extends AbstractThreadList<Runnable> {
......@@ -28,7 +27,7 @@ public class RunnableList extends AbstractThreadList<Runnable> {
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
throw new CodeException(ex.getMessage(), ex);
throw new RuntimeException(ex.getMessage(), ex);
}
}
}
package com.yanzuoguang.util.thread;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper;
import java.util.Date;
......@@ -158,7 +157,7 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
if (ex instanceof RuntimeException) {
throw (RuntimeException) ex;
} else {
throw new CodeException(ex.getMessage(), ex);
throw new RuntimeException(ex.getMessage(), ex);
}
}
......
......@@ -3,7 +3,6 @@ package com.yanzuoguang.util.vo;
import com.yanzuoguang.util.contants.ResultConstants;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
......
package helper;
import base.DemoVo;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.TypeHelper;
import com.yanzuoguang.util.vo.ResponseResult;
import helper.vo.ResponseDataMainResult;
......@@ -24,7 +23,7 @@ public class TestTypeHelper {
TypeHelper.printSuperClass(returnType);
boolean isSub = TypeHelper.isSubType(returnType, ResponseResult.class);
if (!isSub) {
throw new CodeException("泛型继承检测错误");
throw new RuntimeException("泛型继承检测错误");
}
}
}
package thread;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.log.Log;
import com.yanzuoguang.util.thread.RunnableListAuto;
import com.yanzuoguang.util.thread.ThreadHelper;
import org.junit.Test;
......@@ -28,7 +27,7 @@ public class TestRunnableListAuto {
public void test() {
try {
runTest(true);
throw new CodeException("没有抛出异常");
throw new RuntimeException("没有抛出异常");
} catch (Exception ex) {
// Log.error(TestRunnableListAuto.class, ex);
}
......
package com.yanzuoguang.cloud.aop;
import com.yanzuoguang.util.exception.CodeException;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
......@@ -20,7 +19,7 @@ public class HttpAspectUtil {
public static HttpServletRequest getRequest() {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attributes == null) {
throw new CodeException("监视错误");
throw new RuntimeException("监视错误");
}
return attributes.getRequest();
}
......
......@@ -6,7 +6,6 @@ import com.yanzuoguang.excel.ExcelConsole;
import com.yanzuoguang.excel.ExcelRow;
import com.yanzuoguang.excel.ExportBase;
import com.yanzuoguang.excel.ExportData;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper;
import javax.servlet.http.HttpServletResponse;
......@@ -75,7 +74,7 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> {
public static <T extends Object, M extends Object> void export(ExportBase<T> req, HttpServletResponse response, ExcelDao<T, M> excelDao) {
ExportData config = req.getConfig();
if (config == null) {
throw new CodeException("导出时请传入配置信息");
throw new RuntimeException("导出时请传入配置信息");
}
if (StringHelper.isEmpty(config.getServerPath())) {
config.setServerPath("/home/cache/");
......@@ -94,7 +93,7 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> {
excel.down(response);
} catch (IOException e) {
e.printStackTrace();
throw new CodeException("下载失败", e);
throw new RuntimeException("下载失败", e);
} finally {
// 删除生成的临时文件
excel.remove();
......
......@@ -4,7 +4,6 @@ import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.dao.impl.SqlData;
import com.yanzuoguang.dao.impl.SqlDataField;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper;
import java.util.ArrayList;
......@@ -71,7 +70,7 @@ public abstract class SqlCondBase<T extends SqlCondBase> implements SqlCond<T> {
@Override
public String getSql(String sql, SqlData sqlData, SqlDataField sqlDataField, Object model, Map<String, List<String>> codeMap) {
if (sqlDataField.getCond() != this) {
throw new CodeException("不能处理非本条件的字段");
throw new RuntimeException("不能处理非本条件的字段");
}
int condType = getCondType(model, sqlDataField);
switch (condType) {
......@@ -86,7 +85,7 @@ public abstract class SqlCondBase<T extends SqlCondBase> implements SqlCond<T> {
String fieldName = this.fields.isEmpty() ? StringHelper.EMPTY : this.fields.get(0);
// 判断代码片段是否合法
if (sqlDataField.getCodes().size() % 2 == 1) {
throw new CodeException("代码片段" + this.getClass().getSimpleName() + ":" + sqlData.getName() + ":" + fieldName + "为单数");
throw new RuntimeException("代码片段" + this.getClass().getSimpleName() + ":" + sqlData.getName() + ":" + fieldName + "为单数");
}
// 处理代码片段
for (int i = 0; i < sqlDataField.getCodes().size(); i = i + DaoConst.CODE_UNIT) {
......
......@@ -45,7 +45,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
*/
protected String getKey() {
if (this.table == null) {
throw new CodeException("类" + this.getClass().getName() + "未发现表结构");
throw new RuntimeException("类" + this.getClass().getName() + "未发现表结构");
}
return this.table.getTable().getKeyName();
}
......@@ -165,13 +165,13 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
public String update(Object model) {
String keyString = this.getKeyString(model);
if (StringHelper.isEmpty(keyString)) {
throw new CodeException("表" + this.table.getTable().getName() + "主键值为空时不能更新");
throw new RuntimeException("表" + this.table.getTable().getName() + "主键值为空时不能更新");
}
this.check(DaoConst.OPERATOR_TYPE_UPDATE, keyString, model);
SqlData sqlData = this.getSql(DaoConst.UPDATE);
int ret = updateSql(sqlData, model);
if (ret == 0) {
throw new CodeException("修改失败,请确认是否被其他人修改,版本号传入是否正确");
throw new RuntimeException("修改失败,请确认是否被其他人修改,版本号传入是否正确");
}
String retVal = ret > 0 ? keyString : "";
return retVal;
......@@ -851,7 +851,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
try {
from = cls.newInstance();
} catch (Exception ex) {
throw new CodeException("创建对象" + cls.getName() + "出错", ex);
throw new RuntimeException("创建对象" + cls.getName() + "出错", ex);
}
ObjectHelper.writeWithFrom(from, request);
return this.create(from);
......
......@@ -7,7 +7,6 @@ import com.yanzuoguang.db.DbExecute;
import com.yanzuoguang.db.impl.DbRow;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.cache.MemoryCache;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.ArrayHelper;
import com.yanzuoguang.util.helper.StringFormatHandle;
import com.yanzuoguang.util.helper.StringHelper;
......@@ -110,7 +109,7 @@ public abstract class BaseDaoSql {
protected TableSqlCache register(Class<?> clsModel) {
TableAnnotation annotation = clsModel.getAnnotation(TableAnnotation.class);
if (annotation == null) {
throw new CodeException("该页面未绑定表");
throw new RuntimeException("该页面未绑定表");
}
return this.register(annotation.value(), clsModel);
}
......@@ -148,11 +147,11 @@ public abstract class BaseDaoSql {
*/
protected SqlData getSql(String name, boolean isThrow) {
if (this.table == null) {
throw new CodeException("类" + this.getClass().getName() + "未发现表结构");
throw new RuntimeException("类" + this.getClass().getName() + "未发现表结构");
}
SqlData sql = this.table.getNameCache().get(name);
if (isThrow && sql == null) {
throw new CodeException("类" + this.getClass().getName() + "未发现SQL语句" + name);
throw new RuntimeException("类" + this.getClass().getName() + "未发现SQL语句" + name);
}
return sql;
}
......@@ -760,7 +759,7 @@ public abstract class BaseDaoSql {
sb.append("AVG");
break;
default:
throw new CodeException("统计类型[" + from.getGroupType() + "]不支持");
throw new RuntimeException("统计类型[" + from.getGroupType() + "]不支持");
}
sb.append("( CASE WHEN ");
sb.append(from.getCaseField());
......
......@@ -2,7 +2,6 @@ package com.yanzuoguang.dao.impl;
import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.util.cache.MemoryCache;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper;
import java.util.ArrayList;
......@@ -170,7 +169,7 @@ public class TableSqlCache {
for (String item : tableWhereField.getFields()) {
String name = item.toLowerCase();
if (!sqlFieldHas.containsKey(name)) {
throw new CodeException("SQL语句" + item + "不存在纬度" + item);
throw new RuntimeException("SQL语句" + item + "不存在纬度" + item);
}
sqlFieldWhere.put(name, true);
}
......@@ -196,7 +195,7 @@ public class TableSqlCache {
} else if (!StringHelper.isEmpty(this.table.getMD5KeyName())) {
addString(map, "{Key}", this.table.getMD5KeyName());
} else {
throw new CodeException("表中未包含MD5字段");
throw new RuntimeException("表中未包含MD5字段");
}
String lowerKey = this.table.getKeyName().toLowerCase();
......
package com.yanzuoguang.excel;
import com.yanzuoguang.db.impl.DbRow;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.CheckerHelper;
import com.yanzuoguang.util.helper.FileHelper;
import com.yanzuoguang.util.helper.StringHelper;
......@@ -164,7 +163,7 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
*/
protected void initExcel(TableHead head) {
if (this.workbook != null) {
throw new CodeException("Excel已初始化");
throw new RuntimeException("Excel已初始化");
}
// 创建合并对象数据检测
mergerGroup = new HashMap<>();
......@@ -379,13 +378,13 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
out.flush();
} catch (IOException e) {
e.printStackTrace();
throw new CodeException("保存失败");
throw new RuntimeException("保存失败");
} finally {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
throw new CodeException("保存失败");
throw new RuntimeException("保存失败");
}
return this;
}
......@@ -402,7 +401,7 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
File file = new File(this.getFileName());
if (file.exists()) {
if (!file.delete()) {
throw new CodeException("文件删除失败");
throw new RuntimeException("文件删除失败");
}
}
return this;
......
......@@ -2,7 +2,6 @@ package com.yanzuoguang.service.impl;
import com.yanzuoguang.dao.BaseDao;
import com.yanzuoguang.service.BaseService;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper;
import java.util.ArrayList;
......@@ -186,7 +185,7 @@ public abstract class BaseServiceImpl<T> implements BaseService<T> {
*/
private void check(String opTag, String serviceTag, Object id) {
if (StringHelper.isEmpty(id)) {
throw new CodeException(opTag + serviceTag + "失败,该数据可能已被修改");
throw new RuntimeException(opTag + serviceTag + "失败,该数据可能已被修改");
}
}
......
......@@ -16,7 +16,6 @@ import com.yanzuoguang.mq.vo.QueueVo;
import com.yanzuoguang.mq.vo.req.RegisterServerTokenReqVo;
import com.yanzuoguang.mq.vo.req.ServerMessageReqVo;
import com.yanzuoguang.mq.vo.req.ServerQueueReqVo;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.helper.StringHelper;
......
......@@ -2,7 +2,6 @@ package com.yanzuoguang.util;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.helper.StringFormatHandle;
import com.yanzuoguang.util.helper.StringHelper;
......@@ -68,7 +67,7 @@ public class PrinterHelper {
try {
pager = JsonHelper.deserialize(from.getPager(), PrinterPagerData.class);
} catch (Exception ex) {
throw new CodeException("不能识别模板", ex);
throw new RuntimeException("不能识别模板", ex);
}
// 设置偏移量
pager.setMarginTop(pager.getMarginTop() + top);
......
package com.yanzuoguang.util.printer.format;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper;
import java.util.HashMap;
......@@ -53,7 +52,7 @@ public class FormatCenter {
private String format(String command, String formatValue) {
this.initDefault();
if (StringHelper.isEmpty(command)) {
throw new CodeException("你需要格式化的字符串格式为空");
throw new RuntimeException("你需要格式化的字符串格式为空");
}
String[] commands = command.split(":");
String name = commands[0];
......@@ -63,7 +62,7 @@ public class FormatCenter {
}
FormatHandle formatHandle = cache.get(name);
if (formatHandle == null) {
throw new CodeException("需要格式化的字符串不支持");
throw new RuntimeException("需要格式化的字符串不支持");
}
return formatHandle.getFormat(name, format, formatValue);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment