Search in sources :

Example 16 with ConnectionCallback

use of org.springframework.jdbc.core.ConnectionCallback in project spring-boot by spring-projects.

the class AbstractDataSourcePoolMetadataTests method getIdle.

@Test
void getIdle() {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSourceMetadata().getDataSource());
    jdbcTemplate.execute((ConnectionCallback<Void>) (connection) -> null);
    assertThat(getDataSourceMetadata().getIdle()).isEqualTo(1);
}
Also used : Test(org.junit.jupiter.api.Test) DataSourceBuilder(org.springframework.boot.jdbc.DataSourceBuilder) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConnectionCallback(org.springframework.jdbc.core.ConnectionCallback) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Test(org.junit.jupiter.api.Test)

Example 17 with ConnectionCallback

use of org.springframework.jdbc.core.ConnectionCallback in project spring-boot by spring-projects.

the class AbstractDataSourcePoolMetadataTests method getPoolSizeOneConnection.

@Test
void getPoolSizeOneConnection() {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSourceMetadata().getDataSource());
    jdbcTemplate.execute((ConnectionCallback<Void>) (connection) -> {
        assertThat(getDataSourceMetadata().getActive()).isEqualTo(1);
        assertThat(getDataSourceMetadata().getUsage()).isEqualTo(0.5f);
        return null;
    });
}
Also used : Test(org.junit.jupiter.api.Test) DataSourceBuilder(org.springframework.boot.jdbc.DataSourceBuilder) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConnectionCallback(org.springframework.jdbc.core.ConnectionCallback) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Test(org.junit.jupiter.api.Test)

Example 18 with ConnectionCallback

use of org.springframework.jdbc.core.ConnectionCallback in project spring-boot by spring-projects.

the class AbstractDataSourcePoolMetadataTests method getPoolSizeNoConnection.

@Test
void getPoolSizeNoConnection() {
    // Make sure the pool is initialized
    JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSourceMetadata().getDataSource());
    jdbcTemplate.execute((ConnectionCallback<Void>) (connection) -> null);
    assertThat(getDataSourceMetadata().getActive()).isEqualTo(0);
    assertThat(getDataSourceMetadata().getUsage()).isEqualTo(0f);
}
Also used : Test(org.junit.jupiter.api.Test) DataSourceBuilder(org.springframework.boot.jdbc.DataSourceBuilder) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConnectionCallback(org.springframework.jdbc.core.ConnectionCallback) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Test(org.junit.jupiter.api.Test)

Example 19 with ConnectionCallback

use of org.springframework.jdbc.core.ConnectionCallback in project spring-data-jdbc by spring-projects.

the class DefaultJdbcTypeFactory method createArray.

@Override
public Array createArray(Object[] value) {
    Assert.notNull(value, "Value must not be null.");
    Class<?> componentType = arrayColumns.getArrayType(value.getClass());
    SQLType jdbcType = JdbcUtil.targetSqlTypeFor(componentType);
    Assert.notNull(jdbcType, () -> String.format("Couldn't determine JDBCType for %s", componentType));
    String typeName = arrayColumns.getArrayTypeName(jdbcType);
    return operations.execute((ConnectionCallback<Array>) c -> c.createArrayOf(typeName, value));
}
Also used : Array(java.sql.Array) JdbcOperations(org.springframework.jdbc.core.JdbcOperations) JdbcArrayColumns(org.springframework.data.jdbc.core.dialect.JdbcArrayColumns) SQLType(java.sql.SQLType) JdbcUtil(org.springframework.data.jdbc.support.JdbcUtil) ConnectionCallback(org.springframework.jdbc.core.ConnectionCallback) Array(java.sql.Array) Assert(org.springframework.util.Assert) SQLType(java.sql.SQLType)

Aggregations

ConnectionCallback (org.springframework.jdbc.core.ConnectionCallback)19 Connection (java.sql.Connection)13 PreparedStatement (java.sql.PreparedStatement)11 ResultSet (java.sql.ResultSet)11 SQLException (java.sql.SQLException)11 DataAccessException (org.springframework.dao.DataAccessException)9 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)9 IJoinQueryString (org.apereo.portal.jdbc.IJoinQueryString)6 Statement (java.sql.Statement)5 List (java.util.List)5 Date (java.sql.Date)4 Arrays (java.util.Arrays)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 DataSource (javax.sql.DataSource)4 IPerson (org.apereo.portal.security.IPerson)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Test (org.junit.jupiter.api.Test)4 DataSourceBuilder (org.springframework.boot.jdbc.DataSourceBuilder)4 Cache (com.google.common.cache.Cache)3