Skip to content

Commit

Permalink
401
Browse files Browse the repository at this point in the history
  • Loading branch information
youtongluan committed Feb 19, 2024
1 parent 5b63a67 commit 8fd26a8
Show file tree
Hide file tree
Showing 59 changed files with 100 additions and 96 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,6 @@ v3.2.0
v4.0.0
1、增加aop拦截器
2、将sumk工程拆分为base、framewrok、db、http、rpc五个工程,加上早就分出去的async-logger、sumk-rpc-mina,总共7个

v4.0.1
1、取消SumkException的code为负数的限制,并且将内置的负数改为正数
2 changes: 1 addition & 1 deletion async-logger/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.youtongluan</groupId>
<artifactId>sumk</artifactId>
<version>4.0.0</version>
<version>4.0.1</version>
</parent>
<artifactId>async-logger</artifactId>
<name>com.github.youtongluan:sumk</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private LogLevel fromLocationAwareLoggerInt(int logger_int) {
case LocationAwareLogger.ERROR_INT:
return LogLevel.ERROR;
default:
throw new SumkException(-34523521, logger_int + "不是有效的日志级别");
throw new SumkException(34523521, logger_int + "不是有效的日志级别");
}
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.youtongluan</groupId>
<artifactId>sumk</artifactId>
<version>4.0.0</version>
<version>4.0.1</version>
<packaging>pom</packaging>

<name>com.github.youtongluan:sumk</name>
Expand Down
2 changes: 1 addition & 1 deletion sumk-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.youtongluan</groupId>
<artifactId>sumk</artifactId>
<version>4.0.0</version>
<version>4.0.1</version>
</parent>
<artifactId>sumk-base</artifactId>
<name>com.github.youtongluan:sumk</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public ActionContext clone() {
try {
return (ActionContext) super.clone();
} catch (CloneNotSupportedException e) {
throw new SumkException(-8234235, "clone not supported");
throw new SumkException(8234235, "clone not supported");
}
}
}
2 changes: 1 addition & 1 deletion sumk-base/src/main/java/org/yx/base/date/TimeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

