Search in sources :

Example 21 with H2Client

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;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException)

Example 22 with H2Client

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;
}
Also used : StorageInstallException(org.apache.skywalking.apm.collector.storage.StorageInstallException) H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException)

Example 23 with H2Client

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;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException)

Example 24 with H2Client

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;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) NetworkAddress(org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException)

Example 25 with H2Client

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;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException)

Aggregations

H2Client (org.apache.skywalking.apm.collector.client.h2.H2Client)41 H2ClientException (org.apache.skywalking.apm.collector.client.h2.H2ClientException)40 ResultSet (java.sql.ResultSet)32 SQLException (java.sql.SQLException)32 LinkedList (java.util.LinkedList)10 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)3 StorageInstallException (org.apache.skywalking.apm.collector.storage.StorageInstallException)2 Instance (org.apache.skywalking.apm.collector.storage.table.register.Instance)2 JsonObject (com.google.gson.JsonObject)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 StandaloneModuleListenerService (org.apache.skywalking.apm.collector.cluster.standalone.service.StandaloneModuleListenerService)1 StandaloneModuleRegisterService (org.apache.skywalking.apm.collector.cluster.standalone.service.StandaloneModuleRegisterService)1 StorageException (org.apache.skywalking.apm.collector.storage.StorageException)1 BatchH2DAO (org.apache.skywalking.apm.collector.storage.h2.base.dao.BatchH2DAO)1 H2StorageInstaller (org.apache.skywalking.apm.collector.storage.h2.base.define.H2StorageInstaller)1 Application (org.apache.skywalking.apm.collector.storage.table.register.Application)1 NetworkAddress (org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress)1 ServiceName (org.apache.skywalking.apm.collector.storage.table.register.ServiceName)1 Application (org.apache.skywalking.apm.collector.storage.ui.application.Application)1