Java Code Examples for java.sql.Connection#TRANSACTION_READ_COMMITTED

The following examples show how to use java.sql.Connection#TRANSACTION_READ_COMMITTED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: J2EEDataSourceTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private void assertIsoLocks(Connection conn, int expectedIsoLevel)
throws SQLException {
    int conniso = conn.getTransactionIsolation();
    assertEquals(expectedIsoLevel, conniso);

    boolean selectTimedOut = selectTimesoutDuringUpdate(conn);
    // expect a lock timeout for READ_COMMITTED
    switch (conniso) {
        case Connection.TRANSACTION_READ_UNCOMMITTED:
            assertFalse(selectTimedOut); break;
        case Connection.TRANSACTION_READ_COMMITTED:
            assertTrue(selectTimedOut); break;
        default:
            System.out.println("No test support for isolation level");
    }
}
 
Example 2
Source File: Converters.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static byte getThriftTransactionIsolation(int jdbcIsolationLevel) {
  switch (jdbcIsolationLevel) {
    case Connection.TRANSACTION_NONE:
      return gfxdConstants.TRANSACTION_NONE;
    case Connection.TRANSACTION_READ_UNCOMMITTED:
      return gfxdConstants.TRANSACTION_READ_UNCOMMITTED;
    case Connection.TRANSACTION_READ_COMMITTED:
      return gfxdConstants.TRANSACTION_READ_COMMITTED;
    case Connection.TRANSACTION_REPEATABLE_READ:
      return gfxdConstants.TRANSACTION_REPEATABLE_READ;
    case Connection.TRANSACTION_SERIALIZABLE:
      return gfxdConstants.TRANSACTION_SERIALIZABLE;
    default:
      return gfxdConstants.TRANSACTION_NO_CHANGE;
  }
}
 
Example 3
Source File: GFXDPrms.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private static int getTxIsolation(Long key, String val) {
  if (val.equalsIgnoreCase("none")) {
    return TRANSACTION_NONE;
  }
  else {
    if (val.equalsIgnoreCase("read_uncommitted") ||
        val.equalsIgnoreCase("readUncommitted")) {
      return Connection.TRANSACTION_READ_UNCOMMITTED;
    }
    else if (val.equalsIgnoreCase("read_committed") ||
             val.equalsIgnoreCase("readCommitted")) {
      return Connection.TRANSACTION_READ_COMMITTED;
    }
    else if (val.equalsIgnoreCase("repeatable_read") ||
             val.equalsIgnoreCase("repeatableRead")) {
      return Connection.TRANSACTION_REPEATABLE_READ;
    }
    else if (val.equalsIgnoreCase("serializable")) {
      return Connection.TRANSACTION_SERIALIZABLE;
    }
    else {
      String s = "Illegal value for " + BasePrms.nameForKey(key) + ": " + val;
      throw new HydraConfigException(s);
    }
  }
}
 
Example 4
Source File: TransactionUtil.java    From aceql-http with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static int getTransactionIsolation(String actionValue) {

	if (actionValue.equals(HttpParameter.READ_UNCOMMITTED)) {
	    return Connection.TRANSACTION_READ_UNCOMMITTED;
	} else if (actionValue.equals(HttpParameter.READ_COMMITTED)) {
	    return Connection.TRANSACTION_READ_COMMITTED;
	} else if (actionValue.equals(HttpParameter.REPEATABLE_READ)) {
	    return Connection.TRANSACTION_REPEATABLE_READ;
	} else if (actionValue.equals(HttpParameter.SERIALIZABLE)) {
	    return Connection.TRANSACTION_SERIALIZABLE;
	} else {
	    throw new IllegalArgumentException(
		    "Unsupported Transaction Isolation Level: " + actionValue);
	}
    }
 
Example 5
Source File: OraclePrms.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static String getTxIsolation(int n) {
  switch (n) {
    case Connection.TRANSACTION_READ_COMMITTED:
         return "read_committed";
    case Connection.TRANSACTION_SERIALIZABLE:
         return "serializable";
    default:
      String s = "Unknown transaction isolation level: " + n;
      throw new HydraConfigException(s);
  }
}
 
