Advertisement
Guest User

Untitled

a guest
Jul 5th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.31 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <persistence version="2.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_2_0.xsd">
  3. <persistence-unit name="myapp" transaction-type="JTA">
  4. <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
  5. <jta-data-source>jdbc/myapp</jta-data-source>
  6. <exclude-unlisted-classes>false</exclude-unlisted-classes>
  7. <shared-cache-mode>NONE</shared-cache-mode>
  8. <properties>
  9. <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
  10. <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/myapp"/>
  11. <property name="javax.persistence.jdbc.user" value="root"/>
  12. <property name="javax.persistence.jdbc.password" value="password"/>
  13. <property name="javax.persistence.schema-generation.database.action" value="create"/>
  14. <property name="javax.persistence.schema-generation.create-database-schemas" value="false"/>
  15. <property name="javax.persistence.schema-generation.scripts.action" value="drop-and-create"/>
  16. <property name="javax.persistence.schema-generation.scripts.create-target" value="C:/tmp/myapp_create.ddl"/>
  17. <property name="javax.persistence.schema-generation.scripts.drop-target" value="C:/tmp/myapp_drop.ddl"/>
  18. <property name="eclipselink.deploy-on-startup" value="true"/>
  19. <property name="eclipselink.target-database" value="MySQL"/>
  20. <!-- <property name="eclipselink.ddl-generation" value="create-tables"/> -->
  21. <!-- <property name="eclipselink.ddl-generation.output-mode" value="database"/> -->
  22. <!-- <property name="eclipselink.create-ddl-jdbc-file-name" value="myapp.ddl"/> -->
  23. <!-- <property name="eclipselink.logging.level" value="FINE" /> -->
  24. <!-- <property name="eclipselink.logging.level.sql" value="FINE"/> -->
  25. <!-- <property name="eclipselink.logging.parameters" value="true"/> -->
  26. <!-- <property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.DefaultSessionLog"/> -->
  27. </properties>
  28. </persistence-unit>
  29. </persistence>
  30.  
  31. <?xml version="1.0" encoding="UTF-8"?>
  32. <!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
  33. <resources>
  34. <jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="jdbc/myapp_pool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
  35. <property name="serverName" value="localhost"/>
  36. <property name="portNumber" value="3306"/>
  37. <property name="databaseName" value="myapp"/>
  38. <property name="User" value="root"/>
  39. <property name="Password" value="password"/>
  40. <property name="URL" value="jdbc:mysql://localhost:3306/myapp"/>
  41. <property name="driverClass" value="com.mysql.jdbc.Driver"/>
  42. </jdbc-connection-pool>
  43. <jdbc-resource enabled="true" jndi-name="jdbc/myapp" object-type="user" pool-name="jdbc/myapp_pool"/>
  44. </resources>
  45.  
  46. <jdbc-resource pool-name="MyAppPool" jndi-name="java:app/jdbc/my-app-pool"></jdbc-resource>
  47.  
  48. <?xml version="1.0" encoding="UTF-8"?>
  49. <!DOCTYPE resources PUBLIC
  50. "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN"
  51. "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
  52. <resources>
  53. <jdbc-connection-pool validation-table-name="TABLEVALIDATION" allow-non-component-callers="true"
  54. statement-cache-size="200" associate-with-thread="true" statement-timeout-in-seconds="300"
  55. non-transactional-connections="true" connection-leak-reclaim="true"
  56. lazy-connection-association="true" connection-creation-retry-attempts="12"
  57. lazy-connection-enlistment="true" validate-atmost-once-period-in-seconds="120"
  58. statement-leak-timeout-in-seconds="360"
  59. datasource-classname="oracle.jdbc.pool.OracleDataSource" res-type="javax.sql.DataSource"
  60. connection-leak-timeout-in-seconds="420" statement-leak-reclaim="true"
  61. name="UnitTestPool" is-connection-validation-required="true">
  62. <property name="DataSourceName" value="OracleDataSource"></property>
  63. <property name="ImplicitCachingEnabled" value="false"></property>
  64. <property name="NetworkProtocol" value="tcp"></property>
  65. <property name="DatabaseName" value="unittestdb"></property>
  66. <property name="LoginTimeout" value="0"></property>
  67. <property name="Password" value="tester"></property>
  68. <property name="URL" value="jdbc:oracle:thin:@testbed:1521:xe"></property>
  69. <property name="User" value="testertester"></property>
  70. <property name="PortNumber" value="1521"></property>
  71. <property name="ExplicitCachingEnabled" value="false"></property>
  72. <property name="dynamic-reconfiguration-wait-timeout-in-seconds" value="960"></property>
  73. <property name="MaxStatements" value="0"></property>
  74. </jdbc-connection-pool>
  75. <jdbc-resource pool-name="UnitTestPool" jndi-name="java:app/jdbc/unittestdb-pool"></jdbc-resource>
  76. </resources>
  77.  
  78. private static ConnectionPool pool = null;
  79. private static DataSource dataSource = null;
  80.  
  81. private ConnectionPool(){
  82.  
  83. System.out.println("Tentative d'initialisation...");
  84. try{
  85. System.out.println("Debut d'initialisation du context...");
  86. InitialContext ic = new InitialContext();
  87. System.out.println("ouverture du datasource ");
  88. dataSource = (DataSource)ic.lookup("java:/comp/env/jdbc/bdstage");
  89. System.out.print("ouverture reussie ");
  90. }
  91. catch(NamingException e){
  92. System.out.println("ouverture echouee");
  93. System.out.println("voici l'erreur terrible "+e);
  94. }
  95.  
  96. }
  97.  
  98. public static ConnectionPool getInstance(){
  99.  
  100. if(pool == null){
  101. pool = new ConnectionPool();
  102. }
  103. return pool;
  104. }
  105.  
  106. public Connection getConnection(){
  107.  
  108. try{
  109. return dataSource.getConnection();
  110. }
  111. catch(SQLException sqle){
  112. System.out.println(sqle);
  113. return null;
  114. }
  115. }
  116.  
  117. public void freeConnection (Connection c){
  118.  
  119. try{
  120. c.close();
  121. }
  122. catch(SQLException sqle){
  123. sqle.printStackTrace();
  124. }
  125. }
  126.  
  127. public static void main(String[] args) {
  128. // TODO code application logic here
  129. ConnectionPool cp = new ConnectionPool();
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement