Example #1
0
::CDB::longSeq * DAOImpl::get_long_seq (
	const char * propertyName
	
	)
{
	Field fld;
    if( !get_field(propertyName, fld) )
    {
		throw CDBFieldDoesNotExistExImpl (
			__FILE__, __LINE__,
			"DAOImpl::get_long").getCDBFieldDoesNotExistEx();
   }
  // I don't know why but it returns always an array of string
  if(fld.GetType() != Field::tyStringArray)
  {
		throw WrongCDBDataTypeExImpl (
			__FILE__, __LINE__,
			"DAOImpl::get_long").getWrongCDBDataTypeEx();
   }
 // create return value
 CDB::longSeq_var retSeq;
 try
     {
     retSeq = new CDB::longSeq();
     }
 catch(...)
     {
     throw CORBA::NO_MEMORY ();
     }//try-catch

 StringArray * ary = fld.GetStringArray();
  retSeq->length( ary->size() );
 CORBA::ULong n=0;
  for(StringArray::const_iterator aiter = ary->begin(); aiter != ary->end(); ++aiter) 
   {
      //retSeq[n++] = *aiter; //CORBA::long_dup( *aiter); //->c_str() );
      long lng;
      int parsed=sscanf(aiter->c_str(),"%ld",&lng);
      if (parsed==1) {
         retSeq[n++]=lng;
      } else {
         // The string doesn't contain a long: throw an exception
	  throw WrongCDBDataTypeExImpl (
		__FILE__, __LINE__,
		"DAOImpl::get_long").getWrongCDBDataTypeEx();
      }
 }
  
   return retSeq._retn();
}
Example #2
0
CDB::longSeq * DAOProxy::get_long_seq (const char * propertyName)
{
    //ACS_TRACE("cdb::DAOProxy::get_long_seq");

    // check remote mode
    if (m_dao.ptr() != CDB::DAO::_nil()) 
	return m_dao->get_long_seq(propertyName);

    string value;
    try{
    get_field(propertyName, value);
    }catch(cdbErrType::CDBFieldDoesNotExistExImpl ex){
	throw ex.getCDBFieldDoesNotExistEx();
    }

    VectorString array;
    split(value.c_str(), array);

    CDB::longSeq_var seq = new CDB::longSeq();
    seq->length(array.size());

    CORBA::ULong i = 0;
    for (VectorString::const_iterator iter = array.begin();
	 iter != array.end(); iter++)
	{
	std::istringstream is(iter->c_str());
	CORBA::Long val;
	(istream&) is >> val;
	if (!is)
		throw cdbErrType::WrongCDBDataTypeExImpl(
		__FILE__, __LINE__,
		"cdb::DAOProxy::get_long" ).getWrongCDBDataTypeEx();
	//    throw CDB::WrongDataType();
	seq[i++] = val;
	}

    return seq._retn();
}