Example 6
Source File: QueryPerfPrms.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private static int getTxIsolation(Long key, String val) {
  if (val.equalsIgnoreCase("transaction_none") ||
      val.equalsIgnoreCase("transactionNone") ||
      val.equalsIgnoreCase("none")) {
    return TRANSACTION_NONE;
  }
  else {
    if (val.equalsIgnoreCase("transaction_read_uncommitted") ||
        val.equalsIgnoreCase("transactionReadUncommitted") ||
        val.equalsIgnoreCase("read_uncommitted") ||
        val.equalsIgnoreCase("readUncommitted")) {
      return Connection.TRANSACTION_READ_UNCOMMITTED;
    }
    else if (val.equalsIgnoreCase("transaction_read_committed") ||
             val.equalsIgnoreCase("transactionReadCommitted") ||
             val.equalsIgnoreCase("read_committed") ||
             val.equalsIgnoreCase("readCommitted")) {
      return Connection.TRANSACTION_READ_COMMITTED;
    }
    else if (val.equalsIgnoreCase("transaction_repeatable_read") ||
             val.equalsIgnoreCase("transactionRepeatableRead") ||
             val.equalsIgnoreCase("repeatable_read") ||
             val.equalsIgnoreCase("repeatableRead")) {
      return Connection.TRANSACTION_REPEATABLE_READ;
    }
    else if (val.equalsIgnoreCase("transaction_serializable") ||
             val.equalsIgnoreCase("transactionSerializable") ||
             val.equalsIgnoreCase("serializable")) {
      return Connection.TRANSACTION_SERIALIZABLE;
    }
    else {
      String s = "Illegal value for " + BasePrms.nameForKey(key) + ": " + val;
      throw new HydraConfigException(s);
    }
  }
}
 
Example 7
Source File: DatabaseStatusChecker.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private String getIsolation(int i) {
    if (i == Connection.TRANSACTION_READ_COMMITTED) {
        return "READ_COMMITTED";
    }
    if (i == Connection.TRANSACTION_READ_UNCOMMITTED) {
        return "READ_UNCOMMITTED";
    }
    if (i == Connection.TRANSACTION_REPEATABLE_READ) {
        return "REPEATABLE_READ";
    }
    if (i == Connection.TRANSACTION_SERIALIZABLE) {
        return "SERIALIZABLE)";
    }
    return "NONE";
}
 
Example 8
Source File: DatabaseStatusChecker.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private String getIsolation(int i) {
    if (i == Connection.TRANSACTION_READ_COMMITTED) {
        return "READ_COMMITTED";
    }
    if (i == Connection.TRANSACTION_READ_UNCOMMITTED) {
        return "READ_UNCOMMITTED";
    }
    if (i == Connection.TRANSACTION_REPEATABLE_READ) {
        return "REPEATABLE_READ";
    }
    if (i == Connection.TRANSACTION_SERIALIZABLE) {
        return "SERIALIZABLE)";
    }
    return "NONE";
}
 
Example 9
Source File: RuntimeStatisticsParser.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Create a RuntimeStatistics object to parse the text and extract
 * information.
 * 
 * @param rts
 *            Runtime Statistics string
 * 
 */
public RuntimeStatisticsParser(String rts) {
	statistics = rts;
    if (rts.indexOf(" at serializable isolation level ") != -1)
        isolationLevel = Connection.TRANSACTION_SERIALIZABLE;
    else if (rts.indexOf("at read uncommitted isolation level") != -1)
        isolationLevel = Connection.TRANSACTION_READ_UNCOMMITTED;
    else if (rts.indexOf("at read committed isolation level") != -1)
        isolationLevel = Connection.TRANSACTION_READ_COMMITTED;
    else if (rts.indexOf("at repeatable read isolation level") != -1)
        isolationLevel = Connection.TRANSACTION_REPEATABLE_READ;

    if (rts.indexOf("Distinct Scan ResultSet") > 0) {
    	distinctScan = true;
    }
    
    if (rts.indexOf("Table Scan ResultSet") > 0) {
    	tableScan = true;
    }

    indexScan = (rts.indexOf("Index Scan ResultSet") >= 0);
    indexRowToBaseRow =
        (rts.indexOf("Index Row to Base Row ResultSet") >= 0);
    
    if (rts.indexOf("Eliminate duplicates = true") > 0) {
    	eliminatedDuplicates = true;
    }
    if (rts.indexOf("Scroll Insensitive ResultSet:") > 0)
        scrollInsensitive = true;

    qualifiers = findQualifiers();
}
 
