增加SourceException

This commit is contained in:
Redkale
2022-12-23 21:12:10 +08:00
parent 48ba0edd2e
commit b656c8877b
13 changed files with 94 additions and 62 deletions

View File

@@ -746,7 +746,7 @@ public final class Application {
} }
} }
} }
logger.info("PropertiesAgent (type=" + this.propertiesAgent.getClass().getSimpleName() + ") load " + propCount + " data in " + (System.currentTimeMillis() - s) + " ms"); logger.info("PropertiesAgent (type = " + this.propertiesAgent.getClass().getSimpleName() + ") load " + propCount + " data in " + (System.currentTimeMillis() - s) + " ms");
} }
break; break;
} }

View File

@@ -91,7 +91,7 @@ public abstract class AbstractCacheSource extends AbstractService implements Cac
source = (CacheSource) sourceType.getConstructor().newInstance(); source = (CacheSource) sourceType.getConstructor().newInstance();
} }
if (source == null) { if (source == null) {
throw new RuntimeException("Not found CacheSourceProvider for config=" + sourceConf); throw new SourceException("Not found CacheSourceProvider for config=" + sourceConf);
} }
if (!compileMode && resourceFactory != null) { if (!compileMode && resourceFactory != null) {
resourceFactory.inject(sourceName, source); resourceFactory.inject(sourceName, source);

View File

@@ -149,7 +149,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
source = (DataSource) sourceType.getConstructor().newInstance(); source = (DataSource) sourceType.getConstructor().newInstance();
} }
if (source == null) { if (source == null) {
throw new RuntimeException("Not found DataSourceProvider for config=" + sourceConf); throw new SourceException("Not found DataSourceProvider for config=" + sourceConf);
} }
if (!compileMode && resourceFactory != null) { if (!compileMode && resourceFactory != null) {
resourceFactory.inject(sourceName, source); resourceFactory.inject(sourceName, source);
@@ -214,7 +214,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
} else if (url.startsWith("https://")) { } else if (url.startsWith("https://")) {
info.servaddr = new InetSocketAddress(url0, 443); info.servaddr = new InetSocketAddress(url0, 443);
} else { } else {
throw new RuntimeException(url + " parse port error"); throw new SourceException(url + " parse port error");
} }
return info; return info;
} }
@@ -363,7 +363,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
if (clazz == null) { if (clazz == null) {
clazz = val.getClass(); clazz = val.getClass();
if (clazz.getAnnotation(Entity.class) == null && clazz.getAnnotation(javax.persistence.Entity.class) == null) { if (clazz.getAnnotation(Entity.class) == null && clazz.getAnnotation(javax.persistence.Entity.class) == null) {
throw new RuntimeException("Entity Class " + clazz + " must be on Annotation @Entity"); throw new SourceException("Entity Class " + clazz + " must be on Annotation @Entity");
} }
continue; continue;
} }
@@ -373,7 +373,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
future.completeExceptionally(new RuntimeException("DataSource." + action + " must the same Class Entity, but diff is " + clazz + " and " + val.getClass())); future.completeExceptionally(new RuntimeException("DataSource." + action + " must the same Class Entity, but diff is " + clazz + " and " + val.getClass()));
return future; return future;
} }
throw new RuntimeException("DataSource." + action + " must the same Class Entity, but diff is " + clazz + " and " + val.getClass()); throw new SourceException("DataSource." + action + " must the same Class Entity, but diff is " + clazz + " and " + val.getClass());
} }
} }
return null; return null;
@@ -1338,7 +1338,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
for (T t : entitys) { for (T t : entitys) {
Objects.requireNonNull(t); Objects.requireNonNull(t);
if (t.getClass().getAnnotation(Entity.class) == null && t.getClass().getAnnotation(javax.persistence.Entity.class) == null) { if (t.getClass().getAnnotation(Entity.class) == null && t.getClass().getAnnotation(javax.persistence.Entity.class) == null) {
throw new RuntimeException("Entity Class " + t.getClass() + " must be on Annotation @Entity"); throw new SourceException("Entity Class " + t.getClass() + " must be on Annotation @Entity");
} }
this.actions.add(new InsertBatchAction1(t)); this.actions.add(new InsertBatchAction1(t));
} }
@@ -1350,7 +1350,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
for (T t : entitys) { for (T t : entitys) {
Objects.requireNonNull(t); Objects.requireNonNull(t);
if (t.getClass().getAnnotation(Entity.class) == null && t.getClass().getAnnotation(javax.persistence.Entity.class) == null) { if (t.getClass().getAnnotation(Entity.class) == null && t.getClass().getAnnotation(javax.persistence.Entity.class) == null) {
throw new RuntimeException("Entity Class " + t.getClass() + " must be on Annotation @Entity"); throw new SourceException("Entity Class " + t.getClass() + " must be on Annotation @Entity");
} }
this.actions.add(new DeleteBatchAction1(t)); this.actions.add(new DeleteBatchAction1(t));
} }
@@ -1361,10 +1361,10 @@ public abstract class AbstractDataSource extends AbstractService implements Data
public <T> DataBatch delete(Class<T> clazz, Serializable... pks) { public <T> DataBatch delete(Class<T> clazz, Serializable... pks) {
Objects.requireNonNull(clazz); Objects.requireNonNull(clazz);
if (clazz.getAnnotation(Entity.class) == null && clazz.getAnnotation(javax.persistence.Entity.class) == null) { if (clazz.getAnnotation(Entity.class) == null && clazz.getAnnotation(javax.persistence.Entity.class) == null) {
throw new RuntimeException("Entity Class " + clazz + " must be on Annotation @Entity"); throw new SourceException("Entity Class " + clazz + " must be on Annotation @Entity");
} }
if (pks.length < 1) { if (pks.length < 1) {
throw new RuntimeException("delete pk length is zero "); throw new SourceException("delete pk length is zero ");
} }
for (Serializable pk : pks) { for (Serializable pk : pks) {
Objects.requireNonNull(pk); Objects.requireNonNull(pk);
@@ -1382,7 +1382,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
public <T> DataBatch delete(Class<T> clazz, FilterNode node, Flipper flipper) { public <T> DataBatch delete(Class<T> clazz, FilterNode node, Flipper flipper) {
Objects.requireNonNull(clazz); Objects.requireNonNull(clazz);
if (clazz.getAnnotation(Entity.class) == null && clazz.getAnnotation(javax.persistence.Entity.class) == null) { if (clazz.getAnnotation(Entity.class) == null && clazz.getAnnotation(javax.persistence.Entity.class) == null) {
throw new RuntimeException("Entity Class " + clazz + " must be on Annotation @Entity"); throw new SourceException("Entity Class " + clazz + " must be on Annotation @Entity");
} }
this.actions.add(new DeleteBatchAction3(clazz, node, flipper)); this.actions.add(new DeleteBatchAction3(clazz, node, flipper));
return this; return this;
@@ -1393,7 +1393,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
for (T t : entitys) { for (T t : entitys) {
Objects.requireNonNull(t); Objects.requireNonNull(t);
if (t.getClass().getAnnotation(Entity.class) == null && t.getClass().getAnnotation(javax.persistence.Entity.class) == null) { if (t.getClass().getAnnotation(Entity.class) == null && t.getClass().getAnnotation(javax.persistence.Entity.class) == null) {
throw new RuntimeException("Entity Class " + t.getClass() + " must be on Annotation @Entity"); throw new SourceException("Entity Class " + t.getClass() + " must be on Annotation @Entity");
} }
this.actions.add(new UpdateBatchAction1(t)); this.actions.add(new UpdateBatchAction1(t));
} }
@@ -1409,11 +1409,11 @@ public abstract class AbstractDataSource extends AbstractService implements Data
public <T> DataBatch update(Class<T> clazz, Serializable pk, ColumnValue... values) { public <T> DataBatch update(Class<T> clazz, Serializable pk, ColumnValue... values) {
Objects.requireNonNull(clazz); Objects.requireNonNull(clazz);
if (clazz.getAnnotation(Entity.class) == null && clazz.getAnnotation(javax.persistence.Entity.class) == null) { if (clazz.getAnnotation(Entity.class) == null && clazz.getAnnotation(javax.persistence.Entity.class) == null) {
throw new RuntimeException("Entity Class " + clazz + " must be on Annotation @Entity"); throw new SourceException("Entity Class " + clazz + " must be on Annotation @Entity");
} }
Objects.requireNonNull(pk); Objects.requireNonNull(pk);
if (values.length < 1) { if (values.length < 1) {
throw new RuntimeException("update column-value length is zero "); throw new SourceException("update column-value length is zero ");
} }
for (ColumnValue val : values) { for (ColumnValue val : values) {
Objects.requireNonNull(val); Objects.requireNonNull(val);
@@ -1436,10 +1436,10 @@ public abstract class AbstractDataSource extends AbstractService implements Data
public <T> DataBatch update(Class<T> clazz, FilterNode node, Flipper flipper, ColumnValue... values) { public <T> DataBatch update(Class<T> clazz, FilterNode node, Flipper flipper, ColumnValue... values) {
Objects.requireNonNull(clazz); Objects.requireNonNull(clazz);
if (clazz.getAnnotation(Entity.class) == null && clazz.getAnnotation(javax.persistence.Entity.class) == null) { if (clazz.getAnnotation(Entity.class) == null && clazz.getAnnotation(javax.persistence.Entity.class) == null) {
throw new RuntimeException("Entity Class " + clazz + " must be on Annotation @Entity"); throw new SourceException("Entity Class " + clazz + " must be on Annotation @Entity");
} }
if (values.length < 1) { if (values.length < 1) {
throw new RuntimeException("update column-value length is zero "); throw new SourceException("update column-value length is zero ");
} }
for (ColumnValue val : values) { for (ColumnValue val : values) {
Objects.requireNonNull(val); Objects.requireNonNull(val);
@@ -1451,7 +1451,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
@Override @Override
public <T> DataBatch updateColumn(T entity, final String... columns) { public <T> DataBatch updateColumn(T entity, final String... columns) {
if (columns.length < 1) { if (columns.length < 1) {
throw new RuntimeException("update column length is zero "); throw new SourceException("update column length is zero ");
} }
for (String val : columns) { for (String val : columns) {
Objects.requireNonNull(val); Objects.requireNonNull(val);
@@ -1473,7 +1473,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
public <T> DataBatch updateColumn(T entity, final FilterNode node, SelectColumn selects) { public <T> DataBatch updateColumn(T entity, final FilterNode node, SelectColumn selects) {
Objects.requireNonNull(entity); Objects.requireNonNull(entity);
if (entity.getClass().getAnnotation(Entity.class) == null && entity.getClass().getAnnotation(javax.persistence.Entity.class) == null) { if (entity.getClass().getAnnotation(Entity.class) == null && entity.getClass().getAnnotation(javax.persistence.Entity.class) == null) {
throw new RuntimeException("Entity Class " + entity.getClass() + " must be on Annotation @Entity"); throw new SourceException("Entity Class " + entity.getClass() + " must be on Annotation @Entity");
} }
Objects.requireNonNull(selects); Objects.requireNonNull(selects);
this.actions.add(new UpdateBatchAction4(entity, node, selects)); this.actions.add(new UpdateBatchAction4(entity, node, selects));

View File

@@ -647,7 +647,7 @@ public final class CacheMemorySource extends AbstractCacheSource {
@Override @Override
public void mset(Object... keyVals) { public void mset(Object... keyVals) {
if (keyVals.length % 2 != 0) { if (keyVals.length % 2 != 0) {
throw new RuntimeException("key value must be paired"); throw new SourceException("key value must be paired");
} }
for (int i = 0; i < keyVals.length; i += 2) { for (int i = 0; i < keyVals.length; i += 2) {
String key = keyVals[i].toString(); String key = keyVals[i].toString();

View File

@@ -1021,7 +1021,7 @@ public class DataJdbcSource extends DataSqlSource {
slowLog(s, sqls); slowLog(s, sqls);
return rs; return rs;
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new SourceException(e);
} finally { } finally {
if (conn != null) writePool.offerConnection(conn); if (conn != null) writePool.offerConnection(conn);
} }
@@ -1054,7 +1054,7 @@ public class DataJdbcSource extends DataSqlSource {
slowLog(s, sql); slowLog(s, sql);
return rs; return rs;
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new SourceException(ex);
} finally { } finally {
if (conn != null) readPool.offerConnection(conn); if (conn != null) readPool.offerConnection(conn);
} }
@@ -1096,7 +1096,7 @@ public class DataJdbcSource extends DataSqlSource {
try { try {
return rr.next(); return rr.next();
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new SourceException(e);
} }
} }
@@ -1111,7 +1111,7 @@ public class DataJdbcSource extends DataSqlSource {
} }
return labels; return labels;
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new SourceException(e);
} }
} }
@@ -1120,7 +1120,7 @@ public class DataJdbcSource extends DataSqlSource {
try { try {
return rr.wasNull(); return rr.wasNull();
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new SourceException(e);
} }
} }
@@ -1129,7 +1129,7 @@ public class DataJdbcSource extends DataSqlSource {
try { try {
rr.close(); rr.close();
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new SourceException(e);
} }
} }
@@ -1138,7 +1138,7 @@ public class DataJdbcSource extends DataSqlSource {
try { try {
return rr.getObject(index); return rr.getObject(index);
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new SourceException(e);
} }
} }
@@ -1147,7 +1147,7 @@ public class DataJdbcSource extends DataSqlSource {
try { try {
return rr.getObject(column); return rr.getObject(column);
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new SourceException(e);
} }
} }
@@ -1200,7 +1200,7 @@ public class DataJdbcSource extends DataSqlSource {
try { try {
this.driver = DriverManager.getDriver(this.url); this.driver = DriverManager.getDriver(this.url);
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new SourceException(e);
} }
clientInfo.put("version", String.valueOf(urlVersion)); clientInfo.put("version", String.valueOf(urlVersion));
} }
@@ -1257,7 +1257,7 @@ public class DataJdbcSource extends DataSqlSource {
} catch (InterruptedException t) { } catch (InterruptedException t) {
logger.log(Level.WARNING, "take pooled connection error", t); logger.log(Level.WARNING, "take pooled connection error", t);
} }
if (conn == null) throw new RuntimeException("create pooled connection timeout"); if (conn == null) throw new SourceException("create pooled connection timeout");
} }
} }
if (conn != null) { if (conn != null) {
@@ -1275,7 +1275,7 @@ public class DataJdbcSource extends DataSqlSource {
conn = driver.connect(url, connectAttrs); conn = driver.connect(url, connectAttrs);
conn.setClientInfo(clientInfo); conn.setClientInfo(clientInfo);
} catch (SQLException ex) { } catch (SQLException ex) {
throw new RuntimeException(ex); throw new SourceException(ex);
} }
usingCounter.increment(); usingCounter.increment();
creatCounter.increment(); creatCounter.increment();

View File

@@ -152,7 +152,7 @@ public interface DataResultSet extends EntityInfo.DataResultSetRow {
} }
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(row.getEntityInfo() + "." + attr.field() + ".value=" + o + ": " + e.getMessage(), e.getCause()); throw new SourceException(row.getEntityInfo() + "." + attr.field() + ".value=" + o + ": " + e.getMessage(), e.getCause());
} }
return o; return o;
} }

View File

@@ -8,8 +8,7 @@ package org.redkale.source;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.util.*; import java.util.*;
import org.redkale.util.AnyValue; import org.redkale.util.*;
import org.redkale.util.RedkaleClassLoader;
/** /**
* 常量放入 AbstractDataSource 类中方法都已作废persistence.xml 采用 source.properties 代替 * 常量放入 AbstractDataSource 类中方法都已作废persistence.xml 采用 source.properties 代替
@@ -117,7 +116,7 @@ public final class DataSources {
// } // }
// String url = readprop.getProperty(JDBC_URL); // String url = readprop.getProperty(JDBC_URL);
// dbtype = AbstractDataSource.parseDbtype(url); // dbtype = AbstractDataSource.parseDbtype(url);
// if (dbtype == null) throw new RuntimeException("not found datasource implements class, url=" + url); // if (dbtype == null) throw new SourceException("not found datasource implements class, url=" + url);
// //
// RedkaleClassLoader.putServiceLoader(DataSourceProvider.class); // RedkaleClassLoader.putServiceLoader(DataSourceProvider.class);
// Class dsClass = null; // Class dsClass = null;
@@ -144,7 +143,7 @@ public final class DataSources {
// dsClass = provider.sourceClass(); // dsClass = provider.sourceClass();
// if (dsClass != null) break; // if (dsClass != null) break;
// } // }
// if (dsClass == null) throw new RuntimeException("not found datasource implements ServiceLoader, url=" + url); // if (dsClass == null) throw new SourceException("not found datasource implements ServiceLoader, url=" + url);
// impl = dsClass.getName(); // impl = dsClass.getName();
// } // }
// try { // try {
@@ -252,7 +251,7 @@ public final class DataSources {
} catch (RuntimeException e) { } catch (RuntimeException e) {
throw e; throw e;
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new SourceException(ex);
} }
} }
@@ -316,7 +315,7 @@ public final class DataSources {
} }
in.close(); in.close();
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new SourceException(ex);
} }
return map; return map;
} }

View File

@@ -141,11 +141,11 @@ public abstract class DataSqlSource extends AbstractDataSource implements Functi
//不支持读写分离模式的动态切换 //不支持读写分离模式的动态切换
if (readConfProps == writeConfProps if (readConfProps == writeConfProps
&& (events[0].name().startsWith("read.") || events[0].name().startsWith("write."))) { && (events[0].name().startsWith("read.") || events[0].name().startsWith("write."))) {
throw new RuntimeException("DataSource(name=" + resourceName() + ") not support to change to read/write separation mode"); throw new SourceException("DataSource(name=" + resourceName() + ") not support to change to read/write separation mode");
} }
if (readConfProps != writeConfProps if (readConfProps != writeConfProps
&& (!events[0].name().startsWith("read.") && !events[0].name().startsWith("write."))) { && (!events[0].name().startsWith("read.") && !events[0].name().startsWith("write."))) {
throw new RuntimeException("DataSource(name=" + resourceName() + ") not support to change to non read/write separation mode"); throw new SourceException("DataSource(name=" + resourceName() + ") not support to change to non read/write separation mode");
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@@ -1305,7 +1305,7 @@ public abstract class DataSqlSource extends AbstractDataSource implements Functi
for (ColumnValue col : values) { for (ColumnValue col : values) {
if (col == null) continue; if (col == null) continue;
Attribute<T, Serializable> attr = info.getUpdateAttribute(col.getColumn()); Attribute<T, Serializable> attr = info.getUpdateAttribute(col.getColumn());
if (attr == null) throw new RuntimeException(info.getType() + " cannot found column " + col.getColumn()); if (attr == null) throw new SourceException(info.getType() + " cannot found column " + col.getColumn());
if (setsql.length() > 0) setsql.append(", "); if (setsql.length() > 0) setsql.append(", ");
String sqlColumn = info.getSQLColumn(null, col.getColumn()); String sqlColumn = info.getSQLColumn(null, col.getColumn());
if (col.getValue() instanceof byte[]) { if (col.getValue() instanceof byte[]) {
@@ -1316,7 +1316,7 @@ public abstract class DataSqlSource extends AbstractDataSource implements Functi
setsql.append(sqlColumn).append("=").append(info.formatSQLValue(sqlColumn, attr, col, sqlFormatter)); setsql.append(sqlColumn).append("=").append(info.formatSQLValue(sqlColumn, attr, col, sqlFormatter));
} }
} }
if (setsql.length() < 1) throw new RuntimeException("update non column-value array"); if (setsql.length() < 1) throw new SourceException("update non column-value array");
String sql = "UPDATE " + info.getTable(pk) + " SET " + setsql + " WHERE " + info.getPrimarySQLColumn() + "=" + info.formatSQLValue(info.getPrimarySQLColumn(), pk, sqlFormatter); String sql = "UPDATE " + info.getTable(pk) + " SET " + setsql + " WHERE " + info.getPrimarySQLColumn() + "=" + info.formatSQLValue(info.getPrimarySQLColumn(), pk, sqlFormatter);
return new SqlInfo(sql, blobs); return new SqlInfo(sql, blobs);
} }
@@ -1387,7 +1387,7 @@ public abstract class DataSqlSource extends AbstractDataSource implements Functi
setsql.append(sqlColumn).append("=").append(info.formatSQLValue(sqlColumn, attr, col, sqlFormatter)); setsql.append(sqlColumn).append("=").append(info.formatSQLValue(sqlColumn, attr, col, sqlFormatter));
} }
} }
if (setsql.length() < 1) throw new RuntimeException("update non column-value array"); if (setsql.length() < 1) throw new SourceException("update non column-value array");
Map<Class, String> joinTabalis = node == null ? null : node.getJoinTabalis(); Map<Class, String> joinTabalis = node == null ? null : node.getJoinTabalis();
CharSequence join = node == null ? null : node.createSQLJoin(this, true, joinTabalis, new HashSet<>(), info); CharSequence join = node == null ? null : node.createSQLJoin(this, true, joinTabalis, new HashSet<>(), info);
CharSequence where = node == null ? null : node.createSQLExpress(this, info, joinTabalis); CharSequence where = node == null ? null : node.createSQLExpress(this, info, joinTabalis);
@@ -1433,7 +1433,7 @@ public abstract class DataSqlSource extends AbstractDataSource implements Functi
final EntityInfo<T> info = loadEntityInfo(clazz); final EntityInfo<T> info = loadEntityInfo(clazz);
String illegalColumn = checkIllegalColumn(info, selects); String illegalColumn = checkIllegalColumn(info, selects);
if (illegalColumn != null) { if (illegalColumn != null) {
throw new RuntimeException(info.getType() + " cannot found column " + illegalColumn); throw new SourceException(info.getType() + " cannot found column " + illegalColumn);
} }
if (isOnlyCache(info)) return updateCache(info, -1, false, entity, null, selects); if (isOnlyCache(info)) return updateCache(info, -1, false, entity, null, selects);
return this.updateColumnCompose(info, false, entity, null, selects).whenComplete((rs, t) -> { return this.updateColumnCompose(info, false, entity, null, selects).whenComplete((rs, t) -> {
@@ -1480,7 +1480,7 @@ public abstract class DataSqlSource extends AbstractDataSource implements Functi
final EntityInfo<T> info = loadEntityInfo(clazz); final EntityInfo<T> info = loadEntityInfo(clazz);
String illegalColumn = checkIllegalColumn(info, selects); String illegalColumn = checkIllegalColumn(info, selects);
if (illegalColumn != null) { if (illegalColumn != null) {
throw new RuntimeException(info.getType() + " cannot found column " + illegalColumn); throw new SourceException(info.getType() + " cannot found column " + illegalColumn);
} }
if (isOnlyCache(info)) return updateCache(info, -1, true, entity, node, selects); if (isOnlyCache(info)) return updateCache(info, -1, true, entity, node, selects);
return this.updateColumnCompose(info, true, entity, node, selects).whenComplete((rs, t) -> { return this.updateColumnCompose(info, true, entity, node, selects).whenComplete((rs, t) -> {

View File

@@ -503,7 +503,7 @@ public final class EntityCache<T> {
OptionalDouble rs = stream.mapToDouble(x -> (Double) attrFunc.apply(x)).average(); OptionalDouble rs = stream.mapToDouble(x -> (Double) attrFunc.apply(x)).average();
return rs.isPresent() ? rs.getAsDouble() : defResult; return rs.isPresent() ? rs.getAsDouble() : defResult;
} }
throw new RuntimeException("getNumberResult error(type:" + type + ", attr.type: " + attrType); throw new SourceException("getNumberResult error(type:" + type + ", attr.type: " + attrType);
case COUNT: case COUNT:
return stream.count(); return stream.count();
case DISTINCTCOUNT: case DISTINCTCOUNT:
@@ -526,7 +526,7 @@ public final class EntityCache<T> {
OptionalDouble rs = stream.mapToDouble(x -> (Double) attrFunc.apply(x)).max(); OptionalDouble rs = stream.mapToDouble(x -> (Double) attrFunc.apply(x)).max();
return rs.isPresent() ? rs.getAsDouble() : defResult; return rs.isPresent() ? rs.getAsDouble() : defResult;
} }
throw new RuntimeException("getNumberResult error(type:" + type + ", attr.type: " + attrType); throw new SourceException("getNumberResult error(type:" + type + ", attr.type: " + attrType);
case MIN: case MIN:
if (attrType == int.class || attrType == Integer.class || attrType == AtomicInteger.class) { if (attrType == int.class || attrType == Integer.class || attrType == AtomicInteger.class) {
@@ -545,7 +545,7 @@ public final class EntityCache<T> {
OptionalDouble rs = stream.mapToDouble(x -> (Double) attrFunc.apply(x)).min(); OptionalDouble rs = stream.mapToDouble(x -> (Double) attrFunc.apply(x)).min();
return rs.isPresent() ? rs.getAsDouble() : defResult; return rs.isPresent() ? rs.getAsDouble() : defResult;
} }
throw new RuntimeException("getNumberResult error(type:" + type + ", attr.type: " + attrType); throw new SourceException("getNumberResult error(type:" + type + ", attr.type: " + attrType);
case SUM: case SUM:
if (attrType == int.class || attrType == Integer.class || attrType == AtomicInteger.class) { if (attrType == int.class || attrType == Integer.class || attrType == AtomicInteger.class) {
@@ -559,7 +559,7 @@ public final class EntityCache<T> {
} else if (attrType == double.class || attrType == Double.class) { } else if (attrType == double.class || attrType == Double.class) {
return stream.mapToDouble(x -> (Double) attrFunc.apply(x)).sum(); return stream.mapToDouble(x -> (Double) attrFunc.apply(x)).sum();
} }
throw new RuntimeException("getNumberResult error(type:" + type + ", attr.type: " + attrType); throw new SourceException("getNumberResult error(type:" + type + ", attr.type: " + attrType);
} }
return defResult; return defResult;
} }
@@ -980,13 +980,13 @@ public final class EntityCache<T> {
} else if (pattr.type() == double.class || pattr.type() == Double.class) { } else if (pattr.type() == double.class || pattr.type() == Double.class) {
getter = x -> Math.abs(((Number) pattr.get((T) x)).doubleValue()); getter = x -> Math.abs(((Number) pattr.get((T) x)).doubleValue());
} else { } else {
throw new RuntimeException("Flipper not supported sort illegal type by ABS (" + flipper.getSort() + ")"); throw new SourceException("Flipper not supported sort illegal type by ABS (" + flipper.getSort() + ")");
} }
attr = (Attribute<T, Serializable>) Attribute.create(pattr.declaringClass(), pattr.field(), pattr.type(), getter, (o, v) -> pattr.set(o, v)); attr = (Attribute<T, Serializable>) Attribute.create(pattr.declaringClass(), pattr.field(), pattr.type(), getter, (o, v) -> pattr.set(o, v));
} else if (func.isEmpty()) { } else if (func.isEmpty()) {
attr = pattr; attr = pattr;
} else { } else {
throw new RuntimeException("Flipper not supported sort illegal function (" + flipper.getSort() + ")"); throw new SourceException("Flipper not supported sort illegal function (" + flipper.getSort() + ")");
} }
} }
Comparator<T> c = (sub.length > 1 && sub[1].equalsIgnoreCase("DESC")) ? (T o1, T o2) -> { Comparator<T> c = (sub.length > 1 && sub[1].equalsIgnoreCase("DESC")) ? (T o1, T o2) -> {

View File

@@ -309,7 +309,7 @@ public final class EntityInfo<T> {
} else { } else {
this.fullloader = fullloader; this.fullloader = fullloader;
if (tableName0 != null && !tableName0.isEmpty() && tableName0.indexOf('.') >= 0) { if (tableName0 != null && !tableName0.isEmpty() && tableName0.indexOf('.') >= 0) {
throw new RuntimeException(type + " have illegal table.name on @Table"); throw new SourceException(type + " have illegal table.name on @Table");
} }
this.table = (tableCcatalog0 == null) ? type.getSimpleName().toLowerCase() : (tableCcatalog0.isEmpty()) ? (tableName0.isEmpty() ? type.getSimpleName().toLowerCase() : tableName0) : (tableCcatalog0 + '.' + (tableName0.isEmpty() ? type.getSimpleName().toLowerCase() : tableName0)); this.table = (tableCcatalog0 == null) ? type.getSimpleName().toLowerCase() : (tableCcatalog0.isEmpty()) ? (tableName0.isEmpty() ? type.getSimpleName().toLowerCase() : tableName0) : (tableCcatalog0 + '.' + (tableName0.isEmpty() ? type.getSimpleName().toLowerCase() : tableName0));
} }
@@ -405,20 +405,20 @@ public final class EntityInfo<T> {
attributeMap.put(fieldname, attr); attributeMap.put(fieldname, attr);
} }
} while ((cltmp = cltmp.getSuperclass()) != Object.class); } while ((cltmp = cltmp.getSuperclass()) != Object.class);
if (idAttr0 == null) throw new RuntimeException(type.getName() + " have no primary column by @org.redkale.persistence.Id"); if (idAttr0 == null) throw new SourceException(type.getName() + " have no primary column by @org.redkale.persistence.Id");
cltmp = type; cltmp = type;
JsonConvert convert = DEFAULT_JSON_CONVERT; JsonConvert convert = DEFAULT_JSON_CONVERT;
do { do {
for (Method method : cltmp.getDeclaredMethods()) { for (Method method : cltmp.getDeclaredMethods()) {
if (method.getAnnotation(SourceConvert.class) == null) continue; if (method.getAnnotation(SourceConvert.class) == null) continue;
if (!Modifier.isStatic(method.getModifiers())) throw new RuntimeException("@SourceConvert method(" + method + ") must be static"); if (!Modifier.isStatic(method.getModifiers())) throw new SourceException("@SourceConvert method(" + method + ") must be static");
if (method.getReturnType() != JsonConvert.class) throw new RuntimeException("@SourceConvert method(" + method + ") must be return JsonConvert.class"); if (method.getReturnType() != JsonConvert.class) throw new SourceException("@SourceConvert method(" + method + ") must be return JsonConvert.class");
if (method.getParameterCount() > 0) throw new RuntimeException("@SourceConvert method(" + method + ") must be 0 parameter"); if (method.getParameterCount() > 0) throw new SourceException("@SourceConvert method(" + method + ") must be 0 parameter");
try { try {
method.setAccessible(true); method.setAccessible(true);
convert = (JsonConvert) method.invoke(null); convert = (JsonConvert) method.invoke(null);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(method + " invoke error", e); throw new SourceException(method + " invoke error", e);
} }
if (convert != null) break; if (convert != null) break;
} }

View File

@@ -170,7 +170,7 @@ public class FilterNode { //FilterNode 不能实现Serializable接口 否则
} }
protected FilterNode any(FilterNode node, boolean signor) { protected FilterNode any(FilterNode node, boolean signor) {
if (this.readOnly) throw new RuntimeException("FilterNode(" + this + ") is ReadOnly"); if (this.readOnly) throw new SourceException("FilterNode(" + this + ") is ReadOnly");
Objects.requireNonNull(node); Objects.requireNonNull(node);
if (this.column == null) { if (this.column == null) {
this.column = node.column; this.column = node.column;
@@ -692,7 +692,7 @@ public class FilterNode { //FilterNode 不能实现Serializable接口 否则
if (len == 0 && express == NOTIN) return null; if (len == 0 && express == NOTIN) return null;
final Class compType = valtype.getComponentType(); final Class compType = valtype.getComponentType();
if (atype != compType && len > 0) { if (atype != compType && len > 0) {
if (!compType.isPrimitive() && Number.class.isAssignableFrom(compType)) throw new RuntimeException("param(" + val0 + ") type not match " + atype + " for column " + column); if (!compType.isPrimitive() && Number.class.isAssignableFrom(compType)) throw new SourceException("param(" + val0 + ") type not match " + atype + " for column " + column);
if (atype == int.class || atype == Integer.class) { if (atype == int.class || atype == Integer.class) {
int[] vs = new int[len]; int[] vs = new int[len];
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
@@ -786,7 +786,7 @@ public class FilterNode { //FilterNode 不能实现Serializable接口 否则
final Serializable val = (Serializable) val0; final Serializable val = (Serializable) val0;
final boolean fk = (val instanceof FilterKey); final boolean fk = (val instanceof FilterKey);
final Attribute<T, Serializable> fkattr = fk ? cache.getAttribute(((FilterKey) val).getColumn()) : null; final Attribute<T, Serializable> fkattr = fk ? cache.getAttribute(((FilterKey) val).getColumn()) : null;
if (fk && fkattr == null) throw new RuntimeException(cache.getType() + " not found column(" + ((FilterKey) val).getColumn() + ")"); if (fk && fkattr == null) throw new SourceException(cache.getType() + " not found column(" + ((FilterKey) val).getColumn() + ")");
switch (express) { switch (express) {
case EQUAL: case EQUAL:
return fk ? new Predicate<T>() { return fk ? new Predicate<T>() {
@@ -1075,7 +1075,7 @@ public class FilterNode { //FilterNode 不能实现Serializable接口 否则
} }
}; };
default: default:
throw new RuntimeException("(" + fv0 + ")'s express illegal, must be =, !=, <, >, <=, >="); throw new SourceException("(" + fv0 + ")'s express illegal, must be =, !=, <, >, <=, >=");
} }
case FV_DIV: case FV_DIV:
FilterValue fv1 = (FilterValue) val; FilterValue fv1 = (FilterValue) val;
@@ -1159,7 +1159,7 @@ public class FilterNode { //FilterNode 不能实现Serializable接口 否则
} }
}; };
default: default:
throw new RuntimeException("(" + fv1 + ")'s express illegal, must be =, !=, <, >, <=, >="); throw new SourceException("(" + fv1 + ")'s express illegal, must be =, !=, <, >, <=, >=");
} }
case OPAND: case OPAND:
return fk ? new Predicate<T>() { return fk ? new Predicate<T>() {

View File

@@ -227,7 +227,7 @@ public final class FilterNodeBean<T extends FilterBean> implements Comparable<Fi
if (groups.length == 0) groups = new String[]{"[AND]"}; if (groups.length == 0) groups = new String[]{"[AND]"};
for (String key : groups) { for (String key : groups) {
if (!key.startsWith("[AND]") && !key.startsWith("[OR]")) { if (!key.startsWith("[AND]") && !key.startsWith("[OR]")) {
throw new RuntimeException(field + "'s FilterGroup.value(" + key + ") illegal, must be [AND] or [OR] startsWith"); throw new SourceException(field + "'s FilterGroup.value(" + key + ") illegal, must be [AND] or [OR] startsWith");
} }
FilterNodeBean node = nodemap.get(key); FilterNodeBean node = nodemap.get(key);
if (node == null) { if (node == null) {

View File

@@ -0,0 +1,33 @@
/*
*
*/
package org.redkale.source;
/**
* 数据源自定义异常类
*
* <p>
* 详情见: https://redkale.org
*
* @author zhangjx
*
* @since 2.8.0
*/
public class SourceException extends RuntimeException {
public SourceException() {
super();
}
public SourceException(String s) {
super(s);
}
public SourceException(String message, Throwable cause) {
super(message, cause);
}
public SourceException(Throwable cause) {
super(cause);
}
}