Example usage for org.springframework.integration.jdbc StoredProcExecutor setStoredProcedureNameExpression

List of usage examples for org.springframework.integration.jdbc StoredProcExecutor setStoredProcedureNameExpression

Introduction

In this page you can find the example usage for org.springframework.integration.jdbc StoredProcExecutor setStoredProcedureNameExpression.

Prototype

public void setStoredProcedureNameExpression(Expression storedProcedureNameExpression) 

Source Link

Document

Using the StoredProcExecutor#storedProcedureNameExpression the Message can be used as source for the name of the Stored Procedure or Stored Function.

Usage

From source file:org.springframework.integration.jdbc.StoredProcExecutorTests.java

@Test
public void testGetStoredProcedureNameExpressionAsString() throws Exception {

    DataSource datasource = mock(DataSource.class);
    StoredProcExecutor storedProcExecutor = new StoredProcExecutor(datasource);

    final ExpressionFactoryBean efb = new ExpressionFactoryBean("headers['stored_procedure_name']");
    efb.afterPropertiesSet();//from w w  w .  j  ava 2s  .  c o m
    final Expression expression = efb.getObject();

    storedProcExecutor.setStoredProcedureNameExpression(expression);
    storedProcExecutor.setBeanFactory(mock(BeanFactory.class));
    storedProcExecutor.afterPropertiesSet();

    assertEquals("headers['stored_procedure_name']",
            storedProcExecutor.getStoredProcedureNameExpressionAsString());
}

From source file:org.springframework.integration.jdbc.StoredProcExecutorTests.java

@Test
public void testStoredProcExecutorWithNonResolvingExpression() throws Exception {

    final DataSource datasource = mock(DataSource.class);

    final StoredProcExecutor storedProcExecutor = new StoredProcExecutor(datasource);

    final ExpressionFactoryBean efb = new ExpressionFactoryBean("headers['stored_procedure_name']");
    efb.afterPropertiesSet();//from  www.  j  av a  2s.co m
    final Expression expression = efb.getObject();

    storedProcExecutor.setStoredProcedureNameExpression(expression);
    storedProcExecutor.setBeanFactory(mock(BeanFactory.class));

    storedProcExecutor.afterPropertiesSet();

    this.mockTheOperationsCache(storedProcExecutor);

    //This should work

    storedProcExecutor.executeStoredProcedure(
            MessageBuilder.withPayload("test").setHeader("stored_procedure_name", "123").build());

    //This should cause an exception

    try {
        storedProcExecutor.executeStoredProcedure(
                MessageBuilder.withPayload("test").setHeader("some_other_header", "123").build());
    } catch (IllegalArgumentException e) {
        assertEquals(
                "Unable to resolve Stored Procedure/Function name for the provided Expression 'headers['stored_procedure_name']'.",
                e.getMessage());
        return;
    }

    fail("IllegalArgumentException expected.");

}

From source file:org.springframework.integration.jdbc.StoredProcExecutorTests.java

@Test
public void testStoredProcExecutorJdbcCallOperationsCache() throws Exception {

    final DataSource datasource = mock(DataSource.class);

    final StoredProcExecutor storedProcExecutor = new StoredProcExecutor(datasource);

    final ExpressionFactoryBean efb = new ExpressionFactoryBean("headers['stored_procedure_name']");
    efb.afterPropertiesSet();/*from ww w  .  ja va  2 s .c  om*/
    final Expression expression = efb.getObject();

    storedProcExecutor.setStoredProcedureNameExpression(expression);
    storedProcExecutor.setBeanFactory(mock(BeanFactory.class));

    storedProcExecutor.afterPropertiesSet();

    this.mockTheOperationsCache(storedProcExecutor);

    for (int i = 1; i <= 3; i++) {
        storedProcExecutor.executeStoredProcedure(
                MessageBuilder.withPayload("test").setHeader("stored_procedure_name", "123").build());
    }

    final CacheStats stats = (CacheStats) storedProcExecutor.getJdbcCallOperationsCacheStatistics();
    LOGGER.info(stats);
    LOGGER.info(stats.totalLoadTime() / 1000 / 1000);

    assertEquals(stats.hitCount(), 2);
    assertEquals(stats.missCount(), 1);
    assertEquals(stats.loadCount(), 1);

}

From source file:org.springframework.integration.jdbc.StoredProcExecutorTests.java

@Test
public void testSetJdbcCallOperationsCacheSize() throws Exception {

    final DataSource datasource = mock(DataSource.class);

    final StoredProcExecutor storedProcExecutor = new StoredProcExecutor(datasource);

    storedProcExecutor.setJdbcCallOperationsCacheSize(0);

    final ExpressionFactoryBean efb = new ExpressionFactoryBean("headers['stored_procedure_name']");
    efb.afterPropertiesSet();//from  w ww  . ja v  a  2  s .c  om
    final Expression expression = efb.getObject();

    storedProcExecutor.setStoredProcedureNameExpression(expression);
    storedProcExecutor.setBeanFactory(mock(BeanFactory.class));

    storedProcExecutor.afterPropertiesSet();

    this.mockTheOperationsCache(storedProcExecutor);

    for (int i = 1; i <= 10; i++) {
        storedProcExecutor.executeStoredProcedure(
                MessageBuilder.withPayload("test").setHeader("stored_procedure_name", "123").build());
    }

    final CacheStats stats = (CacheStats) storedProcExecutor.getJdbcCallOperationsCacheStatistics();
    LOGGER.info(stats);
    assertEquals("Expected a cache misscount of 10", 10, stats.missCount());

}