Skip to content

Commit

Permalink
Merge pull request #111 from eclipse/query_not_improve
Browse files Browse the repository at this point in the history
Improve Query in both document and column
  • Loading branch information
otaviojava authored Feb 12, 2018
2 parents f251437 + 39de85f commit 82b3dd3
Show file tree
Hide file tree
Showing 20 changed files with 132 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public interface ColumnDeleteFrom {
* Starts a new condition defining the column name
*
* @param name the column name
* @return a new {@link ColumnDeleteWhereName}
* @return a new {@link ColumnDeleteNameCondition}
* @throws NullPointerException when name is null
*/
ColumnDeleteWhereName where(String name);
ColumnDeleteNameCondition where(String name);

/**
* Creates a new instance of {@link ColumnDeleteQuery}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,12 @@ public interface ColumnDeleteNameCondition {
*/
<T> ColumnDeleteWhere in(Iterable<T> values);

/**
* Creates the equals condition {@link org.jnosql.diana.api.Condition#NOT}
*
* @return {@link ColumnDeleteNotCondition}
*/
ColumnDeleteNotCondition not();


}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public interface ColumnFrom {
* Starts a new condition defining the column name
*
* @param name the column name
* @return a new {@link ColumnWhereName}
* @return a new {@link ColumnNameCondition}
* @throws NullPointerException when name is null
*/
ColumnWhereName where(String name);
ColumnNameCondition where(String name);

/**
* Defines the position of the first result to retrieve.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,11 @@ public interface ColumnNameCondition {
*/
<T> ColumnWhere in(Iterable<T> values);

/**
* Creates the equals condition {@link org.jnosql.diana.api.Condition#NOT}
*
* @return {@link ColumnNotCondition}
*/
ColumnNotCondition not();

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* The default implementation to Delete query
*/
class DefaultDeleteQueryBuilder extends BaseQueryBuilder implements ColumnDelete, ColumnDeleteFrom,
ColumnDeleteWhere, ColumnDeleteWhereName, ColumnDeleteNotCondition {
ColumnDeleteWhere, ColumnDeleteNotCondition {

private String columnFamily;

Expand All @@ -48,7 +48,7 @@ public ColumnDeleteFrom from(String columnFamily) {


@Override
public ColumnDeleteWhereName where(String name) {
public ColumnDeleteNameCondition where(String name) {
requireNonNull(name, "name is required");
this.name = name;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* The default implementation of the Select in the column
*/
class DefaultSelectQueryBuilder extends BaseQueryBuilder implements ColumnSelect, ColumnFrom, ColumnLimit, ColumnStart,
ColumnOrder, ColumnWhereName, ColumnNameCondition, ColumnNotCondition, ColumnNameOrder, ColumnWhere {
ColumnOrder, ColumnNameCondition, ColumnNotCondition, ColumnNameOrder, ColumnWhere {


private String columnFamily;
Expand Down Expand Up @@ -57,7 +57,7 @@ public ColumnFrom from(String columnFamily) {


@Override
public ColumnWhereName where(String name) {
public ColumnNameCondition where(String name) {
requireNonNull(name, "name is required");
this.name = name;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.jnosql.diana.api.column.ColumnCondition.eq;
import static org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -230,4 +231,23 @@ public void shouldSelectWhereNameOr() {
ColumnCondition.gt(Column.of("age", 10))));
}

@Test
public void shouldDeleteNegate() {
String columnFamily = "columnFamily";
ColumnDeleteQuery query = delete().from(columnFamily).where("city").not().eq("Assis")
.and("name").not().eq("Lucas").build();

ColumnCondition condition = query.getCondition().orElseThrow(RuntimeException::new);
assertEquals(columnFamily, query.getColumnFamily());
Column column = condition.getColumn();
List<ColumnCondition> conditions = column.get(new TypeReference<List<ColumnCondition>>() {
});

assertEquals(Condition.AND, condition.getCondition());
assertThat(conditions, containsInAnyOrder(eq(Column.of("city", "Assis")).negate(),
eq(Column.of("name", "Lucas")).negate()));


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.jnosql.diana.api.Sort.SortType.ASC;
import static org.jnosql.diana.api.Sort.SortType.DESC;
import static org.jnosql.diana.api.column.ColumnCondition.eq;
import static org.jnosql.diana.api.column.query.ColumnQueryBuilder.select;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -262,7 +263,7 @@ public void shouldSelectWhereNameAnd() {
List<ColumnCondition> conditions = column.get(new TypeReference<List<ColumnCondition>>() {
});
assertEquals(Condition.AND, condition.getCondition());
assertThat(conditions, containsInAnyOrder(ColumnCondition.eq(Column.of("name", name)),
assertThat(conditions, containsInAnyOrder(eq(Column.of("name", name)),
ColumnCondition.gt(Column.of("age", 10))));
}

Expand All @@ -277,9 +278,28 @@ public void shouldSelectWhereNameOr() {
List<ColumnCondition> conditions = column.get(new TypeReference<List<ColumnCondition>>() {
});
assertEquals(Condition.OR, condition.getCondition());
assertThat(conditions, containsInAnyOrder(ColumnCondition.eq(Column.of("name", name)),
assertThat(conditions, containsInAnyOrder(eq(Column.of("name", name)),
ColumnCondition.gt(Column.of("age", 10))));
}

@Test
public void shouldSelectNegate() {
String columnFamily = "columnFamily";
ColumnQuery query = select().from(columnFamily).where("city").not().eq("Assis")
.and("name").not().eq("Lucas").build();

ColumnCondition condition = query.getCondition().orElseThrow(RuntimeException::new);
assertEquals(columnFamily, query.getColumnFamily());
Column column = condition.getColumn();
List<ColumnCondition> conditions = column.get(new TypeReference<List<ColumnCondition>>() {
});

assertEquals(Condition.AND, condition.getCondition());
assertThat(conditions, containsInAnyOrder(eq(Column.of("city", "Assis")).negate(),
eq(Column.of("name", "Lucas")).negate()));


}


}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* The default implementation to Delete query
*/
class DefaultDeleteQueryBuilder extends BaseQueryBuilder implements DocumentDelete, DocumentDeleteFrom,
DocumentDeleteWhere, DocumentDeleteWhereName, DocumentDeleteNotCondition {
DocumentDeleteWhere, DocumentDeleteNotCondition {

private String documentCollection;

Expand All @@ -47,7 +47,7 @@ public DocumentDeleteFrom from(String documentCollection) {


@Override
public DocumentDeleteWhereName where(String name) {
public DocumentDeleteNameCondition where(String name) {
requireNonNull(name, "name is required");
this.name = name;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* The default implementation of the Select in the document
*/
class DefaultSelectQueryBuilder extends BaseQueryBuilder implements DocumentSelect, DocumentFrom, DocumentLimit,
DocumentStart, DocumentOrder, DocumentWhereName, DocumentNotCondition, DocumentNameOrder, DocumentWhere {
DocumentStart, DocumentOrder, DocumentNotCondition, DocumentNameOrder, DocumentWhere {


private String documentCollection;
Expand Down Expand Up @@ -57,7 +57,7 @@ public DocumentFrom from(String documentCollection) {


@Override
public DocumentWhereName where(String name) {
public DocumentNameCondition where(String name) {
requireNonNull(name, "name is required");
this.name = name;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public interface DocumentDeleteFrom {
* Starts a new condition defining the column name
*
* @param name the column name
* @return a new {@link DocumentDeleteWhereName}
* @return a new {@link DocumentDeleteNameCondition}
* @throws NullPointerException when name is null
*/
DocumentDeleteWhereName where(String name);
DocumentDeleteNameCondition where(String name);

/**
* Creates a new instance of {@link DocumentDeleteQuery}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,11 @@ public interface DocumentDeleteNameCondition {
*/
<T> DocumentDeleteWhere in(Iterable<T> values);

/**
* Creates the equals condition {@link org.jnosql.diana.api.Condition#NOT}
*
* @return {@link DocumentDeleteNotCondition}
*/
DocumentDeleteNotCondition not();

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public interface DocumentFrom {
* Starts a new condition defining the column name
*
* @param name the column name
* @return a new {@link DocumentWhereName}
* @return a new {@link DocumentNameCondition}
* @throws NullPointerException when name is null
*/
DocumentWhereName where(String name);
DocumentNameCondition where(String name);

/**
* Defines the position of the first result to retrieve.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,11 @@ public interface DocumentNameCondition {
* @throws NullPointerException when value is null
*/
<T> DocumentWhere in(Iterable<T> values);

/**
* Creates the equals condition {@link org.jnosql.diana.api.Condition#NOT}
*
* @return {@link DocumentNotCondition}
*/
DocumentNotCondition not();
}

This file was deleted.

Loading

0 comments on commit 82b3dd3

Please sign in to comment.