001/*
002 * Copyright 2015-2018 Transmogrify LLC.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.pyranid;
018
019import java.sql.Connection;
020import java.util.Optional;
021
022/**
023 * Strategies for database locking during transactional operations.
024 * 
025 * @author <a href="http://revetkn.com">Mark Allen</a>
026 * @since 1.0.0
027 */
028public enum TransactionIsolation {
029  /**
030   * Default isolation (DBMS-specific).
031   */
032  DEFAULT(Optional.empty()),
033
034  /**
035   * Maps to JDBC value {@link Connection#TRANSACTION_READ_COMMITTED}.
036   */
037  READ_COMMITTED(Optional.of(Connection.TRANSACTION_READ_COMMITTED)),
038
039  /**
040   * Maps to JDBC value {@link Connection#TRANSACTION_READ_UNCOMMITTED}.
041   */
042  READ_UNCOMMITTED(Optional.of(Connection.TRANSACTION_READ_UNCOMMITTED)),
043
044  /**
045   * Maps to JDBC value {@link Connection#TRANSACTION_REPEATABLE_READ}.
046   */
047  REPEATABLE_READ(Optional.of(Connection.TRANSACTION_REPEATABLE_READ)),
048
049  /**
050   * Maps to JDBC value {@link Connection#TRANSACTION_SERIALIZABLE}.
051   */
052  SERIALIZABLE(Optional.of(Connection.TRANSACTION_SERIALIZABLE));
053
054  private final Optional<Integer> jdbcLevel;
055
056  private TransactionIsolation(Optional<Integer> jdbcLevel) {
057    this.jdbcLevel = jdbcLevel;
058  }
059
060  Optional<Integer> jdbcLevel() {
061    return jdbcLevel;
062  }
063}