Example usage for java.sql Connection TRANSACTION_READ_COMMITTED

List of usage examples for java.sql Connection TRANSACTION_READ_COMMITTED

Introduction

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

Prototype

int TRANSACTION_READ_COMMITTED

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

Click Source Link

Document

A constant indicating that dirty reads are prevented; non-repeatable reads and phantom reads can occur.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();

    DatabaseMetaData dbMd = conn.getMetaData();
    if (dbMd.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED)) {
        System.out.println("Transaction Isolation level " + "TRANSACTION_READ_COMMITTED is supported.");
        conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    }//from   ww  w  .j a  va  2 s.co  m

    conn.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    int tx = conn.getMetaData().getDefaultTransactionIsolation();
    String txtxt = null;/*  w  w  w.  ja  va2 s  .  co m*/
    switch (tx) {
    case Connection.TRANSACTION_NONE:
        txtxt = "TRANSACTION_NONE";
        break;
    case Connection.TRANSACTION_READ_COMMITTED:
        txtxt = "TRANSACTION_READ_COMMITTED";
        break;
    case Connection.TRANSACTION_READ_UNCOMMITTED:
        txtxt = "TRANSACTION_READ_UNCOMMITTED";
        break;
    case Connection.TRANSACTION_REPEATABLE_READ:
        txtxt = "TRANSACTION_REPEATABLE_READ";
        break;
    case Connection.TRANSACTION_SERIALIZABLE:
        txtxt = "TRANSACTION_SERIALIZABLE";
        break;
    default:
        txtxt = "UNKNOWN!!";
    }
    System.out.println(txtxt);
    conn.setTransactionIsolation(tx);
    System.out.println("Done");
    conn.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
    System.out.println("TX is now " + conn.getTransactionIsolation());
}

From source file:TXInfo.java

public static void main(String[] a) throws Exception {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:MusicVideo");
    int tx = con.getMetaData().getDefaultTransactionIsolation();
    String txtxt = null;//from  w  w w .  j  a va 2 s  .com
    switch (tx) {
    case Connection.TRANSACTION_NONE:
        txtxt = "TRANSACTION_NONE";
        break;
    case Connection.TRANSACTION_READ_COMMITTED:
        txtxt = "TRANSACTION_READ_COMMITTED";
        break;
    case Connection.TRANSACTION_READ_UNCOMMITTED:
        txtxt = "TRANSACTION_READ_UNCOMMITTED";
        break;
    case Connection.TRANSACTION_REPEATABLE_READ:
        txtxt = "TRANSACTION_REPEATABLE_READ";
        break;
    case Connection.TRANSACTION_SERIALIZABLE:
        txtxt = "TRANSACTION_SERIALIZABLE";
        break;
    default:
        txtxt = "UNKNOWN!!";
    }
    System.out.println(txtxt);
    con.setTransactionIsolation(tx);
    System.out.println("Done");
    con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
    System.out.println("TX is now " + con.getTransactionIsolation());
}

From source file:com.github.akiraly.db4j.pool.DbcpUtils.java

public static BasicDataSource newDefaultDS() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDefaultAutoCommit(false);

    dataSource.setDefaultQueryTimeout(1);
    dataSource.setValidationQueryTimeout(1);
    dataSource.setMaxWaitMillis(5000);/*from w  w w  .ja va  2s  .c  o m*/

    dataSource.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);

    dataSource.setInitialSize(4);
    dataSource.setMinIdle(4);
    dataSource.setMaxIdle(8);
    dataSource.setMaxTotal(16);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setMaxOpenPreparedStatements(128);
    return dataSource;
}

From source file:org.wso2.carbon.identity.agent.outbound.server.util.DatabaseUtil.java

/**
 * Get database connection.//from  w ww  .  j  ava 2  s. c  om
 * @return SQL connection
 * @throws SQLException
 */
public static Connection getDBConnection() throws SQLException {
    Connection dbConnection = getJDBCDataSource().getConnection();
    dbConnection.setAutoCommit(false);
    if (dbConnection.getTransactionIsolation() != java.sql.Connection.TRANSACTION_READ_COMMITTED) {
        dbConnection.setTransactionIsolation(java.sql.Connection.TRANSACTION_READ_COMMITTED);
    }
    return dbConnection;
}

From source file:org.geotools.data.mysql.MySQLTestSetup.java

@Override
protected void initializeDataSource(BasicDataSource ds, Properties db) {
    super.initializeDataSource(ds, db);

    ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
}

From source file:org.spring.data.gemfire.app.dao.vendor.SQLFireHibernateJpaVendorAdapter.java

@Override
public Map<String, Object> getJpaPropertyMap() {
    Map<String, Object> jpaPropertyMap = super.getJpaPropertyMap();
    jpaPropertyMap.put("hibernate.connection.isolation", String.valueOf(Connection.TRANSACTION_READ_COMMITTED));
    return jpaPropertyMap;
}

From source file:iudex.da.ContentUpdater.java

/**
 * Update first any content REFERENCES and then the content itself.
 *///w w w.j av a 2  s  .c  o  m
public void update(UniMap content) throws SQLException {
    Connection conn = dataSource().getConnection();
    try {
        conn.setAutoCommit(false);
        conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
        //FIXME: Correct isolation?

        List<UniMap> refs = content.get(ContentKeys.REFERENCES);
        if (refs != null) {
            update(refs, conn);
        }

        UniMap referer = content.get(ContentKeys.REFERER);
        if (referer != null) {
            //FIXME: Really sufficient as same path as content?
            update(referer, conn);
        }

        update(content, conn);

        conn.commit();
    } finally {
        if (conn != null)
            conn.close();
    }
}

From source file:nl.tudelft.stocktrader.derby.AbstractDerbyDAO.java

public void beginTransaction() throws DAOException {
    logger.debug("AbstractMSSQLDAO.beginTransaction()");
    try {/*from   w w w. ja va 2  s  .  c om*/
        sqlConnection.setAutoCommit(false);
        previousTransactionIsolation = sqlConnection.getTransactionIsolation();
        sqlConnection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    } catch (SQLException e) {
        e.printStackTrace();
        logger.debug("", e);
        throw new DAOException("Exception was thrown during the start of transaction", e);
    }
}

From source file:hermes.store.jdbc.JDBCConnectionPool.java

protected Connection makeObject() throws HermesException {
    try {// www  .  ja va  2s .  c  o  m
        Connection connection = DriverManager.getConnection(url);

        connection.setAutoCommit(autoCommit);
        connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
        return connection;
    } catch (Exception e) {
        log.error(e.getMessage(), e);

        throw new HermesException(e);
    }
}