View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/ebxmlrr/src/share/com/sun/ebxml/registry/query/sql/SQLQueryProcessor.java,v 1.9 2003/07/18 23:06:46 farrukh_najmi Exp $ 3 * 4 * Copyright (c) 1999 Sun Microsystems, Inc. All Rights Reserved. 5 * 6 * This software is the confidential and proprietary information of Sun 7 * Microsystems, Inc. ("Confidential Information"). You shall not 8 * disclose such Confidential Information and shall use it only in 9 * accordance with the terms of the license agreement you entered into 10 * with Sun. 11 * 12 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE 13 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 14 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 15 * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES 16 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING 17 * THIS SOFTWARE OR ITS DERIVATIVES. 18 * 19 */ 20 21 package com.sun.ebxml.registry.query.sql; 22 23 import java.util.*; 24 import java.io.*; 25 26 import org.oasis.ebxml.registry.bindings.query.*; 27 import org.oasis.ebxml.registry.bindings.query.types.*; 28 import org.oasis.ebxml.registry.bindings.rim.*; 29 30 31 import com.sun.ebxml.registry.*; 32 import com.sun.ebxml.registry.persistence.rdb.*; 33 34 import org.apache.commons.logging.Log; 35 import org.apache.commons.logging.LogFactory; 36 37 /*** 38 * Processor for SQL queries. Used by the QueryManagerImpl. 39 * 40 * @see 41 * @author Farrukh S. Najmi 42 */ 43 public class SQLQueryProcessor { 44 private Log log = LogFactory.getLog(this.getClass()); 45 protected SQLQueryProcessor(){} 46 47 public AdhocQueryResponse executeQuery(User user, String sqlQuery, ResponseOption responseOption) throws RegistryException { 48 log.info("executing query: '" + sqlQuery + "')"); 49 AdhocQueryResponse resp = new AdhocQueryResponse(); 50 SQLQueryResult sqlResult = new SQLQueryResult(); 51 52 try { 53 //parse the queryString to sget at certain info like the select column and table name etc. 54 InputStream stream = new ByteArrayInputStream(sqlQuery.getBytes()); 55 SQLParser parser = new SQLParser(stream); 56 57 //Fix the query according to the responseOption to return the right type of objects 58 String fixedQuery = parser.processQuery(user, responseOption); 59 60 //Get the ArrayList of objects (ObjectRef, RegistryObject, RegistryEntry, leaf class) as 61 //specified by the responeOption 62 ArrayList objectRefs = new ArrayList(); 63 ArrayList objs = SQLPersistenceManagerImpl.getInstance().executeSQLQuery(fixedQuery, responseOption, parser.firstTableName, objectRefs); 64 65 if (objs != null) { 66 Iterator iter = objs.iterator(); 67 while (iter.hasNext()) { 68 69 Object obj = iter.next(); 70 71 if (obj.getClass().getName().equals("org.oasis.ebxml.registry.bindings.rim.RegistryObject")) { 72 RegistryObjectListTypeItem item = new RegistryObjectListTypeItem(); 73 item.setRegistryObject((RegistryObject)obj); 74 sqlResult.addRegistryObjectListTypeItem(item); 75 } 76 else if (obj.getClass().getName().equals("org.oasis.ebxml.registry.bindings.rim.RegistryEntry")) { 77 RegistryObjectListTypeItem item = new RegistryObjectListTypeItem(); 78 item.setRegistryEntry((RegistryEntry)obj); 79 sqlResult.addRegistryObjectListTypeItem(item); 80 } 81 else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.Association) { 82 LeafRegistryObjectListTypeItem li = new LeafRegistryObjectListTypeItem(); 83 li.setAssociation((Association)obj); 84 sqlResult.addLeafRegistryObjectListTypeItem(li); 85 } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.AuditableEvent) { 86 LeafRegistryObjectListTypeItem li = new LeafRegistryObjectListTypeItem(); 87 li.setAuditableEvent((AuditableEvent)obj); 88 sqlResult.addLeafRegistryObjectListTypeItem(li); 89 } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.Classification) { 90 LeafRegistryObjectListTypeItem li = new LeafRegistryObjectListTypeItem(); 91 li.setClassification((Classification)obj); 92 sqlResult.addLeafRegistryObjectListTypeItem(li); 93 } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ClassificationNode) { 94 LeafRegistryObjectListTypeItem li = new LeafRegistryObjectListTypeItem(); 95 li.setClassificationNode((ClassificationNode)obj); 96 sqlResult.addLeafRegistryObjectListTypeItem(li); 97 } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ClassificationScheme) { 98 LeafRegistryObjectListTypeItem li = new LeafRegistryObjectListTypeItem(); 99 li.setClassificationScheme((ClassificationScheme)obj); 100 sqlResult.addLeafRegistryObjectListTypeItem(li); 101 } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ExternalIdentifier) { 102 LeafRegistryObjectListTypeItem li = new LeafRegistryObjectListTypeItem(); 103 li.setExternalIdentifier((ExternalIdentifier)obj); 104 sqlResult.addLeafRegistryObjectListTypeItem(li); 105 } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ExternalLink) { 106 LeafRegistryObjectListTypeItem li = new LeafRegistryObjectListTypeItem(); 107 li.setExternalLink((ExternalLink)obj); 108 sqlResult.addLeafRegistryObjectListTypeItem(li); 109 } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ExtrinsicObject) { 110 LeafRegistryObjectListTypeItem li = new LeafRegistryObjectListTypeItem(); 111 li.setExtrinsicObject((ExtrinsicObject)obj); 112 sqlResult.addLeafRegistryObjectListTypeItem(li); 113 } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ObjectRef) { 114 LeafRegistryObjectListTypeItem li = new LeafRegistryObjectListTypeItem(); 115 li.setObjectRef((ObjectRef)obj); 116 sqlResult.addLeafRegistryObjectListTypeItem(li); 117 } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.Organization) { 118 LeafRegistryObjectListTypeItem li = new LeafRegistryObjectListTypeItem(); 119 li.setOrganization((Organization)obj); 120 sqlResult.addLeafRegistryObjectListTypeItem(li); 121 } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.RegistryPackage) { 122 LeafRegistryObjectListTypeItem li = new LeafRegistryObjectListTypeItem(); 123 li.setRegistryPackage((RegistryPackage)obj); 124 sqlResult.addLeafRegistryObjectListTypeItem(li); 125 } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.Service) { 126 LeafRegistryObjectListTypeItem li = new LeafRegistryObjectListTypeItem(); 127 li.setService((Service)obj); 128 sqlResult.addLeafRegistryObjectListTypeItem(li); 129 } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ServiceBinding) { 130 LeafRegistryObjectListTypeItem li = new LeafRegistryObjectListTypeItem(); 131 li.setServiceBinding((ServiceBinding)obj); 132 sqlResult.addLeafRegistryObjectListTypeItem(li); 133 } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.SpecificationLink) { 134 LeafRegistryObjectListTypeItem li = new LeafRegistryObjectListTypeItem(); 135 li.setSpecificationLink((SpecificationLink)obj); 136 sqlResult.addLeafRegistryObjectListTypeItem(li); 137 } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.User) { 138 LeafRegistryObjectListTypeItem li = new LeafRegistryObjectListTypeItem(); 139 li.setUser((User)obj); 140 sqlResult.addLeafRegistryObjectListTypeItem(li); 141 } else { 142 throw new RegistryException("Unexpected object" + obj); 143 } 144 } 145 146 // Attaching the ObjectRef to the response. objectsRefs contains duplicates! 147 Iterator objectRefsIter = objectRefs.iterator(); 148 // It is to store the ObjectRef 's id after removing duplicated ObjectRef. It is a dirty fix, change it later!!!! 149 ArrayList finalObjectRefsIds = new ArrayList(); 150 ArrayList finalObjectRefs = new ArrayList(); 151 while(objectRefsIter.hasNext()) { 152 Object obj = objectRefsIter.next(); 153 if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ObjectRef) { 154 ObjectRef objectRef = (ObjectRef) obj; 155 String id = objectRef.getId(); 156 if (!finalObjectRefsIds.contains(id)) { 157 finalObjectRefsIds.add(id); 158 ObjectRef or = new ObjectRef(); 159 or.setId(id); 160 finalObjectRefs.add(or); 161 } 162 } 163 else { 164 throw new RegistryException("Unexpected object" + obj); 165 } 166 } 167 168 Iterator finalObjectRefsIter = finalObjectRefs.iterator(); 169 while (finalObjectRefsIter.hasNext()) { 170 Object obj = finalObjectRefsIter.next(); 171 if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ObjectRef) { 172 LeafRegistryObjectListTypeItem li = new LeafRegistryObjectListTypeItem(); 173 li.setObjectRef((ObjectRef)obj); 174 sqlResult.addLeafRegistryObjectListTypeItem(li); 175 } 176 else { 177 throw new RegistryException("Unexpected object" + obj); 178 } 179 } 180 } 181 } 182 catch (ParseException e) { 183 e.printStackTrace(); 184 throw new RegistryException(e); 185 } 186 187 188 resp.setSQLQueryResult(sqlResult); 189 190 return resp; 191 } 192 193 public static SQLQueryProcessor getInstance(){ 194 if (instance == null) { 195 synchronized(com.sun.ebxml.registry.query.sql.SQLQueryProcessor.class) { 196 if (instance == null) { 197 instance = new com.sun.ebxml.registry.query.sql.SQLQueryProcessor(); 198 } 199 } 200 } 201 return instance; 202 } 203 204 /*** 205 * @link 206 * @shapeType PatternLink 207 * @pattern Singleton 208 * @supplierRole Singleton factory 209 */ 210 /*# private SQLQueryProcessor _sqlQueryProcessor; */ 211 private static SQLQueryProcessor instance = null; 212 }

This page was automatically generated by Maven