예제 #1
0
 private SqlQueryResult executeQuery(final Domain domain, final String sql)
     throws SQLException, Exception {
   final SqlConnection connection = dataBaseManager.getConnectionProvider().obtainConnection();
   try (final SqlPreparedStatement preparedStatement =
       dataBaseManager.createPreparedStatement(connection, sql, false)) {
     preparedStatement.init();
     return preparedStatement.executeQuery(domain);
   } finally {
     connection.commit();
   }
 }
예제 #2
0
 private void execCallableStatement(final SqlConnection connection, final String sql)
     throws SQLException {
   final SqlCallableStatement callableStatement =
       dataBaseManager.createCallableStatement(connection, sql);
   callableStatement.init();
   callableStatement.executeUpdate();
 }
예제 #3
0
 public void createDatas() throws Exception {
   final SqlConnection connection = dataBaseManager.getConnectionProvider().obtainConnection();
   try {
     execCallableStatement(connection, "insert into movie values (1, 'citizen kane')");
     // -----
     execCallableStatement(connection, "insert into movie values (2, 'vertigo')");
     // -----
     // On passe par une requête bindée
     insert(connection, 3, TITLE_MOVIE_3);
   } finally {
     connection.commit();
   }
 }
예제 #4
0
 private void insert(final SqlConnection connection, final long key, final String libelle)
     throws SQLException {
   final String sql = "insert into movie values (?, ?)";
   try (final SqlCallableStatement callableStatement =
       dataBaseManager.createCallableStatement(connection, sql)) {
     callableStatement.registerParameter(0, DataType.Long, true);
     callableStatement.registerParameter(1, DataType.String, true);
     // -----
     callableStatement.init();
     // -----
     callableStatement.setValue(0, key);
     callableStatement.setValue(1, libelle);
     // -----
     callableStatement.executeUpdate();
   }
 }
예제 #5
0
 @Test
 public void testConnection() throws Exception {
   final SqlConnection connection = dataBaseManager.getConnectionProvider().obtainConnection();
   Assert.assertNotNull(connection);
   connection.commit();
 }
예제 #6
0
 @Override
 protected void doTearDown() throws Exception {
   // A chaque fin de test on arrête la base.
   final SqlConnection connection = dataBaseManager.getConnectionProvider().obtainConnection();
   execCallableStatement(connection, "shutdown;");
 }
예제 #7
0
 @Override
 protected void doSetUp() throws Exception {
   // A chaque test on recrée la table famille
   final SqlConnection connection = dataBaseManager.getConnectionProvider().obtainConnection();
   execCallableStatement(connection, "create table movie(id BIGINT , title varchar(255));");
 }