1 package com.genimen.djeneric.test.strong.impl; 2 3 import java.util.HashMap ; 4 5 import com.genimen.djeneric.repository.DjDomain; 6 import com.genimen.djeneric.repository.DjDomainValue; 7 import com.genimen.djeneric.repository.DjExtent; 8 import com.genimen.djeneric.repository.DjList; 9 import com.genimen.djeneric.repository.DjObject; 10 import com.genimen.djeneric.repository.DjOql; 11 import com.genimen.djeneric.repository.DjQueryByExample; 12 import com.genimen.djeneric.repository.exceptions.DjenericException; 13 import com.genimen.djeneric.repository.exceptions.ObjectNotDefinedException; 14 import com.genimen.djeneric.repository.rdbms.RdbmsSession; 15 import com.genimen.djeneric.test.strong.Customer; 16 import com.genimen.djeneric.test.strong.CustomerCursor; 17 import com.genimen.djeneric.test.strong.CustomerQbe; 18 import com.genimen.djeneric.test.strong.Oql; 19 import com.genimen.djeneric.test.strong.Order; 20 import com.genimen.djeneric.test.strong.OrderCursor; 21 import com.genimen.djeneric.test.strong.OrderQbe; 22 import com.genimen.djeneric.test.strong.Orderline; 23 import com.genimen.djeneric.test.strong.OrderlineCursor; 24 import com.genimen.djeneric.test.strong.OrderlineQbe; 25 import com.genimen.djeneric.test.strong.Product; 26 import com.genimen.djeneric.test.strong.ProductCursor; 27 import com.genimen.djeneric.test.strong.ProductQbe; 28 import com.genimen.djeneric.test.strong.TestException; 29 import com.genimen.djeneric.test.strong.TestMultipleFoundException; 30 import com.genimen.djeneric.test.strong.TestNotFoundException; 31 import com.genimen.djeneric.test.strong.TestSession; 32 33 public class TestAbstractSessionImpl extends RdbmsSession implements TestSession 37 { 38 public static String NO_OBJECT_FOUND = "NO_OBJECT_FOUND"; 39 public static String MORE_THAN_1_OBJECT_FOUND = "MORE_THAN_1_OBJECT_FOUND"; 40 protected DjExtent _customersExtent; 41 protected DjExtent _orderlinesExtent; 42 protected DjExtent _ordersExtent; 43 protected DjExtent _productsExtent; 44 45 protected TestAbstractSessionImpl(TestPersistenceManager mgr) throws ObjectNotDefinedException 46 { 47 super(mgr); 48 _customersExtent = mgr.getExtentByObjectType("Customer"); 49 _orderlinesExtent = mgr.getExtentByObjectType("Orderline"); 50 _ordersExtent = mgr.getExtentByObjectType("Order"); 51 _productsExtent = mgr.getExtentByObjectType("Product"); 52 } 53 54 public DjObject createObject(DjExtent extent) throws DjenericException 55 { 56 if (!isValid()) throw new DjenericException("Session closed"); 57 DjObject po = null; 58 if (extent == _customersExtent) po = new CustomerImpl(this, extent); 59 else if (extent == _orderlinesExtent) po = new OrderlineImpl(this, extent); 60 else if (extent == _ordersExtent) po = new OrderImpl(this, extent); 61 else if (extent == _productsExtent) po = new ProductImpl(this, extent); 62 else po = super.createObject(extent); 63 return po; 64 } 65 66 public DjQueryByExample createQueryByExample(DjExtent extent) throws DjenericException 67 { 68 if (!isValid()) throw new DjenericException("Session closed"); 69 DjQueryByExample qbe = null; 70 if (extent == _customersExtent) qbe = new CustomerQbeImpl(this, extent); 71 else if (extent == _orderlinesExtent) qbe = new OrderlineQbeImpl(this, extent); 72 else if (extent == _ordersExtent) qbe = new OrderQbeImpl(this, extent); 73 else if (extent == _productsExtent) qbe = new ProductQbeImpl(this, extent); 74 else qbe = super.createQueryByExample(extent); 75 return qbe; 76 } 77 78 public Customer createCustomer() throws TestException 79 { 80 try 81 { 82 return (Customer) createObject(_customersExtent); 83 } 84 catch (Exception x) 85 { 86 throw new TestException(x); 87 } 88 } 89 90 public CustomerQbe createCustomerQbe() throws TestException 91 { 92 try 93 { 94 return (CustomerQbe) createQueryByExample(_customersExtent); 95 } 96 catch (Exception x) 97 { 98 throw new TestException(x); 99 } 100 } 101 102 public Oql createCustomerOql() throws TestException 103 { 104 try 105 { 106 return (Oql) new OqlImpl(_customersExtent); 107 } 108 catch (Exception x) 109 { 110 throw new TestException(x); 111 } 112 } 113 114 public Orderline createOrderline() throws TestException 115 { 116 try 117 { 118 return (Orderline) createObject(_orderlinesExtent); 119 } 120 catch (Exception x) 121 { 122 throw new TestException(x); 123 } 124 } 125 126 public OrderlineQbe createOrderlineQbe() throws TestException 127 { 128 try 129 { 130 return (OrderlineQbe) createQueryByExample(_orderlinesExtent); 131 } 132 catch (Exception x) 133 { 134 throw new TestException(x); 135 } 136 } 137 138 public Oql createOrderlineOql() throws TestException 139 { 140 try 141 { 142 return (Oql) new OqlImpl(_orderlinesExtent); 143 } 144 catch (Exception x) 145 { 146 throw new TestException(x); 147 } 148 } 149 150 public Order createOrder() throws TestException 151 { 152 try 153 { 154 return (Order) createObject(_ordersExtent); 155 } 156 catch (Exception x) 157 { 158 throw new TestException(x); 159 } 160 } 161 162 public OrderQbe createOrderQbe() throws TestException 163 { 164 try 165 { 166 return (OrderQbe) createQueryByExample(_ordersExtent); 167 } 168 catch (Exception x) 169 { 170 throw new TestException(x); 171 } 172 } 173 174 public Oql createOrderOql() throws TestException 175 { 176 try 177 { 178 return (Oql) new OqlImpl(_ordersExtent); 179 } 180 catch (Exception x) 181 { 182 throw new TestException(x); 183 } 184 } 185 186 public Product createProduct() throws TestException 187 { 188 try 189 { 190 return (Product) createObject(_productsExtent); 191 } 192 catch (Exception x) 193 { 194 throw new TestException(x); 195 } 196 } 197 198 public ProductQbe createProductQbe() throws TestException 199 { 200 try 201 { 202 return (ProductQbe) createQueryByExample(_productsExtent); 203 } 204 catch (Exception x) 205 { 206 throw new TestException(x); 207 } 208 } 209 210 public Oql createProductOql() throws TestException 211 { 212 try 213 { 214 return (Oql) new OqlImpl(_productsExtent); 215 } 216 catch (Exception x) 217 { 218 throw new TestException(x); 219 } 220 } 221 222 public Customer getCustomer(long objectId) throws TestException 223 { 224 try 225 { 226 return (Customer) getObject(_customersExtent, objectId); 227 } 228 catch (Exception x) 229 { 230 throw new TestException(x); 231 } 232 } 233 234 public Customer[] getCustomerSet() throws TestException 235 { 236 try 237 { 238 return (Customer[]) getObjects(_customersExtent).toArray(new Customer[0]); 239 } 240 catch (Exception x) 241 { 242 throw new TestException(x); 243 } 244 } 245 246 public CustomerCursor getCustomerCursor() throws TestException 247 { 248 try 249 { 250 return new CustomerCursorImpl(getObjectsCursor(_customersExtent)); 251 } 252 catch (Exception x) 253 { 254 throw new TestException(x); 255 } 256 } 257 258 public CustomerCursor getCustomerCursor(CustomerQbe qbe) throws TestException 259 { 260 try 261 { 262 return new CustomerCursorImpl(getObjectsCursor((DjQueryByExample) qbe)); 263 } 264 catch (Exception x) 265 { 266 throw new TestException(x); 267 } 268 } 269 270 public CustomerCursor getCustomerCursor(Oql oql) throws TestException 271 { 272 try 273 { 274 return new CustomerCursorImpl(getObjectsCursor((DjOql) oql)); 275 } 276 catch (Exception x) 277 { 278 throw new TestException(x); 279 } 280 } 281 282 public Customer[] getCustomerSet(CustomerQbe qbe) throws TestException 283 { 284 try 285 { 286 return (Customer[]) getObjects((CustomerQbeImpl) qbe).toArray(new Customer[0]); 287 } 288 catch (Exception x) 289 { 290 throw new TestException(x); 291 } 292 } 293 294 public Customer[] getCustomerSet(Oql oql) throws TestException 295 { 296 try 297 { 298 return (Customer[]) getObjects((DjOql) oql).toArray(new Customer[0]); 299 } 300 catch (Exception x) 301 { 302 throw new TestException(x); 303 } 304 } 305 306 public Customer getCustomer(CustomerQbe qbe) throws TestException, TestNotFoundException, TestMultipleFoundException 307 { 308 DjList result = null; 309 try 310 { 311 result = getObjects((CustomerQbeImpl) qbe); 312 } 313 catch (Exception x) 314 { 315 throw new TestException(x); 316 } 317 if (result.size() == 0) throw new TestNotFoundException("Customer not found"); 318 if (result.size() > 1) throw new TestMultipleFoundException("More than 1 Customer found"); 319 return (Customer) result.getDjenericObjectAt(0); 320 } 321 322 public Customer getCustomer(Oql oql) throws TestException, TestNotFoundException, TestMultipleFoundException 323 { 324 DjList result = null; 325 try 326 { 327 result = getObjects((DjOql) oql); 328 } 329 catch (Exception x) 330 { 331 throw new TestException(x); 332 } 333 if (result.size() == 0) throw new TestNotFoundException("Customer not found"); 334 if (result.size() > 1) throw new TestMultipleFoundException("More than 1 Customer found"); 335 return (Customer) result.getDjenericObjectAt(0); 336 } 337 338 public Orderline getOrderline(long objectId) throws TestException 339 { 340 try 341 { 342 return (Orderline) getObject(_orderlinesExtent, objectId); 343 } 344 catch (Exception x) 345 { 346 throw new TestException(x); 347 } 348 } 349 350 public Orderline[] getOrderlineSet() throws TestException 351 { 352 try 353 { 354 return (Orderline[]) getObjects(_orderlinesExtent).toArray(new Orderline[0]); 355 } 356 catch (Exception x) 357 { 358 throw new TestException(x); 359 } 360 } 361 362 public OrderlineCursor getOrderlineCursor() throws TestException 363 { 364 try 365 { 366 return new OrderlineCursorImpl(getObjectsCursor(_orderlinesExtent)); 367 } 368 catch (Exception x) 369 { 370 throw new TestException(x); 371 } 372 } 373 374 public OrderlineCursor getOrderlineCursor(OrderlineQbe qbe) throws TestException 375 { 376 try 377 { 378 return new OrderlineCursorImpl(getObjectsCursor((DjQueryByExample) qbe)); 379 } 380 catch (Exception x) 381 { 382 throw new TestException(x); 383 } 384 } 385 386 public OrderlineCursor getOrderlineCursor(Oql oql) throws TestException 387 { 388 try 389 { 390 return new OrderlineCursorImpl(getObjectsCursor((DjOql) oql)); 391 } 392 catch (Exception x) 393 { 394 throw new TestException(x); 395 } 396 } 397 398 public Orderline[] getOrderlineSet(OrderlineQbe qbe) throws TestException 399 { 400 try 401 { 402 return (Orderline[]) getObjects((OrderlineQbeImpl) qbe).toArray(new Orderline[0]); 403 } 404 catch (Exception x) 405 { 406 throw new TestException(x); 407 } 408 } 409 410 public Orderline[] getOrderlineSet(Oql oql) throws TestException 411 { 412 try 413 { 414 return (Orderline[]) getObjects((DjOql) oql).toArray(new Orderline[0]); 415 } 416 catch (Exception x) 417 { 418 throw new TestException(x); 419 } 420 } 421 422 public Orderline getOrderline(OrderlineQbe qbe) throws TestException, TestNotFoundException, 423 TestMultipleFoundException 424 { 425 DjList result = null; 426 try 427 { 428 result = getObjects((OrderlineQbeImpl) qbe); 429 } 430 catch (Exception x) 431 { 432 throw new TestException(x); 433 } 434 if (result.size() == 0) throw new TestNotFoundException("Orderline not found"); 435 if (result.size() > 1) throw new TestMultipleFoundException("More than 1 Orderline found"); 436 return (Orderline) result.getDjenericObjectAt(0); 437 } 438 439 public Orderline getOrderline(Oql oql) throws TestException, TestNotFoundException, TestMultipleFoundException 440 { 441 DjList result = null; 442 try 443 { 444 result = getObjects((DjOql) oql); 445 } 446 catch (Exception x) 447 { 448 throw new TestException(x); 449 } 450 if (result.size() == 0) throw new TestNotFoundException("Orderline not found"); 451 if (result.size() > 1) throw new TestMultipleFoundException("More than 1 Orderline found"); 452 return (Orderline) result.getDjenericObjectAt(0); 453 } 454 455 public Order getOrder(long objectId) throws TestException 456 { 457 try 458 { 459 return (Order) getObject(_ordersExtent, objectId); 460 } 461 catch (Exception x) 462 { 463 throw new TestException(x); 464 } 465 } 466 467 public Order[] getOrderSet() throws TestException 468 { 469 try 470 { 471 return (Order[]) getObjects(_ordersExtent).toArray(new Order[0]); 472 } 473 catch (Exception x) 474 { 475 throw new TestException(x); 476 } 477 } 478 479 public OrderCursor getOrderCursor() throws TestException 480 { 481 try 482 { 483 return new OrderCursorImpl(getObjectsCursor(_ordersExtent)); 484 } 485 catch (Exception x) 486 { 487 throw new TestException(x); 488 } 489 } 490 491 public OrderCursor getOrderCursor(OrderQbe qbe) throws TestException 492 { 493 try 494 { 495 return new OrderCursorImpl(getObjectsCursor((DjQueryByExample) qbe)); 496 } 497 catch (Exception x) 498 { 499 throw new TestException(x); 500 } 501 } 502 503 public OrderCursor getOrderCursor(Oql oql) throws TestException 504 { 505 try 506 { 507 return new OrderCursorImpl(getObjectsCursor((DjOql) oql)); 508 } 509 catch (Exception x) 510 { 511 throw new TestException(x); 512 } 513 } 514 515 public Order[] getOrderSet(OrderQbe qbe) throws TestException 516 { 517 try 518 { 519 return (Order[]) getObjects((OrderQbeImpl) qbe).toArray(new Order[0]); 520 } 521 catch (Exception x) 522 { 523 throw new TestException(x); 524 } 525 } 526 527 public Order[] getOrderSet(Oql oql) throws TestException 528 { 529 try 530 { 531 return (Order[]) getObjects((DjOql) oql).toArray(new Order[0]); 532 } 533 catch (Exception x) 534 { 535 throw new TestException(x); 536 } 537 } 538 539 public Order getOrder(OrderQbe qbe) throws TestException, TestNotFoundException, TestMultipleFoundException 540 { 541 DjList result = null; 542 try 543 { 544 result = getObjects((OrderQbeImpl) qbe); 545 } 546 catch (Exception x) 547 { 548 throw new TestException(x); 549 } 550 if (result.size() == 0) throw new TestNotFoundException("Order not found"); 551 if (result.size() > 1) throw new TestMultipleFoundException("More than 1 Order found"); 552 return (Order) result.getDjenericObjectAt(0); 553 } 554 555 public Order getOrder(Oql oql) throws TestException, TestNotFoundException, TestMultipleFoundException 556 { 557 DjList result = null; 558 try 559 { 560 result = getObjects((DjOql) oql); 561 } 562 catch (Exception x) 563 { 564 throw new TestException(x); 565 } 566 if (result.size() == 0) throw new TestNotFoundException("Order not found"); 567 if (result.size() > 1) throw new TestMultipleFoundException("More than 1 Order found"); 568 return (Order) result.getDjenericObjectAt(0); 569 } 570 571 public Product getProduct(long objectId) throws TestException 572 { 573 try 574 { 575 return (Product) getObject(_productsExtent, objectId); 576 } 577 catch (Exception x) 578 { 579 throw new TestException(x); 580 } 581 } 582 583 public Product[] getProductSet() throws TestException 584 { 585 try 586 { 587 return (Product[]) getObjects(_productsExtent).toArray(new Product[0]); 588 } 589 catch (Exception x) 590 { 591 throw new TestException(x); 592 } 593 } 594 595 public ProductCursor getProductCursor() throws TestException 596 { 597 try 598 { 599 return new ProductCursorImpl(getObjectsCursor(_productsExtent)); 600 } 601 catch (Exception x) 602 { 603 throw new TestException(x); 604 } 605 } 606 607 public ProductCursor getProductCursor(ProductQbe qbe) throws TestException 608 { 609 try 610 { 611 return new ProductCursorImpl(getObjectsCursor((DjQueryByExample) qbe)); 612 } 613 catch (Exception x) 614 { 615 throw new TestException(x); 616 } 617 } 618 619 public ProductCursor getProductCursor(Oql oql) throws TestException 620 { 621 try 622 { 623 return new ProductCursorImpl(getObjectsCursor((DjOql) oql)); 624 } 625 catch (Exception x) 626 { 627 throw new TestException(x); 628 } 629 } 630 631 public Product[] getProductSet(ProductQbe qbe) throws TestException 632 { 633 try 634 { 635 return (Product[]) getObjects((ProductQbeImpl) qbe).toArray(new Product[0]); 636 } 637 catch (Exception x) 638 { 639 throw new TestException(x); 640 } 641 } 642 643 public Product[] getProductSet(Oql oql) throws TestException 644 { 645 try 646 { 647 return (Product[]) getObjects((DjOql) oql).toArray(new Product[0]); 648 } 649 catch (Exception x) 650 { 651 throw new TestException(x); 652 } 653 } 654 655 public Product getProduct(ProductQbe qbe) throws TestException, TestNotFoundException, TestMultipleFoundException 656 { 657 DjList result = null; 658 try 659 { 660 result = getObjects((ProductQbeImpl) qbe); 661 } 662 catch (Exception x) 663 { 664 throw new TestException(x); 665 } 666 if (result.size() == 0) throw new TestNotFoundException("Product not found"); 667 if (result.size() > 1) throw new TestMultipleFoundException("More than 1 Product found"); 668 return (Product) result.getDjenericObjectAt(0); 669 } 670 671 public Product getProduct(Oql oql) throws TestException, TestNotFoundException, TestMultipleFoundException 672 { 673 DjList result = null; 674 try 675 { 676 result = getObjects((DjOql) oql); 677 } 678 catch (Exception x) 679 { 680 throw new TestException(x); 681 } 682 if (result.size() == 0) throw new TestNotFoundException("Product not found"); 683 if (result.size() > 1) throw new TestMultipleFoundException("More than 1 Product found"); 684 return (Product) result.getDjenericObjectAt(0); 685 } 686 687 public HashMap [] getDomains() throws TestException 688 { 689 try 690 { 691 DjDomain[] domains = getPersistenceManager().getDomains(); 692 HashMap [] result = new HashMap [domains.length]; 693 for (int i = 0; i < domains.length; i++) 694 { 695 result[i] = doGetDomainDefinition(domains[i]); 696 } 697 return result; 698 } 699 catch (Exception x) 700 { 701 throw new TestException(x); 702 } 703 } 704 705 public HashMap getDomain(String domainName) throws TestException 706 { 707 try 708 { 709 return doGetDomainDefinition(getPersistenceManager().getDomain(domainName)); 710 } 711 catch (Exception x) 712 { 713 throw new TestException(x); 714 } 715 } 716 717 private Object [] getDomainValues(DjDomain domain) throws DjenericException 718 { 719 DjDomainValue[] validValues = domain.getValidValues(); 720 Object [] result = new Object [validValues.length]; 721 722 for (int i = 0; i < validValues.length; i++) 723 { 724 result[i] = validValues[i].getValue(); 725 } 726 return result; 727 } 728 729 private String [] getDomainValueDescriptions(DjDomain domain) throws DjenericException 730 { 731 DjDomainValue[] validValues = domain.getValidValues(); 732 String [] result = new String [validValues.length]; 733 734 for (int i = 0; i < validValues.length; i++) 735 { 736 result[i] = validValues[i].getDescription(); 737 } 738 return result; 739 } 740 741 private HashMap doGetDomainDefinition(DjDomain domain) throws DjenericException 742 { 743 HashMap result = new HashMap (); 744 result.put(TestSession.DOMAIN_NAME, domain.getName()); 745 result.put(TestSession.DOMAIN_DECIMALS, new Integer (domain.getDecimals())); 746 result.put(TestSession.DOMAIN_DESCRIPTION, domain.getDescription()); 747 result.put(TestSession.DOMAIN_ENFORCE, new Boolean (domain.isEnforced())); 748 result.put(TestSession.DOMAIN_FORMAT_MASK, domain.getFormatMask()); 749 result.put(TestSession.DOMAIN_LENGTH, new Integer (domain.getLength())); 750 result.put(TestSession.DOMAIN_TYPE, domain.getNativeTypeAsObject()); 751 result.put(TestSession.DOMAIN_VALUES, getDomainValues(domain)); 752 result.put(TestSession.DOMAIN_VALUE_DESCRIPTIONS, getDomainValueDescriptions(domain)); 753 return result; 754 } 755 756 760 } | Popular Tags |