Advertisement
Guest User

Untitled

a guest
Feb 14th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. public class EjbLocator {
  2. private static Context ctx;
  3. private static EjbLocator instance = new EjbLocator();
  4. private EjbLocator() {
  5. }
  6. public static EjbLocator getLocator() {
  7. return instance;
  8. }
  9.  
  10. private <T> T getEjb(Class<T> ejbClass, String beanName) {
  11. try {
  12. final Hashtable jndiProperties = new Hashtable();
  13. jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
  14. final Context context = new InitialContext(jndiProperties);
  15. final String appName = "hockeyEAR";
  16. final String moduleName = "hockeyEJB";
  17. return (T) context.lookup("java:global/"+appName+"/"+moduleName+"/" + beanName + "!" + ejbClass.getName());
  18. } catch (NamingException e) {
  19. return null;
  20. }
  21. }
  22. public GestionLancersRemote getGestionLancers() {
  23. return getEjb(GestionLancersRemote.class, "GestionLancers");
  24. }
  25. }
  26.  
  27. <persistence-unit name="hockeyUnit" transaction-type="JTA">
  28. <jta-data-source>java:jboss/datasources/hockey</jta-data-source>
  29. <properties>
  30. <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
  31. <property name="hibernate.show_sql" value="true"/>
  32. <property name="hibernate.hbm2ddl.auto" value="update"/>
  33. </properties>
  34. </persistence-unit>
  35.  
  36. <datasources>
  37. <datasource jndi-name="java:jboss/datasources/hockey" pool-name="hockey" enabled="true" use-java-context="true">
  38. <connection-url>jdbc:mysql://localhost:3306/test</connection-url>
  39. <driver>mysql</driver>
  40. <security>
  41. <user-name>something</user-name>
  42. </security>
  43. </datasource>
  44. <drivers>
  45. <driver name="mysql" module="com.mysql">
  46. <xa-datasource-class>com.mysql.jdbc.Driver</xa-datasource-class>
  47. </driver>
  48. </drivers>
  49. </datasources>
  50.  
  51. java:global/ProjectEJB/Hello!hw.HelloRemote
  52. java:app/ProjectEJB/Hello!hw.HelloRemote
  53. java:module/Hello!hw.HelloRemote
  54. java:jboss/exported/ProjectEJB/Hello!hw.HelloRemote
  55. java:global/ProjectEJB/Hello!hw.Hello
  56. java:app/ProjectEJB/Hello!hw.Hello
  57. java:module/Hello!hw.Hello
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement