00001 #include "CondCore/ORA/interface/Exception.h"
00002 #include "InlineCArrayStreamer.h"
00003 #include "DataElement.h"
00004 #include "MappingElement.h"
00005 #include "RelationalOperation.h"
00006 #include "MappingRules.h"
00007 #include "ClassUtils.h"
00008
00009 #include "CoralBase/Attribute.h"
00010
00011
00012 ora::InlineCArrayStreamerBase::InlineCArrayStreamerBase( const Reflex::Type& objectType,
00013 MappingElement& mapping,
00014 ContainerSchema& contSchema):
00015 m_objectType( objectType ),
00016 m_arrayType(),
00017 m_streamerFactory( contSchema ),
00018 m_mapping( mapping ){
00019 }
00020
00021 ora::InlineCArrayStreamerBase::~InlineCArrayStreamerBase(){
00022 }
00023
00024
00025 bool ora::InlineCArrayStreamerBase::buildDataElement(DataElement& dataElement,
00026 IRelationalData& relationalData,
00027 RelationalBuffer* operationBuffer){
00028 m_arrayType = ClassUtils::resolvedType( m_objectType.ToType() );
00029 if ( ! m_arrayType ) {
00030 throwException( "Missing dictionary information for the element of array \"" +
00031 m_objectType.Name(Reflex::SCOPED) + "\"",
00032 "InlineCArrayStreamerBase::buildDataElement" );
00033 }
00034
00035 for ( unsigned int i=0;i<m_objectType.ArrayLength();i++){
00036
00037
00038 std::string arrayElementLabel = MappingRules::variableNameForArrayIndex( m_mapping.variableName(),i);
00039
00040
00041 MappingElement::iterator iMe = m_mapping.find( arrayElementLabel );
00042 if ( iMe == m_mapping.end() ) {
00043 throwException( "Mapping for Array Element \"" + arrayElementLabel + "\" not found in the mapping element",
00044 "InlineCArrayStreamerBase::buildDataElement" );
00045 }
00046 MappingElement& arrayElementMapping = iMe->second;
00047 DataElement& arrayElement = dataElement.addChild( i*m_arrayType.SizeOf(), 0 );
00048
00049 processArrayElement( arrayElement, relationalData, arrayElementMapping, operationBuffer );
00050 }
00051 return true;
00052 }
00053
00054 ora::InlineCArrayWriter::InlineCArrayWriter( const Reflex::Type& objectType,
00055 MappingElement& mapping,
00056 ContainerSchema& contSchema ):
00057 InlineCArrayStreamerBase( objectType, mapping, contSchema ),
00058 m_writers(){
00059 }
00060
00061 ora::InlineCArrayWriter::~InlineCArrayWriter(){
00062 for( std::vector< IRelationalWriter* >::iterator iW = m_writers.begin();
00063 iW != m_writers.end(); ++iW ){
00064 delete *iW;
00065 }
00066 m_writers.clear();
00067 }
00068
00069 void ora::InlineCArrayWriter::processArrayElement( DataElement& arrayElementOffset,
00070 IRelationalData& relationalData,
00071 MappingElement& arrayElementMapping,
00072 RelationalBuffer* operationBuffer ){
00073 IRelationalWriter* arrayElementWriter = m_streamerFactory.newWriter( m_arrayType, arrayElementMapping );
00074 m_writers.push_back( arrayElementWriter );
00075 arrayElementWriter->build( arrayElementOffset, relationalData, *operationBuffer );
00076 }
00077
00078 bool ora::InlineCArrayWriter::build(DataElement& dataElement,
00079 IRelationalData& relationalData,
00080 RelationalBuffer& operationBuffer){
00081 return buildDataElement( dataElement, relationalData, &operationBuffer );
00082 }
00083
00084 void ora::InlineCArrayWriter::setRecordId( const std::vector<int>& identity ){
00085 for( std::vector< IRelationalWriter* >::iterator iW = m_writers.begin();
00086 iW != m_writers.end(); ++iW ){
00087 (*iW)->setRecordId( identity );
00088 }
00089 }
00090
00091 void ora::InlineCArrayWriter::write( int oid, const void* data ){
00092 for( std::vector< IRelationalWriter* >::iterator iW = m_writers.begin();
00093 iW != m_writers.end(); ++iW ){
00094 (*iW)->write( oid, data );
00095 }
00096 }
00097
00098 ora::InlineCArrayUpdater::InlineCArrayUpdater( const Reflex::Type& objectType,
00099 MappingElement& mapping,
00100 ContainerSchema& contSchema ):
00101 InlineCArrayStreamerBase( objectType, mapping, contSchema ),
00102 m_updaters(){
00103 }
00104
00105 ora::InlineCArrayUpdater::~InlineCArrayUpdater(){
00106 for( std::vector< IRelationalUpdater* >::iterator iU = m_updaters.begin();
00107 iU != m_updaters.end(); ++iU ){
00108 delete *iU;
00109 }
00110 m_updaters.clear();
00111 }
00112
00113 void ora::InlineCArrayUpdater::processArrayElement( DataElement& arrayElementOffset,
00114 IRelationalData& relationalData,
00115 MappingElement& arrayElementMapping,
00116 RelationalBuffer* operationBuffer ){
00117 IRelationalUpdater* arrayElementUpdater = m_streamerFactory.newUpdater( m_arrayType, arrayElementMapping );
00118 m_updaters.push_back( arrayElementUpdater );
00119 arrayElementUpdater->build( arrayElementOffset, relationalData, *operationBuffer );
00120 }
00121
00122 bool ora::InlineCArrayUpdater::build(DataElement& dataElement,
00123 IRelationalData& relationalData,
00124 RelationalBuffer& operationBuffer){
00125 return buildDataElement( dataElement, relationalData, &operationBuffer );
00126 }
00127
00128 void ora::InlineCArrayUpdater::setRecordId( const std::vector<int>& identity ){
00129 for( std::vector< IRelationalUpdater* >::iterator iU = m_updaters.begin();
00130 iU != m_updaters.end(); ++iU){
00131 (*iU)->setRecordId( identity );
00132 }
00133 }
00134
00135 void ora::InlineCArrayUpdater::update( int oid,
00136 const void* data ){
00137 for( std::vector< IRelationalUpdater* >::iterator iU = m_updaters.begin();
00138 iU != m_updaters.end(); ++iU ){
00139 (*iU)->update( oid, data );
00140 }
00141 }
00142
00143 ora::InlineCArrayReader::InlineCArrayReader( const Reflex::Type& objectType,
00144 MappingElement& mapping,
00145 ContainerSchema& contSchema ):
00146 InlineCArrayStreamerBase( objectType, mapping, contSchema ),
00147 m_readers(){
00148 }
00149
00150 ora::InlineCArrayReader::~InlineCArrayReader(){
00151 for( std::vector< IRelationalReader* >::iterator iStr = m_readers.begin();
00152 iStr != m_readers.end(); ++iStr ){
00153 delete *iStr;
00154 }
00155 m_readers.clear();
00156 }
00157
00158 void ora::InlineCArrayReader::processArrayElement( DataElement& arrayElementOffset,
00159 IRelationalData& relationalData,
00160 MappingElement& arrayElementMapping,
00161 RelationalBuffer*){
00162 IRelationalReader* arrayElementReader = m_streamerFactory.newReader( m_arrayType, arrayElementMapping );
00163 m_readers.push_back( arrayElementReader );
00164 arrayElementReader->build( arrayElementOffset, relationalData );
00165 }
00166
00167 bool ora::InlineCArrayReader::build(DataElement& dataElement,
00168 IRelationalData& relationalData){
00169 return buildDataElement( dataElement, relationalData, 0 );
00170 }
00171
00172 void ora::InlineCArrayReader::select( int oid){
00173 for( std::vector< IRelationalReader* >::iterator iDepReader = m_readers.begin();
00174 iDepReader != m_readers.end(); ++iDepReader ){
00175 (*iDepReader)->select( oid );
00176 }
00177 }
00178
00179 void ora::InlineCArrayReader::setRecordId( const std::vector<int>& identity ){
00180 for( std::vector< IRelationalReader* >::iterator iDepReader = m_readers.begin();
00181 iDepReader != m_readers.end(); ++iDepReader ){
00182 (*iDepReader)->setRecordId( identity );
00183 }
00184 }
00185
00186 void ora::InlineCArrayReader::read( void* data ){
00187 for( std::vector< IRelationalReader* >::iterator iDepReader = m_readers.begin();
00188 iDepReader != m_readers.end(); ++iDepReader ){
00189 (*iDepReader)->read( data );
00190 }
00191 }
00192
00193 void ora::InlineCArrayReader::clear(){
00194 for( std::vector< IRelationalReader* >::iterator iDepReader = m_readers.begin();
00195 iDepReader != m_readers.end(); ++iDepReader ){
00196 (*iDepReader)->clear();
00197 }
00198 }
00199
00200 ora::InlineCArrayStreamer::InlineCArrayStreamer( const Reflex::Type& objectType,
00201 MappingElement& mapping,
00202 ContainerSchema& schema ):
00203 m_objectType( objectType ),
00204 m_mapping( mapping ),
00205 m_schema( schema ){
00206 }
00207
00208 ora::InlineCArrayStreamer::~InlineCArrayStreamer(){
00209 }
00210
00211 ora::IRelationalWriter* ora::InlineCArrayStreamer::newWriter(){
00212 return new InlineCArrayWriter( m_objectType, m_mapping, m_schema );
00213 }
00214
00215 ora::IRelationalUpdater* ora::InlineCArrayStreamer::newUpdater(){
00216 return new InlineCArrayUpdater( m_objectType, m_mapping, m_schema );
00217 }
00218
00219 ora::IRelationalReader* ora::InlineCArrayStreamer::newReader(){
00220 return new InlineCArrayReader( m_objectType, m_mapping, m_schema );
00221 }