Guest User

Untitled

a guest
Jul 21st, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. package si.uni.mb.aiv;
  2.  
  3. import java.sql.Connection;
  4. import org.apache.tomcat.jdbc.pool.DataSource;
  5. import org.apache.tomcat.jdbc.pool.PoolProperties;
  6.  
  7. public class DBExtensionAdapter extends DBExtension {
  8.    
  9.     private static DataSource datasource = null;
  10.      
  11.     public DBExtensionAdapter() {
  12.     }
  13.  
  14.     public static void initDatasource() {
  15.  
  16.         PoolProperties p = new PoolProperties();
  17.  
  18.         p.setUrl("jdbc:mysql://localhost:3306/vzorci");
  19.         p.setDriverClassName("com.mysql.jdbc.Driver");
  20.         p.setUsername("root");
  21.         p.setPassword("aiv2012");
  22.  
  23.         p.setJmxEnabled(true);
  24.         p.setTestWhileIdle(false);
  25.         p.setTestOnBorrow(true);
  26.         p.setValidationQuery("SELECT 1");
  27.         p.setTestOnReturn(false);
  28.         p.setValidationInterval(30000);
  29.         p.setTimeBetweenEvictionRunsMillis(30000);
  30.  
  31.         p.setMaxActive(75);
  32.         p.setMaxIdle(75);
  33.         p.setInitialSize(10);
  34.         p.setMaxWait(10000);
  35.         p.setRemoveAbandonedTimeout(60);
  36.         p.setMinEvictableIdleTimeMillis(30000);
  37.         p.setMinIdle(10);
  38.  
  39.         p.setLogAbandoned(true);        
  40.         p.setRemoveAbandoned(true);
  41.  
  42.         p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"
  43.                 + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
  44.  
  45.         datasource = new DataSource();
  46.         datasource.setPoolProperties(p);
  47.  
  48.     }
  49.    
  50.     public static void zapriDatasource() {
  51.         datasource.close();
  52.     }
  53.    
  54.     @Override
  55.     public Connection VrniPovezavo() {
  56.         try {
  57.             if (datasource == null) {
  58.                 DBExtensionAdapter.initDatasource();
  59.             }
  60.             return datasource.getConnection();
  61.         } catch (Exception e) {
  62.             return null;
  63.         }
  64.     }
  65.  
  66. }
Add Comment
Please, Sign In to add comment