Search in sources :

Example 31 with RowMapper

use of org.springframework.jdbc.core.RowMapper in project spring-integration by spring-projects.

the class StoredProcExecutorTests method testSetReturningResultSetRowMappersWithEmptyMap.

@Test
public void testSetReturningResultSetRowMappersWithEmptyMap() {
    DataSource datasource = mock(DataSource.class);
    StoredProcExecutor storedProcExecutor = new StoredProcExecutor(datasource);
    Map<String, RowMapper<?>> rowmappers = new HashMap<String, RowMapper<?>>();
    storedProcExecutor.setReturningResultSetRowMappers(rowmappers);
// Should Successfully finish
}
Also used : HashMap(java.util.HashMap) DataSource(javax.sql.DataSource) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.junit.Test)

Example 32 with RowMapper

use of org.springframework.jdbc.core.RowMapper in project spring-integration by spring-projects.

the class StoredProcPollingChannelAdapterParserTests method testReturningResultSetRowMappersAreSet.

@SuppressWarnings("unchecked")
@Test
public void testReturningResultSetRowMappersAreSet() throws Exception {
    setUp("storedProcPollingChannelAdapterParserTest.xml", getClass());
    DirectFieldAccessor accessor = new DirectFieldAccessor(this.pollingAdapter);
    Object source = accessor.getPropertyValue("source");
    accessor = new DirectFieldAccessor(source);
    source = accessor.getPropertyValue("executor");
    accessor = new DirectFieldAccessor(source);
    Object returningResultSetRowMappers = accessor.getPropertyValue("returningResultSetRowMappers");
    assertNotNull(returningResultSetRowMappers);
    assertTrue(returningResultSetRowMappers instanceof Map);
    Map<String, RowMapper<?>> returningResultSetRowMappersAsMap = (Map<String, RowMapper<?>>) returningResultSetRowMappers;
    assertTrue("The rowmapper was not set. Expected returningResultSetRowMappersAsMap.size() == 2", returningResultSetRowMappersAsMap.size() == 2);
    Iterator<Entry<String, RowMapper<?>>> iterator = returningResultSetRowMappersAsMap.entrySet().iterator();
    Entry<String, ?> mapEntry = iterator.next();
    assertEquals("out", mapEntry.getKey());
    assertTrue(mapEntry.getValue() instanceof PrimeMapper);
    mapEntry = iterator.next();
    assertEquals("out2", mapEntry.getKey());
    assertTrue(mapEntry.getValue() instanceof SingleColumnRowMapper);
}
Also used : Entry(java.util.Map.Entry) PrimeMapper(org.springframework.integration.jdbc.storedproc.PrimeMapper) SingleColumnRowMapper(org.springframework.jdbc.core.SingleColumnRowMapper) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Map(java.util.Map) SingleColumnRowMapper(org.springframework.jdbc.core.SingleColumnRowMapper) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.junit.Test)

Example 33 with RowMapper

use of org.springframework.jdbc.core.RowMapper in project spring-integration by spring-projects.

the class StoredProcOutboundGatewayParserTests method testReturningResultSetRowMappersAreSet.

@SuppressWarnings("unchecked")
@Test
public void testReturningResultSetRowMappersAreSet() throws Exception {
    setUp("storedProcOutboundGatewayParserTest.xml", getClass());
    DirectFieldAccessor accessor = new DirectFieldAccessor(this.outboundGateway);
    Object source = accessor.getPropertyValue("handler");
    accessor = new DirectFieldAccessor(source);
    source = accessor.getPropertyValue("executor");
    accessor = new DirectFieldAccessor(source);
    Object returningResultSetRowMappers = accessor.getPropertyValue("returningResultSetRowMappers");
    assertNotNull(returningResultSetRowMappers);
    assertTrue(returningResultSetRowMappers instanceof Map);
    Map<String, RowMapper<?>> returningResultSetRowMappersAsMap = (Map<String, RowMapper<?>>) returningResultSetRowMappers;
    assertTrue("The rowmapper was not set. Expected returningResultSetRowMappersAsMap.size() == 1", returningResultSetRowMappersAsMap.size() == 1);
    Entry<String, ?> mapEntry1 = returningResultSetRowMappersAsMap.entrySet().iterator().next();
    assertEquals("out", mapEntry1.getKey());
    assertTrue(mapEntry1.getValue() instanceof PrimeMapper);
}
Also used : PrimeMapper(org.springframework.integration.jdbc.storedproc.PrimeMapper) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Map(java.util.Map) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.junit.Test)

Example 34 with RowMapper

