30 #include "../../common/STLUtils.h"
31 #include "../../common/StringUtils.h"
32 #include "../../common/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"
59 delete m_graphMetadata;
64 return m_graphMetadata;
69 if(m_graphMetadata == 0 || m_graphMetadata->getDataSource() == 0)
77 saveGraphEdgeList(data);
84 if(m_graphMetadata == 0 || m_graphMetadata->getDataSource() == 0)
93 if(m_graphMetadata == 0 || m_graphMetadata->getDataSource() == 0)
107 std::string tableName = m_graphMetadata->getEdgeTableName();
110 std::auto_ptr<te::da::DataSetType> dsType(m_graphMetadata->getDataSource()->getDataSetType(tableName));
113 std::auto_ptr<te::mem::DataSet> outDataSet(
new te::mem::DataSet(dsType.get()));
114 std::auto_ptr<te::mem::DataSet> outDataSetUpdate(
new te::mem::DataSet(dsType.get()));
116 te::graph::GraphData::EdgeMap::iterator it = data->
getEdgeMap().begin();
118 bool hasNewObjects =
false;
119 bool hasUpdatedObjects =
false;
123 if(it->second->isNew())
128 dsItem->
setInt32(0, it->second->getId());
129 dsItem->
setInt32(1, it->second->getIdFrom());
130 dsItem->
setInt32(2, it->second->getIdTo());
135 if(m_graphMetadata->getEdgePropertySize() != 0)
137 for(
size_t i = 0; i < it->second->getAttributes().size(); ++i)
139 dsItem->
setValue(pos + i, it->second->getAttributes()[i]->clone());
143 outDataSet->add(dsItem);
145 hasNewObjects =
true;
147 else if(it->second->isDirty())
152 dsItem->
setInt32(0, it->second->getId());
153 dsItem->
setInt32(1, it->second->getIdFrom());
154 dsItem->
setInt32(2, it->second->getIdTo());
159 if(m_graphMetadata->getEdgePropertySize() != 0)
161 for(
size_t i = 0; i < it->second->getAttributes().size(); ++i)
163 dsItem->
setValue(pos + i, it->second->getAttributes()[i]->clone());
167 outDataSetUpdate->add(dsItem);
169 hasUpdatedObjects =
true;
175 std::map<std::string, std::string> options;
179 outDataSet->moveFirst();
180 m_graphMetadata->getDataSource()->add(tableName, outDataSet.get(), options);
184 if(hasUpdatedObjects)
186 outDataSetUpdate->moveFirst();
187 std::map<std::string, std::string> options;
188 std::vector<std::size_t> properties;
190 for(
size_t t = 0; t < dsType->getProperties().size(); ++t)
193 properties.push_back(t);
196 m_graphMetadata->getDataSource()->update(tableName, outDataSetUpdate.get(), properties, 0, options);
198 outDataSetUpdate->clear();
201 if(m_graphMetadata->getVertexPropertySize() != 0)
203 saveVertexAttributes(data);
214 std::string tableName = m_graphMetadata->getVertexTableName();
217 std::auto_ptr<te::da::DataSetType> dsType(m_graphMetadata->getDataSource()->getDataSetType(tableName));
220 std::auto_ptr<te::mem::DataSet> outDataSet(
new te::mem::DataSet(dsType.get()));
221 std::auto_ptr<te::mem::DataSet> outDataSetUpdate(
new te::mem::DataSet(dsType.get()));
223 te::graph::GraphData::VertexMap::iterator it = data->
getVertexMap().begin();
225 bool hasNewObjects =
false;
226 bool hasUpdatedObjects =
false;
230 if(it->second->isNew())
235 dsItem->
setInt32(0, it->second->getId());
240 if(m_graphMetadata->getVertexPropertySize() != 0)
242 for(
size_t i = 0; i < it->second->getAttributes().size(); ++i)
244 dsItem->
setValue(pos + i, it->second->getAttributes()[i]->clone());
248 outDataSet->add(dsItem);
250 hasNewObjects =
true;
252 else if(it->second->isDirty())
257 dsItem->
setInt32(0, it->second->getId());
262 if(m_graphMetadata->getVertexPropertySize() != 0)
264 for(
size_t i = 0; i < it->second->getAttributes().size(); ++i)
266 dsItem->
setValue(pos + i, it->second->getAttributes()[i]->clone());
270 outDataSetUpdate->add(dsItem);
272 hasUpdatedObjects =
true;
278 std::map<std::string, std::string> options;
282 outDataSet->moveFirst();
283 m_graphMetadata->getDataSource()->add(tableName, outDataSet.get(), options);
287 if(hasUpdatedObjects)
289 outDataSetUpdate->moveFirst();
290 std::map<std::string, std::string> options;
291 std::vector<std::size_t> properties;
293 for(
size_t t = 0; t < dsType->getProperties().size(); ++t)
296 properties.push_back(t);
299 m_graphMetadata->getDataSource()->update(tableName, outDataSetUpdate.get(), properties, 0, options);
301 outDataSetUpdate->clear();
322 std::string tableName = m_graphMetadata->getVertexTableName();
323 std::auto_ptr<te::da::DataSetType> dsType(m_graphMetadata->getDataSource()->getDataSetType(tableName));
328 fields->push_back(f);
342 std::auto_ptr<te::da::DataSet> dataset = m_graphMetadata->getDataSource()->query(select);
347 if(dataset->moveNext())
356 for(
size_t i = 1; i < dsType->getProperties().size(); ++i)
358 v->
addAttribute(i - 1, dataset->getValue(dsType->getProperty(i)->getName()).release());
368 std::string tableName = m_graphMetadata->getEdgeTableName();
369 std::auto_ptr<te::da::DataSetType> dsType(m_graphMetadata->getDataSource()->getDataSetType(tableName));
374 fields->push_back(f);
388 std::auto_ptr<te::da::DataSet> dataset = m_graphMetadata->getDataSource()->query(select);
393 if(dataset->moveNext())
404 for(
size_t i = 3; i < dsType->getProperties().size(); ++i)
406 e->
addAttribute(i - 3, dataset->getValue(dsType->getProperty(i)->getName()).release());
bool isDirty()
Used to check the graph data state.
Class used to define the edge struct of a graph. Its compose with a identifier, the vertex origin and...
void saveGraphEdgeList(GraphData *data)
Used to save the edge elements from a graph data.
void setAttributeVecSize(int size)
This function is used to set the number of attributes associated with the edge elements.
virtual void removeEdge(int id)
Function used to remove a edge saved in a data source.
A class that models the name of a dataset used in a From clause.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
void setAttributeVecSize(int size)
This function is used to set the number of attributes associated with the vertex elements.
A Select models a query to be used when retrieving data from a DataSource.
AbstractGraphLoaderStrategy(te::graph::GraphMetadata *metadata)
Default constructor.
From the point of view of graph theory, vertices are treated as featureless and indivisible objects...
The Field class can be used to model an expression that takes part of the output items of a SELECT...
This class models a string Literal value.
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...
void addAttribute(int idx, te::dt::AbstractData *ad)
Add a new attribute to this element.
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
A class that models the name of any property of an object.
#define TR_GRAPH(message)
It marks a string in order to get translated. This is a special mark used in the Graph module of Terr...
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
virtual ~AbstractGraphLoaderStrategy()
Default destructor.
void setValue(std::size_t i, te::dt::AbstractData *value)
It sets the value of the i-th property.
void addAttribute(int idx, te::dt::AbstractData *ad)
Add a new attribute to this element.
void saveGraphVertexList(GraphData *data)
Used to save the vertex elements from a graph data.
te::graph::GraphMetadata * getMetadata()
It returns a pointer to a class that describes the graph metadata.
An abstract class that models a source of data in a query.
static const std::string sm_tableEdgeModelAttrVFrom
Attribute Vertex From.
Edge * loadEdge(int id)
Function used to load one edge given a ID.
static const std::string sm_tableVertexModelAttrId
Attribute id.
virtual void removeVertex(int id)
Function used to remove a vertex saved in a data source.
void saveVertexAttributes(GraphData *data)
Used to save the vertex elements attributes from a graph data.
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
EdgeMap & getEdgeMap()
It returns the the edge map.
This class define the main functions necessary to save and load the graph data and metadata informati...
static const std::string sm_tableEdgeModelAttrId
Attribute Id.
Vertex * loadVertex(int id)
Function used to load one vertex given a ID.
static const std::string sm_tableEdgeModelAttrVTo
Attribute Vertex To.
It models the comparison operator.
Class used to define the graph metadata informations.
VertexMap & getVertexMap()
It returns the the vertex map.
virtual void saveData(GraphData *data)
Save the graph data structure in Data Source.
A class that can be used to model a filter expression that can be applied to a query.
Edge * loadEdgeAttrs(int id)
Function used to load one edge given a ID.
void saveEdgeAttributes(GraphData *data)
Used to save the edges elements attributes from a graph data.
This class define a important struct used to group a map of vertex and edges. A flag is used to indic...
Vertex * loadVertexAttrs(int id)
Function used to load one vertex given a ID.