use of com.mysql.cj.protocol.x.XProtocolRowInputStream in project aws-mysql-jdbc by awslabs.
the class StreamingSqlResultBuilder method addProtocolEntity.
@Override
public boolean addProtocolEntity(ProtocolEntity entity) {
if (entity instanceof Notice) {
this.statementExecuteOkBuilder.addProtocolEntity(entity);
} else {
this.lastEntity = entity;
}
AtomicBoolean readLastResult = new AtomicBoolean(false);
Supplier<ProtocolEntity> okReader = () -> {
if (readLastResult.get()) {
throw new CJCommunicationsException("Invalid state attempting to read ok packet");
}
if (this.protocol.hasMoreResults()) {
StatementExecuteOk res = this.statementExecuteOkBuilder.build();
this.statementExecuteOkBuilder = new StatementExecuteOkBuilder();
return res;
}
readLastResult.set(true);
return this.protocol.readQueryResult(this.statementExecuteOkBuilder);
};
Supplier<SqlResult> resultStream = () -> {
if (readLastResult.get()) {
return null;
} else if (this.lastEntity != null && this.lastEntity instanceof Field || this.protocol.isSqlResultPending()) {
ColumnDefinition cd;
if (this.lastEntity != null && this.lastEntity instanceof Field) {
cd = this.protocol.readMetadata((Field) this.lastEntity, (n) -> {
this.statementExecuteOkBuilder.addProtocolEntity(n);
});
this.lastEntity = null;
} else {
cd = this.protocol.readMetadata(this.statementExecuteOkBuilder::addProtocolEntity);
}
return new SqlSingleResult(cd, this.protocol.getServerSession().getDefaultTimeZone(), new XProtocolRowInputStream(cd, this.protocol, (n) -> {
this.statementExecuteOkBuilder.addProtocolEntity(n);
}), okReader, this.pset);
} else {
readLastResult.set(true);
SqlResultBuilder rb = new SqlResultBuilder(this.defaultTimeZone, this.pset);
rb.addProtocolEntity(entity);
return this.protocol.readQueryResult(rb);
}
};
this.result = new SqlMultiResult(resultStream);
return true;
}
Aggregations