1 package mobisnap.common.reservation;
2
3 import mobisnap.mobile_trx.*;
4 import nmp.dbms.*;
5
6 /***
7 * Used to represent the usage of a value-use
8 *
9 * @version 0.045 12-Dec-2000
10 * @author Nuno Pregui�a
11 */
12 public class ValueUseReservationUse
13 extends ReservationUseBase
14 implements java.io.Serializable
15 {
16 transient Object beforeValue;
17
18 public ValueUseReservationUse( ValueUseReservation rsrv) {
19 super( rsrv);
20 }
21
22 /***
23 * The associated transaction has been committed. Updates the associated
24 * reservation accordingly.
25 * Returns true if the reservation has been completely used
26 */
27 public boolean commitCltRsrv() throws Exception {
28 return false;
29 }
30
31 /***
32 * The associated transaction has been rollbacked. Updates the associated
33 * reservation accordingly.
34 */
35 public void rollbackCltRsrv(){
36 // do nothing
37 }
38
39
40 /***
41 * Updates the reservation and database according to the current usage - processed
42 * BEFORE the transaction execution.
43 * Returns false if the current usage is not compatoble with the associated
44 * reservation.
45 */
46 public boolean preSrvTrxExeUpdate( ReservationBase rsrv0, nmp.dbms.JDBC.Jdbc_Sql database) throws Exception {
47 beforeValue = null;
48 if( ! ( rsrv0 instanceof ValueUseReservation))
49 throw new mobisnap.MobisnapException( "Escrow reservation expected in preSrvTrxExeUpdate");
50 ValueUseReservation rsrv = (ValueUseReservation)rsrv0;
51
52 StringBuffer buffer = new StringBuffer();
53 buffer.append( "select ");
54 buffer.append( rsrv.column);
55 buffer.append( " from ");
56 buffer.append( rsrv.table);
57 buffer.append( " where ");
58 int ncond = rsrv.conds.size();
59 for( int i = 0; i < ncond; i++) {
60 if( i != 0)
61 buffer.append( " AND ");
62 ColumnCondition cond = (ColumnCondition)rsrv.conds.elementAt( i);
63 cond.sourceCode( buffer);
64 }
65 buffer.append( ";");
66 SQLVectorResult result = database.executeQuery( buffer.toString());
67 if( result == null || result.rows == null || result.rows.size() != 1)
68 throw new mobisnap.MobisnapException( "Reservation specification error");
69 beforeValue = ((Object[])result.rows.elementAt( 0))[0];
70 if( beforeValue == null)
71 beforeValue = mobisnap.mobile_trx.SQLNull.getInstance();
72
73 buffer.setLength( 0);
74 buffer.append( "update ");
75 buffer.append( rsrv.table);
76 buffer.append( " set ");
77 buffer.append( rsrv.column);
78 buffer.append( " = ");
79 buffer.append( rsrv.value);
80 buffer.append( " where ");
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 ValueUseReservation))
100 throw new mobisnap.MobisnapException( "Escrow reservation expected in preSrvTrxExeUpdate");
101 if( beforeValue == null)
102 return false;
103 ValueUseReservation rsrv = (ValueUseReservation)rsrv0;
104
105 StringBuffer buffer = new StringBuffer();
106 buffer.append( "update ");
107 buffer.append( rsrv.table);
108 buffer.append( " set ");
109 buffer.append( rsrv.column);
110 buffer.append( " = ");
111 buffer.append( beforeValue);
112 buffer.append( " where ");
113 int ncond = rsrv.conds.size();
114 for( int i = 0; i < ncond; i++) {
115 if( i != 0)
116 buffer.append( " AND ");
117 ColumnCondition cond = (ColumnCondition)rsrv.conds.elementAt( i);
118 cond.sourceCode( buffer);
119 }
120 buffer.append( ";");
121 database.executeUpdate( buffer.toString());
122 return false;
123 }
124
125
126 }
This page was automatically generated by Maven