Java Code Examples for java.sql.Connection#TRANSACTION_SERIALIZABLE

The following examples show how to use java.sql.Connection#TRANSACTION_SERIALIZABLE . These examples are extracted from open source projects. 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 Project: gemfirexd-oss   File: GFXDPrms.java    License: Apache License 2.0 6 votes vote down vote up
public static String getTxIsolation(int n) {
  switch (n) {
    case TRANSACTION_NONE:
         return "none";
    case Connection.TRANSACTION_READ_UNCOMMITTED:
         return "read_uncommitted";
    case Connection.TRANSACTION_READ_COMMITTED:
         return "read_committed";
    case Connection.TRANSACTION_REPEATABLE_READ:
         return "repeatable_read";
    case Connection.TRANSACTION_SERIALIZABLE:
         return "serializable";
    default:
      String s = "Unknown transaction isolation level: " + n;
      throw new HydraConfigException(s);
  }
}
 
Example 2
/**
 * Convert transaction isolation level into string.
 *
 * @param isolationLevel
 *         transaction isolation level as integer constant.
 * @return corresponding string representation.
 */
public static String getTransactionIsolationName(int isolationLevel) {
    switch (isolationLevel) {
    case Connection.TRANSACTION_NONE:
        return TRANSACTION_NONE;

    case Connection.TRANSACTION_READ_UNCOMMITTED:
        return TRANSACTION_READ_UNCOMMITTED;

    case Connection.TRANSACTION_READ_COMMITTED:
        return TRANSACTION_READ_COMMITTED;

    case Connection.TRANSACTION_REPEATABLE_READ:
        return TRANSACTION_REPEATABLE_READ;

    case Connection.TRANSACTION_SERIALIZABLE:
        return TRANSACTION_SERIALIZABLE;

    default:
        throw new IllegalArgumentException("Incorrect transaction isolation level.");
    }
}
 
Example 3
/**
 * Get mapping for the specified transaction isolation level.
 *
 * @param transactionIsolation
 *         transaction isolation level.
 * @return set with TPB parameters.
 * @throws IllegalArgumentException
 *         if specified transaction isolation level is unknown.
 */
public TransactionParameterBuffer getMapping(int transactionIsolation) {
    switch (transactionIsolation) {
    case Connection.TRANSACTION_SERIALIZABLE:
    case Connection.TRANSACTION_REPEATABLE_READ:
    case Connection.TRANSACTION_READ_COMMITTED:
        return mapping.get(transactionIsolation).deepCopy();

    case Connection.TRANSACTION_READ_UNCOMMITTED:
        // promote transaction
        return mapping.get(Connection.TRANSACTION_READ_COMMITTED).deepCopy();

    case Connection.TRANSACTION_NONE:
    default:
        // TODO Throw SQLException instead?
        throw new IllegalArgumentException(
                "Transaction isolation level " + transactionIsolation + " is not supported.");
    }
}
 
Example 4
Source Project: Carbonado   File: JDBCRepository.java    License: Apache License 2.0 6 votes vote down vote up
static int mapIsolationLevelToJdbc(IsolationLevel level) {
    switch (level) {
    case NONE: default:
        return Connection.TRANSACTION_NONE;
    case READ_UNCOMMITTED:
        return Connection.TRANSACTION_READ_UNCOMMITTED;
    case READ_COMMITTED:
        return Connection.TRANSACTION_READ_COMMITTED;
    case REPEATABLE_READ:
        return Connection.TRANSACTION_REPEATABLE_READ;
    case SNAPSHOT:
        // TODO: not accurate for all databases.
        return Connection.TRANSACTION_SERIALIZABLE;
    case SERIALIZABLE:
        return Connection.TRANSACTION_SERIALIZABLE;
    }
}
 
Example 5
Source Project: gemfirexd-oss   File: QueryPerfPrms.java    License: Apache License 2.0 6 votes vote down vote up
public static String getTxIsolation(int n) {
  switch (n) {
    case TRANSACTION_NONE:
         return "none";
    case Connection.TRANSACTION_READ_UNCOMMITTED:
         return "transaction_read_uncommitted";
    case Connection.TRANSACTION_READ_COMMITTED:
         return "transaction_read_committed";
    case Connection.TRANSACTION_REPEATABLE_READ:
         return "transaction_repeatable_read";
    case Connection.TRANSACTION_SERIALIZABLE:
         return "transaction_serializable";
    default:
      String s = "Unknown transaction isolation level: " + n;
      throw new QueryPerfException(s);
  }
}
 
