27 #include "../../../../common/Exception.h" 28 #include "../../../../core/translator/Translator.h" 29 #include "../../../../dataaccess/datasource/DataSource.h" 30 #include "../../common/Utils.h" 37 #include <boost/cstdint.hpp> 43 if(args.Holder().IsEmpty())
44 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"In order to use the getType method you must use the object notation: \"t = obj.getType();\"")));
49 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"Invalid data source in getType method!")));
51 const std::string& dst = ds->
getType();
53 ::v8::Local<::v8::String> jdst = ::v8::String::New(dst.c_str());
55 return hs.Close(jdst);
62 if(args.Holder().IsEmpty())
63 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"In order to use the getConnectionInfo method you must use the object notation: \"conninfo = obj.getConnectionInfo();\"")));
68 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"Invalid data source in getConnectionInfo method!")));
74 return hs.Close(jsmap);
81 if(args.Holder().IsEmpty())
82 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"In order to use the setConnectionInfo method you must use the object notation: \"obj.setConnectionInfo(conninfo);\"")));
87 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"Invalid data source in setConnectionInfo method!")));
89 if((args.Length() != 1) || args[0].IsEmpty() || !args[0]->IsArray())
90 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"In order to use setConnectionInfo method you must use object notation: \"obj.setConnectionInfo(connfinfo);\"")));
92 ::v8::Local<::v8::Object> aconninfo = args[0]->ToObject();
94 std::map<std::string, std::string> conninfo;
98 ds->setConnectionInfo(conninfo);
100 return ::v8::Undefined();
105 ::v8::HandleScope hs;
107 if(args.Holder().IsEmpty())
108 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"In order to use the getConnectionStr method you must use the object notation: \"connstr = obj.getConnectionStr();\"")));
113 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"Invalid data source in the getConnectionStr method!")));
115 const std::string& connStr = ds->getConnectionStr();
117 ::v8::Local<::v8::String> jconnStr = ::v8::String::New(connStr.c_str());
119 return hs.Close(jconnStr);
124 ::v8::HandleScope hs;
126 if(args.Holder().IsEmpty())
127 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"In order to use the setConnectionStr method you must use the object notation: \"obj.setConnectionStr(connstr);\"")));
129 if(args.Length() != 1 || args[0].IsEmpty() || !args[0]->IsString())
130 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"In order to use the setConnectionStr method, you must use the object notation: \"obj.setConnectionStr(\"connStr\");\"")));
135 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"Invalid data source in setConnectionStr method!")));
137 ::v8::String::Utf8Value jconnStr(args[0]->
ToString());
139 ds->setConnectionStr(*jconnStr);
141 return ::v8::Undefined();
146 ::v8::HandleScope hs;
147 return ::v8::Undefined();
152 ::v8::HandleScope hs;
153 return ::v8::Undefined();
158 ::v8::HandleScope hs;
160 if(args.Holder().IsEmpty())
161 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"In order to use the open method, you must use the object notation: \"obj.open();\" or \"obj.open(conn_string);\" or \"obj.open(conninfo);\"")));
166 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"Invalid data source in open method!")));
170 if(args.Length() == 0)
176 if((args.Length() == 1) && (!args[0].IsEmpty()) && (args[0]->IsString()))
178 v8::String::Utf8Value jconnInfo(args[0]->
ToString());
179 ds->
open(*jconnInfo);
181 else if((args.Length() == 1) && (!args[0].IsEmpty()) && (args[0]->IsArray()))
183 ::v8::Local<::v8::Object> aconninfo = args[0]->ToObject();
184 std::map<std::string, std::string> conninfo;
192 catch(
const std::exception& e)
194 return ::v8::ThrowException(::v8::String::New(e.what()));
198 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"Unexpected exception in open method!")));
201 return ::v8::Undefined();
206 ::v8::HandleScope hs;
208 if(args.Holder().IsEmpty())
209 return ::v8::ThrowException(::v8::String::New(
"In order to use the close method, you must use the object notation: \"obj.close();\""));
214 return ::v8::ThrowException(::v8::String::New(
"Invalid data source in the close method!"));
220 catch(
const std::exception& e)
222 return ::v8::ThrowException(::v8::String::New(e.what()));
226 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"Unexpected exception in close method!")));
229 return ::v8::Undefined();
234 ::v8::HandleScope hs;
236 if(args.Holder().IsEmpty())
237 return ::v8::ThrowException(::v8::String::New(
"In order to use the isOpened method, you must use the object notation: \"result = obj.isOpened();\""));
242 return ::v8::ThrowException(::v8::String::New(
"Invalid data source in isOpened method!"));
246 ::v8::Handle<::v8::Boolean> jresult = ::v8::Boolean::New(result);
248 return hs.Close(jresult);
253 ::v8::HandleScope hs;
255 if(args.Holder().IsEmpty())
256 return ::v8::ThrowException(::v8::String::New(
"In order to use the isValid method, you must use the object notation: \"result = obj.isValid();\""));
261 return ::v8::ThrowException(::v8::String::New(
"Invalid data source in isValid method!"));
265 ::v8::Handle<::v8::Boolean> jresult = ::v8::Boolean::New(result);
267 return hs.Close(jresult);
272 ::v8::HandleScope hs;
274 if(args.Holder().IsEmpty())
275 return ::v8::ThrowException(::v8::String::New(
"In order to use the getCatalog method you must use the object notation: \"c = obj.getCatalog();\""));
280 return ::v8::ThrowException(::v8::String::New(
"Invalid data source in the getCatalog method!"));
282 std::auto_ptr<te::da::DataSourceCatalog> catalog(ds->getCatalog());
288 return hs.Close(jcatalog);
293 ::v8::HandleScope hs;
295 if(args.Holder().IsEmpty())
296 return ::v8::ThrowException(::v8::String::New(
"In order to use the getTransactor method you must use the object notation: \"c = obj.getTransactor();\""));
301 return ::v8::ThrowException(::v8::String::New(
"Invalid data source in the getTransactor method!"));
305 std::auto_ptr<te::da::DataSourceTransactor> t(ds->
getTransactor());
310 catch(
const std::exception& e)
312 return ::v8::ThrowException(::v8::String::New(e.what()));
316 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"Unexpected exception in getTransactor method!")));
322 ::v8::HandleScope hs;
323 return ::v8::Undefined();
328 ::v8::HandleScope hs;
330 if(args.Length() != 1 || args[0].IsEmpty() || !args[0]->IsObject() )
331 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"Wrong parameters drop method!")));
338 te::v8::common::LooseOwnership<te::da::DataSource>(args[0]->ToObject());
340 catch(
const std::exception& e)
342 return ::v8::ThrowException(::v8::String::New(e.what()));
346 return ::v8::ThrowException(::v8::String::New(
TR_V8JSI(
"Unexpected exception in drop method!")));
349 return ::v8::Undefined();
354 ::v8::HandleScope hs;
356 ::v8::Handle<::v8::ObjectTemplate> objTpl = ::v8::ObjectTemplate::New();
358 objTpl->Set(::v8::String::NewSymbol(
"create"), ::v8::FunctionTemplate::New(
DataSource_Create));
359 objTpl->Set(::v8::String::NewSymbol(
"drop"), ::v8::FunctionTemplate::New(
DataSource_Drop));
361 global->Set(::v8::String::New(
"TeDataSource"), objTpl->NewInstance());
370 ::v8::Local<::v8::FunctionTemplate> result = ::v8::FunctionTemplate::New();
371 ::v8::Handle<::v8::ObjectTemplate> prototype = result->PrototypeTemplate();
373 prototype->Set(::v8::String::NewSymbol(
"getType"), ::v8::FunctionTemplate::New(
DataSource_GetType));
379 prototype->Set(::v8::String::NewSymbol(
"getDialect"), ::v8::FunctionTemplate::New(
DataSource_GetDialect));
380 prototype->Set(::v8::String::NewSymbol(
"open"), ::v8::FunctionTemplate::New(
DataSource_Open));
381 prototype->Set(::v8::String::NewSymbol(
"close"), ::v8::FunctionTemplate::New(
DataSource_Close));
382 prototype->Set(::v8::String::NewSymbol(
"isOpened"), ::v8::FunctionTemplate::New(
DataSource_IsOpened));
383 prototype->Set(::v8::String::NewSymbol(
"isValid"), ::v8::FunctionTemplate::New(
DataSource_IsValid));
384 prototype->Set(::v8::String::NewSymbol(
"getCatalog"), ::v8::FunctionTemplate::New(
DataSource_GetCatalog));
::v8::Local<::v8::Object > Make(T *obj, TF tfunc, const bool isOwner)
It creates a new JavaScript object from a C++ object (obj).
virtual bool isValid() const =0
It checks if the data source is valid (available for using).
::v8::Handle<::v8::Value > DataSource_Open(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > DataSource_GetDialect(const ::v8::Arguments &)
virtual std::unique_ptr< DataSourceTransactor > getTransactor()=0
It returns the set of parameters used to set up the access channel to the underlying repository...
virtual void open()=0
It opens the data source and makes it ready for using.
::v8::Handle<::v8::Value > DataSource_Create(const ::v8::Arguments &)
::v8::Handle<::v8::Value > DataSource_Drop(const ::v8::Arguments &args)
JavaScript exporting routine for the TerraLib Data Access module.
virtual bool isOpened() const =0
It returns true if the data source is opened, otherwise it returns false.
::v8::Handle<::v8::Value > DataSource_GetConnectionStr(const ::v8::Arguments &args)
::v8::Persistent<::v8::FunctionTemplate > & GetDataSourceCatalogTemplate()
It returns a reference to the persistent template of a DataSourceCatalog object.
static te::dt::Date ds(2010, 01, 01)
static void drop(const std::string &dsType, const std::string &connInfo)
It removes a data source identified by its connection information and the driver type.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
::v8::Persistent<::v8::FunctionTemplate > & GetDataSourceTemplate()
It returns a reference to the persistent template of a DataSource object.
void RegisterDataSource(::v8::Local<::v8::Object > &global)
It registers the DataSource class.
::v8::Handle<::v8::Value > DataSource_GetCatalog(const ::v8::Arguments &args)
virtual std::string getType() const =0
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS, or MYSQL.
::v8::Handle<::v8::Value > DataSource_GetConnectionInfo(const ::v8::Arguments &args)
inline::v8::Local<::v8::Object > Convert2Js(const std::map< std::string, std::string > &m)
It converts the input map to an object representing the associative conteiner.
static::v8::Persistent<::v8::FunctionTemplate > sg_datasource_template
void Convert2Cpp(const ::v8::Local<::v8::Object > &jsmap, std::map< std::string, std::string > &cppmap)
It converts the input map to an object representing the associative conteiner.
::v8::Handle<::v8::Value > DataSource_IsValid(const ::v8::Arguments &args)
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
const te::core::URI & getConnectionInfo() const
An Uniform Resource Identifier used to describe the datasource connection.
::v8::Handle<::v8::Value > DataSource_GetType(const ::v8::Arguments &args)
virtual void close()=0
It closes the data source and clears all the resources used by its internal communication channel...
::v8::Handle<::v8::Value > DataSource_SetConnectionInfo(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > DataSource_IsOpened(const ::v8::Arguments &args)
::v8::Persistent<::v8::FunctionTemplate > & GetDataSourceTransactorTemplate()
It returns a reference to the persistent template of a DataSourceTransactor object.
::v8::Handle<::v8::Value > DataSource_SetConnectionStr(const ::v8::Arguments &args)
#define TR_V8JSI(message)
It marks a string in order to get translated. This is a special mark used in the Vector Geometry modu...
::v8::Handle<::v8::Value > DataSource_GetTransactor(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > DataSource_Close(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > DataSource_GetCapabilities(const ::v8::Arguments &)
std::string ToString(const XMLCh *const value)
It converts the XML string to a standard C++ string.