11 #include "CoralBase/Attribute.h"
12 #include "Reflex/Member.h"
15 static 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");
65 m_columnIndex = relationalData.
addData( columns[0],
typeid(std::string) );
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 ];
78 std::string
name = *
static_cast<std::string*
>(refNameAddress);
80 refNameAttr.data<std::string>()= name;
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 ];
92 std::string
name = refNameAttr.data<std::string>();
94 name = std::string(
"");
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;
102 *
static_cast<std::string*
>(refNameAddress) = name;
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)
char data[epos_bytes_allocation]
NamedRefReader(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
void throwException(const std::string &message, const std::string &methodName)
void setRecordId(const std::vector< int > &identity)
virtual ~NamedReferenceStreamerBase()