Java Code Examples for org.apache.camel.component.sql.SqlComponent

The following examples show how to use org.apache.camel.component.sql.SqlComponent. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void testCreateDelegateComponent() throws Exception{
    Map<String, Object> properties = new HashMap<>();
    properties.put("dataSource", ds);
    properties.put("query", "select from dual");

    ComponentProxyComponent component = new ComponentProxyComponent("my-sql-proxy", "sql") {
        @Override
        protected Optional<Component> createDelegateComponent(ComponentDefinition definition, Map<String, Object> options) {
            return Optional.of(new SqlComponent());
        }
    };

    component.setOptions(properties);

    SimpleRegistry registry = new SimpleRegistry();
    registry.bind(component.getComponentId() + "-component", component);

    validate(registry);
}
 
Example 2
@Override
protected CamelContext createCamelContext() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    dataSource = EmbeddedDataSourceFactory.getDataSource("sql/schema.sql");

    DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(dataSource);
    registry.put("transactionManager", transactionManager);

    SpringTransactionPolicy propagationRequired = new SpringTransactionPolicy();
    propagationRequired.setTransactionManager(transactionManager);
    propagationRequired.setPropagationBehaviorName("PROPAGATION_REQUIRED");
    registry.put("PROPAGATION_REQUIRED", propagationRequired);

    auditLogDao = new AuditLogDao(dataSource);
    messageDao = new MessageDao(dataSource);

    CamelContext camelContext = new DefaultCamelContext(registry);

    SqlComponent sqlComponent = new SqlComponent();
    sqlComponent.setDataSource(dataSource);
    camelContext.addComponent("sql", sqlComponent);

    return camelContext;
}
 
Example 3
@Override
protected CamelContext createCamelContext() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    DataSource auditDataSource = EmbeddedDataSourceFactory.getDataSource("sql/schema.sql");

    DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(auditDataSource);
    registry.put("transactionManager", transactionManager);

    SpringTransactionPolicy propagationRequired = new SpringTransactionPolicy();
    propagationRequired.setTransactionManager(transactionManager);
    propagationRequired.setPropagationBehaviorName("PROPAGATION_REQUIRED");
    registry.put("PROPAGATION_REQUIRED", propagationRequired);

    auditLogDao = new AuditLogDao(auditDataSource);

    CamelContext camelContext = new DefaultCamelContext(registry);

    SqlComponent sqlComponent = new SqlComponent();
    sqlComponent.setDataSource(auditDataSource);
    camelContext.addComponent("sql", sqlComponent);

    return camelContext;
}
 
Example 4
Source Project: camel-cookbook-examples   Source File: RollbackTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected CamelContext createCamelContext() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    DataSource auditDataSource = EmbeddedDataSourceFactory.getDataSource("sql/schema.sql");

    DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(auditDataSource);
    registry.put("transactionManager", transactionManager);

    SpringTransactionPolicy propagationRequired = new SpringTransactionPolicy();
    propagationRequired.setTransactionManager(transactionManager);
    propagationRequired.setPropagationBehaviorName("PROPAGATION_REQUIRED");
    registry.put("PROPAGATION_REQUIRED", propagationRequired);

    auditLogDao = new AuditLogDao(auditDataSource);

    CamelContext camelContext = new DefaultCamelContext(registry);

    SqlComponent sqlComponent = new SqlComponent();
    sqlComponent.setDataSource(auditDataSource);
    camelContext.addComponent("sql", sqlComponent);

    return camelContext;
}
 
Example 5
@Override
protected CamelContext createCamelContext() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    auditDataSource = EmbeddedDataSourceFactory.getDataSource("sql/schema.sql");
    //registry.put("auditDataSource", auditDataSource);

    DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(auditDataSource);
    registry.put("transactionManager", transactionManager);

    SpringTransactionPolicy propagationRequired = new SpringTransactionPolicy();
    propagationRequired.setTransactionManager(transactionManager);
    propagationRequired.setPropagationBehaviorName("PROPAGATION_REQUIRED");
    registry.put("PROPAGATION_REQUIRED", propagationRequired);

    auditLogDao = new AuditLogDao(auditDataSource);

    CamelContext camelContext = new DefaultCamelContext(registry);

    SqlComponent sqlComponent = new SqlComponent();
    sqlComponent.setDataSource(auditDataSource);
    camelContext.addComponent("sql", sqlComponent);

    return camelContext;
}
 
Example 6
@Lazy
@Bean(name = "sql-component")
@ConditionalOnMissingBean(SqlComponent.class)
public SqlComponent configureSqlComponent() throws Exception {
    SqlComponent component = new SqlComponent();
    component.setCamelContext(camelContext);
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null,
            false);
    CamelPropertiesHelper.setCamelProperties(camelContext, component,
            parameters, false);
    if (ObjectHelper.isNotEmpty(customizers)) {
        for (ComponentCustomizer<SqlComponent> customizer : customizers) {
            boolean useCustomizer = (customizer instanceof HasId)
                    ? HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.component.customizer",
                            "camel.component.sql.customizer",
                            ((HasId) customizer).getId())
                    : HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.component.customizer",
                            "camel.component.sql.customizer");
            if (useCustomizer) {
                LOGGER.debug("Configure component {}, with customizer {}",
                        component, customizer);
                customizer.customize(component);
            }
        }
    }
    return component;
}
 
Example 7
private void validate(Registry registry) throws Exception {
    final CamelContext context = new DefaultCamelContext(registry);

    try {
        context.setAutoStartup(false);
        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:start")
                    .to("my-sql-proxy")
                    .to("mock:result");
            }
        });

        context.start();

        Collection<String> names = context.getComponentNames();

        assertThat(names).contains("my-sql-proxy");
        assertThat(names).contains("sql-my-sql-proxy");

        SqlComponent sqlComponent = context.getComponent("sql-my-sql-proxy", SqlComponent.class);
        DataSource sqlDatasource = sqlComponent.getDataSource();

        assertThat(sqlDatasource).isEqualTo(this.ds);

        Map<String, Endpoint> endpoints = context.getEndpointMap();
        assertThat(endpoints).containsKey("sql-my-sql-proxy://select%20from%20dual");
    } finally {
        context.stop();
    }
}
 
Example 8
@Override
protected CamelContext createCamelContext() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    dataSource = EmbeddedDataSourceFactory.getDataSource("sql/schema.sql");

    DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(dataSource);
    registry.put("transactionManager", transactionManager);

    {
        SpringTransactionPolicy propagationRequired = new SpringTransactionPolicy();
        propagationRequired.setTransactionManager(transactionManager);
        propagationRequired.setPropagationBehaviorName("PROPAGATION_REQUIRED");
        registry.put("PROPAGATION_REQUIRED", propagationRequired);
    }

    {
        SpringTransactionPolicy propagationNotSupported = new SpringTransactionPolicy();
        propagationNotSupported.setTransactionManager(transactionManager);
        propagationNotSupported.setPropagationBehaviorName("PROPAGATION_NOT_SUPPORTED");
        registry.put("PROPAGATION_NOT_SUPPORTED", propagationNotSupported);
    }

    auditLogDao = new AuditLogDao(dataSource);
    messageDao = new MessageDao(dataSource);

    CamelContext camelContext = new DefaultCamelContext(registry);

    SqlComponent sqlComponent = new SqlComponent();
    sqlComponent.setDataSource(dataSource);
    camelContext.addComponent("sql", sqlComponent);

    return camelContext;
}
 
