11 #include "CoralBase/Attribute.h"
12 #include "Reflex/Member.h"
17 m_objectType( objectType ),
23 m_relationalData( 0 ){
34 m_dataElement = &dataElement;
38 Reflex::OffsetFunction baseOffsetFunc = 0;
39 if( m_objectType != refType ){
42 throwException(
"Type \""+m_objectType.Name(Reflex::SCOPED)+
"\" is not an Ora Reference.",
43 "OraReferenceStreamerBase::buildDataElement");
46 Reflex::Member contIdMember = refType.DataMemberByName(
"m_containerId");
47 Reflex::Member itemIdMember = refType.DataMemberByName(
"m_itemId");
48 if( !contIdMember || !itemIdMember ){
50 "OraReferenceStreamerBase::buildDataElement");
52 m_dataElemOId0 = &dataElement.
addChild( contIdMember.Offset(), baseOffsetFunc );
53 m_dataElemOId1 = &dataElement.
addChild( itemIdMember.Offset(), baseOffsetFunc);
55 const std::vector<std::string>& columns = m_mapping.columnNames();
56 if( columns.size() < 2 ){
57 throwException(
"Expected column names have not been found in the mapping.",
58 "OraReferenceStreamerBase::buildDataElement");
60 const std::type_info& attrType =
typeid(int);
61 for(
size_t i=0;
i<2;
i++ ){
62 m_columnIndexes[
i] = relationalData.
addData( columns[
i],attrType );
64 m_relationalData = &relationalData;
70 if(!m_relationalData){
72 "OraReferenceStreamerBase::bindDataForUpdate");
75 void* oid0Address = m_dataElemOId0->address( data );
76 coral::Attribute& oid0Attr = m_relationalData->data()[ m_columnIndexes[0] ];
77 oid0Attr.data<
int>()= *static_cast<int*>(oid0Address);
78 void* oid1Address = m_dataElemOId1->address( data );
79 coral::Attribute& oid1Attr = m_relationalData->data()[ m_columnIndexes[1] ];
80 oid1Attr.data<
int>()= *static_cast<int*>(oid1Address) ;
82 void* refPtr = m_dataElement->address( data );
83 if(refHandler) refHandler->
onSave( *static_cast<Reference*>( refPtr ) );
87 if(!m_relationalData){
89 "OraReferenceStreamerBase::bindDataForRead");
92 void* oid0Address = m_dataElemOId0->address( data );
93 coral::Attribute& oid0Attr = m_relationalData->data()[ m_columnIndexes[0] ];
94 *
static_cast<int*
>(oid0Address) = oid0Attr.data<
int>();
95 void* oid1Address = m_dataElemOId1->address( data );
96 coral::Attribute& oid1Attr = m_relationalData->data()[ m_columnIndexes[1] ];
97 *
static_cast<int*
>( oid1Address ) = oid1Attr.data<
int>();
99 void* refPtr = m_dataElement->address( data );
100 if(refHandler) refHandler->
onLoad( *static_cast<Reference*>( refPtr ) );
115 return buildDataElement( dataElement, relationalData );
123 bindDataForUpdate( data );
138 return buildDataElement( dataElement, relationalData );
146 bindDataForUpdate( data );
160 return buildDataElement( dataElement, relationalData );
170 bindDataForRead( data );
180 m_objectType( objectType ),
181 m_mapping( mapping ),
bool build(DataElement &dataElement, IRelationalData &relationalData)
OraReferenceUpdater(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &schema)
void write(int oid, const void *data)
Writes a data element.
virtual ~OraReferenceWriter()
virtual bool onLoad(ora::Reference &ref)=0
virtual int addData(const std::string &columnName, const std::type_info &columnType)=0
IRelationalWriter * newWriter()
DataElement & addChild(size_t declaringScopeOffset, Reflex::OffsetFunction offsetFunction)
bool findBaseType(Reflex::Type &type, Reflex::Type &baseType, Reflex::OffsetFunction &func)
OraReferenceStreamer(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &schema)
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
virtual ~OraReferenceReader()
void setRecordId(const std::vector< int > &identity)
OraReferenceStreamerBase(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &schema)
virtual bool onSave(ora::Reference &ref)=0
bool buildDataElement(DataElement &dataElement, IRelationalData &relationalData)
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
void read(void *data)
Reads a data element.
void setRecordId(const std::vector< int > &identity)
void update(int oid, const void *data)
Updates a data element.
OraReferenceReader(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &schema)
void setRecordId(const std::vector< int > &identity)
virtual ~OraReferenceStreamerBase()
void bindDataForRead(void *data)
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
char data[epos_bytes_allocation]
void bindDataForUpdate(const void *data)
OraReferenceWriter(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &schema)
IRelationalUpdater * newUpdater()
virtual ~OraReferenceUpdater()
IRelationalReader * newReader()