Samchon Framework for CPP  1.0.0
samchon::protocol::EntityGroup< _Container, _ETy, T > Class Template Referenceabstract

An Entity and a container of children Entity objects. More...

#include <EntityGroup.hpp>

Collaboration diagram for samchon::protocol::EntityGroup< _Container, _ETy, T >:

Public Member Functions

 EntityGroup ()
 Default Constructor. More...
 
virtual void construct (std::shared_ptr< library::XML > xml)
 Construct data of the Entity from an XML object. More...
 
auto has (const std::string &key) const -> bool
 Indicates whether a container has an object having the specified identifier. More...
 
auto get (const std::string &key) -> value_type &
 Access the element by specified identifier(key). More...
 
auto get (const std::string &key) const -> const value_type &
 Access the const element by specified identifier(key). More...
 
virtual auto toXML () const -> std::shared_ptr< library::XML >
 Get an XML object represents the EntityGroup. More...
 
- Public Member Functions inherited from samchon::protocol::Entity
virtual auto TAG () const -> std::string=0
 A tag name when represented by XML. More...
 
 Entity ()
 Default Constructor. More...
 
virtual auto key () const -> std::string
 Get a key that can identify the Entity uniquely. More...
 
- Public Member Functions inherited from samchon::protocol::IEntityGroup
 IEntityGroup ()
 Default Constructor. More...
 

Protected Member Functions

virtual auto createChild (std::shared_ptr< library::XML >) -> entity_type *=0
 Factory method of a child Entity. More...
 
- Protected Member Functions inherited from samchon::protocol::IEntityGroup
virtual auto CHILD_TAG () const -> std::string=0
 A tag name of children. More...
 

Detailed Description

template<typename _Container, typename _ETy = Entity, typename T = _Container::value_type>
class samchon::protocol::EntityGroup< _Container, _ETy, T >

An Entity and a container of children Entity objects.

Template Parameters
_ContainerA type of container containing children entity objects.
_EtyA type of children entity. It must be a class derived from an Entity class, or Entity class itself.
_TyA type of children element of _Container. Using default template parameter is recommended.

EntityGroup is a template class for containinig children Entity objects, and also another type of an Entity, too. You can realize hierarchical relationship. Although some entities have complicated hierarchical relationship, you can deduct a optimal solution easily with EntityGroup and Entity.

If an entity has some subordinate entities of same type, they are in "Composite relationship". Make the entity to be EmntityGroup and subordinate entities to be children of the entity. When those relationships are continued, continue to create classes dervied from EntityGroup. When those relationshiop meets a terminal node, then make the terminal node to be an Entity.

example_inspect.png

EntityGroup is an Entity, and a container of children Entity objects at the same time. If children type, of a class derived from an EntityGroup, is itself, you can realize hierarchical and recursive relationship. The relationship is called as "Composite pattern".

  • FTFolder extends FTInstance and SharedEntityArray<FTInstance>
  • NTCriteria extends SharedEntityArray<NTCriteria>
Note

As a freelancer developer and architect I am, I even design DB I/O to follow the format representing Entity and EntityGroup by XML. Below T-SQL script also follows the standard format of expressing Entity with XML by procedure and "FOR XML AUTO" statement.

