List:Commits« Previous MessageNext Message »
From:Ole John Aske Date:June 26 2009 12:01pm
Subject:bzr push into mysql-5.1-telco-7.0-spj branch (ole.john.aske:2901 to 2902)
View as plain text  
 2902 Ole John Aske	2009-06-26
      - Removed getRootOperation() according to IRC discussion.
        (Want restrict API to a single root)
      - Added get'ers itterators to get all operations from a 
        NdbQueryDef. (Compensates for removed getRoot...)
      - Rewrite where getRootOperations was used.
      - Populate NdbQueryDef::m_operations[] with all operations
        contained in the NdbQueryDef.
      - Implemented parent/child get'ers in NdbQueryDef
      - Populate NdbQuery::m_operations[] and
        NdbQueryOperation::child[]/parent[] buildQuery() construct 
        query object.
      - Dealloc of objects on d'tors

    modified:
      storage/ndb/include/ndbapi/NdbQueryBuilder.hpp
      storage/ndb/include/ndbapi/NdbQueryOperation.hpp
      storage/ndb/ndbapi-examples/ndbapi_multi_cursor/main.cpp
      storage/ndb/src/ndbapi/NdbQueryBuilder.cpp
      storage/ndb/src/ndbapi/NdbQueryBuilderImpl.hpp
      storage/ndb/src/ndbapi/NdbQueryOperation.cpp
      storage/ndb/src/ndbapi/NdbQueryOperationImpl.hpp
 2901 Jan Wedvik	2009-06-26
      Fixed error that caused mechanism to detect the end of NdbQueryOperations to fail if TCKEYREF was recived.

    modified:
      storage/ndb/src/ndbapi/NdbQueryOperation.cpp
      storage/ndb/src/ndbapi/NdbQueryOperationImpl.hpp
      storage/ndb/src/ndbapi/Ndbif.cpp
=== modified file 'storage/ndb/include/ndbapi/NdbQueryBuilder.hpp'
--- a/storage/ndb/include/ndbapi/NdbQueryBuilder.hpp	2009-06-25 13:38:11 +0000
+++ b/storage/ndb/include/ndbapi/NdbQueryBuilder.hpp	2009-06-26 12:01:17 +0000
@@ -26,6 +26,7 @@
 
 class Ndb;
 
+class NdbQueryDefImpl;
 class NdbQueryBuilderImpl;
 class NdbQueryOperandImpl;
 class NdbQueryOperationDefImpl;
@@ -121,9 +122,6 @@ public:
   Uint32 getNoOfChildOperations() const;
   const NdbQueryOperationDef* getChildOperation(Uint32 i) const;
 
-  const NdbQueryOperationDef* getRootOperation() const;
-  // assert(getRootOperation()->getNoOfParentOperations() == 0);
-
   /**
    * Get table object for this operation
    */
@@ -306,7 +304,7 @@ class NdbQueryDef
 {
 protected:
   // C'tor is protected - only NdbQueryBuilder::prepare() is allowed to construct a new NdbQueryDef
-  NdbQueryDef();
+  NdbQueryDef(NdbQueryDefImpl* pimpl);
 
 public:
   ~NdbQueryDef();
@@ -317,14 +315,15 @@ public:
   NdbQueryDef(const NdbQueryDef& other);
   NdbQueryDef& operator = (const NdbQueryDef& other);
 
-  const NdbQueryOperationDef* getRootOperation() const;
-
-//Uint32 getNoOfOperations() const;
+  Uint32 getNoOfOperations() const;
 
   // Get a specific NdbQueryOperationDef by ident specified
   // when the NdbQueryOperationDef was created.
-//NdbQueryOperationDef* getQueryOperationDef(const char* ident) const;
-//NdbQueryOperationDef* getQueryOperationDef(Uint32 index) const;
+  const NdbQueryOperationDef* getQueryOperation(const char* ident) const;
+  const NdbQueryOperationDef* getQueryOperation(Uint32 index) const;
+
+  // Get the ordinal position of a operation within this queryDef
+  int getQueryOperationIx(const NdbQueryOperationDef*) const;
 
   // Remove this NdbQueryDef including operation and operands it contains
 //void release();    Just delete it instead ?
@@ -332,7 +331,7 @@ public:
 //class NdbQueryDefImpl& getImpl() const;
 
 private:
-//class NdbQueryDefImpl* const m_pimpl;
+  NdbQueryDefImpl* const m_pimpl;
 };
 
 

=== modified file 'storage/ndb/include/ndbapi/NdbQueryOperation.hpp'
--- a/storage/ndb/include/ndbapi/NdbQueryOperation.hpp	2009-06-25 13:38:11 +0000
+++ b/storage/ndb/include/ndbapi/NdbQueryOperation.hpp	2009-06-26 12:01:17 +0000
@@ -68,9 +68,6 @@ public:
   // END Jans hack.
   /////////////////////////////////////////////////
 
-  // get NdbQueryOperation being the root of a linked operation
-  NdbQueryOperation* getRootOperation() const;
-
   Uint32 getNoOfOperations() const;
 
   // Get a specific NdbQueryOperation by ident specified
@@ -179,9 +176,6 @@ public:
 
   // Collection of get'ers to navigate in root, parent/child hierarchy
 
