Skip to content

Commit

Permalink
Added changes to allow optional arguments for some of the commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhenry committed Apr 30, 2014
1 parent a3bad35 commit 5be0520
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.dkhenry</groupId>
<artifactId>rethinkjava</artifactId>
<version>0.9-SNAPSHOT</version>
<version>0.9</version>
<packaging>jar</packaging>

<name>rethinkjava</name>
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/dkhenry/RethinkDB/RqlObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import java.util.Map;
import com.dkhenry.RethinkDB.errors.RqlDriverException;
import com.rethinkdb.Ql2;

public class RqlObject {

Expand All @@ -22,22 +23,46 @@ public RqlObject(com.rethinkdb.Ql2.Datum d) {
public Boolean getBoolean() throws RqlDriverException {
return as();
}

public Boolean isBoolean() {
return _underlying.getType() == Ql2.Datum.DatumType.R_BOOL;
}

public Double getNumber() throws RqlDriverException {
return as();
}

public Boolean isNumber() {
return _underlying.getType() == Ql2.Datum.DatumType.R_NUM;
}

public String getString() throws RqlDriverException {
return as();
}

public Boolean isString() {
return _underlying.getType() == Ql2.Datum.DatumType.R_STR;
}

public List<Object> getList() throws RqlDriverException {
return as();
}

public Boolean isList() {
return _underlying.getType() == Ql2.Datum.DatumType.R_ARRAY;
}

public Map<String,Object> getMap() throws RqlDriverException {
return as();
}

public Boolean isMap() {
return _underlying.getType() == Ql2.Datum.DatumType.R_OBJECT;
}

public Object get() throws RqlDriverException {
return as();
}

@SuppressWarnings("unchecked")
public <T> T as() throws RqlDriverException {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/dkhenry/RethinkDB/RqlQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public RqlMethodQuery.Map map(Object ...args) {
}

public RqlMethodQuery.Filter filter(Object ...args) {
return prepend_construct_with_optargs(args, RqlMethodQuery.Filter.class, 1);
return prepend_construct(args, RqlMethodQuery.Filter.class);
}

public RqlMethodQuery.ConcatMap concat_map(Object ...args) {
Expand Down Expand Up @@ -496,7 +496,7 @@ protected TermType tt() {
}

public RqlMethodQuery.Insert insert(Object... args) {
return prepend_construct_with_optargs(args, RqlMethodQuery.Insert.class, 1);
return prepend_construct(args, RqlMethodQuery.Insert.class);
}

public RqlMethodQuery.Get get(Object ...args) {
Expand All @@ -521,7 +521,7 @@ public RqlMethodQuery.IndexList index_list(Object ...args) {

@Override
public RqlMethodQuery.Filter filter(Object ...args) {
return prepend_construct_with_optargs(args, RqlMethodQuery.Filter.class, 1);
return prepend_construct(args, RqlMethodQuery.Filter.class);
}

public RqlMethodQuery.Count count(Object ...args) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/dkhenry/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ public void insertAndRetrieveData() throws RqlDriverException {
assert rowCount == 4.0 : "Failed at getting the correct row count.";

cursor = r.run(r.db(database).table(table).filter(new HashMap() {{ put("name", "Worf"); }}).update(new HashMap() {{ put("show", "Star Trek Deep Space Nine"); }}));
assert Double.valueOf(1.0).equals(cursor.next().getAs("updated")) : "Error updating Data into Database";
assert Double.valueOf(1.0).equals(cursor.next().getAs("replaced")) : "Error updating Data in Database";
cursor = r.run(r.db(database).table(table).filter(new HashMap() {{ put("name","Worf"); }}));
for(RqlObject o: cursor) {
Map<String,Object> m = o.getMap();
assert m.containsKey("name") : "Data that came back was malformed (missing \"name\")";
assert m.containsKey("Show") : "Data that came back was malformed (missing \"name\")";
assert m.containsKey("show") : "Data that came back was malformed (missing \"show\")";
assert "Star Trek Deep Space Nine".equals(m.get("show")) : "Data that came back was just plain wrong (\"show\" was not \"Star Trek Deep Space Nine\")";
}

Expand Down

0 comments on commit 5be0520

Please sign in to comment.