CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes | Friends

FEConfigSpikeInfo Class Reference

#include <FEConfigSpikeInfo.h>

Inheritance diagram for FEConfigSpikeInfo:
IODConfig IDBObject

List of all members.

Public Member Functions

 FEConfigSpikeInfo ()
int fetchID () throw (std::runtime_error)
int fetchNextId () throw (std::runtime_error)
Tm getDBTime () const
int getId () const
int getID ()
std::string getTable ()
int getVersion () const
bool operator!= (const FEConfigSpikeInfo &r) const
bool operator== (const FEConfigSpikeInfo &r) const
void setByID (int id) throw (std::runtime_error)
void setDBTime (Tm x)
void setId (int id)
void setID (int id)
void setParameters (std::map< std::string, std::string > my_keys_map)
void setVersion (int id)
 ~FEConfigSpikeInfo ()

Private Member Functions

void clear ()
void fetchData (FEConfigSpikeInfo *result) throw (std::runtime_error)
void fetchLastData (FEConfigSpikeInfo *result) throw (std::runtime_error)
void prepareWrite () throw (std::runtime_error)
void writeDB () throw (std::runtime_error)

Private Attributes

Tm m_db_time
int m_ID
int m_version

Friends

class EcalCondDBInterface

Detailed Description

Definition at line 11 of file FEConfigSpikeInfo.h.


Constructor & Destructor Documentation

FEConfigSpikeInfo::FEConfigSpikeInfo ( )

Definition at line 13 of file FEConfigSpikeInfo.cc.

References NULL.

FEConfigSpikeInfo::~FEConfigSpikeInfo ( )

Definition at line 31 of file FEConfigSpikeInfo.cc.

{
}

Member Function Documentation

void FEConfigSpikeInfo::clear ( void  ) [private]

Definition at line 26 of file FEConfigSpikeInfo.cc.

                             {
}
void FEConfigSpikeInfo::fetchData ( FEConfigSpikeInfo result) throw (std::runtime_error) [private]

Definition at line 125 of file FEConfigSpikeInfo.cc.

References DateHandler::dateToTm(), and query::result.

{
  this->checkConnection();
  result->clear();
  if(result->getId()==0 && (result->getConfigTag()=="") ){
    throw(std::runtime_error("FEConfigSpikeInfo::fetchData(): no Id defined for this FEConfigSpikeInfo "));
  }

  try {
    DateHandler dh(m_env, m_conn);

    m_readStmt->setSQL("SELECT * FROM " + getTable() +   
                       " where ( spi_conf_id= :1 or (tag=:2 AND version=:3 ) )" );
    m_readStmt->setInt(1, result->getId());
    m_readStmt->setString(2, result->getConfigTag());
    m_readStmt->setInt(3, result->getVersion());
    ResultSet* rset = m_readStmt->executeQuery();

    rset->next();

    // 1 is the id and 2 is the config tag and 3 is the version

    result->setId(rset->getInt(1));
    result->setConfigTag(rset->getString(2));
    result->setVersion(rset->getInt(3));
    Date dbdate = rset->getDate(4);
    result->setDBTime( dh.dateToTm( dbdate ));

  } catch (SQLException &e) {
    throw(std::runtime_error("FEConfigSpikeInfo::fetchData():  "+e.getMessage()));
  }
}
int FEConfigSpikeInfo::fetchID ( ) throw (std::runtime_error)

Definition at line 184 of file FEConfigSpikeInfo.cc.

