buildframework/helium/sf/java/jpa/src/com/nokia/helium/jpa/ORMCommitCount.java
changeset 628 7c4a911dc066
parent 588 c7c26511138f
child 629 541af5ee3ed9
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
     1 
       
     2 /*
       
     3  * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     4  * All rights reserved.
       
     5  * This component and the accompanying materials are made available
       
     6  * under the terms of the License "Eclipse Public License v1.0"
       
     7  * which accompanies this distribution, and is available
       
     8  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9  *
       
    10  * Initial Contributors:
       
    11  * Nokia Corporation - initial contribution.
       
    12  *
       
    13  * Contributors:
       
    14  *
       
    15  * Description:  
       
    16  *
       
    17  */
       
    18 
       
    19 package com.nokia.helium.jpa;
       
    20 
       
    21 import org.apache.log4j.Logger;
       
    22 import javax.persistence.EntityManager;
       
    23 
       
    24 /**
       
    25  * This class is used to keep track of number of objects
       
    26  * remaining to be commited to the database.
       
    27  */
       
    28 public class ORMCommitCount {
       
    29 
       
    30     private static Logger log = Logger.getLogger(ORMCommitCount.class);
       
    31 
       
    32     private static final int PERSISTANCE_COUNT_LIMIT = 1000;
       
    33 
       
    34     private static EntityManager entityManager;
       
    35 
       
    36     private int count;
       
    37 
       
    38     /** Constructor.
       
    39      */
       
    40     public ORMCommitCount() {
       
    41         count = PERSISTANCE_COUNT_LIMIT;
       
    42     }
       
    43 
       
    44     /**
       
    45      * Reduce the commit count value by one.
       
    46      */
       
    47     public void decreaseCount() {
       
    48         count --;
       
    49     }
       
    50 
       
    51     /**
       
    52      * Reset to maximum limit
       
    53      */
       
    54     public void reset() {
       
    55         count = PERSISTANCE_COUNT_LIMIT;
       
    56     }
       
    57 
       
    58     /**
       
    59      * Returns whether the commit is required or not.
       
    60      * @return if commit required returns true otherwise false.
       
    61      */
       
    62     public boolean isCommitRequired() {
       
    63         return count == 0;
       
    64     }
       
    65 
       
    66     /**
       
    67      * Returns whether if there are any data to commit
       
    68      * @return true if any data there to commit, otherwise false.
       
    69      */
       
    70     public boolean isDatatoCommit() {
       
    71         //log.debug("isDatatoCommit: " + (count < PERSISTANCE_COUNT_LIMIT));
       
    72         return count < PERSISTANCE_COUNT_LIMIT;
       
    73     }
       
    74 }