-  NdbQueryOperation* getRootOperation() const;
-  // assert(getRootOperation()->getNoOfParentOperations() == 0);
-
   Uint32 getNoOfParentOperations() const;
   NdbQueryOperation* getParentOperation(Uint32 i) const;
 

=== modified file 'storage/ndb/ndbapi-examples/ndbapi_multi_cursor/main.cpp'
--- a/storage/ndb/ndbapi-examples/ndbapi_multi_cursor/main.cpp	2009-06-25 13:38:11 +0000
+++ b/storage/ndb/ndbapi-examples/ndbapi_multi_cursor/main.cpp	2009-06-26 12:01:17 +0000
@@ -463,8 +463,59 @@ int testQueryBuilder(Ndb &myNdb)
 *****/
 
 
+  /* Composite operations building real *trees* aka. linked operations.
+   * (First part is identical to building 'qt2' above)
+   *
+   * The related SQL query which this simulates would be something like:
+   *
+   * select * from dept_manager join employees using(emp_no)
+   *  where dept_no = 'd005' and emp_no = 110567;
+   */
+  printf("q4\n");
+  NdbQueryDef* q4 = 0;
+  {
+    NdbQueryBuilder* qb = &myBuilder; //myDict->getQueryBuilder();
+
+    const NdbQueryOperand* managerKey[] =       // Manager is indexed om {"dept_no", "emp_no"}
+    {  qb->paramValue(),         // dept_no parameter,
+       qb->paramValue("emp"),    // emp_no parameter - param naming is optional
+       0
+    };
+    // Lookup a single tuple with key define by 'managerKey' param. tuple
+    const NdbQueryLookupOperationDef *readManager = qb->readTuple(manager, managerKey);
+    if (readManager == NULL) APIERROR(qb->getNdbError());
+
+    // THEN: employee table is joined:
+    //    A linked value is used to let employee lookup refer values
+    //    from the parent operation on manger.
+
+    const NdbQueryOperand* empJoinKey[] =         // Employee is indexed om {"emp_no"}
+    {  qb->linkedValue(readManager, "emp_no"),  // where '= readManger.emp_no'
+       0
+    };
+    const NdbQueryLookupOperationDef* readEmployee = qb->readTuple(employee, empJoinKey);
+    if (readEmployee == NULL) APIERROR(qb->getNdbError());
+
+    q4 = qb->prepare();
+    if (q4 == NULL) APIERROR(qb->getNdbError());
+
+    assert (q4->getNoOfOperations() == 2);
+    assert (q4->getQueryOperation((Uint32)0) == readManager);
+    assert (q4->getQueryOperation((Uint32)1) == readEmployee);
+//  assert (q4->getQueryOperation((Uint32)2) == NULL);
+
+    assert (q4->getQueryOperation((Uint32)0)->getNoOfParentOperations() == 0);
+//  assert (q4->getQueryOperation((Uint32)0)->getParentOperation((Uint32)0) == NULL);
+    assert (q4->getQueryOperation((Uint32)0)->getNoOfChildOperations() == 1);
+    assert (q4->getQueryOperation((Uint32)0)->getChildOperation((Uint32)0) == readEmployee);
+    assert (q4->getQueryOperation((Uint32)1)->getNoOfParentOperations() == 1);
+    assert (q4->getQueryOperation((Uint32)1)->getParentOperation((Uint32)0) == readManager);
+    assert (q4->getQueryOperation((Uint32)1)->getNoOfChildOperations() == 0);
+//  assert (q4->getQueryOperation((Uint32)1)->getChildOperation((Uint32)0) == NULL);
+  }
+
   ///////////////////////////////////////////////////
-  // q2 may later be executed as:
+  // q4 may later be executed as:
   // (Possibly multiple ::execute() or multiple NdbQueryDef instances 
   // within the same NdbTransaction::execute(). )
   ////////////////////////////////////////////////////
@@ -475,14 +526,25 @@ int testQueryBuilder(Ndb &myNdb)
   NdbTransaction* myTransaction= myNdb.startTransaction();
   if (myTransaction == NULL) APIERROR(myNdb.getNdbError());
 
-  NdbQuery* myQuery = myTransaction->createQuery(q2, paramList);
+  NdbQuery* myQuery = myTransaction->createQuery(q4, paramList);
   if (myQuery == NULL)
     APIERROR(myTransaction->getNdbError());
 
