mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
fixed sonar rule violations
This commit is contained in:
@@ -98,9 +98,7 @@ public class DruidStat {
|
||||
try {
|
||||
vm = VirtualMachine.attach(name);
|
||||
} catch (AttachNotSupportedException x) {
|
||||
IOException ioe = new IOException(x.getMessage());
|
||||
ioe.initCause(x);
|
||||
throw ioe;
|
||||
throw new IOException(x.getMessage(), x);
|
||||
}
|
||||
|
||||
String home = vm.getSystemProperties().getProperty("java.home");
|
||||
@@ -122,13 +120,9 @@ public class DruidStat {
|
||||
try {
|
||||
vm.loadAgent(agent, "com.sun.management.jmxremote");
|
||||
} catch (AgentLoadException x) {
|
||||
IOException ioe = new IOException(x.getMessage());
|
||||
ioe.initCause(x);
|
||||
throw ioe;
|
||||
throw new IOException(x.getMessage(), x);
|
||||
} catch (AgentInitializationException x) {
|
||||
IOException ioe = new IOException(x.getMessage());
|
||||
ioe.initCause(x);
|
||||
throw ioe;
|
||||
throw new IOException(x.getMessage(), x);
|
||||
}
|
||||
|
||||
// get the connector address
|
||||
|
||||
@@ -69,9 +69,13 @@ public class TableFormatter {
|
||||
}
|
||||
|
||||
public static String padStr(String old, int length) {
|
||||
if (old == null ) return "";
|
||||
if (old == null ) {
|
||||
return "";
|
||||
}
|
||||
int vlen = displayLen(old);
|
||||
if (vlen > length) return old;
|
||||
if (vlen > length) {
|
||||
return old;
|
||||
}
|
||||
StringBuffer sb = new StringBuffer(old);
|
||||
for (int i=0; i< length -vlen ; i++) {
|
||||
sb.append(" ");
|
||||
|
||||
@@ -23,62 +23,45 @@ import com.alibaba.druid.sql.SQLUtils;
|
||||
|
||||
public class TabledDataPrinter {
|
||||
|
||||
private static final int SQL_MAX_LEN = 32;
|
||||
private static final int MAX_COL = 4;
|
||||
|
||||
private static final String[] sqlRowTitle = new String[] {
|
||||
"ID", "SQL", "ExecCount", "ExecTime",
|
||||
"ExecMax","Txn", "Error","Update","FetchRow","Running","Concurrent",
|
||||
"ExecHisto", "ExecRsHisto","FetchRowHisto","UpdateHisto" };
|
||||
|
||||
|
||||
private static final String[] sqlRowField = new String[] {
|
||||
"ID", "SQL", "ExecuteCount", "TotalTime", "MaxTimespan",
|
||||
"InTransactionCount", "ErrorCount", "EffectedRowCount", "FetchRowCount",
|
||||
"RunningCount","ConcurrentMax","Histogram","ExecuteAndResultHoldTimeHistogram",
|
||||
"FetchRowCountHistogram","EffectedRowCountHistogram" };
|
||||
|
||||
private static final String[] sqlColField = new String[] {
|
||||
"ID", "DataSource", "SQL", "ExecuteCount", "ErrorCount",
|
||||
"TotalTime", "LastTime", "MaxTimespan", "LastError", "EffectedRowCount",
|
||||
"FetchRowCount", "MaxTimespanOccurTime", "BatchSizeMax", "BatchSizeTotal", "ConcurrentMax",
|
||||
"RunningCount", "Name", "File",
|
||||
"LastErrorMessage", "LastErrorClass", "LastErrorStackTrace", "LastErrorTime",
|
||||
"DbType", "URL", "InTransactionCount",
|
||||
"Histogram", "LastSlowParameters", "ResultSetHoldTime", "ExecuteAndResultSetHoldTime", "FetchRowCountHistogram",
|
||||
"EffectedRowCountHistogram", "ExecuteAndResultHoldTimeHistogram", "EffectedRowCountMax", "FetchRowCountMax", "ClobOpenCount" };
|
||||
private static final int SQL_MAX_LEN = 32;
|
||||
private static final int MAX_COL = 4;
|
||||
|
||||
private static final String[] sqlRowTitle = new String[] { "ID", "SQL", "ExecCount", "ExecTime", "ExecMax", "Txn",
|
||||
"Error", "Update", "FetchRow", "Running", "Concurrent", "ExecHisto", "ExecRsHisto", "FetchRowHisto",
|
||||
"UpdateHisto" };
|
||||
|
||||
private static final String[] dsRowTitle = new String[] {
|
||||
"Name", "DbType",
|
||||
"PoolingCount", "PoolingPeak", "PoolingPeakTime",
|
||||
"ActiveCount", "ActivePeak", "ActivePeakTime",
|
||||
"ExecuteCount", "ErrorCount", "CommitCount", "RollbackCount" };
|
||||
private static final String[] sqlRowField = new String[] { "ID", "SQL", "ExecuteCount", "TotalTime", "MaxTimespan",
|
||||
"InTransactionCount", "ErrorCount", "EffectedRowCount", "FetchRowCount", "RunningCount", "ConcurrentMax",
|
||||
"Histogram", "ExecuteAndResultHoldTimeHistogram", "FetchRowCountHistogram", "EffectedRowCountHistogram" };
|
||||
|
||||
private static final String[] dsRowField = new String[] {
|
||||
"Name", "DbType",
|
||||
"PoolingCount", "PoolingPeak", "PoolingPeakTime",
|
||||
"ActiveCount", "ActivePeak", "ActivePeakTime",
|
||||
"ExecuteCount", "ErrorCount", "CommitCount", "RollbackCount" };
|
||||
private static final String[] sqlColField = new String[] { "ID", "DataSource", "SQL", "ExecuteCount", "ErrorCount",
|
||||
"TotalTime", "LastTime", "MaxTimespan", "LastError", "EffectedRowCount", "FetchRowCount",
|
||||
"MaxTimespanOccurTime", "BatchSizeMax", "BatchSizeTotal", "ConcurrentMax", "RunningCount", "Name", "File",
|
||||
"LastErrorMessage", "LastErrorClass", "LastErrorStackTrace", "LastErrorTime", "DbType", "URL",
|
||||
"InTransactionCount", "Histogram", "LastSlowParameters", "ResultSetHoldTime",
|
||||
"ExecuteAndResultSetHoldTime", "FetchRowCountHistogram", "EffectedRowCountHistogram",
|
||||
"ExecuteAndResultHoldTimeHistogram", "EffectedRowCountMax", "FetchRowCountMax", "ClobOpenCount" };
|
||||
|
||||
private static final String[] dsRowTitle = new String[] { "Name", "DbType", "PoolingCount", "PoolingPeak",
|
||||
"PoolingPeakTime", "ActiveCount", "ActivePeak", "ActivePeakTime", "ExecuteCount", "ErrorCount",
|
||||
"CommitCount", "RollbackCount" };
|
||||
|
||||
private static final String[] dsColField = new String[] {
|
||||
"Identity", "Name", "DbType", "DriverClassName", "URL", "UserName", "FilterClassNames",
|
||||
"WaitThreadCount", "NotEmptyWaitCount", "NotEmptyWaitMillis",
|
||||
"PoolingCount", "PoolingPeak", "PoolingPeakTime",
|
||||
"ActiveCount", "ActivePeak", "ActivePeakTime",
|
||||
"InitialSize", "MinIdle", "MaxActive",
|
||||
"QueryTimeout", "TransactionQueryTimeout", "LoginTimeout", "ValidConnectionCheckerClassName", "ExceptionSorterClassName",
|
||||
"TestOnBorrow", "TestOnReturn", "TestWhileIdle",
|
||||
"DefaultAutoCommit", "DefaultReadOnly", "DefaultTransactionIsolation",
|
||||
"LogicConnectCount", "LogicCloseCount", "LogicConnectErrorCount",
|
||||
"PhysicalConnectCount", "PhysicalCloseCount", "PhysicalConnectErrorCount",
|
||||
"ExecuteCount", "ErrorCount", "CommitCount", "RollbackCount",
|
||||
"PSCacheAccessCount", "PSCacheHitCount", "PSCacheMissCount",
|
||||
"StartTransactionCount", "TransactionHistogram",
|
||||
"ConnectionHoldTimeHistogram", "RemoveAbandoned", "ClobOpenCount" };
|
||||
private static final String[] dsRowField = new String[] { "Name", "DbType", "PoolingCount", "PoolingPeak",
|
||||
"PoolingPeakTime", "ActiveCount", "ActivePeak", "ActivePeakTime", "ExecuteCount", "ErrorCount",
|
||||
"CommitCount", "RollbackCount" };
|
||||
|
||||
public static void printActiveConnStack(List<List<String >> content,Option opt) {
|
||||
private static final String[] dsColField = new String[] { "Identity", "Name", "DbType", "DriverClassName", "URL",
|
||||
"UserName", "FilterClassNames", "WaitThreadCount", "NotEmptyWaitCount", "NotEmptyWaitMillis",
|
||||
"PoolingCount", "PoolingPeak", "PoolingPeakTime", "ActiveCount", "ActivePeak", "ActivePeakTime",
|
||||
"InitialSize", "MinIdle", "MaxActive", "QueryTimeout", "TransactionQueryTimeout", "LoginTimeout",
|
||||
"ValidConnectionCheckerClassName", "ExceptionSorterClassName", "TestOnBorrow", "TestOnReturn",
|
||||
"TestWhileIdle", "DefaultAutoCommit", "DefaultReadOnly", "DefaultTransactionIsolation",
|
||||
"LogicConnectCount", "LogicCloseCount", "LogicConnectErrorCount", "PhysicalConnectCount",
|
||||
"PhysicalCloseCount", "PhysicalConnectErrorCount", "ExecuteCount", "ErrorCount", "CommitCount",
|
||||
"RollbackCount", "PSCacheAccessCount", "PSCacheHitCount", "PSCacheMissCount", "StartTransactionCount",
|
||||
"TransactionHistogram", "ConnectionHoldTimeHistogram", "RemoveAbandoned", "ClobOpenCount" };
|
||||
|
||||
public static void printActiveConnStack(List<List<String>> content, Option opt) {
|
||||
for (List<String> stack : content) {
|
||||
for (String line : stack) {
|
||||
System.out.println(line);
|
||||
@@ -87,7 +70,7 @@ public class TabledDataPrinter {
|
||||
}
|
||||
}
|
||||
|
||||
public static void printDataSourceData(List<Map<String, Object>> content,Option opt) {
|
||||
public static void printDataSourceData(List<Map<String, Object>> content, Option opt) {
|
||||
if (opt.getStyle() == Option.PrintStyle.HORIZONTAL) {
|
||||
System.out.println(getFormattedOutput(content, dsRowTitle, dsRowField));
|
||||
} else {
|
||||
@@ -96,23 +79,22 @@ public class TabledDataPrinter {
|
||||
}
|
||||
|
||||
public static void printSqlData(List<Map<String, Object>> content, Option opt) {
|
||||
if (opt.getId() != -1) {
|
||||
List<Map<String,Object>> matchedContent = new ArrayList<Map<String,Object>>();
|
||||
for (Map<String, Object> sqlStat : content) {
|
||||
Integer idStr = (Integer)sqlStat.get("ID");
|
||||
if (idStr.intValue() == opt.getId()) {
|
||||
matchedContent.add(sqlStat);
|
||||
String dbType = (String) sqlStat.get("DbType");
|
||||
String sql = (String) sqlStat.get("SQL");
|
||||
System.out.println(SQLUtils.format(sql, dbType));
|
||||
System.out.println("===============================\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
content = matchedContent;
|
||||
if (opt.getId() != -1) {
|
||||
List<Map<String, Object>> matchedContent = new ArrayList<Map<String, Object>>();
|
||||
for (Map<String, Object> sqlStat : content) {
|
||||
Integer idStr = (Integer) sqlStat.get("ID");
|
||||
if (idStr.intValue() == opt.getId()) {
|
||||
matchedContent.add(sqlStat);
|
||||
String dbType = (String) sqlStat.get("DbType");
|
||||
String sql = (String) sqlStat.get("SQL");
|
||||
System.out.println(SQLUtils.format(sql, dbType));
|
||||
System.out.println("===============================\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
content = matchedContent;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
if (opt.getStyle() == Option.PrintStyle.HORIZONTAL) {
|
||||
System.out.println(getFormattedOutput(content, sqlRowTitle, sqlRowField));
|
||||
} else {
|
||||
@@ -120,17 +102,16 @@ public class TabledDataPrinter {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFormattedOutput(List<Map<String, Object>> content,
|
||||
String[] title , String[] rowField) {
|
||||
public static String getFormattedOutput(List<Map<String, Object>> content, String[] title, String[] rowField) {
|
||||
|
||||
List<String[]> printContents = new ArrayList<String[]>();
|
||||
printContents.add(title);
|
||||
|
||||
|
||||
for (Map<String, Object> sqlStat : content) {
|
||||
String[] row = new String[rowField.length];
|
||||
for (int i = 0; i < rowField.length; ++i) {
|
||||
Object value = sqlStat.get(rowField[i]);
|
||||
row[i] = handleAndConvert(value,rowField[i]);
|
||||
row[i] = handleAndConvert(value, rowField[i]);
|
||||
}
|
||||
printContents.add(row);
|
||||
}
|
||||
@@ -138,19 +119,18 @@ public class TabledDataPrinter {
|
||||
return formattedStr;
|
||||
}
|
||||
|
||||
|
||||
public static String getVerticalFormattedOutput(List<Map<String, Object>> content, String[] titleFields) {
|
||||
List<String[]> printContents = new ArrayList<String[]>();
|
||||
|
||||
int maxCol = content.size() > MAX_COL ? MAX_COL: content.size();
|
||||
|
||||
int maxCol = content.size() > MAX_COL ? MAX_COL : content.size();
|
||||
|
||||
for (int i = 0; i < titleFields.length; ++i) {
|
||||
String[] row = new String[maxCol+1];
|
||||
String[] row = new String[maxCol + 1];
|
||||
row[0] = titleFields[i];
|
||||
for (int j=0; j< maxCol ; j++) {
|
||||
Map<String,Object> sqlStat = content.get(j);
|
||||
for (int j = 0; j < maxCol; j++) {
|
||||
Map<String, Object> sqlStat = content.get(j);
|
||||
Object value = sqlStat.get(titleFields[i]);
|
||||
row[j+1] = handleAndConvert(value, titleFields[i]);
|
||||
row[j + 1] = handleAndConvert(value, titleFields[i]);
|
||||
}
|
||||
printContents.add(row);
|
||||
}
|
||||
@@ -161,11 +141,11 @@ public class TabledDataPrinter {
|
||||
public static String handleAndConvert(Object value, String fieldName) {
|
||||
if (value == null) value = "";
|
||||
if (fieldName.equals("SQL")) {
|
||||
String sql = (String)value;
|
||||
String sql = (String) value;
|
||||
sql = sql.replace("\n", " ");
|
||||
sql = sql.replace("\t", " ");
|
||||
if (sql.length() > SQL_MAX_LEN) {
|
||||
sql = sql.substring(0,SQL_MAX_LEN-3) + "...";
|
||||
sql = sql.substring(0, SQL_MAX_LEN - 3) + "...";
|
||||
}
|
||||
value = sql;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user