Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * $Id: FBSavepoint.java 56942 2012-04-07 10:41:09Z mrotteveel $
   * 
   * Firebird Open Source J2ee connector - jdbc driver
   *
   * Distributable under LGPL license.
   * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html
   *
   * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * LGPL License for more details.
  *
  * This file was created by members of the firebird development team.
  * All individual contributions remain the Copyright (C) of those
  * individuals.  Contributors to this file are either listed here or
  * can be obtained from a CVS history command.
  *
  * All rights reserved.
  */
 package org.firebirdsql.jdbc;
 
Savepoint implementation.

Author(s):
Roman Rokytskyy
 
 @SuppressWarnings("deprecation")
 public class FBSavepoint implements SavepointFirebirdSavepoint {
     public static final String SAVEPOINT_ID_PREFIX = "svpt";
 
     private boolean valid = true;
     private int savepointId;
     private String name;
     private String serverId;
    
    
Create instance of this class.

Parameters:
id ID of the savepoint.
 
     public FBSavepoint(int id) {
         this. = id;
         this. = getSavepointServerId(id);
     }
    
    
Create instance of this class for the specified name.

Parameters:
name name of the savepoint.
 
     public FBSavepoint(String name) {
         this. = name;
         this. = getSavepointServerId(name);
     }
    
    
Generate a savepoint ID for the specified savepoint counter.

Parameters:
counter savepoint counter.
Returns:
valid savepoint ID.
 
     private String getSavepointServerId(int counter) {
         return  + counter;
     }
    
    
Generate a savepoint ID for the specified name.

Parameters:
name name of the savepoint.
Returns:
valid savepoint ID.
 
     private String getSavepointServerId(String name) {
         StringBuffer sb = new StringBuffer();
         
         sb.append('"');
         
         char[] data = name.toCharArray();
         for (int i = 0; i < data.lengthi++) {
             
             // we have to double quote quotes
             if (data[i] == '"'sb.append('"');
             
             sb.append(data[i]);
         }
         
         sb.append('"');
         
         return sb.toString();
     }
    
    
Get SQL server savepoint ID. This method generates correct ID for the savepoint that can be directly used in the SQL statement.

Returns:
valid server-side ID for the savepoint.
        return ;
    }
    
    
Get ID of the savepoint.
    public int getSavepointId() throws SQLException {
        if ( == null)
            return ;
        else
            throw new SQLException("Savepoint is named.");
    }

    
Get name of the savepoint.
    public String getSavepointName() throws SQLException {
        if ( == null)
            throw new SQLException("Savepoint is unnamed.");
        else
            return ;
    }
    
    
Check if this savepoint is named. This method is used internally to avoid unnecessary exception throwing.

Returns:
true if savepoint is named.
    boolean isNamed() {
        return  == null;
    }
    
    
Check if the savepoint is valid.

Returns:
true if savepoint is valid.
    boolean isValid() {
        return ;
    }
    
    
Make this savepoint invalid.
    void invalidate() {
        this. = false;
    }
    
    
Check if objects are equal. For unnamed savepoints their IDs are checked, otherwise their names.

Parameters:
obj object to test.
Returns:
true if obj is equal to this object.
    public boolean equals(Object obj) {
        if (obj == thisreturn true;
        if (!(obj instanceof FBSavepoint)) return false;
        
        FBSavepoint that = (FBSavepoint)obj;
        
        return this. == null ? 
            this. == that.savepointId : 
            this..equals(that.name); 
    }
    
    
Get hash code of this instance.
    public int hashCode() {
        return  == null ?  : .hashCode();
    }
New to GrepCode? Check out our FAQ X