Example 6
Source Project: mdw   File: SystemServicesImpl.java    License: Apache License 2.0 5 votes vote down vote up
private String getTxIsolationLevel(int txIsolation) {
    if (txIsolation == Connection.TRANSACTION_NONE)
        return "NONE";
    else if (txIsolation == Connection.TRANSACTION_READ_UNCOMMITTED)
        return "READ_UNCOMMITED";
    else if (txIsolation == Connection.TRANSACTION_READ_COMMITTED)
        return "READ_COMMITTED";
    else if (txIsolation == Connection.TRANSACTION_REPEATABLE_READ)
        return "REPEATABLE_READ";
    else if (txIsolation == Connection.TRANSACTION_SERIALIZABLE)
        return "SERIALIZABLE";
    else
        return String.valueOf(txIsolation);
}
 
Example 7
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
@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 9
Source Project: gemfirexd-oss   File: OraclePrms.java    License: Apache License 2.0 5 votes vote down vote up
private static int getTxIsolation(Long key, String val) {
  if (val.equalsIgnoreCase("read_committed") ||
           val.equalsIgnoreCase("readCommitted")) {
    return Connection.TRANSACTION_READ_COMMITTED;
  }
  else if (val.equalsIgnoreCase("serializable")) {
    return Connection.TRANSACTION_SERIALIZABLE;
  }
  else {
    String s = "Illegal value for " + nameForKey(key) + ": " + val;
    throw new HydraConfigException(s);
  }
}
 
Example 10
Source Project: RDMP1   File: BaseTableDAO.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets database connection.
 */
protected void setConnection(Connection connection) throws SQLException {
	if (connection == null) {
		throw new SQLException("Invalid connection.");
	}

	if (connection.isClosed()) {
		throw new SQLException("Connection already closed.");
	}

	dbConnection = connection;

	if (connection.getTransactionIsolation() == Connection.TRANSACTION_READ_COMMITTED) {
		logger.debug("Transaction Isolation is TRANSACTION_READ_COMMITTED "
				+ connection);
	} else if (connection.getTransactionIsolation() == Connection.TRANSACTION_READ_UNCOMMITTED) {
		logger
				.debug("Transaction Isolation is TRANSACTION_READ_UNCOMMITTED "
						+ connection);
	} else if (connection.getTransactionIsolation() == Connection.TRANSACTION_REPEATABLE_READ) {
		logger
				.debug("Transaction Isolation is TRANSACTION_REPEATABLE_READ "
						+ connection);
	} else if (connection.getTransactionIsolation() == Connection.TRANSACTION_SERIALIZABLE) {
		logger.debug("Transaction Isolation is TRANSACTION_SERIALIZABLE "
				+ connection);
	}
}
 
Example 11
/**
 * 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 12
/**
 * Test SetTransactionResultSet
 */
public void testSetTransactionResultSet() throws Exception {
    // SetTransactionResultSet
    PreparedStatement[] setIsoLevel = new PreparedStatement[] {
        prepareStatement("set current isolation = read uncommitted"),
        prepareStatement("set current isolation = read committed"),
        prepareStatement("set current isolation = rs"),
        prepareStatement("set current isolation = serializable")
    };
    int[] expectedIsoLevel = new int[] {
        Connection.TRANSACTION_READ_UNCOMMITTED,
        Connection.TRANSACTION_READ_COMMITTED,
        Connection.TRANSACTION_REPEATABLE_READ,
        Connection.TRANSACTION_SERIALIZABLE
    };
    Connection c = getConnection();

    for (int i = 0; i < 20; ++i) {
        for (int iso = 0; iso < setIsoLevel.length; ++iso) {
            setIsoLevel[iso].execute();
            assertEquals("i="+i+" iso="+iso,expectedIsoLevel[iso],
                         c.getTransactionIsolation());
        }
    }
    for (int iso = 0; iso < setIsoLevel.length; ++iso) {
        setIsoLevel[iso].close();
    }
}
 
