question: public synchronized int updatePurchase ( String orderId , String productId , PurchaseState purchaseState , long purchaseTime , String developerPayload ) { insertOrder ( orderId , productId , purchaseState , purchaseTime , developerPayload ) ; Cursor cursor = mDb . query ( PURCHASE_HISTORY_TABLE_NAME , HISTORY_COLUMNS , HISTORY_PRODUCT_ID_COL + "=?" , new String [ ] { productId } , null , null , null , null ) ; if ( cursor == null ) { return 0 ; } int quantity = 0 ; try { while ( cursor . moveToNext ( ) ) { int stateIndex = cursor . getInt ( 2 ) ; PurchaseState state = PurchaseState . valueOf ( stateIndex ) ; if ( state == PurchaseState . PURCHASED || state == PurchaseState . REFUNDED ) { quantity += 1 ; } } updatePurchasedItem ( productId , quantity ) ; } finally { if ( cursor != null ) { cursor . close ( ) ; } } return quantity ; }
target:  Adds the given purchase information to the database and returns the total number of times that the given product has been purchased.