public class TimeUtil {

public static final int DATETIME_CONVERT = -912753916;
public static final int DATETIME_CONVERT = 912753916;

public static boolean isGenericDate(Class<?> type) {
return type == Date.class || type == java.sql.Date.class || type == Time.class || type == Timestamp.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Collection<String> apply(Collection<String> packageNames) {
}
file = new File(url.toURI());
if (!file.exists()) {
throw new SumkException(-9723423, file.getAbsolutePath() + " is not a file");
throw new SumkException(9723423, file.getAbsolutePath() + " is not a file");
}
this.parseFile(classNameList, file, packagePath);
}
Expand Down
2 changes: 1 addition & 1 deletion sumk-base/src/main/java/org/yx/conf/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public final class Const {

public static final String DEFAULT_DB_NAME = "sumk";

public static final int SUMK_VERSION = 0x400;
public static final int SUMK_VERSION = 0x401;

public static String sumkVersion() {
return new StringBuilder(10).append((Const.SUMK_VERSION >> 8) & 0x0F).append('.')
Expand Down
10 changes: 5 additions & 5 deletions sumk-base/src/main/java/org/yx/exception/SumkException.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ public class SumkException extends CodeException {
private static final long serialVersionUID = 3453246435546L;

public SumkException(int code, String msg) {
super(negative(code), msg);
super(stringCode(code), msg);
}

public SumkException(int code, String msg, Throwable exception) {
super(negative(code), msg, exception);
super(stringCode(code), msg, exception);
}

private static String negative(int code) {
return code > 0 ? String.valueOf(-code) : String.valueOf(code);
private static String stringCode(int code) {
return String.valueOf(code);
}

public static SumkException wrap(Throwable e) {
if (e instanceof SumkException) {
throw (SumkException) e;
}
return new SumkException(-34534565, e.getMessage(), e);
return new SumkException(34534565, e.getMessage(), e);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ public interface SumkExceptionCode {
/**
* 存在多个bean
*/
int TOO_MANY_BEAN = -912753951;
int TOO_MANY_BEAN = 912753951;

/**
* 数据库连接已经关闭
*/
int DB_CONNECTION_CLOSED = -912753820;
int DB_CONNECTION_CLOSED = 912753820;

/**
* 数据库queryOne()的时候,返回的结果不止一条
*/
int DB_TOO_MANY_RESULTS = -912753811;
int DB_TOO_MANY_RESULTS = 912753811;

/**
* redis连接异常
*/
int REDIS_DIS_CONNECTION = -912753701;
int REDIS_DIS_CONNECTION = 912753701;

}
4 changes: 2 additions & 2 deletions sumk-base/src/main/java/org/yx/util/BitUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class BitUtil {

public static int setBit(int flag, int rightCount, boolean value) {
if (rightCount < 1 || rightCount > 32) {
throw new SumkException(-23436546, "bit要在1-32之间,实际却是" + rightCount);
throw new SumkException(23436546, "bit要在1-32之间,实际却是" + rightCount);
}
int v = 1 << (rightCount - 1);
if (value) {
Expand All @@ -17,7 +17,7 @@ public static int setBit(int flag, int rightCount, boolean value) {

public static boolean getBit(int flag, int rightCount) {
if (rightCount < 1 || rightCount > 32) {
throw new SumkException(-23436546, "bit要在1-32之间,实际却是" + rightCount);
throw new SumkException(23436546, "bit要在1-32之间,实际却是" + rightCount);
}
int v = 1 << (rightCount - 1);
return (flag & v) != 0;
Expand Down
2 changes: 1 addition & 1 deletion sumk-base/src/main/java/org/yx/util/SumkDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
public final class SumkDate implements Comparable<SumkDate>, Serializable {
private static final long serialVersionUID = 100L;

public static final int SUMKDATE_ERROR_CODE = -912753954;
public static final int SUMKDATE_ERROR_CODE = 912753954;

private static final String LOG_NAME = "sumk.date";

Expand Down
2 changes: 1 addition & 1 deletion sumk-db/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.youtongluan</groupId>
<artifactId>sumk</artifactId>
<version>4.0.0</version>
<version>4.0.1</version>
</parent>
<artifactId>sumk-db</artifactId>
<name>com.github.youtongluan:sumk</name>
Expand Down
2 changes: 1 addition & 1 deletion sumk-db/src/main/java/org/yx/db/conn/SumkDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public <T> T unwrap(Class<T> iface) throws SQLException {
if (iface.isInstance(proxy)) {
return iface.cast(proxy);
}
throw new SumkException(-234345, this.getClass().getSimpleName() + " does not wrap " + iface.getName());
throw new SumkException(234345, this.getClass().getSimpleName() + " does not wrap " + iface.getName());
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion sumk-db/src/main/java/org/yx/db/event/ModifyEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public int flag() {
*/
public void setBoolean(int slot, boolean h) {
if (slot < 29 || slot > 32) {
throw new SumkException(-346243451, "slot必须在29-32之间,实际却是:" + slot);
throw new SumkException(346243451, "slot必须在29-32之间,实际却是:" + slot);
}
this.flag = BitUtil.setBit(flag, slot, h);
}
Expand Down
4 changes: 2 additions & 2 deletions sumk-db/src/main/java/org/yx/db/mapper/SqlParsers.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public final class SqlParsers {

public static Predicate<Map<String, Object>> createParamExpression(String test, String matchType) {
if (test == null || test.isEmpty()) {
throw new SumkException(-34645465, "if中的test不能为空");
throw new SumkException(34645465, "if中的test不能为空");
}
test = StringUtil.toLatin(test.trim());
boolean and = test.contains(SPLIT_AND);
boolean or = test.contains("|");
if (and && or) {
throw new SumkException(-34645465, "if的test不能同时出现,和|");
throw new SumkException(34645465, "if的test不能同时出现,和|");
}
return createParamExpression(test, matchType, !or);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public DocumentBuilder get() {
return this.create();
} catch (Exception e) {
Logs.db().error(e.toString(), e);
throw new SumkException(-7623435, "创建XmlDocumentBuilder失败");
throw new SumkException(7623435, "创建XmlDocumentBuilder失败");
}
}

Expand Down
4 changes: 2 additions & 2 deletions sumk-db/src/main/java/org/yx/db/mapper/SqlXmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void parseXml(Map<String, SqlParser> map, DocumentBuilder dbd, Str
SqlParser parser = compose(parseSqlNode(el.getChildNodes()));
if (parser != null) {
if (map.putIfAbsent(name(namespace, el.getAttribute(ID)), parser) != null) {
throw new SumkException(-1435436,
throw new SumkException(1435436,
fileName + "-" + name(namespace, el.getAttribute(ID)) + " is duplicate");
}
}
Expand Down Expand Up @@ -140,7 +140,7 @@ private static List<SqlParser> parseSqlNode(NodeList sqlNodeList)
add(list, forEach(el));
break;
default:
throw new SumkException(-1874546534, el + "不是有效的tag");
throw new SumkException(1874546534, el + "不是有效的tag");
}
}
return list;
Expand Down
10 changes: 5 additions & 5 deletions sumk-db/src/main/java/org/yx/db/sql/AbstractSqlBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected void checkMap(Map<String, ?> map, PojoMeta pm) {
Set<String> keys = map.keySet();
for (String key : keys) {
if (pm.getByFieldName(key) == null) {
throw new SumkException(-743257, key + " is not a field in " + pm.pojoClz.getName());
throw new SumkException(743257, key + " is not a field in " + pm.pojoClz.getName());
}
}
}
Expand All @@ -66,12 +66,12 @@ protected void failIfNotAllowPropertyMiss(String key) {
}
String msg = this.pojoMeta == null ? key + " is not a field"
: key + " is not a field in " + pojoMeta.pojoClz.getName();
throw new SumkException(-743257, msg);
throw new SumkException(743257, msg);
}

protected void checkIn() {
if (CollectionUtil.isEmpty(this.in)) {
throw new SumkException(-7345245, "no conditions");
throw new SumkException(7345245, "no conditions");
}
}

Expand All @@ -94,7 +94,7 @@ protected Map<String, Object> populate(Object src, boolean keepNull) {
try {
return this.makeSurePojoMeta().populate(src, keepNull);
} catch (Exception e) {
throw new SumkException(-42534254, e.getMessage(), e);
throw new SumkException(42534254, e.getMessage(), e);
}
}

Expand Down Expand Up @@ -145,7 +145,7 @@ protected T accept(SumkDbVisitor<T> visitor) {
if (e instanceof SumkException) {
throw (SumkException) e;
}
throw new SumkException(-53172189, e.getMessage(), e);
throw new SumkException(53172189, e.getMessage(), e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion sumk-db/src/main/java/org/yx/db/sql/ColumnOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public CharSequence buildSql(SelectBuilder select, List<Object> paramters) {
ColumnMeta cm = select.pojoMeta.getByFieldName(name);
if (cm == null) {
if (select.isOn(DBFlag.FAIL_IF_PROPERTY_NOT_MAPPED)) {
throw new SumkException(-54675234, name + "这个字段没有在" + select.pojoMeta.pojoClz.getName() + "中定义");
throw new SumkException(54675234, name + "这个字段没有在" + select.pojoMeta.pojoClz.getName() + "中定义");
}
return "";
}
Expand Down
2 changes: 1 addition & 1 deletion sumk-db/src/main/java/org/yx/db/sql/Insert.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected MapedSql batchInsert() throws Exception {
map.put(key, value);
}
if (map.isEmpty()) {
throw new SumkException(-829341, "存在无效的待插入记录");
throw new SumkException(829341, "存在无效的待插入记录");
}
cacheList.add(map);
if (softDeleteAndNotProvided) {
Expand Down
4 changes: 2 additions & 2 deletions sumk-db/src/main/java/org/yx/db/sql/Select.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public Select orderByDesc(String field) {
public Select offset(int offset) {
if (this.isOn(DBFlag.SELECT_IGNORE_MAX_OFFSET)) {
if (offset < 0 || offset > DBSettings.MaxOffset()) {
throw new SumkException(-235345347,
throw new SumkException(235345347,
"offset需要在0-" + DBSettings.MaxOffset() + "之间,通过ignoreMaxOffset(true)可以取消这个限制");
}
}
Expand All @@ -297,7 +297,7 @@ public Select offset(int offset) {
public Select limit(int limit) {
if (this.isOn(DBFlag.SELECT_IGNORE_MAX_LIMIT)) {
if (limit <= 0 || limit > DBSettings.MaxLimit()) {
throw new SumkException(-235345346,
throw new SumkException(235345346,
"limit需要在1-" + DBSettings.MaxLimit() + "之间,通过ignoreMaxLimit(true)可以取消这个限制");
}
}
Expand Down
6 changes: 3 additions & 3 deletions sumk-db/src/main/java/org/yx/db/sql/SelectBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected CharSequence buildWhere(List<Object> paramters) {
ItemJoiner joiner = new ItemJoiner(" AND ", null, null);
joiner.appendNotEmptyItem(buildEquals(paramters)).appendNotEmptyItem(buildCompare(paramters));
if (joiner.isEmpty() && !this.isOn(DBFlag.SELECT_ALLOW_EMPTY_WHERE)) {
throw new SumkException(-63254325, "empty where");
throw new SumkException(63254325, "empty where");
}
return joiner.appendNotEmptyItem(buildValid(paramters)).toCharSequence();
}
Expand Down Expand Up @@ -173,7 +173,7 @@ private CharSequence parseEqual(Map<String, Object> src, List<Object> paramters)
ColumnMeta cm = pojoMeta.getByFieldName(filedName);
if (cm == null) {
if (this.isOn(DBFlag.FAIL_IF_PROPERTY_NOT_MAPPED)) {
throw new SumkException(-7331234, filedName + "这个字段没有在java的pojo类中定义");
throw new SumkException(7331234, filedName + "这个字段没有在java的pojo类中定义");
}
continue;
}
Expand Down Expand Up @@ -202,7 +202,7 @@ public Order(String name, boolean desc) {
public String toString(PojoMeta pm) {
ColumnMeta cm = pm.getByFieldName(name);
if (cm == null) {
throw new SumkException(-4532018, "排序字段" + name + "不在" + pm.pojoClz.getName() + "字段中");
throw new SumkException(4532018, "排序字段" + name + "不在" + pm.pojoClz.getName() + "字段中");
}
String dbName = cm.dbColumn;
if (desc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Object parseValue(Class<?> type, String value) {
if (Float.class == type || float.class == type) {
return Float.valueOf(value);
}
throw new SumkException(-6234267, type.getName() + " is not supported by soft delete");
throw new SumkException(6234267, type.getName() + " is not supported by soft delete");
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions sumk-db/src/main/java/org/yx/db/sql/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public MapedSql toMapedSql() throws Exception {
this.updateTo = Collections.emptyMap();
}
if (this.updateTo.isEmpty() && CollectionUtil.isEmpty(this.incrMap)) {
throw new SumkException(-3464601, "updateTo is null or empty");
throw new SumkException(3464601, "updateTo is null or empty");
}

this.checkMap(this.updateTo, this.pojoMeta);
Expand Down Expand Up @@ -215,7 +215,7 @@ protected MapedSql _toMapedSql() throws Exception {
}
CharSequence whereStr = orItem.toCharSequence();
if (whereStr == null || whereStr.length() == 0) {
throw new SumkException(-7345445, "where cannot be null");
throw new SumkException(7345445, "where cannot be null");
}
sb.append(whereStr);
mapedSql.sql = sb.toString();
Expand Down
6 changes: 3 additions & 3 deletions sumk-db/src/main/java/org/yx/db/sumk/batis/ProxySession.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ProxySession implements SqlSession {

@Override
public Connection getConnection() {
throw new SumkException(-148675, "getConnection not support");
throw new SumkException(148675, "getConnection not support");
}

protected SqlSession readSession() {
Expand All @@ -44,7 +44,7 @@ protected SqlSession readSession() {
return SqlSessionFactory.get(context.getDbName()).openSession(context.connection(DBType.READ_PREFER));
} catch (SQLException e) {
Log.get("sumk.mybatis").error(e.getMessage(), e);
throw new SumkException(-345254, "创建mybatis的读session失败");
throw new SumkException(345254, "创建mybatis的读session失败");
}
}

Expand All @@ -54,7 +54,7 @@ protected SqlSession writeSession() {
return SqlSessionFactory.get(context.getDbName()).openSession(context.connection(DBType.WRITE));
} catch (SQLException e) {
Log.get("sumk.mybatis").error(e.getMessage(), e);
throw new SumkException(-345255, "创建mybatis的写session失败");
throw new SumkException(345255, "创建mybatis的写session失败");
}
}

Expand Down
2 changes: 1 addition & 1 deletion sumk-db/src/main/java/org/yx/db/visit/ResultSetUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static List<Map<ColumnMeta, Object>> toMapList(ResultSet rs, PojoMeta pm)
for (int i = 1; i <= columnCount; i++) {
ColumnMeta cm = pm.getByColumnDBName(md.getColumnName(i));
if (cm == null) {
throw new SumkException(-629234, md.getColumnName(i) + "这个字段没有在java的pojo类中定义");
throw new SumkException(629234, md.getColumnName(i) + "这个字段没有在java的pojo类中定义");
}
columns[i] = cm;
}
Expand Down
Loading

0 comments on commit 8fd26a8

Please sign in to comment.