CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BlobStreamer.cc
Go to the documentation of this file.
3 #include "DatabaseSession.h"
4 #include "IDatabaseSchema.h"
5 #include "BlobStreamer.h"
6 #include "DataElement.h"
7 #include "MappingElement.h"
8 #include "RelationalOperation.h"
9 #include "RelationalBuffer.h"
10 #include "ContainerSchema.h"
11 #include "ClassUtils.h"
12 // externals
13 #include "CoralBase/Attribute.h"
14 #include "CoralBase/Blob.h"
15 
17  MappingElement& mapping,
18  ContainerSchema& contSchema ):
19  m_objectType( objectType ),
20  m_columnName( "" ),
21  m_schema( contSchema ),
22  m_dataElement( 0 ),
23  m_relationalData( 0 ),
24  m_relationalBuffer( 0 ),
25  m_blobWriter( 0 ),
26  m_useCompression( true ){
27 
28  if( mapping.columnNames().size() ){
29  m_columnName = mapping.columnNames()[0];
30  }
31 }
32 
34 }
35 
37  IRelationalData& relationalData,
38  RelationalBuffer& operationBuffer){
39  if( m_columnName.empty() ){
40  throwException( "Column name not found ",
41  "BlobWriterBase::build");
42  }
43 
44  m_dataElement = &dataElement;
45  relationalData.addBlobData( m_columnName );
46  m_relationalData = &relationalData;
47  m_relationalBuffer = &operationBuffer;
48  m_blobWriter = m_schema.blobStreamingService();
49  if(!m_blobWriter){
50  throwException("Blob Streaming Service is not installed.",
51  "BlobWriterBase::::build");
52  }
53  if( m_schema.dbSession().schema().mainTable().schemaVersion()==poolSchemaVersion() ) m_useCompression = false;
54  return true;
55 }
56 
57 void ora::BlobWriterBase::bindData( const void* data ){
58  if( ! m_dataElement ){
59  throwException( "The streamer has not been built.",
60  "BlobWriterBase::bindData");
61  }
62  void* dataElementAddress = m_dataElement->address( data );
63  coral::Attribute& relDataElement = m_relationalData->data()[ m_columnName ];
64  boost::shared_ptr<coral::Blob> blobData = m_blobWriter->write( dataElementAddress, m_objectType, m_useCompression );
65  m_relationalBuffer->storeBlob( blobData );
66  relDataElement.bind<coral::Blob>( *blobData );
67 }
68 
70  MappingElement& mapping,
71  ContainerSchema& contSchema ):
72  BlobWriterBase( objectType, mapping, contSchema ){
73 }
74 
76 }
77 
79  IRelationalData& relationalData,
80  RelationalBuffer& relationalBuffer ){
81  return buildDataElement( dataElement, relationalData, relationalBuffer );
82 }
83 
84 void ora::BlobWriter::setRecordId( const std::vector<int>& ){
85 }
86 
88  const void* data ){
89  bindData( data );
90 }
91 
93  MappingElement& mapping,
94  ContainerSchema& contSchema ):
95  BlobWriterBase( objectType, mapping, contSchema ){
96 }
97 
99 }
100 
102  IRelationalData& relationalData,
103  RelationalBuffer& relationalBuffer){
104  return buildDataElement( dataElement, relationalData, relationalBuffer );
105 }
106 
107 void ora::BlobUpdater::setRecordId( const std::vector<int>& ){
108 }
109 
111  const void* data ){
112  bindData( data );
113 }
114 
115 
117  MappingElement& mapping,
118  ContainerSchema& contSchema ):
119  m_objectType( objectType ),
120  m_columnName( "" ),
121  m_schema( contSchema ),
122  m_dataElement( 0 ),
123  m_relationalData( 0 ),
124  m_blobReader( 0 ){
125 
126  if( mapping.columnNames().size() ){
127  m_columnName = mapping.columnNames()[0];
128  }
129 }
130 
132 }
133 
135  IRelationalData& relationalData){
136 
137  if( m_columnName.empty() ){
138  throwException( "Column name not found ",
139  "BlobReader::build");
140  }
141 
142  m_dataElement = &dataElement;
143  relationalData.addBlobData( m_columnName );
144  m_relationalData = &relationalData;
145  m_blobReader = m_schema.blobStreamingService();
146  if(!m_blobReader){
147  throwException("Blob Streaming Service is not installed.",
148  "BlobReader::build");
149  }
150  return true;
151 }
152 
154 }
155 
156 void ora::BlobReader::setRecordId( const std::vector<int>& ){
157 }
158 
160  if( ! m_dataElement ){
161  throwException( "The streamer has not been built.",
162  "BlobReader::read");
163  }
164  void* dataElementAddress = m_dataElement->address( data );
165  coral::Attribute& relDataElement = m_relationalData->data()[ m_columnName ];
166  m_blobReader->read(relDataElement.data<coral::Blob>(), dataElementAddress, m_objectType );
167 }
168 
170 }
171 
173  MappingElement& mapping,
174  ContainerSchema& contSchema ):
175  m_objectType( objectType ),
176  m_mapping( mapping ),
177  m_schema( contSchema ){
178 }
179 
181 }
182 
184  return new BlobWriter( m_objectType, m_mapping, m_schema );
185 }
186 
188  return new BlobUpdater( m_objectType, m_mapping, m_schema );
189 }
190 
192  return new BlobReader( m_objectType, m_mapping, m_schema );
193 }
virtual ~BlobWriterBase()
Definition: BlobStreamer.cc:33
bool buildDataElement(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
Definition: BlobStreamer.cc:36
BlobStreamer(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
BlobWriterBase(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
Definition: BlobStreamer.cc:16
void setRecordId(const std::vector< int > &identity)
void bindData(const void *data)
Definition: BlobStreamer.cc:57
bool build(DataElement &dataElement, IRelationalData &relationalData)
std::string poolSchemaVersion()
virtual ~BlobUpdater()
Definition: BlobStreamer.cc:98
virtual ~BlobWriter()
Definition: BlobStreamer.cc:75
void update(int oid, const void *data)
Updates a data element.
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
Definition: BlobStreamer.cc:78
std::string m_columnName
Definition: BlobStreamer.h:89
const std::vector< std::string > & columnNames() const
void select(int oid)
IRelationalUpdater * newUpdater()
void read(void *data)
Reads a data element.
void setRecordId(const std::vector< int > &identity)
BlobReader(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
void setRecordId(const std::vector< int > &identity)
Definition: BlobStreamer.cc:84
IRelationalWriter * newWriter()
std::string m_columnName
Definition: BlobStreamer.h:28
IRelationalReader * newReader()
virtual ~BlobReader()
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
BlobWriter(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
Definition: BlobStreamer.cc:69
virtual void addBlobData(const std::string &columnName)=0
BlobUpdater(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
Definition: BlobStreamer.cc:92
void write(int oid, const void *data)
Writes a data element.
Definition: BlobStreamer.cc:87