Java Code Examples for java.sql.Connection.TRANSACTION_READ_COMMITTED

The following are Jave code examples for showing how to use TRANSACTION_READ_COMMITTED of the java.sql.Connection class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: dev-courses   File: RCData.java   View Source Code Vote up 6 votes
/**
 * Set Transaction Isolation level on the specified JDBC Connection
 */
public static void setTI(Connection c, String tiString)
        throws SQLException {
    int i = -1;
    if (tiString.equals("TRANSACTION_READ_UNCOMMITTED"))
        i = Connection.TRANSACTION_READ_UNCOMMITTED;
    if (tiString.equals("TRANSACTION_READ_COMMITTED"))
        i = Connection.TRANSACTION_READ_COMMITTED;
    if (tiString.equals("TRANSACTION_REPEATABLE_READ"))
        i = Connection.TRANSACTION_REPEATABLE_READ;
    if (tiString.equals("TRANSACTION_SERIALIZABLE"))
        i = Connection.TRANSACTION_SERIALIZABLE;
    if (tiString.equals("TRANSACTION_NONE"))
        i = Connection.TRANSACTION_NONE;
    if (i < 0) {
        throw new SQLException(
                "Trans. isol. value not supported by "
                + RCData.class.getName() + ": " + tiString);
    }
    c.setTransactionIsolation(i);
}
 
Example 2
Project: s-store   File: RCData.java   View Source Code Vote up 6 votes
static public void setTI(Connection c, String tiString)
        throws SQLException {
    int i = -1;
    if (tiString.equals("TRANSACTION_READ_UNCOMMITTED"))
        i = Connection.TRANSACTION_READ_UNCOMMITTED;
    if (tiString.equals("TRANSACTION_READ_COMMITTED"))
        i = Connection.TRANSACTION_READ_COMMITTED;
    if (tiString.equals("TRANSACTION_REPEATABLE_READ"))
        i = Connection.TRANSACTION_REPEATABLE_READ;
    if (tiString.equals("TRANSACTION_SERIALIZABLE"))
        i = Connection.TRANSACTION_SERIALIZABLE;
    if (tiString.equals("TRANSACTION_NONE"))
        i = Connection.TRANSACTION_NONE;
    if (i < 0) {
        throw new SQLException(
                "Trans. isol. value not supported by "
                + RCData.class.getName() + ": " + tiString);
    }
    c.setTransactionIsolation(i);
}
 
Example 3
Project: ProyectoPacientes   File: ConnectionTest.java   View Source Code Vote up 6 votes
/**
 * Tests isolation level functionality
 * 
 * @throws Exception
 *             if an error occurs
 */
public void testIsolationLevel() throws Exception {
    if (versionMeetsMinimum(4, 0)) {
        String[] isoLevelNames = new String[] { "Connection.TRANSACTION_NONE", "Connection.TRANSACTION_READ_COMMITTED",
                "Connection.TRANSACTION_READ_UNCOMMITTED", "Connection.TRANSACTION_REPEATABLE_READ", "Connection.TRANSACTION_SERIALIZABLE" };

        int[] isolationLevels = new int[] { Connection.TRANSACTION_NONE, Connection.TRANSACTION_READ_COMMITTED, Connection.TRANSACTION_READ_UNCOMMITTED,
                Connection.TRANSACTION_REPEATABLE_READ, Connection.TRANSACTION_SERIALIZABLE };

        DatabaseMetaData dbmd = this.conn.getMetaData();

        for (int i = 0; i < isolationLevels.length; i++) {
            if (dbmd.supportsTransactionIsolationLevel(isolationLevels[i])) {
                this.conn.setTransactionIsolation(isolationLevels[i]);

                assertTrue(
                        "Transaction isolation level that was set (" + isoLevelNames[i]
                                + ") was not returned, nor was a more restrictive isolation level used by the server",
                        this.conn.getTransactionIsolation() == isolationLevels[i] || this.conn.getTransactionIsolation() > isolationLevels[i]);
            }
        }
    }
}
 
