diff --git a/.JNI-h-file-generation.launch b/.JNI-h-file-generation.launch index 6ee1b42343..d2c0df6c74 100644 --- a/.JNI-h-file-generation.launch +++ b/.JNI-h-file-generation.launch @@ -5,6 +5,6 @@ - + diff --git a/build.sh b/build.sh index 5b5613b407..27467f78cc 100644 --- a/build.sh +++ b/build.sh @@ -210,8 +210,8 @@ case "$MODE" in # Build tightdb.jar mkdir -p "$JAR_DIR" || exit 1 cd "$TIGHTDB_JAVA_HOME/tightdb-java-core/src/main" || exit 1 - (cd java && $JAVAC com/tightdb/*.java com/tightdb/internal/*.java com/tightdb/lib/*.java) || exit 1 - (cd java && jar cf "$JAR_DIR/tightdb.jar" com/tightdb/*.class com/tightdb/internal/*.class com/tightdb/lib/*.class) || exit 1 + (cd java && $JAVAC com/tightdb/*.java com/tightdb/internal/*.java com/tightdb/typed/*.java) || exit 1 + (cd java && jar cf "$JAR_DIR/tightdb.jar" com/tightdb/*.class com/tightdb/internal/*.class com/tightdb/typed/*.class) || exit 1 jar i "$JAR_DIR/tightdb.jar" || exit 1 # Build tightdb-devkit.jar @@ -232,7 +232,7 @@ case "$MODE" in (cd java && jar uf "$JAR_DIR/tightdb-devkit.jar" com/tightdb/generator/*.class) || exit 1 (cd "$JAR_DIR" && jar i "tightdb-devkit.jar") || exit 1 - # Absorb dependency JARs if we have to - generally a bag thing!!! + # Absorb dependency JARs if we have to - generally a bad thing!!! if [ "$ABSORB_DEP_JARS" ]; then TEMP_JAR_DIR="$TEMP_DIR/jar" mkdir "$TEMP_JAR_DIR" || exit 1 diff --git a/doc/ref/data/group_ref.yaml b/doc/ref/data/group_ref.yaml new file mode 100644 index 0000000000..7d252dce49 --- /dev/null +++ b/doc/ref/data/group_ref.yaml @@ -0,0 +1,225 @@ +# +# Java reference documentation for Group class +# + +#UNDOCUMENTED: [ +# g_group_operator_equal, g_group_operator_not_equal, +# g_group_is_shared, g_group_tostring, +# commit, to_json, get_table_typed] + +ID : class_group +TITLE : Group +SUMMARY : *g_group_summary +DESCR : *g_group_descr +SEE : +EXAMPLES: +- DESCR : + CODE : ex_java_group_intro +IGNORE : [] # List of method-ids to ignore +CATEGORIES: +- Constructor: + METHODS: + - g_group_constructor_plain: + - g_group_constructor_file: + - g_group_constructor_memory: + NAMES : Group + DESCR : *g_group_constructor_descr + SUMMARY : *g_group_constructor_summary + SIGNATURE: | + Group() + Group(File file) + Group(String fileName) + Group(String fileName, boolean readOnly) + Group(byte[] data) + Group(ByteBuffer buffer) + PARAMS: + - NAME : file + TYPES : java.io.File + DESCR : A File object. + - NAME : fileName + TYPES : String + DESCR : The name of the file. + - NAME : readOnly + TYPES : boolean + DESCR : Open the group as read-only or read-write. If not used, the file opened as read-only. + - NAME : data + TYPES : byte[] + DESCR : In-memory binary encoded representation of a group. + - NAME : buffer + TYPES : ByteBuffer + DESCR : In-memory binary encoded representation of a group. + RETURN: + TYPES : Group + DESCR : A - possibly empty - group. + EXAMPLES: + - DESCR : + CODE : ex_java_group_constructor_plain + - DESCR : + CODE : ex_java_group_constructor_file + - DESCR : + CODE : ex_java_group_constructor_memory + SEE : "{@link g_group_is_valid}" + - g_group_desctructor: + NAMES : close + DESCR : > + This method will close the group and release it's resources (memory and files). + Java will to this automatically via garbage collection, but if you want explicit control, + you have the option with this method. + SUMMARY : Close the group and release it's resources. + +- Table: + METHODS: + - g_group_has_table: + NAMES : hasTable + SUMMARY : *g_group_has_table_summary + DESCR : The method checks whether this group contains the specified table. + PARAMS: + - NAME : name + TYPES : String + DESCR : Name of the table you wish to look for. + RETURN: + TYPES : bool + DESCR : true if the table exits, otherwise false. + EXAMPLES: + - DESCR : + CODE : ex_java_group_optional_table + + - g_group_get_table: + NAMES : getTable + SUMMARY : *g_group_get_table_summary + DESCR : > + This method will find and return a named table from the group. + + If no table exists with the specified name, a new + empty table will be created. + PARAMS: + - NAME : name + TYPES : String + DESCR : Name of the table you wish to retrieve. + RETURN: + TYPES : Table + DESCR : The requested Table object. + EXAMPLES: + - DESCR : + CODE : ex_java_group_traverse + - DESCR : + CODE : ex_java_group_optional_table + SEE : "{@link g_group_has_table}" + + - g_group_get_table_name: + NAMES : getTableName + DESCR : *g_group_get_table_name_descr + SUMMARY : *g_group_get_table_name_summary + PARAMS: + - NAME : index + TYPES : int + DESCR : Table index. + RETURN: + TYPES : String + DESCR : The table name. + EXAMPLES: + - DESCR : + CODE : ex_java_group_traverse + +- Serialization: + METHODS: + - g_group_write_to_file: + NAMES : writeToFile + SUMMARY : *g_group_write_to_file_summary + DESCR : *g_group_write_to_file_descr + SIGNATURE: | + writeToFile(File file) + writeToFile(String fileName) + PARAMS: + - NAME : file + TYPES : java.io.File + DESCR : File object + - NAME : fileName + TYPES : String + DESCR : File name, possibly a full path. + RETURN: + DESCR : true is successful, false otherwise. + TYPES : bool + EXAMPLES: + - DESCR : + CODE : ex_java_group_write_to_file + - g_group_write_to_mem: + NAMES : writeToMem + DESCR : *g_group_write_to_mem_descr + SUMMARY : *g_group_write_to_mem_summary + RETURN: + DESCR : A copy of the serialized group. + TYPES : byte[] + EXAMPLES: + - DESCR : + CODE : ex_java_group_write_to_mem + - g_group_write_to_mem_bytebuffer: + NAMES : writeToByteBuffer + DESCR : *g_group_write_to_mem_descr + SUMMARY : *g_group_write_to_mem_summary + RETURN: + DESCR : A copy of the serialized group. + TYPES : ByteBuffer + EXAMPLES: + - DESCR : + CODE : ex_java_group_write_to_mem + +- Group: + METHODS: + - g_group_table_count: + NAMES : getTableCount + DESCR : *g_group_table_count_descr + SUMMARY : *g_group_table_count_summary + RETURN: + TYPES : int + DESCR : The number of tables in the group. + EXAMPLES: + - DESCR : + CODE : #???ex_cpp_group_traverse + + - g_group_is_empty: + NAMES : isEmpty + SUMMARY : *g_group_is_empty_summary + DESCR : *g_group_is_empty_descr + RETURN: + TYPES : bool + DESCR : true if group is empty (no tables), false otherwise. + EXAMPLES: + - DESCR : + CODE : ex_java_group_is_empty + + - g_group_is_valid: + NAMES : isValid + SUMMARY : *g_group_is_valid_summary + DESCR : *g_group_is_valid_descr + RETURN: + TYPES : boolean + DESCR : true if group is valid (consistent), false otherwise. + EXAMPLES: + - DESCR : + CODE : ex_java_group_is_valid + +# - g_group_is_shared: +# NAMES : isShared +# SUMMARY : *g_group_is_shared_summary +# DESCR : *g_group_is_shared_descr +# RETURN: +# TYPES : bool +# DESCR : true if group is shared, false otherwise. +# EXAMPLES: +# - DESCR : +# CODE : ex_java_group_is_shared + +# - g_group_tostring: +# NAMES : toString +# SUMMARY : *g_group_to_string_summary +# DESCR : > +# This methods returns textual information about the group. +# It outputs a list of the table names and the number of rows they contain. +# RETURN: +# TYPES : String +# DESCR : Information about the group. +# EXAMPLES: +# - DESCR : +# CODE : ex_java_group_tostring + diff --git a/doc/ref/data/reference.yaml b/doc/ref/data/reference.yaml new file mode 100644 index 0000000000..092e88b089 --- /dev/null +++ b/doc/ref/data/reference.yaml @@ -0,0 +1,66 @@ +# +# Reference documentation data for language Java +# +ID : java +TITLE : 'Java' +DESCR : > + The goal of TightDB is to provide a high performance + data storage for your applications. + + TightDB integrates seamless in Java, making it + fast to learn and easy to use. You can replace your traditional data + structures with TightDB. Whether it is a simple array of integers or a + complex structure, you interface to TightDB as easily as using a + standard array like container. But in addition you can + handle much more data in much less space, you get powerful query + possibilities in an intuitive language and the ability to share your data + across all supported languages and platforms. + + The core of the framework is the class {@link class_table}. The + class is a representation of the + fundamental concept Table. You can use + {@link class_table} in the situations where you know the table structure + a priori or when the data structure changes dynamically through the run time + of the application. + + Tables organize data in columns and rows and data is compacted for + low memory usage. The interface to the data resembles the native + data structures. Moreover, tables can have nested tables as data. Using subtables + and mixed types you can build arbitrarily complex data structures. + + It is possible to query data using the {@link class_query} and + class. Queries can be complex - involving + any number of columns and values. You can either apply aggregate functions to you + resulting data set or use the data set in your application as a + {@link class_tableview} object. + + The {@link class_group} class lets you serialize tables to disk or memory. The + TightDB data format is consistent across operating systems, hardware platforms, + and programming languages. This implies that you can share data across applications + and environments. For multi-threaded or multi-process applications, you can + use the {@link class_shared_group}. + +IMPORT : [reference, typed_table_ref, dyn_table_ref, dyn_query_ref, group_ref, typed_view_ref, dyn_view_ref, shared_group_ref] +IMPORTPATH: ../../tightdb/doc/ref_cpp/data + + +CATEGORIES: # list global class-id in order of appearence +- Typed Table: # Category header name +# - typed_table # Global Class name. File: 'typed_table_ref.yaml' +# - typed_view +# - typed_query +- Dynamic Table: +# - dyn_table +# - dyn_view +# - dyn_query +- Collection: + - group +# - shared_group +- Helpers: +# - mixed +# - cursor + +EXAMPLES : +- DESCR : + CODE : #ex_cpp_intro # id to example code + diff --git a/doc/ref/data/shared_group_ref.yaml b/doc/ref/data/shared_group_ref.yaml new file mode 100644 index 0000000000..7bf096b581 --- /dev/null +++ b/doc/ref/data/shared_group_ref.yaml @@ -0,0 +1,184 @@ +# +# Java reference documentation for Shared Group class +# + +ID : class_shared_group +TITLE : SharedGroup +SUMMARY : &g_shared_group_summary + Sharing groups +DESCR : &g_shared_group_descr + This class enables you to shared tables across running applications. +SEE : +EXAMPLES: +- DESCR : + CODE : ex_cpp_shared_group_intro +IGNORE : [] +CATEGORIES: +- Constructor: + METHODS: + - g_shared_group_constructor: + NAMES : SharedGroup + SUMMARY : &g_shared_group_constructor_summary + Create a shared group. + DESCR : &g_shared_group_constructor_descr + > + Database files can be shared across running applications. + + When two threads or processes want to access the same + database file, they must each create their own + instance of SharedGroup. + + If the database file does not already exist, it will + be created. When multiple threads are involved, it is + safe to let the first thread, that gets to it, create + the file. + + While at least one instance of SharedGroup exists for + a specific database file, a lock file will exist + too. The lock file will be placed in the same + directory as the database file, and its name is + derived by adding the suffix '.lock' to the name of + the database file. + + Processes that share a database file must reside on + the same host. + PARAMS: + - NAME : path_to_database_file + TYPES : const char* + DESCR : Path to a TightDB data file. + - NAME : replication_tag + TYPES : replication_tag + DESCR : ??? + RETURN: + TYPES : SharedGroup + DESCR : A shared group. + EXAMPLES: + - CODE : ex_cpp_shared_group_constructor + DESCR : +- Utilities: + METHODS: + - g_shared_group_is_valid: + NAMES : is_valid + SUMMARY : &g_shared_group_is_valid_summary + Is shared group valid? + DESCR : &g_shared_group_is_valid_descr + > + This method tests the consistency/validity of a shared group. + RETURN: + TYPES : bool + DESCR : true if consistent/valid, false otherwise. + EXAMPLES: + - CODE : ex_cpp_shared_group_is_valid + DESCR : + - g_shared_group_has_changed: + NAMES : has_changed + SUMMARY : &g_shared_group_has_changed_summary + Has shared group been changed since last transaction? + DESCR : &g_shared_group_has_changed_descr + > + This method tests if the shared group has been modified (by another process), + since the last transaction. + + It has very little overhead and does not affect other processes, so it is + ok to call it at regular intervals (like in the idle handler of an application). + RETURN: + TYPES : bool + DESCR : true if it has changed, false otherwise. + EXAMPLES: + - CODE : ex_cpp_shared_group_has_changed + DESCR : +- Write transactions: + METHODS: + - g_shared_group_begin_write: + NAMES : begin_write + SUMMARY : &g_shared_group_begin_write_summary + Initiate a transaction. + DESCR : &g_shared_group_begin_write_descr + Begin writing to a shared group. + RETURN: + TYPES : Group& + DESCR : A group. + EXAMPLES: + - CODE : ex_cpp_shared_group_begin_write + DESCR : + - g_shared_group_begin_commit: + NAMES : commit + SUMMARY : &g_shared_group_commit_summary + Commit a transaction. + DESCR : &g_shared_group_commit_descr + This method closes a transaction and changes are written to the group. + EXAMPLES: + - CODE : ex_cpp_shared_group_commit + DESCR : + - g_shared_group_rollback: + NAMES : rollback + SUMMARY : &g_shared_group_rollback_summary + Rollback a transaction. + DESCR : &g_shared_group_rollback_descr + This method descards all changes. + EXAMPLES: + - CODE : ex_cpp_shared_group_rollback + DESCR : + - g_shared_group_interrupt_transact: + NAMES : interrupt_transact + SUMMARY : &g_shared_group_interrupt_transact_summary + Interrupt any blocking call. + DESCR : &g_shared_group_interrupt_transact_descr + > + This function may be called asynchronously to interrupt any + blocking call that is part of a transaction in a replication + setup. Only {@link g_shared_group_begin_write} and + modifying function that are part + of a write transaction can block. The transaction is + interrupted only if such a call is blocked or would + block. This function may be called from a different thread. It + may not be called directly from a system signal handler. When + a transaction is interrupted, the only valid member function + to call is {@link g_shared_group_rollback}. If a client calls + {@link g_shared_group_clear_interrupt_transact} after having + called {@link g_shared_group_rollback}, it + may then resume normal operation on this database/shared group. + Currently, + transaction interruption works by throwing an exception from + one of the mentioned member functions that may block. + EXAMPLES: + - CODE : ex_cpp_shared_group_interrupt_transact + DESCR : + - g_shared_group_clear_interrupt_transact: + NAMES : clear_interrupt_transact + SUMMARY : &g_shared_group_clear_interrupt_transact_summary + Clean up interrupted state. + DESCR : &g_shared_group_clear_interrupt_transact_descr + > + This method clears the interrupted state of the shared group after rolling + back a transaction. It is not an error to call this function + in a situation where no interruption has occured. + SEE : g_shared_group_interrupt_transact + EXAMPLES: + - CODE : ex_cpp_shared_group_clear_interrupt_transact + DESCR : +- Read transactions: + METHODS: + - g_shared_group_begin_read: + NAMES : begin_read + SUMMARY : &g_shared_group_begin_read_summary + Initiate reading. + DESCR : &g_shared_group_begin_read_descr + Begin reading from a shared group. + CONST : True + RETURN: + TYPES : Group& + DESCR : A group. + EXAMPLES: + - CODE : ex_cpp_shared_group_begin_read + DESCR : + - g_shared_group_end_read: + NAMES : end_read + SUMMARY : &g_shared_group_end_read_summary + Stop reading from a group. + DESCR : &g_shared_group_end_read_descr + This method stops reading from a shared group. + EXAMPLES: + - CODE : ex_cpp_shared_group_end_read + DESCR : + diff --git a/doc/tutorial.java b/doc/tutorial.java index 7909ce6312..f06c6951c0 100644 --- a/doc/tutorial.java +++ b/doc/tutorial.java @@ -1,154 +1,156 @@ // -// This example is used in the short introduction "Tightdb Java Interface" -// The @@ comments below are used for automatic extraction to the documentation +//This example is used in the short introduction "Tightdb Java Interface" +//The @@ comments below are used for automatic extraction to the documentation // -package com.tightdb.example; +package com.tightdb.examples.tutorial; import java.io.IOException; -import com.tightdb.Group; -import com.tightdb.generated.People; -import com.tightdb.generated.PeopleQuery; -import com.tightdb.generated.PeopleTable; -import com.tightdb.lib.Table; -import com.tightdb.lib.TightDB; - -// @@Example: create_table @@ -public class TutorialExample { - @Table - class people { - String name; - int age; - boolean hired; - } - -public static void main(String[] args) { - PeopleTable peopletable = new PeopleTable(); -// @@EndExample@@ - - /****************************** BASIC OPERATIONS *************************/ - - // @@Example: insert_rows @@ - peopletable.add("John", 20, true); - peopletable.add("Mary", 21, false); - peopletable.add("Lars", 21, true); - peopletable.add("Phil", 43, false); - peopletable.add("Anni", 54, true); - // @@EndExample@@ - - / @@Example: insert_at_index @@ - peopletable.insert(2, "Frank", 34, true); - // @@EndExample@@ - - // @@Example: number_of_rows @@ - if (!peopletable.isEmpty()) { - long s = peopletable.size(); // s => 6 - } - // @@EndExample@@ - - System.out.println("Size = " + peopletable.size() + "\n"); - - /****************************** GETTERS AND SETTERS **********************/ - - // @@Example: accessing_rows @@ - // 2 ways to get the value - String name = peopletable.at(2).getName(); // name => "Mary" - // or - String name2 = peopletable.at(2).name.get(); - - // 2 ways to set the value - peopletable.at(2).name.set("NewName"); - // or - peopletable.at(2).setName("NewName"); - // @@EndExample@@ - - System.out.println("at(2).getName -> " + name + " or " + name2); - System.out.println("at(2).setName('NewName') -> " + peopletable.at(2).getName()); - - /****************************** DATA REMOVAL *****************************/ - // @@Example: deleting_row @@ - peopletable.remove(2); - // @@EndExample@@ - - System.out.println("\nRemoved row 2. Down to " + peopletable.size() + " rows.\n"); - - /****************************** ITERATION OF ALL RECORDS *****************/ - - // lazy iteration over the table - - // @@Example: iteration @@ - for (People person : peopletable) { - System.out.println(person.getName() + " is " + person.getAge() + " years old."); - } - // @@EndExample@@ - - /****************************** SIMPLE QUERY *****************************/ - - // @@Example: simple_seach @@ - People p = peopletable.name.equal("John").findFirst(); - // @@EndExample@@ - - System.out.println("\nFind 'John': " + p + "\n"); - - /****************************** COMPLEX QUERY ****************************/ - - // @@Example: advanced_search @@ - // Define the query - PeopleQuery query = peopletable.name.contains("a") - age.between(20, 30) - .group() - .hired.equal(false) - .or() - .name.endsWith("y") - .endGroup(); - // Count matches - System.out.println(query.count() + " person match query."); - - // Take the average age of the matches - System.out.println(query.average(??) + " years is the average."); - - // Perform query and use the result - for (People person : query.findAll()) { - // ... do something with matching 'person' - } - // @@EndExample - - /****************************** SERIALIZE ********************************/ - - // @@Example: serialisation @@ - // Create Table in Group - Group group = new Group(); - PeopleTable people1 = new PeopleTable(group); - - people1.add("John", 20, true); - people1.add("Mary", 21, false); - - // Write to disk - try { - group.writeToFile("people.tightdb"); - } catch (IOException e) { - e.printStackTrace(); - } - - // Load a group from disk (and print contents) - Group fromDisk = new Group("people.tightdb"); - PeopleTable people2 = new PeopleTable(fromDisk); - - for (People person : people2) { - System.out.println(person.getName() + " is " + person.getAge() + " years old"); - } - - // Write same group to memory buffer - byte[] buffer = group.writeToMem(); - - // Load a group from memory (and print contents) - Group fromMem = new Group(buffer); - PeopleTable people3 = new PeopleTable(fromMem); - - for (People person : people3) { - System.out.println(person.getName() + " is " + person.getAge() + " years old"); - } - // @@EndExample@@ -} +import com.tightdb.*; + +@SuppressWarnings("unused") +//@@Example: create_table @@ +public class tutorial { + // Define the TighDB table with columns "name", "age" and "hired" + @DefineTable(table = "PeopleTable") + class people { + String name; + int age; + boolean hired; + } + + public static void main(String[] args) { + PeopleTable peopletable = new PeopleTable(); + //@@EndExample@@ + + /****************************** BASIC OPERATIONS *************************/ + + // @@Example: insert_rows @@ + peopletable.add("John", 20, true); + peopletable.add("Mary", 21, false); + peopletable.add("Lars", 32, true); + peopletable.add("Phil", 43, false); + peopletable.add("Anni", 54, true); + // @@EndExample@@ + + // @@Example: insert_at_index @@ + peopletable.insert(2, "Frank", 34, true); + // @@EndExample@@ + + // @@Example: number_of_rows @@ + if (!peopletable.isEmpty()) { + long s = peopletable.size(); // s => 6 + } + // @@EndExample@@ + + System.out.println("Size = " + peopletable.size() + "\n"); + + /****************************** GETTERS AND SETTERS **********************/ + + // @@Example: accessing_rows @@ + // 2 ways to get the value + String name = peopletable.at(2).getName(); // name => "Mary" + // or + String name2 = peopletable.at(2).name.get(); + + // 2 ways to set the value + peopletable.at(2).name.set("NewName"); + // or + peopletable.at(2).setName("NewName"); + // @@EndExample@@ + + System.out.println("at(2).getName -> " + name + " or " + name2); + System.out.println("at(2).setName('NewName') -> " + peopletable.at(2).getName()); + + /****************************** DATA REMOVAL *****************************/ + // @@Example: deleting_row @@ + peopletable.remove(2); + // @@EndExample@@ + + System.out.println("\nRemoved row 2. Down to " + peopletable.size() + " rows.\n"); + + /****************************** ITERATION OF ALL RECORDS *****************/ + + // lazy iteration over the table + + // @@Example: iteration @@ + for (PeopleRow person : peopletable) { + System.out.println(person.getName() + " is " + person.getAge() + " years old."); + } + // @@EndExample@@ + + /****************************** SIMPLE QUERY *****************************/ + + System.out.println("\nFound: "); + // @@Example: simple_seach @@ + PeopleRow p = peopletable.name.equal("John").findFirst(); + System.out.println( p ); + // prints: "People {name=John, age=20, hired=true}" + // @@EndExample@@ + + /****************************** COMPLEX QUERY ****************************/ + + // @@Example: advanced_search @@ + // Define the query + PeopleQuery query = peopletable + .age.between(20, 35) // Implicit AND with below + .name.contains("a") // Implicit AND with below + .group() // "(" + .hired.equal(true) + .or() // or + .name.endsWith("y") + .endGroup(); // ")" + // Count matches + PeopleView match = query.findAll(); + System.out.println(match.size() + " person(s) match query."); + + // Take the average age of the matches + System.out.println(match.age.sum() + " years is the summed age."); + + // Perform query and use the result + for (PeopleRow person : match) { + // ... do something with matching 'person' + } + // @@EndExample + System.out.println(""); + + /****************************** SERIALIZE ********************************/ + + System.out.println("Serialize to file:"); + // @@Example: serialisation @@ + // Create Table in Group + Group group = new Group(); + PeopleTable people1 = new PeopleTable(group); + + people1.add("John", 20, true); + people1.add("Mary", 21, false); + + // Write to disk + try { + group.writeToFile("people.tightdb"); + } catch (IOException e) { + e.printStackTrace(); + } + + // Load a group from disk (and print contents) + Group fromDisk = new Group("people.tightdb"); + PeopleTable people2 = new PeopleTable(fromDisk); + + for (PeopleRow person : people2) { + System.out.println(person.getName() + " is " + person.getAge() + " years old"); + } + + // Write same group to memory buffer + byte[] buffer = group.writeToMem(); + + // Load a group from memory (and print contents) + Group fromMem = new Group(buffer); + PeopleTable people3 = new PeopleTable(fromMem); + + for (PeopleRow person : people3) { + System.out.println(person.getName() + " is " + person.getAge() + " years old"); + } + // @@EndExample@@ + } } diff --git a/examples/ant-setup/src/com/tightdb/example/HelloWorld.java b/examples/ant-setup/src/com/tightdb/example/HelloWorld.java index d473fad2e3..8070b164df 100644 --- a/examples/ant-setup/src/com/tightdb/example/HelloWorld.java +++ b/examples/ant-setup/src/com/tightdb/example/HelloWorld.java @@ -29,7 +29,7 @@ public static void main(String[] args) { EmployeeTable employees = new EmployeeTable(); employees.add("John", "Doe", 10000, true, new byte[] { 1, 2, 3 }, - new Date(), "extra"); + new Date(), "extra", null); TightDB.print("Employees", employees); } diff --git a/examples/intro-example/src/com/tightdb/examples/performance/Performance.java b/examples/intro-example/src/com/tightdb/examples/performance/Performance.java index f6678c1c13..4aef51833c 100644 --- a/examples/intro-example/src/com/tightdb/examples/performance/Performance.java +++ b/examples/intro-example/src/com/tightdb/examples/performance/Performance.java @@ -1,7 +1,7 @@ package com.tightdb.examples.performance; import com.tightdb.internal.util; -import com.tightdb.lib.TightDB; +import com.tightdb.typed.TightDB; public class Performance { diff --git a/examples/intro-example/src/com/tightdb/examples/performance/Tightdb.java b/examples/intro-example/src/com/tightdb/examples/performance/Tightdb.java index a579b2076a..1c792ca5b6 100644 --- a/examples/intro-example/src/com/tightdb/examples/performance/Tightdb.java +++ b/examples/intro-example/src/com/tightdb/examples/performance/Tightdb.java @@ -5,7 +5,7 @@ public class Tightdb extends PerformanceBase implements IPerformance { - @Table(row="Test") + @DefineTable(row="Test") class test { int indexInt; diff --git a/examples/intro-example/src/com/tightdb/examples/performance/Util.java b/examples/intro-example/src/com/tightdb/examples/performance/Util.java index 6432afe052..4b63f106b7 100644 --- a/examples/intro-example/src/com/tightdb/examples/performance/Util.java +++ b/examples/intro-example/src/com/tightdb/examples/performance/Util.java @@ -2,7 +2,7 @@ import java.util.Scanner; -import com.tightdb.lib.TightDB; +import com.tightdb.typed.TightDB; public class Util { diff --git a/examples/intro-example/src/com/tightdb/examples/showcase/Showcase.java b/examples/intro-example/src/com/tightdb/examples/showcase/Showcase.java index c67056b684..db7b804b8d 100644 --- a/examples/intro-example/src/com/tightdb/examples/showcase/Showcase.java +++ b/examples/intro-example/src/com/tightdb/examples/showcase/Showcase.java @@ -6,8 +6,8 @@ import com.tightdb.Group; import com.tightdb.Table; -import com.tightdb.lib.AbstractColumn; -import com.tightdb.lib.TightDB; +import com.tightdb.typed.AbstractColumn; +import com.tightdb.typed.TightDB; public class Showcase { @@ -25,7 +25,7 @@ public static void main(String[] args) { * rows in the EmployeeTable, which will also be generated. */ - @Table(row="Employee") + @DefineTable(row="Employee") class employee { String firstName; String lastName; @@ -37,7 +37,7 @@ class employee { phone phones; } - @Table(row="Phone") + @DefineTable(row="Phone") class phone { String type; String number; diff --git a/examples/intro-example/src/com/tightdb/examples/tutorial/tutorial.java b/examples/intro-example/src/com/tightdb/examples/tutorial/tutorial.java index 2fcf0c1a3d..8688deb07e 100644 --- a/examples/intro-example/src/com/tightdb/examples/tutorial/tutorial.java +++ b/examples/intro-example/src/com/tightdb/examples/tutorial/tutorial.java @@ -9,149 +9,148 @@ import com.tightdb.*; - +@SuppressWarnings("unused") //@@Example: create_table @@ public class tutorial { // Define the TighDB table with columns "name", "age" and "hired" - @Table + @DefineTable(table = "PeopleTable") class people { String name; - int age; - boolean hired; + int age; + boolean hired; } - - @SuppressWarnings("unused") + public static void main(String[] args) { - PeopleTable peopletable = new PeopleTable(); + PeopleTable peopletable = new PeopleTable(); //@@EndExample@@ - - /****************************** BASIC OPERATIONS *************************/ - - // @@Example: insert_rows @@ - peopletable.add("John", 20, true); - peopletable.add("Mary", 21, false); - peopletable.add("Lars", 32, true); - peopletable.add("Phil", 43, false); - peopletable.add("Anni", 54, true); - // @@EndExample@@ - - // @@Example: insert_at_index @@ - peopletable.insert(2, "Frank", 34, true); - // @@EndExample@@ - - // @@Example: number_of_rows @@ - if (!peopletable.isEmpty()) { - long s = peopletable.size(); // s => 6 - } - // @@EndExample@@ - - System.out.println("Size = " + peopletable.size() + "\n"); - - /****************************** GETTERS AND SETTERS **********************/ - - // @@Example: accessing_rows @@ - // 2 ways to get the value - String name = peopletable.at(2).getName(); // name => "Mary" - // or - String name2 = peopletable.at(2).name.get(); - - // 2 ways to set the value - peopletable.at(2).name.set("NewName"); - // or - peopletable.at(2).setName("NewName"); - // @@EndExample@@ - - System.out.println("at(2).getName -> " + name + " or " + name2); - System.out.println("at(2).setName('NewName') -> " + peopletable.at(2).getName()); + + /****************************** BASIC OPERATIONS *************************/ + + // @@Example: insert_rows @@ + peopletable.add("John", 20, true); + peopletable.add("Mary", 21, false); + peopletable.add("Lars", 32, true); + peopletable.add("Phil", 43, false); + peopletable.add("Anni", 54, true); + // @@EndExample@@ + + // @@Example: insert_at_index @@ + peopletable.insert(2, "Frank", 34, true); + // @@EndExample@@ + + // @@Example: number_of_rows @@ + if (!peopletable.isEmpty()) { + long s = peopletable.size(); // s => 6 + } + // @@EndExample@@ - /****************************** DATA REMOVAL *****************************/ - // @@Example: deleting_row @@ - peopletable.remove(2); - // @@EndExample@@ + System.out.println("Size = " + peopletable.size() + "\n"); - System.out.println("\nRemoved row 2. Down to " + peopletable.size() + " rows.\n"); + /****************************** GETTERS AND SETTERS **********************/ - /****************************** ITERATION OF ALL RECORDS *****************/ + // @@Example: accessing_rows @@ + // 2 ways to get the value + String name = peopletable.at(2).getName(); // name => "Mary" + // or + String name2 = peopletable.at(2).name.get(); - // lazy iteration over the table - - // @@Example: iteration @@ - for (PeopleRow person : peopletable) { - System.out.println(person.getName() + " is " + person.getAge() + " years old."); - } - // @@EndExample@@ + // 2 ways to set the value + peopletable.at(2).name.set("NewName"); + // or + peopletable.at(2).setName("NewName"); + // @@EndExample@@ + + System.out.println("at(2).getName -> " + name + " or " + name2); + System.out.println("at(2).setName('NewName') -> " + peopletable.at(2).getName()); + + /****************************** DATA REMOVAL *****************************/ + // @@Example: deleting_row @@ + peopletable.remove(2); + // @@EndExample@@ + + System.out.println("\nRemoved row 2. Down to " + peopletable.size() + " rows.\n"); + + /****************************** ITERATION OF ALL RECORDS *****************/ + + // lazy iteration over the table + + // @@Example: iteration @@ + for (PeopleRow person : peopletable) { + System.out.println(person.getName() + " is " + person.getAge() + " years old."); + } + // @@EndExample@@ - /****************************** SIMPLE QUERY *****************************/ - - System.out.println("\nFound: "); - // @@Example: simple_seach @@ - PeopleRow p = peopletable.name.equal("John").findFirst(); - System.out.println( p ); - // prints: "People {name=John, age=20, hired=true}" - // @@EndExample@@ - - /****************************** COMPLEX QUERY ****************************/ - - // @@Example: advanced_search @@ - // Define the query - PeopleQuery query = peopletable - .age.between(20, 35) // Implicit AND with below - .name.contains("a") // Implicit AND with below - .group() // "(" - .hired.equal(true) - .or() // or - .name.endsWith("y") - .endGroup(); // ")" - // Count matches - PeopleView match = query.findAll(); - System.out.println(match.size() + " person(s) match query."); - - // Take the average age of the matches - System.out.println(match.age.sum() + " years is the summed age."); - - // Perform query and use the result - for (PeopleRow person : match) { - // ... do something with matching 'person' - } - // @@EndExample - System.out.println(""); - - /****************************** SERIALIZE ********************************/ - - System.out.println("Serialize to file:"); - // @@Example: serialisation @@ - // Create Table in Group - Group group = new Group(); - PeopleTable people1 = new PeopleTable(group); - - people1.add("John", 20, true); - people1.add("Mary", 21, false); - - // Write to disk - try { - group.writeToFile("people.tightdb"); - } catch (IOException e) { - e.printStackTrace(); - } - - // Load a group from disk (and print contents) - Group fromDisk = new Group("people.tightdb"); - PeopleTable people2 = new PeopleTable(fromDisk); - - for (PeopleRow person : people2) { - System.out.println(person.getName() + " is " + person.getAge() + " years old"); - } - - // Write same group to memory buffer - byte[] buffer = group.writeToMem(); - - // Load a group from memory (and print contents) - Group fromMem = new Group(buffer); - PeopleTable people3 = new PeopleTable(fromMem); - - for (PeopleRow person : people3) { - System.out.println(person.getName() + " is " + person.getAge() + " years old"); - } - // @@EndExample@@ + /****************************** SIMPLE QUERY *****************************/ + + System.out.println("\nFound: "); + // @@Example: simple_seach @@ + PeopleRow p = peopletable.name.equal("John").findFirst(); + System.out.println( p ); + // prints: "People {name=John, age=20, hired=true}" + // @@EndExample@@ + + /****************************** COMPLEX QUERY ****************************/ + + // @@Example: advanced_search @@ + // Define the query + PeopleQuery query = peopletable + .age.between(20, 35) // Implicit AND with below + .name.contains("a") // Implicit AND with below + .group() // "(" + .hired.equal(true) + .or() // or + .name.endsWith("y") + .endGroup(); // ")" + // Count matches + PeopleView match = query.findAll(); + System.out.println(match.size() + " person(s) match query."); + + // Take the average age of the matches + System.out.println(match.age.sum() + " years is the summed age."); + + // Perform query and use the result + for (PeopleRow person : match) { + // ... do something with matching 'person' + } + // @@EndExample + System.out.println(""); + + /****************************** SERIALIZE ********************************/ + + System.out.println("Serialize to file:"); + // @@Example: serialisation @@ + // Create Table in Group + Group group = new Group(); + PeopleTable people1 = new PeopleTable(group); + + people1.add("John", 20, true); + people1.add("Mary", 21, false); + + // Write to disk + try { + group.writeToFile("people.tightdb"); + } catch (IOException e) { + e.printStackTrace(); + } + + // Load a group from disk (and print contents) + Group fromDisk = new Group("people.tightdb"); + PeopleTable people2 = new PeopleTable(fromDisk); + + for (PeopleRow person : people2) { + System.out.println(person.getName() + " is " + person.getAge() + " years old"); + } + + // Write same group to memory buffer + byte[] buffer = group.writeToMem(); + + // Load a group from memory (and print contents) + Group fromMem = new Group(buffer); + PeopleTable people3 = new PeopleTable(fromMem); + + for (PeopleRow person : people3) { + System.out.println(person.getName() + " is " + person.getAge() + " years old"); + } + // @@EndExample@@ } } diff --git a/examples/maven-setup/src/main/java/com/tightdb/example/HelloWorld.java b/examples/maven-setup/src/main/java/com/tightdb/example/HelloWorld.java index 5c564d7d2a..0bd48dd0e8 100644 --- a/examples/maven-setup/src/main/java/com/tightdb/example/HelloWorld.java +++ b/examples/maven-setup/src/main/java/com/tightdb/example/HelloWorld.java @@ -26,7 +26,7 @@ class phone { public static void main(String[] args) { EmployeeTable employees = new EmployeeTable(); - employees.add("John", "Doe", 10000, true, new byte[] { 1, 2, 3 }, new Date(), "extra"); + employees.add("John", "Doe", 10000, true, new byte[] { 1, 2, 3 }, new Date(), "extra", null); TightDB.print("Employees", employees); } diff --git a/lib/tightdb_jni32.dll b/lib/tightdb_jni32.dll deleted file mode 100644 index 0c7c28e3b9..0000000000 Binary files a/lib/tightdb_jni32.dll and /dev/null differ diff --git a/lib/tightdb_jni64.dll b/lib/tightdb_jni64.dll deleted file mode 100644 index 1c573e39a7..0000000000 Binary files a/lib/tightdb_jni64.dll and /dev/null differ diff --git a/pom.xml b/pom.xml index 365fe84bb9..fae37a8553 100644 --- a/pom.xml +++ b/pom.xml @@ -32,20 +32,6 @@ 1.6 - - - org.apache.maven.plugins - maven-jar-plugin - 2.4 - - tightdb - - com/tightdb/*.class - com/tightdb/lib/*.class - - - - diff --git a/tightdb-java-core/pom.xml b/tightdb-java-core/pom.xml index c49ddd970f..35089567ef 100644 --- a/tightdb-java-core/pom.xml +++ b/tightdb-java-core/pom.xml @@ -17,6 +17,7 @@ maven-jar-plugin 2.4 + tightdb ${project.parent.basedir}/lib diff --git a/tightdb-java-core/src/main/java/com/tightdb/ColumnType.java b/tightdb-java-core/src/main/java/com/tightdb/ColumnType.java index da7d02333b..3da3dc007b 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/ColumnType.java +++ b/tightdb-java-core/src/main/java/com/tightdb/ColumnType.java @@ -8,14 +8,29 @@ public enum ColumnType { ColumnTypeBool(1), ColumnTypeInt(0), + ColumnTypeFloat(9), + ColumnTypeDouble(10), ColumnTypeString(2), ColumnTypeBinary(4), ColumnTypeDate(7), ColumnTypeTable(5), ColumnTypeMixed(6); - + // When adding above, remember to update size of largest number below + private final int nativeValue; + // Note that if this array is too small, an + // IndexOutOfBoundsException will be thrown during class loading. + private static ColumnType[] byNativeValue = new ColumnType[11]; + + static { + ColumnType[] columnTypes = values(); + for(int i=0; iColumnType + * @param columnName + * name of the column. Duplicate column name is not allowed. + */ + public void updateFromSpec(TableSpec tableSpec) { + if (immutable) throwImmutable(); + nativeUpdateFromSpec(nativePtr, tableSpec); + } + + protected native void nativeUpdateFromSpec(long nativePtr, TableSpec tableSpec); + + // Table Size and deletion. AutoGenerated subclasses are nothing to do with this + // class. + /** + * Get the number of entries/rows of this table. + * + * @return The number of rows. + */ + public long size() { + return nativeSize(nativePtr); + } + + protected native long nativeSize(long nativeTablePtr); + + /** + * Checks whether this table is empty or not. + * + * @return true if empty, otherwise false. + */ + public boolean isEmpty() { + return size() == 0; + } + + /** + * Clears the table i.e., deleting all rows in the table. + */ + public void clear() { + if (immutable) throwImmutable(); + nativeClear(nativePtr); + } + + protected native void nativeClear(long nativeTablePtr); + + // Column Information. + /** + * Returns the number of columns in the table. + * + * @return the number of columns. + */ + public long getColumnCount() { + return nativeGetColumnCount(nativePtr); + } + + protected native long nativeGetColumnCount(long nativeTablePtr); + + public TableSpec getTableSpec(){ + return nativeGetTableSpec(nativePtr); + } + + protected native TableSpec nativeGetTableSpec(long nativeTablePtr); + + /** + * Returns the name of a column identified by columnIndex. Notice that the + * index is zero based. + * + * @param columnIndex + * the column index + * @return the name of the column + */ + public String getColumnName(long columnIndex) { + return nativeGetColumnName(nativePtr, columnIndex); + } + + protected native String nativeGetColumnName(long nativeTablePtr, long columnIndex); + + /** + * Returns the 0-based index of a column based on the name. + * + * @param name + * column name + * @return the index, -1 if not found + */ + public long getColumnIndex(String name) { + long columnCount = getColumnCount(); + for (int i = 0; i < columnCount; i++) { + if (name.equals(getColumnName(i))) { + return i; + } + } + return -1; + } + + /** + * Get the type of a column identified by the columnIdex. + * + * @param columnIndex + * index of the column. + * @return Type of the particular column. + */ + public ColumnType getColumnType(long columnIndex) + { + return ColumnType.fromNativeValue(nativeGetColumnType(nativePtr, columnIndex)); + } + + protected native int nativeGetColumnType(long nativeTablePtr, long columnIndex); + + /** + * Removes a row from the specific index. As of now the entry is simply + * removed from the table. No Cascading delete for other table is not taken + * care of. Notice that row index is zero based. + * + * @param rowIndex + * the row index + * + */ + public void remove(long rowIndex) { + if (immutable) throwImmutable(); + nativeRemove(nativePtr, rowIndex); + } + + protected native void nativeRemove(long nativeTablePtr, long rowIndex); + + public void removeLast() { + if (immutable) throwImmutable(); + nativeRemoveLast(nativePtr); + } + + protected native void nativeRemoveLast(long nativeTablePtr); + + + // Row Handling methods. + public long addEmptyRow() { + if (immutable) throwImmutable(); + return nativeAddEmptyRow(nativePtr, 1); + } + + public long addEmptyRows(long rows) { + if (immutable) throwImmutable(); + return nativeAddEmptyRow(nativePtr, rows); + } + + protected native long nativeAddEmptyRow(long nativeTablePtr, long rows); + + public void add(Object... values) { + insert(size(), values); + } + + + public void insert(long rowIndex, Object... values) { + if (immutable) throwImmutable(); + + // Check index + long size = size(); + if (rowIndex > size) { + throw new IllegalArgumentException("rowIndex " + String.valueOf(rowIndex) + + " must be <= table.size() " + String.valueOf(size) + "."); + } + + // Check values types + int columns = (int)getColumnCount(); + if (columns != values.length) { + throw new IllegalArgumentException("The number of value parameters (" + + String.valueOf(values.length) + + ") does not match the number of columns in the table (" + + String.valueOf(columns) + ")."); + } + ColumnType colTypes[] = new ColumnType[columns]; + for (int columnIndex = 0; columnIndex < columns; columnIndex++) { + Object value = values[columnIndex]; + ColumnType colType = getColumnType(columnIndex); + colTypes[columnIndex] = colType; + if (!colType.matchObject(value)) { + throw new IllegalArgumentException("Invalid argument no " + String.valueOf(1 + columnIndex) + + ". Expected a value compatible with column type " + colType + ", but got " + value.getClass() + "."); + } + } + + // Insert values + for (long columnIndex = 0; columnIndex < columns; columnIndex++) { + Object value = values[(int)columnIndex]; + switch (colTypes[(int)columnIndex]) { + case ColumnTypeBool: + nativeInsertBoolean(nativePtr, columnIndex, rowIndex, (Boolean)value); + break; + case ColumnTypeInt: + nativeInsertLong(nativePtr, columnIndex, rowIndex, ((Number)value).longValue()); + break; + case ColumnTypeFloat: + nativeInsertFloat(nativePtr, columnIndex, rowIndex, ((Float)value).floatValue()); + break; + case ColumnTypeDouble: + nativeInsertDouble(nativePtr, columnIndex, rowIndex, ((Double)value).doubleValue()); + break; + case ColumnTypeString: + nativeInsertString(nativePtr, columnIndex, rowIndex, (String)value); + break; + case ColumnTypeDate: + nativeInsertDate(nativePtr, columnIndex, rowIndex, ((Date)value).getTime()/1000); + break; + case ColumnTypeMixed: + nativeInsertMixed(nativePtr, columnIndex, rowIndex, Mixed.mixedValue(value)); + break; + case ColumnTypeBinary: + if (value instanceof byte[]) + nativeInsertByteArray(nativePtr, columnIndex, rowIndex, (byte[])value); + else if (value instanceof ByteBuffer) + nativeInsertByteBuffer(nativePtr, columnIndex, rowIndex, (ByteBuffer)value); + break; + case ColumnTypeTable: + nativeInsertSubTable(nativePtr, columnIndex, rowIndex); + insertSubtableValues(rowIndex, columnIndex, value); + break; + default: + throw new RuntimeException("Unexpected columnType: " + String.valueOf(colTypes[(int)columnIndex])); + } + } + insertDone(); + } + + private void insertSubtableValues(long rowIndex, long columnIndex, Object value) { + if (value != null) { + // insert rows in subtable recursively + Table subtable = getSubTableDuringInsert(columnIndex, rowIndex); + int rows = ((Object[])value).length; + for (int i=0; i= size) { + throw new IllegalArgumentException("rowIndex " + String.valueOf(rowIndex) + + " must be < table.size() " + String.valueOf(size) + "."); + } + + // Verify number of 'values' + int columns = (int)getColumnCount(); + if (columns != values.length) { + throw new IllegalArgumentException("The number of value parameters (" + + String.valueOf(values.length) + + ") does not match the number of columns in the table (" + + String.valueOf(columns) + ")."); + } + // Verify type of 'values' + ColumnType colTypes[] = new ColumnType[columns]; + for (int columnIndex = 0; columnIndex < columns; columnIndex++) { + Object value = values[columnIndex]; + ColumnType colType = getColumnType(columnIndex); + colTypes[columnIndex] = colType; + if (!colType.matchObject(value)) { + throw new IllegalArgumentException("Invalid argument no " + String.valueOf(1 + columnIndex) + + ". Expected a value compatible with column type " + colType + ", but got " + value.getClass() + "."); + } + } + + // Now that all values are verified, we can remove the row and insert it again. + // TODO: Can be optimized to only set the values (but clear any subtables) + remove(rowIndex); + insert(rowIndex, values); + } + + + public void insertLong(long columnIndex, long rowIndex, long value) { + if (immutable) throwImmutable(); + nativeInsertLong(nativePtr, columnIndex, rowIndex, value); + } + + protected native void nativeInsertFloat(long nativeTablePtr, long columnIndex, long rowIndex, float value); + + public void insertFloat(long columnIndex, long rowIndex, float value) { + if (immutable) throwImmutable(); + nativeInsertFloat(nativePtr, columnIndex, rowIndex, value); + } + + protected native void nativeInsertDouble(long nativeTablePtr, long columnIndex, long rowIndex, double value); + + public void insertDouble(long columnIndex, long rowIndex, double value) { + if (immutable) throwImmutable(); + nativeInsertDouble(nativePtr, columnIndex, rowIndex, value); + } + + protected native void nativeInsertLong(long nativeTablePtr, long columnIndex, long rowIndex, long value); + + public void insertBoolean(long columnIndex, long rowIndex, boolean value) { + if (immutable) throwImmutable(); + nativeInsertBoolean(nativePtr, columnIndex, rowIndex, value); + } + + protected native void nativeInsertBoolean(long nativeTablePtr, long columnIndex, long rowIndex, boolean value); + + public void insertDate(long columnIndex, long rowIndex, Date date) { + if (immutable) throwImmutable(); + nativeInsertDate(nativePtr, columnIndex, rowIndex, date.getTime()/1000); + } + + protected native void nativeInsertDate(long nativePtr, long columnIndex, long rowIndex, long dateTimeValue); + + public void insertString(long columnIndex, long rowIndex, String value) { + if (immutable) throwImmutable(); + nativeInsertString(nativePtr, columnIndex, rowIndex, value); + } + + protected native void nativeInsertString(long nativeTablePtr, long columnIndex, long rowIndex, String value); + + public void insertMixed(long columnIndex, long rowIndex, Mixed data) { + if (immutable) throwImmutable(); + nativeInsertMixed(nativePtr, columnIndex, rowIndex, data); + } + + protected native void nativeInsertMixed(long nativeTablePtr, long columnIndex, long rowIndex, Mixed mixed); + + public void insertBinary(long columnIndex, long rowIndex, ByteBuffer data) { + if (immutable) throwImmutable(); + //System.err.printf("\ninsertBinary(col %d, row %d, ByteBuffer)\n", columnIndex, rowIndex); + //System.err.println("-- HasArray: " + (data.hasArray() ? "yes":"no") + " len= " + data.array().length); + if (data.isDirect()) + nativeInsertByteBuffer(nativePtr, columnIndex, rowIndex, data); + else + throw new RuntimeException("Currently ByteBuffer must be allocateDirect()."); // FIXME: support other than allocateDirect + } + + protected native void nativeInsertByteBuffer(long nativeTablePtr, long columnIndex, long rowIndex, ByteBuffer data); + + public void insertBinary(long columnIndex, long rowIndex, byte[] data) { + if (immutable) throwImmutable(); + nativeInsertByteArray(nativePtr, columnIndex, rowIndex, data); + } + + protected native void nativeInsertByteArray(long nativePtr, long columnIndex, long rowIndex, byte[] data); + + public void insertSubTable(long columnIndex, long rowIndex, Object[][] values) { + if (immutable) throwImmutable(); + nativeInsertSubTable(nativePtr, columnIndex, rowIndex); + insertSubtableValues(rowIndex, columnIndex, values); + } + + protected native void nativeInsertSubTable(long nativeTablePtr, long columnIndex, long rowIndex); + + public void insertDone() { + if (immutable) throwImmutable(); + nativeInsertDone(nativePtr); + } + + protected native void nativeInsertDone(long nativeTablePtr); + + // + // Getters + // + + public long getLong(long columnIndex, long rowIndex) { + return nativeGetLong(nativePtr, columnIndex, rowIndex); + } + + protected native long nativeGetLong(long nativeTablePtr, long columnIndex, long rowIndex); + + public boolean getBoolean(long columnIndex, long rowIndex) { + return nativeGetBoolean(nativePtr, columnIndex, rowIndex); + } + + protected native boolean nativeGetBoolean(long nativeTablePtr, long columnIndex, long rowIndex); + + public float getFloat(long columnIndex, long rowIndex) { + return nativeGetFloat(nativePtr, columnIndex, rowIndex); + } + + protected native float nativeGetFloat(long nativeTablePtr, long columnIndex, long rowIndex); + + public double getDouble(long columnIndex, long rowIndex) { + return nativeGetDouble(nativePtr, columnIndex, rowIndex); + } + + protected native double nativeGetDouble(long nativeTablePtr, long columnIndex, long rowIndex); + + public Date getDate(long columnIndex, long rowIndex) { + return new Date(nativeGetDateTime(nativePtr, columnIndex, rowIndex)*1000); + } + + protected native long nativeGetDateTime(long nativeTablePtr, long columnIndex, long rowIndex); + + /** + * Get the value of a (string )cell. + * + * @param columnIndex + * 0 based index value of the column + * @param rowIndex + * 0 based index of the row. + * @return value of the particular cell + */ + public String getString(long columnIndex, long rowIndex) { + return nativeGetString(nativePtr, columnIndex, rowIndex); + } + + protected native String nativeGetString(long nativePtr, long columnIndex, long rowIndex); + + /** + * Get the value of a (binary) cell. + * + * @param columnIndex + * 0 based index value of the cell column + * @param rowIndex + * 0 based index value of the cell row + * @return value of the particular cell. + */ + public ByteBuffer getBinaryByteBuffer(long columnIndex, long rowIndex) { + return nativeGetByteBuffer(nativePtr, columnIndex, rowIndex); + } + + protected native ByteBuffer nativeGetByteBuffer(long nativeTablePtr, long columnIndex, long rowIndex); + + public byte[] getBinaryByteArray(long columnIndex, long rowIndex) { + return nativeGetByteArray(nativePtr, columnIndex, rowIndex); + } + + protected native byte[] nativeGetByteArray(long nativePtr, long columnIndex, long rowIndex); + + public Mixed getMixed(long columnIndex, long rowIndex) { + return nativeGetMixed(nativePtr, columnIndex, rowIndex); + } + + public ColumnType getMixedType(long columnIndex, long rowIndex) + { + return ColumnType.fromNativeValue(nativeGetMixedType(nativePtr, columnIndex, rowIndex)); + } + + protected native int nativeGetMixedType(long nativePtr, long columnIndex, long rowIndex); + + protected native Mixed nativeGetMixed(long nativeTablePtr, long columnIndex, long rowIndex); + + /** + * + * Note: The subtable returned will have to be closed again after use. + * You can let javas garbage collector handle that or better yet call close() + * after use. + * + * @param columnIndex column index of the cell + * @param rowIndex row index of the cell + * @return TableBase the subtable at the requested cell + */ + public Table getSubTable(long columnIndex, long rowIndex) { + return new Table(this, nativeGetSubTable(nativePtr, columnIndex, rowIndex), immutable); + } + + protected native long nativeGetSubTable(long nativeTablePtr, long columnIndex, long rowIndex); + + // Below version will allow to getSubTable when number of available rows are not updated yet - + // which happens before an insertDone(). + private Table getSubTableDuringInsert(long columnIndex, long rowIndex) { + return new Table(this, nativeGetSubTableDuringInsert(nativePtr, columnIndex, rowIndex), immutable); + } + private native long nativeGetSubTableDuringInsert(long nativeTablePtr, long columnIndex, long rowIndex); + + + public long getSubTableSize(long columnIndex, long rowIndex) { + return nativeGetSubTableSize(nativePtr, columnIndex, rowIndex); + } + + protected native long nativeGetSubTableSize(long nativeTablePtr, long columnIndex, long rowIndex); + + public void clearSubTable(long columnIndex, long rowIndex) { + if (immutable) throwImmutable(); + nativeClearSubTable(nativePtr, columnIndex, rowIndex); + } + + protected native void nativeClearSubTable(long nativeTablePtr, long columnIndex, long rowIndex); + + + // + // Setters + // + + public void setLong(long columnIndex, long rowIndex, long value) { + if (immutable) throwImmutable(); + nativeSetLong(nativePtr, columnIndex, rowIndex, value); + } + + protected native void nativeSetLong(long nativeTablePtr, long columnIndex, long rowIndex, long value); + + public void setBoolean(long columnIndex, long rowIndex, boolean value) { + if (immutable) throwImmutable(); + nativeSetBoolean(nativePtr, columnIndex, rowIndex, value); + } + + protected native void nativeSetBoolean(long nativeTablePtr, long columnIndex, long rowIndex, boolean value); + + public void setFloat(long columnIndex, long rowIndex, float value) { + if (immutable) throwImmutable(); + nativeSetFloat(nativePtr, columnIndex, rowIndex, value); + } + + protected native void nativeSetFloat(long nativeTablePtr, long columnIndex, long rowIndex, float value); + + public void setDouble(long columnIndex, long rowIndex, double value) { + if (immutable) throwImmutable(); + nativeSetDouble(nativePtr, columnIndex, rowIndex, value); + } + + protected native void nativeSetDouble(long nativeTablePtr, long columnIndex, long rowIndex, double value); + + public void setDate(long columnIndex, long rowIndex, Date date) { + if (immutable) throwImmutable(); + nativeSetDate(nativePtr, columnIndex, rowIndex, date.getTime()/1000); + } + + protected native void nativeSetDate(long nativeTablePtr, long columnIndex, long rowIndex, long dateTimeValue); + + public void setString(long columnIndex, long rowIndex, String value) { + if (immutable) throwImmutable(); + nativeSetString(nativePtr, columnIndex, rowIndex, value); + } + + protected native void nativeSetString(long nativeTablePtr, long columnIndex, long rowIndex, String value); + + /** + * Sets the value for a (binary) cell. + * + * @param columnIndex + * column index of the cell + * @param rowIndex + * row index of the cell + * @param data + * the ByteBuffer must be allocated with ByteBuffer.allocateDirect(len) + */ + public void setBinaryByteBuffer(long columnIndex, long rowIndex, ByteBuffer data) { + if (immutable) throwImmutable(); + if (data == null) + throw new NullPointerException("Null array"); + if (data.isDirect()) + nativeSetByteBuffer(nativePtr, columnIndex, rowIndex, data); + else + throw new RuntimeException("Currently ByteBuffer must be allocateDirect()."); // FIXME: support other than allocateDirect + } + + protected native void nativeSetByteBuffer(long nativeTablePtr, long columnIndex, long rowIndex, ByteBuffer data); + + public void setBinaryByteArray(long columnIndex, long rowIndex, byte[] data) { + if (immutable) throwImmutable(); + if (data == null) + throw new NullPointerException("Null Array"); + nativeSetByteArray(nativePtr, columnIndex, rowIndex, data); + } + + protected native void nativeSetByteArray(long nativePtr, long columnIndex, long rowIndex, byte[] data); + + /** + * Sets the value for a (mixed typed) cell. + * + * @param columnIndex + * column index of the cell + * @param rowIndex + * row index of the cell + * @param data + */ + public void setMixed(long columnIndex, long rowIndex, Mixed data) { + if (immutable) throwImmutable(); + if (data == null) + throw new NullPointerException(); + nativeSetMixed(nativePtr, columnIndex, rowIndex, data); + } + + protected native void nativeSetMixed(long nativeTablePtr, long columnIndex, long rowIndex, Mixed data); + + /** + * Add the value for to all cells in the column. + * + * @param columnIndex column index of the cell + * @param value + */ + //!!!TODO: New. Support in highlevel API + public void addLong(long columnIndex, long value) { + if (immutable) throwImmutable(); + nativeAddInt(nativePtr, columnIndex, value); + } + + protected native void nativeAddInt(long nativeViewPtr, long columnIndex, long value); + + public void setIndex(long columnIndex) { + if (immutable) throwImmutable(); + if (getColumnType(columnIndex) != ColumnType.ColumnTypeString) + throw new IllegalArgumentException("Index is only supported on string columns."); + nativeSetIndex(nativePtr, columnIndex); + } + + protected native void nativeSetIndex(long nativePtr, long columnIndex); + + public boolean hasIndex(long columnIndex) { + return nativeHasIndex(nativePtr, columnIndex); + } + + protected native boolean nativeHasIndex(long nativePtr, long columnIndex); + + // + // Aggregate functions + // + + // Integers + public long sum(long columnIndex) { + return nativeSum(nativePtr, columnIndex); + } + + protected native long nativeSum(long nativePtr, long columnIndex); + + public long maximum(long columnIndex) { + return nativeMaximum(nativePtr, columnIndex); + } + + protected native long nativeMaximum(long nativePtr, long columnIndex); + + public long minimum(long columnIndex) { + return nativeMinimum(nativePtr, columnIndex); + } + + protected native long nativeMinimum(long nativePtr, long columnnIndex); + + public double average(long columnIndex) { + return nativeAverage(nativePtr, columnIndex); + } + + protected native double nativeAverage(long nativePtr, long columnIndex); + + // Floats + public double sumFloat(long columnIndex) { + return nativeSumFloat(nativePtr, columnIndex); + } + + protected native double nativeSumFloat(long nativePtr, long columnIndex); + + public float maximumFloat(long columnIndex) { + return nativeMaximumFloat(nativePtr, columnIndex); + } + + protected native float nativeMaximumFloat(long nativePtr, long columnIndex); + + public float minimumFloat(long columnIndex) { + return nativeMinimumFloat(nativePtr, columnIndex); + } + + protected native float nativeMinimumFloat(long nativePtr, long columnnIndex); + + public double averageFloat(long columnIndex) { + return nativeAverageFloat(nativePtr, columnIndex); + } + + protected native double nativeAverageFloat(long nativePtr, long columnIndex); + + // Doubles + public double sumDouble(long columnIndex) { + return nativeSumDouble(nativePtr, columnIndex); + } + + protected native double nativeSumDouble(long nativePtr, long columnIndex); + + public double maximumDouble(long columnIndex) { + return nativeMaximumDouble(nativePtr, columnIndex); + } + + protected native double nativeMaximumDouble(long nativePtr, long columnIndex); + + public double minimumDouble(long columnIndex) { + return nativeMinimumDouble(nativePtr, columnIndex); + } + + protected native double nativeMinimumDouble(long nativePtr, long columnnIndex); + + public double averageDouble(long columnIndex) { + return nativeAverageDouble(nativePtr, columnIndex); + } + + protected native double nativeAverageDouble(long nativePtr, long columnIndex); + + + // + // Searching methods. + // + + public TableQuery where() { + return new TableQuery(nativeWhere(nativePtr), immutable); + } + + protected native long nativeWhere(long nativeTablePtr); + + public long findFirstLong(long columnIndex, long value) { + return nativeFindFirstInt(nativePtr, columnIndex, value); + } + + protected native long nativeFindFirstInt(long nativeTablePtr, long columnIndex, long value); + + public long findFirstBoolean(long columnIndex, boolean value) { + return nativeFindFirstBool(nativePtr, columnIndex, value); + } + + protected native long nativeFindFirstBool(long nativePtr, long columnIndex, boolean value); + + public long findFirstFloat(long columnIndex, float value) { + return nativeFindFirstFloat(nativePtr, columnIndex, value); + } + + protected native long nativeFindFirstFloat(long nativePtr, long columnIndex, float value); + + public long findFirstDouble(long columnIndex, double value) { + return nativeFindFirstDouble(nativePtr, columnIndex, value); + } + + protected native long nativeFindFirstDouble(long nativePtr, long columnIndex, double value); + + public long findFirstDate(long columnIndex, Date date) { + return nativeFindFirstDate(nativePtr, columnIndex, date.getTime()/1000); + } + + protected native long nativeFindFirstDate(long nativeTablePtr, long columnIndex, long dateTimeValue); + + public long findFirstString(long columnIndex, String value) { + return nativeFindFirstString(nativePtr, columnIndex, value); + } + + protected native long nativeFindFirstString(long nativeTablePtr, long columnIndex, String value); + + public TableView findAllLong(long columnIndex, long value) { + return new TableView(nativeFindAllInt(nativePtr, columnIndex, value), immutable); + } + + protected native long nativeFindAllInt(long nativePtr, long columnIndex, long value); + + public TableView findAllBoolean(long columnIndex, boolean value) { + return new TableView(nativeFindAllBool(nativePtr, columnIndex, value), immutable); + } + + protected native long nativeFindAllBool(long nativePtr, long columnIndex, boolean value); + + public TableView findAllFloat(long columnIndex, float value) { + return new TableView(nativeFindAllFloat(nativePtr, columnIndex, value), immutable); + } + + protected native long nativeFindAllFloat(long nativePtr, long columnIndex, float value); + + public TableView findAllDouble(long columnIndex, double value) { + return new TableView(nativeFindAllDouble(nativePtr, columnIndex, value), immutable); + } + + protected native long nativeFindAllDouble(long nativePtr, long columnIndex, double value); + + public TableView findAllDate(long columnIndex, Date date) { + return new TableView(nativeFindAllDate(nativePtr, columnIndex, date.getTime()/1000), immutable); + } + + protected native long nativeFindAllDate(long nativePtr, long columnIndex, long dateTimeValue); + + public TableView findAllString(long columnIndex, String value) { + return new TableView(nativeFindAllString(nativePtr, columnIndex, value), immutable); + } + + protected native long nativeFindAllString(long nativePtr, long columnIndex, String value); + + public TableView distinct(long columnIndex) { + return new TableView(nativeDistinct(nativePtr, columnIndex), immutable); + } + + protected native long nativeDistinct(long nativePtr, long columnIndex); + + // Optimize + public void optimize() { + if (immutable) throwImmutable(); + nativeOptimize(nativePtr); + } + + protected native void nativeOptimize(long nativeTablePtr); + + public String toJson() { + return nativeToJson(nativePtr); + } + + protected native String nativeToJson(long nativeTablePtr); + + + private void throwImmutable() + { + throw new IllegalStateException("Mutable method call during read transaction."); + } } diff --git a/tightdb-java-core/src/main/java/com/tightdb/TableBase.java b/tightdb-java-core/src/main/java/com/tightdb/TableBase.java deleted file mode 100644 index 3f735958d9..0000000000 --- a/tightdb-java-core/src/main/java/com/tightdb/TableBase.java +++ /dev/null @@ -1,818 +0,0 @@ -package com.tightdb; - -import java.nio.ByteBuffer; -import java.util.Date; - -import com.tightdb.internal.CloseMutex; -import com.tightdb.lib.TightDB; - - - -/** - * This class is a base class for all TightDB tables. The class supports all low - * level methods (define/insert/delete/update) a table has. All the native - * communications to the TightDB C++ library are also handled by this class. - * - * A user who wants to create a table of his choice will automatically inherit - * from this class by the tightdb-class generator. - * - * As an example, let's create a table to keep records of an employee in a - * company. - * - * For this purpose we will create a class named "employee" with an Entity - * annotation as follows. - * - * @Table - * public class employee { - * String name; - * long age; - * boolean hired; - * byte[] imageData; - * } - * - * The tightdb class generator will generate classes relevant to the employee: - * - * 1. Employee.java: Represents one employee of the employee table i.e., a single row. Getter/setter - * methods are declared from which you will be able to set/get values - * for a particular employee. - * 2. EmployeeTable.java: Represents the class for storing a collection of employee i.e., a table - * of rows. The class is inherited from the TableBase class as described above. - * It has all the high level methods to manipulate Employee objects from the table. - * 3. EmployeeView.java: Represents view of the employee table i.e., result set of queries. - * - * - */ - -public class TableBase implements TableOrViewBase { - - public static final long INFINITE = -1; - - protected long nativePtr; - protected boolean immutable = false; - - // test: - protected int tableNo; - protected boolean DEBUG = false; - static int TableCount = 0; - - static { - TightDB.loadLibrary(); - } - - /** - * Construct a Table base object. It can be used to register columns in this - * table. Registering into table is allowed only for empty tables. It - * creates a native reference of the object and keeps a reference to it. - */ - public TableBase() { - // Native methods work will be initialized here. Generated classes will - // have nothing to do with the native functions. Generated Java Table - // classes will work as a wrapper on top of table. - nativePtr = createNative(); - if (nativePtr == 0) - throw new OutOfMemoryError("Out of native memory."); - if (DEBUG) { - tableNo = ++TableCount; - System.err.println("====== New Tablebase " + tableNo + " : ptr = " + nativePtr); - } - } - - protected native long createNative(); - - protected TableBase(Object parent, long nativePtr, boolean immutable) { - this.immutable = immutable; - this.nativePtr = nativePtr; - if (DEBUG) { - tableNo = ++TableCount; - System.err.println("===== New Tablebase(ptr) " + tableNo + " : ptr = " + nativePtr); - } - } - - @Override - public void finalize() { - if (DEBUG) System.err.println("==== FINALIZE " + tableNo + "..."); - close(); - } - - public void close() { - synchronized (CloseMutex.getInstance()) { - if (DEBUG) System.err.println("==== CLOSE " + tableNo + " ptr= " + nativePtr + " remaining " + TableCount); - if (nativePtr == 0) - return; - if (DEBUG) TableCount--; - nativeClose(nativePtr); - nativePtr = 0; - } - } - - protected native void nativeClose(long nativeTablePtr); - - /* - * Check if the Table is valid. - * Whenever a Table/subtable is changed/updated all it's subtables are invalidated. - * You can no longer perform any actions on the table, and if done anyway, an exception is thrown. - * The only method you can call is 'isValid()'. - */ - - public boolean isValid(){ - return nativeIsValid(nativePtr); - } - - protected native boolean nativeIsValid(long nativeTablePtr); - - /** - * Updates a table specification from a Table specification structure. - * Supported types - refer to @see ColumnType. - * - * @param columnType - * data type of the column @see ColumnType - * @param columnName - * name of the column. Duplicate column name is not allowed. - */ - public void updateFromSpec(TableSpec tableSpec) { - if (immutable) throwImmutable(); - nativeUpdateFromSpec(nativePtr, tableSpec); - } - - protected native void nativeUpdateFromSpec(long nativePtr, TableSpec tableSpec); - - // Table Size and deletion. AutoGenerated subclasses are nothing to do with this - // class. - /** - * Get the number of entries/rows of this table. - * - * @return The number of rows. - */ - public long size() { - return nativeSize(nativePtr); - } - - protected native long nativeSize(long nativeTablePtr); - - /** - * Checks whether this table is empty or not. - * - * @return true if empty, otherwise false. - */ - public boolean isEmpty() { - return size() == 0; - } - - /** - * Clears the table i.e., deleting all rows in the table. - */ - public void clear() { - if (immutable) throwImmutable(); - nativeClear(nativePtr); - } - - protected native void nativeClear(long nativeTablePtr); - - // Column Information. - /** - * Returns the number of columns in the table. - * - * @return the number of columns. - */ - public long getColumnCount() { - return nativeGetColumnCount(nativePtr); - } - - protected native long nativeGetColumnCount(long nativeTablePtr); - - public TableSpec getTableSpec(){ - return nativeGetTableSpec(nativePtr); - } - - protected native TableSpec nativeGetTableSpec(long nativeTablePtr); - - /** - * Returns the name of a column identified by columnIndex. Notice that the - * index is zero based. - * - * @param columnIndex - * the column index - * @return the name of the column - */ - public String getColumnName(long columnIndex) { - return nativeGetColumnName(nativePtr, columnIndex); - } - - protected native String nativeGetColumnName(long nativeTablePtr, long columnIndex); - - /** - * Returns the 0-based index of a column based on the name. - * - * @param name - * column name - * @return the index, -1 if not found - */ - public long getColumnIndex(String name) { - long columnCount = getColumnCount(); - for (int i = 0; i < columnCount; i++) { - if (name.equals(getColumnName(i))) { - return i; - } - } - return -1; - } - - /** - * Get the type of a column identified by the columnIdex. - * - * @param columnIndex - * index of the column. - * @return Type of the particular column. - */ - public ColumnType getColumnType(long columnIndex) - { - return ColumnType.fromNativeValue(nativeGetColumnType(nativePtr, columnIndex)); - } - - protected native int nativeGetColumnType(long nativeTablePtr, long columnIndex); - - /** - * Removes a row from the specific index. As of now the entry is simply - * removed from the table. No Cascading delete for other table is not taken - * care of. Notice that row index is zero based. - * - * @param rowIndex - * the row index - * - */ - public void remove(long rowIndex) { - if (immutable) throwImmutable(); - nativeRemove(nativePtr, rowIndex); - } - - protected native void nativeRemove(long nativeTablePtr, long rowIndex); - - public void removeLast() { - if (immutable) throwImmutable(); - nativeRemoveLast(nativePtr); - } - - protected native void nativeRemoveLast(long nativeTablePtr); - - - // Row Handling methods. - public long addEmptyRow() { - if (immutable) throwImmutable(); - return nativeAddEmptyRow(nativePtr, 1); - } - - public long addEmptyRows(long rows) { - if (immutable) throwImmutable(); - return nativeAddEmptyRow(nativePtr, rows); - } - - protected native long nativeAddEmptyRow(long nativeTablePtr, long rows); - - public void add(Object... values) { - insert(size(), values); - } - - - public void insert(long rowIndex, Object... values) { - if (immutable) throwImmutable(); - - // Check index - long size = size(); - if (rowIndex > size) { - throw new IllegalArgumentException("rowIndex " + String.valueOf(rowIndex) + - " must be <= table.size() " + String.valueOf(size) + "."); - } - - // Check values types - int columns = (int)getColumnCount(); - if (columns != values.length) { - throw new IllegalArgumentException("The number of value parameters (" + - String.valueOf(values.length) + - ") does not match the number of columns in the table (" + - String.valueOf(columns) + ")."); - } - ColumnType colTypes[] = new ColumnType[columns]; - for (int columnIndex = 0; columnIndex < columns; columnIndex++) { - Object value = values[columnIndex]; - ColumnType colType = getColumnType(columnIndex); - colTypes[columnIndex] = colType; - if (!colType.matchObject(value)) { - throw new IllegalArgumentException("Invalid argument no " + String.valueOf(1 + columnIndex) + - ". Expected a value compatible with column type " + colType + ", but got " + value.getClass() + "."); - } - } - - // Insert values - for (long columnIndex = 0; columnIndex < columns; columnIndex++) { - Object value = values[(int)columnIndex]; - switch (colTypes[(int)columnIndex]) { - case ColumnTypeBool: - nativeInsertBoolean(nativePtr, columnIndex, rowIndex, (Boolean)value); - break; - case ColumnTypeInt: - nativeInsertLong(nativePtr, columnIndex, rowIndex, ((Number)value).longValue()); - break; - case ColumnTypeString: - nativeInsertString(nativePtr, columnIndex, rowIndex, (String)value); - break; - case ColumnTypeDate: - nativeInsertDate(nativePtr, columnIndex, rowIndex, ((Date)value).getTime()/1000); - break; - case ColumnTypeMixed: - nativeInsertMixed(nativePtr, columnIndex, rowIndex, Mixed.mixedValue(value)); - break; - case ColumnTypeBinary: - if (value instanceof byte[]) - nativeInsertByteArray(nativePtr, columnIndex, rowIndex, (byte[])value); - else if (value instanceof ByteBuffer) - nativeInsertByteBuffer(nativePtr, columnIndex, rowIndex, (ByteBuffer)value); - break; - case ColumnTypeTable: - nativeInsertSubTable(nativePtr, columnIndex, rowIndex); - if (value != null) { - // insert rows in subtable recursively - TableBase subtable = getSubTableDuringInsert(columnIndex, rowIndex); - int rows = ((Object[])value).length; - for (int i=0; i= size) { - throw new IllegalArgumentException("rowIndex " + String.valueOf(rowIndex) + - " must be < table.size() " + String.valueOf(size) + "."); - } - - // Verify number of 'values' - int columns = (int)getColumnCount(); - if (columns != values.length) { - throw new IllegalArgumentException("The number of value parameters (" + - String.valueOf(values.length) + - ") does not match the number of columns in the table (" + - String.valueOf(columns) + ")."); - } - // Verify type of 'values' - ColumnType colTypes[] = new ColumnType[columns]; - for (int columnIndex = 0; columnIndex < columns; columnIndex++) { - Object value = values[columnIndex]; - ColumnType colType = getColumnType(columnIndex); - colTypes[columnIndex] = colType; - if (!colType.matchObject(value)) { - throw new IllegalArgumentException("Invalid argument no " + String.valueOf(1 + columnIndex) + - ". Expected a value compatible with column type " + colType + ", but got " + value.getClass() + "."); - } - } - - // Now that all values are verified, we can remove the row and insert it again. - // TODO: Can be optimized to only set the values (but clear any subtables) - remove(rowIndex); - insert(rowIndex, values); - } - - - public void insertLong(long columnIndex, long rowIndex, long value) { - if (immutable) throwImmutable(); - nativeInsertLong(nativePtr, columnIndex, rowIndex, value); - } - - protected native void nativeInsertLong(long nativeTablePtr, long columnIndex, long rowIndex, long value); - - public void insertBoolean(long columnIndex, long rowIndex, boolean value) { - if (immutable) throwImmutable(); - nativeInsertBoolean(nativePtr, columnIndex, rowIndex, value); - } - - protected native void nativeInsertBoolean(long nativeTablePtr, long columnIndex, long rowIndex, boolean value); - - public void insertDate(long columnIndex, long rowIndex, Date date) { - if (immutable) throwImmutable(); - nativeInsertDate(nativePtr, columnIndex, rowIndex, date.getTime()/1000); - } - - protected native void nativeInsertDate(long nativePtr, long columnIndex, long rowIndex, long dateTimeValue); - - public void insertString(long columnIndex, long rowIndex, String value) { - if (immutable) throwImmutable(); - nativeInsertString(nativePtr, columnIndex, rowIndex, value); - } - - protected native void nativeInsertString(long nativeTablePtr, long columnIndex, long rowIndex, String value); - - public void insertMixed(long columnIndex, long rowIndex, Mixed data) { - if (immutable) throwImmutable(); - nativeInsertMixed(nativePtr, columnIndex, rowIndex, data); - } - - protected native void nativeInsertMixed(long nativeTablePtr, long columnIndex, long rowIndex, Mixed mixed); - - public void insertBinary(long columnIndex, long rowIndex, ByteBuffer data) { - if (immutable) throwImmutable(); - //System.err.printf("\ninsertBinary(col %d, row %d, ByteBuffer)\n", columnIndex, rowIndex); - //System.err.println("-- HasArray: " + (data.hasArray() ? "yes":"no") + " len= " + data.array().length); - if (data.isDirect()) - nativeInsertByteBuffer(nativePtr, columnIndex, rowIndex, data); - else - throw new RuntimeException("Currently ByteBuffer must be allocateDirect()."); // FIXME: support other than allocateDirect - } - - protected native void nativeInsertByteBuffer(long nativeTablePtr, long columnIndex, long rowIndex, ByteBuffer data); - - public void insertBinary(long columnIndex, long rowIndex, byte[] data) { - if (immutable) throwImmutable(); - nativeInsertByteArray(nativePtr, columnIndex, rowIndex, data); - } - - protected native void nativeInsertByteArray(long nativePtr, long columnIndex, long rowIndex, byte[] data); - - public void insertSubTable(long columnIndex, long rowIndex) { - if (immutable) throwImmutable(); - nativeInsertSubTable(nativePtr, columnIndex, rowIndex); - } - - protected native void nativeInsertSubTable(long nativeTablePtr, long columnIndex, long rowIndex); - - public void insertDone() { - if (immutable) throwImmutable(); - nativeInsertDone(nativePtr); - } - - protected native void nativeInsertDone(long nativeTablePtr); - - /** - * Get the value of the particular (integer) cell. - * - * @param columnIndex - * 0 based index value of the column. - * @param rowIndex - * 0 based row value of the column. - * @return value of the particular cell. - */ - public long getLong(long columnIndex, long rowIndex) { - return nativeGetLong(nativePtr, columnIndex, rowIndex); - } - - protected native long nativeGetLong(long nativeTablePtr, long columnIndex, long rowIndex); - - /** - * Get the value of the particular (boolean) cell. - * - * @param columnIndex - * 0 based index value of the cell column. - * @param rowIndex - * 0 based index of the row. - * @return value of the particular cell. - */ - public boolean getBoolean(long columnIndex, long rowIndex) { - return nativeGetBoolean(nativePtr, columnIndex, rowIndex); - } - - protected native boolean nativeGetBoolean(long nativeTablePtr, long columnIndex, long rowIndex); - - public Date getDate(long columnIndex, long rowIndex) { - return new Date(nativeGetDateTime(nativePtr, columnIndex, rowIndex)*1000); - } - - protected native long nativeGetDateTime(long nativeTablePtr, long columnIndex, long rowIndex); - - /** - * Get the value of a (string )cell. - * - * @param columnIndex - * 0 based index value of the column - * @param rowIndex - * 0 based index of the row. - * @return value of the particular cell - */ - public String getString(long columnIndex, long rowIndex) { - return nativeGetString(nativePtr, columnIndex, rowIndex); - } - - protected native String nativeGetString(long nativePtr, long columnIndex, long rowIndex); - - /** - * Get the value of a (binary) cell. - * - * @param columnIndex - * 0 based index value of the cell column - * @param rowIndex - * 0 based index value of the cell row - * @return value of the particular cell. - */ - public ByteBuffer getBinaryByteBuffer(long columnIndex, long rowIndex) { - return nativeGetByteBuffer(nativePtr, columnIndex, rowIndex); - } - - protected native ByteBuffer nativeGetByteBuffer(long nativeTablePtr, long columnIndex, long rowIndex); - - public byte[] getBinaryByteArray(long columnIndex, long rowIndex) { - return nativeGetByteArray(nativePtr, columnIndex, rowIndex); - } - - protected native byte[] nativeGetByteArray(long nativePtr, long columnIndex, long rowIndex); - - public Mixed getMixed(long columnIndex, long rowIndex) { - return nativeGetMixed(nativePtr, columnIndex, rowIndex); - } - - public ColumnType getMixedType(long columnIndex, long rowIndex) - { - return ColumnType.fromNativeValue(nativeGetMixedType(nativePtr, columnIndex, rowIndex)); - } - - protected native int nativeGetMixedType(long nativePtr, long columnIndex, long rowIndex); - - protected native Mixed nativeGetMixed(long nativeTablePtr, long columnIndex, long rowIndex); - - /** - * - * Note: The subtable returned will have to be closed again after use. - * You can let javas garbage collector handle that or better yet call close() - * after use. - * - * @param columnIndex column index of the cell - * @param rowIndex row index of the cell - * @return TableBase the subtable at the requested cell - */ - public TableBase getSubTable(long columnIndex, long rowIndex) { - return new TableBase(this, nativeGetSubTable(nativePtr, columnIndex, rowIndex), immutable); - } - - protected native long nativeGetSubTable(long nativeTablePtr, long columnIndex, long rowIndex); - - // Below version will allow to getSubTable when number of available rows are not updated yet - - // which happens before an insertDone(). - private TableBase getSubTableDuringInsert(long columnIndex, long rowIndex) { - return new TableBase(this, nativeGetSubTableDuringInsert(nativePtr, columnIndex, rowIndex), immutable); - } - private native long nativeGetSubTableDuringInsert(long nativeTablePtr, long columnIndex, long rowIndex); - - - public long getSubTableSize(long columnIndex, long rowIndex) { - return nativeGetSubTableSize(nativePtr, columnIndex, rowIndex); - } - - protected native long nativeGetSubTableSize(long nativeTablePtr, long columnIndex, long rowIndex); - - public void clearSubTable(long columnIndex, long rowIndex) { - if (immutable) throwImmutable(); - nativeClearSubTable(nativePtr, columnIndex, rowIndex); - } - - protected native void nativeClearSubTable(long nativeTablePtr, long columnIndex, long rowIndex); - - /** - * Sets a value for a (string) cell. - * Note that if we call this method on the table for a particular column - * marked by the columnIndex, that column has to be an String based column - * which means the type of the column must be ColumnType.ColumnTypeString. - * - * @param columnIndex - * column index of the cell - * @param rowIndex - * row index of the cell - * @param value - */ - public void setString(long columnIndex, long rowIndex, String value) { - if (immutable) throwImmutable(); - nativeSetString(nativePtr, columnIndex, rowIndex, value); - } - - protected native void nativeSetString(long nativeTablePtr, long columnIndex, long rowIndex, String value); - - /** - * Sets the value for a particular (integer) cell. - * - * @param columnIndex - * column index of the cell - * @param rowIndex - * row index of the cell - * @param value - */ - public void setLong(long columnIndex, long rowIndex, long value) { - if (immutable) throwImmutable(); - nativeSetLong(nativePtr, columnIndex, rowIndex, value); - } - - protected native void nativeSetLong(long nativeTablePtr, long columnIndex, long rowIndex, long value); - - /** - * Sets value for a particular (boolean) cell. - * - * @param columnIndex - * column index of the cell - * @param rowIndex - * row index of the cell - * @param value - */ - public void setBoolean(long columnIndex, long rowIndex, boolean value) { - if (immutable) throwImmutable(); - nativeSetBoolean(nativePtr, columnIndex, rowIndex, value); - } - - protected native void nativeSetBoolean(long nativeTablePtr, long columnIndex, long rowIndex, boolean value); - - public void setDate(long columnIndex, long rowIndex, Date date) { - if (immutable) throwImmutable(); - nativeSetDate(nativePtr, columnIndex, rowIndex, date.getTime()/1000); - } - - protected native void nativeSetDate(long nativeTablePtr, long columnIndex, long rowIndex, long dateTimeValue); - - /** - * Sets the value for a (binary) cell. - * - * @param columnIndex - * column index of the cell - * @param rowIndex - * row index of the cell - * @param data - * the ByteBuffer must be allocated with ByteBuffer.allocateDirect(len) - */ - public void setBinaryByteBuffer(long columnIndex, long rowIndex, ByteBuffer data) { - if (immutable) throwImmutable(); - if (data == null) - throw new NullPointerException("Null array"); - if (data.isDirect()) - nativeSetByteBuffer(nativePtr, columnIndex, rowIndex, data); - else - throw new RuntimeException("Currently ByteBuffer must be allocateDirect()."); // FIXME: support other than allocateDirect - } - - protected native void nativeSetByteBuffer(long nativeTablePtr, long columnIndex, long rowIndex, ByteBuffer data); - - public void setBinaryByteArray(long columnIndex, long rowIndex, byte[] data) { - if (immutable) throwImmutable(); - if (data == null) - throw new NullPointerException("Null Array"); - nativeSetByteArray(nativePtr, columnIndex, rowIndex, data); - } - - protected native void nativeSetByteArray(long nativePtr, long columnIndex, long rowIndex, byte[] data); - - /** - * Sets the value for a (mixed typed) cell. - * - * @param columnIndex - * column index of the cell - * @param rowIndex - * row index of the cell - * @param data - */ - public void setMixed(long columnIndex, long rowIndex, Mixed data) { - if (immutable) throwImmutable(); - if (data == null) - throw new NullPointerException(); - nativeSetMixed(nativePtr, columnIndex, rowIndex, data); - } - - protected native void nativeSetMixed(long nativeTablePtr, long columnIndex, long rowIndex, Mixed data); - - /** - * Add the value for to all cells in the column. - * - * @param columnIndex column index of the cell - * @param value - */ - //!!!TODO: New. Support in highlevel API - public void addLong(long columnIndex, long value) { - if (immutable) throwImmutable(); - nativeAddInt(nativePtr, columnIndex, value); - } - - protected native void nativeAddInt(long nativeViewPtr, long columnIndex, long value); - - public void setIndex(long columnIndex) { - if (immutable) throwImmutable(); - if (getColumnType(columnIndex) != ColumnType.ColumnTypeString) - throw new IllegalArgumentException("Index is only supported on string columns."); - nativeSetIndex(nativePtr, columnIndex); - } - - protected native void nativeSetIndex(long nativePtr, long columnIndex); - - public boolean hasIndex(long columnIndex) { - return nativeHasIndex(nativePtr, columnIndex); - } - - protected native boolean nativeHasIndex(long nativePtr, long columnIndex); - - // Aggregate functions. - public long sum(long columnIndex) { - return nativeSum(nativePtr, columnIndex); - } - - protected native long nativeSum(long nativePtr, long columnIndex); - - public long maximum(long columnIndex) { - return nativeMaximum(nativePtr, columnIndex); - } - - protected native long nativeMaximum(long nativePtr, long columnIndex); - - public long minimum(long columnIndex) { - return nativeMinimum(nativePtr, columnIndex); - } - - protected native long nativeMinimum(long nativePtr, long columnnIndex); - - public double average(long columnIndex) { - return nativeAverage(nativePtr, columnIndex); - } - - protected native double nativeAverage(long nativePtr, long columnIndex); - - // Searching methods. - public TableQuery where() { - return new TableQuery(nativeWhere(nativePtr), immutable); - } - - protected native long nativeWhere(long nativeTablePtr); - - public long findFirstLong(long columnIndex, long value) { - return nativeFindFirstInt(nativePtr, columnIndex, value); - } - - protected native long nativeFindFirstInt(long nativeTablePtr, long columnIndex, long value); - - public long findFirstBoolean(long columnIndex, boolean value) { - return nativeFindFirstBool(nativePtr, columnIndex, value); - } - - protected native long nativeFindFirstBool(long nativePtr, long columnIndex, boolean value); - - public long findFirstDate(long columnIndex, Date date) { - return nativeFindFirstDate(nativePtr, columnIndex, date.getTime()/1000); - } - - protected native long nativeFindFirstDate(long nativeTablePtr, long columnIndex, long dateTimeValue); - - public long findFirstString(long columnIndex, String value) { - return nativeFindFirstString(nativePtr, columnIndex, value); - } - - protected native long nativeFindFirstString(long nativeTablePtr, long columnIndex, String value); - - public TableViewBase findAllLong(long columnIndex, long value) { - return new TableViewBase(nativeFindAllInt(nativePtr, columnIndex, value), immutable); - } - - protected native long nativeFindAllInt(long nativePtr, long columnIndex, long value); - - public TableViewBase findAllBoolean(long columnIndex, boolean value) { - return new TableViewBase(nativeFindAllBool(nativePtr, columnIndex, value), immutable); - } - - protected native long nativeFindAllBool(long nativePtr, long columnIndex, boolean value); - - public TableViewBase findAllDate(long columnIndex, Date date) { - return new TableViewBase(nativeFindAllDate(nativePtr, columnIndex, date.getTime()/1000), immutable); - } - - protected native long nativeFindAllDate(long nativePtr, long columnIndex, long dateTimeValue); - - public TableViewBase findAllString(long columnIndex, String value) { - return new TableViewBase(nativeFindAllString(nativePtr, columnIndex, value), immutable); - } - - protected native long nativeFindAllString(long nativePtr, long columnIndex, String value); - - public TableViewBase distinct(long columnIndex) { - return new TableViewBase(nativeDistinct(nativePtr, columnIndex), immutable); - } - - protected native long nativeDistinct(long nativePtr, long columnIndex); - - // Optimize - public void optimize() { - if (immutable) throwImmutable(); - nativeOptimize(nativePtr); - } - - protected native void nativeOptimize(long nativeTablePtr); - - public String toJson() { - return nativeToJson(nativePtr); - } - - // TODO: implement this! - protected native String nativeToJson(long nativeTablePtr); - - - private void throwImmutable() - { - throw new IllegalStateException("Mutable method call during read transaction."); - } -} diff --git a/tightdb-java-core/src/main/java/com/tightdb/TableOrViewBase.java b/tightdb-java-core/src/main/java/com/tightdb/TableOrView.java similarity index 64% rename from tightdb-java-core/src/main/java/com/tightdb/TableOrViewBase.java rename to tightdb-java-core/src/main/java/com/tightdb/TableOrView.java index d579eb9d66..12b005da0c 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/TableOrViewBase.java +++ b/tightdb-java-core/src/main/java/com/tightdb/TableOrView.java @@ -4,7 +4,7 @@ import java.util.Date; -public interface TableOrViewBase { +public interface TableOrView { void clear(); @@ -53,6 +53,26 @@ public interface TableOrViewBase { */ boolean getBoolean(long columnIndex, long rowIndex); + /** + * Get the float value of a cell of the table identified by the + * columnIndex and rowIndex. + * + * @param columnIndex + * @param rowIndex + * @return + */ + float getFloat(long columnIndex, long rowIndex); + + /** + * Get the double value of a cell of the table identified by the + * columnIndex and rowIndex. + * + * @param columnIndex + * @param rowIndex + * @return + */ + double getDouble(long columnIndex, long rowIndex); + /** * Gets the string value of a cell identified by the columnIndex and * rowIndex of the cell. @@ -89,7 +109,7 @@ public interface TableOrViewBase { ColumnType getMixedType(long columnIndex, long rowIndex); - TableBase getSubTable(long columnIndex, long rowIndex); + Table getSubTable(long columnIndex, long rowIndex); void clearSubTable(long columnIndex, long rowIndex); @@ -115,6 +135,26 @@ public interface TableOrViewBase { */ void setBoolean(long columnIndex, long rowIndex, boolean value); + /** + * Sets the float value of a cell identified by the columnIndex and the + * rowIndex of that cell. + * + * @param columnIndex + * @param rowIndex + * @param value + */ + void setFloat(long columnIndex, long rowIndex, float value); + + /** + * Sets the double value of a cell identified by the columnIndex and the + * rowIndex of that cell. + * + * @param columnIndex + * @param rowIndex + * @param value + */ + void setDouble(long columnIndex, long rowIndex, double value); + /** * Sets the string value of a particular cell of the table/view identified * by the columnIndex and the rowIndex of this table/view @@ -141,6 +181,7 @@ public interface TableOrViewBase { void setMixed(long columnIndex, long rowIndex, Mixed data); + void addLong(long columnIndex, long value); long sum(long columnIndex); @@ -150,22 +191,51 @@ public interface TableOrViewBase { long minimum(long columnIndex); double average(long columnIndex); + + + double sumFloat(long columnIndex); + + float maximumFloat(long columnIndex); + + float minimumFloat(long columnIndex); + + double averageFloat(long columnIndex); + + + double sumDouble(long columnIndex); + + double maximumDouble(long columnIndex); + + double minimumDouble(long columnIndex); + + double averageDouble(long columnIndex); + long findFirstLong(long columnIndex, long value); long findFirstBoolean(long columnIndex, boolean value); + long findFirstFloat(long columnIndex, float value); + + long findFirstDouble(long columnIndex, double value); + long findFirstDate(long columnIndex, Date value); long findFirstString(long columnIndex, String value); + + - TableViewBase findAllLong(long columnIndex, long value); + TableView findAllLong(long columnIndex, long value); + + TableView findAllBoolean(long columnIndex, boolean value); + + TableView findAllFloat(long columnIndex, float value); - TableViewBase findAllBoolean(long columnIndex, boolean value); + TableView findAllDouble(long columnIndex, double value); - TableViewBase findAllDate(long columnIndex, Date value); + TableView findAllDate(long columnIndex, Date value); - TableViewBase findAllString(long columnIndex, String value); + TableView findAllString(long columnIndex, String value); String toJson(); diff --git a/tightdb-java-core/src/main/java/com/tightdb/TableQuery.java b/tightdb-java-core/src/main/java/com/tightdb/TableQuery.java index 074c1eb514..9f5bf1d8b8 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/TableQuery.java +++ b/tightdb-java-core/src/main/java/com/tightdb/TableQuery.java @@ -12,7 +12,7 @@ public TableQuery(long nativeQueryPtr, boolean immutable){ } // Query TableView - public TableQuery tableview(TableViewBase tv){ + public TableQuery tableview(TableView tv){ nativeTableview(nativePtr, tv.nativePtr); return this; } @@ -118,6 +118,145 @@ public TableQuery between(long columnIndex, long value1, long value2){ } protected native void nativeBetween(long nativeQueryPtr, long columnIndex, long value1, long value2); + + // Query for float values. + + public TableQuery equal(long columnIndex, float value){ + nativeEqual(nativePtr, columnIndex, value); + return this; + } + public TableQuery eq(long columnIndex, float value){ + nativeEqual(nativePtr, columnIndex, value); + return this; + } + protected native void nativeEqual(long nativeQueryPtr, long columnIndex, float value); + + public TableQuery notEqual(long columnIndex, float value){ + nativeNotEqual(nativePtr, columnIndex, value); + return this; + } + public TableQuery neq(long columnIndex, float value){ + nativeNotEqual(nativePtr, columnIndex, value); + return this; + } + protected native void nativeNotEqual(long nativeQueryPtr, long columnIndex, float value); + + public TableQuery greaterThan(long columnIndex, float value){ + nativeGreater(nativePtr, columnIndex, value); + return this; + } + public TableQuery gt(long columnIndex, float value){ + nativeGreater(nativePtr, columnIndex, value); + return this; + } + protected native void nativeGreater(long nativeQueryPtr, long columnIndex, float value); + + public TableQuery greaterThanOrEqual(long columnIndex, float value){ + nativeGreaterEqual(nativePtr, columnIndex, value); + return this; + } + public TableQuery gte(long columnIndex, float value){ + nativeGreaterEqual(nativePtr, columnIndex, value); + return this; + } + protected native void nativeGreaterEqual(long nativeQueryPtr, long columnIndex, float value); + + public TableQuery lessThan(long columnIndex, float value){ + nativeLess(nativePtr, columnIndex, value); + return this; + } + public TableQuery lt(long columnIndex, float value){ + nativeLess(nativePtr, columnIndex, value); + return this; + } + protected native void nativeLess(long nativeQueryPtr, long columnIndex, float value); + + public TableQuery lessThanOrEqual(long columnIndex, float value){ + nativeLessEqual(nativePtr, columnIndex, value); + return this; + } + public TableQuery lte(long columnIndex, float value){ + nativeLessEqual(nativePtr, columnIndex, value); + return this; + } + protected native void nativeLessEqual(long nativeQueryPtr, long columnIndex, float value); + + public TableQuery between(long columnIndex, float value1, float value2){ + nativeBetween(nativePtr, columnIndex, value1, value2); + return this; + } + protected native void nativeBetween(long nativeQueryPtr, long columnIndex, float value1, float value2); + + + // Query for double values. + + public TableQuery equal(long columnIndex, double value){ + nativeEqual(nativePtr, columnIndex, value); + return this; + } + public TableQuery eq(long columnIndex, double value){ + nativeEqual(nativePtr, columnIndex, value); + return this; + } + protected native void nativeEqual(long nativeQueryPtr, long columnIndex, double value); + + public TableQuery notEqual(long columnIndex, double value){ + nativeNotEqual(nativePtr, columnIndex, value); + return this; + } + public TableQuery neq(long columnIndex, double value){ + nativeNotEqual(nativePtr, columnIndex, value); + return this; + } + protected native void nativeNotEqual(long nativeQueryPtr, long columnIndex, double value); + + public TableQuery greaterThan(long columnIndex, double value){ + nativeGreater(nativePtr, columnIndex, value); + return this; + } + public TableQuery gt(long columnIndex, double value){ + nativeGreater(nativePtr, columnIndex, value); + return this; + } + protected native void nativeGreater(long nativeQueryPtr, long columnIndex, double value); + + public TableQuery greaterThanOrEqual(long columnIndex, double value){ + nativeGreaterEqual(nativePtr, columnIndex, value); + return this; + } + public TableQuery gte(long columnIndex, double value){ + nativeGreaterEqual(nativePtr, columnIndex, value); + return this; + } + protected native void nativeGreaterEqual(long nativeQueryPtr, long columnIndex, double value); + + public TableQuery lessThan(long columnIndex, double value){ + nativeLess(nativePtr, columnIndex, value); + return this; + } + public TableQuery lt(long columnIndex, double value){ + nativeLess(nativePtr, columnIndex, value); + return this; + } + protected native void nativeLess(long nativeQueryPtr, long columnIndex, double value); + + public TableQuery lessThanOrEqual(long columnIndex, double value){ + nativeLessEqual(nativePtr, columnIndex, value); + return this; + } + public TableQuery lte(long columnIndex, double value){ + nativeLessEqual(nativePtr, columnIndex, value); + return this; + } + protected native void nativeLessEqual(long nativeQueryPtr, long columnIndex, double value); + + public TableQuery between(long columnIndex, double value1, double value2){ + nativeBetween(nativePtr, columnIndex, value1, value2); + return this; + } + protected native void nativeBetween(long nativeQueryPtr, long columnIndex, double value1, double value2); + + // Query for boolean values. public TableQuery equal(long columnIndex, boolean value){ @@ -208,86 +347,158 @@ public long findNext(long lastMatch){ } public long findNext(){ - return nativeFindNext(nativePtr, TableBase.INFINITE); + return nativeFindNext(nativePtr, Table.INFINITE); } protected native long nativeFindNext(long nativeQueryPtr, long lastMatch); - public TableViewBase findAll(long start, long end, long limit){ - return new TableViewBase(nativeFindAll(nativePtr, start, end, limit), immutable); + public TableView findAll(long start, long end, long limit){ + return new TableView(nativeFindAll(nativePtr, start, end, limit), immutable); } - public TableViewBase findAll(){ - return new TableViewBase(nativeFindAll(nativePtr, 0, TableBase.INFINITE, TableBase.INFINITE), immutable); + public TableView findAll(){ + return new TableView(nativeFindAll(nativePtr, 0, Table.INFINITE, Table.INFINITE), immutable); } protected native long nativeFindAll(long nativeQueryPtr, long start, long end, long limit); - + // // Aggregation methods + // + + // Integer aggregation public long sum(long columnIndex, long start, long end){ - return nativeSum(nativePtr, columnIndex, start, end, TableBase.INFINITE); + return nativeSum(nativePtr, columnIndex, start, end, Table.INFINITE); } - public long sum(long columnIndex){ - return nativeSum(nativePtr, columnIndex, 0, TableBase.INFINITE, TableBase.INFINITE); + return nativeSum(nativePtr, columnIndex, 0, Table.INFINITE, Table.INFINITE); } - protected native long nativeSum(long nativeQueryPtr, long columnIndex, long start, long end, long limit); + public long maximum(long columnIndex, long start, long end){ - return nativeMaximum(nativePtr, columnIndex, start, end, TableBase.INFINITE); + return nativeMaximum(nativePtr, columnIndex, start, end, Table.INFINITE); } - public long maximum(long columnIndex){ - return nativeMaximum(nativePtr, columnIndex, 0, TableBase.INFINITE, TableBase.INFINITE); + return nativeMaximum(nativePtr, columnIndex, 0, Table.INFINITE, Table.INFINITE); } - protected native long nativeMaximum(long nativeQueryPtr, long columnIndex, long start, long end, long limit); + public long minimum(long columnIndex, long start, long end){ - return nativeMinimum(nativePtr, columnIndex, start, end, TableBase.INFINITE); + return nativeMinimum(nativePtr, columnIndex, start, end, Table.INFINITE); } - public long minimum(long columnIndex){ - return nativeMinimum(nativePtr, columnIndex, 0, TableBase.INFINITE, TableBase.INFINITE); + return nativeMinimum(nativePtr, columnIndex, 0, Table.INFINITE, Table.INFINITE); } - protected native long nativeMinimum(long nativeQueryPtr, long columnIndex, long start, long end, long limit); public double average(long columnIndex, long start, long end){ - return nativeAverage(nativePtr, columnIndex, start, end, TableBase.INFINITE); + return nativeAverage(nativePtr, columnIndex, start, end, Table.INFINITE); } - public double average(long columnIndex){ - return nativeAverage(nativePtr, columnIndex, 0, TableBase.INFINITE, TableBase.INFINITE); + return nativeAverage(nativePtr, columnIndex, 0, Table.INFINITE, Table.INFINITE); } - protected native double nativeAverage(long nativeQueryPtr, long columnIndex, long start, long end, long limit); - public long count(long start, long end){ - return nativeCount(nativePtr, start, end, TableBase.INFINITE); + // float aggregation + + public double sumFloat(long columnIndex, long start, long end){ + return nativeSumFloat(nativePtr, columnIndex, start, end, Table.INFINITE); + } + public double sumFloat(long columnIndex){ + return nativeSumFloat(nativePtr, columnIndex, 0, Table.INFINITE, Table.INFINITE); } + protected native double nativeSumFloat(long nativeQueryPtr, long columnIndex, long start, long end, long limit); + - public long count(){ - return nativeCount(nativePtr, 0, TableBase.INFINITE, TableBase.INFINITE); + public float maximumFloat(long columnIndex, long start, long end){ + return nativeMaximumFloat(nativePtr, columnIndex, start, end, Table.INFINITE); + } + public float maximumFloat(long columnIndex){ + return nativeMaximumFloat(nativePtr, columnIndex, 0, Table.INFINITE, Table.INFINITE); + } + protected native float nativeMaximumFloat(long nativeQueryPtr, long columnIndex, long start, long end, long limit); + + + public float minimumFloat(long columnIndex, long start, long end){ + return nativeMinimumFloat(nativePtr, columnIndex, start, end, Table.INFINITE); + } + public float minimumFloat(long columnIndex){ + return nativeMinimumFloat(nativePtr, columnIndex, 0, Table.INFINITE, Table.INFINITE); + } + protected native float nativeMinimumFloat(long nativeQueryPtr, long columnIndex, long start, long end, long limit); + + + public double averageFloat(long columnIndex, long start, long end){ + return nativeAverageFloat(nativePtr, columnIndex, start, end, Table.INFINITE); + } + public double averageFloat(long columnIndex){ + return nativeAverageFloat(nativePtr, columnIndex, 0, Table.INFINITE, Table.INFINITE); + } + protected native double nativeAverageFloat(long nativeQueryPtr, long columnIndex, long start, long end, long limit); + + + // double aggregation + + public double sumDouble(long columnIndex, long start, long end){ + return nativeSumDouble(nativePtr, columnIndex, start, end, Table.INFINITE); } + public double sumDouble(long columnIndex){ + return nativeSumDouble(nativePtr, columnIndex, 0, Table.INFINITE, Table.INFINITE); + } + protected native double nativeSumDouble(long nativeQueryPtr, long columnIndex, long start, long end, long limit); + + + public double maximumDouble(long columnIndex, long start, long end){ + return nativeMaximumDouble(nativePtr, columnIndex, start, end, Table.INFINITE); + } + public double maximumDouble(long columnIndex){ + return nativeMaximumDouble(nativePtr, columnIndex, 0, Table.INFINITE, Table.INFINITE); + } + protected native double nativeMaximumDouble(long nativeQueryPtr, long columnIndex, long start, long end, long limit); + + + public double minimumDouble(long columnIndex, long start, long end){ + return nativeMinimumDouble(nativePtr, columnIndex, start, end, Table.INFINITE); + } + public double minimumDouble(long columnIndex){ + return nativeMinimumDouble(nativePtr, columnIndex, 0, Table.INFINITE, Table.INFINITE); + } + protected native double nativeMinimumDouble(long nativeQueryPtr, long columnIndex, long start, long end, long limit); + + public double averageDouble(long columnIndex, long start, long end){ + return nativeAverageDouble(nativePtr, columnIndex, start, end, Table.INFINITE); + } + public double averageDouble(long columnIndex){ + return nativeAverageDouble(nativePtr, columnIndex, 0, Table.INFINITE, Table.INFINITE); + } + protected native double nativeAverageDouble(long nativeQueryPtr, long columnIndex, long start, long end, long limit); + + // count + + public long count(long start, long end){ + return nativeCount(nativePtr, start, end, Table.INFINITE); + } + public long count(){ + return nativeCount(nativePtr, 0, Table.INFINITE, Table.INFINITE); + } protected native long nativeCount(long nativeQueryPtr, long start, long end, long limit); // Deletion. public long remove(long start, long end){ if (immutable) throwImmutable(); - return nativeRemove(nativePtr, start, end, TableBase.INFINITE); + return nativeRemove(nativePtr, start, end, Table.INFINITE); } public long remove(){ if (immutable) throwImmutable(); - return nativeRemove(nativePtr, 0, TableBase.INFINITE, TableBase.INFINITE); + return nativeRemove(nativePtr, 0, Table.INFINITE, Table.INFINITE); } protected native long nativeRemove(long nativeQueryPtr, long start, long end, long limit); @@ -298,12 +509,12 @@ public String getErrorCode(){ protected native String nativeGetErrorCode(long nativePtr); - public TableViewBase findAllMulti(long start, long end){ - return new TableViewBase(nativeFindAllMulti(nativePtr, start, end), immutable); + public TableView findAllMulti(long start, long end){ + return new TableView(nativeFindAllMulti(nativePtr, start, end), immutable); } - public TableViewBase findAllMulti(){ - return new TableViewBase(nativeFindAllMulti(nativePtr, 0, TableBase.INFINITE), immutable); + public TableView findAllMulti(){ + return new TableView(nativeFindAllMulti(nativePtr, 0, Table.INFINITE), immutable); } protected native long nativeFindAllMulti(long nativeQueryPtr, long start, long end); diff --git a/tightdb-java-core/src/main/java/com/tightdb/TableViewBase.java b/tightdb-java-core/src/main/java/com/tightdb/TableView.java similarity index 69% rename from tightdb-java-core/src/main/java/com/tightdb/TableViewBase.java rename to tightdb-java-core/src/main/java/com/tightdb/TableView.java index f796abac92..34142b2583 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/TableViewBase.java +++ b/tightdb-java-core/src/main/java/com/tightdb/TableView.java @@ -24,7 +24,7 @@ * tableview. For that purpose we will first define the spec of an employee * entity * - * @Table + * @DefineTable * public class employee { * String name; * long age; @@ -45,7 +45,7 @@ * The generated class will have more specialized method to do operations on TableView. * */ -public class TableViewBase implements TableOrViewBase { +public class TableView implements TableOrView { /** * Creates a TableViewBase with a Java Object Table and a already created @@ -55,7 +55,7 @@ public class TableViewBase implements TableOrViewBase { * @param table The table. * @param nativePtr pointer to table. */ - protected TableViewBase(long nativePtr, boolean immutable){ + protected TableView(long nativePtr, boolean immutable){ this.immutable = immutable; this.tableView = null; this.nativePtr = nativePtr; @@ -69,7 +69,7 @@ protected TableViewBase(long nativePtr, boolean immutable){ * @param tableView A table view. * @param nativePtr pointer to table. */ - protected TableViewBase(TableViewBase tableView, long nativePtr, boolean immutable){ + protected TableView(TableView tableView, long nativePtr, boolean immutable){ this.immutable = immutable; this.tableView = tableView; this.nativePtr = nativePtr; @@ -121,6 +121,32 @@ public boolean getBoolean(long columnIndex, long rowIndex){ protected native boolean nativeGetBoolean(long nativeViewPtr, long columnIndex, long rowIndex); + /** + * Get the value of the particular (float) cell. + * + * @param columnIndex 0 based index value of the cell column. + * @param rowIndex 0 based index of the row. + * @return value of the particular cell. + */ + public float getFloat(long columnIndex, long rowIndex){ + return nativeGetFloat(nativePtr, columnIndex, rowIndex); + } + + protected native float nativeGetFloat(long nativeViewPtr, long columnIndex, long rowIndex); + + /** + * Get the value of the particular (double) cell. + * + * @param columnIndex 0 based index value of the cell column. + * @param rowIndex 0 based index of the row. + * @return value of the particular cell. + */ + public double getDouble(long columnIndex, long rowIndex){ + return nativeGetDouble(nativePtr, columnIndex, rowIndex); + } + + protected native double nativeGetDouble(long nativeViewPtr, long columnIndex, long rowIndex); + /** * Get the value of the particular (date) cell. * @@ -180,8 +206,8 @@ public Mixed getMixed(long columnIndex, long rowIndex){ protected native Mixed nativeGetMixed(long nativeViewPtr, long columnIndex, long rowIndex); - public TableBase getSubTable(long columnIndex, long rowIndex){ - return new TableBase(this, nativeGetSubTable(nativePtr, columnIndex, rowIndex), immutable); + public Table getSubTable(long columnIndex, long rowIndex){ + return new Table(this, nativeGetSubTable(nativePtr, columnIndex, rowIndex), immutable); } protected native long nativeGetSubTable(long nativeViewPtr, long columnIndex, long rowIndex); @@ -230,6 +256,34 @@ public void setBoolean(long columnIndex, long rowIndex, boolean value){ protected native void nativeSetBoolean(long nativeViewPtr, long columnIndex, long rowIndex, boolean value); + /** + * Sets the value for a particular (float) cell. + * + * @param columnIndex column index of the cell + * @param rowIndex row index of the cell + * @param value + */ + public void setFloat(long columnIndex, long rowIndex, float value){ + if (immutable) throwImmutable(); + nativeSetFloat(nativePtr, columnIndex, rowIndex, value); + } + + protected native void nativeSetFloat(long nativeViewPtr, long columnIndex, long rowIndex, float value); + + /** + * Sets the value for a particular (double) cell. + * + * @param columnIndex column index of the cell + * @param rowIndex row index of the cell + * @param value + */ + public void setDouble(long columnIndex, long rowIndex, double value){ + if (immutable) throwImmutable(); + nativeSetDouble(nativePtr, columnIndex, rowIndex, value); + } + + protected native void nativeSetDouble(long nativeViewPtr, long columnIndex, long rowIndex, double value); + /** * Sets the value for a particular (date) cell. * @@ -350,6 +404,20 @@ public long findFirstBoolean(long columnIndex, boolean value) { protected native long nativeFindFirstBool(long nativePtr, long columnIndex, boolean value); + //!!!TODO: New + public long findFirstFloat(long columnIndex, float value) { + return nativeFindFirstFloat(nativePtr, columnIndex, value); + } + + protected native long nativeFindFirstFloat(long nativePtr, long columnIndex, float value); + + //!!!TODO: New + public long findFirstDouble(long columnIndex, double value) { + return nativeFindFirstDouble(nativePtr, columnIndex, value); + } + + protected native long nativeFindFirstDouble(long nativePtr, long columnIndex, double value); + //!!!TODO: New public long findFirstDate(long columnIndex, Date date) { return nativeFindFirstDate(nativePtr, columnIndex, date.getTime()/1000); @@ -366,38 +434,57 @@ public long findFirstString(long columnIndex, String value){ // Search for all matches - public TableViewBase findAllLong(long columnIndex, long value){ - return new TableViewBase(this, nativeFindAllInt(nativePtr, columnIndex, value), immutable); + public TableView findAllLong(long columnIndex, long value){ + return new TableView(this, nativeFindAllInt(nativePtr, columnIndex, value), immutable); } protected native long nativeFindAllInt(long nativePtr, long columnIndex, long value); //!!!TODO: New - public TableViewBase findAllBoolean(long columnIndex, boolean value) { - return new TableViewBase(this, nativeFindAllBool(nativePtr, columnIndex, value), immutable); + public TableView findAllBoolean(long columnIndex, boolean value) { + return new TableView(this, nativeFindAllBool(nativePtr, columnIndex, value), immutable); } protected native long nativeFindAllBool(long nativePtr, long columnIndex, boolean value); //!!!TODO: New - public TableViewBase findAllDate(long columnIndex, Date date) { - return new TableViewBase(this, nativeFindAllDate(nativePtr, columnIndex, date.getTime()/1000), immutable); + public TableView findAllFloat(long columnIndex, float value) { + return new TableView(this, nativeFindAllFloat(nativePtr, columnIndex, value), immutable); + } + + protected native long nativeFindAllFloat(long nativePtr, long columnIndex, float value); + + //!!!TODO: New + public TableView findAllDouble(long columnIndex, double value) { + return new TableView(this, nativeFindAllDouble(nativePtr, columnIndex, value), immutable); + } + + protected native long nativeFindAllDouble(long nativePtr, long columnIndex, double value); + + //!!!TODO: New + public TableView findAllDate(long columnIndex, Date date) { + return new TableView(this, nativeFindAllDate(nativePtr, columnIndex, date.getTime()/1000), immutable); } protected native long nativeFindAllDate(long nativePtr, long columnIndex, long dateTimeValue); - public TableViewBase findAllString(long columnIndex, String value){ - return new TableViewBase(this, nativeFindAllString(nativePtr, columnIndex, value), immutable); + public TableView findAllString(long columnIndex, String value){ + return new TableView(this, nativeFindAllString(nativePtr, columnIndex, value), immutable); } protected native long nativeFindAllString(long nativePtr, long columnIndex, String value); + + // + // Integer Aggregates + // + /** * Calculate the sum of the values in a particular column of this * tableview. * * Note: the type of the column marked by the columnIndex has to be of - * type ColumnType.ColumnTypeInt for obvious reason. + * type ColumnType.ColumnTypeInt. * * @param columnIndex column index * @return the sum of the values in the column @@ -443,6 +530,59 @@ public double average(long columnIndex) { } protected native double nativeAverage(long nativePtr, long columnIndex); + + + // Float aggregates + + public double sumFloat(long columnIndex){ + return nativeSumFloat(nativePtr, columnIndex); + } + protected native double nativeSumFloat(long nativeViewPtr, long columnIndex); + + public float maximumFloat(long columnIndex){ + return nativeMaximumFloat(nativePtr, columnIndex); + } + protected native float nativeMaximumFloat(long nativeViewPtr, long columnIndex); + + public float minimumFloat(long columnIndex){ + return nativeMinimumFloat(nativePtr, columnIndex); + } + + protected native float nativeMinimumFloat(long nativeViewPtr, long columnIndex); + + public double averageFloat(long columnIndex) { + return nativeAverageFloat(nativePtr, columnIndex); + } + + protected native double nativeAverageFloat(long nativePtr, long columnIndex); + + + // Double aggregates + + public double sumDouble(long columnIndex){ + return nativeSumDouble(nativePtr, columnIndex); + } + protected native double nativeSumDouble(long nativeViewPtr, long columnIndex); + + public double maximumDouble(long columnIndex){ + return nativeMaximumDouble(nativePtr, columnIndex); + } + protected native double nativeMaximumDouble(long nativeViewPtr, long columnIndex); + + public double minimumDouble(long columnIndex){ + return nativeMinimumDouble(nativePtr, columnIndex); + } + + protected native double nativeMinimumDouble(long nativeViewPtr, long columnIndex); + + public double averageDouble(long columnIndex) { + return nativeAverageDouble(nativePtr, columnIndex); + } + + protected native double nativeAverageDouble(long nativePtr, long columnIndex); + + + // Sorting enum Order { ascending, descending }; @@ -459,7 +599,7 @@ public void sort(long columnIndex) { protected native void nativeSort(long nativeTableViewPtr, long columnIndex, boolean ascending); - protected native long createNativeTableView(TableBase table, long nativeTablePtr); + protected native long createNativeTableView(Table table, long nativeTablePtr); public void finalize(){ close(); @@ -487,5 +627,5 @@ private void throwImmutable() protected long nativePtr; protected boolean immutable = false; - protected TableViewBase tableView; + protected TableView tableView; } diff --git a/tightdb-java-core/src/main/java/com/tightdb/internal/util.java b/tightdb-java-core/src/main/java/com/tightdb/internal/util.java index d5b58179c3..92de377eba 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/internal/util.java +++ b/tightdb-java-core/src/main/java/com/tightdb/internal/util.java @@ -2,11 +2,11 @@ import java.util.Scanner; -import com.tightdb.lib.TightDB; +import com.tightdb.typed.TightDB; public class util { - public static final long REQUIRED_JNI_VERSION = 15; + public static final long REQUIRED_JNI_VERSION = 16; static { TightDB.loadLibrary(); diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/AbstractColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/AbstractColumn.java similarity index 73% rename from tightdb-java-core/src/main/java/com/tightdb/lib/AbstractColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/AbstractColumn.java index 91ec5ca1a5..449cb3e27d 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/AbstractColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/AbstractColumn.java @@ -1,9 +1,9 @@ -package com.tightdb.lib; +package com.tightdb.typed; -import com.tightdb.TableBase; -import com.tightdb.TableOrViewBase; +import com.tightdb.Table; +import com.tightdb.TableOrView; import com.tightdb.TableQuery; -import com.tightdb.TableViewBase; +import com.tightdb.TableView; public abstract class AbstractColumn { @@ -12,13 +12,13 @@ public abstract class AbstractColumn { protected final String name; protected final int columnIndex; protected final TableQuery query; - protected final TableOrViewBase tableOrView; + protected final TableOrView tableOrView; public AbstractColumn(EntityTypes types, AbstractCursor cursor, int index, String name) { this(types, cursor.tableOrView, cursor, index, name); } - public AbstractColumn(EntityTypes types, TableOrViewBase tableOrView, AbstractCursor cursor, int index, String name) { + public AbstractColumn(EntityTypes types, TableOrView tableOrView, AbstractCursor cursor, int index, String name) { this.types = types; this.tableOrView = tableOrView; this.query = null; @@ -27,7 +27,7 @@ public AbstractColumn(EntityTypes types, TableOrViewBase this.name = name; } - public AbstractColumn(EntityTypes types, TableOrViewBase tableOrView, TableQuery query, int index, String name) { + public AbstractColumn(EntityTypes types, TableOrView tableOrView, TableQuery query, int index, String name) { this.types = types; this.tableOrView = tableOrView; this.query = query; @@ -61,22 +61,22 @@ public String getReadableValue() { } } - protected TableBase tableOrNull() { - if (tableOrView instanceof TableBase) { - return (TableBase) tableOrView; + protected Table tableOrNull() { + if (tableOrView instanceof Table) { + return (Table) tableOrView; } else { throw new IllegalStateException("Cannot construct a query from a view!"); } } protected TableQuery getQuery() { - TableBase table = tableOrNull(); + Table table = tableOrNull(); return query != null ? query : table.where(); } protected Query query(TableQuery tableQuery) { try { - return types.getQueryClass().getConstructor(TableBase.class, TableQuery.class).newInstance(tableOrNull(), tableQuery); + return types.getQueryClass().getConstructor(Table.class, TableQuery.class).newInstance(tableOrNull(), tableQuery); } catch (Exception e) { throw new RuntimeException("Cannot create a query!", e); } @@ -86,7 +86,7 @@ protected Cursor cursor(long position) { return (position >= 0 && position < tableOrView.size()) ? AbstractCursor.createCursor(types.getCursorClass(), tableOrView, position) : null; } - protected View view(TableViewBase viewBase) { + protected View view(TableView viewBase) { return AbstractView.createView(types.getViewClass(), viewBase); } diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/AbstractCursor.java b/tightdb-java-core/src/main/java/com/tightdb/typed/AbstractCursor.java similarity index 83% rename from tightdb-java-core/src/main/java/com/tightdb/lib/AbstractCursor.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/AbstractCursor.java index dc030e8d8f..0ffb2e862b 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/AbstractCursor.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/AbstractCursor.java @@ -1,15 +1,15 @@ -package com.tightdb.lib; +package com.tightdb.typed; -import com.tightdb.TableOrViewBase; +import com.tightdb.TableOrView; public abstract class AbstractCursor { protected final long position; protected final EntityTypes types; - protected final TableOrViewBase tableOrView; + protected final TableOrView tableOrView; public AbstractCursor(EntityTypes types, - TableOrViewBase tableOrView, long position) { + TableOrView tableOrView, long position) { this.types = types; this.tableOrView = tableOrView; this.position = position; @@ -76,9 +76,9 @@ public String toString() { } protected static C createCursor(Class cursorClass, - TableOrViewBase targetTableOrView, long position) { + TableOrView targetTableOrView, long position) { try { - return cursorClass.getDeclaredConstructor(TableOrViewBase.class, + return cursorClass.getDeclaredConstructor(TableOrView.class, long.class).newInstance(targetTableOrView, position); } catch (Exception e) { throw new RuntimeException("Failed to instantiate a cursor!", e); diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/AbstractQuery.java b/tightdb-java-core/src/main/java/com/tightdb/typed/AbstractQuery.java similarity index 78% rename from tightdb-java-core/src/main/java/com/tightdb/lib/AbstractQuery.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/AbstractQuery.java index d1f2fd75d5..ce6d39cc9d 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/AbstractQuery.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/AbstractQuery.java @@ -1,19 +1,19 @@ -package com.tightdb.lib; +package com.tightdb.typed; -import com.tightdb.TableBase; -import com.tightdb.TableOrViewBase; +import com.tightdb.Table; +import com.tightdb.TableOrView; import com.tightdb.TableQuery; -import com.tightdb.TableViewBase; +import com.tightdb.TableView; public abstract class AbstractQuery> { private Long currPos = null; private final TableQuery query; - private final TableBase table; // TODO ??? needed? + private final Table table; // TODO ??? needed? private final EntityTypes types; - public AbstractQuery(EntityTypes types, TableBase table, TableQuery query) { + public AbstractQuery(EntityTypes types, Table table, TableQuery query) { this.types = types; this.table = table; this.query = query; @@ -64,7 +64,7 @@ public Cursor findNext() { public Cursor findFirst() { // TODO: needed - TableViewBase viewBase = query.findAll(0, TableBase.INFINITE, 1); + TableView viewBase = query.findAll(0, Table.INFINITE, 1); if (viewBase.size() > 0) { return cursor(viewBase, 0); } else { @@ -74,7 +74,7 @@ public Cursor findFirst() { public Cursor findLast() { // TODO: find more efficient way to search - TableViewBase viewBase = query.findAll(); + TableView viewBase = query.findAll(); long count = viewBase.size(); if (count > 0) { return cursor(viewBase, count - 1); @@ -136,17 +136,17 @@ public String toString() { return getClass().getSimpleName(); } - protected View view(TableViewBase viewBase) { + protected View view(TableView viewBase) { return AbstractView.createView(types.getViewClass(), viewBase); } - protected Cursor cursor(TableOrViewBase tableOrView, long position) { + protected Cursor cursor(TableOrView tableOrView, long position) { return AbstractCursor.createCursor(types.getCursorClass(), tableOrView, position); } - protected static Q createQuery(Class queryClass, TableBase tableBase, TableQuery tableQuery) { + protected static Q createQuery(Class queryClass, Table tableBase, TableQuery tableQuery) { try { - return queryClass.getConstructor(TableBase.class, TableQuery.class).newInstance(tableBase, tableQuery); + return queryClass.getConstructor(Table.class, TableQuery.class).newInstance(tableBase, tableQuery); } catch (Exception e) { throw new RuntimeException("Cannot create a query!", e); } diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/AbstractSubtable.java b/tightdb-java-core/src/main/java/com/tightdb/typed/AbstractSubtable.java similarity index 54% rename from tightdb-java-core/src/main/java/com/tightdb/lib/AbstractSubtable.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/AbstractSubtable.java index dc64467570..887637a7dd 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/AbstractSubtable.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/AbstractSubtable.java @@ -1,16 +1,16 @@ -package com.tightdb.lib; +package com.tightdb.typed; -import com.tightdb.TableBase; +import com.tightdb.Table; public abstract class AbstractSubtable extends AbstractTable { - public AbstractSubtable(EntityTypes types, TableBase subtable) { + public AbstractSubtable(EntityTypes types, Table subtable) { super(types, subtable); } - public static S createSubtable(Class subtableClass, TableBase subtableBase) { + protected static S createSubtable(Class subtableClass, Table subtableBase) { try { - S subtable = subtableClass.getConstructor(TableBase.class).newInstance(subtableBase); + S subtable = subtableClass.getConstructor(Table.class).newInstance(subtableBase); return subtable; } catch (Exception e) { throw new RuntimeException("Cannot create subtable instance!", e); diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/AbstractTable.java b/tightdb-java-core/src/main/java/com/tightdb/typed/AbstractTable.java similarity index 83% rename from tightdb-java-core/src/main/java/com/tightdb/lib/AbstractTable.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/AbstractTable.java index 9ee0727fec..5dfc633e01 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/AbstractTable.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/AbstractTable.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; import java.nio.ByteBuffer; import java.util.Date; @@ -6,7 +6,7 @@ import com.tightdb.ColumnType; import com.tightdb.Group; import com.tightdb.Mixed; -import com.tightdb.TableBase; +import com.tightdb.Table; import com.tightdb.TableSpec; public abstract class AbstractTable extends AbstractTableOrView { @@ -15,10 +15,10 @@ public abstract class AbstractTable extends AbstractTableOr TightDB.loadLibrary(); } - protected final TableBase table; + protected final Table table; public AbstractTable(EntityTypes types) { - this(types, new TableBase()); + this(types, new Table()); } public AbstractTable(EntityTypes types, Group group) { @@ -26,7 +26,7 @@ public AbstractTable(EntityTypes types, Group group) { } @SuppressWarnings("unchecked") - protected AbstractTable(EntityTypes types, TableBase table) { + protected AbstractTable(EntityTypes types, Table table) { super(types, table); this.table = table; if (table != null && table.getTableSpec().getColumnCount() <= 0) { @@ -93,6 +93,14 @@ protected static void addLongColumn(TableSpec spec, String name) { spec.addColumn(ColumnType.ColumnTypeInt, name); } + protected static void addFloatColumn(TableSpec spec, String name) { + spec.addColumn(ColumnType.ColumnTypeFloat, name); + } + + protected static void addDoubleColumn(TableSpec spec, String name) { + spec.addColumn(ColumnType.ColumnTypeDouble, name); + } + protected static void addStringColumn(TableSpec spec, String name) { spec.addColumn(ColumnType.ColumnTypeString, name); } @@ -131,6 +139,14 @@ protected void insertLong(long columnIndex, long rowIndex, long value) { table.insertLong(columnIndex, rowIndex, value); } + protected void insertFloat(long columnIndex, long rowIndex, float value) { + table.insertFloat(columnIndex, rowIndex, value); + } + + protected void insertDouble(long columnIndex, long rowIndex, double value) { + table.insertDouble(columnIndex, rowIndex, value); + } + protected void insertString(long columnIndex, long rowIndex, String value) { table.insertString(columnIndex, rowIndex, value); } @@ -159,8 +175,8 @@ protected void insertMixed(long columnIndex, long rowIndex, Object value) { table.insertMixed(columnIndex, rowIndex, mixed); } - protected void insertTable(long columnIndex, long rowIndex) { - table.insertSubTable(columnIndex, rowIndex); + protected void insertTable(long columnIndex, long rowIndex, Object[][] values) { + table.insertSubTable(columnIndex, rowIndex, values); } protected void insertDone() { diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/AbstractTableOrView.java b/tightdb-java-core/src/main/java/com/tightdb/typed/AbstractTableOrView.java similarity index 85% rename from tightdb-java-core/src/main/java/com/tightdb/lib/AbstractTableOrView.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/AbstractTableOrView.java index e1de481d9a..f1832197ec 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/AbstractTableOrView.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/AbstractTableOrView.java @@ -1,15 +1,15 @@ -package com.tightdb.lib; +package com.tightdb.typed; import java.util.Iterator; -import com.tightdb.TableOrViewBase; +import com.tightdb.TableOrView; public abstract class AbstractTableOrView implements Iterable { protected final EntityTypes types; - protected final TableOrViewBase tableOrView; + protected final TableOrView tableOrView; - public AbstractTableOrView(EntityTypes types, TableOrViewBase tableOrView) { + public AbstractTableOrView(EntityTypes types, TableOrView tableOrView) { this.types = types; this.tableOrView = tableOrView; } diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/AbstractView.java b/tightdb-java-core/src/main/java/com/tightdb/typed/AbstractView.java similarity index 62% rename from tightdb-java-core/src/main/java/com/tightdb/lib/AbstractView.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/AbstractView.java index 11a7b45893..f6f284dbcc 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/AbstractView.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/AbstractView.java @@ -1,12 +1,12 @@ -package com.tightdb.lib; +package com.tightdb.typed; -import com.tightdb.TableViewBase; +import com.tightdb.TableView; public abstract class AbstractView extends AbstractTableOrView { - protected final TableViewBase viewBase; + protected final TableView viewBase; - public AbstractView(EntityTypes types, TableViewBase viewBase) { + public AbstractView(EntityTypes types, TableView viewBase) { super(types, viewBase); this.viewBase = viewBase; } @@ -21,9 +21,9 @@ public String toString() { return types.getViewClass().getSimpleName() + " {" + size() + " records}"; } - public static V createView(Class viewClass, TableViewBase viewBase) { + protected static V createView(Class viewClass, TableView viewBase) { try { - return viewClass.getConstructor(TableViewBase.class).newInstance(viewBase); + return viewClass.getConstructor(TableView.class).newInstance(viewBase); } catch (Exception e) { throw new RuntimeException("Cannot create a view!", e); } diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/BinaryCursorColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/BinaryCursorColumn.java similarity index 92% rename from tightdb-java-core/src/main/java/com/tightdb/lib/BinaryCursorColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/BinaryCursorColumn.java index caca546c8e..e8835c32aa 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/BinaryCursorColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/BinaryCursorColumn.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; import java.nio.ByteBuffer; diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/BinaryQueryColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/BinaryQueryColumn.java similarity index 65% rename from tightdb-java-core/src/main/java/com/tightdb/lib/BinaryQueryColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/BinaryQueryColumn.java index f937959f3b..853610edee 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/BinaryQueryColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/BinaryQueryColumn.java @@ -1,13 +1,13 @@ -package com.tightdb.lib; +package com.tightdb.typed; import java.nio.ByteBuffer; -import com.tightdb.TableOrViewBase; +import com.tightdb.TableOrView; import com.tightdb.TableQuery; public class BinaryQueryColumn extends AbstractColumn { - public BinaryQueryColumn(EntityTypes types, TableOrViewBase tableOrView, TableQuery query, int index, String name) { + public BinaryQueryColumn(EntityTypes types, TableOrView tableOrView, TableQuery query, int index, String name) { super(types, tableOrView, query, index, name); } diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/BinaryTableOrViewColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/BinaryTableOrViewColumn.java similarity index 78% rename from tightdb-java-core/src/main/java/com/tightdb/lib/BinaryTableOrViewColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/BinaryTableOrViewColumn.java index 8bfc07b3de..bfb7ae298e 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/BinaryTableOrViewColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/BinaryTableOrViewColumn.java @@ -1,17 +1,17 @@ -package com.tightdb.lib; +package com.tightdb.typed; import java.nio.ByteBuffer; -import com.tightdb.TableOrViewBase; +import com.tightdb.TableOrView; import com.tightdb.TableQuery; public class BinaryTableOrViewColumn extends BinaryQueryColumn implements TableOrViewColumn { - public BinaryTableOrViewColumn(EntityTypes types, TableOrViewBase tableOrView, int index, String name) { + public BinaryTableOrViewColumn(EntityTypes types, TableOrView tableOrView, int index, String name) { this(types, tableOrView, null, index, name); } - public BinaryTableOrViewColumn(EntityTypes types, TableOrViewBase tableOrView, TableQuery query, int index, String name) { + public BinaryTableOrViewColumn(EntityTypes types, TableOrView tableOrView, TableQuery query, int index, String name) { super(types, tableOrView, query, index, name); } diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/BooleanCursorColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/BooleanCursorColumn.java similarity index 91% rename from tightdb-java-core/src/main/java/com/tightdb/lib/BooleanCursorColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/BooleanCursorColumn.java index a2d3f8acc2..f6cd2fa846 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/BooleanCursorColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/BooleanCursorColumn.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; public class BooleanCursorColumn extends AbstractColumn { diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/BooleanQueryColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/BooleanQueryColumn.java similarity index 79% rename from tightdb-java-core/src/main/java/com/tightdb/lib/BooleanQueryColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/BooleanQueryColumn.java index 0a3a5263bd..873472120d 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/BooleanQueryColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/BooleanQueryColumn.java @@ -1,11 +1,11 @@ -package com.tightdb.lib; +package com.tightdb.typed; -import com.tightdb.TableOrViewBase; +import com.tightdb.TableOrView; import com.tightdb.TableQuery; public class BooleanQueryColumn extends AbstractColumn { - public BooleanQueryColumn(EntityTypes types, TableOrViewBase tableOrView, TableQuery query, int index, String name) { + public BooleanQueryColumn(EntityTypes types, TableOrView tableOrView, TableQuery query, int index, String name) { super(types, tableOrView, query, index, name); } diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/BooleanTableOrViewColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/BooleanTableOrViewColumn.java similarity index 80% rename from tightdb-java-core/src/main/java/com/tightdb/lib/BooleanTableOrViewColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/BooleanTableOrViewColumn.java index dd748d75f3..e173de21dc 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/BooleanTableOrViewColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/BooleanTableOrViewColumn.java @@ -1,15 +1,15 @@ -package com.tightdb.lib; +package com.tightdb.typed; -import com.tightdb.TableOrViewBase; +import com.tightdb.TableOrView; import com.tightdb.TableQuery; public class BooleanTableOrViewColumn extends BooleanQueryColumn implements TableOrViewColumn { - public BooleanTableOrViewColumn(EntityTypes types, TableOrViewBase tableOrView, int index, String name) { + public BooleanTableOrViewColumn(EntityTypes types, TableOrView tableOrView, int index, String name) { this(types, tableOrView, null, index, name); } - public BooleanTableOrViewColumn(EntityTypes types, TableOrViewBase tableOrView, TableQuery query, int index, String name) { + public BooleanTableOrViewColumn(EntityTypes types, TableOrView tableOrView, TableQuery query, int index, String name) { super(types, tableOrView, query, index, name); } diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/DateCursorColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/DateCursorColumn.java similarity index 93% rename from tightdb-java-core/src/main/java/com/tightdb/lib/DateCursorColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/DateCursorColumn.java index cc92349709..16d615d439 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/DateCursorColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/DateCursorColumn.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; import java.text.DateFormat; import java.util.Date; diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/DateQueryColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/DateQueryColumn.java similarity index 86% rename from tightdb-java-core/src/main/java/com/tightdb/lib/DateQueryColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/DateQueryColumn.java index e535397a80..a96b18be9a 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/DateQueryColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/DateQueryColumn.java @@ -1,13 +1,13 @@ -package com.tightdb.lib; +package com.tightdb.typed; import java.util.Date; -import com.tightdb.TableOrViewBase; +import com.tightdb.TableOrView; import com.tightdb.TableQuery; public class DateQueryColumn extends AbstractColumn { - public DateQueryColumn(EntityTypes types, TableOrViewBase tableOrView, TableQuery query, int index, String name) { + public DateQueryColumn(EntityTypes types, TableOrView tableOrView, TableQuery query, int index, String name) { super(types, tableOrView, query, index, name); } // FIXME: Add methods diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/DateTableOrViewColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/DateTableOrViewColumn.java similarity index 80% rename from tightdb-java-core/src/main/java/com/tightdb/lib/DateTableOrViewColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/DateTableOrViewColumn.java index 716ec317d4..adaaaa09cc 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/DateTableOrViewColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/DateTableOrViewColumn.java @@ -1,17 +1,17 @@ -package com.tightdb.lib; +package com.tightdb.typed; import java.util.Date; -import com.tightdb.TableOrViewBase; +import com.tightdb.TableOrView; import com.tightdb.TableQuery; public class DateTableOrViewColumn extends DateQueryColumn implements TableOrViewColumn { - public DateTableOrViewColumn(EntityTypes types, TableOrViewBase tableOrView, int index, String name) { + public DateTableOrViewColumn(EntityTypes types, TableOrView tableOrView, int index, String name) { this(types, tableOrView, null, index, name); } - public DateTableOrViewColumn(EntityTypes types, TableOrViewBase tableOrView, TableQuery query, int index, String name) { + public DateTableOrViewColumn(EntityTypes types, TableOrView tableOrView, TableQuery query, int index, String name) { super(types, tableOrView, query, index, name); } diff --git a/tightdb-java-core/src/main/java/com/tightdb/typed/DoubleCursorColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/DoubleCursorColumn.java new file mode 100644 index 0000000000..51e3f3512d --- /dev/null +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/DoubleCursorColumn.java @@ -0,0 +1,24 @@ +package com.tightdb.typed; + +public class DoubleCursorColumn extends AbstractColumn { + + public DoubleCursorColumn(EntityTypes types, AbstractCursor cursor, int index, + String name) { + super(types, cursor, index, name); + } + + @Override + public Double get() { + return cursor.tableOrView.getDouble(columnIndex, cursor.getPosition()); + } + + @Override + public void set(Double value) { + cursor.tableOrView.setDouble(columnIndex, cursor.getPosition(), value); + } + + public void set(double value) { + set(Double.valueOf(value)); + } + +} diff --git a/tightdb-java-core/src/main/java/com/tightdb/typed/DoubleQueryColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/DoubleQueryColumn.java new file mode 100644 index 0000000000..bef1efa6d6 --- /dev/null +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/DoubleQueryColumn.java @@ -0,0 +1,97 @@ +package com.tightdb.typed; + +import com.tightdb.TableOrView; +import com.tightdb.TableQuery; + +public class DoubleQueryColumn extends AbstractColumn { + + public DoubleQueryColumn(EntityTypes types, TableOrView tableOrView, TableQuery query, + int index, String name) { + super(types, tableOrView, query, index, name); + } + + public Query equal(double value) { + return query(getQuery().equal(columnIndex, value)); + } + + public Query eq(double value) { + return query(getQuery().eq(columnIndex, value)); + } + + public Query notEqual(double value) { + return query(getQuery().notEqual(columnIndex, value)); + } + + public Query neq(double value) { + return query(getQuery().neq(columnIndex, value)); + } + + public Query greaterThan(double value) { + return query(getQuery().greaterThan(columnIndex, value)); + } + + public Query gt(double value) { + return query(getQuery().gt(columnIndex, value)); + } + + public Query greaterThanOrEqual(double value) { + return query(getQuery().greaterThanOrEqual(columnIndex, value)); + } + + public Query gte(double value) { + return query(getQuery().gte(columnIndex, value)); + } + + public Query lessThan(double value) { + return query(getQuery().lessThan(columnIndex, value)); + } + + public Query lt(double value) { + return query(getQuery().lt(columnIndex, value)); + } + + public Query lessThanOrEqual(double value) { + return query(getQuery().lessThanOrEqual(columnIndex, value)); + } + + public Query lte(double value) { + return query(getQuery().lte(columnIndex, value)); + } + + public Query between(double from, double to) { + return query(getQuery().between(columnIndex, from, to)); + } + + public double average() { + return getQuery().averageDouble(columnIndex); + } + + public double average(long start, long end) { + return getQuery().averageDouble(columnIndex, start, end); + } + + public double sum() { + return getQuery().sumDouble(columnIndex); + } + + public double sum(long start, long end) { + return getQuery().sumDouble(columnIndex, start, end); + } + + public double maximum() { + return getQuery().maximumDouble(columnIndex); + } + + public double maximum(long start, long end) { + return getQuery().maximumDouble(columnIndex, start, end); + } + + public double minimum() { + return getQuery().minimumDouble(columnIndex); + } + + public double minimum(long start, long end) { + return getQuery().minimumDouble(columnIndex, start, end); + } + +} diff --git a/tightdb-java-core/src/main/java/com/tightdb/typed/DoubleTableOrViewColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/DoubleTableOrViewColumn.java new file mode 100644 index 0000000000..b580415fd2 --- /dev/null +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/DoubleTableOrViewColumn.java @@ -0,0 +1,79 @@ +package com.tightdb.typed; + +import com.tightdb.TableOrView; +import com.tightdb.TableQuery; + +public class DoubleTableOrViewColumn extends DoubleQueryColumn implements + TableOrViewColumn { + + public DoubleTableOrViewColumn(EntityTypes types, TableOrView tableOrView, int index, + String name) { + this(types, tableOrView, null, index, name); + } + + public DoubleTableOrViewColumn(EntityTypes types, TableOrView tableOrView, + TableQuery query, int index, String name) { + super(types, tableOrView, query, index, name); + } + + @Override + public double sum() { + return tableOrView.sumDouble(columnIndex); + } + + @Override + public double maximum() { + return tableOrView.maximumDouble(columnIndex); + } + + @Override + public double minimum() { + return tableOrView.minimumDouble(columnIndex); + } + + @Override + public double average() { + return tableOrView.averageDouble(columnIndex); + } + + /* + * public void setIndex() { tableOrView.setIndex(columnIndex); } + * + * public boolean hasIndex() { return tableOrView.hasIndex(columnIndex); } + */ + + @Override + public Double[] getAll() { + long count = tableOrView.size(); + Double[] values = new Double[(int) count]; + for (int i = 0; i < count; i++) { + values[i] = tableOrView.getDouble(columnIndex, i); + } + return values; + } + + @Override + public void setAll(Double value) { + long count = tableOrView.size(); + for (int i = 0; i < count; i++) { + tableOrView.setDouble(columnIndex, i, value); + } + } + + public void setAll(double value) { + setAll(new Double(value)); + } + + // public void addDouble(double value) { + // tableOrView.addDouble(columnIndex, value); + // } + + public Cursor findFirst(long value) { + return cursor(tableOrView.findFirstDouble(columnIndex, value)); + } + + public View findAll(long value) { + return view(tableOrView.findAllDouble(columnIndex, value)); + } + +} diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/EntityTypes.java b/tightdb-java-core/src/main/java/com/tightdb/typed/EntityTypes.java similarity index 92% rename from tightdb-java-core/src/main/java/com/tightdb/lib/EntityTypes.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/EntityTypes.java index 6608163a22..1a44fffb34 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/EntityTypes.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/EntityTypes.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; public class EntityTypes { diff --git a/tightdb-java-core/src/main/java/com/tightdb/typed/FloatCursorColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/FloatCursorColumn.java new file mode 100644 index 0000000000..f49ee79418 --- /dev/null +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/FloatCursorColumn.java @@ -0,0 +1,24 @@ +package com.tightdb.typed; + +public class FloatCursorColumn extends AbstractColumn { + + public FloatCursorColumn(EntityTypes types, AbstractCursor cursor, int index, + String name) { + super(types, cursor, index, name); + } + + @Override + public Float get() { + return cursor.tableOrView.getFloat(columnIndex, cursor.getPosition()); + } + + @Override + public void set(Float value) { + cursor.tableOrView.setFloat(columnIndex, cursor.getPosition(), value); + } + + public void set(float value) { + set(Float.valueOf(value)); + } + +} diff --git a/tightdb-java-core/src/main/java/com/tightdb/typed/FloatQueryColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/FloatQueryColumn.java new file mode 100644 index 0000000000..8633324c6b --- /dev/null +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/FloatQueryColumn.java @@ -0,0 +1,97 @@ +package com.tightdb.typed; + +import com.tightdb.TableOrView; +import com.tightdb.TableQuery; + +public class FloatQueryColumn extends AbstractColumn { + + public FloatQueryColumn(EntityTypes types, TableOrView tableOrView, TableQuery query, + int index, String name) { + super(types, tableOrView, query, index, name); + } + + public Query equal(float value) { + return query(getQuery().equal(columnIndex, value)); + } + + public Query eq(float value) { + return query(getQuery().eq(columnIndex, value)); + } + + public Query notEqual(float value) { + return query(getQuery().notEqual(columnIndex, value)); + } + + public Query neq(float value) { + return query(getQuery().neq(columnIndex, value)); + } + + public Query greaterThan(float value) { + return query(getQuery().greaterThan(columnIndex, value)); + } + + public Query gt(float value) { + return query(getQuery().gt(columnIndex, value)); + } + + public Query greaterThanOrEqual(float value) { + return query(getQuery().greaterThanOrEqual(columnIndex, value)); + } + + public Query gte(float value) { + return query(getQuery().gte(columnIndex, value)); + } + + public Query lessThan(float value) { + return query(getQuery().lessThan(columnIndex, value)); + } + + public Query lt(float value) { + return query(getQuery().lt(columnIndex, value)); + } + + public Query lessThanOrEqual(float value) { + return query(getQuery().lessThanOrEqual(columnIndex, value)); + } + + public Query lte(float value) { + return query(getQuery().lte(columnIndex, value)); + } + + public Query between(float from, float to) { + return query(getQuery().between(columnIndex, from, to)); + } + + public double average() { + return getQuery().averageFloat(columnIndex); + } + + public double average(long start, long end) { + return getQuery().averageFloat(columnIndex, start, end); + } + + public double sum() { + return getQuery().sumFloat(columnIndex); + } + + public double sum(long start, long end) { + return getQuery().sumFloat(columnIndex, start, end); + } + + public float maximum() { + return getQuery().maximumFloat(columnIndex); + } + + public float maximum(long start, long end) { + return getQuery().maximumFloat(columnIndex, start, end); + } + + public float minimum() { + return getQuery().minimumFloat(columnIndex); + } + + public float minimum(long start, long end) { + return getQuery().minimumFloat(columnIndex, start, end); + } + +} diff --git a/tightdb-java-core/src/main/java/com/tightdb/typed/FloatTableOrViewColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/FloatTableOrViewColumn.java new file mode 100644 index 0000000000..da492b4d19 --- /dev/null +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/FloatTableOrViewColumn.java @@ -0,0 +1,79 @@ +package com.tightdb.typed; + +import com.tightdb.TableOrView; +import com.tightdb.TableQuery; + +public class FloatTableOrViewColumn extends FloatQueryColumn implements + TableOrViewColumn { + + public FloatTableOrViewColumn(EntityTypes types, TableOrView tableOrView, int index, + String name) { + this(types, tableOrView, null, index, name); + } + + public FloatTableOrViewColumn(EntityTypes types, TableOrView tableOrView, TableQuery query, + int index, String name) { + super(types, tableOrView, query, index, name); + } + + @Override + public double sum() { + return tableOrView.sumFloat(columnIndex); + } + + @Override + public float maximum() { + return tableOrView.maximumFloat(columnIndex); + } + + @Override + public float minimum() { + return tableOrView.minimumFloat(columnIndex); + } + + @Override + public double average() { + return tableOrView.averageFloat(columnIndex); + } + + /* + * public void setIndex() { tableOrView.setIndex(columnIndex); } + * + * public boolean hasIndex() { return tableOrView.hasIndex(columnIndex); } + */ + + @Override + public Float[] getAll() { + long count = tableOrView.size(); + Float[] values = new Float[(int) count]; + for (int i = 0; i < count; i++) { + values[i] = tableOrView.getFloat(columnIndex, i); + } + return values; + } + + @Override + public void setAll(Float value) { + long count = tableOrView.size(); + for (int i = 0; i < count; i++) { + tableOrView.setFloat(columnIndex, i, value); + } + } + + public void setAll(float value) { + setAll(new Float(value)); + } + + // public void addFloat(float value) { + // tableOrView.addFloat(columnIndex, value); + // } + + public Cursor findFirst(long value) { + return cursor(tableOrView.findFirstFloat(columnIndex, value)); + } + + public View findAll(long value) { + return view(tableOrView.findAllFloat(columnIndex, value)); + } + +} diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/LongCursorColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/LongCursorColumn.java similarity index 91% rename from tightdb-java-core/src/main/java/com/tightdb/lib/LongCursorColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/LongCursorColumn.java index bd7f4dffc2..9f57f124b8 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/LongCursorColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/LongCursorColumn.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; public class LongCursorColumn extends AbstractColumn { diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/LongQueryColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/LongQueryColumn.java similarity index 90% rename from tightdb-java-core/src/main/java/com/tightdb/lib/LongQueryColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/LongQueryColumn.java index f456bbdacb..34919cf321 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/LongQueryColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/LongQueryColumn.java @@ -1,13 +1,13 @@ -package com.tightdb.lib; +package com.tightdb.typed; -import com.tightdb.TableOrViewBase; +import com.tightdb.TableOrView; import com.tightdb.TableQuery; public class LongQueryColumn extends AbstractColumn { public LongQueryColumn(EntityTypes types, - TableOrViewBase tableOrView, TableQuery query, int index, String name) { + TableOrView tableOrView, TableQuery query, int index, String name) { super(types, tableOrView, query, index, name); } diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/LongTableOrViewColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/LongTableOrViewColumn.java similarity index 86% rename from tightdb-java-core/src/main/java/com/tightdb/lib/LongTableOrViewColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/LongTableOrViewColumn.java index d32d2a9bdf..651b781f92 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/LongTableOrViewColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/LongTableOrViewColumn.java @@ -1,18 +1,18 @@ -package com.tightdb.lib; +package com.tightdb.typed; -import com.tightdb.TableOrViewBase; +import com.tightdb.TableOrView; import com.tightdb.TableQuery; public class LongTableOrViewColumn extends LongQueryColumn implements TableOrViewColumn { public LongTableOrViewColumn(EntityTypes types, - TableOrViewBase tableOrView, int index, String name) { + TableOrView tableOrView, int index, String name) { this(types, tableOrView, null, index, name); } public LongTableOrViewColumn(EntityTypes types, - TableOrViewBase tableOrView, TableQuery query, int index, String name) { + TableOrView tableOrView, TableQuery query, int index, String name) { super(types, tableOrView, query, index, name); } diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/MixedCursorColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/MixedCursorColumn.java similarity index 86% rename from tightdb-java-core/src/main/java/com/tightdb/lib/MixedCursorColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/MixedCursorColumn.java index e1628a72b0..dbe8ae3954 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/MixedCursorColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/MixedCursorColumn.java @@ -1,11 +1,11 @@ -package com.tightdb.lib; +package com.tightdb.typed; import java.nio.ByteBuffer; import java.util.Date; import com.tightdb.ColumnType; import com.tightdb.Mixed; -import com.tightdb.TableBase; +import com.tightdb.Table; import com.tightdb.TableSpec; public class MixedCursorColumn extends AbstractColumn { @@ -54,7 +54,7 @@ public void set(byte[] value) { public Tbl createSubtable(Class tableClass) { set(new Mixed(ColumnType.ColumnTypeTable)); - TableBase subtable = cursor.tableOrView.getSubTable(columnIndex, cursor.getPosition()); + Table subtable = cursor.tableOrView.getSubTable(columnIndex, cursor.getPosition()); return AbstractSubtable.createSubtable(tableClass, subtable); } @@ -63,7 +63,7 @@ public Tbl createSubtable(Class tableClass) { throw new IllegalArgumentException("Wrong subtable type!"); } - TableBase subtableBase = cursor.tableOrView.getSubTable(columnIndex, cursor.getPosition()); + Table subtableBase = cursor.tableOrView.getSubTable(columnIndex, cursor.getPosition()); return AbstractSubtable.createSubtable(tableClass, subtableBase); } @@ -75,7 +75,7 @@ public Tbl createSubtable(Class tableClass) { throw new IllegalArgumentException("The mixed value doesn't contain a sub-table!"); } - TableBase subtableBase = cursor.tableOrView.getSubTable(columnIndex, cursor.getPosition()); + Table subtableBase = cursor.tableOrView.getSubTable(columnIndex, cursor.getPosition()); TableSpec spec = subtableBase.getTableSpec(); // Build table schema diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/MixedQueryColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/MixedQueryColumn.java similarity index 65% rename from tightdb-java-core/src/main/java/com/tightdb/lib/MixedQueryColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/MixedQueryColumn.java index 796ad9b8a8..2f795b7ee0 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/MixedQueryColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/MixedQueryColumn.java @@ -1,12 +1,12 @@ -package com.tightdb.lib; +package com.tightdb.typed; import com.tightdb.Mixed; -import com.tightdb.TableOrViewBase; +import com.tightdb.TableOrView; import com.tightdb.TableQuery; public class MixedQueryColumn extends AbstractColumn { - public MixedQueryColumn(EntityTypes types, TableOrViewBase tableOrView, TableQuery query, int index, String name) { + public MixedQueryColumn(EntityTypes types, TableOrView tableOrView, TableQuery query, int index, String name) { super(types, tableOrView, query, index, name); } diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/MixedTableOrViewColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/MixedTableOrViewColumn.java similarity index 77% rename from tightdb-java-core/src/main/java/com/tightdb/lib/MixedTableOrViewColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/MixedTableOrViewColumn.java index 99ac8ce784..247aff8ba6 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/MixedTableOrViewColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/MixedTableOrViewColumn.java @@ -1,16 +1,16 @@ -package com.tightdb.lib; +package com.tightdb.typed; import com.tightdb.Mixed; -import com.tightdb.TableOrViewBase; +import com.tightdb.TableOrView; import com.tightdb.TableQuery; public class MixedTableOrViewColumn extends MixedQueryColumn implements TableOrViewColumn { - public MixedTableOrViewColumn(EntityTypes types, TableOrViewBase tableOrView, int index, String name) { + public MixedTableOrViewColumn(EntityTypes types, TableOrView tableOrView, int index, String name) { this(types, tableOrView, null, index, name); } - public MixedTableOrViewColumn(EntityTypes types, TableOrViewBase tableOrView, TableQuery query, int index, String name) { + public MixedTableOrViewColumn(EntityTypes types, TableOrView tableOrView, TableQuery query, int index, String name) { super(types, tableOrView, query, index, name); } diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/StringCursorColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/StringCursorColumn.java similarity index 91% rename from tightdb-java-core/src/main/java/com/tightdb/lib/StringCursorColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/StringCursorColumn.java index 34a06edec8..66abff3dcf 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/StringCursorColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/StringCursorColumn.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; public class StringCursorColumn extends AbstractColumn { diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/StringQueryColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/StringQueryColumn.java similarity index 90% rename from tightdb-java-core/src/main/java/com/tightdb/lib/StringQueryColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/StringQueryColumn.java index be94e5c3cf..71c83aa789 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/StringQueryColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/StringQueryColumn.java @@ -1,11 +1,11 @@ -package com.tightdb.lib; +package com.tightdb.typed; -import com.tightdb.TableOrViewBase; +import com.tightdb.TableOrView; import com.tightdb.TableQuery; public class StringQueryColumn extends AbstractColumn { - public StringQueryColumn(EntityTypes types, TableOrViewBase tableOrView, TableQuery query, int index, String name) { + public StringQueryColumn(EntityTypes types, TableOrView tableOrView, TableQuery query, int index, String name) { super(types, tableOrView, query, index, name); } diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/StringTableOrViewColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/StringTableOrViewColumn.java similarity index 79% rename from tightdb-java-core/src/main/java/com/tightdb/lib/StringTableOrViewColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/StringTableOrViewColumn.java index 38ba87bad3..9336b8eed0 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/StringTableOrViewColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/StringTableOrViewColumn.java @@ -1,15 +1,15 @@ -package com.tightdb.lib; +package com.tightdb.typed; -import com.tightdb.TableOrViewBase; +import com.tightdb.TableOrView; import com.tightdb.TableQuery; public class StringTableOrViewColumn extends StringQueryColumn { - public StringTableOrViewColumn(EntityTypes types, TableOrViewBase tableOrView, int index, String name) { + public StringTableOrViewColumn(EntityTypes types, TableOrView tableOrView, int index, String name) { this(types, tableOrView, null, index, name); } - public StringTableOrViewColumn(EntityTypes types, TableOrViewBase tableOrView, TableQuery query, int index, String name) { + public StringTableOrViewColumn(EntityTypes types, TableOrView tableOrView, TableQuery query, int index, String name) { super(types, tableOrView, query, index, name); } diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/TableCursorColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/TableCursorColumn.java similarity index 87% rename from tightdb-java-core/src/main/java/com/tightdb/lib/TableCursorColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/TableCursorColumn.java index 7c08cf64fd..c20034d08d 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/TableCursorColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/TableCursorColumn.java @@ -1,8 +1,8 @@ -package com.tightdb.lib; +package com.tightdb.typed; import java.util.Iterator; -import com.tightdb.TableBase; +import com.tightdb.Table; public class TableCursorColumn> extends AbstractColumn implements Iterable { @@ -17,7 +17,7 @@ public TableCursorColumn(EntityTypes types, AbstractCurs @Override public Subtable get() { - TableBase subTableBase = cursor.tableOrView.getSubTable(columnIndex, cursor.getPosition()); + Table subTableBase = cursor.tableOrView.getSubTable(columnIndex, cursor.getPosition()); return AbstractSubtable.createSubtable(subtableClass, subTableBase); } diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/TableOrViewColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/TableOrViewColumn.java similarity index 72% rename from tightdb-java-core/src/main/java/com/tightdb/lib/TableOrViewColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/TableOrViewColumn.java index c2933e03e6..54a7827047 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/TableOrViewColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/TableOrViewColumn.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; public interface TableOrViewColumn { diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/TableOrViewIterator.java b/tightdb-java-core/src/main/java/com/tightdb/typed/TableOrViewIterator.java similarity index 92% rename from tightdb-java-core/src/main/java/com/tightdb/lib/TableOrViewIterator.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/TableOrViewIterator.java index 2f6bf66e17..d3ebfcbca7 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/TableOrViewIterator.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/TableOrViewIterator.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; import java.util.Iterator; import java.util.NoSuchElementException; diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/TableQueryColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/TableQueryColumn.java similarity index 75% rename from tightdb-java-core/src/main/java/com/tightdb/lib/TableQueryColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/TableQueryColumn.java index 2a7be0e12c..af8b717d77 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/TableQueryColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/TableQueryColumn.java @@ -1,6 +1,6 @@ -package com.tightdb.lib; +package com.tightdb.typed; -import com.tightdb.TableOrViewBase; +import com.tightdb.TableOrView; import com.tightdb.TableQuery; public class TableQueryColumn extends AbstractColumn { @@ -8,7 +8,7 @@ public class TableQueryColumn extends AbstractCol protected Subtable subtable; protected final Class subtableClass; - public TableQueryColumn(EntityTypes types, TableOrViewBase tableOrView, TableQuery query, int index, String name, + public TableQueryColumn(EntityTypes types, TableOrView tableOrView, TableQuery query, int index, String name, Class subtableClass) { super(types, tableOrView, query, index, name); this.subtableClass = subtableClass; diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/TableTableOrViewColumn.java b/tightdb-java-core/src/main/java/com/tightdb/typed/TableTableOrViewColumn.java similarity index 68% rename from tightdb-java-core/src/main/java/com/tightdb/lib/TableTableOrViewColumn.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/TableTableOrViewColumn.java index a7beb24676..02396d4aa0 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/TableTableOrViewColumn.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/TableTableOrViewColumn.java @@ -1,18 +1,18 @@ -package com.tightdb.lib; +package com.tightdb.typed; import java.lang.reflect.Array; -import com.tightdb.TableBase; -import com.tightdb.TableOrViewBase; +import com.tightdb.Table; +import com.tightdb.TableOrView; import com.tightdb.TableQuery; public class TableTableOrViewColumn extends TableQueryColumn { - public TableTableOrViewColumn(EntityTypes types, TableOrViewBase tableOrView, int index, String name, Class subtableClass) { + public TableTableOrViewColumn(EntityTypes types, TableOrView tableOrView, int index, String name, Class subtableClass) { this(types, tableOrView, null, index, name, subtableClass); } - public TableTableOrViewColumn(EntityTypes types, TableOrViewBase tableOrView, TableQuery query, int index, String name, + public TableTableOrViewColumn(EntityTypes types, TableOrView tableOrView, TableQuery query, int index, String name, Class subtableClass) { super(types, tableOrView, query, index, name, subtableClass); } @@ -22,7 +22,7 @@ public Subtable[] getAll() { long count = tableOrView.size(); Subtable[] values = (Subtable[]) Array.newInstance(subtableClass, (int) count); for (int i = 0; i < count; i++) { - TableBase subTableBase = tableOrView.getSubTable(columnIndex, i); + Table subTableBase = tableOrView.getSubTable(columnIndex, i); values[i] = AbstractSubtable.createSubtable(subtableClass, subTableBase); } return values; diff --git a/tightdb-java-core/src/main/java/com/tightdb/lib/TightDB.java b/tightdb-java-core/src/main/java/com/tightdb/typed/TightDB.java similarity index 96% rename from tightdb-java-core/src/main/java/com/tightdb/lib/TightDB.java rename to tightdb-java-core/src/main/java/com/tightdb/typed/TightDB.java index c6bed07475..3353f4fed1 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/lib/TightDB.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/TightDB.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; diff --git a/tightdb-java-doc/src/main/java/com/tightdb/doc/GroupExamples.java b/tightdb-java-doc/src/main/java/com/tightdb/doc/GroupExamples.java index e0745aa7cf..2f1d04359b 100644 --- a/tightdb-java-doc/src/main/java/com/tightdb/doc/GroupExamples.java +++ b/tightdb-java-doc/src/main/java/com/tightdb/doc/GroupExamples.java @@ -5,7 +5,7 @@ import java.nio.ByteBuffer; import com.tightdb.Group; -import com.tightdb.TableBase; +import com.tightdb.Table; public class GroupExamples { @@ -20,7 +20,7 @@ public static void main(String[] args) { /* EXAMPLE: getTable */ - TableBase a = group.getTable("PersonTable"); + Table a = group.getTable("PersonTable"); /* EXAMPLE: getTableCount */ @@ -38,9 +38,9 @@ public static void main(String[] args) { /* EXAMPLE: isValid */ - if (group.isValid()) { +// if (group.isValid()) { // do something - } +// } /* EXAMPLE: writeToByteBuffer */ diff --git a/tightdb-java-example/src/main/java/com/tightdb/example/DynamicTableBaseEx.java b/tightdb-java-example/src/main/java/com/tightdb/example/DynamicTableBaseEx.java index 2441d76a77..6ad3ee9a91 100644 --- a/tightdb-java-example/src/main/java/com/tightdb/example/DynamicTableBaseEx.java +++ b/tightdb-java-example/src/main/java/com/tightdb/example/DynamicTableBaseEx.java @@ -2,7 +2,7 @@ import com.tightdb.*; import com.tightdb.internal.util; -import com.tightdb.lib.TightDB; +import com.tightdb.typed.TightDB; public class DynamicTableBaseEx { @@ -13,7 +13,7 @@ public static void main(String[] args) { TightDB.loadLibrary(); System.out.println("--Memusage: " + util.getNativeMemUsage()); - TableBase base = new TableBase(); + Table base = new Table(); System.out.println("created table"); TableSpec tableSpec = new TableSpec(); @@ -33,7 +33,7 @@ public static void main(String[] args) { System.out.println(base.getString(0, 0)); System.out.println(base.getLong(1, 0)); - TableViewBase results = base.findAllLong(1, 24000); + TableView results = base.findAllLong(1, 24000); System.out.println("Results size: " + results.size()); long rowIndex = base.findFirstString(0, "John"); diff --git a/tightdb-java-example/src/main/java/com/tightdb/example/MixedTest.java b/tightdb-java-example/src/main/java/com/tightdb/example/MixedTest.java index 29dff10b7d..7a444379c6 100644 --- a/tightdb-java-example/src/main/java/com/tightdb/example/MixedTest.java +++ b/tightdb-java-example/src/main/java/com/tightdb/example/MixedTest.java @@ -2,13 +2,13 @@ import com.tightdb.ColumnType; import com.tightdb.Mixed; -import com.tightdb.TableBase; +import com.tightdb.Table; import com.tightdb.TableSpec; public class MixedTest { public static void main(String[] args) { - TableBase table = new TableBase(); + Table table = new Table(); TableSpec tableSpec = new TableSpec(); tableSpec.addColumn(ColumnType.ColumnTypeInt, "num"); diff --git a/tightdb-java-example/src/main/java/com/tightdb/example/NestedTablesExample.java b/tightdb-java-example/src/main/java/com/tightdb/example/NestedTablesExample.java index 45042c6126..f2aacb9a60 100644 --- a/tightdb-java-example/src/main/java/com/tightdb/example/NestedTablesExample.java +++ b/tightdb-java-example/src/main/java/com/tightdb/example/NestedTablesExample.java @@ -2,16 +2,16 @@ import java.util.Date; -import com.tightdb.lib.TightDB; +import com.tightdb.typed.TightDB; public class NestedTablesExample { public static void main(String[] args) { EmployeeTable employees = new EmployeeTable(); - Employee john = employees.add("John", "Doe", 10000, true, new byte[] { 1, 2, 3 }, new Date(), "extra"); - Employee johny = employees.add("Johny", "Goe", 20000, true, new byte[] { 1, 2, 3 }, new Date(), true); - Employee nikolche = employees.insert(1, "Nikolche", "Mihajlovski", 30000, false, new byte[] { 4, 5 }, new Date(), 1234); + Employee john = employees.add("John", "Doe", 10000, true, new byte[] { 1, 2, 3 }, new Date(), "extra", null); + Employee johny = employees.add("Johny", "Goe", 20000, true, new byte[] { 1, 2, 3 }, new Date(), true, null); + Employee nikolche = employees.insert(1, "Nikolche", "Mihajlovski", 30000, false, new byte[] { 4, 5 }, new Date(), 1234, null); PhoneTable p = john.getPhones(); p.add("mobile", "111"); diff --git a/tightdb-java-example/src/main/java/com/tightdb/example/ReplicationExample.java b/tightdb-java-example/src/main/java/com/tightdb/example/ReplicationExample.java index 9b3f924734..b39a5a36ee 100644 --- a/tightdb-java-example/src/main/java/com/tightdb/example/ReplicationExample.java +++ b/tightdb-java-example/src/main/java/com/tightdb/example/ReplicationExample.java @@ -7,7 +7,7 @@ public class ReplicationExample { - @Table(row="Employee") + @DefineTable(row="Employee") class employee { String firstName; String lastName; @@ -19,7 +19,7 @@ class employee { phone phones; } - @Table(row="Phone") + @DefineTable(row="Phone") class phone { String type; String number; @@ -62,7 +62,7 @@ public static void main(String[] args) try { EmployeeTable employees = new EmployeeTable(transact); employees.add("John", "Doe", 10000, true, - new byte[] { 1, 2, 3 }, new Date(), "extra"); + new byte[] { 1, 2, 3 }, new Date(), "extra", null); System.out.println(employees.size()); transact.commit(); } catch (Throwable e) { diff --git a/tightdb-java-example/src/main/java/com/tightdb/example/SearchExample.java b/tightdb-java-example/src/main/java/com/tightdb/example/SearchExample.java index 26ea085f8e..8445888302 100644 --- a/tightdb-java-example/src/main/java/com/tightdb/example/SearchExample.java +++ b/tightdb-java-example/src/main/java/com/tightdb/example/SearchExample.java @@ -3,7 +3,7 @@ import java.util.Arrays; import java.util.Date; -import com.tightdb.lib.TightDB; +import com.tightdb.typed.TightDB; public class SearchExample { @@ -11,9 +11,9 @@ public class SearchExample { public static void main(String[] args) { EmployeeTable Employees = new EmployeeTable(); - Employee john = Employees.add("John", "Doe", 10000, true, new byte[] { 1, 2, 3 }, new Date(), "extra"); - Employee johny = Employees.add("Johny", "Goe", 20000, true, new byte[] { 1, 2, 3 }, new Date(), true); - Employee nikolche = Employees.insert(1, "Nikolche", "Mihajlovski", 30000, false, new byte[] { 4, 5 }, new Date(), 1234); + Employee john = Employees.add("John", "Doe", 10000, true, new byte[] { 1, 2, 3 }, new Date(), "extra", null); + Employee johny = Employees.add("Johny", "Goe", 20000, true, new byte[] { 1, 2, 3 }, new Date(), true, null); + Employee nikolche = Employees.insert(1, "Nikolche", "Mihajlovski", 30000, false, new byte[] { 4, 5 }, new Date(), 1234, null); TightDB.print(Employees); diff --git a/tightdb-java-example/src/main/java/com/tightdb/example/SmallExample.java b/tightdb-java-example/src/main/java/com/tightdb/example/SmallExample.java index 7299615c83..815b503b3c 100644 --- a/tightdb-java-example/src/main/java/com/tightdb/example/SmallExample.java +++ b/tightdb-java-example/src/main/java/com/tightdb/example/SmallExample.java @@ -2,8 +2,8 @@ import java.util.Date; -import com.tightdb.Table; -import com.tightdb.lib.TightDB; +import com.tightdb.*; +import com.tightdb.typed.TightDB; public class SmallExample { @@ -13,15 +13,15 @@ public static void main(String[] args) { /****************************** BASIC OPERATIONS *****************************/ - Employee john = employees.add("John", "Doe", 10000, true, new byte[] {1,2,3}, new Date(), "extra"); - Employee johny = employees.add("Johny", "Goe", 20000, true, new byte[] {2,3,4}, new Date(), true); - Employee nikolche = employees.insert(1, "Nikolche", "Mihajlovski", 30000, false, new byte[] { 4, 5 }, new Date(), 1234); + Employee john = employees.add("John", "Doe", 10000, true, new byte[] {1,2,3}, new Date(), "extra", null); + Employee johny = employees.add("Johny", "Goe", 20000, true, new byte[] {2,3,4}, new Date(), true, null); + Employee nikolche = employees.insert(1, "Nikolche", "Mihajlovski", 30000, false, new byte[] { 4, 5 }, new Date(), 1234, null); TightDB.print("Employees", employees); } - @Table(row = "Employee") + @DefineTable(row = "Employee") class employee { String firstName; String lastName; @@ -33,7 +33,7 @@ class employee { phone phones; } - @Table(row = "Phone") + @DefineTable(row = "Phone") class phone { String type; String number; diff --git a/tightdb-java-example/src/main/java/com/tightdb/example/TopLevelModelExample.java b/tightdb-java-example/src/main/java/com/tightdb/example/TopLevelModelExample.java index 17174cacc1..533e742a01 100644 --- a/tightdb-java-example/src/main/java/com/tightdb/example/TopLevelModelExample.java +++ b/tightdb-java-example/src/main/java/com/tightdb/example/TopLevelModelExample.java @@ -1,8 +1,8 @@ package com.tightdb.example; -import com.tightdb.Table; +import com.tightdb.DefineTable; -@Table +@DefineTable class foo { String b; boolean c; diff --git a/tightdb-java-generator/src/main/java/com/tightdb/generator/AbstractAnnotationProcessor.java b/tightdb-java-generator/src/main/java/com/tightdb/generator/AbstractAnnotationProcessor.java index 17ccae481c..15caf96206 100644 --- a/tightdb-java-generator/src/main/java/com/tightdb/generator/AbstractAnnotationProcessor.java +++ b/tightdb-java-generator/src/main/java/com/tightdb/generator/AbstractAnnotationProcessor.java @@ -19,11 +19,11 @@ import javax.lang.model.util.Types; import javax.tools.FileObject; -import com.tightdb.Table; +import com.tightdb.DefineTable; public abstract class AbstractAnnotationProcessor extends AbstractProcessor { - private static final String[] SUPPORTED_ANNOTATIONS = { Table.class.getCanonicalName() }; + private static final String[] SUPPORTED_ANNOTATIONS = { DefineTable.class.getCanonicalName() }; protected Elements elementUtils; protected Types typeUtils; diff --git a/tightdb-java-generator/src/main/java/com/tightdb/generator/CodeGenProcessor.java b/tightdb-java-generator/src/main/java/com/tightdb/generator/CodeGenProcessor.java index 35a72b1854..b6917c159d 100644 --- a/tightdb-java-generator/src/main/java/com/tightdb/generator/CodeGenProcessor.java +++ b/tightdb-java-generator/src/main/java/com/tightdb/generator/CodeGenProcessor.java @@ -26,7 +26,7 @@ import javax.lang.model.type.TypeMirror; import javax.tools.StandardLocation; -import com.tightdb.Table; +import com.tightdb.DefineTable; public class CodeGenProcessor extends AbstractAnnotationProcessor { @@ -45,9 +45,8 @@ public class CodeGenProcessor extends AbstractAnnotationProcessor { private final CodeRenderer renderer = new CodeRenderer(); static { - NUM_TYPES = new HashSet(Arrays.asList("long", "int", "byte", - "short", "java.lang.Long", "java.lang.Integer", - "java.lang.Byte", "java.lang.Short")); + NUM_TYPES = new HashSet(Arrays.asList("long", "int", "byte", "short", "java.lang.Long", + "java.lang.Integer", "java.lang.Byte", "java.lang.Short")); } private Map tables = new HashMap(); @@ -56,15 +55,14 @@ public class CodeGenProcessor extends AbstractAnnotationProcessor { private FieldSorter fieldSorter; @Override - public void processAnnotations(Set annotations, - RoundEnvironment env, boolean insideEclipse) throws Exception { + public void processAnnotations(Set annotations, RoundEnvironment env, boolean insideEclipse) + throws Exception { fieldSorter = new FieldSorter(logger, getSourceFolders()); for (TypeElement annotation : annotations) { String annotationName = annotation.getQualifiedName().toString(); - if (annotationName.equals(Table.class.getCanonicalName())) { - Set elements = env - .getElementsAnnotatedWith(annotation); + if (annotationName.equals(DefineTable.class.getCanonicalName())) { + Set elements = env.getElementsAnnotatedWith(annotation); processAnnotatedElements(elements, insideEclipse); } else { logger.warn("Unexpected annotation: " + annotationName); @@ -72,12 +70,10 @@ public void processAnnotations(Set annotations, } } - private void processAnnotatedElements(Set elements, boolean insideEclipse) - throws IOException { + private void processAnnotatedElements(Set elements, boolean insideEclipse) throws IOException { logger.info("Processing " + elements.size() + " elements..."); - URI uri = filer.getResource(StandardLocation.SOURCE_OUTPUT, "", "foo") - .toUri(); + URI uri = filer.getResource(StandardLocation.SOURCE_OUTPUT, "", "foo").toUri(); if (uri.toString().equals("foo")) { throw new RuntimeException( "The path of the Java source and generated files must be configured as source output! (see -s option of javac)"); @@ -85,7 +81,8 @@ private void processAnnotatedElements(Set elements, boolean i List sourcesPath = new LinkedList(); - // FIXME: Workaround for OS X - resolve relative URIs against current working directory + // FIXME: Workaround for OS X - resolve relative URIs against current + // working directory uri = new File(".").getAbsoluteFile().toURI().resolve(uri); File file = new File(uri); @@ -126,24 +123,20 @@ private void processAnnotatedElements(Set elements, boolean i } private void setupModelInfo(TypeElement model) { - AnnotationMirror annotationMirror = getAnnotationInfo(model, - Table.class); + AnnotationMirror annotationMirror = getAnnotationInfo(model, DefineTable.class); String tableName = getAttribute(annotationMirror, "table"); String cursorName = getAttribute(annotationMirror, "row"); String viewName = getAttribute(annotationMirror, "view"); String queryName = getAttribute(annotationMirror, "query"); - String entity = StringUtils - .capitalize(model.getSimpleName().toString()); + String entity = StringUtils.capitalize(model.getSimpleName().toString()); tableName = tableName == null ? calculateTableName(entity) : tableName; - cursorName = cursorName == null ? calculateCursorName(entity) - : cursorName; + cursorName = cursorName == null ? calculateCursorName(entity) : cursorName; viewName = viewName == null ? calculateViewName(entity) : viewName; queryName = queryName == null ? calculateQueryName(entity) : queryName; - modelsInfo.put(entity, new ModelInfo(tableName, cursorName, viewName, - queryName)); + modelsInfo.put(entity, new ModelInfo(tableName, cursorName, viewName, queryName)); } private void processModel(List sourceFolders, TypeElement model, boolean insideEclipse) { @@ -158,11 +151,9 @@ private void processModel(List sourceFolders, TypeElement model, boolean i } // get the capitalized model name - String entity = StringUtils - .capitalize(model.getSimpleName().toString()); + String entity = StringUtils.capitalize(model.getSimpleName().toString()); - logger.info("Generating code for entity '" + entity + "' with " - + fields.size() + " columns..."); + logger.info("Generating code for entity '" + entity + "' with " + fields.size() + " columns..."); /*********** Prepare the attributes for the templates ****************/ @@ -190,8 +181,7 @@ private void processModel(List sourceFolders, TypeElement model, boolean i commonAttr.put("queryName", modelInfo.getQueryName()); commonAttr.put("java_header", INFO_GENERATED); - generateSources(model, modelInfo.getTableName(), - modelInfo.getCursorName(), modelInfo.getViewName(), + generateSources(model, modelInfo.getTableName(), modelInfo.getCursorName(), modelInfo.getViewName(), modelInfo.getQueryName(), packageName, commonAttr); } @@ -234,9 +224,8 @@ private List getColumns(List fields) { return columns; } - private void generateSources(TypeElement model, String tableName, - String cursorName, String viewName, String queryName, - String packageName, Map commonAttr) { + private void generateSources(TypeElement model, String tableName, String cursorName, String viewName, + String queryName, String packageName, Map commonAttr) { /*********** Generate the table class ****************/ Model table = new Model(); @@ -315,8 +304,7 @@ private String calculatePackageName(TypeElement model) { String pkgName = pkg.getQualifiedName().toString(); return pkgName.isEmpty() ? "" : pkgName; } else { - logger.warn("Couldn't calculate the target package! Using default: " - + DEFAULT_PACKAGE); + logger.warn("Couldn't calculate the target package! Using default: " + DEFAULT_PACKAGE); return DEFAULT_PACKAGE; } } @@ -352,8 +340,7 @@ private void prepareTables(Set elements) { } } - private boolean isReferencedBy(TypeElement model, - Set elements) { + private boolean isReferencedBy(TypeElement model, Set elements) { String modelType = model.getQualifiedName().toString(); for (Element element : elements) { @@ -363,12 +350,10 @@ private boolean isReferencedBy(TypeElement model, VariableElement field = (VariableElement) enclosedElement; TypeMirror fieldType = field.asType(); if (fieldType.getKind().equals(TypeKind.DECLARED)) { - Element typeAsElement = typeUtils - .asElement(fieldType); + Element typeAsElement = typeUtils.asElement(fieldType); if (typeAsElement instanceof TypeElement) { TypeElement typeElement = (TypeElement) typeAsElement; - if (typeElement.getQualifiedName().toString() - .equals(modelType)) { + if (typeElement.getQualifiedName().toString().equals(modelType)) { return true; } } @@ -387,6 +372,10 @@ private String getColumnType(VariableElement field) { String columnType; if (NUM_TYPES.contains(type)) { columnType = "Long"; + } else if ("float".equals(type) || "java.lang.Float".equals(type)) { + columnType = "Float"; + } else if ("double".equals(type) || "java.lang.Double".equals(type)) { + columnType = "Double"; } else if ("boolean".equals(type) || "java.lang.Boolean".equals(type)) { columnType = "Boolean"; } else if ("java.lang.String".equals(type)) { @@ -415,8 +404,7 @@ private String fieldType(VariableElement field) { } private String fieldSimpleType(VariableElement field) { - return fieldType(field).replaceFirst("<.*>", "").replaceFirst(".*\\.", - ""); + return fieldType(field).replaceFirst("<.*>", "").replaceFirst(".*\\.", ""); } private String getSubtableType(VariableElement field) { @@ -440,17 +428,14 @@ private String getAdjustedFieldType(VariableElement field) { private String getParamType(VariableElement field) { String type = fieldType(field); - if (NUM_TYPES.contains(type)) { - type = "long"; - } else if (type.equals("java.lang.Object")) { - type = "com.tightdb.Mixed"; + if (isSubtable(type)) { + type = "Object[][]"; } return type; } - private static AnnotationMirror getAnnotationInfo(TypeElement typeElement, - Class clazz) { + private static AnnotationMirror getAnnotationInfo(TypeElement typeElement, Class clazz) { String clazzName = clazz.getName(); for (AnnotationMirror m : typeElement.getAnnotationMirrors()) { if (m.getAnnotationType().toString().equals(clazzName)) { @@ -460,10 +445,9 @@ private static AnnotationMirror getAnnotationInfo(TypeElement typeElement, return null; } - private static String getAttribute(AnnotationMirror annotationMirror, - String name) { - for (Entry entry : annotationMirror - .getElementValues().entrySet()) { + private static String getAttribute(AnnotationMirror annotationMirror, String name) { + for (Entry entry : annotationMirror.getElementValues() + .entrySet()) { if (entry.getKey().getSimpleName().toString().equals(name)) { return String.valueOf(entry.getValue().getValue()); } diff --git a/tightdb-java-generator/src/main/java/com/tightdb/generator/Templates.java b/tightdb-java-generator/src/main/java/com/tightdb/generator/Templates.java index b42c405927..29d798b8e2 100644 --- a/tightdb-java-generator/src/main/java/com/tightdb/generator/Templates.java +++ b/tightdb-java-generator/src/main/java/com/tightdb/generator/Templates.java @@ -2,10 +2,10 @@ /* This class is automatically generated from the .ftl templates */ public class Templates { - public static final String TABLE = "${java_header}\r\n<#if packageName?has_content>\r\npackage ${packageName};\r\n\r\n\r\nimport com.tightdb.*;\r\nimport com.tightdb.lib.*;\r\n\r\n/**\r\n * This class represents a TightDB table and was automatically generated.\r\n */\r\n<#if isNested>public class ${tableName} extends AbstractSubtable<${cursorName}, ${viewName}, ${queryName}> {\r\n<#else>public class ${tableName} extends AbstractTable<${cursorName}, ${viewName}, ${queryName}> {\r\n\r\n\tpublic static final EntityTypes<${tableName}, ${viewName}, ${cursorName}, ${queryName}> TYPES = new EntityTypes<${tableName}, ${viewName}, ${cursorName}, ${queryName}>(${tableName}.class, ${viewName}.class, ${cursorName}.class, ${queryName}.class);\r\n\r\n<#foreach f in columns><#if f.isSubtable>\tpublic final ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}, ${f.subTableName}> ${f.name} = new ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}, ${f.subTableName}>(TYPES, table, ${f.index}, \"${f.name}\", ${f.subTableName}.class);\r\n<#else>\tpublic final ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}> ${f.name} = new ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}>(TYPES, table, ${f.index}, \"${f.name}\");\r\n\r\n<#if isNested>\tpublic ${tableName}(TableBase subtableBase) {\r\n\t\tsuper(TYPES, subtableBase);\r\n\t}\r\n<#else>\tpublic ${tableName}() {\r\n\t\tsuper(TYPES);\r\n\t}\r\n\r\n\tpublic ${tableName}(Group group) {\r\n\t\tsuper(TYPES, group);\r\n\t}\r\n\r\n\tpublic static void specifyStructure(TableSpec spec) {\r\n<#foreach f in columns><#if f.isSubtable> add${f.type}Column(spec, \"${f.name}\", new ${f.subTableName}(null));\r\n<#else> add${f.type}Column(spec, \"${f.name}\");\r\n }\r\n\r\n${add}\r\n\r\n${insert}\r\n\r\n}\r\n"; - public static final String TABLE_ADD = " public ${cursorName} add(<#foreach f in columns><#if !f.isSubtable><#if (f_index > 0)>, ${f.originalType} ${f.name}) {\r\n return insert(size()<#foreach f in columns><#if !f.isSubtable>, ${f.name});\r\n }"; - public static final String TABLE_INSERT = " public ${cursorName} insert(long position<#foreach f in columns><#if !f.isSubtable>, ${f.originalType} ${f.name}) {\r\n try {\r\n <#foreach f in columns><#if f.isSubtable>\tinsert${f.type}(${f.index}, position);\r\n <#else>\tinsert${f.type}(${f.index}, position, ${f.name});\r\n insertDone();\r\n\r\n return cursor(position);\r\n } catch (Exception e) {\r\n throw new RuntimeException(\"Error occured while adding/inserting a new row!\", e);\r\n }\r\n }"; - public static final String CURSOR = "${java_header}\r\n<#if packageName?has_content>\r\npackage ${packageName};\r\n\r\n\r\nimport com.tightdb.*;\r\nimport com.tightdb.lib.*;\r\n\r\n/**\r\n * This class represents a TightDB cursor and was automatically generated.\r\n */\r\npublic class ${name} extends AbstractCursor<${name}> {\r\n\r\n<#foreach f in columns><#if f.isSubtable> public final ${f.type}CursorColumn<${name}, ${viewName}, ${queryName}, ${f.subCursorName}, ${f.subTableName}> ${f.name};\r\n<#else> public final ${f.type}CursorColumn<${cursorName}, ${viewName}, ${queryName}> ${f.name};\r\n\r\n\tpublic ${cursorName}(TableOrViewBase tableOrView, long position) {\r\n\t\tsuper(${tableName}.TYPES, tableOrView, position);\r\n\r\n<#foreach f in columns><#if f.isSubtable> ${f.name} = new ${f.type}CursorColumn<${cursorName}, ${viewName}, ${queryName}, ${f.subCursorName}, ${f.subTableName}>(${tableName}.TYPES, this, ${f.index}, \"${f.name}\", ${f.subTableName}.class);\r\n<#else> ${f.name} = new ${f.type}CursorColumn<${cursorName}, ${viewName}, ${queryName}>(${tableName}.TYPES, this, ${f.index}, \"${f.name}\");\r\n\t}\r\n\r\n<#foreach f in columns><#if f.isSubtable>\tpublic ${f.subTableName} get${f.name?cap_first}() {\r\n<#else>\tpublic ${f.fieldType} get${f.name?cap_first}() {\r\n\t\treturn this.${f.name}.get();\r\n\t}\r\n\r\n<#if f.isSubtable>\tpublic void set${f.name?cap_first}(${f.subTableName} ${f.name}) {\r\n<#else>\tpublic void set${f.name?cap_first}(${f.fieldType} ${f.name}) {\r\n\t\tthis.${f.name}.set(${f.name});\r\n\t}\r\n\r\n\t@Override\r\n\tpublic AbstractColumn[] columns() {\r\n\t\treturn getColumnsArray(<#foreach f in columns>${f.name}<#if f_has_next>, );\r\n\t}\r\n\r\n}\r\n"; - public static final String VIEW = "${java_header}\r\n<#if packageName?has_content>\r\npackage ${packageName};\r\n\r\n\r\nimport com.tightdb.*;\r\nimport com.tightdb.lib.*;\r\n\r\n/**\r\n * This class represents a TightDB view and was automatically generated.\r\n */\r\npublic class ${viewName} extends AbstractView<${cursorName}, ${viewName}, ${queryName}> {\r\n\r\n<#foreach f in columns><#if f.isSubtable>\tpublic final ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}, ${f.subTableName}> ${f.name} = new ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}, ${f.subTableName}>(${tableName}.TYPES, tableOrView, ${f.index}, \"${f.name}\", ${f.subTableName}.class);\r\n<#else>\tpublic final ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}> ${f.name} = new ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}>(${tableName}.TYPES, tableOrView, ${f.index}, \"${f.name}\");\r\n\r\n\tpublic ${viewName}(TableViewBase viewBase) {\r\n\t\tsuper(${tableName}.TYPES, viewBase);\r\n\t}\r\n\r\n}\r\n"; - public static final String QUERY = "${java_header}\r\n<#if packageName?has_content>\r\npackage ${packageName};\r\n\r\n\r\nimport com.tightdb.*;\r\nimport com.tightdb.lib.*;\r\n\r\n/**\r\n * This class represents a TightDB query and was automatically generated.\r\n */\r\npublic class ${name} extends AbstractQuery<${name}, ${cursorName}, ${viewName}> {\r\n\r\n<#foreach f in columns><#if f.isSubtable> public final ${f.type}QueryColumn<${cursorName}, ${viewName}, ${name}, ${f.subTableName}> ${f.name};\r\n<#else> public final ${f.type}QueryColumn<${cursorName}, ${viewName}, ${name}> ${f.name};\r\n\r\n\tpublic ${name}(TableBase table, TableQuery query) {\r\n\t\tsuper(${tableName}.TYPES, table, query);\r\n<#foreach f in columns><#if f.isSubtable> ${f.name} = new ${f.type}QueryColumn<${cursorName}, ${viewName}, ${name}, ${f.subTableName}>(${tableName}.TYPES, table, query, ${f.index}, \"${f.name}\", ${f.subTableName}.class);\r\n<#else> ${f.name} = new ${f.type}QueryColumn<${cursorName}, ${viewName}, ${name}>(${tableName}.TYPES, table, query, ${f.index}, \"${f.name}\");\r\n\t}\r\n\r\n}\r\n"; + public static final String TABLE = "${java_header}\r\n<#if packageName?has_content>\r\npackage ${packageName};\r\n\r\n\r\nimport com.tightdb.*;\r\nimport com.tightdb.typed.*;\r\n\r\n/**\r\n * This class represents a TightDB table and was automatically generated.\r\n */\r\n<#if isNested>public class ${tableName} extends AbstractSubtable<${cursorName}, ${viewName}, ${queryName}> {\r\n<#else>public class ${tableName} extends AbstractTable<${cursorName}, ${viewName}, ${queryName}> {\r\n\r\n\tpublic static final EntityTypes<${tableName}, ${viewName}, ${cursorName}, ${queryName}> TYPES = new EntityTypes<${tableName}, ${viewName}, ${cursorName}, ${queryName}>(${tableName}.class, ${viewName}.class, ${cursorName}.class, ${queryName}.class);\r\n\r\n<#foreach f in columns><#if f.isSubtable>\tpublic final ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}, ${f.subTableName}> ${f.name} = new ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}, ${f.subTableName}>(TYPES, table, ${f.index}, \"${f.name}\", ${f.subTableName}.class);\r\n<#else>\tpublic final ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}> ${f.name} = new ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}>(TYPES, table, ${f.index}, \"${f.name}\");\r\n\r\n<#if isNested>\tpublic ${tableName}(Table subtable) {\r\n\t\tsuper(TYPES, subtable);\r\n\t}\r\n<#else>\tpublic ${tableName}() {\r\n\t\tsuper(TYPES);\r\n\t}\r\n\r\n\tpublic ${tableName}(Group group) {\r\n\t\tsuper(TYPES, group);\r\n\t}\r\n\r\n\tpublic static void specifyStructure(TableSpec spec) {\r\n<#foreach f in columns><#if f.isSubtable> add${f.type}Column(spec, \"${f.name}\", new ${f.subTableName}(null));\r\n<#else> add${f.type}Column(spec, \"${f.name}\");\r\n }\r\n\r\n${add}\r\n\r\n${insert}\r\n\r\n}\r\n"; + public static final String TABLE_ADD = " public ${cursorName} add(<#foreach f in columns><#if (f_index > 0)>, ${f.paramType} ${f.name}) {\r\n return insert(size()<#foreach f in columns>, ${f.name});\r\n }"; + public static final String TABLE_INSERT = " public ${cursorName} insert(long position<#foreach f in columns>, ${f.paramType} ${f.name}) {\r\n try {\r\n <#foreach f in columns><#if f.isSubtable> insert${f.type}(${f.index}, position, ${f.name});\r\n <#else>\tinsert${f.type}(${f.index}, position, ${f.name});\r\n insertDone();\r\n\r\n return cursor(position);\r\n } catch (Exception e) {\r\n throw new RuntimeException(\"Error occured while adding/inserting a new row!\", e);\r\n }\r\n }"; + public static final String CURSOR = "${java_header}\r\n<#if packageName?has_content>\r\npackage ${packageName};\r\n\r\n\r\nimport com.tightdb.*;\r\nimport com.tightdb.typed.*;\r\n\r\n/**\r\n * This class represents a TightDB cursor and was automatically generated.\r\n */\r\npublic class ${name} extends AbstractCursor<${name}> {\r\n\r\n<#foreach f in columns><#if f.isSubtable> public final ${f.type}CursorColumn<${name}, ${viewName}, ${queryName}, ${f.subCursorName}, ${f.subTableName}> ${f.name};\r\n<#else> public final ${f.type}CursorColumn<${cursorName}, ${viewName}, ${queryName}> ${f.name};\r\n\r\n\tpublic ${cursorName}(TableOrView tableOrView, long position) {\r\n\t\tsuper(${tableName}.TYPES, tableOrView, position);\r\n\r\n<#foreach f in columns><#if f.isSubtable> ${f.name} = new ${f.type}CursorColumn<${cursorName}, ${viewName}, ${queryName}, ${f.subCursorName}, ${f.subTableName}>(${tableName}.TYPES, this, ${f.index}, \"${f.name}\", ${f.subTableName}.class);\r\n<#else> ${f.name} = new ${f.type}CursorColumn<${cursorName}, ${viewName}, ${queryName}>(${tableName}.TYPES, this, ${f.index}, \"${f.name}\");\r\n\t}\r\n\r\n<#foreach f in columns><#if f.isSubtable>\tpublic ${f.subTableName} get${f.name?cap_first}() {\r\n<#else>\tpublic ${f.fieldType} get${f.name?cap_first}() {\r\n\t\treturn this.${f.name}.get();\r\n\t}\r\n\r\n<#if f.isSubtable>\tpublic void set${f.name?cap_first}(${f.subTableName} ${f.name}) {\r\n<#else>\tpublic void set${f.name?cap_first}(${f.fieldType} ${f.name}) {\r\n\t\tthis.${f.name}.set(${f.name});\r\n\t}\r\n\r\n\t@Override\r\n\tpublic AbstractColumn[] columns() {\r\n\t\treturn getColumnsArray(<#foreach f in columns>${f.name}<#if f_has_next>, );\r\n\t}\r\n\r\n}\r\n"; + public static final String VIEW = "${java_header}\r\n<#if packageName?has_content>\r\npackage ${packageName};\r\n\r\n\r\nimport com.tightdb.*;\r\nimport com.tightdb.typed.*;\r\n\r\n/**\r\n * This class represents a TightDB view and was automatically generated.\r\n */\r\npublic class ${viewName} extends AbstractView<${cursorName}, ${viewName}, ${queryName}> {\r\n\r\n<#foreach f in columns><#if f.isSubtable>\tpublic final ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}, ${f.subTableName}> ${f.name} = new ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}, ${f.subTableName}>(${tableName}.TYPES, tableOrView, ${f.index}, \"${f.name}\", ${f.subTableName}.class);\r\n<#else>\tpublic final ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}> ${f.name} = new ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}>(${tableName}.TYPES, tableOrView, ${f.index}, \"${f.name}\");\r\n\r\n\tpublic ${viewName}(TableView view) {\r\n\t\tsuper(${tableName}.TYPES, view);\r\n\t}\r\n\r\n}\r\n"; + public static final String QUERY = "${java_header}\r\n<#if packageName?has_content>\r\npackage ${packageName};\r\n\r\n\r\nimport com.tightdb.*;\r\nimport com.tightdb.typed.*;\r\n\r\n/**\r\n * This class represents a TightDB query and was automatically generated.\r\n */\r\npublic class ${name} extends AbstractQuery<${name}, ${cursorName}, ${viewName}> {\r\n\r\n<#foreach f in columns><#if f.isSubtable> public final ${f.type}QueryColumn<${cursorName}, ${viewName}, ${name}, ${f.subTableName}> ${f.name};\r\n<#else> public final ${f.type}QueryColumn<${cursorName}, ${viewName}, ${name}> ${f.name};\r\n\r\n\tpublic ${name}(Table table, TableQuery query) {\r\n\t\tsuper(${tableName}.TYPES, table, query);\r\n<#foreach f in columns><#if f.isSubtable> ${f.name} = new ${f.type}QueryColumn<${cursorName}, ${viewName}, ${name}, ${f.subTableName}>(${tableName}.TYPES, table, query, ${f.index}, \"${f.name}\", ${f.subTableName}.class);\r\n<#else> ${f.name} = new ${f.type}QueryColumn<${cursorName}, ${viewName}, ${name}>(${tableName}.TYPES, table, query, ${f.index}, \"${f.name}\");\r\n\t}\r\n\r\n}\r\n"; } diff --git a/tightdb-java-generator/src/main/resources/codegen-templates/cursor.ftl b/tightdb-java-generator/src/main/resources/codegen-templates/cursor.ftl index 8f6b4ad410..7071a0efda 100644 --- a/tightdb-java-generator/src/main/resources/codegen-templates/cursor.ftl +++ b/tightdb-java-generator/src/main/resources/codegen-templates/cursor.ftl @@ -4,7 +4,7 @@ package ${packageName}; import com.tightdb.*; -import com.tightdb.lib.*; +import com.tightdb.typed.*; /** * This class represents a TightDB cursor and was automatically generated. @@ -14,7 +14,7 @@ public class ${name} extends AbstractCursor<${name}> { <#foreach f in columns><#if f.isSubtable> public final ${f.type}CursorColumn<${name}, ${viewName}, ${queryName}, ${f.subCursorName}, ${f.subTableName}> ${f.name}; <#else> public final ${f.type}CursorColumn<${cursorName}, ${viewName}, ${queryName}> ${f.name}; - public ${cursorName}(TableOrViewBase tableOrView, long position) { + public ${cursorName}(TableOrView tableOrView, long position) { super(${tableName}.TYPES, tableOrView, position); <#foreach f in columns><#if f.isSubtable> ${f.name} = new ${f.type}CursorColumn<${cursorName}, ${viewName}, ${queryName}, ${f.subCursorName}, ${f.subTableName}>(${tableName}.TYPES, this, ${f.index}, "${f.name}", ${f.subTableName}.class); diff --git a/tightdb-java-generator/src/main/resources/codegen-templates/query.ftl b/tightdb-java-generator/src/main/resources/codegen-templates/query.ftl index e9fee62ec1..8ded488a93 100644 --- a/tightdb-java-generator/src/main/resources/codegen-templates/query.ftl +++ b/tightdb-java-generator/src/main/resources/codegen-templates/query.ftl @@ -4,7 +4,7 @@ package ${packageName}; import com.tightdb.*; -import com.tightdb.lib.*; +import com.tightdb.typed.*; /** * This class represents a TightDB query and was automatically generated. @@ -14,7 +14,7 @@ public class ${name} extends AbstractQuery<${name}, ${cursorName}, ${viewName}> <#foreach f in columns><#if f.isSubtable> public final ${f.type}QueryColumn<${cursorName}, ${viewName}, ${name}, ${f.subTableName}> ${f.name}; <#else> public final ${f.type}QueryColumn<${cursorName}, ${viewName}, ${name}> ${f.name}; - public ${name}(TableBase table, TableQuery query) { + public ${name}(Table table, TableQuery query) { super(${tableName}.TYPES, table, query); <#foreach f in columns><#if f.isSubtable> ${f.name} = new ${f.type}QueryColumn<${cursorName}, ${viewName}, ${name}, ${f.subTableName}>(${tableName}.TYPES, table, query, ${f.index}, "${f.name}", ${f.subTableName}.class); <#else> ${f.name} = new ${f.type}QueryColumn<${cursorName}, ${viewName}, ${name}>(${tableName}.TYPES, table, query, ${f.index}, "${f.name}"); diff --git a/tightdb-java-generator/src/main/resources/codegen-templates/table.ftl b/tightdb-java-generator/src/main/resources/codegen-templates/table.ftl index c237f0c521..07cedb59a1 100644 --- a/tightdb-java-generator/src/main/resources/codegen-templates/table.ftl +++ b/tightdb-java-generator/src/main/resources/codegen-templates/table.ftl @@ -4,7 +4,7 @@ package ${packageName}; import com.tightdb.*; -import com.tightdb.lib.*; +import com.tightdb.typed.*; /** * This class represents a TightDB table and was automatically generated. @@ -17,8 +17,8 @@ import com.tightdb.lib.*; <#foreach f in columns><#if f.isSubtable> public final ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}, ${f.subTableName}> ${f.name} = new ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}, ${f.subTableName}>(TYPES, table, ${f.index}, "${f.name}", ${f.subTableName}.class); <#else> public final ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}> ${f.name} = new ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}>(TYPES, table, ${f.index}, "${f.name}"); -<#if isNested> public ${tableName}(TableBase subtableBase) { - super(TYPES, subtableBase); +<#if isNested> public ${tableName}(Table subtable) { + super(TYPES, subtable); } <#else> public ${tableName}() { super(TYPES); diff --git a/tightdb-java-generator/src/main/resources/codegen-templates/table_add.ftl b/tightdb-java-generator/src/main/resources/codegen-templates/table_add.ftl index b32f7ec3a1..4cec19891f 100644 --- a/tightdb-java-generator/src/main/resources/codegen-templates/table_add.ftl +++ b/tightdb-java-generator/src/main/resources/codegen-templates/table_add.ftl @@ -1,3 +1,3 @@ - public ${cursorName} add(<#foreach f in columns><#if !f.isSubtable><#if (f_index > 0)>, ${f.originalType} ${f.name}) { - return insert(size()<#foreach f in columns><#if !f.isSubtable>, ${f.name}); + public ${cursorName} add(<#foreach f in columns><#if (f_index > 0)>, ${f.paramType} ${f.name}) { + return insert(size()<#foreach f in columns>, ${f.name}); } \ No newline at end of file diff --git a/tightdb-java-generator/src/main/resources/codegen-templates/table_insert.ftl b/tightdb-java-generator/src/main/resources/codegen-templates/table_insert.ftl index 84eff1b012..739babe949 100644 --- a/tightdb-java-generator/src/main/resources/codegen-templates/table_insert.ftl +++ b/tightdb-java-generator/src/main/resources/codegen-templates/table_insert.ftl @@ -1,8 +1,8 @@ - public ${cursorName} insert(long position<#foreach f in columns><#if !f.isSubtable>, ${f.originalType} ${f.name}) { + public ${cursorName} insert(long position<#foreach f in columns>, ${f.paramType} ${f.name}) { try { - <#foreach f in columns><#if f.isSubtable> insert${f.type}(${f.index}, position); + <#foreach f in columns><#if f.isSubtable> insert${f.type}(${f.index}, position, ${f.name}); <#else> insert${f.type}(${f.index}, position, ${f.name}); - insertDone(); + insertDone(); return cursor(position); } catch (Exception e) { diff --git a/tightdb-java-generator/src/main/resources/codegen-templates/view.ftl b/tightdb-java-generator/src/main/resources/codegen-templates/view.ftl index bc269c91e9..1fa94d7b70 100644 --- a/tightdb-java-generator/src/main/resources/codegen-templates/view.ftl +++ b/tightdb-java-generator/src/main/resources/codegen-templates/view.ftl @@ -4,7 +4,7 @@ package ${packageName}; import com.tightdb.*; -import com.tightdb.lib.*; +import com.tightdb.typed.*; /** * This class represents a TightDB view and was automatically generated. @@ -14,8 +14,8 @@ public class ${viewName} extends AbstractView<${cursorName}, ${viewName}, ${quer <#foreach f in columns><#if f.isSubtable> public final ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}, ${f.subTableName}> ${f.name} = new ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}, ${f.subTableName}>(${tableName}.TYPES, tableOrView, ${f.index}, "${f.name}", ${f.subTableName}.class); <#else> public final ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}> ${f.name} = new ${f.type}TableOrViewColumn<${cursorName}, ${viewName}, ${queryName}>(${tableName}.TYPES, tableOrView, ${f.index}, "${f.name}"); - public ${viewName}(TableViewBase viewBase) { - super(${tableName}.TYPES, viewBase); + public ${viewName}(TableView view) { + super(${tableName}.TYPES, view); } } diff --git a/tightdb-java-test/src/main/java/com/tightdb/test/TestModel.java b/tightdb-java-test/src/main/java/com/tightdb/test/TestModel.java index a8410b81cd..7b4341a858 100644 --- a/tightdb-java-test/src/main/java/com/tightdb/test/TestModel.java +++ b/tightdb-java-test/src/main/java/com/tightdb/test/TestModel.java @@ -2,14 +2,14 @@ import java.util.Date; -import com.tightdb.Table; +import com.tightdb.DefineTable; /** * This model is used to generate classes that are used only for the tests. */ public class TestModel { - @Table + @DefineTable class TestEmployee { String firstName; String lastName; @@ -21,10 +21,17 @@ class TestEmployee { TestPhone phones; } - @Table + @DefineTable class TestPhone { String type; String number; } + @DefineTable + class TestNumbers { + long longNum; + float floatNum; + double doubleNum; + } + } diff --git a/tightdb-java-test/src/test/java/com/tightdb/JNIBinaryTypeTest.java b/tightdb-java-test/src/test/java/com/tightdb/JNIBinaryTypeTest.java index c19b673022..ac6a0bd429 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNIBinaryTypeTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNIBinaryTypeTest.java @@ -7,11 +7,11 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import com.tightdb.lib.TightDB; +import com.tightdb.typed.TightDB; public class JNIBinaryTypeTest { - protected TableBase table; + protected Table table; protected byte [] testArray = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; @BeforeMethod @@ -19,7 +19,7 @@ public void init() { TightDB.loadLibrary(); //util.setDebugLevel(0); //Set to 1 to see more JNI debug messages - table = new TableBase(); + table = new Table(); TableSpec tableSpec = new TableSpec(); tableSpec.addColumn(ColumnType.ColumnTypeBinary, "bin"); @@ -50,7 +50,7 @@ public void shouldStoreValuesOfBinaryType_ByteBuffer_wrap() throws Exception { checkBinaryCell(table, 0, 0, ColumnType.ColumnTypeBinary, testArray); } - private void checkBinaryCell(TableBase table, long col, long row, ColumnType columnType, byte[] value) throws IllegalAccessException { + private void checkBinaryCell(Table table, long col, long row, ColumnType columnType, byte[] value) throws IllegalAccessException { byte[] bin = table.getBinaryByteArray(col, row); assertEquals(value, bin); diff --git a/tightdb-java-test/src/test/java/com/tightdb/JNICloseTest.java b/tightdb-java-test/src/test/java/com/tightdb/JNICloseTest.java index c186046d18..7b3f56ab11 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNICloseTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNICloseTest.java @@ -7,7 +7,7 @@ public class JNICloseTest { @Test (enabled=true, expectedExceptions = IllegalArgumentException.class) public void shouldCloseTable() { // util.setDebugLevel(1); - TableBase table = new TableBase(); + Table table = new Table(); table.close(); @SuppressWarnings("unused") diff --git a/tightdb-java-test/src/test/java/com/tightdb/JNIDistinctTest.java b/tightdb-java-test/src/test/java/com/tightdb/JNIDistinctTest.java index 189461871f..e097411679 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNIDistinctTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNIDistinctTest.java @@ -5,10 +5,10 @@ @SuppressWarnings("unused") public class JNIDistinctTest { - TableBase table; + Table table; void init() { - table = new TableBase(); + table = new Table(); TableSpec tableSpec = new TableSpec(); tableSpec.addColumn(ColumnType.ColumnTypeInt, "number"); tableSpec.addColumn(ColumnType.ColumnTypeString, "name"); @@ -33,7 +33,7 @@ public void shouldTestDistinct() { table.setIndex(1); assertEquals(true, table.hasIndex(1)); - TableViewBase view = table.distinct(1); + TableView view = table.distinct(1); assertEquals(4, view.size()); assertEquals(0, view.getLong(0, 0)); assertEquals(1, view.getLong(0, 1)); @@ -44,14 +44,14 @@ public void shouldTestDistinct() { @Test(expectedExceptions = UnsupportedOperationException.class) public void shouldTestDistinctErrorWhenNoIndex() { init(); - TableViewBase view = table.distinct(1); + TableView view = table.distinct(1); } @Test(expectedExceptions = ArrayIndexOutOfBoundsException.class) public void shouldTestDistinctErrorWhenIndexOutOfBounds() { init(); - TableViewBase view = table.distinct(3); + TableView view = table.distinct(3); } @Test(expectedExceptions = IllegalArgumentException.class) @@ -70,7 +70,7 @@ public void shouldCheckIndexIsOkOnColumn() { public void shouldTestDistinctErrorWhenWrongColumnType() { init(); table.setIndex(1); - TableViewBase view = table.distinct(0); + TableView view = table.distinct(0); } } \ No newline at end of file diff --git a/tightdb-java-test/src/test/java/com/tightdb/JNIMixedSubtableTest.java b/tightdb-java-test/src/test/java/com/tightdb/JNIMixedSubtableTest.java index c9e991c943..b68b8f8192 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNIMixedSubtableTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNIMixedSubtableTest.java @@ -8,7 +8,7 @@ public class JNIMixedSubtableTest { @Test public void shouldCreateSubtableInMixedTypeColumn() { - TableBase table = new TableBase(); + Table table = new Table(); TableSpec tableSpec = new TableSpec(); tableSpec.addColumn(ColumnType.ColumnTypeInt, "num"); @@ -29,7 +29,7 @@ public void shouldCreateSubtableInMixedTypeColumn() { boolean gotException = false; try { @SuppressWarnings("unused") - TableBase subtable = table.getSubTable(1, 0); + Table subtable = table.getSubTable(1, 0); } catch (IllegalArgumentException e) { gotException = true; } @@ -45,7 +45,7 @@ public void shouldCreateSubtableInMixedTypeColumn() { assertEquals(0, table.getSubTableSize(1, 0)); // Create schema for the one Mixed cell with a subtable - TableBase subtable = table.getSubTable(1, ROW); + Table subtable = table.getSubTable(1, ROW); TableSpec subspecMixed = subtable.getTableSpec(); subspecMixed.addColumn(ColumnType.ColumnTypeInt, "num"); subtable.updateFromSpec(subspecMixed); @@ -62,7 +62,7 @@ public void shouldCreateSubtableInMixedTypeColumn() { @SuppressWarnings("unused") @Test public void shouldCreateSubtableInMixedTypeColumn2() { - TableBase table = new TableBase(); + Table table = new Table(); TableSpec tableSpec = new TableSpec(); tableSpec.addColumn(ColumnType.ColumnTypeInt, "num"); @@ -72,7 +72,7 @@ public void shouldCreateSubtableInMixedTypeColumn2() { table.addEmptyRow(); table.setMixed(1, 0, new Mixed(ColumnType.ColumnTypeTable)); - TableBase subtable = table.getSubTable(1, 0); + Table subtable = table.getSubTable(1, 0); } } diff --git a/tightdb-java-test/src/test/java/com/tightdb/JNIMixedTypeTest.java b/tightdb-java-test/src/test/java/com/tightdb/JNIMixedTypeTest.java index 5bdcf7f881..c0cd3e1359 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNIMixedTypeTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNIMixedTypeTest.java @@ -61,7 +61,7 @@ public void shouldFailOnWrongTypeRetrieval(ColumnType columnType) @Test(dataProvider = "mixedValuesProvider") public void shouldStoreValuesOfMixedType(MixedData value1, MixedData value2, MixedData value3) throws Exception { - TableBase table = new TableBase(); + Table table = new Table(); TableSpec tableSpec = new TableSpec(); tableSpec.addColumn(ColumnType.ColumnTypeMixed, "mix"); @@ -81,7 +81,7 @@ public void shouldStoreValuesOfMixedType(MixedData value1, table.close(); } - private void checkMixedCell(TableBase table, long col, long row, + private void checkMixedCell(Table table, long col, long row, ColumnType columnType, Object value) throws IllegalAccessException { ColumnType mixedType = table.getMixedType(col, row); assertEquals(columnType, mixedType); diff --git a/tightdb-java-test/src/test/java/com/tightdb/JNIQueryTest.java b/tightdb-java-test/src/test/java/com/tightdb/JNIQueryTest.java index d4f8e86fe6..b7332fb828 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNIQueryTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNIQueryTest.java @@ -5,10 +5,10 @@ public class JNIQueryTest { - TableBase table; + Table table; void init() { - table = new TableBase(); + table = new Table(); TableSpec tableSpec = new TableSpec(); tableSpec.addColumn(ColumnType.ColumnTypeInt, "number"); tableSpec.addColumn(ColumnType.ColumnTypeString, "name"); diff --git a/tightdb-java-test/src/test/java/com/tightdb/JNISubtableTest.java b/tightdb-java-test/src/test/java/com/tightdb/JNISubtableTest.java index d10a59039d..fa8196df4e 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNISubtableTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNISubtableTest.java @@ -9,7 +9,7 @@ public class JNISubtableTest { @Test() public void shouldSynchronizeNestedTables() { Group group = new Group(); - TableBase table = group.getTable("emp"); + Table table = group.getTable("emp"); TableSpec tableSpec = new TableSpec(); tableSpec.addColumn(ColumnType.ColumnTypeString, "name"); @@ -22,12 +22,12 @@ public void shouldSynchronizeNestedTables() { table.add("Foo", null); assertEquals(1, table.size()); - TableBase subtable1 = table.getSubTable(1, 0); + Table subtable1 = table.getSubTable(1, 0); subtable1.add(123); assertEquals(1, subtable1.size()); subtable1.close(); - TableBase subtable2 = table.getSubTable(1, 0); + Table subtable2 = table.getSubTable(1, 0); assertEquals(1, subtable2.size()); assertEquals(123, subtable2.getLong(0, 0)); @@ -37,7 +37,7 @@ public void shouldSynchronizeNestedTables() { @Test() public void shouldInsertNestedTablesNested() { Group group = new Group(); - TableBase table = group.getTable("emp"); + Table table = group.getTable("emp"); // Define table TableSpec tableSpec = new TableSpec(); diff --git a/tightdb-java-test/src/test/java/com/tightdb/JNITableInsertTest.java b/tightdb-java-test/src/test/java/com/tightdb/JNITableInsertTest.java index d8f6b5fee7..634dff6d5b 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNITableInsertTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNITableInsertTest.java @@ -9,7 +9,7 @@ public class JNITableInsertTest { - public void verifyRow(TableBase tbl, long rowIndex, Object[] values) { + public void verifyRow(Table tbl, long rowIndex, Object[] values) { assertTrue((Boolean)(values[0]) == tbl.getBoolean(0, rowIndex)); assertEquals(((Number)values[1]).longValue(), tbl.getLong(1, rowIndex)); assertEquals((String)values[2], tbl.getString(2, rowIndex)); @@ -23,7 +23,7 @@ public void verifyRow(TableBase tbl, long rowIndex, Object[] values) { // Mixed mix2 = tbl.getMixed(5, rowIndex); // TODO: assertTrue(mix1.equals(mix2)); - TableBase subTable = tbl.getSubTable(6, rowIndex); + Table subTable = tbl.getSubTable(6, rowIndex); Object[] subValues = (Object[])values[6]; for (long i=0; i getEmployees(); @@ -69,7 +72,8 @@ public void shouldRemoveFirstRow() throws IllegalAccessException { getEmployees().remove(0); assertEquals(NAME1, getEmployees().at(0).getFirstName()); assertEquals(NAME2, getEmployees().at(1).getFirstName()); - assertEquals(2, getEmployees().size()); + assertEquals(NAME3, getEmployees().at(2).getFirstName()); + assertEquals(3, getEmployees().size()); } @Test @@ -78,21 +82,24 @@ public void shouldRemoveMiddleRow() throws IllegalAccessException { getEmployees().remove(1); assertEquals(NAME0, getEmployees().at(0).getFirstName()); assertEquals(NAME2, getEmployees().at(1).getFirstName()); - assertEquals(2, getEmployees().size()); + assertEquals(NAME3, getEmployees().at(2).getFirstName()); + assertEquals(3, getEmployees().size()); } @Test public void shouldRemoveLastRow() throws IllegalAccessException { // Remove last row - getEmployees().remove(2); - assertEquals(2, getEmployees().size()); + getEmployees().remove(3); + assertEquals(3, getEmployees().size()); assertEquals(NAME0, getEmployees().at(0).getFirstName()); assertEquals(NAME1, getEmployees().at(1).getFirstName()); + assertEquals(NAME2, getEmployees().at(2).getFirstName()); // Remove last row getEmployees().removeLast(); - assertEquals(1, getEmployees().size()); + assertEquals(2, getEmployees().size()); assertEquals(NAME0, getEmployees().at(0).getFirstName()); + assertEquals(NAME1, getEmployees().at(1).getFirstName()); } @Test diff --git a/tightdb-java-test/src/test/java/com/tightdb/lib/AbstractNavigationTest.java b/tightdb-java-test/src/test/java/com/tightdb/typed/AbstractNavigationTest.java similarity index 92% rename from tightdb-java-test/src/test/java/com/tightdb/lib/AbstractNavigationTest.java rename to tightdb-java-test/src/test/java/com/tightdb/typed/AbstractNavigationTest.java index 47d5790b2b..89bcfc1325 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/lib/AbstractNavigationTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/typed/AbstractNavigationTest.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertNull; @@ -8,6 +8,7 @@ import com.tightdb.test.TestEmployeeQuery; import com.tightdb.test.TestEmployeeRow; import com.tightdb.test.TestEmployeeView; +import com.tightdb.typed.AbstractTableOrView; public abstract class AbstractNavigationTest { diff --git a/tightdb-java-test/src/test/java/com/tightdb/lib/AbstractTest.java b/tightdb-java-test/src/test/java/com/tightdb/typed/AbstractTest.java similarity index 93% rename from tightdb-java-test/src/test/java/com/tightdb/lib/AbstractTest.java rename to tightdb-java-test/src/test/java/com/tightdb/typed/AbstractTest.java index 07c411918f..d5a00b89f4 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/lib/AbstractTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/typed/AbstractTest.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; import static com.tightdb.test.EmployeesFixture.EMPLOYEES; import static org.testng.AssertJUnit.assertEquals; @@ -19,6 +19,7 @@ import com.tightdb.test.TestEmployeeTable; import com.tightdb.test.TestEmployeeView; import com.tightdb.test.TestPhoneRow; +import com.tightdb.typed.AbstractColumn; public abstract class AbstractTest { @@ -61,14 +62,14 @@ public void clear() { protected void addEmployee(TestEmployeeTable employees, EmployeeData emp) { TestEmployeeRow e = employees.add(emp.firstName, emp.lastName, - emp.salary, emp.driver, emp.photo, emp.birthdate, emp.extra); + emp.salary, emp.driver, emp.photo, emp.birthdate, emp.extra, null); addPhones(emp, e); } protected void insertEmployee(TestEmployeeTable employees, long pos, EmployeeData emp) { TestEmployeeRow e = employees.insert(pos, emp.firstName, emp.lastName, - emp.salary, emp.driver, emp.photo, emp.birthdate, emp.extra); + emp.salary, emp.driver, emp.photo, emp.birthdate, emp.extra, null); addPhones(emp, e); } diff --git a/tightdb-java-test/src/test/java/com/tightdb/lib/CursorColumnsTest.java b/tightdb-java-test/src/test/java/com/tightdb/typed/CursorColumnsTest.java similarity index 95% rename from tightdb-java-test/src/test/java/com/tightdb/lib/CursorColumnsTest.java rename to tightdb-java-test/src/test/java/com/tightdb/typed/CursorColumnsTest.java index c03d9650fb..d67265a446 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/lib/CursorColumnsTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/typed/CursorColumnsTest.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertNotNull; @@ -14,6 +14,7 @@ import com.tightdb.test.TestEmployeeQuery; import com.tightdb.test.TestEmployeeRow; import com.tightdb.test.TestEmployeeView; +import com.tightdb.typed.AbstractTableOrView; public class CursorColumnsTest extends AbstractTest { diff --git a/tightdb-java-test/src/test/java/com/tightdb/lib/GroupTest.java b/tightdb-java-test/src/test/java/com/tightdb/typed/GroupTest.java similarity index 93% rename from tightdb-java-test/src/test/java/com/tightdb/lib/GroupTest.java rename to tightdb-java-test/src/test/java/com/tightdb/typed/GroupTest.java index 7b673c2387..c5b7dfc452 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/lib/GroupTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/typed/GroupTest.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; import org.testng.annotations.Test; import static org.testng.AssertJUnit.assertEquals; @@ -57,11 +57,11 @@ public void shouldCreateTablesInGroup() { TestEmployeeTable employees = new TestEmployeeTable(group); employees.add(NAME0, "Doe", 10000, true, new byte[] { 1, 2, 3 }, - new Date(), "extra"); + new Date(), "extra", null); employees.add(NAME2, "B. Good", 20000, true, new byte[] { 1, 2, 3 }, - new Date(), true); + new Date(), true, null); employees.insert(1, NAME1, "Mihajlovski", 30000, false, new byte[] { 4, - 5 }, new Date(), 1234); + 5 }, new Date(), 1234, null); byte[] data = group.writeToMem(); diff --git a/tightdb-java-test/src/test/java/com/tightdb/lib/MixedSubtableTest.java b/tightdb-java-test/src/test/java/com/tightdb/typed/MixedSubtableTest.java similarity index 94% rename from tightdb-java-test/src/test/java/com/tightdb/lib/MixedSubtableTest.java rename to tightdb-java-test/src/test/java/com/tightdb/typed/MixedSubtableTest.java index fc2135c260..14ae923739 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/lib/MixedSubtableTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/typed/MixedSubtableTest.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; import static org.testng.AssertJUnit.assertEquals; diff --git a/tightdb-java-test/src/test/java/com/tightdb/lib/SubtableTest.java b/tightdb-java-test/src/test/java/com/tightdb/typed/SubtableTest.java similarity index 95% rename from tightdb-java-test/src/test/java/com/tightdb/lib/SubtableTest.java rename to tightdb-java-test/src/test/java/com/tightdb/typed/SubtableTest.java index bd26fe8a07..5fdcfd85e8 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/lib/SubtableTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/typed/SubtableTest.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; diff --git a/tightdb-java-test/src/test/java/com/tightdb/lib/TableColumnsTest.java b/tightdb-java-test/src/test/java/com/tightdb/typed/TableColumnsTest.java similarity index 96% rename from tightdb-java-test/src/test/java/com/tightdb/lib/TableColumnsTest.java rename to tightdb-java-test/src/test/java/com/tightdb/typed/TableColumnsTest.java index 23879a2a34..16625df677 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/lib/TableColumnsTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/typed/TableColumnsTest.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; import static com.tightdb.test.ExtraTests.assertArrayEquals; diff --git a/tightdb-java-test/src/test/java/com/tightdb/lib/TableCursorColumnTest.java b/tightdb-java-test/src/test/java/com/tightdb/typed/TableCursorColumnTest.java similarity index 95% rename from tightdb-java-test/src/test/java/com/tightdb/lib/TableCursorColumnTest.java rename to tightdb-java-test/src/test/java/com/tightdb/typed/TableCursorColumnTest.java index 0e9290cb67..095e27531a 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/lib/TableCursorColumnTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/typed/TableCursorColumnTest.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; diff --git a/tightdb-java-test/src/test/java/com/tightdb/lib/TableDataOperationsTest.java b/tightdb-java-test/src/test/java/com/tightdb/typed/TableDataOperationsTest.java similarity index 59% rename from tightdb-java-test/src/test/java/com/tightdb/lib/TableDataOperationsTest.java rename to tightdb-java-test/src/test/java/com/tightdb/typed/TableDataOperationsTest.java index f017cd221e..ca956d2747 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/lib/TableDataOperationsTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/typed/TableDataOperationsTest.java @@ -1,4 +1,4 @@ -package com.tightdb.lib; +package com.tightdb.typed; import static org.testng.AssertJUnit.assertEquals; @@ -11,6 +11,8 @@ import com.tightdb.test.TestEmployeeRow; import com.tightdb.test.TestEmployeeTable; import com.tightdb.test.TestEmployeeView; +import com.tightdb.test.TestPhoneTable; +import com.tightdb.typed.AbstractTableOrView; @Test public class TableDataOperationsTest extends AbstractDataOperationsTest { @@ -26,12 +28,12 @@ protected AbstractTableOrViewCallObjectMethod(jTableSpec, jAddSubtableColumnMethodId, env->NewStringUTF(colName)); const Spec& subTableSpec = spec.get_subtable_spec(i); UpdateJTableSpecFromSpec(env, subTableSpec, jSubTableSpec); diff --git a/tightdb_jni/src/columntypeutil.cpp b/tightdb_jni/src/columntypeutil.cpp index 50c4e145e6..f4ba97912f 100644 --- a/tightdb_jni/src/columntypeutil.cpp +++ b/tightdb_jni/src/columntypeutil.cpp @@ -16,17 +16,17 @@ static jfieldID GetFieldIDColumnType(JNIEnv* env, const char* methodStr, const c return myField; } -ColumnType GetColumnTypeFromJColumnType(JNIEnv* env, jobject jColumnType) +DataType GetColumnTypeFromJColumnType(JNIEnv* env, jobject jColumnType) { static jfieldID jValueFieldId = GetFieldIDColumnType(env, "nativeValue", "I"); if (jValueFieldId == NULL) - return static_cast(0); + return DataType(0); jint columnType = env->GetIntField(jColumnType, jValueFieldId); - return static_cast(columnType); + return static_cast(columnType); } -jobject GetJColumnTypeFromColumnType(JNIEnv* env, ColumnType columnType) +jobject GetJColumnTypeFromColumnType(JNIEnv* env, DataType columnType) { TR((env, "jni: Enter GetJColumnTypeFromColumnType(%d)\n", columnType)); static jclass jColumnTypeClass = GetClass(env, "com/tightdb/ColumnType"); diff --git a/tightdb_jni/src/columntypeutil.h b/tightdb_jni/src/columntypeutil.h index 640b08b575..88573a3f18 100644 --- a/tightdb_jni/src/columntypeutil.h +++ b/tightdb_jni/src/columntypeutil.h @@ -6,14 +6,14 @@ #ifdef __cplusplus -using tightdb::ColumnType; +using tightdb::DataType; extern "C" { #endif -ColumnType GetColumnTypeFromJColumnType(JNIEnv* env, jobject jColumnType); -jobject GetJColumnTypeFromColumnType(JNIEnv* env, ColumnType columnType); +DataType GetColumnTypeFromJColumnType(JNIEnv* env, jobject jColumnType); +jobject GetJColumnTypeFromColumnType(JNIEnv* env, DataType columnType); #ifdef __cplusplus } diff --git a/tightdb_jni/src/com_tightdb_Group.h b/tightdb_jni/src/com_tightdb_Group.h index a67c559452..01c08c332a 100644 --- a/tightdb_jni/src/com_tightdb_Group.h +++ b/tightdb_jni/src/com_tightdb_Group.h @@ -47,14 +47,6 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_Group_createNative__Ljava_nio_ByteBuffe JNIEXPORT void JNICALL Java_com_tightdb_Group_nativeClose (JNIEnv *, jobject, jlong); -/* - * Class: com_tightdb_Group - * Method: nativeIsValid - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL Java_com_tightdb_Group_nativeIsValid - (JNIEnv *, jobject, jlong); - /* * Class: com_tightdb_Group * Method: nativeGetTableCount diff --git a/tightdb_jni/src/com_tightdb_Table.h b/tightdb_jni/src/com_tightdb_Table.h new file mode 100644 index 0000000000..221976ee13 --- /dev/null +++ b/tightdb_jni/src/com_tightdb_Table.h @@ -0,0 +1,639 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class com_tightdb_Table */ + +#ifndef _Included_com_tightdb_Table +#define _Included_com_tightdb_Table +#ifdef __cplusplus +extern "C" { +#endif +#undef com_tightdb_Table_INFINITE +#define com_tightdb_Table_INFINITE -1i64 +/* + * Class: com_tightdb_Table + * Method: createNative + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_createNative + (JNIEnv *, jobject); + +/* + * Class: com_tightdb_Table + * Method: nativeClose + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeClose + (JNIEnv *, jobject, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeIsValid + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_com_tightdb_Table_nativeIsValid + (JNIEnv *, jobject, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeUpdateFromSpec + * Signature: (JLcom/tightdb/TableSpec;)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeUpdateFromSpec + (JNIEnv *, jobject, jlong, jobject); + +/* + * Class: com_tightdb_Table + * Method: nativeSize + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeSize + (JNIEnv *, jobject, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeClear + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeClear + (JNIEnv *, jobject, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeGetColumnCount + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeGetColumnCount + (JNIEnv *, jobject, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeGetTableSpec + * Signature: (J)Lcom/tightdb/TableSpec; + */ +JNIEXPORT jobject JNICALL Java_com_tightdb_Table_nativeGetTableSpec + (JNIEnv *, jobject, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeGetColumnName + * Signature: (JJ)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_tightdb_Table_nativeGetColumnName + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeGetColumnType + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL Java_com_tightdb_Table_nativeGetColumnType + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeRemove + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeRemove + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeRemoveLast + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeRemoveLast + (JNIEnv *, jobject, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeAddEmptyRow + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeAddEmptyRow + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeInsertFloat + * Signature: (JJJF)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertFloat + (JNIEnv *, jobject, jlong, jlong, jlong, jfloat); + +/* + * Class: com_tightdb_Table + * Method: nativeInsertDouble + * Signature: (JJJD)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertDouble + (JNIEnv *, jobject, jlong, jlong, jlong, jdouble); + +/* + * Class: com_tightdb_Table + * Method: nativeInsertLong + * Signature: (JJJJ)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertLong + (JNIEnv *, jobject, jlong, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeInsertBoolean + * Signature: (JJJZ)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertBoolean + (JNIEnv *, jobject, jlong, jlong, jlong, jboolean); + +/* + * Class: com_tightdb_Table + * Method: nativeInsertDate + * Signature: (JJJJ)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertDate + (JNIEnv *, jobject, jlong, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeInsertString + * Signature: (JJJLjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertString + (JNIEnv *, jobject, jlong, jlong, jlong, jstring); + +/* + * Class: com_tightdb_Table + * Method: nativeInsertMixed + * Signature: (JJJLcom/tightdb/Mixed;)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertMixed + (JNIEnv *, jobject, jlong, jlong, jlong, jobject); + +/* + * Class: com_tightdb_Table + * Method: nativeInsertByteBuffer + * Signature: (JJJLjava/nio/ByteBuffer;)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertByteBuffer + (JNIEnv *, jobject, jlong, jlong, jlong, jobject); + +/* + * Class: com_tightdb_Table + * Method: nativeInsertByteArray + * Signature: (JJJ[B)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertByteArray + (JNIEnv *, jobject, jlong, jlong, jlong, jbyteArray); + +/* + * Class: com_tightdb_Table + * Method: nativeInsertSubTable + * Signature: (JJJ)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertSubTable + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeInsertDone + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertDone + (JNIEnv *, jobject, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeGetLong + * Signature: (JJJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeGetLong + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeGetBoolean + * Signature: (JJJ)Z + */ +JNIEXPORT jboolean JNICALL Java_com_tightdb_Table_nativeGetBoolean + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeGetFloat + * Signature: (JJJ)F + */ +JNIEXPORT jfloat JNICALL Java_com_tightdb_Table_nativeGetFloat + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeGetDouble + * Signature: (JJJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_Table_nativeGetDouble + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeGetDateTime + * Signature: (JJJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeGetDateTime + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeGetString + * Signature: (JJJ)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_tightdb_Table_nativeGetString + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeGetByteBuffer + * Signature: (JJJ)Ljava/nio/ByteBuffer; + */ +JNIEXPORT jobject JNICALL Java_com_tightdb_Table_nativeGetByteBuffer + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeGetByteArray + * Signature: (JJJ)[B + */ +JNIEXPORT jbyteArray JNICALL Java_com_tightdb_Table_nativeGetByteArray + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeGetMixedType + * Signature: (JJJ)I + */ +JNIEXPORT jint JNICALL Java_com_tightdb_Table_nativeGetMixedType + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeGetMixed + * Signature: (JJJ)Lcom/tightdb/Mixed; + */ +JNIEXPORT jobject JNICALL Java_com_tightdb_Table_nativeGetMixed + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeGetSubTable + * Signature: (JJJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeGetSubTable + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeGetSubTableDuringInsert + * Signature: (JJJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeGetSubTableDuringInsert + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeGetSubTableSize + * Signature: (JJJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeGetSubTableSize + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeClearSubTable + * Signature: (JJJ)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeClearSubTable + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeSetLong + * Signature: (JJJJ)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetLong + (JNIEnv *, jobject, jlong, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeSetBoolean + * Signature: (JJJZ)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetBoolean + (JNIEnv *, jobject, jlong, jlong, jlong, jboolean); + +/* + * Class: com_tightdb_Table + * Method: nativeSetFloat + * Signature: (JJJF)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetFloat + (JNIEnv *, jobject, jlong, jlong, jlong, jfloat); + +/* + * Class: com_tightdb_Table + * Method: nativeSetDouble + * Signature: (JJJD)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetDouble + (JNIEnv *, jobject, jlong, jlong, jlong, jdouble); + +/* + * Class: com_tightdb_Table + * Method: nativeSetDate + * Signature: (JJJJ)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetDate + (JNIEnv *, jobject, jlong, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeSetString + * Signature: (JJJLjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetString + (JNIEnv *, jobject, jlong, jlong, jlong, jstring); + +/* + * Class: com_tightdb_Table + * Method: nativeSetByteBuffer + * Signature: (JJJLjava/nio/ByteBuffer;)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetByteBuffer + (JNIEnv *, jobject, jlong, jlong, jlong, jobject); + +/* + * Class: com_tightdb_Table + * Method: nativeSetByteArray + * Signature: (JJJ[B)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetByteArray + (JNIEnv *, jobject, jlong, jlong, jlong, jbyteArray); + +/* + * Class: com_tightdb_Table + * Method: nativeSetMixed + * Signature: (JJJLcom/tightdb/Mixed;)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetMixed + (JNIEnv *, jobject, jlong, jlong, jlong, jobject); + +/* + * Class: com_tightdb_Table + * Method: nativeAddInt + * Signature: (JJJ)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeAddInt + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeSetIndex + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetIndex + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeHasIndex + * Signature: (JJ)Z + */ +JNIEXPORT jboolean JNICALL Java_com_tightdb_Table_nativeHasIndex + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeSum + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeSum + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeMaximum + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeMaximum + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeMinimum + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeMinimum + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeAverage + * Signature: (JJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_Table_nativeAverage + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeSumFloat + * Signature: (JJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_Table_nativeSumFloat + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeMaximumFloat + * Signature: (JJ)F + */ +JNIEXPORT jfloat JNICALL Java_com_tightdb_Table_nativeMaximumFloat + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeMinimumFloat + * Signature: (JJ)F + */ +JNIEXPORT jfloat JNICALL Java_com_tightdb_Table_nativeMinimumFloat + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeAverageFloat + * Signature: (JJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_Table_nativeAverageFloat + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeSumDouble + * Signature: (JJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_Table_nativeSumDouble + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeMaximumDouble + * Signature: (JJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_Table_nativeMaximumDouble + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeMinimumDouble + * Signature: (JJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_Table_nativeMinimumDouble + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeAverageDouble + * Signature: (JJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_Table_nativeAverageDouble + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeWhere + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeWhere + (JNIEnv *, jobject, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeFindFirstInt + * Signature: (JJJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindFirstInt + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeFindFirstBool + * Signature: (JJZ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindFirstBool + (JNIEnv *, jobject, jlong, jlong, jboolean); + +/* + * Class: com_tightdb_Table + * Method: nativeFindFirstFloat + * Signature: (JJF)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindFirstFloat + (JNIEnv *, jobject, jlong, jlong, jfloat); + +/* + * Class: com_tightdb_Table + * Method: nativeFindFirstDouble + * Signature: (JJD)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindFirstDouble + (JNIEnv *, jobject, jlong, jlong, jdouble); + +/* + * Class: com_tightdb_Table + * Method: nativeFindFirstDate + * Signature: (JJJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindFirstDate + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeFindFirstString + * Signature: (JJLjava/lang/String;)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindFirstString + (JNIEnv *, jobject, jlong, jlong, jstring); + +/* + * Class: com_tightdb_Table + * Method: nativeFindAllInt + * Signature: (JJJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindAllInt + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeFindAllBool + * Signature: (JJZ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindAllBool + (JNIEnv *, jobject, jlong, jlong, jboolean); + +/* + * Class: com_tightdb_Table + * Method: nativeFindAllFloat + * Signature: (JJF)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindAllFloat + (JNIEnv *, jobject, jlong, jlong, jfloat); + +/* + * Class: com_tightdb_Table + * Method: nativeFindAllDouble + * Signature: (JJD)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindAllDouble + (JNIEnv *, jobject, jlong, jlong, jdouble); + +/* + * Class: com_tightdb_Table + * Method: nativeFindAllDate + * Signature: (JJJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindAllDate + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeFindAllString + * Signature: (JJLjava/lang/String;)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindAllString + (JNIEnv *, jobject, jlong, jlong, jstring); + +/* + * Class: com_tightdb_Table + * Method: nativeDistinct + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeDistinct + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeOptimize + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeOptimize + (JNIEnv *, jobject, jlong); + +/* + * Class: com_tightdb_Table + * Method: nativeToJson + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_tightdb_Table_nativeToJson + (JNIEnv *, jobject, jlong); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/tightdb_jni/src/com_tightdb_TableBase.h b/tightdb_jni/src/com_tightdb_TableBase.h deleted file mode 100644 index ebc57bba78..0000000000 --- a/tightdb_jni/src/com_tightdb_TableBase.h +++ /dev/null @@ -1,495 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class com_tightdb_TableBase */ - -#ifndef _Included_com_tightdb_TableBase -#define _Included_com_tightdb_TableBase -#ifdef __cplusplus -extern "C" { -#endif -#undef com_tightdb_TableBase_INFINITE -#define com_tightdb_TableBase_INFINITE -1i64 -/* - * Class: com_tightdb_TableBase - * Method: createNative - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_createNative - (JNIEnv *, jobject); - -/* - * Class: com_tightdb_TableBase - * Method: nativeClose - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeClose - (JNIEnv *, jobject, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeIsValid - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL Java_com_tightdb_TableBase_nativeIsValid - (JNIEnv *, jobject, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeUpdateFromSpec - * Signature: (JLcom/tightdb/TableSpec;)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeUpdateFromSpec - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: com_tightdb_TableBase - * Method: nativeSize - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeSize - (JNIEnv *, jobject, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeClear - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeClear - (JNIEnv *, jobject, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeGetColumnCount - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeGetColumnCount - (JNIEnv *, jobject, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeGetTableSpec - * Signature: (J)Lcom/tightdb/TableSpec; - */ -JNIEXPORT jobject JNICALL Java_com_tightdb_TableBase_nativeGetTableSpec - (JNIEnv *, jobject, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeGetColumnName - * Signature: (JJ)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_com_tightdb_TableBase_nativeGetColumnName - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeGetColumnType - * Signature: (JJ)I - */ -JNIEXPORT jint JNICALL Java_com_tightdb_TableBase_nativeGetColumnType - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeAddEmptyRow - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeAddEmptyRow - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeRemove - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeRemove - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeRemoveLast - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeRemoveLast - (JNIEnv *, jobject, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeInsertLong - * Signature: (JJJJ)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertLong - (JNIEnv *, jobject, jlong, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeInsertBoolean - * Signature: (JJJZ)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertBoolean - (JNIEnv *, jobject, jlong, jlong, jlong, jboolean); - -/* - * Class: com_tightdb_TableBase - * Method: nativeInsertDate - * Signature: (JJJJ)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertDate - (JNIEnv *, jobject, jlong, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeInsertString - * Signature: (JJJLjava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertString - (JNIEnv *, jobject, jlong, jlong, jlong, jstring); - -/* - * Class: com_tightdb_TableBase - * Method: nativeInsertMixed - * Signature: (JJJLcom/tightdb/Mixed;)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertMixed - (JNIEnv *, jobject, jlong, jlong, jlong, jobject); - -/* - * Class: com_tightdb_TableBase - * Method: nativeInsertByteBuffer - * Signature: (JJJLjava/nio/ByteBuffer;)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertByteBuffer - (JNIEnv *, jobject, jlong, jlong, jlong, jobject); - -/* - * Class: com_tightdb_TableBase - * Method: nativeInsertByteArray - * Signature: (JJJ[B)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertByteArray - (JNIEnv *, jobject, jlong, jlong, jlong, jbyteArray); - -/* - * Class: com_tightdb_TableBase - * Method: nativeInsertSubTable - * Signature: (JJJ)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertSubTable - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeInsertDone - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertDone - (JNIEnv *, jobject, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeGetLong - * Signature: (JJJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeGetLong - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeGetBoolean - * Signature: (JJJ)Z - */ -JNIEXPORT jboolean JNICALL Java_com_tightdb_TableBase_nativeGetBoolean - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeGetDateTime - * Signature: (JJJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeGetDateTime - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeGetString - * Signature: (JJJ)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_com_tightdb_TableBase_nativeGetString - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeGetByteBuffer - * Signature: (JJJ)Ljava/nio/ByteBuffer; - */ -JNIEXPORT jobject JNICALL Java_com_tightdb_TableBase_nativeGetByteBuffer - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeGetByteArray - * Signature: (JJJ)[B - */ -JNIEXPORT jbyteArray JNICALL Java_com_tightdb_TableBase_nativeGetByteArray - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeGetMixedType - * Signature: (JJJ)I - */ -JNIEXPORT jint JNICALL Java_com_tightdb_TableBase_nativeGetMixedType - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeGetMixed - * Signature: (JJJ)Lcom/tightdb/Mixed; - */ -JNIEXPORT jobject JNICALL Java_com_tightdb_TableBase_nativeGetMixed - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeGetSubTable - * Signature: (JJJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeGetSubTable - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeGetSubTableDuringInsert - * Signature: (JJJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeGetSubTableDuringInsert - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeGetSubTableSize - * Signature: (JJJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeGetSubTableSize - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeClearSubTable - * Signature: (JJJ)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeClearSubTable - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeSetString - * Signature: (JJJLjava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetString - (JNIEnv *, jobject, jlong, jlong, jlong, jstring); - -/* - * Class: com_tightdb_TableBase - * Method: nativeSetLong - * Signature: (JJJJ)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetLong - (JNIEnv *, jobject, jlong, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeSetBoolean - * Signature: (JJJZ)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetBoolean - (JNIEnv *, jobject, jlong, jlong, jlong, jboolean); - -/* - * Class: com_tightdb_TableBase - * Method: nativeSetDate - * Signature: (JJJJ)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetDate - (JNIEnv *, jobject, jlong, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeSetByteBuffer - * Signature: (JJJLjava/nio/ByteBuffer;)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetByteBuffer - (JNIEnv *, jobject, jlong, jlong, jlong, jobject); - -/* - * Class: com_tightdb_TableBase - * Method: nativeSetByteArray - * Signature: (JJJ[B)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetByteArray - (JNIEnv *, jobject, jlong, jlong, jlong, jbyteArray); - -/* - * Class: com_tightdb_TableBase - * Method: nativeSetMixed - * Signature: (JJJLcom/tightdb/Mixed;)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetMixed - (JNIEnv *, jobject, jlong, jlong, jlong, jobject); - -/* - * Class: com_tightdb_TableBase - * Method: nativeAddInt - * Signature: (JJJ)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeAddInt - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeSetIndex - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetIndex - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeHasIndex - * Signature: (JJ)Z - */ -JNIEXPORT jboolean JNICALL Java_com_tightdb_TableBase_nativeHasIndex - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeSum - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeSum - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeMaximum - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeMaximum - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeMinimum - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeMinimum - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeAverage - * Signature: (JJ)D - */ -JNIEXPORT jdouble JNICALL Java_com_tightdb_TableBase_nativeAverage - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeWhere - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeWhere - (JNIEnv *, jobject, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeFindFirstInt - * Signature: (JJJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindFirstInt - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeFindFirstBool - * Signature: (JJZ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindFirstBool - (JNIEnv *, jobject, jlong, jlong, jboolean); - -/* - * Class: com_tightdb_TableBase - * Method: nativeFindFirstDate - * Signature: (JJJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindFirstDate - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeFindFirstString - * Signature: (JJLjava/lang/String;)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindFirstString - (JNIEnv *, jobject, jlong, jlong, jstring); - -/* - * Class: com_tightdb_TableBase - * Method: nativeFindAllInt - * Signature: (JJJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindAllInt - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeFindAllBool - * Signature: (JJZ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindAllBool - (JNIEnv *, jobject, jlong, jlong, jboolean); - -/* - * Class: com_tightdb_TableBase - * Method: nativeFindAllDate - * Signature: (JJJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindAllDate - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeFindAllString - * Signature: (JJLjava/lang/String;)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindAllString - (JNIEnv *, jobject, jlong, jlong, jstring); - -/* - * Class: com_tightdb_TableBase - * Method: nativeDistinct - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeDistinct - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeOptimize - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeOptimize - (JNIEnv *, jobject, jlong); - -/* - * Class: com_tightdb_TableBase - * Method: nativeToJson - * Signature: (J)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_com_tightdb_TableBase_nativeToJson - (JNIEnv *, jobject, jlong); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/tightdb_jni/src/com_tightdb_TableQuery.cpp b/tightdb_jni/src/com_tightdb_TableQuery.cpp index 5794dcdc52..77b0b27424 100644 --- a/tightdb_jni/src/com_tightdb_TableQuery.cpp +++ b/tightdb_jni/src/com_tightdb_TableQuery.cpp @@ -8,6 +8,8 @@ inline Table* Ref2Ptr(TableRef tableref) return &*tableref; } +// Integer + JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeEqual__JJJ( JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jlong value) { @@ -20,42 +22,134 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeNotEqual__JJJ( Q(nativeQueryPtr)->not_equal(S(columnIndex), value); } -JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeGreater( +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeGreater__JJJ( JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jlong value) { Q(nativeQueryPtr)->greater(S(columnIndex), value); } -JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeGreaterEqual( +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeGreaterEqual__JJJ( JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jlong value) { Q(nativeQueryPtr)->greater_equal(S(columnIndex), value); } -JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeLess( +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeLess__JJJ( JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jlong value) { Q(nativeQueryPtr)->less(S(columnIndex), value); } -JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeLessEqual( +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeLessEqual__JJJ( JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jlong value) { Q(nativeQueryPtr)->less_equal(S(columnIndex), value); } -JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeBetween( +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeBetween__JJJJ( JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jlong value1, jlong value2) { Q(nativeQueryPtr)->between(S(columnIndex), value1, value2); } +// Float + +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeEqual__JJF( + JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jfloat value) +{ + Q(nativeQueryPtr)->equal(S(columnIndex), value); +} + +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeNotEqual__JJF( + JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jfloat value) +{ + Q(nativeQueryPtr)->not_equal(S(columnIndex), value); +} + +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeGreater__JJF( + JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jfloat value) +{ + Q(nativeQueryPtr)->greater(S(columnIndex), value); +} + +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeGreaterEqual__JJF( + JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jfloat value) +{ + Q(nativeQueryPtr)->greater_equal(S(columnIndex), value); +} + +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeLess__JJF( + JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jfloat value) +{ + Q(nativeQueryPtr)->less(S(columnIndex), value); +} + +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeLessEqual__JJF( + JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jfloat value) +{ + Q(nativeQueryPtr)->less_equal(S(columnIndex), value); +} + +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeBetween__JJFF( + JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jfloat value1, jfloat value2) +{ + Q(nativeQueryPtr)->between(S(columnIndex), value1, value2); +} + +// Double + +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeEqual__JJD( + JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jdouble value) +{ + Q(nativeQueryPtr)->equal(S(columnIndex), value); +} + +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeNotEqual__JJD( + JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jdouble value) +{ + Q(nativeQueryPtr)->not_equal(S(columnIndex), value); +} + +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeGreater__JJD( + JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jdouble value) +{ + Q(nativeQueryPtr)->greater(S(columnIndex), value); +} + +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeGreaterEqual__JJD( + JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jdouble value) +{ + Q(nativeQueryPtr)->greater_equal(S(columnIndex), value); +} + +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeLess__JJD( + JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jdouble value) +{ + Q(nativeQueryPtr)->less(S(columnIndex), value); +} + +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeLessEqual__JJD( + JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jdouble value) +{ + Q(nativeQueryPtr)->less_equal(S(columnIndex), value); +} + +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeBetween__JJDD( + JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jdouble value1, jdouble value2) +{ + Q(nativeQueryPtr)->between(S(columnIndex), value1, value2); +} + +// Bool + JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeEqual__JJZ( JNIEnv*, jobject, jlong nativeQueryPtr, jlong columnIndex, jboolean value) { Q(nativeQueryPtr)->equal(S(columnIndex), value != 0 ? true : false); } +// String + JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeEqual__JJLjava_lang_String_2Z( JNIEnv* env, jobject, jlong nativeQueryPtr, jlong columnIndex, jstring value, jboolean caseSensitive) { @@ -111,6 +205,8 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeNotEqual__JJLjava_lang_ env->ReleaseStringUTFChars(value, valueCharPtr); } +// General + JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeTableview( JNIEnv*, jobject, jlong nativeQueryPtr, jlong nativeTableViewPtr) { @@ -147,6 +243,8 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeOr( Q(nativeQueryPtr)->Or(); } +// Find + JNIEXPORT jlong JNICALL Java_com_tightdb_TableQuery_nativeFindNext( JNIEnv*, jobject, jlong nativeQueryPtr, jlong lastMatch) { @@ -164,6 +262,11 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableQuery_nativeFindAll( return reinterpret_cast(pResultView); } + +// TODO: Check columnTypes in many methods.. + +// Integer Aggregates + JNIEXPORT jlong JNICALL Java_com_tightdb_TableQuery_nativeSum( JNIEnv* env, jobject, jlong nativeQueryPtr, jlong columnIndex, jlong start, jlong end, jlong limit) @@ -192,8 +295,6 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableQuery_nativeMaximum( return pQuery->maximum(S(columnIndex), NULL, S(start), S(end), S(limit)); } -// TODO: Check columnTypes in many methods.. - JNIEXPORT jlong JNICALL Java_com_tightdb_TableQuery_nativeMinimum( JNIEnv* env, jobject, jlong nativeQueryPtr, jlong columnIndex, jlong start, jlong end, jlong limit) @@ -225,6 +326,129 @@ JNIEXPORT jdouble JNICALL Java_com_tightdb_TableQuery_nativeAverage( return avg; } +// float Aggregates + +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableQuery_nativeSumFloat( + JNIEnv* env, jobject, jlong nativeQueryPtr, + jlong columnIndex, jlong start, jlong end, jlong limit) +{ + Query* pQuery = Q(nativeQueryPtr); + Table* pTable = Ref2Ptr(pQuery->get_table()); + if (!COL_INDEX_VALID(env, pTable, columnIndex)) + return 0; + if (!ROW_INDEXES_VALID(env, pTable, start, end, limit)) + return 0; + + return pQuery->sum_float(S(columnIndex), NULL, S(start), S(end), S(limit)); +} + +JNIEXPORT jfloat JNICALL Java_com_tightdb_TableQuery_nativeMaximumFloat( + JNIEnv* env, jobject, jlong nativeQueryPtr, + jlong columnIndex, jlong start, jlong end, jlong limit) +{ + Query* pQuery = Q(nativeQueryPtr); + Table* pTable = Ref2Ptr(pQuery->get_table()); + if (!COL_INDEX_VALID(env, pTable, columnIndex)) + return 0; + if (!ROW_INDEXES_VALID(env, pTable, start, end, limit)) + return 0; + + return pQuery->maximum_float(S(columnIndex), NULL, S(start), S(end), S(limit)); +} + +JNIEXPORT jfloat JNICALL Java_com_tightdb_TableQuery_nativeMinimumFloat( + JNIEnv* env, jobject, jlong nativeQueryPtr, + jlong columnIndex, jlong start, jlong end, jlong limit) +{ + Query* pQuery = Q(nativeQueryPtr); + Table* pTable = Ref2Ptr(pQuery->get_table()); + if (!COL_INDEX_VALID(env, pTable, columnIndex)) + return 0; + if (!ROW_INDEXES_VALID(env, pTable, start, end, limit)) + return 0; + + return pQuery->minimum_float(S(columnIndex), NULL, S(start), S(end), S(limit)); +} + +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableQuery_nativeAverageFloat( + JNIEnv* env, jobject, jlong nativeQueryPtr, + jlong columnIndex, jlong start, jlong end, jlong limit) +{ + Query* pQuery = Q(nativeQueryPtr); + Table* pTable = Ref2Ptr(pQuery->get_table()); + if (!COL_INDEX_VALID(env, pTable, columnIndex)) + return 0; + if (!ROW_INDEXES_VALID(env, pTable, start, end, limit)) + return 0; + + size_t resultcount; + double avg = pQuery->average_float(S(columnIndex), &resultcount, S(start), S(end), S(limit)); + return avg; +} + +// double Aggregates + +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableQuery_nativeSumDouble( + JNIEnv* env, jobject, jlong nativeQueryPtr, + jlong columnIndex, jlong start, jlong end, jlong limit) +{ + Query* pQuery = Q(nativeQueryPtr); + Table* pTable = Ref2Ptr(pQuery->get_table()); + if (!COL_INDEX_VALID(env, pTable, columnIndex)) + return 0; + if (!ROW_INDEXES_VALID(env, pTable, start, end, limit)) + return 0; + + return pQuery->sum_double(S(columnIndex), NULL, S(start), S(end), S(limit)); +} + +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableQuery_nativeMaximumDouble( + JNIEnv* env, jobject, jlong nativeQueryPtr, + jlong columnIndex, jlong start, jlong end, jlong limit) +{ + Query* pQuery = Q(nativeQueryPtr); + Table* pTable = Ref2Ptr(pQuery->get_table()); + if (!COL_INDEX_VALID(env, pTable, columnIndex)) + return 0; + if (!ROW_INDEXES_VALID(env, pTable, start, end, limit)) + return 0; + + return pQuery->maximum_double(S(columnIndex), NULL, S(start), S(end), S(limit)); +} + +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableQuery_nativeMinimumDouble( + JNIEnv* env, jobject, jlong nativeQueryPtr, + jlong columnIndex, jlong start, jlong end, jlong limit) +{ + Query* pQuery = Q(nativeQueryPtr); + Table* pTable = Ref2Ptr(pQuery->get_table()); + if (!COL_INDEX_VALID(env, pTable, columnIndex)) + return 0; + if (!ROW_INDEXES_VALID(env, pTable, start, end, limit)) + return 0; + + return pQuery->minimum_double(S(columnIndex), NULL, S(start), S(end), S(limit)); +} + +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableQuery_nativeAverageDouble( + JNIEnv* env, jobject, jlong nativeQueryPtr, + jlong columnIndex, jlong start, jlong end, jlong limit) +{ + Query* pQuery = Q(nativeQueryPtr); + Table* pTable = Ref2Ptr(pQuery->get_table()); + if (!COL_INDEX_VALID(env, pTable, columnIndex)) + return 0; + if (!ROW_INDEXES_VALID(env, pTable, start, end, limit)) + return 0; + + size_t resultcount; + double avg = pQuery->average_double(S(columnIndex), &resultcount, S(start), S(end), S(limit)); + return avg; +} + + +// Count + JNIEXPORT jlong JNICALL Java_com_tightdb_TableQuery_nativeCount( JNIEnv* env, jobject, jlong nativeQueryPtr, jlong start, jlong end, jlong limit) { diff --git a/tightdb_jni/src/com_tightdb_TableQuery.h b/tightdb_jni/src/com_tightdb_TableQuery.h index 57ca537424..3c679bc9da 100644 --- a/tightdb_jni/src/com_tightdb_TableQuery.h +++ b/tightdb_jni/src/com_tightdb_TableQuery.h @@ -76,7 +76,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeNotEqual__JJJ * Method: nativeGreater * Signature: (JJJ)V */ -JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeGreater +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeGreater__JJJ (JNIEnv *, jobject, jlong, jlong, jlong); /* @@ -84,7 +84,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeGreater * Method: nativeGreaterEqual * Signature: (JJJ)V */ -JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeGreaterEqual +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeGreaterEqual__JJJ (JNIEnv *, jobject, jlong, jlong, jlong); /* @@ -92,7 +92,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeGreaterEqual * Method: nativeLess * Signature: (JJJ)V */ -JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeLess +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeLess__JJJ (JNIEnv *, jobject, jlong, jlong, jlong); /* @@ -100,7 +100,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeLess * Method: nativeLessEqual * Signature: (JJJ)V */ -JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeLessEqual +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeLessEqual__JJJ (JNIEnv *, jobject, jlong, jlong, jlong); /* @@ -108,9 +108,121 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeLessEqual * Method: nativeBetween * Signature: (JJJJ)V */ -JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeBetween +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeBetween__JJJJ (JNIEnv *, jobject, jlong, jlong, jlong, jlong); +/* + * Class: com_tightdb_TableQuery + * Method: nativeEqual + * Signature: (JJF)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeEqual__JJF + (JNIEnv *, jobject, jlong, jlong, jfloat); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeNotEqual + * Signature: (JJF)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeNotEqual__JJF + (JNIEnv *, jobject, jlong, jlong, jfloat); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeGreater + * Signature: (JJF)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeGreater__JJF + (JNIEnv *, jobject, jlong, jlong, jfloat); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeGreaterEqual + * Signature: (JJF)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeGreaterEqual__JJF + (JNIEnv *, jobject, jlong, jlong, jfloat); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeLess + * Signature: (JJF)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeLess__JJF + (JNIEnv *, jobject, jlong, jlong, jfloat); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeLessEqual + * Signature: (JJF)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeLessEqual__JJF + (JNIEnv *, jobject, jlong, jlong, jfloat); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeBetween + * Signature: (JJFF)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeBetween__JJFF + (JNIEnv *, jobject, jlong, jlong, jfloat, jfloat); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeEqual + * Signature: (JJD)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeEqual__JJD + (JNIEnv *, jobject, jlong, jlong, jdouble); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeNotEqual + * Signature: (JJD)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeNotEqual__JJD + (JNIEnv *, jobject, jlong, jlong, jdouble); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeGreater + * Signature: (JJD)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeGreater__JJD + (JNIEnv *, jobject, jlong, jlong, jdouble); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeGreaterEqual + * Signature: (JJD)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeGreaterEqual__JJD + (JNIEnv *, jobject, jlong, jlong, jdouble); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeLess + * Signature: (JJD)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeLess__JJD + (JNIEnv *, jobject, jlong, jlong, jdouble); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeLessEqual + * Signature: (JJD)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeLessEqual__JJD + (JNIEnv *, jobject, jlong, jlong, jdouble); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeBetween + * Signature: (JJDD)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableQuery_nativeBetween__JJDD + (JNIEnv *, jobject, jlong, jlong, jdouble, jdouble); + /* * Class: com_tightdb_TableQuery * Method: nativeEqual @@ -207,6 +319,70 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableQuery_nativeMinimum JNIEXPORT jdouble JNICALL Java_com_tightdb_TableQuery_nativeAverage (JNIEnv *, jobject, jlong, jlong, jlong, jlong, jlong); +/* + * Class: com_tightdb_TableQuery + * Method: nativeSumFloat + * Signature: (JJJJJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableQuery_nativeSumFloat + (JNIEnv *, jobject, jlong, jlong, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeMaximumFloat + * Signature: (JJJJJ)F + */ +JNIEXPORT jfloat JNICALL Java_com_tightdb_TableQuery_nativeMaximumFloat + (JNIEnv *, jobject, jlong, jlong, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeMinimumFloat + * Signature: (JJJJJ)F + */ +JNIEXPORT jfloat JNICALL Java_com_tightdb_TableQuery_nativeMinimumFloat + (JNIEnv *, jobject, jlong, jlong, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeAverageFloat + * Signature: (JJJJJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableQuery_nativeAverageFloat + (JNIEnv *, jobject, jlong, jlong, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeSumDouble + * Signature: (JJJJJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableQuery_nativeSumDouble + (JNIEnv *, jobject, jlong, jlong, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeMaximumDouble + * Signature: (JJJJJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableQuery_nativeMaximumDouble + (JNIEnv *, jobject, jlong, jlong, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeMinimumDouble + * Signature: (JJJJJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableQuery_nativeMinimumDouble + (JNIEnv *, jobject, jlong, jlong, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableQuery + * Method: nativeAverageDouble + * Signature: (JJJJJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableQuery_nativeAverageDouble + (JNIEnv *, jobject, jlong, jlong, jlong, jlong, jlong); + /* * Class: com_tightdb_TableQuery * Method: nativeCount diff --git a/tightdb_jni/src/com_tightdb_TableView.h b/tightdb_jni/src/com_tightdb_TableView.h new file mode 100644 index 0000000000..d1725f0dd5 --- /dev/null +++ b/tightdb_jni/src/com_tightdb_TableView.h @@ -0,0 +1,445 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class com_tightdb_TableView */ + +#ifndef _Included_com_tightdb_TableView +#define _Included_com_tightdb_TableView +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_tightdb_TableView + * Method: nativeSize + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeSize + (JNIEnv *, jobject, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeGetLong + * Signature: (JJJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeGetLong + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeGetBoolean + * Signature: (JJJ)Z + */ +JNIEXPORT jboolean JNICALL Java_com_tightdb_TableView_nativeGetBoolean + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeGetFloat + * Signature: (JJJ)F + */ +JNIEXPORT jfloat JNICALL Java_com_tightdb_TableView_nativeGetFloat + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeGetDouble + * Signature: (JJJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableView_nativeGetDouble + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeGetDateTimeValue + * Signature: (JJJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeGetDateTimeValue + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeGetString + * Signature: (JJJ)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_tightdb_TableView_nativeGetString + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeGetBinary + * Signature: (JJJ)Ljava/nio/ByteBuffer; + */ +JNIEXPORT jobject JNICALL Java_com_tightdb_TableView_nativeGetBinary + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeGetByteArray + * Signature: (JJJ)[B + */ +JNIEXPORT jbyteArray JNICALL Java_com_tightdb_TableView_nativeGetByteArray + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeGetMixedType + * Signature: (JJJ)I + */ +JNIEXPORT jint JNICALL Java_com_tightdb_TableView_nativeGetMixedType + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeGetMixed + * Signature: (JJJ)Lcom/tightdb/Mixed; + */ +JNIEXPORT jobject JNICALL Java_com_tightdb_TableView_nativeGetMixed + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeGetSubTable + * Signature: (JJJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeGetSubTable + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeGetSubTableSize + * Signature: (JJJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeGetSubTableSize + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeClearSubTable + * Signature: (JJJ)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeClearSubTable + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeSetLong + * Signature: (JJJJ)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSetLong + (JNIEnv *, jobject, jlong, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeSetBoolean + * Signature: (JJJZ)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSetBoolean + (JNIEnv *, jobject, jlong, jlong, jlong, jboolean); + +/* + * Class: com_tightdb_TableView + * Method: nativeSetFloat + * Signature: (JJJF)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSetFloat + (JNIEnv *, jobject, jlong, jlong, jlong, jfloat); + +/* + * Class: com_tightdb_TableView + * Method: nativeSetDouble + * Signature: (JJJD)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSetDouble + (JNIEnv *, jobject, jlong, jlong, jlong, jdouble); + +/* + * Class: com_tightdb_TableView + * Method: nativeSetDateTimeValue + * Signature: (JJJJ)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSetDateTimeValue + (JNIEnv *, jobject, jlong, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeSetString + * Signature: (JJJLjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSetString + (JNIEnv *, jobject, jlong, jlong, jlong, jstring); + +/* + * Class: com_tightdb_TableView + * Method: nativeSetBinary + * Signature: (JJJLjava/nio/ByteBuffer;)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSetBinary + (JNIEnv *, jobject, jlong, jlong, jlong, jobject); + +/* + * Class: com_tightdb_TableView + * Method: nativeSetByteArray + * Signature: (JJJ[B)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSetByteArray + (JNIEnv *, jobject, jlong, jlong, jlong, jbyteArray); + +/* + * Class: com_tightdb_TableView + * Method: nativeSetMixed + * Signature: (JJJLcom/tightdb/Mixed;)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSetMixed + (JNIEnv *, jobject, jlong, jlong, jlong, jobject); + +/* + * Class: com_tightdb_TableView + * Method: nativeAddInt + * Signature: (JJJ)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeAddInt + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeClear + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeClear + (JNIEnv *, jobject, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeRemoveRow + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeRemoveRow + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeFindFirstInt + * Signature: (JJJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindFirstInt + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeFindFirstBool + * Signature: (JJZ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindFirstBool + (JNIEnv *, jobject, jlong, jlong, jboolean); + +/* + * Class: com_tightdb_TableView + * Method: nativeFindFirstFloat + * Signature: (JJF)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindFirstFloat + (JNIEnv *, jobject, jlong, jlong, jfloat); + +/* + * Class: com_tightdb_TableView + * Method: nativeFindFirstDouble + * Signature: (JJD)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindFirstDouble + (JNIEnv *, jobject, jlong, jlong, jdouble); + +/* + * Class: com_tightdb_TableView + * Method: nativeFindFirstDate + * Signature: (JJJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindFirstDate + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeFindFirstString + * Signature: (JJLjava/lang/String;)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindFirstString + (JNIEnv *, jobject, jlong, jlong, jstring); + +/* + * Class: com_tightdb_TableView + * Method: nativeFindAllInt + * Signature: (JJJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindAllInt + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeFindAllBool + * Signature: (JJZ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindAllBool + (JNIEnv *, jobject, jlong, jlong, jboolean); + +/* + * Class: com_tightdb_TableView + * Method: nativeFindAllFloat + * Signature: (JJF)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindAllFloat + (JNIEnv *, jobject, jlong, jlong, jfloat); + +/* + * Class: com_tightdb_TableView + * Method: nativeFindAllDouble + * Signature: (JJD)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindAllDouble + (JNIEnv *, jobject, jlong, jlong, jdouble); + +/* + * Class: com_tightdb_TableView + * Method: nativeFindAllDate + * Signature: (JJJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindAllDate + (JNIEnv *, jobject, jlong, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeFindAllString + * Signature: (JJLjava/lang/String;)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindAllString + (JNIEnv *, jobject, jlong, jlong, jstring); + +/* + * Class: com_tightdb_TableView + * Method: nativeSum + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeSum + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeMaximum + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeMaximum + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeMinimum + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeMinimum + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeAverage + * Signature: (JJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableView_nativeAverage + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeSumFloat + * Signature: (JJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableView_nativeSumFloat + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeMaximumFloat + * Signature: (JJ)F + */ +JNIEXPORT jfloat JNICALL Java_com_tightdb_TableView_nativeMaximumFloat + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeMinimumFloat + * Signature: (JJ)F + */ +JNIEXPORT jfloat JNICALL Java_com_tightdb_TableView_nativeMinimumFloat + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeAverageFloat + * Signature: (JJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableView_nativeAverageFloat + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeSumDouble + * Signature: (JJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableView_nativeSumDouble + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeMaximumDouble + * Signature: (JJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableView_nativeMaximumDouble + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeMinimumDouble + * Signature: (JJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableView_nativeMinimumDouble + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeAverageDouble + * Signature: (JJ)D + */ +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableView_nativeAverageDouble + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeSort + * Signature: (JJZ)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSort + (JNIEnv *, jobject, jlong, jlong, jboolean); + +/* + * Class: com_tightdb_TableView + * Method: createNativeTableView + * Signature: (Lcom/tightdb/Table;J)J + */ +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_createNativeTableView + (JNIEnv *, jobject, jobject, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeClose + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeClose + (JNIEnv *, jobject, jlong); + +/* + * Class: com_tightdb_TableView + * Method: nativeToJson + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_tightdb_TableView_nativeToJson + (JNIEnv *, jobject, jlong); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/tightdb_jni/src/com_tightdb_TableViewBase.h b/tightdb_jni/src/com_tightdb_TableViewBase.h deleted file mode 100644 index 1d9800a99a..0000000000 --- a/tightdb_jni/src/com_tightdb_TableViewBase.h +++ /dev/null @@ -1,317 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class com_tightdb_TableViewBase */ - -#ifndef _Included_com_tightdb_TableViewBase -#define _Included_com_tightdb_TableViewBase -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: com_tightdb_TableViewBase - * Method: nativeSize - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeSize - (JNIEnv *, jobject, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeGetLong - * Signature: (JJJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeGetLong - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeGetBoolean - * Signature: (JJJ)Z - */ -JNIEXPORT jboolean JNICALL Java_com_tightdb_TableViewBase_nativeGetBoolean - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeGetDateTimeValue - * Signature: (JJJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeGetDateTimeValue - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeGetString - * Signature: (JJJ)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_com_tightdb_TableViewBase_nativeGetString - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeGetBinary - * Signature: (JJJ)Ljava/nio/ByteBuffer; - */ -JNIEXPORT jobject JNICALL Java_com_tightdb_TableViewBase_nativeGetBinary - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeGetByteArray - * Signature: (JJJ)[B - */ -JNIEXPORT jbyteArray JNICALL Java_com_tightdb_TableViewBase_nativeGetByteArray - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeGetMixedType - * Signature: (JJJ)I - */ -JNIEXPORT jint JNICALL Java_com_tightdb_TableViewBase_nativeGetMixedType - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeGetMixed - * Signature: (JJJ)Lcom/tightdb/Mixed; - */ -JNIEXPORT jobject JNICALL Java_com_tightdb_TableViewBase_nativeGetMixed - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeGetSubTable - * Signature: (JJJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeGetSubTable - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeGetSubTableSize - * Signature: (JJJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeGetSubTableSize - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeClearSubTable - * Signature: (JJJ)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeClearSubTable - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeSetLong - * Signature: (JJJJ)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeSetLong - (JNIEnv *, jobject, jlong, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeSetBoolean - * Signature: (JJJZ)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeSetBoolean - (JNIEnv *, jobject, jlong, jlong, jlong, jboolean); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeSetDateTimeValue - * Signature: (JJJJ)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeSetDateTimeValue - (JNIEnv *, jobject, jlong, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeSetString - * Signature: (JJJLjava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeSetString - (JNIEnv *, jobject, jlong, jlong, jlong, jstring); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeSetBinary - * Signature: (JJJLjava/nio/ByteBuffer;)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeSetBinary - (JNIEnv *, jobject, jlong, jlong, jlong, jobject); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeSetByteArray - * Signature: (JJJ[B)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeSetByteArray - (JNIEnv *, jobject, jlong, jlong, jlong, jbyteArray); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeSetMixed - * Signature: (JJJLcom/tightdb/Mixed;)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeSetMixed - (JNIEnv *, jobject, jlong, jlong, jlong, jobject); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeAddInt - * Signature: (JJJ)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeAddInt - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeClear - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeClear - (JNIEnv *, jobject, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeRemoveRow - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeRemoveRow - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeFindFirstInt - * Signature: (JJJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindFirstInt - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeFindFirstBool - * Signature: (JJZ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindFirstBool - (JNIEnv *, jobject, jlong, jlong, jboolean); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeFindFirstDate - * Signature: (JJJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindFirstDate - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeFindFirstString - * Signature: (JJLjava/lang/String;)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindFirstString - (JNIEnv *, jobject, jlong, jlong, jstring); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeFindAllInt - * Signature: (JJJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindAllInt - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeFindAllBool - * Signature: (JJZ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindAllBool - (JNIEnv *, jobject, jlong, jlong, jboolean); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeFindAllDate - * Signature: (JJJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindAllDate - (JNIEnv *, jobject, jlong, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeFindAllString - * Signature: (JJLjava/lang/String;)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindAllString - (JNIEnv *, jobject, jlong, jlong, jstring); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeSum - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeSum - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeMaximum - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeMaximum - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeMinimum - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeMinimum - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeAverage - * Signature: (JJ)D - */ -JNIEXPORT jdouble JNICALL Java_com_tightdb_TableViewBase_nativeAverage - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeSort - * Signature: (JJZ)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeSort - (JNIEnv *, jobject, jlong, jlong, jboolean); - -/* - * Class: com_tightdb_TableViewBase - * Method: createNativeTableView - * Signature: (Lcom/tightdb/TableBase;J)J - */ -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_createNativeTableView - (JNIEnv *, jobject, jobject, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeClose - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeClose - (JNIEnv *, jobject, jlong); - -/* - * Class: com_tightdb_TableViewBase - * Method: nativeToJson - * Signature: (J)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_com_tightdb_TableViewBase_nativeToJson - (JNIEnv *, jobject, jlong); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/tightdb_jni/src/com_tightdb_internal_util.cpp b/tightdb_jni/src/com_tightdb_internal_util.cpp index 4456155c3b..b179c9c925 100644 --- a/tightdb_jni/src/com_tightdb_internal_util.cpp +++ b/tightdb_jni/src/com_tightdb_internal_util.cpp @@ -4,7 +4,7 @@ int trace_level = 0; -static int TIGHTDB_JNI_VERSION = 15; +static int TIGHTDB_JNI_VERSION = 16; JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM*, void*) { diff --git a/tightdb_jni/src/com_tightdb_internal_util.h b/tightdb_jni/src/com_tightdb_internal_util.h index cd60f61174..baecdde581 100644 --- a/tightdb_jni/src/com_tightdb_internal_util.h +++ b/tightdb_jni/src/com_tightdb_internal_util.h @@ -8,7 +8,7 @@ extern "C" { #endif #undef com_tightdb_internal_util_REQUIRED_JNI_VERSION -#define com_tightdb_internal_util_REQUIRED_JNI_VERSION 15i64 +#define com_tightdb_internal_util_REQUIRED_JNI_VERSION 16i64 /* * Class: com_tightdb_internal_util * Method: nativeGetMemUsage diff --git a/tightdb_jni/src/com_tightdb_TableBase.cpp b/tightdb_jni/src/com_tightdb_table.cpp similarity index 63% rename from tightdb_jni/src/com_tightdb_TableBase.cpp rename to tightdb_jni/src/com_tightdb_table.cpp index 9709d40b1f..8577089320 100644 --- a/tightdb_jni/src/com_tightdb_TableBase.cpp +++ b/tightdb_jni/src/com_tightdb_table.cpp @@ -1,6 +1,6 @@ #include "util.h" #include "mixedutil.h" -#include "com_tightdb_TableBase.h" +#include "com_tightdb_Table.h" #include "columntypeutil.h" #include "TableSpecUtil.h" #include "java_lang_List_Util.h" @@ -12,7 +12,7 @@ using namespace tightdb; -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeUpdateFromSpec( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeUpdateFromSpec( JNIEnv* env, jobject, jlong nativeTablePtr, jobject jTableSpec) { if (!TABLE_VALID(env, TBL(nativeTablePtr))) return; @@ -24,35 +24,35 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeUpdateFromSpec( pTable->update_from_spec(); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeSize( +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeSize( JNIEnv* env, jobject, jlong nativeTablePtr) { if (!TABLE_VALID(env, TBL(nativeTablePtr))) return 0; return TBL(nativeTablePtr)->size(); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeClear( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeClear( JNIEnv* env, jobject, jlong nativeTablePtr) { if (!TABLE_VALID(env, TBL(nativeTablePtr))) return; TBL(nativeTablePtr)->clear(); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeGetColumnCount( +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeGetColumnCount( JNIEnv* env, jobject, jlong nativeTablePtr) { if (!TABLE_VALID(env, TBL(nativeTablePtr))) return 0; return TBL(nativeTablePtr)->get_column_count(); } -JNIEXPORT jstring JNICALL Java_com_tightdb_TableBase_nativeGetColumnName( +JNIEXPORT jstring JNICALL Java_com_tightdb_Table_nativeGetColumnName( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex) { if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return NULL; return env->NewStringUTF( TBL(nativeTablePtr)->get_column_name( S(columnIndex)) ); } -JNIEXPORT jobject JNICALL Java_com_tightdb_TableBase_nativeGetTableSpec( +JNIEXPORT jobject JNICALL Java_com_tightdb_Table_nativeGetTableSpec( JNIEnv* env, jobject, jlong nativeTablePtr) { if (!TABLE_VALID(env, TBL(nativeTablePtr))) return 0; @@ -73,7 +73,7 @@ JNIEXPORT jobject JNICALL Java_com_tightdb_TableBase_nativeGetTableSpec( return NULL; } -JNIEXPORT jint JNICALL Java_com_tightdb_TableBase_nativeGetColumnType( +JNIEXPORT jint JNICALL Java_com_tightdb_Table_nativeGetColumnType( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex) { if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; @@ -81,7 +81,7 @@ JNIEXPORT jint JNICALL Java_com_tightdb_TableBase_nativeGetColumnType( return static_cast( TBL(nativeTablePtr)->get_column_type( S(columnIndex)) ); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeAddEmptyRow( +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeAddEmptyRow( JNIEnv* env, jobject, jlong nativeTablePtr, jlong rows) { if (!TABLE_VALID(env, TBL(nativeTablePtr))) return 0; @@ -89,7 +89,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeAddEmptyRow( return static_cast( TBL(nativeTablePtr)->add_empty_row( S(rows)) ); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeRemove( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeRemove( JNIEnv* env, jobject, jlong nativeTablePtr, jlong rowIndex) { if (!ROW_INDEX_VALID(env, TBL(nativeTablePtr), rowIndex)) return; @@ -97,7 +97,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeRemove( TBL(nativeTablePtr)->remove(S(rowIndex)); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeRemoveLast( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeRemoveLast( JNIEnv* env, jobject, jlong nativeTablePtr) { if (!TABLE_VALID(env, TBL(nativeTablePtr))) return; @@ -105,7 +105,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeRemoveLast( TBL(nativeTablePtr)->remove_last(); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertLong( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertLong( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jlong value) { if (!INDEX_INSERT_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; @@ -114,7 +114,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertLong( TBL(nativeTablePtr)->insert_int( S(columnIndex), S(rowIndex), value); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertBoolean( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertBoolean( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jboolean value) { if (!INDEX_INSERT_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; @@ -122,7 +122,23 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertBoolean( TBL(nativeTablePtr)->insert_bool( S(columnIndex), S(rowIndex), value != 0 ? true : false); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertDate( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertFloat( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jfloat value) +{ + if (!INDEX_INSERT_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; + + TBL(nativeTablePtr)->insert_float( S(columnIndex), S(rowIndex), value); +} + +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertDouble( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jdouble value) +{ + if (!INDEX_INSERT_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; + + TBL(nativeTablePtr)->insert_double( S(columnIndex), S(rowIndex), value); +} + +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertDate( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jlong dateTimeValue) { if (!INDEX_INSERT_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; @@ -130,7 +146,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertDate( TBL(nativeTablePtr)->insert_date( S(columnIndex), S(rowIndex), static_cast(dateTimeValue)); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertString( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertString( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jstring value) { if (!INDEX_INSERT_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; @@ -142,7 +158,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertString( env->ReleaseStringUTFChars(value, valueCharPtr); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertMixed( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertMixed( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jobject jMixedValue) { if (!INDEX_INSERT_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; @@ -150,7 +166,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertMixed( tbl_nativeDoMixed(&Table::insert_mixed, TBL(nativeTablePtr), env, columnIndex, rowIndex, jMixedValue); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetMixed( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetMixed( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jobject jMixedValue) { if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; @@ -158,7 +174,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetMixed( tbl_nativeDoMixed(&Table::set_mixed, TBL(nativeTablePtr), env, columnIndex, rowIndex, jMixedValue); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertSubTable( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertSubTable( JNIEnv* env, jobject jTable, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_INSERT_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; @@ -168,7 +184,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertSubTable( TBL(nativeTablePtr)->insert_subtable( S(columnIndex), S(rowIndex)); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertDone( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertDone( JNIEnv* env, jobject, jlong nativeTablePtr) { if (!TABLE_VALID(env, TBL(nativeTablePtr))) return; @@ -177,7 +193,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertDone( } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeGetLong( +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeGetLong( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return 0; @@ -185,7 +201,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeGetLong( return TBL(nativeTablePtr)->get_int( S(columnIndex), S(rowIndex)); } -JNIEXPORT jboolean JNICALL Java_com_tightdb_TableBase_nativeGetBoolean( +JNIEXPORT jboolean JNICALL Java_com_tightdb_Table_nativeGetBoolean( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return false; @@ -193,7 +209,23 @@ JNIEXPORT jboolean JNICALL Java_com_tightdb_TableBase_nativeGetBoolean( return TBL(nativeTablePtr)->get_bool( S(columnIndex), S(rowIndex)); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeGetDateTime( +JNIEXPORT jfloat JNICALL Java_com_tightdb_Table_nativeGetFloat( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex) +{ + if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return 0; + + return TBL(nativeTablePtr)->get_float( S(columnIndex), S(rowIndex)); +} + +JNIEXPORT jdouble JNICALL Java_com_tightdb_Table_nativeGetDouble( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex) +{ + if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return 0; + + return TBL(nativeTablePtr)->get_double( S(columnIndex), S(rowIndex)); +} + +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeGetDateTime( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return 0; @@ -201,7 +233,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeGetDateTime( return TBL(nativeTablePtr)->get_date( S(columnIndex), S(rowIndex)); } -JNIEXPORT jstring JNICALL Java_com_tightdb_TableBase_nativeGetString( +JNIEXPORT jstring JNICALL Java_com_tightdb_Table_nativeGetString( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return NULL; @@ -210,7 +242,7 @@ JNIEXPORT jstring JNICALL Java_com_tightdb_TableBase_nativeGetString( return env->NewStringUTF(valueCharPtr); } -JNIEXPORT jobject JNICALL Java_com_tightdb_TableBase_nativeGetByteBuffer( +JNIEXPORT jobject JNICALL Java_com_tightdb_Table_nativeGetByteBuffer( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return NULL; @@ -219,7 +251,7 @@ JNIEXPORT jobject JNICALL Java_com_tightdb_TableBase_nativeGetByteBuffer( return env->NewDirectByteBuffer((void*)data.pointer, data.len); } -JNIEXPORT jbyteArray JNICALL Java_com_tightdb_TableBase_nativeGetByteArray( +JNIEXPORT jbyteArray JNICALL Java_com_tightdb_Table_nativeGetByteArray( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return NULL; @@ -227,16 +259,16 @@ JNIEXPORT jbyteArray JNICALL Java_com_tightdb_TableBase_nativeGetByteArray( return tbl_GetByteArray(env, nativeTablePtr, columnIndex, rowIndex); } -JNIEXPORT jint JNICALL Java_com_tightdb_TableBase_nativeGetMixedType( +JNIEXPORT jint JNICALL Java_com_tightdb_Table_nativeGetMixedType( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return 0; - ColumnType mixedType = TBL(nativeTablePtr)->get_mixed_type( S(columnIndex), S(rowIndex)); + DataType mixedType = TBL(nativeTablePtr)->get_mixed_type( S(columnIndex), S(rowIndex)); return static_cast(mixedType); } -JNIEXPORT jobject JNICALL Java_com_tightdb_TableBase_nativeGetMixed( +JNIEXPORT jobject JNICALL Java_com_tightdb_Table_nativeGetMixed( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return NULL; @@ -245,10 +277,10 @@ JNIEXPORT jobject JNICALL Java_com_tightdb_TableBase_nativeGetMixed( return CreateJMixedFromMixed(env, value); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeGetSubTable( +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeGetSubTable( JNIEnv* env, jobject jTableBase, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex) { - if (!INDEX_AND_TYPE_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex, COLUMN_TYPE_TABLE)) return 0; + if (!INDEX_AND_TYPE_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex, type_Table)) return 0; Table* pSubTable = static_cast(LangBindHelper::get_subtable_ptr(TBL(nativeTablePtr), S(columnIndex), S(rowIndex))); @@ -257,11 +289,11 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeGetSubTable( return (jlong)pSubTable; } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeGetSubTableDuringInsert( +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeGetSubTableDuringInsert( JNIEnv* env, jobject jTableBase, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_AND_TYPE_INSERT_VALID(env, TBL(nativeTablePtr), columnIndex, - rowIndex, COLUMN_TYPE_TABLE)) return 0; + rowIndex, type_Table)) return 0; Table* pSubTable = static_cast(LangBindHelper::get_subtable_ptr_during_insert( TBL(nativeTablePtr), S(columnIndex), S(rowIndex))); @@ -270,28 +302,16 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeGetSubTableDuringInsert return (jlong)pSubTable; } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeGetSubTableSize( +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeGetSubTableSize( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex) { - if (!INDEX_AND_TYPE_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex, COLUMN_TYPE_TABLE)) return 0; + if (!INDEX_AND_TYPE_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex, type_Table)) return 0; return TBL(nativeTablePtr)->get_subtable_size( S(columnIndex), S(rowIndex)); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetString( - JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jstring value) -{ - if (!INDEX_AND_TYPE_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex, COLUMN_TYPE_STRING)) return; - - const char* valueCharPtr = env->GetStringUTFChars(value, NULL); - if (valueCharPtr) { - TBL(nativeTablePtr)->set_string( S(columnIndex), S(rowIndex), valueCharPtr); - env->ReleaseStringUTFChars(value, valueCharPtr); - } -} - -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetLong( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetLong( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jlong value) { if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; @@ -299,7 +319,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetLong( return TBL(nativeTablePtr)->set_int( S(columnIndex), S(rowIndex), value); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetBoolean( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetBoolean( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jboolean value) { if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; @@ -307,7 +327,35 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetBoolean( return TBL(nativeTablePtr)->set_bool( S(columnIndex), S(rowIndex), value == JNI_TRUE ? true : false); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetDate( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetFloat( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jfloat value) +{ + if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; + + return TBL(nativeTablePtr)->set_float( S(columnIndex), S(rowIndex), value); +} + +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetDouble( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jdouble value) +{ + if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; + + return TBL(nativeTablePtr)->set_double( S(columnIndex), S(rowIndex), value); +} + +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetString( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jstring value) +{ + if (!INDEX_AND_TYPE_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex, type_String)) return; + + const char* valueCharPtr = env->GetStringUTFChars(value, NULL); + if (valueCharPtr) { + TBL(nativeTablePtr)->set_string( S(columnIndex), S(rowIndex), valueCharPtr); + env->ReleaseStringUTFChars(value, valueCharPtr); + } +} + +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetDate( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jlong dateTimeValue) { if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; @@ -315,7 +363,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetDate( TBL(nativeTablePtr)->set_date( S(columnIndex), S(rowIndex), dateTimeValue); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetByteBuffer( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetByteBuffer( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jobject byteBuffer) { if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; @@ -323,7 +371,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetByteBuffer( tbl_nativeDoBinary(&Table::set_binary, TBL(nativeTablePtr), env, columnIndex, rowIndex, byteBuffer); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertByteBuffer( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertByteBuffer( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jobject byteBuffer) { if (!INDEX_INSERT_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; @@ -331,7 +379,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertByteBuffer( tbl_nativeDoBinary(&Table::insert_binary, TBL(nativeTablePtr), env, columnIndex, rowIndex, byteBuffer); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetByteArray( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetByteArray( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jbyteArray dataArray) { if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; @@ -339,7 +387,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetByteArray( tbl_nativeDoByteArray(&Table::set_binary, TBL(nativeTablePtr), env, columnIndex, rowIndex, dataArray); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertByteArray( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeInsertByteArray( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex, jbyteArray dataArray) { if (!INDEX_INSERT_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; @@ -347,7 +395,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeInsertByteArray( tbl_nativeDoByteArray(&Table::insert_binary, TBL(nativeTablePtr), env, columnIndex, rowIndex, dataArray); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeAddInt( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeAddInt( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong value) { if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return; @@ -356,7 +404,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeAddInt( } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeClearSubTable( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeClearSubTable( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_VALID(env, TBL(nativeTablePtr), columnIndex, rowIndex)) return; @@ -366,20 +414,20 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeClearSubTable( // Indexing methods: -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeSetIndex( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeSetIndex( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex) { Table* pTable = TBL(nativeTablePtr); if (!COL_INDEX_VALID(env, pTable, columnIndex)) return; - if (pTable->get_column_type(columnIndex) != COLUMN_TYPE_STRING) { + if (pTable->get_column_type(columnIndex) != type_String) { ThrowException(env, IllegalArgument, "Invalid columntype - only string columns are supported."); return; } pTable->set_index( S(columnIndex)); } -JNIEXPORT jboolean JNICALL Java_com_tightdb_TableBase_nativeHasIndex( +JNIEXPORT jboolean JNICALL Java_com_tightdb_Table_nativeHasIndex( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex) { if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return false; @@ -387,9 +435,9 @@ JNIEXPORT jboolean JNICALL Java_com_tightdb_TableBase_nativeHasIndex( return TBL(nativeTablePtr)->has_index( S(columnIndex)); } -// Aggregare methods: +// Aggregare methods for integers -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeSum( +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeSum( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex) { if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; @@ -397,7 +445,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeSum( return TBL(nativeTablePtr)->sum( S(columnIndex)); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeMaximum( +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeMaximum( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex) { if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; @@ -405,7 +453,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeMaximum( return TBL(nativeTablePtr)->maximum( S(columnIndex)); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeMinimum( +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeMinimum( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex) { if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; @@ -413,15 +461,83 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeMinimum( return TBL(nativeTablePtr)->minimum( S(columnIndex)); } -JNIEXPORT jdouble JNICALL Java_com_tightdb_TableBase_nativeAverage( +JNIEXPORT jdouble JNICALL Java_com_tightdb_Table_nativeAverage( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex) { if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; return TBL(nativeTablePtr)->average( S(columnIndex)); } +// Aggregare methods for float + +JNIEXPORT jdouble JNICALL Java_com_tightdb_Table_nativeSumFloat( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex) +{ + if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; + + return TBL(nativeTablePtr)->sum_float( S(columnIndex)); +} + +JNIEXPORT jfloat JNICALL Java_com_tightdb_Table_nativeMaximumFloat( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex) +{ + if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; + + return TBL(nativeTablePtr)->maximum_float( S(columnIndex)); +} + +JNIEXPORT jfloat JNICALL Java_com_tightdb_Table_nativeMinimumFloat( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex) +{ + if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; + + return TBL(nativeTablePtr)->minimum_float( S(columnIndex)); +} + +JNIEXPORT jdouble JNICALL Java_com_tightdb_Table_nativeAverageFloat( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex) +{ + if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; + return TBL(nativeTablePtr)->average_float( S(columnIndex)); +} + + +// Aggregare methods for double + +JNIEXPORT jdouble JNICALL Java_com_tightdb_Table_nativeSumDouble( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex) +{ + if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; + + return TBL(nativeTablePtr)->sum_double( S(columnIndex)); +} + +JNIEXPORT jdouble JNICALL Java_com_tightdb_Table_nativeMaximumDouble( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex) +{ + if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; + + return TBL(nativeTablePtr)->maximum_double( S(columnIndex)); +} + +JNIEXPORT jdouble JNICALL Java_com_tightdb_Table_nativeMinimumDouble( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex) +{ + if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; + + return TBL(nativeTablePtr)->minimum_double( S(columnIndex)); +} -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeWhere( +JNIEXPORT jdouble JNICALL Java_com_tightdb_Table_nativeAverageDouble( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex) +{ + if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; + return TBL(nativeTablePtr)->average_double( S(columnIndex)); +} + +// + +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeWhere( JNIEnv *, jobject, jlong nativeTablePtr) { Query query = TBL(nativeTablePtr)->where(); @@ -429,7 +545,9 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeWhere( return reinterpret_cast(queryPtr); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindFirstInt( +// FindFirst + +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindFirstInt( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong value) { if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; @@ -437,7 +555,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindFirstInt( return TBL(nativeTablePtr)->find_first_int( S(columnIndex), value); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindFirstBool( +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindFirstBool( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jboolean value) { if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return false; @@ -445,7 +563,23 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindFirstBool( return TBL(nativeTablePtr)->find_first_bool( S(columnIndex), value != 0 ? true : false); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindFirstDate( +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindFirstFloat( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jfloat value) +{ + if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; + + return TBL(nativeTablePtr)->find_first_float( S(columnIndex), value); +} + +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindFirstDouble( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jdouble value) +{ + if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; + + return TBL(nativeTablePtr)->find_first_double( S(columnIndex), value); +} + +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindFirstDate( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong dateTimeValue) { if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; @@ -453,7 +587,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindFirstDate( return TBL(nativeTablePtr)->find_first_date( S(columnIndex), (time_t)dateTimeValue); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindFirstString( +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindFirstString( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jstring value) { if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; @@ -467,7 +601,9 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindFirstString( return result; } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindAllInt( +// FindAll + +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindAllInt( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong value) { if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; @@ -476,7 +612,25 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindAllInt( return reinterpret_cast(pTableView); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindAllBool( +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindAllFloat( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jfloat value) +{ + if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; + + TableView* pTableView = new TableView( TBL(nativeTablePtr)->find_all_float( S(columnIndex), value) ); + return reinterpret_cast(pTableView); +} + +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindAllDouble( + JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jdouble value) +{ + if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; + + TableView* pTableView = new TableView( TBL(nativeTablePtr)->find_all_double( S(columnIndex), value) ); + return reinterpret_cast(pTableView); +} + +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindAllBool( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jboolean value) { if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; @@ -486,7 +640,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindAllBool( return reinterpret_cast(pTableView); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindAllDate( +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindAllDate( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jlong dateTimeValue) { if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; @@ -496,7 +650,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindAllDate( return reinterpret_cast(pTableView); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindAllString( +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeFindAllString( JNIEnv* env, jobject, jlong nativeTablePtr, jlong columnIndex, jstring value) { if (!COL_INDEX_VALID(env, TBL(nativeTablePtr), columnIndex)) return 0; @@ -510,7 +664,9 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeFindAllString( return reinterpret_cast(pTableView); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeDistinct( +// + +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_nativeDistinct( JNIEnv *env, jobject, jlong nativeTablePtr, jlong columnIndex) { Table* pTable = TBL(nativeTablePtr); @@ -520,7 +676,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeDistinct( ThrowException(env, UnsupportedOperation, "The column must be indexed before distinct() can be used."); return 0; } - if (pTable->get_column_type(columnIndex) != COLUMN_TYPE_STRING) { + if (pTable->get_column_type(columnIndex) != type_String) { ThrowException(env, IllegalArgument, "Invalid columntype - only string columns are supported."); return 0; } @@ -528,7 +684,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_nativeDistinct( return reinterpret_cast(pTableView); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeOptimize( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeOptimize( JNIEnv* env, jobject, jlong nativeTablePtr) { if (!TABLE_VALID(env, TBL(nativeTablePtr))) return; @@ -536,7 +692,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeOptimize( TBL(nativeTablePtr)->optimize(); } -JNIEXPORT jstring JNICALL Java_com_tightdb_TableBase_nativeToJson( +JNIEXPORT jstring JNICALL Java_com_tightdb_Table_nativeToJson( JNIEnv *env, jobject, jlong nativeTablePtr) { Table* table = TBL(nativeTablePtr); @@ -550,7 +706,7 @@ JNIEXPORT jstring JNICALL Java_com_tightdb_TableBase_nativeToJson( return env->NewStringUTF(str.c_str()); } -JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeClose( +JNIEXPORT void JNICALL Java_com_tightdb_Table_nativeClose( JNIEnv* env, jobject jTable, jlong nativeTablePtr) { if (!TABLE_VALID(env, TBL(nativeTablePtr))) return; @@ -559,13 +715,13 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableBase_nativeClose( LangBindHelper::unbind_table_ref(TBL(nativeTablePtr)); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableBase_createNative(JNIEnv* env, jobject jTable) +JNIEXPORT jlong JNICALL Java_com_tightdb_Table_createNative(JNIEnv* env, jobject jTable) { TR((env, "CreateNative(jTable: %x)\n", jTable)); return reinterpret_cast(LangBindHelper::new_table()); // FIXME: May throw } -JNIEXPORT jboolean JNICALL Java_com_tightdb_TableBase_nativeIsValid( +JNIEXPORT jboolean JNICALL Java_com_tightdb_Table_nativeIsValid( JNIEnv*, jobject, jlong nativeTablePtr) { return TBL(nativeTablePtr)->is_valid(); diff --git a/tightdb_jni/src/com_tightdb_TableViewBase.cpp b/tightdb_jni/src/com_tightdb_tableview.cpp similarity index 54% rename from tightdb_jni/src/com_tightdb_TableViewBase.cpp rename to tightdb_jni/src/com_tightdb_tableview.cpp index 18cb40bc8a..095c16b70b 100644 --- a/tightdb_jni/src/com_tightdb_TableViewBase.cpp +++ b/tightdb_jni/src/com_tightdb_tableview.cpp @@ -1,5 +1,5 @@ #include "util.h" -#include "com_tightdb_TableViewBase.h" +#include "com_tightdb_TableView.h" #include "mixedutil.h" #include "tablebase_tpl.hpp" @@ -7,13 +7,13 @@ using namespace tightdb; -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeSize( +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeSize( JNIEnv*, jobject, jlong nativeViewPtr) { return TV(nativeViewPtr)->size(); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeGetLong( +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeGetLong( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex)) return 0; @@ -21,7 +21,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeGetLong( return TV(nativeViewPtr)->get_int( S(columnIndex), S(rowIndex)); } -JNIEXPORT jboolean JNICALL Java_com_tightdb_TableViewBase_nativeGetBoolean( +JNIEXPORT jboolean JNICALL Java_com_tightdb_TableView_nativeGetBoolean( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex)) return false; @@ -29,7 +29,23 @@ JNIEXPORT jboolean JNICALL Java_com_tightdb_TableViewBase_nativeGetBoolean( return TV(nativeViewPtr)->get_bool( S(columnIndex), S(rowIndex)); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeGetDateTimeValue( +JNIEXPORT jfloat JNICALL Java_com_tightdb_TableView_nativeGetFloat( + JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex) +{ + if (!INDEX_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex)) return 0; + + return TV(nativeViewPtr)->get_float( S(columnIndex), S(rowIndex)); +} + +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableView_nativeGetDouble( + JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex) +{ + if (!INDEX_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex)) return 0; + + return TV(nativeViewPtr)->get_double( S(columnIndex), S(rowIndex)); +} + +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeGetDateTimeValue( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex)) return 0; @@ -37,7 +53,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeGetDateTimeValue( return TV(nativeViewPtr)->get_date( S(columnIndex), S(rowIndex)); } -JNIEXPORT jstring JNICALL Java_com_tightdb_TableViewBase_nativeGetString( +JNIEXPORT jstring JNICALL Java_com_tightdb_TableView_nativeGetString( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex)) return NULL; @@ -45,7 +61,7 @@ JNIEXPORT jstring JNICALL Java_com_tightdb_TableViewBase_nativeGetString( return env->NewStringUTF( TV(nativeViewPtr)->get_string( S(columnIndex), S(rowIndex)) ); } -JNIEXPORT jobject JNICALL Java_com_tightdb_TableViewBase_nativeGetBinary( +JNIEXPORT jobject JNICALL Java_com_tightdb_TableView_nativeGetBinary( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex)) return NULL; @@ -54,7 +70,7 @@ JNIEXPORT jobject JNICALL Java_com_tightdb_TableViewBase_nativeGetBinary( return env->NewDirectByteBuffer((void*)data.pointer, static_cast(data.len)); } -JNIEXPORT jbyteArray JNICALL Java_com_tightdb_TableViewBase_nativeGetByteArray( +JNIEXPORT jbyteArray JNICALL Java_com_tightdb_TableView_nativeGetByteArray( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex)) return NULL; @@ -62,16 +78,16 @@ JNIEXPORT jbyteArray JNICALL Java_com_tightdb_TableViewBase_nativeGetByteArray( return tbl_GetByteArray(env, nativeViewPtr, columnIndex, rowIndex); } -JNIEXPORT jint JNICALL Java_com_tightdb_TableViewBase_nativeGetMixedType( +JNIEXPORT jint JNICALL Java_com_tightdb_TableView_nativeGetMixedType( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex)) return 0; - ColumnType mixedType = TV(nativeViewPtr)->get_mixed_type( S(columnIndex), S(rowIndex)); + DataType mixedType = TV(nativeViewPtr)->get_mixed_type( S(columnIndex), S(rowIndex)); return static_cast(mixedType); } -JNIEXPORT jobject JNICALL Java_com_tightdb_TableViewBase_nativeGetMixed( +JNIEXPORT jobject JNICALL Java_com_tightdb_TableView_nativeGetMixed( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex) { if (!INDEX_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex)) return NULL; @@ -80,51 +96,69 @@ JNIEXPORT jobject JNICALL Java_com_tightdb_TableViewBase_nativeGetMixed( return CreateJMixedFromMixed(env, value); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeGetSubTableSize( +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeGetSubTableSize( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex) { - if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, COLUMN_TYPE_TABLE)) return 0; + if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, type_Table)) return 0; return TV(nativeViewPtr)->get_subtable_size( S(columnIndex), S(rowIndex)); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeGetSubTable( +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeGetSubTable( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex) { - if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, COLUMN_TYPE_TABLE)) return 0; + if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, type_Table)) return 0; Table* pSubTable = LangBindHelper::get_subtable_ptr(TV(nativeViewPtr), S(columnIndex), S(rowIndex)); return reinterpret_cast(pSubTable); } -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeSetLong( +// Setters + +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSetLong( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex, jlong value) { - if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, COLUMN_TYPE_INT)) return; + if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, type_Int)) return; TV(nativeViewPtr)->set_int( S(columnIndex), S(rowIndex), value); } -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeSetBoolean( +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSetBoolean( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex, jboolean value) { - if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, COLUMN_TYPE_BOOL)) return; + if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, type_Bool)) return; TV(nativeViewPtr)->set_bool( S(columnIndex), S(rowIndex), value != 0 ? true : false); } -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeSetDateTimeValue( +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSetFloat( + JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex, jfloat value) +{ + if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, type_Float)) return; + + TV(nativeViewPtr)->set_float( S(columnIndex), S(rowIndex), value); +} + +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSetDouble( + JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex, jdouble value) +{ + if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, type_Double)) return; + + TV(nativeViewPtr)->set_double( S(columnIndex), S(rowIndex), value); +} + +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSetDateTimeValue( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex, jlong dateTimeValue) { - if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, COLUMN_TYPE_DATE)) return; + if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, type_Date)) return; TV(nativeViewPtr)->set_date( S(columnIndex), S(rowIndex), dateTimeValue); } -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeSetString( +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSetString( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex, jstring value) { - if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, COLUMN_TYPE_STRING)) return; + if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, type_String)) return; const char* valueCharPtr = env->GetStringUTFChars(value, NULL); if (!valueCharPtr) @@ -134,32 +168,34 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeSetString( env->ReleaseStringUTFChars(value, valueCharPtr); } -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeSetBinary( +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSetBinary( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex, jobject byteBuffer) { - if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, COLUMN_TYPE_BINARY)) return; + if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, type_Binary)) return; tbl_nativeDoBinary(&TableView::set_binary, TV(nativeViewPtr), env, columnIndex, rowIndex, byteBuffer); } -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeSetByteArray( +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSetByteArray( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex, jbyteArray byteArray) { - if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, COLUMN_TYPE_BINARY)) return; + if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, type_Binary)) return; tbl_nativeDoByteArray(&TableView::set_binary, TV(nativeViewPtr), env, columnIndex, rowIndex, byteArray); } -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeSetMixed( +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSetMixed( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong rowIndex, jobject jMixedValue) { -// TODO !!!! if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, COLUMN_TYPE_MIXED)) return; +// TODO !!!! if (!INDEX_AND_TYPE_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex, type_Mixed)) return; if (!INDEX_VALID(env, TV(nativeViewPtr), columnIndex, rowIndex)) return; tbl_nativeDoMixed(&TableView::set_mixed, TV(nativeViewPtr), env, columnIndex, rowIndex, jMixedValue); } -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeAddInt( + + +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeAddInt( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong value) { if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return; @@ -168,13 +204,13 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeAddInt( } -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeClear( +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeClear( JNIEnv*, jobject, jlong nativeViewPtr) { TV(nativeViewPtr)->clear(); } -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeRemoveRow( +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeRemoveRow( JNIEnv* env, jobject, jlong nativeViewPtr, jlong rowIndex) { if (!ROW_INDEX_VALID(env, TV(nativeViewPtr), rowIndex)) return; @@ -182,7 +218,9 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeRemoveRow( TV(nativeViewPtr)->remove( S(rowIndex)); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindFirstInt( +// FindFirst* + +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindFirstInt( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong value) { if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; @@ -190,7 +228,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindFirstInt( return static_cast(TV(nativeViewPtr)->find_first_int( S(columnIndex), value)); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindFirstBool( +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindFirstBool( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jboolean value) { if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return false; @@ -198,7 +236,23 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindFirstBool( return TV(nativeViewPtr)->find_first_bool( S(columnIndex), value != 0 ? true : false); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindFirstDate( +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindFirstFloat( + JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jfloat value) +{ + if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; + + return static_cast(TV(nativeViewPtr)->find_first_float( S(columnIndex), value)); +} + +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindFirstDouble( + JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jdouble value) +{ + if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; + + return static_cast(TV(nativeViewPtr)->find_first_double( S(columnIndex), value)); +} + +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindFirstDate( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong dateTimeValue) { if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; @@ -206,7 +260,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindFirstDate( return TV(nativeViewPtr)->find_first_date( S(columnIndex), (time_t)dateTimeValue); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindFirstString( +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindFirstString( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jstring value) { if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; @@ -220,7 +274,9 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindFirstString( return static_cast(searchIndex); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindAllInt( +// FindAll* + +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindAllInt( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong value) { if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; @@ -229,7 +285,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindAllInt( return reinterpret_cast(pResultView); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindAllBool( +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindAllBool( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jboolean value) { if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; @@ -239,7 +295,25 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindAllBool( return reinterpret_cast(pResultView); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindAllDate( +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindAllFloat( + JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jfloat value) +{ + if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; + + TableView* pResultView = new TableView( TV(nativeViewPtr)->find_all_float( S(columnIndex), value) ); + return reinterpret_cast(pResultView); +} + +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindAllDouble( + JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jdouble value) +{ + if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; + + TableView* pResultView = new TableView( TV(nativeViewPtr)->find_all_double( S(columnIndex), value) ); + return reinterpret_cast(pResultView); +} + +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindAllDate( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jlong dateTimeValue) { if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; @@ -249,7 +323,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindAllDate( return reinterpret_cast(pResultView); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindAllString( +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeFindAllString( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jstring value) { @@ -266,7 +340,9 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeFindAllString( return reinterpret_cast(pResultView); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeSum( +// Integer aggregates + +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeSum( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex) { if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; @@ -274,7 +350,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeSum( return TV(nativeViewPtr)->sum( S(columnIndex)); } -JNIEXPORT jdouble JNICALL Java_com_tightdb_TableViewBase_nativeAverage( +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableView_nativeAverage( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex) { if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; @@ -283,7 +359,7 @@ JNIEXPORT jdouble JNICALL Java_com_tightdb_TableViewBase_nativeAverage( return static_cast( TV(nativeViewPtr)->sum( S(columnIndex)) ) / TV(nativeViewPtr)->size(); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeMaximum( +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeMaximum( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex) { if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; @@ -291,7 +367,7 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeMaximum( return TV(nativeViewPtr)->maximum( S(columnIndex)); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeMinimum( +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_nativeMinimum( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex) { if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; @@ -299,7 +375,79 @@ JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_nativeMinimum( return TV(nativeViewPtr)->minimum( S(columnIndex)); } -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeSort( +// float aggregates + +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableView_nativeSumFloat( + JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex) +{ + if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; + + return TV(nativeViewPtr)->sum_float( S(columnIndex)); +} + +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableView_nativeAverageFloat( + JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex) +{ + if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; + + // FIXME: Add support for native Average + return TV(nativeViewPtr)->sum_float( S(columnIndex)) / TV(nativeViewPtr)->size(); +} + +JNIEXPORT jfloat JNICALL Java_com_tightdb_TableView_nativeMaximumFloat( + JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex) +{ + if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; + + return TV(nativeViewPtr)->maximum_float( S(columnIndex)); +} + +JNIEXPORT jfloat JNICALL Java_com_tightdb_TableView_nativeMinimumFloat( + JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex) +{ + if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; + + return TV(nativeViewPtr)->minimum_float( S(columnIndex)); +} + +// double aggregates + +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableView_nativeSumDouble( + JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex) +{ + if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; + + return TV(nativeViewPtr)->sum_double( S(columnIndex)); +} + +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableView_nativeAverageDouble( + JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex) +{ + if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; + + // FIXME: Add support for native Average + return static_cast( TV(nativeViewPtr)->sum_double( S(columnIndex)) ) / TV(nativeViewPtr)->size(); +} + +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableView_nativeMaximumDouble( + JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex) +{ + if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; + + return TV(nativeViewPtr)->maximum_double( S(columnIndex)); +} + +JNIEXPORT jdouble JNICALL Java_com_tightdb_TableView_nativeMinimumDouble( + JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex) +{ + if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return 0; + + return TV(nativeViewPtr)->minimum_double( S(columnIndex)); +} + +// sort + +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeSort( JNIEnv* env, jobject, jlong nativeViewPtr, jlong columnIndex, jboolean ascending) { if (!COL_INDEX_VALID(env, TV(nativeViewPtr), columnIndex)) return; @@ -307,7 +455,7 @@ JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeSort( TV(nativeViewPtr)->sort( S(columnIndex), ascending != 0 ? true : false); } -JNIEXPORT jstring JNICALL Java_com_tightdb_TableViewBase_nativeToJson( +JNIEXPORT jstring JNICALL Java_com_tightdb_TableView_nativeToJson( JNIEnv *env, jobject, jlong nativeViewPtr) { TableView* tv = TV(nativeViewPtr); @@ -321,13 +469,13 @@ JNIEXPORT jstring JNICALL Java_com_tightdb_TableViewBase_nativeToJson( return env->NewStringUTF(str.c_str()); } -JNIEXPORT jlong JNICALL Java_com_tightdb_TableViewBase_createNativeTableView( +JNIEXPORT jlong JNICALL Java_com_tightdb_TableView_createNativeTableView( JNIEnv*, jobject, jobject, jlong) { return reinterpret_cast( new TableView() ); } -JNIEXPORT void JNICALL Java_com_tightdb_TableViewBase_nativeClose( +JNIEXPORT void JNICALL Java_com_tightdb_TableView_nativeClose( JNIEnv*, jobject, jlong nativeTableViewPtr) { delete TV(nativeTableViewPtr); diff --git a/tightdb_jni/src/mixedutil.cpp b/tightdb_jni/src/mixedutil.cpp index 96dac3284c..c486551b46 100644 --- a/tightdb_jni/src/mixedutil.cpp +++ b/tightdb_jni/src/mixedutil.cpp @@ -24,16 +24,16 @@ jmethodID GetMixedMethodID(JNIEnv* env, const char* methodStr, const char* typeS return myMethod; } -ColumnType GetMixedObjectType(JNIEnv* env, jobject jMixed) +DataType GetMixedObjectType(JNIEnv* env, jobject jMixed) { // Call Java "Mixed.getType" static jmethodID jGetTypeMethodId = GetMixedMethodID(env, "getType", "()Lcom/tightdb/ColumnType;"); if (jGetTypeMethodId == NULL) - return static_cast(0); + return DataType(0); // ???TODO optimize jobject jColumnType = env->CallObjectMethod(jMixed, jGetTypeMethodId); - return static_cast(GetColumnTypeFromJColumnType(env, jColumnType)); + return static_cast(GetColumnTypeFromJColumnType(env, jColumnType)); } jobject CreateJMixedFromMixed(JNIEnv* env, Mixed& mixed) @@ -44,25 +44,37 @@ jobject CreateJMixedFromMixed(JNIEnv* env, Mixed& mixed) TR((env, "CreateJMixedFromMixed(type %d)\n", mixed.get_type())); switch (mixed.get_type()) { - case COLUMN_TYPE_INT: + case type_Int: { jmethodID consId = GetMixedMethodID(env, "", "(J)V"); if (consId) return env->NewObject(jMixedClass, consId, mixed.get_int()); } - case COLUMN_TYPE_STRING: + case type_Float: + { + jmethodID consId = GetMixedMethodID(env, "", "(F)V"); + if (consId) + return env->NewObject(jMixedClass, consId, mixed.get_float()); + } + case type_Double: + { + jmethodID consId = GetMixedMethodID(env, "", "(D)V"); + if (consId) + return env->NewObject(jMixedClass, consId, mixed.get_double()); + } + case type_String: { jmethodID consId = GetMixedMethodID(env, "", "(Ljava/lang/String;)V"); if (consId) return env->NewObject(jMixedClass, consId, env->NewStringUTF(mixed.get_string())); } - case COLUMN_TYPE_BOOL: + case type_Bool: { jmethodID consId = GetMixedMethodID(env, "", "(Z)V"); if (consId) return env->NewObject(jMixedClass, consId, mixed.get_bool()); } - case COLUMN_TYPE_DATE: + case type_Date: { time_t timeValue = mixed.get_date(); jclass jDateClass = env->FindClass("java/util/Date"); @@ -80,7 +92,7 @@ jobject CreateJMixedFromMixed(JNIEnv* env, Mixed& mixed) if (consId) return env->NewObject(jMixedClass, consId, jDate); } - case COLUMN_TYPE_BINARY: + case type_Binary: { BinaryData binaryData = mixed.get_binary(); jmethodID consId = GetMixedMethodID(env, "", "(Ljava/nio/ByteBuffer;)V"); @@ -89,21 +101,18 @@ jobject CreateJMixedFromMixed(JNIEnv* env, Mixed& mixed) return env->NewObject(jMixedClass, consId, jByteBuffer); } } - case COLUMN_TYPE_TABLE: + case type_Table: { // param input: Table* t. - TR((env, " --Mixed(COLUMN_TYPE_TABLE)\n")); + TR((env, " --Mixed(type_Table)\n")); jmethodID consId = GetMixedMethodID(env, "", "(Lcom/tightdb/ColumnType;)V"); - jobject jColumnType = NULL; // GetJColumnTypeFromColumnType(env, COLUMN_TYPE_TABLE); + jobject jColumnType = NULL; // GetJColumnTypeFromColumnType(env, type_Table); if (consId) return env->NewObject(jMixedClass, consId, jColumnType); } - default: - { - ThrowException(env, IllegalArgument, "Invalid Mixed type."); - TR((env, "\n\nERROR: Mixed type is not supported: %d. \n\n", mixed.get_type())); - } + case type_Mixed: + break; } return NULL; @@ -118,6 +127,24 @@ jlong GetMixedIntValue(JNIEnv* env, jobject jMixed) return 0; } +jfloat GetMixedFloatValue(JNIEnv* env, jobject jMixed) +{ + static jmethodID jGetFloatValueMethodId = GetMixedMethodID(env, "getFloatValue", "()F"); + + if (jGetFloatValueMethodId) + return env->CallFloatMethod(jMixed, jGetFloatValueMethodId); + return 0; +} + +jdouble GetMixedDoubleValue(JNIEnv* env, jobject jMixed) +{ + static jmethodID jGetDoubleValueMethodId = GetMixedMethodID(env, "getDoubleValue", "()D"); + + if (jGetDoubleValueMethodId) + return env->CallDoubleMethod(jMixed, jGetDoubleValueMethodId); + return 0; +} + jstring GetMixedStringValue(JNIEnv* env, jobject jMixed) { static jmethodID jGetStringValueMethodId = GetMixedMethodID(env, "getStringValue", "()Ljava/lang/String;");; diff --git a/tightdb_jni/src/mixedutil.h b/tightdb_jni/src/mixedutil.h index 7995e3a268..e8cbd963e9 100644 --- a/tightdb_jni/src/mixedutil.h +++ b/tightdb_jni/src/mixedutil.h @@ -6,7 +6,7 @@ using namespace tightdb; -ColumnType GetMixedObjectType(JNIEnv* env, jobject jMixed); +DataType GetMixedObjectType(JNIEnv* env, jobject jMixed); jobject CreateJMixedFromMixed(JNIEnv* env, Mixed& mixed); jlong GetMixedIntValue(JNIEnv* env, jobject jMixed); jstring GetMixedStringValue(JNIEnv* env, jobject jMixed); diff --git a/tightdb_jni/src/tablebase_tpl.hpp b/tightdb_jni/src/tablebase_tpl.hpp index ebde00893d..2563472767 100644 --- a/tightdb_jni/src/tablebase_tpl.hpp +++ b/tightdb_jni/src/tablebase_tpl.hpp @@ -49,21 +49,21 @@ void tbl_nativeDoBinary(M doBinary, T* pTable, JNIEnv* env, jlong columnIndex, j template void tbl_nativeDoMixed(M doMixed, T* pTable, JNIEnv* env, jlong columnIndex, jlong rowIndex, jobject jMixedValue) { - ColumnType valueType = GetMixedObjectType(env, jMixedValue); + DataType valueType = GetMixedObjectType(env, jMixedValue); switch(valueType) { - case COLUMN_TYPE_INT: + case type_Int: { jlong longValue = GetMixedIntValue(env, jMixedValue); (pTable->*doMixed)( S(columnIndex), S(rowIndex), Mixed(longValue)); return; } - case COLUMN_TYPE_BOOL: + case type_Bool: { jboolean boolValue = GetMixedBooleanValue(env, jMixedValue); (pTable->*doMixed)( S(columnIndex), S(rowIndex), Mixed(boolValue != 0 ? true : false)); return; } - case COLUMN_TYPE_STRING: + case type_String: { jstring stringValue = GetMixedStringValue(env, jMixedValue); const char* stringCharPtr = env->GetStringUTFChars(stringValue, NULL); @@ -74,14 +74,14 @@ void tbl_nativeDoMixed(M doMixed, T* pTable, JNIEnv* env, jlong columnIndex, jlo } break; } - case COLUMN_TYPE_DATE: + case type_Date: { jlong dateTimeValue = GetMixedDateTimeValue(env, jMixedValue); Date date(dateTimeValue); (pTable->*doMixed)( S(columnIndex), S(rowIndex), Mixed(date)); return; } - case COLUMN_TYPE_BINARY: + case type_Binary: { jint mixedBinaryType = GetMixedBinaryType(env, jMixedValue); if (mixedBinaryType == 0) { @@ -107,15 +107,13 @@ void tbl_nativeDoMixed(M doMixed, T* pTable, JNIEnv* env, jlong columnIndex, jlo } break; // failed } - case COLUMN_TYPE_TABLE: + case type_Table: { (pTable->*doMixed)( S(columnIndex), S(rowIndex), Mixed::subtable_tag()); return; } - default: - { - TR_ERR((env, "ERROR: This type of mixed is not supported yet: %d.", valueType)); - } + case type_Mixed: + break; } TR_ERR((env, "\nERROR: nativeSetMixed() failed.\n")); ThrowException(env, IllegalArgument, "nativeSetMixed()"); diff --git a/tightdb_jni/src/util.h b/tightdb_jni/src/util.h index 4511c7ee51..d47e369d6e 100644 --- a/tightdb_jni/src/util.h +++ b/tightdb_jni/src/util.h @@ -162,7 +162,6 @@ inline bool RowIndexValid(JNIEnv* env, T* pTable, jlong rowIndex) return false; bool rowErr = int_greater_than_or_equal(rowIndex, pTable->size()); if (rowErr) { -// const size_t s = pTable->size(); TR_ERR((env, "rowIndex %lld > %lld - invalid!", S(rowIndex), pTable->size())); ThrowException(env, IndexOutOfBounds, "rowIndex > available rows."); } @@ -211,7 +210,7 @@ inline bool TypeValid(JNIEnv* env, T* pTable, jlong columnIndex, jlong rowIndex, size_t col = static_cast(columnIndex); size_t row = static_cast(rowIndex); int colType = pTable->get_column_type(col); - if (colType == tightdb::COLUMN_TYPE_MIXED) + if (colType == tightdb::type_Mixed) colType = pTable->get_mixed_type(col, row); if (colType != expectColType) { diff --git a/tightdb_jni/tightdb_jni.props b/tightdb_jni/tightdb_jni.props index a8902c93d4..b647a9a7b7 100644 --- a/tightdb_jni/tightdb_jni.props +++ b/tightdb_jni/tightdb_jni.props @@ -14,7 +14,7 @@ $(IntDir)$(TargetName)$(TargetExt).intermediate.manifest - $(tightdb_path)src\ + $(tightdb_path);$(tightdb_path)src\;$(tightdb_path)src\win32\pthread\;$(JAVA_INCLUDE); true $(IntDir)\ $(IntDir)\ diff --git a/tightdb_jni/tightdb_jni.sln b/tightdb_jni/tightdb_jni.sln index aaa61ea9a2..05b06f152f 100644 --- a/tightdb_jni/tightdb_jni.sln +++ b/tightdb_jni/tightdb_jni.sln @@ -21,13 +21,9 @@ Global EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {88BB7EE5-308E-4A8B-F4AD-9A6843CA4AF6}.Debug|Win32.ActiveCfg = Debug|Win32 - {88BB7EE5-308E-4A8B-F4AD-9A6843CA4AF6}.Debug|Win32.Build.0 = Debug|Win32 {88BB7EE5-308E-4A8B-F4AD-9A6843CA4AF6}.Debug|x64.ActiveCfg = Debug|x64 - {88BB7EE5-308E-4A8B-F4AD-9A6843CA4AF6}.Debug|x64.Build.0 = Debug|x64 {88BB7EE5-308E-4A8B-F4AD-9A6843CA4AF6}.Release|Win32.ActiveCfg = Release|Win32 - {88BB7EE5-308E-4A8B-F4AD-9A6843CA4AF6}.Release|Win32.Build.0 = Release|Win32 {88BB7EE5-308E-4A8B-F4AD-9A6843CA4AF6}.Release|x64.ActiveCfg = Release|x64 - {88BB7EE5-308E-4A8B-F4AD-9A6843CA4AF6}.Release|x64.Build.0 = Release|x64 {88BB7EE5-308E-4A8B-F4AD-9A6843CA4AF6}.Static library, debug|Win32.ActiveCfg = Debug|Win32 {88BB7EE5-308E-4A8B-F4AD-9A6843CA4AF6}.Static library, debug|x64.ActiveCfg = Debug|x64 {88BB7EE5-308E-4A8B-F4AD-9A6843CA4AF6}.Static library, debug|x64.Build.0 = Debug|x64 diff --git a/tightdb_jni/tightdb_jni.vcxproj b/tightdb_jni/tightdb_jni.vcxproj index 8b181236f3..b2a926553a 100644 --- a/tightdb_jni/tightdb_jni.vcxproj +++ b/tightdb_jni/tightdb_jni.vcxproj @@ -22,9 +22,9 @@ - + - + @@ -34,9 +34,9 @@ - + - + @@ -127,7 +127,6 @@ Level3 true EditAndContinue - ..\..\..\..\tightdb\src\;$(JAVA_INCLUDE);$(JAVA_INCLUDE)\win32;%(AdditionalIncludeDirectories) TIGHTDB_DEBUG;WIN32;_DEBUG;_WINDOWS;_USRDLL;EXAMPLE_EXPORTS;%(PreprocessorDefinitions) .\Debug\ .\Debug\example.pch @@ -176,7 +175,6 @@ true Level3 ProgramDatabase - $(JAVA_INCLUDE);$(JAVA_INCLUDE)\win32;%(AdditionalIncludeDirectories) TIGHTDB_DEBUG;WIN32;_DEBUG;_WINDOWS;_USRDLL;EXAMPLE_EXPORTS;%(PreprocessorDefinitions) EnableFastChecks 4355;4996 @@ -221,7 +219,6 @@ MaxSpeed true Level3 - ..\..\..\..\tightdb\src\;$(JAVA_INCLUDE);$(JAVA_INCLUDE)\win32;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;EXAMPLE_EXPORTS;%(PreprocessorDefinitions) .\Release\ .\Release\example.pch @@ -272,7 +269,6 @@ MaxSpeed true Level3 - ..\..\..\..\tightdb\src\;$(JAVA_INCLUDE);$(JAVA_INCLUDE)\win32;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;EXAMPLE_EXPORTS;%(PreprocessorDefinitions) .\Release\ .\Release\example.pch diff --git a/tightdb_jni/tightdb_jni.vcxproj.filters b/tightdb_jni/tightdb_jni.vcxproj.filters index 1878f9ee36..4fe1b1f04d 100644 --- a/tightdb_jni/tightdb_jni.vcxproj.filters +++ b/tightdb_jni/tightdb_jni.vcxproj.filters @@ -7,15 +7,9 @@ Source Files - - Source Files - Source Files - - Source Files - Source Files @@ -34,6 +28,12 @@ Source Files + + Source Files + + + Source Files + @@ -42,15 +42,9 @@ Header Files - - Header Files - Header Files - - Header Files - Header Files @@ -69,6 +63,12 @@ Header Files + + Header Files + + + Header Files +