Search in sources :

Example 1 with MysqlObjectArrayRow

use of io.mycat.api.collector.MysqlObjectArrayRow in project Mycat2 by MyCATApache.

the class PrepareExecutor method getMysqlPayloadObjectObservable.

@NotNull
public static Observable<MysqlPayloadObject> getMysqlPayloadObjectObservable(ArrayBindable bindable, AsyncMycatDataContextImpl newMycatDataContext, MycatRowMetaData rowMetaData) {
    Observable<MysqlPayloadObject> rowObservable = Observable.<MysqlPayloadObject>create(emitter -> {
        emitter.onNext(new MySQLColumnDef(rowMetaData));
        try {
            Object bindObservable;
            bindObservable = bindable.bindObservable(newMycatDataContext);
            Observable<Object[]> observable;
            if (bindObservable instanceof Observable) {
                observable = (Observable) bindObservable;
            } else {
                Enumerable<Object[]> enumerable = (Enumerable) bindObservable;
                observable = toObservable(newMycatDataContext, enumerable);
            }
            observable.subscribe(objects -> emitter.onNext(new MysqlObjectArrayRow(objects)), throwable -> {
                newMycatDataContext.endFuture().onComplete(event -> emitter.onError(throwable));
            }, () -> {
                CompositeFuture compositeFuture = newMycatDataContext.endFuture();
                compositeFuture.onSuccess(event -> emitter.onComplete());
                compositeFuture.onFailure(event -> emitter.onError(event));
            });
        } catch (Throwable throwable) {
            CompositeFuture compositeFuture = newMycatDataContext.endFuture();
            compositeFuture.onComplete(event -> emitter.onError(throwable));
        }
    });
    return rowObservable;
}
Also used : MySQLColumnDef(io.mycat.api.collector.MySQLColumnDef) CompositeFuture(io.vertx.core.CompositeFuture) ResultSetBuilder(io.mycat.beans.mycat.ResultSetBuilder) MycatRowMetaData(io.mycat.beans.mycat.MycatRowMetaData) Getter(lombok.Getter) Iterator(java.util.Iterator) VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) Enumerable(org.apache.calcite.linq4j.Enumerable) MycatRxJavaUtl(io.mycat.MycatRxJavaUtl) Future(io.vertx.core.Future) ArrayBindable(org.apache.calcite.runtime.ArrayBindable) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) CompositeFuture(io.vertx.core.CompositeFuture) MysqlObjectArrayRow(io.mycat.api.collector.MysqlObjectArrayRow) List(java.util.List) AsyncMycatDataContextImpl(io.mycat.AsyncMycatDataContextImpl) MySQLColumnDef(io.mycat.api.collector.MySQLColumnDef) MysqlPayloadObject(io.mycat.api.collector.MysqlPayloadObject) Observable(io.reactivex.rxjava3.core.Observable) Enumerator(org.apache.calcite.linq4j.Enumerator) RowBaseIterator(io.mycat.api.collector.RowBaseIterator) NotNull(org.jetbrains.annotations.NotNull) Enumerable(org.apache.calcite.linq4j.Enumerable) MysqlObjectArrayRow(io.mycat.api.collector.MysqlObjectArrayRow) MysqlPayloadObject(io.mycat.api.collector.MysqlPayloadObject) MysqlPayloadObject(io.mycat.api.collector.MysqlPayloadObject) Observable(io.reactivex.rxjava3.core.Observable) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with MysqlObjectArrayRow

use of io.mycat.api.collector.MysqlObjectArrayRow 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 3 with MysqlObjectArrayRow

use of io.mycat.api.collector.MysqlObjectArrayRow in project Mycat2 by MyCATApache.

the class EmitterMysqlPayloadCollector method onRow.

@Override
public void onRow(Row row) {
    currentRowCount++;
    MysqlPayloadObject packet = new MysqlObjectArrayRow(BaseRowObservable.getObjects(row, rowMetaData));
    emitter.onNext(packet);
}
Also used : MysqlObjectArrayRow(io.mycat.api.collector.MysqlObjectArrayRow) MysqlPayloadObject(io.mycat.api.collector.MysqlPayloadObject)

Aggregations

MysqlObjectArrayRow (io.mycat.api.collector.MysqlObjectArrayRow)3 MysqlPayloadObject (io.mycat.api.collector.MysqlPayloadObject)3 MySQLColumnDef (io.mycat.api.collector.MySQLColumnDef)2 MycatRowMetaData (io.mycat.beans.mycat.MycatRowMetaData)2 AsyncMycatDataContextImpl (io.mycat.AsyncMycatDataContextImpl)1 MycatRxJavaUtl (io.mycat.MycatRxJavaUtl)1 RowBaseIterator (io.mycat.api.collector.RowBaseIterator)1 ResultSetBuilder (io.mycat.beans.mycat.ResultSetBuilder)1 MysqlCollector (io.mycat.newquery.MysqlCollector)1 Observable (io.reactivex.rxjava3.core.Observable)1 CompositeFuture (io.vertx.core.CompositeFuture)1 Future (io.vertx.core.Future)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Objects (java.util.Objects)1 TimeUnit (java.util.concurrent.TimeUnit)1 Getter (lombok.Getter)1 VectorSchemaRoot (org.apache.arrow.vector.VectorSchemaRoot)1 Enumerable (org.apache.calcite.linq4j.Enumerable)1 Enumerator (org.apache.calcite.linq4j.Enumerator)1