Example 13
@Before
public void setUp() throws SQLException {

	String isolation;
	Connection connection = dataSource.getConnection();
	switch (connection.getTransactionIsolation()) {
		case Connection.TRANSACTION_NONE:
			isolation = "None";
			break;
		case Connection.TRANSACTION_READ_UNCOMMITTED:
			isolation = "Read uncomitted";
			break;
		case Connection.TRANSACTION_READ_COMMITTED:
			isolation = "Read committed";
			break;
		case Connection.TRANSACTION_REPEATABLE_READ:
			isolation = "Repeatable read";
			break;
		case Connection.TRANSACTION_SERIALIZABLE:
			isolation = "Serializable";
			break;
		default:
			isolation = "Unknown";
	}
	log.info("Transaction isolation is: "+ isolation);

	sessionFactory.openStatelessSession(connection);
}
 
Example 14
private  int convertNativeIsolationToJDBC(int nativeIsolation)
{
    if(nativeIsolation== Isolations.REPEATED_READ)
    {
        return Connection.TRANSACTION_REPEATABLE_READ;
    }else
    if(nativeIsolation== Isolations.SERIALIZABLE)
    {
        return Connection.TRANSACTION_SERIALIZABLE;
    } else
    {
        return nativeIsolation;
    }
}
 
Example 15
/**
 * Test SetTransactionResultSet
 */
//GemFireXD does not support all these iso levels
//public void testSetTransactionResultSet() throws Exception {
public void _testSetTransactionResultSet() throws Exception {
    // SetTransactionResultSet
    PreparedStatement[] setIsoLevel = new PreparedStatement[] {
        prepareStatement("set current isolation = read uncommitted"),
        prepareStatement("set current isolation = read committed"),
        prepareStatement("set current isolation = rs"),
        prepareStatement("set current isolation = serializable")
    };
    int[] expectedIsoLevel = new int[] {
        Connection.TRANSACTION_READ_UNCOMMITTED,
        Connection.TRANSACTION_READ_COMMITTED,
        Connection.TRANSACTION_REPEATABLE_READ,
        Connection.TRANSACTION_SERIALIZABLE
    };
    Connection c = getConnection();

    for (int i = 0; i < 20; ++i) {
        for (int iso = 0; iso < setIsoLevel.length; ++iso) {
            setIsoLevel[iso].execute();
            assertEquals("i="+i+" iso="+iso,expectedIsoLevel[iso],
                         c.getTransactionIsolation());
        }
    }
    for (int iso = 0; iso < setIsoLevel.length; ++iso) {
        setIsoLevel[iso].close();
    }
}
 
Example 16
Source Project: gemfirexd-oss   File: SQLTxTest.java    License: Apache License 2.0 5 votes vote down vote up
protected void printIsolationLevel(Connection conn) {
  try {
  	int isolation = conn.getTransactionIsolation();
  	String isoLevel;
  	switch (isolation) {
  	case Connection.TRANSACTION_NONE:
  		isoLevel = "TRANSACTION_NONE";
  		break;
  	case Connection.TRANSACTION_READ_COMMITTED:
  		isoLevel = "TRANSACTION_READ_COMMITTED";
  		break;
  	case Connection.TRANSACTION_REPEATABLE_READ:
  		isoLevel = "TRANSACTION_REPEATABLE_READ";
  		break;
  	case Connection.TRANSACTION_SERIALIZABLE:
  		isoLevel = "TRANSACTION_SERIALIZABLE";
  		break;
 		default:
  			isoLevel = "unknown";    		    		
  	}
  	Log.getLogWriter().info("the connection isolation level is " + isoLevel);
  	java.sql.SQLWarning w =conn.getWarnings();
  	SQLHelper.printSQLWarning(w);
  } catch (SQLException se) {
  	
  }
}
 
