1 package mobisnap.common.reservation; 2 3 import mobisnap.mobile_trx.*; 4 5 /*** 6 * Used to represent the usage of a escrow reservation 7 * 8 * @version 0.045 12-Dec-2000 9 * @author Nuno Pregui´┐Ża 10 */ 11 public class EscrowReservationUse 12 extends ReservationUseBase 13 implements java.io.Serializable 14 { 15 Object used; 16 transient boolean srvPreOK = false; 17 18 public EscrowReservationUse( EscrowReservation rsrv) { 19 super( rsrv); 20 used = new Integer( 0); 21 } 22 23 /*** 24 * Increases the number of used instances in the given reservation 25 */ 26 public void addUsed( Object val) throws Exception { 27 used = mobisnap.mobile_trx.MSQLTypeUtil.add( used, val); 28 Object bool = MSQLTypeUtil.moreEqual( ((EscrowReservation)rsrv).instances, used); 29 if( ! ( bool != null && bool instanceof Boolean && ((Boolean)bool).booleanValue())) 30 throw new NoReservationException( "Reservation overflowed"); 31 } 32 33 /*** 34 * The associated transaction has been committed. Updates the associated 35 * reservation accordingly. 36 * Returns true if the reservation has been completely used 37 */ 38 public boolean commitCltRsrv() throws Exception { 39 EscrowReservation rsrv = (EscrowReservation)this.rsrv; 40 rsrv.instances = MSQLTypeUtil.subtract( rsrv.instances, used); 41 Object bool = MSQLTypeUtil.equal( new Integer( 0), rsrv.instances); 42 return ! ( bool != null && bool instanceof Boolean && ! ((Boolean)bool).booleanValue()); 43 } 44 45 /*** 46 * The associated transaction has been rollbacked. Updates the associated 47 * reservation accordingly. 48 */ 49 public void rollbackCltRsrv(){ 50 // do nothing 51 } 52 53 54 /*** 55 * Updates the reservation and database according to the current usage - processed 56 * BEFORE the transaction execution. 57 * Returns false if the current usage is not compatoble with the associated 58 * reservation. 59 */ 60 public boolean preSrvTrxExeUpdate( ReservationBase rsrv0, nmp.dbms.JDBC.Jdbc_Sql database) throws Exception { 61 if( ! ( rsrv0 instanceof EscrowReservation)) 62 throw new mobisnap.MobisnapException( "Escrow reservation expected in preSrvTrxExeUpdate"); 63 EscrowReservation rsrv = (EscrowReservation)rsrv0; 64 Object bool = MSQLTypeUtil.moreEqual( rsrv.instances, used); 65 if( bool == null || ! ( bool instanceof Boolean) || ! ((Boolean)bool).booleanValue()) 66 return false; 67 srvPreOK = true; 68 rsrv.instances = MSQLTypeUtil.subtract( rsrv.instances, used); 69 70 StringBuffer buffer = new StringBuffer(); 71 buffer.append( "update "); 72 buffer.append( rsrv.table); 73 buffer.append( " set "); 74 buffer.append( rsrv.column); 75 buffer.append( " = "); 76 buffer.append( rsrv.column); 77 buffer.append( " + "); 78 buffer.append( MSQLTypeUtil.value2String( used)); 79 buffer.append( " where "); 80 int ncond = rsrv.conds.size(); 81 for( int i = 0; i < ncond; i++) { 82 if( i != 0) 83 buffer.append( " AND "); 84 ColumnCondition cond = (ColumnCondition)rsrv.conds.elementAt( i); 85 cond.sourceCode( buffer); 86 } 87 buffer.append( ";"); 88 if( database.executeUpdate( buffer.toString()) != 1) 89 return false; 90 return true; 91 } 92 93 /*** 94 * Updates the reservation and database according to the current usage - processed 95 * AFTER the transaction execution. 96 * Returns true if the transaction has been completely used. 97 */ 98 public boolean postSrvTrxExeUpdate( ReservationBase rsrv0, nmp.dbms.JDBC.Jdbc_Sql database) throws Exception { 99 if( ! ( rsrv0 instanceof EscrowReservation)) 100 throw new mobisnap.MobisnapException( "Escrow reservation expected in preSrvTrxExeUpdate"); 101 EscrowReservation rsrv = (EscrowReservation)rsrv0; 102 Object bool = MSQLTypeUtil.moreEqual( rsrv.instances, new Integer( 0)); 103 return bool == null || ! ( bool instanceof Boolean) || ! ((Boolean)bool).booleanValue(); 104 } 105 106 107 }

This page was automatically generated by Maven