1 22 package org.jboss.ejb.plugins.cmp.jdbc.metadata; 23 24 import java.util.ArrayList ; 25 import java.util.Collection ; 26 import java.util.Collections ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 import java.util.Map ; 31 import java.lang.reflect.Method ; 32 33 34 import org.jboss.deployment.DeploymentException; 35 import org.jboss.metadata.EntityMetaData; 36 import org.jboss.metadata.MetaData; 37 import org.jboss.metadata.QueryMetaData; 38 import org.jboss.mx.util.MBeanServerLocator; 39 import org.w3c.dom.Element ; 40 41 import javax.management.ObjectName ; 42 import javax.management.MalformedObjectNameException ; 43 import javax.management.MBeanServer ; 44 45 55 public final class JDBCEntityMetaData 56 { 57 60 private final JDBCApplicationMetaData jdbcApplication; 61 62 65 private final String dataSourceName; 66 67 70 private final String datasourceMappingName; 71 72 75 private final JDBCTypeMappingMetaData datasourceMapping; 76 77 80 private final String entityName; 81 82 85 private final String abstractSchemaName; 86 87 90 private final Class entityClass; 91 92 95 private final Class homeClass; 96 97 100 private final Class remoteClass; 101 102 105 private final Class localHomeClass; 106 107 110 private final Class localClass; 111 112 115 private final boolean isCMP1x; 116 117 120 private final String tableName; 121 122 125 private final boolean createTable; 126 127 130 private final boolean removeTable; 131 132 135 private final boolean alterTable; 136 137 138 142 private final ArrayList tablePostCreateCmd; 143 144 147 private final boolean rowLocking; 148 149 152 private final boolean readOnly; 153 154 157 private final int readTimeOut; 158 159 162 private final boolean primaryKeyConstraint; 163 164 167 private final Class primaryKeyClass; 168 169 173 private final String primaryKeyFieldName; 174 175 178 private final Map cmpFieldsByName = new HashMap (); 179 private final List cmpFields = new ArrayList (); 180 181 184 private final Map loadGroups = new HashMap (); 185 186 190 private final String eagerLoadGroup; 191 192 196 private final List lazyLoadGroups = new ArrayList (); 197 198 201 private final Map queries = new HashMap (); 202 203 206 private final JDBCQueryMetaDataFactory queryFactory; 207 208 211 private final JDBCReadAheadMetaData readAhead; 212 213 217 private final boolean cleanReadAheadOnLoad; 218 219 223 private final int listCacheMax; 224 225 229 private final int fetchSize; 230 231 234 private final JDBCEntityCommandMetaData entityCommand; 235 236 237 240 241 private final JDBCOptimisticLockingMetaData optimisticLocking; 242 243 244 247 248 private final JDBCAuditMetaData audit; 249 250 private final Class qlCompiler; 251 252 255 private final boolean throwRuntimeExceptions; 256 257 258 270 public JDBCEntityMetaData(JDBCApplicationMetaData jdbcApplication, 271 EntityMetaData entity) 272 throws DeploymentException 273 { 274 this.jdbcApplication = jdbcApplication; 275 entityName = entity.getEjbName(); 276 listCacheMax = 1000; 277 fetchSize = 0; 278 279 try 280 { 281 entityClass = getClassLoader().loadClass(entity.getEjbClass()); 282 } 283 catch(ClassNotFoundException e) 284 { 285 throw new DeploymentException("entity class not found: " + entityName); 286 } 287 288 try 289 { 290 primaryKeyClass = getClassLoader().loadClass(entity.getPrimaryKeyClass()); 291 } 292 catch(ClassNotFoundException e) 293 { 294 throw new DeploymentException( 295 "could not load primary key class: " + 296 entity.getPrimaryKeyClass() 297 ); 298 } 299 300 isCMP1x = entity.isCMP1x(); 301 if(isCMP1x) 302 { 303 abstractSchemaName = (entity.getAbstractSchemaName() == null ? entityName : entity.getAbstractSchemaName()); 304 } 305 else 306 { 307 abstractSchemaName = entity.getAbstractSchemaName(); 308 } 309 310 primaryKeyFieldName = entity.getPrimKeyField(); 311 312 String home = entity.getHome(); 313 if(home != null) 314 { 315 try 316 { 317 homeClass = getClassLoader().loadClass(home); 318 } 319 catch(ClassNotFoundException e) 320 { 321 throw new DeploymentException("home class not found: " + home); 322 } 323 try 324 { 325 remoteClass = getClassLoader().loadClass(entity.getRemote()); 326 } 327 catch(ClassNotFoundException e) 328 { 329 throw new DeploymentException( 330 "remote class not found: " + 331 entity.getRemote() 332 ); 333 } 334 } 335 else 336 { 337 homeClass = null; 338 remoteClass = null; 339 } 340 341 String localHome = entity.getLocalHome(); 342 if(localHome != null) 343 { 344 try 345 { 346 localHomeClass = getClassLoader().loadClass(localHome); 347 } 348 catch(ClassNotFoundException e) 349 { 350 throw new DeploymentException( 351 "local home class not found: " + 352 localHome 353 ); 354 } 355 try 356 { 357 localClass = getClassLoader().loadClass(entity.getLocal()); 358 } 359 catch(ClassNotFoundException e) 360 { 361 throw new DeploymentException( 362 "local class not found: " + 363 entity.getLocal() 364 ); 365 } 366 } 367 else 368 { 369 if(home == null) 371 { 372 throw new DeploymentException( 373 "Entity must have atleast a home " + 374 "or local home: " + entityName 375 ); 376 } 377 378 localHomeClass = null; 379 localClass = null; 380 } 381 382 tableName = entityName.replace('.', '_'); 385 386 dataSourceName = null; 389 datasourceMappingName = null; 390 datasourceMapping = null; 391 createTable = false; 392 removeTable = false; 393 alterTable = false; 394 rowLocking = false; 395 primaryKeyConstraint = false; 396 readOnly = false; 397 readTimeOut = -1; 398 tablePostCreateCmd = null; 399 qlCompiler = null; 400 throwRuntimeExceptions = false; 401 402 List nonPkFieldNames = new ArrayList (); 405 for(Iterator i = entity.getCMPFields(); i.hasNext();) 406 { 407 String cmpFieldName = (String ) i.next(); 408 JDBCCMPFieldMetaData cmpField = new JDBCCMPFieldMetaData(this, cmpFieldName); 409 cmpFields.add(cmpField); 410 cmpFieldsByName.put(cmpFieldName, cmpField); 411 if(!cmpField.isPrimaryKeyMember()) 412 { 413 nonPkFieldNames.add(cmpFieldName); 414 } 415 } 416 417 if(primaryKeyClass == java.lang.Object .class) 422 { 423 JDBCCMPFieldMetaData upkField = new JDBCCMPFieldMetaData(this); 424 cmpFields.add(upkField); 425 cmpFieldsByName.put(upkField.getFieldName(), upkField); 426 } 427 428 eagerLoadGroup = "*"; 430 431 queryFactory = new JDBCQueryMetaDataFactory(this); 435 436 for(Iterator queriesIterator = entity.getQueries(); queriesIterator.hasNext();) 437 { 438 QueryMetaData queryData = (QueryMetaData) queriesIterator.next(); 439 Map newQueries = queryFactory.createJDBCQueryMetaData(queryData); 440 queries.putAll(newQueries); 442 } 443 444 447 readAhead = JDBCReadAheadMetaData.DEFAULT; 448 cleanReadAheadOnLoad = false; 449 entityCommand = null; 450 optimisticLocking = null; 451 audit = null; 452 } 453 454 466 public JDBCEntityMetaData(JDBCApplicationMetaData jdbcApplication, 467 Element element, 468 JDBCEntityMetaData defaultValues) 469 throws DeploymentException 470 { 471 this.jdbcApplication = jdbcApplication; 474 475 entityName = defaultValues.getName(); 477 entityClass = defaultValues.getEntityClass(); 478 primaryKeyClass = defaultValues.getPrimaryKeyClass(); 479 isCMP1x = defaultValues.isCMP1x; 480 primaryKeyFieldName = defaultValues.getPrimaryKeyFieldName(); 481 homeClass = defaultValues.getHomeClass(); 482 remoteClass = defaultValues.getRemoteClass(); 483 localHomeClass = defaultValues.getLocalHomeClass(); 484 localClass = defaultValues.getLocalClass(); 485 queryFactory = new JDBCQueryMetaDataFactory(this); 486 487 if(isCMP1x) 488 { 489 abstractSchemaName = (defaultValues.getAbstractSchemaName() == null ? 490 entityName : defaultValues.getAbstractSchemaName()); 491 } 492 else 493 { 494 abstractSchemaName = defaultValues.getAbstractSchemaName(); 495 } 496 497 String dataSourceNameString = MetaData.getOptionalChildContent(element, "datasource"); 499 if(dataSourceNameString != null) 500 { 501 dataSourceName = dataSourceNameString; 502 } 503 else 504 { 505 dataSourceName = defaultValues.getDataSourceName(); 506 } 507 508 String datasourceMappingString = MetaData.getOptionalChildContent(element, "datasource-mapping"); 511 if(datasourceMappingString != null) 512 { 513 datasourceMappingName = datasourceMappingString; 514 datasourceMapping = jdbcApplication.getTypeMappingByName(datasourceMappingString); 515 if(datasourceMapping == null) 516 { 517 throw new DeploymentException( 518 "Error in jbosscmp-jdbc.xml : " 519 + 520 "datasource-mapping " 521 + datasourceMappingString + 522 " not found" 523 ); 524 } 525 } 526 else if(defaultValues.datasourceMappingName != null && defaultValues.datasourceMapping != null) 527 { 528 datasourceMappingName = null; 529 datasourceMapping = defaultValues.datasourceMapping; 530 } 531 else 532 { 533 datasourceMappingName = null; 534 datasourceMapping = obtainTypeMappingFromLibrary(dataSourceName); 535 } 536 537 String tableStr = MetaData.getOptionalChildContent(element, "table-name"); 539 if(tableStr != null) 540 { 541 tableName = tableStr; 542 } 543 else 544 { 545 tableName = defaultValues.getDefaultTableName(); 546 } 547 548 String createStr = MetaData.getOptionalChildContent(element, "create-table"); 550 if(createStr != null) 551 { 552 createTable = Boolean.valueOf(createStr).booleanValue(); 553 } 554 else 555 { 556 createTable = defaultValues.getCreateTable(); 557 } 558 559 String removeStr = MetaData.getOptionalChildContent(element, "remove-table"); 561 if(removeStr != null) 562 { 563 removeTable = Boolean.valueOf(removeStr).booleanValue(); 564 } 565 else 566 { 567 removeTable = defaultValues.getRemoveTable(); 568 } 569 570 String alterStr = MetaData.getOptionalChildContent(element, "alter-table"); 572 if(alterStr != null) 573 { 574 alterTable = Boolean.valueOf(alterStr).booleanValue(); 575 } 576 else 577 { 578 alterTable = defaultValues.getAlterTable(); 579 } 580 581 582 Element posttc = MetaData.getOptionalChild(element, "post-table-create"); 584 if(posttc != null) 585 { 586 Iterator it = MetaData.getChildrenByTagName(posttc, "sql-statement"); 587 tablePostCreateCmd = new ArrayList (); 588 while(it.hasNext()) 589 { 590 Element etmp = (Element ) it.next(); 591 tablePostCreateCmd.add(MetaData.getElementContent(etmp)); 592 } 593 } 594 else 595 { 596 tablePostCreateCmd = defaultValues.getDefaultTablePostCreateCmd(); 597 } 598 599 String readOnlyStr = MetaData.getOptionalChildContent(element, "read-only"); 601 if(readOnlyStr != null) 602 { 603 readOnly = Boolean.valueOf(readOnlyStr).booleanValue(); 604 } 605 else 606 { 607 readOnly = defaultValues.isReadOnly(); 608 } 609 610 String readTimeOutStr = MetaData.getOptionalChildContent(element, "read-time-out"); 612 if(readTimeOutStr != null) 613 { 614 try 615 { 616 readTimeOut = Integer.parseInt(readTimeOutStr); 617 } 618 catch(NumberFormatException e) 619 { 620 throw new DeploymentException( 621 "Invalid number format in " + 622 "read-time-out '" + readTimeOutStr + "': " + e 623 ); 624 } 625 } 626 else 627 { 628 readTimeOut = defaultValues.getReadTimeOut(); 629 } 630 631 String sForUpStr = MetaData.getOptionalChildContent(element, "row-locking"); 632 if(sForUpStr != null) 633 { 634 rowLocking = !isReadOnly() && (Boolean.valueOf(sForUpStr).booleanValue()); 635 } 636 else 637 { 638 rowLocking = defaultValues.hasRowLocking(); 639 } 640 641 String pkStr = MetaData.getOptionalChildContent(element, "pk-constraint"); 643 if(pkStr != null) 644 { 645 primaryKeyConstraint = Boolean.valueOf(pkStr).booleanValue(); 646 } 647 else 648 { 649 primaryKeyConstraint = defaultValues.hasPrimaryKeyConstraint(); 650 } 651 652 String listCacheMaxStr = MetaData.getOptionalChildContent(element, "list-cache-max"); 654 if(listCacheMaxStr != null) 655 { 656 try 657 { 658 listCacheMax = Integer.parseInt(listCacheMaxStr); 659 } 660 catch(NumberFormatException e) 661 { 662 throw new DeploymentException( 663 "Invalid number format in read-" + 664 "ahead list-cache-max '" + listCacheMaxStr + "': " + e 665 ); 666 } 667 if(listCacheMax < 0) 668 { 669 throw new DeploymentException( 670 "Negative value for read ahead " + 671 "list-cache-max '" + listCacheMaxStr + "'." 672 ); 673 } 674 } 675 else 676 { 677 listCacheMax = defaultValues.getListCacheMax(); 678 } 679 680 String fetchSizeStr = MetaData.getOptionalChildContent(element, "fetch-size"); 682 if(fetchSizeStr != null) 683 { 684 try 685 { 686 fetchSize = Integer.parseInt(fetchSizeStr); 687 } 688 catch(NumberFormatException e) 689 { 690 throw new DeploymentException( 691 "Invalid number format in " + 692 "fetch-size '" + fetchSizeStr + "': " + e 693 ); 694 } 695 if(fetchSize < 0) 696 { 697 throw new DeploymentException( 698 "Negative value for fetch size " + 699 "fetch-size '" + fetchSizeStr + "'." 700 ); 701 } 702 } 703 else 704 { 705 fetchSize = defaultValues.getFetchSize(); 706 } 707 708 String compiler = MetaData.getOptionalChildContent(element, "ql-compiler"); 709 if(compiler == null) 710 { 711 qlCompiler = defaultValues.qlCompiler; 712 } 713 else 714 { 715 try 716 { 717 qlCompiler = GetTCLAction.getContextClassLoader().loadClass(compiler); 718 } 719 catch(ClassNotFoundException e) 720 { 721 throw new DeploymentException("Failed to load compiler implementation: " + compiler); 722 } 723 } 724 725 String throwRuntimeExceptionsStr = MetaData.getOptionalChildContent(element, "throw-runtime-exceptions"); 727 if(throwRuntimeExceptionsStr != null) 728 { 729 throwRuntimeExceptions = Boolean.valueOf(throwRuntimeExceptionsStr).booleanValue(); 730 } 731 else 732 { 733 throwRuntimeExceptions = defaultValues.getThrowRuntimeExceptions(); 734 } 735 736 737 741 for(Iterator cmpFieldIterator = defaultValues.cmpFields.iterator(); 743 cmpFieldIterator.hasNext();) 744 { 745 746 JDBCCMPFieldMetaData cmpField = new JDBCCMPFieldMetaData(this, (JDBCCMPFieldMetaData) cmpFieldIterator.next()); 747 cmpFields.add(cmpField); 748 cmpFieldsByName.put(cmpField.getFieldName(), cmpField); 749 } 750 751 for(Iterator i = MetaData.getChildrenByTagName(element, "cmp-field"); i.hasNext();) 753 { 754 Element cmpFieldElement = (Element ) i.next(); 755 String fieldName = MetaData.getUniqueChildContent(cmpFieldElement, "field-name"); 756 757 JDBCCMPFieldMetaData oldCMPField = (JDBCCMPFieldMetaData) cmpFieldsByName.get(fieldName); 758 if(oldCMPField == null) 759 { 760 throw new DeploymentException("CMP field not found : fieldName=" + fieldName); 761 } 762 JDBCCMPFieldMetaData cmpFieldMetaData = new JDBCCMPFieldMetaData( 763 this, 764 cmpFieldElement, 765 oldCMPField 766 ); 767 768 cmpFieldsByName.put(fieldName, cmpFieldMetaData); 770 int index = cmpFields.indexOf(oldCMPField); 771 cmpFields.remove(oldCMPField); 772 cmpFields.add(index, cmpFieldMetaData); 773 } 774 775 if(primaryKeyClass == java.lang.Object .class) 777 { 778 Element upkElement = MetaData.getOptionalChild(element, "unknown-pk"); 779 if(upkElement != null) 780 { 781 JDBCCMPFieldMetaData oldUpkField = null; 783 for(Iterator iter = cmpFields.iterator(); iter.hasNext();) 784 { 785 JDBCCMPFieldMetaData cmpField = (JDBCCMPFieldMetaData) iter.next(); 786 if(cmpField.isUnknownPkField()) 787 { 788 oldUpkField = cmpField; 789 break; 790 } 791 } 792 793 if(oldUpkField == null) 795 { 796 oldUpkField = new JDBCCMPFieldMetaData(this); 797 } 798 799 JDBCCMPFieldMetaData upkField = new JDBCCMPFieldMetaData(this, upkElement, oldUpkField); 800 801 cmpFieldsByName.remove(oldUpkField.getFieldName()); 803 cmpFieldsByName.put(upkField.getFieldName(), upkField); 804 805 int oldUpkFieldInd = cmpFields.indexOf(oldUpkField); 806 cmpFields.remove(oldUpkField); 807 cmpFields.add(oldUpkFieldInd, upkField); 808 } 809 } 810 811 loadGroups.putAll(defaultValues.loadGroups); 813 loadLoadGroupsXml(element); 814 815 Element eagerLoadGroupElement = MetaData.getOptionalChild(element, "eager-load-group"); 817 if(eagerLoadGroupElement != null) 818 { 819 String eagerLoadGroupTmp = MetaData.getElementContent(eagerLoadGroupElement); 820 if(eagerLoadGroupTmp != null && eagerLoadGroupTmp.trim().length() == 0) 821 { 822 eagerLoadGroupTmp = null; 823 } 824 if(eagerLoadGroupTmp != null 825 && !eagerLoadGroupTmp.equals("*") 826 && !loadGroups.containsKey(eagerLoadGroupTmp)) 827 { 828 throw new DeploymentException( 829 "Eager load group not found: " + 830 "eager-load-group=" + eagerLoadGroupTmp 831 ); 832 } 833 eagerLoadGroup = eagerLoadGroupTmp; 834 } 835 else 836 { 837 eagerLoadGroup = defaultValues.getEagerLoadGroup(); 838 } 839 840 lazyLoadGroups.addAll(defaultValues.lazyLoadGroups); 842 loadLazyLoadGroupsXml(element); 843 844 Element readAheadElement = MetaData.getOptionalChild(element, "read-ahead"); 846 if(readAheadElement != null) 847 { 848 readAhead = new JDBCReadAheadMetaData(readAheadElement, defaultValues.getReadAhead()); 849 } 850 else 851 { 852 readAhead = defaultValues.readAhead; 853 } 854 855 String value = MetaData.getOptionalChildContent(element, "clean-read-ahead-on-load"); 856 if("true".equalsIgnoreCase(value)) 857 { 858 cleanReadAheadOnLoad = true; 859 } 860 else if("false".equalsIgnoreCase(value)) 861 { 862 cleanReadAheadOnLoad = false; 863 } 864 else if(value == null) 865 { 866 cleanReadAheadOnLoad = defaultValues.cleanReadAheadOnLoad; 867 } 868 else 869 { 870 throw new DeploymentException("Failed to deploy " + entityName + 871 ": allowed values for clean-read-ahead-on-load are true and false but got " + value); 872 } 873 874 Element optimisticLockingEl = MetaData.getOptionalChild(element, "optimistic-locking"); 876 if(optimisticLockingEl != null) 877 { 878 optimisticLocking = new JDBCOptimisticLockingMetaData(this, optimisticLockingEl); 879 } 880 else 881 { 882 optimisticLocking = defaultValues.getOptimisticLocking(); 883 } 884 885 Element auditElement = MetaData.getOptionalChild(element, "audit"); 887 if(auditElement != null) 888 { 889 audit = new JDBCAuditMetaData(this, auditElement); 890 } 891 else 892 { 893 audit = defaultValues.getAudit(); 894 } 895 896 898 for(Iterator queriesIterator = defaultValues.queries.values().iterator(); 900 queriesIterator.hasNext();) 901 { 902 JDBCQueryMetaData query = JDBCQueryMetaDataFactory.createJDBCQueryMetaData( 903 (JDBCQueryMetaData) queriesIterator.next(), 904 readAhead, qlCompiler 905 ); 906 queries.put(query.getMethod(), query); 907 } 908 909 for(Iterator queriesIterator = MetaData.getChildrenByTagName(element, "query"); 911 queriesIterator.hasNext();) 912 { 913 Element queryElement = (Element ) queriesIterator.next(); 914 Map newQueries = queryFactory.createJDBCQueryMetaData( 915 queryElement, 916 defaultValues.queries, 917 readAhead 918 ); 919 920 queries.putAll(newQueries); 922 } 923 924 Element entityCommandEl = MetaData.getOptionalChild(element, "entity-command"); 926 if(entityCommandEl != null) 927 { 928 String entityCommandName = entityCommandEl.getAttribute("name"); 930 931 JDBCEntityCommandMetaData defaultEntityCommand = defaultValues.getEntityCommand(); 941 942 if((defaultEntityCommand == null) 943 || (!entityCommandName.equals(defaultEntityCommand.getCommandName()))) 944 { 945 defaultEntityCommand = jdbcApplication.getEntityCommandByName(entityCommandName); 946 } 947 948 if(defaultEntityCommand != null) 949 { 950 entityCommand = new JDBCEntityCommandMetaData(entityCommandEl, defaultEntityCommand); 951 } 952 else 953 { 954 entityCommand = new JDBCEntityCommandMetaData(entityCommandEl); 955 } 956 } 957 else 958 { 959 entityCommand = defaultValues.getEntityCommand(); 960 } 961 } 962 963 966 private void loadLoadGroupsXml(Element element) 967 throws DeploymentException 968 { 969 970 Element loadGroupsElement = MetaData.getOptionalChild(element, "load-groups"); 971 if(loadGroupsElement == null) 972 { 973 return; 975 } 976 977 if(isCMP1x) 979 { 980 throw new DeploymentException( 981 "load-groups are only allowed " + 982 "for CMP 2.x" 983 ); 984 } 985 986 Iterator groups = MetaData.getChildrenByTagName(loadGroupsElement, "load-group"); 988 while(groups.hasNext()) 989 { 990 Element groupElement = (Element ) groups.next(); 991 992 String loadGroupName = MetaData.getUniqueChildContent(groupElement, "load-group-name"); 994 if(loadGroups.containsKey(loadGroupName)) 995 { 996 throw new DeploymentException( 997 "Load group already defined: " + 998 " load-group-name=" + loadGroupName 999 ); 1000 } 1001 if(loadGroupName.equals("*")) 1002 { 1003 throw new DeploymentException( 1004 "The * load group is automatically " + 1005 "defined and can't be overriden" 1006 ); 1007 } 1008 ArrayList group = new ArrayList (); 1009 1010 Iterator fields = MetaData.getChildrenByTagName(groupElement, "field-name"); 1012 while(fields.hasNext()) 1013 { 1014 String fieldName = MetaData.getElementContent((Element ) fields.next()); 1015 1016 JDBCCMPFieldMetaData field = getCMPFieldByName(fieldName); 1018 if(field != null && field.isPrimaryKeyMember()) 1019 { 1020 throw new DeploymentException( 1021 "Primary key fields can not be" 1022 + 1023 " a member of a load group: " 1024 + 1025 " load-group-name=" 1026 + loadGroupName + 1027 " field-name=" + fieldName 1028 ); 1029 } 1030 1031 group.add(fieldName); 1032 } 1033 1034 loadGroups.put(loadGroupName, Collections.unmodifiableList(group)); 1035 } 1036 } 1037 1038 1041 private void loadLazyLoadGroupsXml(Element element) 1042 throws DeploymentException 1043 { 1044 Element lazyLoadGroupsElement = MetaData.getOptionalChild(element, "lazy-load-groups"); 1045 1046 if(lazyLoadGroupsElement == null) 1048 { 1049 return; 1050 } 1051 1052 if(isCMP1x) 1054 { 1055 throw new DeploymentException("lazy-load-groups is only allowed for CMP 2.x"); 1056 } 1057 1058 Iterator loadGroupNames = MetaData.getChildrenByTagName(lazyLoadGroupsElement, "load-group-name"); 1060 while(loadGroupNames.hasNext()) 1061 { 1062 String loadGroupName = MetaData.getElementContent((Element ) loadGroupNames.next()); 1063 if(!loadGroupName.equals("*") && !loadGroups.containsKey(loadGroupName)) 1064 { 1065 throw new DeploymentException( 1066 "Lazy load group not found: " + 1067 "load-group-name=" + loadGroupName 1068 ); 1069 } 1070 1071 lazyLoadGroups.add(loadGroupName); 1072 } 1073 1074 } 1075 1076 1081 public JDBCApplicationMetaData getJDBCApplication() 1082 { 1083 return jdbcApplication; 1084 } 1085 1086 1091 public String getDataSourceName() 1092 { 1093 return dataSourceName; 1094 } 1095 1096 1101 public JDBCTypeMappingMetaData getTypeMapping() throws DeploymentException 1102 { 1103 if(datasourceMapping == null) 1104 { 1105 throw new DeploymentException("type-mapping is not initialized: " + dataSourceName 1106 + " was not deployed or type-mapping was not configured."); 1107 } 1108 1109 return datasourceMapping; 1110 } 1111 1112 1117 public String getName() 1118 { 1119 return entityName; 1120 } 1121 1122 1128 public String getAbstractSchemaName() 1129 { 1130 return abstractSchemaName; 1131 } 1132 1133 1140 public ClassLoader getClassLoader() 1141 { 1142 return jdbcApplication.getClassLoader(); 1143 } 1144 1145 1150 public Class getEntityClass() 1151 { 1152 return entityClass; 1153 } 1154 1155 1160 public Class getHomeClass() 1161 { 1162 return homeClass; 1163 } 1164 1165 1170 public Class getRemoteClass() 1171 { 1172 return remoteClass; 1173 } 1174 1175 1180 public Class getLocalHomeClass() 1181 { 1182 return localHomeClass; 1183 } 1184 1185 1190 public Class getLocalClass() 1191 { 1192 return localClass; 1193 } 1194 1195 1200 public boolean isCMP1x() 1201 { 1202 return isCMP1x; 1203 } 1204 1205 1210 public List getCMPFields() 1211 { 1212 return Collections.unmodifiableList(cmpFields); 1213 } 1214 1215 1221 public String getEagerLoadGroup() 1222 { 1223 return eagerLoadGroup; 1224 } 1225 1226 1231 public List getLazyLoadGroups() 1232 { 1233 return Collections.unmodifiableList(lazyLoadGroups); 1234 } 1235 1236 1242 public Map getLoadGroups() 1243 { 1244 return Collections.unmodifiableMap(loadGroups); 1245 } 1246 1247 1253 public List getLoadGroup(String name) throws DeploymentException 1254 { 1255 List group = (List ) loadGroups.get(name); 1256 if(group == null) 1257 { 1258 throw new DeploymentException("Unknown load group: name=" + name); 1259 } 1260 return group; 1261 } 1262 1263 1266 public JDBCOptimisticLockingMetaData getOptimisticLocking() 1267 { 1268 return optimisticLocking; 1269 } 1270 1271 1274 public JDBCAuditMetaData getAudit() 1275 { 1276 return audit; 1277 } 1278 1279 1285 public JDBCCMPFieldMetaData getCMPFieldByName(String name) 1286 { 1287 return (JDBCCMPFieldMetaData) cmpFieldsByName.get(name); 1288 } 1289 1290 1295 public String getDefaultTableName() 1296 { 1297 return tableName; 1298 } 1299 1300 1306 public boolean getCreateTable() 1307 { 1308 return createTable; 1309 } 1310 1311 1317 public boolean getRemoveTable() 1318 { 1319 return removeTable; 1320 } 1321 1322 1326 public boolean getAlterTable() 1327 { 1328 return alterTable; 1329 } 1330 1331 1337 public ArrayList getDefaultTablePostCreateCmd() 1338 { 1339 return tablePostCreateCmd; 1340 } 1341 1342 1349 public boolean hasPrimaryKeyConstraint() 1350 { 1351 return primaryKeyConstraint; 1352 } 1353 1354 1361 public boolean hasRowLocking() 1362 { 1363 return rowLocking; 1364 } 1365 1366 1369 public int getListCacheMax() 1370 { 1371 return listCacheMax; 1372 } 1373 1374 1378 public int getFetchSize() 1379 { 1380 return fetchSize; 1381 } 1382 1383 1384 1389 public Collection getQueries() 1390 { 1391 return Collections.unmodifiableCollection(queries.values()); 1392 } 1393 1394 1398 public JDBCQueryMetaData getQueryMetaDataForMethod(Method method) 1399 { 1400 return (JDBCQueryMetaData) queries.get(method); 1401 } 1402 1403 1410 public Collection getRelationshipRoles() 1411 { 1412 return jdbcApplication.getRolesForEntity(entityName); 1413 } 1414 1415 1420 public Class getPrimaryKeyClass() 1421 { 1422 return primaryKeyClass; 1423 } 1424 1425 1430 public JDBCEntityCommandMetaData getEntityCommand() 1431 { 1432 return entityCommand; 1433 } 1434 1435 1441 public boolean isReadOnly() 1442 { 1443 return readOnly; 1444 } 1445 1446 1457 public int getReadTimeOut() 1458 { 1459 return readTimeOut; 1460 } 1461 1462 1469 public String getPrimaryKeyFieldName() 1470 { 1471 return primaryKeyFieldName; 1472 } 1473 1474 1475 1480 public JDBCReadAheadMetaData getReadAhead() 1481 { 1482 return readAhead; 1483 } 1484 1485 public Class getQLCompiler() 1486 { 1487 return qlCompiler; 1488 } 1489 1490 1495 public boolean isThrowRuntimeExceptions() 1496 { 1497 return throwRuntimeExceptions; 1498 } 1499 1504 public boolean getThrowRuntimeExceptions() 1505 { 1506 return throwRuntimeExceptions; 1507 } 1508 1509 1510 public boolean isCleanReadAheadOnLoad() 1511 { 1512 return cleanReadAheadOnLoad; 1513 } 1514 1515 public static JDBCTypeMappingMetaData obtainTypeMappingFromLibrary(String dataSourceName) 1516 throws DeploymentException 1517 { 1518 JDBCTypeMappingMetaData typeMapping = null; 1519 1520 String datasource; 1521 if(dataSourceName.startsWith("java:")) 1522 { 1523 datasource = dataSourceName.substring("java:".length()); 1524 if(datasource.startsWith("/")) 1525 { 1526 datasource = datasource.substring(1); 1527 } 1528 } 1529 else 1530 { 1531 datasource = dataSourceName; 1532 } 1533 1534 final ObjectName metadataService; 1535 final String str = "jboss.jdbc:service=metadata,datasource=" + datasource; 1536 try 1537 { 1538 metadataService = new ObjectName (str); 1539 } 1540 catch(MalformedObjectNameException e) 1541 { 1542 throw new DeploymentException("Failed to create ObjectName for datasource metadata MBean: " + str, e); 1543 } 1544 1545 try 1546 { 1547 final MBeanServer server = MBeanServerLocator.locateJBoss(); 1548 if(server.isRegistered(metadataService)) 1549 { 1550 typeMapping = (JDBCTypeMappingMetaData)server.getAttribute(metadataService, "TypeMappingMetaData"); 1551 } 1552 } 1553 catch(Exception e) 1554 { 1555 throw new DeploymentException("Failed to obtain type-mapping metadata from the metadata library MBean: " + 1556 e.getMessage(), e); 1557 } 1558 1559 1568 1569 return typeMapping; 1570 } 1571 1572 1581 public boolean equals(Object o) 1582 { 1583 if(o instanceof JDBCEntityMetaData) 1584 { 1585 JDBCEntityMetaData entity = (JDBCEntityMetaData) o; 1586 return entityName.equals(entity.entityName) && 1587 jdbcApplication.equals(entity.jdbcApplication); 1588 } 1589 return false; 1590 } 1591 1592 1599 public int hashCode() 1600 { 1601 int result = 17; 1602 result = 37 * result + jdbcApplication.hashCode(); 1603 result = 37 * result + entityName.hashCode(); 1604 return result; 1605 } 1606 1607 1616 public String toString() 1617 { 1618 return "[JDBCEntityMetaData : entityName=" + entityName + "]"; 1619 } 1620} 1621 | Popular Tags |