10 static const std::string s_classMappingElementType =
"Class";
11 return s_classMappingElementType;
17 static const std::string s_objectMappingElementType =
"Object";
18 return s_objectMappingElementType;
24 static const std::string s_dependencyMappingElementType =
"Dependency";
25 return s_dependencyMappingElementType;
31 static const std::string s_primitiveMappingElementType =
"Primitive";
32 return s_primitiveMappingElementType;
38 static const std::string s_arrayMappingElementType =
"Array";
39 return s_arrayMappingElementType;
45 static const std::string s_CArrayMappingElementType =
"CArray";
46 return s_CArrayMappingElementType;
52 static const std::string s_inlineCArrayMappingElementType =
"InlineCArray";
53 return s_inlineCArrayMappingElementType;
59 static const std::string s_oraReferenceMappingElementType =
"OraReference";
60 return s_oraReferenceMappingElementType;
66 static const std::string s_oraPointerMappingElementType =
"OraPointer";
67 return s_oraPointerMappingElementType;
73 static const std::string s_oraUniqueReferenceMappingElementType =
"UniqueReference";
74 return s_oraUniqueReferenceMappingElementType;
80 static const std::string s_oraArrayMappingElementType =
"OraArray";
81 return s_oraArrayMappingElementType;
87 static const std::string s_pointerMappingElementType =
"Pointer";
88 return s_pointerMappingElementType;
94 static const std::string s_referenceMappingElementType =
"Reference";
95 return s_referenceMappingElementType;
101 static const std::string s_blobMappingElementType =
"Blob";
102 return s_blobMappingElementType;
108 static const std::string s_namedReferenceMappingElementType =
"NamedReference";
109 return s_namedReferenceMappingElementType;
115 return ( elementType == classMappingElementType() ||
116 elementType == objectMappingElementType() ||
117 elementType == dependencyMappingElementType() ||
118 elementType == primitiveMappingElementType() ||
119 elementType == arrayMappingElementType() ||
120 elementType == CArrayMappingElementType() ||
121 elementType == inlineCArrayMappingElementType() ||
122 elementType == OraReferenceMappingElementType() ||
123 elementType == OraPointerMappingElementType() ||
124 elementType == uniqueReferenceMappingElementType() ||
125 elementType == OraArrayMappingElementType() ||
126 elementType == pointerMappingElementType() ||
127 elementType == referenceMappingElementType() ||
128 elementType == blobMappingElementType() ||
129 elementType == namedReferenceMappingElementType() );
135 switch ( elementType ) {
137 return classMappingElementType();
140 return objectMappingElementType();
143 return dependencyMappingElementType();
146 return primitiveMappingElementType();
149 return arrayMappingElementType();
152 return CArrayMappingElementType();
155 return inlineCArrayMappingElementType();
158 return OraReferenceMappingElementType();
161 return OraPointerMappingElementType();
163 case UniqueReference :
164 return uniqueReferenceMappingElementType();
167 return OraArrayMappingElementType();
170 return referenceMappingElementType();
173 return blobMappingElementType();
176 return namedReferenceMappingElementType();
179 return pointerMappingElementType();
186 std::stringstream
ms;
187 ms <<
"Undefined mapping element type code="<< elementType;
189 "MappingElement::elementTypeAsString" );
198 if ( ! isValidMappingElementType( elementType ) ) {
199 throwException(
"\"" + elementType +
"\" is not a supported mapping element type",
200 "MappingElement::elementTypeFromString" );
205 if ( elementType == classMappingElementType() ) {
208 if ( elementType == objectMappingElementType() ) {
211 if ( elementType == dependencyMappingElementType() ) {
214 if ( elementType == primitiveMappingElementType() ) {
217 else if ( elementType == arrayMappingElementType() ) {
220 else if ( elementType == CArrayMappingElementType() ) {
223 else if ( elementType == inlineCArrayMappingElementType() ) {
226 else if ( elementType == pointerMappingElementType() ) {
229 else if ( elementType == referenceMappingElementType() ) {
232 else if ( elementType == OraReferenceMappingElementType() ) {
235 else if ( elementType == OraPointerMappingElementType() ) {
238 else if ( elementType == uniqueReferenceMappingElementType() ) {
239 return UniqueReference;
241 else if ( elementType == OraArrayMappingElementType() ) {
244 else if ( elementType == blobMappingElementType() ) {
247 else if ( elementType == namedReferenceMappingElementType() ) {
258 m_elementType( Undefined ),
259 m_isDependentTree(
false),
261 m_variableName( variableName ),
262 m_variableNameForSchema(
"" ),
263 m_variableType( variableType ),
264 m_tableName( tableName ),
278 std::set<std::string>& tableRegister,
279 std::vector<std::pair<std::string, std::string> >& tableList ){
281 std::set<std::string>::iterator iT = tableRegister.find( tableName );
282 if( iT == tableRegister.end() ){
285 "MappingElement::tableHierarchy");
287 tableRegister.insert( tableName );
288 tableList.push_back( std::make_pair(tableName,element.
columnNames()[0]) );
291 iEl != element.
end(); ++iEl ){
297 std::vector<std::pair<std::string,std::string> >
299 std::set<std::string> involvedTables;
300 std::vector<std::pair<std::string,std::string> > tableList;
306 if( m_columnNames.empty() )
throwException(
"No column names found in the mapping element.",
307 "MappingElement::idColumn");
308 return m_columnNames.front();
313 if( m_isDependentTree ) ind = 1;
314 if( m_columnNames.size() < ind+1 )
315 throwException(
"Column names not found as expected in the mapping element.",
316 "MappingElement::idColumn");
317 return m_columnNames.at( ind );
322 if( m_isDependentTree ) ind = 1;
323 size_t cols = m_columnNames.size();
326 message <<
"Column names for variable=\""<< m_variableName<<
"\" of type=\""<<elementTypeAsString( m_elementType )<<
"\" are not as expected.";
328 "MappingElement::recordIdColumns");
330 std::vector<std::string>
ret;
331 for(
size_t i=ind+1;
i<cols;
i++){
332 ret.push_back( m_columnNames[
i] );
339 if( m_isDependentTree ) ind = 1;
340 if( m_columnNames.size() < ind+2 )
341 throwException(
"Column names not found as expected in the mapping element.",
342 "MappingElement::posColumn");
343 return m_columnNames.back();
353 if ( ! ( m_elementType == Class ||
354 m_elementType ==
Object ||
355 m_elementType == Dependency ||
356 m_elementType == Array ||
357 m_elementType == CArray ||
358 m_elementType == InlineCArray ||
359 m_elementType == OraPointer ||
360 m_elementType == OraArray ) ) {
361 throwException(
"Attempted to insert a sub-element under an element of type \"" +
363 "MappingElement::appendSubElement" );
365 if(m_subElements.find( variableName )!=m_subElements.end()){
366 throwException(
"Attribute name \""+variableName+
"\" is already defined in the mapping element of variable \""+
367 m_variableName+
"\".",
368 "MappingElement::appendSubElement");
375 tableName ) ) ).first->second;
377 if ( m_scopeName.empty() ) {
380 newElement.
m_scopeName = m_scopeName +
"::" + m_variableName;
390 if ( ! isValidMappingElementType( elementType ) ) {
391 throwException(
"\"" + elementType +
"\" is not a supported mapping element type",
392 "MappingElement::alterType");
394 ElementType elementTypeCode = elementTypeFromString( elementType );
395 if(m_elementType != elementTypeCode){
396 m_elementType = elementTypeCode;
398 if ( ! ( m_elementType == Class ||
399 m_elementType ==
Object ||
400 m_elementType == Dependency ||
401 m_elementType == Array ||
402 m_elementType == CArray ||
403 m_elementType == InlineCArray ||
404 m_elementType == OraPointer ||
405 m_elementType == OraArray ) ) {
406 m_subElements.clear();
414 if ( tableName == m_tableName )
return;
417 iElement != this->
end(); ++iElement ) {
425 m_tableName = tableName;
431 m_columnNames = columns;
432 if ( m_subElements.empty() )
return;
444 if(iTarg!=source.
end()){
445 iel->second.override(iTarg->second);
453 outputStream << indentation <<
"<"<<elementTypeString()<<
" name=\""<<m_variableName<<
"\" type=\""<<m_variableType<<
454 "\" table=\""<<m_tableName<<
"\"";
455 if( !m_columnNames.empty()) {
456 outputStream <<
" columns=\"";
457 for( std::vector<std::string>::const_iterator iC=m_columnNames.begin(); iC != m_columnNames.end(); ++iC ){
458 if( iC != m_columnNames.begin() ) outputStream <<
",";
461 outputStream <<
"\"";
463 outputStream <<
" >"<< std::endl;
464 for( std::map< std::string, MappingElement >::const_iterator iM = m_subElements.begin();
465 iM != m_subElements.end(); ++iM ){
466 iM->second.printXML( outputStream, indentation+
" " );
468 outputStream << indentation <<
"</"<<elementTypeString()<<
">"<< std::endl;
static std::string namedReferenceMappingElementType()
Returns the name of the named reference element type.
static std::string blobMappingElementType()
Returns the name of the blob mapping element type.
static std::string arrayMappingElementType()
Returns the name of the array mapping element type.
const std::string & variableName() const
static std::string primitiveMappingElementType()
Returns the name of the primitive mapping element type.
static std::string dependencyMappingElementType()
Returns the name of the dependent class mapping element type.
std::string idColumn() const
static std::string OraReferenceMappingElementType()
Returns the name of the ORA reference mapping element type.
ElementType elementType() const
MappingElement & appendSubElement(const std::string &elementType, const std::string &variableName, const std::string &variableType, const std::string &tableName)
MappingElement()
Empty Constructor.
void alterTableName(const std::string &tableName)
iterator begin()
Returns an iterator in the beginning of the sequence.
static std::string pointerMappingElementType()
Returns the name of the pointer mapping element type.
std::vector< std::string > recordIdColumns() const
std::string posColumn() const
void alterType(const std::string &elementType)
static std::string elementTypeAsString(ElementType elementType)
Converts the enumeration type to a string.
static std::string objectMappingElementType()
Returns the name of the object mapping element type.
std::vector< std::pair< std::string, std::string > > tableHierarchy() const
static std::string uniqueReferenceMappingElementType()
Returns the name of the ORA polymorphic pointer mapping element type.
iterator find(const std::string &key)
Retrieves a sub-element.
std::string pkColumn() const
std::map< std::string, MappingElement >::iterator iterator
Iterator definition.
const std::vector< std::string > & columnNames() const
void printXML(std::ostream &outputStream, std::string indentation="") const
static std::string referenceMappingElementType()
Returns the name of the reference mapping element type.
~MappingElement()
Destructor.
static std::string inlineCArrayMappingElementType()
Returns the name of the inline array mapping element type.
void processTableHierarchy(const MappingElement &element, std::set< std::string > &tableRegister, std::vector< std::pair< std::string, std::string > > &tableList)
void override(const MappingElement &source)
const std::string & variableType() const
std::map< std::string, MappingElement >::const_iterator const_iterator
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
static ElementType elementTypeFromString(const std::string &elementType)
Converts a string into an element type.
iterator end()
Returns an iterator in the end of the sequence.
static std::string OraPointerMappingElementType()
Returns the name of the ORA pointer mapping element type.
static std::string OraArrayMappingElementType()
Returns the name of the ORA array mapping element type.
const std::string & tableName() const
volatile std::atomic< bool > shutdown_flag false
static bool isValidMappingElementType(const std::string &elementType)
Checks if the provided element type is valid.
static std::string classMappingElementType()
Returns the name of the class mapping element type.
static std::string const source
static std::string CArrayMappingElementType()
Returns the name of the array mapping element type.
void setColumnNames(const std::vector< std::string > &columns)
ElementType m_elementType