use of io.shardingjdbc.core.exception.ShardingJdbcException in project sharding-jdbc by shardingjdbc.
the class TableRule method generateDataNodes.
private List<DataNode> generateDataNodes(final List<String> actualDataNodes, final Collection<String> dataSourceNames) {
List<DataNode> result = new LinkedList<>();
for (String each : actualDataNodes) {
DataNode dataNode = new DataNode(each);
if (!dataSourceNames.contains(dataNode.getDataSourceName())) {
throw new ShardingJdbcException("Cannot find data source in sharding rule, invalid actual data node is: '%s'", each);
}
result.add(dataNode);
}
return result;
}
use of io.shardingjdbc.core.exception.ShardingJdbcException in project sharding-jdbc by shardingjdbc.
the class ExecuteEventListener method handle.
private void handle(final AbstractSQLExecutionEvent event, final String operation) {
Tracer tracer = ShardingJDBCTracer.get();
switch(event.getEventExecutionType()) {
case BEFORE_EXECUTE:
if (ExecutorDataMap.getDataMap().containsKey(SNAPSHOT_DATA_KEY) && !isCurrentMainThread()) {
trunkInBranchContainer.set(((ActiveSpan.Continuation) ExecutorDataMap.getDataMap().get(SNAPSHOT_DATA_KEY)).activate());
}
branchContainer.set(tracer.buildSpan("/SJDBC/BRANCH/" + operation).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).withTag(Tags.PEER_HOSTNAME.getKey(), event.getDataSource()).withTag(Tags.COMPONENT.getKey(), "ShardingJDBC").withTag(Tags.DB_INSTANCE.getKey(), event.getDataSource()).withTag(Tags.DB_TYPE.getKey(), "sql").withTag(Tags.DB_STATEMENT.getKey(), event.getSql()).startManual());
break;
case EXECUTE_FAILURE:
Span span = branchContainer.get();
span.setTag(Tags.ERROR.getKey(), true);
if (event.getException().isPresent()) {
span.log(System.currentTimeMillis(), log(event.getException().get()));
}
finish();
break;
case EXECUTE_SUCCESS:
finish();
break;
default:
throw new ShardingJdbcException("Unsupported event type");
}
}
use of io.shardingjdbc.core.exception.ShardingJdbcException in project sharding-jdbc by shardingjdbc.
the class ExecuteEventListener method listenOverall.
/**
* listen overall sql execution event.
*
* @param event Overall sql execution event.
*/
@Subscribe
@AllowConcurrentEvents
public void listenOverall(final OverallExecutionEvent event) {
Tracer tracer = ShardingJDBCTracer.get();
ActiveSpan activeSpan;
switch(event.getEventExecutionType()) {
case BEFORE_EXECUTE:
activeSpan = tracer.buildSpan("/SJDBC/TRUNK/" + event.getSqlType().name()).withTag(Tags.COMPONENT.getKey(), "ShardingJDBC").startActive();
trunkContainer.set(activeSpan);
if (isParallelExecute(event)) {
ExecutorDataMap.getDataMap().put(SNAPSHOT_DATA_KEY, activeSpan.capture());
}
break;
case EXECUTE_FAILURE:
activeSpan = trunkContainer.get();
activeSpan.setTag(Tags.ERROR.getKey(), true);
if (event.getException().isPresent()) {
activeSpan.log(System.currentTimeMillis(), log(event.getException().get()));
}
deactivate();
break;
case EXECUTE_SUCCESS:
deactivate();
break;
default:
throw new ShardingJdbcException("Unsupported event type");
}
}
use of io.shardingjdbc.core.exception.ShardingJdbcException in project sharding-jdbc by shardingjdbc.
the class PropertyUtil method v2.
private static Object v2(final Environment environment, final String prefix, final Class<?> targetClass) {
try {
Class<?> binderClass = Class.forName("org.springframework.boot.context.properties.bind.Binder");
Method getMethod = binderClass.getDeclaredMethod("get", Environment.class);
Method bindMethod = binderClass.getDeclaredMethod("bind", String.class, Class.class);
Object binderObject = getMethod.invoke(null, environment);
String prefixParam = prefix.endsWith(".") ? prefix.substring(0, prefix.length() - 1) : prefix;
Object bindResultObject = bindMethod.invoke(binderObject, prefixParam, targetClass);
Method resultGetMethod = bindResultObject.getClass().getDeclaredMethod("get");
return resultGetMethod.invoke(bindResultObject);
} catch (final ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
throw new ShardingJdbcException(ex.getMessage(), ex);
}
}
use of io.shardingjdbc.core.exception.ShardingJdbcException in project sharding-jdbc by shardingjdbc.
the class MasterSlaveLoadBalanceAlgorithmGsonTypeAdapter method read.
@Override
public MasterSlaveLoadBalanceAlgorithm read(final JsonReader in) throws IOException {
String masterSlaveLoadBalanceAlgorithmClassName = null;
in.beginObject();
while (in.hasNext()) {
Preconditions.checkArgument("masterSlaveLoadBalanceAlgorithm".equals(in.nextName()));
masterSlaveLoadBalanceAlgorithmClassName = in.nextString();
}
in.endObject();
try {
return Strings.isNullOrEmpty(masterSlaveLoadBalanceAlgorithmClassName) ? null : (MasterSlaveLoadBalanceAlgorithm) Class.forName(masterSlaveLoadBalanceAlgorithmClassName).newInstance();
} catch (ReflectiveOperationException ex) {
throw new ShardingJdbcException(ex);
}
}
Aggregations