Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright 2012 Pavel Ponec
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  *  Unless required by applicable law or agreed to in writing, software
  *  distributed under the License is distributed on an "AS IS" BASIS,
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
 
 package org.ujorm.orm;
 
Transaction manager.

Author(s):
Pavel Ponec
 
 final public class Transaction implements javax.transaction.Transaction{

    
Current Sessin
 
     final private Session session;
    
Null value means a root.
 
     final private Transaction parent;
    
Store of the savepoints
 
     final private Savepoint[] savepoints ;
    
JTA Status
 
     private int status;
    
Rollback only, default value is false
 
     private boolean rollbackOnly;
 
     @PackagePrivate Transaction(Session sessionTransaction parent) {
         this. = session;
         this. = parent;
         this. = .;
         this. = new Savepoint[session.getHandler().getDatabases().size()];
     }

    
Returns true, if the transactioni the ROOT.
 
     public boolean isRoot() {
         return ==null;
     }

    
Assign new Savepoint

Parameters:
db Database meta-model
conn Database connection
Throws:
java.lang.IllegalStateException An envelope for a run-time SQL exception
 
         final int pointer = ..of(db);
         if ([pointer] == null) {
             if (!=null) {
                 .assignSavepoint(dbconn);
             }
             try {
                 [pointer] = conn.setSavepoint();
                  = .;
             } catch (SQLException e) {
                 throw new IllegalStateException("Cant save Savepoint"e);
             }
         }
     }

    
Commit the current level of the beginTransaction.

Returns:
Return a parent Transaction or the value [@code null} for the root transaction.
 
     @Override
     public void commit() throws IllegalStateException {
         if (==. && !) {
              = .;
             .commit(truethis);
         } else if (this.) {
             throw new SecurityException("Transaction have got status ROLLBACK_ONLY");
         } else {
             throw new IllegalStateException("Transactíon state isn't STATUS_ACTIVE, but " + );
         }
     }

    
Rollback the current level of the beginTransaction.

Returns:
Return a parent Transaction or the value [@code null} for the root transaction.
 
     @Override
     public void rollback() throws IllegalStateException {
         if (==.) {
              = .;
            .commit(falsethis);
        } else {
            throw new IllegalStateException("Transactíon state isn't STATUS_ACTIVE, but " + );
        }
    }

    
Create a nested transaction
    public Transaction nestedTransaction() {
        return .beginTransaction();
    }

    
Get the current Session.

Returns:
Not null values
    public Session getSession() {
        return ;
    }

    
Returns a parent transaction.

Returns:
The null value means a root transaction-
        return ;
    }

    
Returns a Savepoint array or null in case a transaction root.
        return ;
    }

    
    public boolean delistResource(XAResource xaResint flagthrows IllegalStateException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    
    @Override
    public boolean enlistResource(XAResource xaResthrows IllegalStateException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    
    @Override
    public void registerSynchronization(Synchronization syncthrows IllegalStateException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    
Rollback transaction only, default value is false
    @Override
    public void setRollbackOnly() {
         = true;
    }

    
JTA Status
    @Override
    public int getStatus() {
        return ;
    }
New to GrepCode? Check out our FAQ X