use of org.apache.skywalking.apm.collector.client.h2.H2Client in project incubator-skywalking by apache.
the class ServiceNameH2CacheDAO method getServiceId.
@Override
public int getServiceId(int applicationId, int srcSpanType, String serviceName) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_SERVICE_ID_SQL, ServiceNameTable.COLUMN_SERVICE_ID, ServiceNameTable.TABLE, ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SRC_SPAN_TYPE, ServiceNameTable.COLUMN_SERVICE_NAME);
Object[] params = new Object[] { applicationId, srcSpanType, serviceName };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getInt(ServiceNameTable.COLUMN_SERVICE_ID);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
use of org.apache.skywalking.apm.collector.client.h2.H2Client in project incubator-skywalking by apache.
the class H2StorageInstaller method isExists.
@Override
protected boolean isExists(Client client, TableDefine tableDefine) throws StorageException {
H2Client h2Client = (H2Client) client;
ResultSet rs = null;
try {
logger.info("check if table {} exist ", tableDefine.getName());
rs = h2Client.getConnection().getMetaData().getTables(null, null, tableDefine.getName().toUpperCase(), null);
if (rs.next()) {
return true;
}
} catch (SQLException | H2ClientException e) {
throw new StorageInstallException(e.getMessage(), e);
} finally {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
throw new StorageInstallException(e.getMessage(), e);
}
}
return false;
}
use of org.apache.skywalking.apm.collector.client.h2.H2Client in project incubator-skywalking by apache.
the class ApplicationH2CacheDAO method getApplicationIdByCode.
@Override
public int getApplicationIdByCode(String applicationCode) {
logger.info("get the application id with application code = {}", applicationCode);
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_SQL, ApplicationTable.COLUMN_APPLICATION_ID, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_CODE, ApplicationTable.COLUMN_IS_ADDRESS);
Object[] params = new Object[] { applicationCode, false };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getInt(1);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
use of org.apache.skywalking.apm.collector.client.h2.H2Client in project incubator-skywalking by apache.
the class NetworkAddressH2CacheDAO method getAddress.
@Override
public NetworkAddress getAddress(int addressId) {
logger.debug("get network address, address id: {}", addressId);
H2Client client = getClient();
String dynamicSql = "select * from {0} where {1} = ?";
String sql = SqlBuilder.buildSql(dynamicSql, NetworkAddressTable.TABLE, NetworkAddressTable.COLUMN_ADDRESS_ID);
Object[] params = new Object[] { addressId };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
NetworkAddress networkAddress = new NetworkAddress();
networkAddress.setId(rs.getString(NetworkAddressTable.COLUMN_ID));
networkAddress.setAddressId(rs.getInt(NetworkAddressTable.COLUMN_ADDRESS_ID));
networkAddress.setNetworkAddress(rs.getString(NetworkAddressTable.COLUMN_NETWORK_ADDRESS));
networkAddress.setSpanLayer(rs.getInt(NetworkAddressTable.COLUMN_SPAN_LAYER));
networkAddress.setServerType(rs.getInt(NetworkAddressTable.COLUMN_SERVER_TYPE));
return networkAddress;
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return null;
}
use of org.apache.skywalking.apm.collector.client.h2.H2Client in project incubator-skywalking by apache.
the class NetworkAddressH2CacheDAO method getAddressId.
@Override
public int getAddressId(String networkAddress) {
logger.info("get the address id with network address = {}", networkAddress);
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_ADDRESS_ID_OR_CODE_SQL, NetworkAddressTable.COLUMN_ADDRESS_ID, NetworkAddressTable.TABLE, NetworkAddressTable.COLUMN_NETWORK_ADDRESS);
Object[] params = new Object[] { networkAddress };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getInt(1);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return Const.NONE;
}
Aggregations