support monitor

This commit is contained in:
wenshao
2013-08-14 19:15:08 +08:00
parent 4ad313dfe2
commit 8953a9411c
3 changed files with 115 additions and 11 deletions
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.monitor.dao;
import java.lang.annotation.ElementType;
@@ -1,5 +1,6 @@
package com.alibaba.druid.bvt.support.monitor;
import java.util.Date;
import java.util.List;
import junit.framework.TestCase;
@@ -16,31 +17,48 @@ public class MonitorDaoJdbcImplTest extends TestCase {
public void testBuildSql() throws Exception {
MonitorDaoJdbcImpl dao = new MonitorDaoJdbcImpl();
String sql = dao.buildInsertSql(new BeanInfo(JdbcSqlStatValue.class));
{
String sql = dao.buildInsertSql(new BeanInfo(JdbcSqlStatValue.class));
System.out.println(SQLUtils.format(sql, JdbcConstants.MYSQL));
System.out.println(SQLUtils.format(sql, JdbcConstants.MYSQL));
}
{
String sql = buildCreateSql(dao, new BeanInfo(JdbcSqlStatValue.class));
System.out.println(SQLUtils.format(sql, JdbcConstants.MYSQL));
}
}
public String buildInsertSql(MonitorDaoJdbcImpl dao, BeanInfo beanInfo) {
public String buildCreateSql(MonitorDaoJdbcImpl dao, BeanInfo beanInfo) {
StringBuilder buf = new StringBuilder();
buf.append("CREATE TABLE ") //
.append(dao.getTableName(beanInfo));
buf.append(" (domain, app, cluster, host, pid, collectTime");
buf.append("( id bigint(20) NOT NULL");
buf.append(", domain varchar(45)");
buf.append(", app varchar(45)");
buf.append(", cluster varchar(45)");
buf.append(", host varchar(128)");
buf.append(", pid int(10)");
buf.append(", collectTime datetime NOT NULL");
List<FieldInfo> fields = beanInfo.getFields();
for (int i = 0; i < fields.size(); ++i) {
FieldInfo field = fields.get(i);
buf.append(", ");
buf.append(field.getColumnName());
if (field.getFieldType().equals(int.class) || field.getFieldType().equals(Integer.class)) {
buf.append(" int(10)");
} else if (field.getFieldType().equals(long.class) || field.getFieldType().equals(Long.class)) {
buf.append(" bigint(20)");
} else if (field.getFieldType().equals(String.class)) {
buf.append(" varchar(256)");
} else if (field.getFieldType().equals(Date.class)) {
buf.append(" datetime");
}
}
buf.append(")\nVALUES (?, ?, ?, ?, ?, ?");
for (int i = 0; i < fields.size(); ++i) {
buf.append(", ?");
}
buf.append(", PRIMARY KEY(id)");
buf.append(")");
return buf.toString();
}
}