Example usage for java.sql Connection TRANSACTION_READ_UNCOMMITTED

List of usage examples for java.sql Connection TRANSACTION_READ_UNCOMMITTED

Introduction

In this page you can find the example usage for java.sql Connection TRANSACTION_READ_UNCOMMITTED.

Prototype

int TRANSACTION_READ_UNCOMMITTED

To view the source code for java.sql Connection TRANSACTION_READ_UNCOMMITTED.

Click Source Link

Document

A constant indicating that dirty reads, non-repeatable reads and phantom reads can occur.

Usage

From source file:org.wso2.carbon.datasource.core.utils.RDBMSDataSourceUtils.java

public static PoolConfiguration createPoolConfiguration(RDBMSConfiguration config) throws DataSourceException {
    PoolProperties props = new PoolProperties();
    props.setUrl(config.getUrl());//from   w  w w. ja v a2 s  . c  o  m
    if (config.isDefaultAutoCommit() != null) {
        props.setDefaultAutoCommit(config.isDefaultAutoCommit());
    }
    if (config.isDefaultReadOnly() != null) {
        props.setDefaultReadOnly(config.isDefaultReadOnly());
    }
    String isolationLevelString = config.getDefaultTransactionIsolation();
    if (isolationLevelString != null) {
        if (RDBMSDataSourceConstants.TX_ISOLATION_LEVELS.NONE.equals(isolationLevelString)) {
            props.setDefaultTransactionIsolation(Connection.TRANSACTION_NONE);
        } else if (RDBMSDataSourceConstants.TX_ISOLATION_LEVELS.READ_UNCOMMITTED.equals(isolationLevelString)) {
            props.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
        } else if (RDBMSDataSourceConstants.TX_ISOLATION_LEVELS.READ_COMMITTED.equals(isolationLevelString)) {
            props.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
        } else if (RDBMSDataSourceConstants.TX_ISOLATION_LEVELS.REPEATABLE_READ.equals(isolationLevelString)) {
            props.setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
        } else if (RDBMSDataSourceConstants.TX_ISOLATION_LEVELS.SERIALIZABLE.equals(isolationLevelString)) {
            props.setDefaultTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
        }
    }
    props.setDefaultCatalog(config.getDefaultCatalog());
    props.setDriverClassName(config.getDriverClassName());
    props.setUsername(config.getUsername());
    props.setPassword(config.getPassword());
    if (config.getMaxActive() != null) {
        props.setMaxActive(config.getMaxActive());
    }
    if (config.getMaxIdle() != null) {
        props.setMaxIdle(config.getMaxIdle());
    }
    if (config.getMinIdle() != null) {
        props.setMinIdle(config.getMinIdle());
    }
    if (config.getInitialSize() != null) {
        props.setInitialSize(config.getInitialSize());
    }
    if (config.getMaxWait() != null) {
        props.setMaxWait(config.getMaxWait());
    }
    if (config.isTestOnBorrow() != null) {
        props.setTestOnBorrow(config.isTestOnBorrow());
    }
    if (config.isTestOnReturn() != null) {
        props.setTestOnReturn(config.isTestOnReturn());
    }
    if (config.isTestWhileIdle() != null) {
        props.setTestWhileIdle(config.isTestWhileIdle());
    }
    props.setValidationQuery(config.getValidationQuery());
    props.setValidatorClassName(config.getValidatorClassName());
    if (config.getTimeBetweenEvictionRunsMillis() != null) {
        props.setTimeBetweenEvictionRunsMillis(config.getTimeBetweenEvictionRunsMillis());
    }
    if (config.getNumTestsPerEvictionRun() != null) {
        props.setNumTestsPerEvictionRun(config.getNumTestsPerEvictionRun());
    }
    if (config.getMinEvictableIdleTimeMillis() != null) {
        props.setMinEvictableIdleTimeMillis(config.getMinEvictableIdleTimeMillis());
    }
    if (config.isAccessToUnderlyingConnectionAllowed() != null) {
        props.setAccessToUnderlyingConnectionAllowed(config.isAccessToUnderlyingConnectionAllowed());
    }
    if (config.isRemoveAbandoned() != null) {
        props.setRemoveAbandoned(config.isRemoveAbandoned());
    }
    if (config.getRemoveAbandonedTimeout() != null) {
        props.setRemoveAbandonedTimeout(config.getRemoveAbandonedTimeout());
    }
    if (config.isLogAbandoned() != null) {
        props.setLogAbandoned(config.isLogAbandoned());
    }
    props.setConnectionProperties(config.getConnectionProperties());
    props.setInitSQL(config.getInitSQL());
    props.setJdbcInterceptors(config.getJdbcInterceptors());
    if (config.getValidationInterval() != null) {
        props.setValidationInterval(config.getValidationInterval());
    }
    if (config.isJmxEnabled() != null) {
        props.setJmxEnabled(config.isJmxEnabled());
    }
    if (config.isFairQueue() != null) {
        props.setFairQueue(config.isFairQueue());
    }
    if (config.getAbandonWhenPercentageFull() != null) {
        props.setAbandonWhenPercentageFull(config.getAbandonWhenPercentageFull());
    }
    if (config.getMaxAge() != null) {
        props.setMaxAge(config.getMaxAge());
    }
    if (config.isUseEquals() != null) {
        props.setUseEquals(config.isUseEquals());
    }
    if (config.getSuspectTimeout() != null) {
        props.setSuspectTimeout(config.getSuspectTimeout());
    }
    if (config.isAlternateUsernameAllowed() != null) {
        props.setAlternateUsernameAllowed(config.isAlternateUsernameAllowed());
    }
    if (config.getDataSourceClassName() != null) {
        handleExternalDataSource(props, config);
    }
    return props;
}

