Created
June 11, 2013 06:03
-
-
Save arkjun/5754748 to your computer and use it in GitHub Desktop.
myBatis 로그 합치기 (Log Parser)
input) Preparing: Select dummy from dual where col = ? and col2 = ? and no = ? Parameters: val1(String), val2(String), 1(Long) output -result)
select ... where col = 'val1' and col2 = 'val2' and no = 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>MyBatis Log parse</title> | |
<script src="jquery-2.0.2.js"></script> | |
</head> | |
<body> | |
<div id="div_origin" style="float:left"> | |
<textarea id="txt_origin" rows="30" cols="40"></textarea> | |
</div> | |
<div id="div_origin" style="float:left"> | |
<button id="btn_parse">Parse</button> | |
</div> | |
<div id="div_origin" style="float:left"> | |
<textarea id="txt_parsing" rows="30" cols="40"></textarea> | |
</div> | |
<script> | |
$(document).ready(function() { | |
$("body").on("click", "button", function (e) { | |
doParse(); | |
}); | |
}); | |
/** | |
* myBatis 로그 합치기 | |
* Preparing: Select dummy from dual where col = ? and col2 = ? | |
* Parameters: val1(String), val2(String) | |
* | |
* Result) select ... where col = val1 and col2 = val2 | |
* | |
* @return {[type]} [description] | |
*/ | |
var doParse = function () { | |
var $txt_origin = $("#txt_origin"); | |
var $txt_parsing = $("#txt_parsing"); | |
var originArr = [], parsingArr = [], paramArr = []; | |
var paramCnt = 0; | |
var result = ""; | |
var preparing = ""; | |
var param = {}; | |
originArr = $txt_origin.val().split("\n"); | |
parsingArr[0] = originArr[0].substring ( originArr[0].indexOf ("Preparing: ")+11 ); | |
parsingArr[1] = originArr[1].substring ( originArr[1].indexOf ("Parameters: ")+12 ); | |
preparing = parsingArr[0]; | |
paramArr = parsingArr[1].split(","); | |
for (var i = 0; i < paramArr.length; i++) { | |
var tempParams = paramArr[i]; | |
param.val = tempParams.substring(0, tempParams.lastIndexOf("(")); | |
param.typ = tempParams.substring(tempParams.lastIndexOf("(")+1, paramArr[i].lastIndexOf(")")); | |
if ( preparing.indexOf("?") >= 0 ) { | |
if (param.typ === "String") { | |
param.val = "'"+param.val+"'"; | |
} | |
preparing = preparing.replace("?", param.val); | |
} | |
} | |
result = preparing; | |
$txt_parsing.html(result); | |
}; | |
</script> | |
</body> | |
</html> | |
<!-- | |
DEBUG: java.sql.Connection - ==> Preparing: SELECT TEST1, TEST2 FROM DUAL WHERE COL1 = ? AND COL2 = ? AND NO = ? | |
DEBUG: java.sql.PreparedStatement - ==> Parameters: test1(String), test2(String), 13(Long) | |
--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment