Search in sources :

Example 1 with AnalyticsTableHook

use of org.hisp.dhis.analytics.AnalyticsTableHook in project dhis2-core by dhis2.

the class AbstractJdbcTableManager method invokeAnalyticsTableSqlHooks.

@Override
public int invokeAnalyticsTableSqlHooks() {
    AnalyticsTableType type = getAnalyticsTableType();
    List<AnalyticsTableHook> hooks = tableHookService.getByPhaseAndAnalyticsTableType(AnalyticsTablePhase.ANALYTICS_TABLE_POPULATED, type);
    tableHookService.executeAnalyticsTableSqlHooks(hooks);
    return hooks.size();
}
Also used : AnalyticsTableHook(org.hisp.dhis.analytics.AnalyticsTableHook) AnalyticsTableType(org.hisp.dhis.analytics.AnalyticsTableType)

Example 2 with AnalyticsTableHook

use of org.hisp.dhis.analytics.AnalyticsTableHook in project dhis2-core by dhis2.

the class HibernateAnalyticsTableHookStore method executeAnalyticsTableSqlHooks.

@Override
public void executeAnalyticsTableSqlHooks(List<AnalyticsTableHook> hooks) {
    for (AnalyticsTableHook hook : hooks) {
        log.info(String.format("Executing analytics table hook: '%s', '%s'", hook.getUid(), hook.getName()));
        jdbcTemplate.execute(hook.getSql());
    }
}
Also used : AnalyticsTableHook(org.hisp.dhis.analytics.AnalyticsTableHook)

Example 3 with AnalyticsTableHook

use of org.hisp.dhis.analytics.AnalyticsTableHook in project dhis2-core by dhis2.

the class JdbcResourceTableStore method generateResourceTable.

// -------------------------------------------------------------------------
// ResourceTableStore implementation
// -------------------------------------------------------------------------
@Override
public void generateResourceTable(ResourceTable<?> resourceTable) {
    log.info(String.format("Generating resource table: '%s'", resourceTable.getTableName()));
    final Clock clock = new Clock().startClock();
    final String createTableSql = resourceTable.getCreateTempTableStatement();
    final Optional<String> populateTableSql = resourceTable.getPopulateTempTableStatement();
    final Optional<List<Object[]>> populateTableContent = resourceTable.getPopulateTempTableContent();
    final List<String> createIndexSql = resourceTable.getCreateIndexStatements();
    final String analyzeTableSql = statementBuilder.getAnalyze(resourceTable.getTableName());
    if (dbmsManager.tableExists(resourceTable.getTempTableName())) {
        jdbcTemplate.execute(resourceTable.getDropTempTableStatement());
    }
    // ---------------------------------------------------------------------
    // Create temporary table
    // ---------------------------------------------------------------------
    log.debug(String.format("Create table SQL: '%s'", createTableSql));
    jdbcTemplate.execute(createTableSql);
    if (populateTableSql.isPresent()) {
        log.debug(String.format("Populate table SQL: '%s'", populateTableSql.get()));
        jdbcTemplate.execute(populateTableSql.get());
    } else if (populateTableContent.isPresent()) {
        List<Object[]> content = populateTableContent.get();
        log.debug(String.format("Populate table content rows: '%d'", content.size()));
        if (content.size() > 0) {
            int columns = content.get(0).length;
            batchUpdate(columns, resourceTable.getTempTableName(), content);
        }
    }
    // ---------------------------------------------------------------------
    // Invoke hooks
    // ---------------------------------------------------------------------
    List<AnalyticsTableHook> hooks = analyticsTableHookService.getByPhaseAndResourceTableType(AnalyticsTablePhase.RESOURCE_TABLE_POPULATED, resourceTable.getTableType());
    if (!hooks.isEmpty()) {
        analyticsTableHookService.executeAnalyticsTableSqlHooks(hooks);
        log.info(String.format("Invoked resource table hooks: '%d'", hooks.size()));
    }
    for (final String sql : createIndexSql) {
        log.debug(String.format("Create index SQL: '%s'", sql));
        jdbcTemplate.execute(sql);
    }
    if (dbmsManager.tableExists(resourceTable.getTableName())) {
        jdbcTemplate.execute(resourceTable.getDropTableStatement());
    }
    jdbcTemplate.execute(resourceTable.getRenameTempTableStatement());
    log.debug(String.format("Swapped resource table: '%s'", resourceTable.getTableName()));
    if (analyzeTableSql != null) {
        log.debug("Analyze table SQL: " + analyzeTableSql);
        jdbcTemplate.execute(analyzeTableSql);
    }
    log.debug(String.format("Analyzed resource table: '%s'", resourceTable.getTableName()));
    log.info(String.format("Resource table '%s' update done: '%s'", resourceTable.getTableName(), clock.time()));
}
Also used : AnalyticsTableHook(org.hisp.dhis.analytics.AnalyticsTableHook) List(java.util.List) Clock(org.hisp.dhis.system.util.Clock)

Aggregations

AnalyticsTableHook (org.hisp.dhis.analytics.AnalyticsTableHook)3 List (java.util.List)1 AnalyticsTableType (org.hisp.dhis.analytics.AnalyticsTableType)1 Clock (org.hisp.dhis.system.util.Clock)1