11 #include "CoralBase/Attribute.h"
12 #include "Reflex/Member.h"
15 static const std::string nullLabel(
"ora::NamedRef::Null");
22 m_objectType( objectType ),
27 m_refNameDataElement( 0 ),
28 m_ptrDataElement( 0 ),
29 m_flagDataElement( 0 ),
30 m_relationalData( 0 ){
39 m_dataElement = &dataElement;
40 m_objectType.UpdateMembers();
41 Reflex::Member nameMember = m_objectType.DataMemberByName(
"m_name");
43 throwException(
"Data member \"m_name\" not found in class \""+m_objectType.Name()+
"\".",
44 "NamedReferenceStreamerBase::buildDataElement");
46 m_refNameDataElement = &dataElement.
addChild( nameMember.Offset(), 0 );
47 Reflex::Member ptrMember = m_objectType.DataMemberByName(
"m_ptr");
49 throwException(
"Data member \"m_ptr\" not found in class \""+m_objectType.Name()+
"\".",
50 "NamedReferenceStreamerBase::buildDataElement");
52 m_ptrDataElement = &dataElement.
addChild( ptrMember.Offset(), 0 );
53 Reflex::Member flagMember = m_objectType.DataMemberByName(
"m_isPersistent");
55 throwException(
"Data member \"m_isPersistent\" not found in class \""+m_objectType.Name()+
"\".",
56 "NamedReferenceStreamerBase::buildDataElement");
58 m_flagDataElement = &dataElement.
addChild( flagMember.Offset(), 0 );
60 const std::vector<std::string>& columns = m_mapping.columnNames();
61 if( columns.size()==0 ){
63 "NamedReferenceStreamerBase::buildDataElement");
66 m_relationalData = &relationalData;
71 if(!m_relationalData){
73 "NamedReferenceStreamerBase::bindDataForUpdate");
76 void* refNameAddress = m_refNameDataElement->address( data );
77 coral::Attribute& refNameAttr = m_relationalData->data()[ m_columnIndex ];
84 if(!m_relationalData){
86 "NamedReferenceStreamerBase::bindDataForRead");
88 void* refNameAddress = m_refNameDataElement->address( data );
89 void* ptrAddress = m_ptrDataElement->address( data );
90 void* flagAddress = m_flagDataElement->address( data );
91 coral::Attribute& refNameAttr = m_relationalData->data()[ m_columnIndex ];
97 Reflex::Type namedRefType = m_objectType.TemplateArgumentAt(0);
98 boost::shared_ptr<void> ptr = m_schema.dbSession().fetchTypedObjectByName( name, namedRefType );
99 *
static_cast<boost::shared_ptr<void>*
>(ptrAddress) = ptr;
100 *
static_cast<bool*
>(flagAddress) =
true;
117 return buildDataElement( dataElement, relationalData );
126 bindDataForUpdate( data );
141 return buildDataElement( dataElement, relationalData );
150 bindDataForUpdate( data );
164 return buildDataElement( dataElement, relationalData );
175 bindDataForRead( data );
185 m_objectType( objectType ),
186 m_mapping( mapping ),
187 m_schema( contSchema ){
void update(int oid, const void *data)
Updates a data element.
std::string namedRefNullLabel()
void read(void *destination)
Reads a data element.
void bindDataForUpdate(const void *data)
void setRecordId(const std::vector< int > &identity)
virtual int addData(const std::string &columnName, const std::type_info &columnType)=0
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
IRelationalUpdater * newUpdater()
DataElement & addChild(size_t declaringScopeOffset, Reflex::OffsetFunction offsetFunction)
void bindDataForRead(void *data)
NamedRefWriter(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
bool build(DataElement &offset, IRelationalData &relationalData)
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
virtual ~NamedRefWriter()
NamedRefStreamer(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
virtual ~NamedRefReader()
NamedReferenceStreamerBase(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &schema)
IRelationalWriter * newWriter()
void write(int oid, const void *data)
Writes a data element.
IRelationalReader * newReader()
bool buildDataElement(DataElement &dataElement, IRelationalData &relationalData)
virtual ~NamedRefUpdater()
void setRecordId(const std::vector< int > &identity)
NamedRefUpdater(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
char data[epos_bytes_allocation]
NamedRefReader(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
void setRecordId(const std::vector< int > &identity)
virtual ~NamedReferenceStreamerBase()