Example 17
@Override
public void setDistributionStatistics(XPLAINDistPropsDescriptor distdesc,
    boolean processReplySend) {

  super.setDistributionStatistics(distdesc, processReplySend);

  // derive queryFlags
  {
    StringBuilder sb = new StringBuilder();
    if (isSelect())
      sb.append("is_select,");

    if (GemFireXDUtils.isSet(this.queryFlags, OPTIMIZE_FOR_WRITE))
      sb.append("optimizedForWrite,");

    if (allowSubqueryFlattening())
      sb.append("disallow_subquery_flattening,");

    if (isSpecialCaseOuterJoin())
      sb.append("is_outer_join_rr,");

    if (isSelectForUpdateAndNeedKeys())
      sb.append("select_for_update_need_key,");

    if (hasAuthId())
      sb.append("has_auth_id:").append(defaultSchema).append(",");

    if (needGfxdSubActivation())
      sb.append("need_gfxd_sub_activation,");

    if (statsEnabled())
      sb.append("enable_stats,");

    if (timeStatsEnabled())
      sb.append("enable_timestats,");

    if (explainConnectionEnabled())
      sb.append("explain_connection_mode,");

    if (isSkipListeners())
      sb.append("skip_listeners,");

    final TXStateInterface tx = getTXState();
    if (tx != null) {
      switch (tx.getIsolationLevel().getJdbcIsolationLevel()) {
        case Connection.TRANSACTION_NONE:
          sb.append("none,");
          break;
        case Connection.TRANSACTION_READ_COMMITTED:
          sb.append(XPLAINUtil.ISOLATION_READ_COMMIT).append(",");
          break;
        case Connection.TRANSACTION_READ_UNCOMMITTED:
          sb.append(XPLAINUtil.ISOLATION_READ_UNCOMMITED).append(",");
          break;
        case Connection.TRANSACTION_REPEATABLE_READ:
          sb.append(XPLAINUtil.ISOLATION_REPEAT_READ).append(",");
          break;
        case Connection.TRANSACTION_SERIALIZABLE:
          sb.append(XPLAINUtil.ISOLATION_SERIALIZABLE).append(",");
          break;
      }
    }
    distdesc.setMessageFlags(sb.toString());
  } // end of queryFlags
}
 
Example 18
@Override
public void setDistributionStatistics(XPLAINDistPropsDescriptor distdesc,
    boolean processReplySend) {

  super.setDistributionStatistics(distdesc, processReplySend);

  // derive queryFlags
  {
    StringBuilder sb = new StringBuilder();
    if (isSelect())
      sb.append("is_select,");

    if (GemFireXDUtils.isSet(this.queryFlags, OPTIMIZE_FOR_WRITE))
      sb.append("optimizedForWrite,");

    if (allowSubqueryFlattening())
      sb.append("disallow_subquery_flattening,");

    if (isSpecialCaseOuterJoin())
      sb.append("is_outer_join_rr,");

    if (isSelectForUpdateAndNeedKeys())
      sb.append("select_for_update_need_key,");

    if (hasAuthId())
      sb.append("has_auth_id:").append(defaultSchema).append(",");

    if (needGfxdSubActivation())
      sb.append("need_gfxd_sub_activation,");

    if (statsEnabled())
      sb.append("enable_stats,");

    if (timeStatsEnabled())
      sb.append("enable_timestats,");

    if (explainConnectionEnabled())
      sb.append("explain_connection_mode,");

    if (isSkipListeners())
      sb.append("skip_listeners,");

    final TXStateInterface tx = getTXState();
    if (tx != null) {
      switch (tx.getIsolationLevel().getJdbcIsolationLevel()) {
        case Connection.TRANSACTION_NONE:
          sb.append("none,");
          break;
        case Connection.TRANSACTION_READ_COMMITTED:
          sb.append(XPLAINUtil.ISOLATION_READ_COMMIT).append(",");
          break;
        case Connection.TRANSACTION_READ_UNCOMMITTED:
          sb.append(XPLAINUtil.ISOLATION_READ_UNCOMMITED).append(",");
          break;
        case Connection.TRANSACTION_REPEATABLE_READ:
          sb.append(XPLAINUtil.ISOLATION_REPEAT_READ).append(",");
          break;
        case Connection.TRANSACTION_SERIALIZABLE:
          sb.append(XPLAINUtil.ISOLATION_SERIALIZABLE).append(",");
          break;
      }
    }
    distdesc.setMessageFlags(sb.toString());
  } // end of queryFlags
}
 
Example 19
Source Project: gemfirexd-oss   File: Standard.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create an instance of this implementation.
 * Connection will be set to non auto commit
 * mode and SERIZIALZABLE isolation.
 */
public Standard(Connection conn) throws SQLException
{
    super(conn, false, Connection.TRANSACTION_SERIALIZABLE);
}
 
Example 20
Source Project: gemfirexd-oss   File: Standard.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create an instance of this implementation.
 * Connection will be set to non auto commit
 * mode and SERIZIALZABLE isolation.
 */
public Standard(Connection conn) throws SQLException
{
    super(conn, false, Connection.TRANSACTION_SERIALIZABLE);
}