Example 4
Project: dev-courses   File: RCData.java   View Source Code Vote up 6 votes
/**
 * Return a String representation for the given numerical
 * java.sql.Connection Transaction level.
 * <P>
 * Database implementations are free to provide their own transaction
 * isolation levels, so you can't depend upon this method to much.
 * </P>
 * Returns null, since DB implementations are free to provide
 */
public static String tiToString(int ti) {
    switch (ti) {
        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";
        case Connection.TRANSACTION_NONE:
            return "TRANSACTION_NONE";
    }
    return "Custom Transaction Isolation numerical value: " + ti;
}
 
Example 5
Project: aceql-http   File: TransactionUtil.java   View Source Code Vote up 6 votes
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 6
Project: BibliotecaPS   File: ConnectionTest.java   View Source Code Vote up 6 votes
/**
 * Tests isolation level functionality
 * 
 * @throws Exception
 *             if an error occurs
 */
public void testIsolationLevel() throws Exception {
    if (versionMeetsMinimum(4, 0)) {
        String[] isoLevelNames = new String[] { "Connection.TRANSACTION_NONE", "Connection.TRANSACTION_READ_COMMITTED",
                "Connection.TRANSACTION_READ_UNCOMMITTED", "Connection.TRANSACTION_REPEATABLE_READ", "Connection.TRANSACTION_SERIALIZABLE" };

        int[] isolationLevels = new int[] { Connection.TRANSACTION_NONE, Connection.TRANSACTION_READ_COMMITTED, Connection.TRANSACTION_READ_UNCOMMITTED,
                Connection.TRANSACTION_REPEATABLE_READ, Connection.TRANSACTION_SERIALIZABLE };

        DatabaseMetaData dbmd = this.conn.getMetaData();

        for (int i = 0; i < isolationLevels.length; i++) {
            if (dbmd.supportsTransactionIsolationLevel(isolationLevels[i])) {
                this.conn.setTransactionIsolation(isolationLevels[i]);

                assertTrue(
                        "Transaction isolation level that was set (" + isoLevelNames[i]
                                + ") was not returned, nor was a more restrictive isolation level used by the server",
                        this.conn.getTransactionIsolation() == isolationLevels[i] || this.conn.getTransactionIsolation() > isolationLevels[i]);
            }
        }
    }
}
 
Example 7
Project: github-test   File: DatabaseStatusChecker.java   View Source Code Vote up 5 votes
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
Project: dubbox-hystrix   File: DatabaseStatusChecker.java   View Source Code Vote up 5 votes
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
Project: dev-courses   File: JDBCBench.java   View Source Code Vote up 5 votes
void oneRound(String url, String user, String password,
              boolean transactions,
              boolean prepared) throws InterruptedException, SQLException {

    Vector      vClient  = new Vector();
    Thread      Client   = null;
    Enumeration e        = null;
    Connection  guardian = null;

    //
    this.transactions  = transactions;
    this.prepared_stmt = prepared;
    start_time         = System.currentTimeMillis();

    for (int i = 0; i < n_clients; i++) {
        Client = new ClientThread(n_txn_per_client, url, user, password,
                                  Connection.TRANSACTION_READ_COMMITTED);

        Client.start();
        vClient.addElement(Client);
    }

    /*
     ** Barrier to complete this test session
     */
    e = vClient.elements();

    while (e.hasMoreElements()) {
        Client = (Thread) e.nextElement();

        Client.join();
    }

    vClient.removeAllElements();
    reportDone();

    guardian = connect(url, user, password);

    checkSums(guardian);
    connectClose(guardian);
}
 
Example 10
Project: dubbocloud   File: DatabaseStatusChecker.java   View Source Code Vote up 5 votes
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 11
Project: jdk8u-jdk   File: CommonRowSetTests.java   View Source Code Vote up 5 votes
@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 12
Project: dev-courses   File: JDBCDatabaseMetaData.java   View Source Code Vote up 4 votes
/**
 * Retrieves this database's default transaction isolation level.  The
 * possible values are defined in <code>java.sql.Connection</code>.
 *
 * <!-- start release-specific documentation -->
 * <div class="ReleaseSpecificDocumentation">
 * <h3>HSQLDB-Specific Information</h3>
 *
 * Default isolation mode in version 2.0 is TRANSACTION_READ_COMMITED.
 * </div>
 * <!-- end release-specific documentation -->
 *
 * @return the default isolation level
 * @exception SQLException if a database access error occurs
 * @see JDBCConnection
 */
