Search in sources :

Example 1 with EngineCtx

use of io.mycat.sqlengine.EngineCtx in project Mycat-Server by MyCATApache.

the class ShareRowOutPutDataHandler method processSQL.

public void processSQL(String sql, EngineCtx ctx) {
    String ssql = joinParser.getSql();
    getRoute(ssql);
    RouteResultsetNode[] nodes = rrs.getNodes();
    if (nodes == null || nodes.length == 0 || nodes[0].getName() == null || nodes[0].getName().equals("")) {
        ctx.getSession().getSource().writeErrMessage(ErrorCode.ER_NO_DB_ERROR, "No dataNode found ,please check tables defined in schema:" + ctx.getSession().getSource().getSchema());
        return;
    }
    this.ctx = ctx;
    String[] dataNodes = getDataNodes();
    maxjob = dataNodes.length;
    ShareDBJoinHandler joinHandler = new ShareDBJoinHandler(this, joinParser.getJoinLkey());
    ctx.executeNativeSQLSequnceJob(dataNodes, ssql, joinHandler);
    EngineCtx.LOGGER.info("Catlet exec:" + getDataNode(getDataNodes()) + " sql:" + ssql);
    ctx.setAllJobFinishedListener(new AllJobFinishedListener() {

        @Override
        public void onAllJobFinished(EngineCtx ctx) {
            if (!jointTableIsData) {
                ctx.writeHeader(fields);
            }
            ctx.writeEof();
            EngineCtx.LOGGER.info("发送数据OK");
        }
    });
}
Also used : RouteResultsetNode(io.mycat.route.RouteResultsetNode) AllJobFinishedListener(io.mycat.sqlengine.AllJobFinishedListener) EngineCtx(io.mycat.sqlengine.EngineCtx)

Example 2 with EngineCtx

use of io.mycat.sqlengine.EngineCtx in project Mycat-Server by MyCATApache.

the class HintCatletHandler method route.

/**
	 * 从全局的schema列表中查询指定的schema是否存在, 如果存在则替换connection属性中原有的schema,
	 * 如果不存在,则throws SQLNonTransientException,表示指定的schema 不存在
	 * 
	 * @param sysConfig
	 * @param schema
	 * @param sqlType
	 * @param realSQL
	 * @param charset
	 * @param info
	 * @param cachePool
	 * @param hintSQLValue
	 * @return
	 * @throws SQLNonTransientException
	 */
@Override
public RouteResultset route(SystemConfig sysConfig, SchemaConfig schema, int sqlType, String realSQL, String charset, ServerConnection sc, LayerCachePool cachePool, String hintSQLValue, int hintSqlType, Map hintMap) throws SQLNonTransientException {
    // sc.setEngineCtx ctx
    String cateletClass = hintSQLValue;
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("load catelet class:" + hintSQLValue + " to run sql " + realSQL);
    }
    try {
        Catlet catlet = (Catlet) MycatServer.getInstance().getCatletClassLoader().getInstanceofClass(cateletClass);
        catlet.route(sysConfig, schema, sqlType, realSQL, charset, sc, cachePool);
        catlet.processSQL(realSQL, new EngineCtx(sc.getSession2()));
    } catch (Exception e) {
        LOGGER.warn("catlet error " + e);
        throw new SQLNonTransientException(e);
    }
    return null;
}
Also used : SQLNonTransientException(java.sql.SQLNonTransientException) Catlet(io.mycat.catlets.Catlet) EngineCtx(io.mycat.sqlengine.EngineCtx) SQLNonTransientException(java.sql.SQLNonTransientException)

Example 3 with EngineCtx

use of io.mycat.sqlengine.EngineCtx in project Mycat-Server by MyCATApache.

the class MyRowOutPutDataHandler method processSQL.

public void processSQL(String sql, EngineCtx ctx) {
    DirectDBJoinHandler joinHandler = new DirectDBJoinHandler(ctx);
    String[] dataNodes = { "dn1", "dn2", "dn3" };
    ctx.executeNativeSQLSequnceJob(dataNodes, sql, joinHandler);
    ctx.setAllJobFinishedListener(new AllJobFinishedListener() {

        @Override
        public void onAllJobFinished(EngineCtx ctx) {
            ctx.writeEof();
        }
    });
}
Also used : AllJobFinishedListener(io.mycat.sqlengine.AllJobFinishedListener) EngineCtx(io.mycat.sqlengine.EngineCtx)

Aggregations

EngineCtx (io.mycat.sqlengine.EngineCtx)3 AllJobFinishedListener (io.mycat.sqlengine.AllJobFinishedListener)2 Catlet (io.mycat.catlets.Catlet)1 RouteResultsetNode (io.mycat.route.RouteResultsetNode)1 SQLNonTransientException (java.sql.SQLNonTransientException)1