1 package mobisnap.mobile_trx; 2 3 import java.sql.*; 4 import java.util.*; 5 import java.math.*; 6 import java.text.*; 7 8 public class MSQLTypeUtil 9 { 10 static DateFormat[] df; 11 12 static { 13 df = new DateFormat[12]; 14 df[2] = new SimpleDateFormat( "dd-MMM-yy"); 15 df[3] = new SimpleDateFormat( "dd-MMM-yyyy"); 16 df[4] = new SimpleDateFormat( "dd-MM-yy"); 17 df[5] = new SimpleDateFormat( "dd-MM-yyyy"); 18 df[6] = new SimpleDateFormat( "yy-MM-dd"); 19 df[7] = new SimpleDateFormat( "yyyy-MM-dd"); 20 df[8] = new SimpleDateFormat( "dd-MM-yy HH:mm:ss"); 21 df[9] = new SimpleDateFormat( "dd-MM-yyyy HH:mm:ss"); 22 df[10] = new SimpleDateFormat( "yy-MM-dd HH:mm:ss"); 23 df[11] = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); 24 } 25 26 public static String date2String( java.util.Date d) { 27 for( int i = 0; i < df.length; i++) 28 if( df[i] != null) 29 return df[i].format( d); 30 return d.toString(); 31 } 32 33 /*** 34 * Converts the given value in a string 35 */ 36 public static String value2String( Object value) { 37 if( value instanceof String) 38 return "'" + value + "'"; 39 else if( value instanceof java.util.Date) 40 return date2String( (java.util.Date)value); 41 else if( value == null) 42 return "NULL"; 43 else 44 return value.toString(); 45 } 46 47 /*** 48 * Converts the given value in a string 49 */ 50 public static String value2StringDomain( Object value) { 51 if( value instanceof String) 52 return (String)value; 53 else if( value instanceof java.util.Date) 54 return date2String( (java.util.Date)value); 55 else if( value == null) 56 return "NULL"; 57 else 58 return value.toString(); 59 } 60 61 /*** 62 * Returns true if the given object is NULL 63 */ 64 public static boolean isNull( Object obj) { 65 return obj == null || obj instanceof SQLNull; 66 } 67 68 /*** 69 * Returns true if the given object is of decimal type (int, double, BigDecimal) 70 */ 71 public static boolean isDecimal( Object obj) { 72 return obj instanceof Integer || obj instanceof Double || obj instanceof BigDecimal; 73 } 74 75 /*** 76 * Returns true if the given object may represent a date 77 */ 78 public static boolean mayBeDate( Object obj) { 79 if( obj instanceof java.sql.Date) 80 return true; 81 else if( obj instanceof String) { 82 try { 83 string2Date( (String)obj); 84 return true; 85 } catch( Exception e) { 86 return false; 87 } 88 } else 89 return false; 90 } 91 92 /*** 93 * Upgrades objl if necessary 94 * Integer >> Double >> BigDecimal 95 */ 96 public static Object upgradeDecimal( Object objl, Object objr) throws Exception { 97 if( objl instanceof String) 98 return upgradeDecimal( string2Decimal( (String)objl), objr); 99 if( objr instanceof String) 100 return upgradeDecimal( objl, string2Decimal( (String)objr)); 101 if( objl instanceof Integer) { 102 if( objr instanceof Double) 103 return new Double( ((Integer)objl).doubleValue()); 104 else if( objr instanceof BigDecimal) 105 return new BigDecimal( ((Integer)objl).doubleValue()); 106 } else if( objl instanceof Double && objr instanceof BigDecimal) 107 return new BigDecimal( ((Double)objl).doubleValue()); 108 return objl; 109 } 110 111 /*** 112 * Converts a string to a decimal type 113 */ 114 public static Object string2Decimal( String str) throws Exception { 115 try { 116 if( str.indexOf( '.') == -1) { 117 try { 118 return new Integer( str); 119 } catch ( Exception e) { 120 return new BigDecimal( str); 121 } 122 } else { 123 Double d = new Double( str); 124 BigDecimal bd1 = null; 125 try { 126 bd1 = new BigDecimal( str); 127 } catch( Exception e) { 128 return d; 129 } 130 if( bd1.compareTo( new BigDecimal( d.doubleValue())) == 0) 131 return d; 132 else 133 return bd1; 134 } 135 } catch( Exception e) { 136 throw new mobisnap.MobisnapException( "Impossible string to decimal conversion"); 137 } 138 } 139 140 /*** 141 * Converts a string to a date 142 */ 143 public static java.sql.Date string2Date( String str) throws Exception { 144 try { 145 return java.sql.Date.valueOf( str); 146 } catch( Exception e) { 147 for( int i = 0; i < df.length; i++) { 148 try { 149 if( df[i] != null) 150 return new java.sql.Date( df[i].parse( str).getTime()); 151 } catch( java.text.ParseException ex) { 152 // do nothing 153 } 154 } 155 throw new mobisnap.MobisnapException( "Impossible string to date conversion"); 156 } 157 } 158 159 /*** 160 * Returns the value of applying the minus sign to the given value 161 */ 162 public static Object negate( Object obj) 163 throws Exception { 164 if( obj instanceof SQLNull) 165 return obj; 166 else if( obj instanceof Integer) 167 return new Integer( - ((Integer)obj).intValue()); 168 else if( obj instanceof Double) 169 return new Double( - ((Double)obj).doubleValue()); 170 else if( obj instanceof BigDecimal) 171 return ((BigDecimal)obj).negate(); 172 else if( obj instanceof String) 173 return negate( string2Decimal((String)obj)); 174 throw new mobisnap.MobisnapException( "Invalid input for minus"); 175 } 176 177 /*** 178 * Returns the result objl ** objr 179 */ 180 public static Object pow( Object objl, Object objr) 181 throws Exception { 182 if( objl instanceof SQLNull) 183 return objl; 184 if( objr instanceof SQLNull) 185 return objr; 186 if( ! isDecimal( objl)) { 187 if( objl instanceof String) 188 objl = string2Decimal( (String)objl); 189 else 190 throw new mobisnap.MobisnapException( "Invalid input for expotent"); 191 } 192 if( ! isDecimal( objr)) { 193 if( objr instanceof String) 194 objr = string2Decimal( (String)objr); 195 else 196 throw new mobisnap.MobisnapException( "Invalid input for expotent"); 197 } 198 return new Double( Math.pow( ((Number)objl).doubleValue(), ((Number)objr).doubleValue())); 199 } 200 201 /*** 202 * Returns the result objl * objr 203 */ 204 public static Object multiply( Object objl, Object objr) 205 throws Exception { 206 if( objl instanceof SQLNull) 207 return objl; 208 if( objr instanceof SQLNull) 209 return objr; 210 if( ! isDecimal( objl)) { 211 if( objl instanceof String) 212 objl = string2Decimal( (String)objl); 213 else 214 throw new mobisnap.MobisnapException( "Invalid input for multiply"); 215 } 216 if( ! isDecimal( objr)) { 217 if( objr instanceof String) 218 objr = string2Decimal( (String)objr); 219 else 220 throw new mobisnap.MobisnapException( "Invalid input for multiply"); 221 } 222 objl = upgradeDecimal( objl, objr); 223 objr = upgradeDecimal( objr, objl); 224 if( objl instanceof Integer) 225 return new Integer( ((Integer)objl).intValue() * ((Integer)objr).intValue()); 226 else if( objl instanceof Double) 227 return new Double( ((Double)objl).doubleValue() * ((Double)objr).doubleValue()); 228 else 229 return ((BigDecimal)objl).multiply( (BigDecimal)objr); 230 } 231 232 /*** 233 * Returns the result objl / objr 234 */ 235 public static Object divide( Object objl, Object objr) 236 throws Exception { 237 if( objl instanceof SQLNull) 238 return objl; 239 if( objr instanceof SQLNull) 240 return objr; 241 if( ! isDecimal( objl)) { 242 if( objl instanceof String) 243 objl = string2Decimal( (String)objl); 244 else 245 throw new mobisnap.MobisnapException( "Invalid input for divide"); 246 } 247 if( ! isDecimal( objr)) { 248 if( objr instanceof String) 249 objr = string2Decimal( (String)objr); 250 else 251 throw new mobisnap.MobisnapException( "Invalid input for divide"); 252 } 253 objl = upgradeDecimal( objl, objr); 254 objr = upgradeDecimal( objr, objl); 255 if( objl instanceof Integer) 256 return new Integer( ((Integer)objl).intValue() / ((Integer)objr).intValue()); 257 else if( objl instanceof Double) 258 return new Double( ((Double)objl).doubleValue() / ((Double)objr).doubleValue()); 259 else 260 return ((BigDecimal)objl).divide( (BigDecimal)objr, BigDecimal.ROUND_HALF_UP); 261 } 262 263 /*** 264 * Returns the result objl + objr 265 * 266 * it is possible to add a number to a date -> adds that number of days 267 */ 268 public static Object add( Object objl, Object objr) 269 throws Exception { 270 if( objl instanceof SQLNull) 271 return objl; 272 if( objr instanceof SQLNull) 273 return objr; 274 if( mayBeDate( objl)) { 275 if( objl instanceof String) 276 objl = string2Date( (String)objl); 277 Calendar cal = new GregorianCalendar(); 278 cal.setTime( (java.sql.Date)objl); 279 if( ! isDecimal( objr)) { 280 if( objr instanceof String) 281 objr = string2Decimal( (String)objr); 282 else 283 throw new mobisnap.MobisnapException( "Invalid input for add"); 284 } 285 cal.add( Calendar.DATE, ((Number)objr).intValue()); 286 return new java.sql.Date( cal.getTime().getTime()); 287 } else { 288 if( ! isDecimal( objl)) { 289 if( objl instanceof String) 290 objl = string2Decimal( (String)objl); 291 else 292 throw new mobisnap.MobisnapException( "Invalid input for add"); 293 } 294 if( ! isDecimal( objr)) { 295 if( objr instanceof String) 296 objr = string2Decimal( (String)objr); 297 else 298 throw new mobisnap.MobisnapException( "Invalid input for add"); 299 } 300 objl = upgradeDecimal( objl, objr); 301 objr = upgradeDecimal( objr, objl); 302 if( objl instanceof Integer) 303 return new Integer( ((Integer)objl).intValue() + ((Integer)objr).intValue()); 304 else if( objl instanceof Double) 305 return new Double( ((Double)objl).doubleValue() + ((Double)objr).doubleValue()); 306 else 307 return ((BigDecimal)objl).add( (BigDecimal)objr); 308 } 309 } 310 311 /*** 312 * Returns the result objl - objr 313 */ 314 public static Object subtract( Object objl, Object objr) 315 throws Exception { 316 if( objl instanceof SQLNull) 317 return objl; 318 if( objr instanceof SQLNull) 319 return objr; 320 if( mayBeDate( objl)) { 321 if( objl instanceof String) 322 objl = string2Date( (String)objl); 323 Calendar cal = new GregorianCalendar(); 324 cal.setTime( (java.sql.Date)objl); 325 if( mayBeDate( objr)) { 326 if( objr instanceof String) 327 objr = string2Date( (String)objl); 328 Calendar cal2 = new GregorianCalendar(); 329 cal2.setTime( (java.sql.Date)objr); 330 cal.set( Calendar.MILLISECOND, 0); 331 cal.set( Calendar.SECOND, 0); 332 cal.set( Calendar.MINUTE, 0); 333 cal.set( Calendar.HOUR, 2); 334 cal2.set( Calendar.MILLISECOND, 0); 335 cal2.set( Calendar.SECOND, 0); 336 cal2.set( Calendar.MINUTE, 0); 337 cal2.set( Calendar.HOUR, 2); 338 long l = ((java.sql.Date)objl).getTime() - ((java.sql.Date)objr).getTime(); 339 return new Integer( (int)( l / 86400000L)); 340 } 341 if( ! isDecimal( objr)) { 342 if( objr instanceof String) 343 objr = string2Decimal( (String)objr); 344 else 345 throw new mobisnap.MobisnapException( "Invalid input for subtract"); 346 } 347 cal.add( Calendar.DATE, -((Number)objr).intValue()); 348 return new java.sql.Date( cal.getTime().getTime()); 349 } else { 350 if( ! isDecimal( objl)) { 351 if( objl instanceof String) 352 objl = string2Decimal( (String)objl); 353 else 354 throw new mobisnap.MobisnapException( "Invalid input for subtract"); 355 } 356 if( ! isDecimal( objr)) { 357 if( objr instanceof String) 358 objr = string2Decimal( (String)objr); 359 else 360 throw new mobisnap.MobisnapException( "Invalid input for subtract"); 361 } 362 objl = upgradeDecimal( objl, objr); 363 objr = upgradeDecimal( objr, objl); 364 if( objl instanceof Integer) 365 return new Integer( ((Integer)objl).intValue() - ((Integer)objr).intValue()); 366 else if( objl instanceof Double) 367 return new Double( ((Double)objl).doubleValue() - ((Double)objr).doubleValue()); 368 else 369 return ((BigDecimal)objl).subtract( (BigDecimal)objr); 370 } 371 } 372 373 /*** 374 * Returns the concatenation of obj || objr 375 */ 376 public static Object concat( Object objl, Object objr) throws Exception { 377 if( isDecimal( objl)) 378 objl = objl.toString(); 379 if( isDecimal( objr)) 380 objr = objr.toString(); 381 if( objl instanceof Boolean) 382 objl = objl.toString(); 383 if( objr instanceof Boolean) 384 objr = objr.toString(); 385 if( objr instanceof java.sql.Date) 386 objr = MSQLTypeUtil.date2String( (java.sql.Date)objr); 387 if( objl instanceof java.sql.Date) 388 objl = MSQLTypeUtil.date2String( (java.sql.Date)objl); 389 if( objl instanceof SQLNull && objr instanceof String) 390 return objr; 391 if( objr instanceof SQLNull && objl instanceof String) 392 return objl; 393 if( objl instanceof SQLNull && objr instanceof SQLNull) 394 return objl; 395 if( ! ( objl instanceof String) || ! ( objr instanceof String)) 396 throw new mobisnap.MobisnapException( "Invalid input for concatenation"); 397 return ((String)objl).concat( (String)objr); 398 } 399 400 /*** 401 * Returns the result objl = objr 402 */ 403 public static Object equal( Object objl, Object objr) 404 throws Exception { 405 if( objl instanceof SQLNull) 406 return objl; 407 if( objr instanceof SQLNull) 408 return objr; 409 if( isDecimal( objl) || isDecimal( objr)) { 410 if( ! isDecimal( objl)) { 411 if( objl instanceof String) 412 objl = string2Decimal( (String)objl); 413 else 414 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 00"); 415 } 416 if( ! isDecimal( objr)) { 417 if( objr instanceof String) 418 objr = string2Decimal( (String)objr); 419 else 420 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 01"); 421 } 422 objl = upgradeDecimal( objl, objr); 423 objr = upgradeDecimal( objr, objl); 424 if( objl instanceof Integer) 425 return new Boolean( ((Integer)objl).compareTo((Integer)objr) == 0); 426 else if( objl instanceof Double) 427 return new Boolean( ((Double)objl).compareTo((Double)objr) == 0); 428 else 429 return new Boolean( ((BigDecimal)objl).compareTo( (BigDecimal)objr) == 0); 430 } else if( objl instanceof java.sql.Date || objr instanceof java.sql.Date) { 431 if( objl instanceof String) 432 objl = string2Date( (String)objl); 433 else if( objr instanceof String) 434 objr = string2Date( (String)objr); 435 else 436 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 02"); 437 return new Boolean( ((java.sql.Date)objl).compareTo( (java.sql.Date)objr) == 0); 438 } else if( objl instanceof Boolean && objr instanceof Boolean) 439 return new Boolean( ((Boolean)objl).equals( (Boolean)objr)); 440 else if( objl instanceof String && objr instanceof String) 441 return new Boolean( ((String)objl).compareTo( (String)objr) == 0); 442 else if( objl instanceof String || objr instanceof String) { 443 if( objl instanceof Boolean) { 444 if( ((String)objr).equalsIgnoreCase( "true") || ((String)objr).equalsIgnoreCase( "false")) 445 return new Boolean( ((Boolean)objl).equals( new Boolean( (String)objr))); 446 else 447 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 03"); 448 } 449 if( objr instanceof Boolean) { 450 if( ((String)objl).equalsIgnoreCase( "true") || ((String)objl).equalsIgnoreCase( "false")) 451 return new Boolean( ((Boolean)objr).equals( new Boolean( (String)objr))); 452 else 453 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 04"); 454 } 455 } 456 throw new mobisnap.MobisnapException( "Invalid input for equal"); 457 } 458 459 /*** 460 * Returns the result objl != objr 461 */ 462 public static Object notEqual( Object objl, Object objr) 463 throws Exception { 464 if( objl instanceof SQLNull) 465 return objl; 466 if( objr instanceof SQLNull) 467 return objr; 468 if( isDecimal( objl) || isDecimal( objr)) { 469 if( ! isDecimal( objl)) { 470 if( objl instanceof String) 471 objl = string2Decimal( (String)objl); 472 else 473 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 00"); 474 } 475 if( ! isDecimal( objr)) { 476 if( objr instanceof String) 477 objr = string2Decimal( (String)objr); 478 else 479 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 01"); 480 } 481 objl = upgradeDecimal( objl, objr); 482 objr = upgradeDecimal( objr, objl); 483 if( objl instanceof Integer) 484 return new Boolean( ((Integer)objl).compareTo((Integer)objr) != 0); 485 else if( objl instanceof Double) 486 return new Boolean( ((Double)objl).compareTo((Double)objr) != 0); 487 else 488 return new Boolean( ((BigDecimal)objl).compareTo( (BigDecimal)objr) != 0); 489 } else if( objl instanceof java.sql.Date || objr instanceof java.sql.Date) { 490 if( objl instanceof String) 491 objl = string2Date( (String)objl); 492 else if( objr instanceof String) 493 objr = string2Date( (String)objr); 494 else 495 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 02"); 496 return new Boolean( ((java.sql.Date)objl).compareTo( (java.sql.Date)objr) != 0); 497 } else if( objl instanceof Boolean && objr instanceof Boolean) 498 return new Boolean( ! ((Boolean)objl).equals( (Boolean)objr)); 499 else if( objl instanceof String && objr instanceof String) 500 return new Boolean( ((String)objl).compareTo( (String)objr) != 0); 501 else if( objl instanceof String || objr instanceof String) { 502 if( objl instanceof Boolean) { 503 if( ((String)objr).equalsIgnoreCase( "true") || ((String)objr).equalsIgnoreCase( "false")) 504 return new Boolean( ((Boolean)objl).booleanValue() != new Boolean( (String)objr).booleanValue()); 505 else 506 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 03"); 507 } 508 if( objr instanceof Boolean) { 509 if( ((String)objl).equalsIgnoreCase( "true") || ((String)objl).equalsIgnoreCase( "false")) 510 return new Boolean( ((Boolean)objr).booleanValue() != new Boolean( (String)objr).booleanValue()); 511 else 512 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 04"); 513 } 514 } 515 throw new mobisnap.MobisnapException( "Invalid input for not equal"); 516 } 517 518 /*** 519 * Returns the result objl <> objr 520 */ 521 public static Object moreOrLess( Object objl, Object objr) 522 throws Exception { 523 if( objl instanceof SQLNull) 524 return objl; 525 if( objr instanceof SQLNull) 526 return objr; 527 if( isDecimal( objl) || isDecimal( objr)) { 528 if( ! isDecimal( objl)) { 529 if( objl instanceof String) 530 objl = string2Decimal( (String)objl); 531 else 532 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 00"); 533 } 534 if( ! isDecimal( objr)) { 535 if( objr instanceof String) 536 objr = string2Decimal( (String)objr); 537 else 538 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 01"); 539 } 540 objl = upgradeDecimal( objl, objr); 541 objr = upgradeDecimal( objr, objl); 542 if( objl instanceof Integer) 543 return new Boolean( ((Integer)objl).compareTo((Integer)objr) != 0); 544 else if( objl instanceof Double) 545 return new Boolean( ((Double)objl).compareTo((Double)objr) != 0); 546 else 547 return new Boolean( ((BigDecimal)objl).compareTo( (BigDecimal)objr) != 0); 548 } else if( objl instanceof java.sql.Date || objr instanceof java.sql.Date) { 549 if( objl instanceof String) 550 objl = string2Date( (String)objl); 551 else if( objr instanceof String) 552 objr = string2Date( (String)objr); 553 else 554 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 02"); 555 return new Boolean( ((java.sql.Date)objl).compareTo( (java.sql.Date)objr) != 0); 556 } else if( objl instanceof Boolean && objr instanceof Boolean) 557 return new Boolean( ! ((Boolean)objl).equals( (Boolean)objr)); 558 else if( objl instanceof String && objr instanceof String) 559 return new Boolean( ((String)objl).compareTo( (String)objr) != 0); 560 else if( objl instanceof String || objr instanceof String) { 561 if( objl instanceof Boolean) { 562 if( ((String)objr).equalsIgnoreCase( "true") || ((String)objr).equalsIgnoreCase( "false")) 563 return new Boolean( ((Boolean)objl).booleanValue() != new Boolean( (String)objr).booleanValue() ); 564 else 565 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 03"); 566 } 567 if( objr instanceof Boolean) { 568 if( ((String)objl).equalsIgnoreCase( "true") || ((String)objl).equalsIgnoreCase( "false")) 569 return new Boolean( ((Boolean)objr).booleanValue() != new Boolean( (String)objr).booleanValue()); 570 else 571 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 04"); 572 } 573 } 574 throw new mobisnap.MobisnapException( "Invalid input for more or less"); 575 } 576 577 /*** 578 * Returns the result objl > objr 579 */ 580 public static Object more( Object objl, Object objr) 581 throws Exception { 582 if( objl instanceof SQLNull) 583 return objl; 584 if( objr instanceof SQLNull) 585 return objr; 586 if( isDecimal( objl) || isDecimal( objr)) { 587 if( ! isDecimal( objl)) { 588 if( objl instanceof String) 589 objl = string2Decimal( (String)objl); 590 else 591 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 00"); 592 } 593 if( ! isDecimal( objr)) { 594 if( objr instanceof String) 595 objr = string2Decimal( (String)objr); 596 else 597 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 01"); 598 } 599 objl = upgradeDecimal( objl, objr); 600 objr = upgradeDecimal( objr, objl); 601 if( objl instanceof Integer) 602 return new Boolean( ((Integer)objl).compareTo((Integer)objr) > 0); 603 else if( objl instanceof Double) 604 return new Boolean( ((Double)objl).compareTo((Double)objr) > 0); 605 else 606 return new Boolean( ((BigDecimal)objl).compareTo( (BigDecimal)objr) > 0); 607 } else if( objl instanceof java.sql.Date || objr instanceof java.sql.Date) { 608 if( objl instanceof String) 609 objl = string2Date( (String)objl); 610 else if( objr instanceof String) 611 objr = string2Date( (String)objr); 612 else 613 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 02"); 614 return new Boolean( ((java.sql.Date)objl).compareTo( (java.sql.Date)objr) > 0); 615 } else if( (objl instanceof String || objr instanceof String) && 616 (objl instanceof Boolean || objr instanceof Boolean)) { 617 if( objl instanceof Boolean) 618 objl = objl.toString(); 619 if( objr instanceof Boolean) 620 objr = objr.toString(); 621 return new Boolean( ((String)objl).compareTo( (String)objr) > 0); 622 } else if( objl instanceof String && objr instanceof String) 623 return new Boolean( ((String)objl).compareTo( (String)objr) > 0); 624 throw new mobisnap.MobisnapException( "Invalid input for more"); 625 } 626 627 /*** 628 * Returns the result objl >= objr 629 */ 630 public static Object moreEqual( Object objl, Object objr) 631 throws Exception { 632 if( objl instanceof SQLNull) 633 return objl; 634 if( objr instanceof SQLNull) 635 return objr; 636 if( isDecimal( objl) || isDecimal( objr)) { 637 if( ! isDecimal( objl)) { 638 if( objl instanceof String) 639 objl = string2Decimal( (String)objl); 640 else 641 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 00"); 642 } 643 if( ! isDecimal( objr)) { 644 if( objr instanceof String) 645 objr = string2Decimal( (String)objr); 646 else 647 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 01"); 648 } 649 objl = upgradeDecimal( objl, objr); 650 objr = upgradeDecimal( objr, objl); 651 if( objl instanceof Integer) 652 return new Boolean( ((Integer)objl).compareTo((Integer)objr) >= 0); 653 else if( objl instanceof Double) 654 return new Boolean( ((Double)objl).compareTo((Double)objr) >= 0); 655 else 656 return new Boolean( ((BigDecimal)objl).compareTo( (BigDecimal)objr) >= 0); 657 } else if( objl instanceof java.sql.Date || objr instanceof java.sql.Date) { 658 if( objl instanceof String) 659 objl = string2Date( (String)objl); 660 else if( objr instanceof String) 661 objr = string2Date( (String)objr); 662 else 663 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 02"); 664 return new Boolean( ((java.sql.Date)objl).compareTo( (java.sql.Date)objr) >= 0); 665 } else if( (objl instanceof String || objr instanceof String) && 666 (objl instanceof Boolean || objr instanceof Boolean)) { 667 if( objl instanceof Boolean) 668 objl = objl.toString(); 669 if( objr instanceof Boolean) 670 objr = objr.toString(); 671 return new Boolean( ((String)objl).compareTo( (String)objr) >= 0); 672 } else if( objl instanceof String && objr instanceof String) 673 return new Boolean( ((String)objl).compareTo( (String)objr) >= 0); 674 throw new mobisnap.MobisnapException( "Invalid input for more equal"); 675 } 676 677 /*** 678 * Returns the result objl < objr 679 */ 680 public static Object less( Object objl, Object objr) 681 throws Exception { 682 if( objl instanceof SQLNull) 683 return objl; 684 if( objr instanceof SQLNull) 685 return objr; 686 if( isDecimal( objl) || isDecimal( objr)) { 687 if( ! isDecimal( objl)) { 688 if( objl instanceof String) 689 objl = string2Decimal( (String)objl); 690 else 691 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 00"); 692 } 693 if( ! isDecimal( objr)) { 694 if( objr instanceof String) 695 objr = string2Decimal( (String)objr); 696 else 697 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 01"); 698 } 699 objl = upgradeDecimal( objl, objr); 700 objr = upgradeDecimal( objr, objl); 701 if( objl instanceof Integer) 702 return new Boolean( ((Integer)objl).compareTo((Integer)objr) < 0); 703 else if( objl instanceof Double) 704 return new Boolean( ((Double)objl).compareTo((Double)objr) < 0); 705 else 706 return new Boolean( ((BigDecimal)objl).compareTo( (BigDecimal)objr) < 0); 707 } else if( objl instanceof java.sql.Date || objr instanceof java.sql.Date) { 708 if( objl instanceof String) 709 objl = string2Date( (String)objl); 710 else if( objr instanceof String) 711 objr = string2Date( (String)objr); 712 else 713 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 02"); 714 return new Boolean( ((java.sql.Date)objl).compareTo( (java.sql.Date)objr) < 0); 715 } else if( (objl instanceof String || objr instanceof String) && 716 (objl instanceof Boolean || objr instanceof Boolean)) { 717 if( objl instanceof Boolean) 718 objl = objl.toString(); 719 if( objr instanceof Boolean) 720 objr = objr.toString(); 721 return new Boolean( ((String)objl).compareTo( (String)objr) < 0); 722 } else if( objl instanceof String && objr instanceof String) 723 return new Boolean( ((String)objl).compareTo( (String)objr) < 0); 724 throw new mobisnap.MobisnapException( "Invalid input for less"); 725 } 726 727 /*** 728 * Returns the result objl <= objr 729 */ 730 public static Object lessEqual( Object objl, Object objr) 731 throws Exception { 732 if( objl instanceof SQLNull) 733 return objl; 734 if( objr instanceof SQLNull) 735 return objr; 736 if( isDecimal( objl) || isDecimal( objr)) { 737 if( ! isDecimal( objl)) { 738 if( objl instanceof String) 739 objl = string2Decimal( (String)objl); 740 else 741 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 00"); 742 } 743 if( ! isDecimal( objr)) { 744 if( objr instanceof String) 745 objr = string2Decimal( (String)objr); 746 else 747 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 01"); 748 } 749 objl = upgradeDecimal( objl, objr); 750 objr = upgradeDecimal( objr, objl); 751 if( objl instanceof Integer) 752 return new Boolean( ((Integer)objl).compareTo((Integer)objr) <= 0); 753 else if( objl instanceof Double) 754 return new Boolean( ((Double)objl).compareTo((Double)objr) <= 0); 755 else 756 return new Boolean( ((BigDecimal)objl).compareTo( (BigDecimal)objr) <= 0); 757 } else if( objl instanceof java.sql.Date || objr instanceof java.sql.Date) { 758 if( objl instanceof String) 759 objl = string2Date( (String)objl); 760 else if( objr instanceof String) 761 objr = string2Date( (String)objr); 762 else 763 throw new mobisnap.MobisnapException( "Invalid input for logical expression : 02"); 764 return new Boolean( ((java.sql.Date)objl).compareTo( (java.sql.Date)objr) <= 0); 765 } else if( (objl instanceof String || objr instanceof String) && 766 (objl instanceof Boolean || objr instanceof Boolean)) { 767 if( objl instanceof Boolean) 768 objl = objl.toString(); 769 if( objr instanceof Boolean) 770 objr = objr.toString(); 771 return new Boolean( ((String)objl).compareTo( (String)objr) <= 0); 772 } else if( objl instanceof String && objr instanceof String) 773 return new Boolean( ((String)objl).compareTo( (String)objr) <= 0); 774 throw new mobisnap.MobisnapException( "Invalid input for less equal"); 775 } 776 777 /*** 778 * Returns the value of NOT obj 779 */ 780 public static Object not( Object obj) 781 throws Exception { 782 if( obj instanceof Boolean) 783 return new Boolean( ! ((Boolean)obj).booleanValue()); 784 else if( obj instanceof SQLNull) 785 return obj; 786 else if( obj instanceof String && (((String)obj).equalsIgnoreCase( "true") || ((String)obj).equalsIgnoreCase( "false"))) 787 return new Boolean( ! new Boolean( (String)obj).booleanValue() ); 788 throw new mobisnap.MobisnapException( "Invalid input for not"); 789 } 790 791 /*** 792 * Returns the value of objl AND objr 793 */ 794 public static Object and( Object objl, Object objr) 795 throws Exception { 796 if( objl instanceof SQLNull) 797 return objl; 798 if( objr instanceof SQLNull) 799 return objr; 800 if( objl instanceof String && 801 (((String)objl).equalsIgnoreCase( "true") || 802 ((String)objl).equalsIgnoreCase( "false"))) 803 objl = new Boolean( (String)objl); 804 if( objr instanceof String && 805 (((String)objr).equalsIgnoreCase( "true") || 806 ((String)objr).equalsIgnoreCase( "false"))) 807 objr = new Boolean( (String)objr); 808 if( objl instanceof Boolean && objr instanceof Boolean) 809 return new Boolean( ((Boolean)objl).booleanValue() && ((Boolean)objr).booleanValue()); 810 throw new mobisnap.MobisnapException( "Invalid input for and"); 811 } 812 813 /*** 814 * Returns the value of objl AND objr 815 */ 816 public static Object or( Object objl, Object objr) 817 throws Exception { 818 if( objl instanceof SQLNull) 819 return objl; 820 if( objr instanceof SQLNull) 821 return objr; 822 if( objl instanceof String && 823 (((String)objl).equalsIgnoreCase( "true") || 824 ((String)objl).equalsIgnoreCase( "false"))) 825 objl = new Boolean( (String)objl); 826 if( objr instanceof String && 827 (((String)objr).equalsIgnoreCase( "true") || 828 ((String)objr).equalsIgnoreCase( "false"))) 829 objr = new Boolean( (String)objr); 830 if( objl instanceof Boolean && objr instanceof Boolean) 831 return new Boolean( ((Boolean)objl).booleanValue() || ((Boolean)objr).booleanValue()); 832 throw new mobisnap.MobisnapException( "Invalid input for and"); 833 } 834 835 }

This page was automatically generated by Maven