public int getDefaultTransactionIsolation() throws SQLException {

    ResultSet rs = execute("CALL DATABASE_ISOLATION_LEVEL()");

    rs.next();

    String result = rs.getString(1);

    rs.close();

    if (result.startsWith("READ COMMITTED")) {
        return Connection.TRANSACTION_READ_COMMITTED;
    }

    if (result.startsWith("READ UNCOMMITTED")) {
        return Connection.TRANSACTION_READ_UNCOMMITTED;
    }

    if (result.startsWith("SERIALIZABLE")) {
        return Connection.TRANSACTION_SERIALIZABLE;
    }

    return Connection.TRANSACTION_READ_COMMITTED;
}
 
Example 13
Project: parabuild-ci   File: jdbcDatabaseMetaData.java   View Source Code Vote up 3 votes
/**
 * Retrieves whether this database supports the given transaction
 * isolation level. <p>
 *
 * <!-- start release-specific documentation -->
 * <div class="ReleaseSpecificDocumentation">
 * <h3>HSQLDB-Specific Information</h3>
 * HSQLDB supports <code>TRANSACTION_READ_UNCOMMITED</code> in all cases
 * and the rest of the isolation levels where there is only one connection
 * to the database.
 * </div>
 * <!-- end release-specific documentation -->
 *
 *
 * @param level one of the transaction isolation levels defined in
 *         <code>java.sql.Connection</code>
 * @return <code>true</code> if so; <code>false</code> otherwise
 * @exception SQLException if a database access error occurs
 * @see jdbcConnection
 */
public boolean supportsTransactionIsolationLevel(int level)
throws SQLException {

    return level == Connection.TRANSACTION_READ_UNCOMMITTED
           || level == Connection.TRANSACTION_READ_COMMITTED
           || level == Connection.TRANSACTION_REPEATABLE_READ
           || level == Connection.TRANSACTION_SERIALIZABLE;
}
 
Example 14
Project: OpenDiabetes   File: JDBCDatabaseMetaData.java   View Source Code Vote up 3 votes
/**
 * Retrieves whether this database supports the given transaction isolation level.
 *
 * <!-- start release-specific documentation -->
 * <div class="ReleaseSpecificDocumentation">
 * <h3>HSQLDB-Specific Information</h3>
 * HSQLDB supports all levels.
 * </div>
 * <!-- end release-specific documentation -->
 *
 *
 * @param level one of the transaction isolation levels defined in
 *         <code>java.sql.Connection</code>
 * @return <code>true</code> if so; <code>false</code> otherwise
 * @exception SQLException if a database access error occurs
 * @see JDBCConnection
 */
public boolean supportsTransactionIsolationLevel(
        int level) throws SQLException {

    return level == Connection.TRANSACTION_READ_UNCOMMITTED
           || level == Connection.TRANSACTION_READ_COMMITTED
           || level == Connection.TRANSACTION_REPEATABLE_READ
           || level == Connection.TRANSACTION_SERIALIZABLE;
}
 
Example 15
Project: uroborosql   File: DataSourceConnectionSupplierImpl.java   View Source Code Vote up 3 votes
/**
 * {@link DataSourceConnectionSupplierImpl#setDefaultDataSourceName(String)}
 * で指定したデータソースに対するtransactionIsolationオプションの指定
 *
 * @see Connection#TRANSACTION_READ_UNCOMMITTED
 * @see Connection#TRANSACTION_READ_COMMITTED
 * @see Connection#TRANSACTION_REPEATABLE_READ
 * @see Connection#TRANSACTION_SERIALIZABLE
 *
 * @param dataSourceName データソース名
 * @param transactionIsolation transactionIsolationオプション
 *
 */