1 SET
2  ANSI_NULLS,
3  QUOTED_IDENTIFIER,
4  CONCAT_NULL_YIELDS_NULL,
5  ANSI_WARNINGS,
6  ANSI_PADDING
7 ON;
8 
9 USE OraQ;
10 IF OBJECT_ID('v_studyStatus') IS NOT NULL DROP VIEW v_studyStatus;
11 IF OBJECT_ID('v_nonDicomFileStatus') IS NOT NULL DROP VIEW v_nonDicomFileStatus;
12 IF OBJECT_ID('v_candidateStudy') IS NOT NULL DROP VIEW v_candidateStudy;
13 IF OBJECT_ID('v_candidateFile') IS NOT NULL DROP VIEW v_candidateFile;
14 IF OBJECT_ID('goCandidateInspectList') IS NOT NULL DROP PROCEDURE goCandidateInspectList;
15 GO
16 
17 CREATE VIEW v_studyStatus
18 AS
19  WITH cte AS
20  (
21  SELECT S.studyUID uid, S.type type, ROW_NUMBER() OVER (PARTITION BY S.studyUID ORDER BY H.datetime DESC) no
22  FROM History.history H, History.study S
23  WHERE
24  H.uid = S.uid AND type <> 1
25  )
26  SELECT
27  A.uid,
28  CASE WHEN B.type IS NULL THEN
29  A.type
30  ELSE 1
31  END status
32  FROM
33  (
34  SELECT uid, type
35  FROM cte
36  WHERE no = 1
37  ) A LEFT OUTER JOIN
38  (
39  SELECT studyUID uid, 1 type
40  FROM History.study
41  GROUP BY studyUID
42  HAVING MAX(type) = 1
43  ) B ON A.uid = B.uid
44 GO
45 CREATE VIEW v_nonDicomFileStatus
46 AS
47  WITH cte AS
48  (
49  SELECT
50  F.fileUID uid, F.type type,
51  ROW_NUMBER() OVER (PARTITION BY F.fileUID ORDER BY H.datetime DESC) no
52  FROM History.history H, History.nonDicomFile F
53  WHERE
54  H.uid = F.uid AND type <> 1
55  )
56  SELECT
57  A.uid,
58  CASE WHEN B.type IS NULL THEN
59  A.type
60  ELSE 1
61  END status
62  FROM
63  (
64  SELECT uid, type
65  FROM cte
66  WHERE no = 1
67  ) A LEFT OUTER JOIN
68  (
69  SELECT fileUID uid, 1 type
70  FROM History.nonDicomFile
71  GROUP BY fileUID
72  HAVING MAX(type) = 1
73  ) B ON A.uid = B.uid
74 GO
75 CREATE VIEW v_candidateStudy
76 AS
77  SELECT DISTINCT
78  P.id patientID,
79  P.name patientName, P.gender patientGender,
80  CAST(P.birthdate AS DATE) patientBirthdate,
81  S.uid,
82  S.description,
83  CONVERT(VARCHAR, CAST(S.datetime AS DATETIME), 120) AS datetime,
84  H.status
85  FROM
86  Hospital.patient P, Inspect.media M, Inspect.mediaStudyPair A,
87  Inspect.study S, v_studyStatus H
88  WHERE
89  P.id = M.patientID AND M.uid = A.mediaUID AND A.studyUID = S.uid AND
90  S.uid = H.uid
91 GO
92 CREATE VIEW v_candidateFile
93 AS
94  SELECT DISTINCT
95  P.id patientID,
96  P.name patientName, P.gender patientGender,
97  CAST(P.birthdate AS DATE) patientBirthdate,
98  M.uid mediaUID,
99  F.uid, F.name, F.extension,
100  CONVERT(VARCHAR, CAST(F.datetime AS DATETIME), 120) AS datetime,
101  H.status
102  FROM
103  Hospital.patient P, Inspect.media M,
104  Inspect.nonDicomFile F, v_nonDicomFileStatus H
105  WHERE
106  P.id = M.patientID AND M.uid = F.mediaUID AND F.uid = H.uid
107 GO
108 
109 CREATE PROCEDURE goCandidateInspectList
110 AS
111  DECLARE @xml XML =
112  (
113  SELECT *
114  FROM
115  (
116  SELECT N'candidate' service
117  ) inspect
118  FOR XML AUTO
119  )
120  DECLARE @studyList XML =
121  (
122  SELECT study.*, series.*, image.*
123  FROM
124  v_candidateStudy study
125  LEFT OUTER JOIN Inspect.series series
126  ON study.uid = series.studyUID
127  LEFT OUTER JOIN Inspect.image image
128  ON series.uid = image.seriesUID
129  FOR XML AUTO, ROOT(N'studyList')
130  )
131  DECLARE @fileList XML =
132  (
133  SELECT * FROM v_candidateFile
134  FOR XML RAW(N'file'), ROOT(N'fileList')
135  )
136 
137  IF(@studyList IS NOT NULL) SET @xml.modify('insert sql:variable("@studyList") into (/inspect)[1]')
138  IF(@fileList IS NOT NULL) SET @xml.modify('insert sql:variable("@fileList") into (/inspect)[1]')
139 
140  SELECT @xml;
141 GO
Warning

EntityGroup contains children entity elements as type of pointer. Because children entity objects are not serialized and referenced by pointer, its iteration and accessment is not fast. If it needs higher performance, then use EntityArray (static array for children entity) instead.

[Inherited]

