1 64 package com.jcorporate.expresso.core.dataobjects.jdbc; 65 66 import com.jcorporate.expresso.core.dataobjects.DataException; 67 import com.jcorporate.expresso.core.dataobjects.DataFieldMetaData; 68 import com.jcorporate.expresso.core.dataobjects.DataObject; 69 import com.jcorporate.expresso.core.dataobjects.DataObjectMetaData; 70 import com.jcorporate.expresso.core.dataobjects.Defineable; 71 import com.jcorporate.expresso.core.db.DBException; 72 import com.jcorporate.expresso.core.i18n.Messages; 73 import com.jcorporate.expresso.core.misc.StringUtil; 74 75 import java.util.ArrayList ; 76 import java.util.Collections ; 77 import java.util.HashMap ; 78 import java.util.Iterator ; 79 import java.util.List ; 80 import java.util.Locale ; 81 import java.util.Map ; 82 import java.util.Set ; 83 import java.util.StringTokenizer ; 84 85 97 public class JoinedDataObjectMetaData implements DataObjectMetaData { 98 99 103 private HashMap myDataObjects = new HashMap (); 104 105 108 private List dataObjects = new ArrayList (); 109 110 113 private List aliasesInOrder = new ArrayList (); 114 115 118 private Map fieldsToRetrieve = new HashMap (); 119 120 123 private String description = "Joined Data Object"; 124 125 128 private boolean selectDistinct = false; 129 130 133 private ArrayList allFieldList = null; 134 135 138 private ArrayList keyFieldList = null; 139 140 143 private Map permissions = null; 144 145 148 HashMap allFieldMap = null; 149 150 154 HashMap primaryToForeignKeyMap = new HashMap (); 155 156 160 HashMap foreignKeyToPrimaryKeyMap = new HashMap (); 161 162 165 HashMap relations = new HashMap (); 166 167 private List sqlRelationList = new ArrayList (); 168 169 172 private Set allDetails = null; 173 174 177 private String name = ""; 178 179 182 public JoinedDataObjectMetaData() { 183 } 184 185 public Map getDataObjects() { 186 return Collections.unmodifiableMap(myDataObjects); 187 } 188 189 194 public List getDataObjectsInOrder() { 195 return this.dataObjects; 196 } 197 198 203 public List getAliasesInOrder() { 204 return this.aliasesInOrder; 205 } 206 207 213 public String getDefaultValue(String fieldName) { 214 String values[] = this.getObjectAndField(fieldName); 215 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 216 DataObjectMetaData metadata = oneObj.getMetaData(); 217 return metadata.getDefaultValue(values[1]); 218 } 219 220 235 public void addDataObject(Class dataObjectClass, String definitionName, 236 String alias, String fieldExpressionList) 237 throws DataException, IllegalArgumentException { 238 if (dataObjectClass == null) { 239 throw new IllegalArgumentException ("Must specify a class name"); 240 } 241 242 if (StringUtil.notNull(alias).equals("")) { 243 throw new IllegalArgumentException ("Must specify a short name"); 244 } 245 246 DataObject oneDBObj = null; 247 248 try { 249 oneDBObj = (DataObject) dataObjectClass.newInstance(); 250 } catch (InstantiationException ie) { 251 throw new DataException(":DBObject '" + dataObjectClass.getName() + 252 "' cannot be instantiated", ie); 253 } catch (IllegalAccessException iae) { 254 throw new DataException(":Illegal access loading DBObject '" + 255 dataObjectClass.getName() + "'", iae); 256 } 257 258 if (oneDBObj instanceof Defineable) { 259 ((Defineable) oneDBObj).setDefinitionName(definitionName); 260 } 261 262 oneDBObj.setAttribute("shortName", alias); 263 myDataObjects.put(alias, oneDBObj); 264 this.dataObjects.add(oneDBObj); 265 this.aliasesInOrder.add(alias); 266 267 if (fieldExpressionList != null) { 268 ArrayList fields = new ArrayList (); 269 StringTokenizer stok = new StringTokenizer (fieldExpressionList, "|"); 270 while (stok.hasMoreTokens()) { 271 String fieldExpression = (String ) stok.nextToken(); 272 int lastOpen = fieldExpression.lastIndexOf("("); 275 if (lastOpen == -1) { 276 fields.add(new FieldList(fieldExpression, fieldExpression, false)); 277 continue; 278 } 279 int firstClosed = fieldExpression.indexOf(")"); 280 if (firstClosed == -1) { 281 throw new DataException(":Invalid expression for DBObject '" + 282 dataObjectClass.getName()); 283 } 284 285 String fieldName = fieldExpression.substring(lastOpen + 1, 286 firstClosed); 287 int comma = fieldName.indexOf(","); 288 if (comma != -1) { 289 fieldName = fieldName.substring(comma); 290 } 291 JDBCDataObject JDBObj = (JDBCDataObject) oneDBObj; 292 fieldExpression = 293 StringUtil.replaceStringOnce(fieldExpression, fieldName, 294 JDBObj.getJDBCMetaData(). 295 getTargetTable() + "." + 296 fieldName); 297 fields.add(new FieldList(fieldExpression, fieldName, true)); 298 } 299 fieldsToRetrieve.put(alias, fields); 300 } 301 } 302 303 308 public synchronized Set getDetailSet() { 309 if (allDetails == null) { 310 allDetails = new java.util.HashSet (); 311 for (Iterator i = this.dataObjects.iterator(); i.hasNext();) { 312 JDBCDataObject oneDataObject = (JDBCDataObject) i.next(); 313 allDetails.addAll(oneDataObject.getMetaData().getDetailSet()); 314 } 315 } 316 317 return allDetails; 318 } 319 320 326 public String getDetailFieldsLocal(String detailName) { 327 if (allDetails == null) { 328 return ""; 329 } 330 331 int index = 0; 332 for (Iterator i = this.dataObjects.iterator(); i.hasNext(); index++) { 333 JDBCDataObject oneDataObject = (JDBCDataObject) i.next(); 334 String detailFields = oneDataObject.getMetaData().getDetailFieldsLocal(detailName); 335 336 if (detailFields != null && detailFields.length() > 0) { 337 String prefix = (String ) this.getAliasesInOrder().get(index) + "."; 338 java.lang.StringBuffer returnValue = new java.lang.StringBuffer (64); 339 java.util.StringTokenizer stok = new java.util.StringTokenizer (detailFields, "|"); 340 boolean needPipe = false; 341 while (stok.hasMoreTokens()) { 342 if (needPipe) { 343 returnValue.append("|"); 344 } else { 345 needPipe = true; 346 } 347 String oneField = stok.nextToken(); 348 returnValue.append(prefix); 349 returnValue.append(oneField); 350 } 351 352 return returnValue.toString(); 353 } 354 } 355 356 return ""; 357 } 358 359 365 public synchronized String getDetailFieldsForeign(String detailName) { 366 if (allDetails == null) { 367 return ""; 368 } 369 370 for (Iterator i = this.dataObjects.iterator(); i.hasNext();) { 371 JDBCDataObject oneDataObject = (JDBCDataObject) i.next(); 372 String detailFields = oneDataObject.getMetaData().getDetailFieldsForeign(detailName); 373 374 if (detailFields != null && detailFields.length() > 0) { 375 return detailFields; 376 } 393 } 394 395 return ""; 396 } 397 398 404 public boolean isAllowsNull(String fieldName) throws DBException { 405 String values[] = this.getObjectAndField(fieldName); 406 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 407 DataObjectMetaData metadata = oneObj.getMetaData(); 408 return metadata.isAllowsNull(values[1]); 409 } 410 411 412 418 public void removeAttribute(String fieldName, String attribName) { 419 String values[] = this.getObjectAndField(fieldName); 420 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 421 DataObjectMetaData metadata = oneObj.getMetaData(); 422 metadata.removeAttribute(values[1], attribName); 423 } 424 425 433 public void setAttribute(String fieldName, String attribName, Object attribValue) throws DBException { 434 String values[] = this.getObjectAndField(fieldName); 435 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 436 DataObjectMetaData metadata = oneObj.getMetaData(); 437 metadata.setAttribute(values[1], attribName, attribValue); 438 } 439 440 448 public Object getAttribute(String fieldName, String attribName) throws DBException { 449 String values[] = this.getObjectAndField(fieldName); 450 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 451 DataObjectMetaData metadata = oneObj.getMetaData(); 452 return metadata.getAttribute(values[1], attribName); 453 } 454 455 458 public void disableLogging() { 459 for (Iterator i = this.myDataObjects.keySet().iterator(); i.hasNext();) { 460 String key = (String ) i.next(); 461 DataObject value = (DataObject) myDataObjects.get(key); 462 value.getMetaData().disableLogging(); 463 } 464 } 465 466 472 public void enableLogging() { 473 for (Iterator i = this.myDataObjects.keySet().iterator(); i.hasNext();) { 474 String key = (String ) i.next(); 475 DataObject value = (DataObject) myDataObjects.get(key); 476 value.getMetaData().enableLogging(); 477 } 478 } 479 480 486 public boolean isLoggingEnabled() { 487 return this.getPrimaryDataObject().getMetaData().isLoggingEnabled(); 488 } 489 490 498 public String isFieldIgnoreCase(String fieldName) { 499 String values[] = this.getObjectAndField(fieldName); 500 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 501 DataObjectMetaData metadata = oneObj.getMetaData(); 502 return metadata.isFieldIgnoreCase(values[1]); 503 } 504 505 511 public boolean isField(String fieldName) { 512 String values[] = this.getObjectAndField(fieldName); 513 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 514 DataObjectMetaData metadata = oneObj.getMetaData(); 515 return metadata.isField(values[1]); 516 } 517 518 519 528 public synchronized HashMap getAllFieldsMap() { 529 if (this.allFieldMap == null) { 530 for (Iterator i = this.myDataObjects.keySet().iterator(); i.hasNext();) { 531 String key = (String ) i.next(); 532 533 DataObject oneObj = (DataObject) myDataObjects.get(key); 534 HashMap fieldMap = oneObj.getMetaData().getAllFieldsMap(); 535 for (Iterator j = fieldMap.keySet().iterator(); j.hasNext();) { 536 String fieldName = (String ) j.next(); 537 DataObjectMetaData metadata = (DataObjectMetaData) fieldMap.get(fieldName); 538 String fullFieldName = key + "." + fieldName; 539 if (this.foreignKeyToPrimaryKeyMap.containsKey(fullFieldName)) { 540 continue; 541 } else if (metadata.getFieldMetadata(fieldName).isCharacterLongObjectType()) { 542 continue; 543 } else { 544 this.allFieldMap.put(key + "." + fieldName, metadata); 545 } 546 } 547 548 } 549 } 550 551 return this.allFieldMap; 552 } 553 554 561 public List getFieldsToRetrieve(String alias) { 562 return (List ) this.fieldsToRetrieve.get(alias); 563 } 564 565 571 public HashMap getAllKeysMap() { 572 return this.getPrimaryDataObject().getMetaData().getAllKeysMap(); 573 } 574 575 580 public String getCharset() { 581 DataObject oneObj = this.getPrimaryDataObject(); 582 return oneObj.getMetaData().getCharset(); 583 } 584 585 590 public int getCacheSize() { 591 DataObject oneObj = this.getPrimaryDataObject(); 592 return oneObj.getMetaData().getCacheSize(); 593 } 594 595 596 602 public void setCacheSize(int newValue) { 603 DataObject oneObj = this.getPrimaryDataObject(); 604 oneObj.getMetaData().setCacheSize(newValue); 605 } 606 607 608 613 public String getDescription() { 614 return this.description; 615 } 616 617 626 public String getDescription(java.util.Locale l, String fieldName) { 627 String values[] = this.getObjectAndField(fieldName); 628 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 629 DataObjectMetaData metadata = oneObj.getMetaData(); 630 return metadata.getDescription(l, values[1]); 631 } 632 633 640 public String getDescription(String fieldName) throws DBException { 641 String values[] = this.getObjectAndField(fieldName); 642 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 643 DataObjectMetaData metadata = oneObj.getMetaData(); 644 return metadata.getDescription(values[1]); 645 } 646 647 653 public DataFieldMetaData getFieldMetadata(String fieldName) { 654 String values[] = this.getObjectAndField(fieldName); 655 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 656 DataObjectMetaData metadata = oneObj.getMetaData(); 657 return metadata.getFieldMetadata(values[1]); 658 } 659 660 661 666 public synchronized ArrayList getFieldListArray() { 667 668 if (this.allFieldList == null) { 672 ArrayList newList = new ArrayList (10); 673 for (Iterator i = this.dataObjects.iterator(); i.hasNext();) { 674 DataObject oneObj = (DataObject) i.next(); 675 ArrayList fieldList = oneObj.getMetaData().getFieldListArray(); 676 String dbobjName = null; 677 678 for (Iterator k = this.myDataObjects.keySet().iterator(); k.hasNext();) { 682 String key = (String ) k.next(); 683 JDBCDataObject obj = (JDBCDataObject) myDataObjects.get(key); 684 if (oneObj == obj) { 690 dbobjName = key; 691 break; 692 } 693 } 694 695 if (dbobjName == null) { 699 throw new IllegalStateException ("Unable to find short name for: " 700 + oneObj.getClass().getName()); 701 } 702 703 for (Iterator j = fieldList.iterator(); j.hasNext();) { 708 String fieldName = (String ) j.next(); 709 String completeFieldName = dbobjName + "." + fieldName; 710 if (this.foreignKeyToPrimaryKeyMap.containsKey(completeFieldName)) { 711 continue; 712 } else if (oneObj.getMetaData().getFieldMetadata(fieldName).isCharacterLongObjectType()) { 713 continue; 714 } else { 715 newList.add(completeFieldName); 716 } 717 } 718 719 } 720 721 this.allFieldList = newList; 722 } 723 return allFieldList; 724 } 725 726 727 733 public synchronized ArrayList getKeyFieldListArray() { 734 if (this.keyFieldList == null) { 735 keyFieldList = new ArrayList (this.getPrimaryDataObject().getMetaData().getKeyFieldListArray()); 736 String primaryAlias = this.getPrimaryAlias(); 737 for (int i = 0; i < keyFieldList.size(); i++) { 738 keyFieldList.set(i, primaryAlias + "." + (String ) keyFieldList.get(i)); 739 } 740 } 741 return keyFieldList; 742 } 743 744 745 752 public String getLength(String fieldName) throws DBException { 753 String values[] = this.getObjectAndField(fieldName); 754 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 755 DataObjectMetaData metadata = oneObj.getMetaData(); 756 return metadata.getLength(values[1]); 757 } 758 759 766 public int getLengthInt(String fieldName) throws DBException { 767 String values[] = this.getObjectAndField(fieldName); 768 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 769 DataObjectMetaData metadata = oneObj.getMetaData(); 770 return metadata.getLengthInt(values[1]); 771 } 772 773 779 public int getPrecision(String fieldName) throws DBException { 780 String values[] = this.getObjectAndField(fieldName); 781 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 782 DataObjectMetaData metadata = oneObj.getMetaData(); 783 return metadata.getPrecision(values[1]); 784 } 785 786 796 public String getLookupObject(String fieldName) throws DBException { 797 String values[] = this.getObjectAndField(fieldName); 798 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 799 DataObjectMetaData metadata = oneObj.getMetaData(); 800 return metadata.getLookupObject(values[1]); 801 } 802 803 812 public String getLookupField(String fieldName) { 813 String values[] = this.getObjectAndField(fieldName); 814 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 815 DataObjectMetaData metadata = oneObj.getMetaData(); 816 return metadata.getLookupField(values[1]); 817 } 818 819 820 826 public String getName() { 827 return this.name; 828 } 829 830 831 838 public String getType(String fieldName) throws DBException { 839 String values[] = this.getObjectAndField(fieldName); 840 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 841 DataObjectMetaData metadata = oneObj.getMetaData(); 842 return metadata.getType(values[1]); 843 } 844 845 846 854 public boolean hasField(String fieldName) { 855 String values[] = this.getObjectAndField(fieldName); 856 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 857 DataObjectMetaData metadata = oneObj.getMetaData(); 858 return metadata.hasField(values[1]); 859 } 860 861 862 870 public boolean isMultiValued(String fieldName) throws DBException { 871 String values[] = this.getObjectAndField(fieldName); 872 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 873 DataObjectMetaData metadata = oneObj.getMetaData(); 874 return metadata.isMultiValued(values[1]); 875 } 876 877 885 public boolean isReadOnly(String fieldName) throws DBException { 886 String values[] = this.getObjectAndField(fieldName); 887 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 888 DataObjectMetaData metadata = oneObj.getMetaData(); 889 return metadata.isReadOnly(values[1]); 890 } 891 892 904 public boolean isSecret(String fieldName) throws DBException { 905 String values[] = this.getObjectAndField(fieldName); 906 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 907 DataObjectMetaData metadata = oneObj.getMetaData(); 908 return metadata.isSecret(values[1]); 909 } 910 911 920 public boolean isVirtual(String fieldName) throws DBException { 921 String values[] = this.getObjectAndField(fieldName); 922 DataObject oneObj = (DataObject) myDataObjects.get(values[0]); 923 DataObjectMetaData metadata = oneObj.getMetaData(); 924 return metadata.isVirtual(values[1]); 925 } 926 927 936 public void setCheckZeroUpdate(boolean newFlag) { 937 for (Iterator i = this.myDataObjects.values().iterator(); i.hasNext();) { 938 DataObject oneObj = (DataObject) i.next(); 939 oneObj.getMetaData().setCheckZeroUpdate(newFlag); 940 } 941 } 942 943 948 public boolean checkZeroUpdate() { 949 return this.getPrimaryDataObject().getMetaData().checkZeroUpdate(); 950 } 951 952 957 public void setDescription(String newDescription) { 958 description = newDescription; 959 } 960 961 962 968 public void setName(String theName) { 969 this.name = theName; 970 } 971 972 973 978 public String getSchema() { 979 return this.getPrimaryDataObject().getMetaData().getSchema(); 980 } 981 982 990 public String getTargetDbSchema() { 991 return ((JDBCObjectMetaData) this.getPrimaryDataObject() 992 .getMetaData()).getTargetDbSchema(); 993 } 994 995 1003 public String getTargetDbCatalog() { 1004 return ((JDBCObjectMetaData) this.getPrimaryDataObject() 1005 .getMetaData()).getTargetDbCatalog(); 1006 } 1007 1008 1016 public String getTargetSQLTable(String dataContext) throws DataException { 1017 return ((JDBCObjectMetaData) this.getPrimaryDataObject() 1018 .getMetaData()).getTargetSQLTable(this 1019 .getPrimaryDataObject().getDataContext()); 1020 } 1021 1022 1031 public String [] getFields() { 1032 ArrayList list = this.getFieldListArray(); 1033 1034 String returnValue[] = new String [list.size()]; 1035 1036 return (String []) list.toArray(returnValue); 1037 } 1038 1039 1047 public String getDescription(Locale l) { 1048 String key = this.getDescription(); 1049 1050 if (key == null || key.length() == 0) { 1051 return "Unknown Table"; 1052 } 1053 1054 if (l == null) { 1055 l = Locale.getDefault(); 1056 } 1057 1058 String schema = this.getSchema(); 1059 if (schema == null || schema.length() == 0) { 1060 schema = com.jcorporate.expresso.core.ExpressoSchema.class.getName(); 1061 } 1062 1063 String returnValue; 1064 try { 1065 returnValue = Messages.getString(schema, l, key); 1066 } catch (IllegalArgumentException ex) { 1067 returnValue = key; 1068 } 1069 1070 return returnValue; 1071 1072 } 1073 1074 1081 public void setSelectDistinct(boolean flag) { 1082 selectDistinct = flag; 1083 } 1084 1085 1091 public java.util.Set getAllAttributes(String fieldName) { 1092 1093 throw new java.lang.UnsupportedOperationException ("Method getTransitionsIterator() not yet implemented."); 1094 } 1095 1096 1101 public boolean isSelectDistinct() { 1102 return selectDistinct; 1103 } 1104 1105 1106 1119 public void setForeignKey(String shortName, String foreignKey, 1120 String shortName2, String primaryKey, int joinType) throws DBException { 1121 JDBCDataObject foreignDBObj = (JDBCDataObject) myDataObjects.get(shortName); 1122 1123 if (foreignDBObj == null) { 1124 throw new DBException("DB Object with short name '" + 1125 shortName + "' is not part of this query"); 1126 } 1127 1128 JDBCDataObject primaryDBObj = (JDBCDataObject) myDataObjects.get(shortName2); 1129 1130 if (primaryDBObj == null) { 1131 throw new DBException("DB Object with short name '" + 1132 shortName2 + "' is not part of this query"); 1133 } 1134 1135 1136 Relation r = new JoinedDataObjectMetaData.Relation(); 1137 r.setLocalAlias(shortName); 1138 r.setLocalKey(foreignKey); 1139 r.setForeignAlias(shortName2); 1140 r.setForeignKey(primaryKey); 1141 r.setJoinType(joinType); 1142 1143 this.relations.put(shortName + "|" + shortName2, r); 1144 1145 1146 if (joinType == JoinedDataObject.UNSPECIFIED_JOIN) { 1147 sqlRelationList.add(foreignDBObj.getJDBCMetaData().getTargetSQLTable(foreignDBObj.getDataContext()) + "." + foreignKey + 1148 " = " + primaryDBObj.getJDBCMetaData().getTargetSQLTable(foreignDBObj.getDataContext()) + "." + 1149 primaryKey); 1150 } 1151 1152 1153 String localField = shortName + "." + foreignKey; 1154 String remoteField = shortName2 + "." + primaryKey; 1155 1156 1157 this.primaryToForeignKeyMap.put(remoteField, localField); 1158 this.foreignKeyToPrimaryKeyMap.put(localField, remoteField); 1159 1160 } 1161 1162 1163 1171 public Relation getRelation(String aliaslocal, String aliasJoined) { 1172 return (Relation) relations.get(aliaslocal + "|" + aliasJoined); 1173 } 1174 1175 1180 public Map getAllRelations() { 1181 return Collections.unmodifiableMap(relations); 1182 } 1183 1184 1189 public List getSQLRelationList() { 1190 return this.sqlRelationList; 1191 } 1192 1193 1194 1200 public synchronized HashMap createNestedDataObjects() throws DataException { 1201 HashMap returnMap = new HashMap (this.myDataObjects.size()); 1202 1203 for (Iterator i = myDataObjects.keySet().iterator(); i.hasNext();) { 1204 String key = (String ) i.next(); 1205 JDBCDataObject oneObj = (JDBCDataObject) myDataObjects.get(key); 1206 1207 try { 1208 JDBCDataObject newObj = (JDBCDataObject) oneObj.getClass().newInstance(); 1209 if (newObj instanceof Defineable) { 1210 ((Defineable) newObj).setDefinitionName(((Defineable) oneObj).getDefinitionName()); 1211 } 1212 returnMap.put(key, newObj); 1213 } catch (InstantiationException ex) { 1214 throw new DataException("Unable to instantiate new Data Object", ex); 1215 } catch (IllegalAccessException ex) { 1216 throw new DataException("Target Class " + oneObj.getClass() 1217 + " does not have a public default constructor"); 1218 } 1219 } 1220 1221 return returnMap; 1222 } 1223 1224 1225 1233 public String getPrimaryAlias() { 1234 List l = this.getAliasesInOrder(); 1235 if (l.size() == 0) { 1236 throw new IllegalArgumentException ("No 'primary' alias defined!"); 1237 } 1238 1239 return (String ) l.get(0); 1240 } 1241 1242 1247 private JDBCDataObject getPrimaryDataObject() { 1248 String shortName = this.getPrimaryAlias(); 1249 return (JDBCDataObject) this.myDataObjects.get(shortName); 1250 } 1251 1252 1258 public final String [] getObjectAndField(String fieldName) { 1259 String returnValue[] = new String [2]; 1260 1261 int dotPos = fieldName.indexOf("."); 1262 if (dotPos <= 0 || dotPos == (fieldName.length() - 1)) { 1263 throw new IllegalArgumentException ("Field name must be of format [dataobject alias].[fieldname]"); 1264 } 1265 1266 returnValue[0] = fieldName.substring(0, dotPos); 1267 DataObject oneObj = (DataObject) myDataObjects.get(returnValue[0]); 1268 1269 if (oneObj == null) { 1270 throw new IllegalArgumentException ("Unable to locate dataobject: " + returnValue[0]); 1271 } 1272 1273 returnValue[1] = fieldName.substring(dotPos + 1); 1274 return returnValue; 1275 } 1276 1277 protected Set getAllDetails() { 1279 return allDetails; 1280 } 1281 1282 1283 protected HashMap getForeignKeyToPrimaryKeyMap() { 1284 return foreignKeyToPrimaryKeyMap; 1285 } 1286 1287 1288 protected HashMap getMyDataObjects() { 1290 return myDataObjects; 1291 } 1292 1293 public Map getPermissions() { 1294 return Collections.unmodifiableMap(permissions); 1295 } 1296 1297 public void setPermissions(Map newPermissions) { 1298 permissions = new HashMap (newPermissions); 1299 } 1300 1301 protected HashMap getPrimaryToForeignKeyMap() { 1302 return primaryToForeignKeyMap; 1303 } 1304 1305 protected HashMap getRelations() { 1306 return relations; 1307 } 1308 1309 protected List getSqlRelationList() { 1310 return sqlRelationList; 1311 } 1312 1313 1318 public class Relation { 1319 private String localAlias; 1320 private String foreignAlias; 1321 private String localField; 1322 private String foreignField; 1323 private int joinType = JoinedDataObject.UNSPECIFIED_JOIN; 1324 1325 1330 public void setLocalAlias(String newValue) { 1331 this.localAlias = newValue; 1332 } 1333 1334 1339 public void setForeignAlias(String newValue) { 1340 this.foreignAlias = newValue; 1341 } 1342 1343 1348 public void setLocalKey(String newValue) { 1349 this.localField = newValue; 1350 } 1351 1352 1357 public void setForeignKey(String newValue) { 1358 this.foreignField = newValue; 1359 } 1360 1361 public void setJoinType(int newValue) { 1362 this.joinType = newValue; 1363 } 1364 1365 1370 public String getLocalAlias() { 1371 return localAlias; 1372 } 1373 1374 1379 public String getForeignAlias() { 1380 return this.foreignAlias; 1381 } 1382 1383 1388 public String getLocalField() { 1389 return this.localField; 1390 } 1391 1392 1397 public String getForeignField() { 1398 return this.foreignField; 1399 } 1400 1401 public int getJoinType() { 1402 return joinType; 1403 } 1404 1405 } 1406 1407 1412 public class FieldList { 1413 private String fieldExpression; 1414 private String fieldName; 1415 private boolean isExpression; 1416 1417 public FieldList(String fieldExpression, String fieldName, 1418 boolean isExpression) { 1419 this.fieldExpression = fieldExpression; 1420 this.fieldName = fieldName; 1421 this.isExpression = isExpression; 1422 } 1423 1424 public String getFieldExpression() { 1425 return fieldExpression; 1426 } 1427 1428 public String getFieldName() { 1429 return fieldName; 1430 } 1431 1432 public boolean isExpression() { 1433 return isExpression; 1434 } 1435 1436 } 1437 1438} 1439 | Popular Tags |