+  assert (myQuery->getNoOfOperations() == 2);
+
+  assert (myQuery->getQueryOperation((Uint32)0)->getNoOfParentOperations() == 0);
+//assert (myQuery->getQueryOperation((Uint32)0)->getParentOperation((Uint32)0) == NULL);
+  assert (myQuery->getQueryOperation((Uint32)0)->getNoOfChildOperations() == 1);
+  assert (myQuery->getQueryOperation((Uint32)0)->getChildOperation((Uint32)0) == myQuery->getQueryOperation((Uint32)1));
+  assert (myQuery->getQueryOperation((Uint32)1)->getNoOfParentOperations() == 1);
+  assert (myQuery->getQueryOperation((Uint32)1)->getParentOperation((Uint32)0) == myQuery->getQueryOperation((Uint32)0));
+  assert (myQuery->getQueryOperation((Uint32)1)->getNoOfChildOperations() == 0);
+//assert (myQuery->getQueryOperation((Uint32)1)->getChildOperation((Uint32)0) == NULL);
+
+/*******
   ManagerRow managerRow;
   memset (&managerRow, 0, sizeof(managerRow));
 
-/*******
   // Specify result handling NdbRecord style - need the (single) NdbQueryOperation:
   assert(myQuery->getNoOfOperations()==1);
   NdbQueryOperation* op = myQuery->getQueryOperation((Uint32)0);
@@ -504,44 +566,6 @@ int testQueryBuilder(Ndb &myNdb)
   myNdb.closeTransaction(myTransaction);
   myTransaction = 0;
 
-
-  /* Composite operations building real *trees* aka. linked operations.
-   * (First part is identical to building 'qt2' above)
-   *
-   * The related SQL query which this simulates would be something like:
-   *
-   * select * from dept_manager join employees using(emp_no)
-   *  where dept_no = 'd005' and emp_no = 110567;
-   */
-  printf("q4\n");
-  NdbQueryDef* q4 = 0;
-  {
-    NdbQueryBuilder* qb = &myBuilder; //myDict->getQueryBuilder();
-
-    const NdbQueryOperand* managerKey[] =       // Manager is indexed om {"dept_no", "emp_no"}
-    {  qb->paramValue(),         // dept_no parameter,
-       qb->paramValue("emp"),    // emp_no parameter - param naming is optional
-       0
-    };
-    // Lookup a single tuple with key define by 'managerKey' param. tuple
-    const NdbQueryLookupOperationDef *readManager = qb->readTuple(manager, managerKey);
-    if (readManager == NULL) APIERROR(qb->getNdbError());
-
-    // THEN: employee table is joined:
-    //    A linked value is used to let employee lookup refer values
-    //    from the parent operation on manger.
-
-    const NdbQueryOperand* empJoinKey[] =         // Employee is indexed om {"emp_no"}
-    {  qb->linkedValue(readManager, "emp_no"),  // where '= readManger.emp_no'
-       0
-    };
-    const NdbQueryLookupOperationDef* readEmployee = qb->readTuple(employee, empJoinKey);
-    if (readEmployee == NULL) APIERROR(qb->getNdbError());
-
-    q4 = qb->prepare();
-    if (q4 == NULL) APIERROR(qb->getNdbError());
-  }
-
   return 0;
 }
 

=== modified file 'storage/ndb/src/ndbapi/NdbQueryBuilder.cpp'
--- a/storage/ndb/src/ndbapi/NdbQueryBuilder.cpp	2009-06-25 13:38:11 +0000
+++ b/storage/ndb/src/ndbapi/NdbQueryBuilder.cpp	2009-06-26 12:01:17 +0000
@@ -85,13 +85,15 @@ public:
   { return m_column; };
 
   virtual int bindOperand(const NdbDictionary::Column* column,
-                           NdbQueryOperationDefImpl* operation)
+                          NdbQueryOperationDef* operation)
   { m_column = column;
     return 0;
   }
 
 protected:
   virtual ~NdbQueryOperandImpl() {};
+  friend NdbQueryBuilderImpl::~NdbQueryBuilderImpl();
+
   NdbQueryOperandImpl()
   : m_column(0) {}
 
@@ -108,17 +110,17 @@ class NdbLinkedOperandImpl :
 
 public:
   virtual int bindOperand(const NdbDictionary::Column* column,
-                          NdbQueryOperationDefImpl* operation);
+                          NdbQueryOperationDef* operation);
 
 private:
   virtual ~NdbLinkedOperandImpl() {};
   NdbLinkedOperandImpl (const NdbQueryOperationDef* parent, 
                         const NdbDictionary::Column* column)
    : NdbLinkedOperand(this), NdbQueryOperandImpl(),
-     m_parent(&parent->getImpl()), m_column(column)
+     m_parent(parent), m_column(column)
   {};
 
-  NdbQueryOperationDefImpl* const m_parent;
+  const NdbQueryOperationDef* const m_parent;
   const NdbDictionary::Column* const m_column;
 }; // class NdbLinkedOperandImpl
 
@@ -161,7 +163,7 @@ public:
   virtual const void* getAddr() const = 0;
 
   virtual int bindOperand(const NdbDictionary::Column* column,
-                          NdbQueryOperationDefImpl* operation);
+                          NdbQueryOperationDef* operation);
 
   virtual NdbDictionary::Column::Type getType() const = 0;
 
