当前位置: 首页>>代码示例>>C++>>正文


C++ IDatabase::setDataTypeAction方法代码示例

本文整理汇总了C++中IDatabase::setDataTypeAction方法的典型用法代码示例。如果您正苦于以下问题:C++ IDatabase::setDataTypeAction方法的具体用法?C++ IDatabase::setDataTypeAction怎么用?C++ IDatabase::setDataTypeAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDatabase的用法示例。


在下文中一共展示了IDatabase::setDataTypeAction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getDatabase

    IDatabase* DatabaseFactory::getDatabase(EDataTypes dataType, EDataActions dataAction)
    {
        FUNCTION_ENTRY("getDatabase");
        // Set up a local variable to point to the database that is either created or found
        IDatabase* theDatabase = NULL;

        ThreadGuard guard( m_getDatabaseLock );

        // get the connection string for this datatype/action
        std::string dbConnection;
        
        // forever loop will exit by exception or when a good db is found
        while(1)
        {
            // If this call fails it will throw something.
            try
            {
                DbConnection::getInstance().getConnectionString(dataType, dataAction, dbConnection);
            }
            catch(DbConnectionFailed&)
            {
                // we exit the forever loop with this throw
                TA_THROW(DatabaseException("Unable to find a working database"));
            }

            // Get the ID of this thread - we want one database connection per thread
            int threadId = Thread::getCurrentThreadId();

            // Look to see if there is already a database connection for this thread
			//<ThreadID: Map<ConnectionString, SimpleDBDatabase>>
            ThreadMap::iterator threadIter ( m_databaseMap.find( threadId ));
            if ( threadIter == m_databaseMap.end() )
            {
                // add new ConnectionMap. Set db* to null untill it's defined
                ConnectionMap cmap;
                cmap.insert( ConnectionMap::value_type( dbConnection, 0 ) );
                threadIter = m_databaseMap.insert(ThreadMap::value_type(threadId, cmap) ).first;
            }

            ConnectionMap::iterator connIter ( threadIter->second.find( dbConnection ) );
            if (connIter == threadIter->second.end())
            {
                connIter = threadIter->second.insert(ConnectionMap::value_type( dbConnection, 0 )).first;
            }
            if (connIter->second != 0 )
            {
                // Then the connection already exists.
	            theDatabase = connIter->second; //TODO: need to set dataType and DataAction
				theDatabase->setDataTypeAction(dataType, dataAction);
            }
            else // Database doesn't exist for this thread, so need to create it.
            {
			    LOG(SourceInfo, DebugUtil::GenericLog, DebugUtil::DebugInfo, "New SimpleDbDatabase object created for thread %lu", threadId);
            
	            theDatabase = new TA_Base_Core::SimpleDbDatabase(dataType, dataAction);

                // add to map
                connIter->second = theDatabase;
            }


            // Now that we have a database object, we need to connect it - do this everytime
            // 'cause if the database is alerady connected, nothing will happen, but if it has
            // been inadvertandtly disconnected, then it will be reconnected
            try // The connect line can generate a DatabaseException
            {
                theDatabase->connect( dbConnection );

                // we can also exit the forever loop this (preferred) way
 
                FUNCTION_EXIT;
   		        return theDatabase;
            }
            catch (DatabaseException&) 
            {
                // A DatabaseException was generated. Need to delete the database object for now.
                delete theDatabase;
                threadIter->second.erase(connIter);
                TA_Base_Core::Thread::sleep(100);
                // do not rethrow, just sleep for a while
                // there may be another database we can talk to.
            }
        } // end forever loop
	}
开发者ID:shenglonglin2000,项目名称:MT,代码行数:84,代码来源:DatabaseFactory.cpp


注:本文中的IDatabase::setDataTypeAction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。