28 #include "../../../common/StringUtils.h"
29 #include "../../../common/Translator.h"
30 #include "../../../dataaccess/dataset/DataSetType.h"
31 #include "../../../dataaccess/dataset/ForeignKey.h"
32 #include "../../../dataaccess/dataset/Index.h"
33 #include "../../../dataaccess/dataset/PrimaryKey.h"
34 #include "../../../dataaccess/datasource/DataSource.h"
35 #include "../../../dataaccess/query_h.h"
36 #include "../../../dataaccess/Enums.h"
37 #include "../../../datatype/SimpleProperty.h"
38 #include "../../../datatype/StringProperty.h"
39 #include "../../../geometry/GeometryProperty.h"
40 #include "../../../memory/DataSet.h"
41 #include "../../../memory/DataSetItem.h"
42 #include "../../core/EdgeProperty.h"
43 #include "../../core/VertexProperty.h"
44 #include "../../Config.h"
45 #include "../../Exception.h"
46 #include "../../Globals.h"
63 throw Exception(
TR_GRAPH(
"Data Source not defined."));
70 loadGraphAttrInfo(
id);
77 throw Exception(
TR_GRAPH(
"Data Source not defined."));
80 if(this->getName().empty())
82 throw Exception(
TR_GRAPH(
"Graph name not defined."));
85 if(!isValidGraphName(this->getName()))
87 throw Exception(
TR_GRAPH(
"Invalid graph name."));
91 addGraphTableNewEntry();
94 addGraphAttrTableNewEntry();
99 createGraphTableVertexModel();
101 if(getEdgePropertySize() != 0)
103 createEdgeAttrTable();
108 createGraphTableEdgeModel();
110 if(getVertexPropertySize() != 0)
112 createVertexAttrTable();
127 if(getVertexPropertySize() == 0)
129 createVertexAttrTable();
135 std::string tableName = this->getVertexTableName();
141 saveProperty(tableName, p);
148 std::string propertyName = p->
getName();
153 std::string tableName = this->getVertexTableName();
156 removeProperty(tableName, propertyName);
163 throw Exception(
TR_GRAPH(
"TO DO."));
169 std::string tableName = this->getEdgeTableName();
175 saveProperty(tableName, p);
182 std::string propertyName = p->
getName();
187 std::string tableName = this->getEdgeTableName();
190 removeProperty(tableName, propertyName);
214 dt->
add(prop_tableName);
248 dt->
add(prop_graphId);
258 dt->
add(prop_column);
278 idxName +=
"_attr_idx";
287 throw Exception(
TR_GRAPH(
"TO DO."));
299 dt->
add(prop_edgeId);
312 if(getEdgePropertySize() != 0)
314 for(
int i = 0; i < getEdgePropertySize(); ++i)
329 std::string pkName = tableName;
333 pk->
add(prop_edgeId);
336 std::string idxEdge = tableName;
337 idxEdge +=
"_edge_idx";
339 indexEdge->
add(prop_edgeId);
341 std::string idxVFrom = tableName;
342 idxVFrom +=
"_vfrom_idx";
344 indexVFrom->
add(prop_vFrom);
346 std::string idxVTo = tableName;
347 idxVTo +=
"_vto_idx";
349 indexVTo->
add(prop_vTo);
354 std::string idxSpatial = tableName;
355 idxSpatial +=
"_spatial_idx";
360 createTable(tableName, dt);
376 if(getVertexPropertySize() != 0)
378 for(
int i = 0; i < getVertexPropertySize(); ++i)
393 std::string pkName = tableName;
399 std::string idxName = tableName;
407 std::string idxSpatial = tableName;
408 idxSpatial +=
"_spatial_idx";
413 createTable(tableName, dt);
418 throw Exception(
TR_GRAPH(
"TO DO."));
423 if(m_ds->dataSetExists(tableName))
429 std::map<std::string, std::string> options;
431 m_ds->createDataSet(dt, options);
442 createGraphMetadataTable();
453 dsItem->
setInt32(1, (
int)this->getStorageMode());
457 dsItem->
setString(2, this->getEdgeTableName());
461 dsItem->
setString(2, this->getVertexTableName());
464 dsItem->
setString(3, this->getDescription());
467 std::map<std::string, std::string> options;
480 createGraphAttributesTable();
483 if(getEdgePropertySize() != 0)
485 std::string tableName = this->getEdgeTableName();
487 for(
int i = 0; i < getEdgePropertySize(); ++i)
494 if(getVertexPropertySize() != 0)
496 std::string tableName = this->getVertexTableName();
498 for(
int i = 0; i < getVertexPropertySize(); ++i)
522 std::map<std::string, std::string> options;
533 std::auto_ptr<te::da::DataSetType> dsType(m_ds->getDataSetType(tableName));
536 m_ds->addProperty(tableName, p);
542 std::string idxSpatial = tableName;
543 idxSpatial +=
"_spatial_idx";
548 std::map<std::string, std::string> options;
550 m_ds->addIndex(tableName, idx, options);
556 m_ds->dropProperty(tableName, propertyName);
564 fields->push_back(f);
579 std::auto_ptr<te::da::DataSet> dataset = m_ds->query(select);
581 if(dataset->moveNext())
604 fields->push_back(f);
619 std::auto_ptr<te::da::DataSet> dataset = m_ds->query(select);
621 while(dataset->moveNext())
630 loadVertexAttr(tableName, columnName);
634 loadEdgeAttr(tableName, columnName);
642 std::auto_ptr<te::dt::Property> p = m_ds->getProperty(tableName, columnName);
652 std::auto_ptr<te::dt::Property> p = m_ds->getProperty(tableName, columnName);
663 fields->push_back(f);
677 std::auto_ptr<te::da::DataSet> dataset = m_ds->query(select);
679 if(dataset->moveNext())
std::string Convert2LCase(const std::string &value)
It converts a string to lower case.
static const std::string sm_tableAttributeAttrLink
Attribute Link.
It describes an index associated to a DataSetType.
Class used to define the graph metadata informations over a SGBD source.
void setParent(Property *p)
It associate this property to the informed parent.
virtual te::dt::Property * getVertexProperty(int idx)
Get a vertex property given a index.
A class that models the name of a dataset used in a From clause.
An atomic property like an integer or double.
void saveGraphAttrTableNewEntry(int graphId, std::string tableName, std::string attrName, std::string linkColumn, te::graph::GraphAttrType type)
Save each metadata attributes of vertex and eges into SGBD.
static const std::string sm_tableAttributeAttrTable
Attribute Table.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
void loadEdgeAttr(std::string tableName, std::string columnName)
Load the edge attributes.
void createTable(std::string tableName, te::da::DataSetType *dt)
Function used to create a table inside the SGBD.
void addGraphTableNewEntry()
Add a new graph metadata information into the SGBD.
A Select models a query to be used when retrieving data from a DataSource.
The type for string types: FIXED_STRING, VAR_STRING or STRING.
te::graph::GraphStorageMode m_mode
Enum attribute used to defines the storage mode.
static const std::string sm_tableAttributeAttrType
Attribute Type.
void createGraphTableVertexModel()
Function used to create the vertex model scheme of tables.
virtual void addVertexProperty(te::dt::Property *p)
Add a new property associated to the vertex element.
The Field class can be used to model an expression that takes part of the output items of a SELECT...
void createGraphAttributesTable()
Function used to create the graph metadata attributes tables in a SGBD.
static const std::string sm_tableGraphAttrId
Attribute Id.
This class models a string Literal value.
It describes a primary key (pk) constraint.
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
virtual void removeEdgeProperty(int idx)
Remove a property associated to the edge element.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
const std::string & getName() const
It returns the property name.
void add(Constraint *c)
It adds a new constraint.
void setSize(std::size_t s)
It sets the maximum number of characters for a varying string, or the number of characters for a fixe...
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...
virtual void addVertexProperty(te::dt::Property *p)
Add a new property associated to the vertex element.
~DatabaseGraphMetadata()
Default destructor.
void load(int id)
Function used to load the graph information given a graph id.
void removeProperty(std::string tableName, std::string propertyName)
Remove a property of a table in SGBD.
void addGraphAttrTableNewEntry()
Add a new graph attributes metadata information into the SGBD.
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
static const std::string sm_tableAttributeAttrColumn
Attribute Column.
virtual void removeVertexProperty(int idx)
Remove a property associated to the vertex element.
void saveProperty(std::string tableName, te::dt::Property *p)
Save a property into a table in SGBD.
virtual te::dt::Property * getEdgeProperty(int idx)
Get a edge property given a index.
virtual void addEdgeProperty(te::dt::Property *p)
Add a new property associated to the edge element.
void update()
Function used to update the graph information on a data source.
static const std::string sm_tableGraphAttrTableName
Attribute Table Name.
An abstract class that models a source of data in a query.
static const std::string sm_tableEdgeModelAttrVFrom
Attribute Vertex From.
static const std::string sm_tableVertexModelAttrId
Attribute id.
static const std::string sm_tableEdgeModelSufixName
Database Model Edge Model Table Name.
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
static const std::string sm_tableAttributeAttrGraphId
Attribute Graph Id.
void createVertexAttrTable()
Used when edge_model is selected and vertex objects has attributes associated.
void createGraphMetadataTable()
Function used to create the graph metadata tables in a SGBD.
void add(te::dt::Property *p)
It adds the property to the list of properties of the index.
virtual void removeVertexProperty(int idx)
Remove a property associated to the vertex element.
void setString(std::size_t i, const std::string &value)
It sets the value of the i-th property.
static const std::string sm_tableGraphAttrType
Attribute Type.
static const std::string sm_tableGraphName
Database Model Table Graph Name.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
static const std::string sm_tableVertexAttributeModelSufixName
Database Model Vertex Attribute Model Table Name.
static const std::string sm_tableEdgeModelAttrId
Attribute Id.
void createGraphTableEdgeModel()
Function used to create the edge model scheme of tables.
A class that models the description of a dataset.
bool isValidGraphName(std::string graphName)
Verify if a graph name is valid.
virtual void removeEdgeProperty(int idx)
Remove a property associated to the edge element.
static const std::string sm_tableGraphAttrName
Attribute Name.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
It models a property definition.
void loadGraphAttrInfo(int id)
Function used to load the graph attributes information given a graph id.
static const std::string sm_tableGraphAttrDesc
Attribute Description.
static const std::string sm_tableEdgeModelAttrVTo
Attribute Vertex To.
It models the comparison operator.
Class used to define the graph metadata informations.
int getType() const
It returns the property data type.
void loadVertexAttr(std::string tableName, std::string columnName)
Load the vertex attributes.
void createEdgeAttrTable()
Used when vertex_model is selected and edge objects has attributes associated.
static const std::string sm_tableAttributeName
Database Model Table Attribute Name.
DatabaseGraphMetadata(te::da::DataSource *ds)
Default constructor.
void loadGraphInfo(int id)
Function used to load the graph information given a graph id.
void save()
Function used to save the graph information.
virtual void addEdgeProperty(te::dt::Property *p)
Add a new property associated to the edge element.
A class that can be used to model a filter expression that can be applied to a query.
virtual Property * clone() const =0
It returns a clone of the object.
static const std::string sm_tableAttributeAttrId
Attribute Id.