1 /* 2 * Copyright 2006-2008 The FLWOR Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 #ifndef ZORBA_COMPILER_VALUE_IC 18 #define ZORBA_COMPILER_VALUE_IC 19 20 #include "common/shared_types.h" 21 22 #include "compiler/expression/expr_utils.h" 23 #include "runtime/base/plan_iterator.h" 24 #include "store/api/ic.h" 25 26 27 namespace zorba 28 { 29 30 /****************************************************************************** 31 ValueIC is the class representing the integrity constraint 32 declaration. 33 34 It represents an IC and it's collection dependecies. 35 Contains one of the two kinds of info, either: 36 1) - IC name 37 - and 1 collection name 38 or 2) - IC name 39 - and 2 collection names (to and from) for the foreign key ic kind 40 41 *******************************************************************************/ 42 class ValueIC : public SimpleRCObject 43 { 44 public: 45 46 private: 47 static_context * theSctx; 48 49 store::Item_t theName; 50 store::IC::ICKind theICKind; 51 store::Item_t theCollectionName; 52 store::Item_t theFromCollectionName; 53 store::Item_t theToCollectionName; 54 PlanIter_t thePlan; 55 CompilerCB *theCcb; 56 57 public: SERIALIZABLE_CLASS(ValueIC)58 SERIALIZABLE_CLASS(ValueIC) 59 ValueIC(::zorba::serialization::Archiver& ar) : SimpleRCObject(ar) {}; 60 61 void serialize(::zorba::serialization::Archiver& ar); 62 63 public: ValueIC(static_context * sctx,const store::Item_t & name,const store::Item_t & collName,PlanIter_t icPlan,CompilerCB * ccb)64 ValueIC(static_context* sctx, const store::Item_t& name, 65 const store::Item_t& collName, 66 PlanIter_t icPlan, CompilerCB *ccb) 67 : 68 theSctx(sctx), 69 theName(name), 70 theICKind(store::IC::ic_collection), 71 theCollectionName(collName), 72 thePlan(icPlan), 73 theCcb(ccb) 74 {} 75 ValueIC(static_context * sctx,const store::Item_t & name,const store::Item_t & fromCollName,const store::Item_t & toCollName,PlanIter_t icPlan,CompilerCB * ccb)76 ValueIC(static_context* sctx, const store::Item_t& name, 77 const store::Item_t& fromCollName, const store::Item_t& toCollName, 78 PlanIter_t icPlan, CompilerCB *ccb) 79 : 80 theSctx(sctx), 81 theName(name), 82 theICKind(store::IC::ic_foreignkey), 83 theFromCollectionName(fromCollName), 84 theToCollectionName(toCollName), 85 thePlan(icPlan), 86 theCcb(ccb) 87 {} 88 89 ~ValueIC()90 virtual ~ValueIC() {} 91 getSctx()92 static_context* getSctx() const 93 { 94 return theSctx; 95 } 96 getICName()97 store::Item* getICName() const 98 { 99 return theName.getp(); 100 } 101 getCollectionName()102 const store::Item_t& getCollectionName() const 103 { 104 return theCollectionName; 105 } 106 getFromCollectionName()107 const store::Item_t& getFromCollectionName() const 108 { 109 return theFromCollectionName; 110 } 111 getToCollectionName()112 const store::Item_t& getToCollectionName() const 113 { 114 return theToCollectionName; 115 } 116 getICKind()117 store::IC::ICKind getICKind() const 118 { 119 return theICKind; 120 } 121 122 store::Iterator_t getIterator() const; 123 124 //void analyze(); 125 126 std::string toString(); 127 128 }; 129 130 typedef rchandle<ValueIC> ValueIC_t; 131 132 133 134 /** 135 * Implementation of callback store::ICChecker interface 136 */ 137 class ICCheckerImpl 138 : public store::ICChecker 139 { 140 private: 141 static_context* theSctx; 142 dynamic_context* theDctx; 143 144 public: ICCheckerImpl(static_context * sctx,dynamic_context * dctx)145 ICCheckerImpl(static_context* sctx, dynamic_context* dctx) : 146 theSctx(sctx), theDctx(dctx) {} 147 ~ICCheckerImpl()148 ~ICCheckerImpl() {} 149 150 void check(const store::Item* collName); 151 152 private: 153 void actualCheck(const store::Item* collName, 154 const store::Item* icCollName, 155 const store::Item* icName); 156 157 }; 158 159 160 } 161 162 #endif 163 164 165 /* 166 * Local variables: 167 * mode: c++ 168 * End: 169 */ 170 /* vim:set et sw=2 ts=2: */ 171