Example #1
0
void Test2(IDbSystem* pSystem, LPCTSTR pstrConnection)
{
   //pSystem->Initialize();

   CAutoPtr<IDbDatabase> pDb(pSystem->CreateDatabase());
   BOOL bRes;
   bRes = pDb->Open(NULL, pstrConnection, _T(""), _T(""), DB_OPEN_READ_ONLY);
   if( !bRes ) {
      TCHAR szMsg[256];
      pDb->GetErrors()->GetError(0)->GetMessage(szMsg, 256);
      ::MessageBox( NULL, szMsg, _T("Database Test"), MB_OK|MB_ICONERROR);
      return;
   }

   CAutoPtr<IDbCommand> pCmd(pSystem->CreateCommand(pDb));
   pCmd->Create(_T("SELECT ProductID,ProductName FROM Products WHERE ProductID=? AND ProductName=?"));
   long lVal = 2L;
   pCmd->SetParam(0, &lVal);
   pCmd->SetParam(1, _T("Chang"));
   CAutoPtr<IDbRecordset> pRec(pSystem->CreateRecordset(pDb));
   pCmd->Execute(pRec);
   while( !pRec->IsEOF() ) {
      long lID;
      TCHAR szTitle[128];
      pRec->GetField(0, lID);
      pRec->GetField(1, szTitle, 128);
      pRec->MoveNext();
   }
   pRec->Close();
   pCmd->Close();

   pDb->Close();

   //pSystem->Terminate();
}
Example #2
0
Ou<CRfEditCmd> CRfEditCmd_DiaProp::
	createUndoCmd() 
{
	OuNew<CRfEditCmd>	pCmd( 
		new CRfEditCmd_DiaProp( m_iDiaIndex ,m_strDiaNameOld ) 
		);
	return ( pCmd ) ;
}
Example #3
0
Ou<CRfEditCmd> CRfEditCmd_Dia::createUndoCmd()
{
	if ( m_pCentDedDiaContOld != NULL ){
		OuNew<CRfEditCmd>	pCmd( 
			new CRfEditCmd_Dia( 
				m_iIndexDst , 
				m_CentDedDiaContSrc.size() , 
				*m_pCentDedDiaContOld ) ) ;
		delete m_pCentDedDiaContOld ;
		m_pCentDedDiaContOld = NULL ;
		return pCmd ;
	}
	return ( Ou<CRfEditCmd>() ) ;
}
bool GitlFrontController::detonate( GitlEvent& rcEvt)
{
    GitlIvkCmdEvt& rcCmdRequestEvt = dynamic_cast<GitlIvkCmdEvt&>(rcEvt);
    QString strCommandName = rcCmdRequestEvt.getCommandName();
    QHash<QString, QMetaObject*>::iterator i = m_cCommandTable.find(strCommandName);
    //command not found
    if( i == m_cCommandTable.end() )
    {
        qWarning() << QString("No matched command name found. %1").arg(strCommandName);
        return true;
    }
    //create command
    const QMetaObject* pMetaObj = i.value();
    QObject* pObj = pMetaObj->newInstance();
    //if fail to create command class
    if(pObj == NULL)
    {
        qCritical() << QString("Unable to create command class '%1'! Please ensure the constructor have Q_INVOKABLE macro.")
                    .arg(pMetaObj->className());
        return true;
    }

    QSharedPointer<GitlAbstractCommand> pCmd(static_cast<GitlAbstractCommand *>(pObj));

    /// execute it in worker thread or main(GUI) thread
    if(pCmd->getInWorkerThread() == false)
    {
        onCommandRequestArrive(rcCmdRequestEvt);
    }
    else
    {
        /// pending for worker thread execution
        m_cEvtQueMutex.lock();
        if( m_pcEvtQue.size() >= m_iMaxEvtInQue )
        {
            std::cerr << "Too Many Events Pending...Waiting..." << std::endl;
            m_cEvtQueNotFull.wait(&m_cEvtQueMutex);
            std::cerr << "Event Queue Not Full...Moving on..." << std::endl;
        }
        m_pcEvtQue.push_back(rcEvt.clone());
        m_cEvtQueMutex.unlock();
        m_cEvtQueNotEmpty.wakeAll();
    }

    return true;

}
void GitlFrontController::onCommandRequestArrive(GitlIvkCmdEvt &rcEvt)
{
    QMutexLocker cCmdExeMutexLocker(&m_cCmdExeMutex);
    GitlUpdateUIEvt cRefreshUIEvt;
    GitlCommandParameter& rcRequest = rcEvt.getParameters();
    GitlCommandParameter& rcRespond = cRefreshUIEvt.getParameters();

    // find command by name
    QString strCommandName = rcEvt.getCommandName();
    rcRespond.setParameter("command_name", strCommandName);
    QHash<QString, QMetaObject*>::iterator i = m_cCommandTable.find(strCommandName);
    if( i != m_cCommandTable.end() )
    {
        //command name matched
        //create  command
        const QMetaObject* pMetaObj = i.value();
        QObject* pObj = pMetaObj->newInstance();
        //if fail to create command class
        if(pObj == NULL)
        {
            qCritical() << QString("Unable to create command class '%1'! Please ensure the constructor have Q_INVOKABLE macro.")
                        .arg(pMetaObj->className());
            return;
        }
        QSharedPointer<GitlAbstractCommand> pCmd(static_cast<GitlAbstractCommand *>(pObj));
        //execute command
        if( pCmd->execute(rcRequest, rcRespond) == false )
        {
            qDebug() << QString("%1 Execution Failed!").arg(pMetaObj->className());
        }
        else
        {
            cRefreshUIEvt.dispatch();
            qDebug() << QString("%1 Execution Success!").arg(pMetaObj->className());
        }
        return;

    }
    qWarning() << QString("No matched command name found. %1").arg(strCommandName);
    return;



}
QList<ParameterizedCommand::Pointer>
ParameterizedCommand::GenerateCombinations(const SmartPointer<Command> command)
{
  QList<IParameter::Pointer> parameters(command->GetParameters());

  typedef QList<QList<Parameterization> > ExpandedParamsType;
  const ExpandedParamsType expansion(ExpandParameters(0, parameters));
  QList<ParameterizedCommand::Pointer> combinations;

  for (ExpandedParamsType::const_iterator expansionItr = expansion.begin();
      expansionItr != expansion.end(); ++expansionItr)
  {
    QList<Parameterization> combination(*expansionItr);

    QList<Parameterization> parameterizations(combination);
    ParameterizedCommand::Pointer pCmd(new ParameterizedCommand(command,
            parameterizations));
    combinations.push_back(pCmd);
  }

  return combinations;
}
std::vector<ParameterizedCommand::Pointer>
ParameterizedCommand::GenerateCombinations(const SmartPointer<Command> command)
throw(NotDefinedException)
{
  std::vector<IParameter::Pointer> parameters(command->GetParameters());

  typedef std::vector<std::list<Parameterization> > ExpandedParamsType;
  const ExpandedParamsType expansion(ExpandParameters(0, parameters));
  std::vector<ParameterizedCommand::Pointer> combinations;

  for (ExpandedParamsType::const_iterator expansionItr = expansion.begin();
      expansionItr != expansion.end(); ++expansionItr)
  {
    std::list<Parameterization> combination(*expansionItr);

    std::vector<Parameterization> parameterizations(combination.begin(), combination.end());
    ParameterizedCommand::Pointer pCmd(new ParameterizedCommand(command,
            parameterizations));
    combinations.push_back(pCmd);
  }

  return combinations;
}
Example #8
0
  SmartPointer<ParameterizedCommand> CommandManager::Deserialize(
      const std::string& serializedParameterizedCommand)
      throw(NotDefinedException, SerializationException) {

    const int lparenPosition = (int) this->UnescapedIndexOf(
        serializedParameterizedCommand, PARAMETER_START_CHAR);

    std::string commandIdEscaped;
    std::string serializedParameters;
    if (lparenPosition == -1) {
      commandIdEscaped = serializedParameterizedCommand;
    } else {
      commandIdEscaped = serializedParameterizedCommand.substr(0,
          lparenPosition);

      if (serializedParameterizedCommand
          .at(serializedParameterizedCommand.size() - 1) != PARAMETER_END_CHAR) {
        throw SerializationException(
            "Parentheses must be balanced in serialized ParameterizedCommand"); //$NON-NLS-1$
      }

      serializedParameters = serializedParameterizedCommand.substr(
          lparenPosition + 1, // skip PARAMETER_START_CHAR
          serializedParameterizedCommand.size() - 1); // skip
      // PARAMETER_END_CHAR
    }

    const std::string commandId(this->Unescape(commandIdEscaped));
    Command::Pointer command(this->GetCommand(commandId));
    const std::vector<IParameter::Pointer> parameters(command->GetParameters());
    const std::vector<Parameterization>parameterizations(this->GetParameterizations(
        serializedParameters, parameters));

    ParameterizedCommand::Pointer pCmd(new ParameterizedCommand(command, parameterizations));
    return pCmd;
  }
