Java Code Examples for java.sql.Connection#TRANSACTION_REPEATABLE_READ

The following examples show how to use java.sql.Connection#TRANSACTION_REPEATABLE_READ . 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: micro-integrator   File: RDBMSUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static int toIntTransactionIsolation(String isolation) {
	if (isolation != null && !"".equals(isolation)) {
		if ("TRANSACTION_NONE".equals(isolation)) {
			return Connection.TRANSACTION_NONE;
		} else if ("TRANSACTION_READ_COMMITTED".equals(isolation.trim())) {
			return Connection.TRANSACTION_READ_COMMITTED;
		} else if ("TRANSACTION_READ_UNCOMMITTED".equals(isolation.trim())) {
			return Connection.TRANSACTION_READ_UNCOMMITTED;
		} else if ("TRANSACTION_REPEATABLE_READ".equals(isolation.trim())) {
			return Connection.TRANSACTION_REPEATABLE_READ;
		} else if ("TRANSACTION_SERIALIZABLE".equals(isolation.trim())) {
			return Connection.TRANSACTION_SERIALIZABLE;
		} else {
			return -1;
		}
	} else {
		return -1;
	}
}
 
Example 2
/**
 * Convert transaction isolation level name into a corresponding constant.
 *
 * @param isolationName
 *         name of the transaction isolation.
 * @return corresponding constant.
 */
public static int getTransactionIsolationLevel(String isolationName) {
    switch (isolationName) {
    case TRANSACTION_NONE:
        return Connection.TRANSACTION_NONE;
    case TRANSACTION_READ_UNCOMMITTED:
        return Connection.TRANSACTION_READ_UNCOMMITTED;
    case TRANSACTION_READ_COMMITTED:
        return Connection.TRANSACTION_READ_COMMITTED;
    case TRANSACTION_REPEATABLE_READ:
        return Connection.TRANSACTION_REPEATABLE_READ;
    case TRANSACTION_SERIALIZABLE:
        return Connection.TRANSACTION_SERIALIZABLE;
    default:
        throw new IllegalArgumentException("Invalid isolation name.");
    }
}
 
Example 3
private static String getTransactionIsolationAsString(
    int transactionIsolationLevel) {

if (transactionIsolationLevel == Connection.TRANSACTION_NONE) {
    return HttpParameter.NONE;
} else if (transactionIsolationLevel == Connection.TRANSACTION_READ_UNCOMMITTED) {
    return HttpParameter.READ_UNCOMMITTED;
} else if (transactionIsolationLevel == Connection.TRANSACTION_READ_COMMITTED) {
    return HttpParameter.READ_COMMITTED;
} else if (transactionIsolationLevel == Connection.TRANSACTION_REPEATABLE_READ) {
    return HttpParameter.REPEATABLE_READ;
} else if (transactionIsolationLevel == Connection.TRANSACTION_SERIALIZABLE) {
    return HttpParameter.SERIALIZABLE;
} else {
    return "UNKNOWN";
}
   }
 
Example 4
/**
 * 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 5
Source Project: gemfirexd-oss   File: Converters.java    License: Apache License 2.0 6 votes vote down vote up
public static int getJdbcIsolation(int thriftIsolationLevel) {
  switch (thriftIsolationLevel) {
    case gfxdConstants.TRANSACTION_NONE:
      return Connection.TRANSACTION_NONE;
    case gfxdConstants.TRANSACTION_READ_UNCOMMITTED:
      return Connection.TRANSACTION_READ_UNCOMMITTED;
    case gfxdConstants.TRANSACTION_READ_COMMITTED:
      return Connection.TRANSACTION_READ_COMMITTED;
    case gfxdConstants.TRANSACTION_REPEATABLE_READ:
      return Connection.TRANSACTION_REPEATABLE_READ;
    case gfxdConstants.TRANSACTION_SERIALIZABLE:
      return Connection.TRANSACTION_SERIALIZABLE;
    default:
      throw new IllegalArgumentException("Thrift isolation level="
          + thriftIsolationLevel);
  }
}
 
Example 6
Source Project: gemfirexd-oss   File: GFXDPrms.java    License: 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 " + nameForKey(key) + ": " + val;
      throw new HydraConfigException(s);
    }
  }
}
 
Example 7
Source Project: gemfirexd-oss   File: Converters.java    License: Apache License 2.0 6 votes vote down vote up
public static int getJdbcIsolation(int thriftIsolationLevel) {
  switch (thriftIsolationLevel) {
    case gfxdConstants.TRANSACTION_NONE:
      return Connection.TRANSACTION_NONE;
    case gfxdConstants.TRANSACTION_READ_UNCOMMITTED:
      return Connection.TRANSACTION_READ_UNCOMMITTED;
    case gfxdConstants.TRANSACTION_READ_COMMITTED:
      return Connection.TRANSACTION_READ_COMMITTED;
    case gfxdConstants.TRANSACTION_REPEATABLE_READ:
      return Connection.TRANSACTION_REPEATABLE_READ;
    case gfxdConstants.TRANSACTION_SERIALIZABLE:
      return Connection.TRANSACTION_SERIALIZABLE;
    default:
      throw new IllegalArgumentException("Thrift isolation level="
          + thriftIsolationLevel);
  }
}
 
Example 8
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 9
/**
 * 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 10
@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
/**
 * 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 12
/**
 * Sets the value of defaultTransactionIsolation, which defines the state of connections handed out from this pool.
 * The value can be changed on the Connection using Connection.setTransactionIsolation(int). The default is JDBC
 * driver dependent.
 *
 * @param v
 *            Value to assign to defaultTransactionIsolation
 */
