CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RelationalStreamerFactory.cc
Go to the documentation of this file.
3 #include "MappingElement.h"
4 #include "ClassUtils.h"
5 #include "PrimitiveStreamer.h"
6 #include "BlobStreamer.h"
7 #include "ObjectStreamer.h"
8 #include "STLContainerStreamer.h"
9 #include "CArrayStreamer.h"
10 #include "InlineCArrayStreamer.h"
11 #include "OraReferenceStreamer.h"
12 #include "NamedRefStreamer.h"
13 #include "OraPtrStreamer.h"
14 #include "PVectorStreamer.h"
16 #include "UniqueRefStreamer.h"
17 //
18 #include <memory>
19 
21  m_containerSchema( contSchema ){
22 }
23 
25 }
26 
28  MappingElement& mapping ){
29  IRelationalStreamer* newStreamer = 0;
30  if ( mapping.elementType() == MappingElement::Primitive ) { // Primitives
31  if( ! ClassUtils::isTypePrimitive( type ) ){
32  throwException( "Mapped variable \"" + mapping.variableName() +
33  "\", declared as Primitive, is associated to non-primitive type \""+type.Name()+"\"",
34  "RelationalStreamerFactory::newStreamer" );
35  }
36  newStreamer = new PrimitiveStreamer( type, mapping );
37  } else if ( mapping.elementType() == MappingElement::Blob ){
38  newStreamer = new BlobStreamer( type, mapping, m_containerSchema );
39  } else if ( mapping.elementType() == MappingElement::Object ){
40  newStreamer = new ObjectStreamer( type, mapping, m_containerSchema );
41  } else if ( mapping.elementType() == MappingElement::Array ){
42  if ( !ClassUtils::isTypeContainer( type ) ) {
43  throwException( "Mapped variable \"" + mapping.variableName() +" of type "+
44  mapping.variableType() +
45  "\", declared as Array, is associated to the non-container type \""+
46  type.Name()+"\".",
47  "RelationalStreamerFactory::newStreamer" );
48  }
49  newStreamer = new STLContainerStreamer( type, mapping, m_containerSchema );
50  } else if ( mapping.elementType() == MappingElement::CArray ) {
51  if ( ! type.IsArray() ) {
52  throwException( "Mapped variable \"" + mapping.variableName() +" of type "+
53  mapping.variableType() +
54  "\", declared as C-Array, is associated to the non-array type \""+
55  type.Name()+"\".",
56  "RelationalStreamerFactory::newStreamer" );
57  }
58  newStreamer = new CArrayStreamer( type, mapping, m_containerSchema );
59  } else if ( mapping.elementType() == MappingElement::InlineCArray ) {
60  if ( ! type.IsArray() ) {
61  throwException( "Mapped variable \"" + mapping.variableName() +" of type "+
62  mapping.variableType() +
63  "\", declared as Inline C-Array, is associated to the non-array type \""+
64  type.Name()+"\".",
65  "RelationalStreamerFactory::newStreamer" );
66  }
67  newStreamer = new InlineCArrayStreamer( type, mapping, m_containerSchema );
68  } else if ( mapping.elementType() == MappingElement::OraArray ) {
69  if ( ! ClassUtils::isTypeOraVector( type ) ) {
70  throwException( "Mapped variable \"" + mapping.variableName() +" of type "+
71  mapping.variableType() +
72  "\", declared as OraArray, is associated to the non-array type \""+
73  type.Name()+"\".",
74  "RelationalStreamerFactory::newStreamer" );
75  }
76  if( ClassUtils::isTypePVector( type ) )
77  newStreamer = new PVectorStreamer( type, mapping, m_containerSchema );
78  else if ( ClassUtils::isTypeQueryableVector( type ))
79  newStreamer = new QueryableVectorStreamer( type, mapping, m_containerSchema );
80  } else if ( mapping.elementType() == MappingElement::OraPointer ) {
81  if ( ! ClassUtils::isTypeOraPointer( type )) {
82  throwException( "Mapped variable \"" + mapping.variableName() +" of type "+
83  mapping.variableType() +
84  "\", declared as a OraPointer, is associated to the type \""+
85  type.Name()+"\".",
86  "RelationalStreamerFactory::newStreamer" );
87  }
88  newStreamer = new OraPtrStreamer( type, mapping, m_containerSchema );
89  } else if ( mapping.elementType() == MappingElement::OraReference ) {
90  if ( ! ClassUtils::isTypeOraReference( type )) {
91  throwException( "Mapped variable \"" + mapping.variableName() +" of type "+
92  mapping.variableType() +
93  "\", declared as a OraReference, is associated to the type \""+
94  type.Name()+"\".",
95  "RelationalStreamerFactory::newStreamer" );
96  }
97  newStreamer = new OraReferenceStreamer( type, mapping, m_containerSchema );
98  } else if ( mapping.elementType() == MappingElement::NamedReference ) {
99  if ( ! ClassUtils::isTypeNamedReference( type )) {
100  throwException( "Mapped variable \"" + mapping.variableName() +" of type "+
101  mapping.variableType() +
102  "\", declared as a NamedReference, is associated to the type \""+
103  type.Name()+"\".",
104  "RelationalStreamerFactory::newStreamer" );
105  }
106  newStreamer = new NamedRefStreamer( type, mapping, m_containerSchema );
107  } else if ( mapping.elementType() == MappingElement::UniqueReference ) {
108  if ( ! ClassUtils::isTypeUniqueReference( type )) {
109  throwException( "Mapped variable \"" + mapping.variableName() +" of type "+
110  mapping.variableType() +
111  "\", declared as a UniqueReference, is associated to the type \""+
112  type.Name()+"\".",
113  "RelationalStreamerFactory::newStreamer" );
114  }
115  newStreamer = new UniqueRefStreamer( type, mapping, m_containerSchema );
116  } else {
117  throwException( "Cannot find a streamer suitable for mapped variable \"" + mapping.variableName() +" of type "+
118  mapping.variableType() +
119  "\".",
120  "RelationalStreamerFactory::newStreamer" );
121  }
122 
123  return newStreamer;
124 }
125 
126 
127 
129  MappingElement& mapping ){
130  std::auto_ptr<IRelationalStreamer> streamer( newStreamer( type, mapping ) );
131  return streamer->newWriter();
132 }
133 
135  MappingElement& mapping ){
136  std::auto_ptr<IRelationalStreamer> streamer( newStreamer( type, mapping ) );
137  return streamer->newUpdater();
138 }
139 
141  MappingElement& mapping ){
142  std::auto_ptr<IRelationalStreamer> streamer( newStreamer( type, mapping ) );
143  return streamer->newReader();
144 }
type
Definition: HCALResponse.h:22
bool isTypeOraPointer(const Reflex::Type &typ)
Definition: ClassUtils.cc:250
IRelationalStreamer * newStreamer(const Reflex::Type &dataType, MappingElement &dataMapping)
RelationalStreamerFactory(ContainerSchema &contSchema)
IRelationalReader * newReader(const Reflex::Type &dataType, MappingElement &dataMapping)
const std::string & variableName() const
bool isTypePVector(const Reflex::Type &typ)
Definition: ClassUtils.cc:284
bool isTypeOraReference(const Reflex::Type &typ)
Definition: ClassUtils.cc:263
ElementType elementType() const
bool isTypeUniqueReference(const Reflex::Type &typ)
Definition: ClassUtils.cc:271
bool isTypeContainer(const Reflex::Type &typ)
Definition: ClassUtils.cc:147
IRelationalWriter * newWriter(const Reflex::Type &dataType, MappingElement &dataMapping)
IRelationalUpdater * newUpdater(const Reflex::Type &dataType, MappingElement &dataMapping)
bool isTypePrimitive(const Reflex::Type &typ)
Definition: ClassUtils.cc:143
const std::string & variableType() const
bool isTypeNamedReference(const Reflex::Type &typ)
Definition: ClassUtils.cc:267
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
bool isTypeOraVector(const Reflex::Type &typ)
Definition: ClassUtils.cc:310
bool isTypeQueryableVector(const Reflex::Type &typ)
Definition: ClassUtils.cc:297