Example #1
0
/*******************pubilc interface***********************/
BuddyDesc BuddyRelationLogic::getRelation(const Relationship& relationship) {
    if (relationship.from == relationship.to) {
        return ::Self;
    }
	
    Relationship relation = relationship;
    bool changed = operRelationship(relation);
		
    Entry key(relation.to, 0);
	
    EntryListHolderPtr holder = readObject(relation.from);
	
    if (holder) {
        EntryList entryResult = holder->get(key);
        if (entryResult.empty()) {
            MCE_DEBUG("BuddyRelationCacheManagerI::getRelation found empty.");
            return ::NoPath;
        }

        if (entryResult.size() != 1) {
            MCE_WARN("GetRelation should found only one entry. But found "
					<< entryResult.size() << " entries");
        }
        if(changed){
            return BuddyDescHelper::oppositeDesc(BuddyDescHelper::translateDesc(entryResult.at(0).desc));
        }else{
            return BuddyDescHelper::translateDesc(entryResult.at(0).desc);
        }
    } else {
        MCE_INFO("BuddyRelationCacheManagerI::getRelation, from: " << relation.from << " is not in cache");
    }
    return ::NoPath;
}
Example #2
0
File: kiten.cpp Project: KDE/kiten
/**
 * This method performs the search and displays
 * the result to the screen.
 */
void Kiten::searchAndDisplay( const DictQuery &query )
{
  /* keep the user informed of what we are doing */
  _statusBar->showMessage( i18n( "Searching..." ) );

  /* This gorgeous incantation is all that's necessary to fill a DictQuery
    with a query and an Entrylist with all of the results form all of the
    requested dictionaries */
  EntryList *results = _dictionaryManager.doSearch( query );

  /* if there are no results */
  if ( results->size() == 0 ) //TODO: check here if the user actually prefers this
  {
    //create a modifiable copy of the original query
    DictQuery newQuery( query );

    bool tryAgain = false;

    do
    {
      //by default we don't try again
      tryAgain = false;

      //but if the matchtype is changed we try again
      if ( newQuery.getMatchType() == DictQuery::Exact )
      {
        newQuery.setMatchType( DictQuery::Beginning );
        tryAgain = true;
      }
      else if ( newQuery.getMatchType() == DictQuery::Beginning )
      {
        newQuery.setMatchType( DictQuery::Anywhere );
        tryAgain = true;
      }


      //try another search
      if ( tryAgain )
      {
        delete results;
        results = _dictionaryManager.doSearch( newQuery );

        //results means all is ok; don't try again
        if ( results->size() > 0 )
        {
          tryAgain = false;
        }
      }
    } while ( tryAgain );
  }

  /* synchronize the history (and store this pointer there) */
  addHistory( results );

  /* Add the current search to our drop down list */
  _inputManager->setSearchQuery( results->getQuery() );

  /* suppose it's about time to show the users the results. */
  displayResults( results );
}
Example #3
0
int CustomerData::findEntry(const EntryList& entries, const std::string& stock)
{
    for(int i = 0; i < entries.size(); ++i)
    {
        if (entries[i].first == stock)
            return entries[i].second;
    }
    return -1;
}
DB_Error DataBaseSqlite::AddUser(shared_ptr<User> user)
{
    DB_Error ret = CreateTable("User");
    if (ret == DB_OK)
    {
        EntryList entries = m_pTableComponent->GetTableFormat("User");
        PDEBUG ("entry size: %lu\n", entries.size());
        if (!entries.empty())
        {
            string sql(INSERT_TABLE);
            sql += string("User") + VALUE + LPARENT;
            EntryList::iterator iter = entries.begin();
            EntryList::iterator end  = entries.end();
            for (; iter != end;)
            {
                sql += "@" + iter->name;
                if (++iter != end)
                {
                    sql += ", ";
                }
            }
            sql += string(RPARENT) + SEMI;

            SqliteCommand cmd(this, sql);

            // Ugly hard code!!
            PDEBUG ("Begin binding\n");
            ret = cmd.Bind("@name", user->name());
            ret = ret ? ret : cmd.Bind("@uuid", user->uuid());
            int64 date = 0;
            if (user->has_reg_date())
            {
                ret = user->reg_date();
            }
            ret = ret ? ret : cmd.Bind("@reg_date", date);

            date = 0;

            if (user->has_last_login())
            {
                date = user->last_login();
            }
            ret = ret ? ret : cmd.Bind("@last_login", date);
            // Bind others ...
            ret = ret ? ret : cmd.Execute();
            // Execute ....
        }
    }
    return ret;
}
DB_Error DataBaseSqlite::CreateTable(const string& name)
{
    DB_Error ret = DB_INVAL;


    EntryList entries = m_pTableComponent->GetTableFormat(name);
    PDEBUG ("entry size: %lu\n", entries.size());
    if (!entries.empty())
    {
        string sql(CREATE_TABLE);
        sql += IFNEXT + name + LPARENT;
        EntryList::iterator iter = entries.begin();
        EntryList::iterator end  = entries.end();
        for (; iter != end;)
        {
            sql += iter->name + " " +
                   g_SqlteKeywordMapping[iter->type];

            if (iter->primary)
            {
                sql += PRIMARY_KEY;
            }

            if (++iter != end)
            {
                sql += ", ";
            }
        }
        sql += string(RPARENT) + SEMI;

        SqliteCommand cmd(this, sql);
        ret = cmd.Execute();
    }


    PDEBUG ("Create %s, ret: %d\n", name.c_str(), ret);
    return ret;
}