Search in sources :

Example 1 with H2ClientException

use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.

the class ApplicationH2CacheDAO method getApplicationIdByAddressId.

@Override
public int getApplicationIdByAddressId(int addressId) {
    logger.info("get the application id with address id = {}", addressId);
    H2Client client = getClient();
    String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_SQL, ApplicationTable.COLUMN_APPLICATION_ID, ApplicationTable.TABLE, ApplicationTable.COLUMN_ADDRESS_ID, ApplicationTable.COLUMN_IS_ADDRESS);
    Object[] params = new Object[] { addressId, true };
    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 2 with H2ClientException

use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.

the class ApplicationH2CacheDAO method getApplication.

@Override
public Application getApplication(int applicationId) {
    logger.debug("get application code, applicationId: {}", applicationId);
    H2Client client = getClient();
    String sql = SqlBuilder.buildSql(GET_APPLICATION_SQL, ApplicationTable.COLUMN_APPLICATION_CODE, ApplicationTable.COLUMN_IS_ADDRESS, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID);
    Object[] params = new Object[] { applicationId };
    try (ResultSet rs = client.executeQuery(sql, params)) {
        if (rs.next()) {
            Application application = new Application();
            application.setApplicationId(applicationId);
            application.setApplicationCode(rs.getString(1));
            application.setIsAddress(rs.getInt(2));
            return application;
        }
    } catch (SQLException | H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
    return null;
}
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) Application(org.apache.skywalking.apm.collector.storage.table.register.Application)

Example 3 with H2ClientException

use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.

the class NetworkAddressH2CacheDAO method getAddressById.

@Override
public String getAddressById(int addressId) {
    logger.debug("get network address, address id: {}", addressId);
    H2Client client = getClient();
    String sql = SqlBuilder.buildSql(GET_ADDRESS_ID_OR_CODE_SQL, NetworkAddressTable.COLUMN_NETWORK_ADDRESS, NetworkAddressTable.TABLE, NetworkAddressTable.COLUMN_ADDRESS_ID);
    Object[] params = new Object[] { addressId };
    try (ResultSet rs = client.executeQuery(sql, params)) {
        if (rs.next()) {
            return rs.getString(1);
        }
    } catch (SQLException | H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
    return Const.EMPTY_STRING;
}
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 4 with H2ClientException

use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.

the class StorageModuleH2Provider method start.

@Override
public void start(Properties config) throws ServiceNotProvidedException {
    try {
        h2Client.initialize();
        H2StorageInstaller installer = new H2StorageInstaller();
        installer.install(h2Client);
    } catch (H2ClientException | StorageException e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException) StorageException(org.apache.skywalking.apm.collector.storage.StorageException) H2StorageInstaller(org.apache.skywalking.apm.collector.storage.h2.base.define.H2StorageInstaller)

Example 5 with H2ClientException

use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.

the class BatchH2DAO method batchPersistence.

@Override
public void batchPersistence(List<?> batchCollection) {
    if (batchCollection != null && batchCollection.size() > 0) {
        logger.debug("the batch collection size is {}", batchCollection.size());
        Connection conn;
        final Map<String, PreparedStatement> batchSqls = new HashMap<>();
        try {
            conn = getClient().getConnection();
            conn.setAutoCommit(true);
            PreparedStatement ps;
            for (Object entity : batchCollection) {
                H2SqlEntity e = getH2SqlEntity(entity);
                String sql = e.getSql();
                if (batchSqls.containsKey(sql)) {
                    ps = batchSqls.get(sql);
                } else {
                    ps = conn.prepareStatement(sql);
                    batchSqls.put(sql, ps);
                }
                Object[] params = e.getParams();
                if (params != null) {
                    logger.debug("the sql is {}, params size is {}, params: {}", e.getSql(), params.length, params);
                    for (int i = 0; i < params.length; i++) {
                        ps.setObject(i + 1, params[i]);
                    }
                }
                ps.addBatch();
            }
            for (String k : batchSqls.keySet()) {
                batchSqls.get(k).executeBatch();
            }
        } catch (SQLException | H2ClientException e) {
            logger.error(e.getMessage(), e);
        }
        batchSqls.clear();
    }
}
Also used : HashMap(java.util.HashMap) H2SqlEntity(org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity) SQLException(java.sql.SQLException) Connection(java.sql.Connection) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException) PreparedStatement(java.sql.PreparedStatement)

Aggregations

H2ClientException (org.apache.skywalking.apm.collector.client.h2.H2ClientException)45 H2Client (org.apache.skywalking.apm.collector.client.h2.H2Client)39 SQLException (java.sql.SQLException)37 ResultSet (java.sql.ResultSet)36 LinkedList (java.util.LinkedList)11 HashMap (java.util.HashMap)6 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 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 StorageException (org.apache.skywalking.apm.collector.storage.StorageException)1 H2SqlEntity (org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity)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