Entity is a class for standardization of expression method using on network I/O by XML. If Invoke is a standard message protocol of Samchon Framework which must be kept, Entity is a recommended semi-protocol of message for expressing a data class. Following the semi-protocol Entity is not imposed but encouraged.

As we could get advantages from standardization of message for network I/O with Invoke, we can get additional advantage from standardizing expression method of data class with Entity. We do not need to know a part of network communication. Thus, with the Entity, we can only concentrate on entity's own logics and relationships between another entities. Entity does not need to how network communications are being done.

protocol_entity.png
Example Sources
Note

I say repeatedly. Expression method of Entity is recommended, but not imposed. It's a semi protocol for network I/O but not a essential protocol must be kept. The expression method of Entity, using on network I/O, is expressed by XML string.

If your own network system has a critical performance issue on communication data class, it would be better to using binary communication (with ByteArray or boost::serialization). Don't worry about the problem! Invoke also provides methods for binary data (ByteArray).

See also
protocol
Author
Jeongho Nam http://samchon.org

Definition at line 52 of file EntityGroup.hpp.

Constructor & Destructor Documentation

template<typename _Container , typename _ETy = Entity, typename T = _Container::value_type>
samchon::protocol::EntityGroup< _Container, _ETy, T >::EntityGroup ( )
inline

Default Constructor.

Definition at line 69 of file EntityGroup.hpp.

Member Function Documentation

template<typename _Container , typename _ETy = Entity, typename T = _Container::value_type>
virtual void samchon::protocol::EntityGroup< _Container, _ETy, T >::construct ( std::shared_ptr< library::XML xml)
inlinevirtual

Construct data of the Entity from an XML object.

Constructs the EntityGroup's own member variables only from the input XML object.

Do not consider about constructing children Entity objects' data in EntityGroup::construct(). Those children Entity objects' data will constructed by their own construct() method. Even insertion of XML objects representing children are done by abstract method of EntityGroup::toXML().

Constructs only data of EntityGroup's own.

[Inherited]
Construct data of the Entity from an XML object.

Overrides the construct() method and fetch data of member variables from the XML.

By recommended guidance, data representing member variables are contained in properties of the put XML object.

Parameters
xmlAn xml used to construct data of entity

Implements samchon::protocol::Entity.

Reimplemented in samchon::protocol::master::DistributedSystem, samchon::namtree::NTCriteria, samchon::protocol::master::ParallelSystem, samchon::protocol::ExternalSystem, samchon::protocol::Invoke, samchon::protocol::master::DistributedSystemArray, samchon::protocol::master::ParallelSystemArrayMediator, samchon::protocol::master::DistributedSystemArrayMediator, samchon::namtree::NTParameter, samchon::protocol::ExternalClientArray, samchon::protocol::ExternalServer, samchon::protocol::master::DistributedClientArrayMediator, samchon::protocol::master::ParallelClientArrayMediator, samchon::protocol::master::DistributedClientArray, samchon::protocol::master::DistributedServer, and samchon::protocol::master::ParallelServer.

Definition at line 90 of file EntityGroup.hpp.

References samchon::protocol::IEntityGroup::CHILD_TAG(), samchon::protocol::EntityGroup< _Container, _ETy, T >::createChild(), and samchon::protocol::Entity::key().

Referenced by samchon::protocol::ExternalClientArray::construct(), samchon::namtree::NTParameter::construct(), samchon::protocol::master::ParallelSystemArrayMediator::construct(), samchon::protocol::master::DistributedSystemArray::construct(), samchon::protocol::Invoke::construct(), samchon::protocol::ExternalSystem::construct(), samchon::protocol::master::ParallelSystem::construct(), samchon::namtree::NTFile::construct(), and samchon::library::FTFolder::FTFolder().

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename _Container , typename _ETy = Entity, typename T = _Container::value_type>
virtual auto samchon::protocol::EntityGroup< _Container, _ETy, T >::createChild ( std::shared_ptr< library::XML ) -> entity_type *
protectedpure virtual
template<typename _Container , typename _ETy = Entity, typename T = _Container::value_type>
auto samchon::protocol::EntityGroup< _Container, _ETy, T >::has ( const std::string &  key) const -> bool
inline

Indicates whether a container has an object having the specified identifier.

Parameters
keyAn identifier of an Entity
Returns
If there's the object then true, otherwise false

Definition at line 155 of file EntityGroup.hpp.

References samchon::protocol::Entity::key().

