Skip to content

Commit

Permalink
Merge pull request #31 from fynwin/master
Browse files Browse the repository at this point in the history
存储过程结果集
  • Loading branch information
fynwin authored Jul 24, 2017
2 parents 618f6a6 + bf05365 commit 359fe4a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,54 @@ private ComQueryResponseState() {
}

@Override
protected boolean frontendHandle(MySQLFrontConnection mySQLFrontConnection, Object attachment)throws IOException {
LOGGER.debug("Frontend in ComQueryResponseState");
return true;
protected boolean frontendHandle(MySQLFrontConnection mySQLFrontConnection, Object attachment) throws IOException {
LOGGER.debug("Frontend in ComQueryResponseState");
return true;
}

@Override
protected boolean backendHandle(MySQLBackendConnection mySQLBackendConnection, Object attachment)throws IOException {
protected boolean backendHandle(MySQLBackendConnection mySQLBackendConnection, Object attachment) throws IOException {
LOGGER.debug("Backend in ComQueryResponseState");
boolean returnflag = false;
try {
processPacketHeader(mySQLBackendConnection);
byte packageType;
switch(mySQLBackendConnection.getDirectTransferMode()){
case COMPLETE_PACKET:
packageType = mySQLBackendConnection.getCurrentPacketType();
if (packageType == MySQLPacket.OK_PACKET || packageType == MySQLPacket.ERROR_PACKET) {
//多结果集时会返回OK包,此时服务器的状态应该已经不是多结果集的状态了
processPacketHeader(mySQLBackendConnection);
byte packageType;
switch (mySQLBackendConnection.getDirectTransferMode()) {
case COMPLETE_PACKET:
packageType = mySQLBackendConnection.getCurrentPacketType();
if (packageType == MySQLPacket.OK_PACKET || packageType == MySQLPacket.ERROR_PACKET) {
//多结果集时会返回OK包,此时服务器的状态应该已经不是多结果集的状态了
// MySQLMessage mySQLMessage = new MySQLMessage(dataBuffer);
// mySQLMessage.position(mySQLBackendConnection.getCurrentPacketStartPos());
int serverStatus = 0;
mySQLBackendConnection.setServerStatus(serverStatus);
if ((serverStatus & ServerStatus.SERVER_STATUS_IN_TRANS) != 0) {
LOGGER.debug("后端连接,处于事务中,不能回收!{}", mySQLBackendConnection);
//TODO serverStatus开始位置计算并不精确
int serverStatus = (int) mySQLBackendConnection.getDataBuffer().getFixInt(
mySQLBackendConnection.getCurrentPacketStartPos() + 7,
2
);
mySQLBackendConnection.setServerStatus(serverStatus);
if ((serverStatus & ServerStatus.SERVER_STATUS_IN_TRANS) != 0) {
LOGGER.debug("后端连接,处于事务中,不能回收!{}", mySQLBackendConnection);
} else {
LOGGER.debug("后端连接,不在事务中,可以回收!{}", mySQLBackendConnection);
}
mySQLBackendConnection.setNextState(IdleState.INSTANCE);
SQLEngineCtx.INSTANCE().getDataTransferChannel().transferToFront(mySQLBackendConnection, true, true, true);
returnflag = false; //触发透传,退出当前状态机
} else if (packageType == MySQLPacket.REQUEST_FILE_FIELD_COUNT) {
mySQLBackendConnection.setNextState(ComLoadState.INSTANCE);
SQLEngineCtx.INSTANCE().getDataTransferChannel().transferToFront(mySQLBackendConnection, true, true, false);
} else {
LOGGER.debug("后端连接,不在事务中,可以回收!{}",mySQLBackendConnection);
mySQLBackendConnection.setNextState(ComQueryColumnDefState.INSTANCE);
mySQLBackendConnection.getDataBuffer().writeLimit(mySQLBackendConnection.getCurrentPacketLength());
returnflag = true; //状态机自驱进入下一个状态
}
mySQLBackendConnection.setNextState(IdleState.INSTANCE);
SQLEngineCtx.INSTANCE().getDataTransferChannel().transferToFront(mySQLBackendConnection, true,true, true);
returnflag = false; //触发透传,退出当前状态机
}else if(packageType == MySQLPacket.REQUEST_FILE_FIELD_COUNT){
mySQLBackendConnection.setNextState(ComLoadState.INSTANCE);
SQLEngineCtx.INSTANCE().getDataTransferChannel().transferToFront(mySQLBackendConnection, true,true,false);
}
else {
mySQLBackendConnection.setNextState(ComQueryColumnDefState.INSTANCE);
mySQLBackendConnection.getDataBuffer().writeLimit(mySQLBackendConnection.getCurrentPacketLength());
returnflag = true; //状态机自驱进入下一个状态
}
break;
case LONG_HALF_PACKET:
case SHORT_HALF_PACKET:
case NONE:
returnflag = false;
break;
break;
case LONG_HALF_PACKET:
case SHORT_HALF_PACKET:
SQLEngineCtx.INSTANCE().getDataTransferChannel().transferToFront(mySQLBackendConnection, false, false, false);
case NONE:
returnflag = false;
break;
}
} catch (IOException e) {
LOGGER.error("Backend ComQueryResponseState error", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ protected boolean backendHandle(MySQLBackendConnection mySQLBackendConnection, O
dataBuffer.writeLimit(mySQLBackendConnection.getCurrentPacketLength());
packageType = mySQLBackendConnection.getCurrentPacketType();
if (packageType == MySQLPacket.EOF_PACKET) {
int serverStatus = 0;
//TODO 开始位置计算并不精确
int serverStatus = (int) dataBuffer.getFixInt(mySQLBackendConnection.getCurrentPacketStartPos()+7,2);
mySQLBackendConnection.setServerStatus(serverStatus);
//检查后面还有没有结果集
if ((mySQLBackendConnection.getServerStatus() & ServerStatus.SERVER_MORE_RESULTS_EXISTS) == 0) {
Expand Down

0 comments on commit 359fe4a

Please sign in to comment.