src/terralib/binding/v8/jsi/dataaccess/DataSourceTransactor.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file DataSourceTransactor.cpp
22 
23  \brief Utility functions to register the DataSourceTransactor class into Google JavaScript V8 engine.
24  */
25 
26 // TerraLib
27 #include "../../../../common/Exception.h"
28 #include "../../../../core/translator/Translator.h"
29 #include "../../../../dataaccess/dataset/DataSet.h"
30 #include "../../../../dataaccess/dataset/DataSetPersistence.h"
31 #include "../../../../dataaccess/dataset/DataSetTypePersistence.h"
32 #include "../../../../dataaccess/datasource/BatchExecutor.h"
33 #include "../../../../dataaccess/datasource/DataSource.h"
34 #include "../../../../dataaccess/datasource/DataSourceCatalogLoader.h"
35 #include "../../../../dataaccess/datasource/DataSourceTransactor.h"
36 #include "../../../../dataaccess/datasource/PreparedQuery.h"
37 #include "../../common/Utils.h"
38 #include "DataAccess.h"
39 
40 // STL
41 #include <memory>
42 
43 ::v8::Handle<::v8::Value> DataSourceTransactor_Begin(const ::v8::Arguments& /*args*/)
44 {
45  ::v8::HandleScope hs;
46  return ::v8::Undefined();
47 }
48 
49 ::v8::Handle<::v8::Value> DataSourceTransactor_Commit(const ::v8::Arguments& /*args*/)
50 {
51  ::v8::HandleScope hs;
52  return ::v8::Undefined();
53 }
54 
55 ::v8::Handle<::v8::Value> DataSourceTransactor_RollBack(const ::v8::Arguments& /*args*/)
56 {
57  ::v8::HandleScope hs;
58  return ::v8::Undefined();
59 }
60 
61 ::v8::Handle<::v8::Value> DataSourceTransactor_GetDataSet(const ::v8::Arguments& args)
62 {
63  ::v8::HandleScope hs;
64 
65  if(args.Holder().IsEmpty())
66  return ::v8::ThrowException(::v8::String::New(TR_V8JSI("In order to use the getDataSet method you must use the object notation: \"dataset = obj.getDataSet(\"mydataset-name\");\"")));
67 
68  if(args.Length() != 1 || args[0].IsEmpty() || !args[0]->IsString())
69  return ::v8::ThrowException(::v8::String::New(TR_V8JSI("Wrong parameters in getDataSet method!")));
70 
71  te::da::DataSourceTransactor* t = te::v8::common::Unwrap<te::da::DataSourceTransactor>(args.Holder());
72 
73  if(t == 0)
74  return ::v8::ThrowException(::v8::String::New(TR_V8JSI("Invalid data source transactor in getDataSet method!")));
75 
76  try
77  {
78  v8::String::Utf8Value jdatasetname(args[0]->ToString());
79  std::auto_ptr<te::da::DataSet> dataset(t->getDataSet(*jdatasetname));
80  ::v8::Local<::v8::Object> jsdataset = te::v8::common::Make(dataset.get(), te::v8::jsi::GetDataSetTemplate, true);
81  dataset.release();
82  return hs.Close(jsdataset);
83  }
84  catch(const std::exception& e)
85  {
86  return ::v8::ThrowException(::v8::String::New(e.what()));
87  }
88  catch(...)
89  {
90  return ::v8::ThrowException(::v8::String::New(TR_V8JSI("Unexpected exception in getDataSet method!")));
91  }
92 }
93 
94 ::v8::Handle<::v8::Value> DataSourceTransactor_GetDataSetByEnvelope(const ::v8::Arguments& /*args*/)
95 {
96  ::v8::HandleScope hs;
97  return ::v8::Undefined();
98 }
99 
100 ::v8::Handle<::v8::Value> DataSourceTransactor_GetDataSetByGeom(const ::v8::Arguments& /*args*/)
101 {
102  ::v8::HandleScope hs;
103  return ::v8::Undefined();
104 }
105 
106 ::v8::Handle<::v8::Value> DataSourceTransactor_Query(const ::v8::Arguments& /*args*/)
107 {
108  return ::v8::Undefined();
109 }
110 
111 ::v8::Handle<::v8::Value> DataSourceTransactor_Execute(const ::v8::Arguments& /*args*/)
112 {
113  ::v8::HandleScope hs;
114  return ::v8::Undefined();
115 }
116 
117 ::v8::Handle<::v8::Value> DataSourceTransactor_GetPreparedStmt(const ::v8::Arguments& /*args*/)
118 {
119  ::v8::HandleScope hs;
120  return ::v8::Undefined();
121 }
122 
123 ::v8::Handle<::v8::Value> DataSourceTransactor_GetBatchExecutor(const ::v8::Arguments& /*args*/)
124 {
125  ::v8::HandleScope hs;
126  return ::v8::Undefined();
127 }
128 
129 ::v8::Handle<::v8::Value> DataSourceTransactor_GetCatalogLoader(const ::v8::Arguments& /*args*/)
130 {
131  ::v8::HandleScope hs;
132  return ::v8::Undefined();
133 }
134 
135 ::v8::Handle<::v8::Value> DataSourceTransactor_GetDataSetTypePersistence(const ::v8::Arguments& /*args*/)
136 {
137  ::v8::HandleScope hs;
138  return ::v8::Undefined();
139 }
140 
141 ::v8::Handle<::v8::Value> DataSourceTransactor_GetDataSetPersistence(const ::v8::Arguments& /*args*/)
142 {
143  ::v8::HandleScope hs;
144  return ::v8::Undefined();
145 }
146 
147 ::v8::Handle<::v8::Value> DataSourceTransactor_Cancel(const ::v8::Arguments& /*args*/)
148 {
149  ::v8::HandleScope hs;
150  return ::v8::Undefined();
151 }
152 
153 ::v8::Handle<::v8::Value> DataSourceTransactor_GetDataSource(const ::v8::Arguments& /*args*/)
154 {
155  ::v8::HandleScope hs;
156  return ::v8::Undefined();
157 }
158 
159 static ::v8::Persistent<::v8::FunctionTemplate> sds_datasourcetransactor_template;
160 
161 ::v8::Persistent<::v8::FunctionTemplate>& te::v8::jsi::GetDataSourceTransactorTemplate()
162 {
164  {
165  ::v8::Local<::v8::FunctionTemplate> result = ::v8::FunctionTemplate::New();
166  ::v8::Handle<::v8::ObjectTemplate> prototype = result->PrototypeTemplate();
167 
168  prototype->Set(::v8::String::NewSymbol("begin"), ::v8::FunctionTemplate::New(DataSourceTransactor_Begin));
169  prototype->Set(::v8::String::NewSymbol("commit"), ::v8::FunctionTemplate::New(DataSourceTransactor_Commit));
170  prototype->Set(::v8::String::NewSymbol("rollBack"), ::v8::FunctionTemplate::New(DataSourceTransactor_RollBack));
171  prototype->Set(::v8::String::NewSymbol("getDataSet"), ::v8::FunctionTemplate::New(DataSourceTransactor_GetDataSet));
172  prototype->Set(::v8::String::NewSymbol("getDataSetByEnvelope"), ::v8::FunctionTemplate::New(DataSourceTransactor_GetDataSetByEnvelope));
173  prototype->Set(::v8::String::NewSymbol("getDataSetByGeom"), ::v8::FunctionTemplate::New(DataSourceTransactor_GetDataSetByGeom));
174  prototype->Set(::v8::String::NewSymbol("query"), ::v8::FunctionTemplate::New(DataSourceTransactor_Query));
175  prototype->Set(::v8::String::NewSymbol("execute"), ::v8::FunctionTemplate::New(DataSourceTransactor_Execute));
176  prototype->Set(::v8::String::NewSymbol("getPrepared"), ::v8::FunctionTemplate::New(DataSourceTransactor_GetPreparedStmt));
177  prototype->Set(::v8::String::NewSymbol("getBatchExecutor"), ::v8::FunctionTemplate::New(DataSourceTransactor_GetBatchExecutor));
178  prototype->Set(::v8::String::NewSymbol("getCatalogLoader"), ::v8::FunctionTemplate::New(DataSourceTransactor_GetCatalogLoader));
179  prototype->Set(::v8::String::NewSymbol("getDataSetTypePersistence"), ::v8::FunctionTemplate::New(DataSourceTransactor_GetDataSetTypePersistence));
180  prototype->Set(::v8::String::NewSymbol("getDataSetPersistence"), ::v8::FunctionTemplate::New(DataSourceTransactor_GetDataSetPersistence));
181  prototype->Set(::v8::String::NewSymbol("cancel"), ::v8::FunctionTemplate::New(DataSourceTransactor_Cancel));
182  prototype->Set(::v8::String::NewSymbol("getDataSource"), ::v8::FunctionTemplate::New(DataSourceTransactor_GetDataSource));
183 
184  sds_datasourcetransactor_template = ::v8::Persistent<::v8::FunctionTemplate>::New(result);
185  }
186 
188 }
189 
::v8::Local<::v8::Object > Make(T *obj, TF tfunc, const bool isOwner)
It creates a new JavaScript object from a C++ object (obj).
::v8::Handle<::v8::Value > DataSourceTransactor_Execute(const ::v8::Arguments &)
::v8::Handle<::v8::Value > DataSourceTransactor_GetDataSet(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > DataSourceTransactor_GetDataSetTypePersistence(const ::v8::Arguments &)
JavaScript exporting routine for the TerraLib Data Access module.
::v8::Handle<::v8::Value > DataSourceTransactor_Cancel(const ::v8::Arguments &)
::v8::Handle<::v8::Value > DataSourceTransactor_GetPreparedStmt(const ::v8::Arguments &)
::v8::Handle<::v8::Value > DataSourceTransactor_GetDataSetByGeom(const ::v8::Arguments &)
::v8::Handle<::v8::Value > DataSourceTransactor_Begin(const ::v8::Arguments &)
static::v8::Persistent<::v8::FunctionTemplate > sds_datasourcetransactor_template
::v8::Handle<::v8::Value > DataSourceTransactor_RollBack(const ::v8::Arguments &)
::v8::Handle<::v8::Value > DataSourceTransactor_GetDataSetPersistence(const ::v8::Arguments &)
::v8::Handle<::v8::Value > DataSourceTransactor_Query(const ::v8::Arguments &)
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
::v8::Handle<::v8::Value > DataSourceTransactor_GetDataSource(const ::v8::Arguments &)
::v8::Persistent<::v8::FunctionTemplate > & GetDataSetTemplate()
It returns a reference to the persistent template of a DataSet object.
::v8::Handle<::v8::Value > DataSourceTransactor_Commit(const ::v8::Arguments &)
virtual std::unique_ptr< DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)=0
It gets the dataset identified by the given name. A dataset can be connected or disconnected. A connected dataset, after its creation through the data source transactor, continues to depend on the connection given by its associated data source. Differently, a disconnected dataset, after its creation, no more depends of the connection given by the data source, and it continues to live after the connection has been released to the data source.
::v8::Handle<::v8::Value > DataSourceTransactor_GetBatchExecutor(const ::v8::Arguments &)
::v8::Persistent<::v8::FunctionTemplate > & GetDataSourceTransactorTemplate()
It returns a reference to the persistent template of a DataSourceTransactor object.
#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 > DataSourceTransactor_GetDataSetByEnvelope(const ::v8::Arguments &)
::v8::Handle<::v8::Value > DataSourceTransactor_GetCatalogLoader(const ::v8::Arguments &)
std::string ToString(const XMLCh *const value)
It converts the XML string to a standard C++ string.