(file) Return to CQLChainedIdentifierRep.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / CQL

  1 humberto 1.1.2.1 #include "CQLChainedIdentifier.h"
  2                  #include "CQLChainedIdentifierRep.h"
  3 humberto 1.1.2.2 #include <Pegasus/CQL/CQLFactory.h>
  4 humberto 1.1.2.1 PEGASUS_NAMESPACE_BEGIN
  5                  
  6 humberto 1.1.2.3 CQLChainedIdentifierRep::CQLChainedIdentifierRep(){
  7                  //	printf("CQLChainedIdentifier()\n");
  8                  }
  9                  
 10 humberto 1.1.2.1 CQLChainedIdentifierRep::CQLChainedIdentifierRep(String inString)
 11                  {
 12                  	parse(inString);
 13                  }
 14                  
 15                  CQLChainedIdentifierRep::CQLChainedIdentifierRep(CQLIdentifier &id)
 16                  {
 17                          _subIdentifiers.append(id);
 18 humberto 1.1.2.3 //	printf("CQLChainedIdentifier(CQLIdentifier &id)\n");
 19 humberto 1.1.2.1 }
 20                  
 21 humberto 1.1.2.3 CQLChainedIdentifierRep::CQLChainedIdentifierRep(const CQLChainedIdentifierRep* rep){
 22                  	_subIdentifiers = rep->_subIdentifiers;
 23                  //	printf("CQLChainedIdentifier COPY CONSTR\n");	
 24                  }
 25                  
 26                  CQLChainedIdentifierRep::~CQLChainedIdentifierRep(){
 27                  	
 28                  //	printf("~CQLChainedIdentifierRep()\n");
 29 humberto 1.1.2.1 }
 30                  
 31                  const Array<CQLIdentifier>& CQLChainedIdentifierRep::getSubIdentifiers()const
 32                  {
 33                  	return _subIdentifiers;
 34                  }
 35                  
 36                  CQLIdentifier CQLChainedIdentifierRep::getLastIdentifier(){
 37                  	if(_subIdentifiers.size() > 0)
 38                  		return _subIdentifiers[_subIdentifiers.size()-1];
 39                  	return CQLIdentifier();
 40                  }
 41                  
 42                  String CQLChainedIdentifierRep::toString()const{
 43                  	String s;
 44                  	for(Uint32 i = 0; i < _subIdentifiers.size(); i++){
 45                  		s.append(_subIdentifiers[i].toString());
 46                  		if(i < _subIdentifiers.size() - 1)
 47                  			s.append(".");
 48                  	}
 49                  	return s;
 50 humberto 1.1.2.1 }
 51                  
 52                  void CQLChainedIdentifierRep::append(CQLIdentifier & id){
 53                  	_subIdentifiers.append(id);
 54                  }
 55                  
 56                  Boolean CQLChainedIdentifierRep::isSubChain(CQLChainedIdentifier & chain){
 57                  	Array<CQLIdentifier> ids = chain.getSubIdentifiers();
 58                  	for(Uint32 i = 0; i < ids.size(); i++){
 59                  		if(ids[i] != _subIdentifiers[i].getName())
 60                  			return false;
 61                  	}
 62                  	return true;
 63                  }
 64                  
 65                  CQLIdentifier& CQLChainedIdentifierRep::operator[](Uint32 index){
 66                  	return _subIdentifiers[index];
 67                  }
 68                  
 69 humberto 1.1.2.3 CQLChainedIdentifierRep& CQLChainedIdentifierRep::operator=(const CQLChainedIdentifierRep& rhs){
 70                  	if(&rhs != this){
 71                  		_subIdentifiers = rhs._subIdentifiers;
 72                  //		printf("CQLChainedIdentifierRep::operator=\n");
 73                  	}
 74                  	return *this;
 75                  }
 76                  
 77 humberto 1.1.2.1 Uint32 CQLChainedIdentifierRep::size(){
 78                  	return _subIdentifiers.size();
 79                  }
 80                  
 81                  Boolean CQLChainedIdentifierRep::prepend(CQLIdentifier & id){
 82                  	/*
 83                  	   Compare id against the first element in _subIdentifiers, 
 84                  	   if not an exact match, then prepend.  This is used to fully
 85                  	   qualify the chained identifier.
 86                  	*/
 87                  	if(id != _subIdentifiers[0]){
 88                  		_subIdentifiers.prepend(id);
 89                  		return true;
 90                  	}
 91                  	return false;
 92                  }
 93                  
 94 chuck    1.1.2.4 void CQLChainedIdentifierRep::applyContext(QueryContext& inContext)
 95                  {
 96 chuck    1.1.2.5   CQLIdentifier firstId = _subIdentifiers[0];
 97                    
 98                    if (!firstId.isScoped())
 99                    {
100                      Array<CQLIdentifier> fromList = inContext.getFromList();
101                  
102                      CQLIdentifier matchedId = inContext.findClass(firstId.getName().getString());
103                  
104                      if (firstId.isWildcard())
105                      {
106                        // Example:  SELECT * FROM F AS A 
107                        _subIdentifiers.prepend(fromList[0]);
108                      }  
109                      else
110                      {
111                        if (matchedId.getName().getString() == String::EMPTY)
112                        {
113                  	// Could not find the firstId in the FROM list.
114                  	// Assume the firstId is a property, so prepend the FROM class.
115                  	// Examples:  
116                  	// SELECT p FROM F AS A  
117 chuck    1.1.2.5 	// SELECT p.p1 FROM F AS A (illegal, but caught elsewhere)  
118                          // SELECT p.* FROM F AS A 
119                          // SELECT * FROM F AS A WHERE p ISA B
120                  	_subIdentifiers.prepend(fromList[0]);
121                        }
122                        else
123                        {	
124                  	// The firstId was found in the FROM list, but it could have been 
125                  	// an alias
126                  	if (!matchedId.getName().equal(firstId.getName()))
127                  	{
128                  	  // It was an alias.
129                  	  // Replace the alias with the FROM class
130                  	  // Examples:  
131                  	  // SELECT A.p FROM F AS A 
132                  	  // SELECT A FROM F AS A  (illegal, but caught elsewhere) 
133                  	  // SELECT A.* FROM F AS A
134                  	  // SELECT * FROM F AS A WHERE A ISA B 
135                  	  // SELECT * FROM F AS A WHERE A.p ISA B
136                  	  _subIdentifiers[0] = matchedId;
137                          }
138 chuck    1.1.2.5 	else 
139                  	{
140                  	  // It was not an alias, and it is the only sub-identifier.
141                  	  // Do nothing.
142                  	  // Examples:
143                  	  // SELECT F.p FROM F AS A
144                  	  // SELECT F FROM F AS A (illegal, but caught elsewhere) 
145                  	  // SELECT F.* FROM F AS A
146                  	  // SELECT * FROM F AS A WHERE F ISA B
147                  	  // SELECT * FROM F AS A WHERE F.p ISA B
148                  	  ;
149                  	}
150                        }
151                      }
152                    }
153 humberto 1.1.2.1 }
154                  
155                  void CQLChainedIdentifierRep::parse(String & string){
156                  	/* 
157                  	  - parse string on "."
158                  	  - start from the end of string
159                  	  - if more than one substring found, 
160                  		-- store first found string then
161                  		-- prepend remaining substrings 
162                  	*/
163                  	Char16 delim('.');
164                  	Uint32 index;
165                  	String range;
166                  
167                  	/* remove any array ranges so we dont parse a false . */
168                  	if((index = string.find("[")) != PEG_NOT_FOUND){
169                  		range = string.subString(index);
170                  		string.remove(index);
171                  	}
172                  
173                  	index = string.reverseFind(delim);
174 humberto 1.1.2.1 	if(index == PEG_NOT_FOUND){
175                  		/* append the range we may have removed */
176                  		string.append(range);
177                  		_subIdentifiers.append(CQLIdentifier(string));
178                  	}else{
179                  		/* append the range we may have removed */
180                  		String tmp = string.subString(index+1);
181                  		tmp.append(range);
182                  		PEGASUS_STD(cout) << "tmp = " << tmp << PEGASUS_STD(endl);
183                  		_subIdentifiers.append(CQLIdentifier(tmp));
184                  
185                  		while(index != PEG_NOT_FOUND){
186                  			tmp = string.subString(0,index);
187                  			index = tmp.reverseFind(delim);
188                  			if(index == PEG_NOT_FOUND){
189                  				_subIdentifiers.prepend(CQLIdentifier(tmp));
190                  			}
191                  			else{
192                  				_subIdentifiers.prepend(CQLIdentifier(tmp.subString(index+1)));
193                  			}
194                  		}
195 humberto 1.1.2.1 	}
196                  }
197                  
198                  PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2