public void setTransactionIsolation(final String dataSourceName, final int transactionIsolation) {
	if (Connection.TRANSACTION_READ_UNCOMMITTED == transactionIsolation
			|| Connection.TRANSACTION_READ_COMMITTED == transactionIsolation
			|| Connection.TRANSACTION_REPEATABLE_READ == transactionIsolation
			|| Connection.TRANSACTION_SERIALIZABLE == transactionIsolation) {
		Map<String, String> props = getConnPropsByDataSourceName(dataSourceName);
		props.put(PROPS_TRANSACTION_ISOLATION, String.valueOf(transactionIsolation));
	} else {
		throw new IllegalArgumentException("Unsupported level [" + transactionIsolation + "]");
	}
}
 
Example 16
Project: parabuild-ci   File: jdbcDatabaseMetaData.java   View Source Code Vote up 3 votes
/**
 * Retrieves whether this database supports the given transaction
 * isolation level. <p>
 *
 * <!-- start release-specific documentation -->
 * <div class="ReleaseSpecificDocumentation">
 * <h3>HSQLDB-Specific Information</h3>
 * HSQLDB supports <code>TRANSACTION_READ_UNCOMMITED</code> in all cases
 * and the rest of the isolation levels where there is only one connection
 * to the database.
 * </div>
 * <!-- end release-specific documentation -->
 *
 *
 * @param level one of the transaction isolation levels defined in
 *         <code>java.sql.Connection</code>
 * @return <code>true</code> if so; <code>false</code> otherwise
 * @exception SQLException if a database access error occurs
 * @see jdbcConnection
 */
public boolean supportsTransactionIsolationLevel(int level)
throws SQLException {

    return level == Connection.TRANSACTION_READ_UNCOMMITTED
           || level == Connection.TRANSACTION_READ_COMMITTED
           || level == Connection.TRANSACTION_REPEATABLE_READ
           || level == Connection.TRANSACTION_SERIALIZABLE;
}
 
Example 17
Project: sstore-soft   File: JDBCDatabaseMetaData.java   View Source Code Vote up 2 votes
/**
 * Retrieves this database's default transaction isolation level.  The
 * possible values are defined in <code>java.sql.Connection</code>.
 *
 * <!-- start release-specific documentation -->
 * <div class="ReleaseSpecificDocumentation">
 * <h3>HSQLDB-Specific Information</h3>
 *
 * Default isolation mode in version 1.9.0 is TRANSACTION_READ_COMMITED.
 * </div>
 * <!-- end release-specific documentation -->
 *
 * @return the default isolation level
 * @exception SQLException if a database access error occurs
 * @see JDBCConnection
 */
public int getDefaultTransactionIsolation() throws SQLException {
    return Connection.TRANSACTION_READ_COMMITTED;
}
 
Example 18
Project: aliyun-maxcompute-data-collectors   File: SqlManager.java   View Source Code Vote up 2 votes
/**
 * @return the transaction isolation level to use for metadata queries
 * (queries executed by the ConnManager itself).
 */
protected int getMetadataIsolationLevel() {
  return Connection.TRANSACTION_READ_COMMITTED;
}
 
Example 19
Project: s-store   File: JDBCDatabaseMetaData.java   View Source Code Vote up 2 votes
/**
 * Retrieves this database's default transaction isolation level.  The
 * possible values are defined in <code>java.sql.Connection</code>.
 *
 * <!-- start release-specific documentation -->
 * <div class="ReleaseSpecificDocumentation">
 * <h3>HSQLDB-Specific Information</h3>
 *
 * Default isolation mode in version 1.9.0 is TRANSACTION_READ_COMMITED.
 * </div>
 * <!-- end release-specific documentation -->
 *
 * @return the default isolation level
 * @exception SQLException if a database access error occurs
 * @see JDBCConnection
 */
public int getDefaultTransactionIsolation() throws SQLException {
    return Connection.TRANSACTION_READ_COMMITTED;
}
 
Example 20
Project: DBus   File: SqlManager.java   View Source Code Vote up 2 votes
/**
 * @return the transaction isolation level to use for metadata queries
 * (queries executed by the ConnManager itself).
 */
protected int getMetadataIsolationLevel() {
  return Connection.TRANSACTION_READ_COMMITTED;
}