@@ -254,38 +256,43 @@ class NdbQueryOperationDefImpl
 {
 public:
   Uint32 getNoOfParentOperations() const
-  { return 0; };  // FIXME.
+  { return m_parents.size(); };
 
   const NdbQueryOperationDef* getParentOperation(Uint32 i) const
-  { return 0; };  // FIXME.
+  { return m_parents[i]; };
 
   Uint32 getNoOfChildOperations() const
-  { return 0; };  // FIXME.
+  { return m_children.size(); };
 
   const NdbQueryOperationDef* getChildOperation(Uint32 i) const
-  { return 0; };  // FIXME.
+  { return m_children[i]; };
 
   const NdbDictionary::Table* getTable() const
   { return m_table; };
 
-  void addParent(NdbQueryOperationDefImpl *);
-  void addChild(NdbQueryOperationDefImpl *);
+  void addParent(const NdbQueryOperationDef *);
+  void addChild(const NdbQueryOperationDef *);
 
 protected:
   virtual ~NdbQueryOperationDefImpl() {};
+  friend NdbQueryBuilderImpl::~NdbQueryBuilderImpl();
+  friend NdbQueryDefImpl::~NdbQueryDefImpl();
+
   NdbQueryOperationDefImpl (
                            const NdbDictionary::Table* table,
                            const char* ident)
    : m_table(table), m_ident(ident),
-     m_parent(), m_child()
+     m_parents(), m_children()
  {};
 
 private:
   const NdbDictionary::Table* const m_table;
   const char* const m_ident;
 
-  Vector<NdbQueryOperationDefImpl*> m_parent;
-  Vector<NdbQueryOperationDefImpl*> m_child;
+  // parent / child vectors are indexes into m_operation vector
+  // which contains the real pointers to parent/child operations
+  Vector<const NdbQueryOperationDef*> m_parents;
+  Vector<const NdbQueryOperationDef*> m_children;
 
 }; // class NdbQueryOperationDefImpl
 
@@ -381,38 +388,39 @@ private:
 
 
 
-
-class NdbQueryDefImpl : public NdbQueryDef
-{
-public:
-  NdbQueryDefImpl();
-  ~NdbQueryDefImpl();
-
-
-private:
-  Vector<NdbQueryOperationDefImpl*> m_operation;
-//Vector<NdbParamOperand*> m_paramOperand;
-//Vector<NdbConstOperand*> m_constOperand;
-//Vector<NdbLinkedOperand*> m_linkedOperand;
-}; // class NdbQueryDefImpl
-
-
 ///////////////////////////////////////////////////
 /////// End 'Impl' class declarations /////////////
 ///////////////////////////////////////////////////
 
-NdbQueryDef::NdbQueryDef()
+NdbQueryDef::NdbQueryDef(NdbQueryDefImpl* pimpl) : m_pimpl(pimpl)
 {}
 NdbQueryDef::~NdbQueryDef()
 {}
 
+Uint32
+NdbQueryDef::getNoOfOperations() const
+{ return m_pimpl->m_operations.size();
+}
 
 const NdbQueryOperationDef*
