Search in sources :

Example 1 with MysqlCollector

use of io.mycat.newquery.MysqlCollector in project Mycat2 by MyCATApache.

the class VertxExecuter method runQueryOutputAsMysqlPayloadObject.

public static Observable<MysqlPayloadObject> runQueryOutputAsMysqlPayloadObject(Future<NewMycatConnection> connectionFuture, String sql, List<Object> values) {
    return Observable.create(emitter -> {
        // 连接到达
        connectionFuture.onSuccess(connection -> {
            // 预编译到达
            connection.prepareQuery(sql, values, new MysqlCollector() {

                MycatRowMetaData mycatRowMetaData;

                @Override
                public void onColumnDef(MycatRowMetaData mycatRowMetaData) {
                    emitter.onNext(new MySQLColumnDef(this.mycatRowMetaData = mycatRowMetaData));
                }

                @Override
                public void onRow(Object[] row) {
                    emitter.onNext(new MysqlObjectArrayRow(BaseRowObservable.getObjects(row, this.mycatRowMetaData)));
                }

                @Override
                public void onComplete() {
                    emitter.onComplete();
                }

                @Override
                public void onError(Throwable e) {
                    emitter.onError(e);
                }
            });
        });
        connectionFuture.onFailure(i -> emitter.onError(i));
    });
}
Also used : MySQLColumnDef(io.mycat.api.collector.MySQLColumnDef) MysqlObjectArrayRow(io.mycat.api.collector.MysqlObjectArrayRow) MysqlPayloadObject(io.mycat.api.collector.MysqlPayloadObject) MysqlCollector(io.mycat.newquery.MysqlCollector) MycatRowMetaData(io.mycat.beans.mycat.MycatRowMetaData)

Example 2 with MysqlCollector

use of io.mycat.newquery.MysqlCollector in project Mycat2 by MyCATApache.

the class VertxExecuter method runQuery.

public static Observable<Object[]> runQuery(Future<NewMycatConnection> connectionFuture, String sql, List<Object> values, MycatRowMetaData rowMetaDataArg) {
    return Observable.create(emitter -> {
        // 连接到达
        connectionFuture.onSuccess(connection -> {
            // 预编译到达
            connection.prepareQuery(sql, values, new MysqlCollector() {

                MycatRowMetaData mycatRowMetaData;

                @Override
                public void onColumnDef(MycatRowMetaData mycatRowMetaData) {
                    this.mycatRowMetaData = Optional.ofNullable(rowMetaDataArg).orElse(mycatRowMetaData);
                }

                @Override
                public void onRow(Object[] row) {
                    try {
                        emitter.onNext(BaseRowObservable.getObjects(row, this.mycatRowMetaData));
                    } catch (Exception e) {
                        LOGGER.error("", e);
                        throw e;
                    }
                }

                @Override
                public void onComplete() {
                    emitter.onComplete();
                }

                @Override
                public void onError(Throwable e) {
                    emitter.onError(e);
                }
            });
        });
        connectionFuture.onFailure(i -> emitter.onError(i));
    });
}
Also used : MysqlPayloadObject(io.mycat.api.collector.MysqlPayloadObject) MysqlCollector(io.mycat.newquery.MysqlCollector) MycatRowMetaData(io.mycat.beans.mycat.MycatRowMetaData)

Aggregations

MysqlPayloadObject (io.mycat.api.collector.MysqlPayloadObject)2 MycatRowMetaData (io.mycat.beans.mycat.MycatRowMetaData)2 MysqlCollector (io.mycat.newquery.MysqlCollector)2 MySQLColumnDef (io.mycat.api.collector.MySQLColumnDef)1 MysqlObjectArrayRow (io.mycat.api.collector.MysqlObjectArrayRow)1