{
  // Return from memory if available
  if (m_ID!=0) {
    return m_ID;
  }

  this->checkConnection();

  try {
    Statement* stmt = m_conn->createStatement();
    stmt->setSQL("SELECT spi_conf_id FROM "+ getTable()+
                 " WHERE  tag=:1 and version=:2 " );

    stmt->setString(1, getConfigTag() );
    stmt->setInt(2, getVersion() );

    ResultSet* rset = stmt->executeQuery();

    if (rset->next()) {
      m_ID = rset->getInt(1);
    } else {
      m_ID = 0;
    }
    m_conn->terminateStatement(stmt);
  } catch (SQLException &e) {
    throw(std::runtime_error("FEConfigSpikeInfo::fetchID:  "+e.getMessage()));
  }

  return m_ID;
}
void FEConfigSpikeInfo::fetchLastData ( FEConfigSpikeInfo result) throw (std::runtime_error) [private]

Definition at line 159 of file FEConfigSpikeInfo.cc.

References DateHandler::dateToTm(), and query::result.

{
  this->checkConnection();
  result->clear();
  try {
    DateHandler dh(m_env, m_conn);

    m_readStmt->setSQL("SELECT * FROM " + getTable() +   
                       " where   spi_conf_id = ( select max( spi_conf_id) from "+ getTable() +" ) " );
    ResultSet* rset = m_readStmt->executeQuery();

    rset->next();

    result->setId(rset->getInt(1));
    result->setConfigTag(rset->getString(2));
    result->setVersion(rset->getInt(3));
    Date dbdate = rset->getDate(4);
    result->setDBTime( dh.dateToTm( dbdate ));

  } catch (SQLException &e) {
    throw(std::runtime_error("FEConfigSpikeInfo::fetchData():  "+e.getMessage()));
  }
}
int FEConfigSpikeInfo::fetchNextId ( ) throw (std::runtime_error)

Definition at line 37 of file FEConfigSpikeInfo.cc.

References query::result.

                                                            {

  int result=0;
  try {
    this->checkConnection();

    m_readStmt = m_conn->createStatement(); 
    m_readStmt->setSQL("select FE_CONFIG_SPI_SQ.NextVal from DUAL ");
    ResultSet* rset = m_readStmt->executeQuery();
    while (rset->next ()){
      result= rset->getInt(1);
    }
    result++;
    m_conn->terminateStatement(m_readStmt);
    return result; 

  } catch (SQLException &e) {
    throw(std::runtime_error("FEConfigSpikeInfo::fetchNextId():  "+e.getMessage()));
  }

}
Tm FEConfigSpikeInfo::getDBTime ( ) const [inline]

Definition at line 31 of file FEConfigSpikeInfo.h.

References m_db_time.

{  return m_db_time;}
int FEConfigSpikeInfo::getID ( ) [inline]

Definition at line 25 of file FEConfigSpikeInfo.h.

References getId().

{ return getId() ;}
int FEConfigSpikeInfo::getId ( ) const [inline]

Definition at line 22 of file FEConfigSpikeInfo.h.

References m_ID.

Referenced by getID(), and EcalTPGDBApp::writeToConfDB_Spike().

{ return m_ID; }
std::string FEConfigSpikeInfo::getTable ( ) [inline, virtual]

Implements IODConfig.

Definition at line 19 of file FEConfigSpikeInfo.h.

{ return "FE_CONFIG_SPIKE_INFO"; }
int FEConfigSpikeInfo::getVersion ( ) const [inline]

Definition at line 28 of file FEConfigSpikeInfo.h.

References m_version.

{ return m_version; }
bool FEConfigSpikeInfo::operator!= ( const FEConfigSpikeInfo r) const [inline]

Definition at line 43 of file FEConfigSpikeInfo.h.

References csvReporter::r.

{ return !(*this == r); }
bool FEConfigSpikeInfo::operator== ( const FEConfigSpikeInfo r) const [inline]

Definition at line 42 of file FEConfigSpikeInfo.h.

References m_ID.

{  return (m_ID   == r.m_ID ); }
void FEConfigSpikeInfo::prepareWrite ( ) throw (std::runtime_error) [private, virtual]

Implements IODConfig.

Definition at line 59 of file FEConfigSpikeInfo.cc.

References getId().