ParameterizedCommand::Pointer ParameterizedCommand::GenerateCommand(const SmartPointer<Command> command,
    const std::map<std::string, Object::Pointer>& parameters)
{
  // no parameters
  if (parameters.empty())
  {
    ParameterizedCommand::Pointer pCmd(new ParameterizedCommand(command, std::vector<Parameterization>()));
    return pCmd;
  }

  try
  {
    std::vector<Parameterization> parms;

    // iterate over given parameters
    for (std::map<std::string, Object::Pointer>::const_iterator i = parameters.begin();
        i != parameters.end(); ++i)
    {
      std::string key(i->first);

      // get the parameter from the command
      IParameter::Pointer parameter(command->GetParameter(key));

      // if the parameter is defined add it to the parameter list
      if (!parameter)
      {
        return ParameterizedCommand::Pointer(0);
      }
      ParameterType::Pointer parameterType(command->GetParameterType(key));
      if (!parameterType)
      {
        std::string val(*(i->second.Cast<ObjectString>()));
        parms.push_back(Parameterization(parameter, val));
      }
      else
      {
        IParameterValueConverter::Pointer valueConverter(parameterType
            ->GetValueConverter());
        if (valueConverter)
        {
          std::string val(valueConverter->ConvertToString(i->second));
          parms.push_back(Parameterization(parameter, val));
        }
        else
        {
          std::string val(*(i->second.Cast<ObjectString>()));
          parms.push_back(Parameterization(parameter, val));
        }
      }
    }

    // convert the parameters to an Parameterization array and create
    // the command
    ParameterizedCommand::Pointer pCmd(new ParameterizedCommand(command, parms));
    return pCmd;
  }
  catch (const NotDefinedException* /*e*/)
  {
  }
  catch (const ParameterValueConversionException* /*e*/)
  {
  }
  return ParameterizedCommand::Pointer(0);
}
Example #10
0
void Test1(IDbSystem* pSystem, LPCTSTR pstrConnection)
{
   //pSystem->Initialize();

   CAutoPtr<IDbDatabase> pDb(pSystem->CreateDatabase());
   BOOL bRes;
   bRes = pDb->Open(NULL, pstrConnection, _T(""), _T(""), DB_OPEN_READ_ONLY);
   if( !bRes ) {
      TCHAR szMsg[256];
      pDb->GetErrors()->GetError(0)->GetMessage(szMsg, 256);
      ::MessageBox( NULL, szMsg, _T("Database Test"), MB_OK|MB_ICONERROR);
      return;
   }

   CAutoPtr<IDbRecordset> pRec(pSystem->CreateRecordset(pDb));
   bRes = pRec->Open(_T("SELECT * FROM [dbo].[tbStudy]"), DB_OPEN_TYPE_DYNASET);
   
   DWORD dwCnt = pRec->GetRowCount();
   dwCnt;

   while( !pRec->IsEOF() ) {
      long lID;
      TCHAR szTitle[128];
      float fUnitPrice;
      double dblUnitPrice;
      bool bDiscontinued;
      pRec->GetField(0, lID);
      pRec->GetField(1, szTitle, 128);
      pRec->GetField(2, fUnitPrice);
      pRec->GetField(2, dblUnitPrice);
      pRec->GetField(3, bDiscontinued);
      pRec->MoveNext();
      //DWORD dwRow = pRec->GetRowNumber();
   }

   {
     CAutoPtr<IDbCommand> pCmd(pSystem->CreateCommand(pDb));
     bRes = pCmd->Create(_T("EXEC [dcmqrdb].[dbo].[spRegisterDcmSeries] @studyUiid = ?, @seriesUiid = ?;"));

     bRes = pCmd->SetParam(0, _T("8888"));
     bRes = pCmd->SetParam(1, _T("9999"));


     CAutoPtr<IDbRecordset> pRec(pSystem->CreateRecordset(pDb));
     bRes = pCmd->Execute(pRec);
     while( !pRec->IsEOF() ) {
       long lID;
       TCHAR szTitle[128];
       pRec->GetField(0, lID);
       pRec->GetField(1, szTitle, 128);
       pRec->MoveNext();
     }
   }

   DWORD nFields = pRec->GetColumnCount();
   nFields;
   long iIndex = pRec->GetColumnIndex(_T("UnitPrice"));
   iIndex;

   pRec->Close();

   pDb->Close();

   //pSystem->Terminate();
}