View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/ebxmlrr/src/share/com/sun/ebxml/registry/query/filter/QueryProcessor.java,v 1.7 2002/03/25 04:06:45 nstojano Exp $ 3 */ 4 5 package com.sun.ebxml.registry.query.filter; 6 7 import com.sun.ebxml.registry.*; 8 import com.sun.ebxml.registry.query.sql.*; 9 10 import org.oasis.ebxml.registry.bindings.query.*; 11 import org.oasis.ebxml.registry.bindings.rs.*; 12 13 /*** 14 * Class Declaration for QueryProcessor 15 * @see 16 * @author Nikola Stojanovic 17 */ 18 public abstract class QueryProcessor implements SQLConverter { 19 20 abstract protected void setNativeQuery(RegistryObjectQueryType query); 21 abstract protected String getName(); 22 abstract protected void buildFilterClauses() throws RegistryException; 23 abstract protected void buildQueryClauses() throws RegistryException; 24 abstract protected void buildBranchClauses() throws RegistryException; 25 26 protected FilterProcessor filterProcessor = new FilterProcessor(); 27 protected ClauseHandler clauseHandler = new ClauseHandler(); 28 protected String sqlQuery = null; 29 protected String whereClause = null; 30 31 /* RegistryObjectQuery is a concreete class that is the base class for all query classes, 32 so nativeQuery's role is to polymorphicaly represent any query */ 33 protected RegistryObjectQueryType nativeQuery = null; 34 private String selectColumn = null; 35 private ClauseType sqlClause = new ClauseType(); 36 37 38 public void setParentJoinColumn(String parJoinColumn) { 39 40 sqlClause.parentJoinColumn = parJoinColumn; 41 } 42 43 44 public void setSelectColumn(String selColumn) { 45 46 selectColumn = selColumn; 47 } 48 49 50 /*** 51 * Convert the specified Object obj to an equivalent SQL query string. 52 */ 53 public String convertToSQL(Object obj) throws RegistryException { 54 55 if (!(obj instanceof org.oasis.ebxml.registry.bindings.query.RegistryObjectQueryType)) { 56 throw new RegistryException("Unexpected Object " + obj + ". Was expecting org.oasis.ebxml.registry.bindings.query.RegistryObjectQuery or its subclass."); 57 } 58 59 setNativeQuery((RegistryObjectQueryType)obj); 60 setMainSelect(); 61 buildWhereClause(); 62 63 if (whereClause != null) { 64 sqlQuery = sqlQuery + " WHERE " + whereClause; 65 } 66 67 return sqlQuery; 68 } 69 70 71 public String addWhereClause(String whereClause, Object query) throws RegistryException { 72 73 sqlClause.isReverseSelectNeeded = false; 74 sqlClause.isSubSelectNeeded = true; 75 /* order of next two calls important because of side effcts in the first one -> refactor 76 for now use logic of "SOME", not "ALL/NONE" -> isReverseSelectNeeded not active */ 77 sqlClause.clause = convertToSQL(query); 78 // sqlClause.isReverseSelectNeeded = filterProcessor.isReverseSelectNeeded(); 79 return clauseHandler.addWhereClause(whereClause, sqlClause); 80 } 81 82 83 protected void buildNativeWhereClause(FilterType nativeFilter) throws RegistryException { 84 85 /* builds SQL where clause for Filters that are for the same object as the enclosing Query 86 like OrganizationFilter inside OrganizationQuery */ 87 88 ClauseType newClause = filterProcessor.getNewClause(nativeFilter); 89 whereClause = clauseHandler.addWhereClause(whereClause, newClause); 90 } 91 92 93 protected void buildForeignWhereClause(FilterType foreignFilter) throws RegistryException { 94 95 /* builds SQL where clause for Filters that are for the different object then the enclosing Query 96 like PostalAddressFilter inside OrganizationQuery */ 97 98 ClauseType newClause = filterProcessor.getNewClause(foreignFilter); 99 whereClause = clauseHandler.addWhereClause(whereClause, newClause); 100 } 101 102 103 private void setMainSelect() { 104 105 if (selectColumn == null) { 106 sqlQuery = "SELECT * FROM " + getName(); 107 } 108 else { 109 sqlQuery = "SELECT " + selectColumn + " FROM " + getName(); 110 } 111 } 112 113 114 private void buildWhereClause() throws RegistryException { 115 116 buildFilterClauses(); 117 buildQueryClauses(); 118 buildBranchClauses(); 119 } 120 }

This page was automatically generated by Maven