LockMode.java :  » Database-DBMS » Quadcap-Embeddable-Database » com » quadcap » sql » lock » Java Open Source

Java Open Source » Database DBMS » Quadcap Embeddable Database 
Quadcap Embeddable Database » com » quadcap » sql » lock » LockMode.java
package com.quadcap.sql.lock;

/* Copyright 1999 - 2003 Quadcap Software.  All rights reserved.
 *
 * This software is distributed under the Quadcap Free Software License.
 * This software may be used or modified for any purpose, personal or
 * commercial.  Open Source redistributions are permitted.  Commercial
 * redistribution of larger works derived from, or works which bundle
 * this software requires a "Commercial Redistribution License"; see
 * http://www.quadcap.com/purchase.
 *
 * Redistributions qualify as "Open Source" under  one of the following terms:
 *   
 *    Redistributions are made at no charge beyond the reasonable cost of
 *    materials and delivery.
 *
 *    Redistributions are accompanied by a copy of the Source Code or by an
 *    irrevocable offer to provide a copy of the Source Code for up to three
 *    years at the cost of materials and delivery.  Such redistributions
 *    must allow further use, modification, and redistribution of the Source
 *    Code under substantially the same terms as this license.
 *
 * Redistributions of source code must retain the copyright notices as they
 * appear in each source code file, these license terms, and the
 * disclaimer/limitation of liability set forth as paragraph 6 below.
 *
 * Redistributions in binary form must reproduce this Copyright Notice,
 * these license terms, and the disclaimer/limitation of liability set
 * forth as paragraph 6 below, in the documentation and/or other materials
 * provided with the distribution.
 *
 * The Software is provided on an "AS IS" basis.  No warranty is
 * provided that the Software is free of defects, or fit for a
 * particular purpose.  
 *
 * Limitation of Liability. Quadcap Software shall not be liable
 * for any damages suffered by the Licensee or any third party resulting
 * from use of the Software.
 */

import com.quadcap.util.Debug;

/**
 * Lock modes supported by this package.
 *
 * @author Stan Bailes
 */
public class LockMode {
    public static final int    NL  = 0;
    public static final int    IS  = 1;
    public static final int    IX  = 2;
    public static final int    S  = 3;
    public static final int    SIX  = 4;
    public static final int    X  = 5;
    public static final int    MAX  = 6;

    static final String[] modes = {
  "NL", "IS", "IX", "S", "SIX", "X"
    };

    public static final String toString(int mode) {
  return modes[mode];
    }

    static int[] impl = {
  0,                // NL
        
  ((1 << IS)),              // IS
        
  ((1 << IX) | (1 << IS)),          // IX
        
  ((1 << S) | (1 << IS)),            // S
        
  ((1 << SIX) | (1 << IX) | (1 << S) | (1 << IS) | (1 << SIX)),  // SIX
        
  ((1 << SIX) | (1 << IX) | (1 << S) | (1 << IS) | (1 << SIX)
      | (1 << X))              // X
    };
    
    /**
     * If you have mode 'a' already, do you even need to bother getting
     * mode 'b'?
     */
    public static boolean implies(int a, int b) {
  boolean ret = ((impl[a] >> b) & 1) != 0;
//   Debug.println(0, "implies(" + toString(a) + ", " + toString(b) +
//           ") = " + ret);
  return ret;
    }
}

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.