Xpace
table_j.h
Go to the documentation of this file.
1 
2 /**************************************************************
3  **
4  ** @file data/store/java/table_j.h
5  **
6  ** Copyright (C) 2012 Xpace, LLC. All rights reserved
7  **
8  ** www.xpace.net
9  **
10  **************************************************************/
11 
12 #ifndef XPACE_TABLE_J_H
13 #define XPACE_TABLE_J_H
14 
15 #include "base/datetime.h"
16 #include "data/store/table.h"
17 
18 #include "base/java/types_j.h"
19 
20 // C++ caller for Java Table_Sink - used in several places
21 namespace Xpace
22 {
23  class JavaTableSink : public Table::Sink
24  {
25  public:
26  static
27  std::unique_ptr<Table::Sink> create
28  (JNIEnv* jnienv,
29  jobject jsink);
30 
31  virtual uint add
32  (const String& name,
34  uint column = ~0,
35  bool* added = 0) override // TODO: add this param to the Java call
36  {
37  DerivedDataType::type t(convert_pass(env, type).get().getDerivedType());
38  if (t == BaseDataType::btUint)
40 
41  uint ret(env->CallIntMethod(jsink, add_column,
42  convert_pass(env, name).get(),
43  t,
44  convert_pass(env, column).get()));
45  if (added)
46  *added = true; // TODO
47  return ret;
48  }
49 
50  virtual bool setCount
51  (uint64 count) override
52  {
53  return !!env->CallBooleanMethod(jsink, set_count,
54  convert_pass(env, count).get());
55  }
56 
57  virtual int64 start
58  (uint64 row) override
59  {
60  return env->CallLongMethod(jsink, start_row,
61  convert_pass(env, row).get());
62  }
63 
64  virtual bool set
66  int64 value) override
67  {
68  return !!env->CallBooleanMethod(jsink, set_int64,
69  convert_pass(env, column).get(),
70  convert_pass(env, value).get());
71  }
72 
73  virtual bool set
75  const Xpace::DecimalFloat& value) override
76  {
77  return !!env->CallBooleanMethod(jsink, set_float,
78  convert_pass(env, column).get(),
79  convert_pass(env, value.getMantissa()).get(),
80  convert_pass(env, value.getDecimals()).get());
81  }
82 
83  virtual bool set
85  const Xpace::String8& value) override
86  {
87  return !!env->CallBooleanMethod(jsink, set_string, column,
88  convert_pass(env, value).get());
89  }
90 
91  virtual bool set
93  const Xpace::String16& value) override
94  {
95  return !!env->CallBooleanMethod(jsink, set_string, column,
96  convert_pass(env, value).get());
97  }
98 
99  virtual bool set
101  const Xpace::BytesRef& value) override
102  {
103  return !!env->CallBooleanMethod(jsink, set_bytes, column,
104  convert_pass(env, value).get());
105  }
106 
107  virtual bool set
109  const Xpace::DateTime& value)
110  {
111  Xpace::Date date(value.getDate());
112  Xpace::Time time(value.getTime());
113 
114  return !!env->CallBooleanMethod(jsink, set_dateTime, convert_pass(env, column).get(),
115  convert_pass(env, date.getYear()).get(),
116  convert_pass(env, date.getMonth()).get(),
117  convert_pass(env, date.getDay()).get(),
118  convert_pass(env, time.getHour()).get(),
119  convert_pass(env, time.getMinute()).get(),
120  convert_pass(env, time.getSecond()).get(),
121  convert_pass(env, time.getMillisecond()).get());
122  }
123 
124  virtual void close
125  () override
126  {
127  env->CallVoidMethod(jsink, do_close);
128  }
129 
130  private:
132  (JNIEnv* jnienv,
133  jobject jsink);
134 
135  JNIEnv* env;
136  jobject jsink;
137 
138  jmethodID add_column;
139  jmethodID set_count;
140  jmethodID start_row;
141  jmethodID set_int64;
142  jmethodID set_float;
143  jmethodID set_string;
144  jmethodID set_bytes;
145  jmethodID set_dateTime;
146  jmethodID do_close;
147  };
148 
150  {
151  public:
152  JavaStatus
153  (JNIEnv* jnienv,
154  jobject jsink);
155 
156  int64 operator()
157  (int64 val)
158  {
159  return env->CallLongMethod(jstatus, status, val);
160  }
161 
162  private:
163  JNIEnv* env;
164  jobject jstatus;
165 
166  jmethodID status;
167  };
168 }
169 
170 #endif
const Xpace_Char16 Xpace_Data_Type type
Definition: table_c.h:141
unsigned int uint
Definition: types.h:75
virtual int64 start(uint64 row) override
Begin a new document/record/row, committing current one (if any)
Definition: table_j.h:58
virtual void close() override
We&#39;re finshed with this Sink.
Definition: table_j.h:125
const Xpace_Char16 Xpace_Data_Type uint bool * added
Definition: table_c.h:141
A string, Unicode UTF-16 and reference-counted.
Definition: types.h:269
PassJNI< jintArray > convert_pass(JNIEnv *jniEnv, const Xpace::Store::Location &val)
A low-level const data holder.
Definition: types.h:165
A floatimg-point number with explicit mantissa and decimals TODO: normalize.
Definition: decimalfloat.h:33
A write-only, forward cursor into a table.
Definition: table.h:142
Copyright (C) 2012 Xpace, LLC.
unsigned long long uint64
Definition: types.h:87
virtual bool setCount(uint64 count) override
Inform the Sink how many documents/records/rows to expect.
Definition: table_j.h:51
const Xpace_Char16 * name
Sink callbacks for table data.
Definition: table_c.h:141
uint int64 value
Definition: table_c.h:159
uint column
Add a 64-bit int to the row.
Definition: table_c.h:108
uint64 row
Begin a new row, committing this one (if any)
Definition: table_c.h:89
virtual uint add(const String &name, DerivedDataType type, uint column=~0, bool *added=0) override
Add a column by name.
Definition: table_j.h:32
long long int64
Definition: types.h:86
Xpace project main namespace
Definition: datetime.h:18
static std::unique_ptr< Table::Sink > create(JNIEnv *jnienv, jobject jsink)

current as of Wed Jun 10 2026 12:00:05