提交 6d90f2b9 编写于 作者: clevertension's avatar clevertension

polish code with sqlbuilder

上级 b31a47b7
......@@ -21,6 +21,7 @@ package org.skywalking.apm.collector.agentjvm.worker.cpu.dao;
import org.skywalking.apm.collector.core.stream.Data;
import org.skywalking.apm.collector.storage.define.DataDefine;
import org.skywalking.apm.collector.storage.define.jvm.CpuMetricTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.storage.h2.define.H2SqlEntity;
import org.skywalking.apm.collector.stream.worker.impl.dao.IPersistenceDAO;
......@@ -48,7 +49,7 @@ public class CpuMetricH2DAO extends H2DAO implements ICpuMetricDAO, IPersistence
source.put(CpuMetricTable.COLUMN_TIME_BUCKET, data.getDataLong(0));
logger.debug("prepare cpu metric batch insert, id: {}", data.getDataString(0));
String sql = getBatchInsertSql(CpuMetricTable.TABLE, source.keySet());
String sql = SqlBuilder.buildBatchInsertSql(CpuMetricTable.TABLE, source.keySet());
entity.setSql(sql);
entity.setParams(source.values().toArray(new Object[0]));
return entity;
......
......@@ -18,16 +18,17 @@
package org.skywalking.apm.collector.agentjvm.worker.gc.dao;
import java.util.HashMap;
import java.util.Map;
import org.skywalking.apm.collector.core.stream.Data;
import org.skywalking.apm.collector.storage.define.DataDefine;
import org.skywalking.apm.collector.storage.define.jvm.GCMetricTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.storage.h2.define.H2SqlEntity;
import org.skywalking.apm.collector.stream.worker.impl.dao.IPersistenceDAO;
import java.util.HashMap;
import java.util.Map;
/**
* @author pengys5, clevertension
*/
......@@ -46,7 +47,7 @@ public class GCMetricH2DAO extends H2DAO implements IGCMetricDAO, IPersistenceDA
source.put(GCMetricTable.COLUMN_TIME, data.getDataLong(1));
source.put(GCMetricTable.COLUMN_TIME_BUCKET, data.getDataLong(2));
String sql = getBatchInsertSql(GCMetricTable.TABLE, source.keySet());
String sql = SqlBuilder.buildBatchInsertSql(GCMetricTable.TABLE, source.keySet());
entity.setSql(sql);
entity.setParams(source.values().toArray(new Object[0]));
return entity;
......
......@@ -18,23 +18,26 @@
package org.skywalking.apm.collector.agentjvm.worker.heartbeat.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.framework.UnexpectedException;
import org.skywalking.apm.collector.core.stream.Data;
import org.skywalking.apm.collector.storage.define.DataDefine;
import org.skywalking.apm.collector.storage.define.register.InstanceTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.storage.h2.define.H2SqlEntity;
import org.skywalking.apm.collector.stream.worker.impl.dao.IPersistenceDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.*;
/**
* @author pengys5, clevertension
*/
......@@ -43,7 +46,7 @@ public class InstanceHeartBeatH2DAO extends H2DAO implements IInstanceHeartBeatD
private static final String GET_INSTANCE_HEARTBEAT_SQL = "select * from {0} where {1} = ?";
@Override public Data get(String id, DataDefine dataDefine) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_INSTANCE_HEARTBEAT_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID);
String sql = SqlBuilder.buildSql(GET_INSTANCE_HEARTBEAT_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID);
Object[] params = new Object[]{id};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
......@@ -66,7 +69,7 @@ public class InstanceHeartBeatH2DAO extends H2DAO implements IInstanceHeartBeatD
H2SqlEntity entity = new H2SqlEntity();
Map<String, Object> source = new HashMap<>();
source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, data.getDataLong(0));
String sql = getBatchUpdateSql(InstanceTable.TABLE, source.keySet(), InstanceTable.COLUMN_APPLICATION_ID);
String sql = SqlBuilder.buildBatchUpdateSql(InstanceTable.TABLE, source.keySet(), InstanceTable.COLUMN_APPLICATION_ID);
entity.setSql(sql);
List<Object> params = new ArrayList<>(source.values());
params.add(data.getDataString(0));
......
......@@ -18,16 +18,17 @@
package org.skywalking.apm.collector.agentjvm.worker.memory.dao;
import java.util.HashMap;
import java.util.Map;
import org.skywalking.apm.collector.core.stream.Data;
import org.skywalking.apm.collector.storage.define.DataDefine;
import org.skywalking.apm.collector.storage.define.jvm.MemoryMetricTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.storage.h2.define.H2SqlEntity;
import org.skywalking.apm.collector.stream.worker.impl.dao.IPersistenceDAO;
import java.util.HashMap;
import java.util.Map;
/**
* @author pengys5, clevertension
*/
......@@ -48,7 +49,7 @@ public class MemoryMetricH2DAO extends H2DAO implements IMemoryMetricDAO, IPersi
source.put(MemoryMetricTable.COLUMN_COMMITTED, data.getDataLong(3));
source.put(MemoryMetricTable.COLUMN_TIME_BUCKET, data.getDataLong(4));
String sql = getBatchInsertSql(MemoryMetricTable.TABLE, source.keySet());
String sql = SqlBuilder.buildBatchInsertSql(MemoryMetricTable.TABLE, source.keySet());
entity.setSql(sql);
entity.setParams(source.values().toArray(new Object[0]));
return entity;
......
......@@ -18,16 +18,17 @@
package org.skywalking.apm.collector.agentjvm.worker.memorypool.dao;
import java.util.HashMap;
import java.util.Map;
import org.skywalking.apm.collector.core.stream.Data;
import org.skywalking.apm.collector.storage.define.DataDefine;
import org.skywalking.apm.collector.storage.define.jvm.MemoryPoolMetricTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.storage.h2.define.H2SqlEntity;
import org.skywalking.apm.collector.stream.worker.impl.dao.IPersistenceDAO;
import java.util.HashMap;
import java.util.Map;
/**
* @author pengys5, clevertension
*/
......@@ -48,7 +49,7 @@ public class MemoryPoolMetricH2DAO extends H2DAO implements IMemoryPoolMetricDAO
source.put(MemoryPoolMetricTable.COLUMN_COMMITTED, data.getDataLong(3));
source.put(MemoryPoolMetricTable.COLUMN_TIME_BUCKET, data.getDataLong(4));
String sql = getBatchInsertSql(MemoryPoolMetricTable.TABLE, source.keySet());
String sql = SqlBuilder.buildBatchInsertSql(MemoryPoolMetricTable.TABLE, source.keySet());
entity.setSql(sql);
entity.setParams(source.values().toArray(new Object[0]));
return entity;
......
......@@ -19,12 +19,11 @@
package org.skywalking.apm.collector.agentregister.worker.application.dao;
import java.text.MessageFormat;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.storage.define.register.ApplicationDataDefine;
import org.skywalking.apm.collector.storage.define.register.ApplicationTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -57,7 +56,7 @@ public class ApplicationH2DAO extends H2DAO implements IApplicationDAO {
@Override
public void save(ApplicationDataDefine.Application application) {
H2Client client = getClient();
String sql = MessageFormat.format(INSERT_APPLICATION_SQL, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID,
String sql = SqlBuilder.buildSql(INSERT_APPLICATION_SQL, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID,
ApplicationTable.COLUMN_APPLICATION_CODE);
Object[] params = new Object[] {application.getApplicationId(), application.getApplicationCode()};
try {
......
......@@ -20,7 +20,6 @@ package org.skywalking.apm.collector.agentregister.worker.instance.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
......@@ -28,6 +27,7 @@ import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.storage.define.register.InstanceDataDefine;
import org.skywalking.apm.collector.storage.define.register.InstanceTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -43,7 +43,7 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
@Override public int getInstanceId(int applicationId, String agentUUID) {
logger.info("get the application id with application id = {}, agentUUID = {}", applicationId, agentUUID);
H2Client client = getClient();
String sql = MessageFormat.format(GET_INSTANCE_ID_SQL, InstanceTable.COLUMN_INSTANCE_ID, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID,
String sql = SqlBuilder.buildSql(GET_INSTANCE_ID_SQL, InstanceTable.COLUMN_INSTANCE_ID, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID,
InstanceTable.COLUMN_AGENT_UUID);
Object[] params = new Object[]{applicationId, agentUUID};
try (ResultSet rs = client.executeQuery(sql, params)) {
......@@ -73,7 +73,7 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
source.put(InstanceTable.COLUMN_REGISTER_TIME, instance.getRegisterTime());
source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, instance.getHeartBeatTime());
source.put(InstanceTable.COLUMN_OS_INFO, instance.getOsInfo());
String sql = getBatchInsertSql(InstanceTable.TABLE, source.keySet());
String sql = SqlBuilder.buildBatchInsertSql(InstanceTable.TABLE, source.keySet());
Object[] params = source.values().toArray(new Object[0]);
try {
client.execute(sql, params);
......@@ -84,7 +84,7 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
@Override public void updateHeartbeatTime(int instanceId, long heartbeatTime) {
H2Client client = getClient();
String sql = MessageFormat.format(UPDATE_HEARTBEAT_TIME_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME,
String sql = SqlBuilder.buildSql(UPDATE_HEARTBEAT_TIME_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME,
InstanceTable.COLUMN_INSTANCE_ID);
Object[] params = new Object[] {heartbeatTime, instanceId};
try {
......@@ -97,7 +97,7 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
@Override public int getApplicationId(int applicationInstanceId) {
logger.info("get the application id with application id = {}", applicationInstanceId);
H2Client client = getClient();
String sql = MessageFormat.format(GET_APPLICATION_ID_SQL, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID);
String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_SQL, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID);
Object[] params = new Object[]{applicationInstanceId};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
......
......@@ -18,21 +18,21 @@
package org.skywalking.apm.collector.agentregister.worker.servicename.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.storage.define.register.ServiceNameDataDefine;
import org.skywalking.apm.collector.storage.define.register.ServiceNameTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
/**
* @author pengys5, clevertension
*/
......@@ -44,7 +44,7 @@ public class ServiceNameH2DAO extends H2DAO implements IServiceNameDAO {
@Override
public int getServiceId(int applicationId, String serviceName) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_SERVICE_ID_SQL, ServiceNameTable.COLUMN_SERVICE_ID,
String sql = SqlBuilder.buildSql(GET_SERVICE_ID_SQL, ServiceNameTable.COLUMN_SERVICE_ID,
ServiceNameTable.TABLE, ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SERVICE_NAME);
Object[] params = new Object[]{applicationId, serviceName};
try (ResultSet rs = client.executeQuery(sql, params)) {
......@@ -71,7 +71,7 @@ public class ServiceNameH2DAO extends H2DAO implements IServiceNameDAO {
@Override
public String getServiceName(int serviceId) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_SERVICE_NAME_SQL, ServiceNameTable.COLUMN_SERVICE_NAME,
String sql = SqlBuilder.buildSql(GET_SERVICE_NAME_SQL, ServiceNameTable.COLUMN_SERVICE_NAME,
ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID);
Object[] params = new Object[]{serviceId};
try (ResultSet rs = client.executeQuery(sql, params)) {
......@@ -93,7 +93,7 @@ public class ServiceNameH2DAO extends H2DAO implements IServiceNameDAO {
source.put(ServiceNameTable.COLUMN_APPLICATION_ID, serviceName.getApplicationId());
source.put(ServiceNameTable.COLUMN_SERVICE_NAME, serviceName.getServiceName());
String sql = getBatchInsertSql(ServiceNameTable.TABLE, source.keySet());
String sql = SqlBuilder.buildBatchInsertSql(ServiceNameTable.TABLE, source.keySet());
Object[] params = source.values().toArray(new Object[0]);
try {
client.execute(sql, params);
......
......@@ -22,6 +22,7 @@ import org.skywalking.apm.collector.core.framework.UnexpectedException;
import org.skywalking.apm.collector.core.stream.Data;
import org.skywalking.apm.collector.storage.define.DataDefine;
import org.skywalking.apm.collector.storage.define.global.GlobalTraceTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.storage.h2.define.H2SqlEntity;
import org.skywalking.apm.collector.stream.worker.impl.dao.IPersistenceDAO;
......@@ -53,7 +54,7 @@ public class GlobalTraceH2DAO extends H2DAO implements IGlobalTraceDAO, IPersist
source.put(GlobalTraceTable.COLUMN_TIME_BUCKET, data.getDataLong(0));
logger.debug("global trace source: {}", source.toString());
String sql = getBatchInsertSql(GlobalTraceTable.TABLE, source.keySet());
String sql = SqlBuilder.buildBatchInsertSql(GlobalTraceTable.TABLE, source.keySet());
entity.setSql(sql);
entity.setParams(source.values().toArray(new Object[0]));
return entity;
......
......@@ -18,22 +18,25 @@
package org.skywalking.apm.collector.agentstream.worker.instance.performance.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.stream.Data;
import org.skywalking.apm.collector.storage.define.DataDefine;
import org.skywalking.apm.collector.storage.define.instance.InstPerformanceTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.storage.h2.define.H2SqlEntity;
import org.skywalking.apm.collector.stream.worker.impl.dao.IPersistenceDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.*;
/**
* @author pengys5, clevertension
*/
......@@ -42,7 +45,7 @@ public class InstPerformanceH2DAO extends H2DAO implements IInstPerformanceDAO,
private static final String GET_SQL = "select * from {0} where {1} = ?";
@Override public Data get(String id, DataDefine dataDefine) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_SQL, InstPerformanceTable.TABLE, "id");
String sql = SqlBuilder.buildSql(GET_SQL, InstPerformanceTable.TABLE, "id");
Object[] params = new Object[]{id};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
......@@ -68,7 +71,7 @@ public class InstPerformanceH2DAO extends H2DAO implements IInstPerformanceDAO,
source.put(InstPerformanceTable.COLUMN_CALLS, data.getDataInteger(2));
source.put(InstPerformanceTable.COLUMN_COST_TOTAL, data.getDataLong(0));
source.put(InstPerformanceTable.COLUMN_TIME_BUCKET, data.getDataLong(1));
String sql = getBatchInsertSql(InstPerformanceTable.TABLE, source.keySet());
String sql = SqlBuilder.buildBatchInsertSql(InstPerformanceTable.TABLE, source.keySet());
entity.setSql(sql);
entity.setParams(source.values().toArray(new Object[0]));
return entity;
......@@ -82,7 +85,7 @@ public class InstPerformanceH2DAO extends H2DAO implements IInstPerformanceDAO,
source.put(InstPerformanceTable.COLUMN_COST_TOTAL, data.getDataLong(0));
source.put(InstPerformanceTable.COLUMN_TIME_BUCKET, data.getDataLong(1));
String id = data.getDataString(0);
String sql = getBatchUpdateSql(InstPerformanceTable.TABLE, source.keySet(), "id");
String sql = SqlBuilder.buildBatchUpdateSql(InstPerformanceTable.TABLE, source.keySet(), "id");
entity.setSql(sql);
List<Object> values = new ArrayList<>(source.values());
values.add(id);
......
......@@ -18,23 +18,26 @@
package org.skywalking.apm.collector.agentstream.worker.node.component.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.stream.Data;
import org.skywalking.apm.collector.storage.define.DataDefine;
import org.skywalking.apm.collector.storage.define.node.NodeComponentTable;
import org.skywalking.apm.collector.storage.define.serviceref.ServiceReferenceTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.storage.h2.define.H2SqlEntity;
import org.skywalking.apm.collector.stream.worker.impl.dao.IPersistenceDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.*;
/**
* @author pengys5, clevertension
*/
......@@ -45,7 +48,7 @@ public class NodeComponentH2DAO extends H2DAO implements INodeComponentDAO, IPer
@Override
public Data get(String id, DataDefine dataDefine) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_SQL, ServiceReferenceTable.TABLE, "id");
String sql = SqlBuilder.buildSql(GET_SQL, ServiceReferenceTable.TABLE, "id");
Object[] params = new Object[]{id};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
......@@ -74,7 +77,7 @@ public class NodeComponentH2DAO extends H2DAO implements INodeComponentDAO, IPer
source.put(NodeComponentTable.COLUMN_PEER, data.getDataString(2));
source.put(NodeComponentTable.COLUMN_TIME_BUCKET, data.getDataLong(0));
String sql = getBatchInsertSql(NodeComponentTable.TABLE, source.keySet());
String sql = SqlBuilder.buildBatchInsertSql(NodeComponentTable.TABLE, source.keySet());
entity.setSql(sql);
entity.setParams(source.values().toArray(new Object[0]));
return entity;
......@@ -90,7 +93,7 @@ public class NodeComponentH2DAO extends H2DAO implements INodeComponentDAO, IPer
source.put(NodeComponentTable.COLUMN_PEER, data.getDataString(2));
source.put(NodeComponentTable.COLUMN_TIME_BUCKET, data.getDataLong(0));
String id = data.getDataString(0);
String sql = getBatchUpdateSql(NodeComponentTable.TABLE, source.keySet(), "id");
String sql = SqlBuilder.buildBatchUpdateSql(NodeComponentTable.TABLE, source.keySet(), "id");
entity.setSql(sql);
List<Object> values = new ArrayList<>(source.values());
values.add(id);
......
......@@ -18,23 +18,26 @@
package org.skywalking.apm.collector.agentstream.worker.node.mapping.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.skywalking.apm.collector.agentstream.worker.node.component.dao.NodeComponentH2DAO;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.stream.Data;
import org.skywalking.apm.collector.storage.define.DataDefine;
import org.skywalking.apm.collector.storage.define.node.NodeMappingTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.storage.h2.define.H2SqlEntity;
import org.skywalking.apm.collector.stream.worker.impl.dao.IPersistenceDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.*;
/**
* @author pengys5, clevertension
*/
......@@ -43,7 +46,7 @@ public class NodeMappingH2DAO extends H2DAO implements INodeMappingDAO, IPersist
private static final String GET_SQL = "select * from {0} where {1} = ?";
@Override public Data get(String id, DataDefine dataDefine) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_SQL, NodeMappingTable.TABLE, "id");
String sql = SqlBuilder.buildSql(GET_SQL, NodeMappingTable.TABLE, "id");
Object[] params = new Object[]{id};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
......@@ -67,7 +70,7 @@ public class NodeMappingH2DAO extends H2DAO implements INodeMappingDAO, IPersist
source.put(NodeMappingTable.COLUMN_ADDRESS_ID, data.getDataInteger(1));
source.put(NodeMappingTable.COLUMN_ADDRESS, data.getDataString(1));
source.put(NodeMappingTable.COLUMN_TIME_BUCKET, data.getDataLong(0));
String sql = getBatchInsertSql(NodeMappingTable.TABLE, source.keySet());
String sql = SqlBuilder.buildBatchInsertSql(NodeMappingTable.TABLE, source.keySet());
entity.setSql(sql);
entity.setParams(source.values().toArray(new Object[0]));
......@@ -81,7 +84,7 @@ public class NodeMappingH2DAO extends H2DAO implements INodeMappingDAO, IPersist
source.put(NodeMappingTable.COLUMN_ADDRESS, data.getDataString(1));
source.put(NodeMappingTable.COLUMN_TIME_BUCKET, data.getDataLong(0));
String id = data.getDataString(0);
String sql = getBatchUpdateSql(NodeMappingTable.TABLE, source.keySet(), "id");
String sql = SqlBuilder.buildBatchUpdateSql(NodeMappingTable.TABLE, source.keySet(), "id");
entity.setSql(sql);
List<Object> values = new ArrayList<>(source.values());
values.add(id);
......
......@@ -18,25 +18,25 @@
package org.skywalking.apm.collector.agentstream.worker.noderef.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.stream.Data;
import org.skywalking.apm.collector.storage.define.DataDefine;
import org.skywalking.apm.collector.storage.define.noderef.NodeReferenceTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.storage.h2.define.H2SqlEntity;
import org.skywalking.apm.collector.stream.worker.impl.dao.IPersistenceDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author pengys5, clevertension
*/
......@@ -45,7 +45,7 @@ public class NodeReferenceH2DAO extends H2DAO implements INodeReferenceDAO, IPer
private static final String GET_SQL = "select * from {0} where {1} = ?";
@Override public Data get(String id, DataDefine dataDefine) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_SQL, NodeReferenceTable.TABLE, "id");
String sql = SqlBuilder.buildSql(GET_SQL, NodeReferenceTable.TABLE, "id");
Object[] params = new Object[]{id};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
......@@ -81,7 +81,7 @@ public class NodeReferenceH2DAO extends H2DAO implements INodeReferenceDAO, IPer
source.put(NodeReferenceTable.COLUMN_SUMMARY, data.getDataInteger(6));
source.put(NodeReferenceTable.COLUMN_ERROR, data.getDataInteger(7));
source.put(NodeReferenceTable.COLUMN_TIME_BUCKET, data.getDataLong(0));
String sql = getBatchInsertSql(NodeReferenceTable.TABLE, source.keySet());
String sql = SqlBuilder.buildBatchInsertSql(NodeReferenceTable.TABLE, source.keySet());
entity.setSql(sql);
entity.setParams(source.values().toArray(new Object[0]));
......@@ -101,7 +101,7 @@ public class NodeReferenceH2DAO extends H2DAO implements INodeReferenceDAO, IPer
source.put(NodeReferenceTable.COLUMN_ERROR, data.getDataInteger(7));
source.put(NodeReferenceTable.COLUMN_TIME_BUCKET, data.getDataLong(0));
String id = data.getDataString(0);
String sql = getBatchUpdateSql(NodeReferenceTable.TABLE, source.keySet(), "id");
String sql = SqlBuilder.buildBatchUpdateSql(NodeReferenceTable.TABLE, source.keySet(), "id");
entity.setSql(sql);
List<Object> values = new ArrayList<>(source.values());
values.add(id);
......
......@@ -21,6 +21,7 @@ package org.skywalking.apm.collector.agentstream.worker.segment.cost.dao;
import org.skywalking.apm.collector.core.stream.Data;
import org.skywalking.apm.collector.storage.define.DataDefine;
import org.skywalking.apm.collector.storage.define.segment.SegmentCostTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.storage.h2.define.H2SqlEntity;
import org.skywalking.apm.collector.stream.worker.impl.dao.IPersistenceDAO;
......@@ -53,7 +54,7 @@ public class SegmentCostH2DAO extends H2DAO implements ISegmentCostDAO, IPersist
source.put(SegmentCostTable.COLUMN_TIME_BUCKET, data.getDataLong(3));
logger.debug("segment cost source: {}", source.toString());
String sql = getBatchInsertSql(SegmentCostTable.TABLE, source.keySet());
String sql = SqlBuilder.buildBatchInsertSql(SegmentCostTable.TABLE, source.keySet());
entity.setSql(sql);
entity.setParams(source.values().toArray(new Object[0]));
return entity;
......
......@@ -18,20 +18,21 @@
package org.skywalking.apm.collector.agentstream.worker.segment.origin.dao;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import org.skywalking.apm.collector.agentstream.worker.segment.cost.dao.SegmentCostH2DAO;
import org.skywalking.apm.collector.core.stream.Data;
import org.skywalking.apm.collector.storage.define.DataDefine;
import org.skywalking.apm.collector.storage.define.segment.SegmentTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.storage.h2.define.H2SqlEntity;
import org.skywalking.apm.collector.stream.worker.impl.dao.IPersistenceDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
/**
* @author pengys5, clevertension
*/
......@@ -47,7 +48,7 @@ public class SegmentH2DAO extends H2DAO implements ISegmentDAO, IPersistenceDAO<
source.put(SegmentTable.COLUMN_DATA_BINARY, Base64.getEncoder().encode(data.getDataBytes(0)));
logger.debug("segment source: {}", source.toString());
String sql = getBatchInsertSql(SegmentTable.TABLE, source.keySet());
String sql = SqlBuilder.buildBatchInsertSql(SegmentTable.TABLE, source.keySet());
entity.setSql(sql);
entity.setParams(source.values().toArray(new Object[0]));
return entity;
......
......@@ -18,32 +18,34 @@
package org.skywalking.apm.collector.agentstream.worker.service.entry.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.stream.Data;
import org.skywalking.apm.collector.storage.define.DataDefine;
import org.skywalking.apm.collector.storage.define.service.ServiceEntryTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.storage.h2.define.H2SqlEntity;
import org.skywalking.apm.collector.stream.worker.impl.dao.IPersistenceDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author pengys5, clevertension
*/
public class ServiceEntryH2DAO extends H2DAO implements IServiceEntryDAO, IPersistenceDAO<H2SqlEntity, H2SqlEntity> {
private final Logger logger = LoggerFactory.getLogger(ServiceEntryH2DAO.class);
private static final String GET_SERIVCE_ENTRY_SQL = "select * from {0} where {1} = ?";
@Override public Data get(String id, DataDefine dataDefine) {
H2Client client = getClient();
String sql = "select * from " + ServiceEntryTable.TABLE + " where id = ?";
String sql = SqlBuilder.buildSql(ServiceEntryTable.TABLE, "id");
Object[] params = new Object[] {id};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
......@@ -69,7 +71,7 @@ public class ServiceEntryH2DAO extends H2DAO implements IServiceEntryDAO, IPersi
source.put(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, data.getDataString(1));
source.put(ServiceEntryTable.COLUMN_REGISTER_TIME, data.getDataLong(0));
source.put(ServiceEntryTable.COLUMN_NEWEST_TIME, data.getDataLong(1));
String sql = getBatchInsertSql(ServiceEntryTable.TABLE, source.keySet());
String sql = SqlBuilder.buildBatchInsertSql(ServiceEntryTable.TABLE, source.keySet());
entity.setSql(sql);
entity.setParams(source.values().toArray(new Object[0]));
return entity;
......@@ -83,7 +85,7 @@ public class ServiceEntryH2DAO extends H2DAO implements IServiceEntryDAO, IPersi
source.put(ServiceEntryTable.COLUMN_REGISTER_TIME, data.getDataLong(0));
source.put(ServiceEntryTable.COLUMN_NEWEST_TIME, data.getDataLong(1));
String id = data.getDataString(0);
String sql = getBatchUpdateSql(ServiceEntryTable.TABLE, source.keySet(), "id");
String sql = SqlBuilder.buildBatchUpdateSql(ServiceEntryTable.TABLE, source.keySet(), "id");
entity.setSql(sql);
List<Object> values = new ArrayList<>(source.values());
values.add(id);
......
......@@ -20,7 +20,6 @@ package org.skywalking.apm.collector.agentstream.worker.serviceref.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -31,6 +30,7 @@ import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.stream.Data;
import org.skywalking.apm.collector.storage.define.DataDefine;
import org.skywalking.apm.collector.storage.define.serviceref.ServiceReferenceTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.storage.h2.define.H2SqlEntity;
import org.skywalking.apm.collector.stream.worker.impl.dao.IPersistenceDAO;
......@@ -46,7 +46,7 @@ public class ServiceReferenceH2DAO extends H2DAO implements IServiceReferenceDAO
@Override
public Data get(String id, DataDefine dataDefine) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_SQL, ServiceReferenceTable.TABLE, "id");
String sql = SqlBuilder.buildSql(GET_SQL, ServiceReferenceTable.TABLE, "id");
Object[] params = new Object[]{id};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
......@@ -93,7 +93,7 @@ public class ServiceReferenceH2DAO extends H2DAO implements IServiceReferenceDAO
source.put(ServiceReferenceTable.COLUMN_COST_SUMMARY, data.getDataLong(6));
source.put(ServiceReferenceTable.COLUMN_TIME_BUCKET, data.getDataLong(7));
String sql = getBatchInsertSql(ServiceReferenceTable.TABLE, source.keySet());
String sql = SqlBuilder.buildBatchInsertSql(ServiceReferenceTable.TABLE, source.keySet());
entity.setSql(sql);
entity.setParams(source.values().toArray(new Object[0]));
return entity;
......@@ -119,7 +119,7 @@ public class ServiceReferenceH2DAO extends H2DAO implements IServiceReferenceDAO
source.put(ServiceReferenceTable.COLUMN_TIME_BUCKET, data.getDataLong(7));
String id = data.getDataString(0);
String sql = getBatchUpdateSql(ServiceReferenceTable.TABLE, source.keySet(), "id");
String sql = SqlBuilder.buildBatchUpdateSql(ServiceReferenceTable.TABLE, source.keySet(), "id");
entity.setSql(sql);
List<Object> values = new ArrayList<>(source.values());
values.add(id);
......
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.h2;
import java.text.MessageFormat;
import java.util.List;
import java.util.Set;
public class SqlBuilder {
public static final String buildSql(String sql, Object ... args) {
return MessageFormat.format(sql, args);
}
public static final String buildSql(String sql, List<Object> args) {
MessageFormat messageFormat = new MessageFormat(sql);
return messageFormat.format(args.toArray(new Object[0]));
}
public static final String buildBatchInsertSql(String tableName, Set<String> columnNames) {
StringBuilder sb = new StringBuilder("insert into ");
sb.append(tableName).append("(");
columnNames.forEach((columnName) -> {
sb.append(columnName).append(",");
});
sb.delete(sb.length() - 1, sb.length());
sb.append(") values(");
for (int i = 0; i < columnNames.size(); i++) {
sb.append("?,");
}
sb.delete(sb.length() - 1, sb.length());
sb.append(")");
return sb.toString();
}
public static final String buildBatchUpdateSql(String tableName, Set<String> columnNames, String whereClauseName) {
StringBuilder sb = new StringBuilder("update ");
sb.append(tableName).append(" set ");
columnNames.forEach((columnName) -> {
sb.append(columnName).append("=?,");
});
sb.delete(sb.length() - 1, sb.length());
sb.append(" where ").append(whereClauseName).append("=?");
return sb.toString();
}
}
......@@ -18,16 +18,15 @@
package org.skywalking.apm.collector.storage.h2.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.storage.dao.DAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Set;
/**
* @author pengys5
*/
......@@ -60,30 +59,4 @@ public abstract class H2DAO extends DAO<H2Client> {
return 0;
}
public final String getBatchInsertSql(String tableName, Set<String> columnNames) {
StringBuilder sb = new StringBuilder("insert into ");
sb.append(tableName).append("(");
columnNames.forEach((columnName) -> {
sb.append(columnName).append(",");
});
sb.delete(sb.length() - 1, sb.length());
sb.append(") values(");
for (int i = 0; i < columnNames.size(); i++) {
sb.append("?,");
}
sb.delete(sb.length() - 1, sb.length());
sb.append(")");
return sb.toString();
}
public final String getBatchUpdateSql(String tableName, Set<String> columnNames, String whereClauseName) {
StringBuilder sb = new StringBuilder("update ");
sb.append(tableName).append(" set ");
columnNames.forEach((columnName) -> {
sb.append(columnName).append("=?,");
});
sb.delete(sb.length() - 1, sb.length());
sb.append(" where ").append(whereClauseName).append("=?");
return sb.toString();
}
}
......@@ -18,18 +18,18 @@
package org.skywalking.apm.collector.ui.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.storage.define.register.ApplicationTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
/**
* @author pengys5, clevertension
*/
......@@ -40,7 +40,7 @@ public class ApplicationH2DAO extends H2DAO implements IApplicationDAO {
@Override public String getApplicationCode(int applicationId) {
logger.debug("get application code, applicationId: {}", applicationId);
H2Client client = getClient();
String sql = MessageFormat.format(GET_APPLICATION_CODE_SQL, ApplicationTable.COLUMN_APPLICATION_CODE, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID);
String sql = SqlBuilder.buildSql(GET_APPLICATION_CODE_SQL, ApplicationTable.COLUMN_APPLICATION_CODE, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID);
Object[] params = new Object[]{applicationId};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
......
......@@ -18,21 +18,22 @@
package org.skywalking.apm.collector.ui.dao;
import com.google.gson.JsonArray;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.define.jvm.CpuMetricTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.JsonArray;
/**
* @author pengys5, clevertension
......@@ -44,7 +45,7 @@ public class CpuMetricH2DAO extends H2DAO implements ICpuMetricDAO {
@Override public int getMetric(int instanceId, long timeBucket) {
String id = timeBucket + Const.ID_SPLIT + instanceId;
H2Client client = getClient();
String sql = MessageFormat.format(GET_CPU_METRIC_SQL, CpuMetricTable.TABLE, "id");
String sql = SqlBuilder.buildSql(GET_CPU_METRIC_SQL, CpuMetricTable.TABLE, "id");
Object[] params = new Object[]{id};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
......@@ -58,7 +59,7 @@ public class CpuMetricH2DAO extends H2DAO implements ICpuMetricDAO {
@Override public JsonArray getMetric(int instanceId, long startTimeBucket, long endTimeBucket) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_CPU_METRICS_SQL, CpuMetricTable.TABLE, "id");
String sql = SqlBuilder.buildSql(GET_CPU_METRICS_SQL, CpuMetricTable.TABLE, "id");
long timeBucket = startTimeBucket;
List<String> idList = new ArrayList<>();
......
......@@ -18,23 +18,24 @@
package org.skywalking.apm.collector.ui.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.define.jvm.GCMetricTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.network.proto.GCPhrase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
/**
* @author pengys5, clevertension
......@@ -55,7 +56,7 @@ public class GCMetricH2DAO extends H2DAO implements IGCMetricDAO {
builder.delete(builder.length() - 1, builder.length());
builder.append(")");
sql = sql + builder + " group by {1}";
sql = MessageFormat.format(sql, GCMetricTable.COLUMN_COUNT, GCMetricTable.COLUMN_PHRASE,
sql = SqlBuilder.buildSql(sql, GCMetricTable.COLUMN_COUNT, GCMetricTable.COLUMN_PHRASE,
GCMetricTable.TABLE, GCMetricTable.COLUMN_INSTANCE_ID, "id");
Object[] params = new Object[timeBuckets.length + 1];
for (int i = 0; i < timeBuckets.length; i++) {
......@@ -82,7 +83,7 @@ public class GCMetricH2DAO extends H2DAO implements IGCMetricDAO {
@Override public JsonObject getMetric(int instanceId, long timeBucket) {
JsonObject response = new JsonObject();
H2Client client = getClient();
String sql = MessageFormat.format(GET_GC_METRIC_SQL, GCMetricTable.TABLE, "id");
String sql = SqlBuilder.buildSql(GET_GC_METRIC_SQL, GCMetricTable.TABLE, "id");
String youngId = timeBucket + Const.ID_SPLIT + GCPhrase.NEW_VALUE + instanceId;
Object[] params = new Object[]{youngId};
try (ResultSet rs = client.executeQuery(sql, params)) {
......@@ -108,7 +109,7 @@ public class GCMetricH2DAO extends H2DAO implements IGCMetricDAO {
@Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket) {
JsonObject response = new JsonObject();
H2Client client = getClient();
String sql = MessageFormat.format(GET_GC_METRICS_SQL, GCMetricTable.TABLE, "id");
String sql = SqlBuilder.buildSql(GET_GC_METRICS_SQL, GCMetricTable.TABLE, "id");
long timeBucket = startTimeBucket;
List<String> idList = new ArrayList<>();
do {
......@@ -146,7 +147,7 @@ public class GCMetricH2DAO extends H2DAO implements IGCMetricDAO {
idList1.add(oldId);
}
while (timeBucket <= endTimeBucket);
String sql1 = MessageFormat.format(GET_GC_METRICS_SQL, GCMetricTable.TABLE, "id");
String sql1 = SqlBuilder.buildSql(GET_GC_METRICS_SQL, GCMetricTable.TABLE, "id");
StringBuilder builder1 = new StringBuilder();
for (int i = 0; i < idList1.size(); i++) {
builder1.append("?,");
......
......@@ -18,19 +18,19 @@
package org.skywalking.apm.collector.ui.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.storage.define.global.GlobalTraceTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
/**
* @author pengys5, clevertension
*/
......@@ -41,7 +41,7 @@ public class GlobalTraceH2DAO extends H2DAO implements IGlobalTraceDAO {
@Override public List<String> getGlobalTraceId(String segmentId) {
List<String> globalTraceIds = new ArrayList<>();
H2Client client = getClient();
String sql = MessageFormat.format(GET_GLOBAL_TRACE_ID_SQL, GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID,
String sql = SqlBuilder.buildSql(GET_GLOBAL_TRACE_ID_SQL, GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID,
GlobalTraceTable.TABLE, GlobalTraceTable.COLUMN_SEGMENT_ID);
Object[] params = new Object[]{segmentId};
try (ResultSet rs = client.executeQuery(sql, params)) {
......@@ -59,7 +59,7 @@ public class GlobalTraceH2DAO extends H2DAO implements IGlobalTraceDAO {
@Override public List<String> getSegmentIds(String globalTraceId) {
List<String> segmentIds = new ArrayList<>();
H2Client client = getClient();
String sql = MessageFormat.format(GET_SEGMENT_IDS_SQL, GlobalTraceTable.COLUMN_SEGMENT_ID,
String sql = SqlBuilder.buildSql(GET_SEGMENT_IDS_SQL, GlobalTraceTable.COLUMN_SEGMENT_ID,
GlobalTraceTable.TABLE, GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID);
Object[] params = new Object[]{globalTraceId};
try (ResultSet rs = client.executeQuery(sql, params)) {
......
......@@ -18,21 +18,22 @@
package org.skywalking.apm.collector.ui.dao;
import com.google.gson.JsonArray;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.define.instance.InstPerformanceTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.JsonArray;
/**
* @author pengys5, clevertension
......@@ -45,7 +46,7 @@ public class InstPerformanceH2DAO extends H2DAO implements IInstPerformanceDAO {
@Override public InstPerformance get(long[] timeBuckets, int instanceId) {
H2Client client = getClient();
logger.info("the inst performance inst id = {}", instanceId);
String sql = MessageFormat.format(GET_INST_PERF_SQL, InstPerformanceTable.TABLE, InstPerformanceTable.COLUMN_INSTANCE_ID, InstPerformanceTable.COLUMN_TIME_BUCKET);
String sql = SqlBuilder.buildSql(GET_INST_PERF_SQL, InstPerformanceTable.TABLE, InstPerformanceTable.COLUMN_INSTANCE_ID, InstPerformanceTable.COLUMN_TIME_BUCKET);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < timeBuckets.length; i++) {
builder.append("?,");
......@@ -73,7 +74,7 @@ public class InstPerformanceH2DAO extends H2DAO implements IInstPerformanceDAO {
@Override public int getTpsMetric(int instanceId, long timeBucket) {
logger.info("getTpMetric instanceId = {}, startTimeBucket = {}", instanceId, timeBucket);
H2Client client = getClient();
String sql = MessageFormat.format(GET_TPS_METRIC_SQL, InstPerformanceTable.TABLE, "id");
String sql = SqlBuilder.buildSql(GET_TPS_METRIC_SQL, InstPerformanceTable.TABLE, "id");
Object[] params = new Object[]{instanceId};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
......@@ -88,7 +89,7 @@ public class InstPerformanceH2DAO extends H2DAO implements IInstPerformanceDAO {
@Override public JsonArray getTpsMetric(int instanceId, long startTimeBucket, long endTimeBucket) {
logger.info("getTpsMetric instanceId = {}, startTimeBucket = {}, endTimeBucket = {}", instanceId, startTimeBucket, endTimeBucket);
H2Client client = getClient();
String sql = MessageFormat.format(GET_TPS_METRICS_SQL, InstPerformanceTable.TABLE, "id");
String sql = SqlBuilder.buildSql(GET_TPS_METRICS_SQL, InstPerformanceTable.TABLE, "id");
long timeBucket = startTimeBucket;
List<String> idList = new ArrayList<>();
......@@ -122,7 +123,7 @@ public class InstPerformanceH2DAO extends H2DAO implements IInstPerformanceDAO {
@Override public int getRespTimeMetric(int instanceId, long timeBucket) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_TPS_METRIC_SQL, InstPerformanceTable.TABLE, "id");
String sql = SqlBuilder.buildSql(GET_TPS_METRIC_SQL, InstPerformanceTable.TABLE, "id");
Object[] params = new Object[]{instanceId};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
......@@ -138,7 +139,7 @@ public class InstPerformanceH2DAO extends H2DAO implements IInstPerformanceDAO {
@Override public JsonArray getRespTimeMetric(int instanceId, long startTimeBucket, long endTimeBucket) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_TPS_METRICS_SQL, InstPerformanceTable.TABLE, "id");
String sql = SqlBuilder.buildSql(GET_TPS_METRICS_SQL, InstPerformanceTable.TABLE, "id");
long timeBucket = startTimeBucket;
List<String> idList = new ArrayList<>();
......
......@@ -18,23 +18,24 @@
package org.skywalking.apm.collector.ui.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.define.register.InstanceDataDefine;
import org.skywalking.apm.collector.storage.define.register.InstanceTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.ui.cache.ApplicationCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.LinkedList;
import java.util.List;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
/**
* @author pengys5, clevertension
......@@ -52,7 +53,7 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
H2Client client = getClient();
long fiveMinuteBefore = System.currentTimeMillis() - 5 * 60 * 1000;
fiveMinuteBefore = TimeBucketUtils.INSTANCE.getSecondTimeBucket(fiveMinuteBefore);
String sql = MessageFormat.format(GET_LAST_HEARTBEAT_TIME_SQL, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME);
String sql = SqlBuilder.buildSql(GET_LAST_HEARTBEAT_TIME_SQL, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME);
Object[] params = new Object[]{fiveMinuteBefore};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
......@@ -69,7 +70,7 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
H2Client client = getClient();
long fiveMinuteBefore = System.currentTimeMillis() - 5 * 60 * 1000;
fiveMinuteBefore = TimeBucketUtils.INSTANCE.getSecondTimeBucket(fiveMinuteBefore);
String sql = MessageFormat.format(GET_INST_LAST_HEARTBEAT_TIME_SQL, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.TABLE,
String sql = SqlBuilder.buildSql(GET_INST_LAST_HEARTBEAT_TIME_SQL, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.TABLE,
InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_INSTANCE_ID);
Object[] params = new Object[]{fiveMinuteBefore, applicationInstanceId};
try (ResultSet rs = client.executeQuery(sql, params)) {
......@@ -86,7 +87,7 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
public JsonArray getApplications(long startTime, long endTime) {
H2Client client = getClient();
JsonArray applications = new JsonArray();
String sql = MessageFormat.format(GET_APPLICATIONS_SQL, InstanceTable.COLUMN_INSTANCE_ID,
String sql = SqlBuilder.buildSql(GET_APPLICATIONS_SQL, InstanceTable.COLUMN_INSTANCE_ID,
InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_APPLICATION_ID);
Object[] params = new Object[]{startTime, endTime};
try (ResultSet rs = client.executeQuery(sql, params)) {
......@@ -108,7 +109,7 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
@Override
public InstanceDataDefine.Instance getInstance(int instanceId) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_INSTANCE_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID);
String sql = SqlBuilder.buildSql(GET_INSTANCE_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID);
Object[] params = new Object[]{instanceId};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
......@@ -132,7 +133,7 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
logger.debug("get instances info, application id: {}, timeBucket: {}", applicationId, timeBucket);
List<InstanceDataDefine.Instance> instanceList = new LinkedList<>();
H2Client client = getClient();
String sql = MessageFormat.format(GET_INSTANCES_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.COLUMN_HEARTBEAT_TIME);
String sql = SqlBuilder.buildSql(GET_INSTANCES_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.COLUMN_HEARTBEAT_TIME);
Object[] params = new Object[]{applicationId, timeBucket};
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
......
......@@ -18,22 +18,23 @@
package org.skywalking.apm.collector.ui.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.define.jvm.MemoryMetricTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
/**
* @author clevertension
......@@ -45,7 +46,7 @@ public class MemoryMetricH2DAO extends H2DAO implements IMemoryMetricDAO {
@Override public JsonObject getMetric(int instanceId, long timeBucket, boolean isHeap) {
H2Client client = getClient();
String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + isHeap;
String sql = MessageFormat.format(GET_MEMORY_METRIC_SQL, MemoryMetricTable.TABLE, "id");
String sql = SqlBuilder.buildSql(GET_MEMORY_METRIC_SQL, MemoryMetricTable.TABLE, "id");
Object[] params = new Object[]{id};
JsonObject metric = new JsonObject();
try (ResultSet rs = client.executeQuery(sql, params)) {
......@@ -66,7 +67,7 @@ public class MemoryMetricH2DAO extends H2DAO implements IMemoryMetricDAO {
@Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, boolean isHeap) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_MEMORY_METRICS_SQL, MemoryMetricTable.TABLE, "id");
String sql = SqlBuilder.buildSql(GET_MEMORY_METRICS_SQL, MemoryMetricTable.TABLE, "id");
List<String> idList = new ArrayList<>();
long timeBucket = startTimeBucket;
do {
......
......@@ -18,22 +18,23 @@
package org.skywalking.apm.collector.ui.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.define.jvm.MemoryPoolMetricTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
/**
* @author clevertension
......@@ -45,7 +46,7 @@ public class MemoryPoolMetricH2DAO extends H2DAO implements IMemoryPoolMetricDAO
@Override public JsonObject getMetric(int instanceId, long timeBucket, int poolType) {
H2Client client = getClient();
String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + poolType;
String sql = MessageFormat.format(GET_MEMORY_POOL_METRIC_SQL, MemoryPoolMetricTable.TABLE, "id");
String sql = SqlBuilder.buildSql(GET_MEMORY_POOL_METRIC_SQL, MemoryPoolMetricTable.TABLE, "id");
Object[] params = new Object[]{id};
JsonObject metric = new JsonObject();
try (ResultSet rs = client.executeQuery(sql, params)) {
......@@ -66,7 +67,7 @@ public class MemoryPoolMetricH2DAO extends H2DAO implements IMemoryPoolMetricDAO
@Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, int poolType) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_MEMORY_POOL_METRICS_SQL, MemoryPoolMetricTable.TABLE, "id");
String sql = SqlBuilder.buildSql(GET_MEMORY_POOL_METRICS_SQL, MemoryPoolMetricTable.TABLE, "id");
List<String> idList = new ArrayList<>();
long timeBucket = startTimeBucket;
do {
......
......@@ -18,21 +18,22 @@
package org.skywalking.apm.collector.ui.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.define.node.NodeComponentTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.ui.cache.ApplicationCache;
import org.skywalking.apm.network.trace.component.ComponentsDefine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
/**
* @author pengys5, clevertension
......@@ -49,7 +50,7 @@ public class NodeComponentH2DAO extends H2DAO implements INodeComponentDAO {
H2Client client = getClient();
JsonArray nodeComponentArray = new JsonArray();
String sql = MessageFormat.format(AGGREGATE_COMPONENT_SQL, NodeComponentTable.COLUMN_COMPONENT_ID,
String sql = SqlBuilder.buildSql(AGGREGATE_COMPONENT_SQL, NodeComponentTable.COLUMN_COMPONENT_ID,
NodeComponentTable.COLUMN_PEER, NodeComponentTable.COLUMN_PEER_ID,
NodeComponentTable.TABLE, NodeComponentTable.COLUMN_TIME_BUCKET);
Object[] params = new Object[]{startTime, endTime};
......
......@@ -18,20 +18,21 @@
package org.skywalking.apm.collector.ui.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.define.node.NodeMappingTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.ui.cache.ApplicationCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
/**
* @author pengys5, clevertension
......@@ -42,7 +43,7 @@ public class NodeMappingH2DAO extends H2DAO implements INodeMappingDAO {
@Override public JsonArray load(long startTime, long endTime) {
H2Client client = getClient();
JsonArray nodeMappingArray = new JsonArray();
String sql = MessageFormat.format(NODE_MAPPING_SQL, NodeMappingTable.COLUMN_APPLICATION_ID,
String sql = SqlBuilder.buildSql(NODE_MAPPING_SQL, NodeMappingTable.COLUMN_APPLICATION_ID,
NodeMappingTable.COLUMN_ADDRESS_ID, NodeMappingTable.COLUMN_ADDRESS,
NodeMappingTable.TABLE, NodeMappingTable.COLUMN_TIME_BUCKET);
......
......@@ -18,20 +18,21 @@
package org.skywalking.apm.collector.ui.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.define.noderef.NodeReferenceTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.ui.cache.ApplicationCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
/**
* @author pengys5, clevertension
......@@ -43,7 +44,7 @@ public class NodeReferenceH2DAO extends H2DAO implements INodeReferenceDAO {
@Override public JsonArray load(long startTime, long endTime) {
H2Client client = getClient();
JsonArray nodeRefResSumArray = new JsonArray();
String sql = MessageFormat.format(NODE_REFERENCE_SQL, NodeReferenceTable.COLUMN_S1_LTE,
String sql = SqlBuilder.buildSql(NODE_REFERENCE_SQL, NodeReferenceTable.COLUMN_S1_LTE,
NodeReferenceTable.COLUMN_S3_LTE, NodeReferenceTable.COLUMN_S5_LTE,
NodeReferenceTable.COLUMN_S5_GT, NodeReferenceTable.COLUMN_SUMMARY,
NodeReferenceTable.COLUMN_ERROR, NodeReferenceTable.TABLE, NodeReferenceTable.COLUMN_TIME_BUCKET,
......
......@@ -20,7 +20,6 @@ package org.skywalking.apm.collector.ui.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
......@@ -32,6 +31,7 @@ import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.dao.DAOContainer;
import org.skywalking.apm.collector.storage.define.global.GlobalTraceTable;
import org.skywalking.apm.collector.storage.define.segment.SegmentCostTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -116,8 +116,7 @@ public class SegmentCostH2DAO extends H2DAO implements ISegmentCostDAO {
}
sql = sql + " limit " + from + "," + limit;
MessageFormat messageFormat = new MessageFormat(sql);
sql = messageFormat.format(columns.toArray(new Object[0]));
sql = SqlBuilder.buildSql(sql, columns);
Object[] p = params.toArray(new Object[0]);
JsonObject topSegPaging = new JsonObject();
......
......@@ -18,20 +18,21 @@
package org.skywalking.apm.collector.ui.dao;
import com.google.protobuf.InvalidProtocolBufferException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Base64;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.define.segment.SegmentTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.network.proto.TraceSegmentObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.Base64;
import com.google.protobuf.InvalidProtocolBufferException;
/**
* @author pengys5, clevertension
......@@ -41,7 +42,7 @@ public class SegmentH2DAO extends H2DAO implements ISegmentDAO {
private static final String GET_SEGMENT_SQL = "select {0} from {1} where {2} = ?";
@Override public TraceSegmentObject load(String segmentId) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_SEGMENT_SQL, SegmentTable.COLUMN_DATA_BINARY,
String sql = SqlBuilder.buildSql(GET_SEGMENT_SQL, SegmentTable.COLUMN_DATA_BINARY,
SegmentTable.TABLE, "id");
Object[] params = new Object[]{segmentId};
try (ResultSet rs = client.executeQuery(sql, params)) {
......
......@@ -18,23 +18,24 @@
package org.skywalking.apm.collector.ui.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.ColumnNameUtils;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.define.service.ServiceEntryTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.ui.cache.ApplicationCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
/**
* @author pengys5
......@@ -67,8 +68,7 @@ public class ServiceEntryH2DAO extends H2DAO implements IServiceEntryDAO {
columns.add(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME);
}
sql = sql + " limit " + from + "," + size;
MessageFormat messageFormat = new MessageFormat(sql);
sql = messageFormat.format(columns.toArray(new Object[0]));
sql = SqlBuilder.buildSql(sql, columns);
Object[] p = params.toArray(new Object[0]);
JsonArray serviceArray = new JsonArray();
JsonObject response = new JsonObject();
......
......@@ -18,18 +18,18 @@
package org.skywalking.apm.collector.ui.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.storage.define.register.ServiceNameTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
/**
* @author pengys5, clevertension
*/
......@@ -39,7 +39,7 @@ public class ServiceNameH2DAO extends H2DAO implements IServiceNameDAO {
private static final String GET_SERVICE_ID_SQL = "select {0} from {1} where {2} = ? and {3} = ? limit 1";
@Override public String getServiceName(int serviceId) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_SERVICE_NAME_SQL, ServiceNameTable.COLUMN_SERVICE_NAME,
String sql = SqlBuilder.buildSql(GET_SERVICE_NAME_SQL, ServiceNameTable.COLUMN_SERVICE_NAME,
ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID);
Object[] params = new Object[]{serviceId};
try (ResultSet rs = client.executeQuery(sql, params)) {
......@@ -54,7 +54,7 @@ public class ServiceNameH2DAO extends H2DAO implements IServiceNameDAO {
@Override public int getServiceId(int applicationId, String serviceName) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_SERVICE_ID_SQL, ServiceNameTable.COLUMN_SERVICE_ID,
String sql = SqlBuilder.buildSql(GET_SERVICE_ID_SQL, ServiceNameTable.COLUMN_SERVICE_ID,
ServiceNameTable.TABLE, ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SERVICE_NAME);
Object[] params = new Object[]{applicationId, serviceName};
try (ResultSet rs = client.executeQuery(sql, params)) {
......
......@@ -20,7 +20,6 @@ package org.skywalking.apm.collector.ui.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
......@@ -32,6 +31,7 @@ import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.ObjectUtils;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.define.serviceref.ServiceReferenceTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.skywalking.apm.collector.ui.cache.ServiceIdCache;
import org.skywalking.apm.collector.ui.cache.ServiceNameCache;
......@@ -54,7 +54,7 @@ public class ServiceReferenceH2DAO extends H2DAO implements IServiceReferenceDAO
@Override public JsonArray load(int entryServiceId, long startTime, long endTime) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_SRV_REF_LOAD1, ServiceReferenceTable.TABLE,
String sql = SqlBuilder.buildSql(GET_SRV_REF_LOAD1, ServiceReferenceTable.TABLE,
ServiceReferenceTable.COLUMN_TIME_BUCKET, ServiceReferenceTable.COLUMN_ENTRY_SERVICE_ID, ServiceReferenceTable.COLUMN_ENTRY_SERVICE_NAME,
ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID, ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID,
ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME, ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME,
......@@ -99,7 +99,7 @@ public class ServiceReferenceH2DAO extends H2DAO implements IServiceReferenceDAO
@Override public JsonArray load(String entryServiceName, int entryApplicationId, long startTime, long endTime) {
H2Client client = getClient();
String sql = MessageFormat.format(GET_SRV_REF_LOAD2, ServiceReferenceTable.TABLE,
String sql = SqlBuilder.buildSql(GET_SRV_REF_LOAD2, ServiceReferenceTable.TABLE,
ServiceReferenceTable.COLUMN_TIME_BUCKET, ServiceReferenceTable.COLUMN_ENTRY_SERVICE_NAME,
ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID, ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID,
ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME, ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME,
......@@ -110,7 +110,7 @@ public class ServiceReferenceH2DAO extends H2DAO implements IServiceReferenceDAO
Object[] params = new Object[]{startTime, endTime, entryServiceName};
int entryServiceId = ServiceIdCache.get(entryApplicationId, entryServiceName);
if (entryServiceId != 0) {
sql = MessageFormat.format(GET_SRV_REF_LOAD1, ServiceReferenceTable.TABLE,
sql = SqlBuilder.buildSql(GET_SRV_REF_LOAD1, ServiceReferenceTable.TABLE,
ServiceReferenceTable.COLUMN_TIME_BUCKET, ServiceReferenceTable.COLUMN_ENTRY_SERVICE_ID, ServiceReferenceTable.COLUMN_ENTRY_SERVICE_NAME,
ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID, ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID,
ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME, ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册