-NdbQueryDef::getRootOperation() const
-{
-  return NULL;  // FIXME
+NdbQueryDef::getQueryOperation(Uint32 index) const
+{ return m_pimpl->m_operations[index];
+}
+
+const NdbQueryOperationDef*
+NdbQueryDef::getQueryOperation(const char* ident) const
+{ return NULL;  // FIXME
 }
 
+int
+NdbQueryDef::getQueryOperationIx(const NdbQueryOperationDef* opDef) const
+{
+  for (int i=0; i<m_pimpl->m_operations.size(); ++i)
+  { if (m_pimpl->m_operations[i] == opDef)
+      return i;
+  }
+  return -1;
+}
 
 
 /*************************************************************************
@@ -608,7 +616,7 @@ NdbQueryBuilder::constValue(const char* 
   NdbConstOperandImpl* constOp = new NdbCharConstOperandImpl(value);
   returnErrIf(constOp==0,4000);
 
-  m_pimpl->m_constOperand.push_back(constOp);
+  m_pimpl->m_constOperands.push_back(constOp);
   return constOp;
 }
 NdbConstOperand* 
@@ -618,7 +626,7 @@ NdbQueryBuilder::constValue(const void* 
   NdbConstOperandImpl* constOp = new NdbGenericConstOperandImpl(value,length);
   returnErrIf(constOp==0,4000);
 
-  m_pimpl->m_constOperand.push_back(constOp);
+  m_pimpl->m_constOperands.push_back(constOp);
   return constOp;
 }
 NdbConstOperand* 
@@ -627,7 +635,7 @@ NdbQueryBuilder::constValue(Int32 value)
   NdbConstOperandImpl* constOp = new NdbInt32ConstOperandImpl(value);
   returnErrIf(constOp==0,4000);
 
-  m_pimpl->m_constOperand.push_back(constOp);
+  m_pimpl->m_constOperands.push_back(constOp);
   return constOp;
 }
 NdbConstOperand* 
@@ -636,7 +644,7 @@ NdbQueryBuilder::constValue(Uint32 value
   NdbConstOperandImpl* constOp = new NdbUint32ConstOperandImpl(value);
   returnErrIf(constOp==0,4000);
 
-  m_pimpl->m_constOperand.push_back(constOp);
+  m_pimpl->m_constOperands.push_back(constOp);
   return constOp;
 }
 NdbConstOperand* 
@@ -645,7 +653,7 @@ NdbQueryBuilder::constValue(Int64 value)
   NdbConstOperandImpl* constOp = new NdbInt64ConstOperandImpl(value);
   returnErrIf(constOp==0,4000);
 
-  m_pimpl->m_constOperand.push_back(constOp);
+  m_pimpl->m_constOperands.push_back(constOp);
   return constOp;
 }
 NdbConstOperand* 
@@ -654,7 +662,7 @@ NdbQueryBuilder::constValue(Uint64 value
   NdbConstOperandImpl* constOp = new NdbUint64ConstOperandImpl(value);
   returnErrIf(constOp==0,4000);
 
-  m_pimpl->m_constOperand.push_back(constOp);
+  m_pimpl->m_constOperands.push_back(constOp);
   return constOp;
 }
 
@@ -664,7 +672,7 @@ NdbQueryBuilder::paramValue(const char* 
   NdbParamOperandImpl* paramOp = new NdbParamOperandImpl(name);
   returnErrIf(paramOp==0,4000);
 
-  m_pimpl->m_paramOperand.push_back(paramOp);
+  m_pimpl->m_paramOperands.push_back(paramOp);
   return paramOp;
 }
 
@@ -674,7 +682,7 @@ NdbQueryBuilder::linkedValue(const NdbQu
   returnErrIf(parent==0 || attr==0, 4800);  // Required non-NULL arguments
 
   // Parent should be a OperationDef contained in this query builder context
-  returnErrIf(!m_pimpl->contains(&parent->getImpl()), 4804); // Unknown parent
+  returnErrIf(!m_pimpl->contains(parent), 4804); // Unknown parent
 
   // 'attr' should refer a column from the underlying table in parent:
   const NdbDictionary::Column* column = parent->getTable()->getColumn(attr);
@@ -683,7 +691,7 @@ NdbQueryBuilder::linkedValue(const NdbQu
   NdbLinkedOperandImpl* linkedOp = new NdbLinkedOperandImpl(parent,column);
   returnErrIf(linkedOp==0, 4000);
 
-  m_pimpl->m_linkedOperand.push_back(linkedOp);
+  m_pimpl->m_linkedOperands.push_back(linkedOp);
   return linkedOp;
 }
 
@@ -734,7 +742,7 @@ NdbQueryBuilder::readTuple(const NdbDict
     }
   }
   
-  m_pimpl->m_operation.push_back(op);
+  m_pimpl->m_operations.push_back(op);
   return op;
 }
 
@@ -753,7 +761,7 @@ NdbQueryBuilder::readTuple(const NdbDict
     new NdbQueryLookupOperationDefImpl(index,table,keys,ident);
   returnErrIf(op==0, 4000);
 
-  m_pimpl->m_operation.push_back(op);
+  m_pimpl->m_operations.push_back(op);
   return op;
 }
 
@@ -770,7 +778,7 @@ NdbQueryBuilder::scanTable(const NdbDict
     new NdbQueryTableScanOperationDefImpl(table,ident);
   returnErrIf(op==0, 4000);
 
-  m_pimpl->m_operation.push_back(op);
+  m_pimpl->m_operations.push_back(op);
   return op;
 }
 
@@ -789,7 +797,7 @@ NdbQueryBuilder::scanIndex(const NdbDict
     new NdbQueryIndexScanOperationDefImpl(index,table,bound,ident);
   returnErrIf(op==0, 4000);
 
-  m_pimpl->m_operation.push_back(op);
+  m_pimpl->m_operations.push_back(op);
   return op;
 }
 
@@ -804,79 +812,108 @@ NdbQueryBuilder::prepare()
 ////////////////////////////////////////
 
 NdbQueryBuilderImpl::NdbQueryBuilderImpl(Ndb& ndb)
-: m_ndb(ndb), m_error(), m_operation(),
-  m_paramOperand(), m_constOperand(), m_linkedOperand()
+: m_ndb(ndb), m_error(), m_operations(),
+  m_paramOperands(), m_constOperands(), m_linkedOperands()
 {}
 
 NdbQueryBuilderImpl::~NdbQueryBuilderImpl()
 {
-  // FIXME: Delete all operand and operator in Vector's
+  int i;
+ 
+  // Delete all operand and operator in Vector's
+  for (i=0; i<m_operations.size(); ++i)
+  { delete &m_operations[i]->getImpl();
+  }
+  for (i=0; i<m_paramOperands.size(); ++i)
+  { delete &m_paramOperands[i]->getImpl();
+  }
+  for (i=0; i<m_constOperands.size(); ++i)
+  { delete &m_constOperands[i]->getImpl();
+  }
+  for (i=0; i<m_linkedOperands.size(); ++i)
+  { delete &m_linkedOperands[i]->getImpl();
+  }
 }
 
 
 bool 
-NdbQueryBuilderImpl::contains(const NdbQueryOperationDefImpl* opDef)
+NdbQueryBuilderImpl::contains(const NdbQueryOperationDef* opDef)
 {
-  for (int i=0; i<m_operation.size(); ++i)
-  { if (m_operation[i] == opDef)
+  for (int i=0; i<m_operations.size(); ++i)
+  { if (m_operations[i] == opDef)
       return true;
   }
   return false;
 }
 
+
 NdbQueryDef*
 NdbQueryBuilderImpl::prepare()
 {
   int i;
 
 /****
-  // FIXME: Build parent/child operation references
-  //        Install named OperationDef's in HashMap
+  // FIXME: Install named OperationDef's in HashMap
   for (i = 0; i<m_operation.size(); ++i)
-  { const NdbQueryOperationDef *def = m_operation[i];
+  { const NdbQueryOperationDef *def = m_operations[i];
   }
 ****/
 
-  NdbQueryDef* def = new NdbQueryDefImpl();
+  NdbQueryDefImpl* def = new NdbQueryDefImpl(*this);
   returnErrIf(def==0, 4000);
 
-  // TODO: Copy or handover of below Operand and Operations to NdbQueryDef:
-
-  m_operation.clear();
-  m_paramOperand.clear();
-  m_constOperand.clear();
-  m_linkedOperand.clear();
+  m_operations.clear();
+  m_paramOperands.clear();
+  m_constOperands.clear();
+  m_linkedOperands.clear();
 
   return def;
 }
 
