use of io.mycat.beans.mycat.ResultSetBuilder in project Mycat2 by MyCATApache.
the class NativeMycatServer method showBufferUsage.
@Override
public RowBaseIterator showBufferUsage(long sessionId) {
MycatSession curSession = null;
for (MycatReactorThread mycatReactorThread : getReactorManager().getList()) {
SessionManager.FrontSessionManager<MycatSession> frontManager = mycatReactorThread.getFrontManager();
for (MycatSession session : frontManager.getAllSessions()) {
if (sessionId == session.sessionId()) {
curSession = session;
break;
}
}
}
ResultSetBuilder builder = ResultSetBuilder.create();
builder.addColumnInfo("bufferUsage", JDBCType.BIGINT);
if (curSession != null) {
builder.addObjectRowPayload(Arrays.asList(curSession.writeBufferPool().trace()));
}
return builder.build();
}
use of io.mycat.beans.mycat.ResultSetBuilder in project Mycat2 by MyCATApache.
the class VertxMycatServer method demo.
private static RowBaseIterator demo() {
ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
resultSetBuilder.addColumnInfo("demo", JDBCType.VARCHAR);
resultSetBuilder.addObjectRowPayload(Arrays.asList("unsupported"));
return resultSetBuilder.build();
}
use of io.mycat.beans.mycat.ResultSetBuilder in project Mycat2 by MyCATApache.
the class DrdsRunnerHelper method doExplain.
private RowBaseIterator doExplain(MycatRel relNode1) {
final StringWriter sw = new StringWriter();
final RelWriter planWriter = new RelWriterImpl(new PrintWriter(sw), SqlExplainLevel.ALL_ATTRIBUTES, false);
relNode1.explain(planWriter);
String[] split = sw.getBuffer().toString().split("\n");
ResultSetBuilder builder = ResultSetBuilder.create();
builder.addColumnInfo("explain", JDBCType.VARCHAR);
for (String s : split) {
builder.addObjectRowPayload(Arrays.asList(s));
}
return builder.build();
}
use of io.mycat.beans.mycat.ResultSetBuilder in project Mycat2 by MyCATApache.
the class MycatVertxMySQLHandler method handlePrepareStatement.
private Future<Void> handlePrepareStatement(byte[] bytes, MycatVertxMysqlSession mysqlSession) {
boolean deprecateEOF = mysqlSession.isDeprecateEOF();
String sql = new String(bytes);
// ///////////////////////////////////////////////////
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("received pstmt sql:{}", sql);
}
SQLStatement sqlStatement = SQLUtils.parseSingleMysqlStatement(sql);
boolean allow = (sqlStatement instanceof SQLSelectStatement || sqlStatement instanceof SQLInsertStatement || sqlStatement instanceof SQLUpdateStatement || sqlStatement instanceof SQLDeleteStatement);
// MetadataManager metadataManager = MetaClusterCurrent.wrapper(MetadataManager.class);
MycatRowMetaData fields;
if ((sqlStatement instanceof SQLSelectStatement)) {
PrototypeService prototypeService = MetaClusterCurrent.wrapper(PrototypeService.class);
Optional<MycatRowMetaData> mycatRowMetaDataForPrepareStatement = prototypeService.getMycatRowMetaDataForPrepareStatement(mysqlSession.getDataContext().getDefaultSchema(), sql);
if (!mycatRowMetaDataForPrepareStatement.isPresent()) {
return VertxUtil.castPromise(Future.failedFuture(new SQLException("This command is not supported in the prepared statement protocol yet", "HY000", 1295)));
}
fields = mycatRowMetaDataForPrepareStatement.get();
} else {
fields = ResultSetBuilder.create().build().getMetaData();
}
ResultSetBuilder paramsBuilder = ResultSetBuilder.create();
sqlStatement.accept(new MySqlASTVisitorAdapter() {
@Override
public void endVisit(SQLVariantRefExpr x) {
if ("?".equalsIgnoreCase(x.getName())) {
JDBCType res = JDBCType.VARCHAR;
paramsBuilder.addColumnInfo("", res);
}
super.endVisit(x);
}
});
MycatRowMetaData params = paramsBuilder.build().getMetaData();
long stmtId = mycatDataContext.nextPrepareStatementId();
Map<Long, io.mycat.PreparedStatement> statementMap = this.mycatDataContext.getPrepareInfo();
PreparedStatement preparedStatement = new PreparedStatement(stmtId, sqlStatement, params.getColumnCount());
for (int i = 0; i < params.getColumnCount(); i++) {
preparedStatement.getParametersType()[i] = MysqlDefs.FIELD_TYPE_STRING;
}
statementMap.put(stmtId, preparedStatement);
DefaultPreparedOKPacket info = new DefaultPreparedOKPacket(stmtId, fields.getColumnCount(), params.getColumnCount(), session.getWarningCount());
Future<Void> writeEndFuture = Future.succeededFuture();
if (info.getPrepareOkColumnsCount() == 0 && info.getPrepareOkParametersCount() == 0) {
return session.writeBytes(MySQLPacketUtil.generatePrepareOk(info), true);
}
session.writeBytes(MySQLPacketUtil.generatePrepareOk(info), false);
if (info.getPrepareOkParametersCount() > 0 && info.getPrepareOkColumnsCount() == 0) {
for (int i = 0; i < info.getPrepareOkParametersCount(); i++) {
writeEndFuture = session.writeBytes(MySQLPacketUtil.generateColumnDefPayload(params, i), info.getPrepareOkParametersCount() - 1 == i && deprecateEOF);
}
if (deprecateEOF) {
return writeEndFuture;
} else {
return session.writeBytes(MySQLPacketUtil.generateEof(session.getWarningCount(), session.getServerStatusValue()), true);
}
} else if (info.getPrepareOkParametersCount() == 0 && info.getPrepareOkColumnsCount() > 0) {
for (int i = 0; i < info.getPrepareOkColumnsCount(); i++) {
writeEndFuture = session.writeBytes(MySQLPacketUtil.generateColumnDefPayload(fields, i), info.getPrepareOkColumnsCount() - 1 == i && deprecateEOF);
}
if (deprecateEOF) {
return writeEndFuture;
} else {
return session.writeBytes(MySQLPacketUtil.generateEof(session.getWarningCount(), session.getServerStatusValue()), true);
}
} else {
for (int i = 0; i < info.getPrepareOkParametersCount(); i++) {
writeEndFuture = session.writeBytes(MySQLPacketUtil.generateColumnDefPayload(params, i), false);
}
writeEndFuture = session.writeColumnEndPacket(false);
for (int i = 0; i < info.getPrepareOkColumnsCount(); i++) {
writeEndFuture = session.writeBytes(MySQLPacketUtil.generateColumnDefPayload(fields, i), info.getPrepareOkColumnsCount() - 1 == i && deprecateEOF);
}
if (deprecateEOF) {
return writeEndFuture;
} else {
return session.writeBytes(MySQLPacketUtil.generateEof(session.getWarningCount(), session.getServerStatusValue()), true);
}
}
}
use of io.mycat.beans.mycat.ResultSetBuilder in project Mycat2 by MyCATApache.
the class BinlogUtil method list.
public static RowBaseIterator list(List<BinlogScheduler> schedulers) {
ResultSetBuilder builder = ResultSetBuilder.create();
builder.addColumnInfo("ID", JDBCType.VARCHAR);
builder.addColumnInfo("NAME", JDBCType.VARCHAR);
builder.addColumnInfo("INFO", JDBCType.VARCHAR);
builder.addColumnInfo("START_TIME", JDBCType.TIMESTAMP);
for (BinlogScheduler scheduler : schedulers) {
String id = scheduler.getId();
String name = scheduler.getName();
Map<String, Map<String, List<Partition>>> listMap = scheduler.getListMap();
LocalDateTime startTime = scheduler.getStartTime();
builder.addObjectRowPayload(Arrays.asList(id, name, listMap.toString(), startTime));
}
return builder.build();
}
Aggregations