use of io.mycat.backend.mysql.nio.handler.SecondHandler in project Mycat_plus by coderczp.
the class DruidMycatRouteStrategy method middlerResultRoute.
private RouteResultset middlerResultRoute(final SchemaConfig schema, final String charset, final SQLSelect sqlselect, final int sqlType, final SQLStatement statement, final ServerConnection sc) {
final String middlesql = SQLUtils.toMySqlString(sqlselect);
MiddlerResultHandler<String> middlerResultHandler = new MiddlerQueryResultHandler<>(new SecondHandler() {
@Override
public void doExecute(List param) {
sc.getSession2().setMiddlerResultHandler(null);
String sqls = null;
// 路由计算
RouteResultset rrs = null;
try {
sqls = buildSql(statement, sqlselect, param);
rrs = MycatServer.getInstance().getRouterservice().route(MycatServer.getInstance().getConfig().getSystem(), schema, sqlType, sqls.toLowerCase(), charset, sc);
} catch (Exception e) {
StringBuilder s = new StringBuilder();
LOGGER.warn(s.append(this).append(sqls).toString() + " err:" + e.toString(), e);
String msg = e.getMessage();
sc.writeErrMessage(ErrorCode.ER_PARSE_ERROR, msg == null ? e.getClass().getSimpleName() : msg);
return;
}
NonBlockingSession noBlockSession = new NonBlockingSession(sc.getSession2().getSource());
noBlockSession.setMiddlerResultHandler(null);
// session的预编译标示传递
noBlockSession.setPrepared(sc.getSession2().isPrepared());
if (rrs != null) {
noBlockSession.setCanClose(false);
noBlockSession.execute(rrs, ServerParse.SELECT);
}
}
});
sc.getSession2().setMiddlerResultHandler(middlerResultHandler);
sc.getSession2().setCanClose(false);
// 路由计算
RouteResultset rrs = null;
try {
rrs = MycatServer.getInstance().getRouterservice().route(MycatServer.getInstance().getConfig().getSystem(), schema, ServerParse.SELECT, middlesql, charset, sc);
} catch (Exception e) {
StringBuilder s = new StringBuilder();
LOGGER.warn(s.append(this).append(middlesql).toString() + " err:" + e.toString(), e);
String msg = e.getMessage();
sc.writeErrMessage(ErrorCode.ER_PARSE_ERROR, msg == null ? e.getClass().getSimpleName() : msg);
return null;
}
if (rrs != null) {
rrs.setCacheAble(false);
}
return rrs;
}
use of io.mycat.backend.mysql.nio.handler.SecondHandler in project Mycat-Server by MyCATApache.
the class DruidMycatRouteStrategy method middlerResultRoute.
private RouteResultset middlerResultRoute(final SchemaConfig schema, final String charset, final SQLSelect sqlselect, final int sqlType, final SQLStatement statement, final ServerConnection sc) {
final String middlesql = SQLUtils.toMySqlString(sqlselect);
MiddlerResultHandler<String> middlerResultHandler = new MiddlerQueryResultHandler<>(new SecondHandler() {
@Override
public void doExecute(List param) {
sc.getSession2().setMiddlerResultHandler(null);
String sqls = null;
// 路由计算
RouteResultset rrs = null;
try {
sqls = buildSql(statement, sqlselect, param);
rrs = MycatServer.getInstance().getRouterservice().route(MycatServer.getInstance().getConfig().getSystem(), schema, sqlType, sqls.toLowerCase(), charset, sc);
} catch (Exception e) {
StringBuilder s = new StringBuilder();
LOGGER.warn(s.append(this).append(sqls).toString() + " err:" + e.toString(), e);
String msg = e.getMessage();
sc.writeErrMessage(ErrorCode.ER_PARSE_ERROR, msg == null ? e.getClass().getSimpleName() : msg);
return;
}
NonBlockingSession noBlockSession = new NonBlockingSession(sc.getSession2().getSource());
noBlockSession.setMiddlerResultHandler(null);
// session的预编译标示传递
noBlockSession.setPrepared(sc.getSession2().isPrepared());
if (rrs != null) {
noBlockSession.setCanClose(false);
noBlockSession.execute(rrs, ServerParse.SELECT);
}
}
});
sc.getSession2().setMiddlerResultHandler(middlerResultHandler);
sc.getSession2().setCanClose(false);
// 路由计算
RouteResultset rrs = null;
try {
rrs = MycatServer.getInstance().getRouterservice().route(MycatServer.getInstance().getConfig().getSystem(), schema, ServerParse.SELECT, middlesql, charset, sc);
} catch (Exception e) {
StringBuilder s = new StringBuilder();
LOGGER.warn(s.append(this).append(middlesql).toString() + " err:" + e.toString(), e);
String msg = e.getMessage();
sc.writeErrMessage(ErrorCode.ER_PARSE_ERROR, msg == null ? e.getClass().getSimpleName() : msg);
return null;
}
if (rrs != null) {
rrs.setCacheAble(false);
}
return rrs;
}
Aggregations