use of io.mycat.beans.mycat.MycatMySQLRowMetaData in project Mycat2 by MyCATApache.
the class MySQLPacketUtil method generateColumnDefPayload.
public static final byte[] generateColumnDefPayload(MycatRowMetaData metaData, int columnIndex) {
try (MySQLPayloadWriter writer = new MySQLPayloadWriter(128)) {
ColumnDefPacketImpl columnDefPacket;
if (metaData instanceof MycatMySQLRowMetaData) {
columnDefPacket = (ColumnDefPacketImpl) ((MycatMySQLRowMetaData) metaData).getColumnDefPackets().get(columnIndex);
} else {
columnDefPacket = new ColumnDefPacketImpl(metaData, columnIndex);
}
columnDefPacket.writePayload(writer);
return writer.toByteArray();
}
}
use of io.mycat.beans.mycat.MycatMySQLRowMetaData in project Mycat2 by MyCATApache.
the class NewVertxConnectionImpl method toColumnMetaData.
public static MycatRowMetaData toColumnMetaData(List<ColumnDefinition> event) {
boolean isMysql = event.get(0) instanceof ColumnDefinition;
if (isMysql) {
List<ColumnDefinition> columnDefinitions = event;
List<ColumnDefPacket> columnDefPackets = new ArrayList<>(event.size());
for (ColumnDefinition columnDefinition : columnDefinitions) {
final String catalog = columnDefinition.catalog();
final String schema = columnDefinition.schema();
final String table = columnDefinition.table();
final String orgTable = columnDefinition.orgTable();
final String name = columnDefinition.name();
final String orgName = columnDefinition.orgName();
final int characterSet = columnDefinition.characterSet();
final long columnLength = columnDefinition.columnLength();
final DataType type = columnDefinition.type();
final int flags = columnDefinition.flags();
byte decimals = columnDefinition.decimals();
if (decimals == 31) {
decimals = 0;
}
ColumnDefPacketImpl mySQLFieldInfo = new ColumnDefPacketImpl();
mySQLFieldInfo.setColumnCatalog(catalog.getBytes());
mySQLFieldInfo.setColumnSchema(schema.getBytes());
mySQLFieldInfo.setColumnTable(table.getBytes());
mySQLFieldInfo.setColumnOrgTable(orgTable.getBytes());
mySQLFieldInfo.setColumnName(name.getBytes());
mySQLFieldInfo.setColumnOrgName(orgName.getBytes());
mySQLFieldInfo.setColumnCharsetSet(characterSet);
mySQLFieldInfo.setColumnLength((int) columnLength);
mySQLFieldInfo.setColumnType(type.id);
mySQLFieldInfo.setColumnFlags(flags);
mySQLFieldInfo.setColumnDecimals(decimals);
columnDefPackets.add(mySQLFieldInfo);
}
return new MycatMySQLRowMetaData(columnDefPackets);
} else {
ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
for (ColumnDefinition columnDescriptor : event) {
resultSetBuilder.addColumnInfo(columnDescriptor.name(), columnDescriptor.jdbcType());
}
RowBaseIterator build = resultSetBuilder.build();
return build.getMetaData();
}
}
use of io.mycat.beans.mycat.MycatMySQLRowMetaData in project Mycat2 by MyCATApache.
the class MySQLPacketUtil method generateAllColumnDefPayload.
// public static final byte[] generateColumnDefPayload(ResultSetMetaData metaData, int columnIndex) {
// try (MySQLPayloadWriter writer = new MySQLPayloadWriter(128)) {
// ColumnDefPacketImpl columnDefPacket = new ColumnDefPacketImpl(metaData, columnIndex);
// columnDefPacket.writePayload(writer);
// return writer.toByteArray();
// }
// }
public static final Iterable<byte[]> generateAllColumnDefPayload(MycatRowMetaData metaData) {
List<byte[]> list = new ArrayList<>(metaData.getColumnCount());
final int count = metaData.getColumnCount();
if (metaData instanceof MycatMySQLRowMetaData) {
List<ColumnDefPacketImpl> columnDefPackets = (List) ((MycatMySQLRowMetaData) metaData).getColumnDefPackets();
for (int index = 0; index < count; index++) {
try (MySQLPayloadWriter writer = new MySQLPayloadWriter(128)) {
columnDefPackets.get(index).writePayload(writer);
list.add(writer.toByteArray());
}
}
} else {
for (int index = 0; index < count; index++) {
list.add(MySQLPacketUtil.generateColumnDefPayload(metaData, index));
}
}
return list;
}
use of io.mycat.beans.mycat.MycatMySQLRowMetaData in project Mycat2 by MyCATApache.
the class VertxMycatConnectionPool method query.
@Override
public synchronized Future<RowSet> query(String sql, List<Object> params) {
String psql = deparameterize(sql, params);
Future<RowSet> rowSetFuture = queryCloseFuture.flatMap(unused -> {
Promise<RowSet> promise = Promise.promise();
ObjectArrayDecoder objectArrayDecoder = new ObjectArrayDecoder();
Observable<Object[]> query = connection.query(psql, objectArrayDecoder);
onSend();
Single<RowSet> map = query.subscribeOn(Schedulers.computation()).toList().map(objects -> {
MycatMySQLRowMetaData mycatMySQLRowMetaData = new MycatMySQLRowMetaData(Arrays.asList(objectArrayDecoder.getColumnDefPackets()));
return new RowSet(mycatMySQLRowMetaData, objects);
});
map = map.doOnSuccess(objects -> promise.tryComplete(objects));
map = map.doOnError(objects -> promise.tryFail(objects));
map = map.doOnTerminate(() -> onRev());
map.subscribe();
return promise.future();
});
this.queryCloseFuture = rowSetFuture.mapEmpty();
return rowSetFuture;
}
Aggregations