Search in sources :

Example 1 with ReadWrite

use of org.apache.jena.query.ReadWrite in project jena by apache.

the class DatasetConnection method begin.

/**
     * Begins a new transaction
     * <p>
     * Transactions are typically thread scoped and are shared by each thread so
     * if there is an existing read transaction and another thread tries to
     * start a read transaction it will join the existing read transaction.
     * Trying to join a transaction not of the same type will produce an error.
     * </p>
     * 
     * @param type
     * @throws SQLException
     */
public synchronized void begin(ReadWrite type) throws SQLException {
    try {
        if (this.isClosed())
            throw new SQLException("Cannot start a transaction on a closed connection");
        if (this.getTransactionIsolation() == Connection.TRANSACTION_NONE)
            throw new SQLException("Cannot start a transaction when transaction isolation is set to NONE");
        if (ds.supportsTransactions()) {
            if (ds.isInTransaction()) {
                // Additional participant in existing transaction
                ReadWrite currType = this.transactionType.get();
                if (currType.equals(type)) {
                    this.transactionParticipants.set(this.transactionParticipants.get() + 1);
                } else {
                    throw new SQLException("Unable to start a transaction of a different type on the same thread as an existing transaction, please retry your operation on a different thread");
                }
            } else {
                // Starting a new transaction
                this.transactionType.set(type);
                this.transactionParticipants.set(1);
                this.ds.begin(type);
            }
        }
    } catch (SQLException e) {
        throw e;
    } catch (Exception e) {
        throw new SQLException("Unexpected error starting a transaction", e);
    }
}
Also used : SQLException(java.sql.SQLException) ReadWrite(org.apache.jena.query.ReadWrite) SQLException(java.sql.SQLException) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException)

Aggregations

SQLException (java.sql.SQLException)1 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 ReadWrite (org.apache.jena.query.ReadWrite)1