|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| ReservationBase.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
package mobisnap.common.reservation;
|
|
| 2 |
|
|
| 3 |
import java.io.*;
|
|
| 4 |
import java.util.*;
|
|
| 5 |
import mobisnap.mobile_trx.*;
|
|
| 6 |
|
|
| 7 |
/**
|
|
| 8 |
* Base class for reservations
|
|
| 9 |
*
|
|
| 10 |
* @version 0.045 12-Dec-2000
|
|
| 11 |
* @author Nuno Pregui�a
|
|
| 12 |
*/
|
|
| 13 |
public abstract class ReservationBase |
|
| 14 |
implements Serializable
|
|
| 15 |
{
|
|
| 16 |
java.rmi.server.UID uid; |
|
| 17 |
String table; |
|
| 18 |
String column; |
|
| 19 |
Vector conds; |
|
| 20 |
int lease;
|
|
| 21 |
long time;
|
|
| 22 |
|
|
| 23 | 0 |
public ReservationBase( String table, String column) {
|
| 24 | 0 |
uid = new java.rmi.server.UID();
|
| 25 | 0 |
this.table = table;
|
| 26 | 0 |
this.column = column;
|
| 27 | 0 |
conds = new Vector();
|
| 28 | 0 |
this.lease = 0;
|
| 29 | 0 |
this.time = 0;
|
| 30 |
} |
|
| 31 |
|
|
| 32 | 0 |
public void addCondition( mobisnap.mobile_trx.ColumnCondition cond) { |
| 33 | 0 |
conds.addElement( cond); |
| 34 |
} |
|
| 35 |
|
|
| 36 | 0 |
public mobisnap.mobile_trx.ColumnCondition getCondition( int pos){ |
| 37 | 0 |
try{
|
| 38 | 0 |
return (mobisnap.mobile_trx.ColumnCondition) conds.elementAt( pos);
|
| 39 |
} catch (Exception e){
|
|
| 40 |
// do nothing
|
|
| 41 |
} |
|
| 42 | 0 |
return null; |
| 43 |
} |
|
| 44 |
|
|
| 45 | 0 |
public Vector getConditions(){
|
| 46 | 0 |
return conds;
|
| 47 |
} |
|
| 48 |
|
|
| 49 | 0 |
public String getTableName(){
|
| 50 | 0 |
return table;
|
| 51 |
} |
|
| 52 |
|
|
| 53 | 0 |
public String getColumnName(){
|
| 54 | 0 |
return column;
|
| 55 |
} |
|
| 56 |
|
|
| 57 | 0 |
public java.rmi.server.UID getUID() {
|
| 58 | 0 |
return uid;
|
| 59 |
} |
|
| 60 |
|
|
| 61 | 0 |
public int getLease(){ |
| 62 | 0 |
return lease;
|
| 63 |
} |
|
| 64 |
|
|
| 65 | 0 |
public long getTime(){ |
| 66 | 0 |
return time;
|
| 67 |
} |
|
| 68 |
|
|
| 69 | 0 |
public void setLeaseTime(long time, int lease){ |
| 70 | 0 |
this.time = time;
|
| 71 | 0 |
this.lease = lease;
|
| 72 |
|
|
| 73 |
} |
|
| 74 |
|
|
| 75 |
/**
|
|
| 76 |
* Checks if there exists a reservation that satisfies the given conditions.
|
|
| 77 |
* NOTE: Currently only select in the form of
|
|
| 78 |
* "select col(,col)* into var(,var)* from table where cond1 (AND cond2)*"
|
|
| 79 |
* can be checked
|
|
| 80 |
*
|
|
| 81 |
* @param table Table name of possible reservation
|
|
| 82 |
* @param column Column name of possible reservation
|
|
| 83 |
* @param where Table row specification
|
|
| 84 |
* @return Return true if this resrvation backs up the given conditions
|
|
| 85 |
*/
|
|
| 86 | 0 |
public boolean checkReservation( String table, String column, SimpleNode where) { |
| 87 | 0 |
if( ! table.equals( this.table)) |
| 88 | 0 |
return false; |
| 89 | 0 |
if( (! column.equals( this.column))||( !column.equals("*"))) |
| 90 | 0 |
return false; |
| 91 |
|
|
| 92 | 0 |
return checkReservationConditions( 0, new BitSet( conds.size()), where) == conds.size(); |
| 93 |
} |
|
| 94 |
|
|
| 95 |
/**
|
|
| 96 |
* Checks if there exists a reservation that satisfies the given conditions.
|
|
| 97 |
* NOTE: Currently only select in the form of
|
|
| 98 |
* "select col(,col)* into var(,var)* from table where cond1 (AND cond2)*"
|
|
| 99 |
* can be checked
|
|
| 100 |
*
|
|
| 101 |
* @param table Table name of possible reservation
|
|
| 102 |
* @param column Column name of possible reservation
|
|
| 103 |
* @param where Table row specification
|
|
| 104 |
* @return Return true if this resrvation backs up the given conditions
|
|
| 105 |
*/
|
|
| 106 | 0 |
public boolean checkReservation( String table, String column, Vector specs) { |
| 107 | 0 |
if( ! table.equals( this.table)) |
| 108 | 0 |
return false; |
| 109 | 0 |
if( (! column.equals( this.column))||( column.equals("*"))) |
| 110 | 0 |
return false; |
| 111 |
|
|
| 112 | 0 |
return checkReservationConditions( specs) == conds.size();
|
| 113 |
} |
|
| 114 |
|
|
| 115 |
/**
|
|
| 116 |
* Checks which conditions the given node satisfies
|
|
| 117 |
*
|
|
| 118 |
* @param checked Number of conditions already satisfied
|
|
| 119 |
* @param bs Bitset with the conditions already satisfied
|
|
| 120 |
* @param node Node with the current condition
|
|
| 121 |
*/
|
|
| 122 | 0 |
private int checkReservationConditions( int nchecked, BitSet bs, SimpleNode node) { |
| 123 | 0 |
if( node instanceof ASTSQLAndExpression) { |
| 124 | 0 |
Vector ands = ((ASTSQLAndExpression)node).ands; |
| 125 | 0 |
for( int i = 0; i < ands.size(); i++) { |
| 126 | 0 |
SimpleNode node0 = (SimpleNode)ands.elementAt(i); |
| 127 | 0 |
nchecked = checkReservationConditions( nchecked, bs, node0); |
| 128 | 0 |
if( nchecked == conds.size())
|
| 129 | 0 |
return nchecked;
|
| 130 |
} |
|
| 131 |
} else {
|
|
| 132 | 0 |
for( int i = 0; i < conds.size(); i++) { |
| 133 | 0 |
if( bs.get( i))
|
| 134 | 0 |
continue;
|
| 135 | 0 |
if( ((ColumnCondition)conds.elementAt( i)).sameCondition( node)){
|
| 136 | 0 |
bs.set(i); |
| 137 | 0 |
nchecked++; |
| 138 |
} |
|
| 139 |
} |
|
| 140 |
} |
|
| 141 | 0 |
return nchecked;
|
| 142 |
} |
|
| 143 |
|
|
| 144 |
|
|
| 145 |
/**
|
|
| 146 |
* Checks which conditions the given node satisfies
|
|
| 147 |
*
|
|
| 148 |
* @param specs conditions vector
|
|
| 149 |
*/
|
|
| 150 | 0 |
private int checkReservationConditions( Vector specs) { |
| 151 | 0 |
for( int i = 0; i < conds.size(); i++) { |
| 152 | 0 |
boolean checked = false; |
| 153 | 0 |
int j = 0;
|
| 154 | 0 |
while( j < specs.size() ){
|
| 155 | 0 |
if ( ((ColumnCondition)conds.elementAt( i)).belongsTo( (RelopCondition)specs.elementAt( j)) )
|
| 156 | 0 |
break;
|
| 157 | 0 |
j++; |
| 158 |
} |
|
| 159 | 0 |
if ( j == specs.size())
|
| 160 | 0 |
return conds.size() - 1;
|
| 161 |
} |
|
| 162 | 0 |
return conds.size();
|
| 163 |
} |
|
| 164 |
|
|
| 165 |
/**
|
|
| 166 |
* Checks the given parameters are backed up by this reservation.
|
|
| 167 |
* If so, sets the reserved value to the variable and
|
|
| 168 |
* associate the reservation with the given variable - through a REservationUseBase
|
|
| 169 |
* class which is returned
|
|
| 170 |
* NOTE: Currently only select in the form of
|
|
| 171 |
* "select col(,col)* into var(,var)* from table where cond1 (AND cond2)*"
|
|
| 172 |
* can be checked
|
|
| 173 |
*
|
|
| 174 |
* @param var Variable involved
|
|
| 175 |
* @param table Table name of possible reservation
|
|
| 176 |
* @param column Column name of possible reservation
|
|
| 177 |
* @param where Table row specification
|
|
| 178 |
* @return Return null if there is no associateion between the given parameters
|
|
| 179 |
* ans this reservation. Otherwise returns a class to represent the reservation use
|
|
| 180 |
*/
|
|
| 181 |
public abstract ReservationUseBase checkReservation( MSQLTVariable var, String table, String column, SimpleNode where);
|
|
| 182 |
|
|
| 183 |
/**
|
|
| 184 |
* Returns a readable representation of this reervation - format:<BR>
|
|
| 185 |
* rsrv_id reservation column from table where row specification
|
|
| 186 |
*/
|
|
| 187 | 0 |
public String toString() {
|
| 188 | 0 |
StringBuffer buffer = new StringBuffer();
|
| 189 | 0 |
buffer.append( uid + " RESERVATION " + column + " FROM " + table + " WHERE "); |
| 190 | 0 |
for( int i = 0; i < conds.size(); i++) { |
| 191 | 0 |
if( i > 0)
|
| 192 | 0 |
buffer.append( " AND ");
|
| 193 | 0 |
buffer.append( conds.elementAt( i)); |
| 194 |
} |
|
| 195 | 0 |
buffer.append(" WITH LEASE "+lease);
|
| 196 | 0 |
return buffer.toString();
|
| 197 |
} |
|
| 198 |
} |
|
| 199 |
|
|
| 200 |
|
|
||||||||||