1 package com.frovi.ss.Tree; 2 3 import java.util.Collection ; 4 5 import org.exolab.castor.jdo.Database; 6 import org.infoglue.cms.exception.SystemException; 7 8 14 public abstract class BaseNodeSupplier implements INodeSupplier 15 { 16 private BaseNode rootNode = null; 17 18 public boolean hasChildren() 19 { 20 return true; 21 } 22 23 public boolean hasChildren(Integer nodeId) throws SystemException, Exception 24 { 25 Collection tmp = getChildContainerNodes(nodeId); 28 Collection tmp2 = getChildLeafNodes(nodeId); 29 return (tmp.size() + tmp2.size()) > 0; 30 } 31 32 33 37 protected void setRootNode(BaseNode rootNode) 38 { 39 this.rootNode = rootNode; 40 } 41 42 46 public BaseNode getRootNode() 47 { 48 return rootNode; 49 } 50 51 52 55 56 protected void beginTransaction(Database db) throws SystemException 57 { 58 try 59 { 60 db.begin(); 61 } 62 catch(Exception e) 63 { 64 e.printStackTrace(); 65 throw new SystemException("An error occurred when we tried to begin an transaction. Reason:" + e.getMessage(), e); 66 } 67 } 68 69 70 71 74 75 protected void commitTransaction(Database db) throws SystemException 76 { 77 try 78 { 79 db.commit(); 80 db.close(); 81 } 82 catch(Exception e) 83 { 84 e.printStackTrace(); 85 throw new SystemException("An error occurred when we tried to commit an transaction. Reason:" + e.getMessage(), e); 86 } 87 } 88 89 90 93 94 protected void rollbackTransaction(Database db) throws SystemException 95 { 96 try 97 { 98 if (db.isActive()) 99 { 100 db.rollback(); 101 db.close(); 102 } 103 } 104 catch(Exception e) 105 { 106 e.printStackTrace(); 107 throw new SystemException("An error occurred when we tried to rollback an transaction. Reason:" + e.getMessage(), e); 108 } 109 } 110 111 } 112 | Popular Tags |