use of io.vertigo.database.sql.connection.SqlConnection in project vertigo by KleeGroup.
the class AbstractSqlDataBaseManagerTest method createDatas.
private void createDatas() throws Exception {
final SqlConnection connection = obtainMainConnection();
try {
insert(connection, Movies.createMovie(1, Movies.TITLE_MOVIE_1, // mail
null, null, null, null, new Date(1941 - 1900, 5 - 1, 1, 16, 30), LocalDate.of(1941, 5, 1), LocalDateTime.of(1941, 5, 1, 16, 30).toInstant(ZoneOffset.UTC)));
// -----
insert(connection, Movies.createMovie(2, Movies.TITLE_MOVIE_2, // mail
null, null, null, null, new Date(1958 - 1900, 5 - 1, 9, 16, 30), LocalDate.of(1958, 5, 9), LocalDateTime.of(1958, 5, 9, 16, 30).toInstant(ZoneOffset.UTC)));
// -----
// On passe par une requête bindée
insert(connection, Movies.createMovie(3, Movies.TITLE_MOVIE_3, // Mail
null, null, null, null, null, null, null));
connection.commit();
} finally {
connection.release();
}
}
use of io.vertigo.database.sql.connection.SqlConnection in project vertigo by KleeGroup.
the class AbstractSqlDataBaseManagerTest method testInsert.
@Test
public final void testInsert() throws Exception {
final String insertWithgeneratedKey = obtainMainConnection().getDataBase().getSqlDialect().createInsertQuery("ID", Arrays.asList("TITLE"), "seq_", "movie");
final GenerationMode generationMode = obtainMainConnection().getDataBase().getSqlDialect().getGenerationMode();
// We check that we have the right expected mode
Assert.assertEquals(getExpectedGenerationMode(), generationMode);
// ---
final SqlConnection connection = obtainMainConnection();
long generatedKey;
try {
final Movie movie = new Movie();
movie.setTitle("frankenstein");
generatedKey = dataBaseManager.executeUpdateWithGeneratedKey(SqlStatement.builder(insertWithgeneratedKey).bind("DTO", Movie.class, movie).build(), generationMode, "ID", Long.class, connection).getVal2();
connection.commit();
} finally {
connection.release();
}
final List<Integer> result = executeQuery(Integer.class, "select count(*) from movie", null);
Assert.assertEquals(1, result.size());
Assert.assertEquals(1, result.get(0).intValue());
final List<Integer> keys = executeQuery(Integer.class, "select id from movie", null);
Assert.assertEquals(1, keys.size());
Assert.assertEquals(generatedKey, keys.get(0).intValue());
}
use of io.vertigo.database.sql.connection.SqlConnection in project vertigo by KleeGroup.
the class NameSpace2JavaTest method execSqlScript.
private void execSqlScript(final String sqlScript, final App app) {
final ResourceManager resourceManager = app.getComponentSpace().resolve(ResourceManager.class);
final SqlDataBaseManager sqlDataBaseManager = app.getComponentSpace().resolve(SqlDataBaseManager.class);
final SqlConnection connection = sqlDataBaseManager.getConnectionProvider(SqlDataBaseManager.MAIN_CONNECTION_PROVIDER_NAME).obtainConnection();
DataBaseScriptUtil.execSqlScript(connection, sqlScript, resourceManager, sqlDataBaseManager);
}
Aggregations