增加SourceException
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public abstract class AbstractCacheSource extends AbstractService implements Cac
|
||||
source = (CacheSource) sourceType.getConstructor().newInstance();
|
||||
}
|
||||
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) {
|
||||
resourceFactory.inject(sourceName, source);
|
||||
|
||||
@@ -149,7 +149,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
|
||||
source = (DataSource) sourceType.getConstructor().newInstance();
|
||||
}
|
||||
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) {
|
||||
resourceFactory.inject(sourceName, source);
|
||||
@@ -214,7 +214,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
|
||||
} else if (url.startsWith("https://")) {
|
||||
info.servaddr = new InetSocketAddress(url0, 443);
|
||||
} else {
|
||||
throw new RuntimeException(url + " parse port error");
|
||||
throw new SourceException(url + " parse port error");
|
||||
}
|
||||
return info;
|
||||
}
|
||||
@@ -363,7 +363,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
|
||||
if (clazz == null) {
|
||||
clazz = val.getClass();
|
||||
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;
|
||||
}
|
||||
@@ -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()));
|
||||
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;
|
||||
@@ -1338,7 +1338,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
|
||||
for (T t : entitys) {
|
||||
Objects.requireNonNull(t);
|
||||
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));
|
||||
}
|
||||
@@ -1350,7 +1350,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
|
||||
for (T t : entitys) {
|
||||
Objects.requireNonNull(t);
|
||||
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));
|
||||
}
|
||||
@@ -1361,10 +1361,10 @@ public abstract class AbstractDataSource extends AbstractService implements Data
|
||||
public <T> DataBatch delete(Class<T> clazz, Serializable... pks) {
|
||||
Objects.requireNonNull(clazz);
|
||||
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) {
|
||||
throw new RuntimeException("delete pk length is zero ");
|
||||
throw new SourceException("delete pk length is zero ");
|
||||
}
|
||||
for (Serializable pk : pks) {
|
||||
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) {
|
||||
Objects.requireNonNull(clazz);
|
||||
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));
|
||||
return this;
|
||||
@@ -1393,7 +1393,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
|
||||
for (T t : entitys) {
|
||||
Objects.requireNonNull(t);
|
||||
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));
|
||||
}
|
||||
@@ -1409,11 +1409,11 @@ public abstract class AbstractDataSource extends AbstractService implements Data
|
||||
public <T> DataBatch update(Class<T> clazz, Serializable pk, ColumnValue... values) {
|
||||
Objects.requireNonNull(clazz);
|
||||
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);
|
||||
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) {
|
||||
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) {
|
||||
Objects.requireNonNull(clazz);
|
||||
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) {
|
||||
throw new RuntimeException("update column-value length is zero ");
|
||||
throw new SourceException("update column-value length is zero ");
|
||||
}
|
||||
for (ColumnValue val : values) {
|
||||
Objects.requireNonNull(val);
|
||||
@@ -1451,7 +1451,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
|
||||
@Override
|
||||
public <T> DataBatch updateColumn(T entity, final String... columns) {
|
||||
if (columns.length < 1) {
|
||||
throw new RuntimeException("update column length is zero ");
|
||||
throw new SourceException("update column length is zero ");
|
||||
}
|
||||
for (String val : columns) {
|
||||
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) {
|
||||
Objects.requireNonNull(entity);
|
||||
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);
|
||||
this.actions.add(new UpdateBatchAction4(entity, node, selects));
|
||||
|
||||
@@ -647,7 +647,7 @@ public final class CacheMemorySource extends AbstractCacheSource {
|
||||
@Override
|
||||
public void mset(Object... keyVals) {
|
||||
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) {
|
||||
String key = keyVals[i].toString();
|
||||
|
||||
@@ -1021,7 +1021,7 @@ public class DataJdbcSource extends DataSqlSource {
|
||||
slowLog(s, sqls);
|
||||
return rs;
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new SourceException(e);
|
||||
} finally {
|
||||
if (conn != null) writePool.offerConnection(conn);
|
||||
}
|
||||
@@ -1054,7 +1054,7 @@ public class DataJdbcSource extends DataSqlSource {
|
||||
slowLog(s, sql);
|
||||
return rs;
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
throw new SourceException(ex);
|
||||
} finally {
|
||||
if (conn != null) readPool.offerConnection(conn);
|
||||
}
|
||||
@@ -1096,7 +1096,7 @@ public class DataJdbcSource extends DataSqlSource {
|
||||
try {
|
||||
return rr.next();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new SourceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1111,7 +1111,7 @@ public class DataJdbcSource extends DataSqlSource {
|
||||
}
|
||||
return labels;
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new SourceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1120,7 +1120,7 @@ public class DataJdbcSource extends DataSqlSource {
|
||||
try {
|
||||
return rr.wasNull();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new SourceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1129,7 +1129,7 @@ public class DataJdbcSource extends DataSqlSource {
|
||||
try {
|
||||
rr.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new SourceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1138,7 +1138,7 @@ public class DataJdbcSource extends DataSqlSource {
|
||||
try {
|
||||
return rr.getObject(index);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new SourceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1147,7 +1147,7 @@ public class DataJdbcSource extends DataSqlSource {
|
||||
try {
|
||||
return rr.getObject(column);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new SourceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1200,7 +1200,7 @@ public class DataJdbcSource extends DataSqlSource {
|
||||
try {
|
||||
this.driver = DriverManager.getDriver(this.url);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new SourceException(e);
|
||||
}
|
||||
clientInfo.put("version", String.valueOf(urlVersion));
|
||||
}
|
||||
@@ -1257,7 +1257,7 @@ public class DataJdbcSource extends DataSqlSource {
|
||||
} catch (InterruptedException 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) {
|
||||
@@ -1275,7 +1275,7 @@ public class DataJdbcSource extends DataSqlSource {
|
||||
conn = driver.connect(url, connectAttrs);
|
||||
conn.setClientInfo(clientInfo);
|
||||
} catch (SQLException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
throw new SourceException(ex);
|
||||
}
|
||||
usingCounter.increment();
|
||||
creatCounter.increment();
|
||||
|
||||
@@ -152,7 +152,7 @@ public interface DataResultSet extends EntityInfo.DataResultSetRow {
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,7 @@ package org.redkale.source;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import org.redkale.util.AnyValue;
|
||||
import org.redkale.util.RedkaleClassLoader;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
* 常量放入 AbstractDataSource 类中,方法都已作废,persistence.xml 采用 source.properties 代替
|
||||
@@ -117,7 +116,7 @@ public final class DataSources {
|
||||
// }
|
||||
// String url = readprop.getProperty(JDBC_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);
|
||||
// Class dsClass = null;
|
||||
@@ -144,7 +143,7 @@ public final class DataSources {
|
||||
// dsClass = provider.sourceClass();
|
||||
// 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();
|
||||
// }
|
||||
// try {
|
||||
@@ -252,7 +251,7 @@ public final class DataSources {
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
throw new SourceException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,7 +315,7 @@ public final class DataSources {
|
||||
}
|
||||
in.close();
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
throw new SourceException(ex);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -141,11 +141,11 @@ public abstract class DataSqlSource extends AbstractDataSource implements Functi
|
||||
//不支持读写分离模式的动态切换
|
||||
if (readConfProps == writeConfProps
|
||||
&& (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
|
||||
&& (!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();
|
||||
@@ -1305,7 +1305,7 @@ public abstract class DataSqlSource extends AbstractDataSource implements Functi
|
||||
for (ColumnValue col : values) {
|
||||
if (col == null) continue;
|
||||
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(", ");
|
||||
String sqlColumn = info.getSQLColumn(null, col.getColumn());
|
||||
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));
|
||||
}
|
||||
}
|
||||
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);
|
||||
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));
|
||||
}
|
||||
}
|
||||
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();
|
||||
CharSequence join = node == null ? null : node.createSQLJoin(this, true, joinTabalis, new HashSet<>(), info);
|
||||
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);
|
||||
String illegalColumn = checkIllegalColumn(info, selects);
|
||||
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);
|
||||
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);
|
||||
String illegalColumn = checkIllegalColumn(info, selects);
|
||||
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);
|
||||
return this.updateColumnCompose(info, true, entity, node, selects).whenComplete((rs, t) -> {
|
||||
|
||||
@@ -503,7 +503,7 @@ public final class EntityCache<T> {
|
||||
OptionalDouble rs = stream.mapToDouble(x -> (Double) attrFunc.apply(x)).average();
|
||||
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:
|
||||
return stream.count();
|
||||
case DISTINCTCOUNT:
|
||||
@@ -526,7 +526,7 @@ public final class EntityCache<T> {
|
||||
OptionalDouble rs = stream.mapToDouble(x -> (Double) attrFunc.apply(x)).max();
|
||||
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:
|
||||
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();
|
||||
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:
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
@@ -980,13 +980,13 @@ public final class EntityCache<T> {
|
||||
} else if (pattr.type() == double.class || pattr.type() == Double.class) {
|
||||
getter = x -> Math.abs(((Number) pattr.get((T) x)).doubleValue());
|
||||
} 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));
|
||||
} else if (func.isEmpty()) {
|
||||
attr = pattr;
|
||||
} 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) -> {
|
||||
|
||||
@@ -309,7 +309,7 @@ public final class EntityInfo<T> {
|
||||
} else {
|
||||
this.fullloader = fullloader;
|
||||
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));
|
||||
}
|
||||
@@ -405,20 +405,20 @@ public final class EntityInfo<T> {
|
||||
attributeMap.put(fieldname, attr);
|
||||
}
|
||||
} 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;
|
||||
JsonConvert convert = DEFAULT_JSON_CONVERT;
|
||||
do {
|
||||
for (Method method : cltmp.getDeclaredMethods()) {
|
||||
if (method.getAnnotation(SourceConvert.class) == null) continue;
|
||||
if (!Modifier.isStatic(method.getModifiers())) throw new RuntimeException("@SourceConvert method(" + method + ") must be static");
|
||||
if (method.getReturnType() != JsonConvert.class) throw new RuntimeException("@SourceConvert method(" + method + ") must be return JsonConvert.class");
|
||||
if (method.getParameterCount() > 0) throw new RuntimeException("@SourceConvert method(" + method + ") must be 0 parameter");
|
||||
if (!Modifier.isStatic(method.getModifiers())) throw new SourceException("@SourceConvert method(" + method + ") must be static");
|
||||
if (method.getReturnType() != JsonConvert.class) throw new SourceException("@SourceConvert method(" + method + ") must be return JsonConvert.class");
|
||||
if (method.getParameterCount() > 0) throw new SourceException("@SourceConvert method(" + method + ") must be 0 parameter");
|
||||
try {
|
||||
method.setAccessible(true);
|
||||
convert = (JsonConvert) method.invoke(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(method + " invoke error", e);
|
||||
throw new SourceException(method + " invoke error", e);
|
||||
}
|
||||
if (convert != null) break;
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ public class FilterNode { //FilterNode 不能实现Serializable接口, 否则
|
||||
}
|
||||
|
||||
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);
|
||||
if (this.column == null) {
|
||||
this.column = node.column;
|
||||
@@ -692,7 +692,7 @@ public class FilterNode { //FilterNode 不能实现Serializable接口, 否则
|
||||
if (len == 0 && express == NOTIN) return null;
|
||||
final Class compType = valtype.getComponentType();
|
||||
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) {
|
||||
int[] vs = new int[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
@@ -786,7 +786,7 @@ public class FilterNode { //FilterNode 不能实现Serializable接口, 否则
|
||||
final Serializable val = (Serializable) val0;
|
||||
final boolean fk = (val instanceof FilterKey);
|
||||
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) {
|
||||
case EQUAL:
|
||||
return fk ? new Predicate<T>() {
|
||||
@@ -1075,7 +1075,7 @@ public class FilterNode { //FilterNode 不能实现Serializable接口, 否则
|
||||
}
|
||||
};
|
||||
default:
|
||||
throw new RuntimeException("(" + fv0 + ")'s express illegal, must be =, !=, <, >, <=, >=");
|
||||
throw new SourceException("(" + fv0 + ")'s express illegal, must be =, !=, <, >, <=, >=");
|
||||
}
|
||||
case FV_DIV:
|
||||
FilterValue fv1 = (FilterValue) val;
|
||||
@@ -1159,7 +1159,7 @@ public class FilterNode { //FilterNode 不能实现Serializable接口, 否则
|
||||
}
|
||||
};
|
||||
default:
|
||||
throw new RuntimeException("(" + fv1 + ")'s express illegal, must be =, !=, <, >, <=, >=");
|
||||
throw new SourceException("(" + fv1 + ")'s express illegal, must be =, !=, <, >, <=, >=");
|
||||
}
|
||||
case OPAND:
|
||||
return fk ? new Predicate<T>() {
|
||||
|
||||
@@ -227,7 +227,7 @@ public final class FilterNodeBean<T extends FilterBean> implements Comparable<Fi
|
||||
if (groups.length == 0) groups = new String[]{"[AND]"};
|
||||
for (String key : groups) {
|
||||
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);
|
||||
if (node == null) {
|
||||
|
||||
33
src/main/java/org/redkale/source/SourceException.java
Normal file
33
src/main/java/org/redkale/source/SourceException.java
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user