+///////////////////////////////////
+// The (hidden) Impl of NdbQueryDef
+///////////////////////////////////
+NdbQueryDefImpl::NdbQueryDefImpl(const NdbQueryBuilderImpl& builder)
+ : NdbQueryDef(this), 
+   m_operations(builder.m_operations)
+{}
+
+NdbQueryDefImpl::~NdbQueryDefImpl()
+{
+  // Release all NdbQueryOperations
+  for (int i=0; i<m_operations.size(); ++i)
+  { delete &m_operations[i]->getImpl();
+  }
+}
+
+
 
 
 void
-NdbQueryOperationDefImpl::addParent(NdbQueryOperationDefImpl *operation)
+NdbQueryOperationDefImpl::addParent(const NdbQueryOperationDef *opDef)
 {
-  for (int i=0; i<m_parent.size(); ++i)
-  { if (m_parent[i] == operation)
+  for (int i=0; i<m_parents.size(); ++i)
+  { if (m_parents[i] == opDef)
       return;
   }
-  m_parent.push_back(operation);
+  m_parents.push_back(opDef);
 }
 
 void
-NdbQueryOperationDefImpl::addChild(NdbQueryOperationDefImpl *operation)
+NdbQueryOperationDefImpl::addChild(const NdbQueryOperationDef *opDef)
 {
-  for (int i=0; i<m_child.size(); ++i)
-  { if (m_child[i] == operation)
+  for (int i=0; i<m_children.size(); ++i)
+  { if (m_children[i] == opDef)
       return;
   }
-  m_child.push_back(operation);
+  m_children.push_back(opDef);
 }
 
 
 int
 NdbLinkedOperandImpl::bindOperand(
                            const NdbDictionary::Column* column,
-                           NdbQueryOperationDefImpl* operation)
+                           NdbQueryOperationDef* operation)
 {
   NdbDictionary::Column::Type type = column->getType();
   if (type != m_column->getType())
@@ -885,8 +922,8 @@ NdbLinkedOperandImpl::bindOperand(
   // TODO? Check length if Char, and prec,scale if decimal type
 
   // Register parent/child relations
-  this->m_parent->addChild(operation);
-  operation->addParent(this->m_parent);
+  this->m_parent->getImpl().addChild(operation);
+  operation->getImpl().addParent(this->m_parent);
 
   return NdbQueryOperandImpl::bindOperand(column,operation);
 }
@@ -895,7 +932,7 @@ NdbLinkedOperandImpl::bindOperand(
 int
 NdbConstOperandImpl::bindOperand(
                            const NdbDictionary::Column* column,
-                           NdbQueryOperationDefImpl* operation)
+                           NdbQueryOperationDef* operation)
 {
   NdbDictionary::Column::Type type = column->getType();
   if (type != this->getType())
@@ -907,19 +944,13 @@ NdbConstOperandImpl::bindOperand(
 }
 
 
-NdbQueryDefImpl::NdbQueryDefImpl()
-{}
-NdbQueryDefImpl::~NdbQueryDefImpl()
-{
-  // FIXME: Release elements in Vector<>
-}
 
 
 // Instantiate Vector templates
-template class Vector<NdbQueryOperationDefImpl*>;
-template class Vector<NdbParamOperandImpl*>;
-template class Vector<NdbConstOperandImpl*>;
-template class Vector<NdbLinkedOperandImpl*>;
+template class Vector<const NdbQueryOperationDef*>;
+template class Vector<const NdbParamOperand*>;
+template class Vector<const NdbConstOperand*>;
+template class Vector<const NdbLinkedOperand*>;
 
 
 #if 0

=== modified file 'storage/ndb/src/ndbapi/NdbQueryBuilderImpl.hpp'
--- a/storage/ndb/src/ndbapi/NdbQueryBuilderImpl.hpp	2009-06-25 13:38:11 +0000
+++ b/storage/ndb/src/ndbapi/NdbQueryBuilderImpl.hpp	2009-06-26 12:01:17 +0000
@@ -22,16 +22,30 @@
 
 
 #include <Vector.hpp>
+#include "NdbQueryBuilder.hpp"
 
-class NdbQueryOperationDefImpl;
-class NdbParamOperandImpl;
-class NdbConstOperandImpl;
-class NdbLinkedOperandImpl;
+class NdbQueryBuilderImpl;
+
+class NdbQueryDefImpl : public NdbQueryDef
+{
+  friend class NdbQueryDef;
+
+public:
+  NdbQueryDefImpl(const NdbQueryBuilderImpl& builder);
+  ~NdbQueryDefImpl();
+
+private:
+  Vector<const NdbQueryOperationDef*> m_operations;
+//Vector<NdbParamOperand*> m_paramOperand;
+//Vector<NdbConstOperand*> m_constOperand;
+//Vector<NdbLinkedOperand*> m_linkedOperand;
+}; // class NdbQueryDefImpl
 
 
 class NdbQueryBuilderImpl
 {
   friend class NdbQueryBuilder;
+  friend NdbQueryDefImpl::NdbQueryDefImpl(const NdbQueryBuilderImpl& builder);
 
 public:
   ~NdbQueryBuilderImpl();
@@ -50,15 +64,15 @@ private:
   bool hasError() const
   { return (m_error.code!=0); }
 
-  bool contains(const NdbQueryOperationDefImpl*);
+  bool contains(const NdbQueryOperationDef*);
 
   Ndb& m_ndb;
   NdbError m_error;
 
-  Vector<NdbQueryOperationDefImpl*> m_operation;
-  Vector<NdbParamOperandImpl*> m_paramOperand;
-  Vector<NdbConstOperandImpl*> m_constOperand;
-  Vector<NdbLinkedOperandImpl*> m_linkedOperand;
+  Vector<const NdbQueryOperationDef*> m_operations;
+  Vector<const NdbParamOperand*> m_paramOperands;
+  Vector<const NdbConstOperand*> m_constOperands;
+  Vector<const NdbLinkedOperand*> m_linkedOperands;
 
 }; // class NdbQueryBuilderImpl
 

=== modified file 'storage/ndb/src/ndbapi/NdbQueryOperation.cpp'
--- a/storage/ndb/src/ndbapi/NdbQueryOperation.cpp	2009-06-26 09:48:01 +0000
+++ b/storage/ndb/src/ndbapi/NdbQueryOperation.cpp	2009-06-26 12:01:17 +0000
@@ -117,11 +117,6 @@ NdbQueryOperation::buildQueryOperation(N
   return NdbQueryOperationImpl::buildQueryOperation(queryImpl, operation);
 }
 
-NdbQueryOperation* NdbQuery::getRootOperation() const
-{
-  return m_pimpl->getRootOperation();
-}
-
 Uint32
 NdbQueryOperation::getNoOfParentOperations() const
 {
@@ -217,7 +212,7 @@ NdbQueryImpl::NdbQueryImpl(NdbTransactio
   m_id(trans.getNdb()->theImpl->theNdbObjectIdMap.map(this)),
   m_error(),
   m_transaction(trans),
-  m_rootOperation(NULL),
+  m_operations(),
   m_tcKeyConfReceived(false)
 {
   assert(m_id != NdbObjectIdMap::InvalidId);
@@ -229,19 +224,29 @@ NdbQueryImpl::NdbQueryImpl(NdbTransactio
   m_id(trans.getNdb()->theImpl->theNdbObjectIdMap.map(this)),
   m_error(),
   m_transaction(trans),
-  m_rootOperation(NULL),
+  m_operations(),
   m_tcKeyConfReceived(false)
 {
   assert(m_id != NdbObjectIdMap::InvalidId);
 
-  const NdbQueryOperationDef* def = queryDef.getRootOperation();
-  if (def != NULL)
+  for (int i=0; i<queryDef.getNoOfOperations(); ++i)
   {
+    const NdbQueryOperationDef* def = queryDef.getQueryOperation(i);
+    assert(def!=NULL);
+
     NdbQueryOperationImpl* op = new NdbQueryOperationImpl(*this, def);
-    m_rootOperation = op;
 
-    // TODO: Instantiate NdbQueryOperationImpl's for
-    // entire operation three.
+    // Fill in operations parent refs, and append it as child of its parents
+    for (int p=0; p<def->getNoOfParentOperations(); ++p)
+    { 
+      const NdbQueryOperationDef* parent = def->getParentOperation(p);
+      int ix = queryDef.getQueryOperationIx(parent);
+      assert (ix >=0 && ix < i);
+      op->m_parents.push_back(m_operations[ix]);
+      m_operations[ix]->m_children.push_back(op);
+    }
+
+    m_operations.push_back(op);
   }
 }
 
@@ -250,6 +255,10 @@ NdbQueryImpl::~NdbQueryImpl()
   if (m_id != NdbObjectIdMap::InvalidId) {
     m_transaction.getNdb()->theImpl->theNdbObjectIdMap.unmap(m_id, this);
   }
+
+  for (int i=0; i<m_operations.size(); ++i)
+  { delete m_operations[i];
+  }
 }
 
 //static
@@ -265,17 +274,10 @@ NdbQueryImpl::buildQuery(NdbTransaction&
   return new NdbQueryImpl(trans);
 }
 
-
-NdbQueryOperation*
-NdbQueryImpl::getRootOperation() const
-{
-  return m_rootOperation;
-}
-
 Uint32
 NdbQueryImpl::getNoOfOperations() const
 {
-  return 0;  // FIXME
+  return m_operations.size();
 }
 
 NdbQueryOperation*
@@ -287,7 +289,7 @@ NdbQueryImpl::getQueryOperation(const ch
 NdbQueryOperation*
 NdbQueryImpl::getQueryOperation(Uint32 index) const
 {
-  return NULL; // FIXME
+  return m_operations[index];
 }
 
 Uint32
@@ -330,19 +332,19 @@ bool 
 NdbQueryImpl::isComplete(){
   // TODO: generalize for non-tree operation graphs
     return m_tcKeyConfReceived && 
-      m_rootOperation->isComplete();
+      m_operations[0]->isComplete();
 }
 
 void 
 NdbQueryImpl::prepareSend(){
   // TODO: Fix for cases with non-tree graphs.
-  m_rootOperation->prepareSend();
+  m_operations[0]->prepareSend();
 }
 
 void 
 NdbQueryImpl::release(){
   // TODO: Fix for cases with non-tree graphs.
-  m_rootOperation->release();
+  m_operations[0]->release();
 }
 
 ////////////////////////////////////////////////////
@@ -356,6 +358,8 @@ NdbQueryOperationImpl::NdbQueryOperation
   m_magic(MAGIC),
   m_id(queryImpl.getNdbTransaction()->getNdb()->theImpl
        ->theNdbObjectIdMap.map(this)),
+  m_parents(def->getNoOfParentOperations()),
+  m_children(def->getNoOfChildOperations()),
   m_receiver(queryImpl.getNdbTransaction()->getNdb()),
   m_queryImpl(queryImpl),
   m_state(State_Initial),
@@ -375,6 +379,8 @@ NdbQueryOperationImpl::NdbQueryOperation
   m_magic(MAGIC),
   m_id(queryImpl.getNdbTransaction()->getNdb()->theImpl
        ->theNdbObjectIdMap.map(this)),
+  m_parents(),
+  m_children(),
   m_receiver(queryImpl.getNdbTransaction()->getNdb()),
   m_queryImpl(queryImpl),
   m_state(State_Initial),
@@ -396,12 +402,6 @@ NdbQueryOperationImpl::buildQueryOperati
 // END temp code
 //////////////////////////////////////////////////////////
 
-NdbQueryOperation*
-NdbQueryOperationImpl::getRootOperation() const
-{
-  return m_queryImpl.getRootOperation();
-}
-
 Uint32
 NdbQueryOperationImpl::getNoOfParentOperations() const
 {
@@ -462,7 +462,7 @@ NdbQueryOperationImpl::getValue(
   /* This code will only work for the lookup example in test_spj.cpp.
    */
   assert(aValue==NULL);
-  /*if(getQuery().getRootOperation()==this){
+  /*if(getQuery().getQueryOperation(0)==this){
     m_operation->getValue(column);
     }*/
   return m_receiver.getValue(&NdbColumnImpl::getImpl(*column), aValue);

=== modified file 'storage/ndb/src/ndbapi/NdbQueryOperationImpl.hpp'
--- a/storage/ndb/src/ndbapi/NdbQueryOperationImpl.hpp	2009-06-26 09:48:01 +0000
+++ b/storage/ndb/src/ndbapi/NdbQueryOperationImpl.hpp	2009-06-26 12:01:17 +0000
@@ -23,8 +23,9 @@
 #include "NdbQueryBuilder.hpp"
 #include "NdbImpl.hpp"
 #include "NdbError.hpp"
-#include <ObjectMap.hpp>
 #include "NdbTransaction.hpp"
+#include <ObjectMap.hpp>
+#include <Vector.hpp>
 #include <NdbOut.hpp>
 
 class NdbQueryImpl : public NdbQuery {
@@ -51,14 +52,12 @@ public:
   /** Set an NdbQueryOperation to be the root of a linked operation */
   // LATER: root and *all* NdbQueryOperations will be constructed 
   // together with NdbQuery itself in :.buildQuery()
-  void setRootOperation(NdbQueryOperation* root) {
-    m_rootOperation = &root->getImpl();};
+  void addQueryOperation(NdbQueryOperation* op) {
+    m_operations.push_back(&op->getImpl());
+  }
   //// END: TEMP hacks
   //////////////////////////////////////////////////
   
-  // get NdbQueryOperation being the root of a linked operation
-  NdbQueryOperation* getRootOperation() const;
-
   Uint32 getNoOfOperations() const;
 
   // Get a specific NdbQueryOperation by ident specified
@@ -102,7 +101,7 @@ private:
   const Uint32 m_id;
   NdbError m_error;
   NdbTransaction& m_transaction;
-  NdbQueryOperationImpl* m_rootOperation;
+  Vector<NdbQueryOperationImpl*> m_operations;
   bool m_tcKeyConfReceived; 
   /** Each operation should yiedl either a TCKEYCONF or a TCKEYREF message.
    This is the no of such messages pending.*/
@@ -127,8 +126,6 @@ public:
   STATIC_CONST (MAGIC = 0xfade1234);
 
 
-  NdbQueryOperation* getRootOperation() const;
-
   Uint32 getNoOfParentOperations() const;
   NdbQueryOperation* getParentOperation(Uint32 i) const;
 
@@ -243,11 +240,10 @@ private:
 				 const NdbQueryOperationDef* def);
   explicit NdbQueryOperationImpl(NdbQueryImpl& queryImpl, 
 				 NdbOperation& operation);
-
   ~NdbQueryOperationImpl(){
     if (m_id != NdbObjectIdMap::InvalidId) {
       m_queryImpl.getNdbTransaction()->getNdb()->theImpl
-	->theNdbObjectIdMap.unmap(m_id, this);
+       ->theNdbObjectIdMap.unmap(m_id, this);
     }
   }
 


Attachment: [text/bzr-bundle] bzr/ole.john.aske@sun.com-20090626120117-mtmk7e7m2vawvj7v.bundle
Thread
bzr push into mysql-5.1-telco-7.0-spj branch (ole.john.aske:2901 to 2902) Ole John Aske26 Jun