<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog de CinéPhil</title>
	<atom:link href="https://blog.developpez.com/cinephil/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.developpez.com/cinephil</link>
	<description>Ce qui se conçoit bien s&#039;énonce clairement...</description>
	<lastBuildDate>Tue, 11 Dec 2012 15:58:32 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>Installer Open Modelsphere sous Linux</title>
		<link>https://blog.developpez.com/cinephil/p9577/bases-de-donnees/installer_open_modelsphere_sous_linux</link>
		<comments>https://blog.developpez.com/cinephil/p9577/bases-de-donnees/installer_open_modelsphere_sous_linux#comments</comments>
		<pubDate>Wed, 29 Aug 2012 13:05:39 +0000</pubDate>
		<dc:creator><![CDATA[CinePhil]]></dc:creator>
				<category><![CDATA[Bases de données]]></category>
		<category><![CDATA[Conception]]></category>
		<category><![CDATA[Modélisation]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[MISE À JOUR LE 29/08/2012 pour la version 3.2 &#171;&#160;Open ModelSphere est un outil complet de modélisation de données qui prend en charge la modélisation conceptuelle, logique et physique. Il supporte plusieurs formalismes, entre autres: Entité-Association, DATARUN, et Information Engineering. &#8230; <a href="https://blog.developpez.com/cinephil/p9577/bases-de-donnees/installer_open_modelsphere_sous_linux">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>MISE À JOUR LE 29/08/2012 pour la version 3.2</p>
<p>&laquo;&nbsp;Open ModelSphere est un outil complet de modélisation de données qui prend en charge la modélisation conceptuelle, logique et physique. Il supporte plusieurs formalismes, entre autres: Entité-Association, DATARUN, et Information Engineering. Les modèles conceptuels peuvent être convertis en modèles relationnels et vice versa.&nbsp;&raquo;</p>
<p>Avec Open Modelsphere, on peut notamment modéliser des bases de données selon la méthode Merise ou en faisant un diagramme de classes UML.</p>
<p>C&rsquo;est aussi, à ma connaissance, le seul logiciel de modélisation open source qui permette de faire des MCT Merise.</p>
<p>Il est <a href="http://www.modelsphere.org/fr/download.html">téléchargeable</a> sur le <a href="http://www.modelsphere.org/fr/index.html">site officiel</a>.</p>
<p>Vous remarquerez que la version téléchargeable est indiquée pour Windows mais comme il s&rsquo;agit d&rsquo;un programme Java, il fonctionne aussi sous Linux.</p>
<p>Voici les changements à opérer pour que ça fonctionne&#8230;<br />
<span id="more-2"></span></p>
<p>Après téléchargement de &laquo;&nbsp;Open ModelSphere 3.2 sous Windows (fichier zip)&nbsp;&raquo;, décompressez celui-ci dans le répertoire de votre choix, puis donnez-vous éventuellement les droits d&rsquo;accès nécessaires.<br />
Sur ma Mageia Linux 2, je l&rsquo;ai installé dans /usr/share/. Vous aurez alors un répertoire &laquo;&nbsp;Open_ModelSphere_[version]&nbsp;&raquo;. J&rsquo;ai renommé ce répertoire tout simplement en &laquo;&nbsp;modelsphere&nbsp;&raquo; pour éviter des problèmes avec les noms à espaces et autres points.<br />
Dans ce répertoire, vous trouverez un fichier &laquo;&nbsp;modelsphere.bat&nbsp;&raquo; dont le contenu est le suivant :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&quot;C:\Program Files\Java\jdk1.7.0_01\jre/bin/javaw.exe&quot; -ms32m -mx1024m -ss16m -classpath &quot;.\modelsphere.jar;.\resources.zip;.\resources;.\targets;.\lib\jakarta-regexp-1.5\jakarta-regexp-1.5.jar;.\lib\velocity-1.6.1\velocity-1.6.1.jar;.\lib\jazzy-core\jazzy-core.jar;.\lib\jgrapht-all\jgrapht-all.jar;.\lib\jython-2.2.1\jython.jar;.\lib\velocity-1.6.1\lib\commons-collections-3.2.1.jar;.\lib\velocity-1.6.1\lib\commons-lang-2.4.jar;.\lib\lablib-checkboxtree-3.0.2.jar;.\lib\antlr-3.3-complete.jar;.\plugins\bin\repository_functions.jar&quot; org.modelsphere.sms.Application</div></td></tr></tbody></table></div>
<p>Ouvrez ce fichier avec un éditeur de texte et transformez-le de cette manière :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#!/bin/bash <br />
cd `dirname $0` <br />
java -ms64m -mx1024m -ss16m -classpath &quot;.:./modelsphere.jar:./resources.zip:./resources:./targets:./lib/jakarta-regexp-1.5/jakarta-regexp-1.5.jar:./lib/velocity-1.6.1/velocity-1.6.1.jar:./lib/jazzy-core/jazzy-core.jar:./lib/jgrapht-all/jgrapht-all.jar:./lib/jython-2.2.1/jython.jar:./lib/velocity-1.6.1/lib/commons-collections-3.2.1.jar:./lib/velocity-1.6.1/lib/commons-lang-2.4.jar:./lib/lablib-checkboxtree-3.0.2.jar:./lib/antlr-3.3-complete.jar:./plugins/bin/repository_functions.jar&quot; org.modelsphere.sms.Application</div></td></tr></tbody></table></div>
<p>=> Il faut ajouter le descripteur du shell et la commande pour se rendre dans le répertoire  du logiciel, supprimer le chemin Windows vers le programme java et remplacer :<br />
&#8211; les antislashes par des slashes ;<br />
&#8211; les points virgules par des doubles-points.<br />
Vous pouvez copier/coller directement le code ci-dessus pour la version 3.2 mais si vous installez une version ultérieure, appliquez le principe donné juste avant pour faire votre lanceur d&rsquo;application.</p>
<p>Enregistrez-le sous &laquo;&nbsp;modelsphere.sh&nbsp;&raquo;, rendez-le exécutable (<code class="codecolorer text default"><span class="text">chmod a+x modelsphere.sh</span></code>) et servez-vous en pour démarrer Open Modelsphere.</p>
<p>Vous pouvez ensuite faire un raccourci vers le programme. Je l&rsquo;ai placé dans le menu &laquo;&nbsp;Développement&nbsp;&raquo; de KDE en lui associant la commande suivante : <code class="codecolorer text default"><span class="text">/usr/share/modelsphere/./modelsphere.sh</span></code> </p>
<p>Il faut bien sûr que Java soit installé et qu&rsquo;il puisse être activé par la simple commande &laquo;&nbsp;java&nbsp;&raquo; !</p>
<p>PS :<br />
&#8211; Merci à passie pour sa collaboration dans la recherche de la bonne syntaxe en 2009.<br />
&#8211; Un site utile pour utiliser Open Modelsphere : http://www.marco-savard.com/OpenModelSphere/index_fr.html</p>
<p>Bonnes modélisations !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Jointure externe et condition de restriction.</title>
		<link>https://blog.developpez.com/cinephil/p9571/bases-de-donnees/langage-sql/jointure_externe_et_condition_de_restric</link>
		<comments>https://blog.developpez.com/cinephil/p9571/bases-de-donnees/langage-sql/jointure_externe_et_condition_de_restric#comments</comments>
		<pubDate>Fri, 10 Dec 2010 13:44:17 +0000</pubDate>
		<dc:creator><![CDATA[CinePhil]]></dc:creator>
				<category><![CDATA[Langage SQL]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Quand on fait une jointure externe à gauche et qu&#8217;on pose une restriction (dans le WHERE) sur la table de droite, c&#8217;est comme si on faisait une jointure interne ! Explication avec un exemple simple&#8230; Soit les tables suivantes : &#8230; <a href="https://blog.developpez.com/cinephil/p9571/bases-de-donnees/langage-sql/jointure_externe_et_condition_de_restric">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Quand on fait une jointure externe à gauche et qu&rsquo;on pose une restriction (dans le WHERE) sur la table de droite, c&rsquo;est comme si on faisait une jointure interne !</p>
<p>Explication avec un exemple simple&#8230;<br />
<span id="more-1"></span><br />
Soit les tables suivantes :<br />
Table A<br />
idA, valA<br />
1, &lsquo;toto&rsquo;<br />
2, &lsquo;titi&rsquo;<br />
3, &lsquo;tata&rsquo;</p>
<p>Table B<br />
idB, idA, valB, booleen<br />
1, 2, &lsquo;riri&rsquo;, 0<br />
2, 3, &lsquo;fifi&rsquo;, 1</p>
<p>Faisons une jointure externe à gauche sans condition :<br />
=> Code :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> A<span style="color: #66cc66;">.</span>idA<span style="color: #66cc66;">,</span> A<span style="color: #66cc66;">.</span>valA<span style="color: #66cc66;">,</span> B<span style="color: #66cc66;">.</span>idB<span style="color: #66cc66;">,</span> B<span style="color: #66cc66;">.</span>valB<span style="color: #66cc66;">,</span> B<span style="color: #66cc66;">.</span>booleen <br />
<span style="color: #993333; font-weight: bold;">FROM</span> A <br />
<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> B <span style="color: #993333; font-weight: bold;">ON</span> B<span style="color: #66cc66;">.</span>idA <span style="color: #66cc66;">=</span> A<span style="color: #66cc66;">.</span>idA</div></td></tr></tbody></table></div>
<p>=> Résultat :<br />
idA, valA, idB, valB, booleen<br />
1, &lsquo;toto&rsquo;, NULL, NULL, NULL<br />
2, &lsquo;titi&rsquo;, 1, &lsquo;riri&rsquo;, 0<br />
3, &lsquo;tata&rsquo;, 2, &lsquo;fifi&rsquo;, 1</p>
<p>Ajoutons une restriction dans le WHERE sur la table B :<br />
=> Code :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> A<span style="color: #66cc66;">.</span>idA<span style="color: #66cc66;">,</span> A<span style="color: #66cc66;">.</span>valA<span style="color: #66cc66;">,</span> B<span style="color: #66cc66;">.</span>idB<span style="color: #66cc66;">,</span> B<span style="color: #66cc66;">.</span>valB<span style="color: #66cc66;">,</span> B<span style="color: #66cc66;">.</span>booleen <br />
<span style="color: #993333; font-weight: bold;">FROM</span> A <br />
<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> B <span style="color: #993333; font-weight: bold;">ON</span> B<span style="color: #66cc66;">.</span>idA <span style="color: #66cc66;">=</span> A<span style="color: #66cc66;">.</span>idA <br />
<span style="color: #993333; font-weight: bold;">WHERE</span> B<span style="color: #66cc66;">.</span>booleen <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span></div></td></tr></tbody></table></div>
<p>=> Résultat :<br />
idA, valA, idB, valB, booleen<br />
3, &lsquo;tata&rsquo;, 2, &lsquo;fifi&rsquo;, 1</p>
<p>La seule ligne qui répond à la condition est celle de fifi. On n&rsquo;a plus toutes les lignes de A.<br />
J&rsquo;aurais obtenu le même résultat avec une jointure interne. Démonstration&#8230;</p>
<p>1ère requête sans WHERE<br />
=> Code :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> A<span style="color: #66cc66;">.</span>idA<span style="color: #66cc66;">,</span> A<span style="color: #66cc66;">.</span>valA<span style="color: #66cc66;">,</span> B<span style="color: #66cc66;">.</span>idB<span style="color: #66cc66;">,</span> B<span style="color: #66cc66;">.</span>valB<span style="color: #66cc66;">,</span> B<span style="color: #66cc66;">.</span>booleen <br />
<span style="color: #993333; font-weight: bold;">FROM</span> A <br />
<span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> B <span style="color: #993333; font-weight: bold;">ON</span> B<span style="color: #66cc66;">.</span>idA <span style="color: #66cc66;">=</span> A<span style="color: #66cc66;">.</span>idA</div></td></tr></tbody></table></div>
<p>=> Résultat :<br />
idA, valA, idB, valB, booleen<br />
2, &lsquo;titi&rsquo;, 1, &lsquo;riri&rsquo;, 0<br />
3, &lsquo;tata&rsquo;, 2, &lsquo;fifi&rsquo;, 1</p>
<p>2ème requête avec le WHERE :<br />
=> Code :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> A<span style="color: #66cc66;">.</span>idA<span style="color: #66cc66;">,</span> A<span style="color: #66cc66;">.</span>valA<span style="color: #66cc66;">,</span> B<span style="color: #66cc66;">.</span>idB<span style="color: #66cc66;">,</span> B<span style="color: #66cc66;">.</span>valB<span style="color: #66cc66;">,</span> B<span style="color: #66cc66;">.</span>booleen <br />
&nbsp;<span style="color: #993333; font-weight: bold;">FROM</span> A <br />
&nbsp;<span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> B <span style="color: #993333; font-weight: bold;">ON</span> B<span style="color: #66cc66;">.</span>idA <span style="color: #66cc66;">=</span> A<span style="color: #66cc66;">.</span>idA <br />
<span style="color: #993333; font-weight: bold;">WHERE</span> B<span style="color: #66cc66;">.</span>booleen <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span></div></td></tr></tbody></table></div>
<p>=> Résultat :<br />
idA, valA, idB, valB, booleen<br />
3, &lsquo;tata&rsquo;, 2, &lsquo;fifi&rsquo;, 1</p>
<p>Reprenons maintenant la jointure externe et mettons la restriction dans la clause de jointure :<br />
=> Code :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> A<span style="color: #66cc66;">.</span>idA<span style="color: #66cc66;">,</span> A<span style="color: #66cc66;">.</span>valA<span style="color: #66cc66;">,</span> B<span style="color: #66cc66;">.</span>idB<span style="color: #66cc66;">,</span> B<span style="color: #66cc66;">.</span>valB<span style="color: #66cc66;">,</span> B<span style="color: #66cc66;">.</span>booleen <br />
&nbsp;<span style="color: #993333; font-weight: bold;">FROM</span> A <br />
&nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> B <span style="color: #993333; font-weight: bold;">ON</span> B<span style="color: #66cc66;">.</span>idA <span style="color: #66cc66;">=</span> A<span style="color: #66cc66;">.</span>idA <br />
&nbsp; <span style="color: #993333; font-weight: bold;">AND</span> B<span style="color: #66cc66;">.</span>booleen <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span></div></td></tr></tbody></table></div>
<p>=> Résultat :<br />
idA, valA, idB, valB, booleen<br />
1, &lsquo;toto&rsquo;, NULL, NULL, NULL<br />
2, &lsquo;titi&rsquo;, NULL, NULL, NULL<br />
3, &lsquo;tata&rsquo;, 2, &lsquo;fifi&rsquo;, 1</p>
<p>La jointure est faite sur les données restreintes au booleen = 1, c&rsquo;est à dire seulement fifi mais toutes les lignes de A sont affichées, avec NULL dans les colonnes de B quand il n&rsquo;y a pas de correspondance.</p>
<p><strong>Conclusion :</strong></p>
<p>Avec une jointure externe, il faut déplacer les conditions de restriction sur la table externe du WHERE vers la condition de jointure. Sinon c&rsquo;est l&rsquo;équivalent d&rsquo;une jointure interne. </p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Quand faut-il une table associative ?</title>
		<link>https://blog.developpez.com/cinephil/p10017/bases-de-donnees/quand_faut_il_une_table_associative</link>
		<comments>https://blog.developpez.com/cinephil/p10017/bases-de-donnees/quand_faut_il_une_table_associative#comments</comments>
		<pubDate>Fri, 24 Feb 2012 23:16:46 +0000</pubDate>
		<dc:creator><![CDATA[CinePhil]]></dc:creator>
				<category><![CDATA[Bases de données]]></category>
		<category><![CDATA[Conception]]></category>
		<category><![CDATA[Modélisation]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Mise à jour du 11/12/2012 : Ajout des contraintes d&#8217;unicité sur le cas 01. Merci à Richard_35 pour la suggestion et le travail complémentaire. Ceux qui connaissent le modèle conceptuel de données (MCD) de la méthode Merise savent que lorsque &#8230; <a href="https://blog.developpez.com/cinephil/p10017/bases-de-donnees/quand_faut_il_une_table_associative">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><strong>Mise à jour</strong> du 11/12/2012 : Ajout des contraintes d&rsquo;unicité sur le cas 01. <em>Merci à Richard_35 pour la suggestion et le travail complémentaire.</em></p>
<p>Ceux qui connaissent le modèle conceptuel de données (MCD) de la méthode Merise savent que lorsque les cardinalités maximales d&rsquo;une association sont toutes deux à n, cela entraînera la création d&rsquo;une table associative dans la base de données.</p>
<p>Mais il y a d&rsquo;autres cas et certains suscitent quelques débats au sein des forums.</p>
<p>Examinons tous les cas possibles&#8230;<span id="more-3"></span></p>
<p>Soit deux entités A et B et une association entre elles. Les 16 associations possibles sont les suivantes :<br />
01) A -0,1&#8212;-associer&#8212;-0,1- B<br />
02) A -0,1&#8212;-associer&#8212;-1,1- B<br />
03) A -0,1&#8212;-associer&#8212;-0,n- B<br />
04) A -0,1&#8212;-associer&#8212;-1,n- B<br />
05) A -1,1&#8212;-associer&#8212;-0,1- B<br />
06) A -1,1&#8212;-associer&#8212;-1,1- B<br />
07) A -1,1&#8212;-associer&#8212;-0,n- B<br />
08) A -1,1&#8212;-associer&#8212;-1,n- B<br />
09) A -0,n&#8212;-associer&#8212;-0,1- B<br />
10) A -0,n&#8212;-associer&#8212;-1,1- B<br />
11) A -0,n&#8212;-associer&#8212;-0,n- B<br />
12) A -0,n&#8212;-associer&#8212;-1,n- B<br />
13) A -1,n&#8212;-associer&#8212;-0,1- B<br />
14) A -1,n&#8212;-associer&#8212;-1,1- B<br />
15) A -1,n&#8212;-associer&#8212;-0,n- B<br />
16) A -1,n&#8212;-associer&#8212;-1,n- B</p>
<p>On remarque que les cardinalités de l&rsquo;association 02 sont inversées par rapport à l&rsquo;association 05, de même pour la 03 et la 09, la 04 et la 13, la 07 et la 10, la 08 et la 14, la 12 et la 15.<br />
Il ne reste donc plus que les 10 cas suivants :<br />
01) A -0,1&#8212;-associer&#8212;-0,1- B<br />
02) A -0,1&#8212;-associer&#8212;-1,1- B<br />
03) A -0,1&#8212;-associer&#8212;-0,n- B<br />
04) A -0,1&#8212;-associer&#8212;-1,n- B<br />
06) A -1,1&#8212;-associer&#8212;-1,1- B<br />
07) A -1,1&#8212;-associer&#8212;-0,n- B<br />
08) A -1,1&#8212;-associer&#8212;-1,n- B<br />
11) A -0,n&#8212;-associer&#8212;-0,n- B<br />
12) A -0,n&#8212;-associer&#8212;-1,n- B<br />
16) A -1,n&#8212;-associer&#8212;-1,n- B</p>
<p>Commençons par les cas les plus faciles&#8230;<br />
Comme dit en introduction, il faut une table associative lorsque les cardinalités maximales sont à n. Il s&rsquo;agit ici des 3 derniers cas, 11, 12 et 16.<br />
Lorsque que les cardinalités sont à 1,1 d&rsquo;un côté d&rsquo;une association, il y aura une clé étrangère dans la table issue de l&rsquo;entité située du côté des cardinalités 1,1. Il s&rsquo;agit ici des cas 02, 07 et 08. Le cas 06 appelle des commentaires que je ferai plus tard&#8230;</p>
<p>Inscrivons ces cas simples dans le tableau :<br />
01) A -0,1&#8212;-associer&#8212;-0,1- B<br />
02) A -0,1&#8212;-associer&#8212;-1,1- B =&gt; Clé étrangère dans la table issue de l&rsquo;entité B<br />
03) A -0,1&#8212;-associer&#8212;-0,n- B<br />
04) A -0,1&#8212;-associer&#8212;-1,n- B<br />
06) A -1,1&#8212;-associer&#8212;-1,1- B<br />
07) A -1,1&#8212;-associer&#8212;-0,n- B =&gt; Clé étrangère dans la table issue de l&rsquo;entité A<br />
08) A -1,1&#8212;-associer&#8212;-1,n- B =&gt; Clé étrangère dans la table issue de l&rsquo;entité A<br />
11) A -0,n&#8212;-associer&#8212;-0,n- B =&gt; Table associative<br />
12) A -0,n&#8212;-associer&#8212;-1,n- B =&gt; Table associative<br />
16) A -1,n&#8212;-associer&#8212;-1,n- B =&gt; Table associative</p>
<p>Examinons maintenant les cas qui restent, en commençant par le 06, qui semblerait entrer dans la seconde catégorie des cas faciles&#8230;</p>
<p>Cas 06) A -1,1&#8212;-associer&#8212;-1,1- B<br />
Lorsque les deux couples de cardinalités sont à 1,1, on doit se demander si on peut fusionner les deux entités. Si elles représentent des choses sémantiquement différentes ou si on les conserve pour une raison technique (ajout de table à une BDD existante, amélioration des performances par séparation de données importantes en volume mais rarement lues&#8230;), on a le choix de la table qui accueillera la clé étrangère.</p>
<p>Cas 04) A -0,1&#8212;-associer&#8212;-1,n- B<br />
La clé étrangère ne peut pas aller dans B puisque un B peut être associé à plusieurs A. Mais elle ne peut pas non plus aller dans A puisque un A peut ne pas être associé à un B. Il faut donc une table associative. Et comme un A sera associé au maximum une seule fois à un B, la clé primaire de la table associative sera la clé étrangère référençant A.</p>
<p>Cas 03) A -0,1&#8212;-associer&#8212;-0,n- B<br />
Aucune des deux entités n&rsquo;est systématiquement associée à l&rsquo;autre (cardinalités minimales à 0). Il faut donc une table associative dont la clé primaire sera, pour la même raison que dans le cas 04, la clé étrangère référençant A.</p>
<p>Cas 01) A -0,1&#8212;-associer&#8212;-0,1- B<br />
Pour la même raison que dans le cas 03, il faut une table associative. Et pour la même raison que dans le cas 06, on a le choix de la clé étrangère qui sera également clé primaire, l&rsquo;autre clé étrangère devant être munie d&rsquo;une contrainte d&rsquo;unicité.</p>
<p>Complétons le tableau :<br />
01) A -0,1&#8212;-associer&#8212;-0,1- B =&gt; Table associative avec le choix de la clé primaire.</p>
<ul>
<li><strong>A</strong> (<u>IdA</u>, &#8230;) ;</li>
<li><strong>B</strong> (<u>IdB</u>, &#8230;) ;</li>
<li><strong>AB</strong> (<em><u>#IdA</u>, #IdB</em>, &#8230;) + index unique sur #IdB<br />
ou <strong>AB</strong>(<em><u>#IdB</u>, #IdA</em>, &#8230;) + index unique sur #IdA.</li>
</ul>
<p>02) A -0,1&#8212;-associer&#8212;-1,1- B =&gt; Clé étrangère dans la table issue de l&rsquo;entité B</p>
<ul>
<li><strong>A</strong> (<u>IdA</u>, &#8230;) ;</li>
<li><strong>B</strong> (<u>IdB</u>, <em>#IdA</em>, &#8230;).</li>
</ul>
<p>03) A -0,1&#8212;-associer&#8212;-0,n- B =&gt; Table associative dont la clé primaire référence A</p>
<ul>
<li><strong>A</strong> (<u>IdA</u>, &#8230;) ;</li>
<li><strong>B</strong> (<u>IdB</u>, &#8230;) ;</li>
<li><strong>AB</strong> (<u>#IdA</u>, #IdB, &#8230;).</li>
</ul>
<p>04) A -0,1&#8212;-associer&#8212;-1,n- B =&gt; Table associative dont la clé primaire référence A</p>
<ul>
<li><strong>A</strong> (<u>IdA</u>, &#8230;) ;</li>
<li><strong>B</strong> (<u>IdB</u>, &#8230;) ;</li>
<li><strong>AB</strong> (<u>#IdA</u>, #IdB, &#8230;).</li>
</ul>
<p>06) A -1,1&#8212;-associer&#8212;-1,1- B =&gt; Fusion des deux entités ou clé étrangère dans A ou B</p>
<ul>
<li><strong>AB</strong> (<u>IdAB</u>, {attributs de A}, {attributs de B}, &#8230;).</li>
</ul>
<p>ou :</p>
<ul>
<li><strong>A</strong> (<u>IdA</u>, <em>#IdB</em>, &#8230;) ;</li>
<li><strong>B</strong> (<u>IdB</u>, &#8230;).</li>
</ul>
<p>ou</p>
<ul>
<li><strong>A</strong> (<u>IdA</u>, &#8230;) ;</li>
<li><strong>B</strong> (<u>IdB</u>, <em>#IdA</em>, &#8230;).</li>
</ul>
<p>07) A -1,1&#8212;-associer&#8212;-0,n- B =&gt; Clé étrangère dans la table issue de l&rsquo;entité A</p>
<ul>
<li><strong>A</strong> (<u>IdA</u>, <em>#IdB</em>, &#8230;) ;</li>
<li><strong>B</strong> (<u>IdB</u>, &#8230;) ;</li>
</ul>
<p>08) A -1,1&#8212;-associer&#8212;-1,n- B =&gt; Clé étrangère dans la table issue de l&rsquo;entité A</p>
<ul>
<li><strong>A</strong> (<u>IdA</u>, <em>#IdB</em>, &#8230;) ;</li>
<li><strong>B</strong> (<u>IdB</u>, &#8230;) ;</li>
</ul>
<p>11) A -0,n&#8212;-associer&#8212;-0,n- B =&gt; Table associative</p>
<ul>
<li><strong>A</strong> (<u>IdA</u>, &#8230;) ;</li>
<li><strong>B</strong> (<u>IdB</u>, &#8230;) ;</li>
<li><strong>AB</strong> (<u><em>#IdA, #IdB</em></u>, &#8230;).</li>
</ul>
<p>12) A -0,n&#8212;-associer&#8212;-1,n- B =&gt; Table associative</p>
<ul>
<li><strong>A</strong> (<u>IdA</u>, &#8230;) ;</li>
<li><strong>B</strong> (<u>IdB</u>, &#8230;) ;</li>
<li><strong>AB</strong> (<u><em>#IdA, #IdB</em></u>, &#8230;).</li>
</ul>
<p>16) A -1,n&#8212;-associer&#8212;-1,n- B =&gt; Table associative</p>
<ul>
<li><strong>A</strong> (<u>IdA</u>, &#8230;) ;</li>
<li><strong>B</strong> (<u>IdB</u>, &#8230;) ;</li>
<li><strong>AB</strong> (<u><em>#IdA, #IdB</em></u>, &#8230;).</li>
</ul>
<p>Sur 10 cas, il y en a donc 6 qui nécessitent une table associative !</p>
<p>== Mise à jour du 20/09/2011 ==<br />
Suite à <a href="http://www.developpez.net/forums/d1132688/bases-donnees/mysql/requetes/primary-key-foreign-key/#post6249319">une question</a> posée par cretthie dans une discussion du forum MySQL/Requêtes, j&rsquo;apporte des précisions pour les cas demandant une table associative.</p>
<p>01) Il y aura une clé étrangère référençant A et une autre référençant B. On a le choix de décider quelle clé étrangère constituera également, toute seule, la clé primaire de la table. L&rsquo;autre colonne portant la seconde clé étrangère sera en plus munie d&rsquo;une contrainte d&rsquo;unicité (index de type UNIQUE chez MySQL) pour respecter la cardinalité 0,1.<br />
03) et 04) Là aussi, la clé primaire n&rsquo;est constituée que d&rsquo;une seule des deux clés étrangères : celle référençant A. L&rsquo;autre est une clé étrangère &laquo;&nbsp;ordinaire&nbsp;&raquo;.<br />
11), 12) et 16) Dans ces trois cas, la clé primaire de la table associative est composée des clés étrangères référençant A et B.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>Règle de gestion bien écrite =&gt; Modélisation des données facile</title>
		<link>https://blog.developpez.com/cinephil/p10397/bases-de-donnees/regle_de_gestion_bien_ecrite_g_modelisat</link>
		<comments>https://blog.developpez.com/cinephil/p10397/bases-de-donnees/regle_de_gestion_bien_ecrite_g_modelisat#comments</comments>
		<pubDate>Fri, 17 Feb 2012 13:14:16 +0000</pubDate>
		<dc:creator><![CDATA[CinePhil]]></dc:creator>
				<category><![CDATA[Bases de données]]></category>
		<category><![CDATA[Conception]]></category>
		<category><![CDATA[Modélisation]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Même si vous débutez en modélisation de base de données, en écrivant correctement les règles de gestion des données, vous pourrez facilement créer votre MCD (ou votre diagramme de classes si vous préférez UML). La méthode que je décris ci-après &#8230; <a href="https://blog.developpez.com/cinephil/p10397/bases-de-donnees/regle_de_gestion_bien_ecrite_g_modelisat">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Même si vous débutez en modélisation de base de données, en écrivant correctement les règles de gestion des données, vous pourrez facilement créer votre MCD (ou votre diagramme de classes si vous préférez UML).</p>
<p>La méthode que je décris ci-après devrait vous aider beaucoup pour apprendre à modéliser correctement.<br />
<span id="more-4"></span></p>
<p><strong>1) Écrire une règle de gestion</strong><br />
L&rsquo;exercice consiste à écrire en français (ou dans la langue de votre choix) une phrase décrivant comment sont associés deux concepts.</p>
<p>Par exemple, on vous demande de modéliser les données nécessaires à une gestion de projets et on vous dit, entre autres, qu&rsquo;<em>il y a toujours une personne qui est nommée chef de projet pour un projet et que plusieurs personnes travaillent sur un projet</em>.</p>
<p>L&rsquo;extrait en italique de la phrase précédente pourrait suffire à un concepteur habitué à la modélisation des données pour produire un MCD correct et possible mais il manque des informations pour ne pas faire d&rsquo;erreur :<br />
&#8211; est-ce qu&rsquo;une personne est obligatoirement chef de projet au moins une fois ?<br />
&#8211; est-ce que toute personne enregistrée dans le système travaille sur au moins un projet ?<br />
&#8211; est-ce qu&rsquo;une personne ne peut travailler que sur un seul projet à la fois ?</p>
<p>Muni des réponses à ces questions, vous pouvez écrire vos règles de gestion relatives aux associations entre les personnes et les projets. Par exemple, les réponses peuvent vous amener à écrire à coup sûr ces deux règles de gestion :<br />
1) Un projet est dirigé par une seule personne (nommée &laquo;&nbsp;chef de projet&nbsp;&raquo; pour ce projet) et une personne peut diriger plusieurs projets (en étant nommée &laquo;&nbsp;chef de projet&nbsp;&raquo; pour chacun d&rsquo;eux).<br />
2) Un projet fait travailler de une à plusieurs personnes et une personne peut travailler sur plusieurs projets.</p>
<p>Il faut écrire la phrase en partant d&rsquo;une personne et décrire son association avec les projets (diriger) et compléter la phrase en partant cette fois du projet et décrire l&rsquo;association inverse vers les personnes.</p>
<p><strong>2) Le passage au MCD</strong><br />
Des règles de gestion écrites précédemment, il est très facile d&rsquo;en déduire le MCD :<br />
<strong>personne</strong> -0,n&#8212;-diriger&#8212;-1,1- <strong>projet</strong><br />
|&#8212;&#8212;&#8212;0,n&#8212;-travailler&#8212;-1,n&#8212;|</p>
<p>Comment ai-je fait ?<br />
Examinons la première règle de gestion :<br />
1) Un <strong>projet</strong> <em>est</em> <u>dirigé</u> par <em>une seule</em> <strong>personne</strong> (nommée &laquo;&nbsp;chef de projet&nbsp;&raquo; pour ce projet) et une <strong>personne</strong> <em>peut</em> <u>diriger</u> <em>plusieurs</em> <strong>projets</strong> (en étant nommée &laquo;&nbsp;chef de projet&nbsp;&raquo; pour chacun d&rsquo;eux).</p>
<p>Les termes en gras représentent les entités types du MCD : <strong>personne</strong> et <strong>projet</strong>. Ce sont, dans les règles de gestion, généralement des noms communs qui font ou qui subissent une action.</p>
<p>Les termes soulignés représentent l&rsquo;association : <u>diriger</u>. Ce sont généralement des verbes, le plus souvent conjugués une fois à la forme active ([peut] &laquo;&nbsp;diriger&nbsp;&raquo;, ou bien &laquo;&nbsp;dirige&nbsp;&raquo;) et une fois à la forme passive (&laquo;&nbsp;est dirigé par&nbsp;&raquo;). Dans le MCD, on laissera ce verbe à l&rsquo;infinitif pour pouvoir lire l&rsquo;association dans les deux sens plus facilement.</p>
<p>Les termes en italique sont un guide pour déterminer les cardinalités de l&rsquo;association :<br />
&#8211; &laquo;&nbsp;est dirigé&nbsp;&raquo; indique une obligation, donc une cardinalité minimale de 1 ;<br />
&#8211; &laquo;&nbsp;un seul&nbsp;&raquo; indique une cardinalité maximale de 1 ;<br />
&#8211; &laquo;&nbsp;peut [diriger]&nbsp;&raquo; indique une possibilité, donc aussi la possibilité qu&rsquo;une personne ne dirige aucun projet, soit une cardinalité minimale de 0 ;<br />
&#8211; &laquo;&nbsp;plusieurs&nbsp;&raquo; indique une cardinalité maximale de n.</p>
<p>Examinez la seconde règle de gestion et vous verrez que cela fonctionne de la même manière.</p>
<p>Au bout de quelques exercices de formalisation de règles de gestion de la sorte, vous passerez tellement facilement à la génération du MCD que vous finirez par vous passer de l&rsquo;écriture des règles de gestion et vous contenterez seulement d&rsquo;y penser quand vous dessinerez directement le MCD.</p>
<p><strong>3) Petit exercice</strong><br />
Comment modéliseriez-vous le fait qu&rsquo;un projet est dirigé obligatoirement par une personne ayant le titre de chef de projet et que d&rsquo;autres personnes peuvent travailler sur le projet ?</p>
<p>Écrivez une ou des règles de gestion possibles puis passez au MCD.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Trigger pour incrémentation relative</title>
		<link>https://blog.developpez.com/cinephil/p10269/bases-de-donnees/trigger_pour_incrementation_relative</link>
		<comments>https://blog.developpez.com/cinephil/p10269/bases-de-donnees/trigger_pour_incrementation_relative#comments</comments>
		<pubDate>Thu, 08 Sep 2011 13:18:49 +0000</pubDate>
		<dc:creator><![CDATA[CinePhil]]></dc:creator>
				<category><![CDATA[Bases de données]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Lorsqu&#8217;on pratique l&#8217;identification relative, il est impossible d&#8217;utiliser l&#8217;AUTO_INCREMENT pour numéroter la seconde colonne de la clé primaire relativement à la première qui est une clé étrangère. Par exemple, une chaîne hôtelière pourra avoir, dans sa base de données, une &#8230; <a href="https://blog.developpez.com/cinephil/p10269/bases-de-donnees/trigger_pour_incrementation_relative">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Lorsqu&rsquo;on pratique l&rsquo;identification relative, il est impossible d&rsquo;utiliser l&rsquo;AUTO_INCREMENT pour numéroter la seconde colonne de la clé primaire relativement à la première qui est une clé étrangère. Par exemple, une chaîne hôtelière pourra avoir, dans sa base de données, une table &laquo;&nbsp;Hotel&nbsp;&raquo; et une table &laquo;&nbsp;Chambre&nbsp;&raquo; identifiée relativement à &laquo;&nbsp;Hotel&nbsp;&raquo;. C&rsquo;est à dire que pour chaque identifiant d&rsquo;hôtel dans la table &laquo;&nbsp;Chambre&nbsp;&raquo;, le numéro de la chambre repart de 1.</p>
<p>Je décris ci-après la numérotation automatique des chambres, tout en SQL avec MySQL mais sans doute facilement adaptable dans le langage procédural de n&rsquo;importe quel autre SGBD et pour d&rsquo;autres besoins tels que les lignes de commande, de facture ou de livraison ou (ce qui m&rsquo;a amené à étudier ce sujet) les numéros d&rsquo;exercice d&rsquo;un examen.<br />
<span id="more-6"></span></p>
<p><strong>1. Le modèle de données</strong><br />
MCD :<br />
Hotel -1,n&#8212;-Avoir&#8212;-(1,1)- Chambre</p>
<p><em>Note : les parenthèses autour des cardinalités 1,1 signifient que l&rsquo;entité type Chambre est identifiée relativement à Hotel.</em></p>
<p>Tables :<br />
<strong>Hotel</strong> (<u>htl_id</u>, htl_nom&#8230;)<br />
<strong>Chambre</strong> (<u><em>chb_id_hotel</em>, chb_numero</u>&#8230;)</p>
<p><em>Note : On voit ci-dessus que l&rsquo;identifiant de l&rsquo;hôtel participe à la clé primaire de la chambre.</em></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">-- Table Hotel </span><br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> Hotel &nbsp;<br />
<span style="color: #66cc66;">&#40;</span> <br />
&nbsp; htl_id <span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">,</span> <br />
&nbsp; htl_nom <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">50</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span> <br />
&nbsp; <span style="color: #993333; font-weight: bold;">UNIQUE</span> <span style="color: #66cc66;">&#40;</span>htl_nom<span style="color: #66cc66;">&#41;</span> <br />
<span style="color: #66cc66;">&#41;</span> ENGINE <span style="color: #66cc66;">=</span> InnoDB &nbsp;<br />
<span style="color: #993333; font-weight: bold;">CHARACTER</span> <span style="color: #993333; font-weight: bold;">SET</span> utf8 <span style="color: #993333; font-weight: bold;">COLLATE</span> utf8_general_ci; <br />
&nbsp;<br />
<span style="color: #808080; font-style: italic;">-- Table Chambre </span><br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> Chambre &nbsp;<br />
<span style="color: #66cc66;">&#40;</span> <br />
&nbsp; chb_id_hotel <span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span> <br />
&nbsp; chb_numero <span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span> <br />
&nbsp; <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span> chb_id_hotel <span style="color: #66cc66;">,</span> chb_numero <span style="color: #66cc66;">&#41;</span> <br />
<span style="color: #66cc66;">&#41;</span> ENGINE <span style="color: #66cc66;">=</span> InnoDB &nbsp; <br />
<span style="color: #993333; font-weight: bold;">CHARACTER</span> <span style="color: #993333; font-weight: bold;">SET</span> utf8 <span style="color: #993333; font-weight: bold;">COLLATE</span> utf8_general_ci; <br />
&nbsp;<br />
<span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> Chambre &nbsp;<br />
<span style="color: #993333; font-weight: bold;">ADD</span> <span style="color: #993333; font-weight: bold;">FOREIGN</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span> chb_id_hotel <span style="color: #66cc66;">&#41;</span> &nbsp;<br />
&nbsp; <span style="color: #993333; font-weight: bold;">REFERENCES</span> Hotel <span style="color: #66cc66;">&#40;</span>htl_id<span style="color: #66cc66;">&#41;</span> &nbsp;<br />
&nbsp; <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #993333; font-weight: bold;">DELETE</span> CASCADE ;</div></td></tr></tbody></table></div>
<p><strong>2. Le trigger d&rsquo;incrémentation relative</strong><br />
Je pars du principe que le numéro de la chambre peut être saisi ou non par l&rsquo;utilisateur de l&rsquo;application qui va insérer les nouvelles chambres dans la table. Lorsque le numéro de chambre est laissé vide, c&rsquo;est le SGBD qui doit numéroter automatiquement la chambre en fonction de l&rsquo;identifiant de l&rsquo;hôtel concerné, c&rsquo;est à dire en affectant le plus haut numéro de chambre de cet hôtel déjà présente dans la table + 1 à la colonne chb_numero.</p>
<p>Commençons par insérer quelques hôtels puis quelques chambres avec leur numéro :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> Hotel <span style="color: #66cc66;">&#40;</span>htl_nom<span style="color: #66cc66;">&#41;</span> <br />
<span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Hôtel des flots bleus'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Hôtel de la gare'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Hôtel du parc'</span><span style="color: #66cc66;">&#41;</span>; <br />
&nbsp;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> Chambre <span style="color: #66cc66;">&#40;</span>chb_id_hotel<span style="color: #66cc66;">,</span> chb_numero<span style="color: #66cc66;">&#41;</span> <br />
<span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;</div></td></tr></tbody></table></div>
<p>Nous avons les données suivantes dans la table Chambre :<br />
chb_id_hotel / chb_numero<br />
1 / 1<br />
1 / 2<br />
1 / 3<br />
2 / 1</p>
<p>Voici maintenant le trigger :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">DELIMITER <span style="color: #66cc66;">//</span> <br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> tre_chambre_numero &nbsp;<br />
&nbsp; <span style="color: #993333; font-weight: bold;">BEFORE</span> <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">ON</span> Chambre &nbsp;<br />
&nbsp; <span style="color: #993333; font-weight: bold;">FOR</span> EACH <span style="color: #993333; font-weight: bold;">ROW</span> <br />
<span style="color: #993333; font-weight: bold;">BEGIN</span> <br />
&nbsp; <span style="color: #993333; font-weight: bold;">DECLARE</span> num <span style="color: #993333; font-weight: bold;">INTEGER</span>; <br />
&nbsp; <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NEW</span><span style="color: #66cc66;">.</span>chb_numero <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">NEW</span><span style="color: #66cc66;">.</span>chb_numero <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">THEN</span> <br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">SET</span> num <span style="color: #66cc66;">=</span> &nbsp;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#40;</span>chb_numero<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">FROM</span> Chambre <br />
&nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHERE</span> chb_id_hotel <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">NEW</span><span style="color: #66cc66;">.</span>chb_id_hotel <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#41;</span>; <br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #993333; font-weight: bold;">NEW</span><span style="color: #66cc66;">.</span>chb_numero <span style="color: #66cc66;">=</span> num; <br />
&nbsp; <span style="color: #993333; font-weight: bold;">END</span> <span style="color: #993333; font-weight: bold;">IF</span>; <br />
<span style="color: #993333; font-weight: bold;">END</span><span style="color: #66cc66;">//</span></div></td></tr></tbody></table></div>
<p>Insérons maintenant quelques chambres aux 3 hôtels sans préciser le numéro :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> Chambre <span style="color: #66cc66;">&#40;</span>chb_id_hotel<span style="color: #66cc66;">&#41;</span> <br />
<span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span></div></td></tr></tbody></table></div>
<p>Nous avons maintenant les données suivantes dans la table Chambre :<br />
chb_id_hotel / chb_numero<br />
1 / 1<br />
1 / 2<br />
1 / 3<br />
1 / 4 &#8212; Nouvelle chambre avec le bon numéro<br />
2 / 1<br />
2 / 2 &#8212; Nouvelle chambre avec le bon numéro<br />
3 / 1 &#8212; Nouvelle chambre avec le bon numéro<br />
3 / 2 &#8212; Nouvelle chambre avec le bon numéro</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Autocompletion avec ZendX_JQuery sur une grosse liste de données issues d&#8217;une base de données</title>
		<link>https://blog.developpez.com/cinephil/p9853/php/zend-framework/autocompletion_avec_zendx_jquery_sur_une</link>
		<comments>https://blog.developpez.com/cinephil/p9853/php/zend-framework/autocompletion_avec_zendx_jquery_sur_une#comments</comments>
		<pubDate>Fri, 01 Apr 2011 14:02:36 +0000</pubDate>
		<dc:creator><![CDATA[CinePhil]]></dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Il existe des tutoriels assez bien faits pour insérer dans un formulaire Zend Framework une zone de liste en autocomplétion, en utilisant le composant ZendX_JQuery_Form_Element_Autocomplete, mais ceux-ci sont basés sur une courte liste de données dans un tableau PHP. Ce &#8230; <a href="https://blog.developpez.com/cinephil/p9853/php/zend-framework/autocompletion_avec_zendx_jquery_sur_une">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Il existe des tutoriels assez bien faits pour insérer dans un formulaire Zend Framework une zone de liste en autocomplétion, en utilisant le composant ZendX_JQuery_Form_Element_Autocomplete, mais ceux-ci sont basés sur une courte liste de données dans un tableau PHP.</p>
<p>Ce petit tutoriel vous donne la solution pour avoir la même chose mais en allant chercher parmi une grosse quantité de données issues d&rsquo;une base de données. </p>
<p>Je base cet exemple sur la recherche parmi les 36 682 communes françaises stockées dans une base MySQL mais ça doit être assez facilement adaptable à d&rsquo;autres données.<br />
Le code fourni fonctionne avec Zend Framework 1.11.1, JQuery 1.4.4, jquery-ui-1.8.7.custom.<br />
<span id="more-7"></span></p>
<p><strong>1)</strong>  Il faut, bien entendu, que JQuery soit installé et configuré pour fonctionner avec votre projet !</p>
<p>&#8211; J&rsquo;ai ceci dans le layout (à adapter à votre version de la bibliothèque JQuery et à son emplacement) :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">JQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLocalPath</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseUrl</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/js/jquery/development-bundle/jquery-1.4.4.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">JQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addStyleSheet</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseUrl</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/js/jquery/development-bundle/themes/smoothness/jquery-ui-1.8.7.custom.css'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">JQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setUiLocalPath</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseUrl</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'/js/jquery/development-bundle/ui/jquery-ui-1.8.7.custom.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<br />
&nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">jQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>&#8211; J&rsquo;ai ceci dans le bootstrap :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _initJQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'view'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$view</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'view'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addHelperPath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ZendX/JQuery/View/Helper/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ZendX_JQuery_View_Helper'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$viewRenderer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Controller_Action_Helper_ViewRenderer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$viewRenderer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setView</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$view</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; Zend_Controller_Action_HelperBroker<span style="color: #339933;">::</span><span style="color: #004000;">addHelper</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$viewRenderer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; <span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>2)</strong> Passons au code utile à l&rsquo;autocomplétion en commençant par le modèle et en y créant une fonction qui extrait l&rsquo;identifiant et le nom des communes à partir du début du nom :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getCommunesParDebutNom<span style="color: #009900;">&#40;</span><span style="color: #000088;">$debut</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$debut</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$debut</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'%'</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot; <br />
&nbsp; &nbsp; &nbsp; SELECT cmn_id, cmn_nom &nbsp;<br />
&nbsp; &nbsp; &nbsp; FROM tr_commune_cmn &nbsp;<br />
&nbsp; &nbsp; &nbsp; WHERE cmn_nom LIKE :debut &nbsp;<br />
&nbsp; &nbsp; &quot;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$communestrouvees</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'debut'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$debut</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$communestrouvees</span><span style="color: #339933;">;</span> <br />
&nbsp; <span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>3)</strong> Ensuite, ajoutons d&rsquo;abord le helper d&rsquo;action JQuery Autocomplete dans l&rsquo;initialisation du contrôleur :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Ajout du helper d'action JQuery autoComplete </span><br />
&nbsp; &nbsp; &nbsp; Zend_Controller_Action_HelperBroker<span style="color: #339933;">::</span><span style="color: #004000;">addHelper</span><span style="color: #009900;">&#40;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> ZendX_JQuery_Controller_Action_Helper_AutoComplete<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>4)</strong> Puis, toujours dans le contrôleur, créons une fonction qui va générer la source du champ autocomplete :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> recherchecommunesAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$request</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$debut</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'term'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$commune</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Application_Model_DbTable_Commune<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$commune</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCommunesParDebutNom</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$debut</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000088;">$listecommunes</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$cmn</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$listecommunes</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$cmn</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cmn_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cmn</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cmn_nom'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_helper<span style="color: #339933;">-&gt;</span><span style="color: #004000;">json</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array_values"><span style="color: #990000;">array_values</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$listecommunes</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>=> L&rsquo;action recherchecommunes fait appel à la fonction du modèle.</p>
<p><strong>5)</strong> Passons au formulaire et créons l&rsquo;élément autocomplete :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$baseurl</span> <span style="color: #339933;">=</span> Zend_Controller_Front<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBaseUrl</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Commune </span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// FIXME Ne donne pour le moment que le nom de la commune et pas son identifiant </span><br />
&nbsp; &nbsp; <span style="color: #000088;">$etb_id_commune</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ZendX_JQuery_Form_Element_AutoComplete<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'etb_id_commune'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$etb_id_commune</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLabel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Commune'</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRequired</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFilters</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'StripTags'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setJQueryParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'autoFill'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setJQueryParams</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'source'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$baseurl</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/gereretablissements/recherchecommunes'</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>=> La source de l&rsquo;élément autocomplete est l&rsquo;url de l&rsquo;action recherchecommunes (ici dans le contrôleur gereretablissements).<br />
=> Remarquez aussi le FIXME&#8230; il me reste à peaufiner l&rsquo;utilisation de JQuery ! Ce qui m&rsquo;oblige pour le moment à avoir ce traitement des données postées par l&rsquo;utilisateur dans le contrôleur :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Recherche de l'identifiant de la commune </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// FIXME A revoir quand le JQuery_Autocomplete retournera directement l'id </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$nom_commune</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'etb_id_commune'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$commune</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Application_Model_DbTable_Commune<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$commune</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCommuneParNom</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nom_commune</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'etb_id_commune'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cmn_id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p><strong>6)</strong> Rien de spécial dans la vue :</p>
<p><code class="codecolorer text default"><span class="text">&nbsp; echo $this-&gt;form-&gt;etb_id_commune;</span></code></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Créer un projet Seam pour Tomcat 6 avec Eclipse et les JBoss Tools</title>
		<link>https://blog.developpez.com/cinephil/p9314/bases-de-donnees/creer_un_projet_seam_pour_tomcat_6_avec</link>
		<comments>https://blog.developpez.com/cinephil/p9314/bases-de-donnees/creer_un_projet_seam_pour_tomcat_6_avec#comments</comments>
		<pubDate>Thu, 23 Sep 2010 09:48:11 +0000</pubDate>
		<dc:creator><![CDATA[CinePhil]]></dc:creator>
				<category><![CDATA[Bases de données]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[MISE À JOUR du 20/10/2010 Les mises à jour sont indiquées par les balises [M] et [/M] J&#8217;ai rencontré pas mal de difficultés à utiliser un truc pourtant en apparence tout bête : Créer un nouveau projet Seam configuré pour &#8230; <a href="https://blog.developpez.com/cinephil/p9314/bases-de-donnees/creer_un_projet_seam_pour_tomcat_6_avec">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><strong>MISE À JOUR du 20/10/2010</strong><br />
Les mises à jour sont indiquées par les balises [M] et [/M]</p>
<p>J&rsquo;ai rencontré pas mal de difficultés à utiliser un truc pourtant en apparence tout bête : Créer un nouveau projet Seam configuré pour un serveur Tomcat 6 en utilisant la commande du plugin JBoss Tools pour Eclipse.<br />
Voici le résumé des opérations à effectuer. J&rsquo;en ferai un vrai tutoriel plus tard. Vos remarques et éventuelles erreurs que vous rencontreriez en suivant ces instructions me permettront d&rsquo;améliorer le tutoriel car il est possible que j&rsquo;oublie ici des manipulations que j&rsquo;ai effectuées et pas ou mal notées.<br />
<span id="more-5"></span><br />
<strong>Configuration de l&rsquo;environnement de développement</strong><br />
Voici ce que j&rsquo;ai installé :</p>
<ul>
<li>Eclipse Galileo 3.5.2 ([M]j&rsquo;ai été en échec avec la version Helios au boulot mais j&rsquo;ai réussi à la maison[/M])</li>
<li>Plugins JBoss Tools 3.1 pour Eclipse (j&rsquo;ai installé tout le paquet !)</li>
<li>Tomcat 6.0.29</li>
<li>[M]Jboos-Seam 2.2.0.GA</li>
</ul>
<p>J&rsquo;ai installé le Plugin Sysdeo Tomcat pour Eclipse au boulot mais ça m&rsquo;a posé des problèmes de compatibilité avec la fonction serveur d&rsquo;Eclipse qui s&rsquo;est avérée plus pratique pour lancer les projets Seam. Je n&rsquo;utilise plus Sysdeo.[/M]</p>
<p>Au fil de mes (més)aventures, j&rsquo;ai vu qu&rsquo;il me fallait aussi télécharger <a href="https://javaserverfaces.dev.java.net/download.html">mojarra-1.2-14-FCS-binary.zip</a> à décompresser dans le répertoire java (/usr/share/java sur ma Mandriva Linux 2010.0). [M]Finalement, ça ne semble pas utile car les jars nécessaires (jsf-api.jar et jsf-impl.jar) sont présent dans le répertoire lib de jboss-seam.[/M]</p>
<p><strong>Enchaînement des opérations</strong><br />
Dans Eclipse, utiliser la commande de menu File / New / Seam Web Project.<br />
Dans la fenêtre &laquo;&nbsp;<strong>Seam Web Project</strong>&nbsp;&raquo; :</p>
<ul>
<li>Donnez un nom à votre projet ; j&rsquo;utiliserai ici &laquo;&nbsp;projettest&nbsp;&raquo;.</li>
<li>Dans la liste &laquo;&nbsp;Target runtime&nbsp;&raquo;, choisissez &laquo;&nbsp;Apache Tomcat v6.0&Prime;. S&rsquo;il n&rsquo;est pas encore configuré, vous pouvez l&rsquo;ajouter à l&rsquo;aide du bouton &laquo;&nbsp;New&#8230;&nbsp;&raquo;.</li>
<li>Dans &laquo;&nbsp;Dynamic web module version&nbsp;&raquo;, j&rsquo;ai laissé ce qui s&rsquo;est affiché par défaut : 2.5.</li>
<li>Dans &laquo;&nbsp;Target Server&nbsp;&raquo;, vous choisissez votre serveur Tomcat.</li>
<li>Dans &laquo;&nbsp;Configuration&nbsp;&raquo;, choisissez &laquo;&nbsp;Default configuration for Apache Tomcat v6.0&Prime;. Vous verrez alors apparaître en haut de la fenêtre un message d&rsquo;avertissement indiquant : &laquo;&nbsp;Seam facet must be enabled&nbsp;&raquo;. Et vous n&rsquo;aurez plus accès qu&rsquo;au bouton &laquo;&nbsp;Cancel&nbsp;&raquo;, ce qui vous empêche de continuer à créer le projet. Pas de panique ! Cliquez sur le bouton &laquo;&nbsp;Modify&#8230;&nbsp;&raquo; en face de la liste déroulante de la configuration. Vous arrivez alors dans une fenêtre appelée &laquo;&nbsp;<strong>Project Facets</strong>&laquo;&nbsp;. Cochez &laquo;&nbsp;Java persistence&nbsp;&raquo;, &laquo;&nbsp;JavaServer Faces&nbsp;&raquo; et &laquo;&nbsp;Seam&nbsp;&raquo;, sauvegardez la configuration sous un nouveau nom et cliquez sur OK. Vous revenez alors sur la fenêtre &laquo;&nbsp;Seam Web Project&nbsp;&raquo; sans le message d&rsquo;erreur et vous pouvez maintenant cliquer sur le bouton &laquo;&nbsp;Next >&nbsp;&raquo;.</li>
</ul>
<p>Je n&rsquo;ai rien modifié dans les fenêtres &laquo;&nbsp;<strong>Java</strong>&nbsp;&raquo; et &laquo;&nbsp;<strong>Web Module</strong>&laquo;&nbsp;, successivement affichées par le bouton &laquo;&nbsp;Next >&nbsp;&raquo;.</p>
<p>Sur la fenêtre &laquo;&nbsp;<strong>JPA Facet</strong>&laquo;&nbsp;, [M]choisissez la Platform &laquo;&nbsp;Hibernate&nbsp;&raquo;.<br />
Créez une librairie (que vous pouvez appeler par exemple &laquo;&nbsp;Hibernate&nbsp;&raquo; et importez-y les fichiers hibernate*.jar  + persistence-api.jar de la lib de jboss-seam, puis sélectionnez cette nouvelle librairie. [/M]<br />
La case &laquo;&nbsp;Include libraries with this application&nbsp;&raquo; est cochée.<br />
La Liste déroulante &laquo;&nbsp;Connection&nbsp;&raquo; correspond au choix de la connexion à la base de données. Si vous n&rsquo;en avez défini encore aucune, vous pouvez la créer en cliquant sur le lien &laquo;&nbsp;Add connection&#8230;&nbsp;&raquo;. J&rsquo;ai configuré une base MySQL appelée &laquo;&nbsp;test&nbsp;&raquo;.<br />
J&rsquo;ai coché la case &laquo;&nbsp;Add driver library to build path&nbsp;&raquo; et le driver &laquo;&nbsp;MySQL JDBC Driver&nbsp;&raquo; est apparu dans la liste déroulante.<br />
Dans &laquo;&nbsp;Persistent class management&nbsp;&raquo;, c&rsquo;est l&rsquo;option &laquo;&nbsp;Annotated classes must be listed in persistence.xml&nbsp;&raquo; qui est choisie.<br />
L&rsquo;option &laquo;&nbsp;Create orm.xml&nbsp;&raquo; est cochée [M](Ne semble pas utile)[/m].<br />
Cliquez sur le bouton &laquo;&nbsp;Next >&nbsp;&raquo;.</p>
<p>Dans la fenêtre &laquo;&nbsp;<strong>JSF Capabalities</strong>&laquo;&nbsp;, [M]choisissez le type &laquo;&nbsp;User library&nbsp;&raquo;. Créez une librairie appelée par exemple seam-jsf et importez-y les fichiers jsf-api.jar et jsf-impl.jar puis sélectionnez cette librairie.<br />
L&rsquo;option &laquo;&nbsp;Include libraries with this application&nbsp;&raquo; est cochée. Sous Eclipse Helios, il y a un message d&rsquo;alerte en haut de la fenêtre indiquant qu&rsquo;il peut y avoir une incompatibilité avec le facet choisi.[M]<br />
J&rsquo;ai laissé les zones de saisie tel qu&rsquo;elles ont été remplies par Eclipse.<br />
Cliquez sur le bouton &laquo;&nbsp;Next >&nbsp;&raquo;.</p>
<p>Dans la fenêtre &laquo;&nbsp;<strong>Seam Facet</strong>&laquo;&nbsp;, choisissez le Seam Runtime &laquo;&nbsp;JBoss-seam-2.2.0.GA&nbsp;&raquo; ou ajoutez-le s&rsquo;il n&rsquo;est pas déjà dans la liste. Choisissez l&rsquo;option de déploiement &laquo;&nbsp;WAR&nbsp;&raquo;. Pour la configuration de la Database, j&rsquo;ai choisi &laquo;&nbsp;MySQL5 (InnoDB )&nbsp;&raquo; et j&rsquo;ai coché l&rsquo;option &laquo;&nbsp;DB Tables already exists in database&nbsp;&raquo; puisque j&rsquo;ai créé une table dans la BDD de test. J&rsquo;ai coché l&rsquo;option &laquo;&nbsp;Create test Project&nbsp;&raquo; mais cela ne semble pas obligatoire. Je crois d&rsquo;ailleurs de mémoire qu&rsquo;il faut aussi installer le plugin TestNG pour utiliser le projet de test mais je n&rsquo;en suis pas encore à tester mon projet ! J&rsquo;y reviendrai en temps utile.</p>
<p>Voilà ! On peut cliquer sur le bouton &laquo;&nbsp;Finish&nbsp;&raquo; et laisser Eclipse créer le projet tout seul ! </p>
<p>Jusque là, rien de compliqué, à part la subtilité concernant la configuration par défaut pour Apache à laquelle il manque des facets. Sauf que si vous essayez de démarrer Tomcat et d&rsquo;accéder sur un navigateur à la page d&rsquo;accueil de votre projet, ça ne fonctionnera pas !</p>
<p>On va commencer par ajouter dans le répertoire projettest/WebContent/WEB-INF/lib un paquet de jar pour éviter plus tard une floppée de messages d&rsquo;erreur indiquant que des classes ne sont pas trouvées. [M]J&rsquo;ai essayé de créer une librairie en y mettant tous les jar de la lib de jboss-seam mais j&rsquo;ai eu des messages d&rsquo;erreur lors de la création du projet indiquant qu&rsquo;il y avait plusieurs versions d&rsquo;une classe.[/M] Ces jar sont disponibles dans le répertoire lib de jboss-seam. S&rsquo;il vous en manque, vous pourrez les télécharger en cherchant sur Internet. Copiez les fichiers jars suivant et collez-les, directement à l&rsquo;aide de &laquo;&nbsp;paste&nbsp;&raquo; du menu contextuel d&rsquo;Eclipse, dans le répertoire du projet indiqué plus haut. Voici la <strong>liste des jars nécessaires</strong> pour éviter les messages d&rsquo;erreur à rallonge de Java :</p>
<ul>
<li>antlr.jar</li>
<li>commons-collections.jar</li>
<li>commons-loggin.jar</li>
<li>dom4j.jar</li>
<li>hibernate-annotations.jar</li>
<li>hibernate-commons-annotations.jar</li>
<li>hibernate-core.jar</li>
<li>hibernate-entitymanager.jar</li>
<li>hibernate-validator.jar</li>
<li>javassist.jar</li>
<li>jsf-impl.jar</li>
<li>jsf-api.jar</li>
<li>jta.jar</li>
<li>log4j.jar</li>
<li>lucene-core.jar</li>
<li>persistence-api.jar</li>
<li>slf4j-api.jar</li>
<li>slf4j-log4j12.jar</li>
</ul>
<p>Créer un fichier &laquo;&nbsp;<strong>context.xml</strong>&nbsp;&raquo; dans projettest/WebContent/META-INF. Y insérer le code suivant :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &nbsp; <br />
&lt;Context crossContext=&quot;true&quot; &nbsp; <br />
&nbsp; debug=&quot;5&quot; &nbsp; <br />
&nbsp; docBase=&quot;projettest&quot; &nbsp; <br />
&nbsp; path=&quot;/projettest&quot; &nbsp; <br />
&nbsp; reloadable=&quot;true&quot;&gt; &nbsp; <br />
&nbsp; &lt;Resource auth=&quot;Container&quot; &nbsp; <br />
&nbsp; driverClassName=&quot;com.mysql.jdbc.Driver&quot; &nbsp; <br />
&nbsp; maxActive=&quot;20&quot; &nbsp; <br />
&nbsp; maxIdle=&quot;10&quot; &nbsp; <br />
&nbsp; maxWait=&quot;-1&quot; &nbsp; <br />
&nbsp; name=&quot;jdbc/projettestDatasource&quot; &nbsp; <br />
&nbsp; type=&quot;javax.sql.DataSource&quot; &nbsp; <br />
&nbsp; url=&quot;jdbc:mysql://localhost:3306/test&quot; &nbsp; <br />
&nbsp; username=&quot;votre_utilisateur_mysql&quot; &nbsp; <br />
&nbsp; password=&quot;celui_du_username&quot; /&gt; &nbsp; <br />
&lt;/Context&gt;</div></td></tr></tbody></table></div>
<p>Copier le tag &laquo;&nbsp;Ressource&nbsp;&raquo; ci-dessus dans (répertoire Tomcat)/conf/Catalina/localhost/projettest.xml, à l&rsquo;intérieur du tag &laquo;&nbsp;Context&nbsp;&raquo;. Le fichier projettest.xml doit ressembler à ceci :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;Context path=&quot;/projettest&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; reloadable=&quot;true&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; docBase=&quot;/home/plemenager/workspace/projettest/WebContent&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; workDir=&quot;/home/plemenager/workspace/projettest/work&quot; &gt; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;Logger className=&quot;org.apache.catalina.logger.SystemOutLogger&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; verbosity=&quot;4&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; timestamp=&quot;true&quot;/&gt; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;Resource auth=&quot;Container&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; driverClassName=&quot;com.mysql.jdbc.Driver&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxActive=&quot;20&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxIdle=&quot;10&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxWait=&quot;-1&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name=&quot;jdbc/projettestDatasource&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type=&quot;javax.sql.DataSource&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url=&quot;jdbc:mysql://localhost:3306/test&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; username=&quot;votre_utilisateur_mysql&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; password=&quot;celui_du_username&quot; /&gt; <br />
&lt;/Context&gt;</div></td></tr></tbody></table></div>
<p>Ouvrir le fichier /projettest/src/META-INF/persistence.xml. Dans le tag &laquo;&nbsp;persistence-unit&nbsp;&raquo;, y ajouter le code nécessaire pour que le fichier complet ressemble à ceci :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; <br />
&lt;persistence version=&quot;1.0&quot; &nbsp;<br />
&nbsp; xmlns=&quot;http://java.sun.com/xml/ns/persistence&quot; &nbsp;<br />
&nbsp; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; &nbsp;<br />
&nbsp; xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd&quot; <br />
&gt; <br />
&nbsp; &lt;persistence-unit name=&quot;projettest&quot; transaction-type=&quot;RESOURCE_LOCAL&quot;&gt; <br />
&nbsp; &nbsp; &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt; &nbsp;<br />
&nbsp; &nbsp; &lt;non-jta-data-source&gt;java:comp/env/jdbc/projettestDatasource&lt;/non-jta-data-source&gt; &nbsp;<br />
&nbsp; &nbsp; &lt;properties&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &lt;property name=&quot;hibernate.dialect&quot; value=&quot;org.hibernate.dialect.MySQL5InnoDBDialect&quot; /&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &lt;property name=&quot;hibernate.hbm2ddl.auto&quot; value=&quot;update&quot; /&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &lt;property name=&quot;hibernate.show_sql&quot; value=&quot;true&quot; /&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &lt;property name=&quot;hibernate.format_sql&quot; value=&quot;true&quot; /&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &lt;property name=&quot;hibernate.default_catalog&quot; value=&quot;test&quot;/&gt; <br />
&nbsp; &nbsp; &lt;/properties&gt; &nbsp;<br />
&nbsp; &lt;/persistence-unit&gt; <br />
&lt;/persistence&gt;</div></td></tr></tbody></table></div>
<p>Ouvrez le fichier projettest/WebContent/components.xml. Supprimez les paramètres debug et jndi-pattern du tag &laquo;&nbsp;core:init&nbsp;&raquo; qui ne doit donc plus en contenir.<br />
[M]Ajouter :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">xmlns:transaction=&quot;http://jboss.com/products/seam/transaction&quot; <br />
http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.2.xsd <br />
&lt;transaction:entity-transaction entity-manager=&quot;#{entityManager}&quot;/&gt;</div></td></tr></tbody></table></div>
<p>Le début du fichier doit ressembler à ça :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; <br />
&lt;components xmlns=&quot;http://jboss.com/products/seam/components&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:core=&quot;http://jboss.com/products/seam/core&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:persistence=&quot;http://jboss.com/products/seam/persistence&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:drools=&quot;http://jboss.com/products/seam/drools&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:bpm=&quot;http://jboss.com/products/seam/bpm&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:security=&quot;http://jboss.com/products/seam/security&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:mail=&quot;http://jboss.com/products/seam/mail&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:web=&quot;http://jboss.com/products/seam/web&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:transaction=&quot;http://jboss.com/products/seam/transaction&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xsi:schemaLocation= <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.2.xsd <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.2.xsd <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.2.xsd <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.2.xsd <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.2.xsd <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.2.xsd <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.2.xsd <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.2.xsd <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.2.xsd&quot;&gt; <br />
&nbsp;<br />
&nbsp; &nbsp;&lt;core:init /&gt; <br />
&nbsp;<br />
&nbsp; &nbsp;&lt;core:manager concurrent-request-timeout=&quot;500&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;conversation-timeout=&quot;120000&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;conversation-id-parameter=&quot;cid&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;parent-conversation-id-parameter=&quot;pid&quot;/&gt; <br />
&nbsp;<br />
&nbsp; &nbsp;&lt;transaction:entity-transaction entity-manager=&quot;#{entityManager}&quot;/&gt;</div></td></tr></tbody></table></div>
<p>[/M]</p>
<p>Ouvrez le fichier projettest/WebContent/WEB-INF/pages.xml. Commentez le dernier tag &laquo;&nbsp;exception&nbsp;&raquo; tel que ci-dessous :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;!-- &lt;exception&gt; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;redirect view-id=&quot;/error.xhtml&quot;&gt; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;message severity=&quot;error&quot;&gt;Unexpected error, please try again&lt;/message&gt; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/redirect&gt; <br />
&nbsp; &nbsp; &lt;/exception&gt; --&gt;</div></td></tr></tbody></table></div>
<p>[M]Ouvrir le fichier projettest/WebContent/WEB-INF/web.xml et cliquer sur l&rsquo;onglet Source.<br />
Commenter la partie :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;listener&gt; <br />
&nbsp; &nbsp; &lt;listener-class&gt;com.sun.faces.config.ConfigureListener&lt;/listener-class&gt; <br />
&lt;/listener&gt;</div></td></tr></tbody></table></div>
<p>Copier le fichier jboss-seam-2.2.0.GA/examples/jpa/resources-tomcat/WEB-INF/classes/logj4.xml dans projettest/WebContent/WEB-INF/classes/<br />
[/M]</p>
<p>Si vous avez correctement fait tout cela, et si je n&rsquo;ai rien oublié, vous pouvez maintenant démarrer Tomcat. Le seul problème restant à résoudre est un couple de WARN concernant log4j.</p>
<p>Allez dans votre navigateur préféré et lancez votre application, via le Tomcat Manager ou par une URL du type http://localhost:8080/projettest. Vous devriez alors voir apparaître un superbe : &laquo;&nbsp;<strong>Welcome to Seam!</strong>&laquo;&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
