Search in sources :

Example 1 with StorageInstallException

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

Example 2 with StorageInstallException

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

Aggregations

H2Client (org.apache.skywalking.apm.collector.client.h2.H2Client)2 H2ClientException (org.apache.skywalking.apm.collector.client.h2.H2ClientException)2 StorageInstallException (org.apache.skywalking.apm.collector.storage.StorageInstallException)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1