test
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_mapping( mapping ),
21  m_columnIndex(-1),
22  m_schema( contSchema ),
23  m_dataElement( 0 ),
24  m_relationalData( 0 ),
25  m_relationalBuffer( 0 ),
26  m_blobWriter( 0 ),
27  m_useCompression( true ){
28 }
29 
31 }
32 
34  IRelationalData& relationalData,
35  RelationalBuffer& operationBuffer){
36  if( m_mapping.columnNames().size() == 0 ){
37  throwException( "The mapping element does not contain columns.",
38  "BlobWriterBase::build");
39  }
40 
41  m_dataElement = &dataElement;
42  std::string columnName = m_mapping.columnNames()[0];
43  m_columnIndex = relationalData.addBlobData( columnName );
44  m_relationalData = &relationalData;
45  m_relationalBuffer = &operationBuffer;
46  m_blobWriter = m_schema.blobStreamingService();
47  if(!m_blobWriter){
48  throwException("Blob Streaming Service is not installed.",
49  "BlobWriterBase::::build");
50  }
51  if( m_schema.dbSession().schema().mainTable().schemaVersion()==poolSchemaVersion() ) m_useCompression = false;
52  return true;
53 }
54 
55 void ora::BlobWriterBase::bindData( const void* data ){
56  if( ! m_dataElement ){
57  throwException( "The streamer has not been built.",
58  "BlobWriterBase::bindData");
59  }
60  void* dataElementAddress = m_dataElement->address( data );
61  coral::Attribute& relDataElement = m_relationalData->data()[ m_columnIndex ];
62  boost::shared_ptr<coral::Blob> blobData = m_blobWriter->write( dataElementAddress, m_objectType, m_useCompression );
63  m_relationalBuffer->storeBlob( blobData );
64  relDataElement.bind<coral::Blob>( *blobData );
65 }
66 
68  MappingElement& mapping,
69  ContainerSchema& contSchema ):
70  BlobWriterBase( objectType, mapping, contSchema ){
71 }
72 
74 }
75 
77  IRelationalData& relationalData,
78  RelationalBuffer& relationalBuffer ){
79  return buildDataElement( dataElement, relationalData, relationalBuffer );
80 }
81 
82 void ora::BlobWriter::setRecordId( const std::vector<int>& ){
83 }
84 
86  const void* data ){
87  bindData( data );
88 }
89 
91  MappingElement& mapping,
92  ContainerSchema& contSchema ):
93  BlobWriterBase( objectType, mapping, contSchema ){
94 }
95 
97 }
98 
100  IRelationalData& relationalData,
101  RelationalBuffer& relationalBuffer){
102  return buildDataElement( dataElement, relationalData, relationalBuffer );
103 }
104 
105 void ora::BlobUpdater::setRecordId( const std::vector<int>& ){
106 }
107 
109  const void* data ){
110  bindData( data );
111 }
112 
113 
115  MappingElement& mapping,
116  ContainerSchema& contSchema ):
117  m_objectType( objectType ),
118  m_mapping( mapping ),
119  m_columnIndex( -1 ),
120  m_schema( contSchema ),
121  m_dataElement( 0 ),
122  m_relationalData( 0 ),
123  m_blobReader( 0 ){
124 }
125 
127 }
128 
130  IRelationalData& relationalData){
131 
132  if( m_mapping.columnNames().size() == 0 ){
133  throwException( "The mapping element does not contain columns.",
134  "BlobReader::build");
135  }
136 
137  m_dataElement = &dataElement;
138  std::string columnName = m_mapping.columnNames()[0];
139  m_columnIndex = relationalData.addBlobData( columnName );
140  m_relationalData = &relationalData;
141  m_blobReader = m_schema.blobStreamingService();
142  if(!m_blobReader){
143  throwException("Blob Streaming Service is not installed.",
144  "BlobReader::build");
145  }
146  return true;
147 }
148 
150 }
151 
152 void ora::BlobReader::setRecordId( const std::vector<int>& ){
153 }
154 
156  if( ! m_dataElement ){
157  throwException( "The streamer has not been built.",
158  "BlobReader::read");
159  }
160  void* dataElementAddress = m_dataElement->address( data );
161  coral::Attribute& relDataElement = m_relationalData->data()[ m_columnIndex ];
162  m_blobReader->read(relDataElement.data<coral::Blob>(), dataElementAddress, m_objectType );
163 }
164 
166 }
167 
169  MappingElement& mapping,
170  ContainerSchema& contSchema ):
171  m_objectType( objectType ),
172  m_mapping( mapping ),
173  m_schema( contSchema ){
174 }
175 
177 }
178 
180  return new BlobWriter( m_objectType, m_mapping, m_schema );
181 }
182 
184  return new BlobUpdater( m_objectType, m_mapping, m_schema );
185 }
186 
188  return new BlobReader( m_objectType, m_mapping, m_schema );
189 }
virtual ~BlobWriterBase()
Definition: BlobStreamer.cc:30
bool buildDataElement(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
Definition: BlobStreamer.cc:33
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)
virtual int addBlobData(const std::string &columnName)=0
void bindData(const void *data)
Definition: BlobStreamer.cc:55
bool build(DataElement &dataElement, IRelationalData &relationalData)
std::string poolSchemaVersion()
virtual ~BlobUpdater()
Definition: BlobStreamer.cc:96
virtual ~BlobWriter()
Definition: BlobStreamer.cc:73
void update(int oid, const void *data)
Updates a data element.
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
Definition: BlobStreamer.cc:99
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
Definition: BlobStreamer.cc:76
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:82
IRelationalWriter * newWriter()
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
IRelationalReader * newReader()
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
virtual ~BlobReader()
BlobWriter(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
Definition: BlobStreamer.cc:67
BlobUpdater(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
Definition: BlobStreamer.cc:90
void write(int oid, const void *data)
Writes a data element.
Definition: BlobStreamer.cc:85