use of org.springframework.jdbc.core.RowMapper in project spring-integration by spring-projects.

the class StoredProcExecutor method createSimpleJdbcCall.

private SimpleJdbcCall createSimpleJdbcCall(String storedProcedureName) {
    final SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(this.dataSource);
    if (this.isFunction) {
        simpleJdbcCall.withFunctionName(storedProcedureName);
    } else {
        simpleJdbcCall.withProcedureName(storedProcedureName);
    }
    if (this.ignoreColumnMetaData) {
        simpleJdbcCall.withoutProcedureColumnMetaDataAccess();
    }
    simpleJdbcCall.declareParameters(this.sqlParameters.toArray(new SqlParameter[this.sqlParameters.size()]));
    if (!this.returningResultSetRowMappers.isEmpty()) {
        for (Entry<String, RowMapper<?>> mapEntry : this.returningResultSetRowMappers.entrySet()) {
            simpleJdbcCall.returningResultSet(mapEntry.getKey(), mapEntry.getValue());
        }
    }
    if (this.returnValueRequired) {
        simpleJdbcCall.withReturnValue();
    }
    simpleJdbcCall.getJdbcTemplate().setSkipUndeclaredResults(this.skipUndeclaredResults);
    return simpleJdbcCall;
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) SimpleJdbcCall(org.springframework.jdbc.core.simple.SimpleJdbcCall) RowMapper(org.springframework.jdbc.core.RowMapper)

Example 35 with RowMapper

use of org.springframework.jdbc.core.RowMapper in project ovirt-engine by oVirt.

the class TagDaoImpl method getTagUserGroupByGroupIdAndByTagId.

@Override
public TagsUserGroupMap getTagUserGroupByGroupIdAndByTagId(Guid tag, Guid group) {
    MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource().addValue("group_id", group).addValue("tag_id", tag);
    RowMapper<TagsUserGroupMap> mapper = (rs, rowNum) -> {
        TagsUserGroupMap entity = new TagsUserGroupMap();
        entity.setGroupId(getGuidDefaultEmpty(rs, "group_id"));
        entity.setTagId(getGuidDefaultEmpty(rs, "tag_id"));
        return entity;
    };
    return getCallsHandler().executeRead("GetTagUserGroupByGroupIdAndByTagId", mapper, parameterSource);
}
Also used : TagsVdsMap(org.ovirt.engine.core.common.businessentities.TagsVdsMap) Guid(org.ovirt.engine.core.compat.Guid) TagsUserGroupMap(org.ovirt.engine.core.common.businessentities.TagsUserGroupMap) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Singleton(javax.inject.Singleton) TagsTemplateMap(org.ovirt.engine.core.common.businessentities.TagsTemplateMap) TagsType(org.ovirt.engine.core.common.businessentities.TagsType) SQLException(java.sql.SQLException) List(java.util.List) TagsUserMap(org.ovirt.engine.core.common.businessentities.TagsUserMap) ResultSet(java.sql.ResultSet) Tags(org.ovirt.engine.core.common.businessentities.Tags) TagsVmMap(org.ovirt.engine.core.common.businessentities.TagsVmMap) RowMapper(org.springframework.jdbc.core.RowMapper) Named(javax.inject.Named) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) TagsUserGroupMap(org.ovirt.engine.core.common.businessentities.TagsUserGroupMap)

Aggregations

RowMapper (org.springframework.jdbc.core.RowMapper)51 ResultSet (java.sql.ResultSet)27 SQLException (java.sql.SQLException)16 List (java.util.List)14 Named (javax.inject.Named)8 Singleton (javax.inject.Singleton)8 Test (org.junit.jupiter.api.Test)8 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)8 Guid (org.ovirt.engine.core.compat.Guid)7 QueryMappingConfiguration (org.springframework.data.jdbc.repository.QueryMappingConfiguration)7 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Tags (org.ovirt.engine.core.common.businessentities.Tags)5 TagsTemplateMap (org.ovirt.engine.core.common.businessentities.TagsTemplateMap)5 TagsType (org.ovirt.engine.core.common.businessentities.TagsType)5 TagsUserGroupMap (org.ovirt.engine.core.common.businessentities.TagsUserGroupMap)5 TagsUserMap (org.ovirt.engine.core.common.businessentities.TagsUserMap)5 TagsVdsMap (org.ovirt.engine.core.common.businessentities.TagsVdsMap)5 TagsVmMap (org.ovirt.engine.core.common.businessentities.TagsVmMap)5 DataAccessException (org.springframework.dao.DataAccessException)5