use of io.vertigo.database.sql.connection.SqlConnectionProvider in project vertigo by KleeGroup.
the class AbstractSqlDataBaseManagerTest method testBatchInserts.
@Test
public void testBatchInserts() throws Exception {
final SqlConnectionProvider sqlConnectionProvider = dataBaseManager.getConnectionProvider(SqlDataBaseManager.MAIN_CONNECTION_PROVIDER_NAME);
final String sql = INSERT_INTO_MOVIE_VALUES;
final List<Movie> movies = Movies.bondMovies();
// --prepare data
final List<List<SqlParameter>> batch = new ArrayList<>();
for (final Movie movie : movies) {
final List<SqlParameter> sqlParameters = Arrays.asList(SqlParameter.of(Long.class, movie.getId()), SqlParameter.of(String.class, movie.getTitle()), SqlParameter.of(Double.class, movie.getFps()), SqlParameter.of(BigDecimal.class, movie.getIncome()), SqlParameter.of(Boolean.class, movie.getColor()), SqlParameter.of(Date.class, movie.getReleaseDate()), SqlParameter.of(LocalDate.class, movie.getReleaseLocalDate()), SqlParameter.of(Instant.class, movie.getReleaseInstant()), SqlParameter.of(DataStream.class, movie.getIcon()));
batch.add(sqlParameters);
}
final SqlConnection connection = sqlConnectionProvider.obtainConnection();
final OptionalInt result;
try {
final SqlStatementBuilder sqlStatementBuilder = SqlStatement.builder(sql);
for (final Movie movie : movies) {
sqlStatementBuilder.bind("movie", Movie.class, movie).nextLine();
}
result = dataBaseManager.executeBatch(sqlStatementBuilder.build(), connection);
connection.commit();
} finally {
connection.release();
}
// ---
if (result.isPresent()) {
Assert.assertEquals(movies.size(), result.getAsInt());
}
final List<Integer> countMovie = executeQuery(Integer.class, "select count(*) from movie", 1);
Assert.assertEquals(movies.size(), countMovie.get(0).intValue());
}
use of io.vertigo.database.sql.connection.SqlConnectionProvider in project vertigo by KleeGroup.
the class HibernateConnectionProviderTest method ping.
@Test
public void ping() throws SQLException {
final SqlConnectionProvider sqlConnectionProvider = sqlDataBaseManager.getConnectionProvider(SqlDataBaseManager.MAIN_CONNECTION_PROVIDER_NAME);
final String testQuery = sqlConnectionProvider.getDataBase().getSqlDialect().getTestQuery();
try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
final SqlConnection connection = sqlConnectionProvider.obtainConnection();
try {
sqlDataBaseManager.executeQuery(SqlStatement.builder(testQuery).build(), Integer.class, 1, connection);
} finally {
connection.release();
}
}
}
use of io.vertigo.database.sql.connection.SqlConnectionProvider in project vertigo by KleeGroup.
the class SqlDataBaseManagerImpl method getConnectionProvider.
/**
* {@inheritDoc}
*/
@Override
public SqlConnectionProvider getConnectionProvider(final String name) {
final SqlConnectionProvider sqlConnectionProvider = connectionProviderPluginMap.get(name);
Assertion.checkNotNull(sqlConnectionProvider, "ConnectionProvider {0}, wasn't registered.", name);
return sqlConnectionProvider;
}
Aggregations