use of io.mycat.api.collector.MySQLColumnDef 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;
}
use of io.mycat.api.collector.MySQLColumnDef 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));
});
}
use of io.mycat.api.collector.MySQLColumnDef in project Mycat2 by MyCATApache.
the class EmitterMysqlPayloadCollector method onColumnDefinitions.
@Override
public void onColumnDefinitions(MySQLRowDesc columnDefinitions) {
if (this.rowMetaData == null) {
this.rowMetaData = BaseRowObservable.toColumnMetaData(columnDefinitions.columnDescriptor());
}
if (this.outputColumnDef) {
MysqlPayloadObject packet = new MySQLColumnDef(this.rowMetaData);
emitter.onNext(packet);
}
}
Aggregations