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;
}
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;
}
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;
}
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);
}
}
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();
}
}
Aggregations