{
  this->checkConnection();

  int next_id=0;
  if(getId()==0){
    next_id=fetchNextId();
  }

  try {
    m_writeStmt = m_conn->createStatement();
    m_writeStmt->setSQL("INSERT INTO "+getTable()+" ( spi_conf_id, tag, version ) " 
                        " VALUES ( :1, :2, :3 ) " );

    m_writeStmt->setInt(1, next_id);
    m_ID=next_id;

  } catch (SQLException &e) {
    throw(std::runtime_error("FEConfigSpikeInfo::prepareWrite():  "+e.getMessage()));
  }

}
void FEConfigSpikeInfo::setByID ( int  id) throw (std::runtime_error)

Definition at line 218 of file FEConfigSpikeInfo.cc.

References DateHandler::dateToTm().

{
   this->checkConnection();

   DateHandler dh(m_env, m_conn);

   try {
     Statement* stmt = m_conn->createStatement();

     stmt->setSQL("SELECT * FROM "+ getTable()+" WHERE spi_conf_id = :1");
     stmt->setInt(1, id);
     
     ResultSet* rset = stmt->executeQuery();
     if (rset->next()) {
       this->setId(rset->getInt(1));
       this->setConfigTag(rset->getString(2));
       this->setVersion(rset->getInt(3));
       Date dbdate = rset->getDate(4);
       this->setDBTime( dh.dateToTm( dbdate ));
     } else {
       throw(std::runtime_error("FEConfigSpikeInfo::setByID: Given spi_conf_id is not in the database"));
     }
     
     m_conn->terminateStatement(stmt);
   } catch (SQLException &e) {
     throw(std::runtime_error("FEConfigSpikeInfo::setByID:  "+e.getMessage()));
   }
}
void FEConfigSpikeInfo::setDBTime ( Tm  x) [inline]

Definition at line 32 of file FEConfigSpikeInfo.h.

References m_db_time, and x.

{ m_db_time=x; } 
void FEConfigSpikeInfo::setID ( int  id) [inline]

Definition at line 24 of file FEConfigSpikeInfo.h.

References setId().

{setId(id);} 
void FEConfigSpikeInfo::setId ( int  id) [inline]

Definition at line 21 of file FEConfigSpikeInfo.h.

References m_ID.

Referenced by popcon::EcalTPGSpikeThresholdHandler::getNewObjects(), and setID().

{ m_ID = id; }
void FEConfigSpikeInfo::setParameters ( std::map< std::string, std::string >  my_keys_map)
void FEConfigSpikeInfo::setVersion ( int  id) [inline]

Definition at line 27 of file FEConfigSpikeInfo.h.

References m_version.

{ m_version = id; }
void FEConfigSpikeInfo::writeDB ( ) throw (std::runtime_error) [private]

Definition at line 98 of file FEConfigSpikeInfo.cc.

{
  this->checkConnection();
  this->checkPrepare();

  try {

    // number 1 is the id 
    m_writeStmt->setString(2, this->getConfigTag());
    m_writeStmt->setInt(3, this->getVersion());

    m_writeStmt->executeUpdate();


  } catch (SQLException &e) {
    throw(std::runtime_error("FEConfigSpikeInfo::writeDB():  "+e.getMessage()));
  }
  // Now get the ID
  if (!this->fetchID()) {
    throw(std::runtime_error("FEConfigSpikeInfo::writeDB:  Failed to write"));
  }


}

Friends And Related Function Documentation

friend class EcalCondDBInterface [friend]

Reimplemented from IDBObject.

Definition at line 13 of file FEConfigSpikeInfo.h.


Member Data Documentation

Definition at line 49 of file FEConfigSpikeInfo.h.

Referenced by getDBTime(), and setDBTime().

int FEConfigSpikeInfo::m_ID [private]

Definition at line 48 of file FEConfigSpikeInfo.h.

Referenced by getId(), operator==(), and setId().

Definition at line 50 of file FEConfigSpikeInfo.h.

Referenced by getVersion(), and setVersion().