Example 9
@Override
protected CamelContext createCamelContext() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    DataSource dataSource = EmbeddedDataSourceFactory.getDataSource("sql/schema.sql");

    DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(dataSource);
    registry.put("transactionManager", transactionManager);

    {
        SpringTransactionPolicy propagationRequiresNew = new SpringTransactionPolicy();
        propagationRequiresNew.setTransactionManager(transactionManager);
        propagationRequiresNew.setPropagationBehaviorName("PROPAGATION_REQUIRES_NEW");
        registry.put("PROPAGATION_REQUIRES_NEW", propagationRequiresNew);
    }

    {
        SpringTransactionPolicy propagationRequiresNew2 = new SpringTransactionPolicy();
        propagationRequiresNew2.setTransactionManager(transactionManager);
        propagationRequiresNew2.setPropagationBehaviorName("PROPAGATION_REQUIRES_NEW");
        registry.put("PROPAGATION_REQUIRES_NEW-2", propagationRequiresNew2);
    }

    auditLogDao = new AuditLogDao(dataSource);
    messageDao = new MessageDao(dataSource);

    CamelContext camelContext = new DefaultCamelContext(registry);

    SqlComponent sqlComponent = new SqlComponent();
    sqlComponent.setDataSource(dataSource);
    camelContext.addComponent("sql", sqlComponent);

    return camelContext;
}
 
Example 10
@Override
protected CamelContext createCamelContext() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    auditDataSource = EmbeddedDataSourceFactory.getDataSource("sql/schema.sql");
    registry.put("auditDataSource", auditDataSource);

    DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(auditDataSource);
    registry.put("transactionManager", transactionManager);

    SpringTransactionPolicy propagationRequired = new SpringTransactionPolicy();
    propagationRequired.setTransactionManager(transactionManager);
    propagationRequired.setPropagationBehaviorName("PROPAGATION_REQUIRED");
    registry.put("PROPAGATION_REQUIRED", propagationRequired);

    auditLogDao = new AuditLogDao(auditDataSource);

    TransactionTemplate transactionTemplate = new TransactionTemplate();
    transactionTemplate.setTransactionManager(transactionManager);
    transactionTemplate.setPropagationBehaviorName("PROPAGATION_REQUIRES_NEW");

    idempotentRepository = new JdbcMessageIdRepository(auditDataSource, transactionTemplate, "ws");

    CamelContext camelContext = new DefaultCamelContext(registry);
    SqlComponent sqlComponent = new SqlComponent();
    sqlComponent.setDataSource(auditDataSource);
    camelContext.addComponent("sql", sqlComponent);
    return camelContext;
}
 
Example 11
Source Project: syndesis   Source File: ComponentOptionsTest.java    License: Apache License 2.0 4 votes vote down vote up
private void validatePojoOption(CamelContext context) throws Exception {
    context.start();

    Collection<String> names = context.getComponentNames();

    assertThat(names).contains("my-sql-proxy");
    assertThat(names).contains("sql-my-sql-proxy");

    SqlComponent sqlComponent = context.getComponent("sql-my-sql-proxy", SqlComponent.class);
    DataSource sqlDatasource = sqlComponent.getDataSource();

    assertThat(sqlDatasource).isEqualTo(this.ds);

    Map<String, Endpoint> endpoints = context.getEndpointMap();
    assertThat(endpoints).containsKey("sql-my-sql-proxy://select%20from%20dual");

    context.stop();
}
 
Example 12
Source Project: syndesis   Source File: ComponentOptionsTest.java    License: Apache License 2.0 4 votes vote down vote up
private static void validateRegistryOption(CamelContext context) throws Exception {
    context.start();

    Collection<String> names = context.getComponentNames();

    assertThat(names).contains("my-sql-proxy");
    assertThat(names).contains("sql");
    assertThat(names).doesNotContain("sql-my-sql-proxy");

    SqlComponent sqlComponent = context.getComponent("sql", SqlComponent.class);
    DataSource sqlDatasource = sqlComponent.getDataSource();

    assertThat(sqlDatasource).isNull();

    Map<String, Endpoint> endpoints = context.getEndpointMap();
    assertThat(endpoints).containsKey("sql://select%20from%20dual?dataSource=%23ds");


    context.stop();
}