From source file:org.wso2.carbon.datasource.ui.DataSourceManagementHelper.java

/**
 * Factory method to create a DataSourceInformation from HttpServletResuet
 *
 * @param request HttpServletRequest instance
 * @return A DataSourceInformation/*from   w  w w.  ja va 2 s  . c  om*/
 * @throws javax.servlet.ServletException Throws for any error during DataSourceInformation creation
 */
public static DataSourceInformation createDataSourceInformation(HttpServletRequest request)
        throws ServletException {

    ResourceBundle bundle = ResourceBundle.getBundle("org.wso2.carbon.datasource.ui.i18n.Resources",
            request.getLocale());
    String alias = request.getParameter("alias");
    if (alias == null || "".equals(alias)) {
        alias = request.getParameter("alias_hidden");
        if (alias == null || "".equals(alias)) {
            handleException(bundle.getString("ds.name.cannotfound.msg"));
        }
    }

    String diver = request.getParameter("driver");
    if (diver == null || "".equals(diver)) {
        handleException(bundle.getString("ds.driver.cannotfound.msg"));
    }

    String url = request.getParameter("url");
    if (url == null || "".equals(url)) {
        handleException(bundle.getString("ds.url.cannotfound.msg"));
    }
    DataSourceInformation dataSourceInformation = new DataSourceInformation();

    dataSourceInformation.setAlias(alias.trim());
    dataSourceInformation.setDatasourceName(alias.trim());
    dataSourceInformation.setDriver(diver.trim());
    dataSourceInformation.setUrl(url.trim());

    String user = request.getParameter("user");
    if (user != null && !"".equals(user)) {
        SecretInformation secretInfo;
        if (dataSourceInformation.getSecretInformation() == null) {
            secretInfo = new SecretInformation();
        } else {
            secretInfo = dataSourceInformation.getSecretInformation();
        }
        secretInfo.setUser(user.trim());
        dataSourceInformation.setSecretInformation(secretInfo);
    }
    String password = request.getParameter("password");
    if (password != null && !"".equals(password)) {
        SecretInformation secretInfo;
        if (dataSourceInformation.getSecretInformation() == null) {
            secretInfo = new SecretInformation();
        } else {
            secretInfo = dataSourceInformation.getSecretInformation();
        }
        secretInfo.setAliasSecret(password.trim());
        dataSourceInformation.setSecretInformation(secretInfo);
    }
    String dstype = request.getParameter("dstype");
    if ("peruserds".equals(dstype)) {
        dataSourceInformation.setType("PerUserPoolDataSource");
    }
    //        String dsName = request.getParameter("dsName");
    //        if (dsName != null && !"".equals(dsName)) {
    //            dataSourceInformation.setDatasourceName(dsName.trim());
    //        }
    String dsrepotype = request.getParameter("dsrepotype");
    if ("JNDI".equals(dsrepotype)) {
        dataSourceInformation.setRepositoryType(DataSourceConstants.PROP_REGISTRY_JNDI);
        StringBuffer buffer = new StringBuffer();
        buffer.append(DataSourceConstants.PROP_SYNAPSE_PREFIX_DS);
        buffer.append(DataSourceConstants.DOT_STRING);

        buffer.append(alias.trim());
        buffer.append(DataSourceConstants.DOT_STRING);
        // The prefix for root level jndiProperties
        String rootPrefix = buffer.toString();
        // setting naming provider
        Properties jndiEvn = new Properties();

        String icFactory = request.getParameter("icFactory");
        String providerUrl = request.getParameter("providerUrl");
        String providerPort = request.getParameter("providerPort");
        String providerType = request.getParameter("providerType");
        if (icFactory != null && !"".equals(icFactory)) {
            jndiEvn.setProperty(rootPrefix + DataSourceConstants.PROP_IC_FACTORY, icFactory.trim());
        }
        if ("url".equals(providerType)) {
            if (providerUrl != null && !"".equals(providerUrl)) {
                jndiEvn.setProperty(rootPrefix + DataSourceConstants.PROP_PROVIDER_URL, providerUrl.trim());
            }
        } else {
            if (providerPort != null && !"".equals(providerPort)) {
                jndiEvn.setProperty(rootPrefix + DataSourceConstants.PROP_PROVIDER_PORT, providerPort.trim());
            }
        }
        dataSourceInformation.setProperties(jndiEvn);
    }
    String autocommit = request.getParameter("autocommit");
    if (autocommit != null && !"".equals(autocommit)) {
        dataSourceInformation.setDefaultAutoCommit(Boolean.parseBoolean(autocommit.trim()));
    }
    String isolation = request.getParameter("isolation");
    if (isolation != null && !"".equals(isolation)) {
        if ("TRANSACTION_NONE".equals(isolation)) {
            dataSourceInformation.setDefaultTransactionIsolation(Connection.TRANSACTION_NONE);
        } else if ("TRANSACTION_READ_COMMITTED".equals(isolation.trim())) {
            dataSourceInformation.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
        } else if ("TRANSACTION_READ_UNCOMMITTED".equals(isolation.trim())) {
            dataSourceInformation.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
        } else if ("TRANSACTION_REPEATABLE_READ".equals(isolation.trim())) {
            dataSourceInformation.setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
        } else if ("TRANSACTION_SERIALIZABLE".equals(isolation.trim())) {
            dataSourceInformation.setDefaultTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
        }
    }
    String maxActive = request.getParameter("maxActive");
    if (maxActive != null && !"".equals(maxActive) && !maxActive.contains("int")) {
        try {
            dataSourceInformation.setMaxActive(Integer.parseInt(maxActive.trim()));
        } catch (NumberFormatException e) {
            handleException(bundle.getString("invalid.maxActive"));
        }
    }
    String maxIdle = request.getParameter("maxIdle");
    if (maxIdle != null && !"".equals(maxIdle) && !maxIdle.contains("int")) {
        try {
            dataSourceInformation.setMaxIdle(Integer.parseInt(maxIdle.trim()));
        } catch (NumberFormatException e) {
            handleException(bundle.getString("invalid.maxidle"));
        }
    }
    String maxopenstatements = request.getParameter("maxopenstatements");
    if (maxopenstatements != null && !"".equals(maxopenstatements) && !maxopenstatements.contains("int")) {
        try {
            dataSourceInformation.setMaxOpenPreparedStatements(Integer.parseInt(maxopenstatements.trim()));
        } catch (NumberFormatException e) {
            handleException(bundle.getString("invalid.MaxOpenStatements"));
        }
    }
    String maxWait = request.getParameter("maxWait");
    if (maxWait != null && !"".equals(maxWait) && !maxWait.contains("long")) {
        try {
            dataSourceInformation.setMaxWait(Long.parseLong(maxWait.trim()));
        } catch (NumberFormatException e) {
            handleException(bundle.getString("invalid.MaxWait"));
        }
    }
    String minIdle = request.getParameter("minIdle");
    if (minIdle != null && !"".equals(minIdle) && !minIdle.contains("int")) {
        try {
            dataSourceInformation.setMinIdle(Integer.parseInt(minIdle.trim()));
        } catch (NumberFormatException e) {
            handleException(bundle.getString("invalid.MinIdle"));
        }
    }
    String initialsize = request.getParameter("initialsize");
    if (initialsize != null && !"".equals(initialsize) && !initialsize.contains("int")) {
        try {
            dataSourceInformation.setInitialSize(Integer.parseInt(initialsize.trim()));
        } catch (NumberFormatException e) {
            handleException(bundle.getString("invalid.Initialsize"));
        }
    }
    String poolstatements = request.getParameter("poolstatements");
    if (poolstatements != null && !"".equals(poolstatements)) {
        dataSourceInformation.setPoolPreparedStatements(Boolean.parseBoolean(poolstatements.trim()));
    }
    String removeAbandoned = request.getParameter("removeAbandoned");
    if (removeAbandoned != null && !"".equals(removeAbandoned)) {
        dataSourceInformation.setRemoveAbandoned(Boolean.parseBoolean(removeAbandoned));
    }
    String removeAbandonedTimeout = request.getParameter("removeAbandonedTimeout");
    if (removeAbandonedTimeout != null && !"".equals(removeAbandonedTimeout)) {
        try {
            dataSourceInformation.setRemoveAbandonedTimeout(Integer.parseInt(removeAbandonedTimeout));
        } catch (NumberFormatException e) {
            handleException(bundle.getString("invalid.remove.abandoned.timeout"));
        }
    }
    String logAbandoned = request.getParameter("logAbandoned");
    if (logAbandoned != null && !"".equals(logAbandoned)) {
        dataSourceInformation.setLogAbandoned(Boolean.parseBoolean(logAbandoned));
    }
    String testonborrow = request.getParameter("testonborrow");
    if (testonborrow != null && !"".equals(testonborrow)) {
        dataSourceInformation.setTestOnBorrow(Boolean.parseBoolean(testonborrow.trim()));
    }
    String testwhileidle = request.getParameter("testwhileidle");
    if (testwhileidle != null && !"".equals(testwhileidle)) {
        dataSourceInformation.setTestWhileIdle(Boolean.parseBoolean(testwhileidle.trim()));
    }
    String validationquery = request.getParameter("validationquery");
    if (validationquery != null && !"".equals(validationquery)) {
        dataSourceInformation.setValidationQuery(validationquery.trim());
    }

    return dataSourceInformation;
}

From source file:org.wso2.carbon.datasource.ui.DataSourceManagementHelper.java

public static String toStringIsolation(int isolation) {
    switch (isolation) {
    case Connection.TRANSACTION_NONE: {
        return "TRANSACTION_NONE";
    }//from w w  w.  j  ava2 s.c  o  m
    case Connection.TRANSACTION_READ_COMMITTED: {
        return "TRANSACTION_READ_COMMITTED";
    }
    case Connection.TRANSACTION_READ_UNCOMMITTED: {
        return "TRANSACTION_READ_UNCOMMITTED";
    }
    case Connection.TRANSACTION_REPEATABLE_READ: {
        return "TRANSACTION_REPEATABLE_READ";
    }
    case Connection.TRANSACTION_SERIALIZABLE: {
        return "TRANSACTION_SERIALIZABLE";
    }
    default: {
        return "TRANSACTION_UNKNOWN";
    }
    }
}