use of org.apache.ignite.internal.processors.odbc.ClientMessage in project ignite by apache.
the class JdbcMessageParser method encode.
/**
* {@inheritDoc}
*/
@Override
public ClientMessage encode(ClientListenerResponse msg) {
assert msg != null;
assert msg instanceof JdbcResponse;
JdbcResponse res = (JdbcResponse) msg;
BinaryWriterExImpl writer = createWriter(INIT_CAP);
res.writeBinary(writer, protoCtx);
return new ClientMessage(writer.array());
}
use of org.apache.ignite.internal.processors.odbc.ClientMessage in project ignite by apache.
the class OdbcMessageParser method encode.
/**
* {@inheritDoc}
*/
@Override
public ClientMessage encode(ClientListenerResponse msg0) {
assert msg0 != null;
assert msg0 instanceof OdbcResponse;
OdbcResponse msg = (OdbcResponse) msg0;
// Creating new binary writer
BinaryWriterExImpl writer = new BinaryWriterExImpl(marsh.context(), new BinaryHeapOutputStream(INIT_CAP), BinaryThreadLocalContext.get().schemaHolder(), null);
// Writing status.
if (ver.compareTo(OdbcConnectionContext.VER_2_1_5) < 0) {
writer.writeByte((byte) (msg.status() == ClientListenerResponse.STATUS_SUCCESS ? ClientListenerResponse.STATUS_SUCCESS : ClientListenerResponse.STATUS_FAILED));
} else
writer.writeInt(msg.status());
if (msg.status() != ClientListenerResponse.STATUS_SUCCESS) {
writer.writeString(msg.error());
return new ClientMessage(writer.array());
}
Object res0 = msg.response();
if (res0 == null)
return new ClientMessage(writer.array());
else if (res0 instanceof OdbcQueryExecuteResult) {
OdbcQueryExecuteResult res = (OdbcQueryExecuteResult) res0;
if (log.isDebugEnabled())
log.debug("Resulting query ID: " + res.queryId());
writer.writeLong(res.queryId());
Collection<OdbcColumnMeta> metas = res.columnsMetadata();
writeResultsetMeta(writer, metas);
writeAffectedRows(writer, res.affectedRows());
} else if (res0 instanceof OdbcQueryExecuteBatchResult) {
OdbcQueryExecuteBatchResult res = (OdbcQueryExecuteBatchResult) res0;
writer.writeBoolean(res.errorMessage() == null);
writeAffectedRows(writer, res.affectedRows());
if (res.errorMessage() != null) {
writer.writeLong(res.errorSetIdx());
writer.writeString(res.errorMessage());
if (ver.compareTo(OdbcConnectionContext.VER_2_1_5) >= 0)
writer.writeInt(res.errorCode());
}
} else if (res0 instanceof OdbcStreamingBatchResult) {
OdbcStreamingBatchResult res = (OdbcStreamingBatchResult) res0;
writer.writeString(res.error());
writer.writeInt(res.status());
writer.writeLong(res.order());
} else if (res0 instanceof OdbcQueryFetchResult) {
OdbcQueryFetchResult res = (OdbcQueryFetchResult) res0;
if (log.isDebugEnabled())
log.debug("Resulting query ID: " + res.queryId());
writer.writeLong(res.queryId());
Collection<?> items0 = res.items();
assert items0 != null;
writer.writeBoolean(res.last());
writer.writeInt(items0.size());
for (Object row0 : items0) {
if (row0 != null) {
Collection<?> row = (Collection<?>) row0;
writer.writeInt(row.size());
for (Object obj : row) SqlListenerUtils.writeObject(writer, obj, true);
}
}
} else if (res0 instanceof OdbcQueryMoreResultsResult) {
OdbcQueryMoreResultsResult res = (OdbcQueryMoreResultsResult) res0;
if (log.isDebugEnabled())
log.debug("Resulting query ID: " + res.queryId());
writer.writeLong(res.queryId());
Collection<?> items0 = res.items();
assert items0 != null;
writer.writeBoolean(res.last());
writer.writeInt(items0.size());
for (Object row0 : items0) {
if (row0 != null) {
Collection<?> row = (Collection<?>) row0;
writer.writeInt(row.size());
for (Object obj : row) SqlListenerUtils.writeObject(writer, obj, true);
}
}
} else if (res0 instanceof OdbcQueryCloseResult) {
OdbcQueryCloseResult res = (OdbcQueryCloseResult) res0;
if (log.isDebugEnabled())
log.debug("Resulting query ID: " + res.getQueryId());
writer.writeLong(res.getQueryId());
} else if (res0 instanceof OdbcQueryGetColumnsMetaResult) {
OdbcQueryGetColumnsMetaResult res = (OdbcQueryGetColumnsMetaResult) res0;
Collection<OdbcColumnMeta> columnsMeta = res.meta();
writeResultsetMeta(writer, columnsMeta);
} else if (res0 instanceof OdbcQueryGetTablesMetaResult) {
OdbcQueryGetTablesMetaResult res = (OdbcQueryGetTablesMetaResult) res0;
Collection<OdbcTableMeta> tablesMeta = res.meta();
assert tablesMeta != null;
writer.writeInt(tablesMeta.size());
for (OdbcTableMeta tableMeta : tablesMeta) tableMeta.writeBinary(writer);
} else if (res0 instanceof OdbcQueryGetParamsMetaResult) {
OdbcQueryGetParamsMetaResult res = (OdbcQueryGetParamsMetaResult) res0;
byte[] typeIds = res.typeIds();
SqlListenerUtils.writeObject(writer, typeIds, true);
} else if (res0 instanceof OdbcQueryGetResultsetMetaResult) {
OdbcQueryGetResultsetMetaResult res = (OdbcQueryGetResultsetMetaResult) res0;
writeResultsetMeta(writer, res.columnsMetadata());
} else
assert false : "Should not reach here.";
return new ClientMessage(writer.array());
}
use of org.apache.ignite.internal.processors.odbc.ClientMessage in project ignite by apache.
the class ClientMessageParser method encode.
/**
* {@inheritDoc}
*/
@Override
public ClientMessage encode(ClientListenerResponse resp) {
assert resp != null;
BinaryHeapOutputStream outStream = new BinaryHeapOutputStream(32, BinaryMemoryAllocator.POOLED.chunk());
BinaryRawWriterEx writer = marsh.writer(outStream);
assert resp instanceof ClientOutgoingMessage : "Unexpected response type: " + resp.getClass();
((ClientOutgoingMessage) resp).encode(ctx, writer);
return new ClientMessage(outStream);
}
Aggregations