binding/v8/jsi/dataaccess/AbstractConnectionPool.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 AbstractConnectionPool.cpp
22 
23  \brief Utility functions to register the AbstractConnectionPool class into Google JavaScript V8 engine.
24  */
25 
26 // TerraLib
27 #include "../../../../dataaccess/datasource/AbstractConnectionPool.h"
28 #include "../../common/Utils.h"
29 #include "DataAccess.h"
30 
31 // Boost
32 #include <boost/cstdint.hpp>
33 
34 ::v8::Handle<::v8::Value> AbstractConnectionPool_Initialize(const ::v8::Arguments& args)
35 {
36  te::da::AbstractConnectionPool* pool = te::v8::common::Unwrap<te::da::AbstractConnectionPool>(args.Holder());
37 
38  if(pool == 0)
39  return ::v8::ThrowException(::v8::String::New("Invalid connection pool in the initialize method!"));
40 
41  pool->initialize();
42 
43  return ::v8::Undefined();
44 }
45 
46 ::v8::Handle<::v8::Value> AbstractConnectionPool_Finalize(const ::v8::Arguments& args)
47 {
48  te::da::AbstractConnectionPool* pool = te::v8::common::Unwrap<te::da::AbstractConnectionPool>(args.Holder());
49 
50  if(pool == 0)
51  return ::v8::ThrowException(::v8::String::New("Invalid connection pool in the finalize method!"));
52 
53  pool->finalize();
54 
55  return ::v8::Undefined();
56 }
57 
58 ::v8::Handle<::v8::Value> AbstractConnectionPool_Idle(const ::v8::Arguments& args)
59 {
60  te::da::AbstractConnectionPool* pool = te::v8::common::Unwrap<te::da::AbstractConnectionPool>(args.Holder());
61 
62  if(pool == 0)
63  return ::v8::ThrowException(::v8::String::New("Invalid connection pool in the idle method!"));
64 
65  pool->idle();
66 
67  return ::v8::Undefined();
68 }
69 
70 ::v8::Handle<::v8::Value> AbstractConnectionPool_IsValid(const ::v8::Arguments& args)
71 {
72  ::v8::HandleScope hs;
73 
74  te::da::AbstractConnectionPool* pool = te::v8::common::Unwrap<te::da::AbstractConnectionPool>(args.Holder());
75 
76  if(pool == 0)
77  return ::v8::ThrowException(::v8::String::New("Invalid connection pool in the isValid method!"));
78 
79  bool isValid = pool->isValid();
80 
81  ::v8::Handle<::v8::Boolean> jisValid = ::v8::Boolean::New(isValid);
82 
83  return hs.Close(jisValid);
84 }
85 
86 ::v8::Handle<::v8::Value> AbstractConnectionPool_IsInitialized(const ::v8::Arguments& args)
87 {
88  ::v8::HandleScope hs;
89 
90  te::da::AbstractConnectionPool* pool = te::v8::common::Unwrap<te::da::AbstractConnectionPool>(args.Holder());
91 
92  if(pool == 0)
93  return ::v8::ThrowException(::v8::String::New("Invalid connection pool in the isInitialized method!"));
94 
95  bool isInitialized = pool->isInitialized();
96 
97  ::v8::Handle<::v8::Boolean> jisInitialized = ::v8::Boolean::New(isInitialized);
98 
99  return hs.Close(jisInitialized);
100 }
101 
102 ::v8::Handle<::v8::Value> AbstractConnectionPool_GetPoolSize(const ::v8::Arguments& args)
103 {
104  ::v8::HandleScope hs;
105 
106  te::da::AbstractConnectionPool* pool = te::v8::common::Unwrap<te::da::AbstractConnectionPool>(args.Holder());
107 
108  if(pool == 0)
109  return ::v8::ThrowException(::v8::String::New("Invalid connection pool in the getPoolsize method!"));
110 
111  std::size_t poolSize = pool->getPoolSize();
112 
113  ::v8::Handle<::v8::Integer> jpoolSize = ::v8::Integer::New(static_cast<boost::int32_t>(poolSize));
114 
115  return hs.Close(jpoolSize);
116 }
117 
118 ::v8::Handle<::v8::Value> AbstractConnectionPool_GetInitialPoolSize(const ::v8::Arguments& args)
119 {
120  ::v8::HandleScope hs;
121 
122  te::da::AbstractConnectionPool* pool = te::v8::common::Unwrap<te::da::AbstractConnectionPool>(args.Holder());
123 
124  if(pool == 0)
125  return ::v8::ThrowException(::v8::String::New("Invalid connection pool in the getInitialPoolsize method!"));
126 
127  std::size_t initialPoolSize = pool->getInitialPoolSize();
128 
129  ::v8::Handle<::v8::Integer> jinitialPoolSize = ::v8::Integer::New(static_cast<boost::int32_t>(initialPoolSize));
130 
131  return hs.Close(jinitialPoolSize);
132 }
133 
134 ::v8::Handle<::v8::Value> AbstractConnectionPool_SetInitialPoolSize(const ::v8::Arguments& args)
135 {
136  if(args.Holder().IsEmpty())
137  return ::v8::ThrowException(::v8::String::New("In order to use the setInitialPoolSize method you must use the object notation: \"obj.setInitialPoolSize(size);\""));
138 
139  if((args.Length() != 1) || args[0].IsEmpty() || !args[0]->IsInt32())
140  return ::v8::ThrowException(::v8::String::New("In order to use the setInitialPoolSize method you must use the object notation: \"obj.setInitialPoolSize(size);\""));
141 
142  te::da::AbstractConnectionPool* pool = te::v8::common::Unwrap<te::da::AbstractConnectionPool>(args.Holder());
143 
144  if(pool == 0)
145  return ::v8::ThrowException(::v8::String::New("Invalid connection pool in the setInitialPoolSize method!"));
146 
147  int initialPoolSize = args[0]->ToInt32()->Value();
148 
149  pool->setInitialPoolSize(initialPoolSize);
150 
151  return ::v8::Undefined();
152 }
153 
154 ::v8::Handle<::v8::Value> AbstractConnectionPool_GetMinPoolSize(const ::v8::Arguments& args)
155 {
156  ::v8::HandleScope hs;
157 
158  te::da::AbstractConnectionPool* pool = te::v8::common::Unwrap<te::da::AbstractConnectionPool>(args.Holder());
159 
160  if(pool == 0)
161  return ::v8::ThrowException(::v8::String::New("Invalid connection pool in the getMinPoolsize method!"));
162 
163  std::size_t minPoolSize = pool->getMinPoolSize();
164 
165  ::v8::Handle<::v8::Integer> jminPoolSize = ::v8::Integer::New(static_cast<boost::int32_t>(minPoolSize));
166 
167  return hs.Close(jminPoolSize);
168 }
169 
170 ::v8::Handle<::v8::Value> AbstractConnectionPool_SetMinPoolSize(const ::v8::Arguments& args)
171 {
172  if(args.Holder().IsEmpty())
173  return ::v8::ThrowException(::v8::String::New("In order to use the setMinPoolSize method you must use the object notation: \"obj.setMinPoolSize(size);\""));
174 
175  if((args.Length() != 1) || args[0].IsEmpty() || !args[0]->IsInt32())
176  return ::v8::ThrowException(::v8::String::New("In order to use the setMinPoolSize method you must use the object notation: \"obj.setMinPoolSize(size);\""));
177 
178  te::da::AbstractConnectionPool* pool = te::v8::common::Unwrap<te::da::AbstractConnectionPool>(args.Holder());
179 
180  if(pool == 0)
181  return ::v8::ThrowException(::v8::String::New("Invalid connection pool in the setMinPoolSize method!"));
182 
183  int minPoolSize = args[0]->ToInt32()->Value();
184 
185  pool->setMinPoolSize(minPoolSize);
186 
187  return ::v8::Undefined();
188 }
189 
190 ::v8::Handle<::v8::Value> AbstractConnectionPool_GetMaxPoolSize(const ::v8::Arguments& args)
191 {
192  ::v8::HandleScope hs;
193 
194  te::da::AbstractConnectionPool* pool = te::v8::common::Unwrap<te::da::AbstractConnectionPool>(args.Holder());
195 
196  if(pool == 0)
197  return ::v8::ThrowException(::v8::String::New("Invalid connection pool in the getMaxPoolsize method!"));
198 
199  std::size_t maxPoolSize = pool->getMaxPoolSize();
200 
201  ::v8::Handle<::v8::Integer> jmaxPoolSize = ::v8::Integer::New(static_cast<boost::int32_t>(maxPoolSize));
202 
203  return hs.Close(jmaxPoolSize);
204 }
205 
206 ::v8::Handle<::v8::Value> AbstractConnectionPool_SetMaxPoolSize(const ::v8::Arguments& args)
207 {
208  if(args.Holder().IsEmpty())
209  return ::v8::ThrowException(::v8::String::New("In order to use the setMaxPoolSize method you must use the object notation: \"obj.setMaxPoolSize(size);\""));
210 
211  if((args.Length() != 1) || args[0].IsEmpty() || !args[0]->IsInt32())
212  return ::v8::ThrowException(::v8::String::New("In order to use the setMaxPoolSize method you must use the object notation: \"obj.setMaxPoolSize(size);\""));
213 
214  te::da::AbstractConnectionPool* pool = te::v8::common::Unwrap<te::da::AbstractConnectionPool>(args.Holder());
215 
216  if(pool == 0)
217  return ::v8::ThrowException(::v8::String::New("Invalid connection pool in the setMaxPoolSize method!"));
218 
219  int maxPoolSize = args[0]->ToInt32()->Value();
220 
221  pool->setMaxPoolSize(maxPoolSize);
222 
223  return ::v8::Undefined();
224 }
225 
226 static ::v8::Persistent<::v8::FunctionTemplate> sg_abstractconnectionpool_template;
227 
228 ::v8::Persistent<::v8::FunctionTemplate>& te::v8::jsi::GetAbstractConnectionPoolTemplate()
229 {
231  {
232  ::v8::Local<::v8::FunctionTemplate> result = ::v8::FunctionTemplate::New();
233  ::v8::Handle<::v8::ObjectTemplate> prototype = result->PrototypeTemplate();
234 
235  prototype->Set(::v8::String::NewSymbol("initialize"), ::v8::FunctionTemplate::New(AbstractConnectionPool_Initialize));
236  prototype->Set(::v8::String::NewSymbol("finalize"), ::v8::FunctionTemplate::New(AbstractConnectionPool_Finalize));
237  prototype->Set(::v8::String::NewSymbol("idle"), ::v8::FunctionTemplate::New(AbstractConnectionPool_Idle));
238  prototype->Set(::v8::String::NewSymbol("isValid"), ::v8::FunctionTemplate::New(AbstractConnectionPool_IsValid));
239  prototype->Set(::v8::String::NewSymbol("isInitialized"), ::v8::FunctionTemplate::New(AbstractConnectionPool_IsInitialized));
240  prototype->Set(::v8::String::NewSymbol("getPoolSize"), ::v8::FunctionTemplate::New(AbstractConnectionPool_GetPoolSize));
241  prototype->Set(::v8::String::NewSymbol("getInitialPoolSize"), ::v8::FunctionTemplate::New(AbstractConnectionPool_GetInitialPoolSize));
242  prototype->Set(::v8::String::NewSymbol("setInitialPoolSize"), ::v8::FunctionTemplate::New(AbstractConnectionPool_SetInitialPoolSize));
243  prototype->Set(::v8::String::NewSymbol("getMinPoolSize"), ::v8::FunctionTemplate::New(AbstractConnectionPool_GetMinPoolSize));
244  prototype->Set(::v8::String::NewSymbol("setMinPoolSize"), ::v8::FunctionTemplate::New(AbstractConnectionPool_SetMinPoolSize));
245  prototype->Set(::v8::String::NewSymbol("getMaxPoolSize"), ::v8::FunctionTemplate::New(AbstractConnectionPool_GetMaxPoolSize));
246  prototype->Set(::v8::String::NewSymbol("setMaxPoolSize"), ::v8::FunctionTemplate::New(AbstractConnectionPool_SetMaxPoolSize));
247 
248  sg_abstractconnectionpool_template = ::v8::Persistent<::v8::FunctionTemplate>::New(result);
249  }
250 
252 }
253 
::v8::Handle<::v8::Value > AbstractConnectionPool_IsInitialized(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > AbstractConnectionPool_GetInitialPoolSize(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > AbstractConnectionPool_GetMinPoolSize(const ::v8::Arguments &args)
virtual std::size_t getInitialPoolSize() const =0
It returns the initial number of connections opened by the pool at its startup.
JavaScript exporting routine for the TerraLib Data Access module.
virtual void setInitialPoolSize(std::size_t size)=0
It sets the initial number of connections opened by the pool at its startup.
virtual std::size_t getPoolSize() const =0
It returns the number of connections in the pool.
::v8::Handle<::v8::Value > AbstractConnectionPool_IsValid(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > AbstractConnectionPool_SetInitialPoolSize(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > AbstractConnectionPool_Idle(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > AbstractConnectionPool_SetMaxPoolSize(const ::v8::Arguments &args)
virtual std::size_t getMinPoolSize() const =0
It returns the minimum number of connections managed by the pool.
::v8::Handle<::v8::Value > AbstractConnectionPool_Initialize(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > AbstractConnectionPool_SetMinPoolSize(const ::v8::Arguments &args)
virtual std::size_t getMaxPoolSize() const =0
It returns the maximum number of connections managed by the pool.
static::v8::Persistent<::v8::FunctionTemplate > sg_abstractconnectionpool_template
virtual void initialize()=0
It initializes the connections to be managed by the pool.
::v8::Persistent<::v8::FunctionTemplate > & GetAbstractConnectionPoolTemplate()
It returns a reference to the persistent template of a AbstractConnectionPool object.
virtual void idle()=0
It releases the connections that are not in use for a long time.
::v8::Handle<::v8::Value > AbstractConnectionPool_GetPoolSize(const ::v8::Arguments &args)
virtual bool isValid() const =0
It checks if all the connections in the pool are valid (the communication channel is ok)...
This class defines the basic interface for a connection pool.
virtual void finalize()=0
It closes all connections and clears all resources managed by the pool.
virtual bool isInitialized() const =0
It returns true if the connection pool is initialized, otherwise it returns false.
virtual void setMaxPoolSize(std::size_t size)=0
It sets the maximum number of connections managed by the pool.
::v8::Handle<::v8::Value > AbstractConnectionPool_GetMaxPoolSize(const ::v8::Arguments &args)
virtual void setMinPoolSize(std::size_t size)=0
It sets the minimum number of connections managed by the pool.
::v8::Handle<::v8::Value > AbstractConnectionPool_Finalize(const ::v8::Arguments &args)