private static AggregationRepository getAggregationRepository()

in aggregate-dist/src/main/java/org/apache/camel/example/Application.java [138:166]


    private static AggregationRepository getAggregationRepository() {
        SingleConnectionDataSource ds = new SingleConnectionDataSource(DB_URL, DB_USER, DB_PASS, true);
        ds.setAutoCommit(false);
        try (Connection conn = ds.getConnection();
             Statement statement = conn.createStatement()){
            statement.execute(
                    "create table aggregation("
                            + "id varchar(255) not null primary key,"
                            + "exchange blob not null,"
                            + "version bigint not null"
                            + ")");
            statement.execute(
                    "create table aggregation_completed("
                            + "id varchar(255) not null primary key,"
                            + "exchange blob not null,"
                            + "version bigint not null"
                            + ")");
        } catch (SQLException e) {
            if (!e.getMessage().contains("already exists")) {
                LOG.error("Database initialization failure", e);
            }
        }
        DataSourceTransactionManager txManager = new DataSourceTransactionManager(ds);
        // repositoryName (aggregation) must match tableName (aggregation, aggregation_completed)
        JdbcAggregationRepository repo = new JdbcAggregationRepository(txManager, "aggregation", ds);
        repo.setUseRecovery(false);
        repo.setStoreBodyAsText(false);
        return repo;
    }