Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

dbobjsetstreamer.cpp

Go to the documentation of this file.
00001 //============================================================================= 
00002 //
00003 // XDFLengine library
00004 //
00005 //----------------------------------------------------------------------------- 
00006 //  DBOBJSETREQUEST.CPP
00007 //----------------------------------------------------------------------------- 
00013 //_____________________________________________________________________________
00014 //
00015 //  Copyright (C) 2003 Guillaume Baurand. All Rights Reserved.
00016 //
00017 //  This file is part of the XDFLengine project.
00018 //
00019 //  The XDFLengine is free software; you can redistribute it and/or modify
00020 //  it under the terms of the GNU General Public License as published by
00021 //  the Free Software Foundation; either version 2 of the License, or
00022 //  (at your option) any later version.
00023 //
00024 //  This program is distributed in the hope that it will be useful,
00025 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00026 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00027 //  GNU General Public License for more details.
00028 //
00029 //  You should have received a copy of the GNU General Public License
00030 //  along with this program; if not, write to the Free Software
00031 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
00032 //  USA.
00033 //
00034 //  For more information, 
00035 //      contact  : guillaume@baurand.net 
00036 //      or visit : http://xdflengine.sourceforge.net
00037 //
00038 //=============================================================================
00039 
00040 #   include "flow/consumers/streamsax2parser.hpp"
00041 #   include "processor/xmlflowcontext.hpp"
00042 #   include "dbobjsetstreamer.hpp"
00043 #   include "valuers/sqldbvaluer.hpp"
00044 
00045 
00046 BEGIN_XDFLENGINE_NS
00047 
00048 //============================================================================= 
00049 //  CLASS DBOBJSETREQUEST
00050 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00051 
00052 // CONSTRUCTOR AND DESTRUCTOR
00053 
00054     //_____________________________________________________________________
00055     //  DBOBJSetStreamer
00056     //---------------------------------------------------------------------
00057     DBOBJSetStreamer::DBOBJSetStreamer( const XMLStreamerFactory* p_pParent, StreamerParams* p_pParameters, XMLFlowContext* p_pContext, XMLStreamConsumer* p_pOutput)
00058     :XMLStreamer( p_pParent, p_pParameters, p_pContext, p_pOutput)
00059     {
00060         m_pStreamParser=0;
00061         m_pHandler=0;
00062         m_pErrorReporter=0;
00063         m_pszAction=0;
00064         m_pszConnName=0;
00065         m_pDBOBJOwnedDefinitionRoot = 0;
00066         m_pContext = p_pContext;
00067         DEBUG_CREATE(DBOBJSetStreamer)
00068     }
00069     
00070     //_____________________________________________________________________
00071     //  ~DBOBJSetStreamer
00072     //---------------------------------------------------------------------     
00073     DBOBJSetStreamer::~DBOBJSetStreamer()
00074     {   
00075         stream_cache*   l_pStreamCache;
00076 
00077         DEBUG_ECHO  << "deleting stacked objects\n";
00078         while( !m_vaObjects.empty()) delete m_vaObjects.pop();
00079 
00080         DEBUG_ECHO  << "deleting cached streams\n";
00081         while (!m_vaOTLStreams.empty())
00082         {
00083             l_pStreamCache = m_vaOTLStreams.pop();
00084             l_pStreamCache->varDesc->~otl_var_desc();
00085             OTL_releaseDataStream( l_pStreamCache->otlStream);          
00086             releaseCharBuffer( l_pStreamCache->fieldList);
00087             delete l_pStreamCache;
00088         }
00089 
00090         DEBUG_ECHO  << "release connection\n";
00091         if(m_pConnection) ((DBStreamerFactory*) m_pParent)->releaseConnection(m_pszConnName, m_pContext->getThreadId());
00092 
00093 
00094         DEBUG_ECHO  << "release strings\n";
00095         m_pszAction = releaseCharBuffer( m_pszAction);
00096         m_pszConnName = releaseCharBuffer( m_pszConnName);
00097 
00098         DEBUG_ECHO  << "release nodes count\n";
00099         while(! m_vaNodesCounts.empty() ) m_vaNodesCounts.pop();
00100 
00101         DEBUG_ECHO  << "delete definition\n";
00102         delete m_pDBOBJOwnedDefinitionRoot;     
00103 
00104         DEBUG_ECHO  << "delete parser\n";
00105         delete m_pStreamParser;
00106 
00107         DEBUG_ECHO  << "delete handler\n";
00108         delete m_pHandler;
00109         
00110         DEBUG_ECHO  << "delete error reporter\n";
00111         delete m_pErrorReporter;
00112 
00113         DEBUG_DEL(DBOBJSetStreamer)
00114     }
00115 // STREAM   
00116 
00117     //_____________________________________________________________________
00118     //  INITSTREAM
00119     //---------------------------------------------------------------------
00120     bool DBOBJSetStreamer::initStream()
00121     {
00122         //-----------------------------------------------------------------
00123         const char*                     l_pszDefinitionName=0;
00124         const char*                     l_pszBufferName;
00125         //-----------------------------------------------------------------
00126 
00127         DEBUG_IN(DBOBJSetStreamer::initStream)
00128 
00129         m_uiCommitted=0;
00130         m_uiCommittedRecs=0;
00131         m_uiToStream=0;
00132         m_fError=false;
00133 
00134         // get action
00135         m_pszAction = importCharBuffer(0, getParamValue( m_pParameters, DBOBJSETSTREAMER_ACTION, DBOBJSETSTREAMER_ACTION_DEF)); 
00136         m_intAction = DBOBJaction_None;
00137         if( strcmp( m_pszAction ,DBOBJECTNODE_ACTIONINSERT) == 0 ) m_intAction = DBOBJaction_Insert;
00138         if( strcmp( m_pszAction ,DBOBJECTNODE_ACTIONUPDATE) == 0 ) m_intAction = DBOBJaction_Update;
00139         if( strcmp( m_pszAction ,DBOBJECTNODE_ACTIONDELETE) == 0 ) m_intAction = DBOBJaction_Delete;
00140 
00141         // get paramjeters
00142         // buffer size
00143         m_uiBufferSize = atoi( XMLStreamer::getParamValue( m_pParameters, DBOBJSETSTREAMER_OTL_BUFFER, DBOBJSETSTREAMER_OTL_BUFFER_DEF) );
00144         
00145         // commitpack
00146         m_uiCommitPacks = atoi( XMLStreamer::getParamValue( m_pParameters, DBOBJSETSTREAMER_COMMITPACKS, DBOBJSETSTREAMER_COMMITPACKS_DEF) );
00147         
00148         //db error fatal
00149         m_fErrorFatal=false;
00150         if ( strcmp( XMLStreamer::getParamValue( m_pParameters, DBOBJSETSTREAMER_ERRFATAL, DBOBJSETSTREAMER_ERRFATAL_DEF) , REQ_TRUE) == 0 ) m_fErrorFatal=true;
00151     
00152         // count
00153         m_fCount=false;
00154         if ( strcmp( XMLStreamer::getParamValue( m_pParameters, DBOBJSETSTREAMER_COUNT, DBOBJSETSTREAMER_COUNT_DEF) , REQ_TRUE) == 0 ) m_fCount=true;
00155 
00156         m_uiStreamObjects= atoi( XMLStreamer::getParamValue( m_pParameters, DBOBJSETSTREAMER_STREAMOBJECTS, DBOBJSETSTREAMER_STREAMOBJECTS_DEF));
00157 
00158 
00159         // enclose tag
00160         m_pszEnclose = XMLStreamer::getParamValue(m_pParameters, REQ_ENCLOSE,"");
00161 
00162         // get outputs
00163 
00164         // db errors output
00165         m_pBufferError = 0;
00166         l_pszBufferName = XMLStreamer::getParamValue( m_pParameters, DBOBJSETSTREAMER_OUTPUTDBERROR, DBOBJSETSTREAMER_OUTPUTDBERROR_DEF);
00167         if( strcmp( l_pszBufferName, REQ_PARENTOUTPUT) == 0) m_pBufferError = m_pOutput;
00168         if( !m_pBufferError ) m_pBufferError = m_pContext->getNamedBuffer( l_pszBufferName);
00169         
00170         // rejected objects output
00171         m_pBufferReject = 0;
00172         l_pszBufferName = XMLStreamer::getParamValue( m_pParameters, DBOBJSETSTREAMER_OUTPUTREJECT, DBOBJSETSTREAMER_OUTPUTREJECT_DEF);
00173         if( strcmp( l_pszBufferName, REQ_PARENTOUTPUT) == 0) m_pBufferReject = m_pOutput;
00174         if( !m_pBufferReject ) m_pBufferReject = m_pContext->getNamedBuffer( l_pszBufferName);
00175 
00176         // report output
00177         m_pBufferReport = 0;
00178         l_pszBufferName = XMLStreamer::getParamValue( m_pParameters, DBOBJSETSTREAMER_OUTPUTREPORT, DBOBJSETSTREAMER_OUTPUTREPORT_DEF);
00179         if( strcmp( l_pszBufferName, REQ_PARENTOUTPUT) == 0) m_pBufferReport = m_pOutput;
00180         if( !m_pBufferReport ) m_pBufferReport = m_pContext->getNamedBuffer( l_pszBufferName);
00181 
00182         // get definition
00183         l_pszDefinitionName = XMLStreamer::getParamValue(m_pParameters, DBOBJSETSTREAMER_TARGET);
00184         m_pDBOBJDefinitionRoot = ((DBOBJStreamerFactory*) m_pParent) -> getCachedDefinition( l_pszDefinitionName, m_pContext);
00185         if(!m_pDBOBJDefinitionRoot)
00186         {
00187             m_pDBOBJOwnedDefinitionRoot = ((DBOBJStreamerFactory*) m_pParent) -> buildDefinition( l_pszDefinitionName, m_pContext);
00188             m_pDBOBJDefinitionRoot = m_pDBOBJOwnedDefinitionRoot;
00189         }
00190 
00191         // get connection   
00192         m_pszConnName = importCharBuffer(0, getParamValue(m_pParameters, DBOBJSETSTREAMER_CONNECTION));
00193         m_pConnection = ((DBStreamerFactory*) m_pParent)->getConnection(m_pszConnName, m_pContext->getThreadId()  );
00194 
00195         // init parser
00196         m_pHandler = new DBObjectSAXBuilder(m_pContext, m_pDBOBJDefinitionRoot, m_intAction);
00197         m_pErrorReporter = new XDFLSaxErrorReporter("DBOBJSetStreamer");
00198         m_pStreamParser = new StreamSAX2Parser( m_pHandler, m_pErrorReporter);
00199 
00200         if( (strlen(m_pszEnclose)>0) && (m_pBufferReject) && (m_pBufferReject!=m_pOutput) ) (*m_pBufferReject) << "<" << m_pszEnclose << ">\n";
00201         
00202         DEBUG_OUT(DBOBJSetStreamer::initStream)
00203 
00204         return true;
00205     }
00206 
00207     //_____________________________________________________________________
00208     //  WRITEDATA
00209     //---------------------------------------------------------------------
00210     void DBOBJSetStreamer::writeData( const char*   p_pszData, unsigned int p_uiDataLen)
00211     {
00212         DEBUG_IN(DBOBJSetStreamer::writeData)
00213         
00214         m_pStreamParser -> writeData( p_pszData, p_uiDataLen);
00215 
00216 
00217         DEBUG_OUT(DBOBJSetStreamer::writeData)
00218     }
00219 
00220     //_____________________________________________________________________
00221     //  COMMITSTREAM
00222     //---------------------------------------------------------------------
00223     bool DBOBJSetStreamer::commitStream(bool p_fFinal)
00224     {
00225         bool m_fOK;
00226         DBObjectNode* l_pDBObjectRoot;
00227 
00228         PREP_CATCH_XML_FLOW_ERROR;
00229 
00230         DEBUG_IN(DBOBJSetStreamer::commitStream)
00231 
00232         logout << "\t" << DBOBJSETSTREAMER_TAGNAME << "   :   " << "build objects";
00233         m_fOK = m_pStreamParser -> commitStream( p_fFinal);
00234         logout << "ok\n";
00235 
00236         if( m_pHandler->getObjectsCount()>0)
00237         {
00238             logout << "\t" << DBOBJSETSTREAMER_TAGNAME << "   :   " << m_pszAction << " " << m_pHandler->getObjectsCount() << " objects.\n";
00239             
00240             while( m_pHandler->getObjectsCount() > 0)
00241             {
00242                 l_pDBObjectRoot = m_pHandler->popObject();
00243                 WATCH_XML_FLOW_ERROR {
00244                     processObject(l_pDBObjectRoot );
00245                     l_pDBObjectRoot = 0;
00246                 }
00247                 CATCH_XML_FLOW_ERROR_RELEASE_AND_RETURN;    
00248             }
00249         }
00250 
00251         if( p_fFinal)
00252         {
00253             WATCH_XML_FLOW_ERROR {
00254                 commitObjects();
00255             } CATCH_XML_FLOW_ERROR_RELEASE_AND_RETURN;
00256             if( (strlen(m_pszEnclose)>0) && (m_pBufferReject) && (m_pBufferReject!=m_pOutput)) (*m_pBufferReject) << "</" << m_pszEnclose << ">\n";
00257             makeReport();
00258             if( m_pBufferReject ) m_pBufferReject->commitStream(true);
00259             if( m_pBufferReport ) m_pBufferReport->commitStream(true);
00260             if( m_pBufferError )  m_pBufferError->commitStream(true);
00261             
00262         }               
00263 
00264     RELEASE_AND_RETURN:
00265 
00266         DEBUG_OUT(DBOBJSetStreamer::commitStream)
00267         //ON_XML_FLOW_ERROR_DO delete l_pDBObjectRoot;
00268         ON_XML_FLOW_ERROR_THROW;
00269         return m_fOK;
00270 
00271         
00272     }
00273 
00274 // VIRTUALS
00275 
00276 
00277     //_____________________________________________________________________
00278     //  makeReport
00279     //---------------------------------------------------------------------
00281     //_____________________________________________________________________     
00282     void DBOBJSetStreamer::makeReport()
00283     {
00284         const char*         l_pszObjectName = 0;
00285         unsigned int    l_uiCount;
00286         unsigned int    l_uiSize;
00287         unsigned int    i;
00288         char            l_cCount[20];
00289 
00290         if( m_pBufferReport)
00291         {
00292 
00293             (*m_pBufferReport) << "<REPORT>\n";
00294 
00295             // Report error as a named value DB_SET_ERROR
00296             if(m_fError) (*m_pBufferReport) << "\t<ERROR>1</ERROR>\n";
00297             else (*m_pBufferReport) << "\t<ERROR>0</ERROR>\n";
00298 
00299             if(m_fCount)
00300             {
00301                 (*m_pBufferReport) << "\t<ACTIONS>\n";
00302                 l_uiSize = m_vaNodesCounts.size();
00303                 for(i=0 ; i<l_uiSize;i++)
00304                 {
00305                     l_pszObjectName = m_vaNodesCounts.getKey((unsigned int)0);
00306                     l_uiCount = m_vaNodesCounts.get((unsigned int)0);
00307 
00308                     sprintf((char*) &l_cCount,"%d",l_uiCount);
00309                     (*m_pBufferReport) << "\t\t<" << l_pszObjectName << ">" << " " << (char*) &l_cCount << " " << "</" << l_pszObjectName << ">\n";
00310 
00311                     m_vaNodesCounts.remove((unsigned int) 0);
00312                 }           
00313                 (*m_pBufferReport) << "\t</ACTIONS>\n";
00314             }
00315             (*m_pBufferReport) << "</REPORT>\n";
00316         }
00317     }
00318 
00319 
00320 
00321 
00322     // OBJECTS PROCESSING
00323 
00324     //_________________________________________________________________________
00325     //  PROCESSOBJECT
00326     //-------------------------------------------------------------------------
00327     void DBOBJSetStreamer::processObject( DBObjectNode* p_pDBObjectNode)
00328     {
00329         bool l_fError;
00330         DEBUG_FUNC(DBOBJSetStreamer::buildSQL)
00331         PREP_CATCH_XML_FLOW_ERROR;  
00332 
00333         if( transformObject( p_pDBObjectNode))
00334         {
00335             // configure valuation
00336             ( (SQLDBValuer*) m_pContext->getValuer( SQLVALUER_TAG))->setConnection( m_pConnection);
00337             p_pDBObjectNode->setValuable(m_pContext);
00338             stackObject( p_pDBObjectNode);
00339 
00340             l_fError=false;
00341             WATCH_XML_FLOW_ERROR
00342             { 
00343                 processNode( p_pDBObjectNode, m_intAction);
00344             }
00345             CATCH_XML_FLOW_ERROR
00346             {
00347                 l_pXMLFlowException = e_pXMLFlowException;
00348                 l_fError=true;  
00349             }
00350 
00351             p_pDBObjectNode=0;
00352             ( (SQLDBValuer*) m_pContext->getValuer( SQLVALUER_TAG))->setConnection( 0);
00353 
00354             if(! l_fError)
00355             {
00356                 m_uiCommitted++;
00357                 if( m_uiCommitted >= m_uiCommitPacks) 
00358                 {
00359                     commitObjects();
00360                 }   
00361             }
00362             else
00363             {
00364                 m_fError=true;
00365                 if(m_pBufferError) (*l_pXMLFlowException) >> (*m_pBufferError);
00366                 rollBackObjects();
00367                 if( m_fErrorFatal) throw l_pXMLFlowException;
00368                 else delete l_pXMLFlowException;
00369             }
00370         }
00371         else
00372         {
00373             delete p_pDBObjectNode;
00374         }
00375 
00376     }
00377 
00378 
00379     //_________________________________________________________________________
00380     //  TRANSFORMOBJECT
00381     //-------------------------------------------------------------------------
00382     bool DBOBJSetStreamer::transformObject( DBObjectNode* p_pDBObjectNode)
00383     {
00384         DEBUG_FUNC(DBOBJSetStreamer::transformObject)
00385 
00386         return true;
00387     }
00388 
00389     //_________________________________________________________________________
00390     //  commitObjects
00391     //-------------------------------------------------------------------------
00392     void DBOBJSetStreamer::commitObjects()
00393     {
00394 
00395         DEBUG_IN(DBOBJSetStreamer::commitObject)
00396 
00397         if(m_uiCommittedRecs>0)
00398         {
00399 
00400             logout << "\t" << DBOBJSETSTREAMER_TAGNAME << "   :   " << "commit " << m_vaObjects.size() << " objects (" << m_uiCommittedRecs << " records ).\n";
00401             try
00402             {
00403                 m_pConnection->commit();
00404             }
00405             catch(otl_exception& p)
00406             { 
00407                 rollBackObjects();
00408                 p.~otl_tmpl_exception();
00409                 THROW_XMLFLOW_EXCEPTION ( ERRCODE_LOC_DBOBJSETREQUEST + ERRCODE_CAUSE_DATAACCESS , (char*)(&(p.msg)) , "", "DBOBJSetStreamer::executeSQL", "", false);
00410             }
00411             m_uiCommittedRecs=0;
00412             m_uiCommitted=0;
00413         }
00414         deStackObjects(m_pOutput,m_fCount);
00415 
00416         DEBUG_OUT(DBOBJSetStreamer::commitObject)
00417     }
00418 
00419     //_________________________________________________________________________
00420     //  rollBackObjects
00421     //-------------------------------------------------------------------------
00422     void DBOBJSetStreamer::rollBackObjects()
00423     {
00424         if(m_uiCommittedRecs>0)
00425         {
00426             logout << "\t" << DBOBJSETSTREAMER_TAGNAME << "   :   " << "rollback " << m_vaObjects.size() << " objects (" << m_uiCommittedRecs << " records ).\n";
00427             m_uiCommittedRecs=0;
00428             m_uiCommitted=0;
00429             m_pConnection->rollback();
00430         }
00431         deStackObjects(m_pBufferReject,false);
00432     }
00433 
00434 
00435     // NODES PROCESSING
00436 
00437 
00438     //_________________________________________________________________________
00439     //  PROCESSNODE
00440     //-------------------------------------------------------------------------
00441     void DBOBJSetStreamer::processNode(   DBObjectNode* p_pDBObjectNode, DBOBJSetAction p_intParentAction)
00442     {
00443         //---------------------------------------------------------------------
00444         const DBOBJDefinitionNode*  l_pSAXDB_DefNode=0;
00445         DBOBJSetAction          l_iCurAction;
00446         DBObjectNode*           l_pChildNode;
00447         //---------------------------------------------------------------------
00448         
00449         DEBUG_IN(DBOBJSetStreamer::processNode)
00450 
00451         l_pSAXDB_DefNode = p_pDBObjectNode->getDefinition();
00452         if( !l_pSAXDB_DefNode->isLocked() )
00453         {
00454             l_iCurAction=p_pDBObjectNode->getAction();
00455             if( l_iCurAction != DBOBJaction_None)
00456             {
00457                 // process check pre statement
00458                 sendNodeToDB( p_pDBObjectNode, DBOBJaction_CheckPre);
00459 
00460                 // process node ( forward parse for insert & update )
00461                 if( l_iCurAction != DBOBJaction_Delete)     sendNodeToDB( p_pDBObjectNode, l_iCurAction);
00462                 
00463                 //recurse
00464                 if( l_iCurAction != DBOBJaction_Delete)     p_pDBObjectNode->moveFirstChild();
00465                 else                                        p_pDBObjectNode->moveLastChild();
00466 
00467                 l_pChildNode = p_pDBObjectNode->getCurrentChild();
00468                 while( l_pChildNode)
00469                 {
00470                     processNode( l_pChildNode, l_iCurAction);
00471 
00472                     if( l_iCurAction != DBOBJaction_Delete) p_pDBObjectNode->moveNextChild();
00473                     else                                    p_pDBObjectNode->movePreviousChild();
00474 
00475                     l_pChildNode = p_pDBObjectNode->getCurrentChild();
00476                 }
00477 
00478                 // process node (backward parse for delete)
00479                 if( l_iCurAction == DBOBJaction_Delete)     sendNodeToDB( p_pDBObjectNode, l_iCurAction);
00480 
00481                 // process checkpost statement
00482                 sendNodeToDB( p_pDBObjectNode, DBOBJaction_CheckPost);
00483             }
00484         }
00485         
00486         DEBUG_OUT(DBOBJSetStreamer::processNode)
00487     }
00488 
00489 
00490     //_________________________________________________________________________
00491     //  SENDNODETODB
00492     //-------------------------------------------------------------------------
00493     void DBOBJSetStreamer::sendNodeToDB( DBObjectNode* p_pDBObjectNode, DBOBJSetAction  l_iCurAction)
00494     {
00495         //---------------------------------------------------------------------
00496         char*           l_pszStreamName=0;
00497         char            l_szAction[10];
00498         char*           l_pszStatement=0;
00499         char*           l_pszFieldList=0;
00500         char*           l_pszFieldName=0;
00501 
00502         int             l_iDescLen;
00503         bool            l_fCachable;
00504         
00505         stream_cache*   l_pStreamCache=0;
00506         otl_stream*     l_potlStream=0;
00507         otl_var_desc*   l_varsDesc=0;
00508 
00509         bool            l_fDelStatementObjects;
00510         //---------------------------------------------------------------------
00511 
00512         DEBUG_IN(DBOBJSetStreamer::sendNodeToDB)
00513         PREP_CATCH_XML_FLOW_ERROR;
00514 
00515         // TRAITEMENT DES CHECK_PRE ET CHECK_POST ! 
00516         
00517 
00518         l_pszStreamName = copyCharBuffer( p_pDBObjectNode->getName());
00519         sprintf( (char*) &l_szAction,"_%d", l_iCurAction);
00520         l_pszStreamName = concatCharBuffer( l_pszStreamName, l_szAction);
00521 
00522         // check stream cheche for cacheed stream
00523         l_pStreamCache = m_vaOTLStreams.get( l_pszStreamName);  
00524 
00525         l_fDelStatementObjects = true;
00526 
00527         if( !l_pStreamCache)
00528         {
00529             //build action statement
00530             switch(l_iCurAction)
00531             {
00532             case DBOBJaction_CheckPre:
00533                     l_fCachable = buildCHECKStatement( p_pDBObjectNode, &l_pszStatement, &l_pszFieldList, true);
00534                     break;
00535             case DBOBJaction_CheckPost:
00536                     l_fCachable = buildCHECKStatement( p_pDBObjectNode, &l_pszStatement, &l_pszFieldList, false);
00537                     break;
00538             case DBOBJaction_Insert:
00539                     l_fCachable = buildINSERTStatement( p_pDBObjectNode, &l_pszStatement, &l_pszFieldList);
00540                     break;
00541             case DBOBJaction_Update:
00542                     l_fCachable = buildUPDATEStatement( p_pDBObjectNode, &l_pszStatement, &l_pszFieldList);
00543                     break;
00544             case DBOBJaction_Delete:
00545                     l_fCachable = buildDELETEStatement( p_pDBObjectNode, &l_pszStatement, &l_pszFieldList);
00546                     break;
00547             }
00548 
00549             if(l_pszStatement) 
00550             {
00551 
00552                 try
00553                 {   
00554                     if(l_pszStatement) logout << "\nSQL:" << l_pszStatement << "\n";                
00555                     l_potlStream   = OTL_openDataStream( l_pszStatement, m_pConnection, m_uiBufferSize);
00556                 }
00557                 catch(otl_exception& p)
00558                 { // intercept OTL exceptions
00559                     if(l_pszStatement) logout << "\nSQL:" << l_pszStatement << "\n";
00560                     char* msg=copyCharBuffer( (char*)(&(p.msg)));
00561                     msg=concatCharBuffer( msg," - ");
00562                     msg=concatCharBuffer( msg, l_pszStatement);
00563                     MAKE_XMLFLOW_EXCEPTION( ERRCODE_LOC_DBOBJSETREQUEST + ERRCODE_CAUSE_DATAACCESS , "Error while opening data stream. ", msg, "SAXSQLHandler::openDataStream", "", false);
00564                     p.~otl_tmpl_exception();
00565                     l_potlStream = 0;
00566                     l_fCachable = false;
00567                     goto RELEASE_AND_RETURN;
00568                 }
00569 
00570                 l_pszStatement = releaseCharBuffer( l_pszStatement);
00571                 l_varsDesc = l_potlStream->describe_in_vars(l_iDescLen);
00572             }
00573             else
00574             {
00575                 l_potlStream = 0;
00576                 l_varsDesc = 0;
00577                 l_iDescLen = 0;
00578                 l_pszFieldList = 0;
00579             }
00580 
00581             // stream is cacheable : cache it !
00582             if(l_fCachable)
00583             {
00584                 l_pStreamCache = new stream_cache;
00585                 l_pStreamCache->otlStream = l_potlStream;
00586                 l_pStreamCache->varDesc = l_varsDesc;
00587                 l_pStreamCache->descLen = l_iDescLen;
00588                 l_pStreamCache->fieldList = l_pszFieldList;
00589                 m_vaOTLStreams.add( l_pStreamCache, l_pszStreamName);
00590                 l_fDelStatementObjects=false;
00591             }
00592         }
00593         else
00594         {
00595             // get objects from cached stream
00596             l_fCachable = true;
00597             l_potlStream = l_pStreamCache->otlStream;
00598             l_varsDesc = l_pStreamCache->varDesc;
00599             l_iDescLen = l_pStreamCache->descLen;
00600             l_pszFieldList = l_pStreamCache->fieldList;
00601             l_fDelStatementObjects=false;
00602         }
00603 
00604     
00605         WATCH_XML_FLOW_ERROR
00606         { 
00607             if(l_potlStream) sendRecordToDB( p_pDBObjectNode, l_potlStream, l_pszFieldList, l_iDescLen, l_varsDesc);
00608         }
00609         CATCH_XML_FLOW_ERROR_RELEASE_AND_RETURN;
00610 
00611         // if not cached, objects are to be released
00612 
00613 RELEASE_AND_RETURN:
00614 
00615         if( l_fDelStatementObjects ) 
00616         {
00617             OTL_releaseDataStream( l_potlStream);
00618             if(l_varsDesc) l_varsDesc->~otl_var_desc();
00619             l_pszFieldList = releaseCharBuffer( l_pszFieldList);
00620         }
00621         l_pszStreamName = releaseCharBuffer( l_pszStreamName);
00622 
00623         DEBUG_OUT(DBOBJSetStreamer::sendNodeToDB)
00624 
00625         ON_XML_FLOW_ERROR_THROW;
00626     }
00627 
00628     //_________________________________________________________________________
00629     //  SENDRECORDTODB
00630     //-------------------------------------------------------------------------
00631     void DBOBJSetStreamer::sendRecordToDB( DBObjectNode* p_pDBObjectNode, otl_stream* p_pOTLStream, const char* p_pszFieldList, int p_iDescLen, otl_var_desc*   p_varsDesc)
00632     {
00633         //---------------------------------------------------------------------
00634         char*   l_pszTmp2=0;
00635         char*   l_pszTmp=0;
00636         char*   l_pszFieldName=0;
00637         const char* l_pszValue=0;
00638         int i;
00639         DBObjectField*  l_pObjectField=0;
00640         bool            l_fFlush;
00641         bool            l_fdbError;
00642         char*           l_pszdbErrorMsg;
00643         //-------------------------------------------------------------------------
00644 
00645         PREP_CATCH_XML_FLOW_ERROR;
00646 
00647         DEBUG_IN(DBOBJSetStreamer::sendRecordToDB)      
00648 
00649         // walk fields list to populate stream in vars
00650 
00651         l_fFlush=false;
00652         l_fdbError=false;
00653         m_uiCommittedRecs++;
00654 
00655         if(( p_iDescLen>0 ) && (p_pszFieldList!=0))
00656         {
00657             l_pszTmp2 = copyCharBuffer( p_pszFieldList);
00658             l_pszFieldName = l_pszTmp2;
00659             for(i=0; i<p_iDescLen; i++)
00660             {
00661                 l_pszTmp = strchr( l_pszFieldName,',');
00662                 if( l_pszTmp )  l_pszTmp[0] = '\0';                         
00663                 if( strlen(l_pszFieldName)>0) 
00664                 {
00665                     l_pszValue = 0;
00666                     if( l_pszFieldName[0]=='#')
00667                     {
00668                         l_pszValue=l_pszFieldName+1;
00669                     }
00670                     else
00671                     {
00672                         l_pObjectField = (DBObjectField*) p_pDBObjectNode->selectSingleNode( l_pszFieldName);                   
00673                         if( l_pObjectField) l_pszValue = l_pObjectField->getValue();
00674                     }
00675 
00676                     l_fFlush=true;
00677                     try
00678                     { 
00679                         logout << p_pDBObjectNode->getName() << "." << l_pszFieldName << "=" << l_pszValue << "\n";
00680                         OTL_insertInVar( p_pOTLStream, p_varsDesc[i].ftype, l_pszValue);
00681                     }
00682                     catch(otl_exception& p)
00683                     { 
00684                         // intercept OTL exceptions
00685                         logout << p_pDBObjectNode->getName() << "." << l_pszFieldName << "=" << l_pszValue << "\n";
00686                         l_fdbError=true;
00687                         l_pszdbErrorMsg = copyCharBuffer( (char*)(&(p.msg)));
00688                         p.~otl_exception();
00689                         goto RELEASE_AND_RETURN;
00690                     }
00691                     //logout <<".";
00692                     if( l_pszTmp ) l_pszFieldName = l_pszTmp+1;
00693                 }
00694                 
00695                 if(! l_pszTmp )  break;
00696             }
00697 
00698         }
00699 
00700         try
00701         { 
00702             //logout <<" flush\n";
00703             if(l_fFlush) p_pOTLStream->flush(); 
00704             else p_pOTLStream->rewind();
00705         }
00706         catch(otl_exception& p)
00707         { // intercept OTL exceptions
00708             l_fdbError=true;
00709             l_pszdbErrorMsg = copyCharBuffer( (char*)(&(p.msg)));
00710             p.~otl_exception();
00711             goto RELEASE_AND_RETURN;
00712         }           
00713 
00714     RELEASE_AND_RETURN: 
00715         DEBUG_OUT(DBOBJSetStreamer::sendRecordToDB)
00716 
00717         l_pszTmp2 = releaseCharBuffer( l_pszTmp2);
00718         if(l_fdbError)
00719         {
00720             m_pConnection->rollback();
00721             p_pOTLStream->clean(1);
00722             MAKE_XMLFLOW_EXCEPTION( ERRCODE_LOC_DBOBJSETREQUEST + ERRCODE_CAUSE_DATAACCESS , "Error while flushing data stream. ", /*l_pszdbErrorMsg*/"", "DBOBJSetStreamer::sendRecordToDB", "", false);
00723             l_pszdbErrorMsg = releaseCharBuffer( l_pszdbErrorMsg);
00724         }
00725         ON_XML_FLOW_ERROR_THROW;
00726     }
00727 
00728     //_________________________________________________________________________
00729     //  BUILDINSERTSTATEMENT
00730     //-------------------------------------------------------------------------
00731     bool  DBOBJSetStreamer::buildINSERTStatement( DBObjectNode* p_pDBObjectNode, char** l_ppszStatement, char** l_ppszFields)
00732     {
00733         //---------------------------------------------------------------------
00734         const char*             l_pszOnInsert;
00735         char*                   l_pszSQL = 0;
00736         char*                   l_pszSQLVals = 0;
00737         char*                   l_pszFields = 0;
00738         const char*             l_pszSep = 0;
00739         const char*             l_pszFieldsSep;
00740         DBObjectField*          l_pDBObjectField = 0;
00741         const DBOBJDefinitionField*   l_pSAXDB_defField = 0;
00742         unsigned int            l_uiFieldsCount;
00743         unsigned int            i;
00744         bool                    l_fCachable;
00745         char*                   l_pszValue = 0;
00746         //---------------------------------------------------------------------
00747 
00748         DEBUG_IN(DBOBJSetStreamer::buildINSERTStatement)
00749 
00750 
00751         l_pszSQL = *l_ppszStatement;
00752         l_pszFields = * l_ppszFields;
00753             
00754         l_pszOnInsert = p_pDBObjectNode->getDefinition()->getOnInsert();
00755         if ( strlen( l_pszOnInsert)>0)  l_fCachable =  buildEventStatement( p_pDBObjectNode, l_pszOnInsert, &l_pszSQL, &l_pszFields);
00756         else
00757         {
00758             l_fCachable = true;
00759             l_pszSQL = copyCharBuffer("INSERT INTO ");
00760             l_pszSQL = concatCharBuffer( l_pszSQL, p_pDBObjectNode->getDefinition()->getDBTable());
00761             l_pszSQL = concatCharBuffer( l_pszSQL, "(");
00762 
00763             // Make columns list
00764             l_pszSep="";
00765             l_pszFieldsSep="";
00766             l_uiFieldsCount = p_pDBObjectNode->getDefinition()->getFieldsCount();
00767             for( i=0 ; i<l_uiFieldsCount ; i++)
00768             {
00769                 l_pSAXDB_defField = p_pDBObjectNode->getDefinition()->getField(i);
00770                 l_pDBObjectField = p_pDBObjectNode->getField(l_pSAXDB_defField->getName());
00771                 
00772                 if( l_pDBObjectField)
00773                 {
00774                     l_pszValue = getSQLInsert( l_pDBObjectField, &l_fCachable, &l_pszFields);
00775 
00776                     l_pszSQL = concatCharBuffer( l_pszSQL, l_pszSep);
00777                     l_pszSQL = concatCharBuffer( l_pszSQL, l_pDBObjectField->getDefinition()->getDBField());
00778                     l_pszSQLVals = concatCharBuffer( l_pszSQLVals, l_pszSep);
00779                     l_pszSQLVals = concatCharBuffer( l_pszSQLVals, l_pszValue);
00780 
00781                     l_pszValue = releaseCharBuffer( l_pszValue);
00782 
00783                     l_pszSep = ", ";
00784                 }
00785             }
00786 
00787             l_pszSQL = concatCharBuffer( l_pszSQL, ") VALUES(");
00788             l_pszSQL = concatCharBuffer( l_pszSQL, l_pszSQLVals);
00789             l_pszSQL = concatCharBuffer( l_pszSQL, ")");
00790         }
00791         
00792         *l_ppszStatement=l_pszSQL;
00793         *l_ppszFields=l_pszFields;
00794 
00795         l_pszSQLVals = releaseCharBuffer( l_pszSQLVals);
00796         l_pszValue = releaseCharBuffer( l_pszValue);
00797 
00798         DEBUG_OUT(DBOBJSetStreamer::buildINSERTStatement)
00799 
00800         return l_fCachable;
00801     }
00802 
00803     //_________________________________________________________________________
00804     //  BUILDUPDATESTATEMENT
00805     //-------------------------------------------------------------------------
00806     bool DBOBJSetStreamer::buildUPDATEStatement( DBObjectNode* p_pDBObjectNode, char** l_ppszStatement, char** l_ppszFields)
00807     {
00808         //---------------------------------------------------------------------
00809         char*                   l_pszSQL = 0;
00810         char*                   l_pszWHERE = 0;
00811         char*                   l_pszValue = 0;
00812         const char*             l_pszOnUpdate;
00813         DBObjectField*          l_pDBObjectField=0;
00814         const DBOBJDefinitionField*   l_pSAXDB_defField=0;
00815         const char*             l_pszSep;
00816         unsigned int            l_uiFieldsCount;
00817         unsigned int            i;
00818         bool                    l_fCachable;
00819         char*                   l_pszFields=0;
00820         //---------------------------------------------------------------------
00821 
00822         DEBUG_IN(DBOBJSetStreamer::buildUPDATEStatement)
00823 
00824         l_pszSQL = *l_ppszStatement;
00825         l_pszFields = * l_ppszFields;
00826             
00827         l_pszOnUpdate = p_pDBObjectNode->getDefinition()->getOnUpdate();
00828         if ( strlen( l_pszOnUpdate)>0)  l_fCachable =  buildEventStatement( p_pDBObjectNode, l_pszOnUpdate, &l_pszSQL, &l_pszFields);
00829         else
00830         {
00831             l_fCachable = true;
00832             l_pszSQL = copyCharBuffer( "UPDATE ");
00833             l_pszSQL = concatCharBuffer( l_pszSQL,  p_pDBObjectNode->getDefinition()->getDBTable());
00834             l_pszSQL = concatCharBuffer( l_pszSQL,  " SET ");
00835 
00836             // make columns=value list
00837             l_pszSep = " ";
00838             l_uiFieldsCount = p_pDBObjectNode->getDefinition()->getFieldsCount();
00839             for( i=0 ; i<l_uiFieldsCount ; i++)
00840             {  
00841                 l_pSAXDB_defField = p_pDBObjectNode->getDefinition()->getField(i);
00842                 l_pDBObjectField = p_pDBObjectNode->getField(l_pSAXDB_defField->getName());
00843 
00844                 if(l_pDBObjectField)
00845                 {
00846                     if( !l_pSAXDB_defField->isPkey() )
00847                     {
00848                         l_pszValue = getSQLInsert( l_pDBObjectField, &l_fCachable, &l_pszFields);
00849 
00850                         l_pszSQL = concatCharBuffer( l_pszSQL, l_pszSep);
00851                         l_pszSQL = concatCharBuffer( l_pszSQL, l_pSAXDB_defField->getDBField());
00852                         l_pszSQL = concatCharBuffer( l_pszSQL, "=");
00853                         l_pszSQL = concatCharBuffer( l_pszSQL, l_pszValue);
00854                         l_pszValue = releaseCharBuffer( l_pszValue);
00855                     
00856                         l_pszSep = ", ";
00857                     }
00858                 }
00859             }
00860 
00861             l_pszSQL = concatCharBuffer( l_pszSQL,  " WHERE ");
00862             l_fCachable = l_fCachable && buildWHEREclause( p_pDBObjectNode, &l_pszWHERE, &l_pszFields);
00863             l_pszSQL = concatCharBuffer( l_pszSQL, l_pszWHERE);
00864         }       
00865 
00866         *l_ppszStatement=l_pszSQL;
00867         *l_ppszFields=l_pszFields;
00868 
00869         l_pszWHERE = releaseCharBuffer( l_pszWHERE);
00870         l_pszValue = releaseCharBuffer( l_pszValue);
00871 
00872         DEBUG_OUT(DBOBJSetStreamer::buildUPDATEStatement)
00873         return  l_fCachable;
00874     }
00875 
00876     //_________________________________________________________________________
00877     //  BUILDDELETESTATEMENT
00878     //-------------------------------------------------------------------------
00879     bool DBOBJSetStreamer::buildDELETEStatement( DBObjectNode* p_pDBObjectNode, char** l_ppszStatement, char** l_ppszFields)
00880     {
00881         //---------------------------------------------------------------------
00882         char*       l_pszSQL = 0;
00883         char*       l_pszWHERE = 0;
00884         const char* l_pszOnDelete = 0;
00885         bool        l_fCachable;
00886         char*       l_pszFields;
00887         //---------------------------------------------------------------------
00888         DEBUG_IN(DBOBJSetStreamer::buildDELETEStatement)
00889 
00890         l_pszSQL = *l_ppszStatement;
00891         l_pszFields = * l_ppszFields;   
00892 
00893         l_pszOnDelete = p_pDBObjectNode->getDefinition()->getOnDelete();
00894         if ( strlen( l_pszOnDelete)>0)  l_fCachable =  buildEventStatement( p_pDBObjectNode, l_pszOnDelete, &l_pszSQL, &l_pszFields);
00895         else
00896         {
00897             l_fCachable = true;
00898             l_pszSQL = copyCharBuffer( "DELETE FROM ");
00899             l_pszSQL = concatCharBuffer( l_pszSQL, p_pDBObjectNode->getDefinition()->getDBTable());
00900             l_pszSQL = concatCharBuffer( l_pszSQL, " WHERE ");
00901             l_fCachable = l_fCachable && buildWHEREclause( p_pDBObjectNode, &l_pszWHERE, &l_pszFields);
00902             l_pszSQL = concatCharBuffer( l_pszSQL, l_pszWHERE);
00903         }
00904 
00905         *l_ppszStatement=l_pszSQL;
00906         *l_ppszFields=l_pszFields;
00907 
00908         l_pszWHERE = releaseCharBuffer( l_pszWHERE);
00909 
00910         DEBUG_OUT(DBOBJSetStreamer::buildDELETEStatement)
00911         return  l_fCachable;
00912     }
00913 
00914     //_________________________________________________________________________
00915     //  BUILDWHERECLAUSE
00916     //-------------------------------------------------------------------------
00917     bool DBOBJSetStreamer::buildWHEREclause( DBObjectNode* p_pDBObjectNode, char** l_ppszStatement, char** l_ppszFields)
00918     {
00919         //---------------------------------------------------------------------
00920         DBObjectField*          l_pDBObjectField = 0;
00921         DBOBJDefinitionField*   l_pSAXDB_defField = 0;
00922         char*                   l_pszSQL = 0;
00923         char*                   l_pszFields=0;
00924         char*                   l_pszValue = 0;
00925         const char*             l_pszWSep = 0;
00926         unsigned int            l_uiFieldsCount;
00927         unsigned int            i;
00928         bool                    l_fCachable;
00929         //---------------------------------------------------------------------
00930 
00931         DEBUG_IN(DBOBJSetStreamer::buildWHEREclause)
00932 
00933         l_pszSQL = *l_ppszStatement;
00934         l_pszFields = * l_ppszFields;
00935         
00936         l_fCachable = true;
00937         l_uiFieldsCount = p_pDBObjectNode->getDefinition()->getPkeysCount();
00938         for( i=0 ; i<l_uiFieldsCount ; i++)
00939         {               
00940             l_pSAXDB_defField = p_pDBObjectNode->getDefinition()->getPkey(i);
00941             l_pDBObjectField = p_pDBObjectNode->getField(l_pSAXDB_defField->getName());
00942 
00943             l_pszValue = getSQLInsert( l_pDBObjectField, &l_fCachable, &l_pszFields);
00944             
00945             l_pszSQL = concatCharBuffer( l_pszSQL, l_pszWSep);
00946             l_pszSQL = concatCharBuffer( l_pszSQL, l_pSAXDB_defField->getDBField());
00947             l_pszSQL = concatCharBuffer( l_pszSQL, "=");
00948             l_pszSQL = concatCharBuffer( l_pszSQL, l_pszValue);
00949             l_pszValue = releaseCharBuffer( l_pszValue);
00950 
00951             l_pszWSep = " AND ";
00952         }
00953 
00954         *l_ppszStatement=l_pszSQL;
00955         *l_ppszFields=l_pszFields;
00956 
00957         l_pszValue = releaseCharBuffer( l_pszValue);
00958 
00959         DEBUG_OUT(DBOBJSetStreamer::buildWHEREclause)
00960         return  l_fCachable;
00961     }
00962 
00963     //_________________________________________________________________________
00964     //  BUILDCHECKSTATEMENT
00965     //-------------------------------------------------------------------------
00966     bool DBOBJSetStreamer::buildCHECKStatement( DBObjectNode* p_pDBObjectNode, char** l_ppszStatement, char** l_ppszFields, bool p_boolPre)
00967     {
00968         //---------------------------------------------------------------------
00969         const char* l_pszCheck;
00970         //---------------------------------------------------------------------
00971         DEBUG_FUNC(DBOBJSetStreamer::buildCHECKStatement)
00972 
00973         if(p_boolPre)   l_pszCheck = p_pDBObjectNode->getDefinition()->getCheckPre();
00974         else            l_pszCheck = p_pDBObjectNode->getDefinition()->getCheckPost();
00975         return buildEventStatement( p_pDBObjectNode, l_pszCheck, l_ppszStatement, l_ppszFields);
00976     }
00977 
00978     //_________________________________________________________________________
00979     //  BUILDEVENTSTATEMENT
00980     //-------------------------------------------------------------------------
00981     bool  DBOBJSetStreamer::buildEventStatement( DBObjectNode* p_pDBObjectNode, const char* l_pszEnventString, char** l_ppszStatement, char** l_ppszFields)
00982     {
00983         //---------------------------------------------------------------------
00984         char*   l_pszEvent;
00985         char*   l_pszSQL;
00986         bool    l_fCachable;
00987         char*   l_pszFields;
00988         //---------------------------------------------------------------------
00989     
00990 
00991         l_pszSQL = *l_ppszStatement;
00992         l_pszFields = * l_ppszFields;       
00993 
00994         l_pszEvent = p_pDBObjectNode->calculateRelValue( l_pszEnventString);
00995         if( strcmp(l_pszEvent, DBOBJDEFNODE_NOEVENT )==0 )
00996         {
00997             l_pszEvent = releaseCharBuffer(l_pszEvent);
00998             l_pszSQL = 0;
00999             l_pszFields = 0;
01000             l_fCachable = true;
01001         }
01002         else
01003         {
01004             l_pszSQL = strchr(l_pszEvent, DBOBJDEFNODE_VARSQLSEP);
01005             //logout << l_pszSQL << "\n";
01006             if( l_pszSQL)
01007             {
01008                 // var list provided : statement is dynamic and cachable
01009                 l_pszSQL[0]='\0';
01010                 l_pszSQL++;
01011                 l_pszFields = l_pszEvent;
01012                 l_fCachable = true;
01013             }
01014             else
01015             {
01016                 // no var list provided : statement is static and not cachable
01017                 l_pszSQL=l_pszEvent;
01018                 l_pszFields=0;
01019                 l_fCachable = false;
01020             }
01021         }   
01022 
01023         *l_ppszStatement=l_pszSQL;
01024         *l_ppszFields=l_pszFields;
01025         return  l_fCachable;
01026 
01027     }
01028 
01029 
01030 
01031     // FIELDS EXTRACTION FUNCTION
01032 
01033     //_________________________________________________________________________
01034     //  GETSQLINSERT
01035     //-------------------------------------------------------------------------
01036     char* DBOBJSetStreamer::getSQLInsert(DBObjectField* l_pDBObjectField, bool* p_pfCachable, char** p_ppszFields)
01037     {
01038         bool    l_fCachable;
01039         char*   l_pszInsert=0;
01040         char*   l_pszFields;
01041 
01042         l_pszFields = *p_ppszFields;
01043         l_fCachable = *p_pfCachable;
01044 
01045         if( l_fCachable) l_pszInsert = getFieldBindVar( l_pDBObjectField);
01046 
01047         if( !l_pszInsert)
01048         {
01049             l_fCachable = false;
01050             l_pszInsert = getFieldValue( l_pDBObjectField);
01051         }
01052         else
01053         {
01054             if(l_pszFields) l_pszFields = concatCharBuffer(l_pszFields, ",");
01055             l_pszFields = concatCharBuffer(l_pszFields, l_pDBObjectField->getName() );
01056         }
01057 
01058         *p_ppszFields = l_pszFields;
01059         *p_pfCachable = l_fCachable;
01060 
01061         return l_pszInsert;
01062     }
01063 
01064     //_________________________________________________________________________
01065     //  GETFIELDVALUE
01066     //-------------------------------------------------------------------------
01067     char* DBOBJSetStreamer::getFieldValue(DBObjectField* l_pDBObjectField)
01068     {
01069         //---------------------------------------------------------------------
01070         const char* l_pszFieldValue = 0;
01071         const char* l_pszMap = 0;
01072         const char* l_pszDateFormat = 0;
01073         char*       l_pszTmp = 0;
01074         char*       l_pszTmp2 = 0;
01075         char*       l_pszValue = 0;
01076         //---------------------------------------------------------------------
01077 
01078         DEBUG_FUNC(DBOBJSetStreamer::getFieldValue)
01079 
01080         l_pszFieldValue = l_pDBObjectField->getValue();
01081         if( strcmp( l_pszFieldValue, REQ_NULL) == 0 ) return copyCharBuffer( DB_NULL);
01082 
01083 
01084         l_pszMap = l_pDBObjectField->getDefinition()->getMap();
01085 
01086         if( strcmp( l_pszMap, DBOBJDEFFIELD_MAP_STRING) == 0)
01087         {
01088             // CORRECT VALUE
01089             l_pszValue = copyCharBuffer( "'");
01090 
01091             l_pszTmp = replaceInCharBuffer( l_pszFieldValue, "'","''");
01092             l_pszTmp2 = replaceInCharBuffer( l_pszTmp, "\n","'||CHR(10)||'");
01093             l_pszTmp = releaseCharBuffer( l_pszTmp);
01094             l_pszTmp = replaceInCharBuffer( l_pszTmp2 ,"\r","'||CHR(13)||'");
01095             l_pszTmp2 = releaseCharBuffer( l_pszTmp2);
01096 
01097             l_pszValue = concatCharBuffer( l_pszValue, l_pszTmp);
01098             l_pszValue = concatCharBuffer( l_pszValue, "'");
01099         }
01100         if( strcmp( l_pszMap, DBOBJDEFFIELD_MAP_NUM) == 0 )
01101         {
01102             l_pszValue = replaceInCharBuffer( l_pszFieldValue, ",",".");
01103         }           
01104         if( strcmp( l_pszMap, DBOBJDEFFIELD_MAP_DATE) == 0 )
01105         {
01106             l_pszDateFormat = l_pDBObjectField->getDefinition()->getDateFormat();
01107             l_pszValue = copyCharBuffer( "TO_DATE('");
01108             l_pszValue = concatCharBuffer( l_pszValue, l_pszFieldValue);
01109             l_pszValue = concatCharBuffer( l_pszValue, "','");
01110             l_pszValue = concatCharBuffer( l_pszValue, l_pszDateFormat);
01111             l_pszValue = concatCharBuffer( l_pszValue, "')");
01112         }           
01113 
01114         l_pszTmp2 = releaseCharBuffer( l_pszTmp2);
01115         l_pszTmp = releaseCharBuffer( l_pszTmp);
01116 
01117 
01118         return l_pszValue;
01119     }
01120 
01121 
01122     //_________________________________________________________________________
01123     //  getFieldBindVar
01124     //-------------------------------------------------------------------------
01125     char* DBOBJSetStreamer::getFieldBindVar(DBObjectField* p_pDBObjectField)
01126     {
01127         //---------------------------------------------------------------------
01128         const char* l_pszFieldName = 0;
01129         const char* l_pszFieldDBSpec = 0;
01130         char*       l_pszFieldBindType = 0;
01131         char*       l_pszFieldBindVar = 0;
01132         const char* l_pszMap = 0;
01133         const char* l_pszDateFormat=0;
01134         bool        l_fDate;
01135         //---------------------------------------------------------------------
01136 
01137         DEBUG_FUNC(DBOBJSetStreamer::getFieldValue)
01138 
01139         l_pszFieldName = p_pDBObjectField->getName();
01140         if( p_pDBObjectField->getDefinition()->isAttribute() ) l_pszFieldName++;
01141 
01142         l_pszFieldDBSpec = p_pDBObjectField->getDefinition()->getDBSpecProps();
01143         if( strlen(l_pszFieldDBSpec) == 0 ) return 0;
01144 
01145         l_pszFieldBindType=OTL_getColumBindType( l_pszFieldDBSpec,DBStreamerFactory::getSQLSyntax());
01146 
01147         l_pszMap = p_pDBObjectField->getDefinition()->getMap();
01148         l_fDate = false;
01149         if( strcmp( l_pszMap, DBOBJDEFFIELD_MAP_DATE) == 0 ) l_fDate=true;
01150 
01151         if (DBStreamerFactory::getSQLSyntax()==SQL_SYNTAX_ORA)
01152         {   
01153             if( l_fDate) l_pszFieldBindVar = concatCharBuffer( l_pszFieldBindVar, "TO_DATE(");
01154         }
01155         else if (DBStreamerFactory::getSQLSyntax()==SQL_SYNTAX_MSSQL)
01156         {
01157             if( l_fDate) l_pszFieldBindVar = concatCharBuffer( l_pszFieldBindVar, "CONVERT(datetime,");
01158         }
01159         l_pszFieldBindVar = concatCharBuffer( l_pszFieldBindVar,":");
01160         l_pszFieldBindVar = concatCharBuffer( l_pszFieldBindVar, l_pszFieldName);
01161         l_pszFieldBindVar = concatCharBuffer( l_pszFieldBindVar, "<");
01162         l_pszFieldBindVar = concatCharBuffer( l_pszFieldBindVar, l_pszFieldBindType);
01163         l_pszFieldBindVar = concatCharBuffer( l_pszFieldBindVar, ">");
01164 
01165         if( l_fDate) 
01166         {
01167             if (DBStreamerFactory::getSQLSyntax()==SQL_SYNTAX_ORA)
01168             {       
01169                 l_pszFieldBindVar = concatCharBuffer( l_pszFieldBindVar, ",'");
01170                 l_pszFieldBindVar = concatCharBuffer( l_pszFieldBindVar,  p_pDBObjectField->getDefinition()->getDateFormat());
01171                 l_pszFieldBindVar = concatCharBuffer( l_pszFieldBindVar, "')");
01172             }
01173             else if (DBStreamerFactory::getSQLSyntax()==SQL_SYNTAX_MSSQL)
01174             {       
01175                 l_pszFieldBindVar = concatCharBuffer( l_pszFieldBindVar, ",");
01176                 l_pszFieldBindVar = concatCharBuffer( l_pszFieldBindVar,  p_pDBObjectField->getDefinition()->getDateFormat());
01177                 l_pszFieldBindVar = concatCharBuffer( l_pszFieldBindVar, ")");
01178             }
01179         }
01180 
01181         l_pszFieldBindType = releaseCharBuffer( l_pszFieldBindType);
01182 
01183         return l_pszFieldBindVar;
01184     }
01185 
01186     // OBJECTS STACK
01187 
01188     //_________________________________________________________________________
01189     //  STACKOBJECT
01190     //-------------------------------------------------------------------------
01191     void DBOBJSetStreamer::stackObject( DBObjectNode* p_pDBObjectNode)
01192     {
01193         DEBUG_FUNC(DBOBJSetStreamer::stackObject)
01194 
01195         m_vaObjects.push(p_pDBObjectNode);
01196     }
01197 
01198     //_________________________________________________________________________
01199     //  DESTACKOBJECTS
01200     //-------------------------------------------------------------------------
01201     void DBOBJSetStreamer::deStackObjects( XMLStreamConsumer*  p_pBufferXML, bool p_fCount)
01202     {
01203          //--------------------------------------------------------------------
01204         DBObjectNode* l_pDBObjectNode=0;
01205         unsigned int i=0;
01206          //--------------------------------------------------------------------
01207 
01208         DEBUG_FUNC(DBOBJSetStreamer::deStackObjects)
01209 
01210         while( !m_vaObjects.empty())
01211         {      
01212             i++;
01213             l_pDBObjectNode=m_vaObjects.bottom();
01214             m_vaObjects.remove((unsigned int) 0);
01215             if(p_pBufferXML) l_pDBObjectNode->getXML( p_pBufferXML);
01216 
01217             m_uiToStream++;
01218             if(m_uiToStream >= m_uiStreamObjects) 
01219             {
01220                 logout << "\t" << DBOBJSETSTREAMER_TAGNAME << "   :   " << "output " << m_uiToStream << " object\n";
01221                 m_pOutput->commitStream(false);
01222                 m_uiToStream = 0;
01223             }
01224                             
01225             // COMPTAGE
01226             if( p_fCount ) countObjectNodes(l_pDBObjectNode);
01227             delete( l_pDBObjectNode);
01228         }
01229     }
01230 
01231 
01232     //_________________________________________________________________________
01233     //  COUNTOBJECTNODES
01234     //-------------------------------------------------------------------------
01235     void DBOBJSetStreamer::countObjectNodes(DBObjectNode * p_pDBObjectNode)
01236     {
01237         //--------------------------------------------------------------------
01238         unsigned int i;
01239         unsigned int l_uiChildNodesCount;
01240         char*   l_pszNodeName;      
01241         //--------------------------------------------------------------------
01242 
01243 
01244         l_pszNodeName = DBObjectSAXBuilder::translateAction(p_pDBObjectNode->getAction()); 
01245         l_pszNodeName = concatCharBuffer( l_pszNodeName, "_");
01246         l_pszNodeName = concatCharBuffer( l_pszNodeName, p_pDBObjectNode->getName());
01247 
01248         m_vaNodesCounts.add( m_vaNodesCounts.remove( l_pszNodeName)+1, l_pszNodeName );
01249 
01250         l_pszNodeName = releaseCharBuffer( l_pszNodeName);
01251 
01252         // Recurse ...
01253         l_uiChildNodesCount = p_pDBObjectNode->getChildNodesCount();
01254         for(i=0; i< l_uiChildNodesCount ; i++) countObjectNodes( p_pDBObjectNode->getChildNode(i));
01255     }
01256 
01257 
01258 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01259 //=============================================================================
01260 
01261 
01262 
01263 //=============================================================================
01264 //  CLASS DBOBJSetStreamerFactory
01265 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01266 
01267     XMLStreamer* DBOBJSetStreamerFactory::getStreamer(
01268         StreamerParams*         p_pParameters, 
01269         XMLFlowContext* p_pStreamContext, 
01270         XMLStreamConsumer*      p_pStreamConsumer) const
01271     {
01272         return (XMLStreamer*) new DBOBJSetStreamer(this, p_pParameters, p_pStreamContext, p_pStreamConsumer);
01273     }
01274 
01275 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01276 //=============================================================================
01277 
01278 END_XDFLENGINE_NS
01279 

Generated on Sat Oct 4 13:19:57 2003 for XDFLengine by doxygen1.3-rc2