30 #include "../../common/STLUtils.h" 31 #include "../../common/StringUtils.h" 32 #include "../../core/translator/Translator.h" 33 #include "../../dataaccess/dataset/DataSet.h" 34 #include "../../dataaccess/dataset/DataSetType.h" 35 #include "../../dataaccess/datasource/DataSource.h" 36 #include "../../dataaccess/query_h.h" 37 #include "../../memory/DataSet.h" 38 #include "../../memory/DataSetItem.h" 39 #include "../core/AbstractGraph.h" 40 #include "../core/Edge.h" 41 #include "../core/GraphCache.h" 42 #include "../core/EdgeProperty.h" 43 #include "../core/GraphData.h" 44 #include "../core/GraphMetadata.h" 45 #include "../core/Vertex.h" 46 #include "../core/VertexProperty.h" 47 #include "../Config.h" 48 #include "../Globals.h" 49 #include "../Exception.h" 111 std::unique_ptr<te::mem::DataSet> outDataSet(
new te::mem::DataSet(dsType.get()));
112 std::unique_ptr<te::mem::DataSet> outDataSetUpdate(
new te::mem::DataSet(dsType.get()));
114 te::graph::GraphData::EdgeMap::iterator it = data->
getEdgeMap().begin();
116 bool hasNewObjects =
false;
117 bool hasUpdatedObjects =
false;
121 if(it->second->isNew())
126 dsItem->
setInt32(0, it->second->getId());
127 dsItem->
setInt32(1, it->second->getIdFrom());
128 dsItem->
setInt32(2, it->second->getIdTo());
135 for(
size_t i = 0; i < it->second->getAttributes().size(); ++i)
137 dsItem->
setValue(pos + i, it->second->getAttributes()[i]->clone());
141 outDataSet->add(dsItem);
143 hasNewObjects =
true;
145 else if(it->second->isDirty())
150 dsItem->
setInt32(0, it->second->getId());
151 dsItem->
setInt32(1, it->second->getIdFrom());
152 dsItem->
setInt32(2, it->second->getIdTo());
159 for(
size_t i = 0; i < it->second->getAttributes().size(); ++i)
161 dsItem->
setValue(pos + i, it->second->getAttributes()[i]->clone());
165 outDataSetUpdate->add(dsItem);
167 hasUpdatedObjects =
true;
173 std::map<std::string, std::string> options;
177 outDataSet->moveFirst();
182 if(hasUpdatedObjects)
184 outDataSetUpdate->moveFirst();
185 std::map<std::string, std::string> options;
186 std::vector<std::size_t> properties;
188 for(
size_t t = 0; t < dsType->getProperties().size(); ++t)
191 properties.push_back(t);
196 outDataSetUpdate->clear();
218 std::unique_ptr<te::mem::DataSet> outDataSet(
new te::mem::DataSet(dsType.get()));
219 std::unique_ptr<te::mem::DataSet> outDataSetUpdate(
new te::mem::DataSet(dsType.get()));
221 te::graph::GraphData::VertexMap::iterator it = data->
getVertexMap().begin();
223 bool hasNewObjects =
false;
224 bool hasUpdatedObjects =
false;
228 if(it->second->isNew())
233 dsItem->
setInt32(0, it->second->getId());
240 for(
size_t i = 0; i < it->second->getAttributes().size(); ++i)
242 dsItem->
setValue(pos + i, it->second->getAttributes()[i]->clone());
246 outDataSet->add(dsItem);
248 hasNewObjects =
true;
250 else if(it->second->isDirty())
255 dsItem->
setInt32(0, it->second->getId());
262 for(
size_t i = 0; i < it->second->getAttributes().size(); ++i)
264 dsItem->
setValue(pos + i, it->second->getAttributes()[i]->clone());
268 outDataSetUpdate->add(dsItem);
270 hasUpdatedObjects =
true;
276 std::map<std::string, std::string> options;
280 outDataSet->moveFirst();
285 if(hasUpdatedObjects)
287 outDataSetUpdate->moveFirst();
288 std::map<std::string, std::string> options;
289 std::vector<std::size_t> properties;
291 for(
size_t t = 0; t < dsType->getProperties().size(); ++t)
294 properties.push_back(t);
299 outDataSetUpdate->clear();
329 fields->push_back(f);
348 if(dataset->moveNext())
357 for(
size_t i = 1; i < dsType->getProperties().size(); ++i)
359 v->
addAttribute(static_cast<int>(i - 1), dataset->getValue(dsType->getProperty(i)->getName()).release());
375 fields->push_back(f);
394 if(dataset->moveNext())
405 for(
size_t i = 3; i < dsType->getProperties().size(); ++i)
407 e->
addAttribute(static_cast<int>(i - 3), dataset->getValue(dsType->getProperty(i)->getName()).release());
void saveEdgeAttributes(GraphData *data)
Used to save the edges elements attributes from a graph data.
void setAttributeVecSize(int size)
This function is used to set the number of attributes associated with the vertex elements.
te::graph::GraphMetadata * getMetadata()
It returns a pointer to a class that describes the graph metadata.
void setAttributeVecSize(int size)
This function is used to set the number of attributes associated with the edge elements.
An abstract class that models a source of data in a query.
The Field class can be used to model an expression that takes part of the output items of a SELECT...
VertexMap & getVertexMap()
It returns the the vertex map.
static const std::string sm_tableVertexModelAttrId
Attribute id.
te::graph::GraphMetadata * m_graphMetadata
Graph metadata attribute.
A class that models the name of a dataset used in a From clause.
A class that models the name of any property of an object.
Base exception class for plugin module.
void setValue(std::size_t i, te::dt::AbstractData *value)
It sets the value of the i-th property.
virtual void add(const std::string &datasetName, DataSet *d, const std::map< std::string, std::string > &options, std::size_t limit=0)
It adds data items to the dataset in the data source.
#define TE_TR(message)
It marks a string in order to get translated.
From the point of view of graph theory, vertices are treated as featureless and indivisible objects...
AbstractGraphLoaderStrategy(te::graph::GraphMetadata *metadata)
Default constructor.
virtual std::unique_ptr< DataSet > query(const Select &q, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It executes a query that may return some data using a generic query. This method always returns a dis...
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
Class used to define the edge struct of a graph. Its compose with a identifier, the vertex origin and...
virtual void saveData(GraphData *data)
Save the graph data structure in Data Source.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
static const std::string sm_tableEdgeModelAttrId
Attribute Id.
void saveGraphVertexList(GraphData *data)
Used to save the vertex elements from a graph data.
virtual void removeVertex(int id)
Function used to remove a vertex saved in a data source.
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
A class that can be used to model a filter expression that can be applied to a query.
Vertex * loadVertexAttrs(int id)
Function used to load one vertex given a ID.
Edge * loadEdgeAttrs(int id)
Function used to load one edge given a ID.
Edge * loadEdge(int id)
Function used to load one edge given a ID.
virtual std::unique_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
EdgeMap & getEdgeMap()
It returns the the edge map.
A Select models a query to be used when retrieving data from a DataSource.
void saveVertexAttributes(GraphData *data)
Used to save the vertex elements attributes from a graph data.
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
This class define a important struct used to group a map of vertex and edges. A flag is used to indic...
bool isDirty()
Used to check the graph data state.
It models the comparison operator.
void addAttribute(int idx, te::dt::AbstractData *ad)
Add a new attribute to this element.
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
static const std::string sm_tableEdgeModelAttrVFrom
Attribute Vertex From.
Vertex * loadVertex(int id)
Function used to load one vertex given a ID.
virtual void removeEdge(int id)
Function used to remove a edge saved in a data source.
void saveGraphEdgeList(GraphData *data)
Used to save the edge elements from a graph data.
virtual void update(const std::string &datasetName, DataSet *dataset, const std::vector< std::size_t > &properties, const te::da::ObjectIdSet *oids, const std::map< std::string, std::string > &options, std::size_t limit=0)
It updates the contents of a dataset for the set of data items.
virtual ~AbstractGraphLoaderStrategy()
Default destructor.
void addAttribute(int idx, te::dt::AbstractData *ad)
Add a new attribute to this element.
static const std::string sm_tableEdgeModelAttrVTo
Attribute Vertex To.
This class define the main functions necessary to save and load the graph data and metadata informati...
This class models a string Literal value.