Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING-CHANGES: insertLong(), insertString() etc, moved into public inner class + ColumnType enum renamed #97

Merged
merged 11 commits into from
Sep 3, 2013
Merged
6 changes: 5 additions & 1 deletion doc/changes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
13-August-2013:
===============
+ Table.add() now returns row index of the added row.
+ Table.add() now returns row index of the added row.
! BREAKING CHANGE: Group() now takes a new OpenMode parameter and not a boolean.
It now supports multiple ways to open a group. (ReadOnly, ReadWrite, WriteNoCreate)
+ Added Group.commit()
+ Added Group.equals()

04-August-2013:
===============
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.tightdb.examples.quickbenchmark;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we move this to /experiment folder, since all under examples are distributed to customers.
It would also be good here to test the difference between add() and the local insert() methods.


import java.util.Date;

import com.tightdb.ColumnType;
import com.tightdb.Table;

public class InsertPerformance {

public static void main(String[] args) {

Table t = new Table();


t.addColumn(ColumnType.STRING, "String");
t.addColumn(ColumnType.BOOLEAN, "Bool");
t.addColumn(ColumnType.LONG, "Long");
t.addColumn(ColumnType.DATE, "Date");

Long timer = System.currentTimeMillis();

System.out.println("Performance test for inserting values in table:");

for (int i=0;i<50000000;i++){

t.add("String", false, 4000L, new Date());

if (i % 1000000 == 0 && i > 0){
System.out.println(i + " split time: " + (System.currentTimeMillis() - timer));
}
}

System.out.println("Total time in miliseconds: " + (System.currentTimeMillis() - timer));
}
}
18 changes: 9 additions & 9 deletions tightdb-java-core/src/main/java/com/tightdb/ColumnType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
// FIXME: Add a unit test that verifies the correct correspondance.

public enum ColumnType {
ColumnTypeBool(1),
ColumnTypeInt(0),
ColumnTypeFloat(9),
ColumnTypeDouble(10),
ColumnTypeString(2),
ColumnTypeBinary(4),
ColumnTypeDate(7),
ColumnTypeTable(5),
ColumnTypeMixed(6);
BOOLEAN(1),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider to make the Enums with only first letter Uppercase, and the rest lowercase. That way, it's the same as you write in the typed interface.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is, Enums are constants in java. The convention is to use upper case. See:
http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html

It's correct that it differs from the typed interface differs anyway. But the typed interface is a different animal and also supports simple types e.g. int and long instead of Integer and Long.

LONG(0),
FLOAT(9),
DOUBLE(10),
STRING(2),
BINARY(4),
DATE(7),
TABLE(5),
MIXED(6);
// When adding above, remember to update size of largest number below

private final int nativeValue;
Expand Down
39 changes: 32 additions & 7 deletions tightdb-java-core/src/main/java/com/tightdb/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,30 @@ public Group() {

protected native long createNative();

public Group(String fileName, boolean readOnly) {
this.nativePtr = createNative(fileName, readOnly);
public enum OpenMode {
// Below values must match the values in tightdb::group::OpenMode in C++
READ_ONLY(0),
READ_WRITE(1),
READ_WRITE_NO_CREATE(2);
private int value;
private OpenMode(int value) {
this.value = value;
}
};

public Group(String filepath, OpenMode mode) {
this.nativePtr = createNative(filepath, mode.value);
checkNativePtr();
}

protected native long createNative(String filename, boolean readOnly);
protected native long createNative(String filepath, int value);

public Group(String fileName) {
this(fileName, true);
public Group(String filepath) {
this(filepath, OpenMode.READ_ONLY);
}

public Group(File file) {
this(file.getAbsolutePath(), !file.canWrite());
this(file.getAbsolutePath(), file.canWrite() ? OpenMode.READ_WRITE : OpenMode.READ_ONLY);
}


Expand Down Expand Up @@ -107,7 +118,14 @@ private void verifyGroupIsValid() {
throw new IllegalStateException("Illegal to call methods on a closed Group.");
}


public boolean equals(Object group) {
if (!(group instanceof Group))
return false;
return nativeEquals(nativePtr, ((Group)group).nativePtr);
}

protected native boolean nativeEquals(long nativeGroupPtr, long compareToGroupPtr);

public long size() {
verifyGroupIsValid();
return nativeSize(nativePtr);
Expand Down Expand Up @@ -217,6 +235,13 @@ public ByteBuffer writeToByteBuffer() {
protected native ByteBuffer nativeWriteToByteBuffer(long nativeGroupPtr);
*/

public void commit() {
verifyGroupIsValid();
nativeCommit(nativePtr);
}

protected native void nativeCommit(long nativeGroupPtr);

private void throwImmutable() {
throw new IllegalStateException("Mutable method call during read transaction.");
}
Expand Down
18 changes: 9 additions & 9 deletions tightdb-java-core/src/main/java/com/tightdb/Mixed.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public Mixed(double value) {

public Mixed(ColumnType columnType) {
// It's actually ok to call with any columnType - it will however be assumed to be a ColumnTypeTable.
assert (columnType == null || columnType == ColumnType.ColumnTypeTable);
assert (columnType == null || columnType == ColumnType.TABLE);
this.value = null;
}

Expand Down Expand Up @@ -99,22 +99,22 @@ public boolean equals(Object second) {

public ColumnType getType() {
if (value == null) {
return ColumnType.ColumnTypeTable;
return ColumnType.TABLE;
}
if (value instanceof String)
return ColumnType.ColumnTypeString;
return ColumnType.STRING;
else if (value instanceof Long)
return ColumnType.ColumnTypeInt;
return ColumnType.LONG;
else if (value instanceof Float)
return ColumnType.ColumnTypeFloat;
return ColumnType.FLOAT;
else if (value instanceof Double)
return ColumnType.ColumnTypeDouble;
return ColumnType.DOUBLE;
else if (value instanceof Date)
return ColumnType.ColumnTypeDate;
return ColumnType.DATE;
else if (value instanceof Boolean)
return ColumnType.ColumnTypeBool;
return ColumnType.BOOLEAN;
else if (value instanceof ByteBuffer || (value instanceof byte[])) {
return ColumnType.ColumnTypeBinary;
return ColumnType.BINARY;
}

throw new IllegalStateException("Unknown column type!");
Expand Down
Loading