1 19 package org.openharmonise.rm.resources; 20 21 import java.sql.*; 22 import java.util.*; 23 import java.util.logging.*; 24 25 import org.openharmonise.commons.cache.*; 26 import org.openharmonise.commons.dsi.*; 27 import org.openharmonise.commons.dsi.dml.SelectStatement; 28 import org.openharmonise.rm.*; 29 import org.openharmonise.rm.dsi.*; 30 import org.openharmonise.rm.publishing.*; 31 import org.openharmonise.rm.resources.publishing.Template; 32 import org.w3c.dom.*; 33 34 35 44 public abstract class AbstractObject 45 implements Cloneable , Comparable , Publishable, DataStoreObject, CacheableObject { 46 47 51 public static final int NOTDBSAVED_ID = 0; 52 53 56 public static final int NOTDBSAVED_KEY = 0; 57 58 62 public static final String TAG_HARMONISE_OBJECT = "HarmoniseObject"; 63 64 67 public static final String TAG_NAME = "Name"; 68 69 72 public static final String TAG_SUMMARY = "Summary"; 73 74 77 public static final String TAG_LINK = "Link"; 78 79 82 public static final String TAG_LINK_TEXT = "LinkText"; 83 84 87 public static final String TAG_LINK_IMAGE = "LinkImage"; 88 89 92 public static final String ATTRIB_KEY = "key"; 93 94 97 public static final String ATTRIB_ID = "id"; 98 101 public static final String ATTRIB_NAME = "name"; 102 103 106 public static final String ATTRIB_TYPE = "type"; 107 108 111 public static final String ATTRIB_OBJECT_TYPE = "objectType"; 112 113 116 public static final String ATTRIB_HISTORICAL = "historical"; 117 118 122 protected static final String CLMN_ID = "id"; 123 124 127 private static final String CLMN_KEY = "object_key"; 128 129 132 protected static final String CLMN_NAME = "name"; 133 134 137 protected static final String CLMN_SUMMARY = "summary"; 138 139 142 private static final String CLMN_TYPE = "type"; 143 144 147 public static final String EXT_HIST = "_hist"; 148 149 153 protected int m_nId = NOTDBSAVED_ID; 154 155 158 protected int m_nObjectKey = NOTDBSAVED_KEY; 159 160 163 protected String m_sName = ""; 164 165 168 protected String m_sSummary = ""; 169 170 173 private boolean m_bHistorical = false; 174 175 179 protected String m_sType; 180 181 184 private int m_nHashcode = 0; 185 186 189 protected AbstractDataStoreInterface m_dsi = null; 190 191 195 protected boolean m_bIsPopulated = false; 196 197 201 protected boolean m_bIsChanged = false; 202 203 206 protected String m_sTable = null; 207 208 211 private List m_cache_listeners = new ArrayList(); 212 213 216 static private Logger m_logger = Logger.getLogger(AbstractObject.class.getName()); 217 218 { 220 m_sType = this.getClass().getName(); 221 m_sTable = getDBTableName(); } 223 224 228 public AbstractObject() { 229 super(); 230 } 231 232 239 public AbstractObject(AbstractDataStoreInterface con) { 240 m_dsi = con; 241 } 242 243 250 public AbstractObject(AbstractDataStoreInterface con, boolean bIsHist) { 251 this(con); 252 m_bHistorical = bIsHist; 253 } 254 255 263 public AbstractObject(AbstractDataStoreInterface con, int nId) { 264 this(con); 265 m_nId = nId; 266 } 267 268 276 public AbstractObject( 277 AbstractDataStoreInterface con, 278 int nId, 279 int nKey, 280 boolean bIsHist) { 281 this(con, nId); 282 m_bHistorical = bIsHist; 283 } 284 285 290 public boolean exists() { 291 boolean bIsExist = false; 292 ResultSet rs = null; 293 try { 294 if(m_nId > NOTDBSAVED_ID || m_nObjectKey > NOTDBSAVED_KEY) { 295 if(m_bIsPopulated == false) { 296 297 SelectStatement select = new SelectStatement(); 298 299 ColumnRef refCol = null; 300 int nRef = 0; 301 if(m_bHistorical == false || isKeySupported() == false) { 302 refCol = getInstanceColumnRef(ATTRIB_ID,m_bHistorical); 303 nRef = m_nId; 304 } else { 305 refCol = getInstanceColumnRef(ATTRIB_KEY,m_bHistorical); 306 nRef = m_nObjectKey; 307 } 308 309 select.addSelectColumn(refCol); 310 select.addWhereCondition(refCol, "=", nRef); 311 312 rs = m_dsi.execute(select); 313 314 if(rs.next()) { 315 bIsExist = true; 316 } 317 } else { 318 bIsExist = true; 319 } 320 } 321 322 } catch (DataStoreException e) { 323 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 324 bIsExist = false; 325 } catch (SQLException e) { 326 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 327 bIsExist = false; 328 } finally { 329 if(rs != null) { 330 try { 331 rs.close(); 332 } catch (SQLException e) { 333 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 334 } 335 } 336 } 337 338 return bIsExist; 339 } 340 341 346 public int getId() { 347 return m_nId; 348 } 349 350 351 356 public void setKey(int nKey) { 357 m_nObjectKey = nKey; 358 } 359 360 366 public int getKey() throws DataAccessException { 367 if ((m_nObjectKey == NOTDBSAVED_KEY) && (m_bIsPopulated == false)) { 368 try { 369 populateFromDatabase(); 370 } catch (PopulateException e) { 371 throw new DataAccessException(e.getLocalizedMessage()); 372 } 373 374 } 375 376 return m_nObjectKey; 377 } 378 379 385 public String getName() throws DataAccessException { 386 if ((m_sName == null || m_sName.length() == 0) 387 && (m_bIsPopulated == false)) { 388 try { 389 populateFromDatabase(); 390 } catch (PopulateException e) { 391 throw new DataAccessException("populate error",e); 392 } 393 } 394 395 return m_sName; 396 } 397 398 403 public void setName(String sName) throws InvalidNameException { 404 if (m_bIsPopulated) { 405 if (m_sName.equals(sName) == false) { 406 m_bIsChanged = true; 407 } 408 } 409 410 m_sName = sName; 411 } 412 413 418 public void setSummary(String sSummary) { 419 if (sSummary == null) { 420 sSummary = ""; 421 } 422 423 if (m_bIsPopulated) { 424 if ((m_sSummary == null && sSummary != null) 425 || (m_sSummary.trim().equals(sSummary.trim()) == false)) { 426 m_bIsChanged = true; 427 } 428 } 429 430 m_sSummary = sSummary; 431 } 432 433 446 public void setDataStoreInterface(AbstractDataStoreInterface dsi) throws PopulateException { 447 if(m_dsi != null && dsi.equals(m_dsi) == false) { 448 throw new PopulateException("Can't switch data store interfaces"); 449 } 450 451 m_dsi = dsi; 452 } 453 454 459 public AbstractDataStoreInterface getDataStoreInterface() { 460 return m_dsi; 461 } 462 463 469 public String getSummary() throws DataAccessException { 470 if ((m_sSummary == null || m_sSummary.length() == 0) 471 && !m_bIsPopulated) { 472 try { 473 populateFromDatabase(); 474 } catch (PopulateException e) { 475 throw new DataAccessException(e.getLocalizedMessage()); 476 } 477 } 478 479 return m_sSummary; 480 } 481 482 487 public void setType(String type) { 488 489 if (m_bIsPopulated) { 490 if (m_sType.equals(type) == false) { 491 m_bIsChanged = true; 492 } 493 } 494 495 m_sType = type; 496 } 497 498 504 public String getType() throws DataAccessException { 505 if ((m_sType.length() == 0) && (m_bIsPopulated == false)) { 506 try { 507 populateFromDatabase(); 508 } catch (PopulateException e) { 509 throw new DataAccessException(e.getLocalizedMessage()); 510 } 511 } 512 513 return m_sType; 514 } 515 516 521 public void setHistorical(boolean bIsHistorical) { 522 this.m_bHistorical = bIsHistorical; 523 } 524 525 530 public boolean isHistorical() { 531 return m_bHistorical; 532 } 533 534 541 public boolean isChanged() throws DataAccessException { 542 if (m_bIsPopulated == false && m_bIsChanged == false) { 543 try { 544 populateFromDatabase(); 545 } catch (PopulateException e) { 546 throw new DataAccessException("Data access error",e); 547 } 548 } 549 550 return m_bIsChanged; 551 } 552 553 558 public void setIsChanged(boolean bIsChanged) { 559 m_bIsChanged = bIsChanged; 560 } 561 562 565 public boolean equals(Object obj) { 566 boolean bReturn = false; 567 568 try { 569 populateFromDatabase(); 570 } catch (PopulateException e) { 571 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 574 } 575 576 if (obj instanceof AbstractObject) { 577 578 if (this == obj) { 579 bReturn = true; 580 } else if ( 581 obj.getClass().getName().equals(getClass().getName()) 582 == true) { 583 AbstractObject objCompare = (AbstractObject) obj; 584 585 try { 586 if ((this.getKey() != 0) && (objCompare.getKey() != 0)) { 587 if (m_nObjectKey == objCompare.getKey()) { 588 bReturn = true; 589 } 590 } else { 591 try { 592 if (m_sName.equals(objCompare.getName())) { 593 bReturn = true; 594 } 595 } catch (Exception e) { 596 } 597 } 598 } catch (Exception e) { 599 throw new RuntimeException (e.getMessage()); 600 } 601 } 602 603 } 604 605 return bReturn; 606 } 607 608 611 public int hashCode() { 612 613 if (m_nHashcode == 0) { 614 int nHash = 17; 615 616 try { 617 populateFromDatabase(); 618 } catch (PopulateException e) { 619 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 622 } 623 624 nHash = 37 * nHash + m_nId; 625 nHash = 37 * nHash + m_nObjectKey; 626 if (m_sName != null) { 627 nHash = 37 * nHash + m_sName.hashCode(); 628 } 629 if (m_sSummary != null) { 630 nHash = 37 * nHash + m_sSummary.hashCode(); 631 } 632 m_nHashcode = nHash; 633 } 634 635 return m_nHashcode; 636 } 637 638 641 public void populate(Element xmlElement, State state) 642 throws PopulateException { 643 String sTagName = xmlElement.getTagName(); 644 Text txt = null; 645 String sTemp = null; 646 647 if (sTagName.equals(getTagName()) == true) { 648 sTemp = xmlElement.getAttribute(ATTRIB_ID); 649 650 if (!sTemp.equals("")) { 651 m_nId = Integer.parseInt(sTemp); 652 } 653 654 NodeList nodes = xmlElement.getChildNodes(); 655 List postponedNodes = new Vector(); 656 657 for (int i = 0; i < nodes.getLength(); i++) { 658 if (nodes.item(i).getNodeType() != Node.ELEMENT_NODE) { 659 continue; 660 } 661 662 Element el = null; 663 try { 664 el = (Element) nodes.item(i); 665 populate(el, state); 666 } catch (PopulateDependencyException e) { 667 postponedNodes.add(el); 668 } 669 } 670 for (int i = 0; i < postponedNodes.size(); i++) { 671 Element el = (Element)postponedNodes.get(i); 672 populate(el, state); 673 } 674 } else if (sTagName.equals(TAG_NAME)) { 675 txt = (Text) xmlElement.getFirstChild(); 676 try { 677 setName(txt.getNodeValue()); 678 } catch (InvalidNameException e) { 679 throw new PopulateException(e); 680 } 681 } else if (sTagName.equals(TAG_SUMMARY)) { 682 txt = (Text) xmlElement.getFirstChild(); 683 setSummary(txt.getNodeValue()); 684 } 685 } 686 687 690 public Element publish(Template template, HarmoniseOutput xmlDoc, State state) 691 throws PublishException { 692 Element resultEl = null; 693 694 try { 695 696 resultEl = 697 publish(template.getTemplateRootElement(), xmlDoc, state); 698 } catch (DataAccessException de){ 699 throw new PublishException(de.getLocalizedMessage(),de); 700 } catch (Exception e) { 701 throw new PublishException(e.getLocalizedMessage(),e); 702 } 703 704 return resultEl; 705 } 706 707 710 public Element publish(Element topEl, HarmoniseOutput xmlDoc, State state) 711 throws PublishException { 712 Element docEl = null; 713 NodeList nodes = null; 714 Text txt = null; 715 String sTagName = topEl.getTagName(); 716 717 try { 718 719 if (topEl.getTagName().equals(getTagName()) || topEl.getTagName().equals(TAG_HARMONISE_OBJECT)) { 720 docEl = xmlDoc.createElement(getTagName()); 721 722 docEl.setAttribute(ATTRIB_ID, Integer.toString(m_nId)); 723 724 nodes = topEl.getChildNodes(); 725 } else if (sTagName.equals(TAG_NAME)) { 726 docEl = xmlDoc.createElement(sTagName); 727 txt = xmlDoc.createTextNode(getName()); 728 docEl.appendChild(txt); 729 xmlDoc.copyChildren(docEl, topEl, new Vector()); 730 } else if (sTagName.equals(TAG_SUMMARY)) { 731 docEl = xmlDoc.createElement(sTagName); 732 txt = xmlDoc.createTextNode(getSummary()); 733 docEl.appendChild(txt); 734 xmlDoc.copyChildren(docEl, topEl, new Vector()); 735 } else if ( 736 sTagName.equals(TAG_LINK) 737 || sTagName.equals(TAG_LINK_TEXT) 738 || sTagName.equals(TAG_LINK_IMAGE)) { 739 Node childnode = topEl.getFirstChild(); 746 747 if ((sTagName.equals(TAG_LINK_TEXT) 748 || sTagName.equals(TAG_LINK_IMAGE)) 749 && (childnode.getNodeType() == Node.TEXT_NODE) 750 && ((topEl.getChildNodes()).getLength() == 1)) { 751 docEl = (Element) xmlDoc.copyNode(topEl); 752 } else { 753 docEl = xmlDoc.createElement(sTagName); 754 755 NodeList childnodes = topEl.getChildNodes(); 756 757 for (int k = 0; k < childnodes.getLength(); k++) { 758 if (childnodes.item(k).getNodeType() 759 == Node.ELEMENT_NODE) { 760 Element tempEl = 761 publish( 762 (Element) childnodes.item(k), 763 xmlDoc, 764 state); 765 766 if (tempEl != null) { 767 docEl.appendChild(tempEl); 768 } 769 } 770 } 771 } 772 } 773 774 Element formEl; 776 Element el; 777 778 if (nodes != null) { 779 for (int i = 0; i < nodes.getLength(); i++) { 780 if (nodes.item(i).getNodeType() != Node.ELEMENT_NODE) { 781 continue; 782 } 783 784 formEl = (Element) nodes.item(i); 785 el = publish(formEl, xmlDoc, state); 786 787 if (el != null) { 788 docEl.appendChild(el); 789 } 790 } 791 } 792 793 } catch (DataAccessException e) { 794 throw new PublishException(e.getLocalizedMessage(),e); 795 } catch (Exception ex) { 796 throw new PublishException(ex.getLocalizedMessage(),ex); 797 } 798 799 return docEl; 800 } 801 802 805 public ColumnRef getInstanceColumnRef(String sColumn, boolean bIsHist) 806 throws DataStoreException { 807 String sDBTable = getTableName(bIsHist); 808 809 return getObjectColumnRef(sDBTable, sColumn); 810 } 811 812 822 public static ColumnRef getColumnRef(AbstractObject obj, String sColumn) 823 throws DataStoreException { 824 String sTable = obj.getDBTableName(); 825 826 return getObjectColumnRef(sTable, sColumn); 827 } 828 829 839 public static ColumnRef getColumnRef(String sClassname, String sColumn) 840 throws DataStoreException { 841 return getColumnRef(sClassname, sColumn, false); 842 } 843 844 855 public static ColumnRef getColumnRef( 856 String sClassname, 857 String sColumn, 858 boolean bHist) 859 throws DataStoreException { 860 ColumnRef returnColRef = null; 861 String sTable = getTableName(sClassname,bHist); 862 863 return getObjectColumnRef(sTable, sColumn); 864 } 865 866 876 public static String getTableName(String sClassname,boolean bHist) throws DataStoreException { 877 String sTable = null; 878 879 try { 880 Class clss = Class.forName(sClassname); 882 Class absObjClass = AbstractObject.class; 883 if (absObjClass.isAssignableFrom(clss) == false) { 884 throw new DataStoreException("Classname isn't AbstractObject"); 885 } 886 887 sTable = DatabaseInfo.getInstance().getTableName(sClassname); 888 889 if (bHist == true) { 890 sTable = sTable + EXT_HIST; 891 } 892 } catch (ClassNotFoundException e) { 893 throw new DataStoreException( 894 "Unable to get table name for class" + e.getLocalizedMessage()); 895 } 896 897 return sTable; 898 } 899 900 901 904 public Object clone() { 905 try { 906 if (!m_bIsPopulated) { 907 try { 908 populateFromDatabase(); 909 } catch (PopulateException e) { 910 throw new DataAccessException(e.getLocalizedMessage()); 911 } 912 } 913 914 AbstractObject other = (AbstractObject) super.clone(); 915 916 return other; 917 } catch (CloneNotSupportedException e) { 918 m_logger.log(Level.WARNING, e.getMessage(), e); 919 920 return null; 921 } catch (Exception e) { 922 m_logger.log(Level.WARNING, e.getMessage(), e); 923 924 return null; 925 } 926 } 927 928 933 public void clear() { 934 m_nObjectKey = NOTDBSAVED_KEY; 935 m_sName = ""; 936 m_sSummary = ""; 937 938 m_bHistorical = false; 939 m_bIsPopulated = false; 940 m_bIsChanged = false; 941 } 942 943 946 public int compareTo(Object obj) { 947 int nCompare = 0; 948 try { 949 String sName = getName(); 950 951 AbstractObject abObj = (AbstractObject) obj; 952 953 nCompare = sName.compareTo(abObj.getName()); 954 } catch (DataAccessException e) { 955 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 956 } 957 958 return nCompare; 959 } 960 961 964 public abstract String getDBTableName(); 965 966 969 970 975 protected static Collection getCoreColumnRefs(String sClassname) 976 throws DataStoreException { 977 ArrayList list = new ArrayList(); 978 979 list.add(getColumnRef(sClassname, TAG_NAME)); 980 list.add(getColumnRef(sClassname, TAG_SUMMARY)); 981 list.add(getColumnRef(sClassname, ATTRIB_KEY)); 982 983 return list; 984 } 985 986 991 protected String getHistoricalDBTableName() { 992 return m_sTable + EXT_HIST; 993 } 994 995 1001 protected String getTableName(boolean bIsHist) { 1002 String sTable = m_sTable; 1003 1004 if(bIsHist == true) { 1005 sTable = m_sTable + EXT_HIST; 1006 } 1007 1008 return sTable; 1009 } 1010 1011 1015 protected void fullPopulate() throws PopulateException { 1016 populateFromDatabase(); 1017 } 1018 1019 1024 protected synchronized void populateFromDatabase() throws PopulateException { 1025 if (m_nId != NOTDBSAVED_ID && m_bIsPopulated == false) { 1026 1027 if(m_logger.isLoggable(Level.FINER)) { 1028 m_logger.logp(Level.FINER, this.getClass().getName(), "populateFromDatabase", "populating object, id - " + m_nId + ", key - " + m_nObjectKey); 1029 } 1030 1031 if (isHistorical() && (m_nObjectKey == NOTDBSAVED_KEY && isKeySupported())) { 1032 throw new PopulateException("Can't populate hisorical version without knowing object key"); 1033 } 1034 1035 ResultSet rs = null; 1036 1037 try { 1038 1039 SelectStatement select = new SelectStatement(); 1040 1041 addColumnsToPopulateQuery(select, m_bHistorical); 1042 1043 if (m_bHistorical == false || isKeySupported() == false) { 1044 select.addWhereCondition( 1045 getInstanceColumnRef(ATTRIB_ID, m_bHistorical), 1046 "=", 1047 m_nId); 1048 } else { 1049 select.addWhereCondition( 1050 getInstanceColumnRef(ATTRIB_KEY, m_bHistorical), 1051 "=", 1052 m_nObjectKey); 1053 } 1054 1055 rs = m_dsi.execute(select); 1056 1057 boolean bResultFound = false; 1058 1060 while (rs.next() == true) { 1061 populateFromResultSetRow( 1062 rs, 1063 select); 1064 1065 if (bResultFound == false) { 1066 bResultFound = true; 1067 } 1068 } 1069 1070 if (bResultFound == false) { 1071 throw new ObjectNotFoundException( 1072 "Could not find a " 1073 + getClass().getName() 1074 + " object with id = " 1075 + getId()); 1076 1077 } 1078 1079 1080 m_bIsPopulated = true; } catch (DataStoreException ds_e) { 1082 throw new PopulateException(ds_e); 1083 } catch (SQLException sql_e) { 1084 throw new PopulateException(sql_e); 1085 } finally { 1086 1087 if (rs != null) { 1088 try { 1089 rs.close(); 1090 } catch (SQLException e) { 1091 throw new PopulateException(e.getLocalizedMessage()); 1092 } 1093 } 1094 } 1095 1096 } else { 1097 m_bIsPopulated = true; 1098 } 1099 } 1100 1101 1112 protected abstract boolean isKeySupported(); 1113 1114 1123 protected void addColumnsToPopulateQuery( 1124 SelectStatement select, 1125 boolean bIsHist) 1126 throws DataStoreException { 1127 1128 try { 1129 ColumnRefCache cache = ColumnRefCache.getInstance(); 1130 1131 select.addSelectColumn(cache.getColumnRef(this,TAG_NAME, bIsHist)); 1132 select.addSelectColumn(cache.getColumnRef(this,TAG_SUMMARY, bIsHist)); 1133 select.addSelectColumn(cache.getColumnRef(this,ATTRIB_TYPE, bIsHist)); 1134 select.addSelectColumn(cache.getColumnRef(this,ATTRIB_KEY, bIsHist)); 1135 1136 } catch (CacheException e) { 1137 throw new DataStoreException("Cache error",e); 1138 } 1139 1140 } 1141 1142 1147 protected boolean isPopulated() { 1148 return m_bIsPopulated; 1149 } 1150 1151 1161 protected void populateFromResultSetRow(ResultSet rs, SelectStatement select) 1162 throws PopulateException { 1163 if (isPopulated() == false) { 1164 String sTemp = ""; 1165 1166 try { 1167 ColumnRefCache cache = ColumnRefCache.getInstance(); 1168 1169 ColumnRef nameCol = cache.getColumnRef(this,CLMN_NAME,m_bHistorical); 1170 1171 if (select.containsSelectColumn(nameCol) == true) { 1172 1173 sTemp = rs.getString(select.getResultSetIndex(nameCol)); 1174 1175 if ((sTemp != null) && (sTemp.length() > 0)) { 1176 if ((m_sName == null) || (m_sName.length() == 0)) { 1177 m_sName = sTemp; 1178 } else if (m_sName.equals(sTemp) == false) { 1179 m_bIsChanged = true; 1180 } 1181 } 1182 } 1183 1184 ColumnRef summaryCol = cache.getColumnRef(this,CLMN_SUMMARY,m_bHistorical); 1185 if (select.containsSelectColumn(summaryCol) == true) { 1186 sTemp = rs.getString(select.getResultSetIndex(summaryCol)); 1187 1188 if ((sTemp != null) && (sTemp.length() > 0)) { 1189 if ((m_sSummary == null) 1190 || (m_sSummary.length() == 0)) { 1191 m_sSummary = sTemp; 1192 } else if (m_sSummary.equals(sTemp) == false) { 1193 m_bIsChanged = true; 1194 } 1195 } 1196 } 1197 1198 ColumnRef typeCol = cache.getColumnRef(this,CLMN_TYPE,m_bHistorical); 1199 1200 if (select.containsSelectColumn(typeCol) == true) { 1201 sTemp = rs.getString(select.getResultSetIndex(typeCol)); 1202 1203 if ((sTemp != null) && (sTemp.length() > 0)) { 1204 setType(sTemp); 1205 } 1206 } 1207 1208 ColumnRef keyCol = cache.getColumnRef(this,CLMN_KEY,m_bHistorical); 1209 if (select.containsSelectColumn(keyCol) == true) { 1210 int nKey = rs.getInt(select.getResultSetIndex(keyCol)); 1211 1212 if (nKey > 0) { 1213 setKey(nKey); 1214 } 1215 } 1216 1217 } catch (SQLException e) { 1218 try { 1219 System.out.println("!!" + m_dsi.getSelectStatement(select)); 1220 } catch (DataStoreException e1) { 1221 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e1); 1222 } 1223 1224 throw new PopulateException("SQL error",e); 1225 } catch (CacheException e) { 1226 throw new PopulateException("Cache error getting col ref",e); 1227 } 1228 } 1229 } 1230 1231 1237 protected void markAsNew() throws PopulateException { 1238 m_nId = NOTDBSAVED_ID; 1239 m_bIsPopulated = true; 1240 m_bIsChanged = true; 1241 } 1242 1243 1244 1253 public void setId(int nId) { 1254 if (isPopulated() == true) { 1255 if (m_nId != NOTDBSAVED_ID && nId != m_nId) { 1256 m_bIsChanged = true; 1257 } 1258 } 1259 1260 m_nId = nId; 1261 } 1262 1263 1274 protected static ColumnRef getObjectColumnRef( 1275 String sDBTable, 1276 String sColumn) 1277 throws DataStoreException { 1278 ColumnRef returnColRef = null; 1279 1280 if (sColumn.equals(TAG_NAME) == true 1281 || sColumn.equals(CLMN_NAME) == true) { 1282 returnColRef = new ColumnRef(sDBTable, CLMN_NAME, ColumnRef.TEXT); 1283 } else if ( 1284 sColumn.equals(TAG_SUMMARY) == true 1285 || sColumn.equals(CLMN_SUMMARY) == true) { 1286 returnColRef = 1287 new ColumnRef(sDBTable, CLMN_SUMMARY, ColumnRef.TEXT); 1288 } else if ( 1289 sColumn.equals(ATTRIB_KEY) == true 1290 || sColumn.equals(CLMN_KEY) == true) { 1291 returnColRef = new ColumnRef(sDBTable, CLMN_KEY, ColumnRef.NUMBER); 1292 } else if ( 1293 sColumn.equals(ATTRIB_ID) == true 1294 || sColumn.equals(CLMN_ID) == true) { 1295 returnColRef = new ColumnRef(sDBTable, CLMN_ID, ColumnRef.NUMBER); 1296 } else if ( 1297 sColumn.equals(ATTRIB_OBJECT_TYPE) == true 1298 || sColumn.equals(ATTRIB_TYPE) == true 1299 || sColumn.equals(CLMN_TYPE) == true) { 1300 returnColRef = new ColumnRef(sDBTable, CLMN_TYPE, ColumnRef.TEXT); 1301 } 1302 1303 if (returnColRef == null) { 1304 throw new InvalidColumnReferenceException(sColumn); 1305 } 1306 1307 return returnColRef; 1308 } 1309 1310 1313 public void addCacheListener(CacheListener listener) { 1314 m_cache_listeners.add(listener); 1315 1316 } 1317 1318 1321 public List getCacheListeners() { 1322 return m_cache_listeners; 1323 } 1324 1325 1328 public void removeCacheListener(CacheListener listener) { 1329 m_cache_listeners.remove(listener); 1330 1331 } 1332 1333 1336 public void notifyCacheListeners() { 1337 for (Iterator iter = m_cache_listeners.iterator(); iter.hasNext();) { 1338 CacheListener listener = (CacheListener) iter.next(); 1339 listener.objectRemovedFromCache(this); 1340 } 1341 1342 } 1343} | Popular Tags |