View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/ebxml/QueryManagerImpl.java,v 1.16 2003/05/22 12:29:13 farrukh_najmi Exp $ 3 * 4 * 5 */ 6 7 package com.sun.xml.registry.ebxml; 8 9 import com.sun.xml.registry.ebxml.infomodel.ConceptImpl; 10 import javax.xml.registry.*; 11 import java.util.*; 12 import javax.xml.registry.infomodel.*; 13 14 15 /*** 16 * Class Declaration for Class1 17 * 18 */ 19 public abstract class QueryManagerImpl implements QueryManager { 20 private HashMap schemeToValueMap; 21 private HashMap valueToConceptMap; 22 protected DeclarativeQueryManagerImpl dqm; 23 protected RegistryServiceImpl regService; 24 protected BusinessLifeCycleManagerImpl lcm; 25 protected User callersUser = null; 26 27 QueryManagerImpl(RegistryServiceImpl regService, 28 BusinessLifeCycleManagerImpl lcm, DeclarativeQueryManagerImpl dqm) throws JAXRException { 29 this.regService = regService; 30 this.lcm = lcm; 31 this.dqm = dqm; 32 if (this.dqm == null) { 33 this.dqm = (DeclarativeQueryManagerImpl)this; 34 } 35 } 36 37 /*** 38 * Gets the RegistryObject specified by the Id and type of object. 39 * 40 * <p><DL><DT><B>Capability Level: 0 </B></DL> 41 * 42 * @param id is the id of the Key for a RegistryObject. 43 * @param objectType is a constant definition from LifeCycleManager 44 * that specifies the type of object desired. 45 * @return RegistryObject Is the object is returned as their concrete 46 * type (e.g. Organization, User etc.). 47 */ 48 public RegistryObject getRegistryObject(String id, String objectType) 49 throws JAXRException { 50 String queryStr = "SELECT * FROM " + regService.mapJAXRNameToEbXMLName(objectType) + " WHERE id = '" + id + "'"; 51 Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr); 52 BulkResponse resp = dqm.executeQuery(query); 53 54 return ((BulkResponseImpl)resp).getRegistryObject(); 55 } 56 57 /*** 58 * Gets the RegistryObject specified by the Id. 59 * 60 * <p><DL><DT><B>Capability Level: 1 </B></DL> 61 * 62 * @return RegistryObject Is the object is returned as their concrete 63 * type (e.g. Organization, User etc.). 64 */ 65 public RegistryObject getRegistryObject(String id) throws JAXRException { 66 return getRegistryObject(id, "RegistryObject"); 67 } 68 69 70 /*** 71 * Gets the specified RegistryObjects. The objects are returned as 72 * their concrete type (e.g. Organization, User etc.). 73 * 74 * <p><DL><DT><B>Capability Level: 1 </B></DL> 75 * 76 * 77 * @return BulkResponse containing a hetrogeneous Collection of 78 * RegistryObjects (e.g. Organization, User etc.). 79 */ 80 public BulkResponse getRegistryObjects(Collection objectKeys) 81 throws JAXRException { 82 return getRegistryObjects(objectKeys, "RegistryObject"); 83 } 84 85 /*** 86 * Gets the RegistryObjects owned by the Caller. The objects are returned as 87 * their concrete type (e.g. Organization, User etc.). 88 * For to JAXR 2.0?? 89 * 90 * <p><DL><DT><B>Capability Level: 1 </B></DL> 91 * 92 * 93 * @return BulkResponse containing a hetrogeneous Collection of 94 * RegistryObjects (e.g. Organization, User etc.). 95 */ 96 public BulkResponse getCallersRegistryObjects() throws JAXRException { 97 BulkResponse resp = null; 98 99 User user = getCallersUser(); 100 101 String queryStr = "SELECT * FROM " + regService.mapJAXRNameToEbXMLName("RegistryObject") + " ro, " + 102 regService.mapJAXRNameToEbXMLName("User") + " u, " + 103 regService.mapJAXRNameToEbXMLName("AuditableEvent") + " ae " + 104 " WHERE ae.user_ = '" + user.getKey().getId() + "' AND ae.registryObject = ro.id" ; 105 Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr); 106 resp = dqm.executeQuery(query); 107 108 return resp; 109 } 110 111 112 /*** 113 * Gets the specified RegistryObjects of the specified object type. The objects are returned as 114 * their concrete type (e.g. Organization, User etc.). 115 * 116 * <p><DL><DT><B>Capability Level: 0 </B></DL> 117 * 118 * 119 * @return BulkResponse containing a hetrogeneous Collection of 120 * RegistryObjects (e.g. Organization, User etc.). 121 */ 122 public BulkResponse getRegistryObjects(Collection objectKeys, String objectType) 123 throws JAXRException { 124 StringBuffer queryStr = new StringBuffer("SELECT * FROM "); 125 queryStr.append(regService.mapJAXRNameToEbXMLName(objectType)); 126 queryStr.append(" WHERE id in ("); 127 Iterator iter = objectKeys.iterator(); 128 while (iter.hasNext()) { 129 String id = ((Key)iter.next()).getId(); 130 queryStr.append("'").append(id).append("'"); 131 if (iter.hasNext()) { 132 queryStr.append(", "); 133 } 134 } 135 queryStr.append(")"); 136 137 Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr.toString()); 138 BulkResponse resp = dqm.executeQuery(query); 139 140 return resp; 141 } 142 143 /*** 144 * Gets the RegistryObjects owned by the caller. The objects are 145 * returned as their concrete type (e.g. Organization, User etc.). 146 * 147 * <p><DL><DT><B>Capability Level: 0 </B></DL> 148 * 149 * @return BulkResponse containing a hetrogeneous Collection of 150 * RegistryObjects (e.g. Organization, User etc.). 151 */ 152 public javax.xml.registry.BulkResponse getRegistryObjects() throws javax.xml.registry.JAXRException { 153 // Write your code here 154 return null; 155 } 156 157 /*** 158 * Gets the RegistryObjects owned by the caller, that are of the 159 * specified type. The objects are returned as their concrete type 160 * (e.g. Organization, User etc.). 161 * 162 * <p><DL><DT><B>Capability Level: 0 </B></DL> 163 * 164 * @param objectType Is a constant that defines the type of object 165 * sought. See LifeCycleManager for constants for object types. 166 * @see LifeCycleManager for supported objectTypes 167 * @return BulkResponse containing a hetrogeneous Collection of 168 * RegistryObjects (e.g. Organization, User etc.). 169 */ 170 public BulkResponse getRegistryObjects(String objectType) 171 throws JAXRException { 172 // Write your code here 173 return null; 174 } 175 176 177 /* 178 * Gets the specified pre-defined concept as defined in Appendix A 179 * of the JAXR specification. 180 * 181 * <p><DL><DT><B>Capability Level: 1 </B></DL> 182 * 183 * @return The pre-defined Concept 184 * 185 * Implementation internal 186 * 187 public Concept getPredefinedConcept(String schemeName, String value) 188 throws JAXRException 189 { 190 if (schemeToValueMap == null) { 191 schemeToValueMap = new HashMap(); 192 } 193 HashMap valueToConceptMap = (HashMap)schemeToValueMap.get(schemeName); 194 if (valueToConceptMap == null) { 195 valueToConceptMap = new HashMap(); 196 schemeToValueMap.put(schemeName, valueToConceptMap); 197 } 198 ConceptImpl concept = (ConceptImpl)valueToConceptMap.get(value); 199 if (concept == null) { 200 // Existing ConceptImpl not found so create a new one 201 concept = new ConceptImpl(lcm); 202 concept.setValue(value); 203 // XXX set other Concept parts, like path 204 valueToConceptMap.put(value, concept); 205 } 206 return concept; 207 } 208 **/ 209 210 211 public javax.xml.registry.RegistryService getRegistryService() throws javax.xml.registry.JAXRException { 212 return regService; 213 } 214 215 //Add as Level 1 call in JAXR 2.0?? 216 public User getCallersUser() throws JAXRException { 217 if (callersUser == null) { 218 219 //submit an object and read it back then get its owner 220 221 RegistryPackage pkg = lcm.createRegistryPackage("Temporary object of no value"); 222 223 String id = pkg.getKey().getId(); 224 ArrayList objs = new ArrayList(); 225 objs.add(pkg); 226 lcm.saveObjects(objs); 227 228 try { 229 String queryStr = "SELECT * FROM " + regService.mapJAXRNameToEbXMLName("User") + " u, " + 230 regService.mapJAXRNameToEbXMLName("RegistryObject") + " ro, " + 231 regService.mapJAXRNameToEbXMLName("AuditableEvent") + " ae " + 232 " WHERE ro.id = '" + id + "' AND ae.registryObject = ro.id AND ae.user_ = u.id"; 233 Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr); 234 BulkResponse resp = dqm.executeQuery(query); 235 236 callersUser = (User)(((BulkResponseImpl)resp).getRegistryObject()); 237 } 238 catch (JAXRException e) { 239 throw e; 240 } 241 finally { 242 //Now remove the object that was created 243 ArrayList keys = new ArrayList(); 244 keys.add(pkg.getKey()); 245 lcm.deleteObjects(keys); 246 } 247 248 if (callersUser == null) { 249 //Caller is no registered so create new User so it can register 250 callersUser = lcm.createUser(); 251 } 252 } 253 254 return callersUser; 255 } 256 257 }

This page was automatically generated by Maven