xref: /AOO41X/main/connectivity/source/inc/file/fcomp.hxx (revision caf5cd79edad04a48dcaf209068b3b89eae4622e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _CONNECTIVITY_FILE_FCOMP_HXX_
24 #define _CONNECTIVITY_FILE_FCOMP_HXX_
25 
26 #include "file/fcode.hxx"
27 #include "file/filedllapi.hxx"
28 #ifndef _LIST_
29 #include <list>
30 #endif
31 
32 namespace connectivity
33 {
34     class OSQLParseNode;
35     namespace file
36     {
37         class OCode;
38         class OOperand;
39         class OSQLAnalyzer;
40         typedef::std::vector<OCode*> OCodeList;
41 
42         class OPredicateCompiler : public ::vos::OReference
43         {
44             friend class OPredicateInterpreter;
45             friend class OSQLAnalyzer;
46 
47             OCodeList                               m_aCodeList;
48             OFileColumns                            m_orgColumns; // in filecurs this are the filecolumns
49             OSQLAnalyzer*                           m_pAnalyzer;
50             ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> m_xIndexes;
51             sal_Int32                               m_nParamCounter;
52             sal_Bool                                m_bORCondition;
53         public:
54             OPredicateCompiler(OSQLAnalyzer* pAnalyzer);
55 
56             virtual ~OPredicateCompiler();
57 
operator new(size_t nSize)58             inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () )
59                 { return ::rtl_allocateMemory( nSize ); }
operator new(size_t,void * _pHint)60             inline static void * SAL_CALL operator new( size_t /*nSize*/,void* _pHint ) SAL_THROW( () )
61                 { return _pHint; }
operator delete(void * pMem)62             inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () )
63                 { ::rtl_freeMemory( pMem ); }
operator delete(void *,void *)64             inline static void SAL_CALL operator delete( void * /*pMem*/,void* /*_pHint*/ ) SAL_THROW( () )
65                 {  }
66             void dispose();
67 
68             void start(connectivity::OSQLParseNode* pSQLParseNode);
69             OOperand* execute(connectivity::OSQLParseNode* pPredicateNode);
70 
71             void Clean();
isClean() const72             sal_Bool isClean() const {return m_aCodeList.empty();}
hasCode() const73             sal_Bool hasCode() const {return !isClean();}
hasORCondition() const74             sal_Bool hasORCondition() const {return m_bORCondition;}
setOrigColumns(const OFileColumns & rCols)75             void     setOrigColumns(const OFileColumns& rCols) { m_orgColumns = rCols; }
getOrigColumns() const76             const OFileColumns getOrigColumns() const { return m_orgColumns; }
77         protected:
78             OOperand* execute_COMPARE(connectivity::OSQLParseNode* pPredicateNode) throw( ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
79             OOperand* execute_LIKE(connectivity::OSQLParseNode* pPredicateNode) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
80             OOperand* execute_BETWEEN(connectivity::OSQLParseNode* pPredicateNode) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
81             OOperand* execute_ISNULL(connectivity::OSQLParseNode* pPredicateNode) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
82             OOperand* execute_Operand(connectivity::OSQLParseNode* pPredicateNode) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
83             OOperand* execute_Fold(OSQLParseNode* pPredicateNode) throw( ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
84             OOperand* executeFunction(OSQLParseNode* pPredicateNode) throw( ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
85         };
86 
87 
88         class OPredicateInterpreter :
89             public ::vos::OReference
90         {
91             OCodeStack          m_aStack;
92             ::vos::ORef<OPredicateCompiler> m_rCompiler;
93 
94         public:
OPredicateInterpreter(const::vos::ORef<OPredicateCompiler> & rComp)95             OPredicateInterpreter(const ::vos::ORef<OPredicateCompiler>& rComp) : m_rCompiler(rComp){}
96             virtual ~OPredicateInterpreter();
97 
98             sal_Bool    evaluate(OCodeList& rCodeList);
99             void        evaluateSelection(OCodeList& rCodeList,ORowSetValueDecoratorRef& _rVal);
100 
start()101             inline sal_Bool start()
102             {
103                 return evaluate(m_rCompiler->m_aCodeList);
104             }
105 
startSelection(ORowSetValueDecoratorRef & _rVal)106             inline void startSelection(ORowSetValueDecoratorRef& _rVal)
107             {
108                 evaluateSelection(m_rCompiler->m_aCodeList,_rVal);
109             }
110 
111 
112         };
113     }
114 }
115 #endif // _CONNECTIVITY_FILE_FCOMP_HXX_
116 
117