Пример #1
0
void LLMutex::lock_main(LLFastTimer::DeclareTimer* timer)
{
	llassert(!isSelfLocked());
	LLFastTimer ft1(timer ? *timer : FT_WAIT_FOR_MUTEX);
	LLMutexImpl::lock();
}
Пример #2
0
/**
    \brief Saves the object to the storage system.

    If the object is new then a new record will be inserted into the
    storage system. Existing objects will be updated if any of the storable
    properties were changed.

    \throw xeInvalidStorable If the object is not valid an
                             xeInvalidStorable will be thrown.
 */
void xtStorable::save()
{
  if(!isValid())
    throw xeInvalidStorable(*this);

  if(isLocked() && !isSelfLocked())
    throw std::runtime_error("cannot save this object as it has been locked by someone else.");

  if(isDeleted())
  {
    doDelete();
    return;
  }

  std::map<std::string, QVariant> changed;
  std::set<std::string> fieldnames = getPropertyNames(xtlib::FieldRole);
  for (std::set<std::string>::const_iterator it = fieldnames.begin();
       it != fieldnames.end();
       it++)
  {
    if(! xtAnyUtility::equal(getProperty(*it),
                             getProperty(*it, xtlib::PreviousValueRole)))
      changed.insert(std::pair<std::string, QVariant>(*it, getProperty(*it)));
  }

  if(changed.size())
  {
    _data->_enforceReadOnly = false;
    QString tuser = QString::fromStdString(xtSecurity::logicalUser());
    setProperty("modifier", tuser);
    changed.insert(std::pair<std::string, QVariant>("modifier", tuser));
    QDateTime newt = QDateTime::currentDateTime();
    setProperty("modified", newt);
    changed.insert(std::pair<std::string, QVariant>("modified", newt));
    _data->_enforceReadOnly = true;
    std::string sql;
    if(_data->_id)
    {
      sql = "UPDATE \"";
      sql += _data->_tableName;
      sql += "\" SET ";
      int colcnt = 0;
      for (std::map<std::string, QVariant>::iterator it = changed.begin();
           it != changed.end();
           it++, colcnt++)
      {
        QVariant pFieldData = getProperty((*it).first, xtlib::FieldRole);
        xtFieldData fd = pFieldData.value<xtFieldData>();
        std::string fieldName = _data->_prefix + fd.fieldName;
        if(colcnt)
          sql += ", ";
        sql += "\"" + fieldName;
        sql += "\"='" + xtAnyUtility::toString((*it).second) + "'";
      }
      sql += " WHERE (" + _data->_prefix + "id='";
      sql += QString::number(_data->_id).toStdString();
      sql += "');";
    }
    else
    {
      _data->_enforceReadOnly = false;
      setProperty("creator", tuser);
      changed.insert(std::pair<std::string, QVariant>("creator", tuser));
      setProperty("created", newt);
      changed.insert(std::pair<std::string, QVariant>("created", newt));
      _data->_enforceReadOnly = true;
      sql = "INSERT INTO \"";
      sql += _data->_tableName;
      sql += "\" (";

      int colcnt = 0;
      std::string values;

      for (std::map<std::string, QVariant>::iterator it = changed.begin();
           it != changed.end();
           it++, colcnt++)
      {
        QVariant pFieldData = getProperty((*it).first, xtlib::FieldRole);
        xtFieldData fd = pFieldData.value<xtFieldData>();
        std::string fieldName = _data->_prefix + fd.fieldName;
        if(colcnt)
        {
          sql    += ", ";
          values += ", ";
        }
        sql     += "\"" + fieldName  + "\"";
        values  += "'"  + xtAnyUtility::toString((*it).second) + "'";
      }
      sql += ") VALUES (";
      sql += values;
      sql += ") RETURNING " + _data->_prefix + "id;";
    }

    if(xtlib::debug)
      qDebug() << "executing: " << QString::fromStdString(sql);
    QSqlQuery query;
    query.exec(QString::fromStdString(sql));
    if(query.first())
      _data->_id = query.value(query.record().indexOf(QString::fromStdString(_data->_prefix) + "id")).toLongLong();

    load(_data->_id);
  }
}