Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <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">
- <persistence-unit name="myapp" transaction-type="JTA">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
- <jta-data-source>jdbc/myapp</jta-data-source>
- <exclude-unlisted-classes>false</exclude-unlisted-classes>
- <shared-cache-mode>NONE</shared-cache-mode>
- <properties>
- <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
- <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/myapp"/>
- <property name="javax.persistence.jdbc.user" value="root"/>
- <property name="javax.persistence.jdbc.password" value="password"/>
- <property name="javax.persistence.schema-generation.database.action" value="create"/>
- <property name="javax.persistence.schema-generation.create-database-schemas" value="false"/>
- <property name="javax.persistence.schema-generation.scripts.action" value="drop-and-create"/>
- <property name="javax.persistence.schema-generation.scripts.create-target" value="C:/tmp/myapp_create.ddl"/>
- <property name="javax.persistence.schema-generation.scripts.drop-target" value="C:/tmp/myapp_drop.ddl"/>
- <property name="eclipselink.deploy-on-startup" value="true"/>
- <property name="eclipselink.target-database" value="MySQL"/>
- <!-- <property name="eclipselink.ddl-generation" value="create-tables"/> -->
- <!-- <property name="eclipselink.ddl-generation.output-mode" value="database"/> -->
- <!-- <property name="eclipselink.create-ddl-jdbc-file-name" value="myapp.ddl"/> -->
- <!-- <property name="eclipselink.logging.level" value="FINE" /> -->
- <!-- <property name="eclipselink.logging.level.sql" value="FINE"/> -->
- <!-- <property name="eclipselink.logging.parameters" value="true"/> -->
- <!-- <property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.DefaultSessionLog"/> -->
- </properties>
- </persistence-unit>
- </persistence>
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
- <resources>
- <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">
- <property name="serverName" value="localhost"/>
- <property name="portNumber" value="3306"/>
- <property name="databaseName" value="myapp"/>
- <property name="User" value="root"/>
- <property name="Password" value="password"/>
- <property name="URL" value="jdbc:mysql://localhost:3306/myapp"/>
- <property name="driverClass" value="com.mysql.jdbc.Driver"/>
- </jdbc-connection-pool>
- <jdbc-resource enabled="true" jndi-name="jdbc/myapp" object-type="user" pool-name="jdbc/myapp_pool"/>
- </resources>
- <jdbc-resource pool-name="MyAppPool" jndi-name="java:app/jdbc/my-app-pool"></jdbc-resource>
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE resources PUBLIC
- "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN"
- "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
- <resources>
- <jdbc-connection-pool validation-table-name="TABLEVALIDATION" allow-non-component-callers="true"
- statement-cache-size="200" associate-with-thread="true" statement-timeout-in-seconds="300"
- non-transactional-connections="true" connection-leak-reclaim="true"
- lazy-connection-association="true" connection-creation-retry-attempts="12"
- lazy-connection-enlistment="true" validate-atmost-once-period-in-seconds="120"
- statement-leak-timeout-in-seconds="360"
- datasource-classname="oracle.jdbc.pool.OracleDataSource" res-type="javax.sql.DataSource"
- connection-leak-timeout-in-seconds="420" statement-leak-reclaim="true"
- name="UnitTestPool" is-connection-validation-required="true">
- <property name="DataSourceName" value="OracleDataSource"></property>
- <property name="ImplicitCachingEnabled" value="false"></property>
- <property name="NetworkProtocol" value="tcp"></property>
- <property name="DatabaseName" value="unittestdb"></property>
- <property name="LoginTimeout" value="0"></property>
- <property name="Password" value="tester"></property>
- <property name="URL" value="jdbc:oracle:thin:@testbed:1521:xe"></property>
- <property name="User" value="testertester"></property>
- <property name="PortNumber" value="1521"></property>
- <property name="ExplicitCachingEnabled" value="false"></property>
- <property name="dynamic-reconfiguration-wait-timeout-in-seconds" value="960"></property>
- <property name="MaxStatements" value="0"></property>
- </jdbc-connection-pool>
- <jdbc-resource pool-name="UnitTestPool" jndi-name="java:app/jdbc/unittestdb-pool"></jdbc-resource>
- </resources>
- private static ConnectionPool pool = null;
- private static DataSource dataSource = null;
- private ConnectionPool(){
- System.out.println("Tentative d'initialisation...");
- try{
- System.out.println("Debut d'initialisation du context...");
- InitialContext ic = new InitialContext();
- System.out.println("ouverture du datasource ");
- dataSource = (DataSource)ic.lookup("java:/comp/env/jdbc/bdstage");
- System.out.print("ouverture reussie ");
- }
- catch(NamingException e){
- System.out.println("ouverture echouee");
- System.out.println("voici l'erreur terrible "+e);
- }
- }
- public static ConnectionPool getInstance(){
- if(pool == null){
- pool = new ConnectionPool();
- }
- return pool;
- }
- public Connection getConnection(){
- try{
- return dataSource.getConnection();
- }
- catch(SQLException sqle){
- System.out.println(sqle);
- return null;
- }
- }
- public void freeConnection (Connection c){
- try{
- c.close();
- }
- catch(SQLException sqle){
- sqle.printStackTrace();
- }
- }
- public static void main(String[] args) {
- // TODO code application logic here
- ConnectionPool cp = new ConnectionPool();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement