Java Code Examples for org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations

The following examples show how to use org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations. 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 testInsertion() {
	NamedParameterJdbcOperations namedParameterJdbcOperations = new NamedParameterJdbcTemplate(jdbcOperations);
	Map<String, Object> mapA = new HashMap<>();
	mapA.put("a", "hello1");
	mapA.put("b", 42);
	Map<String, Object> mapB = new HashMap<>();
	mapB.put("a", "hello2");
	mapB.put("b", null);
	Map<String, Object> mapC = new HashMap<>();
	mapC.put("a", "hello3");
	channels.input().send(MessageBuilder.withPayload(mapA).build());
	channels.input().send(MessageBuilder.withPayload(mapB).build());
	channels.input().send(MessageBuilder.withPayload(mapC).build());
	Assert.assertThat(namedParameterJdbcOperations.queryForObject(
			"select count(*) from messages where a = :a and b = :b", mapA, Integer.class), is(1));
	Assert.assertThat(namedParameterJdbcOperations.queryForObject(
			"select count(*) from messages where a = :a and b IS NULL", mapB, Integer.class), is(1));
	Assert.assertThat(namedParameterJdbcOperations.queryForObject(
			"select count(*) from messages where a = :a and b IS NULL", mapC, Integer.class), is(1));
}
 
Example 2
@Bean
@Primary
@ConditionalOnSingleCandidate(JdbcTemplate.class)
@ConditionalOnMissingBean(NamedParameterJdbcOperations.class)
public NamedParameterJdbcTemplate namedParameterJdbcTemplate(JdbcTemplate jdbcTemplate) {
    return new NamedParameterJdbcTemplate(jdbcTemplate);
}
 
Example 3
@Override
public void afterPropertiesSet() {

    Assert.state(this.mappingContext != null, "MappingContext is required and must not be null!");
    Assert.state(this.converter != null, "RelationalConverter is required and must not be null!");

    if (this.operations == null) {

        Assert.state(beanFactory != null, "If no JdbcOperations are set a BeanFactory must be available.");

        this.operations = beanFactory.getBean(NamedParameterJdbcOperations.class);
    }

    if (this.dataAccessStrategy == null) {

        Assert.state(beanFactory != null, "If no DataAccessStrategy is set a BeanFactory must be available.");

        this.dataAccessStrategy = this.beanFactory.getBeanProvider(DataAccessStrategy.class) //
                                                  .getIfAvailable(() -> {
                                                      SqlGeneratorSource sqlGeneratorSource = new SqlGeneratorSource(
                                                              this.mappingContext,
                                                              this.converter,
                                                              this.dialect);
                                                      return new DefaultDataAccessStrategy(sqlGeneratorSource,
                                                                                           this.mappingContext,
                                                                                           this.converter,
                                                                                           this.operations);
                                                  });
    }

    if (this.queryMappingConfiguration == null) {
        this.queryMappingConfiguration = QueryMappingConfiguration.EMPTY;
    }

    if (beanFactory != null) {
        entityCallbacks = EntityCallbacks.create(beanFactory);
    }

    super.afterPropertiesSet();
}
 
Example 4
public QuerydslJdbcRepositoryFactory(DataAccessStrategy dataAccessStrategy,
                                     RelationalMappingContext context,
                                     JdbcConverter converter,
                                     Dialect dialect, ApplicationEventPublisher publisher,
                                     NamedParameterJdbcOperations operations,
                                     SQLQueryFactory sqlQueryFactory) {
    super(dataAccessStrategy, context, converter, dialect, publisher, operations);
    this.publisher = publisher;
    this.context = context;
    this.converter = converter;
    this.accessStrategy = dataAccessStrategy;
    this.sqlQueryFactory = sqlQueryFactory;
}
 
Example 5
Source Project: effectivejava   Source File: SimpleJdbcTemplateTests.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	this.operations = mock(JdbcOperations.class);
	this.namedParameterOperations = mock(NamedParameterJdbcOperations.class);
	this.template = new SimpleJdbcTemplate(operations);
	this.namedParameterTemplate = new SimpleJdbcTemplate(namedParameterOperations);
}
 
Example 6
Source Project: library   Source File: LendingDatabaseConfig.java    License: MIT License 4 votes vote down vote up
@Bean
NamedParameterJdbcOperations operations() {
    return new NamedParameterJdbcTemplate(dataSource());
}
 
Example 7
Source Project: library   Source File: CatalogueDatabaseConfig.java    License: MIT License 4 votes vote down vote up
@Bean
NamedParameterJdbcOperations operations() {
    return new NamedParameterJdbcTemplate(dataSource());
}
 
Example 8
public void setJdbcOperations(NamedParameterJdbcOperations operations) {
    this.operations = operations;
}
 
Example 9
Source Project: piper   Source File: JdbcJobRepository.java    License: Apache License 2.0 4 votes vote down vote up
public void setJdbcOperations (NamedParameterJdbcOperations aJdbcOperations) {
  jdbc = aJdbcOperations;
}
 
Example 10
Source Project: piper   Source File: JdbcTaskExecutionRepository.java    License: Apache License 2.0 4 votes vote down vote up
public void setJdbcOperations (NamedParameterJdbcOperations aJdbcOperations) {
  jdbc = aJdbcOperations;
}
 
Example 11
Source Project: MaxKey   Source File: DefaultJdbcListFactory.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @param jdbcTemplate the jdbc template to use
 */
public DefaultJdbcListFactory(NamedParameterJdbcOperations jdbcTemplate) {
	this.jdbcTemplate = jdbcTemplate;
}
 
Example 12
Source Project: effectivejava   Source File: SimpleJdbcTemplate.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Expose the Spring NamedParameterJdbcTemplate to allow invocation of
 * less commonly used methods.
 */
@Override
public NamedParameterJdbcOperations getNamedParameterJdbcOperations() {
	return this.namedParameterJdbcOperations;
}
 
Example 13
Source Project: platform   Source File: JdbcConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public NamedParameterJdbcOperations namedParameterJdbcOperations(DataSource dataSource) {
    return new NamedParameterJdbcTemplate(dataSource);
}
 
Example 14
Source Project: effectivejava   Source File: SimpleJdbcTemplate.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create a new SimpleJdbcTemplate for the given Spring NamedParameterJdbcTemplate.
 * @param namedParameterJdbcTemplate the Spring NamedParameterJdbcTemplate to wrap
 */
public SimpleJdbcTemplate(NamedParameterJdbcOperations namedParameterJdbcTemplate) {
	this.namedParameterJdbcOperations = namedParameterJdbcTemplate;
}
 
Example 15
Source Project: effectivejava   Source File: SimpleJdbcOperations.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Expose the Spring NamedParameterJdbcTemplate to allow invocation of less
 * commonly used methods.
 */
NamedParameterJdbcOperations getNamedParameterJdbcOperations();