From 56d4d6063ceb3322d952edf48f645bcdf525c951 Mon Sep 17 00:00:00 2001
From: ocaron <olivier.caron@polytech-lille.fr>
Date: Fri, 5 Jan 2018 15:14:57 +0100
Subject: [PATCH] init projet

---
 demoCoursAL/.classpath                                         |   8 ++++++++
 demoCoursAL/.gitignore                                         |   2 ++
 demoCoursAL/.project                                           |  17 +++++++++++++++++
 demoCoursAL/.settings/org.eclipse.jdt.core.prefs               |  11 +++++++++++
 demoCoursAL/build.xml                                          | 196 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 demoCoursAL/jboss-ejb-client.properties                        |   9 +++++++++
 demoCoursAL/jndi.properties                                    |   1 +
 demoCoursAL/src/Reflection.java                                |  52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 demoCoursAL/src/application.xml                                |  15 +++++++++++++++
 demoCoursAL/src/client/Main.java                               |  58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 demoCoursAL/src/ejb/entites/Action.java                        |  26 ++++++++++++++++++++++++++
 demoCoursAL/src/ejb/entites/Compte.java                        |  62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 demoCoursAL/src/ejb/entites/LigneAction.java                   |  45 +++++++++++++++++++++++++++++++++++++++++++++
 demoCoursAL/src/ejb/entites/persistence.xml                    |  12 ++++++++++++
 demoCoursAL/src/ejb/sessions/ActionDejaExistanteException.java |  10 ++++++++++
 demoCoursAL/src/ejb/sessions/ActionInconnueException.java      |  10 ++++++++++
 demoCoursAL/src/ejb/sessions/ApprovisionnementException.java   |  10 ++++++++++
 demoCoursAL/src/ejb/sessions/CompteDejaExistantException.java  |  10 ++++++++++
 demoCoursAL/src/ejb/sessions/CompteInconnuException.java       |  10 ++++++++++
 demoCoursAL/src/ejb/sessions/ServiceBanque.java                |  23 +++++++++++++++++++++++
 demoCoursAL/src/ejb/sessions/ServiceBanqueBean.java            | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 21 files changed, 715 insertions(+), 0 deletions(-)
 create mode 100644 demoCoursAL/.classpath
 create mode 100644 demoCoursAL/.gitignore
 create mode 100644 demoCoursAL/.project
 create mode 100644 demoCoursAL/.settings/org.eclipse.jdt.core.prefs
 create mode 100755 demoCoursAL/build.xml
 create mode 100644 demoCoursAL/jboss-ejb-client.properties
 create mode 100755 demoCoursAL/jndi.properties
 create mode 100644 demoCoursAL/src/Reflection.java
 create mode 100755 demoCoursAL/src/application.xml
 create mode 100644 demoCoursAL/src/client/Main.java
 create mode 100644 demoCoursAL/src/ejb/entites/Action.java
 create mode 100644 demoCoursAL/src/ejb/entites/Compte.java
 create mode 100644 demoCoursAL/src/ejb/entites/LigneAction.java
 create mode 100644 demoCoursAL/src/ejb/entites/persistence.xml
 create mode 100644 demoCoursAL/src/ejb/sessions/ActionDejaExistanteException.java
 create mode 100644 demoCoursAL/src/ejb/sessions/ActionInconnueException.java
 create mode 100644 demoCoursAL/src/ejb/sessions/ApprovisionnementException.java
 create mode 100644 demoCoursAL/src/ejb/sessions/CompteDejaExistantException.java
 create mode 100644 demoCoursAL/src/ejb/sessions/CompteInconnuException.java
 create mode 100644 demoCoursAL/src/ejb/sessions/ServiceBanque.java
 create mode 100644 demoCoursAL/src/ejb/sessions/ServiceBanqueBean.java

