24 #include "../common/progress/TaskProgress.h" 25 #include "../core/logger/Logger.h" 26 #include "../core/translator/Translator.h" 27 #include "../dataaccess/dataset/DataSet.h" 28 #include "../dataaccess/dataset/DataSetAdapter.h" 29 #include "../dataaccess/dataset/DataSetType.h" 30 #include "../dataaccess/dataset/DataSetTypeConverter.h" 31 #include "../dataaccess/dataset/ObjectIdSet.h" 32 #include "../dataaccess/datasource/DataSource.h" 33 #include "../dataaccess/datasource/DataSourceInfo.h" 34 #include "../dataaccess/datasource/DataSourceInfoManager.h" 35 #include "../dataaccess/datasource/DataSourceCapabilities.h" 36 #include "../dataaccess/datasource/DataSourceTransactor.h" 37 #include "../dataaccess/query_h.h" 38 #include "../dataaccess/utils/Utils.h" 40 #include "../datatype/Property.h" 41 #include "../datatype/SimpleData.h" 42 #include "../datatype/StringProperty.h" 44 #include "../geometry/Geometry.h" 45 #include "../geometry/GeometryCollection.h" 46 #include "../geometry/GeometryProperty.h" 47 #include "../geometry/MultiLineString.h" 48 #include "../geometry/MultiPoint.h" 49 #include "../geometry/MultiPolygon.h" 50 #include "../geometry/Utils.h" 52 #include "../memory/DataSet.h" 53 #include "../memory/DataSetItem.h" 61 #include <boost/lexical_cast.hpp> 62 #include <boost/uuid/random_generator.hpp> 63 #include <boost/uuid/uuid_io.hpp> 71 : m_targetDst(nullptr),
83 clock_t tStart = clock();
111 std::unique_ptr<te::da::DataSourceTransactor> transactor;
115 std::unique_ptr<te::da::DataSetType> dst;
137 std::unique_ptr<te::da::DataSetType> aux = transactor->getDataSetType(
m_targetDst->
getName());
155 std::size_t pkPos=std::string::npos;
170 pkPos = dst->getPropertyPosition(pkProp);
188 std::size_t outgPos = dst->getPropertyPosition(outgGrop);
198 std::map<std::string, std::string> op;
200 bool isDtCreated =
false;
210 std::string msg =
TE_TR(
"Operation canceled by the user");
211 transactor->rollBack();
254 std::vector<std::string> pkNameVec;
255 pkNameVec.push_back(pkName);
259 transactor->createDataSet(dst.get(), op);
260 transactor->add(dst->getName(), adaptDs.get(), op);
267 transactor->createDataSet(dst.get(), op);
268 transactor->add(dst->getName(),
ds, op);
278 if ((count % BLOCKSIZE) == 0)
280 TE_LOG_INFO(
TE_TR(
" Target Layer Iterating Count: ") + std::to_string(targetCount));
284 transactor->createDataSet(dst.get(), op);
290 std::vector<std::string> pkNameVec;
291 pkNameVec.push_back(pkName);
295 transactor->add(dst->getName(), adaptDs.get(), op);
299 transactor->add(dst->getName(),
ds, op);
310 TE_LOG_INFO(
TE_TR(
" Target Layer Iterating Count: ") + std::to_string(targetCount));
323 std::string msg =
TE_TR(
"Operation canceled by the user");
324 transactor->rollBack();
383 if (fgGrop->getSRID() != sgGrop->
getSRID())
385 geom->transform(fgGrop->getSRID());
392 if ((count % BLOCKSIZE) == 0)
395 TE_LOG_INFO(
" "+
TE_TR(
"Origin Layer Iterating Count: ") + std::to_string(originCount));
399 transactor->createDataSet(dst.get(), op);
405 std::vector<std::string> pkNameVec;
406 pkNameVec.push_back(pkName);
410 transactor->add(dst->getName(), adaptDs.get(), op);
414 transactor->add(dst->getName(),
ds, op);
425 TE_LOG_INFO(
" "+
TE_TR(
"Origin Layer Iterating Count: ") + std::to_string(originCount));
433 transactor->createDataSet(dst.get(), op);
439 std::vector<std::string> pkNameVec;
440 pkNameVec.push_back(pkName);
444 transactor->add(dst->getName(), adaptDs.get(), op);
448 transactor->add(dst->getName(),
ds, op);
455 transactor->commit();
470 transactor->rollBack();
473 catch (std::exception& e)
477 transactor->rollBack();
481 int seconds = (clock() - tStart) / CLOCKS_PER_SEC;
483 minutes = seconds / 60;
484 hours = minutes / 60;
485 std::string timeStr = std::to_string(
int(hours)) +
":" + std::to_string(
int(minutes % 60)) +
":" + std::to_string(
int(seconds % 60));
492 std::map<std::string, te::dt::AbstractData*>::const_iterator it = specificParams.begin();
496 while (it != specificParams.end())
498 if (it->first !=
"ISUPDATE")
519 std::map<std::string, te::dt::AbstractData*>::const_iterator it = specificParams.begin();
521 std::vector<std::pair<std::string, std::string> > propNames;
523 while (it != specificParams.end())
525 if (it->first !=
"ATTRIBUTES")
554 if (fp.empty() && sp.empty())
564 if ((!fp.empty()) && (!sp.empty()))
571 newProp = fProp->
clone();
579 newProp = fProp->
clone();
582 else if (!fp.empty())
584 newProp = fProp->
clone();
590 else if (!sp.empty())
592 newProp = sProp->
clone();
615 for (std::size_t i = 0; i < pkProp.size(); ++i)
617 newPk->
add(dt->getProperty(pkProp[i]->getName()));
620 dt->setPrimaryKey(newPk);
637 std::vector<te::dt::Property*> targetProps = targetPk->
getProperties();
639 if (targetProps.size() > 1)
686 pFrom.push_back(pFromItem);
695 pFields.push_back(pField);
699 std::unique_ptr<te::da::DataSet> result =
m_targetSource->query(pSelect);
703 std::string maxStr = result->getAsString(0);
705 int maxInt = boost::lexical_cast<
int>(maxStr);
718 for (std::size_t i = 0; i < props.size(); ++i)
720 if (props[i]->getName() ==
p)
730 std::vector<te::dt::Property*> pkProps = pk->
getProperties();
731 std::vector<std::string> pkPropsNames;
733 for (
auto i : pkProps)
735 pkPropsNames.push_back(i->getName());
740 if (std::find(pkPropsNames.begin(), pkPropsNames.end(),
m_properties[i].first) != pkPropsNames.end())
746 if (fp.empty() && sp.empty())
756 if ((!fp.empty()) && (!sp.empty()))
770 else if (!fp.empty())
783 else if (!sp.empty())
785 newProp = sProp->
clone();
bool executeQuery(te::vp::AlgorithmParams *mainParams)
virtual std::unique_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
Property * getProperty(std::size_t i) const
It returns the i-th property.
te::da::DataSourcePtr m_originSource
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
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...
An atomic property like an integer or double.
bool isPrimaryKeyProperty(const te::da::DataSetType *dst, const std::string &p)
A class that models the name of a dataset used in a From clause.
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
std::vector< std::pair< std::string, std::string > > getPropNames(const std::map< std::string, te::dt::AbstractData * > &specificParams)
A class that models the name of any property of an object.
A class that models the description of a dataset.
MergeStrategy checkStrategy()
virtual const char * what() const
It outputs the exception message.
std::vector< std::pair< std::string, std::string > > m_properties
void useTimer(bool flag)
Used to define if task use progress timer information.
te::da::DataSetType * m_originDst
te::da::DataSourcePtr m_targetSource
void updateInputDst(te::da::DataSourceTransactor *transactor)
This class can be used to inform the progress of a task.
void setValue(std::size_t i, te::dt::AbstractData *value)
It sets the value of the i-th property.
PrimaryKey * getPrimaryKey() const
It returns the primary key associated to the dataset type.
std::vector< te::vp::InputParams > getInputParams()
std::string m_outDsetName
static te::dt::Date ds(2010, 01, 01)
void setInt16(std::size_t i, boost::int16_t value)
It sets the value of the i-th property.
virtual void changePropertyDefinition(const std::string &datasetName, const std::string &propName, te::dt::Property *newProp)
#define TE_TR(message)
It marks a string in order to get translated.
virtual Property * clone() const =0
It returns a clone of the object.
#define TE_LOG_INFO(message)
Use this tag in order to log a message to the TerraLib default logger with the INFO level...
It models a property definition.
bool isActive() const
Verify if the task is active.
T getValue() const
It returns the associated value.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
void add(DataSetItem *item)
It adds a new item to the dataset and takes its ownership.
void setTotalSteps(int value)
Set the task total stepes.
TEDATAACCESSEXPORT std::unique_ptr< te::da::DataSet > HideColumns(te::da::DataSet *ds, te::da::DataSetType *dst, const std::vector< std::string > &columns)
It hide columns of a DataSet using DataSetAdapter.
An converter for DataSetType.
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
virtual std::size_t size() const =0
It returns the collection size, if it is known.
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
virtual int code() const
It gets the exception code.
virtual void addProperty(const std::string &datasetName, te::dt::Property *p)=0
It adds a new property to the dataset schema.
virtual bool isEmpty() const =0
It returns true if the collection is empty.
A template for complex data types.
te::da::DataSet * m_targetDs
int getSRID() const
It returns the spatial reference system identifier associated to this property.
const std::string & getOutputDataSetName()
static te::dt::TimeDuration dt(20, 30, 50, 11)
te::da::DataSourcePtr m_outDsrc
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
std::unique_ptr< te::da::DataSetType > getOutputDataSetType(te::vp::AlgorithmParams *mainParams)
A base class for values that can be retrieved from the data access module.
te::da::DataSourcePtr getOutputDataSource()
bool isRequired() const
It returns true if the attribute is required, otherwise it returns false.
const std::map< std::string, te::dt::AbstractData * > & getSpecificParams()
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
Utility functions for the data access module.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
A Select models a query to be used when retrieving data from a DataSource.
te::da::DataSetType * m_targetDst
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
int getType() const
It returns the property data type.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
virtual Property * clone() const
It returns a clone of the object.
virtual std::unique_ptr< te::dt::AbstractData > getValue(std::size_t i) const
Method for retrieving any other type of data value stored in the data source.
It describes a primary key (pk) constraint.
virtual bool moveBeforeFirst()=0
It moves the internal pointer to a position before the first item in the collection.
void setRequired(bool r)
It tells if the property is required or not.
#define TE_LOG_ERROR(message)
Use this tag in order to log a message to the TerraLib default logger with the ERROR level...
TEVPEXPORT void ValidateAlgorithmParams(AlgorithmParams *mainParams, Strategy st)
std::size_t getPropertyPosition(const std::string &name) const
It returns the property position based on its name.
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
bool executeMemory(te::vp::AlgorithmParams *mainParams)
void setInt64(std::size_t i, boost::int64_t value)
It sets the value of the i-th property.
bool isAutoNumber() const
It returns true if the attribute is an autonumber, otherwise it returns false.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
TEDATAACCESSEXPORT te::dt::Property * GetFirstSpatialProperty(const DataSetType *dt)
int getPropertyType(const te::dt::Property *p)
Max statistical function.
bool isUpdate(const std::map< std::string, te::dt::AbstractData * > &specificParams)
te::da::DataSet * m_originDs
const std::string & getName() const
It returns the property name.