Skip to content

Commit

Permalink
Merge branch 'release/1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
paul.rutledge committed Mar 7, 2016
2 parents 179e1ea + 5a33e6b commit b7623af
Show file tree
Hide file tree
Showing 23 changed files with 285 additions and 200 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[![Build Status](https://travis-ci.org/RutledgePaulV/q-builders.svg)](https://travis-ci.org/RutledgePaulV/q-builders)
[![Coverage Status](https://coveralls.io/repos/RutledgePaulV/q-builders/badge.svg?branch=master&service=github)](https://coveralls.io/github/RutledgePaulV/q-builders?branch=master)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.rutledgepaulv/q-builders/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.rutledgepaulv/q-builders)
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/RutledgePaulV/q-builders)

### Overview
A generic abstraction for building queries for arbitrary domain models that minimizes
Expand Down
139 changes: 7 additions & 132 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,19 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.rutledgepaulv</groupId>
<parent>
<groupId>com.github.rutledgepaulv</groupId>
<artifactId>maven</artifactId>
<version>1.1</version>
</parent>

<artifactId>q-builders</artifactId>
<version>1.1</version>
<version>1.2</version>

<name>q-builders</name>
<url>http://github.com/rutledgepaulv/q-builders</url>
<description>A type-safe and database agnostic query building library.</description>

<developers>
<developer>
<name>Paul Rutledge</name>
<email>paul.v.rutledge@gmail.com</email>
</developer>
</developers>

<licenses>
<license>
<name>MIT</name>
<url>http://opensource.org/licenses/MIT</url>
</license>
</licenses>

<scm>
<url>http://github.com/rutledgepaulv/q-builders</url>
<connection>scm:git:git@github.com:rutledgepaulv/q-builders.git</connection>
Expand All @@ -39,115 +30,6 @@
<url>https://github.com/rutledgepaulv/q-builders/issues</url>
</issueManagement>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>

<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.3</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>


<build>
<plugins>
<plugin>
<groupId>external.atlassian.jgitflow</groupId>
<artifactId>jgitflow-maven-plugin</artifactId>
<version>1.0-m5.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.0.0</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>


<dependencies>

<dependency>
Expand All @@ -174,13 +56,6 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>cz.jirutka.rsql</groupId>
<artifactId>rsql-parser</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ public class QBuilder<T extends QBuilder<T>> implements Partial<T> {
private LogicalNode current;

public QBuilder() {
root = new OrNode(null, new ArrayList<>());
current = root;
root = current = new OrNode();
}

public final <S extends Enum<S>> EnumProperty<T,S> enumeration(String field) {
return prop(field, EnumPropertyDelegate.class, EnumProperty.class);
}

public final BooleanProperty<T> bool(String field) {
Expand Down Expand Up @@ -69,11 +72,11 @@ public final InstantProperty<T> instant(String field) {
return prop(field, InstantPropertyDelegate.class, InstantProperty.class);
}

public <S extends QBuilder<S>> ConditionProperty<T, S> condition(String field) {
public final <S extends QBuilder<S>> ConditionProperty<T, S> condition(String field) {
return prop(field, ConditionPropertyDelegate.class, ConditionProperty.class);
}

public final <S extends PropertyDelegate<T>, Q extends Property<T>> Q prop(String field, Class<S> delegate, Class<Q> inter) {
protected final <S extends PropertyDelegate<T>, Q extends Property<T>> Q prop(String field, Class<S> delegate, Class<Q> inter) {
if(!inter.isAssignableFrom(delegate)) {
throw new IllegalArgumentException("Must provide a delegate that implements the interface to be returned.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
*/
public interface Partial<T extends QBuilder<T>> {

/**
* For usage when the field is known to contain values of an enum type.
*
* @param field The name of the field.
*
* @return The property interface so that a constraint can be set against the field.
*/
<S extends Enum<S>> EnumProperty<T,S> enumeration(String field);

/**
* For usage when the field is known to contain values of a boolean type.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.rutledgepaulv.qbuilders.delegates.concrete;

import com.github.rutledgepaulv.qbuilders.builders.QBuilder;
import com.github.rutledgepaulv.qbuilders.delegates.virtual.ListablePropertyDelegate;
import com.github.rutledgepaulv.qbuilders.properties.concrete.EnumProperty;

public final class EnumPropertyDelegate<T extends QBuilder<T>, S extends Enum<S>>
extends ListablePropertyDelegate<T,S> implements EnumProperty<T,S> {

public EnumPropertyDelegate(String field, T canonical) {
super(field, canonical);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,27 @@

import com.github.rutledgepaulv.qbuilders.visitors.NodeVisitor;

import java.util.ArrayList;
import java.util.List;

public abstract class AbstractNode implements Visitable {

private AbstractNode parent;
private List<AbstractNode> children = new ArrayList<>();
private LogicalNode parent;

public AbstractNode(AbstractNode parent) {
this.parent = parent;
}
public AbstractNode() {}

public AbstractNode(AbstractNode parent, List<AbstractNode> children) {
public AbstractNode(LogicalNode parent) {
this.parent = parent;
setChildren(children);
}

public List<AbstractNode> getChildren() {
return children;
}

public void setChildren(List<AbstractNode> children) {
this.children = children;
children.forEach(child -> child.setParent(this));
}


public AbstractNode getParent() {
public LogicalNode getParent() {
return parent;
}

public void setParent(AbstractNode parent) {
public void setParent(LogicalNode parent) {
this.parent = parent;
}

@Override
public <T> T visit(NodeVisitor<T> visitor) {
return visitor.visitAny(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

public final class AndNode extends LogicalNode {

public AndNode(AbstractNode parent, List<AbstractNode> children) {
public AndNode() {}

public AndNode(LogicalNode parent) {
super(parent);
}

public AndNode(LogicalNode parent, List<AbstractNode> children) {
super(parent, children);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public final class ComparisonNode extends AbstractNode {
private ComparisonOperator operator;
private Collection<?> values;

public ComparisonNode(AbstractNode parent) {
public ComparisonNode(LogicalNode parent) {
super(parent);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
package com.github.rutledgepaulv.qbuilders.nodes;

import java.util.LinkedList;
import java.util.List;

public abstract class LogicalNode extends AbstractNode {

public LogicalNode(AbstractNode parent, List<AbstractNode> children) {
super(parent, children);
private List<AbstractNode> children = new LinkedList<>();

public LogicalNode() {}

public LogicalNode(LogicalNode parent) {
super(parent);
}

public LogicalNode(LogicalNode parent, List<AbstractNode> children) {
super(parent);
setChildren(children);
}

public List<AbstractNode> getChildren() {
return children;
}

public void setChildren(List<AbstractNode> children) {
this.children = children;
children.forEach(child -> child.setParent(this));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@

public final class OrNode extends LogicalNode {

public OrNode(AbstractNode parent, List<AbstractNode> children) {
public OrNode() {}

public OrNode(LogicalNode parent) {
super(parent);
}

public OrNode(LogicalNode parent, List<AbstractNode> children) {
super(parent, children);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.github.rutledgepaulv.qbuilders.properties.concrete;

import com.github.rutledgepaulv.qbuilders.builders.QBuilder;
import com.github.rutledgepaulv.qbuilders.properties.virtual.EquitableProperty;
import com.github.rutledgepaulv.qbuilders.properties.virtual.ListableProperty;

/**
* A property view for fields with {@link Enum} values.
*
* @param <T> The type of the final builder.
*/
public interface EnumProperty<T extends QBuilder<T>, S extends Enum<S>>
extends ListableProperty<T,S>, EquitableProperty<T, S> {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

@SuppressWarnings({"unchecked", "Convert2MethodRef"})
public final class ObjectUtils {
private ObjectUtils(){}


/**
* Instantiate a class for the provided constructor arguments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,4 @@ protected QueryBuilder visit(ComparisonNode node) {
throw new UnsupportedOperationException("This visitor does not support the operator " + operator + ".");
}


protected Object single(Collection<?> values) {
if (!values.isEmpty()) {
return values.iterator().next();
} else {
throw new IllegalArgumentException("You must provide a query value for the condition.");
}
}

}
Loading

0 comments on commit b7623af

Please sign in to comment.