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

merge Niko changes. #87

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static void main(String[] args) {
int randLength = randomNames.length;
for (int n = 0; n < ROUNDS; ++n) {
long rowIndex = table.lookup( randomNames[ rand.nextInt(randLength) ] );
tightdbLookups += table.at(rowIndex).getAge();
tightdbLookups += table.get(rowIndex).getAge();
}
long tightdbLookupTime = timer.GetTimeInMs();
System.out.printf(" lookup (random string): %10d msec\n", tightdbLookupTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public static void showLongExample() {
System.out.println("name2: " + john.getFirstName());

// 2 ways to set the value
employees.at(2).lastName.set("NewName");
employees.at(2).setLastName("NewName");
employees.get(2).lastName.set("NewName");
employees.get(2).setLastName("NewName");

/****************************** MANIPULATION OF ALL RECORDS *****************************/

Expand Down Expand Up @@ -182,7 +182,7 @@ public static void showLongExample() {

/*************************** CURSOR NAVIGATION ***************************/

Employee p1 = employees.at(0).next(); // 2nd row
Employee p1 = employees.get(0).next(); // 2nd row
Employee p2 = employees.last().previous(); // 2nd-last row
Employee p3 = employees.first().after(2); // 3rd row
employees.last().before(2); // 3rd-last row
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ public static void main(String[] args) {

// @@Example: accessing_rows @@
// 2 ways to get the value
String name = peopleTable.at(2).getName(); // name => "Mary"
String name = peopleTable.get(2).getName(); // name => "Mary"
// or
String name2 = peopleTable.at(2).name.get();
String name2 = peopleTable.get(2).name.get();

// 2 ways to set the value
peopleTable.at(2).name.set("NewName");
peopleTable.get(2).name.set("NewName");
// or
peopleTable.at(2).setName("NewName");
peopleTable.get(2).setName("NewName");
// @@EndExample@@

System.out.println("at(2).getName -> " + name + " or " + name2);
System.out.println("at(2).setName('NewName') -> " + peopleTable.at(2).getName());
System.out.println("get(2).getName -> " + name + " or " + name2);
System.out.println("get(2).setName('NewName') -> " + peopleTable.get(2).getName());

// @@Example: last_row @@
String lastRowName = peopleTable.last().getName(); // retrieve name for last row
Expand Down
59 changes: 29 additions & 30 deletions tightdb-java-core/src/main/java/com/tightdb/WriteTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,33 @@

public class WriteTransaction extends Group {

public void commit()
{
db.commit();
}

/**
* Does the same thing as close().
*/
public void rollback()
{
db.rollback();
}

public void close()
{
db.rollback();
}


WriteTransaction(SharedGroup db, long nativePtr)
{
super(nativePtr, false); // Group is mutable
this.db = db;
}


protected void finalize() {} // Nullify the actions of Group.finalize()


private SharedGroup db;
private boolean commited;

public void commit() {
db.commit();
commited = true;
}

/**
* Does the same thing as close().
*/
public void rollback() {
db.rollback();
}

public void close() {
if (!commited) {
db.rollback();
}
}

WriteTransaction(SharedGroup db, long nativePtr) {
super(nativePtr, false); // Group is mutable
this.db = db;
}

protected void finalize() {
} // Nullify the actions of Group.finalize()

private SharedGroup db;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,23 @@ public void removeLast() {
tableOrView.removeLast();
}

/* TODO:
* public View range(long from, long to) {
throw new UnsupportedOperationException();
}
*/
/*
* TODO: public View range(long from, long to) { throw new
* UnsupportedOperationException(); }
*/

/**
* This method is deprecated, use {@link #get(long)} instead.
*/
@Deprecated
public Cursor at(long position) {
return cursor(position);
}

public Cursor get(long position) {
return cursor(position);
}

public Cursor first() {
return cursor(0);
}
Expand All @@ -69,5 +77,5 @@ public Iterator<Cursor> iterator() {
public String toJson() {
return tableOrView.toJson();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,18 @@ public void clear() {
cursor.tableOrView.clearSubTable(columnIndex, cursor.getPosition());
}

/**
* This method is deprecated, use {@link #get(long)} instead.
*/
@Deprecated
public Subcursor at(long position) {
return subcursor(position);
}

public Subcursor get(long position) {
return subcursor(position);
}

public Subcursor first() {
return subcursor(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public T next() {
if (hasNext() == false) {
throw new NoSuchElementException();
}
return tableOrView.at(index++);
return tableOrView.get(index++);
}

public void remove() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ public static void print(String caption, AbstractTableOrView<? extends AbstractC
String format = "%-15s| ";
System.out.println(String.format("================== %s ====================", caption));
if (!tableOrView.isEmpty()) {
for (AbstractColumn<?, ?, ?, ?> column : tableOrView.at(0).columns()) {
for (AbstractColumn<?, ?, ?, ?> column : tableOrView.get(0).columns()) {
System.out.print(String.format(format, column.getName()));
}
System.out.println();

for (int i = 0; i < tableOrView.size(); i++) {
AbstractCursor<?> p = tableOrView.at(i);
AbstractCursor<?> p = tableOrView.get(i);
for (AbstractColumn<?, ?, ?, ?> column : p.columns()) {
System.out.print(String.format(format, column.getReadableValue()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ public void describe() {
constructor("Allocates and instantiates a TightDB table, as part of the specified group", "Group", "group");

method("Row", "add", "Insert a new row at the end of the table", "RowDataTypes...", "rowData...");
method("Row", "at", "Get a specific row as an object (rowIndex starts at 0)", "long", "rowIndex");
method("Row", "at", "[Deprecated] Get a specific row as an object (rowIndex starts at 0)", "long", "rowIndex");
method("void", "clear", "Delete all rows in the table");
method("Row", "first", "Get the first row as an object");
method("Row", "get", "Get a specific row as an object (rowIndex starts at 0)", "long", "rowIndex");
method("long", "getColumnCount", "Get number of columns in the table");
method("String", "getColumnName", "Get the name of the column");
method("ColumnType","getColumnType", "Get the type of the column");
Expand Down
3 changes: 2 additions & 1 deletion tightdb-java-doc/src/main/java/com/tightdb/doc/ViewDesc.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ public ViewDesc(List<Constructor> constructors, List<Method> methods) {
}

public void describe() {
method("Row", "at", "Get a specific row", "long", "rowIndex");
method("Row", "at", "[Deprecated] Get a specific row", "long", "rowIndex");
method("void", "clear", "Delete all rows in the view");
method("Row", "first", "Get the first row");
method("Row", "get", "Get a specific row", "long", "rowIndex");
method("boolean", "isEmpty", "Check if the view has no rows");
method("Iterator", "iterator", "Get an iterator for the view rows");
method("Row", "last", "Get the last row");
Expand Down
6 changes: 3 additions & 3 deletions tightdb-java-doc/src/main/resources/RowExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public static void main(String[] args) {

/* EXAMPLE: after */

Person third = people.at(0).after(2);
Person third = people.get(0).after(2);

/* EXAMPLE: before */

Person second = people.at(4).before(3);
Person second = people.get(4).before(3);

/* EXAMPLE: columns */

Expand All @@ -23,7 +23,7 @@ public static void main(String[] args) {

/* EXAMPLE: next */

Person fifth = people.at(3).next();
Person fifth = people.get(3).next();

/* EXAMPLE: previous */

Expand Down
4 changes: 2 additions & 2 deletions tightdb-java-doc/src/main/resources/TableExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public static void main(String[] args) {
people.add("Mary", 21, false);
people.add("Lars", 24, true);

/* EXAMPLE: at */
/* EXAMPLE: get */

Person p = people.at(42);
Person p = people.get(42);

/* EXAMPLE: clear */

Expand Down
4 changes: 2 additions & 2 deletions tightdb-java-doc/src/main/resources/ViewExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ public class ViewExamples {

public static void main(String[] args) {

/* EXAMPLE: at */
/* EXAMPLE: get */

Person p = people.age.equals(19).findAll().at(1);
Person p = people.age.equals(19).findAll().get(1);

/* EXAMPLE: clear */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,60 +27,60 @@ public void clear() {

@Test
public void shouldRetrieveRowsByIndex() {
assertEquals(NAME0, getEmployees().at(0).getFirstName());
assertEquals(NAME1, getEmployees().at(1).getFirstName());
assertEquals(NAME2, getEmployees().at(2).getFirstName());
assertEquals(NAME0, getEmployees().get(0).getFirstName());
assertEquals(NAME1, getEmployees().get(1).getFirstName());
assertEquals(NAME2, getEmployees().get(2).getFirstName());
}

@Test
public void shouldHaveTwoWaysToReadCellValues() {
assertEquals(NAME0, getEmployees().at(0).getFirstName());
assertEquals(NAME0, getEmployees().at(0).firstName.get());
assertEquals(NAME0, getEmployees().get(0).getFirstName());
assertEquals(NAME0, getEmployees().get(0).firstName.get());
}

@Test
public void shouldHaveTwoWaysToWriteCellValues() {
getEmployees().at(0).setFirstName("FOO");
assertEquals("FOO", getEmployees().at(0).getFirstName());
getEmployees().get(0).setFirstName("FOO");
assertEquals("FOO", getEmployees().get(0).getFirstName());

getEmployees().at(0).firstName.set("BAR");
assertEquals("BAR", getEmployees().at(0).getFirstName());
getEmployees().get(0).firstName.set("BAR");
assertEquals("BAR", getEmployees().get(0).getFirstName());
}

@Test
public void shouldAllowMixedValues() throws IllegalAccessException {
assertEquals("extra", getEmployees().at(0).getExtra().getValue());
assertEquals("extra", getEmployees().at(0).getExtra().getStringValue());
assertEquals("extra", getEmployees().get(0).getExtra().getValue());
assertEquals("extra", getEmployees().get(0).getExtra().getStringValue());

assertEquals(1234L, getEmployees().at(1).getExtra().getValue());
assertEquals(1234L, getEmployees().at(1).getExtra().getLongValue());
assertEquals(1234L, getEmployees().get(1).getExtra().getValue());
assertEquals(1234L, getEmployees().get(1).getExtra().getLongValue());

assertEquals(true, getEmployees().at(2).getExtra().getValue());
assertEquals(true, getEmployees().at(2).getExtra().getBooleanValue());
assertEquals(true, getEmployees().get(2).getExtra().getValue());
assertEquals(true, getEmployees().get(2).getExtra().getBooleanValue());

getEmployees().at(1).setExtra(Mixed.mixedValue("new_value"));
assertEquals("new_value", getEmployees().at(1).getExtra().getValue());
assertEquals("new_value", getEmployees().at(1).getExtra()
getEmployees().get(1).setExtra(Mixed.mixedValue("new_value"));
assertEquals("new_value", getEmployees().get(1).getExtra().getValue());
assertEquals("new_value", getEmployees().get(1).getExtra()
.getStringValue());
}

@Test
public void shouldRemoveFirstRow() throws IllegalAccessException {
// Remove first row
getEmployees().remove(0);
assertEquals(NAME1, getEmployees().at(0).getFirstName());
assertEquals(NAME2, getEmployees().at(1).getFirstName());
assertEquals(NAME3, getEmployees().at(2).getFirstName());
assertEquals(NAME1, getEmployees().get(0).getFirstName());
assertEquals(NAME2, getEmployees().get(1).getFirstName());
assertEquals(NAME3, getEmployees().get(2).getFirstName());
assertEquals(3, getEmployees().size());
}

@Test
public void shouldRemoveMiddleRow() throws IllegalAccessException {
// Remove middle row
getEmployees().remove(1);
assertEquals(NAME0, getEmployees().at(0).getFirstName());
assertEquals(NAME2, getEmployees().at(1).getFirstName());
assertEquals(NAME3, getEmployees().at(2).getFirstName());
assertEquals(NAME0, getEmployees().get(0).getFirstName());
assertEquals(NAME2, getEmployees().get(1).getFirstName());
assertEquals(NAME3, getEmployees().get(2).getFirstName());
assertEquals(3, getEmployees().size());
}

Expand All @@ -89,15 +89,15 @@ public void shouldRemoveLastRow() throws IllegalAccessException {
// Remove last row
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());
assertEquals(NAME0, getEmployees().get(0).getFirstName());
assertEquals(NAME1, getEmployees().get(1).getFirstName());
assertEquals(NAME2, getEmployees().get(2).getFirstName());

// Remove last row
getEmployees().removeLast();
assertEquals(2, getEmployees().size());
assertEquals(NAME0, getEmployees().at(0).getFirstName());
assertEquals(NAME1, getEmployees().at(1).getFirstName());
assertEquals(NAME0, getEmployees().get(0).getFirstName());
assertEquals(NAME1, getEmployees().get(1).getFirstName());
}

@Test
Expand Down
Loading