Referenced by samchon::protocol::master::ParallelSystem::construct(), and samchon::protocol::ExternalSystemArray::sendData().

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename _Container , typename _ETy = Entity, typename T = _Container::value_type>
auto samchon::protocol::EntityGroup< _Container, _ETy, T >::get ( const std::string &  key) -> value_type&
inline

Access the element by specified identifier(key).

Parameters
keythe identifier of the element wants to access
Returns
The element having the key, or throw exception if there is none.

Definition at line 170 of file EntityGroup.hpp.

References samchon::protocol::Entity::key().

Referenced by samchon::protocol::master::ParallelSystem::construct(), and samchon::protocol::master::PRMasterHistory::PRMasterHistory().

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename _Container , typename _ETy = Entity, typename T = _Container::value_type>
auto samchon::protocol::EntityGroup< _Container, _ETy, T >::get ( const std::string &  key) const -> const value_type&
inline

Access the const element by specified identifier(key).

Parameters
keythe identifier of the element wants to access
Returns
The const element having the key, or throw exception if there is none.

Definition at line 185 of file EntityGroup.hpp.

References samchon::protocol::Entity::key().

Here is the call graph for this function:

template<typename _Container , typename _ETy = Entity, typename T = _Container::value_type>
virtual auto samchon::protocol::EntityGroup< _Container, _ETy, T >::toXML ( ) const -> std::shared_ptr<library::XML>
inlinevirtual

Get an XML object represents the EntityGroup.

Archives the EntityGroup's own member variables only to the returned XML object.

Do not consider about archiving children Entity objects' data in EntityGroup::toXML(). Those children Entity objects will converted to XML object by their own toXML() method. The insertion of XML objects representing children are done by abstract method of EntityGroup::toXML().

Archives only data of EntityGroup's own.

[Inherited]
Get an XML object represents the Entity.

Returns an XML object that can represents the Entity containing member variables into properties.

A member variable (not object, but atomic value like number, string or date) is categorized as a property within the framework of entity side. Thus, when overriding a toXML() method and archiving member variables to an XML object to return, puts each variable to be a property belongs to only an XML object.

Don't archive the member variable of atomic value to XML::value causing enormouse creation of XML objects to number of member variables. An Entity must be represented by only an XML instance (tag).

Standard Usage Non-standard usage abusing value
<memberList>
     <member id='jhnam88' name='Jeongho+Nam' birthdate='1988-03-11' />
     <member id='master' name='Administartor' birthdate='2011-07-28' />
</memberList>
<member>
     <id>jhnam88</id>
     <name>Jeongho+Nam</name>
     <birthdate>1988-03-11</birthdate>
</member>
Returns
An XML object representing the Entity.

Reimplemented from samchon::protocol::Entity.

Reimplemented in samchon::example::packer::WrapperArray, samchon::example::packer::Packer, samchon::protocol::Invoke, samchon::protocol::master::DistributedSystem, samchon::example::tsp::Travel, samchon::namtree::NTCriteria, samchon::protocol::ExternalSystem, samchon::protocol::master::DistributedSystemArray, samchon::example::packer::Wrapper, samchon::protocol::master::ParallelSystem, samchon::namtree::NTParameter, samchon::protocol::master::ParallelSystemArrayMediator, samchon::protocol::master::DistributedSystemArrayMediator, samchon::protocol::ExternalClientArray, samchon::protocol::ExternalServer, samchon::library::FTFolder, samchon::protocol::master::DistributedClientArrayMediator, samchon::protocol::master::ParallelClientArrayMediator, samchon::protocol::master::DistributedClientArray, samchon::protocol::master::DistributedServer, and samchon::protocol::master::ParallelServer.

Definition at line 212 of file EntityGroup.hpp.

References samchon::protocol::IEntityGroup::CHILD_TAG(), and samchon::protocol::Entity::toXML().

Referenced by samchon::library::FTFolder::toXML(), samchon::protocol::ExternalClientArray::toXML(), samchon::protocol::master::ParallelSystemArrayMediator::toXML(), samchon::namtree::NTParameter::toXML(), samchon::protocol::master::DistributedSystemRole::toXML(), samchon::protocol::master::DistributedSystemArray::toXML(), samchon::protocol::ExternalSystem::toXML(), samchon::namtree::NTFile::toXML(), samchon::protocol::master::DistributedSystem::toXML(), and samchon::protocol::Invoke::toXML().

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: