1 23 24 package org.infoglue.cms.treeservice.ss; 25 26 import java.sql.DriverManager ; 27 import java.sql.ResultSet ; 28 import java.sql.Statement ; 29 import java.util.ArrayList ; 30 import java.util.Collection ; 31 import java.util.List ; 32 33 import org.infoglue.cms.controllers.kernel.impl.simple.ContentControllerProxy; 34 import org.infoglue.cms.entities.content.ContentVO; 35 import org.infoglue.cms.exception.ConstraintException; 36 import org.infoglue.cms.exception.SystemException; 37 38 import com.frovi.ss.Tree.BaseNode; 39 import com.frovi.ss.Tree.BaseNodeSupplier; 40 41 47 public class ContentNodeSupplierJDBC extends BaseNodeSupplier 48 { 49 50 private ArrayList cacheLeafs; 51 private java.sql.Connection conn; 52 53 54 public ContentNodeSupplierJDBC(Integer repositoryId, String userName) throws Exception , SystemException 55 { 56 Class.forName("com.mysql.jdbc.Driver").newInstance(); 57 conn = DriverManager.getConnection("jdbc:mysql://localhost/frovi_cms_dev?user=frovi_cms&password=pass123"); 58 59 Statement stmt = null; 60 stmt = conn.createStatement(); 61 ResultSet rs = stmt.executeQuery("select * from cmContent where parentContentId is null and repositoryId=" + repositoryId); 62 BaseNode rootNode = new ContentNodeImpl(); 63 if (rs.next()) 64 { 65 rootNode.setChildren(true); 66 rootNode.setId(new Integer (rs.getInt("contentId"))); 67 rootNode.setTitle(rs.getString("name")); 68 rootNode.setContainer(rs.getBoolean("isBranch")); 69 setRootNode(rootNode); 70 } 71 else 72 { 73 ContentVO vo =null; 74 try 75 { 76 vo = ContentControllerProxy.getController().getRootContentVO(repositoryId, userName); 77 rootNode.setChildren(true); 78 rootNode.setId(vo.getId()); 79 rootNode.setTitle(vo.getName()); 80 rootNode.setContainer(vo.getIsBranch().booleanValue()); 81 setRootNode(rootNode); 82 } 83 catch (ConstraintException e) 84 { 85 } 86 catch (SystemException e) 87 { 88 } 89 } 90 91 } 92 95 public boolean hasChildren() 96 { 97 return true; 98 } 99 100 103 public boolean hasChildren(Integer nodeId) 104 { 105 boolean res = false; 106 ArrayList ret = new ArrayList (); 107 List l = null; 108 Statement stmt = null; 109 110 111 try { 112 stmt = conn.createStatement(); 113 ResultSet rs; 114 rs = stmt.executeQuery("select count(contentId) as cnt from cmContent where parentContentId="+ nodeId); 115 if(rs.next()) 116 res = rs.getInt("cnt") > 0; 117 } 118 catch(Exception e) 119 { 120 e.printStackTrace(); 121 } 122 return res; 123 } 124 125 126 129 public Collection getChildContainerNodes(Integer parentNode) 130 { 131 ArrayList ret = new ArrayList (); 132 cacheLeafs = new ArrayList (); 133 134 List l = null; 135 ResultSet rs = null; 136 Statement stmt = null; 137 138 139 try { 140 stmt = conn.createStatement(); 141 rs = stmt.executeQuery("select * from cmContent where parentContentId=" + parentNode); 142 while (rs.next()) 143 { 144 BaseNode node = new ContentNodeImpl(); 145 node.setId(new Integer (rs.getInt("contentId"))); 146 node.setTitle(rs.getString("name")); 147 node.setContainer(rs.getBoolean("isBranch")); 148 149 if (node.isContainer()) 150 { 151 ret.add(node); 152 } 153 else 154 { 155 cacheLeafs.add(node); 156 } 157 158 } 159 } 160 catch(Exception e) 161 { 162 e.printStackTrace(); 163 } 164 return ret; 165 } 166 167 170 public Collection getChildLeafNodes(Integer parentNode) 171 { 172 if (cacheLeafs == null) 173 getChildContainerNodes(parentNode); 174 return cacheLeafs; 175 } 176 177 } 178 | Popular Tags |