use of org.apache.skywalking.apm.collector.storage.StorageInstallException in project incubator-skywalking by apache.
the class H2StorageInstaller method createTable.
@Override
protected boolean createTable(Client client, TableDefine tableDefine) throws StorageException {
H2Client h2Client = (H2Client) client;
H2TableDefine h2TableDefine = (H2TableDefine) tableDefine;
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append("CREATE TABLE ").append(h2TableDefine.getName()).append(" (");
h2TableDefine.getColumnDefines().forEach(columnDefine -> {
H2ColumnDefine h2ColumnDefine = (H2ColumnDefine) columnDefine;
if (h2ColumnDefine.getType().equals(H2ColumnDefine.Type.Varchar.name())) {
sqlBuilder.append(h2ColumnDefine.getName()).append(" ").append(h2ColumnDefine.getType()).append("(255),");
} else {
sqlBuilder.append(h2ColumnDefine.getName()).append(" ").append(h2ColumnDefine.getType()).append(",");
}
});
// remove last comma
sqlBuilder.delete(sqlBuilder.length() - 1, sqlBuilder.length());
sqlBuilder.append(")");
try {
logger.info("create h2 table with sql {}", sqlBuilder);
h2Client.execute(sqlBuilder.toString());
} catch (H2ClientException e) {
throw new StorageInstallException(e.getMessage(), e);
}
return true;
}
use of org.apache.skywalking.apm.collector.storage.StorageInstallException 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;
}
Aggregations