jdbcpoolmetadata.java

来自「Java Database connection pool」· Java 代码 · 共 280 行

JAVA
280
字号
/* *  PoolMan Java Object Pooling and Caching Library *  Copyright (C) 1999-2001 The Code Studio * *  This library is free software; you can redistribute it and/or *  modify it under the terms of the GNU Lesser General Public *  License as published by the Free Software Foundation; either *  version 2 of the License, or (at your option) any later version. * *  This library is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *  Lesser General Public License for more details. * *  The full license is located at the root of this distribution *  in the LICENSE file. */package com.codestudio.util;import com.codestudio.PoolManConstants;public class JDBCPoolMetaData extends PoolMetaData {    /* PHYSICAL CONNECTION ATTRIBUTES */    private String driver;    private String URL;    private String username;    private String password;    private boolean nativeResults = false;    /* POOL BEHAVIOR ATTRIBUTES */    private String validationQuery;    private String initialPoolSQL;    private String initialConnectionSQL;    private boolean removeOnExceptions = PoolManConstants.DEFAULT_REMOVE_ON_EXC;    private boolean poolingPreparedStatements = PoolManConstants.DEFAULT_POOL_PREP_STATEMENTS;    /* TX ATTRIBUTES */    private int transactionIsolationLevel = PoolManConstants.DEFAULT_ISO_LEVEL;    private int transactionTimeout = PoolManConstants.DEFAULT_USERTIMEOUT;    /* QUERY CACHE ATTRIBUTES */    private boolean cacheEnabled = PoolManConstants.DEFAULT_CACHE_ENABLED;    private int cacheSize = PoolManConstants.DEFAULT_CACHE_SIZE;    private int cacheRefreshInterval = PoolManConstants.DEFAULT_CACHE_REFRESH;    /* DATASOURCE ATTRIBUTES */    private String JNDIName;    /* PHYSICAL CONNECTION METHODS */    public String getDriver() {        return this.driver;    }    public void setDriver(String driver) {        this.driver = driver;    }    public String getURL() {        return this.URL;    }    public void setURL(String URL) {        this.URL = URL;    }    public String getUserName() {        return this.username;    }    public void setUserName(String username) {        this.username = username;    }    public String getPassword() {        return this.password;    }    public void setPassword(String password) {        this.password = password;    }    /* DATASOURCE METHODS */    public String getDbname() {        return getName();    }    public void setDbname(String n) {        setName(n);    }    public String getJNDIName() {        return this.JNDIName;    }    public void setJNDIName(String n) {        this.JNDIName = n;    }    public boolean isNativeResults() {        return this.nativeResults;    }    public void setNativeResults(boolean b) {        this.nativeResults = b;    }    /* POOL BEHAVIOR METHODS */    public boolean isPoolPreparedStatements() {        return poolingPreparedStatements;    }    public void setPoolPreparedStatements(boolean poolingPreparedStatements) {        this.poolingPreparedStatements = poolingPreparedStatements;    }    public String getValidationQuery() {        return this.validationQuery;    }    public void setValidationQuery(String sql) {        this.validationQuery = sql;    }    public String getInitialPoolSQL() {        return this.initialPoolSQL;    }    public void setInitialPoolSQL(String sql) {        this.initialPoolSQL = sql;    }    public String getInitialConnectionSQL() {        return this.initialConnectionSQL;    }    public void setInitialConnectionSQL(String sql) {        this.initialConnectionSQL = sql;    }    public boolean isRemoveOnExceptions() {        return this.removeOnExceptions;    }    public void setRemoveOnExceptions(boolean b) {        this.removeOnExceptions = b;    }    /* POOLED CONNECTION METHODS */    public int getInitialConnections() {        return getInitialObjects();    }    public void setInitialConnections(int n) {        setInitialObjects(n);    }    public int getConnectionTimeout() {        return getObjectTimeout();    }    public void setConnectionTimeout(int n) {        setObjectTimeout(n);    }    /* TX METHODS */    public int getTransactionTimeout() {        return this.transactionTimeout;    }    public void setTransactionTimeout(int n) {        this.transactionTimeout = n;    }    public int getIsolationLevel() {        return this.transactionIsolationLevel;    }    public void setIsolationLevel(int n) {        this.transactionIsolationLevel = n;    }    public String getTxIsolationLevel() {        return convertIsoToString(getIsolationLevel());    }    public void setTxIsolationLevel(String s) {        setIsolationLevel(convertIsoToInt(s));    }    private int convertIsoToInt(String s) {        int n = PoolManConstants.DEFAULT_ISO_LEVEL;        s = s.toUpperCase().trim();        if (s.equals("NONE"))            n = java.sql.Connection.TRANSACTION_NONE;        else if (s.equals("READ_COMMITTED"))            n = java.sql.Connection.TRANSACTION_READ_COMMITTED;        else if (s.equals("READ_UNCOMMITTED"))            n = java.sql.Connection.TRANSACTION_READ_UNCOMMITTED;        else if (s.equals("REPEATABLE_READ"))            n = java.sql.Connection.TRANSACTION_REPEATABLE_READ;        else if (s.equals("SERIALIZABLE"))            n = java.sql.Connection.TRANSACTION_SERIALIZABLE;        else            System.out.println("Unrecognized isolation level " + s +                               " using default setting of " +                               convertIsoToString(n));        return n;    }    private String convertIsoToString(int n) {        String result = null;        switch (n) {            case java.sql.Connection.TRANSACTION_NONE:                result = "NONE";                break;            case java.sql.Connection.TRANSACTION_READ_COMMITTED:                result = "READ_COMMITTED";                break;            case java.sql.Connection.TRANSACTION_READ_UNCOMMITTED:                result = "READ_UNCOMMITTED";                break;            case java.sql.Connection.TRANSACTION_REPEATABLE_READ:                result = "REPEATABLE_READ";                break;            case java.sql.Connection.TRANSACTION_SERIALIZABLE:                result = "SERIALIZABLE";                break;            default:                break;        }        return result;    }    /* QUERY CACHE METHODS */    public boolean isCacheEnabled() {        return this.cacheEnabled;    }    public void setCacheEnabled(            boolean b) {        this.cacheEnabled = b;    }    public int getCacheSize() {        return this.cacheSize;    }    public void setCacheSize(            int n) {        this.cacheSize = n;    }    public int getCacheRefreshInterval() {        return this.cacheRefreshInterval;    }    public void setCacheRefreshInterval(            int seconds) {        this.cacheRefreshInterval = seconds;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?