Example 10
Source File: CommonRowSetTests.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "rowSetIsolationTypes")
protected Object[][] rowSetIsolationTypes() throws Exception {
    RowSet rs = newInstance();

    return new Object[][]{
        {rs, Connection.TRANSACTION_NONE},
        {rs, Connection.TRANSACTION_READ_COMMITTED},
        {rs, Connection.TRANSACTION_READ_UNCOMMITTED},
        {rs, Connection.TRANSACTION_REPEATABLE_READ},
        {rs, Connection.TRANSACTION_SERIALIZABLE}
    };
}
 
Example 11
Source File: DRDAConnectResponse.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
/**
    * Parse the initial PBSD - PiggyBackedSessionData code point.
    * <p>
    * If sent by the server, it contains a PBSD_ISO code point followed by a
    * byte representing the JDBC isolation level, and a PBSD_SCHEMA code point
    * followed by the name of the current schema as an UTF-8 String.
    */
   private void parseInitialPBSD() {
       if (peekCodePoint() != CodePoint.PBSD) {
           return;
       }
       parseLengthAndMatchCodePoint(CodePoint.PBSD);
       int peekCP = peekCodePoint();
       while (peekCP != END_OF_SAME_ID_CHAIN) {
           parseLengthAndMatchCodePoint(peekCP);
           switch (peekCP) {
               case CodePoint.PBSD_ISO:
                   int isolationLevel = readUnsignedByte();
                   if (isolationLevel != Connection.TRANSACTION_READ_COMMITTED)
                       throw new IllegalStateException("Database using unsupported transaction isolation level: " + isolationLevel);
//                   netAgent_.netConnection_.
//                       completeInitialPiggyBackIsolation(readUnsignedByte());
                   break;
               case CodePoint.PBSD_SCHEMA:
                   String pbSchema = readString(getDdmLength(), CCSIDConstants.UTF8);
//                   netAgent_.netConnection_.
//                       completeInitialPiggyBackSchema
//                           (readString(getDdmLength(), Typdef.UTF8ENCODING));
                   break;
               default:
                   throw new IllegalStateException("Found unknown codepoint: " + Integer.toHexString(peekCP));
           }
           peekCP = peekCodePoint();
       }
   }
 
Example 12
Source File: SnowflakeDatabaseMetaData.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
@Override
public boolean supportsTransactionIsolationLevel(int level)
throws SQLException
{
  logger.debug(
      "public boolean supportsTransactionIsolationLevel(int level)");
  raiseSQLExceptionIfConnectionIsClosed();
  return (level == Connection.TRANSACTION_NONE)
         || (level == Connection.TRANSACTION_READ_COMMITTED);
}
 
Example 13
Source File: Db.java    From jqm with Apache License 2.0 5 votes vote down vote up
/**
 * A connection to the database. Should be short-lived. No transaction active by default.
 *
 * @return a new open connection.
 */
public DbConn getConn()
{
    Connection cnx = null;
    try
    {
        Thread.interrupted(); // this is VERY sad. Needed for Oracle driver which otherwise fails spectacularly.
        cnx = _ds.getConnection();
        if (cnx.getAutoCommit())
        {
            cnx.setAutoCommit(false);
            cnx.rollback(); // To ensure no open transaction created by the pool before changing TX mode
        }

        if (cnx.getTransactionIsolation() != Connection.TRANSACTION_READ_COMMITTED)
        {
            cnx.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
        }

        return new DbConn(this, cnx);
    }
    catch (SQLException e)
    {
        DbHelper.closeQuietly(cnx); // May have been left open when the pool has given us a failed connection.
        throw new DatabaseException(e);
    }
}
 