diff --git a/demoCoursAL/.classpath b/demoCoursAL/.classpath
new file mode 100644
index 0000000..fd14ee7
--- /dev/null
+++ b/demoCoursAL/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<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"/>
+	<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"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/demoCoursAL/.gitignore b/demoCoursAL/.gitignore
new file mode 100644
index 0000000..4a95481
--- /dev/null
+++ b/demoCoursAL/.gitignore
@@ -0,0 +1,2 @@
+/bin/
+/build/
diff --git a/demoCoursAL/.project b/demoCoursAL/.project
new file mode 100644
index 0000000..2b2c38e
--- /dev/null
+++ b/demoCoursAL/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>demoCoursAL</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>
diff --git a/demoCoursAL/.settings/org.eclipse.jdt.core.prefs b/demoCoursAL/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..7341ab1
--- /dev/null
+++ b/demoCoursAL/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/demoCoursAL/build.xml b/demoCoursAL/build.xml
new file mode 100755
index 0000000..ecb4913
--- /dev/null
+++ b/demoCoursAL/build.xml
@@ -0,0 +1,196 @@
+<?xml version="1.0"?>
+<project name="demoCoursAL" default="ear" basedir=".">
+   <!-- Declarations proprietes et classpath -->
+      <!-- LIGNES SUIVANTES A MODIFIER : -->
+      <property name="jboss.dir" value="/home/opt/wildfly10" />
+      <!-- FIN LIGNES  A MODIFIER : -->
+      <property name="jboss.lib.dir" value="${jboss.dir}/lib" />
+      <property name="src.dir" value="${basedir}/src" />
+      <property name="build.dir" value="build" />
+      <property name="name" value="appliBanque" />
+   <!-- The build classpath -->
+   <path id="build.classpath">
+      <pathelement location="${basedir}"/>
+      <fileset dir="${jboss.dir}/modules/system/layers/base/org/hibernate/main">
+        <include name="hibernate-core-5.0.10.Final.jar"/>
+      </fileset>
+      <fileset dir="${jboss.dir}/modules/system/layers/base/javax/persistence/api/main">
+        <include name="hibernate-jpa-2.1-api-1.0.0.Final.jar"/>
+      </fileset>
+      <fileset dir="${jboss.dir}/bin/client">
+        <include name="*.jar"/>
+      </fileset>
+      <fileset dir="${jboss.dir}/modules/system/layers/base/javax/ejb/api/main">
+        <include name="jboss-ejb-api_3.2_spec-1.0.0.Final.jar"/>
+      </fileset>
+	  <pathelement location="${build.dir}/sessions"/>
+	  <pathelement location="${build.dir}/entites" />
+	  <pathelement location="${build.dir}/classes"/>		
+  </path>
+  
+   <!-- Prepare -->
+   <target name="prepare" >
+      <mkdir dir="${build.dir}" />
+      <mkdir dir="${build.dir}/docs" />
+      <mkdir dir="${build.dir}/sessions" /> 
+      <mkdir dir="${build.dir}/entites" />
+      <mkdir dir="${build.dir}/jars" />
+      <mkdir dir="${build.dir}/web" />
+      <mkdir dir="${build.dir}/web/WEB-INF" />
+   </target>
+
+   <!-- Compile sessions-->
+   <target name="compile-sessions" depends="prepare">
+     <javac destdir="${build.dir}/sessions"
+	     classpathref="build.classpath"	>
+             <src path="${src.dir}/ejb/sessions" />		
+      </javac>
+   </target>
+
+   <!-- Create sessions file -->
+   <target name="package-sessions" depends="compile-sessions">
+      <jar jarfile="${build.dir}/jars/${name}Sessions.jar" 
+           basedir="${build.dir}/sessions" >	 				
+      </jar>
+   </target>
+  <!-- Compile entites-->
+   <target name="compile-entites" depends="prepare">
+      <javac destdir="${build.dir}/entites"
+	     classpathref="build.classpath"	>
+	     <src path="${src.dir}/ejb/entites" />		
+      </javac>
+   </target>
+	 
+   <!-- Create entites-jar file -->
+   <target name="package-entites" depends="compile-entites">
+      <schemavalidate file="${src.dir}/ejb/entites/persistence.xml" /> 
+      <jar jarfile="${build.dir}/jars/${name}Entites.jar" 
+           basedir="${build.dir}/entites" >		
+	   <metainf dir="${src.dir}/ejb/entites">
+             <include name="persistence.xml"/>
+       </metainf>
+      </jar>
+   </target>
+   
+   <target name="war" depends="prepare">
+      <!-- <xmlvalidate file="${src.dir}/web/web.xml"/> -->
+      <copy file="${src.dir}/web/web.xml" todir="${build.dir}/web/WEB-INF" />
+      <copy todir="${build.dir}/web">
+        <fileset dir="${src.dir}/web" includes="*" excludes="*.xml" />
+      </copy>
+      <jar
+        basedir="${build.dir}/web/"
+        destfile="${build.dir}/jars/${name}.war" >
+      </jar>
+   </target>  
+	 
+   <target name="earSession" depends="package-sessions">
+      <schemavalidate file="${src.dir}/application.xml"/>
+      <ear destfile="${build.dir}/jars/${name}.ear"
+           appxml="${src.dir}/application.xml">
+           <fileset dir="${build.dir}/jars" excludes="*.ear,*.war" />
+     </ear>
+   </target>
+   
+   <target name="earSessionWeb" depends="package-sessions, war">
+      <schemavalidate file="${src.dir}/application.xml"/>
+      <ear destfile="${build.dir}/jars/${name}.ear"
+           appxml="${src.dir}/application.xml">
+           <fileset dir="${build.dir}/jars" excludes="*.ear" />
+     </ear>
+   </target>
+   
+   <target name="earEntite" depends="package-entites">
+      <schemavalidate file="${src.dir}/application.xml"/>
+      <ear destfile="${build.dir}/jars/${name}.ear"
+           appxml="${src.dir}/application.xml">
+          <fileset dir="${build.dir}/jars" excludes="*.ear,*.war" />
+      </ear>
+   </target>
+   
+   <target name="earEntiteEtSession" depends="package-entites,package-sessions">
+     <schemavalidate file="${src.dir}/application.xml"/>
+     <ear destfile="${build.dir}/jars/${name}.ear"
+          appxml="${src.dir}/application.xml">
+          <fileset dir="${build.dir}/jars" excludes="*.ear,*.war" />
+     </ear>
+   </target>
+   
+
+   <target name="ear" depends="package-entites,package-sessions, war">
+     <schemavalidate file="${src.dir}/application.xml"/>
+     <ear destfile="${build.dir}/jars/${name}.ear"
+          appxml="${src.dir}/application.xml">
+          <fileset dir="${build.dir}/jars" excludes="*.ear" />
+     </ear>
+   </target>
+
+    <target name="deploy">
+     <copy file="${build.dir}/jars/${name}.ear"
+           todir="${jboss.dir}/standalone/deployments" />
+   </target>
+   	 
+   <target name="deployEntite" depends="earEntite, deploy" /> 
+   
+   <target name="deployEntiteEtSession" depends="earEntiteEtSession, deploy" />
+   
+   <target name="deploySession" depends="earSession, deploy" />
+
+   <target name="deploySessionWeb" depends="earSessionWeb, deploy" />
+
+   <target name="deployAll" depends="ear, deploy" />
+	 
+   <target name="undeploy">
+     <delete>
+       <fileset dir="${jboss.dir}/standalone/deployments">
+         <filename name="${name}.*" />
+       </fileset>
+     </delete>
+      
+   </target>
+	 
+   <target name="javadoc" depends="compile-sessions">
+     <javadoc packagenames="*"
+       sourcepath="src/ejb/sessions"
+       classpathref="build.classpath"
+       destdir="build/docs"
+       author="true"
+       private="true"
+       windowtitle="${name} api" >
+     </javadoc>
+   </target>  
+
+   
+   <!-- Clean everything -->
+   <target name="clean" depends="undeploy">
+      <delete dir="${build.dir}" />
+   </target>
+
+   <!-- compilation, execution programme client -->
+   <target name="init-client" depends="prepare">
+     <property name="classes.dir" value="${build.dir}/classes" />
+     <mkdir dir="${classes.dir}" />
+     
+   </target>
+
+
+      <target name="compile-client" depends="init-client">
+     
+      <javac srcdir="${src.dir}/client"
+             destdir="${classes.dir}">
+        <classpath refid="build.classpath" />
+      </javac>
+   </target>
+
+   <target name="run-client" depends="compile-client">      
+      <java classname="client.Main" fork="yes" dir="." >      
+        <classpath refid="build.classpath" />
+      </java>
+   </target>
+	
+   <target name="clean-client" depends="init-client">
+      <delete dir="${build.dir}/classes" />
+   </target>
+   
+</project>
+
diff --git a/demoCoursAL/jboss-ejb-client.properties b/demoCoursAL/jboss-ejb-client.properties
new file mode 100644
index 0000000..6128a44
--- /dev/null
+++ b/demoCoursAL/jboss-ejb-client.properties
@@ -0,0 +1,9 @@
+endpoint.name=client-endpoint
+remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
+
+remote.connections=default
+
+remote.connection.default.host=localhost
+remote.connection.default.port = 8080
+remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
+
diff --git a/demoCoursAL/jndi.properties b/demoCoursAL/jndi.properties
new file mode 100755
index 0000000..ee5a96b
--- /dev/null
+++ b/demoCoursAL/jndi.properties
@@ -0,0 +1 @@
+java.naming.factory.url.pkgs=org.jboss.ejb.client.naming
diff --git a/demoCoursAL/src/Reflection.java b/demoCoursAL/src/Reflection.java
new file mode 100644
index 0000000..7c18387
--- /dev/null
+++ b/demoCoursAL/src/Reflection.java
@@ -0,0 +1,52 @@
+import java.lang.reflect.* ;
+import java.beans.Beans ;
+import java.util.ArrayList ;
+
+public class Reflection {
+
+  @SuppressWarnings("rawtypes")
+  public static void main(String args[]) {
+    ArrayList<Method> propBool=new ArrayList<Method>() ;
+    Class[] paramType= new Class[] { Boolean.TYPE };
+    try {
+	Object obj = Beans.instantiate(null,args[0]) ;
+	Class laClasse = obj.getClass() ;
+	for (Method m :  laClasse.getMethods()) {
+	  if (m.getName().startsWith("is") &&
+	      m.getParameterTypes().length==0 &&
+	      m.getReturnType().toString().equals("boolean")) {     
+		  	System.out.println("getter method found : "+m.getName()) ;
+		  	String setName="set"+m.getName().substring(2) ;
+            try {           
+	          Method methodeSet=laClasse.getMethod(setName,paramType) ;
+	          propBool.add(methodeSet) ;
+	          String propertyName = setName.substring(0,1).toLowerCase() + setName.substring(1);
+		      System.out.println("boolean property found : "+propertyName) ;
+            } catch(NoSuchMethodException e1) { 
+            	System.out.println("No corresponding setter method found : "+setName) ;
+            }
+	    }
+	}
+	Object param[] =new Boolean[1] ;
+	param[0]=new Boolean(true) ;
+	for (Method m : propBool) {
+	  System.out.println("invoke method "+m.getName()+" with true parameter") ;
+	  m.invoke(obj,param) ;
+	}
+    } catch (ArrayIndexOutOfBoundsException e) {
+	System.err.println("Erreur : java Reflection class name") ;
+    } catch (SecurityException e) {
+	System.err.println("exception raised...") ;
+    } catch(IllegalAccessException e) {
+	System.err.println("Access...") ;
+    } catch(InvocationTargetException e) {
+	System.err.println("Argument...") ;
+    } catch(IllegalArgumentException e) {
+	System.err.println("Argument...") ;
+    } catch(java.io.IOException e) {
+	System.err.println("IO...") ;
+    } catch(ClassNotFoundException e) {
+	System.err.println("class...") ;
+    }
+  }  
+}
diff --git a/demoCoursAL/src/application.xml b/demoCoursAL/src/application.xml
new file mode 100755
index 0000000..7ea0e58
--- /dev/null
+++ b/demoCoursAL/src/application.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<application xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="6"
+xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd">
+ 
+  <display-name>Appli Banque</display-name>
+   
+  <module>
+    <ejb>appliBanqueSessions.jar</ejb>
+  </module> 
+	<module>
+    <ejb>appliBanqueEntites.jar</ejb>
+  </module> 
+</application>
+
diff --git a/demoCoursAL/src/client/Main.java b/demoCoursAL/src/client/Main.java
new file mode 100644
index 0000000..5551909
--- /dev/null
+++ b/demoCoursAL/src/client/Main.java
@@ -0,0 +1,58 @@
+package client ;
+
+
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException ;
+
+import ejb.sessions.* ;
+import ejb.entites.* ;
+
+public class Main {
+		
+ public static void main(String[] args) { 
+   try {
+      InitialContext ctx = new InitialContext();
+      System.out.println("Accès au service distant") ;
+      Object obj = ctx.lookup("ejb:appliBanque/appliBanqueSessions//ServiceBanqueBean!ejb.sessions.ServiceBanque");
+      
+      ServiceBanque service = (ServiceBanque) obj ;
+      service.addCompte(1, "Olivier", 2000.0);
+      service.addCompte(2, "Paul", 300.0) ;
+      service.addAction("nintendo",46.5) ;
+      service.addAction("sega", 12.0) ;
+      System.out.println("achat de 10 actions sega") ;
+      service.acheteActions(1, "sega", 10);
+      System.out.println("achat de 3 actions nintendo") ;
+      service.acheteActions(1,  "nintendo", 3);
+      System.out.println("Actions de Olivier:") ;
+      for (LigneAction la : service.getActionsAchetees(1))
+    	System.out.println(la.getNombre()+" action(s) "+la.getAction().getNom()
+    				        +" au taux de "+la.getAction().getTaux()) ;
+      System.out.println("vente de 2 actions sega") ;
+      service.vendActions(1, "sega", 2);
+      System.out.println("Actions de Olivier:") ;
+      for (LigneAction la : service.getActionsAchetees(1))
+    	 System.out.println(la.getNombre()+" action(s) "+la.getAction().getNom()
+    				             +" au taux de "+la.getAction().getTaux()) ;
+      System.out.println("vente de 8 actions sega") ;
+      service.vendActions(1, "sega", 8);
+      System.out.println("Actions de Olivier:") ;
+      for (LigneAction la : service.getActionsAchetees(1))
+        System.out.println(la.getNombre()+" action(s) "+la.getAction().getNom()
+    				             +" au taux de "+la.getAction().getTaux()) ;   	  
+      } catch(CompteInconnuException e) {
+    	  System.err.println("Compte inconnu") ;
+      } catch (NamingException e1) {
+    	  System.err.println("erreur accès service") ;
+	} catch (ActionInconnueException e) {
+		System.err.println("Action inconnue") ;
+	} catch (ApprovisionnementException e) {
+		System.err.println("pb approvisionnement") ;
+	} catch (CompteDejaExistantException e) {
+		System.err.println("Compte existe") ;
+	} catch (ActionDejaExistanteException e) {
+		System.err.println("Action existe") ;
+	}
+   }
+}
\ No newline at end of file
diff --git a/demoCoursAL/src/ejb/entites/Action.java b/demoCoursAL/src/ejb/entites/Action.java
new file mode 100644
index 0000000..1a6ba3f
--- /dev/null
+++ b/demoCoursAL/src/ejb/entites/Action.java
@@ -0,0 +1,26 @@
+package ejb.entites;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+@Entity
+public class Action implements java.io.Serializable {
+  private static final long serialVersionUID = 1L;
+  
+  public Action() {}
+  
+  @Id private String nom ;
+  private double taux ;
+  
+  public String getNom() { return nom; }
+  public void setNom(String nom) {
+	this.nom = nom;
+  }
+  
+  public double getTaux() { return taux; }
+  public void setTaux(double taux) {
+	this.taux = taux;
+  }
+  
+  
+}
diff --git a/demoCoursAL/src/ejb/entites/Compte.java b/demoCoursAL/src/ejb/entites/Compte.java
new file mode 100644
index 0000000..abd19e3
--- /dev/null
+++ b/demoCoursAL/src/ejb/entites/Compte.java
@@ -0,0 +1,62 @@
+package ejb.entites;
+
+import java.io.Serializable ;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+@Entity
+public class Compte implements Serializable {
+	
+	@Id private int numero ;
+	private double solde ;
+	private String titulaire ;
+	@OneToMany(mappedBy="proprietaire", fetch=FetchType.EAGER) 
+	private Set<LigneAction> lignesactions ;
+	
+	
+	
+	public int getNumero() { return numero; }
+
+	public void setNumero(int numero) { 
+		this.numero = numero;
+	}
+
+	public double getSolde() {
+		return solde;
+	}
+
+	public void setSolde(double solde) {
+		this.solde = solde;
+	}
+
+	public String getTitulaire() {
+		return titulaire;
+	}
+
+	public void setTitulaire(String titulaire) {
+		this.titulaire = titulaire;
+	}
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+	public Compte() {}
+
+	public Set<LigneAction> getLignesactions() {
+		return lignesactions;
+	}
+
+	public void setLignesactions(Set<LigneAction> lignesactions) {
+		this.lignesactions = lignesactions;
+	}
+
+	
+	
+	
+}
diff --git a/demoCoursAL/src/ejb/entites/LigneAction.java b/demoCoursAL/src/ejb/entites/LigneAction.java
new file mode 100644
index 0000000..a53eea0
--- /dev/null
+++ b/demoCoursAL/src/ejb/entites/LigneAction.java
@@ -0,0 +1,45 @@
+package ejb.entites;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+
+@Table (name="t_ligne_action") @Entity
+public class LigneAction implements java.io.Serializable {
+  private static final long serialVersionUID = 1L;
+  
+  public LigneAction() {}
+  
+  @Id @GeneratedValue private int id ;
+  private int nombre ;
+  @ManyToOne private Compte proprietaire ;
+  @ManyToOne(fetch=FetchType.EAGER) private Action action ;
+  
+  
+  public int getId() { return id; }
+  public void setId(int id) { this.id = id; }
+
+  public int getNombre() { return nombre; }
+  public void setNombre(int nombre) {
+	this.nombre = nombre;
+  }
+  
+  public Compte getProprietaire() {
+	return proprietaire;
+  }
+  public void setProprietaire(Compte proprietaire) {
+	this.proprietaire = proprietaire;
+  }
+  
+  public Action getAction() {
+	return action;
+  }
+  public void setAction(Action action) {
+	this.action = action;
+  }
+
+}
diff --git a/demoCoursAL/src/ejb/entites/persistence.xml b/demoCoursAL/src/ejb/entites/persistence.xml
new file mode 100644
index 0000000..70cb705
--- /dev/null
+++ b/demoCoursAL/src/ejb/entites/persistence.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+  <persistence-unit name="appliBanque">
+  <jta-data-source>java:/PostgresDS</jta-data-source>
+  <properties>
+    <property name="hibernate.hbm2ddl.auto"
+              value="create-drop"/>
+  </properties>
+	</persistence-unit>
+</persistence>
+
+
diff --git a/demoCoursAL/src/ejb/sessions/ActionDejaExistanteException.java b/demoCoursAL/src/ejb/sessions/ActionDejaExistanteException.java
new file mode 100644
index 0000000..d683a6d
--- /dev/null
+++ b/demoCoursAL/src/ejb/sessions/ActionDejaExistanteException.java
@@ -0,0 +1,10 @@
+package ejb.sessions;
+
+public class ActionDejaExistanteException extends Exception {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+}
diff --git a/demoCoursAL/src/ejb/sessions/ActionInconnueException.java b/demoCoursAL/src/ejb/sessions/ActionInconnueException.java
new file mode 100644
index 0000000..6a0518e
--- /dev/null
+++ b/demoCoursAL/src/ejb/sessions/ActionInconnueException.java
@@ -0,0 +1,10 @@
+package ejb.sessions;
+
+public class ActionInconnueException extends Exception {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+}
diff --git a/demoCoursAL/src/ejb/sessions/ApprovisionnementException.java b/demoCoursAL/src/ejb/sessions/ApprovisionnementException.java
new file mode 100644
index 0000000..c4729f0
--- /dev/null
+++ b/demoCoursAL/src/ejb/sessions/ApprovisionnementException.java
@@ -0,0 +1,10 @@
+package ejb.sessions;
+
+public class ApprovisionnementException extends Exception {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+}
diff --git a/demoCoursAL/src/ejb/sessions/CompteDejaExistantException.java b/demoCoursAL/src/ejb/sessions/CompteDejaExistantException.java
new file mode 100644
index 0000000..6b6c7c5
--- /dev/null
+++ b/demoCoursAL/src/ejb/sessions/CompteDejaExistantException.java
@@ -0,0 +1,10 @@
+package ejb.sessions;
+
+public class CompteDejaExistantException extends Exception {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+}
diff --git a/demoCoursAL/src/ejb/sessions/CompteInconnuException.java b/demoCoursAL/src/ejb/sessions/CompteInconnuException.java
new file mode 100644
index 0000000..9041d28
--- /dev/null
+++ b/demoCoursAL/src/ejb/sessions/CompteInconnuException.java
@@ -0,0 +1,10 @@
+package ejb.sessions;
+
+public class CompteInconnuException extends Exception {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+}
diff --git a/demoCoursAL/src/ejb/sessions/ServiceBanque.java b/demoCoursAL/src/ejb/sessions/ServiceBanque.java
new file mode 100644
index 0000000..4840c25
--- /dev/null
+++ b/demoCoursAL/src/ejb/sessions/ServiceBanque.java
@@ -0,0 +1,23 @@
+package ejb.sessions;
+
+import ejb.entites.LigneAction ;
+
+@javax.ejb.Remote
+public interface ServiceBanque {
+	public void addCompte(int numeroCompte, String nomTitulaire, double soldeDepart)
+	throws CompteDejaExistantException ;
+	public void addAction(String nomAction, double taux) 
+	throws ActionDejaExistanteException ;
+    public void crediterCompte(int numeroCompte, double montant)
+    throws CompteInconnuException ;
+    public void debiterCompte(int numeroCompte, double montant) 
+    throws CompteInconnuException ;
+    public void virementVers(int numCompteDebit, int numCompteCredit, double montant)
+    throws CompteInconnuException,ApprovisionnementException ;
+    public void acheteActions(int numeroCompte, String nomAction, int nb) 
+    throws CompteInconnuException, ActionInconnueException, ApprovisionnementException ;
+    public void vendActions(int numeroCompte, String nomAction, int nb) 
+    throws CompteInconnuException, ActionInconnueException, ApprovisionnementException ;
+    public java.util.Set<LigneAction> getActionsAchetees(int numeroCompte) 
+    throws CompteInconnuException ;
+}
diff --git a/demoCoursAL/src/ejb/sessions/ServiceBanqueBean.java b/demoCoursAL/src/ejb/sessions/ServiceBanqueBean.java
new file mode 100644
index 0000000..3f0c21d
--- /dev/null
+++ b/demoCoursAL/src/ejb/sessions/ServiceBanqueBean.java
@@ -0,0 +1,128 @@
+package ejb.sessions;
+
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import ejb.entites.Action;
+import ejb.entites.Compte;
+import ejb.entites.LigneAction;
+
+@javax.ejb.Stateless
+public class ServiceBanqueBean implements ServiceBanque {
+	@PersistenceContext(unitName="appliBanque") protected EntityManager em ;
+	@Override
+	public void addCompte(int numeroCompte, String nomTitulaire, double soldeDepart)
+			throws CompteDejaExistantException {
+		try {
+			this.getCompte(numeroCompte) ;
+			throw new CompteDejaExistantException() ;
+		} catch(CompteInconnuException e) {
+		  Compte c=new Compte() ;
+		  c.setNumero(numeroCompte); c.setSolde(soldeDepart);
+		  c.setTitulaire(nomTitulaire);
+		  em.persist(c);
+		}
+	}
+
+	@Override
+	public void addAction(String nomAction, double taux)
+			throws ActionDejaExistanteException {
+		try {
+			this.getAction(nomAction) ;
+			throw new ActionDejaExistanteException() ;
+		} catch(ActionInconnueException e) {
+		  Action a=new Action() ;
+		  a.setNom(nomAction); a.setTaux(taux);
+		  em.persist(a);
+		}
+
+	}
+
+	private Action getAction(String nomAction) throws ActionInconnueException {
+		Action a= (Action) em.find(Action.class, nomAction) ;
+		if (a==null) throw new ActionInconnueException() ;
+		return a ;
+	}
+
+	@Override
+	public void crediterCompte(int numeroCompte, double montant)
+			throws CompteInconnuException {
+		Compte c = this.getCompte(numeroCompte) ;
+		c.setSolde(c.getSolde()+montant);
+	}
+
+	@Override
+	public void debiterCompte(int numeroCompte, double montant)
+			throws CompteInconnuException {
+		Compte c = this.getCompte(numeroCompte) ;
+		c.setSolde(c.getSolde()-montant);
+
+	}
+
+	@Override
+	public void virementVers(int numCompteDebit, int numCompteCredit,
+			double montant) throws CompteInconnuException,
+			ApprovisionnementException {
+		
+
+	}
+
+	@Override
+	public void acheteActions(int numeroCompte, String nomAction, int nb)
+			throws CompteInconnuException, ActionInconnueException,
+			ApprovisionnementException {
+		Compte c = this.getCompte(numeroCompte) ;
+		Action a = this.getAction(nomAction) ;
+		if (c.getSolde()< nb*a.getTaux())
+			throw new ApprovisionnementException() ;
+		else
+			c.setSolde(c.getSolde()-nb*a.getTaux()) ;
+		boolean trouve=false ;
+		for (LigneAction la : c.getLignesactions()) 
+			if (la.getAction().getNom().equals(nomAction)) {
+				trouve=true ; la.setNombre(la.getNombre()+nb);
+			}
+		if (!trouve) {
+			LigneAction la = new LigneAction() ;
+			la.setAction(a); la.setProprietaire(c) ; la.setNombre(nb);
+			em.persist(la);
+		}
+	}
+
+	@Override
+	public void vendActions(int numeroCompte, String nomAction, int nb)
+			throws CompteInconnuException, ActionInconnueException,
+			ApprovisionnementException {
+		Compte c = this.getCompte(numeroCompte) ;
+		LigneAction la=null ;
+		for (LigneAction vla : c.getLignesactions()) 
+			if (vla.getAction().getNom().equals(nomAction)) {
+				la=vla ; 
+			}
+		if (la != null) {
+			if (nb > la.getNombre()) 
+				throw new ApprovisionnementException() ;
+			else {
+				c.setSolde(c.getSolde()+nb*la.getAction().getTaux());
+				la.setNombre(la.getNombre()-nb) ;
+				if (la.getNombre()==0) em.remove(la);
+			}
+		}
+	}
+
+	@Override
+	public Set<LigneAction> getActionsAchetees(int numeroCompte)
+			throws CompteInconnuException {
+		Compte c = this.getCompte(numeroCompte) ;
+		return c.getLignesactions() ;
+	}
+	
+	private Compte getCompte(int numeroCompte) throws CompteInconnuException {
+		Compte c= (Compte) em.find(Compte.class, numeroCompte) ;
+		if (c==null) throw new CompteInconnuException() ;
+		return c;
+	}
+
+}
--
libgit2 0.21.2