binding/v8/jsi/dataaccess/PrimaryKey.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 PrimaryKey.cpp
22 
23  \brief Utility functions to register the PrimaryKey class into the Google JavaScript V8 engine.
24  */
25 
26 // TerraLib
27 #include "../../../../dataaccess/dataset/PrimaryKey.h"
28 #include "../../common/Utils.h"
29 #include "DataAccess.h"
30 
31 // Boost
32 #include <boost/cstdint.hpp>
33 
34 ::v8::Handle<::v8::Value> PrimaryKey_GetProperties(const ::v8::Arguments& args)
35 {
36  return ::v8::Undefined();
37 }
38 
39 ::v8::Handle<::v8::Value> PrimaryKey_SetProperties(const ::v8::Arguments& args)
40 {
41  return ::v8::Undefined();
42 }
43 
44 ::v8::Handle<::v8::Value> PrimaryKey_Add(const ::v8::Arguments& args)
45 {
46  return ::v8::Undefined();
47 }
48 
49 ::v8::Handle<::v8::Value> PrimaryKey_SetAssociatedIndex(const ::v8::Arguments& args)
50 {
51  return ::v8::Undefined();
52 }
53 
54 ::v8::Handle<::v8::Value> PrimaryKey_GetAssociatedIndex(const ::v8::Arguments& args)
55 {
56  return ::v8::Undefined();
57 }
58 
59 ::v8::Handle<::v8::Value> PrimaryKey_Has(const ::v8::Arguments& args)
60 {
61  return ::v8::Undefined();
62 }
63 
64 ::v8::Handle<::v8::Value> PrimaryKey_Replace(const ::v8::Arguments& args)
65 {
66  return ::v8::Undefined();
67 }
68 
69 ::v8::Handle<::v8::Value> PrimaryKey_GetType(const ::v8::Arguments& args)
70 {
71  return ::v8::Undefined();
72 }
73 
74 ::v8::Handle<::v8::Value> PrimaryKey_Clone(const ::v8::Arguments& args)
75 {
76  ::v8::HandleScope hs;
77 
78  if(args.Holder().IsEmpty())
79  return ::v8::ThrowException(::v8::String::New("In order to use the clone method, you must use the object notation: \"pk = obj.clone();\""));
80 
81  te::da::PrimaryKey* pk = te::v8::common::Unwrap<te::da::PrimaryKey>(args.Holder());
82 
83  if(pk == 0)
84  return ::v8::ThrowException(::v8::String::New("Invalid primary key in the clone method!"));
85 
86  te::da::Constraint* pkclone = pk->clone();
87 
88  ::v8::Local<::v8::Object> jpkclone = te::v8::common::Make(pkclone, te::v8::jsi::GetPrimaryKeyTemplate, true);
89 
90  return hs.Close(jpkclone);
91 }
92 
93 ::v8::Handle<::v8::Value> PrimaryKey_Constructor(const ::v8::Arguments& args)
94 {
95  //::v8::HandleScope hs;
96 
97  //if(!args.IsConstructCall())
98  // return ::v8::ThrowException(::v8::String::New("In order to create a check constraint, you need to call its constructor like: var c = new TePrimaryKey(dt, id);"));
99 
100  //if(args.Holder().IsEmpty())
101  // return ::v8::ThrowException(::v8::String::New("The PrimaryKey constructor must use object notation!"));
102 
103  //if(args.Length() != 0)
104  // return ::v8::ThrowException(::v8::String::New("The PrimaryKey constructor has no parameters!"));
105 
106  //std::auto_ptr<te::da::PrimaryKey> catalog(new te::da::PrimaryKey());
107 
108  //::v8::Local<::v8::Object> jcatalog = te::v8::common::Make(catalog.get(), te::v8::jsi::GetPrimaryKeyTemplate, true);
109 
110  //catalog.release();
111 
112  //return hs.Close(jcatalog);
113 
114  return ::v8::Undefined();
115 }
116 
117 void te::v8::jsi::RegisterPrimaryKey(::v8::Local<::v8::Object>& global)
118 {
119  ::v8::Local<::v8::FunctionTemplate> jpk = ::v8::FunctionTemplate::New(PrimaryKey_Constructor);
120 
121  global->Set(::v8::String::New("TePrimaryKey"), jpk->GetFunction());
122 }
123 
124 static ::v8::Persistent<::v8::FunctionTemplate> sdset_primarykey_template;
125 
126 ::v8::Persistent<::v8::FunctionTemplate>& te::v8::jsi::GetPrimaryKeyTemplate()
127 {
128  if(sdset_primarykey_template.IsEmpty())
129  {
130  ::v8::Persistent<::v8::FunctionTemplate>& cTpl = GetConstraintTemplate();
131  ::v8::Local<::v8::FunctionTemplate> result = ::v8::FunctionTemplate::New();
132  result->Inherit(cTpl);
133 
134  ::v8::Handle<::v8::ObjectTemplate> prototype = result->PrototypeTemplate();
135 
136  prototype->Set(::v8::String::NewSymbol("getProperties"), ::v8::FunctionTemplate::New(PrimaryKey_GetProperties));
137  prototype->Set(::v8::String::NewSymbol("setProperties"), ::v8::FunctionTemplate::New(PrimaryKey_SetProperties));
138  prototype->Set(::v8::String::NewSymbol("add"), ::v8::FunctionTemplate::New(PrimaryKey_Add));
139  prototype->Set(::v8::String::NewSymbol("setAssociatedIndex"), ::v8::FunctionTemplate::New(PrimaryKey_SetAssociatedIndex));
140  prototype->Set(::v8::String::NewSymbol("getAssociatedIndex"), ::v8::FunctionTemplate::New(PrimaryKey_GetAssociatedIndex));
141  prototype->Set(::v8::String::NewSymbol("has"), ::v8::FunctionTemplate::New(PrimaryKey_Has));
142  prototype->Set(::v8::String::NewSymbol("replace"), ::v8::FunctionTemplate::New(PrimaryKey_Replace));
143  prototype->Set(::v8::String::NewSymbol("getType"), ::v8::FunctionTemplate::New(PrimaryKey_GetType));
144  prototype->Set(::v8::String::NewSymbol("clone"), ::v8::FunctionTemplate::New(PrimaryKey_Clone));
145 
146  sdset_primarykey_template = ::v8::Persistent<::v8::FunctionTemplate>::New(result);
147  }
148 
150 }
::v8::Local<::v8::Object > Make(T *obj, TF tfunc, const bool isOwner)
It creates a new JavaScript object from a C++ object (obj).
void RegisterPrimaryKey(::v8::Local<::v8::Object > &global)
It registers the PrimaryKey class.
::v8::Handle<::v8::Value > PrimaryKey_GetType(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > PrimaryKey_Constructor(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > PrimaryKey_GetAssociatedIndex(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > PrimaryKey_Add(const ::v8::Arguments &args)
::v8::Persistent<::v8::FunctionTemplate > & GetPrimaryKeyTemplate()
It returns a reference to the persistent template of a PrimaryKey object.
JavaScript exporting routine for the TerraLib Data Access module.
::v8::Handle<::v8::Value > PrimaryKey_SetAssociatedIndex(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > PrimaryKey_Clone(const ::v8::Arguments &args)
static::v8::Persistent<::v8::FunctionTemplate > sdset_primarykey_template
::v8::Handle<::v8::Value > PrimaryKey_GetProperties(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > PrimaryKey_Replace(const ::v8::Arguments &args)
Constraint * clone()
It returns a clone of the object.
::v8::Handle<::v8::Value > PrimaryKey_SetProperties(const ::v8::Arguments &args)
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
::v8::Handle<::v8::Value > PrimaryKey_Has(const ::v8::Arguments &args)
::v8::Persistent<::v8::FunctionTemplate > & GetConstraintTemplate()
It returns a reference to the persistent template of a Constraint object.