Commit 56d4d6063ceb3322d952edf48f645bcdf525c951
0 parents
init projet
Showing
21 changed files
with
715 additions
and
0 deletions
Show diff stats
1 | +++ a/demoCoursAL/.classpath | ||
@@ -0,0 +1,8 @@ | @@ -0,0 +1,8 @@ | ||
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<classpath> | ||
3 | + <classpathentry kind="src" path="src"/> | ||
4 | + <classpathentry kind="lib" path="/home/opt/wildfly-10.1.0.Final/modules/system/layers/base/javax/persistence/api/main/hibernate-jpa-2.1-api-1.0.0.Final.jar"/> | ||
5 | + <classpathentry kind="lib" path="/home/opt/wildfly-10.1.0.Final/modules/system/layers/base/javax/ejb/api/main/jboss-ejb-api_3.2_spec-1.0.0.Final.jar"/> | ||
6 | + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
7 | + <classpathentry kind="output" path="bin"/> | ||
8 | +</classpath> |
1 | +++ a/demoCoursAL/.project | ||
@@ -0,0 +1,17 @@ | @@ -0,0 +1,17 @@ | ||
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<projectDescription> | ||
3 | + <name>demoCoursAL</name> | ||
4 | + <comment></comment> | ||
5 | + <projects> | ||
6 | + </projects> | ||
7 | + <buildSpec> | ||
8 | + <buildCommand> | ||
9 | + <name>org.eclipse.jdt.core.javabuilder</name> | ||
10 | + <arguments> | ||
11 | + </arguments> | ||
12 | + </buildCommand> | ||
13 | + </buildSpec> | ||
14 | + <natures> | ||
15 | + <nature>org.eclipse.jdt.core.javanature</nature> | ||
16 | + </natures> | ||
17 | +</projectDescription> |
1 | +++ a/demoCoursAL/.settings/org.eclipse.jdt.core.prefs | ||
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +eclipse.preferences.version=1 | ||
2 | +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
3 | +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
4 | +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
5 | +org.eclipse.jdt.core.compiler.compliance=1.7 | ||
6 | +org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
7 | +org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
8 | +org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
9 | +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
10 | +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
11 | +org.eclipse.jdt.core.compiler.source=1.7 |
1 | +++ a/demoCoursAL/build.xml | ||
@@ -0,0 +1,196 @@ | @@ -0,0 +1,196 @@ | ||
1 | +<?xml version="1.0"?> | ||
2 | +<project name="demoCoursAL" default="ear" basedir="."> | ||
3 | + <!-- Declarations proprietes et classpath --> | ||
4 | + <!-- LIGNES SUIVANTES A MODIFIER : --> | ||
5 | + <property name="jboss.dir" value="/home/opt/wildfly10" /> | ||
6 | + <!-- FIN LIGNES A MODIFIER : --> | ||
7 | + <property name="jboss.lib.dir" value="${jboss.dir}/lib" /> | ||
8 | + <property name="src.dir" value="${basedir}/src" /> | ||
9 | + <property name="build.dir" value="build" /> | ||
10 | + <property name="name" value="appliBanque" /> | ||
11 | + <!-- The build classpath --> | ||
12 | + <path id="build.classpath"> | ||
13 | + <pathelement location="${basedir}"/> | ||
14 | + <fileset dir="${jboss.dir}/modules/system/layers/base/org/hibernate/main"> | ||
15 | + <include name="hibernate-core-5.0.10.Final.jar"/> | ||
16 | + </fileset> | ||
17 | + <fileset dir="${jboss.dir}/modules/system/layers/base/javax/persistence/api/main"> | ||
18 | + <include name="hibernate-jpa-2.1-api-1.0.0.Final.jar"/> | ||
19 | + </fileset> | ||
20 | + <fileset dir="${jboss.dir}/bin/client"> | ||
21 | + <include name="*.jar"/> | ||
22 | + </fileset> | ||
23 | + <fileset dir="${jboss.dir}/modules/system/layers/base/javax/ejb/api/main"> | ||
24 | + <include name="jboss-ejb-api_3.2_spec-1.0.0.Final.jar"/> | ||
25 | + </fileset> | ||
26 | + <pathelement location="${build.dir}/sessions"/> | ||
27 | + <pathelement location="${build.dir}/entites" /> | ||
28 | + <pathelement location="${build.dir}/classes"/> | ||
29 | + </path> | ||
30 | + | ||
31 | + <!-- Prepare --> | ||
32 | + <target name="prepare" > | ||
33 | + <mkdir dir="${build.dir}" /> | ||
34 | + <mkdir dir="${build.dir}/docs" /> | ||
35 | + <mkdir dir="${build.dir}/sessions" /> | ||
36 | + <mkdir dir="${build.dir}/entites" /> | ||
37 | + <mkdir dir="${build.dir}/jars" /> | ||
38 | + <mkdir dir="${build.dir}/web" /> | ||
39 | + <mkdir dir="${build.dir}/web/WEB-INF" /> | ||
40 | + </target> | ||
41 | + | ||
42 | + <!-- Compile sessions--> | ||
43 | + <target name="compile-sessions" depends="prepare"> | ||
44 | + <javac destdir="${build.dir}/sessions" | ||
45 | + classpathref="build.classpath" > | ||
46 | + <src path="${src.dir}/ejb/sessions" /> | ||
47 | + </javac> | ||
48 | + </target> | ||
49 | + | ||
50 | + <!-- Create sessions file --> | ||
51 | + <target name="package-sessions" depends="compile-sessions"> | ||
52 | + <jar jarfile="${build.dir}/jars/${name}Sessions.jar" | ||
53 | + basedir="${build.dir}/sessions" > | ||
54 | + </jar> | ||
55 | + </target> | ||
56 | + <!-- Compile entites--> | ||
57 | + <target name="compile-entites" depends="prepare"> | ||
58 | + <javac destdir="${build.dir}/entites" | ||
59 | + classpathref="build.classpath" > | ||
60 | + <src path="${src.dir}/ejb/entites" /> | ||
61 | + </javac> | ||
62 | + </target> | ||
63 | + | ||
64 | + <!-- Create entites-jar file --> | ||
65 | + <target name="package-entites" depends="compile-entites"> | ||
66 | + <schemavalidate file="${src.dir}/ejb/entites/persistence.xml" /> | ||
67 | + <jar jarfile="${build.dir}/jars/${name}Entites.jar" | ||
68 | + basedir="${build.dir}/entites" > | ||
69 | + <metainf dir="${src.dir}/ejb/entites"> | ||
70 | + <include name="persistence.xml"/> | ||
71 | + </metainf> | ||
72 | + </jar> | ||
73 | + </target> | ||
74 | + | ||
75 | + <target name="war" depends="prepare"> | ||
76 | + <!-- <xmlvalidate file="${src.dir}/web/web.xml"/> --> | ||
77 | + <copy file="${src.dir}/web/web.xml" todir="${build.dir}/web/WEB-INF" /> | ||
78 | + <copy todir="${build.dir}/web"> | ||
79 | + <fileset dir="${src.dir}/web" includes="*" excludes="*.xml" /> | ||
80 | + </copy> | ||
81 | + <jar | ||
82 | + basedir="${build.dir}/web/" | ||
83 | + destfile="${build.dir}/jars/${name}.war" > | ||
84 | + </jar> | ||
85 | + </target> | ||
86 | + | ||
87 | + <target name="earSession" depends="package-sessions"> | ||
88 | + <schemavalidate file="${src.dir}/application.xml"/> | ||
89 | + <ear destfile="${build.dir}/jars/${name}.ear" | ||
90 | + appxml="${src.dir}/application.xml"> | ||
91 | + <fileset dir="${build.dir}/jars" excludes="*.ear,*.war" /> | ||
92 | + </ear> | ||
93 | + </target> | ||
94 | + | ||
95 | + <target name="earSessionWeb" depends="package-sessions, war"> | ||
96 | + <schemavalidate file="${src.dir}/application.xml"/> | ||
97 | + <ear destfile="${build.dir}/jars/${name}.ear" | ||
98 | + appxml="${src.dir}/application.xml"> | ||
99 | + <fileset dir="${build.dir}/jars" excludes="*.ear" /> | ||
100 | + </ear> | ||
101 | + </target> | ||
102 | + | ||
103 | + <target name="earEntite" depends="package-entites"> | ||
104 | + <schemavalidate file="${src.dir}/application.xml"/> | ||
105 | + <ear destfile="${build.dir}/jars/${name}.ear" | ||
106 | + appxml="${src.dir}/application.xml"> | ||
107 | + <fileset dir="${build.dir}/jars" excludes="*.ear,*.war" /> | ||
108 | + </ear> | ||
109 | + </target> | ||
110 | + | ||
111 | + <target name="earEntiteEtSession" depends="package-entites,package-sessions"> | ||
112 | + <schemavalidate file="${src.dir}/application.xml"/> | ||
113 | + <ear destfile="${build.dir}/jars/${name}.ear" | ||
114 | + appxml="${src.dir}/application.xml"> | ||
115 | + <fileset dir="${build.dir}/jars" excludes="*.ear,*.war" /> | ||
116 | + </ear> | ||
117 | + </target> | ||
118 | + | ||
119 | + | ||
120 | + <target name="ear" depends="package-entites,package-sessions, war"> | ||
121 | + <schemavalidate file="${src.dir}/application.xml"/> | ||
122 | + <ear destfile="${build.dir}/jars/${name}.ear" | ||
123 | + appxml="${src.dir}/application.xml"> | ||
124 | + <fileset dir="${build.dir}/jars" excludes="*.ear" /> | ||
125 | + </ear> | ||
126 | + </target> | ||
127 | + | ||
128 | + <target name="deploy"> | ||
129 | + <copy file="${build.dir}/jars/${name}.ear" | ||
130 | + todir="${jboss.dir}/standalone/deployments" /> | ||
131 | + </target> | ||
132 | + | ||
133 | + <target name="deployEntite" depends="earEntite, deploy" /> | ||
134 | + | ||
135 | + <target name="deployEntiteEtSession" depends="earEntiteEtSession, deploy" /> | ||
136 | + | ||
137 | + <target name="deploySession" depends="earSession, deploy" /> | ||
138 | + | ||
139 | + <target name="deploySessionWeb" depends="earSessionWeb, deploy" /> | ||
140 | + | ||
141 | + <target name="deployAll" depends="ear, deploy" /> | ||
142 | + | ||
143 | + <target name="undeploy"> | ||
144 | + <delete> | ||
145 | + <fileset dir="${jboss.dir}/standalone/deployments"> | ||
146 | + <filename name="${name}.*" /> | ||
147 | + </fileset> | ||
148 | + </delete> | ||
149 | + | ||
150 | + </target> | ||
151 | + | ||
152 | + <target name="javadoc" depends="compile-sessions"> | ||
153 | + <javadoc packagenames="*" | ||
154 | + sourcepath="src/ejb/sessions" | ||
155 | + classpathref="build.classpath" | ||
156 | + destdir="build/docs" | ||
157 | + author="true" | ||
158 | + private="true" | ||
159 | + windowtitle="${name} api" > | ||
160 | + </javadoc> | ||
161 | + </target> | ||
162 | + | ||
163 | + | ||
164 | + <!-- Clean everything --> | ||
165 | + <target name="clean" depends="undeploy"> | ||
166 | + <delete dir="${build.dir}" /> | ||
167 | + </target> | ||
168 | + | ||
169 | + <!-- compilation, execution programme client --> | ||
170 | + <target name="init-client" depends="prepare"> | ||
171 | + <property name="classes.dir" value="${build.dir}/classes" /> | ||
172 | + <mkdir dir="${classes.dir}" /> | ||
173 | + | ||
174 | + </target> | ||
175 | + | ||
176 | + | ||
177 | + <target name="compile-client" depends="init-client"> | ||
178 | + | ||
179 | + <javac srcdir="${src.dir}/client" | ||
180 | + destdir="${classes.dir}"> | ||
181 | + <classpath refid="build.classpath" /> | ||
182 | + </javac> | ||
183 | + </target> | ||
184 | + | ||
185 | + <target name="run-client" depends="compile-client"> | ||
186 | + <java classname="client.Main" fork="yes" dir="." > | ||
187 | + <classpath refid="build.classpath" /> | ||
188 | + </java> | ||
189 | + </target> | ||
190 | + | ||
191 | + <target name="clean-client" depends="init-client"> | ||
192 | + <delete dir="${build.dir}/classes" /> | ||
193 | + </target> | ||
194 | + | ||
195 | +</project> | ||
196 | + |
1 | +++ a/demoCoursAL/jboss-ejb-client.properties | ||
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +endpoint.name=client-endpoint | ||
2 | +remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false | ||
3 | + | ||
4 | +remote.connections=default | ||
5 | + | ||
6 | +remote.connection.default.host=localhost | ||
7 | +remote.connection.default.port = 8080 | ||
8 | +remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false | ||
9 | + |
1 | +++ a/demoCoursAL/src/Reflection.java | ||
@@ -0,0 +1,52 @@ | @@ -0,0 +1,52 @@ | ||
1 | +import java.lang.reflect.* ; | ||
2 | +import java.beans.Beans ; | ||
3 | +import java.util.ArrayList ; | ||
4 | + | ||
5 | +public class Reflection { | ||
6 | + | ||
7 | + @SuppressWarnings("rawtypes") | ||
8 | + public static void main(String args[]) { | ||
9 | + ArrayList<Method> propBool=new ArrayList<Method>() ; | ||
10 | + Class[] paramType= new Class[] { Boolean.TYPE }; | ||
11 | + try { | ||
12 | + Object obj = Beans.instantiate(null,args[0]) ; | ||
13 | + Class laClasse = obj.getClass() ; | ||
14 | + for (Method m : laClasse.getMethods()) { | ||
15 | + if (m.getName().startsWith("is") && | ||
16 | + m.getParameterTypes().length==0 && | ||
17 | + m.getReturnType().toString().equals("boolean")) { | ||
18 | + System.out.println("getter method found : "+m.getName()) ; | ||
19 | + String setName="set"+m.getName().substring(2) ; | ||
20 | + try { | ||
21 | + Method methodeSet=laClasse.getMethod(setName,paramType) ; | ||
22 | + propBool.add(methodeSet) ; | ||
23 | + String propertyName = setName.substring(0,1).toLowerCase() + setName.substring(1); | ||
24 | + System.out.println("boolean property found : "+propertyName) ; | ||
25 | + } catch(NoSuchMethodException e1) { | ||
26 | + System.out.println("No corresponding setter method found : "+setName) ; | ||
27 | + } | ||
28 | + } | ||
29 | + } | ||
30 | + Object param[] =new Boolean[1] ; | ||
31 | + param[0]=new Boolean(true) ; | ||
32 | + for (Method m : propBool) { | ||
33 | + System.out.println("invoke method "+m.getName()+" with true parameter") ; | ||
34 | + m.invoke(obj,param) ; | ||
35 | + } | ||
36 | + } catch (ArrayIndexOutOfBoundsException e) { | ||
37 | + System.err.println("Erreur : java Reflection class name") ; | ||
38 | + } catch (SecurityException e) { | ||
39 | + System.err.println("exception raised...") ; | ||
40 | + } catch(IllegalAccessException e) { | ||
41 | + System.err.println("Access...") ; | ||
42 | + } catch(InvocationTargetException e) { | ||
43 | + System.err.println("Argument...") ; | ||
44 | + } catch(IllegalArgumentException e) { | ||
45 | + System.err.println("Argument...") ; | ||
46 | + } catch(java.io.IOException e) { | ||
47 | + System.err.println("IO...") ; | ||
48 | + } catch(ClassNotFoundException e) { | ||
49 | + System.err.println("class...") ; | ||
50 | + } | ||
51 | + } | ||
52 | +} |
1 | +++ a/demoCoursAL/src/application.xml | ||
@@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<application xmlns="http://java.sun.com/xml/ns/javaee" | ||
3 | +xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="6" | ||
4 | +xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd"> | ||
5 | + | ||
6 | + <display-name>Appli Banque</display-name> | ||
7 | + | ||
8 | + <module> | ||
9 | + <ejb>appliBanqueSessions.jar</ejb> | ||
10 | + </module> | ||
11 | + <module> | ||
12 | + <ejb>appliBanqueEntites.jar</ejb> | ||
13 | + </module> | ||
14 | +</application> | ||
15 | + |
1 | +++ a/demoCoursAL/src/client/Main.java | ||
@@ -0,0 +1,58 @@ | @@ -0,0 +1,58 @@ | ||
1 | +package client ; | ||
2 | + | ||
3 | + | ||
4 | + | ||
5 | +import javax.naming.InitialContext; | ||
6 | +import javax.naming.NamingException ; | ||
7 | + | ||
8 | +import ejb.sessions.* ; | ||
9 | +import ejb.entites.* ; | ||
10 | + | ||
11 | +public class Main { | ||
12 | + | ||
13 | + public static void main(String[] args) { | ||
14 | + try { | ||
15 | + InitialContext ctx = new InitialContext(); | ||
16 | + System.out.println("Accès au service distant") ; | ||
17 | + Object obj = ctx.lookup("ejb:appliBanque/appliBanqueSessions//ServiceBanqueBean!ejb.sessions.ServiceBanque"); | ||
18 | + | ||
19 | + ServiceBanque service = (ServiceBanque) obj ; | ||
20 | + service.addCompte(1, "Olivier", 2000.0); | ||
21 | + service.addCompte(2, "Paul", 300.0) ; | ||
22 | + service.addAction("nintendo",46.5) ; | ||
23 | + service.addAction("sega", 12.0) ; | ||
24 | + System.out.println("achat de 10 actions sega") ; | ||
25 | + service.acheteActions(1, "sega", 10); | ||
26 | + System.out.println("achat de 3 actions nintendo") ; | ||
27 | + service.acheteActions(1, "nintendo", 3); | ||
28 | + System.out.println("Actions de Olivier:") ; | ||
29 | + for (LigneAction la : service.getActionsAchetees(1)) | ||
30 | + System.out.println(la.getNombre()+" action(s) "+la.getAction().getNom() | ||
31 | + +" au taux de "+la.getAction().getTaux()) ; | ||
32 | + System.out.println("vente de 2 actions sega") ; | ||
33 | + service.vendActions(1, "sega", 2); | ||
34 | + System.out.println("Actions de Olivier:") ; | ||
35 | + for (LigneAction la : service.getActionsAchetees(1)) | ||
36 | + System.out.println(la.getNombre()+" action(s) "+la.getAction().getNom() | ||
37 | + +" au taux de "+la.getAction().getTaux()) ; | ||
38 | + System.out.println("vente de 8 actions sega") ; | ||
39 | + service.vendActions(1, "sega", 8); | ||
40 | + System.out.println("Actions de Olivier:") ; | ||
41 | + for (LigneAction la : service.getActionsAchetees(1)) | ||
42 | + System.out.println(la.getNombre()+" action(s) "+la.getAction().getNom() | ||
43 | + +" au taux de "+la.getAction().getTaux()) ; | ||
44 | + } catch(CompteInconnuException e) { | ||
45 | + System.err.println("Compte inconnu") ; | ||
46 | + } catch (NamingException e1) { | ||
47 | + System.err.println("erreur accès service") ; | ||
48 | + } catch (ActionInconnueException e) { | ||
49 | + System.err.println("Action inconnue") ; | ||
50 | + } catch (ApprovisionnementException e) { | ||
51 | + System.err.println("pb approvisionnement") ; | ||
52 | + } catch (CompteDejaExistantException e) { | ||
53 | + System.err.println("Compte existe") ; | ||
54 | + } catch (ActionDejaExistanteException e) { | ||
55 | + System.err.println("Action existe") ; | ||
56 | + } | ||
57 | + } | ||
58 | +} | ||
0 | \ No newline at end of file | 59 | \ No newline at end of file |
1 | +++ a/demoCoursAL/src/ejb/entites/Action.java | ||
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +package ejb.entites; | ||
2 | + | ||
3 | +import javax.persistence.Entity; | ||
4 | +import javax.persistence.Id; | ||
5 | + | ||
6 | +@Entity | ||
7 | +public class Action implements java.io.Serializable { | ||
8 | + private static final long serialVersionUID = 1L; | ||
9 | + | ||
10 | + public Action() {} | ||
11 | + | ||
12 | + @Id private String nom ; | ||
13 | + private double taux ; | ||
14 | + | ||
15 | + public String getNom() { return nom; } | ||
16 | + public void setNom(String nom) { | ||
17 | + this.nom = nom; | ||
18 | + } | ||
19 | + | ||
20 | + public double getTaux() { return taux; } | ||
21 | + public void setTaux(double taux) { | ||
22 | + this.taux = taux; | ||
23 | + } | ||
24 | + | ||
25 | + | ||
26 | +} |
1 | +++ a/demoCoursAL/src/ejb/entites/Compte.java | ||
@@ -0,0 +1,62 @@ | @@ -0,0 +1,62 @@ | ||
1 | +package ejb.entites; | ||
2 | + | ||
3 | +import java.io.Serializable ; | ||
4 | +import java.util.Set; | ||
5 | + | ||
6 | +import javax.persistence.Entity; | ||
7 | +import javax.persistence.FetchType; | ||
8 | +import javax.persistence.Id; | ||
9 | +import javax.persistence.OneToMany; | ||
10 | + | ||
11 | +@Entity | ||
12 | +public class Compte implements Serializable { | ||
13 | + | ||
14 | + @Id private int numero ; | ||
15 | + private double solde ; | ||
16 | + private String titulaire ; | ||
17 | + @OneToMany(mappedBy="proprietaire", fetch=FetchType.EAGER) | ||
18 | + private Set<LigneAction> lignesactions ; | ||
19 | + | ||
20 | + | ||
21 | + | ||
22 | + public int getNumero() { return numero; } | ||
23 | + | ||
24 | + public void setNumero(int numero) { | ||
25 | + this.numero = numero; | ||
26 | + } | ||
27 | + | ||
28 | + public double getSolde() { | ||
29 | + return solde; | ||
30 | + } | ||
31 | + | ||
32 | + public void setSolde(double solde) { | ||
33 | + this.solde = solde; | ||
34 | + } | ||
35 | + | ||
36 | + public String getTitulaire() { | ||
37 | + return titulaire; | ||
38 | + } | ||
39 | + | ||
40 | + public void setTitulaire(String titulaire) { | ||
41 | + this.titulaire = titulaire; | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * | ||
46 | + */ | ||
47 | + private static final long serialVersionUID = 1L; | ||
48 | + | ||
49 | + public Compte() {} | ||
50 | + | ||
51 | + public Set<LigneAction> getLignesactions() { | ||
52 | + return lignesactions; | ||
53 | + } | ||
54 | + | ||
55 | + public void setLignesactions(Set<LigneAction> lignesactions) { | ||
56 | + this.lignesactions = lignesactions; | ||
57 | + } | ||
58 | + | ||
59 | + | ||
60 | + | ||
61 | + | ||
62 | +} |
1 | +++ a/demoCoursAL/src/ejb/entites/LigneAction.java | ||
@@ -0,0 +1,45 @@ | @@ -0,0 +1,45 @@ | ||
1 | +package ejb.entites; | ||
2 | + | ||
3 | +import javax.persistence.Entity; | ||
4 | +import javax.persistence.FetchType; | ||
5 | +import javax.persistence.GeneratedValue; | ||
6 | +import javax.persistence.Id; | ||
7 | +import javax.persistence.ManyToOne; | ||
8 | +import javax.persistence.Table; | ||
9 | + | ||
10 | + | ||
11 | +@Table (name="t_ligne_action") @Entity | ||
12 | +public class LigneAction implements java.io.Serializable { | ||
13 | + private static final long serialVersionUID = 1L; | ||
14 | + | ||
15 | + public LigneAction() {} | ||
16 | + | ||
17 | + @Id @GeneratedValue private int id ; | ||
18 | + private int nombre ; | ||
19 | + @ManyToOne private Compte proprietaire ; | ||
20 | + @ManyToOne(fetch=FetchType.EAGER) private Action action ; | ||
21 | + | ||
22 | + | ||
23 | + public int getId() { return id; } | ||
24 | + public void setId(int id) { this.id = id; } | ||
25 | + | ||
26 | + public int getNombre() { return nombre; } | ||
27 | + public void setNombre(int nombre) { | ||
28 | + this.nombre = nombre; | ||
29 | + } | ||
30 | + | ||
31 | + public Compte getProprietaire() { | ||
32 | + return proprietaire; | ||
33 | + } | ||
34 | + public void setProprietaire(Compte proprietaire) { | ||
35 | + this.proprietaire = proprietaire; | ||
36 | + } | ||
37 | + | ||
38 | + public Action getAction() { | ||
39 | + return action; | ||
40 | + } | ||
41 | + public void setAction(Action action) { | ||
42 | + this.action = action; | ||
43 | + } | ||
44 | + | ||
45 | +} |
1 | +++ a/demoCoursAL/src/ejb/entites/persistence.xml | ||
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> | ||
3 | + <persistence-unit name="appliBanque"> | ||
4 | + <jta-data-source>java:/PostgresDS</jta-data-source> | ||
5 | + <properties> | ||
6 | + <property name="hibernate.hbm2ddl.auto" | ||
7 | + value="create-drop"/> | ||
8 | + </properties> | ||
9 | + </persistence-unit> | ||
10 | +</persistence> | ||
11 | + | ||
12 | + |
demoCoursAL/src/ejb/sessions/ActionDejaExistanteException.java
0 → 100644
demoCoursAL/src/ejb/sessions/ActionInconnueException.java
0 → 100644
demoCoursAL/src/ejb/sessions/ApprovisionnementException.java
0 → 100644
demoCoursAL/src/ejb/sessions/CompteDejaExistantException.java
0 → 100644
demoCoursAL/src/ejb/sessions/CompteInconnuException.java
0 → 100644
1 | +++ a/demoCoursAL/src/ejb/sessions/ServiceBanque.java | ||
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +package ejb.sessions; | ||
2 | + | ||
3 | +import ejb.entites.LigneAction ; | ||
4 | + | ||
5 | +@javax.ejb.Remote | ||
6 | +public interface ServiceBanque { | ||
7 | + public void addCompte(int numeroCompte, String nomTitulaire, double soldeDepart) | ||
8 | + throws CompteDejaExistantException ; | ||
9 | + public void addAction(String nomAction, double taux) | ||
10 | + throws ActionDejaExistanteException ; | ||
11 | + public void crediterCompte(int numeroCompte, double montant) | ||
12 | + throws CompteInconnuException ; | ||
13 | + public void debiterCompte(int numeroCompte, double montant) | ||
14 | + throws CompteInconnuException ; | ||
15 | + public void virementVers(int numCompteDebit, int numCompteCredit, double montant) | ||
16 | + throws CompteInconnuException,ApprovisionnementException ; | ||
17 | + public void acheteActions(int numeroCompte, String nomAction, int nb) | ||
18 | + throws CompteInconnuException, ActionInconnueException, ApprovisionnementException ; | ||
19 | + public void vendActions(int numeroCompte, String nomAction, int nb) | ||
20 | + throws CompteInconnuException, ActionInconnueException, ApprovisionnementException ; | ||
21 | + public java.util.Set<LigneAction> getActionsAchetees(int numeroCompte) | ||
22 | + throws CompteInconnuException ; | ||
23 | +} |
demoCoursAL/src/ejb/sessions/ServiceBanqueBean.java
0 → 100644
1 | +++ a/demoCoursAL/src/ejb/sessions/ServiceBanqueBean.java | ||
@@ -0,0 +1,128 @@ | @@ -0,0 +1,128 @@ | ||
1 | +package ejb.sessions; | ||
2 | + | ||
3 | +import java.util.Set; | ||
4 | + | ||
5 | +import javax.persistence.EntityManager; | ||
6 | +import javax.persistence.PersistenceContext; | ||
7 | + | ||
8 | +import ejb.entites.Action; | ||
9 | +import ejb.entites.Compte; | ||
10 | +import ejb.entites.LigneAction; | ||
11 | + | ||
12 | +@javax.ejb.Stateless | ||
13 | +public class ServiceBanqueBean implements ServiceBanque { | ||
14 | + @PersistenceContext(unitName="appliBanque") protected EntityManager em ; | ||
15 | + @Override | ||
16 | + public void addCompte(int numeroCompte, String nomTitulaire, double soldeDepart) | ||
17 | + throws CompteDejaExistantException { | ||
18 | + try { | ||
19 | + this.getCompte(numeroCompte) ; | ||
20 | + throw new CompteDejaExistantException() ; | ||
21 | + } catch(CompteInconnuException e) { | ||
22 | + Compte c=new Compte() ; | ||
23 | + c.setNumero(numeroCompte); c.setSolde(soldeDepart); | ||
24 | + c.setTitulaire(nomTitulaire); | ||
25 | + em.persist(c); | ||
26 | + } | ||
27 | + } | ||
28 | + | ||
29 | + @Override | ||
30 | + public void addAction(String nomAction, double taux) | ||
31 | + throws ActionDejaExistanteException { | ||
32 | + try { | ||
33 | + this.getAction(nomAction) ; | ||
34 | + throw new ActionDejaExistanteException() ; | ||
35 | + } catch(ActionInconnueException e) { | ||
36 | + Action a=new Action() ; | ||
37 | + a.setNom(nomAction); a.setTaux(taux); | ||
38 | + em.persist(a); | ||
39 | + } | ||
40 | + | ||
41 | + } | ||
42 | + | ||
43 | + private Action getAction(String nomAction) throws ActionInconnueException { | ||
44 | + Action a= (Action) em.find(Action.class, nomAction) ; | ||
45 | + if (a==null) throw new ActionInconnueException() ; | ||
46 | + return a ; | ||
47 | + } | ||
48 | + | ||
49 | + @Override | ||
50 | + public void crediterCompte(int numeroCompte, double montant) | ||
51 | + throws CompteInconnuException { | ||
52 | + Compte c = this.getCompte(numeroCompte) ; | ||
53 | + c.setSolde(c.getSolde()+montant); | ||
54 | + } | ||
55 | + | ||
56 | + @Override | ||
57 | + public void debiterCompte(int numeroCompte, double montant) | ||
58 | + throws CompteInconnuException { | ||
59 | + Compte c = this.getCompte(numeroCompte) ; | ||
60 | + c.setSolde(c.getSolde()-montant); | ||
61 | + | ||
62 | + } | ||
63 | + | ||
64 | + @Override | ||
65 | + public void virementVers(int numCompteDebit, int numCompteCredit, | ||
66 | + double montant) throws CompteInconnuException, | ||
67 | + ApprovisionnementException { | ||
68 | + | ||
69 | + | ||
70 | + } | ||
71 | + | ||
72 | + @Override | ||
73 | + public void acheteActions(int numeroCompte, String nomAction, int nb) | ||
74 | + throws CompteInconnuException, ActionInconnueException, | ||
75 | + ApprovisionnementException { | ||
76 | + Compte c = this.getCompte(numeroCompte) ; | ||
77 | + Action a = this.getAction(nomAction) ; | ||
78 | + if (c.getSolde()< nb*a.getTaux()) | ||
79 | + throw new ApprovisionnementException() ; | ||
80 | + else | ||
81 | + c.setSolde(c.getSolde()-nb*a.getTaux()) ; | ||
82 | + boolean trouve=false ; | ||
83 | + for (LigneAction la : c.getLignesactions()) | ||
84 | + if (la.getAction().getNom().equals(nomAction)) { | ||
85 | + trouve=true ; la.setNombre(la.getNombre()+nb); | ||
86 | + } | ||
87 | + if (!trouve) { | ||
88 | + LigneAction la = new LigneAction() ; | ||
89 | + la.setAction(a); la.setProprietaire(c) ; la.setNombre(nb); | ||
90 | + em.persist(la); | ||
91 | + } | ||
92 | + } | ||
93 | + | ||
94 | + @Override | ||
95 | + public void vendActions(int numeroCompte, String nomAction, int nb) | ||
96 | + throws CompteInconnuException, ActionInconnueException, | ||
97 | + ApprovisionnementException { | ||
98 | + Compte c = this.getCompte(numeroCompte) ; | ||
99 | + LigneAction la=null ; | ||
100 | + for (LigneAction vla : c.getLignesactions()) | ||
101 | + if (vla.getAction().getNom().equals(nomAction)) { | ||
102 | + la=vla ; | ||
103 | + } | ||
104 | + if (la != null) { | ||
105 | + if (nb > la.getNombre()) | ||
106 | + throw new ApprovisionnementException() ; | ||
107 | + else { | ||
108 | + c.setSolde(c.getSolde()+nb*la.getAction().getTaux()); | ||
109 | + la.setNombre(la.getNombre()-nb) ; | ||
110 | + if (la.getNombre()==0) em.remove(la); | ||
111 | + } | ||
112 | + } | ||
113 | + } | ||
114 | + | ||
115 | + @Override | ||
116 | + public Set<LigneAction> getActionsAchetees(int numeroCompte) | ||
117 | + throws CompteInconnuException { | ||
118 | + Compte c = this.getCompte(numeroCompte) ; | ||
119 | + return c.getLignesactions() ; | ||
120 | + } | ||
121 | + | ||
122 | + private Compte getCompte(int numeroCompte) throws CompteInconnuException { | ||
123 | + Compte c= (Compte) em.find(Compte.class, numeroCompte) ; | ||
124 | + if (c==null) throw new CompteInconnuException() ; | ||
125 | + return c; | ||
126 | + } | ||
127 | + | ||
128 | +} |