public void setDefaultTransactionIsolation(final int v) {
    assertInitializationAllowed();
    switch (v) {
    case Connection.TRANSACTION_NONE:
    case Connection.TRANSACTION_READ_COMMITTED:
    case Connection.TRANSACTION_READ_UNCOMMITTED:
    case Connection.TRANSACTION_REPEATABLE_READ:
    case Connection.TRANSACTION_SERIALIZABLE:
        break;
    default:
        throw new IllegalArgumentException(BAD_TRANSACTION_ISOLATION);
    }
    this.defaultTransactionIsolation = v;
}
 
Example 13
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 14
@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 15
@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 16
@Override
protected int getIsolationLevel() {
  return Connection.TRANSACTION_REPEATABLE_READ;
}
 
Example 17
@Override
protected int getIsolationLevel() {
  return Connection.TRANSACTION_REPEATABLE_READ;
}
 
Example 18
@Override
protected int getIsolationLevel() {
  return Connection.TRANSACTION_REPEATABLE_READ;
}
 
Example 19
Source Project: requery   File: ConnectionTransaction.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Transaction begin(TransactionIsolation isolation) {
    if (active()) {
        throw new IllegalStateException("transaction already active");
    }
    try {
        transactionListener.beforeBegin(isolation);
        connection = connectionProvider.getConnection();
        uncloseableConnection = new UncloseableConnection(connection);
        if (supportsTransaction) {
            connection.setAutoCommit(false);
            if (isolation != null) {
                previousIsolationLevel = connection.getTransactionIsolation();
                int level;
                switch (isolation) {
                    case NONE:
                        level = Connection.TRANSACTION_NONE;
                        break;
                    case READ_UNCOMMITTED:
                        level = Connection.TRANSACTION_READ_UNCOMMITTED;
                        break;
                    case READ_COMMITTED:
                        level = Connection.TRANSACTION_READ_COMMITTED;
                        break;
                    case REPEATABLE_READ:
                        level = Connection.TRANSACTION_REPEATABLE_READ;
                        break;
                    case SERIALIZABLE:
                        level = Connection.TRANSACTION_SERIALIZABLE;
                        break;
                    default:
                        throw new UnsupportedOperationException();
                }
                connection.setTransactionIsolation(level);
            }
        }
        committed = false;
        rolledBack = false;
        entities.clear();
        transactionListener.afterBegin(isolation);
    } catch (SQLException e) {
        throw new TransactionException(e);
    }
    return this;
}
 
Example 20
/**
    * Does the database support the given transaction isolation level?
 *
 * DatabaseMetaData.supportsTransactionIsolation() should return false for
 * isolation levels that are not supported even if a higher level can be
 * substituted.
    *
    * @param level the values are defined in java.sql.Connection
    * @return true if so
    * @see Connection
	*/	
public boolean supportsTransactionIsolationLevel(int level)
						 {
	// REMIND: This is hard-coded for the moment because it doesn't nicely
	// fit within the framework we've set up for the rest of these values.
	// Part of the reason is that it has a parameter, so it's not just a
	// simple value look-up.  Some ideas for the future on how to make this
	// not hard-coded:
	//	  - code it as a query: "select true from <something> where ? in
	//      (a,b,c)" where a,b,c are the supported isolation levels.  The
	//      parameter would be set to "level".  This seems awfully awkward.
	//    - somehow what you'd really like is to enable the instructions
	//      file to contain the list, or set, of supported isolation
	//      levels.  Something like:
	//          supportsTr...ionLevel=SERIALIZABLE | REPEATABLE_READ | ...
	//      That would take some more code that doesn't seem worthwhile at
	//      the moment for this one case.

	/*
		REMIND: this could be moved into a query that is e.g.
		VALUES ( ? in (8,...) )
		so that database could control the list of supported
		isolations.  For now, it's hard coded, and just the one.
	 */

   // GemStone changes BEGIN
   /*
	return (level == Connection.TRANSACTION_SERIALIZABLE    ||
	        level == Connection.TRANSACTION_REPEATABLE_READ ||
		    level == Connection.TRANSACTION_READ_COMMITTED  ||
		    level == Connection.TRANSACTION_READ_UNCOMMITTED);
    */
  // Rahul : since revision 27539 of gemfirexd_dev_Feb10, three isolation
  // levels are supported, NONE, READ_UNCOMMITTED, READ_COMMITTED.
  // [sumedh] also added support for REPEATABLE_READ in the new TX impl
  return (level == Connection.TRANSACTION_READ_COMMITTED  ||
      level == Connection.TRANSACTION_REPEATABLE_READ ||
      level == Connection.TRANSACTION_READ_UNCOMMITTED ||
      level == Connection.TRANSACTION_NONE);
   
   // GemStone changes END 
}