Bonjour,
J'ai une classe JUnit qui teste l'accès à la base de données,
Code:
package fr.s2e.aps.dao.impl;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import fr.s2e.aps.critere.ArpArchiveCritere;
import fr.s2e.aps.ometier.ArpArchive;
import fr.s2e.test.dao.BeanFactoryImpl;
import fr.s2e.test.dao.HibernateTestCase;
/**
*
*/
public class TestArpArchiveDaoImpl extends HibernateTestCase {
private ArpArchiveDaoImpl dao;
private HashSet<Long> idToDelete;
@Override
protected void setUp() throws Exception {
super.setUp();
idToDelete = new HashSet<Long>();
this.dao = ((ArpArchiveDaoImpl) BeanFactoryImpl
.getBean("arpArchiveDao"));
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
private ArpArchive initialiserObjet(ArpArchive objetTest) {
objetTest.setBoTraitActif(true);
objetTest.setCdPeriod("M");
objetTest.setCdTccp(3);
objetTest.setLbComputer("SHSCMET012");
objetTest.setLbNomEntree("TEST nomEntree");
objetTest.setLbRepEntree("TEST repEntree");
objetTest.setLbRepSortie("TEST repSortie");
objetTest.setNuAnciennete(2);
objetTest.setNuHeureArc(3);
objetTest.setNuJourArc(4);
objetTest.setNuMoisArc(5);
objetTest.setNuRang(6);
objetTest.setDateCreation(new Date());
return objetTest;
}
private void verifierObjet(final ArpArchive objetTest) {
assertTrue(objetTest.getBoTraitActif());
assertEquals("M", objetTest.getCdPeriod());
assertTrue(3 == objetTest.getCdTccp());
assertEquals("SHSCMET012", objetTest.getLbComputer());
assertEquals("TEST nomEntree", objetTest.getLbNomEntree());
assertEquals("TEST repEntree", objetTest.getLbRepEntree());
assertEquals("TEST repSortie", objetTest.getLbRepSortie());
assertTrue(2 == objetTest.getNuAnciennete());
assertTrue(3 == objetTest.getNuHeureArc());
assertTrue(4 == objetTest.getNuJourArc());
assertTrue(5 == objetTest.getNuMoisArc());
assertTrue(6 == objetTest.getNuRang());
}
/**
* Teste l'ajout, la modification, la suppression
*/
public void testBean() {
long id;
// Création
{
ArpArchive objetTest = new ArpArchive();
this.initialiserObjet(objetTest);
objetTest = this.dao.saveOrUpdate(objetTest);
id = objetTest.getId();
this.idToDelete.add(id);
getSession().flush();
}
getSession().clear();
// Récupération de l'objet créé
{
ArpArchive objetTest = this.dao.findById(id);
this.verifierObjet(objetTest);
}
// Suppression
{
ArpArchive objetTest = this.dao.findById(id);
this.dao.delete(objetTest);
getSession().flush();
getSession().clear();
assertNull(dao.findById(id));
getSession().flush();
}
getSession().flush();
}
/**
* Teste la recherche
*/
public void testFindByCriteria() {
long id;
// Création
{
ArpArchive objetTest = new ArpArchive();
this.initialiserObjet(objetTest);
objetTest = this.dao.saveOrUpdate(objetTest);
id = objetTest.getId();
this.idToDelete.add(id);
getSession().flush();
}
getSession().clear();
// Récupération de l'objet créé
{
Map<ArpArchiveCritere, Object> map = new HashMap<ArpArchiveCritere, Object>();
map.put(ArpArchiveCritere.cdPeriod, "M");
map.put(ArpArchiveCritere.cdTccp, 3);
map.put(ArpArchiveCritere.lbComputer, "SHSCMET012");
map.put(ArpArchiveCritere.lbNomEntree, "TEST nomEntree");
map.put(ArpArchiveCritere.lbRepEntree, "TEST repEntree");
map.put(ArpArchiveCritere.lbRepSortie, "TEST repSortie");
map.put(ArpArchiveCritere.nuAnciennete, 2);
map.put(ArpArchiveCritere.nuHeureArc, 3);
map.put(ArpArchiveCritere.nuJourArc, 4);
map.put(ArpArchiveCritere.nuMoisArc, 5);
map.put(ArpArchiveCritere.nuRang, 6);
List<ArpArchive> result = this.dao.findByCriteria(map);
assertEquals(1, result.size());
ArpArchive objetTest = result.get(0);
this.verifierObjet(objetTest);
}
// Suppression
{
ArpArchive objetTest = this.dao.findById(id);
this.dao.delete(objetTest);
getSession().flush();
getSession().clear();
assertNull(dao.findById(id));
getSession().flush();
}
getSession().clear();
}
}
avec la configuration SPRING à la base de données :
Code:
<bean id="BD_MET" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.p6spy.engine.spy.P6SpyDriver" /><!-- A remettre quand la bibliotheque correspondante sera ré-écrite/-->
<property name="jdbcUrl" value="jdbc:oracle:thin:@(description=(address=(host= monserveurbd)(protocol=tcp)(port=18922))(connect_data=(service_name=BD.WORLD)))" />
<property name="user" value="_GNR_GEN_USER" />
<property name="password" value="_PASSWD" />
<property name="initialPoolSize" value="1" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="5" />
<property name="idleConnectionTestPeriod" value="500" />
<property name="acquireIncrement" value="1" />
<property name="maxStatements" value="50" />
<property name="numHelperThreads" value="1" />
</bean>
Lorsque j'exécute les tests testBean() et testFindByCriteria() individuellement, il n'y a pas d'erreur.
En revanche quand j'exécute le JUnit en une seule j'ai l'erreur
Code:
p6spy - 1308916342302|0|0|statement|select this_.ID_ARCHIVE as ID1_1_0_, this_.UT_CREAT as UT2_1_0_, this_.DT_CREAT as DT3_1_0_, this_.DT_MODIF as DT4_1_0_, this_.UT_MODIF as UT5_1_0_, this_.BO_TRAIT_ACTIF as BO6_1_0_, this_.CD_PERIOD as CD7_1_0_, this_.CD_TCCP as CD8_1_0_, this_.LB_COMPUTER as LB9_1_0_, this_.LB_NOM_ENTREE as LB10_1_0_, this_.LB_REP_ENTREE as LB11_1_0_, this_.LB_REP_SORTIE as LB12_1_0_, this_.NU_ANCIENNETE as NU13_1_0_, this_.NU_HEURE_ARC as NU14_1_0_, this_.NU_JOUR_ARC as NU15_1_0_, this_.NU_MOIS_ARC as NU16_1_0_, this_.NU_RANG as NU17_1_0_ from IDE_GNR_ARP_ARCHIVE this_ where (this_.DT_CREAT=? and this_.BO_TRAIT_ACTIF=? and this_.CD_PERIOD=? and this_.CD_TCCP=? and this_.LB_COMPUTER=? and this_.LB_NOM_ENTREE=? and this_.LB_REP_ENTREE=? and this_.LB_REP_SORTIE=? and this_.NU_ANCIENNETE=? and this_.NU_HEURE_ARC=? and this_.NU_JOUR_ARC=? and this_.NU_MOIS_ARC=? and this_.NU_RANG=?)|select this_.ID_ARCHIVE as ID1_1_0_, this_.UT_CREAT as UT2_1_0_, this_.DT_CREAT as DT3_1_0_, this_.DT_MODIF as DT4_1_0_, this_.UT_MODIF as UT5_1_0_, this_.BO_TRAIT_ACTIF as BO6_1_0_, this_.CD_PERIOD as CD7_1_0_, this_.CD_TCCP as CD8_1_0_, this_.LB_COMPUTER as LB9_1_0_, this_.LB_NOM_ENTREE as LB10_1_0_, this_.LB_REP_ENTREE as LB11_1_0_, this_.LB_REP_SORTIE as LB12_1_0_, this_.NU_ANCIENNETE as NU13_1_0_, this_.NU_HEURE_ARC as NU14_1_0_, this_.NU_JOUR_ARC as NU15_1_0_, this_.NU_MOIS_ARC as NU16_1_0_, this_.NU_RANG as NU17_1_0_ from IDE_GNR_ARP_ARCHIVE this_ where (this_.DT_CREAT='2011-06-24 13:52:22.302' and this_.BO_TRAIT_ACTIF='true' and this_.CD_PERIOD='M' and this_.CD_TCCP=3 and this_.LB_COMPUTER='SHSCMET012' and this_.LB_NOM_ENTREE='TEST nomEntree' and this_.LB_REP_ENTREE='TEST repEntree' and this_.LB_REP_SORTIE='TEST repSortie' and this_.NU_ANCIENNETE=2 and this_.NU_HEURE_ARC=3 and this_.NU_JOUR_ARC=4 and this_.NU_MOIS_ARC=5 and this_.NU_RANG=6)
p6spy - 1308916342317|0|0|statement|insert into IDE_GNR_ARP_ARCHIVE (UT_CREAT, DT_CREAT, BO_TRAIT_ACTIF, CD_PERIOD, CD_TCCP, LB_COMPUTER, LB_NOM_ENTREE, LB_REP_ENTREE, LB_REP_SORTIE, NU_ANCIENNETE, NU_HEURE_ARC, NU_JOUR_ARC, NU_MOIS_ARC, NU_RANG) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|insert into IDE_GNR_ARP_ARCHIVE (UT_CREAT, DT_CREAT, BO_TRAIT_ACTIF, CD_PERIOD, CD_TCCP, LB_COMPUTER, LB_NOM_ENTREE, LB_REP_ENTREE, LB_REP_SORTIE, NU_ANCIENNETE, NU_HEURE_ARC, NU_JOUR_ARC, NU_MOIS_ARC, NU_RANG) values ('TST_USR', '2011-06-24 13:52:22.302', 'true', 'M', 3, 'SHSCMET012', 'TEST nomEntree', 'TEST repEntree', 'TEST repSortie', 2, 3, 4, 5, 6)
24 juin 2011 13:52:22 org.hibernate.util.JDBCExceptionReporter logExceptions
ATTENTION: SQL Error: 17041, SQLState: null
24 juin 2011 13:52:22 org.hibernate.util.JDBCExceptionReporter logExceptions
GRAVE: Paramètre IN ou OUT absent dans l'index :: 15
Sans pool de connexion, je n'ai pas d'erreur.
Code:
<bean id="BD_MET" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!-- property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /-->
<property name="driverClassName" value="com.p6spy.engine.spy.P6SpyDriver" />
<property name="url" value="jdbc:oracle:thin:@(description=(address=(host= monserveurbd.com)(protocol=tcp)(port=18922))(connect_data=(service_name=BD.WORLD)))" />
<property name="username" value="_GNR_GEN_USER" />
<property name="password" value="_GNR_PASSWD"/>
</bean>
Est-ce que quelqu'un peut m'aider à configurer le pool de connexion ?
Merci,
jclandron