Example 14
Source File: DatabaseStatusChecker.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private String getIsolation(int i) {
    if (i == Connection.TRANSACTION_READ_COMMITTED) {
        return "READ_COMMITTED";
    }
    if (i == Connection.TRANSACTION_READ_UNCOMMITTED) {
        return "READ_UNCOMMITTED";
    }
    if (i == Connection.TRANSACTION_REPEATABLE_READ) {
        return "REPEATABLE_READ";
    }
    if (i == Connection.TRANSACTION_SERIALIZABLE) {
        return "SERIALIZABLE)";
    }
    return "NONE";
}
 
Example 15
Source File: CommonRowSetTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "rowSetIsolationTypes")
protected Object[][] rowSetIsolationTypes() throws Exception {
    RowSet rs = newInstance();

    return new Object[][]{
        {rs, Connection.TRANSACTION_NONE},
        {rs, Connection.TRANSACTION_READ_COMMITTED},
        {rs, Connection.TRANSACTION_READ_UNCOMMITTED},
        {rs, Connection.TRANSACTION_REPEATABLE_READ},
        {rs, Connection.TRANSACTION_SERIALIZABLE}
    };
}
 
Example 16
Source File: QueryPerfPrms.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private static int getTxIsolation(Long key, String val) {
  if (val.equalsIgnoreCase("transaction_none") ||
      val.equalsIgnoreCase("transactionNone") ||
      val.equalsIgnoreCase("none")) {
    return TRANSACTION_NONE;
  }
  else {
    if (val.equalsIgnoreCase("transaction_read_uncommitted") ||
        val.equalsIgnoreCase("transactionReadUncommitted") ||
        val.equalsIgnoreCase("read_uncommitted") ||
        val.equalsIgnoreCase("readUncommitted")) {
      return Connection.TRANSACTION_READ_UNCOMMITTED;
    }
    else if (val.equalsIgnoreCase("transaction_read_committed") ||
             val.equalsIgnoreCase("transactionReadCommitted") ||
             val.equalsIgnoreCase("read_committed") ||
             val.equalsIgnoreCase("readCommitted")) {
      return Connection.TRANSACTION_READ_COMMITTED;
    }
    else if (val.equalsIgnoreCase("transaction_repeatable_read") ||
             val.equalsIgnoreCase("transactionRepeatableRead") ||
             val.equalsIgnoreCase("repeatable_read") ||
             val.equalsIgnoreCase("repeatableRead")) {
      return Connection.TRANSACTION_REPEATABLE_READ;
    }
    else if (val.equalsIgnoreCase("transaction_serializable") ||
             val.equalsIgnoreCase("transactionSerializable") ||
             val.equalsIgnoreCase("serializable")) {
      return Connection.TRANSACTION_SERIALIZABLE;
    }
    else {
      String s = "Illegal value for " + BasePrms.nameForKey(key) + ": " + val;
      throw new HydraConfigException(s);
    }
  }
}
 
Example 17
Source File: JDBCUserStoreManager.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * @return
 * @throws SQLException
 * @throws UserStoreException
 */
protected Connection getDBConnection() throws SQLException, UserStoreException {
    Connection dbConnection = getJDBCDataSource().getConnection();
    dbConnection.setAutoCommit(false);
    if (dbConnection.getTransactionIsolation() != Connection.TRANSACTION_READ_COMMITTED) {
        dbConnection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    }
    return dbConnection;
}
 
Example 18
Source File: SingleHopRRTransactionDUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
@Override
public int getIsolationLevel() {
  return Connection.TRANSACTION_READ_COMMITTED;
}
 
Example 19
Source File: SelectForUpdateTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
protected int getIsolationLevel() {
  return Connection.TRANSACTION_READ_COMMITTED;
}
 
Example 20
Source File: TransactionBugsReportedDUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
protected int getIsolationLevel() {
  return Connection.TRANSACTION_READ_COMMITTED;
}