1 64 65 package com.jcorporate.expresso.core.dbobj; 66 67 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap; 68 import com.jcorporate.expresso.core.ExpressoSchema; 69 import com.jcorporate.expresso.core.controller.Transition; 70 import com.jcorporate.expresso.core.dataobjects.DataException; 71 import com.jcorporate.expresso.core.dataobjects.DataFieldMetaData; 72 import com.jcorporate.expresso.core.dataobjects.jdbc.JDBCObjectMetaData; 73 import com.jcorporate.expresso.core.db.DBException; 74 import com.jcorporate.expresso.core.db.config.JDBCConfig; 75 import com.jcorporate.expresso.core.i18n.Messages; 76 import com.jcorporate.expresso.core.misc.ConfigManager; 77 import com.jcorporate.expresso.core.misc.ConfigurationException; 78 import com.jcorporate.expresso.core.misc.StringUtil; 79 import com.jcorporate.expresso.core.security.filters.FilterManager; 80 import org.apache.log4j.Logger; 81 import org.apache.oro.text.regex.MalformedPatternException; 82 import org.apache.oro.text.regex.Pattern; 83 import org.apache.oro.text.regex.PatternCompiler; 84 import org.apache.oro.text.regex.Perl5Compiler; 85 86 import java.util.ArrayList ; 87 import java.util.Enumeration ; 88 import java.util.HashMap ; 89 import java.util.Hashtable ; 90 import java.util.Iterator ; 91 import java.util.Locale ; 92 import java.util.Map ; 93 import java.util.Set ; 94 import java.util.StringTokenizer ; 95 import java.util.Vector ; 96 97 98 110 public class DBObjectDef 111 implements JDBCObjectMetaData { 112 113 private static final String OBJECT_NAME_NOT_ASSIGNED = "NOT ASSIGNED"; 114 115 116 transient private static Logger log = Logger.getLogger(DBObjectDef.class); 117 118 122 transient private static PatternCompiler patternCompiler = 123 new Perl5Compiler(); 124 125 128 transient private static FilterManager filterManager = FilterManager.getInstance(); 129 130 134 137 private Map allFields = new ConcurrentReaderHashMap(); 138 139 140 143 private ArrayList fieldNamesInOrder = new ArrayList (); 144 private Map allKeys = new ConcurrentReaderHashMap(); 145 private ArrayList keyList = new ArrayList (); 146 private String objectDescription = ""; 147 148 153 private Map allInParameters = new ConcurrentReaderHashMap(); 154 private ArrayList inParamList = new ArrayList (); 155 private Map allOutParameters = new ConcurrentReaderHashMap(); 156 private ArrayList outParamList = new ArrayList (); 157 158 159 165 private Hashtable detailObjsLocal = new Hashtable (); 166 private Hashtable detailObjsForeign = new Hashtable (); 167 168 172 private ArrayList transitionTabs = new ArrayList (); 173 174 179 private ArrayList indexList = null; 180 181 184 private String tableName = ""; 185 186 189 private String storeProcedureName = (""); 190 191 private boolean returningValue = false; 192 193 194 197 private String dbSchemaName = (""); 198 199 202 private String dbCatalogName = (""); 203 204 205 208 private String charSet = "ISO-8859-1"; 209 private String mObjectName = OBJECT_NAME_NOT_ASSIGNED; 210 211 214 private boolean loggingEnabled = false; 215 216 219 private String mySchema = ExpressoSchema.class.getName(); 220 221 225 private boolean checkZeroUpdate = true; 226 227 transient private int cacheSize = -2; 228 229 234 public DBObjectDef() { 235 } 236 237 250 synchronized public void addField(String fieldName, String fieldType, 251 int fieldSize, int fieldPrecision, 252 boolean allowNull, String fieldDescription) 253 throws DBException { 254 if (ConfigManager.isReservedWord(fieldName)) { 255 throw new DBException("You cannot have a field name of " + 256 fieldName + 257 ". It is a reserved word. Check " + 258 "com.jcorporate.expresso.core.misc.ReservedWords for a full list" + 259 " of reservered words"); 260 } 261 262 if (!DBField.allDataTypes.contains(fieldType)) { 263 throw new DBException("You cannot have a field type of : " + fieldType + 264 ". It is not a recognized Expresso datatype." + 265 " See: com.jcorporate.expresso.core.dbobj.DBField for a list of all recognized datatypes"); 266 } 267 268 allFields.put(fieldName, 269 new DBField(fieldName, fieldType, fieldSize, 270 fieldPrecision, allowNull, fieldDescription)); 271 272 276 if (fieldType.equalsIgnoreCase(DBField.INTEGER_TYPE) || 277 fieldType.equalsIgnoreCase(DBField.INT_TYPE)) { 278 279 setMask(fieldName, DBObject.INT_MASK); 280 setAttribute(fieldName, DBObject.ATTRIBUTE_ERROR_MESSAGE, 281 "You must enter a valid integer for field: " 282 + fieldDescription); 283 } 284 285 286 fieldNamesInOrder.add(fieldName); 287 } 288 289 290 297 synchronized public void setDefaultValue(String fieldName, String fieldValue) 298 throws DBException { 299 if (!isField(fieldName)) { 300 throw new DBException("No such field as '" + fieldName + 301 "' in db object '" + getName() + "'"); 302 } 303 304 getFieldMetadata(fieldName).setDefaultValue(fieldValue); 305 } 306 307 310 public String getDefaultValue(String fieldName) { 311 return getFieldMetadata(fieldName).getDefaultValue(); 312 } 313 314 323 synchronized public void addDetail(String objName, String keyFieldsLocal, 324 String keyFieldsForeign) 325 throws DBException { 326 detailObjsLocal.put(objName, keyFieldsLocal); 327 detailObjsForeign.put(objName, keyFieldsForeign); 328 } 329 330 public Enumeration getDetails() { 331 return detailObjsLocal.keys(); 332 } 333 334 public String getDetailFieldsLocal(String detailName) { 335 return (String ) detailObjsLocal.get(detailName); 336 } 337 338 public String getDetailFieldsForeign(String detailName) { 339 return (String ) detailObjsForeign.get(detailName); 340 } 341 342 359 synchronized public void addField(String fieldName, String fieldType, 360 int fieldSize, boolean allowNull, 361 String fieldDescription) 362 throws DBException { 363 364 370 addField(fieldName, fieldType, fieldSize, allowNull, null, 371 fieldDescription); 372 } 373 374 393 synchronized public void addField(String fieldName, String fieldType, 394 int fieldSize, boolean allowNull, 395 String descriptionKey, String fieldDescription) 396 throws DBException { 397 if (ConfigManager.isReservedWord(fieldName)) { 398 throw new DBException("You cannot have a field name of " + 399 fieldName + 400 ". It is a reserved word. Check " + 401 "com.jcorporate.expresso.core.misc.ConfigManager for a full list" + 402 " of reservered words"); 403 } 404 405 allFields.put(fieldName, 406 new DBField(fieldName, fieldType, fieldSize, 0, 407 allowNull, fieldDescription)); 408 fieldNamesInOrder.add(fieldName); 409 410 411 412 416 if (fieldType.equalsIgnoreCase(DBField.INTEGER_TYPE) || 417 fieldType.equalsIgnoreCase(DBField.INT_TYPE)) { 418 419 setMask(fieldName, DBObject.INT_MASK); 420 setAttribute(fieldName, DBObject.ATTRIBUTE_ERROR_MESSAGE, 421 "You must enter a valid integer for field: " 422 + fieldDescription); 423 } 424 425 } 426 427 428 434 public boolean allowsNull(String fieldName) 435 throws DBException { 436 DBField oneField = (DBField) allFields.get(fieldName); 437 438 if (oneField == null) { 439 throw new DBException("(" + mObjectName + ") Field " + fieldName + 440 " is not defined as a field in this DBObject"); 441 } 442 if (oneField.allowsNull()) { 443 return true; 444 } 445 446 return false; 447 } 448 449 450 457 synchronized public void setMask(String fieldName, String newMask) 458 throws DBException { 459 DBField oneField = (DBField) allFields.get(fieldName); 460 461 if (oneField == null) { 462 throw new DBException("(" + mObjectName + ") Field " + fieldName + 463 " is not defined as a field in this DBObject"); 464 } 465 466 StringUtil.assertNotBlank(newMask, 467 "DBObject.setMask: newMask parameter was null for field: " + 468 fieldName); 469 470 try { 471 Pattern p = patternCompiler.compile(newMask, Perl5Compiler.READ_ONLY_MASK); 472 oneField.setMask(p); 473 } catch (MalformedPatternException mpe) { 474 throw new DBException("Error compiling mask for field: " + 475 fieldName, mpe); 476 } 477 } 478 479 480 486 public void removeAttribute(String fieldName, String attribName) { 487 DBField oneField = (DBField) allFields.get(fieldName); 488 489 if (oneField == null) { 490 return; 491 } 492 493 oneField.removeAttribute(attribName); 494 } 495 496 501 synchronized public void setAttribute(String fieldName, String attribName, Object attribValue) 502 throws DBException { 503 DBField oneField = (DBField) allFields.get(fieldName); 504 505 if (oneField == null) { 506 throw new DBException("(" + getName() + ") Field " + fieldName + 507 " is not defined as a field in this DBObject"); 508 } 509 510 oneField.setAttribute(attribName, attribValue); 511 } 512 513 514 521 public Object getAttribute(String fieldName, String attribName) 522 throws DBException { 523 DBField oneField = (DBField) allFields.get(fieldName); 524 525 if (oneField == null) { 526 throw new DBException("(" + getName() + ") Field " + fieldName + 527 " is not defined as a field in this DBObject"); 528 } 529 530 return oneField.getAttribute(attribName); 531 } 532 533 534 public Iterator getAttributesIterator(String fieldName) 535 throws DBException { 536 DBField oneField = (DBField) allFields.get(fieldName); 537 538 if (oneField == null) { 539 throw new DBException("(" + getName() + ") Field " + fieldName + 540 " is not defined as a field in this DBObject"); 541 } 542 543 return oneField.getAttributesIterator(); 544 } 545 546 555 synchronized public void addIndex(String indexName, String fieldNames, boolean isUnique) 556 throws IllegalArgumentException { 557 558 if (indexName == null) { 562 throw new IllegalArgumentException (Messages.getString(getSchema(), 563 "DBOBJ_Add_Index_IllegalArgument1")); 564 } 565 if (fieldNames == null) { 566 throw new IllegalArgumentException (Messages.getString(getSchema(), 567 "DBOBJ_Add_Index_IllegalArgument2")); 568 } 569 570 String tempString = null; 574 575 StringTokenizer stk = new StringTokenizer (fieldNames, ","); 578 579 while (stk.hasMoreTokens()) { 580 tempString = stk.nextToken(); 581 582 this.getDBField(tempString); 586 } 587 if (indexList == null) { 591 indexList = new ArrayList (); 592 } 593 try { 594 indexList.add(new DBIndex(indexName, getTargetTable(), fieldNames, 595 isUnique)); 596 } catch (DBException e) { 597 throw new IllegalArgumentException (e.getMessage()); 598 } 599 } 600 601 602 611 synchronized public void addKey(String keyFieldName) 612 throws DBException { 613 DBField oneField = (DBField) allFields.get(keyFieldName); 614 615 if (oneField == null) { 616 throw new DBException("(" + getName() + ") Field " + keyFieldName + 617 " is not defined as a field in this DBObject - cannot add " + 618 "to key"); 619 } 620 if (oneField.allowsNull()) { 621 throw new DBException("(" + getName() + ") Field " + keyFieldName + 622 " allows null - not suitable for inclusion " + 623 "in key"); 624 } 625 if (oneField.isVirtual()) { 626 throw new DBException("(" + getName() + ") Field " + keyFieldName + 627 " is a virtual field - not suitable for " + 628 "inclusion in key"); 629 } 630 631 if (oneField.isLongObjectType()) { 632 throw new DBException("(" + getName() + ") Field " + keyFieldName + 633 " allows arbitrarily long length, either text or binary - not suitable for inclusion " + 634 "in key"); 635 } 636 637 oneField.setKey(true); 638 allKeys.put(keyFieldName, oneField); 639 640 641 keyList.add(keyFieldName); 642 } 643 644 645 659 synchronized public void addVirtualField(String fieldName, String fieldType, 660 int fieldSize, String fieldDescription) 661 throws DBException { 662 addVirtualField(fieldName, fieldType, fieldSize, null, 663 fieldDescription); 664 } 665 666 682 synchronized public void addVirtualField(String fieldName, String fieldType, 683 int fieldSize, String descriptionKey, 684 String fieldDescription) 685 throws DBException { 686 DBField newField = new DBField(fieldName, fieldType, fieldSize, 0, 687 true, fieldDescription); 688 newField.setVirtual(true); 689 allFields.put(fieldName, newField); 690 fieldNamesInOrder.add(fieldName); 691 } 692 693 694 707 synchronized public void addVirtualField(String fieldName, String fieldType, 708 int fieldSize, int fieldPrecision, 709 boolean allowNull, 710 String fieldDescription) 711 throws DBException { 712 addVirtualField(fieldName, fieldType, fieldSize, fieldPrecision, 713 allowNull, null, fieldDescription); 714 } 715 716 717 732 synchronized public void addVirtualField(String fieldName, String fieldType, 733 int fieldSize, int fieldPrecision, 734 boolean allowNull, String descriptionKey, 735 String fieldDescription) 736 throws DBException { 737 DBField newField = new DBField(fieldName, fieldType, fieldSize, 738 fieldPrecision, allowNull, 739 fieldDescription); 740 newField.setVirtual(true); 741 allFields.put(fieldName, newField); 742 fieldNamesInOrder.add(fieldName); 743 } 744 745 746 749 public synchronized void disableLogging() { 750 loggingEnabled = false; 751 } 752 753 759 public synchronized void enableLogging() { 760 loggingEnabled = true; 761 } 762 763 764 public boolean isLoggingEnabled() { 765 return loggingEnabled; 766 } 767 768 775 synchronized public Hashtable getAllFields() { 776 return new Hashtable (allFields); 777 } 778 779 787 public String isFieldIgnoreCase(String fieldName) { 788 if (isField(fieldName)) { 790 return fieldName; 791 } 792 793 String internalFieldName = null; 795 for (Iterator i = getFieldListIterator(); i.hasNext();) { 796 String oneFieldName = (String ) i.next(); 797 798 if (oneFieldName.equalsIgnoreCase(fieldName)) { 799 internalFieldName = oneFieldName; 800 break; 801 } 802 } 803 804 return internalFieldName; 805 } 806 807 813 public boolean isField(String fieldName) { 814 return allFields.get(fieldName) != null; 815 } 816 817 823 public HashMap getAllFieldsMap() { 824 return new HashMap(allFields); 825 } 826 827 public HashMap getAllDBFields() { 828 return new HashMap(allFields); 829 } 830 831 836 public Iterator getAllFieldsIterator() { 837 return allFields.values().iterator(); 838 } 839 840 845 public Iterator getKeyFieldListIterator() { 846 return keyList.iterator(); 847 } 848 849 856 public Hashtable getAllKeys() { 857 return new Hashtable (allKeys); 858 } 859 860 866 public HashMap getAllKeysMap() { 867 return new HashMap(allKeys); 868 } 869 870 876 public Iterator getAllKeysIterator() { 877 return allKeys.values().iterator(); 878 } 879 880 885 public String getCharset() { 886 return charSet; 887 } 888 889 895 public int getCacheSize() { 896 return cacheSize; 897 } 898 899 905 public void setCacheSize(int newValue) { 906 if (newValue < -2) { 907 throw new java.lang.IllegalArgumentException (this.getClass().getName() + 908 ".setCacheSize(int). newValue must be greater than or equal to -2"); 909 } 910 911 cacheSize = newValue; 912 } 913 914 930 synchronized public void setCharset(String newCharSet) 931 throws DBException { 932 charSet = newCharSet; 933 } 934 935 936 942 public String getDescription() { 943 if (StringUtil.notNull(objectDescription).equals("")) { 944 return getName(); 945 } else { 946 return objectDescription; 947 } 948 } 949 950 951 959 public String getDescription(Locale l) { 960 String key = this.getDescription(); 961 962 if (key == null || key.length() == 0) { 963 return "Unknown Table"; 964 } 965 966 if (l == null) { 967 l = Locale.getDefault(); 968 } 969 970 String schema = this.getSchema(); 971 if (schema == null || schema.length() == 0) { 972 schema = com.jcorporate.expresso.core.ExpressoSchema.class.getName(); 973 } 974 975 String returnValue; 976 try { 977 returnValue = Messages.getString(schema, l, key); 978 } catch (IllegalArgumentException ex) { 979 returnValue = key; 980 } 981 982 return returnValue; 983 984 } 985 986 987 994 public String getDescription(String fieldName) 995 throws DBException { 996 DBField oneField = (DBField) allFields.get(fieldName); 997 998 if (oneField == null) { 999 throw new DBException("No such field '" + fieldName + "'" + 1000 " in object '" + mObjectName + "'"); 1001 } 1002 1003 return oneField.getDescription(); 1004 } 1005 1006 1007 1016 public String getDescription(java.util.Locale l, String fieldName) { 1017 String key = null; 1018 try { 1019 key = this.getDescription(fieldName); 1020 } catch (DBException ex) { 1021 log.error("Error getting field: " + fieldName, ex); 1022 } 1023 1024 if (key == null) { 1025 return "Unknown Field"; 1026 } 1027 1028 if (l == null) { 1029 l = Locale.getDefault(); 1030 } 1031 1032 String schema = this.getSchema(); 1033 if (schema == null || schema.length() == 0) { 1034 schema = com.jcorporate.expresso.core.ExpressoSchema.class.getName(); 1035 } 1036 1037 String returnValue; 1038 try { 1039 returnValue = Messages.getString(schema, l, key); 1040 } catch (IllegalArgumentException ex) { 1041 returnValue = key; 1042 } 1043 1044 return returnValue; 1045 } 1046 1047 1053 public DBField getDBField(String fieldName) { 1054 DBField oneField = (DBField) allFields.get(fieldName); 1055 1056 if (oneField == null) { 1057 throw new IllegalArgumentException ("No such field as '" + fieldName + 1058 "' in object '" + mObjectName + "'"); 1059 } 1060 1061 return oneField; 1062 } 1063 1064 1065 1071 synchronized public Enumeration getFieldList() { 1072 return new Vector (fieldNamesInOrder).elements(); 1073 } 1074 1075 1076 1082 synchronized public ArrayList getFieldListArray() { 1083 return (ArrayList ) fieldNamesInOrder.clone(); 1084 } 1085 1086 1092 public Iterator getFieldListIterator() { 1093 return fieldNamesInOrder.iterator(); 1094 } 1095 1096 1102 public Enumeration getKeyFieldList() { 1103 Vector newKeys = new Vector (keyList); 1104 1105 return newKeys.elements(); 1106 } 1107 1108 1113 public ArrayList getKeyFieldListArray() { 1114 return keyList; 1115 } 1116 1117 1124 public String getLength(String fieldName) throws DBException { 1125 DBField oneField = getDBField(fieldName); 1126 1127 return oneField.getLength(); 1128 } 1129 1130 1131 public int getLengthInt(String fieldName) throws DBException { 1132 return new Integer (getLength(fieldName)).intValue(); 1133 } 1134 1135 1139 public int getPrecision(String fieldName) 1140 throws DBException { 1141 DBField oneField = getDBField(fieldName); 1142 1143 return oneField.getPrecision(); 1144 } 1145 1146 1147 1157 public String getLookupObject(String fieldName) 1158 throws DBException { 1159 DBField oneField = getDBField(fieldName); 1160 1161 return oneField.getLookupObject(); 1162 } 1163 1164 1165 1174 public String getLookupField(String fieldName) { 1175 DBField oneField = getDBField(fieldName); 1176 if (oneField == null) { 1177 throw new IllegalArgumentException ("No field metadata found for field name: " 1178 + fieldName); 1179 } 1180 1181 return oneField.getLookupField(); 1182 } 1183 1184 1190 public String getName() { 1191 if (mObjectName.equals(OBJECT_NAME_NOT_ASSIGNED) || 1192 "".equals(mObjectName) || mObjectName == null) { 1193 return tableName; 1194 } else { 1195 return mObjectName; 1196 } 1197 } 1198 1199 1206 public String getTargetTable() 1207 throws DataException { 1208 if (tableName == null) { 1209 throw new DataException("No table name supplied"); 1210 } 1211 1212 return tableName; 1213 } 1214 1215 1222 public String getTargetDbSchema() { 1223 return dbSchemaName; 1224 } 1225 1226 1233 public String getTargetDbCatalog() { 1234 return dbCatalogName; 1235 } 1236 1237 1244 public String getType(String fieldName) 1245 throws DBException { 1246 DBField oneField = getDBField(fieldName); 1247 1248 return oneField.getTypeString(); 1249 } 1250 1251 1252 1261 synchronized public Object [] getIndexArray() { 1262 return this.indexList.toArray(); 1263 } 1264 1265 1270 public boolean hasIndex() { 1271 if (this.indexList == null) { 1272 return false; 1273 } else { 1274 return true; 1275 } 1276 } 1277 1278 1286 public boolean hasField(String fieldName) { 1287 if (allFields.containsKey(fieldName)) { 1288 return true; 1289 } 1290 1291 return false; 1292 } 1293 1294 1295 public FilterManager getFilterManager() { 1296 return filterManager; 1297 } 1298 1299 1307 synchronized public boolean isMultiValued(String fieldName) 1308 throws DBException { 1309 DBField oneField = getDBField(fieldName); 1310 1311 return oneField.isMultiValued(); 1312 } 1313 1314 1315 1323 public boolean isReadOnly(String fieldName) 1324 throws DBException { 1325 DBField oneField = getDBField(fieldName); 1326 1327 if (oneField == null) { 1328 throw new DBException("No such field '" + fieldName + "'" + 1329 "' in object '" + mObjectName + "'"); 1330 } 1331 1332 return oneField.isReadOnly(); 1333 } 1334 1335 1336 1347 public boolean isSecret(String fieldName) 1348 throws DBException { 1349 DBField oneField = getDBField(fieldName); 1350 1351 return oneField.isSecret(); 1352 } 1353 1354 1355 1364 public boolean isVirtual(String fieldName) 1365 throws DBException { 1366 DBField oneField = getDBField(fieldName); 1367 1368 return oneField.isVirtual(); 1369 } 1370 1371 1372 1381 synchronized public void setCheckZeroUpdate(boolean newFlag) { 1382 checkZeroUpdate = newFlag; 1383 } 1384 1385 1386 public boolean checkZeroUpdate() { 1387 return checkZeroUpdate; 1388 } 1389 1390 1395 synchronized public void setDescription(String newDescription) { 1396 objectDescription = newDescription; 1397 } 1398 1399 1408 synchronized public void setLookupObject(String fieldName, String objectName) 1409 throws DBException { 1410 DBField oneField = getDBField(fieldName); 1411 oneField.setLookupObject(objectName); 1412 } 1413 1414 1415 1424 synchronized public void setMultiValued(String fieldName) 1425 throws DBException { 1426 DBField oneField = getDBField(fieldName); 1427 1428 if (oneField.isVirtual()) { 1429 throw new DBException("(" + mObjectName + ") Field '" + fieldName + 1430 "' is a virtual field - not suitable for " + 1431 "setting as multi-valued"); 1432 } 1433 1434 oneField.setMultiValued(true); 1435 } 1436 1437 1438 1444 synchronized public void setName(String theName) { 1445 mObjectName = theName; 1446 } 1447 1448 1457 synchronized public void setReadOnly(String fieldName) 1458 throws DBException { 1459 DBField oneField = getDBField(fieldName); 1460 oneField.setReadOnly(); 1461 } 1462 1463 1464 1473 synchronized public void setSecret(String fieldName) 1474 throws DBException { 1475 DBField oneField = getDBField(fieldName); 1476 oneField.setSecret(); 1477 } 1478 1479 1480 1494 synchronized public void setStringFilter(String fieldName, String filterMethod) 1495 throws DBException { 1496 1497 if (!(filterMethod.equalsIgnoreCase("standardFilter") || filterMethod.equalsIgnoreCase("stripFilter") || 1501 filterMethod.equalsIgnoreCase("rawFilter"))) { 1502 throw new DBException("Undefined Filter Method: " + filterMethod); 1503 } 1504 1505 DBField oneField = getDBField(fieldName); 1506 oneField.setFilterMethod(filterMethod); 1507 } 1508 1509 1510 1517 synchronized public void setTargetTable(String theTable) 1518 throws DBException { 1519 if (theTable.length() > 18) { 1520 log.warn("Table name is over 18 characters"); 1521 } 1522 if (ConfigManager.isReservedWord(theTable)) { 1523 throw new DBException("You cannot have a table name of " + 1524 theTable + 1525 ". It is a database reserved word. Check " + 1526 "com.jcorporate.expresso.core.misc.ReservedWords for a full list" + 1527 " of reservered words"); 1528 } 1529 1530 tableName = theTable; 1531 } 1532 1533 1534 1540 synchronized public void setTargetDbSchema(String theSchema) 1541 throws DBException { 1542 if (theSchema.length() > 18) { 1543 log.warn("Schema name is over 18 characters"); 1544 } 1545 if (ConfigManager.isReservedWord(theSchema)) { 1546 throw new DBException("You cannot have a Schema name of " + 1547 theSchema + 1548 ". It is a database reserved word. Check " + 1549 "com.jcorporate.expresso.core.misc.ReservedWords for a full list" + 1550 " of reservered words"); 1551 } 1552 1553 dbSchemaName = theSchema; 1554 } 1555 1556 1562 synchronized public void setTargetDbCatalog(String theCatalog) 1563 throws DBException { 1564 if (theCatalog.length() > 18) { 1565 log.warn("Schema name is over 18 characters"); 1566 } 1567 if (ConfigManager.isReservedWord(theCatalog)) { 1568 throw new DBException("You cannot have a Catalog name of " + 1569 theCatalog + 1570 ". It is a database reserved word. Check " + 1571 "com.jcorporate.expresso.core.misc.ReservedWords for a full list" + 1572 " of reservered words"); 1573 } 1574 1575 dbCatalogName = theCatalog; 1576 } 1577 1578 1579 1582 synchronized public void setSchema(String schemaName) { 1583 StringUtil.assertNotBlank(mySchema, 1584 "Schema name may not be null or blank"); 1585 mySchema = schemaName; 1586 } 1587 1588 1591 public String getSchema() { 1592 return mySchema; 1593 } 1594 1595 1605 public String [] getFields() { 1606 int N = fieldNamesInOrder.size(); 1607 String [] arr = new String [N]; 1608 1609 for (int j = 0; j < N; ++j) { 1610 arr[j] = (String ) fieldNamesInOrder.get(j); 1611 } 1612 1613 return arr; 1614 } 1615 1616 1617 1622 synchronized public void addTransition(Transition t) 1623 throws DBException { 1624 transitionTabs.add(t); 1625 } 1626 1627 1632 public Iterator getTransitionsIterator() 1633 throws DBException { 1634 return transitionTabs.iterator(); 1635 } 1636 1637 1642 public Set getDetailSet() { 1643 return detailObjsLocal.keySet(); 1644 } 1645 1646 1652 public boolean isAllowsNull(String fieldName) throws DBException { 1653 return allowsNull(fieldName); 1654 } 1655 1656 1657 1663 public DataFieldMetaData getFieldMetadata(String fieldName) { 1664 return (DataFieldMetaData) allFields.get(fieldName); 1665 } 1666 1667 1673 public java.util.Set getAllAttributes(String fieldName) { 1674 DBField oneField = (DBField) allFields.get(fieldName); 1675 1676 if (oneField == null) { 1677 throw new IllegalArgumentException ("(" + getName() + ") Field " + fieldName + 1678 " is not defined as a field in this DBObject"); 1679 } 1680 1681 return oneField.getAllAttributes(); 1682 } 1683 1684 1685 1694 public String getTargetStoreProcedure() 1695 throws DataException { 1696 if (storeProcedureName == null) { 1697 throw new DataException("No store procedure name supplied"); 1698 } 1699 1700 return storeProcedureName; 1701 } 1702 1703 1704 1709 synchronized public void setTargetStoreProcedure(String theStoreProcedure) 1710 throws DBException { 1711 if (theStoreProcedure.length() > 18) { 1712 log.warn("Strore procedure name is over 18 characters"); 1713 } 1714 if (ConfigManager.isReservedWord(theStoreProcedure)) { 1715 throw new DBException("You cannot have a store procedure name of " + 1716 theStoreProcedure + 1717 ". It is a database reserved word. Check " + 1718 "com.jcorporate.expresso.core.misc.ReservedWords for a full list" + 1719 " of reservered words"); 1720 } 1721 1722 storeProcedureName = theStoreProcedure; 1723 tableName = theStoreProcedure; 1724 } 1725 1726 1727 1736 synchronized public void addInParam(String inFieldName) 1737 throws DBException { 1738 DBField oneField = (DBField) allFields.get(inFieldName); 1739 1740 if (oneField == null) { 1741 throw new DBException("(" + getName() + ") Field " + inFieldName + 1742 " is not defined as a field in this DBObject - cannot add " + 1743 "to input list parameter"); 1744 } 1745 if (oneField.allowsNull()) { 1746 throw new DBException("(" + getName() + ") Field " + inFieldName + 1747 " allows null - not suitable for inclusion " + 1748 "in key"); 1749 } 1750 if (oneField.isVirtual()) { 1751 throw new DBException("(" + getName() + ") Field " + inFieldName + 1752 " is a virtual field - not suitable for " + 1753 "inclusion in input list parameter"); 1754 } 1755 1756 if (oneField.isLongObjectType()) { 1757 throw new DBException("(" + getName() + ") Field " + inFieldName + 1758 " allows arbitrarily long length, either text or binary - not suitable for inclusion " + 1759 "in the input list parameter"); 1760 } 1761 1762 allInParameters.put(inFieldName, oneField); 1763 1764 1765 inParamList.add(inFieldName); 1766 } 1767 1768 1769 1778 synchronized public void addOutParam(String outFieldName) 1779 throws DBException { 1780 DBField oneField = (DBField) allFields.get(outFieldName); 1781 1782 if (oneField == null) { 1783 throw new DBException("(" + getName() + ") Field " + outFieldName + 1784 " is not defined as a field in this DBObject - cannot add " + 1785 "to the output list parameter"); 1786 } 1787 if (oneField.allowsNull()) { 1788 throw new DBException("(" + getName() + ") Field " + outFieldName + 1789 " allows null - not suitable for inclusion " + 1790 "in the output list parameter"); 1791 } 1792 if (oneField.isVirtual()) { 1793 throw new DBException("(" + getName() + ") Field " + outFieldName + 1794 " is a virtual field - not suitable for " + 1795 "inclusion in the output list parameter"); 1796 } 1797 1798 if (oneField.isLongObjectType()) { 1799 throw new DBException("(" + getName() + ") Field " + outFieldName + 1800 " allows arbitrarily long length, either text or binary - not suitable for inclusion " + 1801 "in the output list parameter"); 1802 } 1803 1804 allOutParameters.put(outFieldName, oneField); 1805 1806 1807 outParamList.add(outFieldName); 1808 } 1809 1810 1811 public boolean isReturningValue() { 1812 return returningValue; 1813 } 1814 1815 1818 public void setReturningValue(boolean value) { 1819 returningValue = value; 1820 } 1821 1822 1828 public boolean isOutField(String fieldName) { 1829 return allOutParameters.get(fieldName) != null; 1830 } 1831 1832 1838 public boolean isInField(String fieldName) { 1839 return allInParameters.get(fieldName) != null; 1840 } 1841 1842 1851 public String getTargetSQLTable(String dataContext) 1852 throws DataException { 1853 String sqlTableName = getTargetTable(); 1854 try { 1855 if (getTargetDbSchema() != null && !"".equals(getTargetDbSchema())) { 1856 sqlTableName = getTargetDbSchema() + "." + getTargetTable(); 1857 } else { 1858 JDBCConfig myConfig = ConfigManager.getJdbcRequired(dataContext); 1859 if (myConfig.getDbSchema() != null && !"".equals(myConfig.getDbSchema())) { 1860 sqlTableName = myConfig.getDbSchema() + "." + getTargetTable(); 1861 } 1862 } 1863 } catch (ConfigurationException ce) { 1864 throw new DataException(ce); 1865 } 1866 return sqlTableName; 1867 } 1868 1869 1870 1875 public ArrayList getInParamListArray() { 1876 return inParamList; 1877 } 1878 1879 1884 public ArrayList getOutParamListArray() { 1885 return outParamList; 1886 } 1887 1888 1889 1894 public Iterator getInParamFieldListIterator() { 1895 return inParamList.iterator(); 1896 } 1897 1898 1899 1904 public Iterator getOutParamFieldListIterator() { 1905 return outParamList.iterator(); 1906 } 1907 1908 1916 public synchronized int getOutParamFieldsCount() 1917 throws DBException { 1918 if (outParamList == null) { 1919 return 0; 1920 } else { 1921 return outParamList.size(); 1922 } 1923 } 1924 1925 1926} 1927 | Popular Tags |