View Javadoc
1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2003 freebxml.org. All rights reserved. 7 * 8 * ==================================================================== 9 * 10 * $Revision: 1.1 $ 11 */ 12 package com.sun.xml.registry.ebxml.util; 13 /*** 14 * Helper routines used to build ad hoc queries. 15 * 16 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 17 */ 18 public class QueryUtil { 19 private static final QueryUtil INSTANCE = new QueryUtil(); 20 21 java.util.HashSet unsupportedObjectTypes = new java.util.HashSet(); 22 23 private QueryUtil() { 24 //Not supoorted as a type 25 unsupportedObjectTypes.add("ObjectType"); 26 27 //Not supported until roll to V3 schema 28 unsupportedObjectTypes.add("Registry"); 29 unsupportedObjectTypes.add("Federation"); 30 unsupportedObjectTypes.add("Subscription"); 31 } 32 33 public static QueryUtil getInstance() { 34 return INSTANCE; 35 } 36 37 /* 38 public StringBuffer addNamePredicate(StringBuffer selectStr, String namePattern) throws JAXRException { 39 return addNameOrDescriptionPredicate(selectStr, namePattern, "Name", "nm"); 40 } 41 42 public StringBuffer addDescriptionPredicate(StringBuffer selectStr, String descPattern) throws JAXRException { 43 return addNameOrDescriptionPredicate(selectStr, descPattern, "Descripton", "des"); 44 } 45 46 /* 47 * Warning assumes that registry object aliasName is 'obj'. 48 */ 49 /* 50 private StringBuffer addNameOrDescriptionPredicate(StringBuffer selectStr, String pattern, String tblName, String aliasName) throws JAXRException { 51 StringBuffer predStr = new StringBuffer();; 52 53 if ((pattern != null) && (pattern.length() > 0)) { 54 //Add name to tables in join 55 selectStr.append(", " + tblName + " " + aliasName + " "); 56 57 if ((pattern != null) && (pattern.length() != 0)) { 58 predStr.append("((" + aliasName + ".parent = obj.id) AND (" + 59 aliasName + ".value LIKE '" + pattern + "')) "); 60 } 61 } 62 63 return predStr; 64 } 65 */ 66 67 /* 68 public StringBuffer addClassificationsPredicate(StringBuffer selectSt, Collection classifications) throws JAXRException { 69 70 String q = query.toString(); 71 StringBuffer qs = new StringBuffer(q); 72 String clExpr = classificationsToExpr(classifications, PRIMARY_TABLE_NAME + ".id"); 73 74 if (clExpr != null) { 75 if (q.indexOf(WHERE_KEYWORD) != -1) { 76 // where clause already created 77 qs.append(" AND "); 78 } 79 else { 80 qs.append(" " + WHERE_KEYWORD + " "); 81 } 82 qs.append(clExpr); 83 } 84 else { 85 // No qualifiers are specified 86 } 87 88 return dqm.createQuery(Query.QUERY_TYPE_SQL, qs.toString()); 89 } 90 */ 91 92 public String classificationsToPred(java.util.Collection classifications, String term) throws javax.xml.registry.JAXRException { 93 94 if (classifications == null || classifications.size() == 0) { 95 return null; 96 } 97 java.util.Iterator i = classifications.iterator(); 98 javax.xml.registry.infomodel.Classification cl = (javax.xml.registry.infomodel.Classification)i.next(); 99 100 //??Need to be fixed to handle external classifications later 101 String sub1 = " IN (SELECT classifiedObject FROM Classification WHERE classificationNode IN ( SELECT id FROM ClassificationNode WHERE path LIKE '"; 102 StringBuffer result = new StringBuffer( 103 "(" + term + sub1 + ((com.sun.xml.registry.ebxml.infomodel.ConceptImpl)cl.getConcept()).getPath() + "%'"); 104 while (i.hasNext()) { 105 cl = (javax.xml.registry.infomodel.Classification)i.next(); 106 result.append("))) AND (" + term + sub1 107 + ((com.sun.xml.registry.ebxml.infomodel.ConceptImpl)cl.getConcept()).getPath() + "%'"); 108 } 109 return result.append(")))").toString(); 110 } 111 112 public String externalIdentifiersToPred(java.util.Collection extIds, String term) throws javax.xml.registry.JAXRException { 113 114 if (extIds == null || extIds.size() == 0) { 115 return null; 116 } 117 118 StringBuffer pred = new StringBuffer(); 119 boolean first = true; 120 java.util.Iterator iter = extIds.iterator(); 121 while (iter.hasNext()) { 122 javax.xml.registry.infomodel.ExternalIdentifier extId = (javax.xml.registry.infomodel.ExternalIdentifier)iter.next(); 123 if (!first) { 124 pred.append("AND "); 125 } 126 else { 127 first = false; 128 } 129 130 pred.append("(" + term + " IN (SELECT extId.registryObject FROM ExternalIdentifier extId WHERE (extId.value LIKE '" + extId.getValue() + "') AND (extId.identificationScheme = '" + extId.getIdentificationScheme().getKey().getId() + "' )))"); 131 132 } 133 return pred.toString(); 134 } 135 136 public String externalLinksToPred(java.util.Collection extLinks, String term) throws javax.xml.registry.JAXRException { 137 138 if (extLinks == null || extLinks.size() == 0) { 139 return null; 140 } 141 142 //SELECT * from RegistryObject obj WHERE obj.id IN 143 //(SELECT ass.targetObject from Association ass WHERE 144 //ass.associationType = 'ExternallyLinks' AND ass.sourceObject IN 145 //(SELECT id from ExternalLink extLink 146 //WHERE extLink.externalURI LIKE '%')) 147 StringBuffer pred = new StringBuffer(); 148 boolean first = true; 149 java.util.Iterator iter = extLinks.iterator(); 150 while (iter.hasNext()) { 151 javax.xml.registry.infomodel.ExternalLink extLink = (javax.xml.registry.infomodel.ExternalLink)iter.next(); 152 if (!first) { 153 pred.append("AND "); 154 } 155 else { 156 first = false; 157 } 158 pred.append("(" + term + " IN (SELECT ass.targetObject FROM Association ass WHERE ass.associationType = 'ExternallyLinks' AND ass.sourceObject IN (SELECT id from ExternalLink extLink WHERE extLink.externalURI LIKE '" + extLink.getExternalURI() + "')))"); 159 160 } 161 return pred.toString(); 162 } 163 164 public java.util.HashSet getUnsupportedObjectTypes() { 165 return unsupportedObjectTypes; 166 } 167 }

This page was automatically generated by Maven