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 1285e5fe5c..246cc54ea0 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/ColumnType.java +++ b/tightdb-java-core/src/main/java/com/tightdb/ColumnType.java @@ -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), + 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; diff --git a/tightdb-java-core/src/main/java/com/tightdb/Mixed.java b/tightdb-java-core/src/main/java/com/tightdb/Mixed.java index 2d4c3d4aee..2635ab4fe1 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/Mixed.java +++ b/tightdb-java-core/src/main/java/com/tightdb/Mixed.java @@ -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; } @@ -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!"); diff --git a/tightdb-java-core/src/main/java/com/tightdb/Table.java b/tightdb-java-core/src/main/java/com/tightdb/Table.java index 5928a2d6f4..d31ae31900 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/Table.java +++ b/tightdb-java-core/src/main/java/com/tightdb/Table.java @@ -360,34 +360,34 @@ public void insert(long rowIndex, Object... values) { for (long columnIndex = 0; columnIndex < columns; columnIndex++) { Object value = values[(int)columnIndex]; switch (colTypes[(int)columnIndex]) { - case ColumnTypeBool: + case BOOLEAN: nativeInsertBoolean(nativePtr, columnIndex, rowIndex, (Boolean)value); break; - case ColumnTypeInt: + case LONG: nativeInsertLong(nativePtr, columnIndex, rowIndex, ((Number)value).longValue()); break; - case ColumnTypeFloat: + case FLOAT: nativeInsertFloat(nativePtr, columnIndex, rowIndex, ((Float)value).floatValue()); break; - case ColumnTypeDouble: + case DOUBLE: nativeInsertDouble(nativePtr, columnIndex, rowIndex, ((Double)value).doubleValue()); break; - case ColumnTypeString: + case STRING: nativeInsertString(nativePtr, columnIndex, rowIndex, (String)value); break; - case ColumnTypeDate: + case DATE: nativeInsertDate(nativePtr, columnIndex, rowIndex, ((Date)value).getTime()/1000); break; - case ColumnTypeMixed: + case MIXED: nativeInsertMixed(nativePtr, columnIndex, rowIndex, Mixed.mixedValue(value)); break; - case ColumnTypeBinary: + case BINARY: if (value instanceof byte[]) nativeInsertByteArray(nativePtr, columnIndex, rowIndex, (byte[])value); else if (value instanceof ByteBuffer) nativeInsertByteBuffer(nativePtr, columnIndex, rowIndex, (ByteBuffer)value); break; - case ColumnTypeTable: + case TABLE: nativeInsertSubTable(nativePtr, columnIndex, rowIndex); insertSubtableValues(rowIndex, columnIndex, value); break; @@ -395,7 +395,9 @@ else if (value instanceof ByteBuffer) throw new RuntimeException("Unexpected columnType: " + String.valueOf(colTypes[(int)columnIndex])); } } - insertDone(); + //Insert done. Use native, no need to check for immutable again here + nativeInsertDone(nativePtr); + } private void insertSubtableValues(long rowIndex, long columnIndex, Object value) { @@ -445,88 +447,121 @@ public void set(long rowIndex, Object... values) { remove(rowIndex); insert(rowIndex, values); } + + //Instance of the inner class InternalMethods. + private InternalMethods internal = new InternalMethods(); + + //Returns InternalMethods instance with public internal methods. Should only be called by AbstractTable + public InternalMethods getInternalMethods(){ + return this.internal; + } + + + //Holds methods that must be publicly available for AbstractClass. + //Should not be called when using the dynamic interface. The methods can be accessed by calling getInternalMethods() in Table class + public class InternalMethods{ + + public void insertLong(long columnIndex, long rowIndex, long value) { + if (immutable) throwImmutable(); + nativeInsertLong(nativePtr, columnIndex, rowIndex, value); + } + + public void insertDouble(long columnIndex, long rowIndex, double value) { + if (immutable) throwImmutable(); + nativeInsertDouble(nativePtr, columnIndex, rowIndex, value); + } + + public void insertFloat(long columnIndex, long rowIndex, float value) { + if (immutable) throwImmutable(); + nativeInsertFloat(nativePtr, columnIndex, rowIndex, value); + } + + public void insertBoolean(long columnIndex, long rowIndex, boolean value) { + if (immutable) throwImmutable(); + nativeInsertBoolean(nativePtr, columnIndex, rowIndex, value); + } + + public void insertDate(long columnIndex, long rowIndex, Date date) { + if (immutable) throwImmutable(); + nativeInsertDate(nativePtr, columnIndex, rowIndex, date.getTime()/1000); + } + + public void insertString(long columnIndex, long rowIndex, String value) { + if (immutable) throwImmutable(); + nativeInsertString(nativePtr, columnIndex, rowIndex, value); + } + + public void insertMixed(long columnIndex, long rowIndex, Mixed data) { + if (immutable) throwImmutable(); + nativeInsertMixed(nativePtr, columnIndex, rowIndex, data); + } + + 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 + } + + public void insertBinary(long columnIndex, long rowIndex, byte[] data) { + if (immutable) throwImmutable(); + nativeInsertByteArray(nativePtr, columnIndex, rowIndex, data); + } + + public void insertSubTable(long columnIndex, long rowIndex, Object[][] values) { + if (immutable) throwImmutable(); + nativeInsertSubTable(nativePtr, columnIndex, rowIndex); + insertSubtableValues(rowIndex, columnIndex, values); + } + + public void insertDone() { + if (immutable) throwImmutable(); + nativeInsertDone(nativePtr); + } + } - 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); @@ -762,7 +797,7 @@ public void addLong(long columnIndex, long value) { public void setIndex(long columnIndex) { if (immutable) throwImmutable(); - if (getColumnType(columnIndex) != ColumnType.ColumnTypeString) + if (getColumnType(columnIndex) != ColumnType.STRING) throw new IllegalArgumentException("Index is only supported on string columns."); nativeSetIndex(nativePtr, columnIndex); } @@ -969,7 +1004,7 @@ public TableView findAllString(long columnIndex, String value) { // Requires that the first column is a string column with index public long lookup(String value) { - if (!this.hasIndex(0) || this.getColumnType(0) != ColumnType.ColumnTypeString) + if (!this.hasIndex(0) || this.getColumnType(0) != ColumnType.STRING) throw new RuntimeException("lookup() requires index on column 0 which must be a String column."); return nativeLookup(nativePtr, value); } diff --git a/tightdb-java-core/src/main/java/com/tightdb/TableSpec.java b/tightdb-java-core/src/main/java/com/tightdb/TableSpec.java index b1f27f4f0c..c30edeb856 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/TableSpec.java +++ b/tightdb-java-core/src/main/java/com/tightdb/TableSpec.java @@ -14,7 +14,7 @@ public static class ColumnInfo { public ColumnInfo(ColumnType type, String name) { this.name = name; this.type = type; - this.tableSpec = (type == ColumnType.ColumnTypeTable) ? new TableSpec() : null; + this.tableSpec = (type == ColumnType.TABLE) ? new TableSpec() : null; } @Override @@ -73,7 +73,7 @@ public TableSpec addSubtableColumn(String name) { if (name.length() > 63) { throw new IllegalArgumentException("Column names are currently limited to max 63 characters."); } - ColumnInfo columnInfo = new ColumnInfo(ColumnType.ColumnTypeTable, name); + ColumnInfo columnInfo = new ColumnInfo(ColumnType.TABLE, name); columnInfos.add(columnInfo); return columnInfo.tableSpec; } diff --git a/tightdb-java-core/src/main/java/com/tightdb/exceptions/IllegalTypeException.java b/tightdb-java-core/src/main/java/com/tightdb/exceptions/IllegalTypeException.java deleted file mode 100644 index 9ee8ae4ea4..0000000000 --- a/tightdb-java-core/src/main/java/com/tightdb/exceptions/IllegalTypeException.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.tightdb.exceptions; - - -/** - * - * This exception extends RuntimeException, so the developer avoids handling exception each time a value is added to a table. - * - */ -@SuppressWarnings("serial") -public class IllegalTypeException extends RuntimeException{ - - - - public IllegalTypeException(String message) { - super(message); - } - - public IllegalTypeException(String message, Throwable throwable) { - super(message, throwable); - } -} diff --git a/tightdb-java-core/src/main/java/com/tightdb/typed/AbstractTable.java b/tightdb-java-core/src/main/java/com/tightdb/typed/AbstractTable.java index 420878e9cf..f01ecc074e 100644 --- a/tightdb-java-core/src/main/java/com/tightdb/typed/AbstractTable.java +++ b/tightdb-java-core/src/main/java/com/tightdb/typed/AbstractTable.java @@ -94,35 +94,35 @@ public ColumnType getColumnType(long columnIndex) { } protected static void addLongColumn(TableSpec spec, String name) { - spec.addColumn(ColumnType.ColumnTypeInt, name); + spec.addColumn(ColumnType.LONG, name); } protected static void addFloatColumn(TableSpec spec, String name) { - spec.addColumn(ColumnType.ColumnTypeFloat, name); + spec.addColumn(ColumnType.FLOAT, name); } protected static void addDoubleColumn(TableSpec spec, String name) { - spec.addColumn(ColumnType.ColumnTypeDouble, name); + spec.addColumn(ColumnType.DOUBLE, name); } protected static void addStringColumn(TableSpec spec, String name) { - spec.addColumn(ColumnType.ColumnTypeString, name); + spec.addColumn(ColumnType.STRING, name); } protected static void addBooleanColumn(TableSpec spec, String name) { - spec.addColumn(ColumnType.ColumnTypeBool, name); + spec.addColumn(ColumnType.BOOLEAN, name); } protected static void addBinaryColumn(TableSpec spec, String name) { - spec.addColumn(ColumnType.ColumnTypeBinary, name); + spec.addColumn(ColumnType.BINARY, name); } protected static void addDateColumn(TableSpec spec, String name) { - spec.addColumn(ColumnType.ColumnTypeDate, name); + spec.addColumn(ColumnType.DATE, name); } protected static void addMixedColumn(TableSpec spec, String name) { - spec.addColumn(ColumnType.ColumnTypeMixed, name); + spec.addColumn(ColumnType.MIXED, name); } @SuppressWarnings("unchecked") @@ -140,51 +140,51 @@ protected static void specifyTableStructure(Class Tbl createSubtable(Class tableClass) { - set(new Mixed(ColumnType.ColumnTypeTable)); + set(new Mixed(ColumnType.TABLE)); Table subtable = cursor.tableOrView.getSubTable(columnIndex, cursor.getPosition()); return AbstractSubtable.createSubtable(tableClass, subtable); } @@ -75,7 +75,7 @@ public Tbl createSubtable(Class tableClass) { * Check if the subtable (this cursor points at) is the same as the tableClass provided as parameter */ public > boolean isSubtable(Class tableClass) { - if (get().getType() != ColumnType.ColumnTypeTable) { + if (get().getType() != ColumnType.TABLE) { throw new IllegalArgumentException("The mixed value doesn't contain a sub-table!"); } 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 4490685276..246a40221b 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 @@ -11,9 +11,9 @@ public static void main(String[] args) { Table base = new Table(); System.out.println("created table"); - base.addColumn(ColumnType.ColumnTypeString, "name"); - base.addColumn(ColumnType.ColumnTypeInt, "salary"); - base.addColumn(ColumnType.ColumnTypeMixed, "Whatever"); + base.addColumn(ColumnType.STRING, "name"); + base.addColumn(ColumnType.LONG, "salary"); + base.addColumn(ColumnType.MIXED, "Whatever"); System.out.println("specified structure"); base.add("John", 24000, new Mixed(1)); 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 e608428345..a9ef3ade25 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 @@ -11,10 +11,10 @@ public static void main(String[] args) { Table table = new Table(); TableSpec tableSpec = new TableSpec(); - tableSpec.addColumn(ColumnType.ColumnTypeInt, "num"); - tableSpec.addColumn(ColumnType.ColumnTypeMixed, "mix"); + tableSpec.addColumn(ColumnType.LONG, "num"); + tableSpec.addColumn(ColumnType.MIXED, "mix"); TableSpec subspec = tableSpec.addSubtableColumn("subtable"); - subspec.addColumn(ColumnType.ColumnTypeInt, "num"); + subspec.addColumn(ColumnType.LONG, "num"); table.updateFromSpec(tableSpec); try { @@ -26,7 +26,7 @@ public static void main(String[] args) { } table.addEmptyRow(); - table.setMixed(1, 0, new Mixed(ColumnType.ColumnTypeTable)); + table.setMixed(1, 0, new Mixed(ColumnType.TABLE)); Mixed m = table.getMixed(1, 0); ColumnType mt = table.getMixedType(1,0); diff --git a/tightdb-java-example/src/main/java/com/tightdb/refdoc/DynTableIntro.java b/tightdb-java-example/src/main/java/com/tightdb/refdoc/DynTableIntro.java index 3ab5cdd283..e13e7aa86f 100644 --- a/tightdb-java-example/src/main/java/com/tightdb/refdoc/DynTableIntro.java +++ b/tightdb-java-example/src/main/java/com/tightdb/refdoc/DynTableIntro.java @@ -7,9 +7,9 @@ public static void main(String[] args) { // @@Show@@ // Create a basic dynamic table with 3 columns: long, String, Mixed Table tbl = new Table(); - tbl.addColumn(ColumnType.ColumnTypeInt, "myInt"); - tbl.addColumn(ColumnType.ColumnTypeString, "myStr"); - tbl.addColumn(ColumnType.ColumnTypeMixed, "myMixed"); + tbl.addColumn(ColumnType.LONG, "myLONG"); + tbl.addColumn(ColumnType.STRING, "myStr"); + tbl.addColumn(ColumnType.MIXED, "myMixed"); // // Add, delete and set whole Rows @@ -27,7 +27,7 @@ public static void main(String[] args) { Assert(tbl.getLong(0,1) == -15); // get value at column 0, row 2 tbl.setMixed(2, 0, new Mixed("changed Long value to String")); // Inspect the type of Mixed value that was just added: - Assert(tbl.getMixedType(2, 0) == ColumnType.ColumnTypeString); + Assert(tbl.getMixedType(2, 0) == ColumnType.STRING); // Inspect table Assert(tbl.size() == 2); @@ -37,14 +37,14 @@ public static void main(String[] args) { tbl.renameColumn(0, "myLong"); // Rename the first column tbl.removeColumn(1); // Remove the string column tbl.add(42, "this is the mixed column"); // We now got two columns left - tbl.addColumn(ColumnType.ColumnTypeDouble, "myDouble"); + tbl.addColumn(ColumnType.DOUBLE, "myDouble"); tbl.add(-15, "still mixed", 123.45); // Column introspection Assert(tbl.getColumnCount() == 3); Assert(tbl.getColumnName(0).equals("myLong")); Assert(tbl.getColumnIndex("myMixed") == 1); - Assert(tbl.getColumnType(2) == ColumnType.ColumnTypeDouble); + Assert(tbl.getColumnType(2) == ColumnType.DOUBLE); // Do some simple aggregations Assert(tbl.maximumDouble(2) == 123.45); @@ -62,7 +62,7 @@ public static void main(String[] args) { // Set index and get distinct values (currently only works on Strings) Table tbl2 = new Table(); - long strColumn = tbl2.addColumn(ColumnType.ColumnTypeString, "new Strings"); + long strColumn = tbl2.addColumn(ColumnType.STRING, "new Strings"); tbl2.setIndex(strColumn); tbl2.add("MyString"); tbl2.add("MyString2"); @@ -83,10 +83,10 @@ public static void main(String[] args) { // Define schema with 1 String column and one Subtable column with 2 columns TableSpec tableSpec = new TableSpec(); - tableSpec.addColumn(ColumnType.ColumnTypeString,"name"); + tableSpec.addColumn(ColumnType.STRING,"name"); TableSpec subSpec = tableSpec.addSubtableColumn("subtable"); // Subtable: - subSpec.addColumn(ColumnType.ColumnTypeString, "key"); - subSpec.addColumn(ColumnType.ColumnTypeMixed, "value"); + subSpec.addColumn(ColumnType.STRING, "key"); + subSpec.addColumn(ColumnType.MIXED, "value"); // Now apply the schema to the table Table tbl3 = new Table(); tbl3.updateFromSpec(tableSpec); 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 a880605a56..1a863abf79 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNIBinaryTypeTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNIBinaryTypeTest.java @@ -22,14 +22,14 @@ public void init() { table = new Table(); TableSpec tableSpec = new TableSpec(); - tableSpec.addColumn(ColumnType.ColumnTypeBinary, "bin"); + tableSpec.addColumn(ColumnType.BINARY, "bin"); table.updateFromSpec(tableSpec); } @Test public void shouldStoreValuesOfBinaryType_ByteArray() throws Exception { table.add(testArray); - checkBinaryCell(table, 0, 0, ColumnType.ColumnTypeBinary, testArray); + checkBinaryCell(table, 0, 0, ColumnType.BINARY, testArray); } @Test @@ -37,7 +37,7 @@ public void shouldStoreValuesOfBinaryType_ByteBuffer_Direct() throws Exception { ByteBuffer bufDirect = ByteBuffer.allocateDirect(testArray.length); bufDirect.put(testArray); table.add(bufDirect); - checkBinaryCell(table, 0, 0, ColumnType.ColumnTypeBinary, testArray); + checkBinaryCell(table, 0, 0, ColumnType.BINARY, testArray); } // TODO: handle wrap ByteBuffers @@ -47,7 +47,7 @@ public void shouldStoreValuesOfBinaryType_ByteBuffer_wrap() throws Exception { ByteBuffer bufWrap = ByteBuffer.wrap(testArray); table.add(bufWrap); - checkBinaryCell(table, 0, 0, ColumnType.ColumnTypeBinary, testArray); + checkBinaryCell(table, 0, 0, ColumnType.BINARY, testArray); } private void checkBinaryCell(Table table, long col, long row, ColumnType columnType, byte[] value) throws IllegalAccessException { 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 8d01b6e77b..508f36061e 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNIDistinctTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNIDistinctTest.java @@ -11,8 +11,8 @@ public class JNIDistinctTest { void init() { table = new Table(); - table.addColumn(ColumnType.ColumnTypeInt, "number"); - table.addColumn(ColumnType.ColumnTypeString, "name"); + table.addColumn(ColumnType.LONG, "number"); + table.addColumn(ColumnType.STRING, "name"); long i = 0; table.add(0, "A"); 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 d64b0820d6..12d5cfd061 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNIMixedSubtableTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNIMixedSubtableTest.java @@ -11,10 +11,10 @@ public void shouldCreateSubtableInMixedTypeColumn() { Table table = new Table(); TableSpec tableSpec = new TableSpec(); - tableSpec.addColumn(ColumnType.ColumnTypeInt, "num"); - tableSpec.addColumn(ColumnType.ColumnTypeMixed, "mix"); + tableSpec.addColumn(ColumnType.LONG, "num"); + tableSpec.addColumn(ColumnType.MIXED, "mix"); TableSpec subspec = tableSpec.addSubtableColumn("subtable"); - subspec.addColumn(ColumnType.ColumnTypeInt, "num"); + subspec.addColumn(ColumnType.LONG, "num"); table.updateFromSpec(tableSpec); // Shouln't work: no Mixed stored yet @@ -40,14 +40,14 @@ public void shouldCreateSubtableInMixedTypeColumn() { long ROW = 0; // Add empty row - the simple way table.addEmptyRow(); - table.setMixed(1, ROW, new Mixed(ColumnType.ColumnTypeTable)); + table.setMixed(1, ROW, new Mixed(ColumnType.TABLE)); assertEquals(1, table.size()); assertEquals(0, table.getSubTableSize(1, 0)); // Create schema for the one Mixed cell with a subtable Table subtable = table.getSubTable(1, ROW); TableSpec subspecMixed = subtable.getTableSpec(); - subspecMixed.addColumn(ColumnType.ColumnTypeInt, "num"); + subspecMixed.addColumn(ColumnType.LONG, "num"); subtable.updateFromSpec(subspecMixed); // Insert value in the Mixed subtable @@ -65,12 +65,12 @@ public void shouldCreateSubtableInMixedTypeColumn2() { Table table = new Table(); TableSpec tableSpec = new TableSpec(); - tableSpec.addColumn(ColumnType.ColumnTypeInt, "num"); - tableSpec.addColumn(ColumnType.ColumnTypeMixed, "mix"); + tableSpec.addColumn(ColumnType.LONG, "num"); + tableSpec.addColumn(ColumnType.MIXED, "mix"); table.updateFromSpec(tableSpec); table.addEmptyRow(); - table.setMixed(1, 0, new Mixed(ColumnType.ColumnTypeTable)); + table.setMixed(1, 0, new Mixed(ColumnType.TABLE)); 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 8c5f0c48b1..d7abbbd7a0 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNIMixedTypeTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNIMixedTypeTest.java @@ -32,29 +32,29 @@ public void shouldMatchMixedValues(MixedData value1, MixedData value2, @Test(expectedExceptions = IllegalAccessException.class, dataProvider = "columnTypesProvider") public void shouldFailOnWrongTypeRetrieval(ColumnType columnType) throws Exception { - Object value = columnType != ColumnType.ColumnTypeString ? "abc" : 123; + Object value = columnType != ColumnType.STRING ? "abc" : 123; Mixed mixed = Mixed.mixedValue(value); switch (columnType) { - case ColumnTypeBinary: + case BINARY: mixed.getBinaryByteArray(); break; - case ColumnTypeDate: + case DATE: mixed.getDateValue(); break; - case ColumnTypeBool: + case BOOLEAN: mixed.getBooleanValue(); break; - case ColumnTypeInt: + case LONG: mixed.getLongValue(); break; - case ColumnTypeFloat: + case FLOAT: mixed.getFloatValue(); break; - case ColumnTypeDouble: + case DOUBLE: mixed.getDoubleValue(); break; - case ColumnTypeString: + case STRING: mixed.getStringValue(); break; @@ -70,7 +70,7 @@ public void shouldStoreValuesOfMixedType(MixedData value1, Table table = new Table(); TableSpec tableSpec = new TableSpec(); - tableSpec.addColumn(ColumnType.ColumnTypeMixed, "mix"); + tableSpec.addColumn(ColumnType.MIXED, "mix"); table.updateFromSpec(tableSpec); table.add(value1.value); @@ -93,7 +93,7 @@ private void checkMixedCell(Table table, long col, long row, assertEquals(columnType, mixedType); Mixed mixed = table.getMixed(col, row); - if (columnType == ColumnType.ColumnTypeBinary) { + if (columnType == ColumnType.BINARY) { if (mixed.getBinaryType() == Mixed.BINARY_TYPE_BYTE_ARRAY) { // NOTE: We never get here because we always "get" a ByteBuffer. byte[] bin = mixed.getBinaryByteArray(); @@ -115,13 +115,13 @@ private void checkMixedCell(Table table, long col, long row, @DataProvider(name = "mixedValuesProvider") public Iterator mixedValuesProvider() { Object[] values = { - new MixedData(ColumnType.ColumnTypeBool, true), - new MixedData(ColumnType.ColumnTypeString, "abc"), - new MixedData(ColumnType.ColumnTypeInt, 123L), - new MixedData(ColumnType.ColumnTypeFloat, 987.123f), - new MixedData(ColumnType.ColumnTypeDouble, 1234567.898d), - new MixedData(ColumnType.ColumnTypeDate, new Date(645342)), - new MixedData(ColumnType.ColumnTypeBinary, new byte[] { 1, 2, + new MixedData(ColumnType.BOOLEAN, true), + new MixedData(ColumnType.STRING, "abc"), + new MixedData(ColumnType.LONG, 123L), + new MixedData(ColumnType.FLOAT, 987.123f), + new MixedData(ColumnType.DOUBLE, 1234567.898d), + new MixedData(ColumnType.DATE, new Date(645342)), + new MixedData(ColumnType.BINARY, new byte[] { 1, 2, 3, 4, 5 }) }; List mixedValues = Arrays.asList(values); @@ -131,10 +131,10 @@ public Iterator mixedValuesProvider() { @DataProvider(name = "columnTypesProvider") public Object[][] columnTypesProvider() { - Object[][] values = { {ColumnType.ColumnTypeBool}, - {ColumnType.ColumnTypeString}, {ColumnType.ColumnTypeInt}, - {ColumnType.ColumnTypeFloat}, {ColumnType.ColumnTypeDouble}, - {ColumnType.ColumnTypeDate}, {ColumnType.ColumnTypeBinary} }; + Object[][] values = { {ColumnType.BOOLEAN}, + {ColumnType.STRING}, {ColumnType.LONG}, + {ColumnType.FLOAT}, {ColumnType.DOUBLE}, + {ColumnType.DATE}, {ColumnType.BINARY} }; return values; } 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 4c70737302..42a4067fc6 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNIQueryTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNIQueryTest.java @@ -10,8 +10,8 @@ public class JNIQueryTest { void init() { table = new Table(); TableSpec tableSpec = new TableSpec(); - tableSpec.addColumn(ColumnType.ColumnTypeInt, "number"); - tableSpec.addColumn(ColumnType.ColumnTypeString, "name"); + tableSpec.addColumn(ColumnType.LONG, "number"); + tableSpec.addColumn(ColumnType.STRING, "name"); table.updateFromSpec(tableSpec); table.add(10, "A"); diff --git a/tightdb-java-test/src/test/java/com/tightdb/JNISortedLongTest.java b/tightdb-java-test/src/test/java/com/tightdb/JNISortedLongTest.java index 48d6df6046..e0c86f9619 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNISortedLongTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNISortedLongTest.java @@ -8,8 +8,8 @@ public class JNISortedLongTest { void init() { table = new Table(); - table.addColumn(ColumnType.ColumnTypeInt, "number"); - table.addColumn(ColumnType.ColumnTypeString, "name"); + table.addColumn(ColumnType.LONG, "number"); + table.addColumn(ColumnType.STRING, "name"); table.add(1, "A"); table.add(10, "B"); 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 f837b8e0e6..2a327f145e 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNISubtableTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNISubtableTest.java @@ -12,10 +12,10 @@ public void shouldSynchronizeNestedTables() { Table table = group.getTable("emp"); TableSpec tableSpec = new TableSpec(); - tableSpec.addColumn(ColumnType.ColumnTypeString, "name"); + tableSpec.addColumn(ColumnType.STRING, "name"); TableSpec subspec = tableSpec.addSubtableColumn("sub"); - subspec.addColumn(ColumnType.ColumnTypeInt, "num"); + subspec.addColumn(ColumnType.LONG, "num"); table.updateFromSpec(tableSpec); @@ -41,12 +41,12 @@ public void shouldInsertNestedTablesNested() { // Define table TableSpec tableSpec = new TableSpec(); - tableSpec.addColumn(ColumnType.ColumnTypeString, "name"); + tableSpec.addColumn(ColumnType.STRING, "name"); TableSpec subspec = tableSpec.addSubtableColumn("sub"); - subspec.addColumn(ColumnType.ColumnTypeInt, "num"); + subspec.addColumn(ColumnType.LONG, "num"); - tableSpec.addColumn(ColumnType.ColumnTypeInt, "Int"); + tableSpec.addColumn(ColumnType.LONG, "Int"); table.updateFromSpec(tableSpec); // Insert values 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 afa79d0527..0ea7f8c09f 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNITableInsertTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNITableInsertTest.java @@ -45,19 +45,19 @@ public void verifyRow(Table tbl, long rowIndex, Object[] values) { public void ShouldInsertAddAndSetRows() { Table table = new Table(); TableSpec tableSpec = new TableSpec(); - tableSpec.addColumn(ColumnType.ColumnTypeBool, "bool"); - tableSpec.addColumn(ColumnType.ColumnTypeInt, "number"); - tableSpec.addColumn(ColumnType.ColumnTypeString, "string"); - tableSpec.addColumn(ColumnType.ColumnTypeBinary, "Bin"); - tableSpec.addColumn(ColumnType.ColumnTypeDate, "date"); - tableSpec.addColumn(ColumnType.ColumnTypeMixed, "mix"); + tableSpec.addColumn(ColumnType.BOOLEAN, "bool"); + tableSpec.addColumn(ColumnType.LONG, "number"); + tableSpec.addColumn(ColumnType.STRING, "string"); + tableSpec.addColumn(ColumnType.BINARY, "Bin"); + tableSpec.addColumn(ColumnType.DATE, "date"); + tableSpec.addColumn(ColumnType.MIXED, "mix"); TableSpec subspec = tableSpec.addSubtableColumn("sub"); - subspec.addColumn(ColumnType.ColumnTypeInt, "sub-num"); - subspec.addColumn(ColumnType.ColumnTypeString, "sub-str"); + subspec.addColumn(ColumnType.LONG, "sub-num"); + subspec.addColumn(ColumnType.STRING, "sub-str"); table.updateFromSpec(tableSpec); ByteBuffer buf = ByteBuffer.allocateDirect(23); - Mixed mixedSubTable = new Mixed(ColumnType.ColumnTypeTable); + Mixed mixedSubTable = new Mixed(ColumnType.TABLE); Date date = new Date(); long mixed = 123; @@ -107,14 +107,14 @@ public void ShouldInsertAddAndSetRows() { public void ShouldFailInsert() { Table table = new Table(); TableSpec tableSpec = new TableSpec(); - tableSpec.addColumn(ColumnType.ColumnTypeBool, "bool"); - tableSpec.addColumn(ColumnType.ColumnTypeInt, "number"); - tableSpec.addColumn(ColumnType.ColumnTypeString, "string"); - tableSpec.addColumn(ColumnType.ColumnTypeBinary, "Bin"); - tableSpec.addColumn(ColumnType.ColumnTypeDate, "date"); - tableSpec.addColumn(ColumnType.ColumnTypeMixed, "mix"); + tableSpec.addColumn(ColumnType.BOOLEAN, "bool"); + tableSpec.addColumn(ColumnType.LONG, "number"); + tableSpec.addColumn(ColumnType.STRING, "string"); + tableSpec.addColumn(ColumnType.BINARY, "Bin"); + tableSpec.addColumn(ColumnType.DATE, "date"); + tableSpec.addColumn(ColumnType.MIXED, "mix"); TableSpec subspec = tableSpec.addSubtableColumn("sub"); - subspec.addColumn(ColumnType.ColumnTypeInt, "sub-num"); + subspec.addColumn(ColumnType.LONG, "sub-num"); table.updateFromSpec(tableSpec); // Wrong number of parameters diff --git a/tightdb-java-test/src/test/java/com/tightdb/JNITableSpecTest.java b/tightdb-java-test/src/test/java/com/tightdb/JNITableSpecTest.java index 21f890c061..70b892eb8f 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNITableSpecTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNITableSpecTest.java @@ -72,29 +72,29 @@ private List columnTypes() { @Test() public void shouldHandleColumnsDynamically() { Table table = new Table(); - table.addColumn(ColumnType.ColumnTypeInt, "0"); + table.addColumn(ColumnType.LONG, "0"); assertEquals(1, table.getColumnCount()); assertEquals(0, table.getColumnIndex("0")); assertEquals("0", table.getColumnName(0)); - assertEquals(ColumnType.ColumnTypeInt, table.getColumnType(0)); + assertEquals(ColumnType.LONG, table.getColumnType(0)); table.add(23); - table.addColumn(ColumnType.ColumnTypeFloat, "1"); + table.addColumn(ColumnType.FLOAT, "1"); table.add(11, 11.1f); - table.addColumn(ColumnType.ColumnTypeDouble, "2"); + table.addColumn(ColumnType.DOUBLE, "2"); table.add(22, 22.2f, -22.2); - table.addColumn(ColumnType.ColumnTypeBool, "3"); + table.addColumn(ColumnType.BOOLEAN, "3"); table.add(33, 33.3f, -33.3, true); - table.addColumn(ColumnType.ColumnTypeString, "4"); + table.addColumn(ColumnType.STRING, "4"); table.add(44, 44.4f, -44.4, true, "44"); - table.addColumn(ColumnType.ColumnTypeDate, "5"); + table.addColumn(ColumnType.DATE, "5"); Date date = new Date(); table.add(55, 55.5f, -55.5, false, "55", date); - table.addColumn(ColumnType.ColumnTypeBinary, "6"); + table.addColumn(ColumnType.BINARY, "6"); table.add(66, 66.6f, -66.6, false, "66", date, new byte[] {6}); - table.addColumn(ColumnType.ColumnTypeMixed, "7"); + table.addColumn(ColumnType.MIXED, "7"); table.add(77, 77.7f, -77.7, true, "77", date, new byte[] {7, 7}, "mix"); - table.addColumn(ColumnType.ColumnTypeTable, "8"); + table.addColumn(ColumnType.TABLE, "8"); table.add(88, 88.8f, -88.8, false, "88", date, new byte[] {8, 8, 8}, "mixed", null); table.addEmptyRows(10); diff --git a/tightdb-java-test/src/test/java/com/tightdb/JNITransactions.java b/tightdb-java-test/src/test/java/com/tightdb/JNITransactions.java index 8c21e54365..042100b672 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNITransactions.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNITransactions.java @@ -43,8 +43,8 @@ protected void writeOneTransaction(long rows) WriteTransaction trans = db.beginWrite(); Table tbl = trans.getTable("EmployeeTable"); TableSpec tableSpec = new TableSpec(); - tableSpec.addColumn(ColumnType.ColumnTypeString, "name"); - tableSpec.addColumn(ColumnType.ColumnTypeInt, "number"); + tableSpec.addColumn(ColumnType.STRING, "name"); + tableSpec.addColumn(ColumnType.LONG, "number"); tbl.updateFromSpec(tableSpec); for (long row=0; row < rows; row++) diff --git a/tightdb-java-test/src/test/java/com/tightdb/JNIViewSearchTest.java b/tightdb-java-test/src/test/java/com/tightdb/JNIViewSearchTest.java index 351a8c0f53..65f2fdd4d0 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNIViewSearchTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNIViewSearchTest.java @@ -10,7 +10,7 @@ public void shouldSearchByColumnValue() { Table table = new Table(); TableSpec tableSpec = new TableSpec(); - tableSpec.addColumn(ColumnType.ColumnTypeString, "name"); + tableSpec.addColumn(ColumnType.STRING, "name"); table.updateFromSpec(tableSpec); table.add("Foo"); @@ -28,7 +28,7 @@ public void shouldQueryInView() { Table table = new Table(); TableSpec tableSpec = new TableSpec(); - tableSpec.addColumn(ColumnType.ColumnTypeString, "name"); + tableSpec.addColumn(ColumnType.STRING, "name"); table.updateFromSpec(tableSpec); table.add("A1"); diff --git a/tightdb-java-test/src/test/java/com/tightdb/JNIViewSortTest.java b/tightdb-java-test/src/test/java/com/tightdb/JNIViewSortTest.java index d3e1ae4fb3..ae4f045c37 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/JNIViewSortTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/JNIViewSortTest.java @@ -20,17 +20,17 @@ public class JNIViewSortTest { void init() { //Specify table t = new Table(); - t.addColumn(ColumnType.ColumnTypeString, "Name"); - t.addColumn(ColumnType.ColumnTypeBool, "Study"); - t.addColumn(ColumnType.ColumnTypeInt, "Age"); - t.addColumn(ColumnType.ColumnTypeDate, "Birthday"); + t.addColumn(ColumnType.STRING, "Name"); + t.addColumn(ColumnType.BOOLEAN, "Study"); + t.addColumn(ColumnType.LONG, "Age"); + t.addColumn(ColumnType.DATE, "Birthday"); // Add unsupported column types - t.addColumn(ColumnType.ColumnTypeString, "Unsupported0"); - t.addColumn(ColumnType.ColumnTypeFloat, "Unsupported1"); - t.addColumn(ColumnType.ColumnTypeDouble, "Unsupported2"); - t.addColumn(ColumnType.ColumnTypeMixed, "Unsupported3"); - t.addColumn(ColumnType.ColumnTypeTable, "Unsupported4"); + t.addColumn(ColumnType.STRING, "Unsupported0"); + t.addColumn(ColumnType.FLOAT, "Unsupported1"); + t.addColumn(ColumnType.DOUBLE, "Unsupported2"); + t.addColumn(ColumnType.MIXED, "Unsupported3"); + t.addColumn(ColumnType.TABLE, "Unsupported4"); //Add data t.add("cc", true, 24, date1, "", 0.0f, 0.0, 0, null); @@ -119,6 +119,4 @@ public void shouldThrowExceptionForUnsupportedColumns() { } } - - -} \ No newline at end of file +} diff --git a/tightdb-java-test/src/test/java/com/tightdb/TableIndexAndDistinctTest.java b/tightdb-java-test/src/test/java/com/tightdb/TableIndexAndDistinctTest.java new file mode 100644 index 0000000000..1da18abbe1 --- /dev/null +++ b/tightdb-java-test/src/test/java/com/tightdb/TableIndexAndDistinctTest.java @@ -0,0 +1,148 @@ +package com.tightdb; + +import static org.testng.AssertJUnit.*; + +import java.util.Arrays; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import com.tightdb.test.DataProviderUtil; +import com.tightdb.test.TestHelper; + + +@SuppressWarnings("unused") +public class TableIndexAndDistinctTest { + Table table; + + void init() { + table = new Table(); + table.addColumn(ColumnType.LONG, "number"); + table.addColumn(ColumnType.STRING, "name"); + + long i = 0; + table.add(0, "A"); + table.add(1, "B"); + table.add(2, "C"); + table.add(3, "B"); + table.add(4, "D"); + table.add(5, "D"); + table.add(6, "D"); + assertEquals(7, table.size()); + } + + @Test + public void shouldTestDistinct() { + init(); + + // Must set index before using distinct() + table.setIndex(1); + assertEquals(true, table.hasIndex(1)); + + TableView view = table.distinct(1); + assertEquals(4, view.size()); + assertEquals(0, view.getLong(0, 0)); + assertEquals(1, view.getLong(0, 1)); + assertEquals(2, view.getLong(0, 2)); + assertEquals(4, view.getLong(0, 3)); + } + + + + /** + * Should throw exception if trying to get distinct on columns where index has not been set + * @param index + */ + @Test(expectedExceptions = UnsupportedOperationException.class, dataProvider = "columnIndex") + public void shouldTestDistinctErrorWhenNoIndex(Long index) { + + //Get a table with all available column types + Table t = TestHelper.getTableWithAllColumnTypes(); + + TableView view = table.distinct(1); + } + + @Test(expectedExceptions = ArrayIndexOutOfBoundsException.class) + public void shouldTestDistinctErrorWhenIndexOutOfBounds() { + init(); + + TableView view = table.distinct(3); + } + + /** + * Checkd that Index can be set on multiple columns, with the String + * @param index + */ + public void shouldTestSettingIndexOnMultipleColumns() { + + //Create a table only with String type columns + Table t = new Table(); + t.addColumn(ColumnType.STRING, "col1"); + t.addColumn(ColumnType.STRING, "col2"); + t.addColumn(ColumnType.STRING, "col3"); + t.addColumn(ColumnType.STRING, "col4"); + t.addColumn(ColumnType.STRING, "col5"); + t.add("row1", "row2", "row3", "row4", "row5"); + t.add("row1", "row2", "row3", "row4", "row5"); + t.add("row1", "row2", "row3", "row4", "row5"); + t.add("row1", "row2", "row3", "row4", "row5"); + t.add("row1", "row2", "row3", "row4", "row5"); + + for (long c=0;c mixedValuesProvider() { + Long[] values = { + 0L,1L,2L,3L,4L,5L,6L,7L,8L + }; + + List mixedValues = Arrays.asList(values); + return DataProviderUtil.allCombinations(mixedValues); + } +} diff --git a/tightdb-java-test/src/test/java/com/tightdb/TableSpecEqualityTest.java b/tightdb-java-test/src/test/java/com/tightdb/TableSpecEqualityTest.java index 01e5cbf678..f81752f676 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/TableSpecEqualityTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/TableSpecEqualityTest.java @@ -9,12 +9,12 @@ public class TableSpecEqualityTest { @Test public void shouldMatchIdenticalSimpleSpecs() { TableSpec spec1 = new TableSpec(); - spec1.addColumn(ColumnType.ColumnTypeString, "foo"); - spec1.addColumn(ColumnType.ColumnTypeBool, "bar"); + spec1.addColumn(ColumnType.STRING, "foo"); + spec1.addColumn(ColumnType.BOOLEAN, "bar"); TableSpec spec2 = new TableSpec(); - spec2.addColumn(ColumnType.ColumnTypeString, "foo"); - spec2.addColumn(ColumnType.ColumnTypeBool, "bar"); + spec2.addColumn(ColumnType.STRING, "foo"); + spec2.addColumn(ColumnType.BOOLEAN, "bar"); assertTrue(spec1.equals(spec2)); } @@ -22,12 +22,12 @@ public void shouldMatchIdenticalSimpleSpecs() { @Test public void shouldntMatchSpecsWithDifferentColumnNames() { TableSpec spec1 = new TableSpec(); - spec1.addColumn(ColumnType.ColumnTypeString, "foo"); - spec1.addColumn(ColumnType.ColumnTypeBool, "bar"); + spec1.addColumn(ColumnType.STRING, "foo"); + spec1.addColumn(ColumnType.BOOLEAN, "bar"); TableSpec spec2 = new TableSpec(); - spec2.addColumn(ColumnType.ColumnTypeString, "foo"); - spec2.addColumn(ColumnType.ColumnTypeBool, "bar2"); + spec2.addColumn(ColumnType.STRING, "foo"); + spec2.addColumn(ColumnType.BOOLEAN, "bar2"); assertFalse(spec1.equals(spec2)); } @@ -35,12 +35,12 @@ public void shouldntMatchSpecsWithDifferentColumnNames() { @Test public void shouldntMatchSpecsWithDifferentColumnTypes() { TableSpec spec1 = new TableSpec(); - spec1.addColumn(ColumnType.ColumnTypeString, "foo"); - spec1.addColumn(ColumnType.ColumnTypeBool, "bar"); + spec1.addColumn(ColumnType.STRING, "foo"); + spec1.addColumn(ColumnType.BOOLEAN, "bar"); TableSpec spec2 = new TableSpec(); - spec2.addColumn(ColumnType.ColumnTypeString, "foo"); - spec2.addColumn(ColumnType.ColumnTypeBinary, "bar"); + spec2.addColumn(ColumnType.STRING, "foo"); + spec2.addColumn(ColumnType.BINARY, "bar"); assertFalse(spec1.equals(spec2)); } @@ -48,18 +48,18 @@ public void shouldntMatchSpecsWithDifferentColumnTypes() { @Test public void shouldMatchDeepRecursiveIdenticalSpecs() { TableSpec spec1 = new TableSpec(); - spec1.addColumn(ColumnType.ColumnTypeString, "foo"); - spec1.addColumn(ColumnType.ColumnTypeTable, "bar"); - spec1.getSubtableSpec(1).addColumn(ColumnType.ColumnTypeInt, "x"); - spec1.getSubtableSpec(1).addColumn(ColumnType.ColumnTypeTable, "sub"); - spec1.getSubtableSpec(1).getSubtableSpec(1).addColumn(ColumnType.ColumnTypeBool, "b"); + spec1.addColumn(ColumnType.STRING, "foo"); + spec1.addColumn(ColumnType.TABLE, "bar"); + spec1.getSubtableSpec(1).addColumn(ColumnType.LONG, "x"); + spec1.getSubtableSpec(1).addColumn(ColumnType.TABLE, "sub"); + spec1.getSubtableSpec(1).getSubtableSpec(1).addColumn(ColumnType.BOOLEAN, "b"); TableSpec spec2 = new TableSpec(); - spec2.addColumn(ColumnType.ColumnTypeString, "foo"); - spec2.addColumn(ColumnType.ColumnTypeTable, "bar"); - spec2.getSubtableSpec(1).addColumn(ColumnType.ColumnTypeInt, "x"); - spec2.getSubtableSpec(1).addColumn(ColumnType.ColumnTypeTable, "sub"); - spec2.getSubtableSpec(1).getSubtableSpec(1).addColumn(ColumnType.ColumnTypeBool, "b"); + spec2.addColumn(ColumnType.STRING, "foo"); + spec2.addColumn(ColumnType.TABLE, "bar"); + spec2.getSubtableSpec(1).addColumn(ColumnType.LONG, "x"); + spec2.getSubtableSpec(1).addColumn(ColumnType.TABLE, "sub"); + spec2.getSubtableSpec(1).getSubtableSpec(1).addColumn(ColumnType.BOOLEAN, "b"); assertTrue(spec1.equals(spec2)); } @@ -67,18 +67,18 @@ public void shouldMatchDeepRecursiveIdenticalSpecs() { @Test public void shouldntMatchDeepRecursiveDifferentSpecs() { TableSpec spec1 = new TableSpec(); - spec1.addColumn(ColumnType.ColumnTypeString, "foo"); - spec1.addColumn(ColumnType.ColumnTypeTable, "bar"); - spec1.getSubtableSpec(1).addColumn(ColumnType.ColumnTypeInt, "x"); - spec1.getSubtableSpec(1).addColumn(ColumnType.ColumnTypeTable, "sub"); - spec1.getSubtableSpec(1).getSubtableSpec(1).addColumn(ColumnType.ColumnTypeBool, "b"); + spec1.addColumn(ColumnType.STRING, "foo"); + spec1.addColumn(ColumnType.TABLE, "bar"); + spec1.getSubtableSpec(1).addColumn(ColumnType.LONG, "x"); + spec1.getSubtableSpec(1).addColumn(ColumnType.TABLE, "sub"); + spec1.getSubtableSpec(1).getSubtableSpec(1).addColumn(ColumnType.BOOLEAN, "b"); TableSpec spec2 = new TableSpec(); - spec2.addColumn(ColumnType.ColumnTypeString, "foo"); - spec2.addColumn(ColumnType.ColumnTypeTable, "bar"); - spec2.getSubtableSpec(1).addColumn(ColumnType.ColumnTypeInt, "x"); - spec2.getSubtableSpec(1).addColumn(ColumnType.ColumnTypeTable, "sub2"); - spec2.getSubtableSpec(1).getSubtableSpec(1).addColumn(ColumnType.ColumnTypeBool, "b"); + spec2.addColumn(ColumnType.STRING, "foo"); + spec2.addColumn(ColumnType.TABLE, "bar"); + spec2.getSubtableSpec(1).addColumn(ColumnType.LONG, "x"); + spec2.getSubtableSpec(1).addColumn(ColumnType.TABLE, "sub2"); + spec2.getSubtableSpec(1).getSubtableSpec(1).addColumn(ColumnType.BOOLEAN, "b"); assertFalse(spec1.equals(spec2)); } diff --git a/tightdb-java-test/src/test/java/com/tightdb/experiment/ColumnTypeQueryTest.java b/tightdb-java-test/src/test/java/com/tightdb/experiment/ColumnTypeQueryTest.java index 19bb82f6fd..1f37494b67 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/experiment/ColumnTypeQueryTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/experiment/ColumnTypeQueryTest.java @@ -8,7 +8,6 @@ import com.tightdb.ColumnType; import com.tightdb.Table; import com.tightdb.TableQuery; -import com.tightdb.exceptions.IllegalTypeException; public class ColumnTypeQueryTest { @@ -18,9 +17,9 @@ public class ColumnTypeQueryTest { @BeforeMethod public void init() { t = new Table(); - t.addColumn(ColumnType.ColumnTypeDate, "Date"); - t.addColumn(ColumnType.ColumnTypeString, "String"); - t.addColumn(ColumnType.ColumnTypeInt, "Integer"); + t.addColumn(ColumnType.DATE, "Date"); + t.addColumn(ColumnType.STRING, "String"); + t.addColumn(ColumnType.LONG, "Long"); t.add(new Date(), "I'm a String", 33); t.add(new Date(), "Second String", 458); @@ -28,17 +27,17 @@ public void init() { q = t.where(); } - @Test(expectedExceptions=IllegalTypeException.class) + @Test(expectedExceptions=IllegalArgumentException.class) public void filterLongOnStringColumn() { q.equal(1, 23).findAll(); } - @Test(expectedExceptions=IllegalTypeException.class) + @Test(expectedExceptions=IllegalArgumentException.class) public void filterStringOnLongColumn() { q.equal(3, "I'm a String").findAll(); } - @Test(expectedExceptions=IllegalTypeException.class) + @Test(expectedExceptions=IllegalArgumentException.class) public void filterStringOnDateColumn() { q.equal(1, "I'm a String").findAll(); } diff --git a/tightdb-java-test/src/test/java/com/tightdb/experiment/ColumnTypeViewTest.java b/tightdb-java-test/src/test/java/com/tightdb/experiment/ColumnTypeViewTest.java index 99ee46acde..c5d667397b 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/experiment/ColumnTypeViewTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/experiment/ColumnTypeViewTest.java @@ -12,7 +12,6 @@ import com.tightdb.ColumnType; import com.tightdb.Table; import com.tightdb.TableView; -import com.tightdb.exceptions.IllegalTypeException; import com.tightdb.test.DataProviderUtil; public class ColumnTypeViewTest { @@ -23,9 +22,9 @@ public class ColumnTypeViewTest { @BeforeMethod public void init() { t = new Table(); - t.addColumn(ColumnType.ColumnTypeDate, "Date"); - t.addColumn(ColumnType.ColumnTypeString, "String"); - t.addColumn(ColumnType.ColumnTypeInt, "Integer"); + t.addColumn(ColumnType.DATE, "Date"); + t.addColumn(ColumnType.STRING, "String"); + t.addColumn(ColumnType.LONG , "Long"); t.add(new Date(), "I'm a String", 33); diff --git a/tightdb-java-test/src/test/java/com/tightdb/experiment/DateToJSONTest.java b/tightdb-java-test/src/test/java/com/tightdb/experiment/DateToJSONTest.java index 76adc7fa6b..21e03bfcd5 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/experiment/DateToJSONTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/experiment/DateToJSONTest.java @@ -21,8 +21,8 @@ public void shouldExportJSONContainingSomeValues() { Table t = new Table(); - t.addColumn(ColumnType.ColumnTypeDate, "date"); - t.addColumn(ColumnType.ColumnTypeString, "name"); + t.addColumn(ColumnType.DATE, "date"); + t.addColumn(ColumnType.STRING, "name"); t.add(date, "name1"); diff --git a/tightdb-java-test/src/test/java/com/tightdb/experiment/InsertPerformance.java b/tightdb-java-test/src/test/java/com/tightdb/experiment/InsertPerformance.java new file mode 100644 index 0000000000..b04f84abb3 --- /dev/null +++ b/tightdb-java-test/src/test/java/com/tightdb/experiment/InsertPerformance.java @@ -0,0 +1,35 @@ +package com.tightdb.experiment; + +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)); + } +} diff --git a/tightdb-java-test/src/test/java/com/tightdb/experiment/SetIndexTest.java b/tightdb-java-test/src/test/java/com/tightdb/experiment/SetIndexTest.java index 995d7ca095..89015565c6 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/experiment/SetIndexTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/experiment/SetIndexTest.java @@ -18,10 +18,10 @@ public void shouldSetIndexWithoutFailing() { //Specify table Table table = new Table(); - table.addColumn(ColumnType.ColumnTypeString, "Name"); - table.addColumn(ColumnType.ColumnTypeDouble, "GPA"); - table.addColumn(ColumnType.ColumnTypeInt, "Age"); - table.addColumn(ColumnType.ColumnTypeString, "Nickname"); + table.addColumn(ColumnType.STRING, "Name"); + table.addColumn(ColumnType.DOUBLE, "GPA"); + table.addColumn(ColumnType.LONG, "Age"); + table.addColumn(ColumnType.STRING, "Nickname"); //Add data table.add("cc", 2.5, 24, "Pete"); @@ -34,10 +34,10 @@ public void shouldSetIndexWithoutFailing() { Group group = new Group(); Table fromGroup = group.getTable("test"); - fromGroup.addColumn(ColumnType.ColumnTypeString, "Name"); - fromGroup.addColumn(ColumnType.ColumnTypeDouble, "GPA"); - fromGroup.addColumn(ColumnType.ColumnTypeInt, "Age"); - fromGroup.addColumn(ColumnType.ColumnTypeString, "Nickname"); + fromGroup.addColumn(ColumnType.STRING, "Name"); + fromGroup.addColumn(ColumnType.DOUBLE, "GPA"); + fromGroup.addColumn(ColumnType.LONG, "Age"); + fromGroup.addColumn(ColumnType.STRING, "Nickname"); //Add data fromGroup.add("cc", 2.5, 24, "Pete"); @@ -52,10 +52,10 @@ public void shouldSetIndexWithoutFailing() { try{ Table tab = wt.getTable("table1"); - tab.addColumn(ColumnType.ColumnTypeString, "Name"); - tab.addColumn(ColumnType.ColumnTypeDouble, "GPA"); - tab.addColumn(ColumnType.ColumnTypeInt, "Age"); - tab.addColumn(ColumnType.ColumnTypeString, "Nickname"); + tab.addColumn(ColumnType.STRING, "Name"); + tab.addColumn(ColumnType.DOUBLE, "GPA"); + tab.addColumn(ColumnType.LONG, "Age"); + tab.addColumn(ColumnType.STRING, "Nickname"); //Add data tab.add("cc", 2.5, 24, "Pete"); diff --git a/tightdb-java-test/src/test/java/com/tightdb/test/TestHelper.java b/tightdb-java-test/src/test/java/com/tightdb/test/TestHelper.java index 196db568ea..59ee56787d 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/test/TestHelper.java +++ b/tightdb-java-test/src/test/java/com/tightdb/test/TestHelper.java @@ -3,6 +3,7 @@ import java.util.Date; import com.tightdb.ColumnType; +import com.tightdb.Table; /** @@ -20,20 +21,42 @@ public class TestHelper { public static ColumnType getColumnType(Object o){ if (o instanceof Boolean) - return ColumnType.ColumnTypeBool; + return ColumnType.BOOLEAN; if (o instanceof String) - return ColumnType.ColumnTypeString; + return ColumnType.STRING; if (o instanceof Long) - return ColumnType.ColumnTypeInt; + return ColumnType.LONG; if (o instanceof Float) - return ColumnType.ColumnTypeFloat; + return ColumnType.FLOAT; if (o instanceof Double) - return ColumnType.ColumnTypeDouble; + return ColumnType.DOUBLE; if (o instanceof Date) - return ColumnType.ColumnTypeDate; + return ColumnType.DATE; if (o instanceof byte[]) - return ColumnType.ColumnTypeBinary; + return ColumnType.BINARY; - return ColumnType.ColumnTypeMixed; + return ColumnType.MIXED; + } + + + /** + * Creates an empty table with 1 column of all our supported column types, currently 9 columns + * @return + */ + public static Table getTableWithAllColumnTypes(){ + + Table t = new Table(); + + t.addColumn(ColumnType.BINARY, "binary"); + t.addColumn(ColumnType.BOOLEAN, "boolean"); + t.addColumn(ColumnType.DATE, "date"); + t.addColumn(ColumnType.DOUBLE, "double"); + t.addColumn(ColumnType.FLOAT, "float"); + t.addColumn(ColumnType.LONG, "long"); + t.addColumn(ColumnType.MIXED, "mixed"); + t.addColumn(ColumnType.STRING, "string"); + t.addColumn(ColumnType.TABLE, "table"); + + return t; } } diff --git a/tightdb-java-test/src/test/java/com/tightdb/typed/AbstractTest.java b/tightdb-java-test/src/test/java/com/tightdb/typed/AbstractTest.java index 01a527ef6f..4d298c9540 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/typed/AbstractTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/typed/AbstractTest.java @@ -28,10 +28,10 @@ public abstract class AbstractTest { "phones" }; protected static final ColumnType[] EXPECTED_COLUMN_TYPE = { - ColumnType.ColumnTypeString, ColumnType.ColumnTypeString, - ColumnType.ColumnTypeInt, ColumnType.ColumnTypeBool, - ColumnType.ColumnTypeBinary, ColumnType.ColumnTypeDate, - ColumnType.ColumnTypeMixed, ColumnType.ColumnTypeTable }; + ColumnType.STRING, ColumnType.STRING, + ColumnType.LONG, ColumnType.BOOLEAN, + ColumnType.BINARY, ColumnType.DATE, + ColumnType.MIXED, ColumnType.TABLE }; protected TestEmployeeTable employees; diff --git a/tightdb-java-test/src/test/java/com/tightdb/typed/CursorColumnsTest.java b/tightdb-java-test/src/test/java/com/tightdb/typed/CursorColumnsTest.java index 463abc0f90..5f1b1fbc8e 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/typed/CursorColumnsTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/typed/CursorColumnsTest.java @@ -62,7 +62,7 @@ private void checkSetAndGetMixedValues( employee.extra.set(true); assertEquals(true, employee.extra.get().getBooleanValue()); - assertEquals(ColumnType.ColumnTypeBool, employee.extra.getType()); + assertEquals(ColumnType.BOOLEAN, employee.extra.getType()); byte[] arr = { 1, 3, 5 }; employee.extra.set(arr); @@ -71,7 +71,7 @@ private void checkSetAndGetMixedValues( .getBinaryType()); assertEquals(ByteBuffer.wrap(arr), employee.extra.get() .getBinaryValue()); - assertEquals(ColumnType.ColumnTypeBinary, employee.extra.getType()); + assertEquals(ColumnType.BINARY, employee.extra.getType()); ByteBuffer buf = ByteBuffer.allocateDirect(3); byte[] arr2 = { 10, 20, 30 }; @@ -81,26 +81,26 @@ private void checkSetAndGetMixedValues( .getBinaryType()); assertEquals(ByteBuffer.wrap(arr2), employee.extra.get() .getBinaryValue()); - assertEquals(ColumnType.ColumnTypeBinary, employee.extra.getType()); + assertEquals(ColumnType.BINARY, employee.extra.getType()); Date date = new Date(6547); employee.extra.set(date); assertEquals(date, employee.extra.get().getDateValue()); - assertEquals(ColumnType.ColumnTypeDate, employee.extra.getType()); + assertEquals(ColumnType.DATE, employee.extra.getType()); long num = 135L; employee.extra.set(num); assertEquals(num, employee.extra.get().getLongValue()); - assertEquals(ColumnType.ColumnTypeInt, employee.extra.getType()); + assertEquals(ColumnType.LONG, employee.extra.getType()); Mixed mixed = Mixed.mixedValue("mixed"); employee.extra.set(mixed); assertEquals(mixed, employee.extra.get()); - assertEquals(ColumnType.ColumnTypeString, employee.extra.getType()); + assertEquals(ColumnType.STRING, employee.extra.getType()); employee.extra.set("abc"); assertEquals("abc", employee.extra.get().getStringValue()); - assertEquals(ColumnType.ColumnTypeString, employee.extra.getType()); + assertEquals(ColumnType.STRING, employee.extra.getType()); } @Test(expectedExceptions = UnsupportedOperationException.class) diff --git a/tightdb-java-test/src/test/java/com/tightdb/typed/GroupTest.java b/tightdb-java-test/src/test/java/com/tightdb/typed/GroupTest.java index 722c52a22e..9b514b4216 100644 --- a/tightdb-java-test/src/test/java/com/tightdb/typed/GroupTest.java +++ b/tightdb-java-test/src/test/java/com/tightdb/typed/GroupTest.java @@ -191,7 +191,7 @@ public void shouldCommitToDisk() throws IOException { group.commit(); Table tbl = group.getTable("test"); - tbl.addColumn(ColumnType.ColumnTypeInt, "number"); + tbl.addColumn(ColumnType.LONG, "number"); tbl.add(1); group.commit(); assertEquals(tbl.getLong(0, 0), 1); @@ -275,12 +275,12 @@ public void shouldThrowExceptionOnMethodCallToClosedGroup() throws IOException { public void shouldCompareGroups() { Group group1 = new Group(); Table tbl = group1.getTable("test"); - tbl.addColumn(ColumnType.ColumnTypeInt, "number"); + tbl.addColumn(ColumnType.LONG, "number"); tbl.add(1); Group group2 = new Group(); Table tbl2 = group2.getTable("test"); - tbl2.addColumn(ColumnType.ColumnTypeInt, "number"); + tbl2.addColumn(ColumnType.LONG, "number"); tbl2.add(1); assertEquals(true, group1.equals(group2)); @@ -288,5 +288,49 @@ public void shouldCompareGroups() { tbl2.add(2); assertEquals(false, group1.equals(group2)); } + + + @Test(expectedExceptions = IllegalArgumentException.class) + public void shouldFailWhenModifyingTablesOnClosedGroup() { + Group group = new Group(); + Table tbl = group.getTable("test"); + tbl.addColumn(ColumnType.LONG, "number"); + tbl.add(1); + + //Close the group + group.close(); + + //Try to add data to table in group + tbl.add(2); + } + + + @Test(expectedExceptions = IllegalStateException.class) + public void shouldFailWhenAddingTablesToClosedGroup() { + Group group = new Group(); + Table tbl = group.getTable("test"); + tbl.addColumn(ColumnType.LONG, "number"); + tbl.add(1); + + //Close the group + group.close(); + + //Try to add data to table in group + Table newTable = group.getTable("test2"); + } + + + @Test(expectedExceptions = IllegalStateException.class) + public void shouldFailWhenGettingValuesFromTablesInClosedGroup() { + Group group = new Group(); + Table tbl = group.getTable("test"); + tbl.addColumn(ColumnType.LONG, "number"); + tbl.add(1); + + //Close the group + group.close(); + + tbl.getLong(0, 0); + } }